1 /*******************************************************************************
4 Copyright(c) 1999 - 2006 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 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
26 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
28 *******************************************************************************/
31 * Shared functions for accessing and configuring the MAC
36 static int32_t e1000_set_phy_type(struct e1000_hw *hw);
37 static void e1000_phy_init_script(struct e1000_hw *hw);
38 static int32_t e1000_setup_copper_link(struct e1000_hw *hw);
39 static int32_t e1000_setup_fiber_serdes_link(struct e1000_hw *hw);
40 static int32_t e1000_adjust_serdes_amplitude(struct e1000_hw *hw);
41 static int32_t e1000_phy_force_speed_duplex(struct e1000_hw *hw);
42 static int32_t e1000_config_mac_to_phy(struct e1000_hw *hw);
43 static void e1000_raise_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl);
44 static void e1000_lower_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl);
45 static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, uint32_t data,
47 static uint16_t e1000_shift_in_mdi_bits(struct e1000_hw *hw);
48 static int32_t e1000_phy_reset_dsp(struct e1000_hw *hw);
49 static int32_t e1000_write_eeprom_spi(struct e1000_hw *hw, uint16_t offset,
50 uint16_t words, uint16_t *data);
51 static int32_t e1000_write_eeprom_microwire(struct e1000_hw *hw,
52 uint16_t offset, uint16_t words,
54 static int32_t e1000_spi_eeprom_ready(struct e1000_hw *hw);
55 static void e1000_raise_ee_clk(struct e1000_hw *hw, uint32_t *eecd);
56 static void e1000_lower_ee_clk(struct e1000_hw *hw, uint32_t *eecd);
57 static void e1000_shift_out_ee_bits(struct e1000_hw *hw, uint16_t data,
59 static int32_t e1000_write_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr,
61 static int32_t e1000_read_phy_reg_ex(struct e1000_hw *hw,uint32_t reg_addr,
63 static uint16_t e1000_shift_in_ee_bits(struct e1000_hw *hw, uint16_t count);
64 static int32_t e1000_acquire_eeprom(struct e1000_hw *hw);
65 static void e1000_release_eeprom(struct e1000_hw *hw);
66 static void e1000_standby_eeprom(struct e1000_hw *hw);
67 static int32_t e1000_set_vco_speed(struct e1000_hw *hw);
68 static int32_t e1000_polarity_reversal_workaround(struct e1000_hw *hw);
69 static int32_t e1000_set_phy_mode(struct e1000_hw *hw);
70 static int32_t e1000_host_if_read_cookie(struct e1000_hw *hw, uint8_t *buffer);
71 static uint8_t e1000_calculate_mng_checksum(char *buffer, uint32_t length);
72 static uint8_t e1000_arc_subsystem_valid(struct e1000_hw *hw);
73 static int32_t e1000_check_downshift(struct e1000_hw *hw);
74 static int32_t e1000_check_polarity(struct e1000_hw *hw, uint16_t *polarity);
75 static void e1000_clear_hw_cntrs(struct e1000_hw *hw);
76 static void e1000_clear_vfta(struct e1000_hw *hw);
77 static int32_t e1000_commit_shadow_ram(struct e1000_hw *hw);
78 static int32_t e1000_config_dsp_after_link_change(struct e1000_hw *hw,
80 static int32_t e1000_config_fc_after_link_up(struct e1000_hw *hw);
81 static int32_t e1000_detect_gig_phy(struct e1000_hw *hw);
82 static int32_t e1000_get_auto_rd_done(struct e1000_hw *hw);
83 static int32_t e1000_get_cable_length(struct e1000_hw *hw,
85 uint16_t *max_length);
86 static int32_t e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw);
87 static int32_t e1000_get_phy_cfg_done(struct e1000_hw *hw);
88 static int32_t e1000_id_led_init(struct e1000_hw * hw);
89 static void e1000_init_rx_addrs(struct e1000_hw *hw);
90 static boolean_t e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw);
91 static int32_t e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd);
92 static void e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw);
93 static int32_t e1000_read_eeprom_eerd(struct e1000_hw *hw, uint16_t offset,
94 uint16_t words, uint16_t *data);
95 static int32_t e1000_set_d0_lplu_state(struct e1000_hw *hw, boolean_t active);
96 static int32_t e1000_set_d3_lplu_state(struct e1000_hw *hw, boolean_t active);
97 static int32_t e1000_wait_autoneg(struct e1000_hw *hw);
99 static void e1000_write_reg_io(struct e1000_hw *hw, uint32_t offset,
102 #define E1000_WRITE_REG_IO(a, reg, val) \
103 e1000_write_reg_io((a), E1000_##reg, val)
104 static int32_t e1000_configure_kmrn_for_10_100(struct e1000_hw *hw);
105 static int32_t e1000_configure_kmrn_for_1000(struct e1000_hw *hw);
107 /* IGP cable length table */
109 uint16_t e1000_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] =
110 { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
111 5, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 25, 25, 25,
112 25, 25, 25, 25, 30, 30, 30, 30, 40, 40, 40, 40, 40, 40, 40, 40,
113 40, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60,
114 60, 70, 70, 70, 70, 70, 70, 80, 80, 80, 80, 80, 80, 90, 90, 90,
115 90, 90, 90, 90, 90, 90, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
116 100, 100, 100, 100, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,
117 110, 110, 110, 110, 110, 110, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120};
120 uint16_t e1000_igp_2_cable_length_table[IGP02E1000_AGC_LENGTH_TABLE_SIZE] =
121 { 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21,
122 0, 0, 0, 3, 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41,
123 6, 10, 14, 18, 22, 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61,
124 21, 26, 31, 35, 40, 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82,
125 40, 45, 51, 56, 61, 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104,
126 60, 66, 72, 77, 82, 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121,
127 83, 89, 95, 100, 105, 109, 113, 116, 119, 122, 124,
128 104, 109, 114, 118, 121, 124};
131 /******************************************************************************
132 * Set the phy type member in the hw struct.
134 * hw - Struct containing variables accessed by shared code
135 *****************************************************************************/
137 e1000_set_phy_type(struct e1000_hw *hw)
139 DEBUGFUNC("e1000_set_phy_type");
141 if(hw->mac_type == e1000_undefined)
142 return -E1000_ERR_PHY_TYPE;
145 case M88E1000_E_PHY_ID:
146 case M88E1000_I_PHY_ID:
147 case M88E1011_I_PHY_ID:
148 case M88E1111_I_PHY_ID:
149 hw->phy_type = e1000_phy_m88;
151 case IGP01E1000_I_PHY_ID:
152 if(hw->mac_type == e1000_82541 ||
153 hw->mac_type == e1000_82541_rev_2 ||
154 hw->mac_type == e1000_82547 ||
155 hw->mac_type == e1000_82547_rev_2) {
156 hw->phy_type = e1000_phy_igp;
159 case GG82563_E_PHY_ID:
160 if (hw->mac_type == e1000_80003es2lan) {
161 hw->phy_type = e1000_phy_gg82563;
166 /* Should never have loaded on this device */
167 hw->phy_type = e1000_phy_undefined;
168 return -E1000_ERR_PHY_TYPE;
171 return E1000_SUCCESS;
174 /******************************************************************************
175 * IGP phy init script - initializes the GbE PHY
177 * hw - Struct containing variables accessed by shared code
178 *****************************************************************************/
180 e1000_phy_init_script(struct e1000_hw *hw)
183 uint16_t phy_saved_data;
185 DEBUGFUNC("e1000_phy_init_script");
187 if(hw->phy_init_script) {
190 /* Save off the current value of register 0x2F5B to be restored at
191 * the end of this routine. */
192 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
194 /* Disabled the PHY transmitter */
195 e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
199 e1000_write_phy_reg(hw,0x0000,0x0140);
203 switch(hw->mac_type) {
206 e1000_write_phy_reg(hw, 0x1F95, 0x0001);
208 e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
210 e1000_write_phy_reg(hw, 0x1F79, 0x0018);
212 e1000_write_phy_reg(hw, 0x1F30, 0x1600);
214 e1000_write_phy_reg(hw, 0x1F31, 0x0014);
216 e1000_write_phy_reg(hw, 0x1F32, 0x161C);
218 e1000_write_phy_reg(hw, 0x1F94, 0x0003);
220 e1000_write_phy_reg(hw, 0x1F96, 0x003F);
222 e1000_write_phy_reg(hw, 0x2010, 0x0008);
225 case e1000_82541_rev_2:
226 case e1000_82547_rev_2:
227 e1000_write_phy_reg(hw, 0x1F73, 0x0099);
233 e1000_write_phy_reg(hw, 0x0000, 0x3300);
237 /* Now enable the transmitter */
238 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
240 if(hw->mac_type == e1000_82547) {
241 uint16_t fused, fine, coarse;
243 /* Move to analog registers page */
244 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_SPARE_FUSE_STATUS, &fused);
246 if(!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
247 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_FUSE_STATUS, &fused);
249 fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
250 coarse = fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
252 if(coarse > IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
253 coarse -= IGP01E1000_ANALOG_FUSE_COARSE_10;
254 fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
255 } else if(coarse == IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
256 fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
258 fused = (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
259 (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
260 (coarse & IGP01E1000_ANALOG_FUSE_COARSE_MASK);
262 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_CONTROL, fused);
263 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_BYPASS,
264 IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
270 /******************************************************************************
271 * Set the mac type member in the hw struct.
273 * hw - Struct containing variables accessed by shared code
274 *****************************************************************************/
276 e1000_set_mac_type(struct e1000_hw *hw)
278 DEBUGFUNC("e1000_set_mac_type");
280 switch (hw->device_id) {
281 case E1000_DEV_ID_82542:
282 switch (hw->revision_id) {
283 case E1000_82542_2_0_REV_ID:
284 hw->mac_type = e1000_82542_rev2_0;
286 case E1000_82542_2_1_REV_ID:
287 hw->mac_type = e1000_82542_rev2_1;
290 /* Invalid 82542 revision ID */
291 return -E1000_ERR_MAC_TYPE;
294 case E1000_DEV_ID_82543GC_FIBER:
295 case E1000_DEV_ID_82543GC_COPPER:
296 hw->mac_type = e1000_82543;
298 case E1000_DEV_ID_82544EI_COPPER:
299 case E1000_DEV_ID_82544EI_FIBER:
300 case E1000_DEV_ID_82544GC_COPPER:
301 case E1000_DEV_ID_82544GC_LOM:
302 hw->mac_type = e1000_82544;
304 case E1000_DEV_ID_82540EM:
305 case E1000_DEV_ID_82540EM_LOM:
306 case E1000_DEV_ID_82540EP:
307 case E1000_DEV_ID_82540EP_LOM:
308 case E1000_DEV_ID_82540EP_LP:
309 hw->mac_type = e1000_82540;
311 case E1000_DEV_ID_82545EM_COPPER:
312 case E1000_DEV_ID_82545EM_FIBER:
313 hw->mac_type = e1000_82545;
315 case E1000_DEV_ID_82545GM_COPPER:
316 case E1000_DEV_ID_82545GM_FIBER:
317 case E1000_DEV_ID_82545GM_SERDES:
318 hw->mac_type = e1000_82545_rev_3;
320 case E1000_DEV_ID_82546EB_COPPER:
321 case E1000_DEV_ID_82546EB_FIBER:
322 case E1000_DEV_ID_82546EB_QUAD_COPPER:
323 hw->mac_type = e1000_82546;
325 case E1000_DEV_ID_82546GB_COPPER:
326 case E1000_DEV_ID_82546GB_FIBER:
327 case E1000_DEV_ID_82546GB_SERDES:
328 case E1000_DEV_ID_82546GB_PCIE:
329 case E1000_DEV_ID_82546GB_QUAD_COPPER:
330 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
331 hw->mac_type = e1000_82546_rev_3;
333 case E1000_DEV_ID_82541EI:
334 case E1000_DEV_ID_82541EI_MOBILE:
335 hw->mac_type = e1000_82541;
337 case E1000_DEV_ID_82541ER:
338 case E1000_DEV_ID_82541GI:
339 case E1000_DEV_ID_82541GI_LF:
340 case E1000_DEV_ID_82541GI_MOBILE:
341 hw->mac_type = e1000_82541_rev_2;
343 case E1000_DEV_ID_82547EI:
344 hw->mac_type = e1000_82547;
346 case E1000_DEV_ID_82547GI:
347 hw->mac_type = e1000_82547_rev_2;
349 case E1000_DEV_ID_82571EB_COPPER:
350 case E1000_DEV_ID_82571EB_FIBER:
351 case E1000_DEV_ID_82571EB_SERDES:
352 hw->mac_type = e1000_82571;
354 case E1000_DEV_ID_82572EI_COPPER:
355 case E1000_DEV_ID_82572EI_FIBER:
356 case E1000_DEV_ID_82572EI_SERDES:
357 hw->mac_type = e1000_82572;
359 case E1000_DEV_ID_82573E:
360 case E1000_DEV_ID_82573E_IAMT:
361 case E1000_DEV_ID_82573L:
362 hw->mac_type = e1000_82573;
364 case E1000_DEV_ID_80003ES2LAN_COPPER_DPT:
365 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
366 hw->mac_type = e1000_80003es2lan;
369 /* Should never have loaded on this device */
370 return -E1000_ERR_MAC_TYPE;
373 switch(hw->mac_type) {
374 case e1000_80003es2lan:
375 hw->swfw_sync_present = TRUE;
380 hw->eeprom_semaphore_present = TRUE;
384 case e1000_82541_rev_2:
385 case e1000_82547_rev_2:
386 hw->asf_firmware_present = TRUE;
392 return E1000_SUCCESS;
395 /*****************************************************************************
396 * Set media type and TBI compatibility.
398 * hw - Struct containing variables accessed by shared code
399 * **************************************************************************/
401 e1000_set_media_type(struct e1000_hw *hw)
405 DEBUGFUNC("e1000_set_media_type");
407 if(hw->mac_type != e1000_82543) {
408 /* tbi_compatibility is only valid on 82543 */
409 hw->tbi_compatibility_en = FALSE;
412 switch (hw->device_id) {
413 case E1000_DEV_ID_82545GM_SERDES:
414 case E1000_DEV_ID_82546GB_SERDES:
415 case E1000_DEV_ID_82571EB_SERDES:
416 case E1000_DEV_ID_82572EI_SERDES:
417 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
418 hw->media_type = e1000_media_type_internal_serdes;
421 switch (hw->mac_type) {
422 case e1000_82542_rev2_0:
423 case e1000_82542_rev2_1:
424 hw->media_type = e1000_media_type_fiber;
427 /* The STATUS_TBIMODE bit is reserved or reused for the this
430 hw->media_type = e1000_media_type_copper;
433 status = E1000_READ_REG(hw, STATUS);
434 if (status & E1000_STATUS_TBIMODE) {
435 hw->media_type = e1000_media_type_fiber;
436 /* tbi_compatibility not valid on fiber */
437 hw->tbi_compatibility_en = FALSE;
439 hw->media_type = e1000_media_type_copper;
446 /******************************************************************************
447 * Reset the transmit and receive units; mask and clear all interrupts.
449 * hw - Struct containing variables accessed by shared code
450 *****************************************************************************/
452 e1000_reset_hw(struct e1000_hw *hw)
460 uint32_t extcnf_ctrl;
463 DEBUGFUNC("e1000_reset_hw");
465 /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
466 if(hw->mac_type == e1000_82542_rev2_0) {
467 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
468 e1000_pci_clear_mwi(hw);
471 if(hw->bus_type == e1000_bus_type_pci_express) {
472 /* Prevent the PCI-E bus from sticking if there is no TLP connection
473 * on the last TLP read/write transaction when MAC is reset.
475 if(e1000_disable_pciex_master(hw) != E1000_SUCCESS) {
476 DEBUGOUT("PCI-E Master disable polling has failed.\n");
480 /* Clear interrupt mask to stop board from generating interrupts */
481 DEBUGOUT("Masking off all interrupts\n");
482 E1000_WRITE_REG(hw, IMC, 0xffffffff);
484 /* Disable the Transmit and Receive units. Then delay to allow
485 * any pending transactions to complete before we hit the MAC with
488 E1000_WRITE_REG(hw, RCTL, 0);
489 E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP);
490 E1000_WRITE_FLUSH(hw);
492 /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
493 hw->tbi_compatibility_on = FALSE;
495 /* Delay to allow any outstanding PCI transactions to complete before
496 * resetting the device
500 ctrl = E1000_READ_REG(hw, CTRL);
502 /* Must reset the PHY before resetting the MAC */
503 if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
504 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_PHY_RST));
508 /* Must acquire the MDIO ownership before MAC reset.
509 * Ownership defaults to firmware after a reset. */
510 if(hw->mac_type == e1000_82573) {
513 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
514 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
517 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
518 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
520 if(extcnf_ctrl & E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP)
523 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
530 /* Issue a global reset to the MAC. This will reset the chip's
531 * transmit, receive, DMA, and link units. It will not effect
532 * the current PCI configuration. The global reset bit is self-
533 * clearing, and should clear within a microsecond.
535 DEBUGOUT("Issuing a global reset to MAC\n");
537 switch(hw->mac_type) {
543 case e1000_82541_rev_2:
544 /* These controllers can't ack the 64-bit write when issuing the
545 * reset, so use IO-mapping as a workaround to issue the reset */
546 E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
548 case e1000_82545_rev_3:
549 case e1000_82546_rev_3:
550 /* Reset is performed on a shadow of the control register */
551 E1000_WRITE_REG(hw, CTRL_DUP, (ctrl | E1000_CTRL_RST));
554 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
558 /* After MAC reset, force reload of EEPROM to restore power-on settings to
559 * device. Later controllers reload the EEPROM automatically, so just wait
560 * for reload to complete.
562 switch(hw->mac_type) {
563 case e1000_82542_rev2_0:
564 case e1000_82542_rev2_1:
567 /* Wait for reset to complete */
569 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
570 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
571 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
572 E1000_WRITE_FLUSH(hw);
573 /* Wait for EEPROM reload */
577 case e1000_82541_rev_2:
579 case e1000_82547_rev_2:
580 /* Wait for EEPROM reload */
584 if (e1000_is_onboard_nvm_eeprom(hw) == FALSE) {
586 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
587 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
588 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
589 E1000_WRITE_FLUSH(hw);
594 case e1000_80003es2lan:
595 ret_val = e1000_get_auto_rd_done(hw);
597 /* We don't want to continue accessing MAC registers. */
601 /* Wait for EEPROM reload (it happens automatically) */
606 /* Disable HW ARPs on ASF enabled adapters */
607 if(hw->mac_type >= e1000_82540 && hw->mac_type <= e1000_82547_rev_2) {
608 manc = E1000_READ_REG(hw, MANC);
609 manc &= ~(E1000_MANC_ARP_EN);
610 E1000_WRITE_REG(hw, MANC, manc);
613 if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
614 e1000_phy_init_script(hw);
616 /* Configure activity LED after PHY reset */
617 led_ctrl = E1000_READ_REG(hw, LEDCTL);
618 led_ctrl &= IGP_ACTIVITY_LED_MASK;
619 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
620 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
623 /* Clear interrupt mask to stop board from generating interrupts */
624 DEBUGOUT("Masking off all interrupts\n");
625 E1000_WRITE_REG(hw, IMC, 0xffffffff);
627 /* Clear any pending interrupt events. */
628 icr = E1000_READ_REG(hw, ICR);
630 /* If MWI was previously enabled, reenable it. */
631 if(hw->mac_type == e1000_82542_rev2_0) {
632 if(hw->pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
633 e1000_pci_set_mwi(hw);
636 return E1000_SUCCESS;
639 /******************************************************************************
640 * Performs basic configuration of the adapter.
642 * hw - Struct containing variables accessed by shared code
644 * Assumes that the controller has previously been reset and is in a
645 * post-reset uninitialized state. Initializes the receive address registers,
646 * multicast table, and VLAN filter table. Calls routines to setup link
647 * configuration and flow control settings. Clears all on-chip counters. Leaves
648 * the transmit and receive units disabled and uninitialized.
649 *****************************************************************************/
651 e1000_init_hw(struct e1000_hw *hw)
656 uint16_t pcix_cmd_word;
657 uint16_t pcix_stat_hi_word;
664 DEBUGFUNC("e1000_init_hw");
666 /* Initialize Identification LED */
667 ret_val = e1000_id_led_init(hw);
669 DEBUGOUT("Error Initializing Identification LED\n");
673 /* Set the media type and TBI compatibility */
674 e1000_set_media_type(hw);
676 /* Disabling VLAN filtering. */
677 DEBUGOUT("Initializing the IEEE VLAN\n");
678 if (hw->mac_type < e1000_82545_rev_3)
679 E1000_WRITE_REG(hw, VET, 0);
680 e1000_clear_vfta(hw);
682 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
683 if(hw->mac_type == e1000_82542_rev2_0) {
684 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
685 e1000_pci_clear_mwi(hw);
686 E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST);
687 E1000_WRITE_FLUSH(hw);
691 /* Setup the receive address. This involves initializing all of the Receive
692 * Address Registers (RARs 0 - 15).
694 e1000_init_rx_addrs(hw);
696 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
697 if(hw->mac_type == e1000_82542_rev2_0) {
698 E1000_WRITE_REG(hw, RCTL, 0);
699 E1000_WRITE_FLUSH(hw);
701 if(hw->pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
702 e1000_pci_set_mwi(hw);
705 /* Zero out the Multicast HASH table */
706 DEBUGOUT("Zeroing the MTA\n");
707 mta_size = E1000_MC_TBL_SIZE;
708 for(i = 0; i < mta_size; i++)
709 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
711 /* Set the PCI priority bit correctly in the CTRL register. This
712 * determines if the adapter gives priority to receives, or if it
713 * gives equal priority to transmits and receives. Valid only on
714 * 82542 and 82543 silicon.
716 if(hw->dma_fairness && hw->mac_type <= e1000_82543) {
717 ctrl = E1000_READ_REG(hw, CTRL);
718 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PRIOR);
721 switch(hw->mac_type) {
722 case e1000_82545_rev_3:
723 case e1000_82546_rev_3:
726 /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
727 if(hw->bus_type == e1000_bus_type_pcix) {
728 e1000_read_pci_cfg(hw, PCIX_COMMAND_REGISTER, &pcix_cmd_word);
729 e1000_read_pci_cfg(hw, PCIX_STATUS_REGISTER_HI,
731 cmd_mmrbc = (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >>
732 PCIX_COMMAND_MMRBC_SHIFT;
733 stat_mmrbc = (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
734 PCIX_STATUS_HI_MMRBC_SHIFT;
735 if(stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
736 stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
737 if(cmd_mmrbc > stat_mmrbc) {
738 pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK;
739 pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
740 e1000_write_pci_cfg(hw, PCIX_COMMAND_REGISTER,
747 /* Call a subroutine to configure the link and setup flow control. */
748 ret_val = e1000_setup_link(hw);
750 /* Set the transmit descriptor write-back policy */
751 if(hw->mac_type > e1000_82544) {
752 ctrl = E1000_READ_REG(hw, TXDCTL);
753 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
754 switch (hw->mac_type) {
760 case e1000_80003es2lan:
761 ctrl |= E1000_TXDCTL_COUNT_DESC;
764 E1000_WRITE_REG(hw, TXDCTL, ctrl);
767 if (hw->mac_type == e1000_82573) {
768 e1000_enable_tx_pkt_filtering(hw);
771 switch (hw->mac_type) {
774 case e1000_80003es2lan:
775 /* Enable retransmit on late collisions */
776 reg_data = E1000_READ_REG(hw, TCTL);
777 reg_data |= E1000_TCTL_RTLC;
778 E1000_WRITE_REG(hw, TCTL, reg_data);
780 /* Configure Gigabit Carry Extend Padding */
781 reg_data = E1000_READ_REG(hw, TCTL_EXT);
782 reg_data &= ~E1000_TCTL_EXT_GCEX_MASK;
783 reg_data |= DEFAULT_80003ES2LAN_TCTL_EXT_GCEX;
784 E1000_WRITE_REG(hw, TCTL_EXT, reg_data);
786 /* Configure Transmit Inter-Packet Gap */
787 reg_data = E1000_READ_REG(hw, TIPG);
788 reg_data &= ~E1000_TIPG_IPGT_MASK;
789 reg_data |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
790 E1000_WRITE_REG(hw, TIPG, reg_data);
792 reg_data = E1000_READ_REG_ARRAY(hw, FFLT, 0x0001);
793 reg_data &= ~0x00100000;
794 E1000_WRITE_REG_ARRAY(hw, FFLT, 0x0001, reg_data);
798 ctrl = E1000_READ_REG(hw, TXDCTL1);
799 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
800 if(hw->mac_type >= e1000_82571)
801 ctrl |= E1000_TXDCTL_COUNT_DESC;
802 E1000_WRITE_REG(hw, TXDCTL1, ctrl);
808 if (hw->mac_type == e1000_82573) {
809 uint32_t gcr = E1000_READ_REG(hw, GCR);
810 gcr |= E1000_GCR_L1_ACT_WITHOUT_L0S_RX;
811 E1000_WRITE_REG(hw, GCR, gcr);
814 /* Clear all of the statistics registers (clear on read). It is
815 * important that we do this after we have tried to establish link
816 * because the symbol error count will increment wildly if there
819 e1000_clear_hw_cntrs(hw);
821 if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER ||
822 hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) {
823 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
824 /* Relaxed ordering must be disabled to avoid a parity
825 * error crash in a PCI slot. */
826 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
827 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
833 /******************************************************************************
834 * Adjust SERDES output amplitude based on EEPROM setting.
836 * hw - Struct containing variables accessed by shared code.
837 *****************************************************************************/
839 e1000_adjust_serdes_amplitude(struct e1000_hw *hw)
841 uint16_t eeprom_data;
844 DEBUGFUNC("e1000_adjust_serdes_amplitude");
846 if(hw->media_type != e1000_media_type_internal_serdes)
847 return E1000_SUCCESS;
849 switch(hw->mac_type) {
850 case e1000_82545_rev_3:
851 case e1000_82546_rev_3:
854 return E1000_SUCCESS;
857 ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1, &eeprom_data);
862 if(eeprom_data != EEPROM_RESERVED_WORD) {
863 /* Adjust SERDES output amplitude only. */
864 eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK;
865 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data);
870 return E1000_SUCCESS;
873 /******************************************************************************
874 * Configures flow control and link settings.
876 * hw - Struct containing variables accessed by shared code
878 * Determines which flow control settings to use. Calls the apropriate media-
879 * specific link configuration function. Configures the flow control settings.
880 * Assuming the adapter has a valid link partner, a valid link should be
881 * established. Assumes the hardware has previously been reset and the
882 * transmitter and receiver are not enabled.
883 *****************************************************************************/
885 e1000_setup_link(struct e1000_hw *hw)
889 uint16_t eeprom_data;
891 DEBUGFUNC("e1000_setup_link");
893 /* In the case of the phy reset being blocked, we already have a link.
894 * We do not have to set it up again. */
895 if (e1000_check_phy_reset_block(hw))
896 return E1000_SUCCESS;
898 /* Read and store word 0x0F of the EEPROM. This word contains bits
899 * that determine the hardware's default PAUSE (flow control) mode,
900 * a bit that determines whether the HW defaults to enabling or
901 * disabling auto-negotiation, and the direction of the
902 * SW defined pins. If there is no SW over-ride of the flow
903 * control setting, then the variable hw->fc will
904 * be initialized based on a value in the EEPROM.
906 if (hw->fc == e1000_fc_default) {
907 switch (hw->mac_type) {
909 hw->fc = e1000_fc_full;
912 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
915 DEBUGOUT("EEPROM Read Error\n");
916 return -E1000_ERR_EEPROM;
918 if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
919 hw->fc = e1000_fc_none;
920 else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
921 EEPROM_WORD0F_ASM_DIR)
922 hw->fc = e1000_fc_tx_pause;
924 hw->fc = e1000_fc_full;
929 /* We want to save off the original Flow Control configuration just
930 * in case we get disconnected and then reconnected into a different
931 * hub or switch with different Flow Control capabilities.
933 if(hw->mac_type == e1000_82542_rev2_0)
934 hw->fc &= (~e1000_fc_tx_pause);
936 if((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
937 hw->fc &= (~e1000_fc_rx_pause);
939 hw->original_fc = hw->fc;
941 DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc);
943 /* Take the 4 bits from EEPROM word 0x0F that determine the initial
944 * polarity value for the SW controlled pins, and setup the
945 * Extended Device Control reg with that info.
946 * This is needed because one of the SW controlled pins is used for
947 * signal detection. So this should be done before e1000_setup_pcs_link()
948 * or e1000_phy_setup() is called.
950 if (hw->mac_type == e1000_82543) {
951 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
954 DEBUGOUT("EEPROM Read Error\n");
955 return -E1000_ERR_EEPROM;
957 ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
959 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
962 /* Call the necessary subroutine to configure the link. */
963 ret_val = (hw->media_type == e1000_media_type_copper) ?
964 e1000_setup_copper_link(hw) :
965 e1000_setup_fiber_serdes_link(hw);
967 /* Initialize the flow control address, type, and PAUSE timer
968 * registers to their default values. This is done even if flow
969 * control is disabled, because it does not hurt anything to
970 * initialize these registers.
972 DEBUGOUT("Initializing the Flow Control address, type and timer regs\n");
974 E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
975 E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
976 E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
978 E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
980 /* Set the flow control receive threshold registers. Normally,
981 * these registers will be set to a default threshold that may be
982 * adjusted later by the driver's runtime code. However, if the
983 * ability to transmit pause frames in not enabled, then these
984 * registers will be set to 0.
986 if(!(hw->fc & e1000_fc_tx_pause)) {
987 E1000_WRITE_REG(hw, FCRTL, 0);
988 E1000_WRITE_REG(hw, FCRTH, 0);
990 /* We need to set up the Receive Threshold high and low water marks
991 * as well as (optionally) enabling the transmission of XON frames.
993 if(hw->fc_send_xon) {
994 E1000_WRITE_REG(hw, FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE));
995 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
997 E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water);
998 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
1004 /******************************************************************************
1005 * Sets up link for a fiber based or serdes based adapter
1007 * hw - Struct containing variables accessed by shared code
1009 * Manipulates Physical Coding Sublayer functions in order to configure
1010 * link. Assumes the hardware has been previously reset and the transmitter
1011 * and receiver are not enabled.
1012 *****************************************************************************/
1014 e1000_setup_fiber_serdes_link(struct e1000_hw *hw)
1020 uint32_t signal = 0;
1023 DEBUGFUNC("e1000_setup_fiber_serdes_link");
1025 /* On 82571 and 82572 Fiber connections, SerDes loopback mode persists
1026 * until explicitly turned off or a power cycle is performed. A read to
1027 * the register does not indicate its status. Therefore, we ensure
1028 * loopback mode is disabled during initialization.
1030 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572)
1031 E1000_WRITE_REG(hw, SCTL, E1000_DISABLE_SERDES_LOOPBACK);
1033 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
1034 * set when the optics detect a signal. On older adapters, it will be
1035 * cleared when there is a signal. This applies to fiber media only.
1036 * If we're on serdes media, adjust the output amplitude to value set in
1039 ctrl = E1000_READ_REG(hw, CTRL);
1040 if(hw->media_type == e1000_media_type_fiber)
1041 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
1043 ret_val = e1000_adjust_serdes_amplitude(hw);
1047 /* Take the link out of reset */
1048 ctrl &= ~(E1000_CTRL_LRST);
1050 /* Adjust VCO speed to improve BER performance */
1051 ret_val = e1000_set_vco_speed(hw);
1055 e1000_config_collision_dist(hw);
1057 /* Check for a software override of the flow control settings, and setup
1058 * the device accordingly. If auto-negotiation is enabled, then software
1059 * will have to set the "PAUSE" bits to the correct value in the Tranmsit
1060 * Config Word Register (TXCW) and re-start auto-negotiation. However, if
1061 * auto-negotiation is disabled, then software will have to manually
1062 * configure the two flow control enable bits in the CTRL register.
1064 * The possible values of the "fc" parameter are:
1065 * 0: Flow control is completely disabled
1066 * 1: Rx flow control is enabled (we can receive pause frames, but
1067 * not send pause frames).
1068 * 2: Tx flow control is enabled (we can send pause frames but we do
1069 * not support receiving pause frames).
1070 * 3: Both Rx and TX flow control (symmetric) are enabled.
1074 /* Flow control is completely disabled by a software over-ride. */
1075 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
1077 case e1000_fc_rx_pause:
1078 /* RX Flow control is enabled and TX Flow control is disabled by a
1079 * software over-ride. Since there really isn't a way to advertise
1080 * that we are capable of RX Pause ONLY, we will advertise that we
1081 * support both symmetric and asymmetric RX PAUSE. Later, we will
1082 * disable the adapter's ability to send PAUSE frames.
1084 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1086 case e1000_fc_tx_pause:
1087 /* TX Flow control is enabled, and RX Flow control is disabled, by a
1088 * software over-ride.
1090 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
1093 /* Flow control (both RX and TX) is enabled by a software over-ride. */
1094 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1097 DEBUGOUT("Flow control param set incorrectly\n");
1098 return -E1000_ERR_CONFIG;
1102 /* Since auto-negotiation is enabled, take the link out of reset (the link
1103 * will be in reset, because we previously reset the chip). This will
1104 * restart auto-negotiation. If auto-neogtiation is successful then the
1105 * link-up status bit will be set and the flow control enable bits (RFCE
1106 * and TFCE) will be set according to their negotiated value.
1108 DEBUGOUT("Auto-negotiation enabled\n");
1110 E1000_WRITE_REG(hw, TXCW, txcw);
1111 E1000_WRITE_REG(hw, CTRL, ctrl);
1112 E1000_WRITE_FLUSH(hw);
1117 /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
1118 * indication in the Device Status Register. Time-out if a link isn't
1119 * seen in 500 milliseconds seconds (Auto-negotiation should complete in
1120 * less than 500 milliseconds even if the other end is doing it in SW).
1121 * For internal serdes, we just assume a signal is present, then poll.
1123 if(hw->media_type == e1000_media_type_internal_serdes ||
1124 (E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) {
1125 DEBUGOUT("Looking for Link\n");
1126 for(i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
1128 status = E1000_READ_REG(hw, STATUS);
1129 if(status & E1000_STATUS_LU) break;
1131 if(i == (LINK_UP_TIMEOUT / 10)) {
1132 DEBUGOUT("Never got a valid link from auto-neg!!!\n");
1133 hw->autoneg_failed = 1;
1134 /* AutoNeg failed to achieve a link, so we'll call
1135 * e1000_check_for_link. This routine will force the link up if
1136 * we detect a signal. This will allow us to communicate with
1137 * non-autonegotiating link partners.
1139 ret_val = e1000_check_for_link(hw);
1141 DEBUGOUT("Error while checking for link\n");
1144 hw->autoneg_failed = 0;
1146 hw->autoneg_failed = 0;
1147 DEBUGOUT("Valid Link Found\n");
1150 DEBUGOUT("No Signal Detected\n");
1152 return E1000_SUCCESS;
1155 /******************************************************************************
1156 * Make sure we have a valid PHY and change PHY mode before link setup.
1158 * hw - Struct containing variables accessed by shared code
1159 ******************************************************************************/
1161 e1000_copper_link_preconfig(struct e1000_hw *hw)
1167 DEBUGFUNC("e1000_copper_link_preconfig");
1169 ctrl = E1000_READ_REG(hw, CTRL);
1170 /* With 82543, we need to force speed and duplex on the MAC equal to what
1171 * the PHY speed and duplex configuration is. In addition, we need to
1172 * perform a hardware reset on the PHY to take it out of reset.
1174 if(hw->mac_type > e1000_82543) {
1175 ctrl |= E1000_CTRL_SLU;
1176 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1177 E1000_WRITE_REG(hw, CTRL, ctrl);
1179 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
1180 E1000_WRITE_REG(hw, CTRL, ctrl);
1181 ret_val = e1000_phy_hw_reset(hw);
1186 /* Make sure we have a valid PHY */
1187 ret_val = e1000_detect_gig_phy(hw);
1189 DEBUGOUT("Error, did not detect valid phy.\n");
1192 DEBUGOUT1("Phy ID = %x \n", hw->phy_id);
1194 /* Set PHY to class A mode (if necessary) */
1195 ret_val = e1000_set_phy_mode(hw);
1199 if((hw->mac_type == e1000_82545_rev_3) ||
1200 (hw->mac_type == e1000_82546_rev_3)) {
1201 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1202 phy_data |= 0x00000008;
1203 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1206 if(hw->mac_type <= e1000_82543 ||
1207 hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
1208 hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2)
1209 hw->phy_reset_disable = FALSE;
1211 return E1000_SUCCESS;
1215 /********************************************************************
1216 * Copper link setup for e1000_phy_igp series.
1218 * hw - Struct containing variables accessed by shared code
1219 *********************************************************************/
1221 e1000_copper_link_igp_setup(struct e1000_hw *hw)
1227 DEBUGFUNC("e1000_copper_link_igp_setup");
1229 if (hw->phy_reset_disable)
1230 return E1000_SUCCESS;
1232 ret_val = e1000_phy_reset(hw);
1234 DEBUGOUT("Error Resetting the PHY\n");
1238 /* Wait 10ms for MAC to configure PHY from eeprom settings */
1241 /* Configure activity LED after PHY reset */
1242 led_ctrl = E1000_READ_REG(hw, LEDCTL);
1243 led_ctrl &= IGP_ACTIVITY_LED_MASK;
1244 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
1245 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
1247 /* disable lplu d3 during driver init */
1248 ret_val = e1000_set_d3_lplu_state(hw, FALSE);
1250 DEBUGOUT("Error Disabling LPLU D3\n");
1254 /* disable lplu d0 during driver init */
1255 ret_val = e1000_set_d0_lplu_state(hw, FALSE);
1257 DEBUGOUT("Error Disabling LPLU D0\n");
1260 /* Configure mdi-mdix settings */
1261 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1265 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
1266 hw->dsp_config_state = e1000_dsp_config_disabled;
1267 /* Force MDI for earlier revs of the IGP PHY */
1268 phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX | IGP01E1000_PSCR_FORCE_MDI_MDIX);
1272 hw->dsp_config_state = e1000_dsp_config_enabled;
1273 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1277 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1280 phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
1284 phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
1288 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1292 /* set auto-master slave resolution settings */
1294 e1000_ms_type phy_ms_setting = hw->master_slave;
1296 if(hw->ffe_config_state == e1000_ffe_config_active)
1297 hw->ffe_config_state = e1000_ffe_config_enabled;
1299 if(hw->dsp_config_state == e1000_dsp_config_activated)
1300 hw->dsp_config_state = e1000_dsp_config_enabled;
1302 /* when autonegotiation advertisment is only 1000Mbps then we
1303 * should disable SmartSpeed and enable Auto MasterSlave
1304 * resolution as hardware default. */
1305 if(hw->autoneg_advertised == ADVERTISE_1000_FULL) {
1306 /* Disable SmartSpeed */
1307 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
1310 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1311 ret_val = e1000_write_phy_reg(hw,
1312 IGP01E1000_PHY_PORT_CONFIG,
1316 /* Set auto Master/Slave resolution process */
1317 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1320 phy_data &= ~CR_1000T_MS_ENABLE;
1321 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1326 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1330 /* load defaults for future use */
1331 hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
1332 ((phy_data & CR_1000T_MS_VALUE) ?
1333 e1000_ms_force_master :
1334 e1000_ms_force_slave) :
1337 switch (phy_ms_setting) {
1338 case e1000_ms_force_master:
1339 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
1341 case e1000_ms_force_slave:
1342 phy_data |= CR_1000T_MS_ENABLE;
1343 phy_data &= ~(CR_1000T_MS_VALUE);
1346 phy_data &= ~CR_1000T_MS_ENABLE;
1350 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1355 return E1000_SUCCESS;
1358 /********************************************************************
1359 * Copper link setup for e1000_phy_gg82563 series.
1361 * hw - Struct containing variables accessed by shared code
1362 *********************************************************************/
1364 e1000_copper_link_ggp_setup(struct e1000_hw *hw)
1370 DEBUGFUNC("e1000_copper_link_ggp_setup");
1372 if(!hw->phy_reset_disable) {
1374 /* Enable CRS on TX for half-duplex operation. */
1375 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL,
1380 phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
1381 /* Use 25MHz for both link down and 1000BASE-T for Tx clock */
1382 phy_data |= GG82563_MSCR_TX_CLK_1000MBPS_25MHZ;
1384 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL,
1390 * MDI/MDI-X = 0 (default)
1391 * 0 - Auto for all speeds
1394 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1396 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_SPEC_CTRL, &phy_data);
1400 phy_data &= ~GG82563_PSCR_CROSSOVER_MODE_MASK;
1404 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDI;
1407 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDIX;
1411 phy_data |= GG82563_PSCR_CROSSOVER_MODE_AUTO;
1416 * disable_polarity_correction = 0 (default)
1417 * Automatic Correction for Reversed Cable Polarity
1421 phy_data &= ~GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
1422 if(hw->disable_polarity_correction == 1)
1423 phy_data |= GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
1424 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_SPEC_CTRL, phy_data);
1429 /* SW Reset the PHY so all changes take effect */
1430 ret_val = e1000_phy_reset(hw);
1432 DEBUGOUT("Error Resetting the PHY\n");
1435 } /* phy_reset_disable */
1437 if (hw->mac_type == e1000_80003es2lan) {
1438 /* Bypass RX and TX FIFO's */
1439 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_FIFO_CTRL,
1440 E1000_KUMCTRLSTA_FIFO_CTRL_RX_BYPASS |
1441 E1000_KUMCTRLSTA_FIFO_CTRL_TX_BYPASS);
1445 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_SPEC_CTRL_2, &phy_data);
1449 phy_data &= ~GG82563_PSCR2_REVERSE_AUTO_NEG;
1450 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_SPEC_CTRL_2, phy_data);
1455 reg_data = E1000_READ_REG(hw, CTRL_EXT);
1456 reg_data &= ~(E1000_CTRL_EXT_LINK_MODE_MASK);
1457 E1000_WRITE_REG(hw, CTRL_EXT, reg_data);
1459 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_PWR_MGMT_CTRL,
1464 /* Do not init these registers when the HW is in IAMT mode, since the
1465 * firmware will have already initialized them. We only initialize
1466 * them if the HW is not in IAMT mode.
1468 if (e1000_check_mng_mode(hw) == FALSE) {
1469 /* Enable Electrical Idle on the PHY */
1470 phy_data |= GG82563_PMCR_ENABLE_ELECTRICAL_IDLE;
1471 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_PWR_MGMT_CTRL,
1476 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
1481 /* Enable Pass False Carrier on the PHY */
1482 phy_data |= GG82563_KMCR_PASS_FALSE_CARRIER;
1484 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
1490 /* Workaround: Disable padding in Kumeran interface in the MAC
1491 * and in the PHY to avoid CRC errors.
1493 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_INBAND_CTRL,
1497 phy_data |= GG82563_ICR_DIS_PADDING;
1498 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_INBAND_CTRL,
1504 return E1000_SUCCESS;
1507 /********************************************************************
1508 * Copper link setup for e1000_phy_m88 series.
1510 * hw - Struct containing variables accessed by shared code
1511 *********************************************************************/
1513 e1000_copper_link_mgp_setup(struct e1000_hw *hw)
1518 DEBUGFUNC("e1000_copper_link_mgp_setup");
1520 if(hw->phy_reset_disable)
1521 return E1000_SUCCESS;
1523 /* Enable CRS on TX. This must be set for half-duplex operation. */
1524 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1528 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1531 * MDI/MDI-X = 0 (default)
1532 * 0 - Auto for all speeds
1535 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1537 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1541 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
1544 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
1547 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
1551 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
1556 * disable_polarity_correction = 0 (default)
1557 * Automatic Correction for Reversed Cable Polarity
1561 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
1562 if(hw->disable_polarity_correction == 1)
1563 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
1564 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1568 /* Force TX_CLK in the Extended PHY Specific Control Register
1571 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1575 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1577 if (hw->phy_revision < M88E1011_I_REV_4) {
1578 /* Configure Master and Slave downshift values */
1579 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
1580 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
1581 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
1582 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
1583 ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1588 /* SW Reset the PHY so all changes take effect */
1589 ret_val = e1000_phy_reset(hw);
1591 DEBUGOUT("Error Resetting the PHY\n");
1595 return E1000_SUCCESS;
1598 /********************************************************************
1599 * Setup auto-negotiation and flow control advertisements,
1600 * and then perform auto-negotiation.
1602 * hw - Struct containing variables accessed by shared code
1603 *********************************************************************/
1605 e1000_copper_link_autoneg(struct e1000_hw *hw)
1610 DEBUGFUNC("e1000_copper_link_autoneg");
1612 /* Perform some bounds checking on the hw->autoneg_advertised
1613 * parameter. If this variable is zero, then set it to the default.
1615 hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
1617 /* If autoneg_advertised is zero, we assume it was not defaulted
1618 * by the calling code so we set to advertise full capability.
1620 if(hw->autoneg_advertised == 0)
1621 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
1623 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
1624 ret_val = e1000_phy_setup_autoneg(hw);
1626 DEBUGOUT("Error Setting up Auto-Negotiation\n");
1629 DEBUGOUT("Restarting Auto-Neg\n");
1631 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
1632 * the Auto Neg Restart bit in the PHY control register.
1634 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
1638 phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
1639 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
1643 /* Does the user want to wait for Auto-Neg to complete here, or
1644 * check at a later time (for example, callback routine).
1646 if(hw->wait_autoneg_complete) {
1647 ret_val = e1000_wait_autoneg(hw);
1649 DEBUGOUT("Error while waiting for autoneg to complete\n");
1654 hw->get_link_status = TRUE;
1656 return E1000_SUCCESS;
1660 /******************************************************************************
1661 * Config the MAC and the PHY after link is up.
1662 * 1) Set up the MAC to the current PHY speed/duplex
1663 * if we are on 82543. If we
1664 * are on newer silicon, we only need to configure
1665 * collision distance in the Transmit Control Register.
1666 * 2) Set up flow control on the MAC to that established with
1668 * 3) Config DSP to improve Gigabit link quality for some PHY revisions.
1670 * hw - Struct containing variables accessed by shared code
1671 ******************************************************************************/
1673 e1000_copper_link_postconfig(struct e1000_hw *hw)
1676 DEBUGFUNC("e1000_copper_link_postconfig");
1678 if(hw->mac_type >= e1000_82544) {
1679 e1000_config_collision_dist(hw);
1681 ret_val = e1000_config_mac_to_phy(hw);
1683 DEBUGOUT("Error configuring MAC to PHY settings\n");
1687 ret_val = e1000_config_fc_after_link_up(hw);
1689 DEBUGOUT("Error Configuring Flow Control\n");
1693 /* Config DSP to improve Giga link quality */
1694 if(hw->phy_type == e1000_phy_igp) {
1695 ret_val = e1000_config_dsp_after_link_change(hw, TRUE);
1697 DEBUGOUT("Error Configuring DSP after link up\n");
1702 return E1000_SUCCESS;
1705 /******************************************************************************
1706 * Detects which PHY is present and setup the speed and duplex
1708 * hw - Struct containing variables accessed by shared code
1709 ******************************************************************************/
1711 e1000_setup_copper_link(struct e1000_hw *hw)
1718 DEBUGFUNC("e1000_setup_copper_link");
1720 /* Check if it is a valid PHY and set PHY mode if necessary. */
1721 ret_val = e1000_copper_link_preconfig(hw);
1725 switch (hw->mac_type) {
1726 case e1000_80003es2lan:
1727 ret_val = e1000_read_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_INB_CTRL,
1731 reg_data |= E1000_KUMCTRLSTA_INB_CTRL_DIS_PADDING;
1732 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_INB_CTRL,
1741 if (hw->phy_type == e1000_phy_igp ||
1742 hw->phy_type == e1000_phy_igp_2) {
1743 ret_val = e1000_copper_link_igp_setup(hw);
1746 } else if (hw->phy_type == e1000_phy_m88) {
1747 ret_val = e1000_copper_link_mgp_setup(hw);
1750 } else if (hw->phy_type == e1000_phy_gg82563) {
1751 ret_val = e1000_copper_link_ggp_setup(hw);
1757 /* Setup autoneg and flow control advertisement
1758 * and perform autonegotiation */
1759 ret_val = e1000_copper_link_autoneg(hw);
1763 /* PHY will be set to 10H, 10F, 100H,or 100F
1764 * depending on value from forced_speed_duplex. */
1765 DEBUGOUT("Forcing speed and duplex\n");
1766 ret_val = e1000_phy_force_speed_duplex(hw);
1768 DEBUGOUT("Error Forcing Speed and Duplex\n");
1773 /* Check link status. Wait up to 100 microseconds for link to become
1776 for(i = 0; i < 10; i++) {
1777 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
1780 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
1784 if(phy_data & MII_SR_LINK_STATUS) {
1785 /* Config the MAC and PHY after link is up */
1786 ret_val = e1000_copper_link_postconfig(hw);
1790 DEBUGOUT("Valid link established!!!\n");
1791 return E1000_SUCCESS;
1796 DEBUGOUT("Unable to establish link!!!\n");
1797 return E1000_SUCCESS;
1800 /******************************************************************************
1801 * Configure the MAC-to-PHY interface for 10/100Mbps
1803 * hw - Struct containing variables accessed by shared code
1804 ******************************************************************************/
1806 e1000_configure_kmrn_for_10_100(struct e1000_hw *hw)
1808 int32_t ret_val = E1000_SUCCESS;
1812 DEBUGFUNC("e1000_configure_kmrn_for_10_100");
1814 reg_data = E1000_KUMCTRLSTA_HD_CTRL_10_100_DEFAULT;
1815 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_HD_CTRL,
1820 /* Configure Transmit Inter-Packet Gap */
1821 tipg = E1000_READ_REG(hw, TIPG);
1822 tipg &= ~E1000_TIPG_IPGT_MASK;
1823 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_10_100;
1824 E1000_WRITE_REG(hw, TIPG, tipg);
1830 e1000_configure_kmrn_for_1000(struct e1000_hw *hw)
1832 int32_t ret_val = E1000_SUCCESS;
1836 DEBUGFUNC("e1000_configure_kmrn_for_1000");
1838 reg_data = E1000_KUMCTRLSTA_HD_CTRL_1000_DEFAULT;
1839 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_HD_CTRL,
1844 /* Configure Transmit Inter-Packet Gap */
1845 tipg = E1000_READ_REG(hw, TIPG);
1846 tipg &= ~E1000_TIPG_IPGT_MASK;
1847 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
1848 E1000_WRITE_REG(hw, TIPG, tipg);
1853 /******************************************************************************
1854 * Configures PHY autoneg and flow control advertisement settings
1856 * hw - Struct containing variables accessed by shared code
1857 ******************************************************************************/
1859 e1000_phy_setup_autoneg(struct e1000_hw *hw)
1862 uint16_t mii_autoneg_adv_reg;
1863 uint16_t mii_1000t_ctrl_reg;
1865 DEBUGFUNC("e1000_phy_setup_autoneg");
1867 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
1868 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
1872 /* Read the MII 1000Base-T Control Register (Address 9). */
1873 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
1877 /* Need to parse both autoneg_advertised and fc and set up
1878 * the appropriate PHY registers. First we will parse for
1879 * autoneg_advertised software override. Since we can advertise
1880 * a plethora of combinations, we need to check each bit
1884 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
1885 * Advertisement Register (Address 4) and the 1000 mb speed bits in
1886 * the 1000Base-T Control Register (Address 9).
1888 mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
1889 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
1891 DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised);
1893 /* Do we want to advertise 10 Mb Half Duplex? */
1894 if(hw->autoneg_advertised & ADVERTISE_10_HALF) {
1895 DEBUGOUT("Advertise 10mb Half duplex\n");
1896 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
1899 /* Do we want to advertise 10 Mb Full Duplex? */
1900 if(hw->autoneg_advertised & ADVERTISE_10_FULL) {
1901 DEBUGOUT("Advertise 10mb Full duplex\n");
1902 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
1905 /* Do we want to advertise 100 Mb Half Duplex? */
1906 if(hw->autoneg_advertised & ADVERTISE_100_HALF) {
1907 DEBUGOUT("Advertise 100mb Half duplex\n");
1908 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
1911 /* Do we want to advertise 100 Mb Full Duplex? */
1912 if(hw->autoneg_advertised & ADVERTISE_100_FULL) {
1913 DEBUGOUT("Advertise 100mb Full duplex\n");
1914 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
1917 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
1918 if(hw->autoneg_advertised & ADVERTISE_1000_HALF) {
1919 DEBUGOUT("Advertise 1000mb Half duplex requested, request denied!\n");
1922 /* Do we want to advertise 1000 Mb Full Duplex? */
1923 if(hw->autoneg_advertised & ADVERTISE_1000_FULL) {
1924 DEBUGOUT("Advertise 1000mb Full duplex\n");
1925 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
1928 /* Check for a software override of the flow control settings, and
1929 * setup the PHY advertisement registers accordingly. If
1930 * auto-negotiation is enabled, then software will have to set the
1931 * "PAUSE" bits to the correct value in the Auto-Negotiation
1932 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
1934 * The possible values of the "fc" parameter are:
1935 * 0: Flow control is completely disabled
1936 * 1: Rx flow control is enabled (we can receive pause frames
1937 * but not send pause frames).
1938 * 2: Tx flow control is enabled (we can send pause frames
1939 * but we do not support receiving pause frames).
1940 * 3: Both Rx and TX flow control (symmetric) are enabled.
1941 * other: No software override. The flow control configuration
1942 * in the EEPROM is used.
1945 case e1000_fc_none: /* 0 */
1946 /* Flow control (RX & TX) is completely disabled by a
1947 * software over-ride.
1949 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1951 case e1000_fc_rx_pause: /* 1 */
1952 /* RX Flow control is enabled, and TX Flow control is
1953 * disabled, by a software over-ride.
1955 /* Since there really isn't a way to advertise that we are
1956 * capable of RX Pause ONLY, we will advertise that we
1957 * support both symmetric and asymmetric RX PAUSE. Later
1958 * (in e1000_config_fc_after_link_up) we will disable the
1959 *hw's ability to send PAUSE frames.
1961 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1963 case e1000_fc_tx_pause: /* 2 */
1964 /* TX Flow control is enabled, and RX Flow control is
1965 * disabled, by a software over-ride.
1967 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
1968 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
1970 case e1000_fc_full: /* 3 */
1971 /* Flow control (both RX and TX) is enabled by a software
1974 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1977 DEBUGOUT("Flow control param set incorrectly\n");
1978 return -E1000_ERR_CONFIG;
1981 ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
1985 DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
1987 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg);
1991 return E1000_SUCCESS;
1994 /******************************************************************************
1995 * Force PHY speed and duplex settings to hw->forced_speed_duplex
1997 * hw - Struct containing variables accessed by shared code
1998 ******************************************************************************/
2000 e1000_phy_force_speed_duplex(struct e1000_hw *hw)
2004 uint16_t mii_ctrl_reg;
2005 uint16_t mii_status_reg;
2009 DEBUGFUNC("e1000_phy_force_speed_duplex");
2011 /* Turn off Flow control if we are forcing speed and duplex. */
2012 hw->fc = e1000_fc_none;
2014 DEBUGOUT1("hw->fc = %d\n", hw->fc);
2016 /* Read the Device Control Register. */
2017 ctrl = E1000_READ_REG(hw, CTRL);
2019 /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */
2020 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2021 ctrl &= ~(DEVICE_SPEED_MASK);
2023 /* Clear the Auto Speed Detect Enable bit. */
2024 ctrl &= ~E1000_CTRL_ASDE;
2026 /* Read the MII Control Register. */
2027 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg);
2031 /* We need to disable autoneg in order to force link and duplex. */
2033 mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN;
2035 /* Are we forcing Full or Half Duplex? */
2036 if(hw->forced_speed_duplex == e1000_100_full ||
2037 hw->forced_speed_duplex == e1000_10_full) {
2038 /* We want to force full duplex so we SET the full duplex bits in the
2039 * Device and MII Control Registers.
2041 ctrl |= E1000_CTRL_FD;
2042 mii_ctrl_reg |= MII_CR_FULL_DUPLEX;
2043 DEBUGOUT("Full Duplex\n");
2045 /* We want to force half duplex so we CLEAR the full duplex bits in
2046 * the Device and MII Control Registers.
2048 ctrl &= ~E1000_CTRL_FD;
2049 mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX;
2050 DEBUGOUT("Half Duplex\n");
2053 /* Are we forcing 100Mbps??? */
2054 if(hw->forced_speed_duplex == e1000_100_full ||
2055 hw->forced_speed_duplex == e1000_100_half) {
2056 /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */
2057 ctrl |= E1000_CTRL_SPD_100;
2058 mii_ctrl_reg |= MII_CR_SPEED_100;
2059 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
2060 DEBUGOUT("Forcing 100mb ");
2062 /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */
2063 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
2064 mii_ctrl_reg |= MII_CR_SPEED_10;
2065 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
2066 DEBUGOUT("Forcing 10mb ");
2069 e1000_config_collision_dist(hw);
2071 /* Write the configured values back to the Device Control Reg. */
2072 E1000_WRITE_REG(hw, CTRL, ctrl);
2074 if ((hw->phy_type == e1000_phy_m88) ||
2075 (hw->phy_type == e1000_phy_gg82563)) {
2076 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
2080 /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
2081 * forced whenever speed are duplex are forced.
2083 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
2084 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
2088 DEBUGOUT1("M88E1000 PSCR: %x \n", phy_data);
2090 /* Need to reset the PHY or these changes will be ignored */
2091 mii_ctrl_reg |= MII_CR_RESET;
2093 /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
2094 * forced whenever speed or duplex are forced.
2096 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
2100 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
2101 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
2103 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
2108 /* Write back the modified PHY MII control register. */
2109 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg);
2115 /* The wait_autoneg_complete flag may be a little misleading here.
2116 * Since we are forcing speed and duplex, Auto-Neg is not enabled.
2117 * But we do want to delay for a period while forcing only so we
2118 * don't generate false No Link messages. So we will wait here
2119 * only if the user has set wait_autoneg_complete to 1, which is
2122 if(hw->wait_autoneg_complete) {
2123 /* We will wait for autoneg to complete. */
2124 DEBUGOUT("Waiting for forced speed/duplex link.\n");
2127 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
2128 for(i = PHY_FORCE_TIME; i > 0; i--) {
2129 /* Read the MII Status Register and wait for Auto-Neg Complete bit
2132 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2136 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2140 if(mii_status_reg & MII_SR_LINK_STATUS) break;
2144 ((hw->phy_type == e1000_phy_m88) ||
2145 (hw->phy_type == e1000_phy_gg82563))) {
2146 /* We didn't get link. Reset the DSP and wait again for link. */
2147 ret_val = e1000_phy_reset_dsp(hw);
2149 DEBUGOUT("Error Resetting PHY DSP\n");
2153 /* This loop will early-out if the link condition has been met. */
2154 for(i = PHY_FORCE_TIME; i > 0; i--) {
2155 if(mii_status_reg & MII_SR_LINK_STATUS) break;
2157 /* Read the MII Status Register and wait for Auto-Neg Complete bit
2160 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2164 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2170 if (hw->phy_type == e1000_phy_m88) {
2171 /* Because we reset the PHY above, we need to re-force TX_CLK in the
2172 * Extended PHY Specific Control Register to 25MHz clock. This value
2173 * defaults back to a 2.5MHz clock when the PHY is reset.
2175 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
2179 phy_data |= M88E1000_EPSCR_TX_CLK_25;
2180 ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
2184 /* In addition, because of the s/w reset above, we need to enable CRS on
2185 * TX. This must be set for both full and half duplex operation.
2187 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
2191 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
2192 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
2196 if((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
2198 (hw->forced_speed_duplex == e1000_10_full ||
2199 hw->forced_speed_duplex == e1000_10_half)) {
2200 ret_val = e1000_polarity_reversal_workaround(hw);
2204 } else if (hw->phy_type == e1000_phy_gg82563) {
2205 /* The TX_CLK of the Extended PHY Specific Control Register defaults
2206 * to 2.5MHz on a reset. We need to re-force it back to 25MHz, if
2207 * we're not in a forced 10/duplex configuration. */
2208 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, &phy_data);
2212 phy_data &= ~GG82563_MSCR_TX_CLK_MASK;
2213 if ((hw->forced_speed_duplex == e1000_10_full) ||
2214 (hw->forced_speed_duplex == e1000_10_half))
2215 phy_data |= GG82563_MSCR_TX_CLK_10MBPS_2_5MHZ;
2217 phy_data |= GG82563_MSCR_TX_CLK_100MBPS_25MHZ;
2219 /* Also due to the reset, we need to enable CRS on Tx. */
2220 phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
2222 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, phy_data);
2226 return E1000_SUCCESS;
2229 /******************************************************************************
2230 * Sets the collision distance in the Transmit Control register
2232 * hw - Struct containing variables accessed by shared code
2234 * Link should have been established previously. Reads the speed and duplex
2235 * information from the Device Status register.
2236 ******************************************************************************/
2238 e1000_config_collision_dist(struct e1000_hw *hw)
2240 uint32_t tctl, coll_dist;
2242 DEBUGFUNC("e1000_config_collision_dist");
2244 if (hw->mac_type < e1000_82543)
2245 coll_dist = E1000_COLLISION_DISTANCE_82542;
2247 coll_dist = E1000_COLLISION_DISTANCE;
2249 tctl = E1000_READ_REG(hw, TCTL);
2251 tctl &= ~E1000_TCTL_COLD;
2252 tctl |= coll_dist << E1000_COLD_SHIFT;
2254 E1000_WRITE_REG(hw, TCTL, tctl);
2255 E1000_WRITE_FLUSH(hw);
2258 /******************************************************************************
2259 * Sets MAC speed and duplex settings to reflect the those in the PHY
2261 * hw - Struct containing variables accessed by shared code
2262 * mii_reg - data to write to the MII control register
2264 * The contents of the PHY register containing the needed information need to
2266 ******************************************************************************/
2268 e1000_config_mac_to_phy(struct e1000_hw *hw)
2274 DEBUGFUNC("e1000_config_mac_to_phy");
2276 /* 82544 or newer MAC, Auto Speed Detection takes care of
2277 * MAC speed/duplex configuration.*/
2278 if (hw->mac_type >= e1000_82544)
2279 return E1000_SUCCESS;
2281 /* Read the Device Control Register and set the bits to Force Speed
2284 ctrl = E1000_READ_REG(hw, CTRL);
2285 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2286 ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
2288 /* Set up duplex in the Device Control and Transmit Control
2289 * registers depending on negotiated values.
2291 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
2295 if(phy_data & M88E1000_PSSR_DPLX)
2296 ctrl |= E1000_CTRL_FD;
2298 ctrl &= ~E1000_CTRL_FD;
2300 e1000_config_collision_dist(hw);
2302 /* Set up speed in the Device Control register depending on
2303 * negotiated values.
2305 if((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
2306 ctrl |= E1000_CTRL_SPD_1000;
2307 else if((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
2308 ctrl |= E1000_CTRL_SPD_100;
2310 /* Write the configured values back to the Device Control Reg. */
2311 E1000_WRITE_REG(hw, CTRL, ctrl);
2312 return E1000_SUCCESS;
2315 /******************************************************************************
2316 * Forces the MAC's flow control settings.
2318 * hw - Struct containing variables accessed by shared code
2320 * Sets the TFCE and RFCE bits in the device control register to reflect
2321 * the adapter settings. TFCE and RFCE need to be explicitly set by
2322 * software when a Copper PHY is used because autonegotiation is managed
2323 * by the PHY rather than the MAC. Software must also configure these
2324 * bits when link is forced on a fiber connection.
2325 *****************************************************************************/
2327 e1000_force_mac_fc(struct e1000_hw *hw)
2331 DEBUGFUNC("e1000_force_mac_fc");
2333 /* Get the current configuration of the Device Control Register */
2334 ctrl = E1000_READ_REG(hw, CTRL);
2336 /* Because we didn't get link via the internal auto-negotiation
2337 * mechanism (we either forced link or we got link via PHY
2338 * auto-neg), we have to manually enable/disable transmit an
2339 * receive flow control.
2341 * The "Case" statement below enables/disable flow control
2342 * according to the "hw->fc" parameter.
2344 * The possible values of the "fc" parameter are:
2345 * 0: Flow control is completely disabled
2346 * 1: Rx flow control is enabled (we can receive pause
2347 * frames but not send pause frames).
2348 * 2: Tx flow control is enabled (we can send pause frames
2349 * frames but we do not receive pause frames).
2350 * 3: Both Rx and TX flow control (symmetric) is enabled.
2351 * other: No other values should be possible at this point.
2356 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
2358 case e1000_fc_rx_pause:
2359 ctrl &= (~E1000_CTRL_TFCE);
2360 ctrl |= E1000_CTRL_RFCE;
2362 case e1000_fc_tx_pause:
2363 ctrl &= (~E1000_CTRL_RFCE);
2364 ctrl |= E1000_CTRL_TFCE;
2367 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
2370 DEBUGOUT("Flow control param set incorrectly\n");
2371 return -E1000_ERR_CONFIG;
2374 /* Disable TX Flow Control for 82542 (rev 2.0) */
2375 if(hw->mac_type == e1000_82542_rev2_0)
2376 ctrl &= (~E1000_CTRL_TFCE);
2378 E1000_WRITE_REG(hw, CTRL, ctrl);
2379 return E1000_SUCCESS;
2382 /******************************************************************************
2383 * Configures flow control settings after link is established
2385 * hw - Struct containing variables accessed by shared code
2387 * Should be called immediately after a valid link has been established.
2388 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
2389 * and autonegotiation is enabled, the MAC flow control settings will be set
2390 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
2391 * and RFCE bits will be automaticaly set to the negotiated flow control mode.
2392 *****************************************************************************/
2394 e1000_config_fc_after_link_up(struct e1000_hw *hw)
2397 uint16_t mii_status_reg;
2398 uint16_t mii_nway_adv_reg;
2399 uint16_t mii_nway_lp_ability_reg;
2403 DEBUGFUNC("e1000_config_fc_after_link_up");
2405 /* Check for the case where we have fiber media and auto-neg failed
2406 * so we had to force link. In this case, we need to force the
2407 * configuration of the MAC to match the "fc" parameter.
2409 if(((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) ||
2410 ((hw->media_type == e1000_media_type_internal_serdes) && (hw->autoneg_failed)) ||
2411 ((hw->media_type == e1000_media_type_copper) && (!hw->autoneg))) {
2412 ret_val = e1000_force_mac_fc(hw);
2414 DEBUGOUT("Error forcing flow control settings\n");
2419 /* Check for the case where we have copper media and auto-neg is
2420 * enabled. In this case, we need to check and see if Auto-Neg
2421 * has completed, and if so, how the PHY and link partner has
2422 * flow control configured.
2424 if((hw->media_type == e1000_media_type_copper) && hw->autoneg) {
2425 /* Read the MII Status Register and check to see if AutoNeg
2426 * has completed. We read this twice because this reg has
2427 * some "sticky" (latched) bits.
2429 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2432 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2436 if(mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
2437 /* The AutoNeg process has completed, so we now need to
2438 * read both the Auto Negotiation Advertisement Register
2439 * (Address 4) and the Auto_Negotiation Base Page Ability
2440 * Register (Address 5) to determine how flow control was
2443 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV,
2447 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY,
2448 &mii_nway_lp_ability_reg);
2452 /* Two bits in the Auto Negotiation Advertisement Register
2453 * (Address 4) and two bits in the Auto Negotiation Base
2454 * Page Ability Register (Address 5) determine flow control
2455 * for both the PHY and the link partner. The following
2456 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
2457 * 1999, describes these PAUSE resolution bits and how flow
2458 * control is determined based upon these settings.
2459 * NOTE: DC = Don't Care
2461 * LOCAL DEVICE | LINK PARTNER
2462 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
2463 *-------|---------|-------|---------|--------------------
2464 * 0 | 0 | DC | DC | e1000_fc_none
2465 * 0 | 1 | 0 | DC | e1000_fc_none
2466 * 0 | 1 | 1 | 0 | e1000_fc_none
2467 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
2468 * 1 | 0 | 0 | DC | e1000_fc_none
2469 * 1 | DC | 1 | DC | e1000_fc_full
2470 * 1 | 1 | 0 | 0 | e1000_fc_none
2471 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
2474 /* Are both PAUSE bits set to 1? If so, this implies
2475 * Symmetric Flow Control is enabled at both ends. The
2476 * ASM_DIR bits are irrelevant per the spec.
2478 * For Symmetric Flow Control:
2480 * LOCAL DEVICE | LINK PARTNER
2481 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2482 *-------|---------|-------|---------|--------------------
2483 * 1 | DC | 1 | DC | e1000_fc_full
2486 if((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2487 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
2488 /* Now we need to check if the user selected RX ONLY
2489 * of pause frames. In this case, we had to advertise
2490 * FULL flow control because we could not advertise RX
2491 * ONLY. Hence, we must now check to see if we need to
2492 * turn OFF the TRANSMISSION of PAUSE frames.
2494 if(hw->original_fc == e1000_fc_full) {
2495 hw->fc = e1000_fc_full;
2496 DEBUGOUT("Flow Control = FULL.\n");
2498 hw->fc = e1000_fc_rx_pause;
2499 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
2502 /* For receiving PAUSE frames ONLY.
2504 * LOCAL DEVICE | LINK PARTNER
2505 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2506 *-------|---------|-------|---------|--------------------
2507 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
2510 else if(!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2511 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2512 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2513 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
2514 hw->fc = e1000_fc_tx_pause;
2515 DEBUGOUT("Flow Control = TX PAUSE frames only.\n");
2517 /* For transmitting PAUSE frames ONLY.
2519 * LOCAL DEVICE | LINK PARTNER
2520 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2521 *-------|---------|-------|---------|--------------------
2522 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
2525 else if((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2526 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2527 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2528 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
2529 hw->fc = e1000_fc_rx_pause;
2530 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
2532 /* Per the IEEE spec, at this point flow control should be
2533 * disabled. However, we want to consider that we could
2534 * be connected to a legacy switch that doesn't advertise
2535 * desired flow control, but can be forced on the link
2536 * partner. So if we advertised no flow control, that is
2537 * what we will resolve to. If we advertised some kind of
2538 * receive capability (Rx Pause Only or Full Flow Control)
2539 * and the link partner advertised none, we will configure
2540 * ourselves to enable Rx Flow Control only. We can do
2541 * this safely for two reasons: If the link partner really
2542 * didn't want flow control enabled, and we enable Rx, no
2543 * harm done since we won't be receiving any PAUSE frames
2544 * anyway. If the intent on the link partner was to have
2545 * flow control enabled, then by us enabling RX only, we
2546 * can at least receive pause frames and process them.
2547 * This is a good idea because in most cases, since we are
2548 * predominantly a server NIC, more times than not we will
2549 * be asked to delay transmission of packets than asking
2550 * our link partner to pause transmission of frames.
2552 else if((hw->original_fc == e1000_fc_none ||
2553 hw->original_fc == e1000_fc_tx_pause) ||
2554 hw->fc_strict_ieee) {
2555 hw->fc = e1000_fc_none;
2556 DEBUGOUT("Flow Control = NONE.\n");
2558 hw->fc = e1000_fc_rx_pause;
2559 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
2562 /* Now we need to do one last check... If we auto-
2563 * negotiated to HALF DUPLEX, flow control should not be
2564 * enabled per IEEE 802.3 spec.
2566 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
2568 DEBUGOUT("Error getting link speed and duplex\n");
2572 if(duplex == HALF_DUPLEX)
2573 hw->fc = e1000_fc_none;
2575 /* Now we call a subroutine to actually force the MAC
2576 * controller to use the correct flow control settings.
2578 ret_val = e1000_force_mac_fc(hw);
2580 DEBUGOUT("Error forcing flow control settings\n");
2584 DEBUGOUT("Copper PHY and Auto Neg has not completed.\n");
2587 return E1000_SUCCESS;
2590 /******************************************************************************
2591 * Checks to see if the link status of the hardware has changed.
2593 * hw - Struct containing variables accessed by shared code
2595 * Called by any function that needs to check the link status of the adapter.
2596 *****************************************************************************/
2598 e1000_check_for_link(struct e1000_hw *hw)
2605 uint32_t signal = 0;
2609 DEBUGFUNC("e1000_check_for_link");
2611 ctrl = E1000_READ_REG(hw, CTRL);
2612 status = E1000_READ_REG(hw, STATUS);
2614 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
2615 * set when the optics detect a signal. On older adapters, it will be
2616 * cleared when there is a signal. This applies to fiber media only.
2618 if((hw->media_type == e1000_media_type_fiber) ||
2619 (hw->media_type == e1000_media_type_internal_serdes)) {
2620 rxcw = E1000_READ_REG(hw, RXCW);
2622 if(hw->media_type == e1000_media_type_fiber) {
2623 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
2624 if(status & E1000_STATUS_LU)
2625 hw->get_link_status = FALSE;
2629 /* If we have a copper PHY then we only want to go out to the PHY
2630 * registers to see if Auto-Neg has completed and/or if our link
2631 * status has changed. The get_link_status flag will be set if we
2632 * receive a Link Status Change interrupt or we have Rx Sequence
2635 if((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
2636 /* First we want to see if the MII Status Register reports
2637 * link. If so, then we want to get the current speed/duplex
2639 * Read the register twice since the link bit is sticky.
2641 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2644 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2648 if(phy_data & MII_SR_LINK_STATUS) {
2649 hw->get_link_status = FALSE;
2650 /* Check if there was DownShift, must be checked immediately after
2652 e1000_check_downshift(hw);
2654 /* If we are on 82544 or 82543 silicon and speed/duplex
2655 * are forced to 10H or 10F, then we will implement the polarity
2656 * reversal workaround. We disable interrupts first, and upon
2657 * returning, place the devices interrupt state to its previous
2658 * value except for the link status change interrupt which will
2659 * happen due to the execution of this workaround.
2662 if((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
2664 (hw->forced_speed_duplex == e1000_10_full ||
2665 hw->forced_speed_duplex == e1000_10_half)) {
2666 E1000_WRITE_REG(hw, IMC, 0xffffffff);
2667 ret_val = e1000_polarity_reversal_workaround(hw);
2668 icr = E1000_READ_REG(hw, ICR);
2669 E1000_WRITE_REG(hw, ICS, (icr & ~E1000_ICS_LSC));
2670 E1000_WRITE_REG(hw, IMS, IMS_ENABLE_MASK);
2674 /* No link detected */
2675 e1000_config_dsp_after_link_change(hw, FALSE);
2679 /* If we are forcing speed/duplex, then we simply return since
2680 * we have already determined whether we have link or not.
2682 if(!hw->autoneg) return -E1000_ERR_CONFIG;
2684 /* optimize the dsp settings for the igp phy */
2685 e1000_config_dsp_after_link_change(hw, TRUE);
2687 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
2688 * have Si on board that is 82544 or newer, Auto
2689 * Speed Detection takes care of MAC speed/duplex
2690 * configuration. So we only need to configure Collision
2691 * Distance in the MAC. Otherwise, we need to force
2692 * speed/duplex on the MAC to the current PHY speed/duplex
2695 if(hw->mac_type >= e1000_82544)
2696 e1000_config_collision_dist(hw);
2698 ret_val = e1000_config_mac_to_phy(hw);
2700 DEBUGOUT("Error configuring MAC to PHY settings\n");
2705 /* Configure Flow Control now that Auto-Neg has completed. First, we
2706 * need to restore the desired flow control settings because we may
2707 * have had to re-autoneg with a different link partner.
2709 ret_val = e1000_config_fc_after_link_up(hw);
2711 DEBUGOUT("Error configuring flow control\n");
2715 /* At this point we know that we are on copper and we have
2716 * auto-negotiated link. These are conditions for checking the link
2717 * partner capability register. We use the link speed to determine if
2718 * TBI compatibility needs to be turned on or off. If the link is not
2719 * at gigabit speed, then TBI compatibility is not needed. If we are
2720 * at gigabit speed, we turn on TBI compatibility.
2722 if(hw->tbi_compatibility_en) {
2723 uint16_t speed, duplex;
2724 e1000_get_speed_and_duplex(hw, &speed, &duplex);
2725 if(speed != SPEED_1000) {
2726 /* If link speed is not set to gigabit speed, we do not need
2727 * to enable TBI compatibility.
2729 if(hw->tbi_compatibility_on) {
2730 /* If we previously were in the mode, turn it off. */
2731 rctl = E1000_READ_REG(hw, RCTL);
2732 rctl &= ~E1000_RCTL_SBP;
2733 E1000_WRITE_REG(hw, RCTL, rctl);
2734 hw->tbi_compatibility_on = FALSE;
2737 /* If TBI compatibility is was previously off, turn it on. For
2738 * compatibility with a TBI link partner, we will store bad
2739 * packets. Some frames have an additional byte on the end and
2740 * will look like CRC errors to to the hardware.
2742 if(!hw->tbi_compatibility_on) {
2743 hw->tbi_compatibility_on = TRUE;
2744 rctl = E1000_READ_REG(hw, RCTL);
2745 rctl |= E1000_RCTL_SBP;
2746 E1000_WRITE_REG(hw, RCTL, rctl);
2751 /* If we don't have link (auto-negotiation failed or link partner cannot
2752 * auto-negotiate), the cable is plugged in (we have signal), and our
2753 * link partner is not trying to auto-negotiate with us (we are receiving
2754 * idles or data), we need to force link up. We also need to give
2755 * auto-negotiation time to complete, in case the cable was just plugged
2756 * in. The autoneg_failed flag does this.
2758 else if((((hw->media_type == e1000_media_type_fiber) &&
2759 ((ctrl & E1000_CTRL_SWDPIN1) == signal)) ||
2760 (hw->media_type == e1000_media_type_internal_serdes)) &&
2761 (!(status & E1000_STATUS_LU)) &&
2762 (!(rxcw & E1000_RXCW_C))) {
2763 if(hw->autoneg_failed == 0) {
2764 hw->autoneg_failed = 1;
2767 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\n");
2769 /* Disable auto-negotiation in the TXCW register */
2770 E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
2772 /* Force link-up and also force full-duplex. */
2773 ctrl = E1000_READ_REG(hw, CTRL);
2774 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
2775 E1000_WRITE_REG(hw, CTRL, ctrl);
2777 /* Configure Flow Control after forcing link up. */
2778 ret_val = e1000_config_fc_after_link_up(hw);
2780 DEBUGOUT("Error configuring flow control\n");
2784 /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
2785 * auto-negotiation in the TXCW register and disable forced link in the
2786 * Device Control register in an attempt to auto-negotiate with our link
2789 else if(((hw->media_type == e1000_media_type_fiber) ||
2790 (hw->media_type == e1000_media_type_internal_serdes)) &&
2791 (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
2792 DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\n");
2793 E1000_WRITE_REG(hw, TXCW, hw->txcw);
2794 E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
2796 hw->serdes_link_down = FALSE;
2798 /* If we force link for non-auto-negotiation switch, check link status
2799 * based on MAC synchronization for internal serdes media type.
2801 else if((hw->media_type == e1000_media_type_internal_serdes) &&
2802 !(E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
2803 /* SYNCH bit and IV bit are sticky. */
2805 if(E1000_RXCW_SYNCH & E1000_READ_REG(hw, RXCW)) {
2806 if(!(rxcw & E1000_RXCW_IV)) {
2807 hw->serdes_link_down = FALSE;
2808 DEBUGOUT("SERDES: Link is up.\n");
2811 hw->serdes_link_down = TRUE;
2812 DEBUGOUT("SERDES: Link is down.\n");
2815 if((hw->media_type == e1000_media_type_internal_serdes) &&
2816 (E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
2817 hw->serdes_link_down = !(E1000_STATUS_LU & E1000_READ_REG(hw, STATUS));
2819 return E1000_SUCCESS;
2822 /******************************************************************************
2823 * Detects the current speed and duplex settings of the hardware.
2825 * hw - Struct containing variables accessed by shared code
2826 * speed - Speed of the connection
2827 * duplex - Duplex setting of the connection
2828 *****************************************************************************/
2830 e1000_get_speed_and_duplex(struct e1000_hw *hw,
2838 DEBUGFUNC("e1000_get_speed_and_duplex");
2840 if(hw->mac_type >= e1000_82543) {
2841 status = E1000_READ_REG(hw, STATUS);
2842 if(status & E1000_STATUS_SPEED_1000) {
2843 *speed = SPEED_1000;
2844 DEBUGOUT("1000 Mbs, ");
2845 } else if(status & E1000_STATUS_SPEED_100) {
2847 DEBUGOUT("100 Mbs, ");
2850 DEBUGOUT("10 Mbs, ");
2853 if(status & E1000_STATUS_FD) {
2854 *duplex = FULL_DUPLEX;
2855 DEBUGOUT("Full Duplex\n");
2857 *duplex = HALF_DUPLEX;
2858 DEBUGOUT(" Half Duplex\n");
2861 DEBUGOUT("1000 Mbs, Full Duplex\n");
2862 *speed = SPEED_1000;
2863 *duplex = FULL_DUPLEX;
2866 /* IGP01 PHY may advertise full duplex operation after speed downgrade even
2867 * if it is operating at half duplex. Here we set the duplex settings to
2868 * match the duplex in the link partner's capabilities.
2870 if(hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
2871 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
2875 if(!(phy_data & NWAY_ER_LP_NWAY_CAPS))
2876 *duplex = HALF_DUPLEX;
2878 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data);
2881 if((*speed == SPEED_100 && !(phy_data & NWAY_LPAR_100TX_FD_CAPS)) ||
2882 (*speed == SPEED_10 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
2883 *duplex = HALF_DUPLEX;
2887 if ((hw->mac_type == e1000_80003es2lan) &&
2888 (hw->media_type == e1000_media_type_copper)) {
2889 if (*speed == SPEED_1000)
2890 ret_val = e1000_configure_kmrn_for_1000(hw);
2892 ret_val = e1000_configure_kmrn_for_10_100(hw);
2897 return E1000_SUCCESS;
2900 /******************************************************************************
2901 * Blocks until autoneg completes or times out (~4.5 seconds)
2903 * hw - Struct containing variables accessed by shared code
2904 ******************************************************************************/
2906 e1000_wait_autoneg(struct e1000_hw *hw)
2912 DEBUGFUNC("e1000_wait_autoneg");
2913 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
2915 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
2916 for(i = PHY_AUTO_NEG_TIME; i > 0; i--) {
2917 /* Read the MII Status Register and wait for Auto-Neg
2918 * Complete bit to be set.
2920 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2923 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2926 if(phy_data & MII_SR_AUTONEG_COMPLETE) {
2927 return E1000_SUCCESS;
2931 return E1000_SUCCESS;
2934 /******************************************************************************
2935 * Raises the Management Data Clock
2937 * hw - Struct containing variables accessed by shared code
2938 * ctrl - Device control register's current value
2939 ******************************************************************************/
2941 e1000_raise_mdi_clk(struct e1000_hw *hw,
2944 /* Raise the clock input to the Management Data Clock (by setting the MDC
2945 * bit), and then delay 10 microseconds.
2947 E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
2948 E1000_WRITE_FLUSH(hw);
2952 /******************************************************************************
2953 * Lowers the Management Data Clock
2955 * hw - Struct containing variables accessed by shared code
2956 * ctrl - Device control register's current value
2957 ******************************************************************************/
2959 e1000_lower_mdi_clk(struct e1000_hw *hw,
2962 /* Lower the clock input to the Management Data Clock (by clearing the MDC
2963 * bit), and then delay 10 microseconds.
2965 E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
2966 E1000_WRITE_FLUSH(hw);
2970 /******************************************************************************
2971 * Shifts data bits out to the PHY
2973 * hw - Struct containing variables accessed by shared code
2974 * data - Data to send out to the PHY
2975 * count - Number of bits to shift out
2977 * Bits are shifted out in MSB to LSB order.
2978 ******************************************************************************/
2980 e1000_shift_out_mdi_bits(struct e1000_hw *hw,
2987 /* We need to shift "count" number of bits out to the PHY. So, the value
2988 * in the "data" parameter will be shifted out to the PHY one bit at a
2989 * time. In order to do this, "data" must be broken down into bits.
2992 mask <<= (count - 1);
2994 ctrl = E1000_READ_REG(hw, CTRL);
2996 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
2997 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
3000 /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
3001 * then raising and lowering the Management Data Clock. A "0" is
3002 * shifted out to the PHY by setting the MDIO bit to "0" and then
3003 * raising and lowering the clock.
3005 if(data & mask) ctrl |= E1000_CTRL_MDIO;
3006 else ctrl &= ~E1000_CTRL_MDIO;
3008 E1000_WRITE_REG(hw, CTRL, ctrl);
3009 E1000_WRITE_FLUSH(hw);
3013 e1000_raise_mdi_clk(hw, &ctrl);
3014 e1000_lower_mdi_clk(hw, &ctrl);
3020 /******************************************************************************
3021 * Shifts data bits in from the PHY
3023 * hw - Struct containing variables accessed by shared code
3025 * Bits are shifted in in MSB to LSB order.
3026 ******************************************************************************/
3028 e1000_shift_in_mdi_bits(struct e1000_hw *hw)
3034 /* In order to read a register from the PHY, we need to shift in a total
3035 * of 18 bits from the PHY. The first two bit (turnaround) times are used
3036 * to avoid contention on the MDIO pin when a read operation is performed.
3037 * These two bits are ignored by us and thrown away. Bits are "shifted in"
3038 * by raising the input to the Management Data Clock (setting the MDC bit),
3039 * and then reading the value of the MDIO bit.
3041 ctrl = E1000_READ_REG(hw, CTRL);
3043 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
3044 ctrl &= ~E1000_CTRL_MDIO_DIR;
3045 ctrl &= ~E1000_CTRL_MDIO;
3047 E1000_WRITE_REG(hw, CTRL, ctrl);
3048 E1000_WRITE_FLUSH(hw);
3050 /* Raise and Lower the clock before reading in the data. This accounts for
3051 * the turnaround bits. The first clock occurred when we clocked out the
3052 * last bit of the Register Address.
3054 e1000_raise_mdi_clk(hw, &ctrl);
3055 e1000_lower_mdi_clk(hw, &ctrl);
3057 for(data = 0, i = 0; i < 16; i++) {
3059 e1000_raise_mdi_clk(hw, &ctrl);
3060 ctrl = E1000_READ_REG(hw, CTRL);
3061 /* Check to see if we shifted in a "1". */
3062 if(ctrl & E1000_CTRL_MDIO) data |= 1;
3063 e1000_lower_mdi_clk(hw, &ctrl);
3066 e1000_raise_mdi_clk(hw, &ctrl);
3067 e1000_lower_mdi_clk(hw, &ctrl);
3073 e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask)
3075 uint32_t swfw_sync = 0;
3076 uint32_t swmask = mask;
3077 uint32_t fwmask = mask << 16;
3078 int32_t timeout = 200;
3080 DEBUGFUNC("e1000_swfw_sync_acquire");
3082 if (!hw->swfw_sync_present)
3083 return e1000_get_hw_eeprom_semaphore(hw);
3086 if (e1000_get_hw_eeprom_semaphore(hw))
3087 return -E1000_ERR_SWFW_SYNC;
3089 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
3090 if (!(swfw_sync & (fwmask | swmask))) {
3094 /* firmware currently using resource (fwmask) */
3095 /* or other software thread currently using resource (swmask) */
3096 e1000_put_hw_eeprom_semaphore(hw);
3102 DEBUGOUT("Driver can't access resource, SW_FW_SYNC timeout.\n");
3103 return -E1000_ERR_SWFW_SYNC;
3106 swfw_sync |= swmask;
3107 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
3109 e1000_put_hw_eeprom_semaphore(hw);
3110 return E1000_SUCCESS;
3114 e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask)
3117 uint32_t swmask = mask;
3119 DEBUGFUNC("e1000_swfw_sync_release");
3121 if (!hw->swfw_sync_present) {
3122 e1000_put_hw_eeprom_semaphore(hw);
3126 /* if (e1000_get_hw_eeprom_semaphore(hw))
3127 * return -E1000_ERR_SWFW_SYNC; */
3128 while (e1000_get_hw_eeprom_semaphore(hw) != E1000_SUCCESS);
3131 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
3132 swfw_sync &= ~swmask;
3133 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
3135 e1000_put_hw_eeprom_semaphore(hw);
3138 /*****************************************************************************
3139 * Reads the value from a PHY register, if the value is on a specific non zero
3140 * page, sets the page first.
3141 * hw - Struct containing variables accessed by shared code
3142 * reg_addr - address of the PHY register to read
3143 ******************************************************************************/
3145 e1000_read_phy_reg(struct e1000_hw *hw,
3152 DEBUGFUNC("e1000_read_phy_reg");
3154 if ((hw->mac_type == e1000_80003es2lan) &&
3155 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3156 swfw = E1000_SWFW_PHY1_SM;
3158 swfw = E1000_SWFW_PHY0_SM;
3160 if (e1000_swfw_sync_acquire(hw, swfw))
3161 return -E1000_ERR_SWFW_SYNC;
3163 if((hw->phy_type == e1000_phy_igp ||
3164 hw->phy_type == e1000_phy_igp_2) &&
3165 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
3166 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
3167 (uint16_t)reg_addr);
3169 e1000_swfw_sync_release(hw, swfw);
3172 } else if (hw->phy_type == e1000_phy_gg82563) {
3173 if (((reg_addr & MAX_PHY_REG_ADDRESS) > MAX_PHY_MULTI_PAGE_REG) ||
3174 (hw->mac_type == e1000_80003es2lan)) {
3175 /* Select Configuration Page */
3176 if ((reg_addr & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) {
3177 ret_val = e1000_write_phy_reg_ex(hw, GG82563_PHY_PAGE_SELECT,
3178 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3180 /* Use Alternative Page Select register to access
3181 * registers 30 and 31
3183 ret_val = e1000_write_phy_reg_ex(hw,
3184 GG82563_PHY_PAGE_SELECT_ALT,
3185 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3189 e1000_swfw_sync_release(hw, swfw);
3195 ret_val = e1000_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
3198 e1000_swfw_sync_release(hw, swfw);
3203 e1000_read_phy_reg_ex(struct e1000_hw *hw,
3209 const uint32_t phy_addr = 1;
3211 DEBUGFUNC("e1000_read_phy_reg_ex");
3213 if(reg_addr > MAX_PHY_REG_ADDRESS) {
3214 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
3215 return -E1000_ERR_PARAM;
3218 if(hw->mac_type > e1000_82543) {
3219 /* Set up Op-code, Phy Address, and register address in the MDI
3220 * Control register. The MAC will take care of interfacing with the
3221 * PHY to retrieve the desired data.
3223 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
3224 (phy_addr << E1000_MDIC_PHY_SHIFT) |
3225 (E1000_MDIC_OP_READ));
3227 E1000_WRITE_REG(hw, MDIC, mdic);
3229 /* Poll the ready bit to see if the MDI read completed */
3230 for(i = 0; i < 64; i++) {
3232 mdic = E1000_READ_REG(hw, MDIC);
3233 if(mdic & E1000_MDIC_READY) break;
3235 if(!(mdic & E1000_MDIC_READY)) {
3236 DEBUGOUT("MDI Read did not complete\n");
3237 return -E1000_ERR_PHY;
3239 if(mdic & E1000_MDIC_ERROR) {
3240 DEBUGOUT("MDI Error\n");
3241 return -E1000_ERR_PHY;
3243 *phy_data = (uint16_t) mdic;
3245 /* We must first send a preamble through the MDIO pin to signal the
3246 * beginning of an MII instruction. This is done by sending 32
3247 * consecutive "1" bits.
3249 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
3251 /* Now combine the next few fields that are required for a read
3252 * operation. We use this method instead of calling the
3253 * e1000_shift_out_mdi_bits routine five different times. The format of
3254 * a MII read instruction consists of a shift out of 14 bits and is
3255 * defined as follows:
3256 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
3257 * followed by a shift in of 18 bits. This first two bits shifted in
3258 * are TurnAround bits used to avoid contention on the MDIO pin when a
3259 * READ operation is performed. These two bits are thrown away
3260 * followed by a shift in of 16 bits which contains the desired data.
3262 mdic = ((reg_addr) | (phy_addr << 5) |
3263 (PHY_OP_READ << 10) | (PHY_SOF << 12));
3265 e1000_shift_out_mdi_bits(hw, mdic, 14);
3267 /* Now that we've shifted out the read command to the MII, we need to
3268 * "shift in" the 16-bit value (18 total bits) of the requested PHY
3271 *phy_data = e1000_shift_in_mdi_bits(hw);
3273 return E1000_SUCCESS;
3276 /******************************************************************************
3277 * Writes a value to a PHY register
3279 * hw - Struct containing variables accessed by shared code
3280 * reg_addr - address of the PHY register to write
3281 * data - data to write to the PHY
3282 ******************************************************************************/
3284 e1000_write_phy_reg(struct e1000_hw *hw,
3291 DEBUGFUNC("e1000_write_phy_reg");
3293 if ((hw->mac_type == e1000_80003es2lan) &&
3294 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3295 swfw = E1000_SWFW_PHY1_SM;
3297 swfw = E1000_SWFW_PHY0_SM;
3299 if (e1000_swfw_sync_acquire(hw, swfw))
3300 return -E1000_ERR_SWFW_SYNC;
3302 if((hw->phy_type == e1000_phy_igp ||
3303 hw->phy_type == e1000_phy_igp_2) &&
3304 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
3305 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
3306 (uint16_t)reg_addr);
3308 e1000_swfw_sync_release(hw, swfw);
3311 } else if (hw->phy_type == e1000_phy_gg82563) {
3312 if (((reg_addr & MAX_PHY_REG_ADDRESS) > MAX_PHY_MULTI_PAGE_REG) ||
3313 (hw->mac_type == e1000_80003es2lan)) {
3314 /* Select Configuration Page */
3315 if ((reg_addr & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) {
3316 ret_val = e1000_write_phy_reg_ex(hw, GG82563_PHY_PAGE_SELECT,
3317 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3319 /* Use Alternative Page Select register to access
3320 * registers 30 and 31
3322 ret_val = e1000_write_phy_reg_ex(hw,
3323 GG82563_PHY_PAGE_SELECT_ALT,
3324 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3328 e1000_swfw_sync_release(hw, swfw);
3334 ret_val = e1000_write_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
3337 e1000_swfw_sync_release(hw, swfw);
3342 e1000_write_phy_reg_ex(struct e1000_hw *hw,
3348 const uint32_t phy_addr = 1;
3350 DEBUGFUNC("e1000_write_phy_reg_ex");
3352 if(reg_addr > MAX_PHY_REG_ADDRESS) {
3353 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
3354 return -E1000_ERR_PARAM;
3357 if(hw->mac_type > e1000_82543) {
3358 /* Set up Op-code, Phy Address, register address, and data intended
3359 * for the PHY register in the MDI Control register. The MAC will take
3360 * care of interfacing with the PHY to send the desired data.
3362 mdic = (((uint32_t) phy_data) |
3363 (reg_addr << E1000_MDIC_REG_SHIFT) |
3364 (phy_addr << E1000_MDIC_PHY_SHIFT) |
3365 (E1000_MDIC_OP_WRITE));
3367 E1000_WRITE_REG(hw, MDIC, mdic);
3369 /* Poll the ready bit to see if the MDI read completed */
3370 for(i = 0; i < 640; i++) {
3372 mdic = E1000_READ_REG(hw, MDIC);
3373 if(mdic & E1000_MDIC_READY) break;
3375 if(!(mdic & E1000_MDIC_READY)) {
3376 DEBUGOUT("MDI Write did not complete\n");
3377 return -E1000_ERR_PHY;
3380 /* We'll need to use the SW defined pins to shift the write command
3381 * out to the PHY. We first send a preamble to the PHY to signal the
3382 * beginning of the MII instruction. This is done by sending 32
3383 * consecutive "1" bits.
3385 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
3387 /* Now combine the remaining required fields that will indicate a
3388 * write operation. We use this method instead of calling the
3389 * e1000_shift_out_mdi_bits routine for each field in the command. The
3390 * format of a MII write instruction is as follows:
3391 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
3393 mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
3394 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
3396 mdic |= (uint32_t) phy_data;
3398 e1000_shift_out_mdi_bits(hw, mdic, 32);
3401 return E1000_SUCCESS;
3405 e1000_read_kmrn_reg(struct e1000_hw *hw,
3411 DEBUGFUNC("e1000_read_kmrn_reg");
3413 if ((hw->mac_type == e1000_80003es2lan) &&
3414 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3415 swfw = E1000_SWFW_PHY1_SM;
3417 swfw = E1000_SWFW_PHY0_SM;
3419 if (e1000_swfw_sync_acquire(hw, swfw))
3420 return -E1000_ERR_SWFW_SYNC;
3422 /* Write register address */
3423 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
3424 E1000_KUMCTRLSTA_OFFSET) |
3425 E1000_KUMCTRLSTA_REN;
3426 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
3429 /* Read the data returned */
3430 reg_val = E1000_READ_REG(hw, KUMCTRLSTA);
3431 *data = (uint16_t)reg_val;
3433 e1000_swfw_sync_release(hw, swfw);
3434 return E1000_SUCCESS;
3438 e1000_write_kmrn_reg(struct e1000_hw *hw,
3444 DEBUGFUNC("e1000_write_kmrn_reg");
3446 if ((hw->mac_type == e1000_80003es2lan) &&
3447 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3448 swfw = E1000_SWFW_PHY1_SM;
3450 swfw = E1000_SWFW_PHY0_SM;
3452 if (e1000_swfw_sync_acquire(hw, swfw))
3453 return -E1000_ERR_SWFW_SYNC;
3455 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
3456 E1000_KUMCTRLSTA_OFFSET) | data;
3457 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
3460 e1000_swfw_sync_release(hw, swfw);
3461 return E1000_SUCCESS;
3464 /******************************************************************************
3465 * Returns the PHY to the power-on reset state
3467 * hw - Struct containing variables accessed by shared code
3468 ******************************************************************************/
3470 e1000_phy_hw_reset(struct e1000_hw *hw)
3472 uint32_t ctrl, ctrl_ext;
3477 DEBUGFUNC("e1000_phy_hw_reset");
3479 /* In the case of the phy reset being blocked, it's not an error, we
3480 * simply return success without performing the reset. */
3481 ret_val = e1000_check_phy_reset_block(hw);
3483 return E1000_SUCCESS;
3485 DEBUGOUT("Resetting Phy...\n");
3487 if(hw->mac_type > e1000_82543) {
3488 if ((hw->mac_type == e1000_80003es2lan) &&
3489 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3490 swfw = E1000_SWFW_PHY1_SM;
3492 swfw = E1000_SWFW_PHY0_SM;
3494 if (e1000_swfw_sync_acquire(hw, swfw)) {
3495 e1000_release_software_semaphore(hw);
3496 return -E1000_ERR_SWFW_SYNC;
3498 /* Read the device control register and assert the E1000_CTRL_PHY_RST
3499 * bit. Then, take it out of reset.
3500 * For pre-e1000_82571 hardware, we delay for 10ms between the assert
3501 * and deassert. For e1000_82571 hardware and later, we instead delay
3502 * for 50us between and 10ms after the deassertion.
3504 ctrl = E1000_READ_REG(hw, CTRL);
3505 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST);
3506 E1000_WRITE_FLUSH(hw);
3508 if (hw->mac_type < e1000_82571)
3513 E1000_WRITE_REG(hw, CTRL, ctrl);
3514 E1000_WRITE_FLUSH(hw);
3516 if (hw->mac_type >= e1000_82571)
3518 e1000_swfw_sync_release(hw, swfw);
3520 /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
3521 * bit to put the PHY into reset. Then, take it out of reset.
3523 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
3524 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
3525 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
3526 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
3527 E1000_WRITE_FLUSH(hw);
3529 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
3530 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
3531 E1000_WRITE_FLUSH(hw);
3535 if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
3536 /* Configure activity LED after PHY reset */
3537 led_ctrl = E1000_READ_REG(hw, LEDCTL);
3538 led_ctrl &= IGP_ACTIVITY_LED_MASK;
3539 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
3540 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
3543 /* Wait for FW to finish PHY configuration. */
3544 ret_val = e1000_get_phy_cfg_done(hw);
3545 e1000_release_software_semaphore(hw);
3550 /******************************************************************************
3553 * hw - Struct containing variables accessed by shared code
3555 * Sets bit 15 of the MII Control regiser
3556 ******************************************************************************/
3558 e1000_phy_reset(struct e1000_hw *hw)
3563 DEBUGFUNC("e1000_phy_reset");
3565 /* In the case of the phy reset being blocked, it's not an error, we
3566 * simply return success without performing the reset. */
3567 ret_val = e1000_check_phy_reset_block(hw);
3569 return E1000_SUCCESS;
3571 switch (hw->mac_type) {
3572 case e1000_82541_rev_2:
3575 ret_val = e1000_phy_hw_reset(hw);
3580 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
3584 phy_data |= MII_CR_RESET;
3585 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
3593 if(hw->phy_type == e1000_phy_igp || hw->phy_type == e1000_phy_igp_2)
3594 e1000_phy_init_script(hw);
3596 return E1000_SUCCESS;
3599 /******************************************************************************
3600 * Probes the expected PHY address for known PHY IDs
3602 * hw - Struct containing variables accessed by shared code
3603 ******************************************************************************/
3605 e1000_detect_gig_phy(struct e1000_hw *hw)
3607 int32_t phy_init_status, ret_val;
3608 uint16_t phy_id_high, phy_id_low;
3609 boolean_t match = FALSE;
3611 DEBUGFUNC("e1000_detect_gig_phy");
3613 /* The 82571 firmware may still be configuring the PHY. In this
3614 * case, we cannot access the PHY until the configuration is done. So
3615 * we explicitly set the PHY values. */
3616 if(hw->mac_type == e1000_82571 ||
3617 hw->mac_type == e1000_82572) {
3618 hw->phy_id = IGP01E1000_I_PHY_ID;
3619 hw->phy_type = e1000_phy_igp_2;
3620 return E1000_SUCCESS;
3623 /* ESB-2 PHY reads require e1000_phy_gg82563 to be set because of a work-
3624 * around that forces PHY page 0 to be set or the reads fail. The rest of
3625 * the code in this routine uses e1000_read_phy_reg to read the PHY ID.
3626 * So for ESB-2 we need to have this set so our reads won't fail. If the
3627 * attached PHY is not a e1000_phy_gg82563, the routines below will figure
3628 * this out as well. */
3629 if (hw->mac_type == e1000_80003es2lan)
3630 hw->phy_type = e1000_phy_gg82563;
3632 /* Read the PHY ID Registers to identify which PHY is onboard. */
3633 ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
3637 hw->phy_id = (uint32_t) (phy_id_high << 16);
3639 ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
3643 hw->phy_id |= (uint32_t) (phy_id_low & PHY_REVISION_MASK);
3644 hw->phy_revision = (uint32_t) phy_id_low & ~PHY_REVISION_MASK;
3646 switch(hw->mac_type) {
3648 if(hw->phy_id == M88E1000_E_PHY_ID) match = TRUE;
3651 if(hw->phy_id == M88E1000_I_PHY_ID) match = TRUE;
3655 case e1000_82545_rev_3:
3657 case e1000_82546_rev_3:
3658 if(hw->phy_id == M88E1011_I_PHY_ID) match = TRUE;
3661 case e1000_82541_rev_2:
3663 case e1000_82547_rev_2:
3664 if(hw->phy_id == IGP01E1000_I_PHY_ID) match = TRUE;
3667 if(hw->phy_id == M88E1111_I_PHY_ID) match = TRUE;
3669 case e1000_80003es2lan:
3670 if (hw->phy_id == GG82563_E_PHY_ID) match = TRUE;
3673 DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type);
3674 return -E1000_ERR_CONFIG;
3676 phy_init_status = e1000_set_phy_type(hw);
3678 if ((match) && (phy_init_status == E1000_SUCCESS)) {
3679 DEBUGOUT1("PHY ID 0x%X detected\n", hw->phy_id);
3680 return E1000_SUCCESS;
3682 DEBUGOUT1("Invalid PHY ID 0x%X\n", hw->phy_id);
3683 return -E1000_ERR_PHY;
3686 /******************************************************************************
3687 * Resets the PHY's DSP
3689 * hw - Struct containing variables accessed by shared code
3690 ******************************************************************************/
3692 e1000_phy_reset_dsp(struct e1000_hw *hw)
3695 DEBUGFUNC("e1000_phy_reset_dsp");
3698 if (hw->phy_type != e1000_phy_gg82563) {
3699 ret_val = e1000_write_phy_reg(hw, 29, 0x001d);
3702 ret_val = e1000_write_phy_reg(hw, 30, 0x00c1);
3704 ret_val = e1000_write_phy_reg(hw, 30, 0x0000);
3706 ret_val = E1000_SUCCESS;
3712 /******************************************************************************
3713 * Get PHY information from various PHY registers for igp PHY only.
3715 * hw - Struct containing variables accessed by shared code
3716 * phy_info - PHY information structure
3717 ******************************************************************************/
3719 e1000_phy_igp_get_info(struct e1000_hw *hw,
3720 struct e1000_phy_info *phy_info)
3723 uint16_t phy_data, polarity, min_length, max_length, average;
3725 DEBUGFUNC("e1000_phy_igp_get_info");
3727 /* The downshift status is checked only once, after link is established,
3728 * and it stored in the hw->speed_downgraded parameter. */
3729 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
3731 /* IGP01E1000 does not need to support it. */
3732 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
3734 /* IGP01E1000 always correct polarity reversal */
3735 phy_info->polarity_correction = e1000_polarity_reversal_enabled;
3737 /* Check polarity status */
3738 ret_val = e1000_check_polarity(hw, &polarity);
3742 phy_info->cable_polarity = polarity;
3744 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, &phy_data);
3748 phy_info->mdix_mode = (phy_data & IGP01E1000_PSSR_MDIX) >>
3749 IGP01E1000_PSSR_MDIX_SHIFT;
3751 if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
3752 IGP01E1000_PSSR_SPEED_1000MBPS) {
3753 /* Local/Remote Receiver Information are only valid at 1000 Mbps */
3754 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
3758 phy_info->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS) >>
3759 SR_1000T_LOCAL_RX_STATUS_SHIFT;
3760 phy_info->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS) >>
3761 SR_1000T_REMOTE_RX_STATUS_SHIFT;
3763 /* Get cable length */
3764 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
3768 /* Translate to old method */
3769 average = (max_length + min_length) / 2;
3771 if(average <= e1000_igp_cable_length_50)
3772 phy_info->cable_length = e1000_cable_length_50;
3773 else if(average <= e1000_igp_cable_length_80)
3774 phy_info->cable_length = e1000_cable_length_50_80;
3775 else if(average <= e1000_igp_cable_length_110)
3776 phy_info->cable_length = e1000_cable_length_80_110;
3777 else if(average <= e1000_igp_cable_length_140)
3778 phy_info->cable_length = e1000_cable_length_110_140;
3780 phy_info->cable_length = e1000_cable_length_140;
3783 return E1000_SUCCESS;
3786 /******************************************************************************
3787 * Get PHY information from various PHY registers fot m88 PHY only.
3789 * hw - Struct containing variables accessed by shared code
3790 * phy_info - PHY information structure
3791 ******************************************************************************/
3793 e1000_phy_m88_get_info(struct e1000_hw *hw,
3794 struct e1000_phy_info *phy_info)
3797 uint16_t phy_data, polarity;
3799 DEBUGFUNC("e1000_phy_m88_get_info");
3801 /* The downshift status is checked only once, after link is established,
3802 * and it stored in the hw->speed_downgraded parameter. */
3803 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
3805 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
3809 phy_info->extended_10bt_distance =
3810 (phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >>
3811 M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT;
3812 phy_info->polarity_correction =
3813 (phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >>
3814 M88E1000_PSCR_POLARITY_REVERSAL_SHIFT;
3816 /* Check polarity status */
3817 ret_val = e1000_check_polarity(hw, &polarity);
3820 phy_info->cable_polarity = polarity;
3822 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
3826 phy_info->mdix_mode = (phy_data & M88E1000_PSSR_MDIX) >>
3827 M88E1000_PSSR_MDIX_SHIFT;
3829 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
3830 /* Cable Length Estimation and Local/Remote Receiver Information
3831 * are only valid at 1000 Mbps.
3833 if (hw->phy_type != e1000_phy_gg82563) {
3834 phy_info->cable_length = ((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
3835 M88E1000_PSSR_CABLE_LENGTH_SHIFT);
3837 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_DSP_DISTANCE,
3842 phy_info->cable_length = phy_data & GG82563_DSPD_CABLE_LENGTH;
3845 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
3849 phy_info->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS) >>
3850 SR_1000T_LOCAL_RX_STATUS_SHIFT;
3852 phy_info->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS) >>
3853 SR_1000T_REMOTE_RX_STATUS_SHIFT;
3856 return E1000_SUCCESS;
3859 /******************************************************************************
3860 * Get PHY information from various PHY registers
3862 * hw - Struct containing variables accessed by shared code
3863 * phy_info - PHY information structure
3864 ******************************************************************************/
3866 e1000_phy_get_info(struct e1000_hw *hw,
3867 struct e1000_phy_info *phy_info)
3872 DEBUGFUNC("e1000_phy_get_info");
3874 phy_info->cable_length = e1000_cable_length_undefined;
3875 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined;
3876 phy_info->cable_polarity = e1000_rev_polarity_undefined;
3877 phy_info->downshift = e1000_downshift_undefined;
3878 phy_info->polarity_correction = e1000_polarity_reversal_undefined;
3879 phy_info->mdix_mode = e1000_auto_x_mode_undefined;
3880 phy_info->local_rx = e1000_1000t_rx_status_undefined;
3881 phy_info->remote_rx = e1000_1000t_rx_status_undefined;
3883 if(hw->media_type != e1000_media_type_copper) {
3884 DEBUGOUT("PHY info is only valid for copper media\n");
3885 return -E1000_ERR_CONFIG;
3888 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3892 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3896 if((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) {
3897 DEBUGOUT("PHY info is only valid if link is up\n");
3898 return -E1000_ERR_CONFIG;
3901 if(hw->phy_type == e1000_phy_igp ||
3902 hw->phy_type == e1000_phy_igp_2)
3903 return e1000_phy_igp_get_info(hw, phy_info);
3905 return e1000_phy_m88_get_info(hw, phy_info);
3909 e1000_validate_mdi_setting(struct e1000_hw *hw)
3911 DEBUGFUNC("e1000_validate_mdi_settings");
3913 if(!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) {
3914 DEBUGOUT("Invalid MDI setting detected\n");
3916 return -E1000_ERR_CONFIG;
3918 return E1000_SUCCESS;
3922 /******************************************************************************
3923 * Sets up eeprom variables in the hw struct. Must be called after mac_type
3924 * is configured. Additionally, if this is ICH8, the flash controller GbE
3925 * registers must be mapped, or this will crash.
3927 * hw - Struct containing variables accessed by shared code
3928 *****************************************************************************/
3930 e1000_init_eeprom_params(struct e1000_hw *hw)
3932 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3933 uint32_t eecd = E1000_READ_REG(hw, EECD);
3934 int32_t ret_val = E1000_SUCCESS;
3935 uint16_t eeprom_size;
3937 DEBUGFUNC("e1000_init_eeprom_params");
3939 switch (hw->mac_type) {
3940 case e1000_82542_rev2_0:
3941 case e1000_82542_rev2_1:
3944 eeprom->type = e1000_eeprom_microwire;
3945 eeprom->word_size = 64;
3946 eeprom->opcode_bits = 3;
3947 eeprom->address_bits = 6;
3948 eeprom->delay_usec = 50;
3949 eeprom->use_eerd = FALSE;
3950 eeprom->use_eewr = FALSE;
3954 case e1000_82545_rev_3:
3956 case e1000_82546_rev_3:
3957 eeprom->type = e1000_eeprom_microwire;
3958 eeprom->opcode_bits = 3;
3959 eeprom->delay_usec = 50;
3960 if(eecd & E1000_EECD_SIZE) {
3961 eeprom->word_size = 256;
3962 eeprom->address_bits = 8;
3964 eeprom->word_size = 64;
3965 eeprom->address_bits = 6;
3967 eeprom->use_eerd = FALSE;
3968 eeprom->use_eewr = FALSE;
3971 case e1000_82541_rev_2:
3973 case e1000_82547_rev_2:
3974 if (eecd & E1000_EECD_TYPE) {
3975 eeprom->type = e1000_eeprom_spi;
3976 eeprom->opcode_bits = 8;
3977 eeprom->delay_usec = 1;
3978 if (eecd & E1000_EECD_ADDR_BITS) {
3979 eeprom->page_size = 32;
3980 eeprom->address_bits = 16;
3982 eeprom->page_size = 8;
3983 eeprom->address_bits = 8;
3986 eeprom->type = e1000_eeprom_microwire;
3987 eeprom->opcode_bits = 3;
3988 eeprom->delay_usec = 50;
3989 if (eecd & E1000_EECD_ADDR_BITS) {
3990 eeprom->word_size = 256;
3991 eeprom->address_bits = 8;
3993 eeprom->word_size = 64;
3994 eeprom->address_bits = 6;
3997 eeprom->use_eerd = FALSE;
3998 eeprom->use_eewr = FALSE;
4002 eeprom->type = e1000_eeprom_spi;
4003 eeprom->opcode_bits = 8;
4004 eeprom->delay_usec = 1;
4005 if (eecd & E1000_EECD_ADDR_BITS) {
4006 eeprom->page_size = 32;
4007 eeprom->address_bits = 16;
4009 eeprom->page_size = 8;
4010 eeprom->address_bits = 8;
4012 eeprom->use_eerd = FALSE;
4013 eeprom->use_eewr = FALSE;
4016 eeprom->type = e1000_eeprom_spi;
4017 eeprom->opcode_bits = 8;
4018 eeprom->delay_usec = 1;
4019 if (eecd & E1000_EECD_ADDR_BITS) {
4020 eeprom->page_size = 32;
4021 eeprom->address_bits = 16;
4023 eeprom->page_size = 8;
4024 eeprom->address_bits = 8;
4026 eeprom->use_eerd = TRUE;
4027 eeprom->use_eewr = TRUE;
4028 if(e1000_is_onboard_nvm_eeprom(hw) == FALSE) {
4029 eeprom->type = e1000_eeprom_flash;
4030 eeprom->word_size = 2048;
4032 /* Ensure that the Autonomous FLASH update bit is cleared due to
4033 * Flash update issue on parts which use a FLASH for NVM. */
4034 eecd &= ~E1000_EECD_AUPDEN;
4035 E1000_WRITE_REG(hw, EECD, eecd);
4038 case e1000_80003es2lan:
4039 eeprom->type = e1000_eeprom_spi;
4040 eeprom->opcode_bits = 8;
4041 eeprom->delay_usec = 1;
4042 if (eecd & E1000_EECD_ADDR_BITS) {
4043 eeprom->page_size = 32;
4044 eeprom->address_bits = 16;
4046 eeprom->page_size = 8;
4047 eeprom->address_bits = 8;
4049 eeprom->use_eerd = TRUE;
4050 eeprom->use_eewr = FALSE;
4056 if (eeprom->type == e1000_eeprom_spi) {
4057 /* eeprom_size will be an enum [0..8] that maps to eeprom sizes 128B to
4058 * 32KB (incremented by powers of 2).
4060 if(hw->mac_type <= e1000_82547_rev_2) {
4061 /* Set to default value for initial eeprom read. */
4062 eeprom->word_size = 64;
4063 ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size);
4066 eeprom_size = (eeprom_size & EEPROM_SIZE_MASK) >> EEPROM_SIZE_SHIFT;
4067 /* 256B eeprom size was not supported in earlier hardware, so we
4068 * bump eeprom_size up one to ensure that "1" (which maps to 256B)
4069 * is never the result used in the shifting logic below. */
4073 eeprom_size = (uint16_t)((eecd & E1000_EECD_SIZE_EX_MASK) >>
4074 E1000_EECD_SIZE_EX_SHIFT);
4077 eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT);
4082 /******************************************************************************
4083 * Raises the EEPROM's clock input.
4085 * hw - Struct containing variables accessed by shared code
4086 * eecd - EECD's current value
4087 *****************************************************************************/
4089 e1000_raise_ee_clk(struct e1000_hw *hw,
4092 /* Raise the clock input to the EEPROM (by setting the SK bit), and then
4093 * wait <delay> microseconds.
4095 *eecd = *eecd | E1000_EECD_SK;
4096 E1000_WRITE_REG(hw, EECD, *eecd);
4097 E1000_WRITE_FLUSH(hw);
4098 udelay(hw->eeprom.delay_usec);
4101 /******************************************************************************
4102 * Lowers the EEPROM's clock input.
4104 * hw - Struct containing variables accessed by shared code
4105 * eecd - EECD's current value
4106 *****************************************************************************/
4108 e1000_lower_ee_clk(struct e1000_hw *hw,
4111 /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
4112 * wait 50 microseconds.
4114 *eecd = *eecd & ~E1000_EECD_SK;
4115 E1000_WRITE_REG(hw, EECD, *eecd);
4116 E1000_WRITE_FLUSH(hw);
4117 udelay(hw->eeprom.delay_usec);
4120 /******************************************************************************
4121 * Shift data bits out to the EEPROM.
4123 * hw - Struct containing variables accessed by shared code
4124 * data - data to send to the EEPROM
4125 * count - number of bits to shift out
4126 *****************************************************************************/
4128 e1000_shift_out_ee_bits(struct e1000_hw *hw,
4132 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4136 /* We need to shift "count" bits out to the EEPROM. So, value in the
4137 * "data" parameter will be shifted out to the EEPROM one bit at a time.
4138 * In order to do this, "data" must be broken down into bits.
4140 mask = 0x01 << (count - 1);
4141 eecd = E1000_READ_REG(hw, EECD);
4142 if (eeprom->type == e1000_eeprom_microwire) {
4143 eecd &= ~E1000_EECD_DO;
4144 } else if (eeprom->type == e1000_eeprom_spi) {
4145 eecd |= E1000_EECD_DO;
4148 /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
4149 * and then raising and then lowering the clock (the SK bit controls
4150 * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
4151 * by setting "DI" to "0" and then raising and then lowering the clock.
4153 eecd &= ~E1000_EECD_DI;
4156 eecd |= E1000_EECD_DI;
4158 E1000_WRITE_REG(hw, EECD, eecd);
4159 E1000_WRITE_FLUSH(hw);
4161 udelay(eeprom->delay_usec);
4163 e1000_raise_ee_clk(hw, &eecd);
4164 e1000_lower_ee_clk(hw, &eecd);
4170 /* We leave the "DI" bit set to "0" when we leave this routine. */
4171 eecd &= ~E1000_EECD_DI;
4172 E1000_WRITE_REG(hw, EECD, eecd);
4175 /******************************************************************************
4176 * Shift data bits in from the EEPROM
4178 * hw - Struct containing variables accessed by shared code
4179 *****************************************************************************/
4181 e1000_shift_in_ee_bits(struct e1000_hw *hw,
4188 /* In order to read a register from the EEPROM, we need to shift 'count'
4189 * bits in from the EEPROM. Bits are "shifted in" by raising the clock
4190 * input to the EEPROM (setting the SK bit), and then reading the value of
4191 * the "DO" bit. During this "shifting in" process the "DI" bit should
4195 eecd = E1000_READ_REG(hw, EECD);
4197 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
4200 for(i = 0; i < count; i++) {
4202 e1000_raise_ee_clk(hw, &eecd);
4204 eecd = E1000_READ_REG(hw, EECD);
4206 eecd &= ~(E1000_EECD_DI);
4207 if(eecd & E1000_EECD_DO)
4210 e1000_lower_ee_clk(hw, &eecd);
4216 /******************************************************************************
4217 * Prepares EEPROM for access
4219 * hw - Struct containing variables accessed by shared code
4221 * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
4222 * function should be called before issuing a command to the EEPROM.
4223 *****************************************************************************/
4225 e1000_acquire_eeprom(struct e1000_hw *hw)
4227 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4230 DEBUGFUNC("e1000_acquire_eeprom");
4232 if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
4233 return -E1000_ERR_SWFW_SYNC;
4234 eecd = E1000_READ_REG(hw, EECD);
4236 if (hw->mac_type != e1000_82573) {
4237 /* Request EEPROM Access */
4238 if(hw->mac_type > e1000_82544) {
4239 eecd |= E1000_EECD_REQ;
4240 E1000_WRITE_REG(hw, EECD, eecd);
4241 eecd = E1000_READ_REG(hw, EECD);
4242 while((!(eecd & E1000_EECD_GNT)) &&
4243 (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
4246 eecd = E1000_READ_REG(hw, EECD);
4248 if(!(eecd & E1000_EECD_GNT)) {
4249 eecd &= ~E1000_EECD_REQ;
4250 E1000_WRITE_REG(hw, EECD, eecd);
4251 DEBUGOUT("Could not acquire EEPROM grant\n");
4252 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
4253 return -E1000_ERR_EEPROM;
4258 /* Setup EEPROM for Read/Write */
4260 if (eeprom->type == e1000_eeprom_microwire) {
4261 /* Clear SK and DI */
4262 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
4263 E1000_WRITE_REG(hw, EECD, eecd);
4266 eecd |= E1000_EECD_CS;
4267 E1000_WRITE_REG(hw, EECD, eecd);
4268 } else if (eeprom->type == e1000_eeprom_spi) {
4269 /* Clear SK and CS */
4270 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
4271 E1000_WRITE_REG(hw, EECD, eecd);
4275 return E1000_SUCCESS;
4278 /******************************************************************************
4279 * Returns EEPROM to a "standby" state
4281 * hw - Struct containing variables accessed by shared code
4282 *****************************************************************************/
4284 e1000_standby_eeprom(struct e1000_hw *hw)
4286 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4289 eecd = E1000_READ_REG(hw, EECD);
4291 if(eeprom->type == e1000_eeprom_microwire) {
4292 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
4293 E1000_WRITE_REG(hw, EECD, eecd);
4294 E1000_WRITE_FLUSH(hw);
4295 udelay(eeprom->delay_usec);
4298 eecd |= E1000_EECD_SK;
4299 E1000_WRITE_REG(hw, EECD, eecd);
4300 E1000_WRITE_FLUSH(hw);
4301 udelay(eeprom->delay_usec);
4304 eecd |= E1000_EECD_CS;
4305 E1000_WRITE_REG(hw, EECD, eecd);
4306 E1000_WRITE_FLUSH(hw);
4307 udelay(eeprom->delay_usec);
4310 eecd &= ~E1000_EECD_SK;
4311 E1000_WRITE_REG(hw, EECD, eecd);
4312 E1000_WRITE_FLUSH(hw);
4313 udelay(eeprom->delay_usec);
4314 } else if(eeprom->type == e1000_eeprom_spi) {
4315 /* Toggle CS to flush commands */
4316 eecd |= E1000_EECD_CS;
4317 E1000_WRITE_REG(hw, EECD, eecd);
4318 E1000_WRITE_FLUSH(hw);
4319 udelay(eeprom->delay_usec);
4320 eecd &= ~E1000_EECD_CS;
4321 E1000_WRITE_REG(hw, EECD, eecd);
4322 E1000_WRITE_FLUSH(hw);
4323 udelay(eeprom->delay_usec);
4327 /******************************************************************************
4328 * Terminates a command by inverting the EEPROM's chip select pin
4330 * hw - Struct containing variables accessed by shared code
4331 *****************************************************************************/
4333 e1000_release_eeprom(struct e1000_hw *hw)
4337 DEBUGFUNC("e1000_release_eeprom");
4339 eecd = E1000_READ_REG(hw, EECD);
4341 if (hw->eeprom.type == e1000_eeprom_spi) {
4342 eecd |= E1000_EECD_CS; /* Pull CS high */
4343 eecd &= ~E1000_EECD_SK; /* Lower SCK */
4345 E1000_WRITE_REG(hw, EECD, eecd);
4347 udelay(hw->eeprom.delay_usec);
4348 } else if(hw->eeprom.type == e1000_eeprom_microwire) {
4349 /* cleanup eeprom */
4351 /* CS on Microwire is active-high */
4352 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
4354 E1000_WRITE_REG(hw, EECD, eecd);
4356 /* Rising edge of clock */
4357 eecd |= E1000_EECD_SK;
4358 E1000_WRITE_REG(hw, EECD, eecd);
4359 E1000_WRITE_FLUSH(hw);
4360 udelay(hw->eeprom.delay_usec);
4362 /* Falling edge of clock */
4363 eecd &= ~E1000_EECD_SK;
4364 E1000_WRITE_REG(hw, EECD, eecd);
4365 E1000_WRITE_FLUSH(hw);
4366 udelay(hw->eeprom.delay_usec);
4369 /* Stop requesting EEPROM access */
4370 if(hw->mac_type > e1000_82544) {
4371 eecd &= ~E1000_EECD_REQ;
4372 E1000_WRITE_REG(hw, EECD, eecd);
4375 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
4378 /******************************************************************************
4379 * Reads a 16 bit word from the EEPROM.
4381 * hw - Struct containing variables accessed by shared code
4382 *****************************************************************************/
4384 e1000_spi_eeprom_ready(struct e1000_hw *hw)
4386 uint16_t retry_count = 0;
4387 uint8_t spi_stat_reg;
4389 DEBUGFUNC("e1000_spi_eeprom_ready");
4391 /* Read "Status Register" repeatedly until the LSB is cleared. The
4392 * EEPROM will signal that the command has been completed by clearing
4393 * bit 0 of the internal status register. If it's not cleared within
4394 * 5 milliseconds, then error out.
4398 e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
4399 hw->eeprom.opcode_bits);
4400 spi_stat_reg = (uint8_t)e1000_shift_in_ee_bits(hw, 8);
4401 if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
4407 e1000_standby_eeprom(hw);
4408 } while(retry_count < EEPROM_MAX_RETRY_SPI);
4410 /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
4411 * only 0-5mSec on 5V devices)
4413 if(retry_count >= EEPROM_MAX_RETRY_SPI) {
4414 DEBUGOUT("SPI EEPROM Status error\n");
4415 return -E1000_ERR_EEPROM;
4418 return E1000_SUCCESS;
4421 /******************************************************************************
4422 * Reads a 16 bit word from the EEPROM.
4424 * hw - Struct containing variables accessed by shared code
4425 * offset - offset of word in the EEPROM to read
4426 * data - word read from the EEPROM
4427 * words - number of words to read
4428 *****************************************************************************/
4430 e1000_read_eeprom(struct e1000_hw *hw,
4435 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4439 DEBUGFUNC("e1000_read_eeprom");
4441 /* A check for invalid values: offset too large, too many words, and not
4444 if((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
4446 DEBUGOUT("\"words\" parameter out of bounds\n");
4447 return -E1000_ERR_EEPROM;
4450 /* FLASH reads without acquiring the semaphore are safe */
4451 if (e1000_is_onboard_nvm_eeprom(hw) == TRUE &&
4452 hw->eeprom.use_eerd == FALSE) {
4453 switch (hw->mac_type) {
4454 case e1000_80003es2lan:
4457 /* Prepare the EEPROM for reading */
4458 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
4459 return -E1000_ERR_EEPROM;
4464 if (eeprom->use_eerd == TRUE) {
4465 ret_val = e1000_read_eeprom_eerd(hw, offset, words, data);
4466 if ((e1000_is_onboard_nvm_eeprom(hw) == TRUE) ||
4467 (hw->mac_type != e1000_82573))
4468 e1000_release_eeprom(hw);
4472 if(eeprom->type == e1000_eeprom_spi) {
4474 uint8_t read_opcode = EEPROM_READ_OPCODE_SPI;
4476 if(e1000_spi_eeprom_ready(hw)) {
4477 e1000_release_eeprom(hw);
4478 return -E1000_ERR_EEPROM;
4481 e1000_standby_eeprom(hw);
4483 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
4484 if((eeprom->address_bits == 8) && (offset >= 128))
4485 read_opcode |= EEPROM_A8_OPCODE_SPI;
4487 /* Send the READ command (opcode + addr) */
4488 e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
4489 e1000_shift_out_ee_bits(hw, (uint16_t)(offset*2), eeprom->address_bits);
4491 /* Read the data. The address of the eeprom internally increments with
4492 * each byte (spi) being read, saving on the overhead of eeprom setup
4493 * and tear-down. The address counter will roll over if reading beyond
4494 * the size of the eeprom, thus allowing the entire memory to be read
4495 * starting from any offset. */
4496 for (i = 0; i < words; i++) {
4497 word_in = e1000_shift_in_ee_bits(hw, 16);
4498 data[i] = (word_in >> 8) | (word_in << 8);
4500 } else if(eeprom->type == e1000_eeprom_microwire) {
4501 for (i = 0; i < words; i++) {
4502 /* Send the READ command (opcode + addr) */
4503 e1000_shift_out_ee_bits(hw, EEPROM_READ_OPCODE_MICROWIRE,
4504 eeprom->opcode_bits);
4505 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + i),
4506 eeprom->address_bits);
4508 /* Read the data. For microwire, each word requires the overhead
4509 * of eeprom setup and tear-down. */
4510 data[i] = e1000_shift_in_ee_bits(hw, 16);
4511 e1000_standby_eeprom(hw);
4515 /* End this read operation */
4516 e1000_release_eeprom(hw);
4518 return E1000_SUCCESS;
4521 /******************************************************************************
4522 * Reads a 16 bit word from the EEPROM using the EERD register.
4524 * hw - Struct containing variables accessed by shared code
4525 * offset - offset of word in the EEPROM to read
4526 * data - word read from the EEPROM
4527 * words - number of words to read
4528 *****************************************************************************/
4530 e1000_read_eeprom_eerd(struct e1000_hw *hw,
4535 uint32_t i, eerd = 0;
4538 for (i = 0; i < words; i++) {
4539 eerd = ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) +
4540 E1000_EEPROM_RW_REG_START;
4542 E1000_WRITE_REG(hw, EERD, eerd);
4543 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_READ);
4548 data[i] = (E1000_READ_REG(hw, EERD) >> E1000_EEPROM_RW_REG_DATA);
4555 /******************************************************************************
4556 * Writes a 16 bit word from the EEPROM using the EEWR register.
4558 * hw - Struct containing variables accessed by shared code
4559 * offset - offset of word in the EEPROM to read
4560 * data - word read from the EEPROM
4561 * words - number of words to read
4562 *****************************************************************************/
4564 e1000_write_eeprom_eewr(struct e1000_hw *hw,
4569 uint32_t register_value = 0;
4573 if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
4574 return -E1000_ERR_SWFW_SYNC;
4576 for (i = 0; i < words; i++) {
4577 register_value = (data[i] << E1000_EEPROM_RW_REG_DATA) |
4578 ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) |
4579 E1000_EEPROM_RW_REG_START;
4581 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
4586 E1000_WRITE_REG(hw, EEWR, register_value);
4588 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
4595 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
4599 /******************************************************************************
4600 * Polls the status bit (bit 1) of the EERD to determine when the read is done.
4602 * hw - Struct containing variables accessed by shared code
4603 *****************************************************************************/
4605 e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd)
4607 uint32_t attempts = 100000;
4608 uint32_t i, reg = 0;
4609 int32_t done = E1000_ERR_EEPROM;
4611 for(i = 0; i < attempts; i++) {
4612 if(eerd == E1000_EEPROM_POLL_READ)
4613 reg = E1000_READ_REG(hw, EERD);
4615 reg = E1000_READ_REG(hw, EEWR);
4617 if(reg & E1000_EEPROM_RW_REG_DONE) {
4618 done = E1000_SUCCESS;
4627 /***************************************************************************
4628 * Description: Determines if the onboard NVM is FLASH or EEPROM.
4630 * hw - Struct containing variables accessed by shared code
4631 ****************************************************************************/
4633 e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw)
4637 DEBUGFUNC("e1000_is_onboard_nvm_eeprom");
4639 if(hw->mac_type == e1000_82573) {
4640 eecd = E1000_READ_REG(hw, EECD);
4642 /* Isolate bits 15 & 16 */
4643 eecd = ((eecd >> 15) & 0x03);
4645 /* If both bits are set, device is Flash type */
4653 /******************************************************************************
4654 * Verifies that the EEPROM has a valid checksum
4656 * hw - Struct containing variables accessed by shared code
4658 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
4659 * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
4661 *****************************************************************************/
4663 e1000_validate_eeprom_checksum(struct e1000_hw *hw)
4665 uint16_t checksum = 0;
4666 uint16_t i, eeprom_data;
4668 DEBUGFUNC("e1000_validate_eeprom_checksum");
4670 if ((hw->mac_type == e1000_82573) &&
4671 (e1000_is_onboard_nvm_eeprom(hw) == FALSE)) {
4672 /* Check bit 4 of word 10h. If it is 0, firmware is done updating
4673 * 10h-12h. Checksum may need to be fixed. */
4674 e1000_read_eeprom(hw, 0x10, 1, &eeprom_data);
4675 if ((eeprom_data & 0x10) == 0) {
4676 /* Read 0x23 and check bit 15. This bit is a 1 when the checksum
4677 * has already been fixed. If the checksum is still wrong and this
4678 * bit is a 1, we need to return bad checksum. Otherwise, we need
4679 * to set this bit to a 1 and update the checksum. */
4680 e1000_read_eeprom(hw, 0x23, 1, &eeprom_data);
4681 if ((eeprom_data & 0x8000) == 0) {
4682 eeprom_data |= 0x8000;
4683 e1000_write_eeprom(hw, 0x23, 1, &eeprom_data);
4684 e1000_update_eeprom_checksum(hw);
4689 for(i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
4690 if(e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
4691 DEBUGOUT("EEPROM Read Error\n");
4692 return -E1000_ERR_EEPROM;
4694 checksum += eeprom_data;
4697 if(checksum == (uint16_t) EEPROM_SUM)
4698 return E1000_SUCCESS;
4700 DEBUGOUT("EEPROM Checksum Invalid\n");
4701 return -E1000_ERR_EEPROM;
4705 /******************************************************************************
4706 * Calculates the EEPROM checksum and writes it to the EEPROM
4708 * hw - Struct containing variables accessed by shared code
4710 * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA.
4711 * Writes the difference to word offset 63 of the EEPROM.
4712 *****************************************************************************/
4714 e1000_update_eeprom_checksum(struct e1000_hw *hw)
4716 uint16_t checksum = 0;
4717 uint16_t i, eeprom_data;
4719 DEBUGFUNC("e1000_update_eeprom_checksum");
4721 for(i = 0; i < EEPROM_CHECKSUM_REG; i++) {
4722 if(e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
4723 DEBUGOUT("EEPROM Read Error\n");
4724 return -E1000_ERR_EEPROM;
4726 checksum += eeprom_data;
4728 checksum = (uint16_t) EEPROM_SUM - checksum;
4729 if(e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) {
4730 DEBUGOUT("EEPROM Write Error\n");
4731 return -E1000_ERR_EEPROM;
4732 } else if (hw->eeprom.type == e1000_eeprom_flash) {
4733 e1000_commit_shadow_ram(hw);
4735 return E1000_SUCCESS;
4738 /******************************************************************************
4739 * Parent function for writing words to the different EEPROM types.
4741 * hw - Struct containing variables accessed by shared code
4742 * offset - offset within the EEPROM to be written to
4743 * words - number of words to write
4744 * data - 16 bit word to be written to the EEPROM
4746 * If e1000_update_eeprom_checksum is not called after this function, the
4747 * EEPROM will most likely contain an invalid checksum.
4748 *****************************************************************************/
4750 e1000_write_eeprom(struct e1000_hw *hw,
4755 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4758 DEBUGFUNC("e1000_write_eeprom");
4760 /* A check for invalid values: offset too large, too many words, and not
4763 if((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
4765 DEBUGOUT("\"words\" parameter out of bounds\n");
4766 return -E1000_ERR_EEPROM;
4769 /* 82573 writes only through eewr */
4770 if(eeprom->use_eewr == TRUE)
4771 return e1000_write_eeprom_eewr(hw, offset, words, data);
4773 /* Prepare the EEPROM for writing */
4774 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
4775 return -E1000_ERR_EEPROM;
4777 if(eeprom->type == e1000_eeprom_microwire) {
4778 status = e1000_write_eeprom_microwire(hw, offset, words, data);
4780 status = e1000_write_eeprom_spi(hw, offset, words, data);
4784 /* Done with writing */
4785 e1000_release_eeprom(hw);
4790 /******************************************************************************
4791 * Writes a 16 bit word to a given offset in an SPI EEPROM.
4793 * hw - Struct containing variables accessed by shared code
4794 * offset - offset within the EEPROM to be written to
4795 * words - number of words to write
4796 * data - pointer to array of 8 bit words to be written to the EEPROM
4798 *****************************************************************************/
4800 e1000_write_eeprom_spi(struct e1000_hw *hw,
4805 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4808 DEBUGFUNC("e1000_write_eeprom_spi");
4810 while (widx < words) {
4811 uint8_t write_opcode = EEPROM_WRITE_OPCODE_SPI;
4813 if(e1000_spi_eeprom_ready(hw)) return -E1000_ERR_EEPROM;
4815 e1000_standby_eeprom(hw);
4817 /* Send the WRITE ENABLE command (8 bit opcode ) */
4818 e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI,
4819 eeprom->opcode_bits);
4821 e1000_standby_eeprom(hw);
4823 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
4824 if((eeprom->address_bits == 8) && (offset >= 128))
4825 write_opcode |= EEPROM_A8_OPCODE_SPI;
4827 /* Send the Write command (8-bit opcode + addr) */
4828 e1000_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits);
4830 e1000_shift_out_ee_bits(hw, (uint16_t)((offset + widx)*2),
4831 eeprom->address_bits);
4835 /* Loop to allow for up to whole page write (32 bytes) of eeprom */
4836 while (widx < words) {
4837 uint16_t word_out = data[widx];
4838 word_out = (word_out >> 8) | (word_out << 8);
4839 e1000_shift_out_ee_bits(hw, word_out, 16);
4842 /* Some larger eeprom sizes are capable of a 32-byte PAGE WRITE
4843 * operation, while the smaller eeproms are capable of an 8-byte
4844 * PAGE WRITE operation. Break the inner loop to pass new address
4846 if((((offset + widx)*2) % eeprom->page_size) == 0) {
4847 e1000_standby_eeprom(hw);
4853 return E1000_SUCCESS;
4856 /******************************************************************************
4857 * Writes a 16 bit word to a given offset in a Microwire EEPROM.
4859 * hw - Struct containing variables accessed by shared code
4860 * offset - offset within the EEPROM to be written to
4861 * words - number of words to write
4862 * data - pointer to array of 16 bit words to be written to the EEPROM
4864 *****************************************************************************/
4866 e1000_write_eeprom_microwire(struct e1000_hw *hw,
4871 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4873 uint16_t words_written = 0;
4876 DEBUGFUNC("e1000_write_eeprom_microwire");
4878 /* Send the write enable command to the EEPROM (3-bit opcode plus
4879 * 6/8-bit dummy address beginning with 11). It's less work to include
4880 * the 11 of the dummy address as part of the opcode than it is to shift
4881 * it over the correct number of bits for the address. This puts the
4882 * EEPROM into write/erase mode.
4884 e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE,
4885 (uint16_t)(eeprom->opcode_bits + 2));
4887 e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
4889 /* Prepare the EEPROM */
4890 e1000_standby_eeprom(hw);
4892 while (words_written < words) {
4893 /* Send the Write command (3-bit opcode + addr) */
4894 e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE,
4895 eeprom->opcode_bits);
4897 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + words_written),
4898 eeprom->address_bits);
4901 e1000_shift_out_ee_bits(hw, data[words_written], 16);
4903 /* Toggle the CS line. This in effect tells the EEPROM to execute
4904 * the previous command.
4906 e1000_standby_eeprom(hw);
4908 /* Read DO repeatedly until it is high (equal to '1'). The EEPROM will
4909 * signal that the command has been completed by raising the DO signal.
4910 * If DO does not go high in 10 milliseconds, then error out.
4912 for(i = 0; i < 200; i++) {
4913 eecd = E1000_READ_REG(hw, EECD);
4914 if(eecd & E1000_EECD_DO) break;
4918 DEBUGOUT("EEPROM Write did not complete\n");
4919 return -E1000_ERR_EEPROM;
4922 /* Recover from write */
4923 e1000_standby_eeprom(hw);
4928 /* Send the write disable command to the EEPROM (3-bit opcode plus
4929 * 6/8-bit dummy address beginning with 10). It's less work to include
4930 * the 10 of the dummy address as part of the opcode than it is to shift
4931 * it over the correct number of bits for the address. This takes the
4932 * EEPROM out of write/erase mode.
4934 e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE,
4935 (uint16_t)(eeprom->opcode_bits + 2));
4937 e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
4939 return E1000_SUCCESS;
4942 /******************************************************************************
4943 * Flushes the cached eeprom to NVM. This is done by saving the modified values
4944 * in the eeprom cache and the non modified values in the currently active bank
4947 * hw - Struct containing variables accessed by shared code
4948 * offset - offset of word in the EEPROM to read
4949 * data - word read from the EEPROM
4950 * words - number of words to read
4951 *****************************************************************************/
4953 e1000_commit_shadow_ram(struct e1000_hw *hw)
4955 uint32_t attempts = 100000;
4959 int32_t error = E1000_SUCCESS;
4961 /* The flop register will be used to determine if flash type is STM */
4962 flop = E1000_READ_REG(hw, FLOP);
4964 if (hw->mac_type == e1000_82573) {
4965 for (i=0; i < attempts; i++) {
4966 eecd = E1000_READ_REG(hw, EECD);
4967 if ((eecd & E1000_EECD_FLUPD) == 0) {
4973 if (i == attempts) {
4974 return -E1000_ERR_EEPROM;
4977 /* If STM opcode located in bits 15:8 of flop, reset firmware */
4978 if ((flop & 0xFF00) == E1000_STM_OPCODE) {
4979 E1000_WRITE_REG(hw, HICR, E1000_HICR_FW_RESET);
4982 /* Perform the flash update */
4983 E1000_WRITE_REG(hw, EECD, eecd | E1000_EECD_FLUPD);
4985 for (i=0; i < attempts; i++) {
4986 eecd = E1000_READ_REG(hw, EECD);
4987 if ((eecd & E1000_EECD_FLUPD) == 0) {
4993 if (i == attempts) {
4994 return -E1000_ERR_EEPROM;
5001 /******************************************************************************
5002 * Reads the adapter's part number from the EEPROM
5004 * hw - Struct containing variables accessed by shared code
5005 * part_num - Adapter's part number
5006 *****************************************************************************/
5008 e1000_read_part_num(struct e1000_hw *hw,
5011 uint16_t offset = EEPROM_PBA_BYTE_1;
5012 uint16_t eeprom_data;
5014 DEBUGFUNC("e1000_read_part_num");
5016 /* Get word 0 from EEPROM */
5017 if(e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
5018 DEBUGOUT("EEPROM Read Error\n");
5019 return -E1000_ERR_EEPROM;
5021 /* Save word 0 in upper half of part_num */
5022 *part_num = (uint32_t) (eeprom_data << 16);
5024 /* Get word 1 from EEPROM */
5025 if(e1000_read_eeprom(hw, ++offset, 1, &eeprom_data) < 0) {
5026 DEBUGOUT("EEPROM Read Error\n");
5027 return -E1000_ERR_EEPROM;
5029 /* Save word 1 in lower half of part_num */
5030 *part_num |= eeprom_data;
5032 return E1000_SUCCESS;
5035 /******************************************************************************
5036 * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
5037 * second function of dual function devices
5039 * hw - Struct containing variables accessed by shared code
5040 *****************************************************************************/
5042 e1000_read_mac_addr(struct e1000_hw * hw)
5045 uint16_t eeprom_data, i;
5047 DEBUGFUNC("e1000_read_mac_addr");
5049 for(i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
5051 if(e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
5052 DEBUGOUT("EEPROM Read Error\n");
5053 return -E1000_ERR_EEPROM;
5055 hw->perm_mac_addr[i] = (uint8_t) (eeprom_data & 0x00FF);
5056 hw->perm_mac_addr[i+1] = (uint8_t) (eeprom_data >> 8);
5059 switch (hw->mac_type) {
5063 case e1000_82546_rev_3:
5065 case e1000_80003es2lan:
5066 if(E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
5067 hw->perm_mac_addr[5] ^= 0x01;
5071 for(i = 0; i < NODE_ADDRESS_SIZE; i++)
5072 hw->mac_addr[i] = hw->perm_mac_addr[i];
5073 return E1000_SUCCESS;
5076 /******************************************************************************
5077 * Initializes receive address filters.
5079 * hw - Struct containing variables accessed by shared code
5081 * Places the MAC address in receive address register 0 and clears the rest
5082 * of the receive addresss registers. Clears the multicast table. Assumes
5083 * the receiver is in reset when the routine is called.
5084 *****************************************************************************/
5086 e1000_init_rx_addrs(struct e1000_hw *hw)
5091 DEBUGFUNC("e1000_init_rx_addrs");
5093 /* Setup the receive address. */
5094 DEBUGOUT("Programming MAC Address into RAR[0]\n");
5096 e1000_rar_set(hw, hw->mac_addr, 0);
5098 rar_num = E1000_RAR_ENTRIES;
5100 /* Reserve a spot for the Locally Administered Address to work around
5101 * an 82571 issue in which a reset on one port will reload the MAC on
5102 * the other port. */
5103 if ((hw->mac_type == e1000_82571) && (hw->laa_is_present == TRUE))
5105 /* Zero out the other 15 receive addresses. */
5106 DEBUGOUT("Clearing RAR[1-15]\n");
5107 for(i = 1; i < rar_num; i++) {
5108 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
5109 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
5114 /******************************************************************************
5115 * Updates the MAC's list of multicast addresses.
5117 * hw - Struct containing variables accessed by shared code
5118 * mc_addr_list - the list of new multicast addresses
5119 * mc_addr_count - number of addresses
5120 * pad - number of bytes between addresses in the list
5121 * rar_used_count - offset where to start adding mc addresses into the RAR's
5123 * The given list replaces any existing list. Clears the last 15 receive
5124 * address registers and the multicast table. Uses receive address registers
5125 * for the first 15 multicast addresses, and hashes the rest into the
5127 *****************************************************************************/
5129 e1000_mc_addr_list_update(struct e1000_hw *hw,
5130 uint8_t *mc_addr_list,
5131 uint32_t mc_addr_count,
5133 uint32_t rar_used_count)
5135 uint32_t hash_value;
5137 uint32_t num_rar_entry;
5138 uint32_t num_mta_entry;
5140 DEBUGFUNC("e1000_mc_addr_list_update");
5142 /* Set the new number of MC addresses that we are being requested to use. */
5143 hw->num_mc_addrs = mc_addr_count;
5145 /* Clear RAR[1-15] */
5146 DEBUGOUT(" Clearing RAR[1-15]\n");
5147 num_rar_entry = E1000_RAR_ENTRIES;
5148 /* Reserve a spot for the Locally Administered Address to work around
5149 * an 82571 issue in which a reset on one port will reload the MAC on
5150 * the other port. */
5151 if ((hw->mac_type == e1000_82571) && (hw->laa_is_present == TRUE))
5154 for(i = rar_used_count; i < num_rar_entry; i++) {
5155 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
5156 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
5160 DEBUGOUT(" Clearing MTA\n");
5161 num_mta_entry = E1000_NUM_MTA_REGISTERS;
5162 for(i = 0; i < num_mta_entry; i++) {
5163 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
5166 /* Add the new addresses */
5167 for(i = 0; i < mc_addr_count; i++) {
5168 DEBUGOUT(" Adding the multicast addresses:\n");
5169 DEBUGOUT7(" MC Addr #%d =%.2X %.2X %.2X %.2X %.2X %.2X\n", i,
5170 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad)],
5171 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 1],
5172 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 2],
5173 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 3],
5174 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 4],
5175 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 5]);
5177 hash_value = e1000_hash_mc_addr(hw,
5179 (i * (ETH_LENGTH_OF_ADDRESS + pad)));
5181 DEBUGOUT1(" Hash value = 0x%03X\n", hash_value);
5183 /* Place this multicast address in the RAR if there is room, *
5184 * else put it in the MTA
5186 if (rar_used_count < num_rar_entry) {
5188 mc_addr_list + (i * (ETH_LENGTH_OF_ADDRESS + pad)),
5192 e1000_mta_set(hw, hash_value);
5195 DEBUGOUT("MC Update Complete\n");
5199 /******************************************************************************
5200 * Hashes an address to determine its location in the multicast table
5202 * hw - Struct containing variables accessed by shared code
5203 * mc_addr - the multicast address to hash
5204 *****************************************************************************/
5206 e1000_hash_mc_addr(struct e1000_hw *hw,
5209 uint32_t hash_value = 0;
5211 /* The portion of the address that is used for the hash table is
5212 * determined by the mc_filter_type setting.
5214 switch (hw->mc_filter_type) {
5215 /* [0] [1] [2] [3] [4] [5]
5220 /* [47:36] i.e. 0x563 for above example address */
5221 hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4));
5224 /* [46:35] i.e. 0xAC6 for above example address */
5225 hash_value = ((mc_addr[4] >> 3) | (((uint16_t) mc_addr[5]) << 5));
5228 /* [45:34] i.e. 0x5D8 for above example address */
5229 hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6));
5232 /* [43:32] i.e. 0x634 for above example address */
5233 hash_value = ((mc_addr[4]) | (((uint16_t) mc_addr[5]) << 8));
5237 hash_value &= 0xFFF;
5242 /******************************************************************************
5243 * Sets the bit in the multicast table corresponding to the hash value.
5245 * hw - Struct containing variables accessed by shared code
5246 * hash_value - Multicast address hash value
5247 *****************************************************************************/
5249 e1000_mta_set(struct e1000_hw *hw,
5250 uint32_t hash_value)
5252 uint32_t hash_bit, hash_reg;
5256 /* The MTA is a register array of 128 32-bit registers.
5257 * It is treated like an array of 4096 bits. We want to set
5258 * bit BitArray[hash_value]. So we figure out what register
5259 * the bit is in, read it, OR in the new bit, then write
5260 * back the new value. The register is determined by the
5261 * upper 7 bits of the hash value and the bit within that
5262 * register are determined by the lower 5 bits of the value.
5264 hash_reg = (hash_value >> 5) & 0x7F;
5265 hash_bit = hash_value & 0x1F;
5267 mta = E1000_READ_REG_ARRAY(hw, MTA, hash_reg);
5269 mta |= (1 << hash_bit);
5271 /* If we are on an 82544 and we are trying to write an odd offset
5272 * in the MTA, save off the previous entry before writing and
5273 * restore the old value after writing.
5275 if((hw->mac_type == e1000_82544) && ((hash_reg & 0x1) == 1)) {
5276 temp = E1000_READ_REG_ARRAY(hw, MTA, (hash_reg - 1));
5277 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
5278 E1000_WRITE_REG_ARRAY(hw, MTA, (hash_reg - 1), temp);
5280 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
5284 /******************************************************************************
5285 * Puts an ethernet address into a receive address register.
5287 * hw - Struct containing variables accessed by shared code
5288 * addr - Address to put into receive address register
5289 * index - Receive address register to write
5290 *****************************************************************************/
5292 e1000_rar_set(struct e1000_hw *hw,
5296 uint32_t rar_low, rar_high;
5298 /* HW expects these in little endian so we reverse the byte order
5299 * from network order (big endian) to little endian
5301 rar_low = ((uint32_t) addr[0] |
5302 ((uint32_t) addr[1] << 8) |
5303 ((uint32_t) addr[2] << 16) | ((uint32_t) addr[3] << 24));
5304 rar_high = ((uint32_t) addr[4] | ((uint32_t) addr[5] << 8));
5306 /* Disable Rx and flush all Rx frames before enabling RSS to avoid Rx
5310 * If there are any Rx frames queued up or otherwise present in the HW
5311 * before RSS is enabled, and then we enable RSS, the HW Rx unit will
5312 * hang. To work around this issue, we have to disable receives and
5313 * flush out all Rx frames before we enable RSS. To do so, we modify we
5314 * redirect all Rx traffic to manageability and then reset the HW.
5315 * This flushes away Rx frames, and (since the redirections to
5316 * manageability persists across resets) keeps new ones from coming in
5317 * while we work. Then, we clear the Address Valid AV bit for all MAC
5318 * addresses and undo the re-direction to manageability.
5319 * Now, frames are coming in again, but the MAC won't accept them, so
5320 * far so good. We now proceed to initialize RSS (if necessary) and
5321 * configure the Rx unit. Last, we re-enable the AV bits and continue
5324 switch (hw->mac_type) {
5327 case e1000_80003es2lan:
5328 if (hw->leave_av_bit_off == TRUE)
5331 /* Indicate to hardware the Address is Valid. */
5332 rar_high |= E1000_RAH_AV;
5336 E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
5337 E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
5340 /******************************************************************************
5341 * Writes a value to the specified offset in the VLAN filter table.
5343 * hw - Struct containing variables accessed by shared code
5344 * offset - Offset in VLAN filer table to write
5345 * value - Value to write into VLAN filter table
5346 *****************************************************************************/
5348 e1000_write_vfta(struct e1000_hw *hw,
5354 if((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) {
5355 temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1));
5356 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
5357 E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp);
5359 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
5363 /******************************************************************************
5364 * Clears the VLAN filer table
5366 * hw - Struct containing variables accessed by shared code
5367 *****************************************************************************/
5369 e1000_clear_vfta(struct e1000_hw *hw)
5372 uint32_t vfta_value = 0;
5373 uint32_t vfta_offset = 0;
5374 uint32_t vfta_bit_in_reg = 0;
5376 if (hw->mac_type == e1000_82573) {
5377 if (hw->mng_cookie.vlan_id != 0) {
5378 /* The VFTA is a 4096b bit-field, each identifying a single VLAN
5379 * ID. The following operations determine which 32b entry
5380 * (i.e. offset) into the array we want to set the VLAN ID
5381 * (i.e. bit) of the manageability unit. */
5382 vfta_offset = (hw->mng_cookie.vlan_id >>
5383 E1000_VFTA_ENTRY_SHIFT) &
5384 E1000_VFTA_ENTRY_MASK;
5385 vfta_bit_in_reg = 1 << (hw->mng_cookie.vlan_id &
5386 E1000_VFTA_ENTRY_BIT_SHIFT_MASK);
5389 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
5390 /* If the offset we want to clear is the same offset of the
5391 * manageability VLAN ID, then clear all bits except that of the
5392 * manageability unit */
5393 vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0;
5394 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, vfta_value);
5399 e1000_id_led_init(struct e1000_hw * hw)
5402 const uint32_t ledctl_mask = 0x000000FF;
5403 const uint32_t ledctl_on = E1000_LEDCTL_MODE_LED_ON;
5404 const uint32_t ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
5405 uint16_t eeprom_data, i, temp;
5406 const uint16_t led_mask = 0x0F;
5408 DEBUGFUNC("e1000_id_led_init");
5410 if(hw->mac_type < e1000_82540) {
5412 return E1000_SUCCESS;
5415 ledctl = E1000_READ_REG(hw, LEDCTL);
5416 hw->ledctl_default = ledctl;
5417 hw->ledctl_mode1 = hw->ledctl_default;
5418 hw->ledctl_mode2 = hw->ledctl_default;
5420 if(e1000_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, 1, &eeprom_data) < 0) {
5421 DEBUGOUT("EEPROM Read Error\n");
5422 return -E1000_ERR_EEPROM;
5424 if((eeprom_data== ID_LED_RESERVED_0000) ||
5425 (eeprom_data == ID_LED_RESERVED_FFFF)) eeprom_data = ID_LED_DEFAULT;
5426 for(i = 0; i < 4; i++) {
5427 temp = (eeprom_data >> (i << 2)) & led_mask;
5429 case ID_LED_ON1_DEF2:
5430 case ID_LED_ON1_ON2:
5431 case ID_LED_ON1_OFF2:
5432 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
5433 hw->ledctl_mode1 |= ledctl_on << (i << 3);
5435 case ID_LED_OFF1_DEF2:
5436 case ID_LED_OFF1_ON2:
5437 case ID_LED_OFF1_OFF2:
5438 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
5439 hw->ledctl_mode1 |= ledctl_off << (i << 3);
5446 case ID_LED_DEF1_ON2:
5447 case ID_LED_ON1_ON2:
5448 case ID_LED_OFF1_ON2:
5449 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
5450 hw->ledctl_mode2 |= ledctl_on << (i << 3);
5452 case ID_LED_DEF1_OFF2:
5453 case ID_LED_ON1_OFF2:
5454 case ID_LED_OFF1_OFF2:
5455 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
5456 hw->ledctl_mode2 |= ledctl_off << (i << 3);
5463 return E1000_SUCCESS;
5466 /******************************************************************************
5467 * Prepares SW controlable LED for use and saves the current state of the LED.
5469 * hw - Struct containing variables accessed by shared code
5470 *****************************************************************************/
5472 e1000_setup_led(struct e1000_hw *hw)
5475 int32_t ret_val = E1000_SUCCESS;
5477 DEBUGFUNC("e1000_setup_led");
5479 switch(hw->mac_type) {
5480 case e1000_82542_rev2_0:
5481 case e1000_82542_rev2_1:
5484 /* No setup necessary */
5488 case e1000_82541_rev_2:
5489 case e1000_82547_rev_2:
5490 /* Turn off PHY Smart Power Down (if enabled) */
5491 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
5492 &hw->phy_spd_default);
5495 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
5496 (uint16_t)(hw->phy_spd_default &
5497 ~IGP01E1000_GMII_SPD));
5502 if(hw->media_type == e1000_media_type_fiber) {
5503 ledctl = E1000_READ_REG(hw, LEDCTL);
5504 /* Save current LEDCTL settings */
5505 hw->ledctl_default = ledctl;
5507 ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
5508 E1000_LEDCTL_LED0_BLINK |
5509 E1000_LEDCTL_LED0_MODE_MASK);
5510 ledctl |= (E1000_LEDCTL_MODE_LED_OFF <<
5511 E1000_LEDCTL_LED0_MODE_SHIFT);
5512 E1000_WRITE_REG(hw, LEDCTL, ledctl);
5513 } else if(hw->media_type == e1000_media_type_copper)
5514 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
5518 return E1000_SUCCESS;
5521 /******************************************************************************
5522 * Restores the saved state of the SW controlable LED.
5524 * hw - Struct containing variables accessed by shared code
5525 *****************************************************************************/
5527 e1000_cleanup_led(struct e1000_hw *hw)
5529 int32_t ret_val = E1000_SUCCESS;
5531 DEBUGFUNC("e1000_cleanup_led");
5533 switch(hw->mac_type) {
5534 case e1000_82542_rev2_0:
5535 case e1000_82542_rev2_1:
5538 /* No cleanup necessary */
5542 case e1000_82541_rev_2:
5543 case e1000_82547_rev_2:
5544 /* Turn on PHY Smart Power Down (if previously enabled) */
5545 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
5546 hw->phy_spd_default);
5551 /* Restore LEDCTL settings */
5552 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_default);
5556 return E1000_SUCCESS;
5559 /******************************************************************************
5560 * Turns on the software controllable LED
5562 * hw - Struct containing variables accessed by shared code
5563 *****************************************************************************/
5565 e1000_led_on(struct e1000_hw *hw)
5567 uint32_t ctrl = E1000_READ_REG(hw, CTRL);
5569 DEBUGFUNC("e1000_led_on");
5571 switch(hw->mac_type) {
5572 case e1000_82542_rev2_0:
5573 case e1000_82542_rev2_1:
5575 /* Set SW Defineable Pin 0 to turn on the LED */
5576 ctrl |= E1000_CTRL_SWDPIN0;
5577 ctrl |= E1000_CTRL_SWDPIO0;
5580 if(hw->media_type == e1000_media_type_fiber) {
5581 /* Set SW Defineable Pin 0 to turn on the LED */
5582 ctrl |= E1000_CTRL_SWDPIN0;
5583 ctrl |= E1000_CTRL_SWDPIO0;
5585 /* Clear SW Defineable Pin 0 to turn on the LED */
5586 ctrl &= ~E1000_CTRL_SWDPIN0;
5587 ctrl |= E1000_CTRL_SWDPIO0;
5591 if(hw->media_type == e1000_media_type_fiber) {
5592 /* Clear SW Defineable Pin 0 to turn on the LED */
5593 ctrl &= ~E1000_CTRL_SWDPIN0;
5594 ctrl |= E1000_CTRL_SWDPIO0;
5595 } else if(hw->media_type == e1000_media_type_copper) {
5596 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode2);
5597 return E1000_SUCCESS;
5602 E1000_WRITE_REG(hw, CTRL, ctrl);
5604 return E1000_SUCCESS;
5607 /******************************************************************************
5608 * Turns off the software controllable LED
5610 * hw - Struct containing variables accessed by shared code
5611 *****************************************************************************/
5613 e1000_led_off(struct e1000_hw *hw)
5615 uint32_t ctrl = E1000_READ_REG(hw, CTRL);
5617 DEBUGFUNC("e1000_led_off");
5619 switch(hw->mac_type) {
5620 case e1000_82542_rev2_0:
5621 case e1000_82542_rev2_1:
5623 /* Clear SW Defineable Pin 0 to turn off the LED */
5624 ctrl &= ~E1000_CTRL_SWDPIN0;
5625 ctrl |= E1000_CTRL_SWDPIO0;
5628 if(hw->media_type == e1000_media_type_fiber) {
5629 /* Clear SW Defineable Pin 0 to turn off the LED */
5630 ctrl &= ~E1000_CTRL_SWDPIN0;
5631 ctrl |= E1000_CTRL_SWDPIO0;
5633 /* Set SW Defineable Pin 0 to turn off the LED */
5634 ctrl |= E1000_CTRL_SWDPIN0;
5635 ctrl |= E1000_CTRL_SWDPIO0;
5639 if(hw->media_type == e1000_media_type_fiber) {
5640 /* Set SW Defineable Pin 0 to turn off the LED */
5641 ctrl |= E1000_CTRL_SWDPIN0;
5642 ctrl |= E1000_CTRL_SWDPIO0;
5643 } else if(hw->media_type == e1000_media_type_copper) {
5644 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
5645 return E1000_SUCCESS;
5650 E1000_WRITE_REG(hw, CTRL, ctrl);
5652 return E1000_SUCCESS;
5655 /******************************************************************************
5656 * Clears all hardware statistics counters.
5658 * hw - Struct containing variables accessed by shared code
5659 *****************************************************************************/
5661 e1000_clear_hw_cntrs(struct e1000_hw *hw)
5663 volatile uint32_t temp;
5665 temp = E1000_READ_REG(hw, CRCERRS);
5666 temp = E1000_READ_REG(hw, SYMERRS);
5667 temp = E1000_READ_REG(hw, MPC);
5668 temp = E1000_READ_REG(hw, SCC);
5669 temp = E1000_READ_REG(hw, ECOL);
5670 temp = E1000_READ_REG(hw, MCC);
5671 temp = E1000_READ_REG(hw, LATECOL);
5672 temp = E1000_READ_REG(hw, COLC);
5673 temp = E1000_READ_REG(hw, DC);
5674 temp = E1000_READ_REG(hw, SEC);
5675 temp = E1000_READ_REG(hw, RLEC);
5676 temp = E1000_READ_REG(hw, XONRXC);
5677 temp = E1000_READ_REG(hw, XONTXC);
5678 temp = E1000_READ_REG(hw, XOFFRXC);
5679 temp = E1000_READ_REG(hw, XOFFTXC);
5680 temp = E1000_READ_REG(hw, FCRUC);
5681 temp = E1000_READ_REG(hw, PRC64);
5682 temp = E1000_READ_REG(hw, PRC127);
5683 temp = E1000_READ_REG(hw, PRC255);
5684 temp = E1000_READ_REG(hw, PRC511);
5685 temp = E1000_READ_REG(hw, PRC1023);
5686 temp = E1000_READ_REG(hw, PRC1522);
5687 temp = E1000_READ_REG(hw, GPRC);
5688 temp = E1000_READ_REG(hw, BPRC);
5689 temp = E1000_READ_REG(hw, MPRC);
5690 temp = E1000_READ_REG(hw, GPTC);
5691 temp = E1000_READ_REG(hw, GORCL);
5692 temp = E1000_READ_REG(hw, GORCH);
5693 temp = E1000_READ_REG(hw, GOTCL);
5694 temp = E1000_READ_REG(hw, GOTCH);
5695 temp = E1000_READ_REG(hw, RNBC);
5696 temp = E1000_READ_REG(hw, RUC);
5697 temp = E1000_READ_REG(hw, RFC);
5698 temp = E1000_READ_REG(hw, ROC);
5699 temp = E1000_READ_REG(hw, RJC);
5700 temp = E1000_READ_REG(hw, TORL);
5701 temp = E1000_READ_REG(hw, TORH);
5702 temp = E1000_READ_REG(hw, TOTL);
5703 temp = E1000_READ_REG(hw, TOTH);
5704 temp = E1000_READ_REG(hw, TPR);
5705 temp = E1000_READ_REG(hw, TPT);
5706 temp = E1000_READ_REG(hw, PTC64);
5707 temp = E1000_READ_REG(hw, PTC127);
5708 temp = E1000_READ_REG(hw, PTC255);
5709 temp = E1000_READ_REG(hw, PTC511);
5710 temp = E1000_READ_REG(hw, PTC1023);
5711 temp = E1000_READ_REG(hw, PTC1522);
5712 temp = E1000_READ_REG(hw, MPTC);
5713 temp = E1000_READ_REG(hw, BPTC);
5715 if(hw->mac_type < e1000_82543) return;
5717 temp = E1000_READ_REG(hw, ALGNERRC);
5718 temp = E1000_READ_REG(hw, RXERRC);
5719 temp = E1000_READ_REG(hw, TNCRS);
5720 temp = E1000_READ_REG(hw, CEXTERR);
5721 temp = E1000_READ_REG(hw, TSCTC);
5722 temp = E1000_READ_REG(hw, TSCTFC);
5724 if(hw->mac_type <= e1000_82544) return;
5726 temp = E1000_READ_REG(hw, MGTPRC);
5727 temp = E1000_READ_REG(hw, MGTPDC);
5728 temp = E1000_READ_REG(hw, MGTPTC);
5730 if(hw->mac_type <= e1000_82547_rev_2) return;
5732 temp = E1000_READ_REG(hw, IAC);
5733 temp = E1000_READ_REG(hw, ICRXOC);
5734 temp = E1000_READ_REG(hw, ICRXPTC);
5735 temp = E1000_READ_REG(hw, ICRXATC);
5736 temp = E1000_READ_REG(hw, ICTXPTC);
5737 temp = E1000_READ_REG(hw, ICTXATC);
5738 temp = E1000_READ_REG(hw, ICTXQEC);
5739 temp = E1000_READ_REG(hw, ICTXQMTC);
5740 temp = E1000_READ_REG(hw, ICRXDMTC);
5743 /******************************************************************************
5744 * Resets Adaptive IFS to its default state.
5746 * hw - Struct containing variables accessed by shared code
5748 * Call this after e1000_init_hw. You may override the IFS defaults by setting
5749 * hw->ifs_params_forced to TRUE. However, you must initialize hw->
5750 * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio
5751 * before calling this function.
5752 *****************************************************************************/
5754 e1000_reset_adaptive(struct e1000_hw *hw)
5756 DEBUGFUNC("e1000_reset_adaptive");
5758 if(hw->adaptive_ifs) {
5759 if(!hw->ifs_params_forced) {
5760 hw->current_ifs_val = 0;
5761 hw->ifs_min_val = IFS_MIN;
5762 hw->ifs_max_val = IFS_MAX;
5763 hw->ifs_step_size = IFS_STEP;
5764 hw->ifs_ratio = IFS_RATIO;
5766 hw->in_ifs_mode = FALSE;
5767 E1000_WRITE_REG(hw, AIT, 0);
5769 DEBUGOUT("Not in Adaptive IFS mode!\n");
5773 /******************************************************************************
5774 * Called during the callback/watchdog routine to update IFS value based on
5775 * the ratio of transmits to collisions.
5777 * hw - Struct containing variables accessed by shared code
5778 * tx_packets - Number of transmits since last callback
5779 * total_collisions - Number of collisions since last callback
5780 *****************************************************************************/
5782 e1000_update_adaptive(struct e1000_hw *hw)
5784 DEBUGFUNC("e1000_update_adaptive");
5786 if(hw->adaptive_ifs) {
5787 if((hw->collision_delta * hw->ifs_ratio) > hw->tx_packet_delta) {
5788 if(hw->tx_packet_delta > MIN_NUM_XMITS) {
5789 hw->in_ifs_mode = TRUE;
5790 if(hw->current_ifs_val < hw->ifs_max_val) {
5791 if(hw->current_ifs_val == 0)
5792 hw->current_ifs_val = hw->ifs_min_val;
5794 hw->current_ifs_val += hw->ifs_step_size;
5795 E1000_WRITE_REG(hw, AIT, hw->current_ifs_val);
5799 if(hw->in_ifs_mode && (hw->tx_packet_delta <= MIN_NUM_XMITS)) {
5800 hw->current_ifs_val = 0;
5801 hw->in_ifs_mode = FALSE;
5802 E1000_WRITE_REG(hw, AIT, 0);
5806 DEBUGOUT("Not in Adaptive IFS mode!\n");
5810 /******************************************************************************
5811 * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT
5813 * hw - Struct containing variables accessed by shared code
5814 * frame_len - The length of the frame in question
5815 * mac_addr - The Ethernet destination address of the frame in question
5816 *****************************************************************************/
5818 e1000_tbi_adjust_stats(struct e1000_hw *hw,
5819 struct e1000_hw_stats *stats,
5825 /* First adjust the frame length. */
5827 /* We need to adjust the statistics counters, since the hardware
5828 * counters overcount this packet as a CRC error and undercount
5829 * the packet as a good packet
5831 /* This packet should not be counted as a CRC error. */
5833 /* This packet does count as a Good Packet Received. */
5836 /* Adjust the Good Octets received counters */
5837 carry_bit = 0x80000000 & stats->gorcl;
5838 stats->gorcl += frame_len;
5839 /* If the high bit of Gorcl (the low 32 bits of the Good Octets
5840 * Received Count) was one before the addition,
5841 * AND it is zero after, then we lost the carry out,
5842 * need to add one to Gorch (Good Octets Received Count High).
5843 * This could be simplified if all environments supported
5846 if(carry_bit && ((stats->gorcl & 0x80000000) == 0))
5848 /* Is this a broadcast or multicast? Check broadcast first,
5849 * since the test for a multicast frame will test positive on
5850 * a broadcast frame.
5852 if((mac_addr[0] == (uint8_t) 0xff) && (mac_addr[1] == (uint8_t) 0xff))
5853 /* Broadcast packet */
5855 else if(*mac_addr & 0x01)
5856 /* Multicast packet */
5859 if(frame_len == hw->max_frame_size) {
5860 /* In this case, the hardware has overcounted the number of
5867 /* Adjust the bin counters when the extra byte put the frame in the
5868 * wrong bin. Remember that the frame_len was adjusted above.
5870 if(frame_len == 64) {
5873 } else if(frame_len == 127) {
5876 } else if(frame_len == 255) {
5879 } else if(frame_len == 511) {
5882 } else if(frame_len == 1023) {
5885 } else if(frame_len == 1522) {
5890 /******************************************************************************
5891 * Gets the current PCI bus type, speed, and width of the hardware
5893 * hw - Struct containing variables accessed by shared code
5894 *****************************************************************************/
5896 e1000_get_bus_info(struct e1000_hw *hw)
5900 switch (hw->mac_type) {
5901 case e1000_82542_rev2_0:
5902 case e1000_82542_rev2_1:
5903 hw->bus_type = e1000_bus_type_unknown;
5904 hw->bus_speed = e1000_bus_speed_unknown;
5905 hw->bus_width = e1000_bus_width_unknown;
5909 hw->bus_type = e1000_bus_type_pci_express;
5910 hw->bus_speed = e1000_bus_speed_2500;
5911 hw->bus_width = e1000_bus_width_pciex_1;
5914 case e1000_80003es2lan:
5915 hw->bus_type = e1000_bus_type_pci_express;
5916 hw->bus_speed = e1000_bus_speed_2500;
5917 hw->bus_width = e1000_bus_width_pciex_4;
5920 status = E1000_READ_REG(hw, STATUS);
5921 hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
5922 e1000_bus_type_pcix : e1000_bus_type_pci;
5924 if(hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) {
5925 hw->bus_speed = (hw->bus_type == e1000_bus_type_pci) ?
5926 e1000_bus_speed_66 : e1000_bus_speed_120;
5927 } else if(hw->bus_type == e1000_bus_type_pci) {
5928 hw->bus_speed = (status & E1000_STATUS_PCI66) ?
5929 e1000_bus_speed_66 : e1000_bus_speed_33;
5931 switch (status & E1000_STATUS_PCIX_SPEED) {
5932 case E1000_STATUS_PCIX_SPEED_66:
5933 hw->bus_speed = e1000_bus_speed_66;
5935 case E1000_STATUS_PCIX_SPEED_100:
5936 hw->bus_speed = e1000_bus_speed_100;
5938 case E1000_STATUS_PCIX_SPEED_133:
5939 hw->bus_speed = e1000_bus_speed_133;
5942 hw->bus_speed = e1000_bus_speed_reserved;
5946 hw->bus_width = (status & E1000_STATUS_BUS64) ?
5947 e1000_bus_width_64 : e1000_bus_width_32;
5953 /******************************************************************************
5954 * Reads a value from one of the devices registers using port I/O (as opposed
5955 * memory mapped I/O). Only 82544 and newer devices support port I/O.
5957 * hw - Struct containing variables accessed by shared code
5958 * offset - offset to read from
5959 *****************************************************************************/
5961 e1000_read_reg_io(struct e1000_hw *hw,
5964 unsigned long io_addr = hw->io_base;
5965 unsigned long io_data = hw->io_base + 4;
5967 e1000_io_write(hw, io_addr, offset);
5968 return e1000_io_read(hw, io_data);
5972 /******************************************************************************
5973 * Writes a value to one of the devices registers using port I/O (as opposed to
5974 * memory mapped I/O). Only 82544 and newer devices support port I/O.
5976 * hw - Struct containing variables accessed by shared code
5977 * offset - offset to write to
5978 * value - value to write
5979 *****************************************************************************/
5981 e1000_write_reg_io(struct e1000_hw *hw,
5985 unsigned long io_addr = hw->io_base;
5986 unsigned long io_data = hw->io_base + 4;
5988 e1000_io_write(hw, io_addr, offset);
5989 e1000_io_write(hw, io_data, value);
5993 /******************************************************************************
5994 * Estimates the cable length.
5996 * hw - Struct containing variables accessed by shared code
5997 * min_length - The estimated minimum length
5998 * max_length - The estimated maximum length
6000 * returns: - E1000_ERR_XXX
6003 * This function always returns a ranged length (minimum & maximum).
6004 * So for M88 phy's, this function interprets the one value returned from the
6005 * register to the minimum and maximum range.
6006 * For IGP phy's, the function calculates the range by the AGC registers.
6007 *****************************************************************************/
6009 e1000_get_cable_length(struct e1000_hw *hw,
6010 uint16_t *min_length,
6011 uint16_t *max_length)
6014 uint16_t agc_value = 0;
6015 uint16_t cur_agc, min_agc = IGP01E1000_AGC_LENGTH_TABLE_SIZE;
6016 uint16_t max_agc = 0;
6017 uint16_t i, phy_data;
6018 uint16_t cable_length;
6020 DEBUGFUNC("e1000_get_cable_length");
6022 *min_length = *max_length = 0;
6024 /* Use old method for Phy older than IGP */
6025 if(hw->phy_type == e1000_phy_m88) {
6027 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6031 cable_length = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
6032 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
6034 /* Convert the enum value to ranged values */
6035 switch (cable_length) {
6036 case e1000_cable_length_50:
6038 *max_length = e1000_igp_cable_length_50;
6040 case e1000_cable_length_50_80:
6041 *min_length = e1000_igp_cable_length_50;
6042 *max_length = e1000_igp_cable_length_80;
6044 case e1000_cable_length_80_110:
6045 *min_length = e1000_igp_cable_length_80;
6046 *max_length = e1000_igp_cable_length_110;
6048 case e1000_cable_length_110_140:
6049 *min_length = e1000_igp_cable_length_110;
6050 *max_length = e1000_igp_cable_length_140;
6052 case e1000_cable_length_140:
6053 *min_length = e1000_igp_cable_length_140;
6054 *max_length = e1000_igp_cable_length_170;
6057 return -E1000_ERR_PHY;
6060 } else if (hw->phy_type == e1000_phy_gg82563) {
6061 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_DSP_DISTANCE,
6065 cable_length = phy_data & GG82563_DSPD_CABLE_LENGTH;
6067 switch (cable_length) {
6068 case e1000_gg_cable_length_60:
6070 *max_length = e1000_igp_cable_length_60;
6072 case e1000_gg_cable_length_60_115:
6073 *min_length = e1000_igp_cable_length_60;
6074 *max_length = e1000_igp_cable_length_115;
6076 case e1000_gg_cable_length_115_150:
6077 *min_length = e1000_igp_cable_length_115;
6078 *max_length = e1000_igp_cable_length_150;
6080 case e1000_gg_cable_length_150:
6081 *min_length = e1000_igp_cable_length_150;
6082 *max_length = e1000_igp_cable_length_180;
6085 return -E1000_ERR_PHY;
6088 } else if(hw->phy_type == e1000_phy_igp) { /* For IGP PHY */
6089 uint16_t agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
6090 {IGP01E1000_PHY_AGC_A,
6091 IGP01E1000_PHY_AGC_B,
6092 IGP01E1000_PHY_AGC_C,
6093 IGP01E1000_PHY_AGC_D};
6094 /* Read the AGC registers for all channels */
6095 for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
6097 ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
6101 cur_agc = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT;
6103 /* Array bound check. */
6104 if((cur_agc >= IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1) ||
6106 return -E1000_ERR_PHY;
6108 agc_value += cur_agc;
6110 /* Update minimal AGC value. */
6111 if(min_agc > cur_agc)
6115 /* Remove the minimal AGC result for length < 50m */
6116 if(agc_value < IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) {
6117 agc_value -= min_agc;
6119 /* Get the average length of the remaining 3 channels */
6120 agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1);
6122 /* Get the average length of all the 4 channels. */
6123 agc_value /= IGP01E1000_PHY_CHANNEL_NUM;
6126 /* Set the range of the calculated length. */
6127 *min_length = ((e1000_igp_cable_length_table[agc_value] -
6128 IGP01E1000_AGC_RANGE) > 0) ?
6129 (e1000_igp_cable_length_table[agc_value] -
6130 IGP01E1000_AGC_RANGE) : 0;
6131 *max_length = e1000_igp_cable_length_table[agc_value] +
6132 IGP01E1000_AGC_RANGE;
6133 } else if (hw->phy_type == e1000_phy_igp_2) {
6134 uint16_t agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] =
6135 {IGP02E1000_PHY_AGC_A,
6136 IGP02E1000_PHY_AGC_B,
6137 IGP02E1000_PHY_AGC_C,
6138 IGP02E1000_PHY_AGC_D};
6139 /* Read the AGC registers for all channels */
6140 for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
6141 ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
6145 /* Getting bits 15:9, which represent the combination of course and
6146 * fine gain values. The result is a number that can be put into
6147 * the lookup table to obtain the approximate cable length. */
6148 cur_agc = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
6149 IGP02E1000_AGC_LENGTH_MASK;
6151 /* Remove min & max AGC values from calculation. */
6152 if (e1000_igp_2_cable_length_table[min_agc] > e1000_igp_2_cable_length_table[cur_agc])
6154 if (e1000_igp_2_cable_length_table[max_agc] < e1000_igp_2_cable_length_table[cur_agc])
6157 agc_value += e1000_igp_2_cable_length_table[cur_agc];
6160 agc_value -= (e1000_igp_2_cable_length_table[min_agc] + e1000_igp_2_cable_length_table[max_agc]);
6161 agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
6163 /* Calculate cable length with the error range of +/- 10 meters. */
6164 *min_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
6165 (agc_value - IGP02E1000_AGC_RANGE) : 0;
6166 *max_length = agc_value + IGP02E1000_AGC_RANGE;
6169 return E1000_SUCCESS;
6172 /******************************************************************************
6173 * Check the cable polarity
6175 * hw - Struct containing variables accessed by shared code
6176 * polarity - output parameter : 0 - Polarity is not reversed
6177 * 1 - Polarity is reversed.
6179 * returns: - E1000_ERR_XXX
6182 * For phy's older then IGP, this function simply reads the polarity bit in the
6183 * Phy Status register. For IGP phy's, this bit is valid only if link speed is
6184 * 10 Mbps. If the link speed is 100 Mbps there is no polarity so this bit will
6185 * return 0. If the link speed is 1000 Mbps the polarity status is in the
6186 * IGP01E1000_PHY_PCS_INIT_REG.
6187 *****************************************************************************/
6189 e1000_check_polarity(struct e1000_hw *hw,
6195 DEBUGFUNC("e1000_check_polarity");
6197 if ((hw->phy_type == e1000_phy_m88) ||
6198 (hw->phy_type == e1000_phy_gg82563)) {
6199 /* return the Polarity bit in the Status register. */
6200 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6204 *polarity = (phy_data & M88E1000_PSSR_REV_POLARITY) >>
6205 M88E1000_PSSR_REV_POLARITY_SHIFT;
6206 } else if(hw->phy_type == e1000_phy_igp ||
6207 hw->phy_type == e1000_phy_igp_2) {
6208 /* Read the Status register to check the speed */
6209 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
6214 /* If speed is 1000 Mbps, must read the IGP01E1000_PHY_PCS_INIT_REG to
6215 * find the polarity status */
6216 if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
6217 IGP01E1000_PSSR_SPEED_1000MBPS) {
6219 /* Read the GIG initialization PCS register (0x00B4) */
6220 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG,
6225 /* Check the polarity bits */
6226 *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ? 1 : 0;
6228 /* For 10 Mbps, read the polarity bit in the status register. (for
6229 * 100 Mbps this bit is always 0) */
6230 *polarity = phy_data & IGP01E1000_PSSR_POLARITY_REVERSED;
6233 return E1000_SUCCESS;
6236 /******************************************************************************
6237 * Check if Downshift occured
6239 * hw - Struct containing variables accessed by shared code
6240 * downshift - output parameter : 0 - No Downshift ocured.
6241 * 1 - Downshift ocured.
6243 * returns: - E1000_ERR_XXX
6246 * For phy's older then IGP, this function reads the Downshift bit in the Phy
6247 * Specific Status register. For IGP phy's, it reads the Downgrade bit in the
6248 * Link Health register. In IGP this bit is latched high, so the driver must
6249 * read it immediately after link is established.
6250 *****************************************************************************/
6252 e1000_check_downshift(struct e1000_hw *hw)
6257 DEBUGFUNC("e1000_check_downshift");
6259 if(hw->phy_type == e1000_phy_igp ||
6260 hw->phy_type == e1000_phy_igp_2) {
6261 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH,
6266 hw->speed_downgraded = (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0;
6267 } else if ((hw->phy_type == e1000_phy_m88) ||
6268 (hw->phy_type == e1000_phy_gg82563)) {
6269 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6274 hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >>
6275 M88E1000_PSSR_DOWNSHIFT_SHIFT;
6278 return E1000_SUCCESS;
6281 /*****************************************************************************
6283 * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a
6284 * gigabit link is achieved to improve link quality.
6286 * hw: Struct containing variables accessed by shared code
6288 * returns: - E1000_ERR_PHY if fail to read/write the PHY
6289 * E1000_SUCCESS at any other case.
6291 ****************************************************************************/
6294 e1000_config_dsp_after_link_change(struct e1000_hw *hw,
6298 uint16_t phy_data, phy_saved_data, speed, duplex, i;
6299 uint16_t dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
6300 {IGP01E1000_PHY_AGC_PARAM_A,
6301 IGP01E1000_PHY_AGC_PARAM_B,
6302 IGP01E1000_PHY_AGC_PARAM_C,
6303 IGP01E1000_PHY_AGC_PARAM_D};
6304 uint16_t min_length, max_length;
6306 DEBUGFUNC("e1000_config_dsp_after_link_change");
6308 if(hw->phy_type != e1000_phy_igp)
6309 return E1000_SUCCESS;
6312 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
6314 DEBUGOUT("Error getting link speed and duplex\n");
6318 if(speed == SPEED_1000) {
6320 e1000_get_cable_length(hw, &min_length, &max_length);
6322 if((hw->dsp_config_state == e1000_dsp_config_enabled) &&
6323 min_length >= e1000_igp_cable_length_50) {
6325 for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
6326 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i],
6331 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
6333 ret_val = e1000_write_phy_reg(hw, dsp_reg_array[i],
6338 hw->dsp_config_state = e1000_dsp_config_activated;
6341 if((hw->ffe_config_state == e1000_ffe_config_enabled) &&
6342 (min_length < e1000_igp_cable_length_50)) {
6344 uint16_t ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_20;
6345 uint32_t idle_errs = 0;
6347 /* clear previous idle error counts */
6348 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
6353 for(i = 0; i < ffe_idle_err_timeout; i++) {
6355 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
6360 idle_errs += (phy_data & SR_1000T_IDLE_ERROR_CNT);
6361 if(idle_errs > SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT) {
6362 hw->ffe_config_state = e1000_ffe_config_active;
6364 ret_val = e1000_write_phy_reg(hw,
6365 IGP01E1000_PHY_DSP_FFE,
6366 IGP01E1000_PHY_DSP_FFE_CM_CP);
6373 ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_100;
6378 if(hw->dsp_config_state == e1000_dsp_config_activated) {
6379 /* Save off the current value of register 0x2F5B to be restored at
6380 * the end of the routines. */
6381 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
6386 /* Disable the PHY transmitter */
6387 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
6394 ret_val = e1000_write_phy_reg(hw, 0x0000,
6395 IGP01E1000_IEEE_FORCE_GIGA);
6398 for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
6399 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i], &phy_data);
6403 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
6404 phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS;
6406 ret_val = e1000_write_phy_reg(hw,dsp_reg_array[i], phy_data);
6411 ret_val = e1000_write_phy_reg(hw, 0x0000,
6412 IGP01E1000_IEEE_RESTART_AUTONEG);
6418 /* Now enable the transmitter */
6419 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
6424 hw->dsp_config_state = e1000_dsp_config_enabled;
6427 if(hw->ffe_config_state == e1000_ffe_config_active) {
6428 /* Save off the current value of register 0x2F5B to be restored at
6429 * the end of the routines. */
6430 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
6435 /* Disable the PHY transmitter */
6436 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
6443 ret_val = e1000_write_phy_reg(hw, 0x0000,
6444 IGP01E1000_IEEE_FORCE_GIGA);
6447 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE,
6448 IGP01E1000_PHY_DSP_FFE_DEFAULT);
6452 ret_val = e1000_write_phy_reg(hw, 0x0000,
6453 IGP01E1000_IEEE_RESTART_AUTONEG);
6459 /* Now enable the transmitter */
6460 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
6465 hw->ffe_config_state = e1000_ffe_config_enabled;
6468 return E1000_SUCCESS;
6471 /*****************************************************************************
6472 * Set PHY to class A mode
6473 * Assumes the following operations will follow to enable the new class mode.
6474 * 1. Do a PHY soft reset
6475 * 2. Restart auto-negotiation or force link.
6477 * hw - Struct containing variables accessed by shared code
6478 ****************************************************************************/
6480 e1000_set_phy_mode(struct e1000_hw *hw)
6483 uint16_t eeprom_data;
6485 DEBUGFUNC("e1000_set_phy_mode");
6487 if((hw->mac_type == e1000_82545_rev_3) &&
6488 (hw->media_type == e1000_media_type_copper)) {
6489 ret_val = e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, 1, &eeprom_data);
6494 if((eeprom_data != EEPROM_RESERVED_WORD) &&
6495 (eeprom_data & EEPROM_PHY_CLASS_A)) {
6496 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x000B);
6499 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x8104);
6503 hw->phy_reset_disable = FALSE;
6507 return E1000_SUCCESS;
6510 /*****************************************************************************
6512 * This function sets the lplu state according to the active flag. When
6513 * activating lplu this function also disables smart speed and vise versa.
6514 * lplu will not be activated unless the device autonegotiation advertisment
6515 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
6516 * hw: Struct containing variables accessed by shared code
6517 * active - true to enable lplu false to disable lplu.
6519 * returns: - E1000_ERR_PHY if fail to read/write the PHY
6520 * E1000_SUCCESS at any other case.
6522 ****************************************************************************/
6525 e1000_set_d3_lplu_state(struct e1000_hw *hw,
6530 DEBUGFUNC("e1000_set_d3_lplu_state");
6532 if(hw->phy_type != e1000_phy_igp && hw->phy_type != e1000_phy_igp_2)
6533 return E1000_SUCCESS;
6535 /* During driver activity LPLU should not be used or it will attain link
6536 * from the lowest speeds starting from 10Mbps. The capability is used for
6537 * Dx transitions and states */
6538 if(hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2) {
6539 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data);
6543 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
6549 if(hw->mac_type == e1000_82541_rev_2 ||
6550 hw->mac_type == e1000_82547_rev_2) {
6551 phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
6552 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
6556 phy_data &= ~IGP02E1000_PM_D3_LPLU;
6557 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
6563 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
6564 * Dx states where the power conservation is most important. During
6565 * driver activity we should enable SmartSpeed, so performance is
6567 if (hw->smart_speed == e1000_smart_speed_on) {
6568 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
6573 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
6574 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
6578 } else if (hw->smart_speed == e1000_smart_speed_off) {
6579 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
6584 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
6585 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
6591 } else if((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT) ||
6592 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL ) ||
6593 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) {
6595 if(hw->mac_type == e1000_82541_rev_2 ||
6596 hw->mac_type == e1000_82547_rev_2) {
6597 phy_data |= IGP01E1000_GMII_FLEX_SPD;
6598 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
6602 phy_data |= IGP02E1000_PM_D3_LPLU;
6603 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
6609 /* When LPLU is enabled we should disable SmartSpeed */
6610 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
6614 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
6615 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
6620 return E1000_SUCCESS;
6623 /*****************************************************************************
6625 * This function sets the lplu d0 state according to the active flag. When
6626 * activating lplu this function also disables smart speed and vise versa.
6627 * lplu will not be activated unless the device autonegotiation advertisment
6628 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
6629 * hw: Struct containing variables accessed by shared code
6630 * active - true to enable lplu false to disable lplu.
6632 * returns: - E1000_ERR_PHY if fail to read/write the PHY
6633 * E1000_SUCCESS at any other case.
6635 ****************************************************************************/
6638 e1000_set_d0_lplu_state(struct e1000_hw *hw,
6643 DEBUGFUNC("e1000_set_d0_lplu_state");
6645 if(hw->mac_type <= e1000_82547_rev_2)
6646 return E1000_SUCCESS;
6648 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
6653 phy_data &= ~IGP02E1000_PM_D0_LPLU;
6654 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
6658 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
6659 * Dx states where the power conservation is most important. During
6660 * driver activity we should enable SmartSpeed, so performance is
6662 if (hw->smart_speed == e1000_smart_speed_on) {
6663 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
6668 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
6669 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
6673 } else if (hw->smart_speed == e1000_smart_speed_off) {
6674 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
6679 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
6680 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
6689 phy_data |= IGP02E1000_PM_D0_LPLU;
6690 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
6694 /* When LPLU is enabled we should disable SmartSpeed */
6695 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
6699 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
6700 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
6705 return E1000_SUCCESS;
6708 /******************************************************************************
6709 * Change VCO speed register to improve Bit Error Rate performance of SERDES.
6711 * hw - Struct containing variables accessed by shared code
6712 *****************************************************************************/
6714 e1000_set_vco_speed(struct e1000_hw *hw)
6717 uint16_t default_page = 0;
6720 DEBUGFUNC("e1000_set_vco_speed");
6722 switch(hw->mac_type) {
6723 case e1000_82545_rev_3:
6724 case e1000_82546_rev_3:
6727 return E1000_SUCCESS;
6730 /* Set PHY register 30, page 5, bit 8 to 0 */
6732 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, &default_page);
6736 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005);
6740 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
6744 phy_data &= ~M88E1000_PHY_VCO_REG_BIT8;
6745 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
6749 /* Set PHY register 30, page 4, bit 11 to 1 */
6751 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004);
6755 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
6759 phy_data |= M88E1000_PHY_VCO_REG_BIT11;
6760 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
6764 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, default_page);
6768 return E1000_SUCCESS;
6772 /*****************************************************************************
6773 * This function reads the cookie from ARC ram.
6775 * returns: - E1000_SUCCESS .
6776 ****************************************************************************/
6778 e1000_host_if_read_cookie(struct e1000_hw * hw, uint8_t *buffer)
6781 uint32_t offset = E1000_MNG_DHCP_COOKIE_OFFSET;
6782 uint8_t length = E1000_MNG_DHCP_COOKIE_LENGTH;
6784 length = (length >> 2);
6785 offset = (offset >> 2);
6787 for (i = 0; i < length; i++) {
6788 *((uint32_t *) buffer + i) =
6789 E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset + i);
6791 return E1000_SUCCESS;
6795 /*****************************************************************************
6796 * This function checks whether the HOST IF is enabled for command operaton
6797 * and also checks whether the previous command is completed.
6798 * It busy waits in case of previous command is not completed.
6800 * returns: - E1000_ERR_HOST_INTERFACE_COMMAND in case if is not ready or
6802 * - E1000_SUCCESS for success.
6803 ****************************************************************************/
6805 e1000_mng_enable_host_if(struct e1000_hw * hw)
6810 /* Check that the host interface is enabled. */
6811 hicr = E1000_READ_REG(hw, HICR);
6812 if ((hicr & E1000_HICR_EN) == 0) {
6813 DEBUGOUT("E1000_HOST_EN bit disabled.\n");
6814 return -E1000_ERR_HOST_INTERFACE_COMMAND;
6816 /* check the previous command is completed */
6817 for (i = 0; i < E1000_MNG_DHCP_COMMAND_TIMEOUT; i++) {
6818 hicr = E1000_READ_REG(hw, HICR);
6819 if (!(hicr & E1000_HICR_C))
6824 if (i == E1000_MNG_DHCP_COMMAND_TIMEOUT) {
6825 DEBUGOUT("Previous command timeout failed .\n");
6826 return -E1000_ERR_HOST_INTERFACE_COMMAND;
6828 return E1000_SUCCESS;
6831 /*****************************************************************************
6832 * This function writes the buffer content at the offset given on the host if.
6833 * It also does alignment considerations to do the writes in most efficient way.
6834 * Also fills up the sum of the buffer in *buffer parameter.
6836 * returns - E1000_SUCCESS for success.
6837 ****************************************************************************/
6839 e1000_mng_host_if_write(struct e1000_hw * hw, uint8_t *buffer,
6840 uint16_t length, uint16_t offset, uint8_t *sum)
6843 uint8_t *bufptr = buffer;
6845 uint16_t remaining, i, j, prev_bytes;
6847 /* sum = only sum of the data and it is not checksum */
6849 if (length == 0 || offset + length > E1000_HI_MAX_MNG_DATA_LENGTH) {
6850 return -E1000_ERR_PARAM;
6853 tmp = (uint8_t *)&data;
6854 prev_bytes = offset & 0x3;
6859 data = E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset);
6860 for (j = prev_bytes; j < sizeof(uint32_t); j++) {
6861 *(tmp + j) = *bufptr++;
6864 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset, data);
6865 length -= j - prev_bytes;
6869 remaining = length & 0x3;
6870 length -= remaining;
6872 /* Calculate length in DWORDs */
6875 /* The device driver writes the relevant command block into the
6877 for (i = 0; i < length; i++) {
6878 for (j = 0; j < sizeof(uint32_t); j++) {
6879 *(tmp + j) = *bufptr++;
6883 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data);
6886 for (j = 0; j < sizeof(uint32_t); j++) {
6888 *(tmp + j) = *bufptr++;
6894 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data);
6897 return E1000_SUCCESS;
6901 /*****************************************************************************
6902 * This function writes the command header after does the checksum calculation.
6904 * returns - E1000_SUCCESS for success.
6905 ****************************************************************************/
6907 e1000_mng_write_cmd_header(struct e1000_hw * hw,
6908 struct e1000_host_mng_command_header * hdr)
6914 /* Write the whole command header structure which includes sum of
6917 uint16_t length = sizeof(struct e1000_host_mng_command_header);
6919 sum = hdr->checksum;
6922 buffer = (uint8_t *) hdr;
6927 hdr->checksum = 0 - sum;
6930 /* The device driver writes the relevant command block into the ram area. */
6931 for (i = 0; i < length; i++)
6932 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, i, *((uint32_t *) hdr + i));
6934 return E1000_SUCCESS;
6938 /*****************************************************************************
6939 * This function indicates to ARC that a new command is pending which completes
6940 * one write operation by the driver.
6942 * returns - E1000_SUCCESS for success.
6943 ****************************************************************************/
6945 e1000_mng_write_commit(
6946 struct e1000_hw * hw)
6950 hicr = E1000_READ_REG(hw, HICR);
6951 /* Setting this bit tells the ARC that a new command is pending. */
6952 E1000_WRITE_REG(hw, HICR, hicr | E1000_HICR_C);
6954 return E1000_SUCCESS;
6958 /*****************************************************************************
6959 * This function checks the mode of the firmware.
6961 * returns - TRUE when the mode is IAMT or FALSE.
6962 ****************************************************************************/
6964 e1000_check_mng_mode(
6965 struct e1000_hw *hw)
6969 fwsm = E1000_READ_REG(hw, FWSM);
6971 if((fwsm & E1000_FWSM_MODE_MASK) ==
6972 (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
6979 /*****************************************************************************
6980 * This function writes the dhcp info .
6981 ****************************************************************************/
6983 e1000_mng_write_dhcp_info(struct e1000_hw * hw, uint8_t *buffer,
6987 struct e1000_host_mng_command_header hdr;
6989 hdr.command_id = E1000_MNG_DHCP_TX_PAYLOAD_CMD;
6990 hdr.command_length = length;
6995 ret_val = e1000_mng_enable_host_if(hw);
6996 if (ret_val == E1000_SUCCESS) {
6997 ret_val = e1000_mng_host_if_write(hw, buffer, length, sizeof(hdr),
6999 if (ret_val == E1000_SUCCESS) {
7000 ret_val = e1000_mng_write_cmd_header(hw, &hdr);
7001 if (ret_val == E1000_SUCCESS)
7002 ret_val = e1000_mng_write_commit(hw);
7009 /*****************************************************************************
7010 * This function calculates the checksum.
7012 * returns - checksum of buffer contents.
7013 ****************************************************************************/
7015 e1000_calculate_mng_checksum(char *buffer, uint32_t length)
7023 for (i=0; i < length; i++)
7026 return (uint8_t) (0 - sum);
7029 /*****************************************************************************
7030 * This function checks whether tx pkt filtering needs to be enabled or not.
7032 * returns - TRUE for packet filtering or FALSE.
7033 ****************************************************************************/
7035 e1000_enable_tx_pkt_filtering(struct e1000_hw *hw)
7037 /* called in init as well as watchdog timer functions */
7039 int32_t ret_val, checksum;
7040 boolean_t tx_filter = FALSE;
7041 struct e1000_host_mng_dhcp_cookie *hdr = &(hw->mng_cookie);
7042 uint8_t *buffer = (uint8_t *) &(hw->mng_cookie);
7044 if (e1000_check_mng_mode(hw)) {
7045 ret_val = e1000_mng_enable_host_if(hw);
7046 if (ret_val == E1000_SUCCESS) {
7047 ret_val = e1000_host_if_read_cookie(hw, buffer);
7048 if (ret_val == E1000_SUCCESS) {
7049 checksum = hdr->checksum;
7051 if ((hdr->signature == E1000_IAMT_SIGNATURE) &&
7052 checksum == e1000_calculate_mng_checksum((char *)buffer,
7053 E1000_MNG_DHCP_COOKIE_LENGTH)) {
7055 E1000_MNG_DHCP_COOKIE_STATUS_PARSING_SUPPORT)
7064 hw->tx_pkt_filtering = tx_filter;
7068 /******************************************************************************
7069 * Verifies the hardware needs to allow ARPs to be processed by the host
7071 * hw - Struct containing variables accessed by shared code
7073 * returns: - TRUE/FALSE
7075 *****************************************************************************/
7077 e1000_enable_mng_pass_thru(struct e1000_hw *hw)
7080 uint32_t fwsm, factps;
7082 if (hw->asf_firmware_present) {
7083 manc = E1000_READ_REG(hw, MANC);
7085 if (!(manc & E1000_MANC_RCV_TCO_EN) ||
7086 !(manc & E1000_MANC_EN_MAC_ADDR_FILTER))
7088 if (e1000_arc_subsystem_valid(hw) == TRUE) {
7089 fwsm = E1000_READ_REG(hw, FWSM);
7090 factps = E1000_READ_REG(hw, FACTPS);
7092 if (((fwsm & E1000_FWSM_MODE_MASK) ==
7093 (e1000_mng_mode_pt << E1000_FWSM_MODE_SHIFT)) &&
7094 (factps & E1000_FACTPS_MNGCG))
7097 if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN))
7104 e1000_polarity_reversal_workaround(struct e1000_hw *hw)
7107 uint16_t mii_status_reg;
7110 /* Polarity reversal workaround for forced 10F/10H links. */
7112 /* Disable the transmitter on the PHY */
7114 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
7117 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF);
7121 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
7125 /* This loop will early-out if the NO link condition has been met. */
7126 for(i = PHY_FORCE_TIME; i > 0; i--) {
7127 /* Read the MII Status Register and wait for Link Status bit
7131 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
7135 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
7139 if((mii_status_reg & ~MII_SR_LINK_STATUS) == 0) break;
7140 msec_delay_irq(100);
7143 /* Recommended delay time after link has been lost */
7144 msec_delay_irq(1000);
7146 /* Now we will re-enable th transmitter on the PHY */
7148 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
7152 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0);
7156 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00);
7160 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000);
7164 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
7168 /* This loop will early-out if the link condition has been met. */
7169 for(i = PHY_FORCE_TIME; i > 0; i--) {
7170 /* Read the MII Status Register and wait for Link Status bit
7174 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
7178 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
7182 if(mii_status_reg & MII_SR_LINK_STATUS) break;
7183 msec_delay_irq(100);
7185 return E1000_SUCCESS;
7188 /***************************************************************************
7190 * Disables PCI-Express master access.
7192 * hw: Struct containing variables accessed by shared code
7196 ***************************************************************************/
7198 e1000_set_pci_express_master_disable(struct e1000_hw *hw)
7202 DEBUGFUNC("e1000_set_pci_express_master_disable");
7204 if (hw->bus_type != e1000_bus_type_pci_express)
7207 ctrl = E1000_READ_REG(hw, CTRL);
7208 ctrl |= E1000_CTRL_GIO_MASTER_DISABLE;
7209 E1000_WRITE_REG(hw, CTRL, ctrl);
7213 /***************************************************************************
7215 * Enables PCI-Express master access.
7217 * hw: Struct containing variables accessed by shared code
7221 ***************************************************************************/
7223 e1000_enable_pciex_master(struct e1000_hw *hw)
7227 DEBUGFUNC("e1000_enable_pciex_master");
7229 if (hw->bus_type != e1000_bus_type_pci_express)
7232 ctrl = E1000_READ_REG(hw, CTRL);
7233 ctrl &= ~E1000_CTRL_GIO_MASTER_DISABLE;
7234 E1000_WRITE_REG(hw, CTRL, ctrl);
7238 /*******************************************************************************
7240 * Disables PCI-Express master access and verifies there are no pending requests
7242 * hw: Struct containing variables accessed by shared code
7244 * returns: - E1000_ERR_MASTER_REQUESTS_PENDING if master disable bit hasn't
7245 * caused the master requests to be disabled.
7246 * E1000_SUCCESS master requests disabled.
7248 ******************************************************************************/
7250 e1000_disable_pciex_master(struct e1000_hw *hw)
7252 int32_t timeout = MASTER_DISABLE_TIMEOUT; /* 80ms */
7254 DEBUGFUNC("e1000_disable_pciex_master");
7256 if (hw->bus_type != e1000_bus_type_pci_express)
7257 return E1000_SUCCESS;
7259 e1000_set_pci_express_master_disable(hw);
7262 if(!(E1000_READ_REG(hw, STATUS) & E1000_STATUS_GIO_MASTER_ENABLE))
7270 DEBUGOUT("Master requests are pending.\n");
7271 return -E1000_ERR_MASTER_REQUESTS_PENDING;
7274 return E1000_SUCCESS;
7277 /*******************************************************************************
7279 * Check for EEPROM Auto Read bit done.
7281 * hw: Struct containing variables accessed by shared code
7283 * returns: - E1000_ERR_RESET if fail to reset MAC
7284 * E1000_SUCCESS at any other case.
7286 ******************************************************************************/
7288 e1000_get_auto_rd_done(struct e1000_hw *hw)
7290 int32_t timeout = AUTO_READ_DONE_TIMEOUT;
7292 DEBUGFUNC("e1000_get_auto_rd_done");
7294 switch (hw->mac_type) {
7301 case e1000_80003es2lan:
7303 if (E1000_READ_REG(hw, EECD) & E1000_EECD_AUTO_RD) break;
7309 DEBUGOUT("Auto read by HW from EEPROM has not completed.\n");
7310 return -E1000_ERR_RESET;
7315 /* PHY configuration from NVM just starts after EECD_AUTO_RD sets to high.
7316 * Need to wait for PHY configuration completion before accessing NVM
7318 if (hw->mac_type == e1000_82573)
7321 return E1000_SUCCESS;
7324 /***************************************************************************
7325 * Checks if the PHY configuration is done
7327 * hw: Struct containing variables accessed by shared code
7329 * returns: - E1000_ERR_RESET if fail to reset MAC
7330 * E1000_SUCCESS at any other case.
7332 ***************************************************************************/
7334 e1000_get_phy_cfg_done(struct e1000_hw *hw)
7336 int32_t timeout = PHY_CFG_TIMEOUT;
7337 uint32_t cfg_mask = E1000_EEPROM_CFG_DONE;
7339 DEBUGFUNC("e1000_get_phy_cfg_done");
7341 switch (hw->mac_type) {
7345 case e1000_80003es2lan:
7346 /* Separate *_CFG_DONE_* bit for each port */
7347 if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
7348 cfg_mask = E1000_EEPROM_CFG_DONE_PORT_1;
7353 if (E1000_READ_REG(hw, EEMNGCTL) & cfg_mask)
7361 DEBUGOUT("MNG configuration cycle has not completed.\n");
7362 return -E1000_ERR_RESET;
7367 return E1000_SUCCESS;
7370 /***************************************************************************
7372 * Using the combination of SMBI and SWESMBI semaphore bits when resetting
7373 * adapter or Eeprom access.
7375 * hw: Struct containing variables accessed by shared code
7377 * returns: - E1000_ERR_EEPROM if fail to access EEPROM.
7378 * E1000_SUCCESS at any other case.
7380 ***************************************************************************/
7382 e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw)
7387 DEBUGFUNC("e1000_get_hw_eeprom_semaphore");
7389 if(!hw->eeprom_semaphore_present)
7390 return E1000_SUCCESS;
7392 if (hw->mac_type == e1000_80003es2lan) {
7393 /* Get the SW semaphore. */
7394 if (e1000_get_software_semaphore(hw) != E1000_SUCCESS)
7395 return -E1000_ERR_EEPROM;
7398 /* Get the FW semaphore. */
7399 timeout = hw->eeprom.word_size + 1;
7401 swsm = E1000_READ_REG(hw, SWSM);
7402 swsm |= E1000_SWSM_SWESMBI;
7403 E1000_WRITE_REG(hw, SWSM, swsm);
7404 /* if we managed to set the bit we got the semaphore. */
7405 swsm = E1000_READ_REG(hw, SWSM);
7406 if(swsm & E1000_SWSM_SWESMBI)
7414 /* Release semaphores */
7415 e1000_put_hw_eeprom_semaphore(hw);
7416 DEBUGOUT("Driver can't access the Eeprom - SWESMBI bit is set.\n");
7417 return -E1000_ERR_EEPROM;
7420 return E1000_SUCCESS;
7423 /***************************************************************************
7424 * This function clears HW semaphore bits.
7426 * hw: Struct containing variables accessed by shared code
7430 ***************************************************************************/
7432 e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw)
7436 DEBUGFUNC("e1000_put_hw_eeprom_semaphore");
7438 if(!hw->eeprom_semaphore_present)
7441 swsm = E1000_READ_REG(hw, SWSM);
7442 if (hw->mac_type == e1000_80003es2lan) {
7443 /* Release both semaphores. */
7444 swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
7446 swsm &= ~(E1000_SWSM_SWESMBI);
7447 E1000_WRITE_REG(hw, SWSM, swsm);
7450 /***************************************************************************
7452 * Obtaining software semaphore bit (SMBI) before resetting PHY.
7454 * hw: Struct containing variables accessed by shared code
7456 * returns: - E1000_ERR_RESET if fail to obtain semaphore.
7457 * E1000_SUCCESS at any other case.
7459 ***************************************************************************/
7461 e1000_get_software_semaphore(struct e1000_hw *hw)
7463 int32_t timeout = hw->eeprom.word_size + 1;
7466 DEBUGFUNC("e1000_get_software_semaphore");
7468 if (hw->mac_type != e1000_80003es2lan)
7469 return E1000_SUCCESS;
7472 swsm = E1000_READ_REG(hw, SWSM);
7473 /* If SMBI bit cleared, it is now set and we hold the semaphore */
7474 if(!(swsm & E1000_SWSM_SMBI))
7481 DEBUGOUT("Driver can't access device - SMBI bit is set.\n");
7482 return -E1000_ERR_RESET;
7485 return E1000_SUCCESS;
7488 /***************************************************************************
7490 * Release semaphore bit (SMBI).
7492 * hw: Struct containing variables accessed by shared code
7494 ***************************************************************************/
7496 e1000_release_software_semaphore(struct e1000_hw *hw)
7500 DEBUGFUNC("e1000_release_software_semaphore");
7502 if (hw->mac_type != e1000_80003es2lan)
7505 swsm = E1000_READ_REG(hw, SWSM);
7506 /* Release the SW semaphores.*/
7507 swsm &= ~E1000_SWSM_SMBI;
7508 E1000_WRITE_REG(hw, SWSM, swsm);
7511 /******************************************************************************
7512 * Checks if PHY reset is blocked due to SOL/IDER session, for example.
7513 * Returning E1000_BLK_PHY_RESET isn't necessarily an error. But it's up to
7514 * the caller to figure out how to deal with it.
7516 * hw - Struct containing variables accessed by shared code
7518 * returns: - E1000_BLK_PHY_RESET
7521 *****************************************************************************/
7523 e1000_check_phy_reset_block(struct e1000_hw *hw)
7527 if (hw->mac_type > e1000_82547_rev_2)
7528 manc = E1000_READ_REG(hw, MANC);
7529 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
7530 E1000_BLK_PHY_RESET : E1000_SUCCESS;
7534 e1000_arc_subsystem_valid(struct e1000_hw *hw)
7538 /* On 8257x silicon, registers in the range of 0x8800 - 0x8FFC
7539 * may not be provided a DMA clock when no manageability features are
7540 * enabled. We do not want to perform any reads/writes to these registers
7541 * if this is the case. We read FWSM to determine the manageability mode.
7543 switch (hw->mac_type) {
7547 case e1000_80003es2lan:
7548 fwsm = E1000_READ_REG(hw, FWSM);
7549 if((fwsm & E1000_FWSM_MODE_MASK) != 0)