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);
710 /* use write flush to prevent Memory Write Block (MWB) from
711 * occuring when accessing our register space */
712 E1000_WRITE_FLUSH(hw);
715 /* Set the PCI priority bit correctly in the CTRL register. This
716 * determines if the adapter gives priority to receives, or if it
717 * gives equal priority to transmits and receives. Valid only on
718 * 82542 and 82543 silicon.
720 if(hw->dma_fairness && hw->mac_type <= e1000_82543) {
721 ctrl = E1000_READ_REG(hw, CTRL);
722 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PRIOR);
725 switch(hw->mac_type) {
726 case e1000_82545_rev_3:
727 case e1000_82546_rev_3:
730 /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
731 if(hw->bus_type == e1000_bus_type_pcix) {
732 e1000_read_pci_cfg(hw, PCIX_COMMAND_REGISTER, &pcix_cmd_word);
733 e1000_read_pci_cfg(hw, PCIX_STATUS_REGISTER_HI,
735 cmd_mmrbc = (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >>
736 PCIX_COMMAND_MMRBC_SHIFT;
737 stat_mmrbc = (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
738 PCIX_STATUS_HI_MMRBC_SHIFT;
739 if(stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
740 stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
741 if(cmd_mmrbc > stat_mmrbc) {
742 pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK;
743 pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
744 e1000_write_pci_cfg(hw, PCIX_COMMAND_REGISTER,
751 /* Call a subroutine to configure the link and setup flow control. */
752 ret_val = e1000_setup_link(hw);
754 /* Set the transmit descriptor write-back policy */
755 if(hw->mac_type > e1000_82544) {
756 ctrl = E1000_READ_REG(hw, TXDCTL);
757 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
758 switch (hw->mac_type) {
764 case e1000_80003es2lan:
765 ctrl |= E1000_TXDCTL_COUNT_DESC;
768 E1000_WRITE_REG(hw, TXDCTL, ctrl);
771 if (hw->mac_type == e1000_82573) {
772 e1000_enable_tx_pkt_filtering(hw);
775 switch (hw->mac_type) {
778 case e1000_80003es2lan:
779 /* Enable retransmit on late collisions */
780 reg_data = E1000_READ_REG(hw, TCTL);
781 reg_data |= E1000_TCTL_RTLC;
782 E1000_WRITE_REG(hw, TCTL, reg_data);
784 /* Configure Gigabit Carry Extend Padding */
785 reg_data = E1000_READ_REG(hw, TCTL_EXT);
786 reg_data &= ~E1000_TCTL_EXT_GCEX_MASK;
787 reg_data |= DEFAULT_80003ES2LAN_TCTL_EXT_GCEX;
788 E1000_WRITE_REG(hw, TCTL_EXT, reg_data);
790 /* Configure Transmit Inter-Packet Gap */
791 reg_data = E1000_READ_REG(hw, TIPG);
792 reg_data &= ~E1000_TIPG_IPGT_MASK;
793 reg_data |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
794 E1000_WRITE_REG(hw, TIPG, reg_data);
796 reg_data = E1000_READ_REG_ARRAY(hw, FFLT, 0x0001);
797 reg_data &= ~0x00100000;
798 E1000_WRITE_REG_ARRAY(hw, FFLT, 0x0001, reg_data);
802 ctrl = E1000_READ_REG(hw, TXDCTL1);
803 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
804 if(hw->mac_type >= e1000_82571)
805 ctrl |= E1000_TXDCTL_COUNT_DESC;
806 E1000_WRITE_REG(hw, TXDCTL1, ctrl);
812 if (hw->mac_type == e1000_82573) {
813 uint32_t gcr = E1000_READ_REG(hw, GCR);
814 gcr |= E1000_GCR_L1_ACT_WITHOUT_L0S_RX;
815 E1000_WRITE_REG(hw, GCR, gcr);
818 /* Clear all of the statistics registers (clear on read). It is
819 * important that we do this after we have tried to establish link
820 * because the symbol error count will increment wildly if there
823 e1000_clear_hw_cntrs(hw);
825 if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER ||
826 hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) {
827 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
828 /* Relaxed ordering must be disabled to avoid a parity
829 * error crash in a PCI slot. */
830 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
831 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
837 /******************************************************************************
838 * Adjust SERDES output amplitude based on EEPROM setting.
840 * hw - Struct containing variables accessed by shared code.
841 *****************************************************************************/
843 e1000_adjust_serdes_amplitude(struct e1000_hw *hw)
845 uint16_t eeprom_data;
848 DEBUGFUNC("e1000_adjust_serdes_amplitude");
850 if(hw->media_type != e1000_media_type_internal_serdes)
851 return E1000_SUCCESS;
853 switch(hw->mac_type) {
854 case e1000_82545_rev_3:
855 case e1000_82546_rev_3:
858 return E1000_SUCCESS;
861 ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1, &eeprom_data);
866 if(eeprom_data != EEPROM_RESERVED_WORD) {
867 /* Adjust SERDES output amplitude only. */
868 eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK;
869 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data);
874 return E1000_SUCCESS;
877 /******************************************************************************
878 * Configures flow control and link settings.
880 * hw - Struct containing variables accessed by shared code
882 * Determines which flow control settings to use. Calls the apropriate media-
883 * specific link configuration function. Configures the flow control settings.
884 * Assuming the adapter has a valid link partner, a valid link should be
885 * established. Assumes the hardware has previously been reset and the
886 * transmitter and receiver are not enabled.
887 *****************************************************************************/
889 e1000_setup_link(struct e1000_hw *hw)
893 uint16_t eeprom_data;
895 DEBUGFUNC("e1000_setup_link");
897 /* In the case of the phy reset being blocked, we already have a link.
898 * We do not have to set it up again. */
899 if (e1000_check_phy_reset_block(hw))
900 return E1000_SUCCESS;
902 /* Read and store word 0x0F of the EEPROM. This word contains bits
903 * that determine the hardware's default PAUSE (flow control) mode,
904 * a bit that determines whether the HW defaults to enabling or
905 * disabling auto-negotiation, and the direction of the
906 * SW defined pins. If there is no SW over-ride of the flow
907 * control setting, then the variable hw->fc will
908 * be initialized based on a value in the EEPROM.
910 if (hw->fc == e1000_fc_default) {
911 switch (hw->mac_type) {
913 hw->fc = e1000_fc_full;
916 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
919 DEBUGOUT("EEPROM Read Error\n");
920 return -E1000_ERR_EEPROM;
922 if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
923 hw->fc = e1000_fc_none;
924 else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
925 EEPROM_WORD0F_ASM_DIR)
926 hw->fc = e1000_fc_tx_pause;
928 hw->fc = e1000_fc_full;
933 /* We want to save off the original Flow Control configuration just
934 * in case we get disconnected and then reconnected into a different
935 * hub or switch with different Flow Control capabilities.
937 if(hw->mac_type == e1000_82542_rev2_0)
938 hw->fc &= (~e1000_fc_tx_pause);
940 if((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
941 hw->fc &= (~e1000_fc_rx_pause);
943 hw->original_fc = hw->fc;
945 DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc);
947 /* Take the 4 bits from EEPROM word 0x0F that determine the initial
948 * polarity value for the SW controlled pins, and setup the
949 * Extended Device Control reg with that info.
950 * This is needed because one of the SW controlled pins is used for
951 * signal detection. So this should be done before e1000_setup_pcs_link()
952 * or e1000_phy_setup() is called.
954 if (hw->mac_type == e1000_82543) {
955 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
958 DEBUGOUT("EEPROM Read Error\n");
959 return -E1000_ERR_EEPROM;
961 ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
963 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
966 /* Call the necessary subroutine to configure the link. */
967 ret_val = (hw->media_type == e1000_media_type_copper) ?
968 e1000_setup_copper_link(hw) :
969 e1000_setup_fiber_serdes_link(hw);
971 /* Initialize the flow control address, type, and PAUSE timer
972 * registers to their default values. This is done even if flow
973 * control is disabled, because it does not hurt anything to
974 * initialize these registers.
976 DEBUGOUT("Initializing the Flow Control address, type and timer regs\n");
978 E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
979 E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
980 E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
982 E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
984 /* Set the flow control receive threshold registers. Normally,
985 * these registers will be set to a default threshold that may be
986 * adjusted later by the driver's runtime code. However, if the
987 * ability to transmit pause frames in not enabled, then these
988 * registers will be set to 0.
990 if(!(hw->fc & e1000_fc_tx_pause)) {
991 E1000_WRITE_REG(hw, FCRTL, 0);
992 E1000_WRITE_REG(hw, FCRTH, 0);
994 /* We need to set up the Receive Threshold high and low water marks
995 * as well as (optionally) enabling the transmission of XON frames.
997 if(hw->fc_send_xon) {
998 E1000_WRITE_REG(hw, FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE));
999 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
1001 E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water);
1002 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
1008 /******************************************************************************
1009 * Sets up link for a fiber based or serdes based adapter
1011 * hw - Struct containing variables accessed by shared code
1013 * Manipulates Physical Coding Sublayer functions in order to configure
1014 * link. Assumes the hardware has been previously reset and the transmitter
1015 * and receiver are not enabled.
1016 *****************************************************************************/
1018 e1000_setup_fiber_serdes_link(struct e1000_hw *hw)
1024 uint32_t signal = 0;
1027 DEBUGFUNC("e1000_setup_fiber_serdes_link");
1029 /* On 82571 and 82572 Fiber connections, SerDes loopback mode persists
1030 * until explicitly turned off or a power cycle is performed. A read to
1031 * the register does not indicate its status. Therefore, we ensure
1032 * loopback mode is disabled during initialization.
1034 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572)
1035 E1000_WRITE_REG(hw, SCTL, E1000_DISABLE_SERDES_LOOPBACK);
1037 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
1038 * set when the optics detect a signal. On older adapters, it will be
1039 * cleared when there is a signal. This applies to fiber media only.
1040 * If we're on serdes media, adjust the output amplitude to value set in
1043 ctrl = E1000_READ_REG(hw, CTRL);
1044 if(hw->media_type == e1000_media_type_fiber)
1045 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
1047 ret_val = e1000_adjust_serdes_amplitude(hw);
1051 /* Take the link out of reset */
1052 ctrl &= ~(E1000_CTRL_LRST);
1054 /* Adjust VCO speed to improve BER performance */
1055 ret_val = e1000_set_vco_speed(hw);
1059 e1000_config_collision_dist(hw);
1061 /* Check for a software override of the flow control settings, and setup
1062 * the device accordingly. If auto-negotiation is enabled, then software
1063 * will have to set the "PAUSE" bits to the correct value in the Tranmsit
1064 * Config Word Register (TXCW) and re-start auto-negotiation. However, if
1065 * auto-negotiation is disabled, then software will have to manually
1066 * configure the two flow control enable bits in the CTRL register.
1068 * The possible values of the "fc" parameter are:
1069 * 0: Flow control is completely disabled
1070 * 1: Rx flow control is enabled (we can receive pause frames, but
1071 * not send pause frames).
1072 * 2: Tx flow control is enabled (we can send pause frames but we do
1073 * not support receiving pause frames).
1074 * 3: Both Rx and TX flow control (symmetric) are enabled.
1078 /* Flow control is completely disabled by a software over-ride. */
1079 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
1081 case e1000_fc_rx_pause:
1082 /* RX Flow control is enabled and TX Flow control is disabled by a
1083 * software over-ride. Since there really isn't a way to advertise
1084 * that we are capable of RX Pause ONLY, we will advertise that we
1085 * support both symmetric and asymmetric RX PAUSE. Later, we will
1086 * disable the adapter's ability to send PAUSE frames.
1088 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1090 case e1000_fc_tx_pause:
1091 /* TX Flow control is enabled, and RX Flow control is disabled, by a
1092 * software over-ride.
1094 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
1097 /* Flow control (both RX and TX) is enabled by a software over-ride. */
1098 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1101 DEBUGOUT("Flow control param set incorrectly\n");
1102 return -E1000_ERR_CONFIG;
1106 /* Since auto-negotiation is enabled, take the link out of reset (the link
1107 * will be in reset, because we previously reset the chip). This will
1108 * restart auto-negotiation. If auto-neogtiation is successful then the
1109 * link-up status bit will be set and the flow control enable bits (RFCE
1110 * and TFCE) will be set according to their negotiated value.
1112 DEBUGOUT("Auto-negotiation enabled\n");
1114 E1000_WRITE_REG(hw, TXCW, txcw);
1115 E1000_WRITE_REG(hw, CTRL, ctrl);
1116 E1000_WRITE_FLUSH(hw);
1121 /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
1122 * indication in the Device Status Register. Time-out if a link isn't
1123 * seen in 500 milliseconds seconds (Auto-negotiation should complete in
1124 * less than 500 milliseconds even if the other end is doing it in SW).
1125 * For internal serdes, we just assume a signal is present, then poll.
1127 if(hw->media_type == e1000_media_type_internal_serdes ||
1128 (E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) {
1129 DEBUGOUT("Looking for Link\n");
1130 for(i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
1132 status = E1000_READ_REG(hw, STATUS);
1133 if(status & E1000_STATUS_LU) break;
1135 if(i == (LINK_UP_TIMEOUT / 10)) {
1136 DEBUGOUT("Never got a valid link from auto-neg!!!\n");
1137 hw->autoneg_failed = 1;
1138 /* AutoNeg failed to achieve a link, so we'll call
1139 * e1000_check_for_link. This routine will force the link up if
1140 * we detect a signal. This will allow us to communicate with
1141 * non-autonegotiating link partners.
1143 ret_val = e1000_check_for_link(hw);
1145 DEBUGOUT("Error while checking for link\n");
1148 hw->autoneg_failed = 0;
1150 hw->autoneg_failed = 0;
1151 DEBUGOUT("Valid Link Found\n");
1154 DEBUGOUT("No Signal Detected\n");
1156 return E1000_SUCCESS;
1159 /******************************************************************************
1160 * Make sure we have a valid PHY and change PHY mode before link setup.
1162 * hw - Struct containing variables accessed by shared code
1163 ******************************************************************************/
1165 e1000_copper_link_preconfig(struct e1000_hw *hw)
1171 DEBUGFUNC("e1000_copper_link_preconfig");
1173 ctrl = E1000_READ_REG(hw, CTRL);
1174 /* With 82543, we need to force speed and duplex on the MAC equal to what
1175 * the PHY speed and duplex configuration is. In addition, we need to
1176 * perform a hardware reset on the PHY to take it out of reset.
1178 if(hw->mac_type > e1000_82543) {
1179 ctrl |= E1000_CTRL_SLU;
1180 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1181 E1000_WRITE_REG(hw, CTRL, ctrl);
1183 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
1184 E1000_WRITE_REG(hw, CTRL, ctrl);
1185 ret_val = e1000_phy_hw_reset(hw);
1190 /* Make sure we have a valid PHY */
1191 ret_val = e1000_detect_gig_phy(hw);
1193 DEBUGOUT("Error, did not detect valid phy.\n");
1196 DEBUGOUT1("Phy ID = %x \n", hw->phy_id);
1198 /* Set PHY to class A mode (if necessary) */
1199 ret_val = e1000_set_phy_mode(hw);
1203 if((hw->mac_type == e1000_82545_rev_3) ||
1204 (hw->mac_type == e1000_82546_rev_3)) {
1205 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1206 phy_data |= 0x00000008;
1207 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1210 if(hw->mac_type <= e1000_82543 ||
1211 hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
1212 hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2)
1213 hw->phy_reset_disable = FALSE;
1215 return E1000_SUCCESS;
1219 /********************************************************************
1220 * Copper link setup for e1000_phy_igp series.
1222 * hw - Struct containing variables accessed by shared code
1223 *********************************************************************/
1225 e1000_copper_link_igp_setup(struct e1000_hw *hw)
1231 DEBUGFUNC("e1000_copper_link_igp_setup");
1233 if (hw->phy_reset_disable)
1234 return E1000_SUCCESS;
1236 ret_val = e1000_phy_reset(hw);
1238 DEBUGOUT("Error Resetting the PHY\n");
1242 /* Wait 10ms for MAC to configure PHY from eeprom settings */
1245 /* Configure activity LED after PHY reset */
1246 led_ctrl = E1000_READ_REG(hw, LEDCTL);
1247 led_ctrl &= IGP_ACTIVITY_LED_MASK;
1248 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
1249 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
1251 /* disable lplu d3 during driver init */
1252 ret_val = e1000_set_d3_lplu_state(hw, FALSE);
1254 DEBUGOUT("Error Disabling LPLU D3\n");
1258 /* disable lplu d0 during driver init */
1259 ret_val = e1000_set_d0_lplu_state(hw, FALSE);
1261 DEBUGOUT("Error Disabling LPLU D0\n");
1264 /* Configure mdi-mdix settings */
1265 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1269 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
1270 hw->dsp_config_state = e1000_dsp_config_disabled;
1271 /* Force MDI for earlier revs of the IGP PHY */
1272 phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX | IGP01E1000_PSCR_FORCE_MDI_MDIX);
1276 hw->dsp_config_state = e1000_dsp_config_enabled;
1277 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1281 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1284 phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
1288 phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
1292 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1296 /* set auto-master slave resolution settings */
1298 e1000_ms_type phy_ms_setting = hw->master_slave;
1300 if(hw->ffe_config_state == e1000_ffe_config_active)
1301 hw->ffe_config_state = e1000_ffe_config_enabled;
1303 if(hw->dsp_config_state == e1000_dsp_config_activated)
1304 hw->dsp_config_state = e1000_dsp_config_enabled;
1306 /* when autonegotiation advertisment is only 1000Mbps then we
1307 * should disable SmartSpeed and enable Auto MasterSlave
1308 * resolution as hardware default. */
1309 if(hw->autoneg_advertised == ADVERTISE_1000_FULL) {
1310 /* Disable SmartSpeed */
1311 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
1314 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1315 ret_val = e1000_write_phy_reg(hw,
1316 IGP01E1000_PHY_PORT_CONFIG,
1320 /* Set auto Master/Slave resolution process */
1321 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1324 phy_data &= ~CR_1000T_MS_ENABLE;
1325 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1330 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1334 /* load defaults for future use */
1335 hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
1336 ((phy_data & CR_1000T_MS_VALUE) ?
1337 e1000_ms_force_master :
1338 e1000_ms_force_slave) :
1341 switch (phy_ms_setting) {
1342 case e1000_ms_force_master:
1343 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
1345 case e1000_ms_force_slave:
1346 phy_data |= CR_1000T_MS_ENABLE;
1347 phy_data &= ~(CR_1000T_MS_VALUE);
1350 phy_data &= ~CR_1000T_MS_ENABLE;
1354 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1359 return E1000_SUCCESS;
1362 /********************************************************************
1363 * Copper link setup for e1000_phy_gg82563 series.
1365 * hw - Struct containing variables accessed by shared code
1366 *********************************************************************/
1368 e1000_copper_link_ggp_setup(struct e1000_hw *hw)
1374 DEBUGFUNC("e1000_copper_link_ggp_setup");
1376 if(!hw->phy_reset_disable) {
1378 /* Enable CRS on TX for half-duplex operation. */
1379 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL,
1384 phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
1385 /* Use 25MHz for both link down and 1000BASE-T for Tx clock */
1386 phy_data |= GG82563_MSCR_TX_CLK_1000MBPS_25MHZ;
1388 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL,
1394 * MDI/MDI-X = 0 (default)
1395 * 0 - Auto for all speeds
1398 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1400 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_SPEC_CTRL, &phy_data);
1404 phy_data &= ~GG82563_PSCR_CROSSOVER_MODE_MASK;
1408 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDI;
1411 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDIX;
1415 phy_data |= GG82563_PSCR_CROSSOVER_MODE_AUTO;
1420 * disable_polarity_correction = 0 (default)
1421 * Automatic Correction for Reversed Cable Polarity
1425 phy_data &= ~GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
1426 if(hw->disable_polarity_correction == 1)
1427 phy_data |= GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
1428 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_SPEC_CTRL, phy_data);
1433 /* SW Reset the PHY so all changes take effect */
1434 ret_val = e1000_phy_reset(hw);
1436 DEBUGOUT("Error Resetting the PHY\n");
1439 } /* phy_reset_disable */
1441 if (hw->mac_type == e1000_80003es2lan) {
1442 /* Bypass RX and TX FIFO's */
1443 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_FIFO_CTRL,
1444 E1000_KUMCTRLSTA_FIFO_CTRL_RX_BYPASS |
1445 E1000_KUMCTRLSTA_FIFO_CTRL_TX_BYPASS);
1449 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_SPEC_CTRL_2, &phy_data);
1453 phy_data &= ~GG82563_PSCR2_REVERSE_AUTO_NEG;
1454 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_SPEC_CTRL_2, phy_data);
1459 reg_data = E1000_READ_REG(hw, CTRL_EXT);
1460 reg_data &= ~(E1000_CTRL_EXT_LINK_MODE_MASK);
1461 E1000_WRITE_REG(hw, CTRL_EXT, reg_data);
1463 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_PWR_MGMT_CTRL,
1468 /* Do not init these registers when the HW is in IAMT mode, since the
1469 * firmware will have already initialized them. We only initialize
1470 * them if the HW is not in IAMT mode.
1472 if (e1000_check_mng_mode(hw) == FALSE) {
1473 /* Enable Electrical Idle on the PHY */
1474 phy_data |= GG82563_PMCR_ENABLE_ELECTRICAL_IDLE;
1475 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_PWR_MGMT_CTRL,
1480 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
1485 /* Enable Pass False Carrier on the PHY */
1486 phy_data |= GG82563_KMCR_PASS_FALSE_CARRIER;
1488 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
1494 /* Workaround: Disable padding in Kumeran interface in the MAC
1495 * and in the PHY to avoid CRC errors.
1497 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_INBAND_CTRL,
1501 phy_data |= GG82563_ICR_DIS_PADDING;
1502 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_INBAND_CTRL,
1508 return E1000_SUCCESS;
1511 /********************************************************************
1512 * Copper link setup for e1000_phy_m88 series.
1514 * hw - Struct containing variables accessed by shared code
1515 *********************************************************************/
1517 e1000_copper_link_mgp_setup(struct e1000_hw *hw)
1522 DEBUGFUNC("e1000_copper_link_mgp_setup");
1524 if(hw->phy_reset_disable)
1525 return E1000_SUCCESS;
1527 /* Enable CRS on TX. This must be set for half-duplex operation. */
1528 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1532 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1535 * MDI/MDI-X = 0 (default)
1536 * 0 - Auto for all speeds
1539 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1541 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1545 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
1548 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
1551 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
1555 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
1560 * disable_polarity_correction = 0 (default)
1561 * Automatic Correction for Reversed Cable Polarity
1565 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
1566 if(hw->disable_polarity_correction == 1)
1567 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
1568 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1572 if (hw->phy_revision < M88E1011_I_REV_4) {
1573 /* Force TX_CLK in the Extended PHY Specific Control Register
1576 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1580 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1582 if ((hw->phy_revision == E1000_REVISION_2) &&
1583 (hw->phy_id == M88E1111_I_PHY_ID)) {
1584 /* Vidalia Phy, set the downshift counter to 5x */
1585 phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK);
1586 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
1587 ret_val = e1000_write_phy_reg(hw,
1588 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1592 /* Configure Master and Slave downshift values */
1593 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
1594 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
1595 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
1596 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
1597 ret_val = e1000_write_phy_reg(hw,
1598 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1604 /* SW Reset the PHY so all changes take effect */
1605 ret_val = e1000_phy_reset(hw);
1607 DEBUGOUT("Error Resetting the PHY\n");
1611 return E1000_SUCCESS;
1614 /********************************************************************
1615 * Setup auto-negotiation and flow control advertisements,
1616 * and then perform auto-negotiation.
1618 * hw - Struct containing variables accessed by shared code
1619 *********************************************************************/
1621 e1000_copper_link_autoneg(struct e1000_hw *hw)
1626 DEBUGFUNC("e1000_copper_link_autoneg");
1628 /* Perform some bounds checking on the hw->autoneg_advertised
1629 * parameter. If this variable is zero, then set it to the default.
1631 hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
1633 /* If autoneg_advertised is zero, we assume it was not defaulted
1634 * by the calling code so we set to advertise full capability.
1636 if(hw->autoneg_advertised == 0)
1637 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
1639 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
1640 ret_val = e1000_phy_setup_autoneg(hw);
1642 DEBUGOUT("Error Setting up Auto-Negotiation\n");
1645 DEBUGOUT("Restarting Auto-Neg\n");
1647 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
1648 * the Auto Neg Restart bit in the PHY control register.
1650 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
1654 phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
1655 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
1659 /* Does the user want to wait for Auto-Neg to complete here, or
1660 * check at a later time (for example, callback routine).
1662 if(hw->wait_autoneg_complete) {
1663 ret_val = e1000_wait_autoneg(hw);
1665 DEBUGOUT("Error while waiting for autoneg to complete\n");
1670 hw->get_link_status = TRUE;
1672 return E1000_SUCCESS;
1676 /******************************************************************************
1677 * Config the MAC and the PHY after link is up.
1678 * 1) Set up the MAC to the current PHY speed/duplex
1679 * if we are on 82543. If we
1680 * are on newer silicon, we only need to configure
1681 * collision distance in the Transmit Control Register.
1682 * 2) Set up flow control on the MAC to that established with
1684 * 3) Config DSP to improve Gigabit link quality for some PHY revisions.
1686 * hw - Struct containing variables accessed by shared code
1687 ******************************************************************************/
1689 e1000_copper_link_postconfig(struct e1000_hw *hw)
1692 DEBUGFUNC("e1000_copper_link_postconfig");
1694 if(hw->mac_type >= e1000_82544) {
1695 e1000_config_collision_dist(hw);
1697 ret_val = e1000_config_mac_to_phy(hw);
1699 DEBUGOUT("Error configuring MAC to PHY settings\n");
1703 ret_val = e1000_config_fc_after_link_up(hw);
1705 DEBUGOUT("Error Configuring Flow Control\n");
1709 /* Config DSP to improve Giga link quality */
1710 if(hw->phy_type == e1000_phy_igp) {
1711 ret_val = e1000_config_dsp_after_link_change(hw, TRUE);
1713 DEBUGOUT("Error Configuring DSP after link up\n");
1718 return E1000_SUCCESS;
1721 /******************************************************************************
1722 * Detects which PHY is present and setup the speed and duplex
1724 * hw - Struct containing variables accessed by shared code
1725 ******************************************************************************/
1727 e1000_setup_copper_link(struct e1000_hw *hw)
1734 DEBUGFUNC("e1000_setup_copper_link");
1736 /* Check if it is a valid PHY and set PHY mode if necessary. */
1737 ret_val = e1000_copper_link_preconfig(hw);
1741 switch (hw->mac_type) {
1742 case e1000_80003es2lan:
1743 ret_val = e1000_read_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_INB_CTRL,
1747 reg_data |= E1000_KUMCTRLSTA_INB_CTRL_DIS_PADDING;
1748 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_INB_CTRL,
1757 if (hw->phy_type == e1000_phy_igp ||
1758 hw->phy_type == e1000_phy_igp_2) {
1759 ret_val = e1000_copper_link_igp_setup(hw);
1762 } else if (hw->phy_type == e1000_phy_m88) {
1763 ret_val = e1000_copper_link_mgp_setup(hw);
1766 } else if (hw->phy_type == e1000_phy_gg82563) {
1767 ret_val = e1000_copper_link_ggp_setup(hw);
1773 /* Setup autoneg and flow control advertisement
1774 * and perform autonegotiation */
1775 ret_val = e1000_copper_link_autoneg(hw);
1779 /* PHY will be set to 10H, 10F, 100H,or 100F
1780 * depending on value from forced_speed_duplex. */
1781 DEBUGOUT("Forcing speed and duplex\n");
1782 ret_val = e1000_phy_force_speed_duplex(hw);
1784 DEBUGOUT("Error Forcing Speed and Duplex\n");
1789 /* Check link status. Wait up to 100 microseconds for link to become
1792 for(i = 0; i < 10; i++) {
1793 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
1796 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
1800 if(phy_data & MII_SR_LINK_STATUS) {
1801 /* Config the MAC and PHY after link is up */
1802 ret_val = e1000_copper_link_postconfig(hw);
1806 DEBUGOUT("Valid link established!!!\n");
1807 return E1000_SUCCESS;
1812 DEBUGOUT("Unable to establish link!!!\n");
1813 return E1000_SUCCESS;
1816 /******************************************************************************
1817 * Configure the MAC-to-PHY interface for 10/100Mbps
1819 * hw - Struct containing variables accessed by shared code
1820 ******************************************************************************/
1822 e1000_configure_kmrn_for_10_100(struct e1000_hw *hw)
1824 int32_t ret_val = E1000_SUCCESS;
1828 DEBUGFUNC("e1000_configure_kmrn_for_10_100");
1830 reg_data = E1000_KUMCTRLSTA_HD_CTRL_10_100_DEFAULT;
1831 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_HD_CTRL,
1836 /* Configure Transmit Inter-Packet Gap */
1837 tipg = E1000_READ_REG(hw, TIPG);
1838 tipg &= ~E1000_TIPG_IPGT_MASK;
1839 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_10_100;
1840 E1000_WRITE_REG(hw, TIPG, tipg);
1846 e1000_configure_kmrn_for_1000(struct e1000_hw *hw)
1848 int32_t ret_val = E1000_SUCCESS;
1852 DEBUGFUNC("e1000_configure_kmrn_for_1000");
1854 reg_data = E1000_KUMCTRLSTA_HD_CTRL_1000_DEFAULT;
1855 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_HD_CTRL,
1860 /* Configure Transmit Inter-Packet Gap */
1861 tipg = E1000_READ_REG(hw, TIPG);
1862 tipg &= ~E1000_TIPG_IPGT_MASK;
1863 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
1864 E1000_WRITE_REG(hw, TIPG, tipg);
1869 /******************************************************************************
1870 * Configures PHY autoneg and flow control advertisement settings
1872 * hw - Struct containing variables accessed by shared code
1873 ******************************************************************************/
1875 e1000_phy_setup_autoneg(struct e1000_hw *hw)
1878 uint16_t mii_autoneg_adv_reg;
1879 uint16_t mii_1000t_ctrl_reg;
1881 DEBUGFUNC("e1000_phy_setup_autoneg");
1883 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
1884 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
1888 /* Read the MII 1000Base-T Control Register (Address 9). */
1889 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
1893 /* Need to parse both autoneg_advertised and fc and set up
1894 * the appropriate PHY registers. First we will parse for
1895 * autoneg_advertised software override. Since we can advertise
1896 * a plethora of combinations, we need to check each bit
1900 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
1901 * Advertisement Register (Address 4) and the 1000 mb speed bits in
1902 * the 1000Base-T Control Register (Address 9).
1904 mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
1905 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
1907 DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised);
1909 /* Do we want to advertise 10 Mb Half Duplex? */
1910 if(hw->autoneg_advertised & ADVERTISE_10_HALF) {
1911 DEBUGOUT("Advertise 10mb Half duplex\n");
1912 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
1915 /* Do we want to advertise 10 Mb Full Duplex? */
1916 if(hw->autoneg_advertised & ADVERTISE_10_FULL) {
1917 DEBUGOUT("Advertise 10mb Full duplex\n");
1918 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
1921 /* Do we want to advertise 100 Mb Half Duplex? */
1922 if(hw->autoneg_advertised & ADVERTISE_100_HALF) {
1923 DEBUGOUT("Advertise 100mb Half duplex\n");
1924 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
1927 /* Do we want to advertise 100 Mb Full Duplex? */
1928 if(hw->autoneg_advertised & ADVERTISE_100_FULL) {
1929 DEBUGOUT("Advertise 100mb Full duplex\n");
1930 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
1933 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
1934 if(hw->autoneg_advertised & ADVERTISE_1000_HALF) {
1935 DEBUGOUT("Advertise 1000mb Half duplex requested, request denied!\n");
1938 /* Do we want to advertise 1000 Mb Full Duplex? */
1939 if(hw->autoneg_advertised & ADVERTISE_1000_FULL) {
1940 DEBUGOUT("Advertise 1000mb Full duplex\n");
1941 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
1944 /* Check for a software override of the flow control settings, and
1945 * setup the PHY advertisement registers accordingly. If
1946 * auto-negotiation is enabled, then software will have to set the
1947 * "PAUSE" bits to the correct value in the Auto-Negotiation
1948 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
1950 * The possible values of the "fc" parameter are:
1951 * 0: Flow control is completely disabled
1952 * 1: Rx flow control is enabled (we can receive pause frames
1953 * but not send pause frames).
1954 * 2: Tx flow control is enabled (we can send pause frames
1955 * but we do not support receiving pause frames).
1956 * 3: Both Rx and TX flow control (symmetric) are enabled.
1957 * other: No software override. The flow control configuration
1958 * in the EEPROM is used.
1961 case e1000_fc_none: /* 0 */
1962 /* Flow control (RX & TX) is completely disabled by a
1963 * software over-ride.
1965 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1967 case e1000_fc_rx_pause: /* 1 */
1968 /* RX Flow control is enabled, and TX Flow control is
1969 * disabled, by a software over-ride.
1971 /* Since there really isn't a way to advertise that we are
1972 * capable of RX Pause ONLY, we will advertise that we
1973 * support both symmetric and asymmetric RX PAUSE. Later
1974 * (in e1000_config_fc_after_link_up) we will disable the
1975 *hw's ability to send PAUSE frames.
1977 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1979 case e1000_fc_tx_pause: /* 2 */
1980 /* TX Flow control is enabled, and RX Flow control is
1981 * disabled, by a software over-ride.
1983 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
1984 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
1986 case e1000_fc_full: /* 3 */
1987 /* Flow control (both RX and TX) is enabled by a software
1990 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1993 DEBUGOUT("Flow control param set incorrectly\n");
1994 return -E1000_ERR_CONFIG;
1997 ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
2001 DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
2003 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg);
2007 return E1000_SUCCESS;
2010 /******************************************************************************
2011 * Force PHY speed and duplex settings to hw->forced_speed_duplex
2013 * hw - Struct containing variables accessed by shared code
2014 ******************************************************************************/
2016 e1000_phy_force_speed_duplex(struct e1000_hw *hw)
2020 uint16_t mii_ctrl_reg;
2021 uint16_t mii_status_reg;
2025 DEBUGFUNC("e1000_phy_force_speed_duplex");
2027 /* Turn off Flow control if we are forcing speed and duplex. */
2028 hw->fc = e1000_fc_none;
2030 DEBUGOUT1("hw->fc = %d\n", hw->fc);
2032 /* Read the Device Control Register. */
2033 ctrl = E1000_READ_REG(hw, CTRL);
2035 /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */
2036 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2037 ctrl &= ~(DEVICE_SPEED_MASK);
2039 /* Clear the Auto Speed Detect Enable bit. */
2040 ctrl &= ~E1000_CTRL_ASDE;
2042 /* Read the MII Control Register. */
2043 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg);
2047 /* We need to disable autoneg in order to force link and duplex. */
2049 mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN;
2051 /* Are we forcing Full or Half Duplex? */
2052 if(hw->forced_speed_duplex == e1000_100_full ||
2053 hw->forced_speed_duplex == e1000_10_full) {
2054 /* We want to force full duplex so we SET the full duplex bits in the
2055 * Device and MII Control Registers.
2057 ctrl |= E1000_CTRL_FD;
2058 mii_ctrl_reg |= MII_CR_FULL_DUPLEX;
2059 DEBUGOUT("Full Duplex\n");
2061 /* We want to force half duplex so we CLEAR the full duplex bits in
2062 * the Device and MII Control Registers.
2064 ctrl &= ~E1000_CTRL_FD;
2065 mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX;
2066 DEBUGOUT("Half Duplex\n");
2069 /* Are we forcing 100Mbps??? */
2070 if(hw->forced_speed_duplex == e1000_100_full ||
2071 hw->forced_speed_duplex == e1000_100_half) {
2072 /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */
2073 ctrl |= E1000_CTRL_SPD_100;
2074 mii_ctrl_reg |= MII_CR_SPEED_100;
2075 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
2076 DEBUGOUT("Forcing 100mb ");
2078 /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */
2079 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
2080 mii_ctrl_reg |= MII_CR_SPEED_10;
2081 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
2082 DEBUGOUT("Forcing 10mb ");
2085 e1000_config_collision_dist(hw);
2087 /* Write the configured values back to the Device Control Reg. */
2088 E1000_WRITE_REG(hw, CTRL, ctrl);
2090 if ((hw->phy_type == e1000_phy_m88) ||
2091 (hw->phy_type == e1000_phy_gg82563)) {
2092 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
2096 /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
2097 * forced whenever speed are duplex are forced.
2099 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
2100 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
2104 DEBUGOUT1("M88E1000 PSCR: %x \n", phy_data);
2106 /* Need to reset the PHY or these changes will be ignored */
2107 mii_ctrl_reg |= MII_CR_RESET;
2109 /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
2110 * forced whenever speed or duplex are forced.
2112 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
2116 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
2117 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
2119 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
2124 /* Write back the modified PHY MII control register. */
2125 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg);
2131 /* The wait_autoneg_complete flag may be a little misleading here.
2132 * Since we are forcing speed and duplex, Auto-Neg is not enabled.
2133 * But we do want to delay for a period while forcing only so we
2134 * don't generate false No Link messages. So we will wait here
2135 * only if the user has set wait_autoneg_complete to 1, which is
2138 if(hw->wait_autoneg_complete) {
2139 /* We will wait for autoneg to complete. */
2140 DEBUGOUT("Waiting for forced speed/duplex link.\n");
2143 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
2144 for(i = PHY_FORCE_TIME; i > 0; i--) {
2145 /* Read the MII Status Register and wait for Auto-Neg Complete bit
2148 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2152 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2156 if(mii_status_reg & MII_SR_LINK_STATUS) break;
2160 ((hw->phy_type == e1000_phy_m88) ||
2161 (hw->phy_type == e1000_phy_gg82563))) {
2162 /* We didn't get link. Reset the DSP and wait again for link. */
2163 ret_val = e1000_phy_reset_dsp(hw);
2165 DEBUGOUT("Error Resetting PHY DSP\n");
2169 /* This loop will early-out if the link condition has been met. */
2170 for(i = PHY_FORCE_TIME; i > 0; i--) {
2171 if(mii_status_reg & MII_SR_LINK_STATUS) break;
2173 /* Read the MII Status Register and wait for Auto-Neg Complete bit
2176 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2180 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2186 if (hw->phy_type == e1000_phy_m88) {
2187 /* Because we reset the PHY above, we need to re-force TX_CLK in the
2188 * Extended PHY Specific Control Register to 25MHz clock. This value
2189 * defaults back to a 2.5MHz clock when the PHY is reset.
2191 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
2195 phy_data |= M88E1000_EPSCR_TX_CLK_25;
2196 ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
2200 /* In addition, because of the s/w reset above, we need to enable CRS on
2201 * TX. This must be set for both full and half duplex operation.
2203 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
2207 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
2208 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
2212 if((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
2214 (hw->forced_speed_duplex == e1000_10_full ||
2215 hw->forced_speed_duplex == e1000_10_half)) {
2216 ret_val = e1000_polarity_reversal_workaround(hw);
2220 } else if (hw->phy_type == e1000_phy_gg82563) {
2221 /* The TX_CLK of the Extended PHY Specific Control Register defaults
2222 * to 2.5MHz on a reset. We need to re-force it back to 25MHz, if
2223 * we're not in a forced 10/duplex configuration. */
2224 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, &phy_data);
2228 phy_data &= ~GG82563_MSCR_TX_CLK_MASK;
2229 if ((hw->forced_speed_duplex == e1000_10_full) ||
2230 (hw->forced_speed_duplex == e1000_10_half))
2231 phy_data |= GG82563_MSCR_TX_CLK_10MBPS_2_5MHZ;
2233 phy_data |= GG82563_MSCR_TX_CLK_100MBPS_25MHZ;
2235 /* Also due to the reset, we need to enable CRS on Tx. */
2236 phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
2238 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, phy_data);
2242 return E1000_SUCCESS;
2245 /******************************************************************************
2246 * Sets the collision distance in the Transmit Control register
2248 * hw - Struct containing variables accessed by shared code
2250 * Link should have been established previously. Reads the speed and duplex
2251 * information from the Device Status register.
2252 ******************************************************************************/
2254 e1000_config_collision_dist(struct e1000_hw *hw)
2256 uint32_t tctl, coll_dist;
2258 DEBUGFUNC("e1000_config_collision_dist");
2260 if (hw->mac_type < e1000_82543)
2261 coll_dist = E1000_COLLISION_DISTANCE_82542;
2263 coll_dist = E1000_COLLISION_DISTANCE;
2265 tctl = E1000_READ_REG(hw, TCTL);
2267 tctl &= ~E1000_TCTL_COLD;
2268 tctl |= coll_dist << E1000_COLD_SHIFT;
2270 E1000_WRITE_REG(hw, TCTL, tctl);
2271 E1000_WRITE_FLUSH(hw);
2274 /******************************************************************************
2275 * Sets MAC speed and duplex settings to reflect the those in the PHY
2277 * hw - Struct containing variables accessed by shared code
2278 * mii_reg - data to write to the MII control register
2280 * The contents of the PHY register containing the needed information need to
2282 ******************************************************************************/
2284 e1000_config_mac_to_phy(struct e1000_hw *hw)
2290 DEBUGFUNC("e1000_config_mac_to_phy");
2292 /* 82544 or newer MAC, Auto Speed Detection takes care of
2293 * MAC speed/duplex configuration.*/
2294 if (hw->mac_type >= e1000_82544)
2295 return E1000_SUCCESS;
2297 /* Read the Device Control Register and set the bits to Force Speed
2300 ctrl = E1000_READ_REG(hw, CTRL);
2301 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2302 ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
2304 /* Set up duplex in the Device Control and Transmit Control
2305 * registers depending on negotiated values.
2307 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
2311 if(phy_data & M88E1000_PSSR_DPLX)
2312 ctrl |= E1000_CTRL_FD;
2314 ctrl &= ~E1000_CTRL_FD;
2316 e1000_config_collision_dist(hw);
2318 /* Set up speed in the Device Control register depending on
2319 * negotiated values.
2321 if((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
2322 ctrl |= E1000_CTRL_SPD_1000;
2323 else if((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
2324 ctrl |= E1000_CTRL_SPD_100;
2326 /* Write the configured values back to the Device Control Reg. */
2327 E1000_WRITE_REG(hw, CTRL, ctrl);
2328 return E1000_SUCCESS;
2331 /******************************************************************************
2332 * Forces the MAC's flow control settings.
2334 * hw - Struct containing variables accessed by shared code
2336 * Sets the TFCE and RFCE bits in the device control register to reflect
2337 * the adapter settings. TFCE and RFCE need to be explicitly set by
2338 * software when a Copper PHY is used because autonegotiation is managed
2339 * by the PHY rather than the MAC. Software must also configure these
2340 * bits when link is forced on a fiber connection.
2341 *****************************************************************************/
2343 e1000_force_mac_fc(struct e1000_hw *hw)
2347 DEBUGFUNC("e1000_force_mac_fc");
2349 /* Get the current configuration of the Device Control Register */
2350 ctrl = E1000_READ_REG(hw, CTRL);
2352 /* Because we didn't get link via the internal auto-negotiation
2353 * mechanism (we either forced link or we got link via PHY
2354 * auto-neg), we have to manually enable/disable transmit an
2355 * receive flow control.
2357 * The "Case" statement below enables/disable flow control
2358 * according to the "hw->fc" parameter.
2360 * The possible values of the "fc" parameter are:
2361 * 0: Flow control is completely disabled
2362 * 1: Rx flow control is enabled (we can receive pause
2363 * frames but not send pause frames).
2364 * 2: Tx flow control is enabled (we can send pause frames
2365 * frames but we do not receive pause frames).
2366 * 3: Both Rx and TX flow control (symmetric) is enabled.
2367 * other: No other values should be possible at this point.
2372 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
2374 case e1000_fc_rx_pause:
2375 ctrl &= (~E1000_CTRL_TFCE);
2376 ctrl |= E1000_CTRL_RFCE;
2378 case e1000_fc_tx_pause:
2379 ctrl &= (~E1000_CTRL_RFCE);
2380 ctrl |= E1000_CTRL_TFCE;
2383 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
2386 DEBUGOUT("Flow control param set incorrectly\n");
2387 return -E1000_ERR_CONFIG;
2390 /* Disable TX Flow Control for 82542 (rev 2.0) */
2391 if(hw->mac_type == e1000_82542_rev2_0)
2392 ctrl &= (~E1000_CTRL_TFCE);
2394 E1000_WRITE_REG(hw, CTRL, ctrl);
2395 return E1000_SUCCESS;
2398 /******************************************************************************
2399 * Configures flow control settings after link is established
2401 * hw - Struct containing variables accessed by shared code
2403 * Should be called immediately after a valid link has been established.
2404 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
2405 * and autonegotiation is enabled, the MAC flow control settings will be set
2406 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
2407 * and RFCE bits will be automaticaly set to the negotiated flow control mode.
2408 *****************************************************************************/
2410 e1000_config_fc_after_link_up(struct e1000_hw *hw)
2413 uint16_t mii_status_reg;
2414 uint16_t mii_nway_adv_reg;
2415 uint16_t mii_nway_lp_ability_reg;
2419 DEBUGFUNC("e1000_config_fc_after_link_up");
2421 /* Check for the case where we have fiber media and auto-neg failed
2422 * so we had to force link. In this case, we need to force the
2423 * configuration of the MAC to match the "fc" parameter.
2425 if(((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) ||
2426 ((hw->media_type == e1000_media_type_internal_serdes) && (hw->autoneg_failed)) ||
2427 ((hw->media_type == e1000_media_type_copper) && (!hw->autoneg))) {
2428 ret_val = e1000_force_mac_fc(hw);
2430 DEBUGOUT("Error forcing flow control settings\n");
2435 /* Check for the case where we have copper media and auto-neg is
2436 * enabled. In this case, we need to check and see if Auto-Neg
2437 * has completed, and if so, how the PHY and link partner has
2438 * flow control configured.
2440 if((hw->media_type == e1000_media_type_copper) && hw->autoneg) {
2441 /* Read the MII Status Register and check to see if AutoNeg
2442 * has completed. We read this twice because this reg has
2443 * some "sticky" (latched) bits.
2445 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2448 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2452 if(mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
2453 /* The AutoNeg process has completed, so we now need to
2454 * read both the Auto Negotiation Advertisement Register
2455 * (Address 4) and the Auto_Negotiation Base Page Ability
2456 * Register (Address 5) to determine how flow control was
2459 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV,
2463 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY,
2464 &mii_nway_lp_ability_reg);
2468 /* Two bits in the Auto Negotiation Advertisement Register
2469 * (Address 4) and two bits in the Auto Negotiation Base
2470 * Page Ability Register (Address 5) determine flow control
2471 * for both the PHY and the link partner. The following
2472 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
2473 * 1999, describes these PAUSE resolution bits and how flow
2474 * control is determined based upon these settings.
2475 * NOTE: DC = Don't Care
2477 * LOCAL DEVICE | LINK PARTNER
2478 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
2479 *-------|---------|-------|---------|--------------------
2480 * 0 | 0 | DC | DC | e1000_fc_none
2481 * 0 | 1 | 0 | DC | e1000_fc_none
2482 * 0 | 1 | 1 | 0 | e1000_fc_none
2483 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
2484 * 1 | 0 | 0 | DC | e1000_fc_none
2485 * 1 | DC | 1 | DC | e1000_fc_full
2486 * 1 | 1 | 0 | 0 | e1000_fc_none
2487 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
2490 /* Are both PAUSE bits set to 1? If so, this implies
2491 * Symmetric Flow Control is enabled at both ends. The
2492 * ASM_DIR bits are irrelevant per the spec.
2494 * For Symmetric Flow Control:
2496 * LOCAL DEVICE | LINK PARTNER
2497 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2498 *-------|---------|-------|---------|--------------------
2499 * 1 | DC | 1 | DC | e1000_fc_full
2502 if((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2503 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
2504 /* Now we need to check if the user selected RX ONLY
2505 * of pause frames. In this case, we had to advertise
2506 * FULL flow control because we could not advertise RX
2507 * ONLY. Hence, we must now check to see if we need to
2508 * turn OFF the TRANSMISSION of PAUSE frames.
2510 if(hw->original_fc == e1000_fc_full) {
2511 hw->fc = e1000_fc_full;
2512 DEBUGOUT("Flow Control = FULL.\n");
2514 hw->fc = e1000_fc_rx_pause;
2515 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
2518 /* For receiving PAUSE frames ONLY.
2520 * LOCAL DEVICE | LINK PARTNER
2521 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2522 *-------|---------|-------|---------|--------------------
2523 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
2526 else if(!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2527 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2528 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2529 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
2530 hw->fc = e1000_fc_tx_pause;
2531 DEBUGOUT("Flow Control = TX PAUSE frames only.\n");
2533 /* For transmitting PAUSE frames ONLY.
2535 * LOCAL DEVICE | LINK PARTNER
2536 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2537 *-------|---------|-------|---------|--------------------
2538 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
2541 else if((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2542 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2543 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2544 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
2545 hw->fc = e1000_fc_rx_pause;
2546 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
2548 /* Per the IEEE spec, at this point flow control should be
2549 * disabled. However, we want to consider that we could
2550 * be connected to a legacy switch that doesn't advertise
2551 * desired flow control, but can be forced on the link
2552 * partner. So if we advertised no flow control, that is
2553 * what we will resolve to. If we advertised some kind of
2554 * receive capability (Rx Pause Only or Full Flow Control)
2555 * and the link partner advertised none, we will configure
2556 * ourselves to enable Rx Flow Control only. We can do
2557 * this safely for two reasons: If the link partner really
2558 * didn't want flow control enabled, and we enable Rx, no
2559 * harm done since we won't be receiving any PAUSE frames
2560 * anyway. If the intent on the link partner was to have
2561 * flow control enabled, then by us enabling RX only, we
2562 * can at least receive pause frames and process them.
2563 * This is a good idea because in most cases, since we are
2564 * predominantly a server NIC, more times than not we will
2565 * be asked to delay transmission of packets than asking
2566 * our link partner to pause transmission of frames.
2568 else if((hw->original_fc == e1000_fc_none ||
2569 hw->original_fc == e1000_fc_tx_pause) ||
2570 hw->fc_strict_ieee) {
2571 hw->fc = e1000_fc_none;
2572 DEBUGOUT("Flow Control = NONE.\n");
2574 hw->fc = e1000_fc_rx_pause;
2575 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
2578 /* Now we need to do one last check... If we auto-
2579 * negotiated to HALF DUPLEX, flow control should not be
2580 * enabled per IEEE 802.3 spec.
2582 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
2584 DEBUGOUT("Error getting link speed and duplex\n");
2588 if(duplex == HALF_DUPLEX)
2589 hw->fc = e1000_fc_none;
2591 /* Now we call a subroutine to actually force the MAC
2592 * controller to use the correct flow control settings.
2594 ret_val = e1000_force_mac_fc(hw);
2596 DEBUGOUT("Error forcing flow control settings\n");
2600 DEBUGOUT("Copper PHY and Auto Neg has not completed.\n");
2603 return E1000_SUCCESS;
2606 /******************************************************************************
2607 * Checks to see if the link status of the hardware has changed.
2609 * hw - Struct containing variables accessed by shared code
2611 * Called by any function that needs to check the link status of the adapter.
2612 *****************************************************************************/
2614 e1000_check_for_link(struct e1000_hw *hw)
2621 uint32_t signal = 0;
2625 DEBUGFUNC("e1000_check_for_link");
2627 ctrl = E1000_READ_REG(hw, CTRL);
2628 status = E1000_READ_REG(hw, STATUS);
2630 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
2631 * set when the optics detect a signal. On older adapters, it will be
2632 * cleared when there is a signal. This applies to fiber media only.
2634 if((hw->media_type == e1000_media_type_fiber) ||
2635 (hw->media_type == e1000_media_type_internal_serdes)) {
2636 rxcw = E1000_READ_REG(hw, RXCW);
2638 if(hw->media_type == e1000_media_type_fiber) {
2639 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
2640 if(status & E1000_STATUS_LU)
2641 hw->get_link_status = FALSE;
2645 /* If we have a copper PHY then we only want to go out to the PHY
2646 * registers to see if Auto-Neg has completed and/or if our link
2647 * status has changed. The get_link_status flag will be set if we
2648 * receive a Link Status Change interrupt or we have Rx Sequence
2651 if((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
2652 /* First we want to see if the MII Status Register reports
2653 * link. If so, then we want to get the current speed/duplex
2655 * Read the register twice since the link bit is sticky.
2657 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2660 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2664 if(phy_data & MII_SR_LINK_STATUS) {
2665 hw->get_link_status = FALSE;
2666 /* Check if there was DownShift, must be checked immediately after
2668 e1000_check_downshift(hw);
2670 /* If we are on 82544 or 82543 silicon and speed/duplex
2671 * are forced to 10H or 10F, then we will implement the polarity
2672 * reversal workaround. We disable interrupts first, and upon
2673 * returning, place the devices interrupt state to its previous
2674 * value except for the link status change interrupt which will
2675 * happen due to the execution of this workaround.
2678 if((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
2680 (hw->forced_speed_duplex == e1000_10_full ||
2681 hw->forced_speed_duplex == e1000_10_half)) {
2682 E1000_WRITE_REG(hw, IMC, 0xffffffff);
2683 ret_val = e1000_polarity_reversal_workaround(hw);
2684 icr = E1000_READ_REG(hw, ICR);
2685 E1000_WRITE_REG(hw, ICS, (icr & ~E1000_ICS_LSC));
2686 E1000_WRITE_REG(hw, IMS, IMS_ENABLE_MASK);
2690 /* No link detected */
2691 e1000_config_dsp_after_link_change(hw, FALSE);
2695 /* If we are forcing speed/duplex, then we simply return since
2696 * we have already determined whether we have link or not.
2698 if(!hw->autoneg) return -E1000_ERR_CONFIG;
2700 /* optimize the dsp settings for the igp phy */
2701 e1000_config_dsp_after_link_change(hw, TRUE);
2703 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
2704 * have Si on board that is 82544 or newer, Auto
2705 * Speed Detection takes care of MAC speed/duplex
2706 * configuration. So we only need to configure Collision
2707 * Distance in the MAC. Otherwise, we need to force
2708 * speed/duplex on the MAC to the current PHY speed/duplex
2711 if(hw->mac_type >= e1000_82544)
2712 e1000_config_collision_dist(hw);
2714 ret_val = e1000_config_mac_to_phy(hw);
2716 DEBUGOUT("Error configuring MAC to PHY settings\n");
2721 /* Configure Flow Control now that Auto-Neg has completed. First, we
2722 * need to restore the desired flow control settings because we may
2723 * have had to re-autoneg with a different link partner.
2725 ret_val = e1000_config_fc_after_link_up(hw);
2727 DEBUGOUT("Error configuring flow control\n");
2731 /* At this point we know that we are on copper and we have
2732 * auto-negotiated link. These are conditions for checking the link
2733 * partner capability register. We use the link speed to determine if
2734 * TBI compatibility needs to be turned on or off. If the link is not
2735 * at gigabit speed, then TBI compatibility is not needed. If we are
2736 * at gigabit speed, we turn on TBI compatibility.
2738 if(hw->tbi_compatibility_en) {
2739 uint16_t speed, duplex;
2740 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
2742 DEBUGOUT("Error getting link speed and duplex\n");
2745 if (speed != SPEED_1000) {
2746 /* If link speed is not set to gigabit speed, we do not need
2747 * to enable TBI compatibility.
2749 if(hw->tbi_compatibility_on) {
2750 /* If we previously were in the mode, turn it off. */
2751 rctl = E1000_READ_REG(hw, RCTL);
2752 rctl &= ~E1000_RCTL_SBP;
2753 E1000_WRITE_REG(hw, RCTL, rctl);
2754 hw->tbi_compatibility_on = FALSE;
2757 /* If TBI compatibility is was previously off, turn it on. For
2758 * compatibility with a TBI link partner, we will store bad
2759 * packets. Some frames have an additional byte on the end and
2760 * will look like CRC errors to to the hardware.
2762 if(!hw->tbi_compatibility_on) {
2763 hw->tbi_compatibility_on = TRUE;
2764 rctl = E1000_READ_REG(hw, RCTL);
2765 rctl |= E1000_RCTL_SBP;
2766 E1000_WRITE_REG(hw, RCTL, rctl);
2771 /* If we don't have link (auto-negotiation failed or link partner cannot
2772 * auto-negotiate), the cable is plugged in (we have signal), and our
2773 * link partner is not trying to auto-negotiate with us (we are receiving
2774 * idles or data), we need to force link up. We also need to give
2775 * auto-negotiation time to complete, in case the cable was just plugged
2776 * in. The autoneg_failed flag does this.
2778 else if((((hw->media_type == e1000_media_type_fiber) &&
2779 ((ctrl & E1000_CTRL_SWDPIN1) == signal)) ||
2780 (hw->media_type == e1000_media_type_internal_serdes)) &&
2781 (!(status & E1000_STATUS_LU)) &&
2782 (!(rxcw & E1000_RXCW_C))) {
2783 if(hw->autoneg_failed == 0) {
2784 hw->autoneg_failed = 1;
2787 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\n");
2789 /* Disable auto-negotiation in the TXCW register */
2790 E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
2792 /* Force link-up and also force full-duplex. */
2793 ctrl = E1000_READ_REG(hw, CTRL);
2794 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
2795 E1000_WRITE_REG(hw, CTRL, ctrl);
2797 /* Configure Flow Control after forcing link up. */
2798 ret_val = e1000_config_fc_after_link_up(hw);
2800 DEBUGOUT("Error configuring flow control\n");
2804 /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
2805 * auto-negotiation in the TXCW register and disable forced link in the
2806 * Device Control register in an attempt to auto-negotiate with our link
2809 else if(((hw->media_type == e1000_media_type_fiber) ||
2810 (hw->media_type == e1000_media_type_internal_serdes)) &&
2811 (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
2812 DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\n");
2813 E1000_WRITE_REG(hw, TXCW, hw->txcw);
2814 E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
2816 hw->serdes_link_down = FALSE;
2818 /* If we force link for non-auto-negotiation switch, check link status
2819 * based on MAC synchronization for internal serdes media type.
2821 else if((hw->media_type == e1000_media_type_internal_serdes) &&
2822 !(E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
2823 /* SYNCH bit and IV bit are sticky. */
2825 if(E1000_RXCW_SYNCH & E1000_READ_REG(hw, RXCW)) {
2826 if(!(rxcw & E1000_RXCW_IV)) {
2827 hw->serdes_link_down = FALSE;
2828 DEBUGOUT("SERDES: Link is up.\n");
2831 hw->serdes_link_down = TRUE;
2832 DEBUGOUT("SERDES: Link is down.\n");
2835 if((hw->media_type == e1000_media_type_internal_serdes) &&
2836 (E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
2837 hw->serdes_link_down = !(E1000_STATUS_LU & E1000_READ_REG(hw, STATUS));
2839 return E1000_SUCCESS;
2842 /******************************************************************************
2843 * Detects the current speed and duplex settings of the hardware.
2845 * hw - Struct containing variables accessed by shared code
2846 * speed - Speed of the connection
2847 * duplex - Duplex setting of the connection
2848 *****************************************************************************/
2850 e1000_get_speed_and_duplex(struct e1000_hw *hw,
2858 DEBUGFUNC("e1000_get_speed_and_duplex");
2860 if(hw->mac_type >= e1000_82543) {
2861 status = E1000_READ_REG(hw, STATUS);
2862 if(status & E1000_STATUS_SPEED_1000) {
2863 *speed = SPEED_1000;
2864 DEBUGOUT("1000 Mbs, ");
2865 } else if(status & E1000_STATUS_SPEED_100) {
2867 DEBUGOUT("100 Mbs, ");
2870 DEBUGOUT("10 Mbs, ");
2873 if(status & E1000_STATUS_FD) {
2874 *duplex = FULL_DUPLEX;
2875 DEBUGOUT("Full Duplex\n");
2877 *duplex = HALF_DUPLEX;
2878 DEBUGOUT(" Half Duplex\n");
2881 DEBUGOUT("1000 Mbs, Full Duplex\n");
2882 *speed = SPEED_1000;
2883 *duplex = FULL_DUPLEX;
2886 /* IGP01 PHY may advertise full duplex operation after speed downgrade even
2887 * if it is operating at half duplex. Here we set the duplex settings to
2888 * match the duplex in the link partner's capabilities.
2890 if(hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
2891 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
2895 if(!(phy_data & NWAY_ER_LP_NWAY_CAPS))
2896 *duplex = HALF_DUPLEX;
2898 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data);
2901 if((*speed == SPEED_100 && !(phy_data & NWAY_LPAR_100TX_FD_CAPS)) ||
2902 (*speed == SPEED_10 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
2903 *duplex = HALF_DUPLEX;
2907 if ((hw->mac_type == e1000_80003es2lan) &&
2908 (hw->media_type == e1000_media_type_copper)) {
2909 if (*speed == SPEED_1000)
2910 ret_val = e1000_configure_kmrn_for_1000(hw);
2912 ret_val = e1000_configure_kmrn_for_10_100(hw);
2917 return E1000_SUCCESS;
2920 /******************************************************************************
2921 * Blocks until autoneg completes or times out (~4.5 seconds)
2923 * hw - Struct containing variables accessed by shared code
2924 ******************************************************************************/
2926 e1000_wait_autoneg(struct e1000_hw *hw)
2932 DEBUGFUNC("e1000_wait_autoneg");
2933 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
2935 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
2936 for(i = PHY_AUTO_NEG_TIME; i > 0; i--) {
2937 /* Read the MII Status Register and wait for Auto-Neg
2938 * Complete bit to be set.
2940 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2943 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2946 if(phy_data & MII_SR_AUTONEG_COMPLETE) {
2947 return E1000_SUCCESS;
2951 return E1000_SUCCESS;
2954 /******************************************************************************
2955 * Raises the Management Data Clock
2957 * hw - Struct containing variables accessed by shared code
2958 * ctrl - Device control register's current value
2959 ******************************************************************************/
2961 e1000_raise_mdi_clk(struct e1000_hw *hw,
2964 /* Raise the clock input to the Management Data Clock (by setting the MDC
2965 * bit), and then delay 10 microseconds.
2967 E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
2968 E1000_WRITE_FLUSH(hw);
2972 /******************************************************************************
2973 * Lowers the Management Data Clock
2975 * hw - Struct containing variables accessed by shared code
2976 * ctrl - Device control register's current value
2977 ******************************************************************************/
2979 e1000_lower_mdi_clk(struct e1000_hw *hw,
2982 /* Lower the clock input to the Management Data Clock (by clearing the MDC
2983 * bit), and then delay 10 microseconds.
2985 E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
2986 E1000_WRITE_FLUSH(hw);
2990 /******************************************************************************
2991 * Shifts data bits out to the PHY
2993 * hw - Struct containing variables accessed by shared code
2994 * data - Data to send out to the PHY
2995 * count - Number of bits to shift out
2997 * Bits are shifted out in MSB to LSB order.
2998 ******************************************************************************/
3000 e1000_shift_out_mdi_bits(struct e1000_hw *hw,
3007 /* We need to shift "count" number of bits out to the PHY. So, the value
3008 * in the "data" parameter will be shifted out to the PHY one bit at a
3009 * time. In order to do this, "data" must be broken down into bits.
3012 mask <<= (count - 1);
3014 ctrl = E1000_READ_REG(hw, CTRL);
3016 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
3017 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
3020 /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
3021 * then raising and lowering the Management Data Clock. A "0" is
3022 * shifted out to the PHY by setting the MDIO bit to "0" and then
3023 * raising and lowering the clock.
3025 if(data & mask) ctrl |= E1000_CTRL_MDIO;
3026 else ctrl &= ~E1000_CTRL_MDIO;
3028 E1000_WRITE_REG(hw, CTRL, ctrl);
3029 E1000_WRITE_FLUSH(hw);
3033 e1000_raise_mdi_clk(hw, &ctrl);
3034 e1000_lower_mdi_clk(hw, &ctrl);
3040 /******************************************************************************
3041 * Shifts data bits in from the PHY
3043 * hw - Struct containing variables accessed by shared code
3045 * Bits are shifted in in MSB to LSB order.
3046 ******************************************************************************/
3048 e1000_shift_in_mdi_bits(struct e1000_hw *hw)
3054 /* In order to read a register from the PHY, we need to shift in a total
3055 * of 18 bits from the PHY. The first two bit (turnaround) times are used
3056 * to avoid contention on the MDIO pin when a read operation is performed.
3057 * These two bits are ignored by us and thrown away. Bits are "shifted in"
3058 * by raising the input to the Management Data Clock (setting the MDC bit),
3059 * and then reading the value of the MDIO bit.
3061 ctrl = E1000_READ_REG(hw, CTRL);
3063 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
3064 ctrl &= ~E1000_CTRL_MDIO_DIR;
3065 ctrl &= ~E1000_CTRL_MDIO;
3067 E1000_WRITE_REG(hw, CTRL, ctrl);
3068 E1000_WRITE_FLUSH(hw);
3070 /* Raise and Lower the clock before reading in the data. This accounts for
3071 * the turnaround bits. The first clock occurred when we clocked out the
3072 * last bit of the Register Address.
3074 e1000_raise_mdi_clk(hw, &ctrl);
3075 e1000_lower_mdi_clk(hw, &ctrl);
3077 for(data = 0, i = 0; i < 16; i++) {
3079 e1000_raise_mdi_clk(hw, &ctrl);
3080 ctrl = E1000_READ_REG(hw, CTRL);
3081 /* Check to see if we shifted in a "1". */
3082 if(ctrl & E1000_CTRL_MDIO) data |= 1;
3083 e1000_lower_mdi_clk(hw, &ctrl);
3086 e1000_raise_mdi_clk(hw, &ctrl);
3087 e1000_lower_mdi_clk(hw, &ctrl);
3093 e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask)
3095 uint32_t swfw_sync = 0;
3096 uint32_t swmask = mask;
3097 uint32_t fwmask = mask << 16;
3098 int32_t timeout = 200;
3100 DEBUGFUNC("e1000_swfw_sync_acquire");
3102 if (!hw->swfw_sync_present)
3103 return e1000_get_hw_eeprom_semaphore(hw);
3106 if (e1000_get_hw_eeprom_semaphore(hw))
3107 return -E1000_ERR_SWFW_SYNC;
3109 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
3110 if (!(swfw_sync & (fwmask | swmask))) {
3114 /* firmware currently using resource (fwmask) */
3115 /* or other software thread currently using resource (swmask) */
3116 e1000_put_hw_eeprom_semaphore(hw);
3122 DEBUGOUT("Driver can't access resource, SW_FW_SYNC timeout.\n");
3123 return -E1000_ERR_SWFW_SYNC;
3126 swfw_sync |= swmask;
3127 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
3129 e1000_put_hw_eeprom_semaphore(hw);
3130 return E1000_SUCCESS;
3134 e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask)
3137 uint32_t swmask = mask;
3139 DEBUGFUNC("e1000_swfw_sync_release");
3141 if (!hw->swfw_sync_present) {
3142 e1000_put_hw_eeprom_semaphore(hw);
3146 /* if (e1000_get_hw_eeprom_semaphore(hw))
3147 * return -E1000_ERR_SWFW_SYNC; */
3148 while (e1000_get_hw_eeprom_semaphore(hw) != E1000_SUCCESS);
3151 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
3152 swfw_sync &= ~swmask;
3153 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
3155 e1000_put_hw_eeprom_semaphore(hw);
3158 /*****************************************************************************
3159 * Reads the value from a PHY register, if the value is on a specific non zero
3160 * page, sets the page first.
3161 * hw - Struct containing variables accessed by shared code
3162 * reg_addr - address of the PHY register to read
3163 ******************************************************************************/
3165 e1000_read_phy_reg(struct e1000_hw *hw,
3172 DEBUGFUNC("e1000_read_phy_reg");
3174 if ((hw->mac_type == e1000_80003es2lan) &&
3175 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3176 swfw = E1000_SWFW_PHY1_SM;
3178 swfw = E1000_SWFW_PHY0_SM;
3180 if (e1000_swfw_sync_acquire(hw, swfw))
3181 return -E1000_ERR_SWFW_SYNC;
3183 if((hw->phy_type == e1000_phy_igp ||
3184 hw->phy_type == e1000_phy_igp_2) &&
3185 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
3186 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
3187 (uint16_t)reg_addr);
3189 e1000_swfw_sync_release(hw, swfw);
3192 } else if (hw->phy_type == e1000_phy_gg82563) {
3193 if (((reg_addr & MAX_PHY_REG_ADDRESS) > MAX_PHY_MULTI_PAGE_REG) ||
3194 (hw->mac_type == e1000_80003es2lan)) {
3195 /* Select Configuration Page */
3196 if ((reg_addr & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) {
3197 ret_val = e1000_write_phy_reg_ex(hw, GG82563_PHY_PAGE_SELECT,
3198 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3200 /* Use Alternative Page Select register to access
3201 * registers 30 and 31
3203 ret_val = e1000_write_phy_reg_ex(hw,
3204 GG82563_PHY_PAGE_SELECT_ALT,
3205 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3209 e1000_swfw_sync_release(hw, swfw);
3215 ret_val = e1000_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
3218 e1000_swfw_sync_release(hw, swfw);
3223 e1000_read_phy_reg_ex(struct e1000_hw *hw,
3229 const uint32_t phy_addr = 1;
3231 DEBUGFUNC("e1000_read_phy_reg_ex");
3233 if(reg_addr > MAX_PHY_REG_ADDRESS) {
3234 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
3235 return -E1000_ERR_PARAM;
3238 if(hw->mac_type > e1000_82543) {
3239 /* Set up Op-code, Phy Address, and register address in the MDI
3240 * Control register. The MAC will take care of interfacing with the
3241 * PHY to retrieve the desired data.
3243 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
3244 (phy_addr << E1000_MDIC_PHY_SHIFT) |
3245 (E1000_MDIC_OP_READ));
3247 E1000_WRITE_REG(hw, MDIC, mdic);
3249 /* Poll the ready bit to see if the MDI read completed */
3250 for(i = 0; i < 64; i++) {
3252 mdic = E1000_READ_REG(hw, MDIC);
3253 if(mdic & E1000_MDIC_READY) break;
3255 if(!(mdic & E1000_MDIC_READY)) {
3256 DEBUGOUT("MDI Read did not complete\n");
3257 return -E1000_ERR_PHY;
3259 if(mdic & E1000_MDIC_ERROR) {
3260 DEBUGOUT("MDI Error\n");
3261 return -E1000_ERR_PHY;
3263 *phy_data = (uint16_t) mdic;
3265 /* We must first send a preamble through the MDIO pin to signal the
3266 * beginning of an MII instruction. This is done by sending 32
3267 * consecutive "1" bits.
3269 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
3271 /* Now combine the next few fields that are required for a read
3272 * operation. We use this method instead of calling the
3273 * e1000_shift_out_mdi_bits routine five different times. The format of
3274 * a MII read instruction consists of a shift out of 14 bits and is
3275 * defined as follows:
3276 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
3277 * followed by a shift in of 18 bits. This first two bits shifted in
3278 * are TurnAround bits used to avoid contention on the MDIO pin when a
3279 * READ operation is performed. These two bits are thrown away
3280 * followed by a shift in of 16 bits which contains the desired data.
3282 mdic = ((reg_addr) | (phy_addr << 5) |
3283 (PHY_OP_READ << 10) | (PHY_SOF << 12));
3285 e1000_shift_out_mdi_bits(hw, mdic, 14);
3287 /* Now that we've shifted out the read command to the MII, we need to
3288 * "shift in" the 16-bit value (18 total bits) of the requested PHY
3291 *phy_data = e1000_shift_in_mdi_bits(hw);
3293 return E1000_SUCCESS;
3296 /******************************************************************************
3297 * Writes a value to a PHY register
3299 * hw - Struct containing variables accessed by shared code
3300 * reg_addr - address of the PHY register to write
3301 * data - data to write to the PHY
3302 ******************************************************************************/
3304 e1000_write_phy_reg(struct e1000_hw *hw,
3311 DEBUGFUNC("e1000_write_phy_reg");
3313 if ((hw->mac_type == e1000_80003es2lan) &&
3314 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3315 swfw = E1000_SWFW_PHY1_SM;
3317 swfw = E1000_SWFW_PHY0_SM;
3319 if (e1000_swfw_sync_acquire(hw, swfw))
3320 return -E1000_ERR_SWFW_SYNC;
3322 if((hw->phy_type == e1000_phy_igp ||
3323 hw->phy_type == e1000_phy_igp_2) &&
3324 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
3325 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
3326 (uint16_t)reg_addr);
3328 e1000_swfw_sync_release(hw, swfw);
3331 } else if (hw->phy_type == e1000_phy_gg82563) {
3332 if (((reg_addr & MAX_PHY_REG_ADDRESS) > MAX_PHY_MULTI_PAGE_REG) ||
3333 (hw->mac_type == e1000_80003es2lan)) {
3334 /* Select Configuration Page */
3335 if ((reg_addr & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) {
3336 ret_val = e1000_write_phy_reg_ex(hw, GG82563_PHY_PAGE_SELECT,
3337 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3339 /* Use Alternative Page Select register to access
3340 * registers 30 and 31
3342 ret_val = e1000_write_phy_reg_ex(hw,
3343 GG82563_PHY_PAGE_SELECT_ALT,
3344 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3348 e1000_swfw_sync_release(hw, swfw);
3354 ret_val = e1000_write_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
3357 e1000_swfw_sync_release(hw, swfw);
3362 e1000_write_phy_reg_ex(struct e1000_hw *hw,
3368 const uint32_t phy_addr = 1;
3370 DEBUGFUNC("e1000_write_phy_reg_ex");
3372 if(reg_addr > MAX_PHY_REG_ADDRESS) {
3373 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
3374 return -E1000_ERR_PARAM;
3377 if(hw->mac_type > e1000_82543) {
3378 /* Set up Op-code, Phy Address, register address, and data intended
3379 * for the PHY register in the MDI Control register. The MAC will take
3380 * care of interfacing with the PHY to send the desired data.
3382 mdic = (((uint32_t) phy_data) |
3383 (reg_addr << E1000_MDIC_REG_SHIFT) |
3384 (phy_addr << E1000_MDIC_PHY_SHIFT) |
3385 (E1000_MDIC_OP_WRITE));
3387 E1000_WRITE_REG(hw, MDIC, mdic);
3389 /* Poll the ready bit to see if the MDI read completed */
3390 for(i = 0; i < 640; i++) {
3392 mdic = E1000_READ_REG(hw, MDIC);
3393 if(mdic & E1000_MDIC_READY) break;
3395 if(!(mdic & E1000_MDIC_READY)) {
3396 DEBUGOUT("MDI Write did not complete\n");
3397 return -E1000_ERR_PHY;
3400 /* We'll need to use the SW defined pins to shift the write command
3401 * out to the PHY. We first send a preamble to the PHY to signal the
3402 * beginning of the MII instruction. This is done by sending 32
3403 * consecutive "1" bits.
3405 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
3407 /* Now combine the remaining required fields that will indicate a
3408 * write operation. We use this method instead of calling the
3409 * e1000_shift_out_mdi_bits routine for each field in the command. The
3410 * format of a MII write instruction is as follows:
3411 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
3413 mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
3414 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
3416 mdic |= (uint32_t) phy_data;
3418 e1000_shift_out_mdi_bits(hw, mdic, 32);
3421 return E1000_SUCCESS;
3425 e1000_read_kmrn_reg(struct e1000_hw *hw,
3431 DEBUGFUNC("e1000_read_kmrn_reg");
3433 if ((hw->mac_type == e1000_80003es2lan) &&
3434 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3435 swfw = E1000_SWFW_PHY1_SM;
3437 swfw = E1000_SWFW_PHY0_SM;
3439 if (e1000_swfw_sync_acquire(hw, swfw))
3440 return -E1000_ERR_SWFW_SYNC;
3442 /* Write register address */
3443 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
3444 E1000_KUMCTRLSTA_OFFSET) |
3445 E1000_KUMCTRLSTA_REN;
3446 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
3449 /* Read the data returned */
3450 reg_val = E1000_READ_REG(hw, KUMCTRLSTA);
3451 *data = (uint16_t)reg_val;
3453 e1000_swfw_sync_release(hw, swfw);
3454 return E1000_SUCCESS;
3458 e1000_write_kmrn_reg(struct e1000_hw *hw,
3464 DEBUGFUNC("e1000_write_kmrn_reg");
3466 if ((hw->mac_type == e1000_80003es2lan) &&
3467 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3468 swfw = E1000_SWFW_PHY1_SM;
3470 swfw = E1000_SWFW_PHY0_SM;
3472 if (e1000_swfw_sync_acquire(hw, swfw))
3473 return -E1000_ERR_SWFW_SYNC;
3475 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
3476 E1000_KUMCTRLSTA_OFFSET) | data;
3477 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
3480 e1000_swfw_sync_release(hw, swfw);
3481 return E1000_SUCCESS;
3484 /******************************************************************************
3485 * Returns the PHY to the power-on reset state
3487 * hw - Struct containing variables accessed by shared code
3488 ******************************************************************************/
3490 e1000_phy_hw_reset(struct e1000_hw *hw)
3492 uint32_t ctrl, ctrl_ext;
3497 DEBUGFUNC("e1000_phy_hw_reset");
3499 /* In the case of the phy reset being blocked, it's not an error, we
3500 * simply return success without performing the reset. */
3501 ret_val = e1000_check_phy_reset_block(hw);
3503 return E1000_SUCCESS;
3505 DEBUGOUT("Resetting Phy...\n");
3507 if(hw->mac_type > e1000_82543) {
3508 if ((hw->mac_type == e1000_80003es2lan) &&
3509 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3510 swfw = E1000_SWFW_PHY1_SM;
3512 swfw = E1000_SWFW_PHY0_SM;
3514 if (e1000_swfw_sync_acquire(hw, swfw)) {
3515 e1000_release_software_semaphore(hw);
3516 return -E1000_ERR_SWFW_SYNC;
3518 /* Read the device control register and assert the E1000_CTRL_PHY_RST
3519 * bit. Then, take it out of reset.
3520 * For pre-e1000_82571 hardware, we delay for 10ms between the assert
3521 * and deassert. For e1000_82571 hardware and later, we instead delay
3522 * for 50us between and 10ms after the deassertion.
3524 ctrl = E1000_READ_REG(hw, CTRL);
3525 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST);
3526 E1000_WRITE_FLUSH(hw);
3528 if (hw->mac_type < e1000_82571)
3533 E1000_WRITE_REG(hw, CTRL, ctrl);
3534 E1000_WRITE_FLUSH(hw);
3536 if (hw->mac_type >= e1000_82571)
3538 e1000_swfw_sync_release(hw, swfw);
3540 /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
3541 * bit to put the PHY into reset. Then, take it out of reset.
3543 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
3544 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
3545 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
3546 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
3547 E1000_WRITE_FLUSH(hw);
3549 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
3550 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
3551 E1000_WRITE_FLUSH(hw);
3555 if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
3556 /* Configure activity LED after PHY reset */
3557 led_ctrl = E1000_READ_REG(hw, LEDCTL);
3558 led_ctrl &= IGP_ACTIVITY_LED_MASK;
3559 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
3560 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
3563 /* Wait for FW to finish PHY configuration. */
3564 ret_val = e1000_get_phy_cfg_done(hw);
3565 e1000_release_software_semaphore(hw);
3570 /******************************************************************************
3573 * hw - Struct containing variables accessed by shared code
3575 * Sets bit 15 of the MII Control regiser
3576 ******************************************************************************/
3578 e1000_phy_reset(struct e1000_hw *hw)
3583 DEBUGFUNC("e1000_phy_reset");
3585 /* In the case of the phy reset being blocked, it's not an error, we
3586 * simply return success without performing the reset. */
3587 ret_val = e1000_check_phy_reset_block(hw);
3589 return E1000_SUCCESS;
3591 switch (hw->mac_type) {
3592 case e1000_82541_rev_2:
3595 ret_val = e1000_phy_hw_reset(hw);
3600 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
3604 phy_data |= MII_CR_RESET;
3605 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
3613 if(hw->phy_type == e1000_phy_igp || hw->phy_type == e1000_phy_igp_2)
3614 e1000_phy_init_script(hw);
3616 return E1000_SUCCESS;
3619 /******************************************************************************
3620 * Probes the expected PHY address for known PHY IDs
3622 * hw - Struct containing variables accessed by shared code
3623 ******************************************************************************/
3625 e1000_detect_gig_phy(struct e1000_hw *hw)
3627 int32_t phy_init_status, ret_val;
3628 uint16_t phy_id_high, phy_id_low;
3629 boolean_t match = FALSE;
3631 DEBUGFUNC("e1000_detect_gig_phy");
3633 /* The 82571 firmware may still be configuring the PHY. In this
3634 * case, we cannot access the PHY until the configuration is done. So
3635 * we explicitly set the PHY values. */
3636 if(hw->mac_type == e1000_82571 ||
3637 hw->mac_type == e1000_82572) {
3638 hw->phy_id = IGP01E1000_I_PHY_ID;
3639 hw->phy_type = e1000_phy_igp_2;
3640 return E1000_SUCCESS;
3643 /* ESB-2 PHY reads require e1000_phy_gg82563 to be set because of a work-
3644 * around that forces PHY page 0 to be set or the reads fail. The rest of
3645 * the code in this routine uses e1000_read_phy_reg to read the PHY ID.
3646 * So for ESB-2 we need to have this set so our reads won't fail. If the
3647 * attached PHY is not a e1000_phy_gg82563, the routines below will figure
3648 * this out as well. */
3649 if (hw->mac_type == e1000_80003es2lan)
3650 hw->phy_type = e1000_phy_gg82563;
3652 /* Read the PHY ID Registers to identify which PHY is onboard. */
3653 ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
3657 hw->phy_id = (uint32_t) (phy_id_high << 16);
3659 ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
3663 hw->phy_id |= (uint32_t) (phy_id_low & PHY_REVISION_MASK);
3664 hw->phy_revision = (uint32_t) phy_id_low & ~PHY_REVISION_MASK;
3666 switch(hw->mac_type) {
3668 if(hw->phy_id == M88E1000_E_PHY_ID) match = TRUE;
3671 if(hw->phy_id == M88E1000_I_PHY_ID) match = TRUE;
3675 case e1000_82545_rev_3:
3677 case e1000_82546_rev_3:
3678 if(hw->phy_id == M88E1011_I_PHY_ID) match = TRUE;
3681 case e1000_82541_rev_2:
3683 case e1000_82547_rev_2:
3684 if(hw->phy_id == IGP01E1000_I_PHY_ID) match = TRUE;
3687 if(hw->phy_id == M88E1111_I_PHY_ID) match = TRUE;
3689 case e1000_80003es2lan:
3690 if (hw->phy_id == GG82563_E_PHY_ID) match = TRUE;
3693 DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type);
3694 return -E1000_ERR_CONFIG;
3696 phy_init_status = e1000_set_phy_type(hw);
3698 if ((match) && (phy_init_status == E1000_SUCCESS)) {
3699 DEBUGOUT1("PHY ID 0x%X detected\n", hw->phy_id);
3700 return E1000_SUCCESS;
3702 DEBUGOUT1("Invalid PHY ID 0x%X\n", hw->phy_id);
3703 return -E1000_ERR_PHY;
3706 /******************************************************************************
3707 * Resets the PHY's DSP
3709 * hw - Struct containing variables accessed by shared code
3710 ******************************************************************************/
3712 e1000_phy_reset_dsp(struct e1000_hw *hw)
3715 DEBUGFUNC("e1000_phy_reset_dsp");
3718 if (hw->phy_type != e1000_phy_gg82563) {
3719 ret_val = e1000_write_phy_reg(hw, 29, 0x001d);
3722 ret_val = e1000_write_phy_reg(hw, 30, 0x00c1);
3724 ret_val = e1000_write_phy_reg(hw, 30, 0x0000);
3726 ret_val = E1000_SUCCESS;
3732 /******************************************************************************
3733 * Get PHY information from various PHY registers for igp PHY only.
3735 * hw - Struct containing variables accessed by shared code
3736 * phy_info - PHY information structure
3737 ******************************************************************************/
3739 e1000_phy_igp_get_info(struct e1000_hw *hw,
3740 struct e1000_phy_info *phy_info)
3743 uint16_t phy_data, polarity, min_length, max_length, average;
3745 DEBUGFUNC("e1000_phy_igp_get_info");
3747 /* The downshift status is checked only once, after link is established,
3748 * and it stored in the hw->speed_downgraded parameter. */
3749 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
3751 /* IGP01E1000 does not need to support it. */
3752 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
3754 /* IGP01E1000 always correct polarity reversal */
3755 phy_info->polarity_correction = e1000_polarity_reversal_enabled;
3757 /* Check polarity status */
3758 ret_val = e1000_check_polarity(hw, &polarity);
3762 phy_info->cable_polarity = polarity;
3764 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, &phy_data);
3768 phy_info->mdix_mode = (phy_data & IGP01E1000_PSSR_MDIX) >>
3769 IGP01E1000_PSSR_MDIX_SHIFT;
3771 if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
3772 IGP01E1000_PSSR_SPEED_1000MBPS) {
3773 /* Local/Remote Receiver Information are only valid at 1000 Mbps */
3774 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
3778 phy_info->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS) >>
3779 SR_1000T_LOCAL_RX_STATUS_SHIFT;
3780 phy_info->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS) >>
3781 SR_1000T_REMOTE_RX_STATUS_SHIFT;
3783 /* Get cable length */
3784 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
3788 /* Translate to old method */
3789 average = (max_length + min_length) / 2;
3791 if(average <= e1000_igp_cable_length_50)
3792 phy_info->cable_length = e1000_cable_length_50;
3793 else if(average <= e1000_igp_cable_length_80)
3794 phy_info->cable_length = e1000_cable_length_50_80;
3795 else if(average <= e1000_igp_cable_length_110)
3796 phy_info->cable_length = e1000_cable_length_80_110;
3797 else if(average <= e1000_igp_cable_length_140)
3798 phy_info->cable_length = e1000_cable_length_110_140;
3800 phy_info->cable_length = e1000_cable_length_140;
3803 return E1000_SUCCESS;
3806 /******************************************************************************
3807 * Get PHY information from various PHY registers fot m88 PHY only.
3809 * hw - Struct containing variables accessed by shared code
3810 * phy_info - PHY information structure
3811 ******************************************************************************/
3813 e1000_phy_m88_get_info(struct e1000_hw *hw,
3814 struct e1000_phy_info *phy_info)
3817 uint16_t phy_data, polarity;
3819 DEBUGFUNC("e1000_phy_m88_get_info");
3821 /* The downshift status is checked only once, after link is established,
3822 * and it stored in the hw->speed_downgraded parameter. */
3823 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
3825 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
3829 phy_info->extended_10bt_distance =
3830 (phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >>
3831 M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT;
3832 phy_info->polarity_correction =
3833 (phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >>
3834 M88E1000_PSCR_POLARITY_REVERSAL_SHIFT;
3836 /* Check polarity status */
3837 ret_val = e1000_check_polarity(hw, &polarity);
3840 phy_info->cable_polarity = polarity;
3842 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
3846 phy_info->mdix_mode = (phy_data & M88E1000_PSSR_MDIX) >>
3847 M88E1000_PSSR_MDIX_SHIFT;
3849 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
3850 /* Cable Length Estimation and Local/Remote Receiver Information
3851 * are only valid at 1000 Mbps.
3853 if (hw->phy_type != e1000_phy_gg82563) {
3854 phy_info->cable_length = ((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
3855 M88E1000_PSSR_CABLE_LENGTH_SHIFT);
3857 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_DSP_DISTANCE,
3862 phy_info->cable_length = phy_data & GG82563_DSPD_CABLE_LENGTH;
3865 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
3869 phy_info->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS) >>
3870 SR_1000T_LOCAL_RX_STATUS_SHIFT;
3872 phy_info->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS) >>
3873 SR_1000T_REMOTE_RX_STATUS_SHIFT;
3876 return E1000_SUCCESS;
3879 /******************************************************************************
3880 * Get PHY information from various PHY registers
3882 * hw - Struct containing variables accessed by shared code
3883 * phy_info - PHY information structure
3884 ******************************************************************************/
3886 e1000_phy_get_info(struct e1000_hw *hw,
3887 struct e1000_phy_info *phy_info)
3892 DEBUGFUNC("e1000_phy_get_info");
3894 phy_info->cable_length = e1000_cable_length_undefined;
3895 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined;
3896 phy_info->cable_polarity = e1000_rev_polarity_undefined;
3897 phy_info->downshift = e1000_downshift_undefined;
3898 phy_info->polarity_correction = e1000_polarity_reversal_undefined;
3899 phy_info->mdix_mode = e1000_auto_x_mode_undefined;
3900 phy_info->local_rx = e1000_1000t_rx_status_undefined;
3901 phy_info->remote_rx = e1000_1000t_rx_status_undefined;
3903 if(hw->media_type != e1000_media_type_copper) {
3904 DEBUGOUT("PHY info is only valid for copper media\n");
3905 return -E1000_ERR_CONFIG;
3908 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3912 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3916 if((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) {
3917 DEBUGOUT("PHY info is only valid if link is up\n");
3918 return -E1000_ERR_CONFIG;
3921 if(hw->phy_type == e1000_phy_igp ||
3922 hw->phy_type == e1000_phy_igp_2)
3923 return e1000_phy_igp_get_info(hw, phy_info);
3925 return e1000_phy_m88_get_info(hw, phy_info);
3929 e1000_validate_mdi_setting(struct e1000_hw *hw)
3931 DEBUGFUNC("e1000_validate_mdi_settings");
3933 if(!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) {
3934 DEBUGOUT("Invalid MDI setting detected\n");
3936 return -E1000_ERR_CONFIG;
3938 return E1000_SUCCESS;
3942 /******************************************************************************
3943 * Sets up eeprom variables in the hw struct. Must be called after mac_type
3944 * is configured. Additionally, if this is ICH8, the flash controller GbE
3945 * registers must be mapped, or this will crash.
3947 * hw - Struct containing variables accessed by shared code
3948 *****************************************************************************/
3950 e1000_init_eeprom_params(struct e1000_hw *hw)
3952 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3953 uint32_t eecd = E1000_READ_REG(hw, EECD);
3954 int32_t ret_val = E1000_SUCCESS;
3955 uint16_t eeprom_size;
3957 DEBUGFUNC("e1000_init_eeprom_params");
3959 switch (hw->mac_type) {
3960 case e1000_82542_rev2_0:
3961 case e1000_82542_rev2_1:
3964 eeprom->type = e1000_eeprom_microwire;
3965 eeprom->word_size = 64;
3966 eeprom->opcode_bits = 3;
3967 eeprom->address_bits = 6;
3968 eeprom->delay_usec = 50;
3969 eeprom->use_eerd = FALSE;
3970 eeprom->use_eewr = FALSE;
3974 case e1000_82545_rev_3:
3976 case e1000_82546_rev_3:
3977 eeprom->type = e1000_eeprom_microwire;
3978 eeprom->opcode_bits = 3;
3979 eeprom->delay_usec = 50;
3980 if(eecd & E1000_EECD_SIZE) {
3981 eeprom->word_size = 256;
3982 eeprom->address_bits = 8;
3984 eeprom->word_size = 64;
3985 eeprom->address_bits = 6;
3987 eeprom->use_eerd = FALSE;
3988 eeprom->use_eewr = FALSE;
3991 case e1000_82541_rev_2:
3993 case e1000_82547_rev_2:
3994 if (eecd & E1000_EECD_TYPE) {
3995 eeprom->type = e1000_eeprom_spi;
3996 eeprom->opcode_bits = 8;
3997 eeprom->delay_usec = 1;
3998 if (eecd & E1000_EECD_ADDR_BITS) {
3999 eeprom->page_size = 32;
4000 eeprom->address_bits = 16;
4002 eeprom->page_size = 8;
4003 eeprom->address_bits = 8;
4006 eeprom->type = e1000_eeprom_microwire;
4007 eeprom->opcode_bits = 3;
4008 eeprom->delay_usec = 50;
4009 if (eecd & E1000_EECD_ADDR_BITS) {
4010 eeprom->word_size = 256;
4011 eeprom->address_bits = 8;
4013 eeprom->word_size = 64;
4014 eeprom->address_bits = 6;
4017 eeprom->use_eerd = FALSE;
4018 eeprom->use_eewr = FALSE;
4022 eeprom->type = e1000_eeprom_spi;
4023 eeprom->opcode_bits = 8;
4024 eeprom->delay_usec = 1;
4025 if (eecd & E1000_EECD_ADDR_BITS) {
4026 eeprom->page_size = 32;
4027 eeprom->address_bits = 16;
4029 eeprom->page_size = 8;
4030 eeprom->address_bits = 8;
4032 eeprom->use_eerd = FALSE;
4033 eeprom->use_eewr = FALSE;
4036 eeprom->type = e1000_eeprom_spi;
4037 eeprom->opcode_bits = 8;
4038 eeprom->delay_usec = 1;
4039 if (eecd & E1000_EECD_ADDR_BITS) {
4040 eeprom->page_size = 32;
4041 eeprom->address_bits = 16;
4043 eeprom->page_size = 8;
4044 eeprom->address_bits = 8;
4046 eeprom->use_eerd = TRUE;
4047 eeprom->use_eewr = TRUE;
4048 if(e1000_is_onboard_nvm_eeprom(hw) == FALSE) {
4049 eeprom->type = e1000_eeprom_flash;
4050 eeprom->word_size = 2048;
4052 /* Ensure that the Autonomous FLASH update bit is cleared due to
4053 * Flash update issue on parts which use a FLASH for NVM. */
4054 eecd &= ~E1000_EECD_AUPDEN;
4055 E1000_WRITE_REG(hw, EECD, eecd);
4058 case e1000_80003es2lan:
4059 eeprom->type = e1000_eeprom_spi;
4060 eeprom->opcode_bits = 8;
4061 eeprom->delay_usec = 1;
4062 if (eecd & E1000_EECD_ADDR_BITS) {
4063 eeprom->page_size = 32;
4064 eeprom->address_bits = 16;
4066 eeprom->page_size = 8;
4067 eeprom->address_bits = 8;
4069 eeprom->use_eerd = TRUE;
4070 eeprom->use_eewr = FALSE;
4076 if (eeprom->type == e1000_eeprom_spi) {
4077 /* eeprom_size will be an enum [0..8] that maps to eeprom sizes 128B to
4078 * 32KB (incremented by powers of 2).
4080 if(hw->mac_type <= e1000_82547_rev_2) {
4081 /* Set to default value for initial eeprom read. */
4082 eeprom->word_size = 64;
4083 ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size);
4086 eeprom_size = (eeprom_size & EEPROM_SIZE_MASK) >> EEPROM_SIZE_SHIFT;
4087 /* 256B eeprom size was not supported in earlier hardware, so we
4088 * bump eeprom_size up one to ensure that "1" (which maps to 256B)
4089 * is never the result used in the shifting logic below. */
4093 eeprom_size = (uint16_t)((eecd & E1000_EECD_SIZE_EX_MASK) >>
4094 E1000_EECD_SIZE_EX_SHIFT);
4097 eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT);
4102 /******************************************************************************
4103 * Raises the EEPROM's clock input.
4105 * hw - Struct containing variables accessed by shared code
4106 * eecd - EECD's current value
4107 *****************************************************************************/
4109 e1000_raise_ee_clk(struct e1000_hw *hw,
4112 /* Raise the clock input to the EEPROM (by setting the SK bit), and then
4113 * wait <delay> microseconds.
4115 *eecd = *eecd | E1000_EECD_SK;
4116 E1000_WRITE_REG(hw, EECD, *eecd);
4117 E1000_WRITE_FLUSH(hw);
4118 udelay(hw->eeprom.delay_usec);
4121 /******************************************************************************
4122 * Lowers the EEPROM's clock input.
4124 * hw - Struct containing variables accessed by shared code
4125 * eecd - EECD's current value
4126 *****************************************************************************/
4128 e1000_lower_ee_clk(struct e1000_hw *hw,
4131 /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
4132 * wait 50 microseconds.
4134 *eecd = *eecd & ~E1000_EECD_SK;
4135 E1000_WRITE_REG(hw, EECD, *eecd);
4136 E1000_WRITE_FLUSH(hw);
4137 udelay(hw->eeprom.delay_usec);
4140 /******************************************************************************
4141 * Shift data bits out to the EEPROM.
4143 * hw - Struct containing variables accessed by shared code
4144 * data - data to send to the EEPROM
4145 * count - number of bits to shift out
4146 *****************************************************************************/
4148 e1000_shift_out_ee_bits(struct e1000_hw *hw,
4152 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4156 /* We need to shift "count" bits out to the EEPROM. So, value in the
4157 * "data" parameter will be shifted out to the EEPROM one bit at a time.
4158 * In order to do this, "data" must be broken down into bits.
4160 mask = 0x01 << (count - 1);
4161 eecd = E1000_READ_REG(hw, EECD);
4162 if (eeprom->type == e1000_eeprom_microwire) {
4163 eecd &= ~E1000_EECD_DO;
4164 } else if (eeprom->type == e1000_eeprom_spi) {
4165 eecd |= E1000_EECD_DO;
4168 /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
4169 * and then raising and then lowering the clock (the SK bit controls
4170 * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
4171 * by setting "DI" to "0" and then raising and then lowering the clock.
4173 eecd &= ~E1000_EECD_DI;
4176 eecd |= E1000_EECD_DI;
4178 E1000_WRITE_REG(hw, EECD, eecd);
4179 E1000_WRITE_FLUSH(hw);
4181 udelay(eeprom->delay_usec);
4183 e1000_raise_ee_clk(hw, &eecd);
4184 e1000_lower_ee_clk(hw, &eecd);
4190 /* We leave the "DI" bit set to "0" when we leave this routine. */
4191 eecd &= ~E1000_EECD_DI;
4192 E1000_WRITE_REG(hw, EECD, eecd);
4195 /******************************************************************************
4196 * Shift data bits in from the EEPROM
4198 * hw - Struct containing variables accessed by shared code
4199 *****************************************************************************/
4201 e1000_shift_in_ee_bits(struct e1000_hw *hw,
4208 /* In order to read a register from the EEPROM, we need to shift 'count'
4209 * bits in from the EEPROM. Bits are "shifted in" by raising the clock
4210 * input to the EEPROM (setting the SK bit), and then reading the value of
4211 * the "DO" bit. During this "shifting in" process the "DI" bit should
4215 eecd = E1000_READ_REG(hw, EECD);
4217 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
4220 for(i = 0; i < count; i++) {
4222 e1000_raise_ee_clk(hw, &eecd);
4224 eecd = E1000_READ_REG(hw, EECD);
4226 eecd &= ~(E1000_EECD_DI);
4227 if(eecd & E1000_EECD_DO)
4230 e1000_lower_ee_clk(hw, &eecd);
4236 /******************************************************************************
4237 * Prepares EEPROM for access
4239 * hw - Struct containing variables accessed by shared code
4241 * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
4242 * function should be called before issuing a command to the EEPROM.
4243 *****************************************************************************/
4245 e1000_acquire_eeprom(struct e1000_hw *hw)
4247 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4250 DEBUGFUNC("e1000_acquire_eeprom");
4252 if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
4253 return -E1000_ERR_SWFW_SYNC;
4254 eecd = E1000_READ_REG(hw, EECD);
4256 if (hw->mac_type != e1000_82573) {
4257 /* Request EEPROM Access */
4258 if(hw->mac_type > e1000_82544) {
4259 eecd |= E1000_EECD_REQ;
4260 E1000_WRITE_REG(hw, EECD, eecd);
4261 eecd = E1000_READ_REG(hw, EECD);
4262 while((!(eecd & E1000_EECD_GNT)) &&
4263 (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
4266 eecd = E1000_READ_REG(hw, EECD);
4268 if(!(eecd & E1000_EECD_GNT)) {
4269 eecd &= ~E1000_EECD_REQ;
4270 E1000_WRITE_REG(hw, EECD, eecd);
4271 DEBUGOUT("Could not acquire EEPROM grant\n");
4272 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
4273 return -E1000_ERR_EEPROM;
4278 /* Setup EEPROM for Read/Write */
4280 if (eeprom->type == e1000_eeprom_microwire) {
4281 /* Clear SK and DI */
4282 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
4283 E1000_WRITE_REG(hw, EECD, eecd);
4286 eecd |= E1000_EECD_CS;
4287 E1000_WRITE_REG(hw, EECD, eecd);
4288 } else if (eeprom->type == e1000_eeprom_spi) {
4289 /* Clear SK and CS */
4290 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
4291 E1000_WRITE_REG(hw, EECD, eecd);
4295 return E1000_SUCCESS;
4298 /******************************************************************************
4299 * Returns EEPROM to a "standby" state
4301 * hw - Struct containing variables accessed by shared code
4302 *****************************************************************************/
4304 e1000_standby_eeprom(struct e1000_hw *hw)
4306 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4309 eecd = E1000_READ_REG(hw, EECD);
4311 if(eeprom->type == e1000_eeprom_microwire) {
4312 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
4313 E1000_WRITE_REG(hw, EECD, eecd);
4314 E1000_WRITE_FLUSH(hw);
4315 udelay(eeprom->delay_usec);
4318 eecd |= E1000_EECD_SK;
4319 E1000_WRITE_REG(hw, EECD, eecd);
4320 E1000_WRITE_FLUSH(hw);
4321 udelay(eeprom->delay_usec);
4324 eecd |= E1000_EECD_CS;
4325 E1000_WRITE_REG(hw, EECD, eecd);
4326 E1000_WRITE_FLUSH(hw);
4327 udelay(eeprom->delay_usec);
4330 eecd &= ~E1000_EECD_SK;
4331 E1000_WRITE_REG(hw, EECD, eecd);
4332 E1000_WRITE_FLUSH(hw);
4333 udelay(eeprom->delay_usec);
4334 } else if(eeprom->type == e1000_eeprom_spi) {
4335 /* Toggle CS to flush commands */
4336 eecd |= E1000_EECD_CS;
4337 E1000_WRITE_REG(hw, EECD, eecd);
4338 E1000_WRITE_FLUSH(hw);
4339 udelay(eeprom->delay_usec);
4340 eecd &= ~E1000_EECD_CS;
4341 E1000_WRITE_REG(hw, EECD, eecd);
4342 E1000_WRITE_FLUSH(hw);
4343 udelay(eeprom->delay_usec);
4347 /******************************************************************************
4348 * Terminates a command by inverting the EEPROM's chip select pin
4350 * hw - Struct containing variables accessed by shared code
4351 *****************************************************************************/
4353 e1000_release_eeprom(struct e1000_hw *hw)
4357 DEBUGFUNC("e1000_release_eeprom");
4359 eecd = E1000_READ_REG(hw, EECD);
4361 if (hw->eeprom.type == e1000_eeprom_spi) {
4362 eecd |= E1000_EECD_CS; /* Pull CS high */
4363 eecd &= ~E1000_EECD_SK; /* Lower SCK */
4365 E1000_WRITE_REG(hw, EECD, eecd);
4367 udelay(hw->eeprom.delay_usec);
4368 } else if(hw->eeprom.type == e1000_eeprom_microwire) {
4369 /* cleanup eeprom */
4371 /* CS on Microwire is active-high */
4372 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
4374 E1000_WRITE_REG(hw, EECD, eecd);
4376 /* Rising edge of clock */
4377 eecd |= E1000_EECD_SK;
4378 E1000_WRITE_REG(hw, EECD, eecd);
4379 E1000_WRITE_FLUSH(hw);
4380 udelay(hw->eeprom.delay_usec);
4382 /* Falling edge of clock */
4383 eecd &= ~E1000_EECD_SK;
4384 E1000_WRITE_REG(hw, EECD, eecd);
4385 E1000_WRITE_FLUSH(hw);
4386 udelay(hw->eeprom.delay_usec);
4389 /* Stop requesting EEPROM access */
4390 if(hw->mac_type > e1000_82544) {
4391 eecd &= ~E1000_EECD_REQ;
4392 E1000_WRITE_REG(hw, EECD, eecd);
4395 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
4398 /******************************************************************************
4399 * Reads a 16 bit word from the EEPROM.
4401 * hw - Struct containing variables accessed by shared code
4402 *****************************************************************************/
4404 e1000_spi_eeprom_ready(struct e1000_hw *hw)
4406 uint16_t retry_count = 0;
4407 uint8_t spi_stat_reg;
4409 DEBUGFUNC("e1000_spi_eeprom_ready");
4411 /* Read "Status Register" repeatedly until the LSB is cleared. The
4412 * EEPROM will signal that the command has been completed by clearing
4413 * bit 0 of the internal status register. If it's not cleared within
4414 * 5 milliseconds, then error out.
4418 e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
4419 hw->eeprom.opcode_bits);
4420 spi_stat_reg = (uint8_t)e1000_shift_in_ee_bits(hw, 8);
4421 if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
4427 e1000_standby_eeprom(hw);
4428 } while(retry_count < EEPROM_MAX_RETRY_SPI);
4430 /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
4431 * only 0-5mSec on 5V devices)
4433 if(retry_count >= EEPROM_MAX_RETRY_SPI) {
4434 DEBUGOUT("SPI EEPROM Status error\n");
4435 return -E1000_ERR_EEPROM;
4438 return E1000_SUCCESS;
4441 /******************************************************************************
4442 * Reads a 16 bit word from the EEPROM.
4444 * hw - Struct containing variables accessed by shared code
4445 * offset - offset of word in the EEPROM to read
4446 * data - word read from the EEPROM
4447 * words - number of words to read
4448 *****************************************************************************/
4450 e1000_read_eeprom(struct e1000_hw *hw,
4455 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4459 DEBUGFUNC("e1000_read_eeprom");
4461 /* A check for invalid values: offset too large, too many words, and not
4464 if((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
4466 DEBUGOUT("\"words\" parameter out of bounds\n");
4467 return -E1000_ERR_EEPROM;
4470 /* FLASH reads without acquiring the semaphore are safe */
4471 if (e1000_is_onboard_nvm_eeprom(hw) == TRUE &&
4472 hw->eeprom.use_eerd == FALSE) {
4473 switch (hw->mac_type) {
4474 case e1000_80003es2lan:
4477 /* Prepare the EEPROM for reading */
4478 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
4479 return -E1000_ERR_EEPROM;
4484 if (eeprom->use_eerd == TRUE) {
4485 ret_val = e1000_read_eeprom_eerd(hw, offset, words, data);
4486 if ((e1000_is_onboard_nvm_eeprom(hw) == TRUE) ||
4487 (hw->mac_type != e1000_82573))
4488 e1000_release_eeprom(hw);
4492 if(eeprom->type == e1000_eeprom_spi) {
4494 uint8_t read_opcode = EEPROM_READ_OPCODE_SPI;
4496 if(e1000_spi_eeprom_ready(hw)) {
4497 e1000_release_eeprom(hw);
4498 return -E1000_ERR_EEPROM;
4501 e1000_standby_eeprom(hw);
4503 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
4504 if((eeprom->address_bits == 8) && (offset >= 128))
4505 read_opcode |= EEPROM_A8_OPCODE_SPI;
4507 /* Send the READ command (opcode + addr) */
4508 e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
4509 e1000_shift_out_ee_bits(hw, (uint16_t)(offset*2), eeprom->address_bits);
4511 /* Read the data. The address of the eeprom internally increments with
4512 * each byte (spi) being read, saving on the overhead of eeprom setup
4513 * and tear-down. The address counter will roll over if reading beyond
4514 * the size of the eeprom, thus allowing the entire memory to be read
4515 * starting from any offset. */
4516 for (i = 0; i < words; i++) {
4517 word_in = e1000_shift_in_ee_bits(hw, 16);
4518 data[i] = (word_in >> 8) | (word_in << 8);
4520 } else if(eeprom->type == e1000_eeprom_microwire) {
4521 for (i = 0; i < words; i++) {
4522 /* Send the READ command (opcode + addr) */
4523 e1000_shift_out_ee_bits(hw, EEPROM_READ_OPCODE_MICROWIRE,
4524 eeprom->opcode_bits);
4525 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + i),
4526 eeprom->address_bits);
4528 /* Read the data. For microwire, each word requires the overhead
4529 * of eeprom setup and tear-down. */
4530 data[i] = e1000_shift_in_ee_bits(hw, 16);
4531 e1000_standby_eeprom(hw);
4535 /* End this read operation */
4536 e1000_release_eeprom(hw);
4538 return E1000_SUCCESS;
4541 /******************************************************************************
4542 * Reads a 16 bit word from the EEPROM using the EERD register.
4544 * hw - Struct containing variables accessed by shared code
4545 * offset - offset of word in the EEPROM to read
4546 * data - word read from the EEPROM
4547 * words - number of words to read
4548 *****************************************************************************/
4550 e1000_read_eeprom_eerd(struct e1000_hw *hw,
4555 uint32_t i, eerd = 0;
4558 for (i = 0; i < words; i++) {
4559 eerd = ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) +
4560 E1000_EEPROM_RW_REG_START;
4562 E1000_WRITE_REG(hw, EERD, eerd);
4563 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_READ);
4568 data[i] = (E1000_READ_REG(hw, EERD) >> E1000_EEPROM_RW_REG_DATA);
4575 /******************************************************************************
4576 * Writes a 16 bit word from the EEPROM using the EEWR register.
4578 * hw - Struct containing variables accessed by shared code
4579 * offset - offset of word in the EEPROM to read
4580 * data - word read from the EEPROM
4581 * words - number of words to read
4582 *****************************************************************************/
4584 e1000_write_eeprom_eewr(struct e1000_hw *hw,
4589 uint32_t register_value = 0;
4593 if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
4594 return -E1000_ERR_SWFW_SYNC;
4596 for (i = 0; i < words; i++) {
4597 register_value = (data[i] << E1000_EEPROM_RW_REG_DATA) |
4598 ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) |
4599 E1000_EEPROM_RW_REG_START;
4601 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
4606 E1000_WRITE_REG(hw, EEWR, register_value);
4608 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
4615 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
4619 /******************************************************************************
4620 * Polls the status bit (bit 1) of the EERD to determine when the read is done.
4622 * hw - Struct containing variables accessed by shared code
4623 *****************************************************************************/
4625 e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd)
4627 uint32_t attempts = 100000;
4628 uint32_t i, reg = 0;
4629 int32_t done = E1000_ERR_EEPROM;
4631 for(i = 0; i < attempts; i++) {
4632 if(eerd == E1000_EEPROM_POLL_READ)
4633 reg = E1000_READ_REG(hw, EERD);
4635 reg = E1000_READ_REG(hw, EEWR);
4637 if(reg & E1000_EEPROM_RW_REG_DONE) {
4638 done = E1000_SUCCESS;
4647 /***************************************************************************
4648 * Description: Determines if the onboard NVM is FLASH or EEPROM.
4650 * hw - Struct containing variables accessed by shared code
4651 ****************************************************************************/
4653 e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw)
4657 DEBUGFUNC("e1000_is_onboard_nvm_eeprom");
4659 if(hw->mac_type == e1000_82573) {
4660 eecd = E1000_READ_REG(hw, EECD);
4662 /* Isolate bits 15 & 16 */
4663 eecd = ((eecd >> 15) & 0x03);
4665 /* If both bits are set, device is Flash type */
4673 /******************************************************************************
4674 * Verifies that the EEPROM has a valid checksum
4676 * hw - Struct containing variables accessed by shared code
4678 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
4679 * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
4681 *****************************************************************************/
4683 e1000_validate_eeprom_checksum(struct e1000_hw *hw)
4685 uint16_t checksum = 0;
4686 uint16_t i, eeprom_data;
4688 DEBUGFUNC("e1000_validate_eeprom_checksum");
4690 if ((hw->mac_type == e1000_82573) &&
4691 (e1000_is_onboard_nvm_eeprom(hw) == FALSE)) {
4692 /* Check bit 4 of word 10h. If it is 0, firmware is done updating
4693 * 10h-12h. Checksum may need to be fixed. */
4694 e1000_read_eeprom(hw, 0x10, 1, &eeprom_data);
4695 if ((eeprom_data & 0x10) == 0) {
4696 /* Read 0x23 and check bit 15. This bit is a 1 when the checksum
4697 * has already been fixed. If the checksum is still wrong and this
4698 * bit is a 1, we need to return bad checksum. Otherwise, we need
4699 * to set this bit to a 1 and update the checksum. */
4700 e1000_read_eeprom(hw, 0x23, 1, &eeprom_data);
4701 if ((eeprom_data & 0x8000) == 0) {
4702 eeprom_data |= 0x8000;
4703 e1000_write_eeprom(hw, 0x23, 1, &eeprom_data);
4704 e1000_update_eeprom_checksum(hw);
4709 for(i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
4710 if(e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
4711 DEBUGOUT("EEPROM Read Error\n");
4712 return -E1000_ERR_EEPROM;
4714 checksum += eeprom_data;
4717 if(checksum == (uint16_t) EEPROM_SUM)
4718 return E1000_SUCCESS;
4720 DEBUGOUT("EEPROM Checksum Invalid\n");
4721 return -E1000_ERR_EEPROM;
4725 /******************************************************************************
4726 * Calculates the EEPROM checksum and writes it to the EEPROM
4728 * hw - Struct containing variables accessed by shared code
4730 * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA.
4731 * Writes the difference to word offset 63 of the EEPROM.
4732 *****************************************************************************/
4734 e1000_update_eeprom_checksum(struct e1000_hw *hw)
4736 uint16_t checksum = 0;
4737 uint16_t i, eeprom_data;
4739 DEBUGFUNC("e1000_update_eeprom_checksum");
4741 for(i = 0; i < EEPROM_CHECKSUM_REG; i++) {
4742 if(e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
4743 DEBUGOUT("EEPROM Read Error\n");
4744 return -E1000_ERR_EEPROM;
4746 checksum += eeprom_data;
4748 checksum = (uint16_t) EEPROM_SUM - checksum;
4749 if(e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) {
4750 DEBUGOUT("EEPROM Write Error\n");
4751 return -E1000_ERR_EEPROM;
4752 } else if (hw->eeprom.type == e1000_eeprom_flash) {
4753 e1000_commit_shadow_ram(hw);
4755 return E1000_SUCCESS;
4758 /******************************************************************************
4759 * Parent function for writing words to the different EEPROM types.
4761 * hw - Struct containing variables accessed by shared code
4762 * offset - offset within the EEPROM to be written to
4763 * words - number of words to write
4764 * data - 16 bit word to be written to the EEPROM
4766 * If e1000_update_eeprom_checksum is not called after this function, the
4767 * EEPROM will most likely contain an invalid checksum.
4768 *****************************************************************************/
4770 e1000_write_eeprom(struct e1000_hw *hw,
4775 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4778 DEBUGFUNC("e1000_write_eeprom");
4780 /* A check for invalid values: offset too large, too many words, and not
4783 if((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
4785 DEBUGOUT("\"words\" parameter out of bounds\n");
4786 return -E1000_ERR_EEPROM;
4789 /* 82573 writes only through eewr */
4790 if(eeprom->use_eewr == TRUE)
4791 return e1000_write_eeprom_eewr(hw, offset, words, data);
4793 /* Prepare the EEPROM for writing */
4794 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
4795 return -E1000_ERR_EEPROM;
4797 if(eeprom->type == e1000_eeprom_microwire) {
4798 status = e1000_write_eeprom_microwire(hw, offset, words, data);
4800 status = e1000_write_eeprom_spi(hw, offset, words, data);
4804 /* Done with writing */
4805 e1000_release_eeprom(hw);
4810 /******************************************************************************
4811 * Writes a 16 bit word to a given offset in an SPI EEPROM.
4813 * hw - Struct containing variables accessed by shared code
4814 * offset - offset within the EEPROM to be written to
4815 * words - number of words to write
4816 * data - pointer to array of 8 bit words to be written to the EEPROM
4818 *****************************************************************************/
4820 e1000_write_eeprom_spi(struct e1000_hw *hw,
4825 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4828 DEBUGFUNC("e1000_write_eeprom_spi");
4830 while (widx < words) {
4831 uint8_t write_opcode = EEPROM_WRITE_OPCODE_SPI;
4833 if(e1000_spi_eeprom_ready(hw)) return -E1000_ERR_EEPROM;
4835 e1000_standby_eeprom(hw);
4837 /* Send the WRITE ENABLE command (8 bit opcode ) */
4838 e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI,
4839 eeprom->opcode_bits);
4841 e1000_standby_eeprom(hw);
4843 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
4844 if((eeprom->address_bits == 8) && (offset >= 128))
4845 write_opcode |= EEPROM_A8_OPCODE_SPI;
4847 /* Send the Write command (8-bit opcode + addr) */
4848 e1000_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits);
4850 e1000_shift_out_ee_bits(hw, (uint16_t)((offset + widx)*2),
4851 eeprom->address_bits);
4855 /* Loop to allow for up to whole page write (32 bytes) of eeprom */
4856 while (widx < words) {
4857 uint16_t word_out = data[widx];
4858 word_out = (word_out >> 8) | (word_out << 8);
4859 e1000_shift_out_ee_bits(hw, word_out, 16);
4862 /* Some larger eeprom sizes are capable of a 32-byte PAGE WRITE
4863 * operation, while the smaller eeproms are capable of an 8-byte
4864 * PAGE WRITE operation. Break the inner loop to pass new address
4866 if((((offset + widx)*2) % eeprom->page_size) == 0) {
4867 e1000_standby_eeprom(hw);
4873 return E1000_SUCCESS;
4876 /******************************************************************************
4877 * Writes a 16 bit word to a given offset in a Microwire EEPROM.
4879 * hw - Struct containing variables accessed by shared code
4880 * offset - offset within the EEPROM to be written to
4881 * words - number of words to write
4882 * data - pointer to array of 16 bit words to be written to the EEPROM
4884 *****************************************************************************/
4886 e1000_write_eeprom_microwire(struct e1000_hw *hw,
4891 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4893 uint16_t words_written = 0;
4896 DEBUGFUNC("e1000_write_eeprom_microwire");
4898 /* Send the write enable command to the EEPROM (3-bit opcode plus
4899 * 6/8-bit dummy address beginning with 11). It's less work to include
4900 * the 11 of the dummy address as part of the opcode than it is to shift
4901 * it over the correct number of bits for the address. This puts the
4902 * EEPROM into write/erase mode.
4904 e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE,
4905 (uint16_t)(eeprom->opcode_bits + 2));
4907 e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
4909 /* Prepare the EEPROM */
4910 e1000_standby_eeprom(hw);
4912 while (words_written < words) {
4913 /* Send the Write command (3-bit opcode + addr) */
4914 e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE,
4915 eeprom->opcode_bits);
4917 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + words_written),
4918 eeprom->address_bits);
4921 e1000_shift_out_ee_bits(hw, data[words_written], 16);
4923 /* Toggle the CS line. This in effect tells the EEPROM to execute
4924 * the previous command.
4926 e1000_standby_eeprom(hw);
4928 /* Read DO repeatedly until it is high (equal to '1'). The EEPROM will
4929 * signal that the command has been completed by raising the DO signal.
4930 * If DO does not go high in 10 milliseconds, then error out.
4932 for(i = 0; i < 200; i++) {
4933 eecd = E1000_READ_REG(hw, EECD);
4934 if(eecd & E1000_EECD_DO) break;
4938 DEBUGOUT("EEPROM Write did not complete\n");
4939 return -E1000_ERR_EEPROM;
4942 /* Recover from write */
4943 e1000_standby_eeprom(hw);
4948 /* Send the write disable command to the EEPROM (3-bit opcode plus
4949 * 6/8-bit dummy address beginning with 10). It's less work to include
4950 * the 10 of the dummy address as part of the opcode than it is to shift
4951 * it over the correct number of bits for the address. This takes the
4952 * EEPROM out of write/erase mode.
4954 e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE,
4955 (uint16_t)(eeprom->opcode_bits + 2));
4957 e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
4959 return E1000_SUCCESS;
4962 /******************************************************************************
4963 * Flushes the cached eeprom to NVM. This is done by saving the modified values
4964 * in the eeprom cache and the non modified values in the currently active bank
4967 * hw - Struct containing variables accessed by shared code
4968 * offset - offset of word in the EEPROM to read
4969 * data - word read from the EEPROM
4970 * words - number of words to read
4971 *****************************************************************************/
4973 e1000_commit_shadow_ram(struct e1000_hw *hw)
4975 uint32_t attempts = 100000;
4979 int32_t error = E1000_SUCCESS;
4981 /* The flop register will be used to determine if flash type is STM */
4982 flop = E1000_READ_REG(hw, FLOP);
4984 if (hw->mac_type == e1000_82573) {
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;
4997 /* If STM opcode located in bits 15:8 of flop, reset firmware */
4998 if ((flop & 0xFF00) == E1000_STM_OPCODE) {
4999 E1000_WRITE_REG(hw, HICR, E1000_HICR_FW_RESET);
5002 /* Perform the flash update */
5003 E1000_WRITE_REG(hw, EECD, eecd | E1000_EECD_FLUPD);
5005 for (i=0; i < attempts; i++) {
5006 eecd = E1000_READ_REG(hw, EECD);
5007 if ((eecd & E1000_EECD_FLUPD) == 0) {
5013 if (i == attempts) {
5014 return -E1000_ERR_EEPROM;
5021 /******************************************************************************
5022 * Reads the adapter's part number from the EEPROM
5024 * hw - Struct containing variables accessed by shared code
5025 * part_num - Adapter's part number
5026 *****************************************************************************/
5028 e1000_read_part_num(struct e1000_hw *hw,
5031 uint16_t offset = EEPROM_PBA_BYTE_1;
5032 uint16_t eeprom_data;
5034 DEBUGFUNC("e1000_read_part_num");
5036 /* Get word 0 from EEPROM */
5037 if(e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
5038 DEBUGOUT("EEPROM Read Error\n");
5039 return -E1000_ERR_EEPROM;
5041 /* Save word 0 in upper half of part_num */
5042 *part_num = (uint32_t) (eeprom_data << 16);
5044 /* Get word 1 from EEPROM */
5045 if(e1000_read_eeprom(hw, ++offset, 1, &eeprom_data) < 0) {
5046 DEBUGOUT("EEPROM Read Error\n");
5047 return -E1000_ERR_EEPROM;
5049 /* Save word 1 in lower half of part_num */
5050 *part_num |= eeprom_data;
5052 return E1000_SUCCESS;
5055 /******************************************************************************
5056 * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
5057 * second function of dual function devices
5059 * hw - Struct containing variables accessed by shared code
5060 *****************************************************************************/
5062 e1000_read_mac_addr(struct e1000_hw * hw)
5065 uint16_t eeprom_data, i;
5067 DEBUGFUNC("e1000_read_mac_addr");
5069 for(i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
5071 if(e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
5072 DEBUGOUT("EEPROM Read Error\n");
5073 return -E1000_ERR_EEPROM;
5075 hw->perm_mac_addr[i] = (uint8_t) (eeprom_data & 0x00FF);
5076 hw->perm_mac_addr[i+1] = (uint8_t) (eeprom_data >> 8);
5079 switch (hw->mac_type) {
5083 case e1000_82546_rev_3:
5085 case e1000_80003es2lan:
5086 if(E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
5087 hw->perm_mac_addr[5] ^= 0x01;
5091 for(i = 0; i < NODE_ADDRESS_SIZE; i++)
5092 hw->mac_addr[i] = hw->perm_mac_addr[i];
5093 return E1000_SUCCESS;
5096 /******************************************************************************
5097 * Initializes receive address filters.
5099 * hw - Struct containing variables accessed by shared code
5101 * Places the MAC address in receive address register 0 and clears the rest
5102 * of the receive addresss registers. Clears the multicast table. Assumes
5103 * the receiver is in reset when the routine is called.
5104 *****************************************************************************/
5106 e1000_init_rx_addrs(struct e1000_hw *hw)
5111 DEBUGFUNC("e1000_init_rx_addrs");
5113 /* Setup the receive address. */
5114 DEBUGOUT("Programming MAC Address into RAR[0]\n");
5116 e1000_rar_set(hw, hw->mac_addr, 0);
5118 rar_num = E1000_RAR_ENTRIES;
5120 /* Reserve a spot for the Locally Administered Address to work around
5121 * an 82571 issue in which a reset on one port will reload the MAC on
5122 * the other port. */
5123 if ((hw->mac_type == e1000_82571) && (hw->laa_is_present == TRUE))
5125 /* Zero out the other 15 receive addresses. */
5126 DEBUGOUT("Clearing RAR[1-15]\n");
5127 for(i = 1; i < rar_num; i++) {
5128 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
5129 E1000_WRITE_FLUSH(hw);
5130 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
5131 E1000_WRITE_FLUSH(hw);
5136 /******************************************************************************
5137 * Updates the MAC's list of multicast addresses.
5139 * hw - Struct containing variables accessed by shared code
5140 * mc_addr_list - the list of new multicast addresses
5141 * mc_addr_count - number of addresses
5142 * pad - number of bytes between addresses in the list
5143 * rar_used_count - offset where to start adding mc addresses into the RAR's
5145 * The given list replaces any existing list. Clears the last 15 receive
5146 * address registers and the multicast table. Uses receive address registers
5147 * for the first 15 multicast addresses, and hashes the rest into the
5149 *****************************************************************************/
5151 e1000_mc_addr_list_update(struct e1000_hw *hw,
5152 uint8_t *mc_addr_list,
5153 uint32_t mc_addr_count,
5155 uint32_t rar_used_count)
5157 uint32_t hash_value;
5159 uint32_t num_rar_entry;
5160 uint32_t num_mta_entry;
5162 DEBUGFUNC("e1000_mc_addr_list_update");
5164 /* Set the new number of MC addresses that we are being requested to use. */
5165 hw->num_mc_addrs = mc_addr_count;
5167 /* Clear RAR[1-15] */
5168 DEBUGOUT(" Clearing RAR[1-15]\n");
5169 num_rar_entry = E1000_RAR_ENTRIES;
5170 /* Reserve a spot for the Locally Administered Address to work around
5171 * an 82571 issue in which a reset on one port will reload the MAC on
5172 * the other port. */
5173 if ((hw->mac_type == e1000_82571) && (hw->laa_is_present == TRUE))
5176 for(i = rar_used_count; i < num_rar_entry; i++) {
5177 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
5178 E1000_WRITE_FLUSH(hw);
5179 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
5180 E1000_WRITE_FLUSH(hw);
5184 DEBUGOUT(" Clearing MTA\n");
5185 num_mta_entry = E1000_NUM_MTA_REGISTERS;
5186 for(i = 0; i < num_mta_entry; i++) {
5187 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
5188 E1000_WRITE_FLUSH(hw);
5191 /* Add the new addresses */
5192 for(i = 0; i < mc_addr_count; i++) {
5193 DEBUGOUT(" Adding the multicast addresses:\n");
5194 DEBUGOUT7(" MC Addr #%d =%.2X %.2X %.2X %.2X %.2X %.2X\n", i,
5195 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad)],
5196 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 1],
5197 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 2],
5198 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 3],
5199 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 4],
5200 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 5]);
5202 hash_value = e1000_hash_mc_addr(hw,
5204 (i * (ETH_LENGTH_OF_ADDRESS + pad)));
5206 DEBUGOUT1(" Hash value = 0x%03X\n", hash_value);
5208 /* Place this multicast address in the RAR if there is room, *
5209 * else put it in the MTA
5211 if (rar_used_count < num_rar_entry) {
5213 mc_addr_list + (i * (ETH_LENGTH_OF_ADDRESS + pad)),
5217 e1000_mta_set(hw, hash_value);
5220 DEBUGOUT("MC Update Complete\n");
5224 /******************************************************************************
5225 * Hashes an address to determine its location in the multicast table
5227 * hw - Struct containing variables accessed by shared code
5228 * mc_addr - the multicast address to hash
5229 *****************************************************************************/
5231 e1000_hash_mc_addr(struct e1000_hw *hw,
5234 uint32_t hash_value = 0;
5236 /* The portion of the address that is used for the hash table is
5237 * determined by the mc_filter_type setting.
5239 switch (hw->mc_filter_type) {
5240 /* [0] [1] [2] [3] [4] [5]
5245 /* [47:36] i.e. 0x563 for above example address */
5246 hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4));
5249 /* [46:35] i.e. 0xAC6 for above example address */
5250 hash_value = ((mc_addr[4] >> 3) | (((uint16_t) mc_addr[5]) << 5));
5253 /* [45:34] i.e. 0x5D8 for above example address */
5254 hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6));
5257 /* [43:32] i.e. 0x634 for above example address */
5258 hash_value = ((mc_addr[4]) | (((uint16_t) mc_addr[5]) << 8));
5262 hash_value &= 0xFFF;
5267 /******************************************************************************
5268 * Sets the bit in the multicast table corresponding to the hash value.
5270 * hw - Struct containing variables accessed by shared code
5271 * hash_value - Multicast address hash value
5272 *****************************************************************************/
5274 e1000_mta_set(struct e1000_hw *hw,
5275 uint32_t hash_value)
5277 uint32_t hash_bit, hash_reg;
5281 /* The MTA is a register array of 128 32-bit registers.
5282 * It is treated like an array of 4096 bits. We want to set
5283 * bit BitArray[hash_value]. So we figure out what register
5284 * the bit is in, read it, OR in the new bit, then write
5285 * back the new value. The register is determined by the
5286 * upper 7 bits of the hash value and the bit within that
5287 * register are determined by the lower 5 bits of the value.
5289 hash_reg = (hash_value >> 5) & 0x7F;
5290 hash_bit = hash_value & 0x1F;
5292 mta = E1000_READ_REG_ARRAY(hw, MTA, hash_reg);
5294 mta |= (1 << hash_bit);
5296 /* If we are on an 82544 and we are trying to write an odd offset
5297 * in the MTA, save off the previous entry before writing and
5298 * restore the old value after writing.
5300 if((hw->mac_type == e1000_82544) && ((hash_reg & 0x1) == 1)) {
5301 temp = E1000_READ_REG_ARRAY(hw, MTA, (hash_reg - 1));
5302 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
5303 E1000_WRITE_FLUSH(hw);
5304 E1000_WRITE_REG_ARRAY(hw, MTA, (hash_reg - 1), temp);
5305 E1000_WRITE_FLUSH(hw);
5307 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
5308 E1000_WRITE_FLUSH(hw);
5312 /******************************************************************************
5313 * Puts an ethernet address into a receive address register.
5315 * hw - Struct containing variables accessed by shared code
5316 * addr - Address to put into receive address register
5317 * index - Receive address register to write
5318 *****************************************************************************/
5320 e1000_rar_set(struct e1000_hw *hw,
5324 uint32_t rar_low, rar_high;
5326 /* HW expects these in little endian so we reverse the byte order
5327 * from network order (big endian) to little endian
5329 rar_low = ((uint32_t) addr[0] |
5330 ((uint32_t) addr[1] << 8) |
5331 ((uint32_t) addr[2] << 16) | ((uint32_t) addr[3] << 24));
5332 rar_high = ((uint32_t) addr[4] | ((uint32_t) addr[5] << 8));
5334 /* Disable Rx and flush all Rx frames before enabling RSS to avoid Rx
5338 * If there are any Rx frames queued up or otherwise present in the HW
5339 * before RSS is enabled, and then we enable RSS, the HW Rx unit will
5340 * hang. To work around this issue, we have to disable receives and
5341 * flush out all Rx frames before we enable RSS. To do so, we modify we
5342 * redirect all Rx traffic to manageability and then reset the HW.
5343 * This flushes away Rx frames, and (since the redirections to
5344 * manageability persists across resets) keeps new ones from coming in
5345 * while we work. Then, we clear the Address Valid AV bit for all MAC
5346 * addresses and undo the re-direction to manageability.
5347 * Now, frames are coming in again, but the MAC won't accept them, so
5348 * far so good. We now proceed to initialize RSS (if necessary) and
5349 * configure the Rx unit. Last, we re-enable the AV bits and continue
5352 switch (hw->mac_type) {
5355 case e1000_80003es2lan:
5356 if (hw->leave_av_bit_off == TRUE)
5359 /* Indicate to hardware the Address is Valid. */
5360 rar_high |= E1000_RAH_AV;
5364 E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
5365 E1000_WRITE_FLUSH(hw);
5366 E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
5367 E1000_WRITE_FLUSH(hw);
5370 /******************************************************************************
5371 * Writes a value to the specified offset in the VLAN filter table.
5373 * hw - Struct containing variables accessed by shared code
5374 * offset - Offset in VLAN filer table to write
5375 * value - Value to write into VLAN filter table
5376 *****************************************************************************/
5378 e1000_write_vfta(struct e1000_hw *hw,
5384 if((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) {
5385 temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1));
5386 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
5387 E1000_WRITE_FLUSH(hw);
5388 E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp);
5389 E1000_WRITE_FLUSH(hw);
5391 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
5392 E1000_WRITE_FLUSH(hw);
5396 /******************************************************************************
5397 * Clears the VLAN filer table
5399 * hw - Struct containing variables accessed by shared code
5400 *****************************************************************************/
5402 e1000_clear_vfta(struct e1000_hw *hw)
5405 uint32_t vfta_value = 0;
5406 uint32_t vfta_offset = 0;
5407 uint32_t vfta_bit_in_reg = 0;
5409 if (hw->mac_type == e1000_82573) {
5410 if (hw->mng_cookie.vlan_id != 0) {
5411 /* The VFTA is a 4096b bit-field, each identifying a single VLAN
5412 * ID. The following operations determine which 32b entry
5413 * (i.e. offset) into the array we want to set the VLAN ID
5414 * (i.e. bit) of the manageability unit. */
5415 vfta_offset = (hw->mng_cookie.vlan_id >>
5416 E1000_VFTA_ENTRY_SHIFT) &
5417 E1000_VFTA_ENTRY_MASK;
5418 vfta_bit_in_reg = 1 << (hw->mng_cookie.vlan_id &
5419 E1000_VFTA_ENTRY_BIT_SHIFT_MASK);
5422 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
5423 /* If the offset we want to clear is the same offset of the
5424 * manageability VLAN ID, then clear all bits except that of the
5425 * manageability unit */
5426 vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0;
5427 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, vfta_value);
5428 E1000_WRITE_FLUSH(hw);
5433 e1000_id_led_init(struct e1000_hw * hw)
5436 const uint32_t ledctl_mask = 0x000000FF;
5437 const uint32_t ledctl_on = E1000_LEDCTL_MODE_LED_ON;
5438 const uint32_t ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
5439 uint16_t eeprom_data, i, temp;
5440 const uint16_t led_mask = 0x0F;
5442 DEBUGFUNC("e1000_id_led_init");
5444 if(hw->mac_type < e1000_82540) {
5446 return E1000_SUCCESS;
5449 ledctl = E1000_READ_REG(hw, LEDCTL);
5450 hw->ledctl_default = ledctl;
5451 hw->ledctl_mode1 = hw->ledctl_default;
5452 hw->ledctl_mode2 = hw->ledctl_default;
5454 if(e1000_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, 1, &eeprom_data) < 0) {
5455 DEBUGOUT("EEPROM Read Error\n");
5456 return -E1000_ERR_EEPROM;
5458 if((eeprom_data== ID_LED_RESERVED_0000) ||
5459 (eeprom_data == ID_LED_RESERVED_FFFF)) eeprom_data = ID_LED_DEFAULT;
5460 for(i = 0; i < 4; i++) {
5461 temp = (eeprom_data >> (i << 2)) & led_mask;
5463 case ID_LED_ON1_DEF2:
5464 case ID_LED_ON1_ON2:
5465 case ID_LED_ON1_OFF2:
5466 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
5467 hw->ledctl_mode1 |= ledctl_on << (i << 3);
5469 case ID_LED_OFF1_DEF2:
5470 case ID_LED_OFF1_ON2:
5471 case ID_LED_OFF1_OFF2:
5472 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
5473 hw->ledctl_mode1 |= ledctl_off << (i << 3);
5480 case ID_LED_DEF1_ON2:
5481 case ID_LED_ON1_ON2:
5482 case ID_LED_OFF1_ON2:
5483 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
5484 hw->ledctl_mode2 |= ledctl_on << (i << 3);
5486 case ID_LED_DEF1_OFF2:
5487 case ID_LED_ON1_OFF2:
5488 case ID_LED_OFF1_OFF2:
5489 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
5490 hw->ledctl_mode2 |= ledctl_off << (i << 3);
5497 return E1000_SUCCESS;
5500 /******************************************************************************
5501 * Prepares SW controlable LED for use and saves the current state of the LED.
5503 * hw - Struct containing variables accessed by shared code
5504 *****************************************************************************/
5506 e1000_setup_led(struct e1000_hw *hw)
5509 int32_t ret_val = E1000_SUCCESS;
5511 DEBUGFUNC("e1000_setup_led");
5513 switch(hw->mac_type) {
5514 case e1000_82542_rev2_0:
5515 case e1000_82542_rev2_1:
5518 /* No setup necessary */
5522 case e1000_82541_rev_2:
5523 case e1000_82547_rev_2:
5524 /* Turn off PHY Smart Power Down (if enabled) */
5525 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
5526 &hw->phy_spd_default);
5529 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
5530 (uint16_t)(hw->phy_spd_default &
5531 ~IGP01E1000_GMII_SPD));
5536 if(hw->media_type == e1000_media_type_fiber) {
5537 ledctl = E1000_READ_REG(hw, LEDCTL);
5538 /* Save current LEDCTL settings */
5539 hw->ledctl_default = ledctl;
5541 ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
5542 E1000_LEDCTL_LED0_BLINK |
5543 E1000_LEDCTL_LED0_MODE_MASK);
5544 ledctl |= (E1000_LEDCTL_MODE_LED_OFF <<
5545 E1000_LEDCTL_LED0_MODE_SHIFT);
5546 E1000_WRITE_REG(hw, LEDCTL, ledctl);
5547 } else if(hw->media_type == e1000_media_type_copper)
5548 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
5552 return E1000_SUCCESS;
5555 /******************************************************************************
5556 * Used on 82571 and later Si that has LED blink bits.
5557 * Callers must use their own timer and should have already called
5558 * e1000_id_led_init()
5559 * Call e1000_cleanup led() to stop blinking
5561 * hw - Struct containing variables accessed by shared code
5562 *****************************************************************************/
5564 e1000_blink_led_start(struct e1000_hw *hw)
5567 uint32_t ledctl_blink = 0;
5569 DEBUGFUNC("e1000_id_led_blink_on");
5571 if (hw->mac_type < e1000_82571) {
5573 return E1000_SUCCESS;
5575 if (hw->media_type == e1000_media_type_fiber) {
5576 /* always blink LED0 for PCI-E fiber */
5577 ledctl_blink = E1000_LEDCTL_LED0_BLINK |
5578 (E1000_LEDCTL_MODE_LED_ON << E1000_LEDCTL_LED0_MODE_SHIFT);
5580 /* set the blink bit for each LED that's "on" (0x0E) in ledctl_mode2 */
5581 ledctl_blink = hw->ledctl_mode2;
5582 for (i=0; i < 4; i++)
5583 if (((hw->ledctl_mode2 >> (i * 8)) & 0xFF) ==
5584 E1000_LEDCTL_MODE_LED_ON)
5585 ledctl_blink |= (E1000_LEDCTL_LED0_BLINK << (i * 8));
5588 E1000_WRITE_REG(hw, LEDCTL, ledctl_blink);
5590 return E1000_SUCCESS;
5593 /******************************************************************************
5594 * Restores the saved state of the SW controlable LED.
5596 * hw - Struct containing variables accessed by shared code
5597 *****************************************************************************/
5599 e1000_cleanup_led(struct e1000_hw *hw)
5601 int32_t ret_val = E1000_SUCCESS;
5603 DEBUGFUNC("e1000_cleanup_led");
5605 switch(hw->mac_type) {
5606 case e1000_82542_rev2_0:
5607 case e1000_82542_rev2_1:
5610 /* No cleanup necessary */
5614 case e1000_82541_rev_2:
5615 case e1000_82547_rev_2:
5616 /* Turn on PHY Smart Power Down (if previously enabled) */
5617 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
5618 hw->phy_spd_default);
5623 /* Restore LEDCTL settings */
5624 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_default);
5628 return E1000_SUCCESS;
5631 /******************************************************************************
5632 * Turns on the software controllable LED
5634 * hw - Struct containing variables accessed by shared code
5635 *****************************************************************************/
5637 e1000_led_on(struct e1000_hw *hw)
5639 uint32_t ctrl = E1000_READ_REG(hw, CTRL);
5641 DEBUGFUNC("e1000_led_on");
5643 switch(hw->mac_type) {
5644 case e1000_82542_rev2_0:
5645 case e1000_82542_rev2_1:
5647 /* Set SW Defineable Pin 0 to turn on the LED */
5648 ctrl |= E1000_CTRL_SWDPIN0;
5649 ctrl |= E1000_CTRL_SWDPIO0;
5652 if(hw->media_type == e1000_media_type_fiber) {
5653 /* Set SW Defineable Pin 0 to turn on the LED */
5654 ctrl |= E1000_CTRL_SWDPIN0;
5655 ctrl |= E1000_CTRL_SWDPIO0;
5657 /* Clear SW Defineable Pin 0 to turn on the LED */
5658 ctrl &= ~E1000_CTRL_SWDPIN0;
5659 ctrl |= E1000_CTRL_SWDPIO0;
5663 if(hw->media_type == e1000_media_type_fiber) {
5664 /* Clear SW Defineable Pin 0 to turn on the LED */
5665 ctrl &= ~E1000_CTRL_SWDPIN0;
5666 ctrl |= E1000_CTRL_SWDPIO0;
5667 } else if(hw->media_type == e1000_media_type_copper) {
5668 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode2);
5669 return E1000_SUCCESS;
5674 E1000_WRITE_REG(hw, CTRL, ctrl);
5676 return E1000_SUCCESS;
5679 /******************************************************************************
5680 * Turns off the software controllable LED
5682 * hw - Struct containing variables accessed by shared code
5683 *****************************************************************************/
5685 e1000_led_off(struct e1000_hw *hw)
5687 uint32_t ctrl = E1000_READ_REG(hw, CTRL);
5689 DEBUGFUNC("e1000_led_off");
5691 switch(hw->mac_type) {
5692 case e1000_82542_rev2_0:
5693 case e1000_82542_rev2_1:
5695 /* Clear SW Defineable Pin 0 to turn off the LED */
5696 ctrl &= ~E1000_CTRL_SWDPIN0;
5697 ctrl |= E1000_CTRL_SWDPIO0;
5700 if(hw->media_type == e1000_media_type_fiber) {
5701 /* Clear SW Defineable Pin 0 to turn off the LED */
5702 ctrl &= ~E1000_CTRL_SWDPIN0;
5703 ctrl |= E1000_CTRL_SWDPIO0;
5705 /* Set SW Defineable Pin 0 to turn off the LED */
5706 ctrl |= E1000_CTRL_SWDPIN0;
5707 ctrl |= E1000_CTRL_SWDPIO0;
5711 if(hw->media_type == e1000_media_type_fiber) {
5712 /* Set SW Defineable Pin 0 to turn off the LED */
5713 ctrl |= E1000_CTRL_SWDPIN0;
5714 ctrl |= E1000_CTRL_SWDPIO0;
5715 } else if(hw->media_type == e1000_media_type_copper) {
5716 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
5717 return E1000_SUCCESS;
5722 E1000_WRITE_REG(hw, CTRL, ctrl);
5724 return E1000_SUCCESS;
5727 /******************************************************************************
5728 * Clears all hardware statistics counters.
5730 * hw - Struct containing variables accessed by shared code
5731 *****************************************************************************/
5733 e1000_clear_hw_cntrs(struct e1000_hw *hw)
5735 volatile uint32_t temp;
5737 temp = E1000_READ_REG(hw, CRCERRS);
5738 temp = E1000_READ_REG(hw, SYMERRS);
5739 temp = E1000_READ_REG(hw, MPC);
5740 temp = E1000_READ_REG(hw, SCC);
5741 temp = E1000_READ_REG(hw, ECOL);
5742 temp = E1000_READ_REG(hw, MCC);
5743 temp = E1000_READ_REG(hw, LATECOL);
5744 temp = E1000_READ_REG(hw, COLC);
5745 temp = E1000_READ_REG(hw, DC);
5746 temp = E1000_READ_REG(hw, SEC);
5747 temp = E1000_READ_REG(hw, RLEC);
5748 temp = E1000_READ_REG(hw, XONRXC);
5749 temp = E1000_READ_REG(hw, XONTXC);
5750 temp = E1000_READ_REG(hw, XOFFRXC);
5751 temp = E1000_READ_REG(hw, XOFFTXC);
5752 temp = E1000_READ_REG(hw, FCRUC);
5753 temp = E1000_READ_REG(hw, PRC64);
5754 temp = E1000_READ_REG(hw, PRC127);
5755 temp = E1000_READ_REG(hw, PRC255);
5756 temp = E1000_READ_REG(hw, PRC511);
5757 temp = E1000_READ_REG(hw, PRC1023);
5758 temp = E1000_READ_REG(hw, PRC1522);
5759 temp = E1000_READ_REG(hw, GPRC);
5760 temp = E1000_READ_REG(hw, BPRC);
5761 temp = E1000_READ_REG(hw, MPRC);
5762 temp = E1000_READ_REG(hw, GPTC);
5763 temp = E1000_READ_REG(hw, GORCL);
5764 temp = E1000_READ_REG(hw, GORCH);
5765 temp = E1000_READ_REG(hw, GOTCL);
5766 temp = E1000_READ_REG(hw, GOTCH);
5767 temp = E1000_READ_REG(hw, RNBC);
5768 temp = E1000_READ_REG(hw, RUC);
5769 temp = E1000_READ_REG(hw, RFC);
5770 temp = E1000_READ_REG(hw, ROC);
5771 temp = E1000_READ_REG(hw, RJC);
5772 temp = E1000_READ_REG(hw, TORL);
5773 temp = E1000_READ_REG(hw, TORH);
5774 temp = E1000_READ_REG(hw, TOTL);
5775 temp = E1000_READ_REG(hw, TOTH);
5776 temp = E1000_READ_REG(hw, TPR);
5777 temp = E1000_READ_REG(hw, TPT);
5778 temp = E1000_READ_REG(hw, PTC64);
5779 temp = E1000_READ_REG(hw, PTC127);
5780 temp = E1000_READ_REG(hw, PTC255);
5781 temp = E1000_READ_REG(hw, PTC511);
5782 temp = E1000_READ_REG(hw, PTC1023);
5783 temp = E1000_READ_REG(hw, PTC1522);
5784 temp = E1000_READ_REG(hw, MPTC);
5785 temp = E1000_READ_REG(hw, BPTC);
5787 if(hw->mac_type < e1000_82543) return;
5789 temp = E1000_READ_REG(hw, ALGNERRC);
5790 temp = E1000_READ_REG(hw, RXERRC);
5791 temp = E1000_READ_REG(hw, TNCRS);
5792 temp = E1000_READ_REG(hw, CEXTERR);
5793 temp = E1000_READ_REG(hw, TSCTC);
5794 temp = E1000_READ_REG(hw, TSCTFC);
5796 if(hw->mac_type <= e1000_82544) return;
5798 temp = E1000_READ_REG(hw, MGTPRC);
5799 temp = E1000_READ_REG(hw, MGTPDC);
5800 temp = E1000_READ_REG(hw, MGTPTC);
5802 if(hw->mac_type <= e1000_82547_rev_2) return;
5804 temp = E1000_READ_REG(hw, IAC);
5805 temp = E1000_READ_REG(hw, ICRXOC);
5806 temp = E1000_READ_REG(hw, ICRXPTC);
5807 temp = E1000_READ_REG(hw, ICRXATC);
5808 temp = E1000_READ_REG(hw, ICTXPTC);
5809 temp = E1000_READ_REG(hw, ICTXATC);
5810 temp = E1000_READ_REG(hw, ICTXQEC);
5811 temp = E1000_READ_REG(hw, ICTXQMTC);
5812 temp = E1000_READ_REG(hw, ICRXDMTC);
5815 /******************************************************************************
5816 * Resets Adaptive IFS to its default state.
5818 * hw - Struct containing variables accessed by shared code
5820 * Call this after e1000_init_hw. You may override the IFS defaults by setting
5821 * hw->ifs_params_forced to TRUE. However, you must initialize hw->
5822 * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio
5823 * before calling this function.
5824 *****************************************************************************/
5826 e1000_reset_adaptive(struct e1000_hw *hw)
5828 DEBUGFUNC("e1000_reset_adaptive");
5830 if(hw->adaptive_ifs) {
5831 if(!hw->ifs_params_forced) {
5832 hw->current_ifs_val = 0;
5833 hw->ifs_min_val = IFS_MIN;
5834 hw->ifs_max_val = IFS_MAX;
5835 hw->ifs_step_size = IFS_STEP;
5836 hw->ifs_ratio = IFS_RATIO;
5838 hw->in_ifs_mode = FALSE;
5839 E1000_WRITE_REG(hw, AIT, 0);
5841 DEBUGOUT("Not in Adaptive IFS mode!\n");
5845 /******************************************************************************
5846 * Called during the callback/watchdog routine to update IFS value based on
5847 * the ratio of transmits to collisions.
5849 * hw - Struct containing variables accessed by shared code
5850 * tx_packets - Number of transmits since last callback
5851 * total_collisions - Number of collisions since last callback
5852 *****************************************************************************/
5854 e1000_update_adaptive(struct e1000_hw *hw)
5856 DEBUGFUNC("e1000_update_adaptive");
5858 if(hw->adaptive_ifs) {
5859 if((hw->collision_delta * hw->ifs_ratio) > hw->tx_packet_delta) {
5860 if(hw->tx_packet_delta > MIN_NUM_XMITS) {
5861 hw->in_ifs_mode = TRUE;
5862 if(hw->current_ifs_val < hw->ifs_max_val) {
5863 if(hw->current_ifs_val == 0)
5864 hw->current_ifs_val = hw->ifs_min_val;
5866 hw->current_ifs_val += hw->ifs_step_size;
5867 E1000_WRITE_REG(hw, AIT, hw->current_ifs_val);
5871 if(hw->in_ifs_mode && (hw->tx_packet_delta <= MIN_NUM_XMITS)) {
5872 hw->current_ifs_val = 0;
5873 hw->in_ifs_mode = FALSE;
5874 E1000_WRITE_REG(hw, AIT, 0);
5878 DEBUGOUT("Not in Adaptive IFS mode!\n");
5882 /******************************************************************************
5883 * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT
5885 * hw - Struct containing variables accessed by shared code
5886 * frame_len - The length of the frame in question
5887 * mac_addr - The Ethernet destination address of the frame in question
5888 *****************************************************************************/
5890 e1000_tbi_adjust_stats(struct e1000_hw *hw,
5891 struct e1000_hw_stats *stats,
5897 /* First adjust the frame length. */
5899 /* We need to adjust the statistics counters, since the hardware
5900 * counters overcount this packet as a CRC error and undercount
5901 * the packet as a good packet
5903 /* This packet should not be counted as a CRC error. */
5905 /* This packet does count as a Good Packet Received. */
5908 /* Adjust the Good Octets received counters */
5909 carry_bit = 0x80000000 & stats->gorcl;
5910 stats->gorcl += frame_len;
5911 /* If the high bit of Gorcl (the low 32 bits of the Good Octets
5912 * Received Count) was one before the addition,
5913 * AND it is zero after, then we lost the carry out,
5914 * need to add one to Gorch (Good Octets Received Count High).
5915 * This could be simplified if all environments supported
5918 if(carry_bit && ((stats->gorcl & 0x80000000) == 0))
5920 /* Is this a broadcast or multicast? Check broadcast first,
5921 * since the test for a multicast frame will test positive on
5922 * a broadcast frame.
5924 if((mac_addr[0] == (uint8_t) 0xff) && (mac_addr[1] == (uint8_t) 0xff))
5925 /* Broadcast packet */
5927 else if(*mac_addr & 0x01)
5928 /* Multicast packet */
5931 if(frame_len == hw->max_frame_size) {
5932 /* In this case, the hardware has overcounted the number of
5939 /* Adjust the bin counters when the extra byte put the frame in the
5940 * wrong bin. Remember that the frame_len was adjusted above.
5942 if(frame_len == 64) {
5945 } else if(frame_len == 127) {
5948 } else if(frame_len == 255) {
5951 } else if(frame_len == 511) {
5954 } else if(frame_len == 1023) {
5957 } else if(frame_len == 1522) {
5962 /******************************************************************************
5963 * Gets the current PCI bus type, speed, and width of the hardware
5965 * hw - Struct containing variables accessed by shared code
5966 *****************************************************************************/
5968 e1000_get_bus_info(struct e1000_hw *hw)
5972 switch (hw->mac_type) {
5973 case e1000_82542_rev2_0:
5974 case e1000_82542_rev2_1:
5975 hw->bus_type = e1000_bus_type_unknown;
5976 hw->bus_speed = e1000_bus_speed_unknown;
5977 hw->bus_width = e1000_bus_width_unknown;
5981 hw->bus_type = e1000_bus_type_pci_express;
5982 hw->bus_speed = e1000_bus_speed_2500;
5983 hw->bus_width = e1000_bus_width_pciex_1;
5986 case e1000_80003es2lan:
5987 hw->bus_type = e1000_bus_type_pci_express;
5988 hw->bus_speed = e1000_bus_speed_2500;
5989 hw->bus_width = e1000_bus_width_pciex_4;
5992 status = E1000_READ_REG(hw, STATUS);
5993 hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
5994 e1000_bus_type_pcix : e1000_bus_type_pci;
5996 if(hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) {
5997 hw->bus_speed = (hw->bus_type == e1000_bus_type_pci) ?
5998 e1000_bus_speed_66 : e1000_bus_speed_120;
5999 } else if(hw->bus_type == e1000_bus_type_pci) {
6000 hw->bus_speed = (status & E1000_STATUS_PCI66) ?
6001 e1000_bus_speed_66 : e1000_bus_speed_33;
6003 switch (status & E1000_STATUS_PCIX_SPEED) {
6004 case E1000_STATUS_PCIX_SPEED_66:
6005 hw->bus_speed = e1000_bus_speed_66;
6007 case E1000_STATUS_PCIX_SPEED_100:
6008 hw->bus_speed = e1000_bus_speed_100;
6010 case E1000_STATUS_PCIX_SPEED_133:
6011 hw->bus_speed = e1000_bus_speed_133;
6014 hw->bus_speed = e1000_bus_speed_reserved;
6018 hw->bus_width = (status & E1000_STATUS_BUS64) ?
6019 e1000_bus_width_64 : e1000_bus_width_32;
6025 /******************************************************************************
6026 * Reads a value from one of the devices registers using port I/O (as opposed
6027 * memory mapped I/O). Only 82544 and newer devices support port I/O.
6029 * hw - Struct containing variables accessed by shared code
6030 * offset - offset to read from
6031 *****************************************************************************/
6033 e1000_read_reg_io(struct e1000_hw *hw,
6036 unsigned long io_addr = hw->io_base;
6037 unsigned long io_data = hw->io_base + 4;
6039 e1000_io_write(hw, io_addr, offset);
6040 return e1000_io_read(hw, io_data);
6044 /******************************************************************************
6045 * Writes a value to one of the devices registers using port I/O (as opposed to
6046 * memory mapped I/O). Only 82544 and newer devices support port I/O.
6048 * hw - Struct containing variables accessed by shared code
6049 * offset - offset to write to
6050 * value - value to write
6051 *****************************************************************************/
6053 e1000_write_reg_io(struct e1000_hw *hw,
6057 unsigned long io_addr = hw->io_base;
6058 unsigned long io_data = hw->io_base + 4;
6060 e1000_io_write(hw, io_addr, offset);
6061 e1000_io_write(hw, io_data, value);
6065 /******************************************************************************
6066 * Estimates the cable length.
6068 * hw - Struct containing variables accessed by shared code
6069 * min_length - The estimated minimum length
6070 * max_length - The estimated maximum length
6072 * returns: - E1000_ERR_XXX
6075 * This function always returns a ranged length (minimum & maximum).
6076 * So for M88 phy's, this function interprets the one value returned from the
6077 * register to the minimum and maximum range.
6078 * For IGP phy's, the function calculates the range by the AGC registers.
6079 *****************************************************************************/
6081 e1000_get_cable_length(struct e1000_hw *hw,
6082 uint16_t *min_length,
6083 uint16_t *max_length)
6086 uint16_t agc_value = 0;
6087 uint16_t cur_agc, min_agc = IGP01E1000_AGC_LENGTH_TABLE_SIZE;
6088 uint16_t max_agc = 0;
6089 uint16_t i, phy_data;
6090 uint16_t cable_length;
6092 DEBUGFUNC("e1000_get_cable_length");
6094 *min_length = *max_length = 0;
6096 /* Use old method for Phy older than IGP */
6097 if(hw->phy_type == e1000_phy_m88) {
6099 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6103 cable_length = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
6104 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
6106 /* Convert the enum value to ranged values */
6107 switch (cable_length) {
6108 case e1000_cable_length_50:
6110 *max_length = e1000_igp_cable_length_50;
6112 case e1000_cable_length_50_80:
6113 *min_length = e1000_igp_cable_length_50;
6114 *max_length = e1000_igp_cable_length_80;
6116 case e1000_cable_length_80_110:
6117 *min_length = e1000_igp_cable_length_80;
6118 *max_length = e1000_igp_cable_length_110;
6120 case e1000_cable_length_110_140:
6121 *min_length = e1000_igp_cable_length_110;
6122 *max_length = e1000_igp_cable_length_140;
6124 case e1000_cable_length_140:
6125 *min_length = e1000_igp_cable_length_140;
6126 *max_length = e1000_igp_cable_length_170;
6129 return -E1000_ERR_PHY;
6132 } else if (hw->phy_type == e1000_phy_gg82563) {
6133 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_DSP_DISTANCE,
6137 cable_length = phy_data & GG82563_DSPD_CABLE_LENGTH;
6139 switch (cable_length) {
6140 case e1000_gg_cable_length_60:
6142 *max_length = e1000_igp_cable_length_60;
6144 case e1000_gg_cable_length_60_115:
6145 *min_length = e1000_igp_cable_length_60;
6146 *max_length = e1000_igp_cable_length_115;
6148 case e1000_gg_cable_length_115_150:
6149 *min_length = e1000_igp_cable_length_115;
6150 *max_length = e1000_igp_cable_length_150;
6152 case e1000_gg_cable_length_150:
6153 *min_length = e1000_igp_cable_length_150;
6154 *max_length = e1000_igp_cable_length_180;
6157 return -E1000_ERR_PHY;
6160 } else if(hw->phy_type == e1000_phy_igp) { /* For IGP PHY */
6161 uint16_t agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
6162 {IGP01E1000_PHY_AGC_A,
6163 IGP01E1000_PHY_AGC_B,
6164 IGP01E1000_PHY_AGC_C,
6165 IGP01E1000_PHY_AGC_D};
6166 /* Read the AGC registers for all channels */
6167 for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
6169 ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
6173 cur_agc = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT;
6175 /* Array bound check. */
6176 if((cur_agc >= IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1) ||
6178 return -E1000_ERR_PHY;
6180 agc_value += cur_agc;
6182 /* Update minimal AGC value. */
6183 if(min_agc > cur_agc)
6187 /* Remove the minimal AGC result for length < 50m */
6188 if(agc_value < IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) {
6189 agc_value -= min_agc;
6191 /* Get the average length of the remaining 3 channels */
6192 agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1);
6194 /* Get the average length of all the 4 channels. */
6195 agc_value /= IGP01E1000_PHY_CHANNEL_NUM;
6198 /* Set the range of the calculated length. */
6199 *min_length = ((e1000_igp_cable_length_table[agc_value] -
6200 IGP01E1000_AGC_RANGE) > 0) ?
6201 (e1000_igp_cable_length_table[agc_value] -
6202 IGP01E1000_AGC_RANGE) : 0;
6203 *max_length = e1000_igp_cable_length_table[agc_value] +
6204 IGP01E1000_AGC_RANGE;
6205 } else if (hw->phy_type == e1000_phy_igp_2) {
6206 uint16_t agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] =
6207 {IGP02E1000_PHY_AGC_A,
6208 IGP02E1000_PHY_AGC_B,
6209 IGP02E1000_PHY_AGC_C,
6210 IGP02E1000_PHY_AGC_D};
6211 /* Read the AGC registers for all channels */
6212 for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
6213 ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
6217 /* Getting bits 15:9, which represent the combination of course and
6218 * fine gain values. The result is a number that can be put into
6219 * the lookup table to obtain the approximate cable length. */
6220 cur_agc = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
6221 IGP02E1000_AGC_LENGTH_MASK;
6223 /* Remove min & max AGC values from calculation. */
6224 if (e1000_igp_2_cable_length_table[min_agc] > e1000_igp_2_cable_length_table[cur_agc])
6226 if (e1000_igp_2_cable_length_table[max_agc] < e1000_igp_2_cable_length_table[cur_agc])
6229 agc_value += e1000_igp_2_cable_length_table[cur_agc];
6232 agc_value -= (e1000_igp_2_cable_length_table[min_agc] + e1000_igp_2_cable_length_table[max_agc]);
6233 agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
6235 /* Calculate cable length with the error range of +/- 10 meters. */
6236 *min_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
6237 (agc_value - IGP02E1000_AGC_RANGE) : 0;
6238 *max_length = agc_value + IGP02E1000_AGC_RANGE;
6241 return E1000_SUCCESS;
6244 /******************************************************************************
6245 * Check the cable polarity
6247 * hw - Struct containing variables accessed by shared code
6248 * polarity - output parameter : 0 - Polarity is not reversed
6249 * 1 - Polarity is reversed.
6251 * returns: - E1000_ERR_XXX
6254 * For phy's older then IGP, this function simply reads the polarity bit in the
6255 * Phy Status register. For IGP phy's, this bit is valid only if link speed is
6256 * 10 Mbps. If the link speed is 100 Mbps there is no polarity so this bit will
6257 * return 0. If the link speed is 1000 Mbps the polarity status is in the
6258 * IGP01E1000_PHY_PCS_INIT_REG.
6259 *****************************************************************************/
6261 e1000_check_polarity(struct e1000_hw *hw,
6267 DEBUGFUNC("e1000_check_polarity");
6269 if ((hw->phy_type == e1000_phy_m88) ||
6270 (hw->phy_type == e1000_phy_gg82563)) {
6271 /* return the Polarity bit in the Status register. */
6272 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6276 *polarity = (phy_data & M88E1000_PSSR_REV_POLARITY) >>
6277 M88E1000_PSSR_REV_POLARITY_SHIFT;
6278 } else if(hw->phy_type == e1000_phy_igp ||
6279 hw->phy_type == e1000_phy_igp_2) {
6280 /* Read the Status register to check the speed */
6281 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
6286 /* If speed is 1000 Mbps, must read the IGP01E1000_PHY_PCS_INIT_REG to
6287 * find the polarity status */
6288 if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
6289 IGP01E1000_PSSR_SPEED_1000MBPS) {
6291 /* Read the GIG initialization PCS register (0x00B4) */
6292 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG,
6297 /* Check the polarity bits */
6298 *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ? 1 : 0;
6300 /* For 10 Mbps, read the polarity bit in the status register. (for
6301 * 100 Mbps this bit is always 0) */
6302 *polarity = phy_data & IGP01E1000_PSSR_POLARITY_REVERSED;
6305 return E1000_SUCCESS;
6308 /******************************************************************************
6309 * Check if Downshift occured
6311 * hw - Struct containing variables accessed by shared code
6312 * downshift - output parameter : 0 - No Downshift ocured.
6313 * 1 - Downshift ocured.
6315 * returns: - E1000_ERR_XXX
6318 * For phy's older then IGP, this function reads the Downshift bit in the Phy
6319 * Specific Status register. For IGP phy's, it reads the Downgrade bit in the
6320 * Link Health register. In IGP this bit is latched high, so the driver must
6321 * read it immediately after link is established.
6322 *****************************************************************************/
6324 e1000_check_downshift(struct e1000_hw *hw)
6329 DEBUGFUNC("e1000_check_downshift");
6331 if(hw->phy_type == e1000_phy_igp ||
6332 hw->phy_type == e1000_phy_igp_2) {
6333 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH,
6338 hw->speed_downgraded = (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0;
6339 } else if ((hw->phy_type == e1000_phy_m88) ||
6340 (hw->phy_type == e1000_phy_gg82563)) {
6341 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6346 hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >>
6347 M88E1000_PSSR_DOWNSHIFT_SHIFT;
6350 return E1000_SUCCESS;
6353 /*****************************************************************************
6355 * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a
6356 * gigabit link is achieved to improve link quality.
6358 * hw: Struct containing variables accessed by shared code
6360 * returns: - E1000_ERR_PHY if fail to read/write the PHY
6361 * E1000_SUCCESS at any other case.
6363 ****************************************************************************/
6366 e1000_config_dsp_after_link_change(struct e1000_hw *hw,
6370 uint16_t phy_data, phy_saved_data, speed, duplex, i;
6371 uint16_t dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
6372 {IGP01E1000_PHY_AGC_PARAM_A,
6373 IGP01E1000_PHY_AGC_PARAM_B,
6374 IGP01E1000_PHY_AGC_PARAM_C,
6375 IGP01E1000_PHY_AGC_PARAM_D};
6376 uint16_t min_length, max_length;
6378 DEBUGFUNC("e1000_config_dsp_after_link_change");
6380 if(hw->phy_type != e1000_phy_igp)
6381 return E1000_SUCCESS;
6384 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
6386 DEBUGOUT("Error getting link speed and duplex\n");
6390 if(speed == SPEED_1000) {
6392 e1000_get_cable_length(hw, &min_length, &max_length);
6394 if((hw->dsp_config_state == e1000_dsp_config_enabled) &&
6395 min_length >= e1000_igp_cable_length_50) {
6397 for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
6398 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i],
6403 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
6405 ret_val = e1000_write_phy_reg(hw, dsp_reg_array[i],
6410 hw->dsp_config_state = e1000_dsp_config_activated;
6413 if((hw->ffe_config_state == e1000_ffe_config_enabled) &&
6414 (min_length < e1000_igp_cable_length_50)) {
6416 uint16_t ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_20;
6417 uint32_t idle_errs = 0;
6419 /* clear previous idle error counts */
6420 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
6425 for(i = 0; i < ffe_idle_err_timeout; i++) {
6427 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
6432 idle_errs += (phy_data & SR_1000T_IDLE_ERROR_CNT);
6433 if(idle_errs > SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT) {
6434 hw->ffe_config_state = e1000_ffe_config_active;
6436 ret_val = e1000_write_phy_reg(hw,
6437 IGP01E1000_PHY_DSP_FFE,
6438 IGP01E1000_PHY_DSP_FFE_CM_CP);
6445 ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_100;
6450 if(hw->dsp_config_state == e1000_dsp_config_activated) {
6451 /* Save off the current value of register 0x2F5B to be restored at
6452 * the end of the routines. */
6453 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
6458 /* Disable the PHY transmitter */
6459 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
6466 ret_val = e1000_write_phy_reg(hw, 0x0000,
6467 IGP01E1000_IEEE_FORCE_GIGA);
6470 for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
6471 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i], &phy_data);
6475 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
6476 phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS;
6478 ret_val = e1000_write_phy_reg(hw,dsp_reg_array[i], phy_data);
6483 ret_val = e1000_write_phy_reg(hw, 0x0000,
6484 IGP01E1000_IEEE_RESTART_AUTONEG);
6490 /* Now enable the transmitter */
6491 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
6496 hw->dsp_config_state = e1000_dsp_config_enabled;
6499 if(hw->ffe_config_state == e1000_ffe_config_active) {
6500 /* Save off the current value of register 0x2F5B to be restored at
6501 * the end of the routines. */
6502 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
6507 /* Disable the PHY transmitter */
6508 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
6515 ret_val = e1000_write_phy_reg(hw, 0x0000,
6516 IGP01E1000_IEEE_FORCE_GIGA);
6519 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE,
6520 IGP01E1000_PHY_DSP_FFE_DEFAULT);
6524 ret_val = e1000_write_phy_reg(hw, 0x0000,
6525 IGP01E1000_IEEE_RESTART_AUTONEG);
6531 /* Now enable the transmitter */
6532 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
6537 hw->ffe_config_state = e1000_ffe_config_enabled;
6540 return E1000_SUCCESS;
6543 /*****************************************************************************
6544 * Set PHY to class A mode
6545 * Assumes the following operations will follow to enable the new class mode.
6546 * 1. Do a PHY soft reset
6547 * 2. Restart auto-negotiation or force link.
6549 * hw - Struct containing variables accessed by shared code
6550 ****************************************************************************/
6552 e1000_set_phy_mode(struct e1000_hw *hw)
6555 uint16_t eeprom_data;
6557 DEBUGFUNC("e1000_set_phy_mode");
6559 if((hw->mac_type == e1000_82545_rev_3) &&
6560 (hw->media_type == e1000_media_type_copper)) {
6561 ret_val = e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, 1, &eeprom_data);
6566 if((eeprom_data != EEPROM_RESERVED_WORD) &&
6567 (eeprom_data & EEPROM_PHY_CLASS_A)) {
6568 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x000B);
6571 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x8104);
6575 hw->phy_reset_disable = FALSE;
6579 return E1000_SUCCESS;
6582 /*****************************************************************************
6584 * This function sets the lplu state according to the active flag. When
6585 * activating lplu this function also disables smart speed and vise versa.
6586 * lplu will not be activated unless the device autonegotiation advertisment
6587 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
6588 * hw: Struct containing variables accessed by shared code
6589 * active - true to enable lplu false to disable lplu.
6591 * returns: - E1000_ERR_PHY if fail to read/write the PHY
6592 * E1000_SUCCESS at any other case.
6594 ****************************************************************************/
6597 e1000_set_d3_lplu_state(struct e1000_hw *hw,
6602 DEBUGFUNC("e1000_set_d3_lplu_state");
6604 if(hw->phy_type != e1000_phy_igp && hw->phy_type != e1000_phy_igp_2)
6605 return E1000_SUCCESS;
6607 /* During driver activity LPLU should not be used or it will attain link
6608 * from the lowest speeds starting from 10Mbps. The capability is used for
6609 * Dx transitions and states */
6610 if(hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2) {
6611 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data);
6615 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
6621 if(hw->mac_type == e1000_82541_rev_2 ||
6622 hw->mac_type == e1000_82547_rev_2) {
6623 phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
6624 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
6628 phy_data &= ~IGP02E1000_PM_D3_LPLU;
6629 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
6635 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
6636 * Dx states where the power conservation is most important. During
6637 * driver activity we should enable SmartSpeed, so performance is
6639 if (hw->smart_speed == e1000_smart_speed_on) {
6640 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
6645 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
6646 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
6650 } else if (hw->smart_speed == e1000_smart_speed_off) {
6651 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
6656 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
6657 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
6663 } else if((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT) ||
6664 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL ) ||
6665 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) {
6667 if(hw->mac_type == e1000_82541_rev_2 ||
6668 hw->mac_type == e1000_82547_rev_2) {
6669 phy_data |= IGP01E1000_GMII_FLEX_SPD;
6670 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
6674 phy_data |= IGP02E1000_PM_D3_LPLU;
6675 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
6681 /* When LPLU is enabled we should disable SmartSpeed */
6682 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
6686 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
6687 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
6692 return E1000_SUCCESS;
6695 /*****************************************************************************
6697 * This function sets the lplu d0 state according to the active flag. When
6698 * activating lplu this function also disables smart speed and vise versa.
6699 * lplu will not be activated unless the device autonegotiation advertisment
6700 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
6701 * hw: Struct containing variables accessed by shared code
6702 * active - true to enable lplu false to disable lplu.
6704 * returns: - E1000_ERR_PHY if fail to read/write the PHY
6705 * E1000_SUCCESS at any other case.
6707 ****************************************************************************/
6710 e1000_set_d0_lplu_state(struct e1000_hw *hw,
6715 DEBUGFUNC("e1000_set_d0_lplu_state");
6717 if(hw->mac_type <= e1000_82547_rev_2)
6718 return E1000_SUCCESS;
6720 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
6725 phy_data &= ~IGP02E1000_PM_D0_LPLU;
6726 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
6730 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
6731 * Dx states where the power conservation is most important. During
6732 * driver activity we should enable SmartSpeed, so performance is
6734 if (hw->smart_speed == e1000_smart_speed_on) {
6735 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
6740 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
6741 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
6745 } else if (hw->smart_speed == e1000_smart_speed_off) {
6746 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
6751 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
6752 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
6761 phy_data |= IGP02E1000_PM_D0_LPLU;
6762 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
6766 /* When LPLU is enabled we should disable SmartSpeed */
6767 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
6771 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
6772 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
6777 return E1000_SUCCESS;
6780 /******************************************************************************
6781 * Change VCO speed register to improve Bit Error Rate performance of SERDES.
6783 * hw - Struct containing variables accessed by shared code
6784 *****************************************************************************/
6786 e1000_set_vco_speed(struct e1000_hw *hw)
6789 uint16_t default_page = 0;
6792 DEBUGFUNC("e1000_set_vco_speed");
6794 switch(hw->mac_type) {
6795 case e1000_82545_rev_3:
6796 case e1000_82546_rev_3:
6799 return E1000_SUCCESS;
6802 /* Set PHY register 30, page 5, bit 8 to 0 */
6804 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, &default_page);
6808 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005);
6812 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
6816 phy_data &= ~M88E1000_PHY_VCO_REG_BIT8;
6817 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
6821 /* Set PHY register 30, page 4, bit 11 to 1 */
6823 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004);
6827 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
6831 phy_data |= M88E1000_PHY_VCO_REG_BIT11;
6832 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
6836 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, default_page);
6840 return E1000_SUCCESS;
6844 /*****************************************************************************
6845 * This function reads the cookie from ARC ram.
6847 * returns: - E1000_SUCCESS .
6848 ****************************************************************************/
6850 e1000_host_if_read_cookie(struct e1000_hw * hw, uint8_t *buffer)
6853 uint32_t offset = E1000_MNG_DHCP_COOKIE_OFFSET;
6854 uint8_t length = E1000_MNG_DHCP_COOKIE_LENGTH;
6856 length = (length >> 2);
6857 offset = (offset >> 2);
6859 for (i = 0; i < length; i++) {
6860 *((uint32_t *) buffer + i) =
6861 E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset + i);
6863 return E1000_SUCCESS;
6867 /*****************************************************************************
6868 * This function checks whether the HOST IF is enabled for command operaton
6869 * and also checks whether the previous command is completed.
6870 * It busy waits in case of previous command is not completed.
6872 * returns: - E1000_ERR_HOST_INTERFACE_COMMAND in case if is not ready or
6874 * - E1000_SUCCESS for success.
6875 ****************************************************************************/
6877 e1000_mng_enable_host_if(struct e1000_hw * hw)
6882 /* Check that the host interface is enabled. */
6883 hicr = E1000_READ_REG(hw, HICR);
6884 if ((hicr & E1000_HICR_EN) == 0) {
6885 DEBUGOUT("E1000_HOST_EN bit disabled.\n");
6886 return -E1000_ERR_HOST_INTERFACE_COMMAND;
6888 /* check the previous command is completed */
6889 for (i = 0; i < E1000_MNG_DHCP_COMMAND_TIMEOUT; i++) {
6890 hicr = E1000_READ_REG(hw, HICR);
6891 if (!(hicr & E1000_HICR_C))
6896 if (i == E1000_MNG_DHCP_COMMAND_TIMEOUT) {
6897 DEBUGOUT("Previous command timeout failed .\n");
6898 return -E1000_ERR_HOST_INTERFACE_COMMAND;
6900 return E1000_SUCCESS;
6903 /*****************************************************************************
6904 * This function writes the buffer content at the offset given on the host if.
6905 * It also does alignment considerations to do the writes in most efficient way.
6906 * Also fills up the sum of the buffer in *buffer parameter.
6908 * returns - E1000_SUCCESS for success.
6909 ****************************************************************************/
6911 e1000_mng_host_if_write(struct e1000_hw * hw, uint8_t *buffer,
6912 uint16_t length, uint16_t offset, uint8_t *sum)
6915 uint8_t *bufptr = buffer;
6917 uint16_t remaining, i, j, prev_bytes;
6919 /* sum = only sum of the data and it is not checksum */
6921 if (length == 0 || offset + length > E1000_HI_MAX_MNG_DATA_LENGTH) {
6922 return -E1000_ERR_PARAM;
6925 tmp = (uint8_t *)&data;
6926 prev_bytes = offset & 0x3;
6931 data = E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset);
6932 for (j = prev_bytes; j < sizeof(uint32_t); j++) {
6933 *(tmp + j) = *bufptr++;
6936 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset, data);
6937 length -= j - prev_bytes;
6941 remaining = length & 0x3;
6942 length -= remaining;
6944 /* Calculate length in DWORDs */
6947 /* The device driver writes the relevant command block into the
6949 for (i = 0; i < length; i++) {
6950 for (j = 0; j < sizeof(uint32_t); j++) {
6951 *(tmp + j) = *bufptr++;
6955 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data);
6958 for (j = 0; j < sizeof(uint32_t); j++) {
6960 *(tmp + j) = *bufptr++;
6966 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data);
6969 return E1000_SUCCESS;
6973 /*****************************************************************************
6974 * This function writes the command header after does the checksum calculation.
6976 * returns - E1000_SUCCESS for success.
6977 ****************************************************************************/
6979 e1000_mng_write_cmd_header(struct e1000_hw * hw,
6980 struct e1000_host_mng_command_header * hdr)
6986 /* Write the whole command header structure which includes sum of
6989 uint16_t length = sizeof(struct e1000_host_mng_command_header);
6991 sum = hdr->checksum;
6994 buffer = (uint8_t *) hdr;
6999 hdr->checksum = 0 - sum;
7002 /* The device driver writes the relevant command block into the ram area. */
7003 for (i = 0; i < length; i++) {
7004 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, i, *((uint32_t *) hdr + i));
7005 E1000_WRITE_FLUSH(hw);
7008 return E1000_SUCCESS;
7012 /*****************************************************************************
7013 * This function indicates to ARC that a new command is pending which completes
7014 * one write operation by the driver.
7016 * returns - E1000_SUCCESS for success.
7017 ****************************************************************************/
7019 e1000_mng_write_commit(
7020 struct e1000_hw * hw)
7024 hicr = E1000_READ_REG(hw, HICR);
7025 /* Setting this bit tells the ARC that a new command is pending. */
7026 E1000_WRITE_REG(hw, HICR, hicr | E1000_HICR_C);
7028 return E1000_SUCCESS;
7032 /*****************************************************************************
7033 * This function checks the mode of the firmware.
7035 * returns - TRUE when the mode is IAMT or FALSE.
7036 ****************************************************************************/
7038 e1000_check_mng_mode(
7039 struct e1000_hw *hw)
7043 fwsm = E1000_READ_REG(hw, FWSM);
7045 if((fwsm & E1000_FWSM_MODE_MASK) ==
7046 (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
7053 /*****************************************************************************
7054 * This function writes the dhcp info .
7055 ****************************************************************************/
7057 e1000_mng_write_dhcp_info(struct e1000_hw * hw, uint8_t *buffer,
7061 struct e1000_host_mng_command_header hdr;
7063 hdr.command_id = E1000_MNG_DHCP_TX_PAYLOAD_CMD;
7064 hdr.command_length = length;
7069 ret_val = e1000_mng_enable_host_if(hw);
7070 if (ret_val == E1000_SUCCESS) {
7071 ret_val = e1000_mng_host_if_write(hw, buffer, length, sizeof(hdr),
7073 if (ret_val == E1000_SUCCESS) {
7074 ret_val = e1000_mng_write_cmd_header(hw, &hdr);
7075 if (ret_val == E1000_SUCCESS)
7076 ret_val = e1000_mng_write_commit(hw);
7083 /*****************************************************************************
7084 * This function calculates the checksum.
7086 * returns - checksum of buffer contents.
7087 ****************************************************************************/
7089 e1000_calculate_mng_checksum(char *buffer, uint32_t length)
7097 for (i=0; i < length; i++)
7100 return (uint8_t) (0 - sum);
7103 /*****************************************************************************
7104 * This function checks whether tx pkt filtering needs to be enabled or not.
7106 * returns - TRUE for packet filtering or FALSE.
7107 ****************************************************************************/
7109 e1000_enable_tx_pkt_filtering(struct e1000_hw *hw)
7111 /* called in init as well as watchdog timer functions */
7113 int32_t ret_val, checksum;
7114 boolean_t tx_filter = FALSE;
7115 struct e1000_host_mng_dhcp_cookie *hdr = &(hw->mng_cookie);
7116 uint8_t *buffer = (uint8_t *) &(hw->mng_cookie);
7118 if (e1000_check_mng_mode(hw)) {
7119 ret_val = e1000_mng_enable_host_if(hw);
7120 if (ret_val == E1000_SUCCESS) {
7121 ret_val = e1000_host_if_read_cookie(hw, buffer);
7122 if (ret_val == E1000_SUCCESS) {
7123 checksum = hdr->checksum;
7125 if ((hdr->signature == E1000_IAMT_SIGNATURE) &&
7126 checksum == e1000_calculate_mng_checksum((char *)buffer,
7127 E1000_MNG_DHCP_COOKIE_LENGTH)) {
7129 E1000_MNG_DHCP_COOKIE_STATUS_PARSING_SUPPORT)
7138 hw->tx_pkt_filtering = tx_filter;
7142 /******************************************************************************
7143 * Verifies the hardware needs to allow ARPs to be processed by the host
7145 * hw - Struct containing variables accessed by shared code
7147 * returns: - TRUE/FALSE
7149 *****************************************************************************/
7151 e1000_enable_mng_pass_thru(struct e1000_hw *hw)
7154 uint32_t fwsm, factps;
7156 if (hw->asf_firmware_present) {
7157 manc = E1000_READ_REG(hw, MANC);
7159 if (!(manc & E1000_MANC_RCV_TCO_EN) ||
7160 !(manc & E1000_MANC_EN_MAC_ADDR_FILTER))
7162 if (e1000_arc_subsystem_valid(hw) == TRUE) {
7163 fwsm = E1000_READ_REG(hw, FWSM);
7164 factps = E1000_READ_REG(hw, FACTPS);
7166 if (((fwsm & E1000_FWSM_MODE_MASK) ==
7167 (e1000_mng_mode_pt << E1000_FWSM_MODE_SHIFT)) &&
7168 (factps & E1000_FACTPS_MNGCG))
7171 if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN))
7178 e1000_polarity_reversal_workaround(struct e1000_hw *hw)
7181 uint16_t mii_status_reg;
7184 /* Polarity reversal workaround for forced 10F/10H links. */
7186 /* Disable the transmitter on the PHY */
7188 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
7191 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF);
7195 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
7199 /* This loop will early-out if the NO link condition has been met. */
7200 for(i = PHY_FORCE_TIME; i > 0; i--) {
7201 /* Read the MII Status Register and wait for Link Status bit
7205 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
7209 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
7213 if((mii_status_reg & ~MII_SR_LINK_STATUS) == 0) break;
7214 msec_delay_irq(100);
7217 /* Recommended delay time after link has been lost */
7218 msec_delay_irq(1000);
7220 /* Now we will re-enable th transmitter on the PHY */
7222 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
7226 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0);
7230 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00);
7234 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000);
7238 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
7242 /* This loop will early-out if the link condition has been met. */
7243 for(i = PHY_FORCE_TIME; i > 0; i--) {
7244 /* Read the MII Status Register and wait for Link Status bit
7248 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
7252 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
7256 if(mii_status_reg & MII_SR_LINK_STATUS) break;
7257 msec_delay_irq(100);
7259 return E1000_SUCCESS;
7262 /***************************************************************************
7264 * Disables PCI-Express master access.
7266 * hw: Struct containing variables accessed by shared code
7270 ***************************************************************************/
7272 e1000_set_pci_express_master_disable(struct e1000_hw *hw)
7276 DEBUGFUNC("e1000_set_pci_express_master_disable");
7278 if (hw->bus_type != e1000_bus_type_pci_express)
7281 ctrl = E1000_READ_REG(hw, CTRL);
7282 ctrl |= E1000_CTRL_GIO_MASTER_DISABLE;
7283 E1000_WRITE_REG(hw, CTRL, ctrl);
7287 /***************************************************************************
7289 * Enables PCI-Express master access.
7291 * hw: Struct containing variables accessed by shared code
7295 ***************************************************************************/
7297 e1000_enable_pciex_master(struct e1000_hw *hw)
7301 DEBUGFUNC("e1000_enable_pciex_master");
7303 if (hw->bus_type != e1000_bus_type_pci_express)
7306 ctrl = E1000_READ_REG(hw, CTRL);
7307 ctrl &= ~E1000_CTRL_GIO_MASTER_DISABLE;
7308 E1000_WRITE_REG(hw, CTRL, ctrl);
7312 /*******************************************************************************
7314 * Disables PCI-Express master access and verifies there are no pending requests
7316 * hw: Struct containing variables accessed by shared code
7318 * returns: - E1000_ERR_MASTER_REQUESTS_PENDING if master disable bit hasn't
7319 * caused the master requests to be disabled.
7320 * E1000_SUCCESS master requests disabled.
7322 ******************************************************************************/
7324 e1000_disable_pciex_master(struct e1000_hw *hw)
7326 int32_t timeout = MASTER_DISABLE_TIMEOUT; /* 80ms */
7328 DEBUGFUNC("e1000_disable_pciex_master");
7330 if (hw->bus_type != e1000_bus_type_pci_express)
7331 return E1000_SUCCESS;
7333 e1000_set_pci_express_master_disable(hw);
7336 if(!(E1000_READ_REG(hw, STATUS) & E1000_STATUS_GIO_MASTER_ENABLE))
7344 DEBUGOUT("Master requests are pending.\n");
7345 return -E1000_ERR_MASTER_REQUESTS_PENDING;
7348 return E1000_SUCCESS;
7351 /*******************************************************************************
7353 * Check for EEPROM Auto Read bit done.
7355 * hw: Struct containing variables accessed by shared code
7357 * returns: - E1000_ERR_RESET if fail to reset MAC
7358 * E1000_SUCCESS at any other case.
7360 ******************************************************************************/
7362 e1000_get_auto_rd_done(struct e1000_hw *hw)
7364 int32_t timeout = AUTO_READ_DONE_TIMEOUT;
7366 DEBUGFUNC("e1000_get_auto_rd_done");
7368 switch (hw->mac_type) {
7375 case e1000_80003es2lan:
7377 if (E1000_READ_REG(hw, EECD) & E1000_EECD_AUTO_RD) break;
7383 DEBUGOUT("Auto read by HW from EEPROM has not completed.\n");
7384 return -E1000_ERR_RESET;
7389 /* PHY configuration from NVM just starts after EECD_AUTO_RD sets to high.
7390 * Need to wait for PHY configuration completion before accessing NVM
7392 if (hw->mac_type == e1000_82573)
7395 return E1000_SUCCESS;
7398 /***************************************************************************
7399 * Checks if the PHY configuration is done
7401 * hw: Struct containing variables accessed by shared code
7403 * returns: - E1000_ERR_RESET if fail to reset MAC
7404 * E1000_SUCCESS at any other case.
7406 ***************************************************************************/
7408 e1000_get_phy_cfg_done(struct e1000_hw *hw)
7410 int32_t timeout = PHY_CFG_TIMEOUT;
7411 uint32_t cfg_mask = E1000_EEPROM_CFG_DONE;
7413 DEBUGFUNC("e1000_get_phy_cfg_done");
7415 switch (hw->mac_type) {
7419 case e1000_80003es2lan:
7420 /* Separate *_CFG_DONE_* bit for each port */
7421 if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
7422 cfg_mask = E1000_EEPROM_CFG_DONE_PORT_1;
7427 if (E1000_READ_REG(hw, EEMNGCTL) & cfg_mask)
7435 DEBUGOUT("MNG configuration cycle has not completed.\n");
7436 return -E1000_ERR_RESET;
7441 return E1000_SUCCESS;
7444 /***************************************************************************
7446 * Using the combination of SMBI and SWESMBI semaphore bits when resetting
7447 * adapter or Eeprom access.
7449 * hw: Struct containing variables accessed by shared code
7451 * returns: - E1000_ERR_EEPROM if fail to access EEPROM.
7452 * E1000_SUCCESS at any other case.
7454 ***************************************************************************/
7456 e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw)
7461 DEBUGFUNC("e1000_get_hw_eeprom_semaphore");
7463 if(!hw->eeprom_semaphore_present)
7464 return E1000_SUCCESS;
7466 if (hw->mac_type == e1000_80003es2lan) {
7467 /* Get the SW semaphore. */
7468 if (e1000_get_software_semaphore(hw) != E1000_SUCCESS)
7469 return -E1000_ERR_EEPROM;
7472 /* Get the FW semaphore. */
7473 timeout = hw->eeprom.word_size + 1;
7475 swsm = E1000_READ_REG(hw, SWSM);
7476 swsm |= E1000_SWSM_SWESMBI;
7477 E1000_WRITE_REG(hw, SWSM, swsm);
7478 /* if we managed to set the bit we got the semaphore. */
7479 swsm = E1000_READ_REG(hw, SWSM);
7480 if(swsm & E1000_SWSM_SWESMBI)
7488 /* Release semaphores */
7489 e1000_put_hw_eeprom_semaphore(hw);
7490 DEBUGOUT("Driver can't access the Eeprom - SWESMBI bit is set.\n");
7491 return -E1000_ERR_EEPROM;
7494 return E1000_SUCCESS;
7497 /***************************************************************************
7498 * This function clears HW semaphore bits.
7500 * hw: Struct containing variables accessed by shared code
7504 ***************************************************************************/
7506 e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw)
7510 DEBUGFUNC("e1000_put_hw_eeprom_semaphore");
7512 if(!hw->eeprom_semaphore_present)
7515 swsm = E1000_READ_REG(hw, SWSM);
7516 if (hw->mac_type == e1000_80003es2lan) {
7517 /* Release both semaphores. */
7518 swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
7520 swsm &= ~(E1000_SWSM_SWESMBI);
7521 E1000_WRITE_REG(hw, SWSM, swsm);
7524 /***************************************************************************
7526 * Obtaining software semaphore bit (SMBI) before resetting PHY.
7528 * hw: Struct containing variables accessed by shared code
7530 * returns: - E1000_ERR_RESET if fail to obtain semaphore.
7531 * E1000_SUCCESS at any other case.
7533 ***************************************************************************/
7535 e1000_get_software_semaphore(struct e1000_hw *hw)
7537 int32_t timeout = hw->eeprom.word_size + 1;
7540 DEBUGFUNC("e1000_get_software_semaphore");
7542 if (hw->mac_type != e1000_80003es2lan)
7543 return E1000_SUCCESS;
7546 swsm = E1000_READ_REG(hw, SWSM);
7547 /* If SMBI bit cleared, it is now set and we hold the semaphore */
7548 if(!(swsm & E1000_SWSM_SMBI))
7555 DEBUGOUT("Driver can't access device - SMBI bit is set.\n");
7556 return -E1000_ERR_RESET;
7559 return E1000_SUCCESS;
7562 /***************************************************************************
7564 * Release semaphore bit (SMBI).
7566 * hw: Struct containing variables accessed by shared code
7568 ***************************************************************************/
7570 e1000_release_software_semaphore(struct e1000_hw *hw)
7574 DEBUGFUNC("e1000_release_software_semaphore");
7576 if (hw->mac_type != e1000_80003es2lan)
7579 swsm = E1000_READ_REG(hw, SWSM);
7580 /* Release the SW semaphores.*/
7581 swsm &= ~E1000_SWSM_SMBI;
7582 E1000_WRITE_REG(hw, SWSM, swsm);
7585 /******************************************************************************
7586 * Checks if PHY reset is blocked due to SOL/IDER session, for example.
7587 * Returning E1000_BLK_PHY_RESET isn't necessarily an error. But it's up to
7588 * the caller to figure out how to deal with it.
7590 * hw - Struct containing variables accessed by shared code
7592 * returns: - E1000_BLK_PHY_RESET
7595 *****************************************************************************/
7597 e1000_check_phy_reset_block(struct e1000_hw *hw)
7601 if (hw->mac_type > e1000_82547_rev_2)
7602 manc = E1000_READ_REG(hw, MANC);
7603 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
7604 E1000_BLK_PHY_RESET : E1000_SUCCESS;
7608 e1000_arc_subsystem_valid(struct e1000_hw *hw)
7612 /* On 8257x silicon, registers in the range of 0x8800 - 0x8FFC
7613 * may not be provided a DMA clock when no manageability features are
7614 * enabled. We do not want to perform any reads/writes to these registers
7615 * if this is the case. We read FWSM to determine the manageability mode.
7617 switch (hw->mac_type) {
7621 case e1000_80003es2lan:
7622 fwsm = E1000_READ_REG(hw, FWSM);
7623 if((fwsm & E1000_FWSM_MODE_MASK) != 0)