1 /*******************************************************************************
4 Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2 of the License, or (at your option)
11 This program is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 You should have received a copy of the GNU General Public License along with
17 this program; if not, write to the Free Software Foundation, Inc., 59
18 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 The full GNU General Public License is included in this distribution in the
24 Linux NICS <linux.nics@intel.com>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *******************************************************************************/
30 * Shared functions for accessing and configuring the MAC
35 static int32_t e1000_set_phy_type(struct e1000_hw *hw);
36 static void e1000_phy_init_script(struct e1000_hw *hw);
37 static int32_t e1000_setup_copper_link(struct e1000_hw *hw);
38 static int32_t e1000_setup_fiber_serdes_link(struct e1000_hw *hw);
39 static int32_t e1000_adjust_serdes_amplitude(struct e1000_hw *hw);
40 static int32_t e1000_phy_force_speed_duplex(struct e1000_hw *hw);
41 static int32_t e1000_config_mac_to_phy(struct e1000_hw *hw);
42 static void e1000_raise_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl);
43 static void e1000_lower_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl);
44 static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, uint32_t data,
46 static uint16_t e1000_shift_in_mdi_bits(struct e1000_hw *hw);
47 static int32_t e1000_phy_reset_dsp(struct e1000_hw *hw);
48 static int32_t e1000_write_eeprom_spi(struct e1000_hw *hw, uint16_t offset,
49 uint16_t words, uint16_t *data);
50 static int32_t e1000_write_eeprom_microwire(struct e1000_hw *hw,
51 uint16_t offset, uint16_t words,
53 static int32_t e1000_spi_eeprom_ready(struct e1000_hw *hw);
54 static void e1000_raise_ee_clk(struct e1000_hw *hw, uint32_t *eecd);
55 static void e1000_lower_ee_clk(struct e1000_hw *hw, uint32_t *eecd);
56 static void e1000_shift_out_ee_bits(struct e1000_hw *hw, uint16_t data,
58 static int32_t e1000_write_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr,
60 static int32_t e1000_read_phy_reg_ex(struct e1000_hw *hw,uint32_t reg_addr,
62 static uint16_t e1000_shift_in_ee_bits(struct e1000_hw *hw, uint16_t count);
63 static int32_t e1000_acquire_eeprom(struct e1000_hw *hw);
64 static void e1000_release_eeprom(struct e1000_hw *hw);
65 static void e1000_standby_eeprom(struct e1000_hw *hw);
66 static int32_t e1000_set_vco_speed(struct e1000_hw *hw);
67 static int32_t e1000_polarity_reversal_workaround(struct e1000_hw *hw);
68 static int32_t e1000_set_phy_mode(struct e1000_hw *hw);
69 static int32_t e1000_host_if_read_cookie(struct e1000_hw *hw, uint8_t *buffer);
70 static uint8_t e1000_calculate_mng_checksum(char *buffer, uint32_t length);
71 static uint8_t e1000_arc_subsystem_valid(struct e1000_hw *hw);
72 static int32_t e1000_check_downshift(struct e1000_hw *hw);
73 static int32_t e1000_check_polarity(struct e1000_hw *hw, uint16_t *polarity);
74 static void e1000_clear_hw_cntrs(struct e1000_hw *hw);
75 static void e1000_clear_vfta(struct e1000_hw *hw);
76 static int32_t e1000_commit_shadow_ram(struct e1000_hw *hw);
77 static int32_t e1000_config_dsp_after_link_change(struct e1000_hw *hw,
79 static int32_t e1000_config_fc_after_link_up(struct e1000_hw *hw);
80 static int32_t e1000_detect_gig_phy(struct e1000_hw *hw);
81 static int32_t e1000_get_auto_rd_done(struct e1000_hw *hw);
82 static int32_t e1000_get_cable_length(struct e1000_hw *hw,
84 uint16_t *max_length);
85 static int32_t e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw);
86 static int32_t e1000_get_phy_cfg_done(struct e1000_hw *hw);
87 static int32_t e1000_id_led_init(struct e1000_hw * hw);
88 static void e1000_init_rx_addrs(struct e1000_hw *hw);
89 static boolean_t e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw);
90 static int32_t e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd);
91 static void e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw);
92 static int32_t e1000_read_eeprom_eerd(struct e1000_hw *hw, uint16_t offset,
93 uint16_t words, uint16_t *data);
94 static int32_t e1000_set_d0_lplu_state(struct e1000_hw *hw, boolean_t active);
95 static int32_t e1000_set_d3_lplu_state(struct e1000_hw *hw, boolean_t active);
96 static int32_t e1000_wait_autoneg(struct e1000_hw *hw);
98 static void e1000_write_reg_io(struct e1000_hw *hw, uint32_t offset,
101 #define E1000_WRITE_REG_IO(a, reg, val) \
102 e1000_write_reg_io((a), E1000_##reg, val)
103 static int32_t e1000_configure_kmrn_for_10_100(struct e1000_hw *hw);
104 static int32_t e1000_configure_kmrn_for_1000(struct e1000_hw *hw);
106 /* IGP cable length table */
108 uint16_t e1000_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] =
109 { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
110 5, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 25, 25, 25,
111 25, 25, 25, 25, 30, 30, 30, 30, 40, 40, 40, 40, 40, 40, 40, 40,
112 40, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60,
113 60, 70, 70, 70, 70, 70, 70, 80, 80, 80, 80, 80, 80, 90, 90, 90,
114 90, 90, 90, 90, 90, 90, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
115 100, 100, 100, 100, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,
116 110, 110, 110, 110, 110, 110, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120};
119 uint16_t e1000_igp_2_cable_length_table[IGP02E1000_AGC_LENGTH_TABLE_SIZE] =
120 { 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21,
121 0, 0, 0, 3, 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41,
122 6, 10, 14, 18, 22, 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61,
123 21, 26, 31, 35, 40, 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82,
124 40, 45, 51, 56, 61, 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104,
125 60, 66, 72, 77, 82, 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121,
126 83, 89, 95, 100, 105, 109, 113, 116, 119, 122, 124,
127 104, 109, 114, 118, 121, 124};
130 /******************************************************************************
131 * Set the phy type member in the hw struct.
133 * hw - Struct containing variables accessed by shared code
134 *****************************************************************************/
136 e1000_set_phy_type(struct e1000_hw *hw)
138 DEBUGFUNC("e1000_set_phy_type");
140 if(hw->mac_type == e1000_undefined)
141 return -E1000_ERR_PHY_TYPE;
144 case M88E1000_E_PHY_ID:
145 case M88E1000_I_PHY_ID:
146 case M88E1011_I_PHY_ID:
147 case M88E1111_I_PHY_ID:
148 hw->phy_type = e1000_phy_m88;
150 case IGP01E1000_I_PHY_ID:
151 if(hw->mac_type == e1000_82541 ||
152 hw->mac_type == e1000_82541_rev_2 ||
153 hw->mac_type == e1000_82547 ||
154 hw->mac_type == e1000_82547_rev_2) {
155 hw->phy_type = e1000_phy_igp;
158 case GG82563_E_PHY_ID:
159 if (hw->mac_type == e1000_80003es2lan) {
160 hw->phy_type = e1000_phy_gg82563;
165 /* Should never have loaded on this device */
166 hw->phy_type = e1000_phy_undefined;
167 return -E1000_ERR_PHY_TYPE;
170 return E1000_SUCCESS;
173 /******************************************************************************
174 * IGP phy init script - initializes the GbE PHY
176 * hw - Struct containing variables accessed by shared code
177 *****************************************************************************/
179 e1000_phy_init_script(struct e1000_hw *hw)
182 uint16_t phy_saved_data;
184 DEBUGFUNC("e1000_phy_init_script");
186 if(hw->phy_init_script) {
189 /* Save off the current value of register 0x2F5B to be restored at
190 * the end of this routine. */
191 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
193 /* Disabled the PHY transmitter */
194 e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
198 e1000_write_phy_reg(hw,0x0000,0x0140);
202 switch(hw->mac_type) {
205 e1000_write_phy_reg(hw, 0x1F95, 0x0001);
207 e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
209 e1000_write_phy_reg(hw, 0x1F79, 0x0018);
211 e1000_write_phy_reg(hw, 0x1F30, 0x1600);
213 e1000_write_phy_reg(hw, 0x1F31, 0x0014);
215 e1000_write_phy_reg(hw, 0x1F32, 0x161C);
217 e1000_write_phy_reg(hw, 0x1F94, 0x0003);
219 e1000_write_phy_reg(hw, 0x1F96, 0x003F);
221 e1000_write_phy_reg(hw, 0x2010, 0x0008);
224 case e1000_82541_rev_2:
225 case e1000_82547_rev_2:
226 e1000_write_phy_reg(hw, 0x1F73, 0x0099);
232 e1000_write_phy_reg(hw, 0x0000, 0x3300);
236 /* Now enable the transmitter */
237 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
239 if(hw->mac_type == e1000_82547) {
240 uint16_t fused, fine, coarse;
242 /* Move to analog registers page */
243 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_SPARE_FUSE_STATUS, &fused);
245 if(!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
246 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_FUSE_STATUS, &fused);
248 fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
249 coarse = fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
251 if(coarse > IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
252 coarse -= IGP01E1000_ANALOG_FUSE_COARSE_10;
253 fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
254 } else if(coarse == IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
255 fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
257 fused = (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
258 (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
259 (coarse & IGP01E1000_ANALOG_FUSE_COARSE_MASK);
261 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_CONTROL, fused);
262 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_BYPASS,
263 IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
269 /******************************************************************************
270 * Set the mac type member in the hw struct.
272 * hw - Struct containing variables accessed by shared code
273 *****************************************************************************/
275 e1000_set_mac_type(struct e1000_hw *hw)
277 DEBUGFUNC("e1000_set_mac_type");
279 switch (hw->device_id) {
280 case E1000_DEV_ID_82542:
281 switch (hw->revision_id) {
282 case E1000_82542_2_0_REV_ID:
283 hw->mac_type = e1000_82542_rev2_0;
285 case E1000_82542_2_1_REV_ID:
286 hw->mac_type = e1000_82542_rev2_1;
289 /* Invalid 82542 revision ID */
290 return -E1000_ERR_MAC_TYPE;
293 case E1000_DEV_ID_82543GC_FIBER:
294 case E1000_DEV_ID_82543GC_COPPER:
295 hw->mac_type = e1000_82543;
297 case E1000_DEV_ID_82544EI_COPPER:
298 case E1000_DEV_ID_82544EI_FIBER:
299 case E1000_DEV_ID_82544GC_COPPER:
300 case E1000_DEV_ID_82544GC_LOM:
301 hw->mac_type = e1000_82544;
303 case E1000_DEV_ID_82540EM:
304 case E1000_DEV_ID_82540EM_LOM:
305 case E1000_DEV_ID_82540EP:
306 case E1000_DEV_ID_82540EP_LOM:
307 case E1000_DEV_ID_82540EP_LP:
308 hw->mac_type = e1000_82540;
310 case E1000_DEV_ID_82545EM_COPPER:
311 case E1000_DEV_ID_82545EM_FIBER:
312 hw->mac_type = e1000_82545;
314 case E1000_DEV_ID_82545GM_COPPER:
315 case E1000_DEV_ID_82545GM_FIBER:
316 case E1000_DEV_ID_82545GM_SERDES:
317 hw->mac_type = e1000_82545_rev_3;
319 case E1000_DEV_ID_82546EB_COPPER:
320 case E1000_DEV_ID_82546EB_FIBER:
321 case E1000_DEV_ID_82546EB_QUAD_COPPER:
322 hw->mac_type = e1000_82546;
324 case E1000_DEV_ID_82546GB_COPPER:
325 case E1000_DEV_ID_82546GB_FIBER:
326 case E1000_DEV_ID_82546GB_SERDES:
327 case E1000_DEV_ID_82546GB_PCIE:
328 case E1000_DEV_ID_82546GB_QUAD_COPPER:
329 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
330 hw->mac_type = e1000_82546_rev_3;
332 case E1000_DEV_ID_82541EI:
333 case E1000_DEV_ID_82541EI_MOBILE:
334 hw->mac_type = e1000_82541;
336 case E1000_DEV_ID_82541ER:
337 case E1000_DEV_ID_82541GI:
338 case E1000_DEV_ID_82541GI_LF:
339 case E1000_DEV_ID_82541GI_MOBILE:
340 hw->mac_type = e1000_82541_rev_2;
342 case E1000_DEV_ID_82547EI:
343 hw->mac_type = e1000_82547;
345 case E1000_DEV_ID_82547GI:
346 hw->mac_type = e1000_82547_rev_2;
348 case E1000_DEV_ID_82571EB_COPPER:
349 case E1000_DEV_ID_82571EB_FIBER:
350 case E1000_DEV_ID_82571EB_SERDES:
351 hw->mac_type = e1000_82571;
353 case E1000_DEV_ID_82572EI_COPPER:
354 case E1000_DEV_ID_82572EI_FIBER:
355 case E1000_DEV_ID_82572EI_SERDES:
356 hw->mac_type = e1000_82572;
358 case E1000_DEV_ID_82573E:
359 case E1000_DEV_ID_82573E_IAMT:
360 case E1000_DEV_ID_82573L:
361 hw->mac_type = e1000_82573;
363 case E1000_DEV_ID_80003ES2LAN_COPPER_DPT:
364 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
365 hw->mac_type = e1000_80003es2lan;
368 /* Should never have loaded on this device */
369 return -E1000_ERR_MAC_TYPE;
372 switch(hw->mac_type) {
373 case e1000_80003es2lan:
374 hw->swfw_sync_present = TRUE;
379 hw->eeprom_semaphore_present = TRUE;
383 case e1000_82541_rev_2:
384 case e1000_82547_rev_2:
385 hw->asf_firmware_present = TRUE;
391 return E1000_SUCCESS;
394 /*****************************************************************************
395 * Set media type and TBI compatibility.
397 * hw - Struct containing variables accessed by shared code
398 * **************************************************************************/
400 e1000_set_media_type(struct e1000_hw *hw)
404 DEBUGFUNC("e1000_set_media_type");
406 if(hw->mac_type != e1000_82543) {
407 /* tbi_compatibility is only valid on 82543 */
408 hw->tbi_compatibility_en = FALSE;
411 switch (hw->device_id) {
412 case E1000_DEV_ID_82545GM_SERDES:
413 case E1000_DEV_ID_82546GB_SERDES:
414 case E1000_DEV_ID_82571EB_SERDES:
415 case E1000_DEV_ID_82572EI_SERDES:
416 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
417 hw->media_type = e1000_media_type_internal_serdes;
420 switch (hw->mac_type) {
421 case e1000_82542_rev2_0:
422 case e1000_82542_rev2_1:
423 hw->media_type = e1000_media_type_fiber;
426 /* The STATUS_TBIMODE bit is reserved or reused for the this
429 hw->media_type = e1000_media_type_copper;
432 status = E1000_READ_REG(hw, STATUS);
433 if (status & E1000_STATUS_TBIMODE) {
434 hw->media_type = e1000_media_type_fiber;
435 /* tbi_compatibility not valid on fiber */
436 hw->tbi_compatibility_en = FALSE;
438 hw->media_type = e1000_media_type_copper;
445 /******************************************************************************
446 * Reset the transmit and receive units; mask and clear all interrupts.
448 * hw - Struct containing variables accessed by shared code
449 *****************************************************************************/
451 e1000_reset_hw(struct e1000_hw *hw)
459 uint32_t extcnf_ctrl;
462 DEBUGFUNC("e1000_reset_hw");
464 /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
465 if(hw->mac_type == e1000_82542_rev2_0) {
466 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
467 e1000_pci_clear_mwi(hw);
470 if(hw->bus_type == e1000_bus_type_pci_express) {
471 /* Prevent the PCI-E bus from sticking if there is no TLP connection
472 * on the last TLP read/write transaction when MAC is reset.
474 if(e1000_disable_pciex_master(hw) != E1000_SUCCESS) {
475 DEBUGOUT("PCI-E Master disable polling has failed.\n");
479 /* Clear interrupt mask to stop board from generating interrupts */
480 DEBUGOUT("Masking off all interrupts\n");
481 E1000_WRITE_REG(hw, IMC, 0xffffffff);
483 /* Disable the Transmit and Receive units. Then delay to allow
484 * any pending transactions to complete before we hit the MAC with
487 E1000_WRITE_REG(hw, RCTL, 0);
488 E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP);
489 E1000_WRITE_FLUSH(hw);
491 /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
492 hw->tbi_compatibility_on = FALSE;
494 /* Delay to allow any outstanding PCI transactions to complete before
495 * resetting the device
499 ctrl = E1000_READ_REG(hw, CTRL);
501 /* Must reset the PHY before resetting the MAC */
502 if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
503 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_PHY_RST));
507 /* Must acquire the MDIO ownership before MAC reset.
508 * Ownership defaults to firmware after a reset. */
509 if(hw->mac_type == e1000_82573) {
512 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
513 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
516 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
517 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
519 if(extcnf_ctrl & E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP)
522 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
529 /* Issue a global reset to the MAC. This will reset the chip's
530 * transmit, receive, DMA, and link units. It will not effect
531 * the current PCI configuration. The global reset bit is self-
532 * clearing, and should clear within a microsecond.
534 DEBUGOUT("Issuing a global reset to MAC\n");
536 switch(hw->mac_type) {
542 case e1000_82541_rev_2:
543 /* These controllers can't ack the 64-bit write when issuing the
544 * reset, so use IO-mapping as a workaround to issue the reset */
545 E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
547 case e1000_82545_rev_3:
548 case e1000_82546_rev_3:
549 /* Reset is performed on a shadow of the control register */
550 E1000_WRITE_REG(hw, CTRL_DUP, (ctrl | E1000_CTRL_RST));
553 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
557 /* After MAC reset, force reload of EEPROM to restore power-on settings to
558 * device. Later controllers reload the EEPROM automatically, so just wait
559 * for reload to complete.
561 switch(hw->mac_type) {
562 case e1000_82542_rev2_0:
563 case e1000_82542_rev2_1:
566 /* Wait for reset to complete */
568 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
569 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
570 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
571 E1000_WRITE_FLUSH(hw);
572 /* Wait for EEPROM reload */
576 case e1000_82541_rev_2:
578 case e1000_82547_rev_2:
579 /* Wait for EEPROM reload */
583 if (e1000_is_onboard_nvm_eeprom(hw) == FALSE) {
585 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
586 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
587 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
588 E1000_WRITE_FLUSH(hw);
593 case e1000_80003es2lan:
594 ret_val = e1000_get_auto_rd_done(hw);
596 /* We don't want to continue accessing MAC registers. */
600 /* Wait for EEPROM reload (it happens automatically) */
605 /* Disable HW ARPs on ASF enabled adapters */
606 if(hw->mac_type >= e1000_82540 && hw->mac_type <= e1000_82547_rev_2) {
607 manc = E1000_READ_REG(hw, MANC);
608 manc &= ~(E1000_MANC_ARP_EN);
609 E1000_WRITE_REG(hw, MANC, manc);
612 if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
613 e1000_phy_init_script(hw);
615 /* Configure activity LED after PHY reset */
616 led_ctrl = E1000_READ_REG(hw, LEDCTL);
617 led_ctrl &= IGP_ACTIVITY_LED_MASK;
618 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
619 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
622 /* Clear interrupt mask to stop board from generating interrupts */
623 DEBUGOUT("Masking off all interrupts\n");
624 E1000_WRITE_REG(hw, IMC, 0xffffffff);
626 /* Clear any pending interrupt events. */
627 icr = E1000_READ_REG(hw, ICR);
629 /* If MWI was previously enabled, reenable it. */
630 if(hw->mac_type == e1000_82542_rev2_0) {
631 if(hw->pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
632 e1000_pci_set_mwi(hw);
635 return E1000_SUCCESS;
638 /******************************************************************************
639 * Performs basic configuration of the adapter.
641 * hw - Struct containing variables accessed by shared code
643 * Assumes that the controller has previously been reset and is in a
644 * post-reset uninitialized state. Initializes the receive address registers,
645 * multicast table, and VLAN filter table. Calls routines to setup link
646 * configuration and flow control settings. Clears all on-chip counters. Leaves
647 * the transmit and receive units disabled and uninitialized.
648 *****************************************************************************/
650 e1000_init_hw(struct e1000_hw *hw)
655 uint16_t pcix_cmd_word;
656 uint16_t pcix_stat_hi_word;
663 DEBUGFUNC("e1000_init_hw");
665 /* Initialize Identification LED */
666 ret_val = e1000_id_led_init(hw);
668 DEBUGOUT("Error Initializing Identification LED\n");
672 /* Set the media type and TBI compatibility */
673 e1000_set_media_type(hw);
675 /* Disabling VLAN filtering. */
676 DEBUGOUT("Initializing the IEEE VLAN\n");
677 if (hw->mac_type < e1000_82545_rev_3)
678 E1000_WRITE_REG(hw, VET, 0);
679 e1000_clear_vfta(hw);
681 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
682 if(hw->mac_type == e1000_82542_rev2_0) {
683 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
684 e1000_pci_clear_mwi(hw);
685 E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST);
686 E1000_WRITE_FLUSH(hw);
690 /* Setup the receive address. This involves initializing all of the Receive
691 * Address Registers (RARs 0 - 15).
693 e1000_init_rx_addrs(hw);
695 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
696 if(hw->mac_type == e1000_82542_rev2_0) {
697 E1000_WRITE_REG(hw, RCTL, 0);
698 E1000_WRITE_FLUSH(hw);
700 if(hw->pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
701 e1000_pci_set_mwi(hw);
704 /* Zero out the Multicast HASH table */
705 DEBUGOUT("Zeroing the MTA\n");
706 mta_size = E1000_MC_TBL_SIZE;
707 for(i = 0; i < mta_size; i++)
708 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
710 /* Set the PCI priority bit correctly in the CTRL register. This
711 * determines if the adapter gives priority to receives, or if it
712 * gives equal priority to transmits and receives. Valid only on
713 * 82542 and 82543 silicon.
715 if(hw->dma_fairness && hw->mac_type <= e1000_82543) {
716 ctrl = E1000_READ_REG(hw, CTRL);
717 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PRIOR);
720 switch(hw->mac_type) {
721 case e1000_82545_rev_3:
722 case e1000_82546_rev_3:
725 /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
726 if(hw->bus_type == e1000_bus_type_pcix) {
727 e1000_read_pci_cfg(hw, PCIX_COMMAND_REGISTER, &pcix_cmd_word);
728 e1000_read_pci_cfg(hw, PCIX_STATUS_REGISTER_HI,
730 cmd_mmrbc = (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >>
731 PCIX_COMMAND_MMRBC_SHIFT;
732 stat_mmrbc = (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
733 PCIX_STATUS_HI_MMRBC_SHIFT;
734 if(stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
735 stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
736 if(cmd_mmrbc > stat_mmrbc) {
737 pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK;
738 pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
739 e1000_write_pci_cfg(hw, PCIX_COMMAND_REGISTER,
746 /* Call a subroutine to configure the link and setup flow control. */
747 ret_val = e1000_setup_link(hw);
749 /* Set the transmit descriptor write-back policy */
750 if(hw->mac_type > e1000_82544) {
751 ctrl = E1000_READ_REG(hw, TXDCTL);
752 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
753 switch (hw->mac_type) {
759 case e1000_80003es2lan:
760 ctrl |= E1000_TXDCTL_COUNT_DESC;
763 E1000_WRITE_REG(hw, TXDCTL, ctrl);
766 if (hw->mac_type == e1000_82573) {
767 e1000_enable_tx_pkt_filtering(hw);
770 switch (hw->mac_type) {
773 case e1000_80003es2lan:
774 /* Enable retransmit on late collisions */
775 reg_data = E1000_READ_REG(hw, TCTL);
776 reg_data |= E1000_TCTL_RTLC;
777 E1000_WRITE_REG(hw, TCTL, reg_data);
779 /* Configure Gigabit Carry Extend Padding */
780 reg_data = E1000_READ_REG(hw, TCTL_EXT);
781 reg_data &= ~E1000_TCTL_EXT_GCEX_MASK;
782 reg_data |= DEFAULT_80003ES2LAN_TCTL_EXT_GCEX;
783 E1000_WRITE_REG(hw, TCTL_EXT, reg_data);
785 /* Configure Transmit Inter-Packet Gap */
786 reg_data = E1000_READ_REG(hw, TIPG);
787 reg_data &= ~E1000_TIPG_IPGT_MASK;
788 reg_data |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
789 E1000_WRITE_REG(hw, TIPG, reg_data);
791 reg_data = E1000_READ_REG_ARRAY(hw, FFLT, 0x0001);
792 reg_data &= ~0x00100000;
793 E1000_WRITE_REG_ARRAY(hw, FFLT, 0x0001, reg_data);
797 ctrl = E1000_READ_REG(hw, TXDCTL1);
798 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
799 if(hw->mac_type >= e1000_82571)
800 ctrl |= E1000_TXDCTL_COUNT_DESC;
801 E1000_WRITE_REG(hw, TXDCTL1, ctrl);
807 if (hw->mac_type == e1000_82573) {
808 uint32_t gcr = E1000_READ_REG(hw, GCR);
809 gcr |= E1000_GCR_L1_ACT_WITHOUT_L0S_RX;
810 E1000_WRITE_REG(hw, GCR, gcr);
813 /* Clear all of the statistics registers (clear on read). It is
814 * important that we do this after we have tried to establish link
815 * because the symbol error count will increment wildly if there
818 e1000_clear_hw_cntrs(hw);
820 if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER ||
821 hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) {
822 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
823 /* Relaxed ordering must be disabled to avoid a parity
824 * error crash in a PCI slot. */
825 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
826 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
832 /******************************************************************************
833 * Adjust SERDES output amplitude based on EEPROM setting.
835 * hw - Struct containing variables accessed by shared code.
836 *****************************************************************************/
838 e1000_adjust_serdes_amplitude(struct e1000_hw *hw)
840 uint16_t eeprom_data;
843 DEBUGFUNC("e1000_adjust_serdes_amplitude");
845 if(hw->media_type != e1000_media_type_internal_serdes)
846 return E1000_SUCCESS;
848 switch(hw->mac_type) {
849 case e1000_82545_rev_3:
850 case e1000_82546_rev_3:
853 return E1000_SUCCESS;
856 ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1, &eeprom_data);
861 if(eeprom_data != EEPROM_RESERVED_WORD) {
862 /* Adjust SERDES output amplitude only. */
863 eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK;
864 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data);
869 return E1000_SUCCESS;
872 /******************************************************************************
873 * Configures flow control and link settings.
875 * hw - Struct containing variables accessed by shared code
877 * Determines which flow control settings to use. Calls the apropriate media-
878 * specific link configuration function. Configures the flow control settings.
879 * Assuming the adapter has a valid link partner, a valid link should be
880 * established. Assumes the hardware has previously been reset and the
881 * transmitter and receiver are not enabled.
882 *****************************************************************************/
884 e1000_setup_link(struct e1000_hw *hw)
888 uint16_t eeprom_data;
890 DEBUGFUNC("e1000_setup_link");
892 /* In the case of the phy reset being blocked, we already have a link.
893 * We do not have to set it up again. */
894 if (e1000_check_phy_reset_block(hw))
895 return E1000_SUCCESS;
897 /* Read and store word 0x0F of the EEPROM. This word contains bits
898 * that determine the hardware's default PAUSE (flow control) mode,
899 * a bit that determines whether the HW defaults to enabling or
900 * disabling auto-negotiation, and the direction of the
901 * SW defined pins. If there is no SW over-ride of the flow
902 * control setting, then the variable hw->fc will
903 * be initialized based on a value in the EEPROM.
905 if (hw->fc == e1000_fc_default) {
906 switch (hw->mac_type) {
908 hw->fc = e1000_fc_full;
911 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
914 DEBUGOUT("EEPROM Read Error\n");
915 return -E1000_ERR_EEPROM;
917 if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
918 hw->fc = e1000_fc_none;
919 else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
920 EEPROM_WORD0F_ASM_DIR)
921 hw->fc = e1000_fc_tx_pause;
923 hw->fc = e1000_fc_full;
928 /* We want to save off the original Flow Control configuration just
929 * in case we get disconnected and then reconnected into a different
930 * hub or switch with different Flow Control capabilities.
932 if(hw->mac_type == e1000_82542_rev2_0)
933 hw->fc &= (~e1000_fc_tx_pause);
935 if((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
936 hw->fc &= (~e1000_fc_rx_pause);
938 hw->original_fc = hw->fc;
940 DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc);
942 /* Take the 4 bits from EEPROM word 0x0F that determine the initial
943 * polarity value for the SW controlled pins, and setup the
944 * Extended Device Control reg with that info.
945 * This is needed because one of the SW controlled pins is used for
946 * signal detection. So this should be done before e1000_setup_pcs_link()
947 * or e1000_phy_setup() is called.
949 if (hw->mac_type == e1000_82543) {
950 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
953 DEBUGOUT("EEPROM Read Error\n");
954 return -E1000_ERR_EEPROM;
956 ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
958 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
961 /* Call the necessary subroutine to configure the link. */
962 ret_val = (hw->media_type == e1000_media_type_copper) ?
963 e1000_setup_copper_link(hw) :
964 e1000_setup_fiber_serdes_link(hw);
966 /* Initialize the flow control address, type, and PAUSE timer
967 * registers to their default values. This is done even if flow
968 * control is disabled, because it does not hurt anything to
969 * initialize these registers.
971 DEBUGOUT("Initializing the Flow Control address, type and timer regs\n");
973 E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
974 E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
975 E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
977 E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
979 /* Set the flow control receive threshold registers. Normally,
980 * these registers will be set to a default threshold that may be
981 * adjusted later by the driver's runtime code. However, if the
982 * ability to transmit pause frames in not enabled, then these
983 * registers will be set to 0.
985 if(!(hw->fc & e1000_fc_tx_pause)) {
986 E1000_WRITE_REG(hw, FCRTL, 0);
987 E1000_WRITE_REG(hw, FCRTH, 0);
989 /* We need to set up the Receive Threshold high and low water marks
990 * as well as (optionally) enabling the transmission of XON frames.
992 if(hw->fc_send_xon) {
993 E1000_WRITE_REG(hw, FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE));
994 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
996 E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water);
997 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
1003 /******************************************************************************
1004 * Sets up link for a fiber based or serdes based adapter
1006 * hw - Struct containing variables accessed by shared code
1008 * Manipulates Physical Coding Sublayer functions in order to configure
1009 * link. Assumes the hardware has been previously reset and the transmitter
1010 * and receiver are not enabled.
1011 *****************************************************************************/
1013 e1000_setup_fiber_serdes_link(struct e1000_hw *hw)
1019 uint32_t signal = 0;
1022 DEBUGFUNC("e1000_setup_fiber_serdes_link");
1024 /* On 82571 and 82572 Fiber connections, SerDes loopback mode persists
1025 * until explicitly turned off or a power cycle is performed. A read to
1026 * the register does not indicate its status. Therefore, we ensure
1027 * loopback mode is disabled during initialization.
1029 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572)
1030 E1000_WRITE_REG(hw, SCTL, E1000_DISABLE_SERDES_LOOPBACK);
1032 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
1033 * set when the optics detect a signal. On older adapters, it will be
1034 * cleared when there is a signal. This applies to fiber media only.
1035 * If we're on serdes media, adjust the output amplitude to value set in
1038 ctrl = E1000_READ_REG(hw, CTRL);
1039 if(hw->media_type == e1000_media_type_fiber)
1040 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
1042 ret_val = e1000_adjust_serdes_amplitude(hw);
1046 /* Take the link out of reset */
1047 ctrl &= ~(E1000_CTRL_LRST);
1049 /* Adjust VCO speed to improve BER performance */
1050 ret_val = e1000_set_vco_speed(hw);
1054 e1000_config_collision_dist(hw);
1056 /* Check for a software override of the flow control settings, and setup
1057 * the device accordingly. If auto-negotiation is enabled, then software
1058 * will have to set the "PAUSE" bits to the correct value in the Tranmsit
1059 * Config Word Register (TXCW) and re-start auto-negotiation. However, if
1060 * auto-negotiation is disabled, then software will have to manually
1061 * configure the two flow control enable bits in the CTRL register.
1063 * The possible values of the "fc" parameter are:
1064 * 0: Flow control is completely disabled
1065 * 1: Rx flow control is enabled (we can receive pause frames, but
1066 * not send pause frames).
1067 * 2: Tx flow control is enabled (we can send pause frames but we do
1068 * not support receiving pause frames).
1069 * 3: Both Rx and TX flow control (symmetric) are enabled.
1073 /* Flow control is completely disabled by a software over-ride. */
1074 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
1076 case e1000_fc_rx_pause:
1077 /* RX Flow control is enabled and TX Flow control is disabled by a
1078 * software over-ride. Since there really isn't a way to advertise
1079 * that we are capable of RX Pause ONLY, we will advertise that we
1080 * support both symmetric and asymmetric RX PAUSE. Later, we will
1081 * disable the adapter's ability to send PAUSE frames.
1083 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1085 case e1000_fc_tx_pause:
1086 /* TX Flow control is enabled, and RX Flow control is disabled, by a
1087 * software over-ride.
1089 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
1092 /* Flow control (both RX and TX) is enabled by a software over-ride. */
1093 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1096 DEBUGOUT("Flow control param set incorrectly\n");
1097 return -E1000_ERR_CONFIG;
1101 /* Since auto-negotiation is enabled, take the link out of reset (the link
1102 * will be in reset, because we previously reset the chip). This will
1103 * restart auto-negotiation. If auto-neogtiation is successful then the
1104 * link-up status bit will be set and the flow control enable bits (RFCE
1105 * and TFCE) will be set according to their negotiated value.
1107 DEBUGOUT("Auto-negotiation enabled\n");
1109 E1000_WRITE_REG(hw, TXCW, txcw);
1110 E1000_WRITE_REG(hw, CTRL, ctrl);
1111 E1000_WRITE_FLUSH(hw);
1116 /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
1117 * indication in the Device Status Register. Time-out if a link isn't
1118 * seen in 500 milliseconds seconds (Auto-negotiation should complete in
1119 * less than 500 milliseconds even if the other end is doing it in SW).
1120 * For internal serdes, we just assume a signal is present, then poll.
1122 if(hw->media_type == e1000_media_type_internal_serdes ||
1123 (E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) {
1124 DEBUGOUT("Looking for Link\n");
1125 for(i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
1127 status = E1000_READ_REG(hw, STATUS);
1128 if(status & E1000_STATUS_LU) break;
1130 if(i == (LINK_UP_TIMEOUT / 10)) {
1131 DEBUGOUT("Never got a valid link from auto-neg!!!\n");
1132 hw->autoneg_failed = 1;
1133 /* AutoNeg failed to achieve a link, so we'll call
1134 * e1000_check_for_link. This routine will force the link up if
1135 * we detect a signal. This will allow us to communicate with
1136 * non-autonegotiating link partners.
1138 ret_val = e1000_check_for_link(hw);
1140 DEBUGOUT("Error while checking for link\n");
1143 hw->autoneg_failed = 0;
1145 hw->autoneg_failed = 0;
1146 DEBUGOUT("Valid Link Found\n");
1149 DEBUGOUT("No Signal Detected\n");
1151 return E1000_SUCCESS;
1154 /******************************************************************************
1155 * Make sure we have a valid PHY and change PHY mode before link setup.
1157 * hw - Struct containing variables accessed by shared code
1158 ******************************************************************************/
1160 e1000_copper_link_preconfig(struct e1000_hw *hw)
1166 DEBUGFUNC("e1000_copper_link_preconfig");
1168 ctrl = E1000_READ_REG(hw, CTRL);
1169 /* With 82543, we need to force speed and duplex on the MAC equal to what
1170 * the PHY speed and duplex configuration is. In addition, we need to
1171 * perform a hardware reset on the PHY to take it out of reset.
1173 if(hw->mac_type > e1000_82543) {
1174 ctrl |= E1000_CTRL_SLU;
1175 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1176 E1000_WRITE_REG(hw, CTRL, ctrl);
1178 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
1179 E1000_WRITE_REG(hw, CTRL, ctrl);
1180 ret_val = e1000_phy_hw_reset(hw);
1185 /* Make sure we have a valid PHY */
1186 ret_val = e1000_detect_gig_phy(hw);
1188 DEBUGOUT("Error, did not detect valid phy.\n");
1191 DEBUGOUT1("Phy ID = %x \n", hw->phy_id);
1193 /* Set PHY to class A mode (if necessary) */
1194 ret_val = e1000_set_phy_mode(hw);
1198 if((hw->mac_type == e1000_82545_rev_3) ||
1199 (hw->mac_type == e1000_82546_rev_3)) {
1200 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1201 phy_data |= 0x00000008;
1202 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1205 if(hw->mac_type <= e1000_82543 ||
1206 hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
1207 hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2)
1208 hw->phy_reset_disable = FALSE;
1210 return E1000_SUCCESS;
1214 /********************************************************************
1215 * Copper link setup for e1000_phy_igp series.
1217 * hw - Struct containing variables accessed by shared code
1218 *********************************************************************/
1220 e1000_copper_link_igp_setup(struct e1000_hw *hw)
1226 DEBUGFUNC("e1000_copper_link_igp_setup");
1228 if (hw->phy_reset_disable)
1229 return E1000_SUCCESS;
1231 ret_val = e1000_phy_reset(hw);
1233 DEBUGOUT("Error Resetting the PHY\n");
1237 /* Wait 10ms for MAC to configure PHY from eeprom settings */
1240 /* Configure activity LED after PHY reset */
1241 led_ctrl = E1000_READ_REG(hw, LEDCTL);
1242 led_ctrl &= IGP_ACTIVITY_LED_MASK;
1243 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
1244 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
1246 /* disable lplu d3 during driver init */
1247 ret_val = e1000_set_d3_lplu_state(hw, FALSE);
1249 DEBUGOUT("Error Disabling LPLU D3\n");
1253 /* disable lplu d0 during driver init */
1254 ret_val = e1000_set_d0_lplu_state(hw, FALSE);
1256 DEBUGOUT("Error Disabling LPLU D0\n");
1259 /* Configure mdi-mdix settings */
1260 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1264 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
1265 hw->dsp_config_state = e1000_dsp_config_disabled;
1266 /* Force MDI for earlier revs of the IGP PHY */
1267 phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX | IGP01E1000_PSCR_FORCE_MDI_MDIX);
1271 hw->dsp_config_state = e1000_dsp_config_enabled;
1272 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1276 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1279 phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
1283 phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
1287 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1291 /* set auto-master slave resolution settings */
1293 e1000_ms_type phy_ms_setting = hw->master_slave;
1295 if(hw->ffe_config_state == e1000_ffe_config_active)
1296 hw->ffe_config_state = e1000_ffe_config_enabled;
1298 if(hw->dsp_config_state == e1000_dsp_config_activated)
1299 hw->dsp_config_state = e1000_dsp_config_enabled;
1301 /* when autonegotiation advertisment is only 1000Mbps then we
1302 * should disable SmartSpeed and enable Auto MasterSlave
1303 * resolution as hardware default. */
1304 if(hw->autoneg_advertised == ADVERTISE_1000_FULL) {
1305 /* Disable SmartSpeed */
1306 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
1309 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1310 ret_val = e1000_write_phy_reg(hw,
1311 IGP01E1000_PHY_PORT_CONFIG,
1315 /* Set auto Master/Slave resolution process */
1316 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1319 phy_data &= ~CR_1000T_MS_ENABLE;
1320 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1325 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1329 /* load defaults for future use */
1330 hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
1331 ((phy_data & CR_1000T_MS_VALUE) ?
1332 e1000_ms_force_master :
1333 e1000_ms_force_slave) :
1336 switch (phy_ms_setting) {
1337 case e1000_ms_force_master:
1338 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
1340 case e1000_ms_force_slave:
1341 phy_data |= CR_1000T_MS_ENABLE;
1342 phy_data &= ~(CR_1000T_MS_VALUE);
1345 phy_data &= ~CR_1000T_MS_ENABLE;
1349 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1354 return E1000_SUCCESS;
1357 /********************************************************************
1358 * Copper link setup for e1000_phy_gg82563 series.
1360 * hw - Struct containing variables accessed by shared code
1361 *********************************************************************/
1363 e1000_copper_link_ggp_setup(struct e1000_hw *hw)
1369 DEBUGFUNC("e1000_copper_link_ggp_setup");
1371 if(!hw->phy_reset_disable) {
1373 /* Enable CRS on TX for half-duplex operation. */
1374 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL,
1379 phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
1380 /* Use 25MHz for both link down and 1000BASE-T for Tx clock */
1381 phy_data |= GG82563_MSCR_TX_CLK_1000MBPS_25MHZ;
1383 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL,
1389 * MDI/MDI-X = 0 (default)
1390 * 0 - Auto for all speeds
1393 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1395 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_SPEC_CTRL, &phy_data);
1399 phy_data &= ~GG82563_PSCR_CROSSOVER_MODE_MASK;
1403 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDI;
1406 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDIX;
1410 phy_data |= GG82563_PSCR_CROSSOVER_MODE_AUTO;
1415 * disable_polarity_correction = 0 (default)
1416 * Automatic Correction for Reversed Cable Polarity
1420 phy_data &= ~GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
1421 if(hw->disable_polarity_correction == 1)
1422 phy_data |= GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
1423 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_SPEC_CTRL, phy_data);
1428 /* SW Reset the PHY so all changes take effect */
1429 ret_val = e1000_phy_reset(hw);
1431 DEBUGOUT("Error Resetting the PHY\n");
1434 } /* phy_reset_disable */
1436 if (hw->mac_type == e1000_80003es2lan) {
1437 /* Bypass RX and TX FIFO's */
1438 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_FIFO_CTRL,
1439 E1000_KUMCTRLSTA_FIFO_CTRL_RX_BYPASS |
1440 E1000_KUMCTRLSTA_FIFO_CTRL_TX_BYPASS);
1444 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_SPEC_CTRL_2, &phy_data);
1448 phy_data &= ~GG82563_PSCR2_REVERSE_AUTO_NEG;
1449 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_SPEC_CTRL_2, phy_data);
1454 reg_data = E1000_READ_REG(hw, CTRL_EXT);
1455 reg_data &= ~(E1000_CTRL_EXT_LINK_MODE_MASK);
1456 E1000_WRITE_REG(hw, CTRL_EXT, reg_data);
1458 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_PWR_MGMT_CTRL,
1463 /* Do not init these registers when the HW is in IAMT mode, since the
1464 * firmware will have already initialized them. We only initialize
1465 * them if the HW is not in IAMT mode.
1467 if (e1000_check_mng_mode(hw) == FALSE) {
1468 /* Enable Electrical Idle on the PHY */
1469 phy_data |= GG82563_PMCR_ENABLE_ELECTRICAL_IDLE;
1470 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_PWR_MGMT_CTRL,
1475 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
1480 /* Enable Pass False Carrier on the PHY */
1481 phy_data |= GG82563_KMCR_PASS_FALSE_CARRIER;
1483 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
1489 /* Workaround: Disable padding in Kumeran interface in the MAC
1490 * and in the PHY to avoid CRC errors.
1492 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_INBAND_CTRL,
1496 phy_data |= GG82563_ICR_DIS_PADDING;
1497 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_INBAND_CTRL,
1503 return E1000_SUCCESS;
1506 /********************************************************************
1507 * Copper link setup for e1000_phy_m88 series.
1509 * hw - Struct containing variables accessed by shared code
1510 *********************************************************************/
1512 e1000_copper_link_mgp_setup(struct e1000_hw *hw)
1517 DEBUGFUNC("e1000_copper_link_mgp_setup");
1519 if(hw->phy_reset_disable)
1520 return E1000_SUCCESS;
1522 /* Enable CRS on TX. This must be set for half-duplex operation. */
1523 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1527 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1530 * MDI/MDI-X = 0 (default)
1531 * 0 - Auto for all speeds
1534 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1536 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1540 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
1543 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
1546 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
1550 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
1555 * disable_polarity_correction = 0 (default)
1556 * Automatic Correction for Reversed Cable Polarity
1560 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
1561 if(hw->disable_polarity_correction == 1)
1562 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
1563 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1567 /* Force TX_CLK in the Extended PHY Specific Control Register
1570 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1574 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1576 if (hw->phy_revision < M88E1011_I_REV_4) {
1577 /* Configure Master and Slave downshift values */
1578 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
1579 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
1580 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
1581 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
1582 ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1587 /* SW Reset the PHY so all changes take effect */
1588 ret_val = e1000_phy_reset(hw);
1590 DEBUGOUT("Error Resetting the PHY\n");
1594 return E1000_SUCCESS;
1597 /********************************************************************
1598 * Setup auto-negotiation and flow control advertisements,
1599 * and then perform auto-negotiation.
1601 * hw - Struct containing variables accessed by shared code
1602 *********************************************************************/
1604 e1000_copper_link_autoneg(struct e1000_hw *hw)
1609 DEBUGFUNC("e1000_copper_link_autoneg");
1611 /* Perform some bounds checking on the hw->autoneg_advertised
1612 * parameter. If this variable is zero, then set it to the default.
1614 hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
1616 /* If autoneg_advertised is zero, we assume it was not defaulted
1617 * by the calling code so we set to advertise full capability.
1619 if(hw->autoneg_advertised == 0)
1620 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
1622 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
1623 ret_val = e1000_phy_setup_autoneg(hw);
1625 DEBUGOUT("Error Setting up Auto-Negotiation\n");
1628 DEBUGOUT("Restarting Auto-Neg\n");
1630 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
1631 * the Auto Neg Restart bit in the PHY control register.
1633 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
1637 phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
1638 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
1642 /* Does the user want to wait for Auto-Neg to complete here, or
1643 * check at a later time (for example, callback routine).
1645 if(hw->wait_autoneg_complete) {
1646 ret_val = e1000_wait_autoneg(hw);
1648 DEBUGOUT("Error while waiting for autoneg to complete\n");
1653 hw->get_link_status = TRUE;
1655 return E1000_SUCCESS;
1659 /******************************************************************************
1660 * Config the MAC and the PHY after link is up.
1661 * 1) Set up the MAC to the current PHY speed/duplex
1662 * if we are on 82543. If we
1663 * are on newer silicon, we only need to configure
1664 * collision distance in the Transmit Control Register.
1665 * 2) Set up flow control on the MAC to that established with
1667 * 3) Config DSP to improve Gigabit link quality for some PHY revisions.
1669 * hw - Struct containing variables accessed by shared code
1670 ******************************************************************************/
1672 e1000_copper_link_postconfig(struct e1000_hw *hw)
1675 DEBUGFUNC("e1000_copper_link_postconfig");
1677 if(hw->mac_type >= e1000_82544) {
1678 e1000_config_collision_dist(hw);
1680 ret_val = e1000_config_mac_to_phy(hw);
1682 DEBUGOUT("Error configuring MAC to PHY settings\n");
1686 ret_val = e1000_config_fc_after_link_up(hw);
1688 DEBUGOUT("Error Configuring Flow Control\n");
1692 /* Config DSP to improve Giga link quality */
1693 if(hw->phy_type == e1000_phy_igp) {
1694 ret_val = e1000_config_dsp_after_link_change(hw, TRUE);
1696 DEBUGOUT("Error Configuring DSP after link up\n");
1701 return E1000_SUCCESS;
1704 /******************************************************************************
1705 * Detects which PHY is present and setup the speed and duplex
1707 * hw - Struct containing variables accessed by shared code
1708 ******************************************************************************/
1710 e1000_setup_copper_link(struct e1000_hw *hw)
1717 DEBUGFUNC("e1000_setup_copper_link");
1719 /* Check if it is a valid PHY and set PHY mode if necessary. */
1720 ret_val = e1000_copper_link_preconfig(hw);
1724 switch (hw->mac_type) {
1725 case e1000_80003es2lan:
1726 ret_val = e1000_read_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_INB_CTRL,
1730 reg_data |= E1000_KUMCTRLSTA_INB_CTRL_DIS_PADDING;
1731 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_INB_CTRL,
1740 if (hw->phy_type == e1000_phy_igp ||
1741 hw->phy_type == e1000_phy_igp_2) {
1742 ret_val = e1000_copper_link_igp_setup(hw);
1745 } else if (hw->phy_type == e1000_phy_m88) {
1746 ret_val = e1000_copper_link_mgp_setup(hw);
1749 } else if (hw->phy_type == e1000_phy_gg82563) {
1750 ret_val = e1000_copper_link_ggp_setup(hw);
1756 /* Setup autoneg and flow control advertisement
1757 * and perform autonegotiation */
1758 ret_val = e1000_copper_link_autoneg(hw);
1762 /* PHY will be set to 10H, 10F, 100H,or 100F
1763 * depending on value from forced_speed_duplex. */
1764 DEBUGOUT("Forcing speed and duplex\n");
1765 ret_val = e1000_phy_force_speed_duplex(hw);
1767 DEBUGOUT("Error Forcing Speed and Duplex\n");
1772 /* Check link status. Wait up to 100 microseconds for link to become
1775 for(i = 0; i < 10; i++) {
1776 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
1779 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
1783 if(phy_data & MII_SR_LINK_STATUS) {
1784 /* Config the MAC and PHY after link is up */
1785 ret_val = e1000_copper_link_postconfig(hw);
1789 DEBUGOUT("Valid link established!!!\n");
1790 return E1000_SUCCESS;
1795 DEBUGOUT("Unable to establish link!!!\n");
1796 return E1000_SUCCESS;
1799 /******************************************************************************
1800 * Configure the MAC-to-PHY interface for 10/100Mbps
1802 * hw - Struct containing variables accessed by shared code
1803 ******************************************************************************/
1805 e1000_configure_kmrn_for_10_100(struct e1000_hw *hw)
1807 int32_t ret_val = E1000_SUCCESS;
1811 DEBUGFUNC("e1000_configure_kmrn_for_10_100");
1813 reg_data = E1000_KUMCTRLSTA_HD_CTRL_10_100_DEFAULT;
1814 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_HD_CTRL,
1819 /* Configure Transmit Inter-Packet Gap */
1820 tipg = E1000_READ_REG(hw, TIPG);
1821 tipg &= ~E1000_TIPG_IPGT_MASK;
1822 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_10_100;
1823 E1000_WRITE_REG(hw, TIPG, tipg);
1829 e1000_configure_kmrn_for_1000(struct e1000_hw *hw)
1831 int32_t ret_val = E1000_SUCCESS;
1835 DEBUGFUNC("e1000_configure_kmrn_for_1000");
1837 reg_data = E1000_KUMCTRLSTA_HD_CTRL_1000_DEFAULT;
1838 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_HD_CTRL,
1843 /* Configure Transmit Inter-Packet Gap */
1844 tipg = E1000_READ_REG(hw, TIPG);
1845 tipg &= ~E1000_TIPG_IPGT_MASK;
1846 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
1847 E1000_WRITE_REG(hw, TIPG, tipg);
1852 /******************************************************************************
1853 * Configures PHY autoneg and flow control advertisement settings
1855 * hw - Struct containing variables accessed by shared code
1856 ******************************************************************************/
1858 e1000_phy_setup_autoneg(struct e1000_hw *hw)
1861 uint16_t mii_autoneg_adv_reg;
1862 uint16_t mii_1000t_ctrl_reg;
1864 DEBUGFUNC("e1000_phy_setup_autoneg");
1866 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
1867 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
1871 /* Read the MII 1000Base-T Control Register (Address 9). */
1872 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
1876 /* Need to parse both autoneg_advertised and fc and set up
1877 * the appropriate PHY registers. First we will parse for
1878 * autoneg_advertised software override. Since we can advertise
1879 * a plethora of combinations, we need to check each bit
1883 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
1884 * Advertisement Register (Address 4) and the 1000 mb speed bits in
1885 * the 1000Base-T Control Register (Address 9).
1887 mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
1888 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
1890 DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised);
1892 /* Do we want to advertise 10 Mb Half Duplex? */
1893 if(hw->autoneg_advertised & ADVERTISE_10_HALF) {
1894 DEBUGOUT("Advertise 10mb Half duplex\n");
1895 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
1898 /* Do we want to advertise 10 Mb Full Duplex? */
1899 if(hw->autoneg_advertised & ADVERTISE_10_FULL) {
1900 DEBUGOUT("Advertise 10mb Full duplex\n");
1901 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
1904 /* Do we want to advertise 100 Mb Half Duplex? */
1905 if(hw->autoneg_advertised & ADVERTISE_100_HALF) {
1906 DEBUGOUT("Advertise 100mb Half duplex\n");
1907 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
1910 /* Do we want to advertise 100 Mb Full Duplex? */
1911 if(hw->autoneg_advertised & ADVERTISE_100_FULL) {
1912 DEBUGOUT("Advertise 100mb Full duplex\n");
1913 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
1916 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
1917 if(hw->autoneg_advertised & ADVERTISE_1000_HALF) {
1918 DEBUGOUT("Advertise 1000mb Half duplex requested, request denied!\n");
1921 /* Do we want to advertise 1000 Mb Full Duplex? */
1922 if(hw->autoneg_advertised & ADVERTISE_1000_FULL) {
1923 DEBUGOUT("Advertise 1000mb Full duplex\n");
1924 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
1927 /* Check for a software override of the flow control settings, and
1928 * setup the PHY advertisement registers accordingly. If
1929 * auto-negotiation is enabled, then software will have to set the
1930 * "PAUSE" bits to the correct value in the Auto-Negotiation
1931 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
1933 * The possible values of the "fc" parameter are:
1934 * 0: Flow control is completely disabled
1935 * 1: Rx flow control is enabled (we can receive pause frames
1936 * but not send pause frames).
1937 * 2: Tx flow control is enabled (we can send pause frames
1938 * but we do not support receiving pause frames).
1939 * 3: Both Rx and TX flow control (symmetric) are enabled.
1940 * other: No software override. The flow control configuration
1941 * in the EEPROM is used.
1944 case e1000_fc_none: /* 0 */
1945 /* Flow control (RX & TX) is completely disabled by a
1946 * software over-ride.
1948 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1950 case e1000_fc_rx_pause: /* 1 */
1951 /* RX Flow control is enabled, and TX Flow control is
1952 * disabled, by a software over-ride.
1954 /* Since there really isn't a way to advertise that we are
1955 * capable of RX Pause ONLY, we will advertise that we
1956 * support both symmetric and asymmetric RX PAUSE. Later
1957 * (in e1000_config_fc_after_link_up) we will disable the
1958 *hw's ability to send PAUSE frames.
1960 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1962 case e1000_fc_tx_pause: /* 2 */
1963 /* TX Flow control is enabled, and RX Flow control is
1964 * disabled, by a software over-ride.
1966 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
1967 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
1969 case e1000_fc_full: /* 3 */
1970 /* Flow control (both RX and TX) is enabled by a software
1973 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1976 DEBUGOUT("Flow control param set incorrectly\n");
1977 return -E1000_ERR_CONFIG;
1980 ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
1984 DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
1986 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg);
1990 return E1000_SUCCESS;
1993 /******************************************************************************
1994 * Force PHY speed and duplex settings to hw->forced_speed_duplex
1996 * hw - Struct containing variables accessed by shared code
1997 ******************************************************************************/
1999 e1000_phy_force_speed_duplex(struct e1000_hw *hw)
2003 uint16_t mii_ctrl_reg;
2004 uint16_t mii_status_reg;
2008 DEBUGFUNC("e1000_phy_force_speed_duplex");
2010 /* Turn off Flow control if we are forcing speed and duplex. */
2011 hw->fc = e1000_fc_none;
2013 DEBUGOUT1("hw->fc = %d\n", hw->fc);
2015 /* Read the Device Control Register. */
2016 ctrl = E1000_READ_REG(hw, CTRL);
2018 /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */
2019 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2020 ctrl &= ~(DEVICE_SPEED_MASK);
2022 /* Clear the Auto Speed Detect Enable bit. */
2023 ctrl &= ~E1000_CTRL_ASDE;
2025 /* Read the MII Control Register. */
2026 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg);
2030 /* We need to disable autoneg in order to force link and duplex. */
2032 mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN;
2034 /* Are we forcing Full or Half Duplex? */
2035 if(hw->forced_speed_duplex == e1000_100_full ||
2036 hw->forced_speed_duplex == e1000_10_full) {
2037 /* We want to force full duplex so we SET the full duplex bits in the
2038 * Device and MII Control Registers.
2040 ctrl |= E1000_CTRL_FD;
2041 mii_ctrl_reg |= MII_CR_FULL_DUPLEX;
2042 DEBUGOUT("Full Duplex\n");
2044 /* We want to force half duplex so we CLEAR the full duplex bits in
2045 * the Device and MII Control Registers.
2047 ctrl &= ~E1000_CTRL_FD;
2048 mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX;
2049 DEBUGOUT("Half Duplex\n");
2052 /* Are we forcing 100Mbps??? */
2053 if(hw->forced_speed_duplex == e1000_100_full ||
2054 hw->forced_speed_duplex == e1000_100_half) {
2055 /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */
2056 ctrl |= E1000_CTRL_SPD_100;
2057 mii_ctrl_reg |= MII_CR_SPEED_100;
2058 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
2059 DEBUGOUT("Forcing 100mb ");
2061 /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */
2062 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
2063 mii_ctrl_reg |= MII_CR_SPEED_10;
2064 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
2065 DEBUGOUT("Forcing 10mb ");
2068 e1000_config_collision_dist(hw);
2070 /* Write the configured values back to the Device Control Reg. */
2071 E1000_WRITE_REG(hw, CTRL, ctrl);
2073 if ((hw->phy_type == e1000_phy_m88) ||
2074 (hw->phy_type == e1000_phy_gg82563)) {
2075 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
2079 /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
2080 * forced whenever speed are duplex are forced.
2082 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
2083 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
2087 DEBUGOUT1("M88E1000 PSCR: %x \n", phy_data);
2089 /* Need to reset the PHY or these changes will be ignored */
2090 mii_ctrl_reg |= MII_CR_RESET;
2092 /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
2093 * forced whenever speed or duplex are forced.
2095 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
2099 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
2100 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
2102 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
2107 /* Write back the modified PHY MII control register. */
2108 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg);
2114 /* The wait_autoneg_complete flag may be a little misleading here.
2115 * Since we are forcing speed and duplex, Auto-Neg is not enabled.
2116 * But we do want to delay for a period while forcing only so we
2117 * don't generate false No Link messages. So we will wait here
2118 * only if the user has set wait_autoneg_complete to 1, which is
2121 if(hw->wait_autoneg_complete) {
2122 /* We will wait for autoneg to complete. */
2123 DEBUGOUT("Waiting for forced speed/duplex link.\n");
2126 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
2127 for(i = PHY_FORCE_TIME; i > 0; i--) {
2128 /* Read the MII Status Register and wait for Auto-Neg Complete bit
2131 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2135 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2139 if(mii_status_reg & MII_SR_LINK_STATUS) break;
2143 ((hw->phy_type == e1000_phy_m88) ||
2144 (hw->phy_type == e1000_phy_gg82563))) {
2145 /* We didn't get link. Reset the DSP and wait again for link. */
2146 ret_val = e1000_phy_reset_dsp(hw);
2148 DEBUGOUT("Error Resetting PHY DSP\n");
2152 /* This loop will early-out if the link condition has been met. */
2153 for(i = PHY_FORCE_TIME; i > 0; i--) {
2154 if(mii_status_reg & MII_SR_LINK_STATUS) break;
2156 /* Read the MII Status Register and wait for Auto-Neg Complete bit
2159 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2163 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2169 if (hw->phy_type == e1000_phy_m88) {
2170 /* Because we reset the PHY above, we need to re-force TX_CLK in the
2171 * Extended PHY Specific Control Register to 25MHz clock. This value
2172 * defaults back to a 2.5MHz clock when the PHY is reset.
2174 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
2178 phy_data |= M88E1000_EPSCR_TX_CLK_25;
2179 ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
2183 /* In addition, because of the s/w reset above, we need to enable CRS on
2184 * TX. This must be set for both full and half duplex operation.
2186 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
2190 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
2191 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
2195 if((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
2197 (hw->forced_speed_duplex == e1000_10_full ||
2198 hw->forced_speed_duplex == e1000_10_half)) {
2199 ret_val = e1000_polarity_reversal_workaround(hw);
2203 } else if (hw->phy_type == e1000_phy_gg82563) {
2204 /* The TX_CLK of the Extended PHY Specific Control Register defaults
2205 * to 2.5MHz on a reset. We need to re-force it back to 25MHz, if
2206 * we're not in a forced 10/duplex configuration. */
2207 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, &phy_data);
2211 phy_data &= ~GG82563_MSCR_TX_CLK_MASK;
2212 if ((hw->forced_speed_duplex == e1000_10_full) ||
2213 (hw->forced_speed_duplex == e1000_10_half))
2214 phy_data |= GG82563_MSCR_TX_CLK_10MBPS_2_5MHZ;
2216 phy_data |= GG82563_MSCR_TX_CLK_100MBPS_25MHZ;
2218 /* Also due to the reset, we need to enable CRS on Tx. */
2219 phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
2221 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, phy_data);
2225 return E1000_SUCCESS;
2228 /******************************************************************************
2229 * Sets the collision distance in the Transmit Control register
2231 * hw - Struct containing variables accessed by shared code
2233 * Link should have been established previously. Reads the speed and duplex
2234 * information from the Device Status register.
2235 ******************************************************************************/
2237 e1000_config_collision_dist(struct e1000_hw *hw)
2239 uint32_t tctl, coll_dist;
2241 DEBUGFUNC("e1000_config_collision_dist");
2243 if (hw->mac_type < e1000_82543)
2244 coll_dist = E1000_COLLISION_DISTANCE_82542;
2246 coll_dist = E1000_COLLISION_DISTANCE;
2248 tctl = E1000_READ_REG(hw, TCTL);
2250 tctl &= ~E1000_TCTL_COLD;
2251 tctl |= coll_dist << E1000_COLD_SHIFT;
2253 E1000_WRITE_REG(hw, TCTL, tctl);
2254 E1000_WRITE_FLUSH(hw);
2257 /******************************************************************************
2258 * Sets MAC speed and duplex settings to reflect the those in the PHY
2260 * hw - Struct containing variables accessed by shared code
2261 * mii_reg - data to write to the MII control register
2263 * The contents of the PHY register containing the needed information need to
2265 ******************************************************************************/
2267 e1000_config_mac_to_phy(struct e1000_hw *hw)
2273 DEBUGFUNC("e1000_config_mac_to_phy");
2275 /* 82544 or newer MAC, Auto Speed Detection takes care of
2276 * MAC speed/duplex configuration.*/
2277 if (hw->mac_type >= e1000_82544)
2278 return E1000_SUCCESS;
2280 /* Read the Device Control Register and set the bits to Force Speed
2283 ctrl = E1000_READ_REG(hw, CTRL);
2284 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2285 ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
2287 /* Set up duplex in the Device Control and Transmit Control
2288 * registers depending on negotiated values.
2290 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
2294 if(phy_data & M88E1000_PSSR_DPLX)
2295 ctrl |= E1000_CTRL_FD;
2297 ctrl &= ~E1000_CTRL_FD;
2299 e1000_config_collision_dist(hw);
2301 /* Set up speed in the Device Control register depending on
2302 * negotiated values.
2304 if((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
2305 ctrl |= E1000_CTRL_SPD_1000;
2306 else if((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
2307 ctrl |= E1000_CTRL_SPD_100;
2309 /* Write the configured values back to the Device Control Reg. */
2310 E1000_WRITE_REG(hw, CTRL, ctrl);
2311 return E1000_SUCCESS;
2314 /******************************************************************************
2315 * Forces the MAC's flow control settings.
2317 * hw - Struct containing variables accessed by shared code
2319 * Sets the TFCE and RFCE bits in the device control register to reflect
2320 * the adapter settings. TFCE and RFCE need to be explicitly set by
2321 * software when a Copper PHY is used because autonegotiation is managed
2322 * by the PHY rather than the MAC. Software must also configure these
2323 * bits when link is forced on a fiber connection.
2324 *****************************************************************************/
2326 e1000_force_mac_fc(struct e1000_hw *hw)
2330 DEBUGFUNC("e1000_force_mac_fc");
2332 /* Get the current configuration of the Device Control Register */
2333 ctrl = E1000_READ_REG(hw, CTRL);
2335 /* Because we didn't get link via the internal auto-negotiation
2336 * mechanism (we either forced link or we got link via PHY
2337 * auto-neg), we have to manually enable/disable transmit an
2338 * receive flow control.
2340 * The "Case" statement below enables/disable flow control
2341 * according to the "hw->fc" parameter.
2343 * The possible values of the "fc" parameter are:
2344 * 0: Flow control is completely disabled
2345 * 1: Rx flow control is enabled (we can receive pause
2346 * frames but not send pause frames).
2347 * 2: Tx flow control is enabled (we can send pause frames
2348 * frames but we do not receive pause frames).
2349 * 3: Both Rx and TX flow control (symmetric) is enabled.
2350 * other: No other values should be possible at this point.
2355 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
2357 case e1000_fc_rx_pause:
2358 ctrl &= (~E1000_CTRL_TFCE);
2359 ctrl |= E1000_CTRL_RFCE;
2361 case e1000_fc_tx_pause:
2362 ctrl &= (~E1000_CTRL_RFCE);
2363 ctrl |= E1000_CTRL_TFCE;
2366 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
2369 DEBUGOUT("Flow control param set incorrectly\n");
2370 return -E1000_ERR_CONFIG;
2373 /* Disable TX Flow Control for 82542 (rev 2.0) */
2374 if(hw->mac_type == e1000_82542_rev2_0)
2375 ctrl &= (~E1000_CTRL_TFCE);
2377 E1000_WRITE_REG(hw, CTRL, ctrl);
2378 return E1000_SUCCESS;
2381 /******************************************************************************
2382 * Configures flow control settings after link is established
2384 * hw - Struct containing variables accessed by shared code
2386 * Should be called immediately after a valid link has been established.
2387 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
2388 * and autonegotiation is enabled, the MAC flow control settings will be set
2389 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
2390 * and RFCE bits will be automaticaly set to the negotiated flow control mode.
2391 *****************************************************************************/
2393 e1000_config_fc_after_link_up(struct e1000_hw *hw)
2396 uint16_t mii_status_reg;
2397 uint16_t mii_nway_adv_reg;
2398 uint16_t mii_nway_lp_ability_reg;
2402 DEBUGFUNC("e1000_config_fc_after_link_up");
2404 /* Check for the case where we have fiber media and auto-neg failed
2405 * so we had to force link. In this case, we need to force the
2406 * configuration of the MAC to match the "fc" parameter.
2408 if(((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) ||
2409 ((hw->media_type == e1000_media_type_internal_serdes) && (hw->autoneg_failed)) ||
2410 ((hw->media_type == e1000_media_type_copper) && (!hw->autoneg))) {
2411 ret_val = e1000_force_mac_fc(hw);
2413 DEBUGOUT("Error forcing flow control settings\n");
2418 /* Check for the case where we have copper media and auto-neg is
2419 * enabled. In this case, we need to check and see if Auto-Neg
2420 * has completed, and if so, how the PHY and link partner has
2421 * flow control configured.
2423 if((hw->media_type == e1000_media_type_copper) && hw->autoneg) {
2424 /* Read the MII Status Register and check to see if AutoNeg
2425 * has completed. We read this twice because this reg has
2426 * some "sticky" (latched) bits.
2428 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2431 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2435 if(mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
2436 /* The AutoNeg process has completed, so we now need to
2437 * read both the Auto Negotiation Advertisement Register
2438 * (Address 4) and the Auto_Negotiation Base Page Ability
2439 * Register (Address 5) to determine how flow control was
2442 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV,
2446 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY,
2447 &mii_nway_lp_ability_reg);
2451 /* Two bits in the Auto Negotiation Advertisement Register
2452 * (Address 4) and two bits in the Auto Negotiation Base
2453 * Page Ability Register (Address 5) determine flow control
2454 * for both the PHY and the link partner. The following
2455 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
2456 * 1999, describes these PAUSE resolution bits and how flow
2457 * control is determined based upon these settings.
2458 * NOTE: DC = Don't Care
2460 * LOCAL DEVICE | LINK PARTNER
2461 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
2462 *-------|---------|-------|---------|--------------------
2463 * 0 | 0 | DC | DC | e1000_fc_none
2464 * 0 | 1 | 0 | DC | e1000_fc_none
2465 * 0 | 1 | 1 | 0 | e1000_fc_none
2466 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
2467 * 1 | 0 | 0 | DC | e1000_fc_none
2468 * 1 | DC | 1 | DC | e1000_fc_full
2469 * 1 | 1 | 0 | 0 | e1000_fc_none
2470 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
2473 /* Are both PAUSE bits set to 1? If so, this implies
2474 * Symmetric Flow Control is enabled at both ends. The
2475 * ASM_DIR bits are irrelevant per the spec.
2477 * For Symmetric Flow Control:
2479 * LOCAL DEVICE | LINK PARTNER
2480 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2481 *-------|---------|-------|---------|--------------------
2482 * 1 | DC | 1 | DC | e1000_fc_full
2485 if((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2486 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
2487 /* Now we need to check if the user selected RX ONLY
2488 * of pause frames. In this case, we had to advertise
2489 * FULL flow control because we could not advertise RX
2490 * ONLY. Hence, we must now check to see if we need to
2491 * turn OFF the TRANSMISSION of PAUSE frames.
2493 if(hw->original_fc == e1000_fc_full) {
2494 hw->fc = e1000_fc_full;
2495 DEBUGOUT("Flow Control = FULL.\r\n");
2497 hw->fc = e1000_fc_rx_pause;
2498 DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
2501 /* For receiving PAUSE frames ONLY.
2503 * LOCAL DEVICE | LINK PARTNER
2504 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2505 *-------|---------|-------|---------|--------------------
2506 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
2509 else if(!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2510 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2511 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2512 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
2513 hw->fc = e1000_fc_tx_pause;
2514 DEBUGOUT("Flow Control = TX PAUSE frames only.\r\n");
2516 /* For transmitting PAUSE frames ONLY.
2518 * LOCAL DEVICE | LINK PARTNER
2519 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2520 *-------|---------|-------|---------|--------------------
2521 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
2524 else if((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2525 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2526 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2527 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
2528 hw->fc = e1000_fc_rx_pause;
2529 DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
2531 /* Per the IEEE spec, at this point flow control should be
2532 * disabled. However, we want to consider that we could
2533 * be connected to a legacy switch that doesn't advertise
2534 * desired flow control, but can be forced on the link
2535 * partner. So if we advertised no flow control, that is
2536 * what we will resolve to. If we advertised some kind of
2537 * receive capability (Rx Pause Only or Full Flow Control)
2538 * and the link partner advertised none, we will configure
2539 * ourselves to enable Rx Flow Control only. We can do
2540 * this safely for two reasons: If the link partner really
2541 * didn't want flow control enabled, and we enable Rx, no
2542 * harm done since we won't be receiving any PAUSE frames
2543 * anyway. If the intent on the link partner was to have
2544 * flow control enabled, then by us enabling RX only, we
2545 * can at least receive pause frames and process them.
2546 * This is a good idea because in most cases, since we are
2547 * predominantly a server NIC, more times than not we will
2548 * be asked to delay transmission of packets than asking
2549 * our link partner to pause transmission of frames.
2551 else if((hw->original_fc == e1000_fc_none ||
2552 hw->original_fc == e1000_fc_tx_pause) ||
2553 hw->fc_strict_ieee) {
2554 hw->fc = e1000_fc_none;
2555 DEBUGOUT("Flow Control = NONE.\r\n");
2557 hw->fc = e1000_fc_rx_pause;
2558 DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
2561 /* Now we need to do one last check... If we auto-
2562 * negotiated to HALF DUPLEX, flow control should not be
2563 * enabled per IEEE 802.3 spec.
2565 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
2567 DEBUGOUT("Error getting link speed and duplex\n");
2571 if(duplex == HALF_DUPLEX)
2572 hw->fc = e1000_fc_none;
2574 /* Now we call a subroutine to actually force the MAC
2575 * controller to use the correct flow control settings.
2577 ret_val = e1000_force_mac_fc(hw);
2579 DEBUGOUT("Error forcing flow control settings\n");
2583 DEBUGOUT("Copper PHY and Auto Neg has not completed.\r\n");
2586 return E1000_SUCCESS;
2589 /******************************************************************************
2590 * Checks to see if the link status of the hardware has changed.
2592 * hw - Struct containing variables accessed by shared code
2594 * Called by any function that needs to check the link status of the adapter.
2595 *****************************************************************************/
2597 e1000_check_for_link(struct e1000_hw *hw)
2604 uint32_t signal = 0;
2608 DEBUGFUNC("e1000_check_for_link");
2610 ctrl = E1000_READ_REG(hw, CTRL);
2611 status = E1000_READ_REG(hw, STATUS);
2613 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
2614 * set when the optics detect a signal. On older adapters, it will be
2615 * cleared when there is a signal. This applies to fiber media only.
2617 if((hw->media_type == e1000_media_type_fiber) ||
2618 (hw->media_type == e1000_media_type_internal_serdes)) {
2619 rxcw = E1000_READ_REG(hw, RXCW);
2621 if(hw->media_type == e1000_media_type_fiber) {
2622 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
2623 if(status & E1000_STATUS_LU)
2624 hw->get_link_status = FALSE;
2628 /* If we have a copper PHY then we only want to go out to the PHY
2629 * registers to see if Auto-Neg has completed and/or if our link
2630 * status has changed. The get_link_status flag will be set if we
2631 * receive a Link Status Change interrupt or we have Rx Sequence
2634 if((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
2635 /* First we want to see if the MII Status Register reports
2636 * link. If so, then we want to get the current speed/duplex
2638 * Read the register twice since the link bit is sticky.
2640 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2643 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2647 if(phy_data & MII_SR_LINK_STATUS) {
2648 hw->get_link_status = FALSE;
2649 /* Check if there was DownShift, must be checked immediately after
2651 e1000_check_downshift(hw);
2653 /* If we are on 82544 or 82543 silicon and speed/duplex
2654 * are forced to 10H or 10F, then we will implement the polarity
2655 * reversal workaround. We disable interrupts first, and upon
2656 * returning, place the devices interrupt state to its previous
2657 * value except for the link status change interrupt which will
2658 * happen due to the execution of this workaround.
2661 if((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
2663 (hw->forced_speed_duplex == e1000_10_full ||
2664 hw->forced_speed_duplex == e1000_10_half)) {
2665 E1000_WRITE_REG(hw, IMC, 0xffffffff);
2666 ret_val = e1000_polarity_reversal_workaround(hw);
2667 icr = E1000_READ_REG(hw, ICR);
2668 E1000_WRITE_REG(hw, ICS, (icr & ~E1000_ICS_LSC));
2669 E1000_WRITE_REG(hw, IMS, IMS_ENABLE_MASK);
2673 /* No link detected */
2674 e1000_config_dsp_after_link_change(hw, FALSE);
2678 /* If we are forcing speed/duplex, then we simply return since
2679 * we have already determined whether we have link or not.
2681 if(!hw->autoneg) return -E1000_ERR_CONFIG;
2683 /* optimize the dsp settings for the igp phy */
2684 e1000_config_dsp_after_link_change(hw, TRUE);
2686 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
2687 * have Si on board that is 82544 or newer, Auto
2688 * Speed Detection takes care of MAC speed/duplex
2689 * configuration. So we only need to configure Collision
2690 * Distance in the MAC. Otherwise, we need to force
2691 * speed/duplex on the MAC to the current PHY speed/duplex
2694 if(hw->mac_type >= e1000_82544)
2695 e1000_config_collision_dist(hw);
2697 ret_val = e1000_config_mac_to_phy(hw);
2699 DEBUGOUT("Error configuring MAC to PHY settings\n");
2704 /* Configure Flow Control now that Auto-Neg has completed. First, we
2705 * need to restore the desired flow control settings because we may
2706 * have had to re-autoneg with a different link partner.
2708 ret_val = e1000_config_fc_after_link_up(hw);
2710 DEBUGOUT("Error configuring flow control\n");
2714 /* At this point we know that we are on copper and we have
2715 * auto-negotiated link. These are conditions for checking the link
2716 * partner capability register. We use the link speed to determine if
2717 * TBI compatibility needs to be turned on or off. If the link is not
2718 * at gigabit speed, then TBI compatibility is not needed. If we are
2719 * at gigabit speed, we turn on TBI compatibility.
2721 if(hw->tbi_compatibility_en) {
2722 uint16_t speed, duplex;
2723 e1000_get_speed_and_duplex(hw, &speed, &duplex);
2724 if(speed != SPEED_1000) {
2725 /* If link speed is not set to gigabit speed, we do not need
2726 * to enable TBI compatibility.
2728 if(hw->tbi_compatibility_on) {
2729 /* If we previously were in the mode, turn it off. */
2730 rctl = E1000_READ_REG(hw, RCTL);
2731 rctl &= ~E1000_RCTL_SBP;
2732 E1000_WRITE_REG(hw, RCTL, rctl);
2733 hw->tbi_compatibility_on = FALSE;
2736 /* If TBI compatibility is was previously off, turn it on. For
2737 * compatibility with a TBI link partner, we will store bad
2738 * packets. Some frames have an additional byte on the end and
2739 * will look like CRC errors to to the hardware.
2741 if(!hw->tbi_compatibility_on) {
2742 hw->tbi_compatibility_on = TRUE;
2743 rctl = E1000_READ_REG(hw, RCTL);
2744 rctl |= E1000_RCTL_SBP;
2745 E1000_WRITE_REG(hw, RCTL, rctl);
2750 /* If we don't have link (auto-negotiation failed or link partner cannot
2751 * auto-negotiate), the cable is plugged in (we have signal), and our
2752 * link partner is not trying to auto-negotiate with us (we are receiving
2753 * idles or data), we need to force link up. We also need to give
2754 * auto-negotiation time to complete, in case the cable was just plugged
2755 * in. The autoneg_failed flag does this.
2757 else if((((hw->media_type == e1000_media_type_fiber) &&
2758 ((ctrl & E1000_CTRL_SWDPIN1) == signal)) ||
2759 (hw->media_type == e1000_media_type_internal_serdes)) &&
2760 (!(status & E1000_STATUS_LU)) &&
2761 (!(rxcw & E1000_RXCW_C))) {
2762 if(hw->autoneg_failed == 0) {
2763 hw->autoneg_failed = 1;
2766 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\r\n");
2768 /* Disable auto-negotiation in the TXCW register */
2769 E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
2771 /* Force link-up and also force full-duplex. */
2772 ctrl = E1000_READ_REG(hw, CTRL);
2773 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
2774 E1000_WRITE_REG(hw, CTRL, ctrl);
2776 /* Configure Flow Control after forcing link up. */
2777 ret_val = e1000_config_fc_after_link_up(hw);
2779 DEBUGOUT("Error configuring flow control\n");
2783 /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
2784 * auto-negotiation in the TXCW register and disable forced link in the
2785 * Device Control register in an attempt to auto-negotiate with our link
2788 else if(((hw->media_type == e1000_media_type_fiber) ||
2789 (hw->media_type == e1000_media_type_internal_serdes)) &&
2790 (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
2791 DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\r\n");
2792 E1000_WRITE_REG(hw, TXCW, hw->txcw);
2793 E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
2795 hw->serdes_link_down = FALSE;
2797 /* If we force link for non-auto-negotiation switch, check link status
2798 * based on MAC synchronization for internal serdes media type.
2800 else if((hw->media_type == e1000_media_type_internal_serdes) &&
2801 !(E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
2802 /* SYNCH bit and IV bit are sticky. */
2804 if(E1000_RXCW_SYNCH & E1000_READ_REG(hw, RXCW)) {
2805 if(!(rxcw & E1000_RXCW_IV)) {
2806 hw->serdes_link_down = FALSE;
2807 DEBUGOUT("SERDES: Link is up.\n");
2810 hw->serdes_link_down = TRUE;
2811 DEBUGOUT("SERDES: Link is down.\n");
2814 if((hw->media_type == e1000_media_type_internal_serdes) &&
2815 (E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
2816 hw->serdes_link_down = !(E1000_STATUS_LU & E1000_READ_REG(hw, STATUS));
2818 return E1000_SUCCESS;
2821 /******************************************************************************
2822 * Detects the current speed and duplex settings of the hardware.
2824 * hw - Struct containing variables accessed by shared code
2825 * speed - Speed of the connection
2826 * duplex - Duplex setting of the connection
2827 *****************************************************************************/
2829 e1000_get_speed_and_duplex(struct e1000_hw *hw,
2837 DEBUGFUNC("e1000_get_speed_and_duplex");
2839 if(hw->mac_type >= e1000_82543) {
2840 status = E1000_READ_REG(hw, STATUS);
2841 if(status & E1000_STATUS_SPEED_1000) {
2842 *speed = SPEED_1000;
2843 DEBUGOUT("1000 Mbs, ");
2844 } else if(status & E1000_STATUS_SPEED_100) {
2846 DEBUGOUT("100 Mbs, ");
2849 DEBUGOUT("10 Mbs, ");
2852 if(status & E1000_STATUS_FD) {
2853 *duplex = FULL_DUPLEX;
2854 DEBUGOUT("Full Duplex\r\n");
2856 *duplex = HALF_DUPLEX;
2857 DEBUGOUT(" Half Duplex\r\n");
2860 DEBUGOUT("1000 Mbs, Full Duplex\r\n");
2861 *speed = SPEED_1000;
2862 *duplex = FULL_DUPLEX;
2865 /* IGP01 PHY may advertise full duplex operation after speed downgrade even
2866 * if it is operating at half duplex. Here we set the duplex settings to
2867 * match the duplex in the link partner's capabilities.
2869 if(hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
2870 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
2874 if(!(phy_data & NWAY_ER_LP_NWAY_CAPS))
2875 *duplex = HALF_DUPLEX;
2877 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data);
2880 if((*speed == SPEED_100 && !(phy_data & NWAY_LPAR_100TX_FD_CAPS)) ||
2881 (*speed == SPEED_10 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
2882 *duplex = HALF_DUPLEX;
2886 if ((hw->mac_type == e1000_80003es2lan) &&
2887 (hw->media_type == e1000_media_type_copper)) {
2888 if (*speed == SPEED_1000)
2889 ret_val = e1000_configure_kmrn_for_1000(hw);
2891 ret_val = e1000_configure_kmrn_for_10_100(hw);
2896 return E1000_SUCCESS;
2899 /******************************************************************************
2900 * Blocks until autoneg completes or times out (~4.5 seconds)
2902 * hw - Struct containing variables accessed by shared code
2903 ******************************************************************************/
2905 e1000_wait_autoneg(struct e1000_hw *hw)
2911 DEBUGFUNC("e1000_wait_autoneg");
2912 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
2914 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
2915 for(i = PHY_AUTO_NEG_TIME; i > 0; i--) {
2916 /* Read the MII Status Register and wait for Auto-Neg
2917 * Complete bit to be set.
2919 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2922 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2925 if(phy_data & MII_SR_AUTONEG_COMPLETE) {
2926 return E1000_SUCCESS;
2930 return E1000_SUCCESS;
2933 /******************************************************************************
2934 * Raises the Management Data Clock
2936 * hw - Struct containing variables accessed by shared code
2937 * ctrl - Device control register's current value
2938 ******************************************************************************/
2940 e1000_raise_mdi_clk(struct e1000_hw *hw,
2943 /* Raise the clock input to the Management Data Clock (by setting the MDC
2944 * bit), and then delay 10 microseconds.
2946 E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
2947 E1000_WRITE_FLUSH(hw);
2951 /******************************************************************************
2952 * Lowers the Management Data Clock
2954 * hw - Struct containing variables accessed by shared code
2955 * ctrl - Device control register's current value
2956 ******************************************************************************/
2958 e1000_lower_mdi_clk(struct e1000_hw *hw,
2961 /* Lower the clock input to the Management Data Clock (by clearing the MDC
2962 * bit), and then delay 10 microseconds.
2964 E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
2965 E1000_WRITE_FLUSH(hw);
2969 /******************************************************************************
2970 * Shifts data bits out to the PHY
2972 * hw - Struct containing variables accessed by shared code
2973 * data - Data to send out to the PHY
2974 * count - Number of bits to shift out
2976 * Bits are shifted out in MSB to LSB order.
2977 ******************************************************************************/
2979 e1000_shift_out_mdi_bits(struct e1000_hw *hw,
2986 /* We need to shift "count" number of bits out to the PHY. So, the value
2987 * in the "data" parameter will be shifted out to the PHY one bit at a
2988 * time. In order to do this, "data" must be broken down into bits.
2991 mask <<= (count - 1);
2993 ctrl = E1000_READ_REG(hw, CTRL);
2995 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
2996 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
2999 /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
3000 * then raising and lowering the Management Data Clock. A "0" is
3001 * shifted out to the PHY by setting the MDIO bit to "0" and then
3002 * raising and lowering the clock.
3004 if(data & mask) ctrl |= E1000_CTRL_MDIO;
3005 else ctrl &= ~E1000_CTRL_MDIO;
3007 E1000_WRITE_REG(hw, CTRL, ctrl);
3008 E1000_WRITE_FLUSH(hw);
3012 e1000_raise_mdi_clk(hw, &ctrl);
3013 e1000_lower_mdi_clk(hw, &ctrl);
3019 /******************************************************************************
3020 * Shifts data bits in from the PHY
3022 * hw - Struct containing variables accessed by shared code
3024 * Bits are shifted in in MSB to LSB order.
3025 ******************************************************************************/
3027 e1000_shift_in_mdi_bits(struct e1000_hw *hw)
3033 /* In order to read a register from the PHY, we need to shift in a total
3034 * of 18 bits from the PHY. The first two bit (turnaround) times are used
3035 * to avoid contention on the MDIO pin when a read operation is performed.
3036 * These two bits are ignored by us and thrown away. Bits are "shifted in"
3037 * by raising the input to the Management Data Clock (setting the MDC bit),
3038 * and then reading the value of the MDIO bit.
3040 ctrl = E1000_READ_REG(hw, CTRL);
3042 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
3043 ctrl &= ~E1000_CTRL_MDIO_DIR;
3044 ctrl &= ~E1000_CTRL_MDIO;
3046 E1000_WRITE_REG(hw, CTRL, ctrl);
3047 E1000_WRITE_FLUSH(hw);
3049 /* Raise and Lower the clock before reading in the data. This accounts for
3050 * the turnaround bits. The first clock occurred when we clocked out the
3051 * last bit of the Register Address.
3053 e1000_raise_mdi_clk(hw, &ctrl);
3054 e1000_lower_mdi_clk(hw, &ctrl);
3056 for(data = 0, i = 0; i < 16; i++) {
3058 e1000_raise_mdi_clk(hw, &ctrl);
3059 ctrl = E1000_READ_REG(hw, CTRL);
3060 /* Check to see if we shifted in a "1". */
3061 if(ctrl & E1000_CTRL_MDIO) data |= 1;
3062 e1000_lower_mdi_clk(hw, &ctrl);
3065 e1000_raise_mdi_clk(hw, &ctrl);
3066 e1000_lower_mdi_clk(hw, &ctrl);
3072 e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask)
3074 uint32_t swfw_sync = 0;
3075 uint32_t swmask = mask;
3076 uint32_t fwmask = mask << 16;
3077 int32_t timeout = 200;
3079 DEBUGFUNC("e1000_swfw_sync_acquire");
3081 if (!hw->swfw_sync_present)
3082 return e1000_get_hw_eeprom_semaphore(hw);
3085 if (e1000_get_hw_eeprom_semaphore(hw))
3086 return -E1000_ERR_SWFW_SYNC;
3088 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
3089 if (!(swfw_sync & (fwmask | swmask))) {
3093 /* firmware currently using resource (fwmask) */
3094 /* or other software thread currently using resource (swmask) */
3095 e1000_put_hw_eeprom_semaphore(hw);
3101 DEBUGOUT("Driver can't access resource, SW_FW_SYNC timeout.\n");
3102 return -E1000_ERR_SWFW_SYNC;
3105 swfw_sync |= swmask;
3106 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
3108 e1000_put_hw_eeprom_semaphore(hw);
3109 return E1000_SUCCESS;
3113 e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask)
3116 uint32_t swmask = mask;
3118 DEBUGFUNC("e1000_swfw_sync_release");
3120 if (!hw->swfw_sync_present) {
3121 e1000_put_hw_eeprom_semaphore(hw);
3125 /* if (e1000_get_hw_eeprom_semaphore(hw))
3126 * return -E1000_ERR_SWFW_SYNC; */
3127 while (e1000_get_hw_eeprom_semaphore(hw) != E1000_SUCCESS);
3130 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
3131 swfw_sync &= ~swmask;
3132 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
3134 e1000_put_hw_eeprom_semaphore(hw);
3137 /*****************************************************************************
3138 * Reads the value from a PHY register, if the value is on a specific non zero
3139 * page, sets the page first.
3140 * hw - Struct containing variables accessed by shared code
3141 * reg_addr - address of the PHY register to read
3142 ******************************************************************************/
3144 e1000_read_phy_reg(struct e1000_hw *hw,
3151 DEBUGFUNC("e1000_read_phy_reg");
3153 if ((hw->mac_type == e1000_80003es2lan) &&
3154 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3155 swfw = E1000_SWFW_PHY1_SM;
3157 swfw = E1000_SWFW_PHY0_SM;
3159 if (e1000_swfw_sync_acquire(hw, swfw))
3160 return -E1000_ERR_SWFW_SYNC;
3162 if((hw->phy_type == e1000_phy_igp ||
3163 hw->phy_type == e1000_phy_igp_2) &&
3164 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
3165 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
3166 (uint16_t)reg_addr);
3168 e1000_swfw_sync_release(hw, swfw);
3171 } else if (hw->phy_type == e1000_phy_gg82563) {
3172 if (((reg_addr & MAX_PHY_REG_ADDRESS) > MAX_PHY_MULTI_PAGE_REG) ||
3173 (hw->mac_type == e1000_80003es2lan)) {
3174 /* Select Configuration Page */
3175 if ((reg_addr & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) {
3176 ret_val = e1000_write_phy_reg_ex(hw, GG82563_PHY_PAGE_SELECT,
3177 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3179 /* Use Alternative Page Select register to access
3180 * registers 30 and 31
3182 ret_val = e1000_write_phy_reg_ex(hw,
3183 GG82563_PHY_PAGE_SELECT_ALT,
3184 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3188 e1000_swfw_sync_release(hw, swfw);
3194 ret_val = e1000_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
3197 e1000_swfw_sync_release(hw, swfw);
3202 e1000_read_phy_reg_ex(struct e1000_hw *hw,
3208 const uint32_t phy_addr = 1;
3210 DEBUGFUNC("e1000_read_phy_reg_ex");
3212 if(reg_addr > MAX_PHY_REG_ADDRESS) {
3213 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
3214 return -E1000_ERR_PARAM;
3217 if(hw->mac_type > e1000_82543) {
3218 /* Set up Op-code, Phy Address, and register address in the MDI
3219 * Control register. The MAC will take care of interfacing with the
3220 * PHY to retrieve the desired data.
3222 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
3223 (phy_addr << E1000_MDIC_PHY_SHIFT) |
3224 (E1000_MDIC_OP_READ));
3226 E1000_WRITE_REG(hw, MDIC, mdic);
3228 /* Poll the ready bit to see if the MDI read completed */
3229 for(i = 0; i < 64; i++) {
3231 mdic = E1000_READ_REG(hw, MDIC);
3232 if(mdic & E1000_MDIC_READY) break;
3234 if(!(mdic & E1000_MDIC_READY)) {
3235 DEBUGOUT("MDI Read did not complete\n");
3236 return -E1000_ERR_PHY;
3238 if(mdic & E1000_MDIC_ERROR) {
3239 DEBUGOUT("MDI Error\n");
3240 return -E1000_ERR_PHY;
3242 *phy_data = (uint16_t) mdic;
3244 /* We must first send a preamble through the MDIO pin to signal the
3245 * beginning of an MII instruction. This is done by sending 32
3246 * consecutive "1" bits.
3248 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
3250 /* Now combine the next few fields that are required for a read
3251 * operation. We use this method instead of calling the
3252 * e1000_shift_out_mdi_bits routine five different times. The format of
3253 * a MII read instruction consists of a shift out of 14 bits and is
3254 * defined as follows:
3255 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
3256 * followed by a shift in of 18 bits. This first two bits shifted in
3257 * are TurnAround bits used to avoid contention on the MDIO pin when a
3258 * READ operation is performed. These two bits are thrown away
3259 * followed by a shift in of 16 bits which contains the desired data.
3261 mdic = ((reg_addr) | (phy_addr << 5) |
3262 (PHY_OP_READ << 10) | (PHY_SOF << 12));
3264 e1000_shift_out_mdi_bits(hw, mdic, 14);
3266 /* Now that we've shifted out the read command to the MII, we need to
3267 * "shift in" the 16-bit value (18 total bits) of the requested PHY
3270 *phy_data = e1000_shift_in_mdi_bits(hw);
3272 return E1000_SUCCESS;
3275 /******************************************************************************
3276 * Writes a value to a PHY register
3278 * hw - Struct containing variables accessed by shared code
3279 * reg_addr - address of the PHY register to write
3280 * data - data to write to the PHY
3281 ******************************************************************************/
3283 e1000_write_phy_reg(struct e1000_hw *hw,
3290 DEBUGFUNC("e1000_write_phy_reg");
3292 if ((hw->mac_type == e1000_80003es2lan) &&
3293 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3294 swfw = E1000_SWFW_PHY1_SM;
3296 swfw = E1000_SWFW_PHY0_SM;
3298 if (e1000_swfw_sync_acquire(hw, swfw))
3299 return -E1000_ERR_SWFW_SYNC;
3301 if((hw->phy_type == e1000_phy_igp ||
3302 hw->phy_type == e1000_phy_igp_2) &&
3303 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
3304 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
3305 (uint16_t)reg_addr);
3307 e1000_swfw_sync_release(hw, swfw);
3310 } else if (hw->phy_type == e1000_phy_gg82563) {
3311 if (((reg_addr & MAX_PHY_REG_ADDRESS) > MAX_PHY_MULTI_PAGE_REG) ||
3312 (hw->mac_type == e1000_80003es2lan)) {
3313 /* Select Configuration Page */
3314 if ((reg_addr & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) {
3315 ret_val = e1000_write_phy_reg_ex(hw, GG82563_PHY_PAGE_SELECT,
3316 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3318 /* Use Alternative Page Select register to access
3319 * registers 30 and 31
3321 ret_val = e1000_write_phy_reg_ex(hw,
3322 GG82563_PHY_PAGE_SELECT_ALT,
3323 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3327 e1000_swfw_sync_release(hw, swfw);
3333 ret_val = e1000_write_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
3336 e1000_swfw_sync_release(hw, swfw);
3341 e1000_write_phy_reg_ex(struct e1000_hw *hw,
3347 const uint32_t phy_addr = 1;
3349 DEBUGFUNC("e1000_write_phy_reg_ex");
3351 if(reg_addr > MAX_PHY_REG_ADDRESS) {
3352 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
3353 return -E1000_ERR_PARAM;
3356 if(hw->mac_type > e1000_82543) {
3357 /* Set up Op-code, Phy Address, register address, and data intended
3358 * for the PHY register in the MDI Control register. The MAC will take
3359 * care of interfacing with the PHY to send the desired data.
3361 mdic = (((uint32_t) phy_data) |
3362 (reg_addr << E1000_MDIC_REG_SHIFT) |
3363 (phy_addr << E1000_MDIC_PHY_SHIFT) |
3364 (E1000_MDIC_OP_WRITE));
3366 E1000_WRITE_REG(hw, MDIC, mdic);
3368 /* Poll the ready bit to see if the MDI read completed */
3369 for(i = 0; i < 640; i++) {
3371 mdic = E1000_READ_REG(hw, MDIC);
3372 if(mdic & E1000_MDIC_READY) break;
3374 if(!(mdic & E1000_MDIC_READY)) {
3375 DEBUGOUT("MDI Write did not complete\n");
3376 return -E1000_ERR_PHY;
3379 /* We'll need to use the SW defined pins to shift the write command
3380 * out to the PHY. We first send a preamble to the PHY to signal the
3381 * beginning of the MII instruction. This is done by sending 32
3382 * consecutive "1" bits.
3384 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
3386 /* Now combine the remaining required fields that will indicate a
3387 * write operation. We use this method instead of calling the
3388 * e1000_shift_out_mdi_bits routine for each field in the command. The
3389 * format of a MII write instruction is as follows:
3390 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
3392 mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
3393 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
3395 mdic |= (uint32_t) phy_data;
3397 e1000_shift_out_mdi_bits(hw, mdic, 32);
3400 return E1000_SUCCESS;
3404 e1000_read_kmrn_reg(struct e1000_hw *hw,
3410 DEBUGFUNC("e1000_read_kmrn_reg");
3412 if ((hw->mac_type == e1000_80003es2lan) &&
3413 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3414 swfw = E1000_SWFW_PHY1_SM;
3416 swfw = E1000_SWFW_PHY0_SM;
3418 if (e1000_swfw_sync_acquire(hw, swfw))
3419 return -E1000_ERR_SWFW_SYNC;
3421 /* Write register address */
3422 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
3423 E1000_KUMCTRLSTA_OFFSET) |
3424 E1000_KUMCTRLSTA_REN;
3425 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
3428 /* Read the data returned */
3429 reg_val = E1000_READ_REG(hw, KUMCTRLSTA);
3430 *data = (uint16_t)reg_val;
3432 e1000_swfw_sync_release(hw, swfw);
3433 return E1000_SUCCESS;
3437 e1000_write_kmrn_reg(struct e1000_hw *hw,
3443 DEBUGFUNC("e1000_write_kmrn_reg");
3445 if ((hw->mac_type == e1000_80003es2lan) &&
3446 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3447 swfw = E1000_SWFW_PHY1_SM;
3449 swfw = E1000_SWFW_PHY0_SM;
3451 if (e1000_swfw_sync_acquire(hw, swfw))
3452 return -E1000_ERR_SWFW_SYNC;
3454 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
3455 E1000_KUMCTRLSTA_OFFSET) | data;
3456 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
3459 e1000_swfw_sync_release(hw, swfw);
3460 return E1000_SUCCESS;
3463 /******************************************************************************
3464 * Returns the PHY to the power-on reset state
3466 * hw - Struct containing variables accessed by shared code
3467 ******************************************************************************/
3469 e1000_phy_hw_reset(struct e1000_hw *hw)
3471 uint32_t ctrl, ctrl_ext;
3476 DEBUGFUNC("e1000_phy_hw_reset");
3478 /* In the case of the phy reset being blocked, it's not an error, we
3479 * simply return success without performing the reset. */
3480 ret_val = e1000_check_phy_reset_block(hw);
3482 return E1000_SUCCESS;
3484 DEBUGOUT("Resetting Phy...\n");
3486 if(hw->mac_type > e1000_82543) {
3487 if ((hw->mac_type == e1000_80003es2lan) &&
3488 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3489 swfw = E1000_SWFW_PHY1_SM;
3491 swfw = E1000_SWFW_PHY0_SM;
3493 if (e1000_swfw_sync_acquire(hw, swfw)) {
3494 e1000_release_software_semaphore(hw);
3495 return -E1000_ERR_SWFW_SYNC;
3497 /* Read the device control register and assert the E1000_CTRL_PHY_RST
3498 * bit. Then, take it out of reset.
3499 * For pre-e1000_82571 hardware, we delay for 10ms between the assert
3500 * and deassert. For e1000_82571 hardware and later, we instead delay
3501 * for 50us between and 10ms after the deassertion.
3503 ctrl = E1000_READ_REG(hw, CTRL);
3504 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST);
3505 E1000_WRITE_FLUSH(hw);
3507 if (hw->mac_type < e1000_82571)
3512 E1000_WRITE_REG(hw, CTRL, ctrl);
3513 E1000_WRITE_FLUSH(hw);
3515 if (hw->mac_type >= e1000_82571)
3517 e1000_swfw_sync_release(hw, swfw);
3519 /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
3520 * bit to put the PHY into reset. Then, take it out of reset.
3522 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
3523 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
3524 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
3525 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
3526 E1000_WRITE_FLUSH(hw);
3528 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
3529 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
3530 E1000_WRITE_FLUSH(hw);
3534 if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
3535 /* Configure activity LED after PHY reset */
3536 led_ctrl = E1000_READ_REG(hw, LEDCTL);
3537 led_ctrl &= IGP_ACTIVITY_LED_MASK;
3538 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
3539 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
3542 /* Wait for FW to finish PHY configuration. */
3543 ret_val = e1000_get_phy_cfg_done(hw);
3544 e1000_release_software_semaphore(hw);
3549 /******************************************************************************
3552 * hw - Struct containing variables accessed by shared code
3554 * Sets bit 15 of the MII Control regiser
3555 ******************************************************************************/
3557 e1000_phy_reset(struct e1000_hw *hw)
3562 DEBUGFUNC("e1000_phy_reset");
3564 /* In the case of the phy reset being blocked, it's not an error, we
3565 * simply return success without performing the reset. */
3566 ret_val = e1000_check_phy_reset_block(hw);
3568 return E1000_SUCCESS;
3570 switch (hw->mac_type) {
3571 case e1000_82541_rev_2:
3574 ret_val = e1000_phy_hw_reset(hw);
3579 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
3583 phy_data |= MII_CR_RESET;
3584 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
3592 if(hw->phy_type == e1000_phy_igp || hw->phy_type == e1000_phy_igp_2)
3593 e1000_phy_init_script(hw);
3595 return E1000_SUCCESS;
3598 /******************************************************************************
3599 * Probes the expected PHY address for known PHY IDs
3601 * hw - Struct containing variables accessed by shared code
3602 ******************************************************************************/
3604 e1000_detect_gig_phy(struct e1000_hw *hw)
3606 int32_t phy_init_status, ret_val;
3607 uint16_t phy_id_high, phy_id_low;
3608 boolean_t match = FALSE;
3610 DEBUGFUNC("e1000_detect_gig_phy");
3612 /* The 82571 firmware may still be configuring the PHY. In this
3613 * case, we cannot access the PHY until the configuration is done. So
3614 * we explicitly set the PHY values. */
3615 if(hw->mac_type == e1000_82571 ||
3616 hw->mac_type == e1000_82572) {
3617 hw->phy_id = IGP01E1000_I_PHY_ID;
3618 hw->phy_type = e1000_phy_igp_2;
3619 return E1000_SUCCESS;
3622 /* ESB-2 PHY reads require e1000_phy_gg82563 to be set because of a work-
3623 * around that forces PHY page 0 to be set or the reads fail. The rest of
3624 * the code in this routine uses e1000_read_phy_reg to read the PHY ID.
3625 * So for ESB-2 we need to have this set so our reads won't fail. If the
3626 * attached PHY is not a e1000_phy_gg82563, the routines below will figure
3627 * this out as well. */
3628 if (hw->mac_type == e1000_80003es2lan)
3629 hw->phy_type = e1000_phy_gg82563;
3631 /* Read the PHY ID Registers to identify which PHY is onboard. */
3632 ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
3636 hw->phy_id = (uint32_t) (phy_id_high << 16);
3638 ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
3642 hw->phy_id |= (uint32_t) (phy_id_low & PHY_REVISION_MASK);
3643 hw->phy_revision = (uint32_t) phy_id_low & ~PHY_REVISION_MASK;
3645 switch(hw->mac_type) {
3647 if(hw->phy_id == M88E1000_E_PHY_ID) match = TRUE;
3650 if(hw->phy_id == M88E1000_I_PHY_ID) match = TRUE;
3654 case e1000_82545_rev_3:
3656 case e1000_82546_rev_3:
3657 if(hw->phy_id == M88E1011_I_PHY_ID) match = TRUE;
3660 case e1000_82541_rev_2:
3662 case e1000_82547_rev_2:
3663 if(hw->phy_id == IGP01E1000_I_PHY_ID) match = TRUE;
3666 if(hw->phy_id == M88E1111_I_PHY_ID) match = TRUE;
3668 case e1000_80003es2lan:
3669 if (hw->phy_id == GG82563_E_PHY_ID) match = TRUE;
3672 DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type);
3673 return -E1000_ERR_CONFIG;
3675 phy_init_status = e1000_set_phy_type(hw);
3677 if ((match) && (phy_init_status == E1000_SUCCESS)) {
3678 DEBUGOUT1("PHY ID 0x%X detected\n", hw->phy_id);
3679 return E1000_SUCCESS;
3681 DEBUGOUT1("Invalid PHY ID 0x%X\n", hw->phy_id);
3682 return -E1000_ERR_PHY;
3685 /******************************************************************************
3686 * Resets the PHY's DSP
3688 * hw - Struct containing variables accessed by shared code
3689 ******************************************************************************/
3691 e1000_phy_reset_dsp(struct e1000_hw *hw)
3694 DEBUGFUNC("e1000_phy_reset_dsp");
3697 if (hw->phy_type != e1000_phy_gg82563) {
3698 ret_val = e1000_write_phy_reg(hw, 29, 0x001d);
3701 ret_val = e1000_write_phy_reg(hw, 30, 0x00c1);
3703 ret_val = e1000_write_phy_reg(hw, 30, 0x0000);
3705 ret_val = E1000_SUCCESS;
3711 /******************************************************************************
3712 * Get PHY information from various PHY registers for igp PHY only.
3714 * hw - Struct containing variables accessed by shared code
3715 * phy_info - PHY information structure
3716 ******************************************************************************/
3718 e1000_phy_igp_get_info(struct e1000_hw *hw,
3719 struct e1000_phy_info *phy_info)
3722 uint16_t phy_data, polarity, min_length, max_length, average;
3724 DEBUGFUNC("e1000_phy_igp_get_info");
3726 /* The downshift status is checked only once, after link is established,
3727 * and it stored in the hw->speed_downgraded parameter. */
3728 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
3730 /* IGP01E1000 does not need to support it. */
3731 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
3733 /* IGP01E1000 always correct polarity reversal */
3734 phy_info->polarity_correction = e1000_polarity_reversal_enabled;
3736 /* Check polarity status */
3737 ret_val = e1000_check_polarity(hw, &polarity);
3741 phy_info->cable_polarity = polarity;
3743 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, &phy_data);
3747 phy_info->mdix_mode = (phy_data & IGP01E1000_PSSR_MDIX) >>
3748 IGP01E1000_PSSR_MDIX_SHIFT;
3750 if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
3751 IGP01E1000_PSSR_SPEED_1000MBPS) {
3752 /* Local/Remote Receiver Information are only valid at 1000 Mbps */
3753 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
3757 phy_info->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS) >>
3758 SR_1000T_LOCAL_RX_STATUS_SHIFT;
3759 phy_info->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS) >>
3760 SR_1000T_REMOTE_RX_STATUS_SHIFT;
3762 /* Get cable length */
3763 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
3767 /* Translate to old method */
3768 average = (max_length + min_length) / 2;
3770 if(average <= e1000_igp_cable_length_50)
3771 phy_info->cable_length = e1000_cable_length_50;
3772 else if(average <= e1000_igp_cable_length_80)
3773 phy_info->cable_length = e1000_cable_length_50_80;
3774 else if(average <= e1000_igp_cable_length_110)
3775 phy_info->cable_length = e1000_cable_length_80_110;
3776 else if(average <= e1000_igp_cable_length_140)
3777 phy_info->cable_length = e1000_cable_length_110_140;
3779 phy_info->cable_length = e1000_cable_length_140;
3782 return E1000_SUCCESS;
3785 /******************************************************************************
3786 * Get PHY information from various PHY registers fot m88 PHY only.
3788 * hw - Struct containing variables accessed by shared code
3789 * phy_info - PHY information structure
3790 ******************************************************************************/
3792 e1000_phy_m88_get_info(struct e1000_hw *hw,
3793 struct e1000_phy_info *phy_info)
3796 uint16_t phy_data, polarity;
3798 DEBUGFUNC("e1000_phy_m88_get_info");
3800 /* The downshift status is checked only once, after link is established,
3801 * and it stored in the hw->speed_downgraded parameter. */
3802 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
3804 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
3808 phy_info->extended_10bt_distance =
3809 (phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >>
3810 M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT;
3811 phy_info->polarity_correction =
3812 (phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >>
3813 M88E1000_PSCR_POLARITY_REVERSAL_SHIFT;
3815 /* Check polarity status */
3816 ret_val = e1000_check_polarity(hw, &polarity);
3819 phy_info->cable_polarity = polarity;
3821 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
3825 phy_info->mdix_mode = (phy_data & M88E1000_PSSR_MDIX) >>
3826 M88E1000_PSSR_MDIX_SHIFT;
3828 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
3829 /* Cable Length Estimation and Local/Remote Receiver Information
3830 * are only valid at 1000 Mbps.
3832 if (hw->phy_type != e1000_phy_gg82563) {
3833 phy_info->cable_length = ((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
3834 M88E1000_PSSR_CABLE_LENGTH_SHIFT);
3836 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_DSP_DISTANCE,
3841 phy_info->cable_length = phy_data & GG82563_DSPD_CABLE_LENGTH;
3844 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
3848 phy_info->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS) >>
3849 SR_1000T_LOCAL_RX_STATUS_SHIFT;
3851 phy_info->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS) >>
3852 SR_1000T_REMOTE_RX_STATUS_SHIFT;
3855 return E1000_SUCCESS;
3858 /******************************************************************************
3859 * Get PHY information from various PHY registers
3861 * hw - Struct containing variables accessed by shared code
3862 * phy_info - PHY information structure
3863 ******************************************************************************/
3865 e1000_phy_get_info(struct e1000_hw *hw,
3866 struct e1000_phy_info *phy_info)
3871 DEBUGFUNC("e1000_phy_get_info");
3873 phy_info->cable_length = e1000_cable_length_undefined;
3874 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined;
3875 phy_info->cable_polarity = e1000_rev_polarity_undefined;
3876 phy_info->downshift = e1000_downshift_undefined;
3877 phy_info->polarity_correction = e1000_polarity_reversal_undefined;
3878 phy_info->mdix_mode = e1000_auto_x_mode_undefined;
3879 phy_info->local_rx = e1000_1000t_rx_status_undefined;
3880 phy_info->remote_rx = e1000_1000t_rx_status_undefined;
3882 if(hw->media_type != e1000_media_type_copper) {
3883 DEBUGOUT("PHY info is only valid for copper media\n");
3884 return -E1000_ERR_CONFIG;
3887 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3891 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3895 if((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) {
3896 DEBUGOUT("PHY info is only valid if link is up\n");
3897 return -E1000_ERR_CONFIG;
3900 if(hw->phy_type == e1000_phy_igp ||
3901 hw->phy_type == e1000_phy_igp_2)
3902 return e1000_phy_igp_get_info(hw, phy_info);
3904 return e1000_phy_m88_get_info(hw, phy_info);
3908 e1000_validate_mdi_setting(struct e1000_hw *hw)
3910 DEBUGFUNC("e1000_validate_mdi_settings");
3912 if(!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) {
3913 DEBUGOUT("Invalid MDI setting detected\n");
3915 return -E1000_ERR_CONFIG;
3917 return E1000_SUCCESS;
3921 /******************************************************************************
3922 * Sets up eeprom variables in the hw struct. Must be called after mac_type
3923 * is configured. Additionally, if this is ICH8, the flash controller GbE
3924 * registers must be mapped, or this will crash.
3926 * hw - Struct containing variables accessed by shared code
3927 *****************************************************************************/
3929 e1000_init_eeprom_params(struct e1000_hw *hw)
3931 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3932 uint32_t eecd = E1000_READ_REG(hw, EECD);
3933 int32_t ret_val = E1000_SUCCESS;
3934 uint16_t eeprom_size;
3936 DEBUGFUNC("e1000_init_eeprom_params");
3938 switch (hw->mac_type) {
3939 case e1000_82542_rev2_0:
3940 case e1000_82542_rev2_1:
3943 eeprom->type = e1000_eeprom_microwire;
3944 eeprom->word_size = 64;
3945 eeprom->opcode_bits = 3;
3946 eeprom->address_bits = 6;
3947 eeprom->delay_usec = 50;
3948 eeprom->use_eerd = FALSE;
3949 eeprom->use_eewr = FALSE;
3953 case e1000_82545_rev_3:
3955 case e1000_82546_rev_3:
3956 eeprom->type = e1000_eeprom_microwire;
3957 eeprom->opcode_bits = 3;
3958 eeprom->delay_usec = 50;
3959 if(eecd & E1000_EECD_SIZE) {
3960 eeprom->word_size = 256;
3961 eeprom->address_bits = 8;
3963 eeprom->word_size = 64;
3964 eeprom->address_bits = 6;
3966 eeprom->use_eerd = FALSE;
3967 eeprom->use_eewr = FALSE;
3970 case e1000_82541_rev_2:
3972 case e1000_82547_rev_2:
3973 if (eecd & E1000_EECD_TYPE) {
3974 eeprom->type = e1000_eeprom_spi;
3975 eeprom->opcode_bits = 8;
3976 eeprom->delay_usec = 1;
3977 if (eecd & E1000_EECD_ADDR_BITS) {
3978 eeprom->page_size = 32;
3979 eeprom->address_bits = 16;
3981 eeprom->page_size = 8;
3982 eeprom->address_bits = 8;
3985 eeprom->type = e1000_eeprom_microwire;
3986 eeprom->opcode_bits = 3;
3987 eeprom->delay_usec = 50;
3988 if (eecd & E1000_EECD_ADDR_BITS) {
3989 eeprom->word_size = 256;
3990 eeprom->address_bits = 8;
3992 eeprom->word_size = 64;
3993 eeprom->address_bits = 6;
3996 eeprom->use_eerd = FALSE;
3997 eeprom->use_eewr = FALSE;
4001 eeprom->type = e1000_eeprom_spi;
4002 eeprom->opcode_bits = 8;
4003 eeprom->delay_usec = 1;
4004 if (eecd & E1000_EECD_ADDR_BITS) {
4005 eeprom->page_size = 32;
4006 eeprom->address_bits = 16;
4008 eeprom->page_size = 8;
4009 eeprom->address_bits = 8;
4011 eeprom->use_eerd = FALSE;
4012 eeprom->use_eewr = FALSE;
4015 eeprom->type = e1000_eeprom_spi;
4016 eeprom->opcode_bits = 8;
4017 eeprom->delay_usec = 1;
4018 if (eecd & E1000_EECD_ADDR_BITS) {
4019 eeprom->page_size = 32;
4020 eeprom->address_bits = 16;
4022 eeprom->page_size = 8;
4023 eeprom->address_bits = 8;
4025 eeprom->use_eerd = TRUE;
4026 eeprom->use_eewr = TRUE;
4027 if(e1000_is_onboard_nvm_eeprom(hw) == FALSE) {
4028 eeprom->type = e1000_eeprom_flash;
4029 eeprom->word_size = 2048;
4031 /* Ensure that the Autonomous FLASH update bit is cleared due to
4032 * Flash update issue on parts which use a FLASH for NVM. */
4033 eecd &= ~E1000_EECD_AUPDEN;
4034 E1000_WRITE_REG(hw, EECD, eecd);
4037 case e1000_80003es2lan:
4038 eeprom->type = e1000_eeprom_spi;
4039 eeprom->opcode_bits = 8;
4040 eeprom->delay_usec = 1;
4041 if (eecd & E1000_EECD_ADDR_BITS) {
4042 eeprom->page_size = 32;
4043 eeprom->address_bits = 16;
4045 eeprom->page_size = 8;
4046 eeprom->address_bits = 8;
4048 eeprom->use_eerd = TRUE;
4049 eeprom->use_eewr = FALSE;
4055 if (eeprom->type == e1000_eeprom_spi) {
4056 /* eeprom_size will be an enum [0..8] that maps to eeprom sizes 128B to
4057 * 32KB (incremented by powers of 2).
4059 if(hw->mac_type <= e1000_82547_rev_2) {
4060 /* Set to default value for initial eeprom read. */
4061 eeprom->word_size = 64;
4062 ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size);
4065 eeprom_size = (eeprom_size & EEPROM_SIZE_MASK) >> EEPROM_SIZE_SHIFT;
4066 /* 256B eeprom size was not supported in earlier hardware, so we
4067 * bump eeprom_size up one to ensure that "1" (which maps to 256B)
4068 * is never the result used in the shifting logic below. */
4072 eeprom_size = (uint16_t)((eecd & E1000_EECD_SIZE_EX_MASK) >>
4073 E1000_EECD_SIZE_EX_SHIFT);
4076 eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT);
4081 /******************************************************************************
4082 * Raises the EEPROM's clock input.
4084 * hw - Struct containing variables accessed by shared code
4085 * eecd - EECD's current value
4086 *****************************************************************************/
4088 e1000_raise_ee_clk(struct e1000_hw *hw,
4091 /* Raise the clock input to the EEPROM (by setting the SK bit), and then
4092 * wait <delay> microseconds.
4094 *eecd = *eecd | E1000_EECD_SK;
4095 E1000_WRITE_REG(hw, EECD, *eecd);
4096 E1000_WRITE_FLUSH(hw);
4097 udelay(hw->eeprom.delay_usec);
4100 /******************************************************************************
4101 * Lowers the EEPROM's clock input.
4103 * hw - Struct containing variables accessed by shared code
4104 * eecd - EECD's current value
4105 *****************************************************************************/
4107 e1000_lower_ee_clk(struct e1000_hw *hw,
4110 /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
4111 * wait 50 microseconds.
4113 *eecd = *eecd & ~E1000_EECD_SK;
4114 E1000_WRITE_REG(hw, EECD, *eecd);
4115 E1000_WRITE_FLUSH(hw);
4116 udelay(hw->eeprom.delay_usec);
4119 /******************************************************************************
4120 * Shift data bits out to the EEPROM.
4122 * hw - Struct containing variables accessed by shared code
4123 * data - data to send to the EEPROM
4124 * count - number of bits to shift out
4125 *****************************************************************************/
4127 e1000_shift_out_ee_bits(struct e1000_hw *hw,
4131 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4135 /* We need to shift "count" bits out to the EEPROM. So, value in the
4136 * "data" parameter will be shifted out to the EEPROM one bit at a time.
4137 * In order to do this, "data" must be broken down into bits.
4139 mask = 0x01 << (count - 1);
4140 eecd = E1000_READ_REG(hw, EECD);
4141 if (eeprom->type == e1000_eeprom_microwire) {
4142 eecd &= ~E1000_EECD_DO;
4143 } else if (eeprom->type == e1000_eeprom_spi) {
4144 eecd |= E1000_EECD_DO;
4147 /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
4148 * and then raising and then lowering the clock (the SK bit controls
4149 * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
4150 * by setting "DI" to "0" and then raising and then lowering the clock.
4152 eecd &= ~E1000_EECD_DI;
4155 eecd |= E1000_EECD_DI;
4157 E1000_WRITE_REG(hw, EECD, eecd);
4158 E1000_WRITE_FLUSH(hw);
4160 udelay(eeprom->delay_usec);
4162 e1000_raise_ee_clk(hw, &eecd);
4163 e1000_lower_ee_clk(hw, &eecd);
4169 /* We leave the "DI" bit set to "0" when we leave this routine. */
4170 eecd &= ~E1000_EECD_DI;
4171 E1000_WRITE_REG(hw, EECD, eecd);
4174 /******************************************************************************
4175 * Shift data bits in from the EEPROM
4177 * hw - Struct containing variables accessed by shared code
4178 *****************************************************************************/
4180 e1000_shift_in_ee_bits(struct e1000_hw *hw,
4187 /* In order to read a register from the EEPROM, we need to shift 'count'
4188 * bits in from the EEPROM. Bits are "shifted in" by raising the clock
4189 * input to the EEPROM (setting the SK bit), and then reading the value of
4190 * the "DO" bit. During this "shifting in" process the "DI" bit should
4194 eecd = E1000_READ_REG(hw, EECD);
4196 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
4199 for(i = 0; i < count; i++) {
4201 e1000_raise_ee_clk(hw, &eecd);
4203 eecd = E1000_READ_REG(hw, EECD);
4205 eecd &= ~(E1000_EECD_DI);
4206 if(eecd & E1000_EECD_DO)
4209 e1000_lower_ee_clk(hw, &eecd);
4215 /******************************************************************************
4216 * Prepares EEPROM for access
4218 * hw - Struct containing variables accessed by shared code
4220 * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
4221 * function should be called before issuing a command to the EEPROM.
4222 *****************************************************************************/
4224 e1000_acquire_eeprom(struct e1000_hw *hw)
4226 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4229 DEBUGFUNC("e1000_acquire_eeprom");
4231 if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
4232 return -E1000_ERR_SWFW_SYNC;
4233 eecd = E1000_READ_REG(hw, EECD);
4235 if (hw->mac_type != e1000_82573) {
4236 /* Request EEPROM Access */
4237 if(hw->mac_type > e1000_82544) {
4238 eecd |= E1000_EECD_REQ;
4239 E1000_WRITE_REG(hw, EECD, eecd);
4240 eecd = E1000_READ_REG(hw, EECD);
4241 while((!(eecd & E1000_EECD_GNT)) &&
4242 (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
4245 eecd = E1000_READ_REG(hw, EECD);
4247 if(!(eecd & E1000_EECD_GNT)) {
4248 eecd &= ~E1000_EECD_REQ;
4249 E1000_WRITE_REG(hw, EECD, eecd);
4250 DEBUGOUT("Could not acquire EEPROM grant\n");
4251 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
4252 return -E1000_ERR_EEPROM;
4257 /* Setup EEPROM for Read/Write */
4259 if (eeprom->type == e1000_eeprom_microwire) {
4260 /* Clear SK and DI */
4261 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
4262 E1000_WRITE_REG(hw, EECD, eecd);
4265 eecd |= E1000_EECD_CS;
4266 E1000_WRITE_REG(hw, EECD, eecd);
4267 } else if (eeprom->type == e1000_eeprom_spi) {
4268 /* Clear SK and CS */
4269 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
4270 E1000_WRITE_REG(hw, EECD, eecd);
4274 return E1000_SUCCESS;
4277 /******************************************************************************
4278 * Returns EEPROM to a "standby" state
4280 * hw - Struct containing variables accessed by shared code
4281 *****************************************************************************/
4283 e1000_standby_eeprom(struct e1000_hw *hw)
4285 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4288 eecd = E1000_READ_REG(hw, EECD);
4290 if(eeprom->type == e1000_eeprom_microwire) {
4291 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
4292 E1000_WRITE_REG(hw, EECD, eecd);
4293 E1000_WRITE_FLUSH(hw);
4294 udelay(eeprom->delay_usec);
4297 eecd |= E1000_EECD_SK;
4298 E1000_WRITE_REG(hw, EECD, eecd);
4299 E1000_WRITE_FLUSH(hw);
4300 udelay(eeprom->delay_usec);
4303 eecd |= E1000_EECD_CS;
4304 E1000_WRITE_REG(hw, EECD, eecd);
4305 E1000_WRITE_FLUSH(hw);
4306 udelay(eeprom->delay_usec);
4309 eecd &= ~E1000_EECD_SK;
4310 E1000_WRITE_REG(hw, EECD, eecd);
4311 E1000_WRITE_FLUSH(hw);
4312 udelay(eeprom->delay_usec);
4313 } else if(eeprom->type == e1000_eeprom_spi) {
4314 /* Toggle CS to flush commands */
4315 eecd |= E1000_EECD_CS;
4316 E1000_WRITE_REG(hw, EECD, eecd);
4317 E1000_WRITE_FLUSH(hw);
4318 udelay(eeprom->delay_usec);
4319 eecd &= ~E1000_EECD_CS;
4320 E1000_WRITE_REG(hw, EECD, eecd);
4321 E1000_WRITE_FLUSH(hw);
4322 udelay(eeprom->delay_usec);
4326 /******************************************************************************
4327 * Terminates a command by inverting the EEPROM's chip select pin
4329 * hw - Struct containing variables accessed by shared code
4330 *****************************************************************************/
4332 e1000_release_eeprom(struct e1000_hw *hw)
4336 DEBUGFUNC("e1000_release_eeprom");
4338 eecd = E1000_READ_REG(hw, EECD);
4340 if (hw->eeprom.type == e1000_eeprom_spi) {
4341 eecd |= E1000_EECD_CS; /* Pull CS high */
4342 eecd &= ~E1000_EECD_SK; /* Lower SCK */
4344 E1000_WRITE_REG(hw, EECD, eecd);
4346 udelay(hw->eeprom.delay_usec);
4347 } else if(hw->eeprom.type == e1000_eeprom_microwire) {
4348 /* cleanup eeprom */
4350 /* CS on Microwire is active-high */
4351 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
4353 E1000_WRITE_REG(hw, EECD, eecd);
4355 /* Rising edge of clock */
4356 eecd |= E1000_EECD_SK;
4357 E1000_WRITE_REG(hw, EECD, eecd);
4358 E1000_WRITE_FLUSH(hw);
4359 udelay(hw->eeprom.delay_usec);
4361 /* Falling edge of clock */
4362 eecd &= ~E1000_EECD_SK;
4363 E1000_WRITE_REG(hw, EECD, eecd);
4364 E1000_WRITE_FLUSH(hw);
4365 udelay(hw->eeprom.delay_usec);
4368 /* Stop requesting EEPROM access */
4369 if(hw->mac_type > e1000_82544) {
4370 eecd &= ~E1000_EECD_REQ;
4371 E1000_WRITE_REG(hw, EECD, eecd);
4374 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
4377 /******************************************************************************
4378 * Reads a 16 bit word from the EEPROM.
4380 * hw - Struct containing variables accessed by shared code
4381 *****************************************************************************/
4383 e1000_spi_eeprom_ready(struct e1000_hw *hw)
4385 uint16_t retry_count = 0;
4386 uint8_t spi_stat_reg;
4388 DEBUGFUNC("e1000_spi_eeprom_ready");
4390 /* Read "Status Register" repeatedly until the LSB is cleared. The
4391 * EEPROM will signal that the command has been completed by clearing
4392 * bit 0 of the internal status register. If it's not cleared within
4393 * 5 milliseconds, then error out.
4397 e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
4398 hw->eeprom.opcode_bits);
4399 spi_stat_reg = (uint8_t)e1000_shift_in_ee_bits(hw, 8);
4400 if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
4406 e1000_standby_eeprom(hw);
4407 } while(retry_count < EEPROM_MAX_RETRY_SPI);
4409 /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
4410 * only 0-5mSec on 5V devices)
4412 if(retry_count >= EEPROM_MAX_RETRY_SPI) {
4413 DEBUGOUT("SPI EEPROM Status error\n");
4414 return -E1000_ERR_EEPROM;
4417 return E1000_SUCCESS;
4420 /******************************************************************************
4421 * Reads a 16 bit word from the EEPROM.
4423 * hw - Struct containing variables accessed by shared code
4424 * offset - offset of word in the EEPROM to read
4425 * data - word read from the EEPROM
4426 * words - number of words to read
4427 *****************************************************************************/
4429 e1000_read_eeprom(struct e1000_hw *hw,
4434 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4438 DEBUGFUNC("e1000_read_eeprom");
4440 /* A check for invalid values: offset too large, too many words, and not
4443 if((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
4445 DEBUGOUT("\"words\" parameter out of bounds\n");
4446 return -E1000_ERR_EEPROM;
4449 /* FLASH reads without acquiring the semaphore are safe */
4450 if (e1000_is_onboard_nvm_eeprom(hw) == TRUE &&
4451 hw->eeprom.use_eerd == FALSE) {
4452 switch (hw->mac_type) {
4453 case e1000_80003es2lan:
4456 /* Prepare the EEPROM for reading */
4457 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
4458 return -E1000_ERR_EEPROM;
4463 if (eeprom->use_eerd == TRUE) {
4464 ret_val = e1000_read_eeprom_eerd(hw, offset, words, data);
4465 if ((e1000_is_onboard_nvm_eeprom(hw) == TRUE) ||
4466 (hw->mac_type != e1000_82573))
4467 e1000_release_eeprom(hw);
4471 if(eeprom->type == e1000_eeprom_spi) {
4473 uint8_t read_opcode = EEPROM_READ_OPCODE_SPI;
4475 if(e1000_spi_eeprom_ready(hw)) {
4476 e1000_release_eeprom(hw);
4477 return -E1000_ERR_EEPROM;
4480 e1000_standby_eeprom(hw);
4482 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
4483 if((eeprom->address_bits == 8) && (offset >= 128))
4484 read_opcode |= EEPROM_A8_OPCODE_SPI;
4486 /* Send the READ command (opcode + addr) */
4487 e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
4488 e1000_shift_out_ee_bits(hw, (uint16_t)(offset*2), eeprom->address_bits);
4490 /* Read the data. The address of the eeprom internally increments with
4491 * each byte (spi) being read, saving on the overhead of eeprom setup
4492 * and tear-down. The address counter will roll over if reading beyond
4493 * the size of the eeprom, thus allowing the entire memory to be read
4494 * starting from any offset. */
4495 for (i = 0; i < words; i++) {
4496 word_in = e1000_shift_in_ee_bits(hw, 16);
4497 data[i] = (word_in >> 8) | (word_in << 8);
4499 } else if(eeprom->type == e1000_eeprom_microwire) {
4500 for (i = 0; i < words; i++) {
4501 /* Send the READ command (opcode + addr) */
4502 e1000_shift_out_ee_bits(hw, EEPROM_READ_OPCODE_MICROWIRE,
4503 eeprom->opcode_bits);
4504 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + i),
4505 eeprom->address_bits);
4507 /* Read the data. For microwire, each word requires the overhead
4508 * of eeprom setup and tear-down. */
4509 data[i] = e1000_shift_in_ee_bits(hw, 16);
4510 e1000_standby_eeprom(hw);
4514 /* End this read operation */
4515 e1000_release_eeprom(hw);
4517 return E1000_SUCCESS;
4520 /******************************************************************************
4521 * Reads a 16 bit word from the EEPROM using the EERD register.
4523 * hw - Struct containing variables accessed by shared code
4524 * offset - offset of word in the EEPROM to read
4525 * data - word read from the EEPROM
4526 * words - number of words to read
4527 *****************************************************************************/
4529 e1000_read_eeprom_eerd(struct e1000_hw *hw,
4534 uint32_t i, eerd = 0;
4537 for (i = 0; i < words; i++) {
4538 eerd = ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) +
4539 E1000_EEPROM_RW_REG_START;
4541 E1000_WRITE_REG(hw, EERD, eerd);
4542 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_READ);
4547 data[i] = (E1000_READ_REG(hw, EERD) >> E1000_EEPROM_RW_REG_DATA);
4554 /******************************************************************************
4555 * Writes a 16 bit word from the EEPROM using the EEWR register.
4557 * hw - Struct containing variables accessed by shared code
4558 * offset - offset of word in the EEPROM to read
4559 * data - word read from the EEPROM
4560 * words - number of words to read
4561 *****************************************************************************/
4563 e1000_write_eeprom_eewr(struct e1000_hw *hw,
4568 uint32_t register_value = 0;
4572 if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
4573 return -E1000_ERR_SWFW_SYNC;
4575 for (i = 0; i < words; i++) {
4576 register_value = (data[i] << E1000_EEPROM_RW_REG_DATA) |
4577 ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) |
4578 E1000_EEPROM_RW_REG_START;
4580 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
4585 E1000_WRITE_REG(hw, EEWR, register_value);
4587 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
4594 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
4598 /******************************************************************************
4599 * Polls the status bit (bit 1) of the EERD to determine when the read is done.
4601 * hw - Struct containing variables accessed by shared code
4602 *****************************************************************************/
4604 e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd)
4606 uint32_t attempts = 100000;
4607 uint32_t i, reg = 0;
4608 int32_t done = E1000_ERR_EEPROM;
4610 for(i = 0; i < attempts; i++) {
4611 if(eerd == E1000_EEPROM_POLL_READ)
4612 reg = E1000_READ_REG(hw, EERD);
4614 reg = E1000_READ_REG(hw, EEWR);
4616 if(reg & E1000_EEPROM_RW_REG_DONE) {
4617 done = E1000_SUCCESS;
4626 /***************************************************************************
4627 * Description: Determines if the onboard NVM is FLASH or EEPROM.
4629 * hw - Struct containing variables accessed by shared code
4630 ****************************************************************************/
4632 e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw)
4636 DEBUGFUNC("e1000_is_onboard_nvm_eeprom");
4638 if(hw->mac_type == e1000_82573) {
4639 eecd = E1000_READ_REG(hw, EECD);
4641 /* Isolate bits 15 & 16 */
4642 eecd = ((eecd >> 15) & 0x03);
4644 /* If both bits are set, device is Flash type */
4652 /******************************************************************************
4653 * Verifies that the EEPROM has a valid checksum
4655 * hw - Struct containing variables accessed by shared code
4657 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
4658 * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
4660 *****************************************************************************/
4662 e1000_validate_eeprom_checksum(struct e1000_hw *hw)
4664 uint16_t checksum = 0;
4665 uint16_t i, eeprom_data;
4667 DEBUGFUNC("e1000_validate_eeprom_checksum");
4669 if ((hw->mac_type == e1000_82573) &&
4670 (e1000_is_onboard_nvm_eeprom(hw) == FALSE)) {
4671 /* Check bit 4 of word 10h. If it is 0, firmware is done updating
4672 * 10h-12h. Checksum may need to be fixed. */
4673 e1000_read_eeprom(hw, 0x10, 1, &eeprom_data);
4674 if ((eeprom_data & 0x10) == 0) {
4675 /* Read 0x23 and check bit 15. This bit is a 1 when the checksum
4676 * has already been fixed. If the checksum is still wrong and this
4677 * bit is a 1, we need to return bad checksum. Otherwise, we need
4678 * to set this bit to a 1 and update the checksum. */
4679 e1000_read_eeprom(hw, 0x23, 1, &eeprom_data);
4680 if ((eeprom_data & 0x8000) == 0) {
4681 eeprom_data |= 0x8000;
4682 e1000_write_eeprom(hw, 0x23, 1, &eeprom_data);
4683 e1000_update_eeprom_checksum(hw);
4688 for(i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
4689 if(e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
4690 DEBUGOUT("EEPROM Read Error\n");
4691 return -E1000_ERR_EEPROM;
4693 checksum += eeprom_data;
4696 if(checksum == (uint16_t) EEPROM_SUM)
4697 return E1000_SUCCESS;
4699 DEBUGOUT("EEPROM Checksum Invalid\n");
4700 return -E1000_ERR_EEPROM;
4704 /******************************************************************************
4705 * Calculates the EEPROM checksum and writes it to the EEPROM
4707 * hw - Struct containing variables accessed by shared code
4709 * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA.
4710 * Writes the difference to word offset 63 of the EEPROM.
4711 *****************************************************************************/
4713 e1000_update_eeprom_checksum(struct e1000_hw *hw)
4715 uint16_t checksum = 0;
4716 uint16_t i, eeprom_data;
4718 DEBUGFUNC("e1000_update_eeprom_checksum");
4720 for(i = 0; i < EEPROM_CHECKSUM_REG; i++) {
4721 if(e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
4722 DEBUGOUT("EEPROM Read Error\n");
4723 return -E1000_ERR_EEPROM;
4725 checksum += eeprom_data;
4727 checksum = (uint16_t) EEPROM_SUM - checksum;
4728 if(e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) {
4729 DEBUGOUT("EEPROM Write Error\n");
4730 return -E1000_ERR_EEPROM;
4731 } else if (hw->eeprom.type == e1000_eeprom_flash) {
4732 e1000_commit_shadow_ram(hw);
4734 return E1000_SUCCESS;
4737 /******************************************************************************
4738 * Parent function for writing words to the different EEPROM types.
4740 * hw - Struct containing variables accessed by shared code
4741 * offset - offset within the EEPROM to be written to
4742 * words - number of words to write
4743 * data - 16 bit word to be written to the EEPROM
4745 * If e1000_update_eeprom_checksum is not called after this function, the
4746 * EEPROM will most likely contain an invalid checksum.
4747 *****************************************************************************/
4749 e1000_write_eeprom(struct e1000_hw *hw,
4754 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4757 DEBUGFUNC("e1000_write_eeprom");
4759 /* A check for invalid values: offset too large, too many words, and not
4762 if((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
4764 DEBUGOUT("\"words\" parameter out of bounds\n");
4765 return -E1000_ERR_EEPROM;
4768 /* 82573 writes only through eewr */
4769 if(eeprom->use_eewr == TRUE)
4770 return e1000_write_eeprom_eewr(hw, offset, words, data);
4772 /* Prepare the EEPROM for writing */
4773 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
4774 return -E1000_ERR_EEPROM;
4776 if(eeprom->type == e1000_eeprom_microwire) {
4777 status = e1000_write_eeprom_microwire(hw, offset, words, data);
4779 status = e1000_write_eeprom_spi(hw, offset, words, data);
4783 /* Done with writing */
4784 e1000_release_eeprom(hw);
4789 /******************************************************************************
4790 * Writes a 16 bit word to a given offset in an SPI EEPROM.
4792 * hw - Struct containing variables accessed by shared code
4793 * offset - offset within the EEPROM to be written to
4794 * words - number of words to write
4795 * data - pointer to array of 8 bit words to be written to the EEPROM
4797 *****************************************************************************/
4799 e1000_write_eeprom_spi(struct e1000_hw *hw,
4804 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4807 DEBUGFUNC("e1000_write_eeprom_spi");
4809 while (widx < words) {
4810 uint8_t write_opcode = EEPROM_WRITE_OPCODE_SPI;
4812 if(e1000_spi_eeprom_ready(hw)) return -E1000_ERR_EEPROM;
4814 e1000_standby_eeprom(hw);
4816 /* Send the WRITE ENABLE command (8 bit opcode ) */
4817 e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI,
4818 eeprom->opcode_bits);
4820 e1000_standby_eeprom(hw);
4822 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
4823 if((eeprom->address_bits == 8) && (offset >= 128))
4824 write_opcode |= EEPROM_A8_OPCODE_SPI;
4826 /* Send the Write command (8-bit opcode + addr) */
4827 e1000_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits);
4829 e1000_shift_out_ee_bits(hw, (uint16_t)((offset + widx)*2),
4830 eeprom->address_bits);
4834 /* Loop to allow for up to whole page write (32 bytes) of eeprom */
4835 while (widx < words) {
4836 uint16_t word_out = data[widx];
4837 word_out = (word_out >> 8) | (word_out << 8);
4838 e1000_shift_out_ee_bits(hw, word_out, 16);
4841 /* Some larger eeprom sizes are capable of a 32-byte PAGE WRITE
4842 * operation, while the smaller eeproms are capable of an 8-byte
4843 * PAGE WRITE operation. Break the inner loop to pass new address
4845 if((((offset + widx)*2) % eeprom->page_size) == 0) {
4846 e1000_standby_eeprom(hw);
4852 return E1000_SUCCESS;
4855 /******************************************************************************
4856 * Writes a 16 bit word to a given offset in a Microwire EEPROM.
4858 * hw - Struct containing variables accessed by shared code
4859 * offset - offset within the EEPROM to be written to
4860 * words - number of words to write
4861 * data - pointer to array of 16 bit words to be written to the EEPROM
4863 *****************************************************************************/
4865 e1000_write_eeprom_microwire(struct e1000_hw *hw,
4870 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4872 uint16_t words_written = 0;
4875 DEBUGFUNC("e1000_write_eeprom_microwire");
4877 /* Send the write enable command to the EEPROM (3-bit opcode plus
4878 * 6/8-bit dummy address beginning with 11). It's less work to include
4879 * the 11 of the dummy address as part of the opcode than it is to shift
4880 * it over the correct number of bits for the address. This puts the
4881 * EEPROM into write/erase mode.
4883 e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE,
4884 (uint16_t)(eeprom->opcode_bits + 2));
4886 e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
4888 /* Prepare the EEPROM */
4889 e1000_standby_eeprom(hw);
4891 while (words_written < words) {
4892 /* Send the Write command (3-bit opcode + addr) */
4893 e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE,
4894 eeprom->opcode_bits);
4896 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + words_written),
4897 eeprom->address_bits);
4900 e1000_shift_out_ee_bits(hw, data[words_written], 16);
4902 /* Toggle the CS line. This in effect tells the EEPROM to execute
4903 * the previous command.
4905 e1000_standby_eeprom(hw);
4907 /* Read DO repeatedly until it is high (equal to '1'). The EEPROM will
4908 * signal that the command has been completed by raising the DO signal.
4909 * If DO does not go high in 10 milliseconds, then error out.
4911 for(i = 0; i < 200; i++) {
4912 eecd = E1000_READ_REG(hw, EECD);
4913 if(eecd & E1000_EECD_DO) break;
4917 DEBUGOUT("EEPROM Write did not complete\n");
4918 return -E1000_ERR_EEPROM;
4921 /* Recover from write */
4922 e1000_standby_eeprom(hw);
4927 /* Send the write disable command to the EEPROM (3-bit opcode plus
4928 * 6/8-bit dummy address beginning with 10). It's less work to include
4929 * the 10 of the dummy address as part of the opcode than it is to shift
4930 * it over the correct number of bits for the address. This takes the
4931 * EEPROM out of write/erase mode.
4933 e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE,
4934 (uint16_t)(eeprom->opcode_bits + 2));
4936 e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
4938 return E1000_SUCCESS;
4941 /******************************************************************************
4942 * Flushes the cached eeprom to NVM. This is done by saving the modified values
4943 * in the eeprom cache and the non modified values in the currently active bank
4946 * hw - Struct containing variables accessed by shared code
4947 * offset - offset of word in the EEPROM to read
4948 * data - word read from the EEPROM
4949 * words - number of words to read
4950 *****************************************************************************/
4952 e1000_commit_shadow_ram(struct e1000_hw *hw)
4954 uint32_t attempts = 100000;
4958 int32_t error = E1000_SUCCESS;
4960 /* The flop register will be used to determine if flash type is STM */
4961 flop = E1000_READ_REG(hw, FLOP);
4963 if (hw->mac_type == e1000_82573) {
4964 for (i=0; i < attempts; i++) {
4965 eecd = E1000_READ_REG(hw, EECD);
4966 if ((eecd & E1000_EECD_FLUPD) == 0) {
4972 if (i == attempts) {
4973 return -E1000_ERR_EEPROM;
4976 /* If STM opcode located in bits 15:8 of flop, reset firmware */
4977 if ((flop & 0xFF00) == E1000_STM_OPCODE) {
4978 E1000_WRITE_REG(hw, HICR, E1000_HICR_FW_RESET);
4981 /* Perform the flash update */
4982 E1000_WRITE_REG(hw, EECD, eecd | E1000_EECD_FLUPD);
4984 for (i=0; i < attempts; i++) {
4985 eecd = E1000_READ_REG(hw, EECD);
4986 if ((eecd & E1000_EECD_FLUPD) == 0) {
4992 if (i == attempts) {
4993 return -E1000_ERR_EEPROM;
5000 /******************************************************************************
5001 * Reads the adapter's part number from the EEPROM
5003 * hw - Struct containing variables accessed by shared code
5004 * part_num - Adapter's part number
5005 *****************************************************************************/
5007 e1000_read_part_num(struct e1000_hw *hw,
5010 uint16_t offset = EEPROM_PBA_BYTE_1;
5011 uint16_t eeprom_data;
5013 DEBUGFUNC("e1000_read_part_num");
5015 /* Get word 0 from EEPROM */
5016 if(e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
5017 DEBUGOUT("EEPROM Read Error\n");
5018 return -E1000_ERR_EEPROM;
5020 /* Save word 0 in upper half of part_num */
5021 *part_num = (uint32_t) (eeprom_data << 16);
5023 /* Get word 1 from EEPROM */
5024 if(e1000_read_eeprom(hw, ++offset, 1, &eeprom_data) < 0) {
5025 DEBUGOUT("EEPROM Read Error\n");
5026 return -E1000_ERR_EEPROM;
5028 /* Save word 1 in lower half of part_num */
5029 *part_num |= eeprom_data;
5031 return E1000_SUCCESS;
5034 /******************************************************************************
5035 * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
5036 * second function of dual function devices
5038 * hw - Struct containing variables accessed by shared code
5039 *****************************************************************************/
5041 e1000_read_mac_addr(struct e1000_hw * hw)
5044 uint16_t eeprom_data, i;
5046 DEBUGFUNC("e1000_read_mac_addr");
5048 for(i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
5050 if(e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
5051 DEBUGOUT("EEPROM Read Error\n");
5052 return -E1000_ERR_EEPROM;
5054 hw->perm_mac_addr[i] = (uint8_t) (eeprom_data & 0x00FF);
5055 hw->perm_mac_addr[i+1] = (uint8_t) (eeprom_data >> 8);
5058 switch (hw->mac_type) {
5062 case e1000_82546_rev_3:
5064 case e1000_80003es2lan:
5065 if(E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
5066 hw->perm_mac_addr[5] ^= 0x01;
5070 for(i = 0; i < NODE_ADDRESS_SIZE; i++)
5071 hw->mac_addr[i] = hw->perm_mac_addr[i];
5072 return E1000_SUCCESS;
5075 /******************************************************************************
5076 * Initializes receive address filters.
5078 * hw - Struct containing variables accessed by shared code
5080 * Places the MAC address in receive address register 0 and clears the rest
5081 * of the receive addresss registers. Clears the multicast table. Assumes
5082 * the receiver is in reset when the routine is called.
5083 *****************************************************************************/
5085 e1000_init_rx_addrs(struct e1000_hw *hw)
5090 DEBUGFUNC("e1000_init_rx_addrs");
5092 /* Setup the receive address. */
5093 DEBUGOUT("Programming MAC Address into RAR[0]\n");
5095 e1000_rar_set(hw, hw->mac_addr, 0);
5097 rar_num = E1000_RAR_ENTRIES;
5099 /* Reserve a spot for the Locally Administered Address to work around
5100 * an 82571 issue in which a reset on one port will reload the MAC on
5101 * the other port. */
5102 if ((hw->mac_type == e1000_82571) && (hw->laa_is_present == TRUE))
5104 /* Zero out the other 15 receive addresses. */
5105 DEBUGOUT("Clearing RAR[1-15]\n");
5106 for(i = 1; i < rar_num; i++) {
5107 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
5108 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
5113 /******************************************************************************
5114 * Updates the MAC's list of multicast addresses.
5116 * hw - Struct containing variables accessed by shared code
5117 * mc_addr_list - the list of new multicast addresses
5118 * mc_addr_count - number of addresses
5119 * pad - number of bytes between addresses in the list
5120 * rar_used_count - offset where to start adding mc addresses into the RAR's
5122 * The given list replaces any existing list. Clears the last 15 receive
5123 * address registers and the multicast table. Uses receive address registers
5124 * for the first 15 multicast addresses, and hashes the rest into the
5126 *****************************************************************************/
5128 e1000_mc_addr_list_update(struct e1000_hw *hw,
5129 uint8_t *mc_addr_list,
5130 uint32_t mc_addr_count,
5132 uint32_t rar_used_count)
5134 uint32_t hash_value;
5136 uint32_t num_rar_entry;
5137 uint32_t num_mta_entry;
5139 DEBUGFUNC("e1000_mc_addr_list_update");
5141 /* Set the new number of MC addresses that we are being requested to use. */
5142 hw->num_mc_addrs = mc_addr_count;
5144 /* Clear RAR[1-15] */
5145 DEBUGOUT(" Clearing RAR[1-15]\n");
5146 num_rar_entry = E1000_RAR_ENTRIES;
5147 /* Reserve a spot for the Locally Administered Address to work around
5148 * an 82571 issue in which a reset on one port will reload the MAC on
5149 * the other port. */
5150 if ((hw->mac_type == e1000_82571) && (hw->laa_is_present == TRUE))
5153 for(i = rar_used_count; i < num_rar_entry; i++) {
5154 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
5155 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
5159 DEBUGOUT(" Clearing MTA\n");
5160 num_mta_entry = E1000_NUM_MTA_REGISTERS;
5161 for(i = 0; i < num_mta_entry; i++) {
5162 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
5165 /* Add the new addresses */
5166 for(i = 0; i < mc_addr_count; i++) {
5167 DEBUGOUT(" Adding the multicast addresses:\n");
5168 DEBUGOUT7(" MC Addr #%d =%.2X %.2X %.2X %.2X %.2X %.2X\n", i,
5169 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad)],
5170 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 1],
5171 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 2],
5172 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 3],
5173 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 4],
5174 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 5]);
5176 hash_value = e1000_hash_mc_addr(hw,
5178 (i * (ETH_LENGTH_OF_ADDRESS + pad)));
5180 DEBUGOUT1(" Hash value = 0x%03X\n", hash_value);
5182 /* Place this multicast address in the RAR if there is room, *
5183 * else put it in the MTA
5185 if (rar_used_count < num_rar_entry) {
5187 mc_addr_list + (i * (ETH_LENGTH_OF_ADDRESS + pad)),
5191 e1000_mta_set(hw, hash_value);
5194 DEBUGOUT("MC Update Complete\n");
5198 /******************************************************************************
5199 * Hashes an address to determine its location in the multicast table
5201 * hw - Struct containing variables accessed by shared code
5202 * mc_addr - the multicast address to hash
5203 *****************************************************************************/
5205 e1000_hash_mc_addr(struct e1000_hw *hw,
5208 uint32_t hash_value = 0;
5210 /* The portion of the address that is used for the hash table is
5211 * determined by the mc_filter_type setting.
5213 switch (hw->mc_filter_type) {
5214 /* [0] [1] [2] [3] [4] [5]
5219 /* [47:36] i.e. 0x563 for above example address */
5220 hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4));
5223 /* [46:35] i.e. 0xAC6 for above example address */
5224 hash_value = ((mc_addr[4] >> 3) | (((uint16_t) mc_addr[5]) << 5));
5227 /* [45:34] i.e. 0x5D8 for above example address */
5228 hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6));
5231 /* [43:32] i.e. 0x634 for above example address */
5232 hash_value = ((mc_addr[4]) | (((uint16_t) mc_addr[5]) << 8));
5236 hash_value &= 0xFFF;
5241 /******************************************************************************
5242 * Sets the bit in the multicast table corresponding to the hash value.
5244 * hw - Struct containing variables accessed by shared code
5245 * hash_value - Multicast address hash value
5246 *****************************************************************************/
5248 e1000_mta_set(struct e1000_hw *hw,
5249 uint32_t hash_value)
5251 uint32_t hash_bit, hash_reg;
5255 /* The MTA is a register array of 128 32-bit registers.
5256 * It is treated like an array of 4096 bits. We want to set
5257 * bit BitArray[hash_value]. So we figure out what register
5258 * the bit is in, read it, OR in the new bit, then write
5259 * back the new value. The register is determined by the
5260 * upper 7 bits of the hash value and the bit within that
5261 * register are determined by the lower 5 bits of the value.
5263 hash_reg = (hash_value >> 5) & 0x7F;
5264 hash_bit = hash_value & 0x1F;
5266 mta = E1000_READ_REG_ARRAY(hw, MTA, hash_reg);
5268 mta |= (1 << hash_bit);
5270 /* If we are on an 82544 and we are trying to write an odd offset
5271 * in the MTA, save off the previous entry before writing and
5272 * restore the old value after writing.
5274 if((hw->mac_type == e1000_82544) && ((hash_reg & 0x1) == 1)) {
5275 temp = E1000_READ_REG_ARRAY(hw, MTA, (hash_reg - 1));
5276 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
5277 E1000_WRITE_REG_ARRAY(hw, MTA, (hash_reg - 1), temp);
5279 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
5283 /******************************************************************************
5284 * Puts an ethernet address into a receive address register.
5286 * hw - Struct containing variables accessed by shared code
5287 * addr - Address to put into receive address register
5288 * index - Receive address register to write
5289 *****************************************************************************/
5291 e1000_rar_set(struct e1000_hw *hw,
5295 uint32_t rar_low, rar_high;
5297 /* HW expects these in little endian so we reverse the byte order
5298 * from network order (big endian) to little endian
5300 rar_low = ((uint32_t) addr[0] |
5301 ((uint32_t) addr[1] << 8) |
5302 ((uint32_t) addr[2] << 16) | ((uint32_t) addr[3] << 24));
5303 rar_high = ((uint32_t) addr[4] | ((uint32_t) addr[5] << 8));
5305 /* Disable Rx and flush all Rx frames before enabling RSS to avoid Rx
5309 * If there are any Rx frames queued up or otherwise present in the HW
5310 * before RSS is enabled, and then we enable RSS, the HW Rx unit will
5311 * hang. To work around this issue, we have to disable receives and
5312 * flush out all Rx frames before we enable RSS. To do so, we modify we
5313 * redirect all Rx traffic to manageability and then reset the HW.
5314 * This flushes away Rx frames, and (since the redirections to
5315 * manageability persists across resets) keeps new ones from coming in
5316 * while we work. Then, we clear the Address Valid AV bit for all MAC
5317 * addresses and undo the re-direction to manageability.
5318 * Now, frames are coming in again, but the MAC won't accept them, so
5319 * far so good. We now proceed to initialize RSS (if necessary) and
5320 * configure the Rx unit. Last, we re-enable the AV bits and continue
5323 switch (hw->mac_type) {
5326 case e1000_80003es2lan:
5327 if (hw->leave_av_bit_off == TRUE)
5330 /* Indicate to hardware the Address is Valid. */
5331 rar_high |= E1000_RAH_AV;
5335 E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
5336 E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
5339 /******************************************************************************
5340 * Writes a value to the specified offset in the VLAN filter table.
5342 * hw - Struct containing variables accessed by shared code
5343 * offset - Offset in VLAN filer table to write
5344 * value - Value to write into VLAN filter table
5345 *****************************************************************************/
5347 e1000_write_vfta(struct e1000_hw *hw,
5353 if((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) {
5354 temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1));
5355 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
5356 E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp);
5358 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
5362 /******************************************************************************
5363 * Clears the VLAN filer table
5365 * hw - Struct containing variables accessed by shared code
5366 *****************************************************************************/
5368 e1000_clear_vfta(struct e1000_hw *hw)
5371 uint32_t vfta_value = 0;
5372 uint32_t vfta_offset = 0;
5373 uint32_t vfta_bit_in_reg = 0;
5375 if (hw->mac_type == e1000_82573) {
5376 if (hw->mng_cookie.vlan_id != 0) {
5377 /* The VFTA is a 4096b bit-field, each identifying a single VLAN
5378 * ID. The following operations determine which 32b entry
5379 * (i.e. offset) into the array we want to set the VLAN ID
5380 * (i.e. bit) of the manageability unit. */
5381 vfta_offset = (hw->mng_cookie.vlan_id >>
5382 E1000_VFTA_ENTRY_SHIFT) &
5383 E1000_VFTA_ENTRY_MASK;
5384 vfta_bit_in_reg = 1 << (hw->mng_cookie.vlan_id &
5385 E1000_VFTA_ENTRY_BIT_SHIFT_MASK);
5388 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
5389 /* If the offset we want to clear is the same offset of the
5390 * manageability VLAN ID, then clear all bits except that of the
5391 * manageability unit */
5392 vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0;
5393 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, vfta_value);
5398 e1000_id_led_init(struct e1000_hw * hw)
5401 const uint32_t ledctl_mask = 0x000000FF;
5402 const uint32_t ledctl_on = E1000_LEDCTL_MODE_LED_ON;
5403 const uint32_t ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
5404 uint16_t eeprom_data, i, temp;
5405 const uint16_t led_mask = 0x0F;
5407 DEBUGFUNC("e1000_id_led_init");
5409 if(hw->mac_type < e1000_82540) {
5411 return E1000_SUCCESS;
5414 ledctl = E1000_READ_REG(hw, LEDCTL);
5415 hw->ledctl_default = ledctl;
5416 hw->ledctl_mode1 = hw->ledctl_default;
5417 hw->ledctl_mode2 = hw->ledctl_default;
5419 if(e1000_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, 1, &eeprom_data) < 0) {
5420 DEBUGOUT("EEPROM Read Error\n");
5421 return -E1000_ERR_EEPROM;
5423 if((eeprom_data== ID_LED_RESERVED_0000) ||
5424 (eeprom_data == ID_LED_RESERVED_FFFF)) eeprom_data = ID_LED_DEFAULT;
5425 for(i = 0; i < 4; i++) {
5426 temp = (eeprom_data >> (i << 2)) & led_mask;
5428 case ID_LED_ON1_DEF2:
5429 case ID_LED_ON1_ON2:
5430 case ID_LED_ON1_OFF2:
5431 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
5432 hw->ledctl_mode1 |= ledctl_on << (i << 3);
5434 case ID_LED_OFF1_DEF2:
5435 case ID_LED_OFF1_ON2:
5436 case ID_LED_OFF1_OFF2:
5437 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
5438 hw->ledctl_mode1 |= ledctl_off << (i << 3);
5445 case ID_LED_DEF1_ON2:
5446 case ID_LED_ON1_ON2:
5447 case ID_LED_OFF1_ON2:
5448 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
5449 hw->ledctl_mode2 |= ledctl_on << (i << 3);
5451 case ID_LED_DEF1_OFF2:
5452 case ID_LED_ON1_OFF2:
5453 case ID_LED_OFF1_OFF2:
5454 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
5455 hw->ledctl_mode2 |= ledctl_off << (i << 3);
5462 return E1000_SUCCESS;
5465 /******************************************************************************
5466 * Prepares SW controlable LED for use and saves the current state of the LED.
5468 * hw - Struct containing variables accessed by shared code
5469 *****************************************************************************/
5471 e1000_setup_led(struct e1000_hw *hw)
5474 int32_t ret_val = E1000_SUCCESS;
5476 DEBUGFUNC("e1000_setup_led");
5478 switch(hw->mac_type) {
5479 case e1000_82542_rev2_0:
5480 case e1000_82542_rev2_1:
5483 /* No setup necessary */
5487 case e1000_82541_rev_2:
5488 case e1000_82547_rev_2:
5489 /* Turn off PHY Smart Power Down (if enabled) */
5490 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
5491 &hw->phy_spd_default);
5494 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
5495 (uint16_t)(hw->phy_spd_default &
5496 ~IGP01E1000_GMII_SPD));
5501 if(hw->media_type == e1000_media_type_fiber) {
5502 ledctl = E1000_READ_REG(hw, LEDCTL);
5503 /* Save current LEDCTL settings */
5504 hw->ledctl_default = ledctl;
5506 ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
5507 E1000_LEDCTL_LED0_BLINK |
5508 E1000_LEDCTL_LED0_MODE_MASK);
5509 ledctl |= (E1000_LEDCTL_MODE_LED_OFF <<
5510 E1000_LEDCTL_LED0_MODE_SHIFT);
5511 E1000_WRITE_REG(hw, LEDCTL, ledctl);
5512 } else if(hw->media_type == e1000_media_type_copper)
5513 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
5517 return E1000_SUCCESS;
5520 /******************************************************************************
5521 * Restores the saved state of the SW controlable LED.
5523 * hw - Struct containing variables accessed by shared code
5524 *****************************************************************************/
5526 e1000_cleanup_led(struct e1000_hw *hw)
5528 int32_t ret_val = E1000_SUCCESS;
5530 DEBUGFUNC("e1000_cleanup_led");
5532 switch(hw->mac_type) {
5533 case e1000_82542_rev2_0:
5534 case e1000_82542_rev2_1:
5537 /* No cleanup necessary */
5541 case e1000_82541_rev_2:
5542 case e1000_82547_rev_2:
5543 /* Turn on PHY Smart Power Down (if previously enabled) */
5544 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
5545 hw->phy_spd_default);
5550 /* Restore LEDCTL settings */
5551 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_default);
5555 return E1000_SUCCESS;
5558 /******************************************************************************
5559 * Turns on the software controllable LED
5561 * hw - Struct containing variables accessed by shared code
5562 *****************************************************************************/
5564 e1000_led_on(struct e1000_hw *hw)
5566 uint32_t ctrl = E1000_READ_REG(hw, CTRL);
5568 DEBUGFUNC("e1000_led_on");
5570 switch(hw->mac_type) {
5571 case e1000_82542_rev2_0:
5572 case e1000_82542_rev2_1:
5574 /* Set SW Defineable Pin 0 to turn on the LED */
5575 ctrl |= E1000_CTRL_SWDPIN0;
5576 ctrl |= E1000_CTRL_SWDPIO0;
5579 if(hw->media_type == e1000_media_type_fiber) {
5580 /* Set SW Defineable Pin 0 to turn on the LED */
5581 ctrl |= E1000_CTRL_SWDPIN0;
5582 ctrl |= E1000_CTRL_SWDPIO0;
5584 /* Clear SW Defineable Pin 0 to turn on the LED */
5585 ctrl &= ~E1000_CTRL_SWDPIN0;
5586 ctrl |= E1000_CTRL_SWDPIO0;
5590 if(hw->media_type == e1000_media_type_fiber) {
5591 /* Clear SW Defineable Pin 0 to turn on the LED */
5592 ctrl &= ~E1000_CTRL_SWDPIN0;
5593 ctrl |= E1000_CTRL_SWDPIO0;
5594 } else if(hw->media_type == e1000_media_type_copper) {
5595 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode2);
5596 return E1000_SUCCESS;
5601 E1000_WRITE_REG(hw, CTRL, ctrl);
5603 return E1000_SUCCESS;
5606 /******************************************************************************
5607 * Turns off the software controllable LED
5609 * hw - Struct containing variables accessed by shared code
5610 *****************************************************************************/
5612 e1000_led_off(struct e1000_hw *hw)
5614 uint32_t ctrl = E1000_READ_REG(hw, CTRL);
5616 DEBUGFUNC("e1000_led_off");
5618 switch(hw->mac_type) {
5619 case e1000_82542_rev2_0:
5620 case e1000_82542_rev2_1:
5622 /* Clear SW Defineable Pin 0 to turn off the LED */
5623 ctrl &= ~E1000_CTRL_SWDPIN0;
5624 ctrl |= E1000_CTRL_SWDPIO0;
5627 if(hw->media_type == e1000_media_type_fiber) {
5628 /* Clear SW Defineable Pin 0 to turn off the LED */
5629 ctrl &= ~E1000_CTRL_SWDPIN0;
5630 ctrl |= E1000_CTRL_SWDPIO0;
5632 /* Set SW Defineable Pin 0 to turn off the LED */
5633 ctrl |= E1000_CTRL_SWDPIN0;
5634 ctrl |= E1000_CTRL_SWDPIO0;
5638 if(hw->media_type == e1000_media_type_fiber) {
5639 /* Set SW Defineable Pin 0 to turn off the LED */
5640 ctrl |= E1000_CTRL_SWDPIN0;
5641 ctrl |= E1000_CTRL_SWDPIO0;
5642 } else if(hw->media_type == e1000_media_type_copper) {
5643 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
5644 return E1000_SUCCESS;
5649 E1000_WRITE_REG(hw, CTRL, ctrl);
5651 return E1000_SUCCESS;
5654 /******************************************************************************
5655 * Clears all hardware statistics counters.
5657 * hw - Struct containing variables accessed by shared code
5658 *****************************************************************************/
5660 e1000_clear_hw_cntrs(struct e1000_hw *hw)
5662 volatile uint32_t temp;
5664 temp = E1000_READ_REG(hw, CRCERRS);
5665 temp = E1000_READ_REG(hw, SYMERRS);
5666 temp = E1000_READ_REG(hw, MPC);
5667 temp = E1000_READ_REG(hw, SCC);
5668 temp = E1000_READ_REG(hw, ECOL);
5669 temp = E1000_READ_REG(hw, MCC);
5670 temp = E1000_READ_REG(hw, LATECOL);
5671 temp = E1000_READ_REG(hw, COLC);
5672 temp = E1000_READ_REG(hw, DC);
5673 temp = E1000_READ_REG(hw, SEC);
5674 temp = E1000_READ_REG(hw, RLEC);
5675 temp = E1000_READ_REG(hw, XONRXC);
5676 temp = E1000_READ_REG(hw, XONTXC);
5677 temp = E1000_READ_REG(hw, XOFFRXC);
5678 temp = E1000_READ_REG(hw, XOFFTXC);
5679 temp = E1000_READ_REG(hw, FCRUC);
5680 temp = E1000_READ_REG(hw, PRC64);
5681 temp = E1000_READ_REG(hw, PRC127);
5682 temp = E1000_READ_REG(hw, PRC255);
5683 temp = E1000_READ_REG(hw, PRC511);
5684 temp = E1000_READ_REG(hw, PRC1023);
5685 temp = E1000_READ_REG(hw, PRC1522);
5686 temp = E1000_READ_REG(hw, GPRC);
5687 temp = E1000_READ_REG(hw, BPRC);
5688 temp = E1000_READ_REG(hw, MPRC);
5689 temp = E1000_READ_REG(hw, GPTC);
5690 temp = E1000_READ_REG(hw, GORCL);
5691 temp = E1000_READ_REG(hw, GORCH);
5692 temp = E1000_READ_REG(hw, GOTCL);
5693 temp = E1000_READ_REG(hw, GOTCH);
5694 temp = E1000_READ_REG(hw, RNBC);
5695 temp = E1000_READ_REG(hw, RUC);
5696 temp = E1000_READ_REG(hw, RFC);
5697 temp = E1000_READ_REG(hw, ROC);
5698 temp = E1000_READ_REG(hw, RJC);
5699 temp = E1000_READ_REG(hw, TORL);
5700 temp = E1000_READ_REG(hw, TORH);
5701 temp = E1000_READ_REG(hw, TOTL);
5702 temp = E1000_READ_REG(hw, TOTH);
5703 temp = E1000_READ_REG(hw, TPR);
5704 temp = E1000_READ_REG(hw, TPT);
5705 temp = E1000_READ_REG(hw, PTC64);
5706 temp = E1000_READ_REG(hw, PTC127);
5707 temp = E1000_READ_REG(hw, PTC255);
5708 temp = E1000_READ_REG(hw, PTC511);
5709 temp = E1000_READ_REG(hw, PTC1023);
5710 temp = E1000_READ_REG(hw, PTC1522);
5711 temp = E1000_READ_REG(hw, MPTC);
5712 temp = E1000_READ_REG(hw, BPTC);
5714 if(hw->mac_type < e1000_82543) return;
5716 temp = E1000_READ_REG(hw, ALGNERRC);
5717 temp = E1000_READ_REG(hw, RXERRC);
5718 temp = E1000_READ_REG(hw, TNCRS);
5719 temp = E1000_READ_REG(hw, CEXTERR);
5720 temp = E1000_READ_REG(hw, TSCTC);
5721 temp = E1000_READ_REG(hw, TSCTFC);
5723 if(hw->mac_type <= e1000_82544) return;
5725 temp = E1000_READ_REG(hw, MGTPRC);
5726 temp = E1000_READ_REG(hw, MGTPDC);
5727 temp = E1000_READ_REG(hw, MGTPTC);
5729 if(hw->mac_type <= e1000_82547_rev_2) return;
5731 temp = E1000_READ_REG(hw, IAC);
5732 temp = E1000_READ_REG(hw, ICRXOC);
5733 temp = E1000_READ_REG(hw, ICRXPTC);
5734 temp = E1000_READ_REG(hw, ICRXATC);
5735 temp = E1000_READ_REG(hw, ICTXPTC);
5736 temp = E1000_READ_REG(hw, ICTXATC);
5737 temp = E1000_READ_REG(hw, ICTXQEC);
5738 temp = E1000_READ_REG(hw, ICTXQMTC);
5739 temp = E1000_READ_REG(hw, ICRXDMTC);
5742 /******************************************************************************
5743 * Resets Adaptive IFS to its default state.
5745 * hw - Struct containing variables accessed by shared code
5747 * Call this after e1000_init_hw. You may override the IFS defaults by setting
5748 * hw->ifs_params_forced to TRUE. However, you must initialize hw->
5749 * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio
5750 * before calling this function.
5751 *****************************************************************************/
5753 e1000_reset_adaptive(struct e1000_hw *hw)
5755 DEBUGFUNC("e1000_reset_adaptive");
5757 if(hw->adaptive_ifs) {
5758 if(!hw->ifs_params_forced) {
5759 hw->current_ifs_val = 0;
5760 hw->ifs_min_val = IFS_MIN;
5761 hw->ifs_max_val = IFS_MAX;
5762 hw->ifs_step_size = IFS_STEP;
5763 hw->ifs_ratio = IFS_RATIO;
5765 hw->in_ifs_mode = FALSE;
5766 E1000_WRITE_REG(hw, AIT, 0);
5768 DEBUGOUT("Not in Adaptive IFS mode!\n");
5772 /******************************************************************************
5773 * Called during the callback/watchdog routine to update IFS value based on
5774 * the ratio of transmits to collisions.
5776 * hw - Struct containing variables accessed by shared code
5777 * tx_packets - Number of transmits since last callback
5778 * total_collisions - Number of collisions since last callback
5779 *****************************************************************************/
5781 e1000_update_adaptive(struct e1000_hw *hw)
5783 DEBUGFUNC("e1000_update_adaptive");
5785 if(hw->adaptive_ifs) {
5786 if((hw->collision_delta * hw->ifs_ratio) > hw->tx_packet_delta) {
5787 if(hw->tx_packet_delta > MIN_NUM_XMITS) {
5788 hw->in_ifs_mode = TRUE;
5789 if(hw->current_ifs_val < hw->ifs_max_val) {
5790 if(hw->current_ifs_val == 0)
5791 hw->current_ifs_val = hw->ifs_min_val;
5793 hw->current_ifs_val += hw->ifs_step_size;
5794 E1000_WRITE_REG(hw, AIT, hw->current_ifs_val);
5798 if(hw->in_ifs_mode && (hw->tx_packet_delta <= MIN_NUM_XMITS)) {
5799 hw->current_ifs_val = 0;
5800 hw->in_ifs_mode = FALSE;
5801 E1000_WRITE_REG(hw, AIT, 0);
5805 DEBUGOUT("Not in Adaptive IFS mode!\n");
5809 /******************************************************************************
5810 * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT
5812 * hw - Struct containing variables accessed by shared code
5813 * frame_len - The length of the frame in question
5814 * mac_addr - The Ethernet destination address of the frame in question
5815 *****************************************************************************/
5817 e1000_tbi_adjust_stats(struct e1000_hw *hw,
5818 struct e1000_hw_stats *stats,
5824 /* First adjust the frame length. */
5826 /* We need to adjust the statistics counters, since the hardware
5827 * counters overcount this packet as a CRC error and undercount
5828 * the packet as a good packet
5830 /* This packet should not be counted as a CRC error. */
5832 /* This packet does count as a Good Packet Received. */
5835 /* Adjust the Good Octets received counters */
5836 carry_bit = 0x80000000 & stats->gorcl;
5837 stats->gorcl += frame_len;
5838 /* If the high bit of Gorcl (the low 32 bits of the Good Octets
5839 * Received Count) was one before the addition,
5840 * AND it is zero after, then we lost the carry out,
5841 * need to add one to Gorch (Good Octets Received Count High).
5842 * This could be simplified if all environments supported
5845 if(carry_bit && ((stats->gorcl & 0x80000000) == 0))
5847 /* Is this a broadcast or multicast? Check broadcast first,
5848 * since the test for a multicast frame will test positive on
5849 * a broadcast frame.
5851 if((mac_addr[0] == (uint8_t) 0xff) && (mac_addr[1] == (uint8_t) 0xff))
5852 /* Broadcast packet */
5854 else if(*mac_addr & 0x01)
5855 /* Multicast packet */
5858 if(frame_len == hw->max_frame_size) {
5859 /* In this case, the hardware has overcounted the number of
5866 /* Adjust the bin counters when the extra byte put the frame in the
5867 * wrong bin. Remember that the frame_len was adjusted above.
5869 if(frame_len == 64) {
5872 } else if(frame_len == 127) {
5875 } else if(frame_len == 255) {
5878 } else if(frame_len == 511) {
5881 } else if(frame_len == 1023) {
5884 } else if(frame_len == 1522) {
5889 /******************************************************************************
5890 * Gets the current PCI bus type, speed, and width of the hardware
5892 * hw - Struct containing variables accessed by shared code
5893 *****************************************************************************/
5895 e1000_get_bus_info(struct e1000_hw *hw)
5899 switch (hw->mac_type) {
5900 case e1000_82542_rev2_0:
5901 case e1000_82542_rev2_1:
5902 hw->bus_type = e1000_bus_type_unknown;
5903 hw->bus_speed = e1000_bus_speed_unknown;
5904 hw->bus_width = e1000_bus_width_unknown;
5908 hw->bus_type = e1000_bus_type_pci_express;
5909 hw->bus_speed = e1000_bus_speed_2500;
5910 hw->bus_width = e1000_bus_width_pciex_1;
5913 case e1000_80003es2lan:
5914 hw->bus_type = e1000_bus_type_pci_express;
5915 hw->bus_speed = e1000_bus_speed_2500;
5916 hw->bus_width = e1000_bus_width_pciex_4;
5919 status = E1000_READ_REG(hw, STATUS);
5920 hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
5921 e1000_bus_type_pcix : e1000_bus_type_pci;
5923 if(hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) {
5924 hw->bus_speed = (hw->bus_type == e1000_bus_type_pci) ?
5925 e1000_bus_speed_66 : e1000_bus_speed_120;
5926 } else if(hw->bus_type == e1000_bus_type_pci) {
5927 hw->bus_speed = (status & E1000_STATUS_PCI66) ?
5928 e1000_bus_speed_66 : e1000_bus_speed_33;
5930 switch (status & E1000_STATUS_PCIX_SPEED) {
5931 case E1000_STATUS_PCIX_SPEED_66:
5932 hw->bus_speed = e1000_bus_speed_66;
5934 case E1000_STATUS_PCIX_SPEED_100:
5935 hw->bus_speed = e1000_bus_speed_100;
5937 case E1000_STATUS_PCIX_SPEED_133:
5938 hw->bus_speed = e1000_bus_speed_133;
5941 hw->bus_speed = e1000_bus_speed_reserved;
5945 hw->bus_width = (status & E1000_STATUS_BUS64) ?
5946 e1000_bus_width_64 : e1000_bus_width_32;
5952 /******************************************************************************
5953 * Reads a value from one of the devices registers using port I/O (as opposed
5954 * memory mapped I/O). Only 82544 and newer devices support port I/O.
5956 * hw - Struct containing variables accessed by shared code
5957 * offset - offset to read from
5958 *****************************************************************************/
5960 e1000_read_reg_io(struct e1000_hw *hw,
5963 unsigned long io_addr = hw->io_base;
5964 unsigned long io_data = hw->io_base + 4;
5966 e1000_io_write(hw, io_addr, offset);
5967 return e1000_io_read(hw, io_data);
5971 /******************************************************************************
5972 * Writes a value to one of the devices registers using port I/O (as opposed to
5973 * memory mapped I/O). Only 82544 and newer devices support port I/O.
5975 * hw - Struct containing variables accessed by shared code
5976 * offset - offset to write to
5977 * value - value to write
5978 *****************************************************************************/
5980 e1000_write_reg_io(struct e1000_hw *hw,
5984 unsigned long io_addr = hw->io_base;
5985 unsigned long io_data = hw->io_base + 4;
5987 e1000_io_write(hw, io_addr, offset);
5988 e1000_io_write(hw, io_data, value);
5992 /******************************************************************************
5993 * Estimates the cable length.
5995 * hw - Struct containing variables accessed by shared code
5996 * min_length - The estimated minimum length
5997 * max_length - The estimated maximum length
5999 * returns: - E1000_ERR_XXX
6002 * This function always returns a ranged length (minimum & maximum).
6003 * So for M88 phy's, this function interprets the one value returned from the
6004 * register to the minimum and maximum range.
6005 * For IGP phy's, the function calculates the range by the AGC registers.
6006 *****************************************************************************/
6008 e1000_get_cable_length(struct e1000_hw *hw,
6009 uint16_t *min_length,
6010 uint16_t *max_length)
6013 uint16_t agc_value = 0;
6014 uint16_t cur_agc, min_agc = IGP01E1000_AGC_LENGTH_TABLE_SIZE;
6015 uint16_t max_agc = 0;
6016 uint16_t i, phy_data;
6017 uint16_t cable_length;
6019 DEBUGFUNC("e1000_get_cable_length");
6021 *min_length = *max_length = 0;
6023 /* Use old method for Phy older than IGP */
6024 if(hw->phy_type == e1000_phy_m88) {
6026 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6030 cable_length = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
6031 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
6033 /* Convert the enum value to ranged values */
6034 switch (cable_length) {
6035 case e1000_cable_length_50:
6037 *max_length = e1000_igp_cable_length_50;
6039 case e1000_cable_length_50_80:
6040 *min_length = e1000_igp_cable_length_50;
6041 *max_length = e1000_igp_cable_length_80;
6043 case e1000_cable_length_80_110:
6044 *min_length = e1000_igp_cable_length_80;
6045 *max_length = e1000_igp_cable_length_110;
6047 case e1000_cable_length_110_140:
6048 *min_length = e1000_igp_cable_length_110;
6049 *max_length = e1000_igp_cable_length_140;
6051 case e1000_cable_length_140:
6052 *min_length = e1000_igp_cable_length_140;
6053 *max_length = e1000_igp_cable_length_170;
6056 return -E1000_ERR_PHY;
6059 } else if (hw->phy_type == e1000_phy_gg82563) {
6060 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_DSP_DISTANCE,
6064 cable_length = phy_data & GG82563_DSPD_CABLE_LENGTH;
6066 switch (cable_length) {
6067 case e1000_gg_cable_length_60:
6069 *max_length = e1000_igp_cable_length_60;
6071 case e1000_gg_cable_length_60_115:
6072 *min_length = e1000_igp_cable_length_60;
6073 *max_length = e1000_igp_cable_length_115;
6075 case e1000_gg_cable_length_115_150:
6076 *min_length = e1000_igp_cable_length_115;
6077 *max_length = e1000_igp_cable_length_150;
6079 case e1000_gg_cable_length_150:
6080 *min_length = e1000_igp_cable_length_150;
6081 *max_length = e1000_igp_cable_length_180;
6084 return -E1000_ERR_PHY;
6087 } else if(hw->phy_type == e1000_phy_igp) { /* For IGP PHY */
6088 uint16_t agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
6089 {IGP01E1000_PHY_AGC_A,
6090 IGP01E1000_PHY_AGC_B,
6091 IGP01E1000_PHY_AGC_C,
6092 IGP01E1000_PHY_AGC_D};
6093 /* Read the AGC registers for all channels */
6094 for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
6096 ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
6100 cur_agc = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT;
6102 /* Array bound check. */
6103 if((cur_agc >= IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1) ||
6105 return -E1000_ERR_PHY;
6107 agc_value += cur_agc;
6109 /* Update minimal AGC value. */
6110 if(min_agc > cur_agc)
6114 /* Remove the minimal AGC result for length < 50m */
6115 if(agc_value < IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) {
6116 agc_value -= min_agc;
6118 /* Get the average length of the remaining 3 channels */
6119 agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1);
6121 /* Get the average length of all the 4 channels. */
6122 agc_value /= IGP01E1000_PHY_CHANNEL_NUM;
6125 /* Set the range of the calculated length. */
6126 *min_length = ((e1000_igp_cable_length_table[agc_value] -
6127 IGP01E1000_AGC_RANGE) > 0) ?
6128 (e1000_igp_cable_length_table[agc_value] -
6129 IGP01E1000_AGC_RANGE) : 0;
6130 *max_length = e1000_igp_cable_length_table[agc_value] +
6131 IGP01E1000_AGC_RANGE;
6132 } else if (hw->phy_type == e1000_phy_igp_2) {
6133 uint16_t agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] =
6134 {IGP02E1000_PHY_AGC_A,
6135 IGP02E1000_PHY_AGC_B,
6136 IGP02E1000_PHY_AGC_C,
6137 IGP02E1000_PHY_AGC_D};
6138 /* Read the AGC registers for all channels */
6139 for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
6140 ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
6144 /* Getting bits 15:9, which represent the combination of course and
6145 * fine gain values. The result is a number that can be put into
6146 * the lookup table to obtain the approximate cable length. */
6147 cur_agc = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
6148 IGP02E1000_AGC_LENGTH_MASK;
6150 /* Remove min & max AGC values from calculation. */
6151 if (e1000_igp_2_cable_length_table[min_agc] > e1000_igp_2_cable_length_table[cur_agc])
6153 if (e1000_igp_2_cable_length_table[max_agc] < e1000_igp_2_cable_length_table[cur_agc])
6156 agc_value += e1000_igp_2_cable_length_table[cur_agc];
6159 agc_value -= (e1000_igp_2_cable_length_table[min_agc] + e1000_igp_2_cable_length_table[max_agc]);
6160 agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
6162 /* Calculate cable length with the error range of +/- 10 meters. */
6163 *min_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
6164 (agc_value - IGP02E1000_AGC_RANGE) : 0;
6165 *max_length = agc_value + IGP02E1000_AGC_RANGE;
6168 return E1000_SUCCESS;
6171 /******************************************************************************
6172 * Check the cable polarity
6174 * hw - Struct containing variables accessed by shared code
6175 * polarity - output parameter : 0 - Polarity is not reversed
6176 * 1 - Polarity is reversed.
6178 * returns: - E1000_ERR_XXX
6181 * For phy's older then IGP, this function simply reads the polarity bit in the
6182 * Phy Status register. For IGP phy's, this bit is valid only if link speed is
6183 * 10 Mbps. If the link speed is 100 Mbps there is no polarity so this bit will
6184 * return 0. If the link speed is 1000 Mbps the polarity status is in the
6185 * IGP01E1000_PHY_PCS_INIT_REG.
6186 *****************************************************************************/
6188 e1000_check_polarity(struct e1000_hw *hw,
6194 DEBUGFUNC("e1000_check_polarity");
6196 if ((hw->phy_type == e1000_phy_m88) ||
6197 (hw->phy_type == e1000_phy_gg82563)) {
6198 /* return the Polarity bit in the Status register. */
6199 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6203 *polarity = (phy_data & M88E1000_PSSR_REV_POLARITY) >>
6204 M88E1000_PSSR_REV_POLARITY_SHIFT;
6205 } else if(hw->phy_type == e1000_phy_igp ||
6206 hw->phy_type == e1000_phy_igp_2) {
6207 /* Read the Status register to check the speed */
6208 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
6213 /* If speed is 1000 Mbps, must read the IGP01E1000_PHY_PCS_INIT_REG to
6214 * find the polarity status */
6215 if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
6216 IGP01E1000_PSSR_SPEED_1000MBPS) {
6218 /* Read the GIG initialization PCS register (0x00B4) */
6219 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG,
6224 /* Check the polarity bits */
6225 *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ? 1 : 0;
6227 /* For 10 Mbps, read the polarity bit in the status register. (for
6228 * 100 Mbps this bit is always 0) */
6229 *polarity = phy_data & IGP01E1000_PSSR_POLARITY_REVERSED;
6232 return E1000_SUCCESS;
6235 /******************************************************************************
6236 * Check if Downshift occured
6238 * hw - Struct containing variables accessed by shared code
6239 * downshift - output parameter : 0 - No Downshift ocured.
6240 * 1 - Downshift ocured.
6242 * returns: - E1000_ERR_XXX
6245 * For phy's older then IGP, this function reads the Downshift bit in the Phy
6246 * Specific Status register. For IGP phy's, it reads the Downgrade bit in the
6247 * Link Health register. In IGP this bit is latched high, so the driver must
6248 * read it immediately after link is established.
6249 *****************************************************************************/
6251 e1000_check_downshift(struct e1000_hw *hw)
6256 DEBUGFUNC("e1000_check_downshift");
6258 if(hw->phy_type == e1000_phy_igp ||
6259 hw->phy_type == e1000_phy_igp_2) {
6260 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH,
6265 hw->speed_downgraded = (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0;
6266 } else if ((hw->phy_type == e1000_phy_m88) ||
6267 (hw->phy_type == e1000_phy_gg82563)) {
6268 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6273 hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >>
6274 M88E1000_PSSR_DOWNSHIFT_SHIFT;
6277 return E1000_SUCCESS;
6280 /*****************************************************************************
6282 * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a
6283 * gigabit link is achieved to improve link quality.
6285 * hw: Struct containing variables accessed by shared code
6287 * returns: - E1000_ERR_PHY if fail to read/write the PHY
6288 * E1000_SUCCESS at any other case.
6290 ****************************************************************************/
6293 e1000_config_dsp_after_link_change(struct e1000_hw *hw,
6297 uint16_t phy_data, phy_saved_data, speed, duplex, i;
6298 uint16_t dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
6299 {IGP01E1000_PHY_AGC_PARAM_A,
6300 IGP01E1000_PHY_AGC_PARAM_B,
6301 IGP01E1000_PHY_AGC_PARAM_C,
6302 IGP01E1000_PHY_AGC_PARAM_D};
6303 uint16_t min_length, max_length;
6305 DEBUGFUNC("e1000_config_dsp_after_link_change");
6307 if(hw->phy_type != e1000_phy_igp)
6308 return E1000_SUCCESS;
6311 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
6313 DEBUGOUT("Error getting link speed and duplex\n");
6317 if(speed == SPEED_1000) {
6319 e1000_get_cable_length(hw, &min_length, &max_length);
6321 if((hw->dsp_config_state == e1000_dsp_config_enabled) &&
6322 min_length >= e1000_igp_cable_length_50) {
6324 for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
6325 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i],
6330 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
6332 ret_val = e1000_write_phy_reg(hw, dsp_reg_array[i],
6337 hw->dsp_config_state = e1000_dsp_config_activated;
6340 if((hw->ffe_config_state == e1000_ffe_config_enabled) &&
6341 (min_length < e1000_igp_cable_length_50)) {
6343 uint16_t ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_20;
6344 uint32_t idle_errs = 0;
6346 /* clear previous idle error counts */
6347 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
6352 for(i = 0; i < ffe_idle_err_timeout; i++) {
6354 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
6359 idle_errs += (phy_data & SR_1000T_IDLE_ERROR_CNT);
6360 if(idle_errs > SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT) {
6361 hw->ffe_config_state = e1000_ffe_config_active;
6363 ret_val = e1000_write_phy_reg(hw,
6364 IGP01E1000_PHY_DSP_FFE,
6365 IGP01E1000_PHY_DSP_FFE_CM_CP);
6372 ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_100;
6377 if(hw->dsp_config_state == e1000_dsp_config_activated) {
6378 /* Save off the current value of register 0x2F5B to be restored at
6379 * the end of the routines. */
6380 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
6385 /* Disable the PHY transmitter */
6386 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
6393 ret_val = e1000_write_phy_reg(hw, 0x0000,
6394 IGP01E1000_IEEE_FORCE_GIGA);
6397 for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
6398 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i], &phy_data);
6402 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
6403 phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS;
6405 ret_val = e1000_write_phy_reg(hw,dsp_reg_array[i], phy_data);
6410 ret_val = e1000_write_phy_reg(hw, 0x0000,
6411 IGP01E1000_IEEE_RESTART_AUTONEG);
6417 /* Now enable the transmitter */
6418 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
6423 hw->dsp_config_state = e1000_dsp_config_enabled;
6426 if(hw->ffe_config_state == e1000_ffe_config_active) {
6427 /* Save off the current value of register 0x2F5B to be restored at
6428 * the end of the routines. */
6429 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
6434 /* Disable the PHY transmitter */
6435 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
6442 ret_val = e1000_write_phy_reg(hw, 0x0000,
6443 IGP01E1000_IEEE_FORCE_GIGA);
6446 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE,
6447 IGP01E1000_PHY_DSP_FFE_DEFAULT);
6451 ret_val = e1000_write_phy_reg(hw, 0x0000,
6452 IGP01E1000_IEEE_RESTART_AUTONEG);
6458 /* Now enable the transmitter */
6459 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
6464 hw->ffe_config_state = e1000_ffe_config_enabled;
6467 return E1000_SUCCESS;
6470 /*****************************************************************************
6471 * Set PHY to class A mode
6472 * Assumes the following operations will follow to enable the new class mode.
6473 * 1. Do a PHY soft reset
6474 * 2. Restart auto-negotiation or force link.
6476 * hw - Struct containing variables accessed by shared code
6477 ****************************************************************************/
6479 e1000_set_phy_mode(struct e1000_hw *hw)
6482 uint16_t eeprom_data;
6484 DEBUGFUNC("e1000_set_phy_mode");
6486 if((hw->mac_type == e1000_82545_rev_3) &&
6487 (hw->media_type == e1000_media_type_copper)) {
6488 ret_val = e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, 1, &eeprom_data);
6493 if((eeprom_data != EEPROM_RESERVED_WORD) &&
6494 (eeprom_data & EEPROM_PHY_CLASS_A)) {
6495 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x000B);
6498 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x8104);
6502 hw->phy_reset_disable = FALSE;
6506 return E1000_SUCCESS;
6509 /*****************************************************************************
6511 * This function sets the lplu state according to the active flag. When
6512 * activating lplu this function also disables smart speed and vise versa.
6513 * lplu will not be activated unless the device autonegotiation advertisment
6514 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
6515 * hw: Struct containing variables accessed by shared code
6516 * active - true to enable lplu false to disable lplu.
6518 * returns: - E1000_ERR_PHY if fail to read/write the PHY
6519 * E1000_SUCCESS at any other case.
6521 ****************************************************************************/
6524 e1000_set_d3_lplu_state(struct e1000_hw *hw,
6529 DEBUGFUNC("e1000_set_d3_lplu_state");
6531 if(hw->phy_type != e1000_phy_igp && hw->phy_type != e1000_phy_igp_2)
6532 return E1000_SUCCESS;
6534 /* During driver activity LPLU should not be used or it will attain link
6535 * from the lowest speeds starting from 10Mbps. The capability is used for
6536 * Dx transitions and states */
6537 if(hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2) {
6538 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data);
6542 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
6548 if(hw->mac_type == e1000_82541_rev_2 ||
6549 hw->mac_type == e1000_82547_rev_2) {
6550 phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
6551 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
6555 phy_data &= ~IGP02E1000_PM_D3_LPLU;
6556 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
6562 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
6563 * Dx states where the power conservation is most important. During
6564 * driver activity we should enable SmartSpeed, so performance is
6566 if (hw->smart_speed == e1000_smart_speed_on) {
6567 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
6572 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
6573 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
6577 } else if (hw->smart_speed == e1000_smart_speed_off) {
6578 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
6583 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
6584 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
6590 } else if((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT) ||
6591 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL ) ||
6592 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) {
6594 if(hw->mac_type == e1000_82541_rev_2 ||
6595 hw->mac_type == e1000_82547_rev_2) {
6596 phy_data |= IGP01E1000_GMII_FLEX_SPD;
6597 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
6601 phy_data |= IGP02E1000_PM_D3_LPLU;
6602 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
6608 /* When LPLU is enabled we should disable SmartSpeed */
6609 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
6613 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
6614 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
6619 return E1000_SUCCESS;
6622 /*****************************************************************************
6624 * This function sets the lplu d0 state according to the active flag. When
6625 * activating lplu this function also disables smart speed and vise versa.
6626 * lplu will not be activated unless the device autonegotiation advertisment
6627 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
6628 * hw: Struct containing variables accessed by shared code
6629 * active - true to enable lplu false to disable lplu.
6631 * returns: - E1000_ERR_PHY if fail to read/write the PHY
6632 * E1000_SUCCESS at any other case.
6634 ****************************************************************************/
6637 e1000_set_d0_lplu_state(struct e1000_hw *hw,
6642 DEBUGFUNC("e1000_set_d0_lplu_state");
6644 if(hw->mac_type <= e1000_82547_rev_2)
6645 return E1000_SUCCESS;
6647 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
6652 phy_data &= ~IGP02E1000_PM_D0_LPLU;
6653 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
6657 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
6658 * Dx states where the power conservation is most important. During
6659 * driver activity we should enable SmartSpeed, so performance is
6661 if (hw->smart_speed == e1000_smart_speed_on) {
6662 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
6667 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
6668 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
6672 } else if (hw->smart_speed == e1000_smart_speed_off) {
6673 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
6678 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
6679 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
6688 phy_data |= IGP02E1000_PM_D0_LPLU;
6689 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
6693 /* When LPLU is enabled we should disable SmartSpeed */
6694 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
6698 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
6699 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
6704 return E1000_SUCCESS;
6707 /******************************************************************************
6708 * Change VCO speed register to improve Bit Error Rate performance of SERDES.
6710 * hw - Struct containing variables accessed by shared code
6711 *****************************************************************************/
6713 e1000_set_vco_speed(struct e1000_hw *hw)
6716 uint16_t default_page = 0;
6719 DEBUGFUNC("e1000_set_vco_speed");
6721 switch(hw->mac_type) {
6722 case e1000_82545_rev_3:
6723 case e1000_82546_rev_3:
6726 return E1000_SUCCESS;
6729 /* Set PHY register 30, page 5, bit 8 to 0 */
6731 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, &default_page);
6735 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005);
6739 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
6743 phy_data &= ~M88E1000_PHY_VCO_REG_BIT8;
6744 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
6748 /* Set PHY register 30, page 4, bit 11 to 1 */
6750 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004);
6754 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
6758 phy_data |= M88E1000_PHY_VCO_REG_BIT11;
6759 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
6763 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, default_page);
6767 return E1000_SUCCESS;
6771 /*****************************************************************************
6772 * This function reads the cookie from ARC ram.
6774 * returns: - E1000_SUCCESS .
6775 ****************************************************************************/
6777 e1000_host_if_read_cookie(struct e1000_hw * hw, uint8_t *buffer)
6780 uint32_t offset = E1000_MNG_DHCP_COOKIE_OFFSET;
6781 uint8_t length = E1000_MNG_DHCP_COOKIE_LENGTH;
6783 length = (length >> 2);
6784 offset = (offset >> 2);
6786 for (i = 0; i < length; i++) {
6787 *((uint32_t *) buffer + i) =
6788 E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset + i);
6790 return E1000_SUCCESS;
6794 /*****************************************************************************
6795 * This function checks whether the HOST IF is enabled for command operaton
6796 * and also checks whether the previous command is completed.
6797 * It busy waits in case of previous command is not completed.
6799 * returns: - E1000_ERR_HOST_INTERFACE_COMMAND in case if is not ready or
6801 * - E1000_SUCCESS for success.
6802 ****************************************************************************/
6804 e1000_mng_enable_host_if(struct e1000_hw * hw)
6809 /* Check that the host interface is enabled. */
6810 hicr = E1000_READ_REG(hw, HICR);
6811 if ((hicr & E1000_HICR_EN) == 0) {
6812 DEBUGOUT("E1000_HOST_EN bit disabled.\n");
6813 return -E1000_ERR_HOST_INTERFACE_COMMAND;
6815 /* check the previous command is completed */
6816 for (i = 0; i < E1000_MNG_DHCP_COMMAND_TIMEOUT; i++) {
6817 hicr = E1000_READ_REG(hw, HICR);
6818 if (!(hicr & E1000_HICR_C))
6823 if (i == E1000_MNG_DHCP_COMMAND_TIMEOUT) {
6824 DEBUGOUT("Previous command timeout failed .\n");
6825 return -E1000_ERR_HOST_INTERFACE_COMMAND;
6827 return E1000_SUCCESS;
6830 /*****************************************************************************
6831 * This function writes the buffer content at the offset given on the host if.
6832 * It also does alignment considerations to do the writes in most efficient way.
6833 * Also fills up the sum of the buffer in *buffer parameter.
6835 * returns - E1000_SUCCESS for success.
6836 ****************************************************************************/
6838 e1000_mng_host_if_write(struct e1000_hw * hw, uint8_t *buffer,
6839 uint16_t length, uint16_t offset, uint8_t *sum)
6842 uint8_t *bufptr = buffer;
6844 uint16_t remaining, i, j, prev_bytes;
6846 /* sum = only sum of the data and it is not checksum */
6848 if (length == 0 || offset + length > E1000_HI_MAX_MNG_DATA_LENGTH) {
6849 return -E1000_ERR_PARAM;
6852 tmp = (uint8_t *)&data;
6853 prev_bytes = offset & 0x3;
6858 data = E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset);
6859 for (j = prev_bytes; j < sizeof(uint32_t); j++) {
6860 *(tmp + j) = *bufptr++;
6863 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset, data);
6864 length -= j - prev_bytes;
6868 remaining = length & 0x3;
6869 length -= remaining;
6871 /* Calculate length in DWORDs */
6874 /* The device driver writes the relevant command block into the
6876 for (i = 0; i < length; i++) {
6877 for (j = 0; j < sizeof(uint32_t); j++) {
6878 *(tmp + j) = *bufptr++;
6882 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data);
6885 for (j = 0; j < sizeof(uint32_t); j++) {
6887 *(tmp + j) = *bufptr++;
6893 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data);
6896 return E1000_SUCCESS;
6900 /*****************************************************************************
6901 * This function writes the command header after does the checksum calculation.
6903 * returns - E1000_SUCCESS for success.
6904 ****************************************************************************/
6906 e1000_mng_write_cmd_header(struct e1000_hw * hw,
6907 struct e1000_host_mng_command_header * hdr)
6913 /* Write the whole command header structure which includes sum of
6916 uint16_t length = sizeof(struct e1000_host_mng_command_header);
6918 sum = hdr->checksum;
6921 buffer = (uint8_t *) hdr;
6926 hdr->checksum = 0 - sum;
6929 /* The device driver writes the relevant command block into the ram area. */
6930 for (i = 0; i < length; i++)
6931 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, i, *((uint32_t *) hdr + i));
6933 return E1000_SUCCESS;
6937 /*****************************************************************************
6938 * This function indicates to ARC that a new command is pending which completes
6939 * one write operation by the driver.
6941 * returns - E1000_SUCCESS for success.
6942 ****************************************************************************/
6944 e1000_mng_write_commit(
6945 struct e1000_hw * hw)
6949 hicr = E1000_READ_REG(hw, HICR);
6950 /* Setting this bit tells the ARC that a new command is pending. */
6951 E1000_WRITE_REG(hw, HICR, hicr | E1000_HICR_C);
6953 return E1000_SUCCESS;
6957 /*****************************************************************************
6958 * This function checks the mode of the firmware.
6960 * returns - TRUE when the mode is IAMT or FALSE.
6961 ****************************************************************************/
6963 e1000_check_mng_mode(
6964 struct e1000_hw *hw)
6968 fwsm = E1000_READ_REG(hw, FWSM);
6970 if((fwsm & E1000_FWSM_MODE_MASK) ==
6971 (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
6978 /*****************************************************************************
6979 * This function writes the dhcp info .
6980 ****************************************************************************/
6982 e1000_mng_write_dhcp_info(struct e1000_hw * hw, uint8_t *buffer,
6986 struct e1000_host_mng_command_header hdr;
6988 hdr.command_id = E1000_MNG_DHCP_TX_PAYLOAD_CMD;
6989 hdr.command_length = length;
6994 ret_val = e1000_mng_enable_host_if(hw);
6995 if (ret_val == E1000_SUCCESS) {
6996 ret_val = e1000_mng_host_if_write(hw, buffer, length, sizeof(hdr),
6998 if (ret_val == E1000_SUCCESS) {
6999 ret_val = e1000_mng_write_cmd_header(hw, &hdr);
7000 if (ret_val == E1000_SUCCESS)
7001 ret_val = e1000_mng_write_commit(hw);
7008 /*****************************************************************************
7009 * This function calculates the checksum.
7011 * returns - checksum of buffer contents.
7012 ****************************************************************************/
7014 e1000_calculate_mng_checksum(char *buffer, uint32_t length)
7022 for (i=0; i < length; i++)
7025 return (uint8_t) (0 - sum);
7028 /*****************************************************************************
7029 * This function checks whether tx pkt filtering needs to be enabled or not.
7031 * returns - TRUE for packet filtering or FALSE.
7032 ****************************************************************************/
7034 e1000_enable_tx_pkt_filtering(struct e1000_hw *hw)
7036 /* called in init as well as watchdog timer functions */
7038 int32_t ret_val, checksum;
7039 boolean_t tx_filter = FALSE;
7040 struct e1000_host_mng_dhcp_cookie *hdr = &(hw->mng_cookie);
7041 uint8_t *buffer = (uint8_t *) &(hw->mng_cookie);
7043 if (e1000_check_mng_mode(hw)) {
7044 ret_val = e1000_mng_enable_host_if(hw);
7045 if (ret_val == E1000_SUCCESS) {
7046 ret_val = e1000_host_if_read_cookie(hw, buffer);
7047 if (ret_val == E1000_SUCCESS) {
7048 checksum = hdr->checksum;
7050 if ((hdr->signature == E1000_IAMT_SIGNATURE) &&
7051 checksum == e1000_calculate_mng_checksum((char *)buffer,
7052 E1000_MNG_DHCP_COOKIE_LENGTH)) {
7054 E1000_MNG_DHCP_COOKIE_STATUS_PARSING_SUPPORT)
7063 hw->tx_pkt_filtering = tx_filter;
7067 /******************************************************************************
7068 * Verifies the hardware needs to allow ARPs to be processed by the host
7070 * hw - Struct containing variables accessed by shared code
7072 * returns: - TRUE/FALSE
7074 *****************************************************************************/
7076 e1000_enable_mng_pass_thru(struct e1000_hw *hw)
7079 uint32_t fwsm, factps;
7081 if (hw->asf_firmware_present) {
7082 manc = E1000_READ_REG(hw, MANC);
7084 if (!(manc & E1000_MANC_RCV_TCO_EN) ||
7085 !(manc & E1000_MANC_EN_MAC_ADDR_FILTER))
7087 if (e1000_arc_subsystem_valid(hw) == TRUE) {
7088 fwsm = E1000_READ_REG(hw, FWSM);
7089 factps = E1000_READ_REG(hw, FACTPS);
7091 if (((fwsm & E1000_FWSM_MODE_MASK) ==
7092 (e1000_mng_mode_pt << E1000_FWSM_MODE_SHIFT)) &&
7093 (factps & E1000_FACTPS_MNGCG))
7096 if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN))
7103 e1000_polarity_reversal_workaround(struct e1000_hw *hw)
7106 uint16_t mii_status_reg;
7109 /* Polarity reversal workaround for forced 10F/10H links. */
7111 /* Disable the transmitter on the PHY */
7113 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
7116 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF);
7120 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
7124 /* This loop will early-out if the NO link condition has been met. */
7125 for(i = PHY_FORCE_TIME; i > 0; i--) {
7126 /* Read the MII Status Register and wait for Link Status bit
7130 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
7134 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
7138 if((mii_status_reg & ~MII_SR_LINK_STATUS) == 0) break;
7139 msec_delay_irq(100);
7142 /* Recommended delay time after link has been lost */
7143 msec_delay_irq(1000);
7145 /* Now we will re-enable th transmitter on the PHY */
7147 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
7151 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0);
7155 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00);
7159 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000);
7163 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
7167 /* This loop will early-out if the link condition has been met. */
7168 for(i = PHY_FORCE_TIME; i > 0; i--) {
7169 /* Read the MII Status Register and wait for Link Status bit
7173 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
7177 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
7181 if(mii_status_reg & MII_SR_LINK_STATUS) break;
7182 msec_delay_irq(100);
7184 return E1000_SUCCESS;
7187 /***************************************************************************
7189 * Disables PCI-Express master access.
7191 * hw: Struct containing variables accessed by shared code
7195 ***************************************************************************/
7197 e1000_set_pci_express_master_disable(struct e1000_hw *hw)
7201 DEBUGFUNC("e1000_set_pci_express_master_disable");
7203 if (hw->bus_type != e1000_bus_type_pci_express)
7206 ctrl = E1000_READ_REG(hw, CTRL);
7207 ctrl |= E1000_CTRL_GIO_MASTER_DISABLE;
7208 E1000_WRITE_REG(hw, CTRL, ctrl);
7212 /***************************************************************************
7214 * Enables PCI-Express master access.
7216 * hw: Struct containing variables accessed by shared code
7220 ***************************************************************************/
7222 e1000_enable_pciex_master(struct e1000_hw *hw)
7226 DEBUGFUNC("e1000_enable_pciex_master");
7228 if (hw->bus_type != e1000_bus_type_pci_express)
7231 ctrl = E1000_READ_REG(hw, CTRL);
7232 ctrl &= ~E1000_CTRL_GIO_MASTER_DISABLE;
7233 E1000_WRITE_REG(hw, CTRL, ctrl);
7237 /*******************************************************************************
7239 * Disables PCI-Express master access and verifies there are no pending requests
7241 * hw: Struct containing variables accessed by shared code
7243 * returns: - E1000_ERR_MASTER_REQUESTS_PENDING if master disable bit hasn't
7244 * caused the master requests to be disabled.
7245 * E1000_SUCCESS master requests disabled.
7247 ******************************************************************************/
7249 e1000_disable_pciex_master(struct e1000_hw *hw)
7251 int32_t timeout = MASTER_DISABLE_TIMEOUT; /* 80ms */
7253 DEBUGFUNC("e1000_disable_pciex_master");
7255 if (hw->bus_type != e1000_bus_type_pci_express)
7256 return E1000_SUCCESS;
7258 e1000_set_pci_express_master_disable(hw);
7261 if(!(E1000_READ_REG(hw, STATUS) & E1000_STATUS_GIO_MASTER_ENABLE))
7269 DEBUGOUT("Master requests are pending.\n");
7270 return -E1000_ERR_MASTER_REQUESTS_PENDING;
7273 return E1000_SUCCESS;
7276 /*******************************************************************************
7278 * Check for EEPROM Auto Read bit done.
7280 * hw: Struct containing variables accessed by shared code
7282 * returns: - E1000_ERR_RESET if fail to reset MAC
7283 * E1000_SUCCESS at any other case.
7285 ******************************************************************************/
7287 e1000_get_auto_rd_done(struct e1000_hw *hw)
7289 int32_t timeout = AUTO_READ_DONE_TIMEOUT;
7291 DEBUGFUNC("e1000_get_auto_rd_done");
7293 switch (hw->mac_type) {
7300 case e1000_80003es2lan:
7302 if (E1000_READ_REG(hw, EECD) & E1000_EECD_AUTO_RD) break;
7308 DEBUGOUT("Auto read by HW from EEPROM has not completed.\n");
7309 return -E1000_ERR_RESET;
7314 /* PHY configuration from NVM just starts after EECD_AUTO_RD sets to high.
7315 * Need to wait for PHY configuration completion before accessing NVM
7317 if (hw->mac_type == e1000_82573)
7320 return E1000_SUCCESS;
7323 /***************************************************************************
7324 * Checks if the PHY configuration is done
7326 * hw: Struct containing variables accessed by shared code
7328 * returns: - E1000_ERR_RESET if fail to reset MAC
7329 * E1000_SUCCESS at any other case.
7331 ***************************************************************************/
7333 e1000_get_phy_cfg_done(struct e1000_hw *hw)
7335 int32_t timeout = PHY_CFG_TIMEOUT;
7336 uint32_t cfg_mask = E1000_EEPROM_CFG_DONE;
7338 DEBUGFUNC("e1000_get_phy_cfg_done");
7340 switch (hw->mac_type) {
7344 case e1000_80003es2lan:
7345 /* Separate *_CFG_DONE_* bit for each port */
7346 if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
7347 cfg_mask = E1000_EEPROM_CFG_DONE_PORT_1;
7352 if (E1000_READ_REG(hw, EEMNGCTL) & cfg_mask)
7360 DEBUGOUT("MNG configuration cycle has not completed.\n");
7361 return -E1000_ERR_RESET;
7366 return E1000_SUCCESS;
7369 /***************************************************************************
7371 * Using the combination of SMBI and SWESMBI semaphore bits when resetting
7372 * adapter or Eeprom access.
7374 * hw: Struct containing variables accessed by shared code
7376 * returns: - E1000_ERR_EEPROM if fail to access EEPROM.
7377 * E1000_SUCCESS at any other case.
7379 ***************************************************************************/
7381 e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw)
7386 DEBUGFUNC("e1000_get_hw_eeprom_semaphore");
7388 if(!hw->eeprom_semaphore_present)
7389 return E1000_SUCCESS;
7391 if (hw->mac_type == e1000_80003es2lan) {
7392 /* Get the SW semaphore. */
7393 if (e1000_get_software_semaphore(hw) != E1000_SUCCESS)
7394 return -E1000_ERR_EEPROM;
7397 /* Get the FW semaphore. */
7398 timeout = hw->eeprom.word_size + 1;
7400 swsm = E1000_READ_REG(hw, SWSM);
7401 swsm |= E1000_SWSM_SWESMBI;
7402 E1000_WRITE_REG(hw, SWSM, swsm);
7403 /* if we managed to set the bit we got the semaphore. */
7404 swsm = E1000_READ_REG(hw, SWSM);
7405 if(swsm & E1000_SWSM_SWESMBI)
7413 /* Release semaphores */
7414 e1000_put_hw_eeprom_semaphore(hw);
7415 DEBUGOUT("Driver can't access the Eeprom - SWESMBI bit is set.\n");
7416 return -E1000_ERR_EEPROM;
7419 return E1000_SUCCESS;
7422 /***************************************************************************
7423 * This function clears HW semaphore bits.
7425 * hw: Struct containing variables accessed by shared code
7429 ***************************************************************************/
7431 e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw)
7435 DEBUGFUNC("e1000_put_hw_eeprom_semaphore");
7437 if(!hw->eeprom_semaphore_present)
7440 swsm = E1000_READ_REG(hw, SWSM);
7441 if (hw->mac_type == e1000_80003es2lan) {
7442 /* Release both semaphores. */
7443 swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
7445 swsm &= ~(E1000_SWSM_SWESMBI);
7446 E1000_WRITE_REG(hw, SWSM, swsm);
7449 /***************************************************************************
7451 * Obtaining software semaphore bit (SMBI) before resetting PHY.
7453 * hw: Struct containing variables accessed by shared code
7455 * returns: - E1000_ERR_RESET if fail to obtain semaphore.
7456 * E1000_SUCCESS at any other case.
7458 ***************************************************************************/
7460 e1000_get_software_semaphore(struct e1000_hw *hw)
7462 int32_t timeout = hw->eeprom.word_size + 1;
7465 DEBUGFUNC("e1000_get_software_semaphore");
7467 if (hw->mac_type != e1000_80003es2lan)
7468 return E1000_SUCCESS;
7471 swsm = E1000_READ_REG(hw, SWSM);
7472 /* If SMBI bit cleared, it is now set and we hold the semaphore */
7473 if(!(swsm & E1000_SWSM_SMBI))
7480 DEBUGOUT("Driver can't access device - SMBI bit is set.\n");
7481 return -E1000_ERR_RESET;
7484 return E1000_SUCCESS;
7487 /***************************************************************************
7489 * Release semaphore bit (SMBI).
7491 * hw: Struct containing variables accessed by shared code
7493 ***************************************************************************/
7495 e1000_release_software_semaphore(struct e1000_hw *hw)
7499 DEBUGFUNC("e1000_release_software_semaphore");
7501 if (hw->mac_type != e1000_80003es2lan)
7504 swsm = E1000_READ_REG(hw, SWSM);
7505 /* Release the SW semaphores.*/
7506 swsm &= ~E1000_SWSM_SMBI;
7507 E1000_WRITE_REG(hw, SWSM, swsm);
7510 /******************************************************************************
7511 * Checks if PHY reset is blocked due to SOL/IDER session, for example.
7512 * Returning E1000_BLK_PHY_RESET isn't necessarily an error. But it's up to
7513 * the caller to figure out how to deal with it.
7515 * hw - Struct containing variables accessed by shared code
7517 * returns: - E1000_BLK_PHY_RESET
7520 *****************************************************************************/
7522 e1000_check_phy_reset_block(struct e1000_hw *hw)
7526 if (hw->mac_type > e1000_82547_rev_2)
7527 manc = E1000_READ_REG(hw, MANC);
7528 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
7529 E1000_BLK_PHY_RESET : E1000_SUCCESS;
7533 e1000_arc_subsystem_valid(struct e1000_hw *hw)
7537 /* On 8257x silicon, registers in the range of 0x8800 - 0x8FFC
7538 * may not be provided a DMA clock when no manageability features are
7539 * enabled. We do not want to perform any reads/writes to these registers
7540 * if this is the case. We read FWSM to determine the manageability mode.
7542 switch (hw->mac_type) {
7546 case e1000_80003es2lan:
7547 fwsm = E1000_READ_REG(hw, FWSM);
7548 if((fwsm & E1000_FWSM_MODE_MASK) != 0)