1 /*******************************************************************************
4 Copyright(c) 1999 - 2006 Intel Corporation. All rights reserved.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2 of the License, or (at your option)
11 This program is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 You should have received a copy of the GNU General Public License along with
17 this program; if not, write to the Free Software Foundation, Inc., 59
18 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 The full GNU General Public License is included in this distribution in the
24 Linux NICS <linux.nics@intel.com>
25 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
26 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
28 *******************************************************************************/
31 * Shared functions for accessing and configuring the MAC
36 static int32_t e1000_set_phy_type(struct e1000_hw *hw);
37 static void e1000_phy_init_script(struct e1000_hw *hw);
38 static int32_t e1000_setup_copper_link(struct e1000_hw *hw);
39 static int32_t e1000_setup_fiber_serdes_link(struct e1000_hw *hw);
40 static int32_t e1000_adjust_serdes_amplitude(struct e1000_hw *hw);
41 static int32_t e1000_phy_force_speed_duplex(struct e1000_hw *hw);
42 static int32_t e1000_config_mac_to_phy(struct e1000_hw *hw);
43 static void e1000_raise_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl);
44 static void e1000_lower_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl);
45 static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, uint32_t data,
47 static uint16_t e1000_shift_in_mdi_bits(struct e1000_hw *hw);
48 static int32_t e1000_phy_reset_dsp(struct e1000_hw *hw);
49 static int32_t e1000_write_eeprom_spi(struct e1000_hw *hw, uint16_t offset,
50 uint16_t words, uint16_t *data);
51 static int32_t e1000_write_eeprom_microwire(struct e1000_hw *hw,
52 uint16_t offset, uint16_t words,
54 static int32_t e1000_spi_eeprom_ready(struct e1000_hw *hw);
55 static void e1000_raise_ee_clk(struct e1000_hw *hw, uint32_t *eecd);
56 static void e1000_lower_ee_clk(struct e1000_hw *hw, uint32_t *eecd);
57 static void e1000_shift_out_ee_bits(struct e1000_hw *hw, uint16_t data,
59 static int32_t e1000_write_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr,
61 static int32_t e1000_read_phy_reg_ex(struct e1000_hw *hw,uint32_t reg_addr,
63 static uint16_t e1000_shift_in_ee_bits(struct e1000_hw *hw, uint16_t count);
64 static int32_t e1000_acquire_eeprom(struct e1000_hw *hw);
65 static void e1000_release_eeprom(struct e1000_hw *hw);
66 static void e1000_standby_eeprom(struct e1000_hw *hw);
67 static int32_t e1000_set_vco_speed(struct e1000_hw *hw);
68 static int32_t e1000_polarity_reversal_workaround(struct e1000_hw *hw);
69 static int32_t e1000_set_phy_mode(struct e1000_hw *hw);
70 static int32_t e1000_host_if_read_cookie(struct e1000_hw *hw, uint8_t *buffer);
71 static uint8_t e1000_calculate_mng_checksum(char *buffer, uint32_t length);
72 static uint8_t e1000_arc_subsystem_valid(struct e1000_hw *hw);
73 static int32_t e1000_check_downshift(struct e1000_hw *hw);
74 static int32_t e1000_check_polarity(struct e1000_hw *hw, uint16_t *polarity);
75 static void e1000_clear_hw_cntrs(struct e1000_hw *hw);
76 static void e1000_clear_vfta(struct e1000_hw *hw);
77 static int32_t e1000_commit_shadow_ram(struct e1000_hw *hw);
78 static int32_t e1000_config_dsp_after_link_change(struct e1000_hw *hw,
80 static int32_t e1000_config_fc_after_link_up(struct e1000_hw *hw);
81 static int32_t e1000_detect_gig_phy(struct e1000_hw *hw);
82 static int32_t e1000_get_auto_rd_done(struct e1000_hw *hw);
83 static int32_t e1000_get_cable_length(struct e1000_hw *hw,
85 uint16_t *max_length);
86 static int32_t e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw);
87 static int32_t e1000_get_phy_cfg_done(struct e1000_hw *hw);
88 static int32_t e1000_id_led_init(struct e1000_hw * hw);
89 static void e1000_init_rx_addrs(struct e1000_hw *hw);
90 static boolean_t e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw);
91 static int32_t e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd);
92 static void e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw);
93 static int32_t e1000_read_eeprom_eerd(struct e1000_hw *hw, uint16_t offset,
94 uint16_t words, uint16_t *data);
95 static int32_t e1000_set_d0_lplu_state(struct e1000_hw *hw, boolean_t active);
96 static int32_t e1000_set_d3_lplu_state(struct e1000_hw *hw, boolean_t active);
97 static int32_t e1000_wait_autoneg(struct e1000_hw *hw);
99 static void e1000_write_reg_io(struct e1000_hw *hw, uint32_t offset,
102 #define E1000_WRITE_REG_IO(a, reg, val) \
103 e1000_write_reg_io((a), E1000_##reg, val)
104 static int32_t e1000_configure_kmrn_for_10_100(struct e1000_hw *hw,
106 static int32_t e1000_configure_kmrn_for_1000(struct e1000_hw *hw);
108 /* IGP cable length table */
110 uint16_t e1000_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] =
111 { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
112 5, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 25, 25, 25,
113 25, 25, 25, 25, 30, 30, 30, 30, 40, 40, 40, 40, 40, 40, 40, 40,
114 40, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60,
115 60, 70, 70, 70, 70, 70, 70, 80, 80, 80, 80, 80, 80, 90, 90, 90,
116 90, 90, 90, 90, 90, 90, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
117 100, 100, 100, 100, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,
118 110, 110, 110, 110, 110, 110, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120};
121 uint16_t e1000_igp_2_cable_length_table[IGP02E1000_AGC_LENGTH_TABLE_SIZE] =
122 { 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21,
123 0, 0, 0, 3, 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41,
124 6, 10, 14, 18, 22, 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61,
125 21, 26, 31, 35, 40, 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82,
126 40, 45, 51, 56, 61, 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104,
127 60, 66, 72, 77, 82, 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121,
128 83, 89, 95, 100, 105, 109, 113, 116, 119, 122, 124,
129 104, 109, 114, 118, 121, 124};
132 /******************************************************************************
133 * Set the phy type member in the hw struct.
135 * hw - Struct containing variables accessed by shared code
136 *****************************************************************************/
138 e1000_set_phy_type(struct e1000_hw *hw)
140 DEBUGFUNC("e1000_set_phy_type");
142 if(hw->mac_type == e1000_undefined)
143 return -E1000_ERR_PHY_TYPE;
146 case M88E1000_E_PHY_ID:
147 case M88E1000_I_PHY_ID:
148 case M88E1011_I_PHY_ID:
149 case M88E1111_I_PHY_ID:
150 hw->phy_type = e1000_phy_m88;
152 case IGP01E1000_I_PHY_ID:
153 if(hw->mac_type == e1000_82541 ||
154 hw->mac_type == e1000_82541_rev_2 ||
155 hw->mac_type == e1000_82547 ||
156 hw->mac_type == e1000_82547_rev_2) {
157 hw->phy_type = e1000_phy_igp;
160 case IGP03E1000_E_PHY_ID:
161 hw->phy_type = e1000_phy_igp_3;
164 case IFE_PLUS_E_PHY_ID:
166 hw->phy_type = e1000_phy_ife;
168 case GG82563_E_PHY_ID:
169 if (hw->mac_type == e1000_80003es2lan) {
170 hw->phy_type = e1000_phy_gg82563;
175 /* Should never have loaded on this device */
176 hw->phy_type = e1000_phy_undefined;
177 return -E1000_ERR_PHY_TYPE;
180 return E1000_SUCCESS;
183 /******************************************************************************
184 * IGP phy init script - initializes the GbE PHY
186 * hw - Struct containing variables accessed by shared code
187 *****************************************************************************/
189 e1000_phy_init_script(struct e1000_hw *hw)
192 uint16_t phy_saved_data;
194 DEBUGFUNC("e1000_phy_init_script");
196 if(hw->phy_init_script) {
199 /* Save off the current value of register 0x2F5B to be restored at
200 * the end of this routine. */
201 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
203 /* Disabled the PHY transmitter */
204 e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
208 e1000_write_phy_reg(hw,0x0000,0x0140);
212 switch(hw->mac_type) {
215 e1000_write_phy_reg(hw, 0x1F95, 0x0001);
217 e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
219 e1000_write_phy_reg(hw, 0x1F79, 0x0018);
221 e1000_write_phy_reg(hw, 0x1F30, 0x1600);
223 e1000_write_phy_reg(hw, 0x1F31, 0x0014);
225 e1000_write_phy_reg(hw, 0x1F32, 0x161C);
227 e1000_write_phy_reg(hw, 0x1F94, 0x0003);
229 e1000_write_phy_reg(hw, 0x1F96, 0x003F);
231 e1000_write_phy_reg(hw, 0x2010, 0x0008);
234 case e1000_82541_rev_2:
235 case e1000_82547_rev_2:
236 e1000_write_phy_reg(hw, 0x1F73, 0x0099);
242 e1000_write_phy_reg(hw, 0x0000, 0x3300);
246 /* Now enable the transmitter */
247 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
249 if(hw->mac_type == e1000_82547) {
250 uint16_t fused, fine, coarse;
252 /* Move to analog registers page */
253 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_SPARE_FUSE_STATUS, &fused);
255 if(!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
256 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_FUSE_STATUS, &fused);
258 fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
259 coarse = fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
261 if(coarse > IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
262 coarse -= IGP01E1000_ANALOG_FUSE_COARSE_10;
263 fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
264 } else if(coarse == IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
265 fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
267 fused = (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
268 (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
269 (coarse & IGP01E1000_ANALOG_FUSE_COARSE_MASK);
271 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_CONTROL, fused);
272 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_BYPASS,
273 IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
279 /******************************************************************************
280 * Set the mac type member in the hw struct.
282 * hw - Struct containing variables accessed by shared code
283 *****************************************************************************/
285 e1000_set_mac_type(struct e1000_hw *hw)
287 DEBUGFUNC("e1000_set_mac_type");
289 switch (hw->device_id) {
290 case E1000_DEV_ID_82542:
291 switch (hw->revision_id) {
292 case E1000_82542_2_0_REV_ID:
293 hw->mac_type = e1000_82542_rev2_0;
295 case E1000_82542_2_1_REV_ID:
296 hw->mac_type = e1000_82542_rev2_1;
299 /* Invalid 82542 revision ID */
300 return -E1000_ERR_MAC_TYPE;
303 case E1000_DEV_ID_82543GC_FIBER:
304 case E1000_DEV_ID_82543GC_COPPER:
305 hw->mac_type = e1000_82543;
307 case E1000_DEV_ID_82544EI_COPPER:
308 case E1000_DEV_ID_82544EI_FIBER:
309 case E1000_DEV_ID_82544GC_COPPER:
310 case E1000_DEV_ID_82544GC_LOM:
311 hw->mac_type = e1000_82544;
313 case E1000_DEV_ID_82540EM:
314 case E1000_DEV_ID_82540EM_LOM:
315 case E1000_DEV_ID_82540EP:
316 case E1000_DEV_ID_82540EP_LOM:
317 case E1000_DEV_ID_82540EP_LP:
318 hw->mac_type = e1000_82540;
320 case E1000_DEV_ID_82545EM_COPPER:
321 case E1000_DEV_ID_82545EM_FIBER:
322 hw->mac_type = e1000_82545;
324 case E1000_DEV_ID_82545GM_COPPER:
325 case E1000_DEV_ID_82545GM_FIBER:
326 case E1000_DEV_ID_82545GM_SERDES:
327 hw->mac_type = e1000_82545_rev_3;
329 case E1000_DEV_ID_82546EB_COPPER:
330 case E1000_DEV_ID_82546EB_FIBER:
331 case E1000_DEV_ID_82546EB_QUAD_COPPER:
332 hw->mac_type = e1000_82546;
334 case E1000_DEV_ID_82546GB_COPPER:
335 case E1000_DEV_ID_82546GB_FIBER:
336 case E1000_DEV_ID_82546GB_SERDES:
337 case E1000_DEV_ID_82546GB_PCIE:
338 case E1000_DEV_ID_82546GB_QUAD_COPPER:
339 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
340 hw->mac_type = e1000_82546_rev_3;
342 case E1000_DEV_ID_82541EI:
343 case E1000_DEV_ID_82541EI_MOBILE:
344 case E1000_DEV_ID_82541ER_LOM:
345 hw->mac_type = e1000_82541;
347 case E1000_DEV_ID_82541ER:
348 case E1000_DEV_ID_82541GI:
349 case E1000_DEV_ID_82541GI_LF:
350 case E1000_DEV_ID_82541GI_MOBILE:
351 hw->mac_type = e1000_82541_rev_2;
353 case E1000_DEV_ID_82547EI:
354 case E1000_DEV_ID_82547EI_MOBILE:
355 hw->mac_type = e1000_82547;
357 case E1000_DEV_ID_82547GI:
358 hw->mac_type = e1000_82547_rev_2;
360 case E1000_DEV_ID_82571EB_COPPER:
361 case E1000_DEV_ID_82571EB_FIBER:
362 case E1000_DEV_ID_82571EB_SERDES:
363 hw->mac_type = e1000_82571;
365 case E1000_DEV_ID_82572EI_COPPER:
366 case E1000_DEV_ID_82572EI_FIBER:
367 case E1000_DEV_ID_82572EI_SERDES:
368 case E1000_DEV_ID_82572EI:
369 hw->mac_type = e1000_82572;
371 case E1000_DEV_ID_82573E:
372 case E1000_DEV_ID_82573E_IAMT:
373 case E1000_DEV_ID_82573L:
374 hw->mac_type = e1000_82573;
376 case E1000_DEV_ID_80003ES2LAN_COPPER_SPT:
377 case E1000_DEV_ID_80003ES2LAN_SERDES_SPT:
378 case E1000_DEV_ID_80003ES2LAN_COPPER_DPT:
379 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
380 hw->mac_type = e1000_80003es2lan;
382 case E1000_DEV_ID_ICH8_IGP_M_AMT:
383 case E1000_DEV_ID_ICH8_IGP_AMT:
384 case E1000_DEV_ID_ICH8_IGP_C:
385 case E1000_DEV_ID_ICH8_IFE:
386 case E1000_DEV_ID_ICH8_IGP_M:
387 hw->mac_type = e1000_ich8lan;
390 /* Should never have loaded on this device */
391 return -E1000_ERR_MAC_TYPE;
394 switch(hw->mac_type) {
396 hw->swfwhw_semaphore_present = TRUE;
397 hw->asf_firmware_present = TRUE;
399 case e1000_80003es2lan:
400 hw->swfw_sync_present = TRUE;
405 hw->eeprom_semaphore_present = TRUE;
409 case e1000_82541_rev_2:
410 case e1000_82547_rev_2:
411 hw->asf_firmware_present = TRUE;
417 return E1000_SUCCESS;
420 /*****************************************************************************
421 * Set media type and TBI compatibility.
423 * hw - Struct containing variables accessed by shared code
424 * **************************************************************************/
426 e1000_set_media_type(struct e1000_hw *hw)
430 DEBUGFUNC("e1000_set_media_type");
432 if(hw->mac_type != e1000_82543) {
433 /* tbi_compatibility is only valid on 82543 */
434 hw->tbi_compatibility_en = FALSE;
437 switch (hw->device_id) {
438 case E1000_DEV_ID_82545GM_SERDES:
439 case E1000_DEV_ID_82546GB_SERDES:
440 case E1000_DEV_ID_82571EB_SERDES:
441 case E1000_DEV_ID_82572EI_SERDES:
442 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
443 hw->media_type = e1000_media_type_internal_serdes;
446 switch (hw->mac_type) {
447 case e1000_82542_rev2_0:
448 case e1000_82542_rev2_1:
449 hw->media_type = e1000_media_type_fiber;
453 /* The STATUS_TBIMODE bit is reserved or reused for the this
456 hw->media_type = e1000_media_type_copper;
459 status = E1000_READ_REG(hw, STATUS);
460 if (status & E1000_STATUS_TBIMODE) {
461 hw->media_type = e1000_media_type_fiber;
462 /* tbi_compatibility not valid on fiber */
463 hw->tbi_compatibility_en = FALSE;
465 hw->media_type = e1000_media_type_copper;
472 /******************************************************************************
473 * Reset the transmit and receive units; mask and clear all interrupts.
475 * hw - Struct containing variables accessed by shared code
476 *****************************************************************************/
478 e1000_reset_hw(struct e1000_hw *hw)
486 uint32_t extcnf_ctrl;
489 DEBUGFUNC("e1000_reset_hw");
491 /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
492 if(hw->mac_type == e1000_82542_rev2_0) {
493 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
494 e1000_pci_clear_mwi(hw);
497 if(hw->bus_type == e1000_bus_type_pci_express) {
498 /* Prevent the PCI-E bus from sticking if there is no TLP connection
499 * on the last TLP read/write transaction when MAC is reset.
501 if(e1000_disable_pciex_master(hw) != E1000_SUCCESS) {
502 DEBUGOUT("PCI-E Master disable polling has failed.\n");
506 /* Clear interrupt mask to stop board from generating interrupts */
507 DEBUGOUT("Masking off all interrupts\n");
508 E1000_WRITE_REG(hw, IMC, 0xffffffff);
510 /* Disable the Transmit and Receive units. Then delay to allow
511 * any pending transactions to complete before we hit the MAC with
514 E1000_WRITE_REG(hw, RCTL, 0);
515 E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP);
516 E1000_WRITE_FLUSH(hw);
518 /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
519 hw->tbi_compatibility_on = FALSE;
521 /* Delay to allow any outstanding PCI transactions to complete before
522 * resetting the device
526 ctrl = E1000_READ_REG(hw, CTRL);
528 /* Must reset the PHY before resetting the MAC */
529 if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
530 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_PHY_RST));
534 /* Must acquire the MDIO ownership before MAC reset.
535 * Ownership defaults to firmware after a reset. */
536 if(hw->mac_type == e1000_82573) {
539 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
540 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
543 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
544 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
546 if(extcnf_ctrl & E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP)
549 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
556 /* Workaround for ICH8 bit corruption issue in FIFO memory */
557 if (hw->mac_type == e1000_ich8lan) {
558 /* Set Tx and Rx buffer allocation to 8k apiece. */
559 E1000_WRITE_REG(hw, PBA, E1000_PBA_8K);
560 /* Set Packet Buffer Size to 16k. */
561 E1000_WRITE_REG(hw, PBS, E1000_PBS_16K);
564 /* Issue a global reset to the MAC. This will reset the chip's
565 * transmit, receive, DMA, and link units. It will not effect
566 * the current PCI configuration. The global reset bit is self-
567 * clearing, and should clear within a microsecond.
569 DEBUGOUT("Issuing a global reset to MAC\n");
571 switch(hw->mac_type) {
577 case e1000_82541_rev_2:
578 /* These controllers can't ack the 64-bit write when issuing the
579 * reset, so use IO-mapping as a workaround to issue the reset */
580 E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
582 case e1000_82545_rev_3:
583 case e1000_82546_rev_3:
584 /* Reset is performed on a shadow of the control register */
585 E1000_WRITE_REG(hw, CTRL_DUP, (ctrl | E1000_CTRL_RST));
588 if (!hw->phy_reset_disable &&
589 e1000_check_phy_reset_block(hw) == E1000_SUCCESS) {
590 /* e1000_ich8lan PHY HW reset requires MAC CORE reset
591 * at the same time to make sure the interface between
592 * MAC and the external PHY is reset.
594 ctrl |= E1000_CTRL_PHY_RST;
597 e1000_get_software_flag(hw);
598 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
602 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
606 /* After MAC reset, force reload of EEPROM to restore power-on settings to
607 * device. Later controllers reload the EEPROM automatically, so just wait
608 * for reload to complete.
610 switch(hw->mac_type) {
611 case e1000_82542_rev2_0:
612 case e1000_82542_rev2_1:
615 /* Wait for reset to complete */
617 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
618 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
619 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
620 E1000_WRITE_FLUSH(hw);
621 /* Wait for EEPROM reload */
625 case e1000_82541_rev_2:
627 case e1000_82547_rev_2:
628 /* Wait for EEPROM reload */
632 if (e1000_is_onboard_nvm_eeprom(hw) == FALSE) {
634 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
635 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
636 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
637 E1000_WRITE_FLUSH(hw);
643 case e1000_80003es2lan:
644 ret_val = e1000_get_auto_rd_done(hw);
646 /* We don't want to continue accessing MAC registers. */
650 /* Wait for EEPROM reload (it happens automatically) */
655 /* Disable HW ARPs on ASF enabled adapters */
656 if(hw->mac_type >= e1000_82540 && hw->mac_type <= e1000_82547_rev_2) {
657 manc = E1000_READ_REG(hw, MANC);
658 manc &= ~(E1000_MANC_ARP_EN);
659 E1000_WRITE_REG(hw, MANC, manc);
662 if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
663 e1000_phy_init_script(hw);
665 /* Configure activity LED after PHY reset */
666 led_ctrl = E1000_READ_REG(hw, LEDCTL);
667 led_ctrl &= IGP_ACTIVITY_LED_MASK;
668 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
669 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
672 /* Clear interrupt mask to stop board from generating interrupts */
673 DEBUGOUT("Masking off all interrupts\n");
674 E1000_WRITE_REG(hw, IMC, 0xffffffff);
676 /* Clear any pending interrupt events. */
677 icr = E1000_READ_REG(hw, ICR);
679 /* If MWI was previously enabled, reenable it. */
680 if(hw->mac_type == e1000_82542_rev2_0) {
681 if(hw->pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
682 e1000_pci_set_mwi(hw);
685 if (hw->mac_type == e1000_ich8lan) {
686 uint32_t kab = E1000_READ_REG(hw, KABGTXD);
687 kab |= E1000_KABGTXD_BGSQLBIAS;
688 E1000_WRITE_REG(hw, KABGTXD, kab);
691 return E1000_SUCCESS;
694 /******************************************************************************
695 * Performs basic configuration of the adapter.
697 * hw - Struct containing variables accessed by shared code
699 * Assumes that the controller has previously been reset and is in a
700 * post-reset uninitialized state. Initializes the receive address registers,
701 * multicast table, and VLAN filter table. Calls routines to setup link
702 * configuration and flow control settings. Clears all on-chip counters. Leaves
703 * the transmit and receive units disabled and uninitialized.
704 *****************************************************************************/
706 e1000_init_hw(struct e1000_hw *hw)
711 uint16_t pcix_cmd_word;
712 uint16_t pcix_stat_hi_word;
719 DEBUGFUNC("e1000_init_hw");
721 /* force full DMA clock frequency for 10/100 on ICH8 A0-B0 */
722 if (hw->mac_type == e1000_ich8lan) {
723 reg_data = E1000_READ_REG(hw, TARC0);
724 reg_data |= 0x30000000;
725 E1000_WRITE_REG(hw, TARC0, reg_data);
727 reg_data = E1000_READ_REG(hw, STATUS);
728 reg_data &= ~0x80000000;
729 E1000_WRITE_REG(hw, STATUS, reg_data);
732 /* Initialize Identification LED */
733 ret_val = e1000_id_led_init(hw);
735 DEBUGOUT("Error Initializing Identification LED\n");
739 /* Set the media type and TBI compatibility */
740 e1000_set_media_type(hw);
742 /* Disabling VLAN filtering. */
743 DEBUGOUT("Initializing the IEEE VLAN\n");
744 /* VET hardcoded to standard value and VFTA removed in ICH8 LAN */
745 if (hw->mac_type != e1000_ich8lan) {
746 if (hw->mac_type < e1000_82545_rev_3)
747 E1000_WRITE_REG(hw, VET, 0);
748 e1000_clear_vfta(hw);
751 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
752 if(hw->mac_type == e1000_82542_rev2_0) {
753 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
754 e1000_pci_clear_mwi(hw);
755 E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST);
756 E1000_WRITE_FLUSH(hw);
760 /* Setup the receive address. This involves initializing all of the Receive
761 * Address Registers (RARs 0 - 15).
763 e1000_init_rx_addrs(hw);
765 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
766 if(hw->mac_type == e1000_82542_rev2_0) {
767 E1000_WRITE_REG(hw, RCTL, 0);
768 E1000_WRITE_FLUSH(hw);
770 if(hw->pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
771 e1000_pci_set_mwi(hw);
774 /* Zero out the Multicast HASH table */
775 DEBUGOUT("Zeroing the MTA\n");
776 mta_size = E1000_MC_TBL_SIZE;
777 if (hw->mac_type == e1000_ich8lan)
778 mta_size = E1000_MC_TBL_SIZE_ICH8LAN;
779 for(i = 0; i < mta_size; i++) {
780 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
781 /* use write flush to prevent Memory Write Block (MWB) from
782 * occuring when accessing our register space */
783 E1000_WRITE_FLUSH(hw);
786 /* Set the PCI priority bit correctly in the CTRL register. This
787 * determines if the adapter gives priority to receives, or if it
788 * gives equal priority to transmits and receives. Valid only on
789 * 82542 and 82543 silicon.
791 if(hw->dma_fairness && hw->mac_type <= e1000_82543) {
792 ctrl = E1000_READ_REG(hw, CTRL);
793 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PRIOR);
796 switch(hw->mac_type) {
797 case e1000_82545_rev_3:
798 case e1000_82546_rev_3:
801 /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
802 if(hw->bus_type == e1000_bus_type_pcix) {
803 e1000_read_pci_cfg(hw, PCIX_COMMAND_REGISTER, &pcix_cmd_word);
804 e1000_read_pci_cfg(hw, PCIX_STATUS_REGISTER_HI,
806 cmd_mmrbc = (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >>
807 PCIX_COMMAND_MMRBC_SHIFT;
808 stat_mmrbc = (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
809 PCIX_STATUS_HI_MMRBC_SHIFT;
810 if(stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
811 stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
812 if(cmd_mmrbc > stat_mmrbc) {
813 pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK;
814 pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
815 e1000_write_pci_cfg(hw, PCIX_COMMAND_REGISTER,
822 /* More time needed for PHY to initialize */
823 if (hw->mac_type == e1000_ich8lan)
826 /* Call a subroutine to configure the link and setup flow control. */
827 ret_val = e1000_setup_link(hw);
829 /* Set the transmit descriptor write-back policy */
830 if(hw->mac_type > e1000_82544) {
831 ctrl = E1000_READ_REG(hw, TXDCTL);
832 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
833 switch (hw->mac_type) {
840 case e1000_80003es2lan:
841 ctrl |= E1000_TXDCTL_COUNT_DESC;
844 E1000_WRITE_REG(hw, TXDCTL, ctrl);
847 if (hw->mac_type == e1000_82573) {
848 e1000_enable_tx_pkt_filtering(hw);
851 switch (hw->mac_type) {
854 case e1000_80003es2lan:
855 /* Enable retransmit on late collisions */
856 reg_data = E1000_READ_REG(hw, TCTL);
857 reg_data |= E1000_TCTL_RTLC;
858 E1000_WRITE_REG(hw, TCTL, reg_data);
860 /* Configure Gigabit Carry Extend Padding */
861 reg_data = E1000_READ_REG(hw, TCTL_EXT);
862 reg_data &= ~E1000_TCTL_EXT_GCEX_MASK;
863 reg_data |= DEFAULT_80003ES2LAN_TCTL_EXT_GCEX;
864 E1000_WRITE_REG(hw, TCTL_EXT, reg_data);
866 /* Configure Transmit Inter-Packet Gap */
867 reg_data = E1000_READ_REG(hw, TIPG);
868 reg_data &= ~E1000_TIPG_IPGT_MASK;
869 reg_data |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
870 E1000_WRITE_REG(hw, TIPG, reg_data);
872 reg_data = E1000_READ_REG_ARRAY(hw, FFLT, 0x0001);
873 reg_data &= ~0x00100000;
874 E1000_WRITE_REG_ARRAY(hw, FFLT, 0x0001, reg_data);
879 ctrl = E1000_READ_REG(hw, TXDCTL1);
880 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
881 if(hw->mac_type >= e1000_82571)
882 ctrl |= E1000_TXDCTL_COUNT_DESC;
883 E1000_WRITE_REG(hw, TXDCTL1, ctrl);
889 if (hw->mac_type == e1000_82573) {
890 uint32_t gcr = E1000_READ_REG(hw, GCR);
891 gcr |= E1000_GCR_L1_ACT_WITHOUT_L0S_RX;
892 E1000_WRITE_REG(hw, GCR, gcr);
895 /* Clear all of the statistics registers (clear on read). It is
896 * important that we do this after we have tried to establish link
897 * because the symbol error count will increment wildly if there
900 e1000_clear_hw_cntrs(hw);
902 /* ICH8 No-snoop bits are opposite polarity.
903 * Set to snoop by default after reset. */
904 if (hw->mac_type == e1000_ich8lan)
905 e1000_set_pci_ex_no_snoop(hw, PCI_EX_82566_SNOOP_ALL);
907 if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER ||
908 hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) {
909 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
910 /* Relaxed ordering must be disabled to avoid a parity
911 * error crash in a PCI slot. */
912 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
913 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
919 /******************************************************************************
920 * Adjust SERDES output amplitude based on EEPROM setting.
922 * hw - Struct containing variables accessed by shared code.
923 *****************************************************************************/
925 e1000_adjust_serdes_amplitude(struct e1000_hw *hw)
927 uint16_t eeprom_data;
930 DEBUGFUNC("e1000_adjust_serdes_amplitude");
932 if(hw->media_type != e1000_media_type_internal_serdes)
933 return E1000_SUCCESS;
935 switch(hw->mac_type) {
936 case e1000_82545_rev_3:
937 case e1000_82546_rev_3:
940 return E1000_SUCCESS;
943 ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1, &eeprom_data);
948 if(eeprom_data != EEPROM_RESERVED_WORD) {
949 /* Adjust SERDES output amplitude only. */
950 eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK;
951 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data);
956 return E1000_SUCCESS;
959 /******************************************************************************
960 * Configures flow control and link settings.
962 * hw - Struct containing variables accessed by shared code
964 * Determines which flow control settings to use. Calls the apropriate media-
965 * specific link configuration function. Configures the flow control settings.
966 * Assuming the adapter has a valid link partner, a valid link should be
967 * established. Assumes the hardware has previously been reset and the
968 * transmitter and receiver are not enabled.
969 *****************************************************************************/
971 e1000_setup_link(struct e1000_hw *hw)
975 uint16_t eeprom_data;
977 DEBUGFUNC("e1000_setup_link");
979 /* In the case of the phy reset being blocked, we already have a link.
980 * We do not have to set it up again. */
981 if (e1000_check_phy_reset_block(hw))
982 return E1000_SUCCESS;
984 /* Read and store word 0x0F of the EEPROM. This word contains bits
985 * that determine the hardware's default PAUSE (flow control) mode,
986 * a bit that determines whether the HW defaults to enabling or
987 * disabling auto-negotiation, and the direction of the
988 * SW defined pins. If there is no SW over-ride of the flow
989 * control setting, then the variable hw->fc will
990 * be initialized based on a value in the EEPROM.
992 if (hw->fc == e1000_fc_default) {
993 switch (hw->mac_type) {
996 hw->fc = e1000_fc_full;
999 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
1002 DEBUGOUT("EEPROM Read Error\n");
1003 return -E1000_ERR_EEPROM;
1005 if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
1006 hw->fc = e1000_fc_none;
1007 else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
1008 EEPROM_WORD0F_ASM_DIR)
1009 hw->fc = e1000_fc_tx_pause;
1011 hw->fc = e1000_fc_full;
1016 /* We want to save off the original Flow Control configuration just
1017 * in case we get disconnected and then reconnected into a different
1018 * hub or switch with different Flow Control capabilities.
1020 if(hw->mac_type == e1000_82542_rev2_0)
1021 hw->fc &= (~e1000_fc_tx_pause);
1023 if((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
1024 hw->fc &= (~e1000_fc_rx_pause);
1026 hw->original_fc = hw->fc;
1028 DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc);
1030 /* Take the 4 bits from EEPROM word 0x0F that determine the initial
1031 * polarity value for the SW controlled pins, and setup the
1032 * Extended Device Control reg with that info.
1033 * This is needed because one of the SW controlled pins is used for
1034 * signal detection. So this should be done before e1000_setup_pcs_link()
1035 * or e1000_phy_setup() is called.
1037 if (hw->mac_type == e1000_82543) {
1038 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
1041 DEBUGOUT("EEPROM Read Error\n");
1042 return -E1000_ERR_EEPROM;
1044 ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
1046 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1049 /* Call the necessary subroutine to configure the link. */
1050 ret_val = (hw->media_type == e1000_media_type_copper) ?
1051 e1000_setup_copper_link(hw) :
1052 e1000_setup_fiber_serdes_link(hw);
1054 /* Initialize the flow control address, type, and PAUSE timer
1055 * registers to their default values. This is done even if flow
1056 * control is disabled, because it does not hurt anything to
1057 * initialize these registers.
1059 DEBUGOUT("Initializing the Flow Control address, type and timer regs\n");
1061 /* FCAL/H and FCT are hardcoded to standard values in e1000_ich8lan. */
1062 if (hw->mac_type != e1000_ich8lan) {
1063 E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
1064 E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
1065 E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
1068 E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
1070 /* Set the flow control receive threshold registers. Normally,
1071 * these registers will be set to a default threshold that may be
1072 * adjusted later by the driver's runtime code. However, if the
1073 * ability to transmit pause frames in not enabled, then these
1074 * registers will be set to 0.
1076 if(!(hw->fc & e1000_fc_tx_pause)) {
1077 E1000_WRITE_REG(hw, FCRTL, 0);
1078 E1000_WRITE_REG(hw, FCRTH, 0);
1080 /* We need to set up the Receive Threshold high and low water marks
1081 * as well as (optionally) enabling the transmission of XON frames.
1083 if(hw->fc_send_xon) {
1084 E1000_WRITE_REG(hw, FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE));
1085 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
1087 E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water);
1088 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
1094 /******************************************************************************
1095 * Sets up link for a fiber based or serdes based adapter
1097 * hw - Struct containing variables accessed by shared code
1099 * Manipulates Physical Coding Sublayer functions in order to configure
1100 * link. Assumes the hardware has been previously reset and the transmitter
1101 * and receiver are not enabled.
1102 *****************************************************************************/
1104 e1000_setup_fiber_serdes_link(struct e1000_hw *hw)
1110 uint32_t signal = 0;
1113 DEBUGFUNC("e1000_setup_fiber_serdes_link");
1115 /* On 82571 and 82572 Fiber connections, SerDes loopback mode persists
1116 * until explicitly turned off or a power cycle is performed. A read to
1117 * the register does not indicate its status. Therefore, we ensure
1118 * loopback mode is disabled during initialization.
1120 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572)
1121 E1000_WRITE_REG(hw, SCTL, E1000_DISABLE_SERDES_LOOPBACK);
1123 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
1124 * set when the optics detect a signal. On older adapters, it will be
1125 * cleared when there is a signal. This applies to fiber media only.
1126 * If we're on serdes media, adjust the output amplitude to value set in
1129 ctrl = E1000_READ_REG(hw, CTRL);
1130 if(hw->media_type == e1000_media_type_fiber)
1131 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
1133 ret_val = e1000_adjust_serdes_amplitude(hw);
1137 /* Take the link out of reset */
1138 ctrl &= ~(E1000_CTRL_LRST);
1140 /* Adjust VCO speed to improve BER performance */
1141 ret_val = e1000_set_vco_speed(hw);
1145 e1000_config_collision_dist(hw);
1147 /* Check for a software override of the flow control settings, and setup
1148 * the device accordingly. If auto-negotiation is enabled, then software
1149 * will have to set the "PAUSE" bits to the correct value in the Tranmsit
1150 * Config Word Register (TXCW) and re-start auto-negotiation. However, if
1151 * auto-negotiation is disabled, then software will have to manually
1152 * configure the two flow control enable bits in the CTRL register.
1154 * The possible values of the "fc" parameter are:
1155 * 0: Flow control is completely disabled
1156 * 1: Rx flow control is enabled (we can receive pause frames, but
1157 * not send pause frames).
1158 * 2: Tx flow control is enabled (we can send pause frames but we do
1159 * not support receiving pause frames).
1160 * 3: Both Rx and TX flow control (symmetric) are enabled.
1164 /* Flow control is completely disabled by a software over-ride. */
1165 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
1167 case e1000_fc_rx_pause:
1168 /* RX Flow control is enabled and TX Flow control is disabled by a
1169 * software over-ride. Since there really isn't a way to advertise
1170 * that we are capable of RX Pause ONLY, we will advertise that we
1171 * support both symmetric and asymmetric RX PAUSE. Later, we will
1172 * disable the adapter's ability to send PAUSE frames.
1174 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1176 case e1000_fc_tx_pause:
1177 /* TX Flow control is enabled, and RX Flow control is disabled, by a
1178 * software over-ride.
1180 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
1183 /* Flow control (both RX and TX) is enabled by a software over-ride. */
1184 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1187 DEBUGOUT("Flow control param set incorrectly\n");
1188 return -E1000_ERR_CONFIG;
1192 /* Since auto-negotiation is enabled, take the link out of reset (the link
1193 * will be in reset, because we previously reset the chip). This will
1194 * restart auto-negotiation. If auto-neogtiation is successful then the
1195 * link-up status bit will be set and the flow control enable bits (RFCE
1196 * and TFCE) will be set according to their negotiated value.
1198 DEBUGOUT("Auto-negotiation enabled\n");
1200 E1000_WRITE_REG(hw, TXCW, txcw);
1201 E1000_WRITE_REG(hw, CTRL, ctrl);
1202 E1000_WRITE_FLUSH(hw);
1207 /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
1208 * indication in the Device Status Register. Time-out if a link isn't
1209 * seen in 500 milliseconds seconds (Auto-negotiation should complete in
1210 * less than 500 milliseconds even if the other end is doing it in SW).
1211 * For internal serdes, we just assume a signal is present, then poll.
1213 if(hw->media_type == e1000_media_type_internal_serdes ||
1214 (E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) {
1215 DEBUGOUT("Looking for Link\n");
1216 for(i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
1218 status = E1000_READ_REG(hw, STATUS);
1219 if(status & E1000_STATUS_LU) break;
1221 if(i == (LINK_UP_TIMEOUT / 10)) {
1222 DEBUGOUT("Never got a valid link from auto-neg!!!\n");
1223 hw->autoneg_failed = 1;
1224 /* AutoNeg failed to achieve a link, so we'll call
1225 * e1000_check_for_link. This routine will force the link up if
1226 * we detect a signal. This will allow us to communicate with
1227 * non-autonegotiating link partners.
1229 ret_val = e1000_check_for_link(hw);
1231 DEBUGOUT("Error while checking for link\n");
1234 hw->autoneg_failed = 0;
1236 hw->autoneg_failed = 0;
1237 DEBUGOUT("Valid Link Found\n");
1240 DEBUGOUT("No Signal Detected\n");
1242 return E1000_SUCCESS;
1245 /******************************************************************************
1246 * Make sure we have a valid PHY and change PHY mode before link setup.
1248 * hw - Struct containing variables accessed by shared code
1249 ******************************************************************************/
1251 e1000_copper_link_preconfig(struct e1000_hw *hw)
1257 DEBUGFUNC("e1000_copper_link_preconfig");
1259 ctrl = E1000_READ_REG(hw, CTRL);
1260 /* With 82543, we need to force speed and duplex on the MAC equal to what
1261 * the PHY speed and duplex configuration is. In addition, we need to
1262 * perform a hardware reset on the PHY to take it out of reset.
1264 if(hw->mac_type > e1000_82543) {
1265 ctrl |= E1000_CTRL_SLU;
1266 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1267 E1000_WRITE_REG(hw, CTRL, ctrl);
1269 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
1270 E1000_WRITE_REG(hw, CTRL, ctrl);
1271 ret_val = e1000_phy_hw_reset(hw);
1276 /* Make sure we have a valid PHY */
1277 ret_val = e1000_detect_gig_phy(hw);
1279 DEBUGOUT("Error, did not detect valid phy.\n");
1282 DEBUGOUT1("Phy ID = %x \n", hw->phy_id);
1284 /* Set PHY to class A mode (if necessary) */
1285 ret_val = e1000_set_phy_mode(hw);
1289 if((hw->mac_type == e1000_82545_rev_3) ||
1290 (hw->mac_type == e1000_82546_rev_3)) {
1291 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1292 phy_data |= 0x00000008;
1293 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1296 if(hw->mac_type <= e1000_82543 ||
1297 hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
1298 hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2)
1299 hw->phy_reset_disable = FALSE;
1301 return E1000_SUCCESS;
1305 /********************************************************************
1306 * Copper link setup for e1000_phy_igp series.
1308 * hw - Struct containing variables accessed by shared code
1309 *********************************************************************/
1311 e1000_copper_link_igp_setup(struct e1000_hw *hw)
1317 DEBUGFUNC("e1000_copper_link_igp_setup");
1319 if (hw->phy_reset_disable)
1320 return E1000_SUCCESS;
1322 ret_val = e1000_phy_reset(hw);
1324 DEBUGOUT("Error Resetting the PHY\n");
1328 /* Wait 10ms for MAC to configure PHY from eeprom settings */
1330 if (hw->mac_type != e1000_ich8lan) {
1331 /* Configure activity LED after PHY reset */
1332 led_ctrl = E1000_READ_REG(hw, LEDCTL);
1333 led_ctrl &= IGP_ACTIVITY_LED_MASK;
1334 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
1335 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
1338 /* The NVM settings will configure LPLU in D3 for IGP2 and IGP3 PHYs */
1339 if (hw->phy_type == e1000_phy_igp) {
1340 /* disable lplu d3 during driver init */
1341 ret_val = e1000_set_d3_lplu_state(hw, FALSE);
1343 DEBUGOUT("Error Disabling LPLU D3\n");
1348 /* disable lplu d0 during driver init */
1349 ret_val = e1000_set_d0_lplu_state(hw, FALSE);
1351 DEBUGOUT("Error Disabling LPLU D0\n");
1354 /* Configure mdi-mdix settings */
1355 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1359 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
1360 hw->dsp_config_state = e1000_dsp_config_disabled;
1361 /* Force MDI for earlier revs of the IGP PHY */
1362 phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX | IGP01E1000_PSCR_FORCE_MDI_MDIX);
1366 hw->dsp_config_state = e1000_dsp_config_enabled;
1367 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1371 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1374 phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
1378 phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
1382 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1386 /* set auto-master slave resolution settings */
1388 e1000_ms_type phy_ms_setting = hw->master_slave;
1390 if(hw->ffe_config_state == e1000_ffe_config_active)
1391 hw->ffe_config_state = e1000_ffe_config_enabled;
1393 if(hw->dsp_config_state == e1000_dsp_config_activated)
1394 hw->dsp_config_state = e1000_dsp_config_enabled;
1396 /* when autonegotiation advertisment is only 1000Mbps then we
1397 * should disable SmartSpeed and enable Auto MasterSlave
1398 * resolution as hardware default. */
1399 if(hw->autoneg_advertised == ADVERTISE_1000_FULL) {
1400 /* Disable SmartSpeed */
1401 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
1404 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1405 ret_val = e1000_write_phy_reg(hw,
1406 IGP01E1000_PHY_PORT_CONFIG,
1410 /* Set auto Master/Slave resolution process */
1411 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1414 phy_data &= ~CR_1000T_MS_ENABLE;
1415 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1420 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1424 /* load defaults for future use */
1425 hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
1426 ((phy_data & CR_1000T_MS_VALUE) ?
1427 e1000_ms_force_master :
1428 e1000_ms_force_slave) :
1431 switch (phy_ms_setting) {
1432 case e1000_ms_force_master:
1433 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
1435 case e1000_ms_force_slave:
1436 phy_data |= CR_1000T_MS_ENABLE;
1437 phy_data &= ~(CR_1000T_MS_VALUE);
1440 phy_data &= ~CR_1000T_MS_ENABLE;
1444 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1449 return E1000_SUCCESS;
1452 /********************************************************************
1453 * Copper link setup for e1000_phy_gg82563 series.
1455 * hw - Struct containing variables accessed by shared code
1456 *********************************************************************/
1458 e1000_copper_link_ggp_setup(struct e1000_hw *hw)
1464 DEBUGFUNC("e1000_copper_link_ggp_setup");
1466 if(!hw->phy_reset_disable) {
1468 /* Enable CRS on TX for half-duplex operation. */
1469 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL,
1474 phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
1475 /* Use 25MHz for both link down and 1000BASE-T for Tx clock */
1476 phy_data |= GG82563_MSCR_TX_CLK_1000MBPS_25MHZ;
1478 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL,
1484 * MDI/MDI-X = 0 (default)
1485 * 0 - Auto for all speeds
1488 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1490 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_SPEC_CTRL, &phy_data);
1494 phy_data &= ~GG82563_PSCR_CROSSOVER_MODE_MASK;
1498 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDI;
1501 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDIX;
1505 phy_data |= GG82563_PSCR_CROSSOVER_MODE_AUTO;
1510 * disable_polarity_correction = 0 (default)
1511 * Automatic Correction for Reversed Cable Polarity
1515 phy_data &= ~GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
1516 if(hw->disable_polarity_correction == 1)
1517 phy_data |= GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
1518 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_SPEC_CTRL, phy_data);
1523 /* SW Reset the PHY so all changes take effect */
1524 ret_val = e1000_phy_reset(hw);
1526 DEBUGOUT("Error Resetting the PHY\n");
1529 } /* phy_reset_disable */
1531 if (hw->mac_type == e1000_80003es2lan) {
1532 /* Bypass RX and TX FIFO's */
1533 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_FIFO_CTRL,
1534 E1000_KUMCTRLSTA_FIFO_CTRL_RX_BYPASS |
1535 E1000_KUMCTRLSTA_FIFO_CTRL_TX_BYPASS);
1539 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_SPEC_CTRL_2, &phy_data);
1543 phy_data &= ~GG82563_PSCR2_REVERSE_AUTO_NEG;
1544 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_SPEC_CTRL_2, phy_data);
1549 reg_data = E1000_READ_REG(hw, CTRL_EXT);
1550 reg_data &= ~(E1000_CTRL_EXT_LINK_MODE_MASK);
1551 E1000_WRITE_REG(hw, CTRL_EXT, reg_data);
1553 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_PWR_MGMT_CTRL,
1558 /* Do not init these registers when the HW is in IAMT mode, since the
1559 * firmware will have already initialized them. We only initialize
1560 * them if the HW is not in IAMT mode.
1562 if (e1000_check_mng_mode(hw) == FALSE) {
1563 /* Enable Electrical Idle on the PHY */
1564 phy_data |= GG82563_PMCR_ENABLE_ELECTRICAL_IDLE;
1565 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_PWR_MGMT_CTRL,
1570 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
1575 phy_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
1577 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
1583 /* Workaround: Disable padding in Kumeran interface in the MAC
1584 * and in the PHY to avoid CRC errors.
1586 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_INBAND_CTRL,
1590 phy_data |= GG82563_ICR_DIS_PADDING;
1591 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_INBAND_CTRL,
1597 return E1000_SUCCESS;
1600 /********************************************************************
1601 * Copper link setup for e1000_phy_m88 series.
1603 * hw - Struct containing variables accessed by shared code
1604 *********************************************************************/
1606 e1000_copper_link_mgp_setup(struct e1000_hw *hw)
1611 DEBUGFUNC("e1000_copper_link_mgp_setup");
1613 if(hw->phy_reset_disable)
1614 return E1000_SUCCESS;
1616 /* Enable CRS on TX. This must be set for half-duplex operation. */
1617 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1621 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1624 * MDI/MDI-X = 0 (default)
1625 * 0 - Auto for all speeds
1628 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1630 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1634 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
1637 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
1640 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
1644 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
1649 * disable_polarity_correction = 0 (default)
1650 * Automatic Correction for Reversed Cable Polarity
1654 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
1655 if(hw->disable_polarity_correction == 1)
1656 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
1657 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1661 if (hw->phy_revision < M88E1011_I_REV_4) {
1662 /* Force TX_CLK in the Extended PHY Specific Control Register
1665 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1669 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1671 if ((hw->phy_revision == E1000_REVISION_2) &&
1672 (hw->phy_id == M88E1111_I_PHY_ID)) {
1673 /* Vidalia Phy, set the downshift counter to 5x */
1674 phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK);
1675 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
1676 ret_val = e1000_write_phy_reg(hw,
1677 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1681 /* Configure Master and Slave downshift values */
1682 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
1683 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
1684 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
1685 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
1686 ret_val = e1000_write_phy_reg(hw,
1687 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1693 /* SW Reset the PHY so all changes take effect */
1694 ret_val = e1000_phy_reset(hw);
1696 DEBUGOUT("Error Resetting the PHY\n");
1700 return E1000_SUCCESS;
1703 /********************************************************************
1704 * Setup auto-negotiation and flow control advertisements,
1705 * and then perform auto-negotiation.
1707 * hw - Struct containing variables accessed by shared code
1708 *********************************************************************/
1710 e1000_copper_link_autoneg(struct e1000_hw *hw)
1715 DEBUGFUNC("e1000_copper_link_autoneg");
1717 /* Perform some bounds checking on the hw->autoneg_advertised
1718 * parameter. If this variable is zero, then set it to the default.
1720 hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
1722 /* If autoneg_advertised is zero, we assume it was not defaulted
1723 * by the calling code so we set to advertise full capability.
1725 if(hw->autoneg_advertised == 0)
1726 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
1728 /* IFE phy only supports 10/100 */
1729 if (hw->phy_type == e1000_phy_ife)
1730 hw->autoneg_advertised &= AUTONEG_ADVERTISE_10_100_ALL;
1732 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
1733 ret_val = e1000_phy_setup_autoneg(hw);
1735 DEBUGOUT("Error Setting up Auto-Negotiation\n");
1738 DEBUGOUT("Restarting Auto-Neg\n");
1740 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
1741 * the Auto Neg Restart bit in the PHY control register.
1743 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
1747 phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
1748 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
1752 /* Does the user want to wait for Auto-Neg to complete here, or
1753 * check at a later time (for example, callback routine).
1755 if(hw->wait_autoneg_complete) {
1756 ret_val = e1000_wait_autoneg(hw);
1758 DEBUGOUT("Error while waiting for autoneg to complete\n");
1763 hw->get_link_status = TRUE;
1765 return E1000_SUCCESS;
1769 /******************************************************************************
1770 * Config the MAC and the PHY after link is up.
1771 * 1) Set up the MAC to the current PHY speed/duplex
1772 * if we are on 82543. If we
1773 * are on newer silicon, we only need to configure
1774 * collision distance in the Transmit Control Register.
1775 * 2) Set up flow control on the MAC to that established with
1777 * 3) Config DSP to improve Gigabit link quality for some PHY revisions.
1779 * hw - Struct containing variables accessed by shared code
1780 ******************************************************************************/
1782 e1000_copper_link_postconfig(struct e1000_hw *hw)
1785 DEBUGFUNC("e1000_copper_link_postconfig");
1787 if(hw->mac_type >= e1000_82544) {
1788 e1000_config_collision_dist(hw);
1790 ret_val = e1000_config_mac_to_phy(hw);
1792 DEBUGOUT("Error configuring MAC to PHY settings\n");
1796 ret_val = e1000_config_fc_after_link_up(hw);
1798 DEBUGOUT("Error Configuring Flow Control\n");
1802 /* Config DSP to improve Giga link quality */
1803 if(hw->phy_type == e1000_phy_igp) {
1804 ret_val = e1000_config_dsp_after_link_change(hw, TRUE);
1806 DEBUGOUT("Error Configuring DSP after link up\n");
1811 return E1000_SUCCESS;
1814 /******************************************************************************
1815 * Detects which PHY is present and setup the speed and duplex
1817 * hw - Struct containing variables accessed by shared code
1818 ******************************************************************************/
1820 e1000_setup_copper_link(struct e1000_hw *hw)
1827 DEBUGFUNC("e1000_setup_copper_link");
1829 switch (hw->mac_type) {
1830 case e1000_80003es2lan:
1832 /* Set the mac to wait the maximum time between each
1833 * iteration and increase the max iterations when
1834 * polling the phy; this fixes erroneous timeouts at 10Mbps. */
1835 ret_val = e1000_write_kmrn_reg(hw, GG82563_REG(0x34, 4), 0xFFFF);
1838 ret_val = e1000_read_kmrn_reg(hw, GG82563_REG(0x34, 9), ®_data);
1842 ret_val = e1000_write_kmrn_reg(hw, GG82563_REG(0x34, 9), reg_data);
1849 /* Check if it is a valid PHY and set PHY mode if necessary. */
1850 ret_val = e1000_copper_link_preconfig(hw);
1854 switch (hw->mac_type) {
1855 case e1000_80003es2lan:
1856 /* Kumeran registers are written-only */
1857 reg_data = E1000_KUMCTRLSTA_INB_CTRL_LINK_STATUS_TX_TIMEOUT_DEFAULT;
1858 reg_data |= E1000_KUMCTRLSTA_INB_CTRL_DIS_PADDING;
1859 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_INB_CTRL,
1868 if (hw->phy_type == e1000_phy_igp ||
1869 hw->phy_type == e1000_phy_igp_3 ||
1870 hw->phy_type == e1000_phy_igp_2) {
1871 ret_val = e1000_copper_link_igp_setup(hw);
1874 } else if (hw->phy_type == e1000_phy_m88) {
1875 ret_val = e1000_copper_link_mgp_setup(hw);
1878 } else if (hw->phy_type == e1000_phy_gg82563) {
1879 ret_val = e1000_copper_link_ggp_setup(hw);
1885 /* Setup autoneg and flow control advertisement
1886 * and perform autonegotiation */
1887 ret_val = e1000_copper_link_autoneg(hw);
1891 /* PHY will be set to 10H, 10F, 100H,or 100F
1892 * depending on value from forced_speed_duplex. */
1893 DEBUGOUT("Forcing speed and duplex\n");
1894 ret_val = e1000_phy_force_speed_duplex(hw);
1896 DEBUGOUT("Error Forcing Speed and Duplex\n");
1901 /* Check link status. Wait up to 100 microseconds for link to become
1904 for(i = 0; i < 10; i++) {
1905 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
1908 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
1912 if(phy_data & MII_SR_LINK_STATUS) {
1913 /* Config the MAC and PHY after link is up */
1914 ret_val = e1000_copper_link_postconfig(hw);
1918 DEBUGOUT("Valid link established!!!\n");
1919 return E1000_SUCCESS;
1924 DEBUGOUT("Unable to establish link!!!\n");
1925 return E1000_SUCCESS;
1928 /******************************************************************************
1929 * Configure the MAC-to-PHY interface for 10/100Mbps
1931 * hw - Struct containing variables accessed by shared code
1932 ******************************************************************************/
1934 e1000_configure_kmrn_for_10_100(struct e1000_hw *hw, uint16_t duplex)
1936 int32_t ret_val = E1000_SUCCESS;
1940 DEBUGFUNC("e1000_configure_kmrn_for_10_100");
1942 reg_data = E1000_KUMCTRLSTA_HD_CTRL_10_100_DEFAULT;
1943 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_HD_CTRL,
1948 /* Configure Transmit Inter-Packet Gap */
1949 tipg = E1000_READ_REG(hw, TIPG);
1950 tipg &= ~E1000_TIPG_IPGT_MASK;
1951 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_10_100;
1952 E1000_WRITE_REG(hw, TIPG, tipg);
1954 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, ®_data);
1959 if (duplex == HALF_DUPLEX)
1960 reg_data |= GG82563_KMCR_PASS_FALSE_CARRIER;
1962 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
1964 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
1970 e1000_configure_kmrn_for_1000(struct e1000_hw *hw)
1972 int32_t ret_val = E1000_SUCCESS;
1976 DEBUGFUNC("e1000_configure_kmrn_for_1000");
1978 reg_data = E1000_KUMCTRLSTA_HD_CTRL_1000_DEFAULT;
1979 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_HD_CTRL,
1984 /* Configure Transmit Inter-Packet Gap */
1985 tipg = E1000_READ_REG(hw, TIPG);
1986 tipg &= ~E1000_TIPG_IPGT_MASK;
1987 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
1988 E1000_WRITE_REG(hw, TIPG, tipg);
1990 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, ®_data);
1995 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
1996 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
2001 /******************************************************************************
2002 * Configures PHY autoneg and flow control advertisement settings
2004 * hw - Struct containing variables accessed by shared code
2005 ******************************************************************************/
2007 e1000_phy_setup_autoneg(struct e1000_hw *hw)
2010 uint16_t mii_autoneg_adv_reg;
2011 uint16_t mii_1000t_ctrl_reg;
2013 DEBUGFUNC("e1000_phy_setup_autoneg");
2015 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
2016 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
2020 if (hw->phy_type != e1000_phy_ife) {
2021 /* Read the MII 1000Base-T Control Register (Address 9). */
2022 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
2026 mii_1000t_ctrl_reg=0;
2028 /* Need to parse both autoneg_advertised and fc and set up
2029 * the appropriate PHY registers. First we will parse for
2030 * autoneg_advertised software override. Since we can advertise
2031 * a plethora of combinations, we need to check each bit
2035 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
2036 * Advertisement Register (Address 4) and the 1000 mb speed bits in
2037 * the 1000Base-T Control Register (Address 9).
2039 mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
2040 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
2042 DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised);
2044 /* Do we want to advertise 10 Mb Half Duplex? */
2045 if(hw->autoneg_advertised & ADVERTISE_10_HALF) {
2046 DEBUGOUT("Advertise 10mb Half duplex\n");
2047 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
2050 /* Do we want to advertise 10 Mb Full Duplex? */
2051 if(hw->autoneg_advertised & ADVERTISE_10_FULL) {
2052 DEBUGOUT("Advertise 10mb Full duplex\n");
2053 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
2056 /* Do we want to advertise 100 Mb Half Duplex? */
2057 if(hw->autoneg_advertised & ADVERTISE_100_HALF) {
2058 DEBUGOUT("Advertise 100mb Half duplex\n");
2059 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
2062 /* Do we want to advertise 100 Mb Full Duplex? */
2063 if(hw->autoneg_advertised & ADVERTISE_100_FULL) {
2064 DEBUGOUT("Advertise 100mb Full duplex\n");
2065 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
2068 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
2069 if(hw->autoneg_advertised & ADVERTISE_1000_HALF) {
2070 DEBUGOUT("Advertise 1000mb Half duplex requested, request denied!\n");
2073 /* Do we want to advertise 1000 Mb Full Duplex? */
2074 if(hw->autoneg_advertised & ADVERTISE_1000_FULL) {
2075 DEBUGOUT("Advertise 1000mb Full duplex\n");
2076 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
2077 if (hw->phy_type == e1000_phy_ife) {
2078 DEBUGOUT("e1000_phy_ife is a 10/100 PHY. Gigabit speed is not supported.\n");
2082 /* Check for a software override of the flow control settings, and
2083 * setup the PHY advertisement registers accordingly. If
2084 * auto-negotiation is enabled, then software will have to set the
2085 * "PAUSE" bits to the correct value in the Auto-Negotiation
2086 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
2088 * The possible values of the "fc" parameter are:
2089 * 0: Flow control is completely disabled
2090 * 1: Rx flow control is enabled (we can receive pause frames
2091 * but not send pause frames).
2092 * 2: Tx flow control is enabled (we can send pause frames
2093 * but we do not support receiving pause frames).
2094 * 3: Both Rx and TX flow control (symmetric) are enabled.
2095 * other: No software override. The flow control configuration
2096 * in the EEPROM is used.
2099 case e1000_fc_none: /* 0 */
2100 /* Flow control (RX & TX) is completely disabled by a
2101 * software over-ride.
2103 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2105 case e1000_fc_rx_pause: /* 1 */
2106 /* RX Flow control is enabled, and TX Flow control is
2107 * disabled, by a software over-ride.
2109 /* Since there really isn't a way to advertise that we are
2110 * capable of RX Pause ONLY, we will advertise that we
2111 * support both symmetric and asymmetric RX PAUSE. Later
2112 * (in e1000_config_fc_after_link_up) we will disable the
2113 *hw's ability to send PAUSE frames.
2115 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2117 case e1000_fc_tx_pause: /* 2 */
2118 /* TX Flow control is enabled, and RX Flow control is
2119 * disabled, by a software over-ride.
2121 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
2122 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
2124 case e1000_fc_full: /* 3 */
2125 /* Flow control (both RX and TX) is enabled by a software
2128 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2131 DEBUGOUT("Flow control param set incorrectly\n");
2132 return -E1000_ERR_CONFIG;
2135 ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
2139 DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
2141 if (hw->phy_type != e1000_phy_ife) {
2142 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg);
2147 return E1000_SUCCESS;
2150 /******************************************************************************
2151 * Force PHY speed and duplex settings to hw->forced_speed_duplex
2153 * hw - Struct containing variables accessed by shared code
2154 ******************************************************************************/
2156 e1000_phy_force_speed_duplex(struct e1000_hw *hw)
2160 uint16_t mii_ctrl_reg;
2161 uint16_t mii_status_reg;
2165 DEBUGFUNC("e1000_phy_force_speed_duplex");
2167 /* Turn off Flow control if we are forcing speed and duplex. */
2168 hw->fc = e1000_fc_none;
2170 DEBUGOUT1("hw->fc = %d\n", hw->fc);
2172 /* Read the Device Control Register. */
2173 ctrl = E1000_READ_REG(hw, CTRL);
2175 /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */
2176 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2177 ctrl &= ~(DEVICE_SPEED_MASK);
2179 /* Clear the Auto Speed Detect Enable bit. */
2180 ctrl &= ~E1000_CTRL_ASDE;
2182 /* Read the MII Control Register. */
2183 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg);
2187 /* We need to disable autoneg in order to force link and duplex. */
2189 mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN;
2191 /* Are we forcing Full or Half Duplex? */
2192 if(hw->forced_speed_duplex == e1000_100_full ||
2193 hw->forced_speed_duplex == e1000_10_full) {
2194 /* We want to force full duplex so we SET the full duplex bits in the
2195 * Device and MII Control Registers.
2197 ctrl |= E1000_CTRL_FD;
2198 mii_ctrl_reg |= MII_CR_FULL_DUPLEX;
2199 DEBUGOUT("Full Duplex\n");
2201 /* We want to force half duplex so we CLEAR the full duplex bits in
2202 * the Device and MII Control Registers.
2204 ctrl &= ~E1000_CTRL_FD;
2205 mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX;
2206 DEBUGOUT("Half Duplex\n");
2209 /* Are we forcing 100Mbps??? */
2210 if(hw->forced_speed_duplex == e1000_100_full ||
2211 hw->forced_speed_duplex == e1000_100_half) {
2212 /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */
2213 ctrl |= E1000_CTRL_SPD_100;
2214 mii_ctrl_reg |= MII_CR_SPEED_100;
2215 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
2216 DEBUGOUT("Forcing 100mb ");
2218 /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */
2219 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
2220 mii_ctrl_reg |= MII_CR_SPEED_10;
2221 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
2222 DEBUGOUT("Forcing 10mb ");
2225 e1000_config_collision_dist(hw);
2227 /* Write the configured values back to the Device Control Reg. */
2228 E1000_WRITE_REG(hw, CTRL, ctrl);
2230 if ((hw->phy_type == e1000_phy_m88) ||
2231 (hw->phy_type == e1000_phy_gg82563)) {
2232 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
2236 /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
2237 * forced whenever speed are duplex are forced.
2239 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
2240 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
2244 DEBUGOUT1("M88E1000 PSCR: %x \n", phy_data);
2246 /* Need to reset the PHY or these changes will be ignored */
2247 mii_ctrl_reg |= MII_CR_RESET;
2248 /* Disable MDI-X support for 10/100 */
2249 } else if (hw->phy_type == e1000_phy_ife) {
2250 ret_val = e1000_read_phy_reg(hw, IFE_PHY_MDIX_CONTROL, &phy_data);
2254 phy_data &= ~IFE_PMC_AUTO_MDIX;
2255 phy_data &= ~IFE_PMC_FORCE_MDIX;
2257 ret_val = e1000_write_phy_reg(hw, IFE_PHY_MDIX_CONTROL, phy_data);
2261 /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
2262 * forced whenever speed or duplex are forced.
2264 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
2268 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
2269 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
2271 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
2276 /* Write back the modified PHY MII control register. */
2277 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg);
2283 /* The wait_autoneg_complete flag may be a little misleading here.
2284 * Since we are forcing speed and duplex, Auto-Neg is not enabled.
2285 * But we do want to delay for a period while forcing only so we
2286 * don't generate false No Link messages. So we will wait here
2287 * only if the user has set wait_autoneg_complete to 1, which is
2290 if(hw->wait_autoneg_complete) {
2291 /* We will wait for autoneg to complete. */
2292 DEBUGOUT("Waiting for forced speed/duplex link.\n");
2295 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
2296 for(i = PHY_FORCE_TIME; i > 0; i--) {
2297 /* Read the MII Status Register and wait for Auto-Neg Complete bit
2300 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2304 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2308 if(mii_status_reg & MII_SR_LINK_STATUS) break;
2312 ((hw->phy_type == e1000_phy_m88) ||
2313 (hw->phy_type == e1000_phy_gg82563))) {
2314 /* We didn't get link. Reset the DSP and wait again for link. */
2315 ret_val = e1000_phy_reset_dsp(hw);
2317 DEBUGOUT("Error Resetting PHY DSP\n");
2321 /* This loop will early-out if the link condition has been met. */
2322 for(i = PHY_FORCE_TIME; i > 0; i--) {
2323 if(mii_status_reg & MII_SR_LINK_STATUS) break;
2325 /* Read the MII Status Register and wait for Auto-Neg Complete bit
2328 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2332 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2338 if (hw->phy_type == e1000_phy_m88) {
2339 /* Because we reset the PHY above, we need to re-force TX_CLK in the
2340 * Extended PHY Specific Control Register to 25MHz clock. This value
2341 * defaults back to a 2.5MHz clock when the PHY is reset.
2343 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
2347 phy_data |= M88E1000_EPSCR_TX_CLK_25;
2348 ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
2352 /* In addition, because of the s/w reset above, we need to enable CRS on
2353 * TX. This must be set for both full and half duplex operation.
2355 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
2359 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
2360 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
2364 if((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
2366 (hw->forced_speed_duplex == e1000_10_full ||
2367 hw->forced_speed_duplex == e1000_10_half)) {
2368 ret_val = e1000_polarity_reversal_workaround(hw);
2372 } else if (hw->phy_type == e1000_phy_gg82563) {
2373 /* The TX_CLK of the Extended PHY Specific Control Register defaults
2374 * to 2.5MHz on a reset. We need to re-force it back to 25MHz, if
2375 * we're not in a forced 10/duplex configuration. */
2376 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, &phy_data);
2380 phy_data &= ~GG82563_MSCR_TX_CLK_MASK;
2381 if ((hw->forced_speed_duplex == e1000_10_full) ||
2382 (hw->forced_speed_duplex == e1000_10_half))
2383 phy_data |= GG82563_MSCR_TX_CLK_10MBPS_2_5MHZ;
2385 phy_data |= GG82563_MSCR_TX_CLK_100MBPS_25MHZ;
2387 /* Also due to the reset, we need to enable CRS on Tx. */
2388 phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
2390 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, phy_data);
2394 return E1000_SUCCESS;
2397 /******************************************************************************
2398 * Sets the collision distance in the Transmit Control register
2400 * hw - Struct containing variables accessed by shared code
2402 * Link should have been established previously. Reads the speed and duplex
2403 * information from the Device Status register.
2404 ******************************************************************************/
2406 e1000_config_collision_dist(struct e1000_hw *hw)
2408 uint32_t tctl, coll_dist;
2410 DEBUGFUNC("e1000_config_collision_dist");
2412 if (hw->mac_type < e1000_82543)
2413 coll_dist = E1000_COLLISION_DISTANCE_82542;
2415 coll_dist = E1000_COLLISION_DISTANCE;
2417 tctl = E1000_READ_REG(hw, TCTL);
2419 tctl &= ~E1000_TCTL_COLD;
2420 tctl |= coll_dist << E1000_COLD_SHIFT;
2422 E1000_WRITE_REG(hw, TCTL, tctl);
2423 E1000_WRITE_FLUSH(hw);
2426 /******************************************************************************
2427 * Sets MAC speed and duplex settings to reflect the those in the PHY
2429 * hw - Struct containing variables accessed by shared code
2430 * mii_reg - data to write to the MII control register
2432 * The contents of the PHY register containing the needed information need to
2434 ******************************************************************************/
2436 e1000_config_mac_to_phy(struct e1000_hw *hw)
2442 DEBUGFUNC("e1000_config_mac_to_phy");
2444 /* 82544 or newer MAC, Auto Speed Detection takes care of
2445 * MAC speed/duplex configuration.*/
2446 if (hw->mac_type >= e1000_82544)
2447 return E1000_SUCCESS;
2449 /* Read the Device Control Register and set the bits to Force Speed
2452 ctrl = E1000_READ_REG(hw, CTRL);
2453 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2454 ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
2456 /* Set up duplex in the Device Control and Transmit Control
2457 * registers depending on negotiated values.
2459 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
2463 if(phy_data & M88E1000_PSSR_DPLX)
2464 ctrl |= E1000_CTRL_FD;
2466 ctrl &= ~E1000_CTRL_FD;
2468 e1000_config_collision_dist(hw);
2470 /* Set up speed in the Device Control register depending on
2471 * negotiated values.
2473 if((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
2474 ctrl |= E1000_CTRL_SPD_1000;
2475 else if((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
2476 ctrl |= E1000_CTRL_SPD_100;
2478 /* Write the configured values back to the Device Control Reg. */
2479 E1000_WRITE_REG(hw, CTRL, ctrl);
2480 return E1000_SUCCESS;
2483 /******************************************************************************
2484 * Forces the MAC's flow control settings.
2486 * hw - Struct containing variables accessed by shared code
2488 * Sets the TFCE and RFCE bits in the device control register to reflect
2489 * the adapter settings. TFCE and RFCE need to be explicitly set by
2490 * software when a Copper PHY is used because autonegotiation is managed
2491 * by the PHY rather than the MAC. Software must also configure these
2492 * bits when link is forced on a fiber connection.
2493 *****************************************************************************/
2495 e1000_force_mac_fc(struct e1000_hw *hw)
2499 DEBUGFUNC("e1000_force_mac_fc");
2501 /* Get the current configuration of the Device Control Register */
2502 ctrl = E1000_READ_REG(hw, CTRL);
2504 /* Because we didn't get link via the internal auto-negotiation
2505 * mechanism (we either forced link or we got link via PHY
2506 * auto-neg), we have to manually enable/disable transmit an
2507 * receive flow control.
2509 * The "Case" statement below enables/disable flow control
2510 * according to the "hw->fc" parameter.
2512 * The possible values of the "fc" parameter are:
2513 * 0: Flow control is completely disabled
2514 * 1: Rx flow control is enabled (we can receive pause
2515 * frames but not send pause frames).
2516 * 2: Tx flow control is enabled (we can send pause frames
2517 * frames but we do not receive pause frames).
2518 * 3: Both Rx and TX flow control (symmetric) is enabled.
2519 * other: No other values should be possible at this point.
2524 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
2526 case e1000_fc_rx_pause:
2527 ctrl &= (~E1000_CTRL_TFCE);
2528 ctrl |= E1000_CTRL_RFCE;
2530 case e1000_fc_tx_pause:
2531 ctrl &= (~E1000_CTRL_RFCE);
2532 ctrl |= E1000_CTRL_TFCE;
2535 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
2538 DEBUGOUT("Flow control param set incorrectly\n");
2539 return -E1000_ERR_CONFIG;
2542 /* Disable TX Flow Control for 82542 (rev 2.0) */
2543 if(hw->mac_type == e1000_82542_rev2_0)
2544 ctrl &= (~E1000_CTRL_TFCE);
2546 E1000_WRITE_REG(hw, CTRL, ctrl);
2547 return E1000_SUCCESS;
2550 /******************************************************************************
2551 * Configures flow control settings after link is established
2553 * hw - Struct containing variables accessed by shared code
2555 * Should be called immediately after a valid link has been established.
2556 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
2557 * and autonegotiation is enabled, the MAC flow control settings will be set
2558 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
2559 * and RFCE bits will be automaticaly set to the negotiated flow control mode.
2560 *****************************************************************************/
2562 e1000_config_fc_after_link_up(struct e1000_hw *hw)
2565 uint16_t mii_status_reg;
2566 uint16_t mii_nway_adv_reg;
2567 uint16_t mii_nway_lp_ability_reg;
2571 DEBUGFUNC("e1000_config_fc_after_link_up");
2573 /* Check for the case where we have fiber media and auto-neg failed
2574 * so we had to force link. In this case, we need to force the
2575 * configuration of the MAC to match the "fc" parameter.
2577 if(((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) ||
2578 ((hw->media_type == e1000_media_type_internal_serdes) && (hw->autoneg_failed)) ||
2579 ((hw->media_type == e1000_media_type_copper) && (!hw->autoneg))) {
2580 ret_val = e1000_force_mac_fc(hw);
2582 DEBUGOUT("Error forcing flow control settings\n");
2587 /* Check for the case where we have copper media and auto-neg is
2588 * enabled. In this case, we need to check and see if Auto-Neg
2589 * has completed, and if so, how the PHY and link partner has
2590 * flow control configured.
2592 if((hw->media_type == e1000_media_type_copper) && hw->autoneg) {
2593 /* Read the MII Status Register and check to see if AutoNeg
2594 * has completed. We read this twice because this reg has
2595 * some "sticky" (latched) bits.
2597 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2600 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2604 if(mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
2605 /* The AutoNeg process has completed, so we now need to
2606 * read both the Auto Negotiation Advertisement Register
2607 * (Address 4) and the Auto_Negotiation Base Page Ability
2608 * Register (Address 5) to determine how flow control was
2611 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV,
2615 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY,
2616 &mii_nway_lp_ability_reg);
2620 /* Two bits in the Auto Negotiation Advertisement Register
2621 * (Address 4) and two bits in the Auto Negotiation Base
2622 * Page Ability Register (Address 5) determine flow control
2623 * for both the PHY and the link partner. The following
2624 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
2625 * 1999, describes these PAUSE resolution bits and how flow
2626 * control is determined based upon these settings.
2627 * NOTE: DC = Don't Care
2629 * LOCAL DEVICE | LINK PARTNER
2630 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
2631 *-------|---------|-------|---------|--------------------
2632 * 0 | 0 | DC | DC | e1000_fc_none
2633 * 0 | 1 | 0 | DC | e1000_fc_none
2634 * 0 | 1 | 1 | 0 | e1000_fc_none
2635 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
2636 * 1 | 0 | 0 | DC | e1000_fc_none
2637 * 1 | DC | 1 | DC | e1000_fc_full
2638 * 1 | 1 | 0 | 0 | e1000_fc_none
2639 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
2642 /* Are both PAUSE bits set to 1? If so, this implies
2643 * Symmetric Flow Control is enabled at both ends. The
2644 * ASM_DIR bits are irrelevant per the spec.
2646 * For Symmetric Flow Control:
2648 * LOCAL DEVICE | LINK PARTNER
2649 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2650 *-------|---------|-------|---------|--------------------
2651 * 1 | DC | 1 | DC | e1000_fc_full
2654 if((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2655 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
2656 /* Now we need to check if the user selected RX ONLY
2657 * of pause frames. In this case, we had to advertise
2658 * FULL flow control because we could not advertise RX
2659 * ONLY. Hence, we must now check to see if we need to
2660 * turn OFF the TRANSMISSION of PAUSE frames.
2662 if(hw->original_fc == e1000_fc_full) {
2663 hw->fc = e1000_fc_full;
2664 DEBUGOUT("Flow Control = FULL.\n");
2666 hw->fc = e1000_fc_rx_pause;
2667 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
2670 /* For receiving PAUSE frames ONLY.
2672 * LOCAL DEVICE | LINK PARTNER
2673 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2674 *-------|---------|-------|---------|--------------------
2675 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
2678 else if(!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2679 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2680 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2681 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
2682 hw->fc = e1000_fc_tx_pause;
2683 DEBUGOUT("Flow Control = TX PAUSE frames only.\n");
2685 /* For transmitting PAUSE frames ONLY.
2687 * LOCAL DEVICE | LINK PARTNER
2688 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2689 *-------|---------|-------|---------|--------------------
2690 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
2693 else if((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2694 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2695 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2696 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
2697 hw->fc = e1000_fc_rx_pause;
2698 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
2700 /* Per the IEEE spec, at this point flow control should be
2701 * disabled. However, we want to consider that we could
2702 * be connected to a legacy switch that doesn't advertise
2703 * desired flow control, but can be forced on the link
2704 * partner. So if we advertised no flow control, that is
2705 * what we will resolve to. If we advertised some kind of
2706 * receive capability (Rx Pause Only or Full Flow Control)
2707 * and the link partner advertised none, we will configure
2708 * ourselves to enable Rx Flow Control only. We can do
2709 * this safely for two reasons: If the link partner really
2710 * didn't want flow control enabled, and we enable Rx, no
2711 * harm done since we won't be receiving any PAUSE frames
2712 * anyway. If the intent on the link partner was to have
2713 * flow control enabled, then by us enabling RX only, we
2714 * can at least receive pause frames and process them.
2715 * This is a good idea because in most cases, since we are
2716 * predominantly a server NIC, more times than not we will
2717 * be asked to delay transmission of packets than asking
2718 * our link partner to pause transmission of frames.
2720 else if((hw->original_fc == e1000_fc_none ||
2721 hw->original_fc == e1000_fc_tx_pause) ||
2722 hw->fc_strict_ieee) {
2723 hw->fc = e1000_fc_none;
2724 DEBUGOUT("Flow Control = NONE.\n");
2726 hw->fc = e1000_fc_rx_pause;
2727 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
2730 /* Now we need to do one last check... If we auto-
2731 * negotiated to HALF DUPLEX, flow control should not be
2732 * enabled per IEEE 802.3 spec.
2734 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
2736 DEBUGOUT("Error getting link speed and duplex\n");
2740 if(duplex == HALF_DUPLEX)
2741 hw->fc = e1000_fc_none;
2743 /* Now we call a subroutine to actually force the MAC
2744 * controller to use the correct flow control settings.
2746 ret_val = e1000_force_mac_fc(hw);
2748 DEBUGOUT("Error forcing flow control settings\n");
2752 DEBUGOUT("Copper PHY and Auto Neg has not completed.\n");
2755 return E1000_SUCCESS;
2758 /******************************************************************************
2759 * Checks to see if the link status of the hardware has changed.
2761 * hw - Struct containing variables accessed by shared code
2763 * Called by any function that needs to check the link status of the adapter.
2764 *****************************************************************************/
2766 e1000_check_for_link(struct e1000_hw *hw)
2773 uint32_t signal = 0;
2777 DEBUGFUNC("e1000_check_for_link");
2779 ctrl = E1000_READ_REG(hw, CTRL);
2780 status = E1000_READ_REG(hw, STATUS);
2782 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
2783 * set when the optics detect a signal. On older adapters, it will be
2784 * cleared when there is a signal. This applies to fiber media only.
2786 if((hw->media_type == e1000_media_type_fiber) ||
2787 (hw->media_type == e1000_media_type_internal_serdes)) {
2788 rxcw = E1000_READ_REG(hw, RXCW);
2790 if(hw->media_type == e1000_media_type_fiber) {
2791 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
2792 if(status & E1000_STATUS_LU)
2793 hw->get_link_status = FALSE;
2797 /* If we have a copper PHY then we only want to go out to the PHY
2798 * registers to see if Auto-Neg has completed and/or if our link
2799 * status has changed. The get_link_status flag will be set if we
2800 * receive a Link Status Change interrupt or we have Rx Sequence
2803 if((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
2804 /* First we want to see if the MII Status Register reports
2805 * link. If so, then we want to get the current speed/duplex
2807 * Read the register twice since the link bit is sticky.
2809 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2812 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2816 if(phy_data & MII_SR_LINK_STATUS) {
2817 hw->get_link_status = FALSE;
2818 /* Check if there was DownShift, must be checked immediately after
2820 e1000_check_downshift(hw);
2822 /* If we are on 82544 or 82543 silicon and speed/duplex
2823 * are forced to 10H or 10F, then we will implement the polarity
2824 * reversal workaround. We disable interrupts first, and upon
2825 * returning, place the devices interrupt state to its previous
2826 * value except for the link status change interrupt which will
2827 * happen due to the execution of this workaround.
2830 if((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
2832 (hw->forced_speed_duplex == e1000_10_full ||
2833 hw->forced_speed_duplex == e1000_10_half)) {
2834 E1000_WRITE_REG(hw, IMC, 0xffffffff);
2835 ret_val = e1000_polarity_reversal_workaround(hw);
2836 icr = E1000_READ_REG(hw, ICR);
2837 E1000_WRITE_REG(hw, ICS, (icr & ~E1000_ICS_LSC));
2838 E1000_WRITE_REG(hw, IMS, IMS_ENABLE_MASK);
2842 /* No link detected */
2843 e1000_config_dsp_after_link_change(hw, FALSE);
2847 /* If we are forcing speed/duplex, then we simply return since
2848 * we have already determined whether we have link or not.
2850 if(!hw->autoneg) return -E1000_ERR_CONFIG;
2852 /* optimize the dsp settings for the igp phy */
2853 e1000_config_dsp_after_link_change(hw, TRUE);
2855 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
2856 * have Si on board that is 82544 or newer, Auto
2857 * Speed Detection takes care of MAC speed/duplex
2858 * configuration. So we only need to configure Collision
2859 * Distance in the MAC. Otherwise, we need to force
2860 * speed/duplex on the MAC to the current PHY speed/duplex
2863 if(hw->mac_type >= e1000_82544)
2864 e1000_config_collision_dist(hw);
2866 ret_val = e1000_config_mac_to_phy(hw);
2868 DEBUGOUT("Error configuring MAC to PHY settings\n");
2873 /* Configure Flow Control now that Auto-Neg has completed. First, we
2874 * need to restore the desired flow control settings because we may
2875 * have had to re-autoneg with a different link partner.
2877 ret_val = e1000_config_fc_after_link_up(hw);
2879 DEBUGOUT("Error configuring flow control\n");
2883 /* At this point we know that we are on copper and we have
2884 * auto-negotiated link. These are conditions for checking the link
2885 * partner capability register. We use the link speed to determine if
2886 * TBI compatibility needs to be turned on or off. If the link is not
2887 * at gigabit speed, then TBI compatibility is not needed. If we are
2888 * at gigabit speed, we turn on TBI compatibility.
2890 if(hw->tbi_compatibility_en) {
2891 uint16_t speed, duplex;
2892 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
2894 DEBUGOUT("Error getting link speed and duplex\n");
2897 if (speed != SPEED_1000) {
2898 /* If link speed is not set to gigabit speed, we do not need
2899 * to enable TBI compatibility.
2901 if(hw->tbi_compatibility_on) {
2902 /* If we previously were in the mode, turn it off. */
2903 rctl = E1000_READ_REG(hw, RCTL);
2904 rctl &= ~E1000_RCTL_SBP;
2905 E1000_WRITE_REG(hw, RCTL, rctl);
2906 hw->tbi_compatibility_on = FALSE;
2909 /* If TBI compatibility is was previously off, turn it on. For
2910 * compatibility with a TBI link partner, we will store bad
2911 * packets. Some frames have an additional byte on the end and
2912 * will look like CRC errors to to the hardware.
2914 if(!hw->tbi_compatibility_on) {
2915 hw->tbi_compatibility_on = TRUE;
2916 rctl = E1000_READ_REG(hw, RCTL);
2917 rctl |= E1000_RCTL_SBP;
2918 E1000_WRITE_REG(hw, RCTL, rctl);
2923 /* If we don't have link (auto-negotiation failed or link partner cannot
2924 * auto-negotiate), the cable is plugged in (we have signal), and our
2925 * link partner is not trying to auto-negotiate with us (we are receiving
2926 * idles or data), we need to force link up. We also need to give
2927 * auto-negotiation time to complete, in case the cable was just plugged
2928 * in. The autoneg_failed flag does this.
2930 else if((((hw->media_type == e1000_media_type_fiber) &&
2931 ((ctrl & E1000_CTRL_SWDPIN1) == signal)) ||
2932 (hw->media_type == e1000_media_type_internal_serdes)) &&
2933 (!(status & E1000_STATUS_LU)) &&
2934 (!(rxcw & E1000_RXCW_C))) {
2935 if(hw->autoneg_failed == 0) {
2936 hw->autoneg_failed = 1;
2939 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\n");
2941 /* Disable auto-negotiation in the TXCW register */
2942 E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
2944 /* Force link-up and also force full-duplex. */
2945 ctrl = E1000_READ_REG(hw, CTRL);
2946 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
2947 E1000_WRITE_REG(hw, CTRL, ctrl);
2949 /* Configure Flow Control after forcing link up. */
2950 ret_val = e1000_config_fc_after_link_up(hw);
2952 DEBUGOUT("Error configuring flow control\n");
2956 /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
2957 * auto-negotiation in the TXCW register and disable forced link in the
2958 * Device Control register in an attempt to auto-negotiate with our link
2961 else if(((hw->media_type == e1000_media_type_fiber) ||
2962 (hw->media_type == e1000_media_type_internal_serdes)) &&
2963 (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
2964 DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\n");
2965 E1000_WRITE_REG(hw, TXCW, hw->txcw);
2966 E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
2968 hw->serdes_link_down = FALSE;
2970 /* If we force link for non-auto-negotiation switch, check link status
2971 * based on MAC synchronization for internal serdes media type.
2973 else if((hw->media_type == e1000_media_type_internal_serdes) &&
2974 !(E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
2975 /* SYNCH bit and IV bit are sticky. */
2977 if(E1000_RXCW_SYNCH & E1000_READ_REG(hw, RXCW)) {
2978 if(!(rxcw & E1000_RXCW_IV)) {
2979 hw->serdes_link_down = FALSE;
2980 DEBUGOUT("SERDES: Link is up.\n");
2983 hw->serdes_link_down = TRUE;
2984 DEBUGOUT("SERDES: Link is down.\n");
2987 if((hw->media_type == e1000_media_type_internal_serdes) &&
2988 (E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
2989 hw->serdes_link_down = !(E1000_STATUS_LU & E1000_READ_REG(hw, STATUS));
2991 return E1000_SUCCESS;
2994 /******************************************************************************
2995 * Detects the current speed and duplex settings of the hardware.
2997 * hw - Struct containing variables accessed by shared code
2998 * speed - Speed of the connection
2999 * duplex - Duplex setting of the connection
3000 *****************************************************************************/
3002 e1000_get_speed_and_duplex(struct e1000_hw *hw,
3010 DEBUGFUNC("e1000_get_speed_and_duplex");
3012 if(hw->mac_type >= e1000_82543) {
3013 status = E1000_READ_REG(hw, STATUS);
3014 if(status & E1000_STATUS_SPEED_1000) {
3015 *speed = SPEED_1000;
3016 DEBUGOUT("1000 Mbs, ");
3017 } else if(status & E1000_STATUS_SPEED_100) {
3019 DEBUGOUT("100 Mbs, ");
3022 DEBUGOUT("10 Mbs, ");
3025 if(status & E1000_STATUS_FD) {
3026 *duplex = FULL_DUPLEX;
3027 DEBUGOUT("Full Duplex\n");
3029 *duplex = HALF_DUPLEX;
3030 DEBUGOUT(" Half Duplex\n");
3033 DEBUGOUT("1000 Mbs, Full Duplex\n");
3034 *speed = SPEED_1000;
3035 *duplex = FULL_DUPLEX;
3038 /* IGP01 PHY may advertise full duplex operation after speed downgrade even
3039 * if it is operating at half duplex. Here we set the duplex settings to
3040 * match the duplex in the link partner's capabilities.
3042 if(hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
3043 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
3047 if(!(phy_data & NWAY_ER_LP_NWAY_CAPS))
3048 *duplex = HALF_DUPLEX;
3050 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data);
3053 if((*speed == SPEED_100 && !(phy_data & NWAY_LPAR_100TX_FD_CAPS)) ||
3054 (*speed == SPEED_10 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
3055 *duplex = HALF_DUPLEX;
3059 if ((hw->mac_type == e1000_80003es2lan) &&
3060 (hw->media_type == e1000_media_type_copper)) {
3061 if (*speed == SPEED_1000)
3062 ret_val = e1000_configure_kmrn_for_1000(hw);
3064 ret_val = e1000_configure_kmrn_for_10_100(hw, *duplex);
3069 if ((hw->phy_type == e1000_phy_igp_3) && (*speed == SPEED_1000)) {
3070 ret_val = e1000_kumeran_lock_loss_workaround(hw);
3075 return E1000_SUCCESS;
3078 /******************************************************************************
3079 * Blocks until autoneg completes or times out (~4.5 seconds)
3081 * hw - Struct containing variables accessed by shared code
3082 ******************************************************************************/
3084 e1000_wait_autoneg(struct e1000_hw *hw)
3090 DEBUGFUNC("e1000_wait_autoneg");
3091 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
3093 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
3094 for(i = PHY_AUTO_NEG_TIME; i > 0; i--) {
3095 /* Read the MII Status Register and wait for Auto-Neg
3096 * Complete bit to be set.
3098 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3101 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3104 if(phy_data & MII_SR_AUTONEG_COMPLETE) {
3105 return E1000_SUCCESS;
3109 return E1000_SUCCESS;
3112 /******************************************************************************
3113 * Raises the Management Data Clock
3115 * hw - Struct containing variables accessed by shared code
3116 * ctrl - Device control register's current value
3117 ******************************************************************************/
3119 e1000_raise_mdi_clk(struct e1000_hw *hw,
3122 /* Raise the clock input to the Management Data Clock (by setting the MDC
3123 * bit), and then delay 10 microseconds.
3125 E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
3126 E1000_WRITE_FLUSH(hw);
3130 /******************************************************************************
3131 * Lowers the Management Data Clock
3133 * hw - Struct containing variables accessed by shared code
3134 * ctrl - Device control register's current value
3135 ******************************************************************************/
3137 e1000_lower_mdi_clk(struct e1000_hw *hw,
3140 /* Lower the clock input to the Management Data Clock (by clearing the MDC
3141 * bit), and then delay 10 microseconds.
3143 E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
3144 E1000_WRITE_FLUSH(hw);
3148 /******************************************************************************
3149 * Shifts data bits out to the PHY
3151 * hw - Struct containing variables accessed by shared code
3152 * data - Data to send out to the PHY
3153 * count - Number of bits to shift out
3155 * Bits are shifted out in MSB to LSB order.
3156 ******************************************************************************/
3158 e1000_shift_out_mdi_bits(struct e1000_hw *hw,
3165 /* We need to shift "count" number of bits out to the PHY. So, the value
3166 * in the "data" parameter will be shifted out to the PHY one bit at a
3167 * time. In order to do this, "data" must be broken down into bits.
3170 mask <<= (count - 1);
3172 ctrl = E1000_READ_REG(hw, CTRL);
3174 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
3175 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
3178 /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
3179 * then raising and lowering the Management Data Clock. A "0" is
3180 * shifted out to the PHY by setting the MDIO bit to "0" and then
3181 * raising and lowering the clock.
3183 if(data & mask) ctrl |= E1000_CTRL_MDIO;
3184 else ctrl &= ~E1000_CTRL_MDIO;
3186 E1000_WRITE_REG(hw, CTRL, ctrl);
3187 E1000_WRITE_FLUSH(hw);
3191 e1000_raise_mdi_clk(hw, &ctrl);
3192 e1000_lower_mdi_clk(hw, &ctrl);
3198 /******************************************************************************
3199 * Shifts data bits in from the PHY
3201 * hw - Struct containing variables accessed by shared code
3203 * Bits are shifted in in MSB to LSB order.
3204 ******************************************************************************/
3206 e1000_shift_in_mdi_bits(struct e1000_hw *hw)
3212 /* In order to read a register from the PHY, we need to shift in a total
3213 * of 18 bits from the PHY. The first two bit (turnaround) times are used
3214 * to avoid contention on the MDIO pin when a read operation is performed.
3215 * These two bits are ignored by us and thrown away. Bits are "shifted in"
3216 * by raising the input to the Management Data Clock (setting the MDC bit),
3217 * and then reading the value of the MDIO bit.
3219 ctrl = E1000_READ_REG(hw, CTRL);
3221 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
3222 ctrl &= ~E1000_CTRL_MDIO_DIR;
3223 ctrl &= ~E1000_CTRL_MDIO;
3225 E1000_WRITE_REG(hw, CTRL, ctrl);
3226 E1000_WRITE_FLUSH(hw);
3228 /* Raise and Lower the clock before reading in the data. This accounts for
3229 * the turnaround bits. The first clock occurred when we clocked out the
3230 * last bit of the Register Address.
3232 e1000_raise_mdi_clk(hw, &ctrl);
3233 e1000_lower_mdi_clk(hw, &ctrl);
3235 for(data = 0, i = 0; i < 16; i++) {
3237 e1000_raise_mdi_clk(hw, &ctrl);
3238 ctrl = E1000_READ_REG(hw, CTRL);
3239 /* Check to see if we shifted in a "1". */
3240 if(ctrl & E1000_CTRL_MDIO) data |= 1;
3241 e1000_lower_mdi_clk(hw, &ctrl);
3244 e1000_raise_mdi_clk(hw, &ctrl);
3245 e1000_lower_mdi_clk(hw, &ctrl);
3251 e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask)
3253 uint32_t swfw_sync = 0;
3254 uint32_t swmask = mask;
3255 uint32_t fwmask = mask << 16;
3256 int32_t timeout = 200;
3258 DEBUGFUNC("e1000_swfw_sync_acquire");
3260 if (hw->swfwhw_semaphore_present)
3261 return e1000_get_software_flag(hw);
3263 if (!hw->swfw_sync_present)
3264 return e1000_get_hw_eeprom_semaphore(hw);
3267 if (e1000_get_hw_eeprom_semaphore(hw))
3268 return -E1000_ERR_SWFW_SYNC;
3270 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
3271 if (!(swfw_sync & (fwmask | swmask))) {
3275 /* firmware currently using resource (fwmask) */
3276 /* or other software thread currently using resource (swmask) */
3277 e1000_put_hw_eeprom_semaphore(hw);
3283 DEBUGOUT("Driver can't access resource, SW_FW_SYNC timeout.\n");
3284 return -E1000_ERR_SWFW_SYNC;
3287 swfw_sync |= swmask;
3288 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
3290 e1000_put_hw_eeprom_semaphore(hw);
3291 return E1000_SUCCESS;
3295 e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask)
3298 uint32_t swmask = mask;
3300 DEBUGFUNC("e1000_swfw_sync_release");
3302 if (hw->swfwhw_semaphore_present) {
3303 e1000_release_software_flag(hw);
3307 if (!hw->swfw_sync_present) {
3308 e1000_put_hw_eeprom_semaphore(hw);
3312 /* if (e1000_get_hw_eeprom_semaphore(hw))
3313 * return -E1000_ERR_SWFW_SYNC; */
3314 while (e1000_get_hw_eeprom_semaphore(hw) != E1000_SUCCESS);
3317 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
3318 swfw_sync &= ~swmask;
3319 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
3321 e1000_put_hw_eeprom_semaphore(hw);
3324 /*****************************************************************************
3325 * Reads the value from a PHY register, if the value is on a specific non zero
3326 * page, sets the page first.
3327 * hw - Struct containing variables accessed by shared code
3328 * reg_addr - address of the PHY register to read
3329 ******************************************************************************/
3331 e1000_read_phy_reg(struct e1000_hw *hw,
3338 DEBUGFUNC("e1000_read_phy_reg");
3340 if ((hw->mac_type == e1000_80003es2lan) &&
3341 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3342 swfw = E1000_SWFW_PHY1_SM;
3344 swfw = E1000_SWFW_PHY0_SM;
3346 if (e1000_swfw_sync_acquire(hw, swfw))
3347 return -E1000_ERR_SWFW_SYNC;
3349 if ((hw->phy_type == e1000_phy_igp ||
3350 hw->phy_type == e1000_phy_igp_3 ||
3351 hw->phy_type == e1000_phy_igp_2) &&
3352 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
3353 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
3354 (uint16_t)reg_addr);
3356 e1000_swfw_sync_release(hw, swfw);
3359 } else if (hw->phy_type == e1000_phy_gg82563) {
3360 if (((reg_addr & MAX_PHY_REG_ADDRESS) > MAX_PHY_MULTI_PAGE_REG) ||
3361 (hw->mac_type == e1000_80003es2lan)) {
3362 /* Select Configuration Page */
3363 if ((reg_addr & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) {
3364 ret_val = e1000_write_phy_reg_ex(hw, GG82563_PHY_PAGE_SELECT,
3365 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3367 /* Use Alternative Page Select register to access
3368 * registers 30 and 31
3370 ret_val = e1000_write_phy_reg_ex(hw,
3371 GG82563_PHY_PAGE_SELECT_ALT,
3372 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3376 e1000_swfw_sync_release(hw, swfw);
3382 ret_val = e1000_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
3385 e1000_swfw_sync_release(hw, swfw);
3390 e1000_read_phy_reg_ex(struct e1000_hw *hw,
3396 const uint32_t phy_addr = 1;
3398 DEBUGFUNC("e1000_read_phy_reg_ex");
3400 if(reg_addr > MAX_PHY_REG_ADDRESS) {
3401 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
3402 return -E1000_ERR_PARAM;
3405 if(hw->mac_type > e1000_82543) {
3406 /* Set up Op-code, Phy Address, and register address in the MDI
3407 * Control register. The MAC will take care of interfacing with the
3408 * PHY to retrieve the desired data.
3410 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
3411 (phy_addr << E1000_MDIC_PHY_SHIFT) |
3412 (E1000_MDIC_OP_READ));
3414 E1000_WRITE_REG(hw, MDIC, mdic);
3416 /* Poll the ready bit to see if the MDI read completed */
3417 for(i = 0; i < 64; i++) {
3419 mdic = E1000_READ_REG(hw, MDIC);
3420 if(mdic & E1000_MDIC_READY) break;
3422 if(!(mdic & E1000_MDIC_READY)) {
3423 DEBUGOUT("MDI Read did not complete\n");
3424 return -E1000_ERR_PHY;
3426 if(mdic & E1000_MDIC_ERROR) {
3427 DEBUGOUT("MDI Error\n");
3428 return -E1000_ERR_PHY;
3430 *phy_data = (uint16_t) mdic;
3432 /* We must first send a preamble through the MDIO pin to signal the
3433 * beginning of an MII instruction. This is done by sending 32
3434 * consecutive "1" bits.
3436 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
3438 /* Now combine the next few fields that are required for a read
3439 * operation. We use this method instead of calling the
3440 * e1000_shift_out_mdi_bits routine five different times. The format of
3441 * a MII read instruction consists of a shift out of 14 bits and is
3442 * defined as follows:
3443 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
3444 * followed by a shift in of 18 bits. This first two bits shifted in
3445 * are TurnAround bits used to avoid contention on the MDIO pin when a
3446 * READ operation is performed. These two bits are thrown away
3447 * followed by a shift in of 16 bits which contains the desired data.
3449 mdic = ((reg_addr) | (phy_addr << 5) |
3450 (PHY_OP_READ << 10) | (PHY_SOF << 12));
3452 e1000_shift_out_mdi_bits(hw, mdic, 14);
3454 /* Now that we've shifted out the read command to the MII, we need to
3455 * "shift in" the 16-bit value (18 total bits) of the requested PHY
3458 *phy_data = e1000_shift_in_mdi_bits(hw);
3460 return E1000_SUCCESS;
3463 /******************************************************************************
3464 * Writes a value to a PHY register
3466 * hw - Struct containing variables accessed by shared code
3467 * reg_addr - address of the PHY register to write
3468 * data - data to write to the PHY
3469 ******************************************************************************/
3471 e1000_write_phy_reg(struct e1000_hw *hw,
3478 DEBUGFUNC("e1000_write_phy_reg");
3480 if ((hw->mac_type == e1000_80003es2lan) &&
3481 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3482 swfw = E1000_SWFW_PHY1_SM;
3484 swfw = E1000_SWFW_PHY0_SM;
3486 if (e1000_swfw_sync_acquire(hw, swfw))
3487 return -E1000_ERR_SWFW_SYNC;
3489 if ((hw->phy_type == e1000_phy_igp ||
3490 hw->phy_type == e1000_phy_igp_3 ||
3491 hw->phy_type == e1000_phy_igp_2) &&
3492 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
3493 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
3494 (uint16_t)reg_addr);
3496 e1000_swfw_sync_release(hw, swfw);
3499 } else if (hw->phy_type == e1000_phy_gg82563) {
3500 if (((reg_addr & MAX_PHY_REG_ADDRESS) > MAX_PHY_MULTI_PAGE_REG) ||
3501 (hw->mac_type == e1000_80003es2lan)) {
3502 /* Select Configuration Page */
3503 if ((reg_addr & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) {
3504 ret_val = e1000_write_phy_reg_ex(hw, GG82563_PHY_PAGE_SELECT,
3505 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3507 /* Use Alternative Page Select register to access
3508 * registers 30 and 31
3510 ret_val = e1000_write_phy_reg_ex(hw,
3511 GG82563_PHY_PAGE_SELECT_ALT,
3512 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3516 e1000_swfw_sync_release(hw, swfw);
3522 ret_val = e1000_write_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
3525 e1000_swfw_sync_release(hw, swfw);
3530 e1000_write_phy_reg_ex(struct e1000_hw *hw,
3536 const uint32_t phy_addr = 1;
3538 DEBUGFUNC("e1000_write_phy_reg_ex");
3540 if(reg_addr > MAX_PHY_REG_ADDRESS) {
3541 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
3542 return -E1000_ERR_PARAM;
3545 if(hw->mac_type > e1000_82543) {
3546 /* Set up Op-code, Phy Address, register address, and data intended
3547 * for the PHY register in the MDI Control register. The MAC will take
3548 * care of interfacing with the PHY to send the desired data.
3550 mdic = (((uint32_t) phy_data) |
3551 (reg_addr << E1000_MDIC_REG_SHIFT) |
3552 (phy_addr << E1000_MDIC_PHY_SHIFT) |
3553 (E1000_MDIC_OP_WRITE));
3555 E1000_WRITE_REG(hw, MDIC, mdic);
3557 /* Poll the ready bit to see if the MDI read completed */
3558 for(i = 0; i < 640; i++) {
3560 mdic = E1000_READ_REG(hw, MDIC);
3561 if(mdic & E1000_MDIC_READY) break;
3563 if(!(mdic & E1000_MDIC_READY)) {
3564 DEBUGOUT("MDI Write did not complete\n");
3565 return -E1000_ERR_PHY;
3568 /* We'll need to use the SW defined pins to shift the write command
3569 * out to the PHY. We first send a preamble to the PHY to signal the
3570 * beginning of the MII instruction. This is done by sending 32
3571 * consecutive "1" bits.
3573 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
3575 /* Now combine the remaining required fields that will indicate a
3576 * write operation. We use this method instead of calling the
3577 * e1000_shift_out_mdi_bits routine for each field in the command. The
3578 * format of a MII write instruction is as follows:
3579 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
3581 mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
3582 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
3584 mdic |= (uint32_t) phy_data;
3586 e1000_shift_out_mdi_bits(hw, mdic, 32);
3589 return E1000_SUCCESS;
3593 e1000_read_kmrn_reg(struct e1000_hw *hw,
3599 DEBUGFUNC("e1000_read_kmrn_reg");
3601 if ((hw->mac_type == e1000_80003es2lan) &&
3602 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3603 swfw = E1000_SWFW_PHY1_SM;
3605 swfw = E1000_SWFW_PHY0_SM;
3607 if (e1000_swfw_sync_acquire(hw, swfw))
3608 return -E1000_ERR_SWFW_SYNC;
3610 /* Write register address */
3611 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
3612 E1000_KUMCTRLSTA_OFFSET) |
3613 E1000_KUMCTRLSTA_REN;
3614 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
3617 /* Read the data returned */
3618 reg_val = E1000_READ_REG(hw, KUMCTRLSTA);
3619 *data = (uint16_t)reg_val;
3621 e1000_swfw_sync_release(hw, swfw);
3622 return E1000_SUCCESS;
3626 e1000_write_kmrn_reg(struct e1000_hw *hw,
3632 DEBUGFUNC("e1000_write_kmrn_reg");
3634 if ((hw->mac_type == e1000_80003es2lan) &&
3635 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3636 swfw = E1000_SWFW_PHY1_SM;
3638 swfw = E1000_SWFW_PHY0_SM;
3640 if (e1000_swfw_sync_acquire(hw, swfw))
3641 return -E1000_ERR_SWFW_SYNC;
3643 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
3644 E1000_KUMCTRLSTA_OFFSET) | data;
3645 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
3648 e1000_swfw_sync_release(hw, swfw);
3649 return E1000_SUCCESS;
3652 /******************************************************************************
3653 * Returns the PHY to the power-on reset state
3655 * hw - Struct containing variables accessed by shared code
3656 ******************************************************************************/
3658 e1000_phy_hw_reset(struct e1000_hw *hw)
3660 uint32_t ctrl, ctrl_ext;
3665 DEBUGFUNC("e1000_phy_hw_reset");
3667 /* In the case of the phy reset being blocked, it's not an error, we
3668 * simply return success without performing the reset. */
3669 ret_val = e1000_check_phy_reset_block(hw);
3671 return E1000_SUCCESS;
3673 DEBUGOUT("Resetting Phy...\n");
3675 if(hw->mac_type > e1000_82543) {
3676 if ((hw->mac_type == e1000_80003es2lan) &&
3677 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3678 swfw = E1000_SWFW_PHY1_SM;
3680 swfw = E1000_SWFW_PHY0_SM;
3682 if (e1000_swfw_sync_acquire(hw, swfw)) {
3683 e1000_release_software_semaphore(hw);
3684 return -E1000_ERR_SWFW_SYNC;
3686 /* Read the device control register and assert the E1000_CTRL_PHY_RST
3687 * bit. Then, take it out of reset.
3688 * For pre-e1000_82571 hardware, we delay for 10ms between the assert
3689 * and deassert. For e1000_82571 hardware and later, we instead delay
3690 * for 50us between and 10ms after the deassertion.
3692 ctrl = E1000_READ_REG(hw, CTRL);
3693 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST);
3694 E1000_WRITE_FLUSH(hw);
3696 if (hw->mac_type < e1000_82571)
3701 E1000_WRITE_REG(hw, CTRL, ctrl);
3702 E1000_WRITE_FLUSH(hw);
3704 if (hw->mac_type >= e1000_82571)
3706 e1000_swfw_sync_release(hw, swfw);
3708 /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
3709 * bit to put the PHY into reset. Then, take it out of reset.
3711 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
3712 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
3713 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
3714 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
3715 E1000_WRITE_FLUSH(hw);
3717 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
3718 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
3719 E1000_WRITE_FLUSH(hw);
3723 if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
3724 /* Configure activity LED after PHY reset */
3725 led_ctrl = E1000_READ_REG(hw, LEDCTL);
3726 led_ctrl &= IGP_ACTIVITY_LED_MASK;
3727 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
3728 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
3731 /* Wait for FW to finish PHY configuration. */
3732 ret_val = e1000_get_phy_cfg_done(hw);
3733 e1000_release_software_semaphore(hw);
3735 if ((hw->mac_type == e1000_ich8lan) &&
3736 (hw->phy_type == e1000_phy_igp_3)) {
3737 ret_val = e1000_init_lcd_from_nvm(hw);
3744 /******************************************************************************
3747 * hw - Struct containing variables accessed by shared code
3749 * Sets bit 15 of the MII Control regiser
3750 ******************************************************************************/
3752 e1000_phy_reset(struct e1000_hw *hw)
3757 DEBUGFUNC("e1000_phy_reset");
3759 /* In the case of the phy reset being blocked, it's not an error, we
3760 * simply return success without performing the reset. */
3761 ret_val = e1000_check_phy_reset_block(hw);
3763 return E1000_SUCCESS;
3765 switch (hw->mac_type) {
3766 case e1000_82541_rev_2:
3770 ret_val = e1000_phy_hw_reset(hw);
3776 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
3780 phy_data |= MII_CR_RESET;
3781 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
3789 if(hw->phy_type == e1000_phy_igp || hw->phy_type == e1000_phy_igp_2)
3790 e1000_phy_init_script(hw);
3792 return E1000_SUCCESS;
3795 /******************************************************************************
3796 * Work-around for 82566 power-down: on D3 entry-
3797 * 1) disable gigabit link
3798 * 2) write VR power-down enable
3800 * if successful continue, else issue LCD reset and repeat
3802 * hw - struct containing variables accessed by shared code
3803 ******************************************************************************/
3805 e1000_phy_powerdown_workaround(struct e1000_hw *hw)
3811 DEBUGFUNC("e1000_phy_powerdown_workaround");
3813 if (hw->phy_type != e1000_phy_igp_3)
3818 reg = E1000_READ_REG(hw, PHY_CTRL);
3819 E1000_WRITE_REG(hw, PHY_CTRL, reg | E1000_PHY_CTRL_GBE_DISABLE |
3820 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
3822 /* Write VR power-down enable */
3823 e1000_read_phy_reg(hw, IGP3_VR_CTRL, &phy_data);
3824 e1000_write_phy_reg(hw, IGP3_VR_CTRL, phy_data |
3825 IGP3_VR_CTRL_MODE_SHUT);
3827 /* Read it back and test */
3828 e1000_read_phy_reg(hw, IGP3_VR_CTRL, &phy_data);
3829 if ((phy_data & IGP3_VR_CTRL_MODE_SHUT) || retry)
3832 /* Issue PHY reset and repeat at most one more time */
3833 reg = E1000_READ_REG(hw, CTRL);
3834 E1000_WRITE_REG(hw, CTRL, reg | E1000_CTRL_PHY_RST);
3842 /******************************************************************************
3843 * Work-around for 82566 Kumeran PCS lock loss:
3844 * On link status change (i.e. PCI reset, speed change) and link is up and
3846 * 0) if workaround is optionally disabled do nothing
3847 * 1) wait 1ms for Kumeran link to come up
3848 * 2) check Kumeran Diagnostic register PCS lock loss bit
3849 * 3) if not set the link is locked (all is good), otherwise...
3851 * 5) repeat up to 10 times
3852 * Note: this is only called for IGP3 copper when speed is 1gb.
3854 * hw - struct containing variables accessed by shared code
3855 ******************************************************************************/
3857 e1000_kumeran_lock_loss_workaround(struct e1000_hw *hw)
3864 if (hw->kmrn_lock_loss_workaround_disabled)
3865 return E1000_SUCCESS;
3867 /* Make sure link is up before proceeding. If not just return.
3868 * Attempting this while link is negotiating fouls up link
3870 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3871 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3873 if (phy_data & MII_SR_LINK_STATUS) {
3874 for (cnt = 0; cnt < 10; cnt++) {
3875 /* read once to clear */
3876 ret_val = e1000_read_phy_reg(hw, IGP3_KMRN_DIAG, &phy_data);
3879 /* and again to get new status */
3880 ret_val = e1000_read_phy_reg(hw, IGP3_KMRN_DIAG, &phy_data);
3884 /* check for PCS lock */
3885 if (!(phy_data & IGP3_KMRN_DIAG_PCS_LOCK_LOSS))
3886 return E1000_SUCCESS;
3888 /* Issue PHY reset */
3889 e1000_phy_hw_reset(hw);
3892 /* Disable GigE link negotiation */
3893 reg = E1000_READ_REG(hw, PHY_CTRL);
3894 E1000_WRITE_REG(hw, PHY_CTRL, reg | E1000_PHY_CTRL_GBE_DISABLE |
3895 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
3897 /* unable to acquire PCS lock */
3898 return E1000_ERR_PHY;
3901 return E1000_SUCCESS;
3904 /******************************************************************************
3905 * Probes the expected PHY address for known PHY IDs
3907 * hw - Struct containing variables accessed by shared code
3908 ******************************************************************************/
3910 e1000_detect_gig_phy(struct e1000_hw *hw)
3912 int32_t phy_init_status, ret_val;
3913 uint16_t phy_id_high, phy_id_low;
3914 boolean_t match = FALSE;
3916 DEBUGFUNC("e1000_detect_gig_phy");
3918 /* The 82571 firmware may still be configuring the PHY. In this
3919 * case, we cannot access the PHY until the configuration is done. So
3920 * we explicitly set the PHY values. */
3921 if (hw->mac_type == e1000_82571 ||
3922 hw->mac_type == e1000_82572) {
3923 hw->phy_id = IGP01E1000_I_PHY_ID;
3924 hw->phy_type = e1000_phy_igp_2;
3925 return E1000_SUCCESS;
3928 /* ESB-2 PHY reads require e1000_phy_gg82563 to be set because of a work-
3929 * around that forces PHY page 0 to be set or the reads fail. The rest of
3930 * the code in this routine uses e1000_read_phy_reg to read the PHY ID.
3931 * So for ESB-2 we need to have this set so our reads won't fail. If the
3932 * attached PHY is not a e1000_phy_gg82563, the routines below will figure
3933 * this out as well. */
3934 if (hw->mac_type == e1000_80003es2lan)
3935 hw->phy_type = e1000_phy_gg82563;
3937 /* Read the PHY ID Registers to identify which PHY is onboard. */
3938 ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
3942 hw->phy_id = (uint32_t) (phy_id_high << 16);
3944 ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
3948 hw->phy_id |= (uint32_t) (phy_id_low & PHY_REVISION_MASK);
3949 hw->phy_revision = (uint32_t) phy_id_low & ~PHY_REVISION_MASK;
3951 switch(hw->mac_type) {
3953 if(hw->phy_id == M88E1000_E_PHY_ID) match = TRUE;
3956 if(hw->phy_id == M88E1000_I_PHY_ID) match = TRUE;
3960 case e1000_82545_rev_3:
3962 case e1000_82546_rev_3:
3963 if(hw->phy_id == M88E1011_I_PHY_ID) match = TRUE;
3966 case e1000_82541_rev_2:
3968 case e1000_82547_rev_2:
3969 if(hw->phy_id == IGP01E1000_I_PHY_ID) match = TRUE;
3972 if(hw->phy_id == M88E1111_I_PHY_ID) match = TRUE;
3974 case e1000_80003es2lan:
3975 if (hw->phy_id == GG82563_E_PHY_ID) match = TRUE;
3978 if (hw->phy_id == IGP03E1000_E_PHY_ID) match = TRUE;
3979 if (hw->phy_id == IFE_E_PHY_ID) match = TRUE;
3980 if (hw->phy_id == IFE_PLUS_E_PHY_ID) match = TRUE;
3981 if (hw->phy_id == IFE_C_E_PHY_ID) match = TRUE;
3984 DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type);
3985 return -E1000_ERR_CONFIG;
3987 phy_init_status = e1000_set_phy_type(hw);
3989 if ((match) && (phy_init_status == E1000_SUCCESS)) {
3990 DEBUGOUT1("PHY ID 0x%X detected\n", hw->phy_id);
3991 return E1000_SUCCESS;
3993 DEBUGOUT1("Invalid PHY ID 0x%X\n", hw->phy_id);
3994 return -E1000_ERR_PHY;
3997 /******************************************************************************
3998 * Resets the PHY's DSP
4000 * hw - Struct containing variables accessed by shared code
4001 ******************************************************************************/
4003 e1000_phy_reset_dsp(struct e1000_hw *hw)
4006 DEBUGFUNC("e1000_phy_reset_dsp");
4009 if (hw->phy_type != e1000_phy_gg82563) {
4010 ret_val = e1000_write_phy_reg(hw, 29, 0x001d);
4013 ret_val = e1000_write_phy_reg(hw, 30, 0x00c1);
4015 ret_val = e1000_write_phy_reg(hw, 30, 0x0000);
4017 ret_val = E1000_SUCCESS;
4023 /******************************************************************************
4024 * Get PHY information from various PHY registers for igp PHY only.
4026 * hw - Struct containing variables accessed by shared code
4027 * phy_info - PHY information structure
4028 ******************************************************************************/
4030 e1000_phy_igp_get_info(struct e1000_hw *hw,
4031 struct e1000_phy_info *phy_info)
4034 uint16_t phy_data, polarity, min_length, max_length, average;
4036 DEBUGFUNC("e1000_phy_igp_get_info");
4038 /* The downshift status is checked only once, after link is established,
4039 * and it stored in the hw->speed_downgraded parameter. */
4040 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
4042 /* IGP01E1000 does not need to support it. */
4043 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
4045 /* IGP01E1000 always correct polarity reversal */
4046 phy_info->polarity_correction = e1000_polarity_reversal_enabled;
4048 /* Check polarity status */
4049 ret_val = e1000_check_polarity(hw, &polarity);
4053 phy_info->cable_polarity = polarity;
4055 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, &phy_data);
4059 phy_info->mdix_mode = (phy_data & IGP01E1000_PSSR_MDIX) >>
4060 IGP01E1000_PSSR_MDIX_SHIFT;
4062 if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
4063 IGP01E1000_PSSR_SPEED_1000MBPS) {
4064 /* Local/Remote Receiver Information are only valid at 1000 Mbps */
4065 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
4069 phy_info->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS) >>
4070 SR_1000T_LOCAL_RX_STATUS_SHIFT;
4071 phy_info->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS) >>
4072 SR_1000T_REMOTE_RX_STATUS_SHIFT;
4074 /* Get cable length */
4075 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
4079 /* Translate to old method */
4080 average = (max_length + min_length) / 2;
4082 if(average <= e1000_igp_cable_length_50)
4083 phy_info->cable_length = e1000_cable_length_50;
4084 else if(average <= e1000_igp_cable_length_80)
4085 phy_info->cable_length = e1000_cable_length_50_80;
4086 else if(average <= e1000_igp_cable_length_110)
4087 phy_info->cable_length = e1000_cable_length_80_110;
4088 else if(average <= e1000_igp_cable_length_140)
4089 phy_info->cable_length = e1000_cable_length_110_140;
4091 phy_info->cable_length = e1000_cable_length_140;
4094 return E1000_SUCCESS;
4097 /******************************************************************************
4098 * Get PHY information from various PHY registers for ife PHY only.
4100 * hw - Struct containing variables accessed by shared code
4101 * phy_info - PHY information structure
4102 ******************************************************************************/
4104 e1000_phy_ife_get_info(struct e1000_hw *hw,
4105 struct e1000_phy_info *phy_info)
4108 uint16_t phy_data, polarity;
4110 DEBUGFUNC("e1000_phy_ife_get_info");
4112 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
4113 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
4115 ret_val = e1000_read_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL, &phy_data);
4118 phy_info->polarity_correction =
4119 (phy_data & IFE_PSC_AUTO_POLARITY_DISABLE) >>
4120 IFE_PSC_AUTO_POLARITY_DISABLE_SHIFT;
4122 if (phy_info->polarity_correction == e1000_polarity_reversal_enabled) {
4123 ret_val = e1000_check_polarity(hw, &polarity);
4127 /* Polarity is forced. */
4128 polarity = (phy_data & IFE_PSC_FORCE_POLARITY) >>
4129 IFE_PSC_FORCE_POLARITY_SHIFT;
4131 phy_info->cable_polarity = polarity;
4133 ret_val = e1000_read_phy_reg(hw, IFE_PHY_MDIX_CONTROL, &phy_data);
4137 phy_info->mdix_mode =
4138 (phy_data & (IFE_PMC_AUTO_MDIX | IFE_PMC_FORCE_MDIX)) >>
4139 IFE_PMC_MDIX_MODE_SHIFT;
4141 return E1000_SUCCESS;
4144 /******************************************************************************
4145 * Get PHY information from various PHY registers fot m88 PHY only.
4147 * hw - Struct containing variables accessed by shared code
4148 * phy_info - PHY information structure
4149 ******************************************************************************/
4151 e1000_phy_m88_get_info(struct e1000_hw *hw,
4152 struct e1000_phy_info *phy_info)
4155 uint16_t phy_data, polarity;
4157 DEBUGFUNC("e1000_phy_m88_get_info");
4159 /* The downshift status is checked only once, after link is established,
4160 * and it stored in the hw->speed_downgraded parameter. */
4161 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
4163 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
4167 phy_info->extended_10bt_distance =
4168 (phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >>
4169 M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT;
4170 phy_info->polarity_correction =
4171 (phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >>
4172 M88E1000_PSCR_POLARITY_REVERSAL_SHIFT;
4174 /* Check polarity status */
4175 ret_val = e1000_check_polarity(hw, &polarity);
4178 phy_info->cable_polarity = polarity;
4180 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
4184 phy_info->mdix_mode = (phy_data & M88E1000_PSSR_MDIX) >>
4185 M88E1000_PSSR_MDIX_SHIFT;
4187 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
4188 /* Cable Length Estimation and Local/Remote Receiver Information
4189 * are only valid at 1000 Mbps.
4191 if (hw->phy_type != e1000_phy_gg82563) {
4192 phy_info->cable_length = ((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
4193 M88E1000_PSSR_CABLE_LENGTH_SHIFT);
4195 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_DSP_DISTANCE,
4200 phy_info->cable_length = phy_data & GG82563_DSPD_CABLE_LENGTH;
4203 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
4207 phy_info->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS) >>
4208 SR_1000T_LOCAL_RX_STATUS_SHIFT;
4210 phy_info->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS) >>
4211 SR_1000T_REMOTE_RX_STATUS_SHIFT;
4214 return E1000_SUCCESS;
4217 /******************************************************************************
4218 * Get PHY information from various PHY registers
4220 * hw - Struct containing variables accessed by shared code
4221 * phy_info - PHY information structure
4222 ******************************************************************************/
4224 e1000_phy_get_info(struct e1000_hw *hw,
4225 struct e1000_phy_info *phy_info)
4230 DEBUGFUNC("e1000_phy_get_info");
4232 phy_info->cable_length = e1000_cable_length_undefined;
4233 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined;
4234 phy_info->cable_polarity = e1000_rev_polarity_undefined;
4235 phy_info->downshift = e1000_downshift_undefined;
4236 phy_info->polarity_correction = e1000_polarity_reversal_undefined;
4237 phy_info->mdix_mode = e1000_auto_x_mode_undefined;
4238 phy_info->local_rx = e1000_1000t_rx_status_undefined;
4239 phy_info->remote_rx = e1000_1000t_rx_status_undefined;
4241 if(hw->media_type != e1000_media_type_copper) {
4242 DEBUGOUT("PHY info is only valid for copper media\n");
4243 return -E1000_ERR_CONFIG;
4246 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
4250 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
4254 if((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) {
4255 DEBUGOUT("PHY info is only valid if link is up\n");
4256 return -E1000_ERR_CONFIG;
4259 if (hw->phy_type == e1000_phy_igp ||
4260 hw->phy_type == e1000_phy_igp_3 ||
4261 hw->phy_type == e1000_phy_igp_2)
4262 return e1000_phy_igp_get_info(hw, phy_info);
4263 else if (hw->phy_type == e1000_phy_ife)
4264 return e1000_phy_ife_get_info(hw, phy_info);
4266 return e1000_phy_m88_get_info(hw, phy_info);
4270 e1000_validate_mdi_setting(struct e1000_hw *hw)
4272 DEBUGFUNC("e1000_validate_mdi_settings");
4274 if(!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) {
4275 DEBUGOUT("Invalid MDI setting detected\n");
4277 return -E1000_ERR_CONFIG;
4279 return E1000_SUCCESS;
4283 /******************************************************************************
4284 * Sets up eeprom variables in the hw struct. Must be called after mac_type
4285 * is configured. Additionally, if this is ICH8, the flash controller GbE
4286 * registers must be mapped, or this will crash.
4288 * hw - Struct containing variables accessed by shared code
4289 *****************************************************************************/
4291 e1000_init_eeprom_params(struct e1000_hw *hw)
4293 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4294 uint32_t eecd = E1000_READ_REG(hw, EECD);
4295 int32_t ret_val = E1000_SUCCESS;
4296 uint16_t eeprom_size;
4298 DEBUGFUNC("e1000_init_eeprom_params");
4300 switch (hw->mac_type) {
4301 case e1000_82542_rev2_0:
4302 case e1000_82542_rev2_1:
4305 eeprom->type = e1000_eeprom_microwire;
4306 eeprom->word_size = 64;
4307 eeprom->opcode_bits = 3;
4308 eeprom->address_bits = 6;
4309 eeprom->delay_usec = 50;
4310 eeprom->use_eerd = FALSE;
4311 eeprom->use_eewr = FALSE;
4315 case e1000_82545_rev_3:
4317 case e1000_82546_rev_3:
4318 eeprom->type = e1000_eeprom_microwire;
4319 eeprom->opcode_bits = 3;
4320 eeprom->delay_usec = 50;
4321 if(eecd & E1000_EECD_SIZE) {
4322 eeprom->word_size = 256;
4323 eeprom->address_bits = 8;
4325 eeprom->word_size = 64;
4326 eeprom->address_bits = 6;
4328 eeprom->use_eerd = FALSE;
4329 eeprom->use_eewr = FALSE;
4332 case e1000_82541_rev_2:
4334 case e1000_82547_rev_2:
4335 if (eecd & E1000_EECD_TYPE) {
4336 eeprom->type = e1000_eeprom_spi;
4337 eeprom->opcode_bits = 8;
4338 eeprom->delay_usec = 1;
4339 if (eecd & E1000_EECD_ADDR_BITS) {
4340 eeprom->page_size = 32;
4341 eeprom->address_bits = 16;
4343 eeprom->page_size = 8;
4344 eeprom->address_bits = 8;
4347 eeprom->type = e1000_eeprom_microwire;
4348 eeprom->opcode_bits = 3;
4349 eeprom->delay_usec = 50;
4350 if (eecd & E1000_EECD_ADDR_BITS) {
4351 eeprom->word_size = 256;
4352 eeprom->address_bits = 8;
4354 eeprom->word_size = 64;
4355 eeprom->address_bits = 6;
4358 eeprom->use_eerd = FALSE;
4359 eeprom->use_eewr = FALSE;
4363 eeprom->type = e1000_eeprom_spi;
4364 eeprom->opcode_bits = 8;
4365 eeprom->delay_usec = 1;
4366 if (eecd & E1000_EECD_ADDR_BITS) {
4367 eeprom->page_size = 32;
4368 eeprom->address_bits = 16;
4370 eeprom->page_size = 8;
4371 eeprom->address_bits = 8;
4373 eeprom->use_eerd = FALSE;
4374 eeprom->use_eewr = FALSE;
4377 eeprom->type = e1000_eeprom_spi;
4378 eeprom->opcode_bits = 8;
4379 eeprom->delay_usec = 1;
4380 if (eecd & E1000_EECD_ADDR_BITS) {
4381 eeprom->page_size = 32;
4382 eeprom->address_bits = 16;
4384 eeprom->page_size = 8;
4385 eeprom->address_bits = 8;
4387 eeprom->use_eerd = TRUE;
4388 eeprom->use_eewr = TRUE;
4389 if(e1000_is_onboard_nvm_eeprom(hw) == FALSE) {
4390 eeprom->type = e1000_eeprom_flash;
4391 eeprom->word_size = 2048;
4393 /* Ensure that the Autonomous FLASH update bit is cleared due to
4394 * Flash update issue on parts which use a FLASH for NVM. */
4395 eecd &= ~E1000_EECD_AUPDEN;
4396 E1000_WRITE_REG(hw, EECD, eecd);
4399 case e1000_80003es2lan:
4400 eeprom->type = e1000_eeprom_spi;
4401 eeprom->opcode_bits = 8;
4402 eeprom->delay_usec = 1;
4403 if (eecd & E1000_EECD_ADDR_BITS) {
4404 eeprom->page_size = 32;
4405 eeprom->address_bits = 16;
4407 eeprom->page_size = 8;
4408 eeprom->address_bits = 8;
4410 eeprom->use_eerd = TRUE;
4411 eeprom->use_eewr = FALSE;
4416 uint32_t flash_size = E1000_READ_ICH8_REG(hw, ICH8_FLASH_GFPREG);
4418 eeprom->type = e1000_eeprom_ich8;
4419 eeprom->use_eerd = FALSE;
4420 eeprom->use_eewr = FALSE;
4421 eeprom->word_size = E1000_SHADOW_RAM_WORDS;
4423 /* Zero the shadow RAM structure. But don't load it from NVM
4424 * so as to save time for driver init */
4425 if (hw->eeprom_shadow_ram != NULL) {
4426 for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
4427 hw->eeprom_shadow_ram[i].modified = FALSE;
4428 hw->eeprom_shadow_ram[i].eeprom_word = 0xFFFF;
4432 hw->flash_base_addr = (flash_size & ICH8_GFPREG_BASE_MASK) *
4433 ICH8_FLASH_SECTOR_SIZE;
4435 hw->flash_bank_size = ((flash_size >> 16) & ICH8_GFPREG_BASE_MASK) + 1;
4436 hw->flash_bank_size -= (flash_size & ICH8_GFPREG_BASE_MASK);
4437 hw->flash_bank_size *= ICH8_FLASH_SECTOR_SIZE;
4438 hw->flash_bank_size /= 2 * sizeof(uint16_t);
4446 if (eeprom->type == e1000_eeprom_spi) {
4447 /* eeprom_size will be an enum [0..8] that maps to eeprom sizes 128B to
4448 * 32KB (incremented by powers of 2).
4450 if(hw->mac_type <= e1000_82547_rev_2) {
4451 /* Set to default value for initial eeprom read. */
4452 eeprom->word_size = 64;
4453 ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size);
4456 eeprom_size = (eeprom_size & EEPROM_SIZE_MASK) >> EEPROM_SIZE_SHIFT;
4457 /* 256B eeprom size was not supported in earlier hardware, so we
4458 * bump eeprom_size up one to ensure that "1" (which maps to 256B)
4459 * is never the result used in the shifting logic below. */
4463 eeprom_size = (uint16_t)((eecd & E1000_EECD_SIZE_EX_MASK) >>
4464 E1000_EECD_SIZE_EX_SHIFT);
4467 eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT);
4472 /******************************************************************************
4473 * Raises the EEPROM's clock input.
4475 * hw - Struct containing variables accessed by shared code
4476 * eecd - EECD's current value
4477 *****************************************************************************/
4479 e1000_raise_ee_clk(struct e1000_hw *hw,
4482 /* Raise the clock input to the EEPROM (by setting the SK bit), and then
4483 * wait <delay> microseconds.
4485 *eecd = *eecd | E1000_EECD_SK;
4486 E1000_WRITE_REG(hw, EECD, *eecd);
4487 E1000_WRITE_FLUSH(hw);
4488 udelay(hw->eeprom.delay_usec);
4491 /******************************************************************************
4492 * Lowers the EEPROM's clock input.
4494 * hw - Struct containing variables accessed by shared code
4495 * eecd - EECD's current value
4496 *****************************************************************************/
4498 e1000_lower_ee_clk(struct e1000_hw *hw,
4501 /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
4502 * wait 50 microseconds.
4504 *eecd = *eecd & ~E1000_EECD_SK;
4505 E1000_WRITE_REG(hw, EECD, *eecd);
4506 E1000_WRITE_FLUSH(hw);
4507 udelay(hw->eeprom.delay_usec);
4510 /******************************************************************************
4511 * Shift data bits out to the EEPROM.
4513 * hw - Struct containing variables accessed by shared code
4514 * data - data to send to the EEPROM
4515 * count - number of bits to shift out
4516 *****************************************************************************/
4518 e1000_shift_out_ee_bits(struct e1000_hw *hw,
4522 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4526 /* We need to shift "count" bits out to the EEPROM. So, value in the
4527 * "data" parameter will be shifted out to the EEPROM one bit at a time.
4528 * In order to do this, "data" must be broken down into bits.
4530 mask = 0x01 << (count - 1);
4531 eecd = E1000_READ_REG(hw, EECD);
4532 if (eeprom->type == e1000_eeprom_microwire) {
4533 eecd &= ~E1000_EECD_DO;
4534 } else if (eeprom->type == e1000_eeprom_spi) {
4535 eecd |= E1000_EECD_DO;
4538 /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
4539 * and then raising and then lowering the clock (the SK bit controls
4540 * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
4541 * by setting "DI" to "0" and then raising and then lowering the clock.
4543 eecd &= ~E1000_EECD_DI;
4546 eecd |= E1000_EECD_DI;
4548 E1000_WRITE_REG(hw, EECD, eecd);
4549 E1000_WRITE_FLUSH(hw);
4551 udelay(eeprom->delay_usec);
4553 e1000_raise_ee_clk(hw, &eecd);
4554 e1000_lower_ee_clk(hw, &eecd);
4560 /* We leave the "DI" bit set to "0" when we leave this routine. */
4561 eecd &= ~E1000_EECD_DI;
4562 E1000_WRITE_REG(hw, EECD, eecd);
4565 /******************************************************************************
4566 * Shift data bits in from the EEPROM
4568 * hw - Struct containing variables accessed by shared code
4569 *****************************************************************************/
4571 e1000_shift_in_ee_bits(struct e1000_hw *hw,
4578 /* In order to read a register from the EEPROM, we need to shift 'count'
4579 * bits in from the EEPROM. Bits are "shifted in" by raising the clock
4580 * input to the EEPROM (setting the SK bit), and then reading the value of
4581 * the "DO" bit. During this "shifting in" process the "DI" bit should
4585 eecd = E1000_READ_REG(hw, EECD);
4587 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
4590 for(i = 0; i < count; i++) {
4592 e1000_raise_ee_clk(hw, &eecd);
4594 eecd = E1000_READ_REG(hw, EECD);
4596 eecd &= ~(E1000_EECD_DI);
4597 if(eecd & E1000_EECD_DO)
4600 e1000_lower_ee_clk(hw, &eecd);
4606 /******************************************************************************
4607 * Prepares EEPROM for access
4609 * hw - Struct containing variables accessed by shared code
4611 * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
4612 * function should be called before issuing a command to the EEPROM.
4613 *****************************************************************************/
4615 e1000_acquire_eeprom(struct e1000_hw *hw)
4617 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4620 DEBUGFUNC("e1000_acquire_eeprom");
4622 if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
4623 return -E1000_ERR_SWFW_SYNC;
4624 eecd = E1000_READ_REG(hw, EECD);
4626 if (hw->mac_type != e1000_82573) {
4627 /* Request EEPROM Access */
4628 if(hw->mac_type > e1000_82544) {
4629 eecd |= E1000_EECD_REQ;
4630 E1000_WRITE_REG(hw, EECD, eecd);
4631 eecd = E1000_READ_REG(hw, EECD);
4632 while((!(eecd & E1000_EECD_GNT)) &&
4633 (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
4636 eecd = E1000_READ_REG(hw, EECD);
4638 if(!(eecd & E1000_EECD_GNT)) {
4639 eecd &= ~E1000_EECD_REQ;
4640 E1000_WRITE_REG(hw, EECD, eecd);
4641 DEBUGOUT("Could not acquire EEPROM grant\n");
4642 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
4643 return -E1000_ERR_EEPROM;
4648 /* Setup EEPROM for Read/Write */
4650 if (eeprom->type == e1000_eeprom_microwire) {
4651 /* Clear SK and DI */
4652 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
4653 E1000_WRITE_REG(hw, EECD, eecd);
4656 eecd |= E1000_EECD_CS;
4657 E1000_WRITE_REG(hw, EECD, eecd);
4658 } else if (eeprom->type == e1000_eeprom_spi) {
4659 /* Clear SK and CS */
4660 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
4661 E1000_WRITE_REG(hw, EECD, eecd);
4665 return E1000_SUCCESS;
4668 /******************************************************************************
4669 * Returns EEPROM to a "standby" state
4671 * hw - Struct containing variables accessed by shared code
4672 *****************************************************************************/
4674 e1000_standby_eeprom(struct e1000_hw *hw)
4676 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4679 eecd = E1000_READ_REG(hw, EECD);
4681 if(eeprom->type == e1000_eeprom_microwire) {
4682 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
4683 E1000_WRITE_REG(hw, EECD, eecd);
4684 E1000_WRITE_FLUSH(hw);
4685 udelay(eeprom->delay_usec);
4688 eecd |= E1000_EECD_SK;
4689 E1000_WRITE_REG(hw, EECD, eecd);
4690 E1000_WRITE_FLUSH(hw);
4691 udelay(eeprom->delay_usec);
4694 eecd |= E1000_EECD_CS;
4695 E1000_WRITE_REG(hw, EECD, eecd);
4696 E1000_WRITE_FLUSH(hw);
4697 udelay(eeprom->delay_usec);
4700 eecd &= ~E1000_EECD_SK;
4701 E1000_WRITE_REG(hw, EECD, eecd);
4702 E1000_WRITE_FLUSH(hw);
4703 udelay(eeprom->delay_usec);
4704 } else if(eeprom->type == e1000_eeprom_spi) {
4705 /* Toggle CS to flush commands */
4706 eecd |= E1000_EECD_CS;
4707 E1000_WRITE_REG(hw, EECD, eecd);
4708 E1000_WRITE_FLUSH(hw);
4709 udelay(eeprom->delay_usec);
4710 eecd &= ~E1000_EECD_CS;
4711 E1000_WRITE_REG(hw, EECD, eecd);
4712 E1000_WRITE_FLUSH(hw);
4713 udelay(eeprom->delay_usec);
4717 /******************************************************************************
4718 * Terminates a command by inverting the EEPROM's chip select pin
4720 * hw - Struct containing variables accessed by shared code
4721 *****************************************************************************/
4723 e1000_release_eeprom(struct e1000_hw *hw)
4727 DEBUGFUNC("e1000_release_eeprom");
4729 eecd = E1000_READ_REG(hw, EECD);
4731 if (hw->eeprom.type == e1000_eeprom_spi) {
4732 eecd |= E1000_EECD_CS; /* Pull CS high */
4733 eecd &= ~E1000_EECD_SK; /* Lower SCK */
4735 E1000_WRITE_REG(hw, EECD, eecd);
4737 udelay(hw->eeprom.delay_usec);
4738 } else if(hw->eeprom.type == e1000_eeprom_microwire) {
4739 /* cleanup eeprom */
4741 /* CS on Microwire is active-high */
4742 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
4744 E1000_WRITE_REG(hw, EECD, eecd);
4746 /* Rising edge of clock */
4747 eecd |= E1000_EECD_SK;
4748 E1000_WRITE_REG(hw, EECD, eecd);
4749 E1000_WRITE_FLUSH(hw);
4750 udelay(hw->eeprom.delay_usec);
4752 /* Falling edge of clock */
4753 eecd &= ~E1000_EECD_SK;
4754 E1000_WRITE_REG(hw, EECD, eecd);
4755 E1000_WRITE_FLUSH(hw);
4756 udelay(hw->eeprom.delay_usec);
4759 /* Stop requesting EEPROM access */
4760 if(hw->mac_type > e1000_82544) {
4761 eecd &= ~E1000_EECD_REQ;
4762 E1000_WRITE_REG(hw, EECD, eecd);
4765 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
4768 /******************************************************************************
4769 * Reads a 16 bit word from the EEPROM.
4771 * hw - Struct containing variables accessed by shared code
4772 *****************************************************************************/
4774 e1000_spi_eeprom_ready(struct e1000_hw *hw)
4776 uint16_t retry_count = 0;
4777 uint8_t spi_stat_reg;
4779 DEBUGFUNC("e1000_spi_eeprom_ready");
4781 /* Read "Status Register" repeatedly until the LSB is cleared. The
4782 * EEPROM will signal that the command has been completed by clearing
4783 * bit 0 of the internal status register. If it's not cleared within
4784 * 5 milliseconds, then error out.
4788 e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
4789 hw->eeprom.opcode_bits);
4790 spi_stat_reg = (uint8_t)e1000_shift_in_ee_bits(hw, 8);
4791 if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
4797 e1000_standby_eeprom(hw);
4798 } while(retry_count < EEPROM_MAX_RETRY_SPI);
4800 /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
4801 * only 0-5mSec on 5V devices)
4803 if(retry_count >= EEPROM_MAX_RETRY_SPI) {
4804 DEBUGOUT("SPI EEPROM Status error\n");
4805 return -E1000_ERR_EEPROM;
4808 return E1000_SUCCESS;
4811 /******************************************************************************
4812 * Reads a 16 bit word from the EEPROM.
4814 * hw - Struct containing variables accessed by shared code
4815 * offset - offset of word in the EEPROM to read
4816 * data - word read from the EEPROM
4817 * words - number of words to read
4818 *****************************************************************************/
4820 e1000_read_eeprom(struct e1000_hw *hw,
4825 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4829 DEBUGFUNC("e1000_read_eeprom");
4831 /* A check for invalid values: offset too large, too many words, and not
4834 if((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
4836 DEBUGOUT("\"words\" parameter out of bounds\n");
4837 return -E1000_ERR_EEPROM;
4840 /* FLASH reads without acquiring the semaphore are safe */
4841 if (e1000_is_onboard_nvm_eeprom(hw) == TRUE &&
4842 hw->eeprom.use_eerd == FALSE) {
4843 switch (hw->mac_type) {
4844 case e1000_80003es2lan:
4847 /* Prepare the EEPROM for reading */
4848 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
4849 return -E1000_ERR_EEPROM;
4854 if (eeprom->use_eerd == TRUE) {
4855 ret_val = e1000_read_eeprom_eerd(hw, offset, words, data);
4856 if ((e1000_is_onboard_nvm_eeprom(hw) == TRUE) ||
4857 (hw->mac_type != e1000_82573))
4858 e1000_release_eeprom(hw);
4862 if (eeprom->type == e1000_eeprom_ich8)
4863 return e1000_read_eeprom_ich8(hw, offset, words, data);
4865 if (eeprom->type == e1000_eeprom_spi) {
4867 uint8_t read_opcode = EEPROM_READ_OPCODE_SPI;
4869 if(e1000_spi_eeprom_ready(hw)) {
4870 e1000_release_eeprom(hw);
4871 return -E1000_ERR_EEPROM;
4874 e1000_standby_eeprom(hw);
4876 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
4877 if((eeprom->address_bits == 8) && (offset >= 128))
4878 read_opcode |= EEPROM_A8_OPCODE_SPI;
4880 /* Send the READ command (opcode + addr) */
4881 e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
4882 e1000_shift_out_ee_bits(hw, (uint16_t)(offset*2), eeprom->address_bits);
4884 /* Read the data. The address of the eeprom internally increments with
4885 * each byte (spi) being read, saving on the overhead of eeprom setup
4886 * and tear-down. The address counter will roll over if reading beyond
4887 * the size of the eeprom, thus allowing the entire memory to be read
4888 * starting from any offset. */
4889 for (i = 0; i < words; i++) {
4890 word_in = e1000_shift_in_ee_bits(hw, 16);
4891 data[i] = (word_in >> 8) | (word_in << 8);
4893 } else if(eeprom->type == e1000_eeprom_microwire) {
4894 for (i = 0; i < words; i++) {
4895 /* Send the READ command (opcode + addr) */
4896 e1000_shift_out_ee_bits(hw, EEPROM_READ_OPCODE_MICROWIRE,
4897 eeprom->opcode_bits);
4898 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + i),
4899 eeprom->address_bits);
4901 /* Read the data. For microwire, each word requires the overhead
4902 * of eeprom setup and tear-down. */
4903 data[i] = e1000_shift_in_ee_bits(hw, 16);
4904 e1000_standby_eeprom(hw);
4908 /* End this read operation */
4909 e1000_release_eeprom(hw);
4911 return E1000_SUCCESS;
4914 /******************************************************************************
4915 * Reads a 16 bit word from the EEPROM using the EERD register.
4917 * hw - Struct containing variables accessed by shared code
4918 * offset - offset of word in the EEPROM to read
4919 * data - word read from the EEPROM
4920 * words - number of words to read
4921 *****************************************************************************/
4923 e1000_read_eeprom_eerd(struct e1000_hw *hw,
4928 uint32_t i, eerd = 0;
4931 for (i = 0; i < words; i++) {
4932 eerd = ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) +
4933 E1000_EEPROM_RW_REG_START;
4935 E1000_WRITE_REG(hw, EERD, eerd);
4936 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_READ);
4941 data[i] = (E1000_READ_REG(hw, EERD) >> E1000_EEPROM_RW_REG_DATA);
4948 /******************************************************************************
4949 * Writes a 16 bit word from the EEPROM using the EEWR register.
4951 * hw - Struct containing variables accessed by shared code
4952 * offset - offset of word in the EEPROM to read
4953 * data - word read from the EEPROM
4954 * words - number of words to read
4955 *****************************************************************************/
4957 e1000_write_eeprom_eewr(struct e1000_hw *hw,
4962 uint32_t register_value = 0;
4966 if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
4967 return -E1000_ERR_SWFW_SYNC;
4969 for (i = 0; i < words; i++) {
4970 register_value = (data[i] << E1000_EEPROM_RW_REG_DATA) |
4971 ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) |
4972 E1000_EEPROM_RW_REG_START;
4974 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
4979 E1000_WRITE_REG(hw, EEWR, register_value);
4981 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
4988 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
4992 /******************************************************************************
4993 * Polls the status bit (bit 1) of the EERD to determine when the read is done.
4995 * hw - Struct containing variables accessed by shared code
4996 *****************************************************************************/
4998 e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd)
5000 uint32_t attempts = 100000;
5001 uint32_t i, reg = 0;
5002 int32_t done = E1000_ERR_EEPROM;
5004 for(i = 0; i < attempts; i++) {
5005 if(eerd == E1000_EEPROM_POLL_READ)
5006 reg = E1000_READ_REG(hw, EERD);
5008 reg = E1000_READ_REG(hw, EEWR);
5010 if(reg & E1000_EEPROM_RW_REG_DONE) {
5011 done = E1000_SUCCESS;
5020 /***************************************************************************
5021 * Description: Determines if the onboard NVM is FLASH or EEPROM.
5023 * hw - Struct containing variables accessed by shared code
5024 ****************************************************************************/
5026 e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw)
5030 DEBUGFUNC("e1000_is_onboard_nvm_eeprom");
5032 if (hw->mac_type == e1000_ich8lan)
5035 if (hw->mac_type == e1000_82573) {
5036 eecd = E1000_READ_REG(hw, EECD);
5038 /* Isolate bits 15 & 16 */
5039 eecd = ((eecd >> 15) & 0x03);
5041 /* If both bits are set, device is Flash type */
5049 /******************************************************************************
5050 * Verifies that the EEPROM has a valid checksum
5052 * hw - Struct containing variables accessed by shared code
5054 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
5055 * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
5057 *****************************************************************************/
5059 e1000_validate_eeprom_checksum(struct e1000_hw *hw)
5061 uint16_t checksum = 0;
5062 uint16_t i, eeprom_data;
5064 DEBUGFUNC("e1000_validate_eeprom_checksum");
5066 if ((hw->mac_type == e1000_82573) &&
5067 (e1000_is_onboard_nvm_eeprom(hw) == FALSE)) {
5068 /* Check bit 4 of word 10h. If it is 0, firmware is done updating
5069 * 10h-12h. Checksum may need to be fixed. */
5070 e1000_read_eeprom(hw, 0x10, 1, &eeprom_data);
5071 if ((eeprom_data & 0x10) == 0) {
5072 /* Read 0x23 and check bit 15. This bit is a 1 when the checksum
5073 * has already been fixed. If the checksum is still wrong and this
5074 * bit is a 1, we need to return bad checksum. Otherwise, we need
5075 * to set this bit to a 1 and update the checksum. */
5076 e1000_read_eeprom(hw, 0x23, 1, &eeprom_data);
5077 if ((eeprom_data & 0x8000) == 0) {
5078 eeprom_data |= 0x8000;
5079 e1000_write_eeprom(hw, 0x23, 1, &eeprom_data);
5080 e1000_update_eeprom_checksum(hw);
5085 if (hw->mac_type == e1000_ich8lan) {
5086 /* Drivers must allocate the shadow ram structure for the
5087 * EEPROM checksum to be updated. Otherwise, this bit as well
5088 * as the checksum must both be set correctly for this
5089 * validation to pass.
5091 e1000_read_eeprom(hw, 0x19, 1, &eeprom_data);
5092 if ((eeprom_data & 0x40) == 0) {
5093 eeprom_data |= 0x40;
5094 e1000_write_eeprom(hw, 0x19, 1, &eeprom_data);
5095 e1000_update_eeprom_checksum(hw);
5099 for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
5100 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
5101 DEBUGOUT("EEPROM Read Error\n");
5102 return -E1000_ERR_EEPROM;
5104 checksum += eeprom_data;
5107 if(checksum == (uint16_t) EEPROM_SUM)
5108 return E1000_SUCCESS;
5110 DEBUGOUT("EEPROM Checksum Invalid\n");
5111 return -E1000_ERR_EEPROM;
5115 /******************************************************************************
5116 * Calculates the EEPROM checksum and writes it to the EEPROM
5118 * hw - Struct containing variables accessed by shared code
5120 * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA.
5121 * Writes the difference to word offset 63 of the EEPROM.
5122 *****************************************************************************/
5124 e1000_update_eeprom_checksum(struct e1000_hw *hw)
5127 uint16_t checksum = 0;
5128 uint16_t i, eeprom_data;
5130 DEBUGFUNC("e1000_update_eeprom_checksum");
5132 for(i = 0; i < EEPROM_CHECKSUM_REG; i++) {
5133 if(e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
5134 DEBUGOUT("EEPROM Read Error\n");
5135 return -E1000_ERR_EEPROM;
5137 checksum += eeprom_data;
5139 checksum = (uint16_t) EEPROM_SUM - checksum;
5140 if(e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) {
5141 DEBUGOUT("EEPROM Write Error\n");
5142 return -E1000_ERR_EEPROM;
5143 } else if (hw->eeprom.type == e1000_eeprom_flash) {
5144 e1000_commit_shadow_ram(hw);
5145 } else if (hw->eeprom.type == e1000_eeprom_ich8) {
5146 e1000_commit_shadow_ram(hw);
5147 /* Reload the EEPROM, or else modifications will not appear
5148 * until after next adapter reset. */
5149 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
5150 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
5151 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
5154 return E1000_SUCCESS;
5157 /******************************************************************************
5158 * Parent function for writing words to the different EEPROM types.
5160 * hw - Struct containing variables accessed by shared code
5161 * offset - offset within the EEPROM to be written to
5162 * words - number of words to write
5163 * data - 16 bit word to be written to the EEPROM
5165 * If e1000_update_eeprom_checksum is not called after this function, the
5166 * EEPROM will most likely contain an invalid checksum.
5167 *****************************************************************************/
5169 e1000_write_eeprom(struct e1000_hw *hw,
5174 struct e1000_eeprom_info *eeprom = &hw->eeprom;
5177 DEBUGFUNC("e1000_write_eeprom");
5179 /* A check for invalid values: offset too large, too many words, and not
5182 if((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
5184 DEBUGOUT("\"words\" parameter out of bounds\n");
5185 return -E1000_ERR_EEPROM;
5188 /* 82573 writes only through eewr */
5189 if(eeprom->use_eewr == TRUE)
5190 return e1000_write_eeprom_eewr(hw, offset, words, data);
5192 if (eeprom->type == e1000_eeprom_ich8)
5193 return e1000_write_eeprom_ich8(hw, offset, words, data);
5195 /* Prepare the EEPROM for writing */
5196 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
5197 return -E1000_ERR_EEPROM;
5199 if(eeprom->type == e1000_eeprom_microwire) {
5200 status = e1000_write_eeprom_microwire(hw, offset, words, data);
5202 status = e1000_write_eeprom_spi(hw, offset, words, data);
5206 /* Done with writing */
5207 e1000_release_eeprom(hw);
5212 /******************************************************************************
5213 * Writes a 16 bit word to a given offset in an SPI EEPROM.
5215 * hw - Struct containing variables accessed by shared code
5216 * offset - offset within the EEPROM to be written to
5217 * words - number of words to write
5218 * data - pointer to array of 8 bit words to be written to the EEPROM
5220 *****************************************************************************/
5222 e1000_write_eeprom_spi(struct e1000_hw *hw,
5227 struct e1000_eeprom_info *eeprom = &hw->eeprom;
5230 DEBUGFUNC("e1000_write_eeprom_spi");
5232 while (widx < words) {
5233 uint8_t write_opcode = EEPROM_WRITE_OPCODE_SPI;
5235 if(e1000_spi_eeprom_ready(hw)) return -E1000_ERR_EEPROM;
5237 e1000_standby_eeprom(hw);
5239 /* Send the WRITE ENABLE command (8 bit opcode ) */
5240 e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI,
5241 eeprom->opcode_bits);
5243 e1000_standby_eeprom(hw);
5245 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
5246 if((eeprom->address_bits == 8) && (offset >= 128))
5247 write_opcode |= EEPROM_A8_OPCODE_SPI;
5249 /* Send the Write command (8-bit opcode + addr) */
5250 e1000_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits);
5252 e1000_shift_out_ee_bits(hw, (uint16_t)((offset + widx)*2),
5253 eeprom->address_bits);
5257 /* Loop to allow for up to whole page write (32 bytes) of eeprom */
5258 while (widx < words) {
5259 uint16_t word_out = data[widx];
5260 word_out = (word_out >> 8) | (word_out << 8);
5261 e1000_shift_out_ee_bits(hw, word_out, 16);
5264 /* Some larger eeprom sizes are capable of a 32-byte PAGE WRITE
5265 * operation, while the smaller eeproms are capable of an 8-byte
5266 * PAGE WRITE operation. Break the inner loop to pass new address
5268 if((((offset + widx)*2) % eeprom->page_size) == 0) {
5269 e1000_standby_eeprom(hw);
5275 return E1000_SUCCESS;
5278 /******************************************************************************
5279 * Writes a 16 bit word to a given offset in a Microwire EEPROM.
5281 * hw - Struct containing variables accessed by shared code
5282 * offset - offset within the EEPROM to be written to
5283 * words - number of words to write
5284 * data - pointer to array of 16 bit words to be written to the EEPROM
5286 *****************************************************************************/
5288 e1000_write_eeprom_microwire(struct e1000_hw *hw,
5293 struct e1000_eeprom_info *eeprom = &hw->eeprom;
5295 uint16_t words_written = 0;
5298 DEBUGFUNC("e1000_write_eeprom_microwire");
5300 /* Send the write enable command to the EEPROM (3-bit opcode plus
5301 * 6/8-bit dummy address beginning with 11). It's less work to include
5302 * the 11 of the dummy address as part of the opcode than it is to shift
5303 * it over the correct number of bits for the address. This puts the
5304 * EEPROM into write/erase mode.
5306 e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE,
5307 (uint16_t)(eeprom->opcode_bits + 2));
5309 e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
5311 /* Prepare the EEPROM */
5312 e1000_standby_eeprom(hw);
5314 while (words_written < words) {
5315 /* Send the Write command (3-bit opcode + addr) */
5316 e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE,
5317 eeprom->opcode_bits);
5319 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + words_written),
5320 eeprom->address_bits);
5323 e1000_shift_out_ee_bits(hw, data[words_written], 16);
5325 /* Toggle the CS line. This in effect tells the EEPROM to execute
5326 * the previous command.
5328 e1000_standby_eeprom(hw);
5330 /* Read DO repeatedly until it is high (equal to '1'). The EEPROM will
5331 * signal that the command has been completed by raising the DO signal.
5332 * If DO does not go high in 10 milliseconds, then error out.
5334 for(i = 0; i < 200; i++) {
5335 eecd = E1000_READ_REG(hw, EECD);
5336 if(eecd & E1000_EECD_DO) break;
5340 DEBUGOUT("EEPROM Write did not complete\n");
5341 return -E1000_ERR_EEPROM;
5344 /* Recover from write */
5345 e1000_standby_eeprom(hw);
5350 /* Send the write disable command to the EEPROM (3-bit opcode plus
5351 * 6/8-bit dummy address beginning with 10). It's less work to include
5352 * the 10 of the dummy address as part of the opcode than it is to shift
5353 * it over the correct number of bits for the address. This takes the
5354 * EEPROM out of write/erase mode.
5356 e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE,
5357 (uint16_t)(eeprom->opcode_bits + 2));
5359 e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
5361 return E1000_SUCCESS;
5364 /******************************************************************************
5365 * Flushes the cached eeprom to NVM. This is done by saving the modified values
5366 * in the eeprom cache and the non modified values in the currently active bank
5369 * hw - Struct containing variables accessed by shared code
5370 * offset - offset of word in the EEPROM to read
5371 * data - word read from the EEPROM
5372 * words - number of words to read
5373 *****************************************************************************/
5375 e1000_commit_shadow_ram(struct e1000_hw *hw)
5377 uint32_t attempts = 100000;
5381 int32_t error = E1000_SUCCESS;
5382 uint32_t old_bank_offset = 0;
5383 uint32_t new_bank_offset = 0;
5384 uint32_t sector_retries = 0;
5385 uint8_t low_byte = 0;
5386 uint8_t high_byte = 0;
5387 uint8_t temp_byte = 0;
5388 boolean_t sector_write_failed = FALSE;
5390 if (hw->mac_type == e1000_82573) {
5391 /* The flop register will be used to determine if flash type is STM */
5392 flop = E1000_READ_REG(hw, FLOP);
5393 for (i=0; i < attempts; i++) {
5394 eecd = E1000_READ_REG(hw, EECD);
5395 if ((eecd & E1000_EECD_FLUPD) == 0) {
5401 if (i == attempts) {
5402 return -E1000_ERR_EEPROM;
5405 /* If STM opcode located in bits 15:8 of flop, reset firmware */
5406 if ((flop & 0xFF00) == E1000_STM_OPCODE) {
5407 E1000_WRITE_REG(hw, HICR, E1000_HICR_FW_RESET);
5410 /* Perform the flash update */
5411 E1000_WRITE_REG(hw, EECD, eecd | E1000_EECD_FLUPD);
5413 for (i=0; i < attempts; i++) {
5414 eecd = E1000_READ_REG(hw, EECD);
5415 if ((eecd & E1000_EECD_FLUPD) == 0) {
5421 if (i == attempts) {
5422 return -E1000_ERR_EEPROM;
5426 if (hw->mac_type == e1000_ich8lan && hw->eeprom_shadow_ram != NULL) {
5427 /* We're writing to the opposite bank so if we're on bank 1,
5428 * write to bank 0 etc. We also need to erase the segment that
5429 * is going to be written */
5430 if (!(E1000_READ_REG(hw, EECD) & E1000_EECD_SEC1VAL)) {
5431 new_bank_offset = hw->flash_bank_size * 2;
5432 old_bank_offset = 0;
5433 e1000_erase_ich8_4k_segment(hw, 1);
5435 old_bank_offset = hw->flash_bank_size * 2;
5436 new_bank_offset = 0;
5437 e1000_erase_ich8_4k_segment(hw, 0);
5441 sector_write_failed = FALSE;
5442 /* Loop for every byte in the shadow RAM,
5443 * which is in units of words. */
5444 for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
5445 /* Determine whether to write the value stored
5446 * in the other NVM bank or a modified value stored
5447 * in the shadow RAM */
5448 if (hw->eeprom_shadow_ram[i].modified == TRUE) {
5449 low_byte = (uint8_t)hw->eeprom_shadow_ram[i].eeprom_word;
5450 e1000_read_ich8_byte(hw, (i << 1) + old_bank_offset,
5453 error = e1000_verify_write_ich8_byte(hw,
5454 (i << 1) + new_bank_offset,
5456 if (error != E1000_SUCCESS)
5457 sector_write_failed = TRUE;
5459 (uint8_t)(hw->eeprom_shadow_ram[i].eeprom_word >> 8);
5460 e1000_read_ich8_byte(hw, (i << 1) + old_bank_offset + 1,
5464 e1000_read_ich8_byte(hw, (i << 1) + old_bank_offset,
5467 error = e1000_verify_write_ich8_byte(hw,
5468 (i << 1) + new_bank_offset, low_byte);
5469 if (error != E1000_SUCCESS)
5470 sector_write_failed = TRUE;
5471 e1000_read_ich8_byte(hw, (i << 1) + old_bank_offset + 1,
5475 /* If the word is 0x13, then make sure the signature bits
5476 * (15:14) are 11b until the commit has completed.
5477 * This will allow us to write 10b which indicates the
5478 * signature is valid. We want to do this after the write
5479 * has completed so that we don't mark the segment valid
5480 * while the write is still in progress */
5481 if (i == E1000_ICH8_NVM_SIG_WORD)
5482 high_byte = E1000_ICH8_NVM_SIG_MASK | high_byte;
5484 error = e1000_verify_write_ich8_byte(hw,
5485 (i << 1) + new_bank_offset + 1, high_byte);
5486 if (error != E1000_SUCCESS)
5487 sector_write_failed = TRUE;
5489 if (sector_write_failed == FALSE) {
5490 /* Clear the now not used entry in the cache */
5491 hw->eeprom_shadow_ram[i].modified = FALSE;
5492 hw->eeprom_shadow_ram[i].eeprom_word = 0xFFFF;
5496 /* Don't bother writing the segment valid bits if sector
5497 * programming failed. */
5498 if (sector_write_failed == FALSE) {
5499 /* Finally validate the new segment by setting bit 15:14
5500 * to 10b in word 0x13 , this can be done without an
5501 * erase as well since these bits are 11 to start with
5502 * and we need to change bit 14 to 0b */
5503 e1000_read_ich8_byte(hw,
5504 E1000_ICH8_NVM_SIG_WORD * 2 + 1 + new_bank_offset,
5507 error = e1000_verify_write_ich8_byte(hw,
5508 E1000_ICH8_NVM_SIG_WORD * 2 + 1 + new_bank_offset,
5510 if (error != E1000_SUCCESS)
5511 sector_write_failed = TRUE;
5513 /* And invalidate the previously valid segment by setting
5514 * its signature word (0x13) high_byte to 0b. This can be
5515 * done without an erase because flash erase sets all bits
5516 * to 1's. We can write 1's to 0's without an erase */
5517 error = e1000_verify_write_ich8_byte(hw,
5518 E1000_ICH8_NVM_SIG_WORD * 2 + 1 + old_bank_offset,
5520 if (error != E1000_SUCCESS)
5521 sector_write_failed = TRUE;
5523 } while (++sector_retries < 10 && sector_write_failed == TRUE);
5529 /******************************************************************************
5530 * Reads the adapter's part number from the EEPROM
5532 * hw - Struct containing variables accessed by shared code
5533 * part_num - Adapter's part number
5534 *****************************************************************************/
5536 e1000_read_part_num(struct e1000_hw *hw,
5539 uint16_t offset = EEPROM_PBA_BYTE_1;
5540 uint16_t eeprom_data;
5542 DEBUGFUNC("e1000_read_part_num");
5544 /* Get word 0 from EEPROM */
5545 if(e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
5546 DEBUGOUT("EEPROM Read Error\n");
5547 return -E1000_ERR_EEPROM;
5549 /* Save word 0 in upper half of part_num */
5550 *part_num = (uint32_t) (eeprom_data << 16);
5552 /* Get word 1 from EEPROM */
5553 if(e1000_read_eeprom(hw, ++offset, 1, &eeprom_data) < 0) {
5554 DEBUGOUT("EEPROM Read Error\n");
5555 return -E1000_ERR_EEPROM;
5557 /* Save word 1 in lower half of part_num */
5558 *part_num |= eeprom_data;
5560 return E1000_SUCCESS;
5563 /******************************************************************************
5564 * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
5565 * second function of dual function devices
5567 * hw - Struct containing variables accessed by shared code
5568 *****************************************************************************/
5570 e1000_read_mac_addr(struct e1000_hw * hw)
5573 uint16_t eeprom_data, i;
5575 DEBUGFUNC("e1000_read_mac_addr");
5577 for(i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
5579 if(e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
5580 DEBUGOUT("EEPROM Read Error\n");
5581 return -E1000_ERR_EEPROM;
5583 hw->perm_mac_addr[i] = (uint8_t) (eeprom_data & 0x00FF);
5584 hw->perm_mac_addr[i+1] = (uint8_t) (eeprom_data >> 8);
5587 switch (hw->mac_type) {
5591 case e1000_82546_rev_3:
5593 case e1000_80003es2lan:
5594 if(E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
5595 hw->perm_mac_addr[5] ^= 0x01;
5599 for(i = 0; i < NODE_ADDRESS_SIZE; i++)
5600 hw->mac_addr[i] = hw->perm_mac_addr[i];
5601 return E1000_SUCCESS;
5604 /******************************************************************************
5605 * Initializes receive address filters.
5607 * hw - Struct containing variables accessed by shared code
5609 * Places the MAC address in receive address register 0 and clears the rest
5610 * of the receive addresss registers. Clears the multicast table. Assumes
5611 * the receiver is in reset when the routine is called.
5612 *****************************************************************************/
5614 e1000_init_rx_addrs(struct e1000_hw *hw)
5619 DEBUGFUNC("e1000_init_rx_addrs");
5621 /* Setup the receive address. */
5622 DEBUGOUT("Programming MAC Address into RAR[0]\n");
5624 e1000_rar_set(hw, hw->mac_addr, 0);
5626 rar_num = E1000_RAR_ENTRIES;
5628 /* Reserve a spot for the Locally Administered Address to work around
5629 * an 82571 issue in which a reset on one port will reload the MAC on
5630 * the other port. */
5631 if ((hw->mac_type == e1000_82571) && (hw->laa_is_present == TRUE))
5633 if (hw->mac_type == e1000_ich8lan)
5634 rar_num = E1000_RAR_ENTRIES_ICH8LAN;
5636 /* Zero out the other 15 receive addresses. */
5637 DEBUGOUT("Clearing RAR[1-15]\n");
5638 for(i = 1; i < rar_num; i++) {
5639 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
5640 E1000_WRITE_FLUSH(hw);
5641 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
5642 E1000_WRITE_FLUSH(hw);
5646 /******************************************************************************
5647 * Updates the MAC's list of multicast addresses.
5649 * hw - Struct containing variables accessed by shared code
5650 * mc_addr_list - the list of new multicast addresses
5651 * mc_addr_count - number of addresses
5652 * pad - number of bytes between addresses in the list
5653 * rar_used_count - offset where to start adding mc addresses into the RAR's
5655 * The given list replaces any existing list. Clears the last 15 receive
5656 * address registers and the multicast table. Uses receive address registers
5657 * for the first 15 multicast addresses, and hashes the rest into the
5659 *****************************************************************************/
5661 e1000_mc_addr_list_update(struct e1000_hw *hw,
5662 uint8_t *mc_addr_list,
5663 uint32_t mc_addr_count,
5665 uint32_t rar_used_count)
5667 uint32_t hash_value;
5669 uint32_t num_rar_entry;
5670 uint32_t num_mta_entry;
5672 DEBUGFUNC("e1000_mc_addr_list_update");
5674 /* Set the new number of MC addresses that we are being requested to use. */
5675 hw->num_mc_addrs = mc_addr_count;
5677 /* Clear RAR[1-15] */
5678 DEBUGOUT(" Clearing RAR[1-15]\n");
5679 num_rar_entry = E1000_RAR_ENTRIES;
5680 if (hw->mac_type == e1000_ich8lan)
5681 num_rar_entry = E1000_RAR_ENTRIES_ICH8LAN;
5682 /* Reserve a spot for the Locally Administered Address to work around
5683 * an 82571 issue in which a reset on one port will reload the MAC on
5684 * the other port. */
5685 if ((hw->mac_type == e1000_82571) && (hw->laa_is_present == TRUE))
5688 for(i = rar_used_count; i < num_rar_entry; i++) {
5689 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
5690 E1000_WRITE_FLUSH(hw);
5691 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
5692 E1000_WRITE_FLUSH(hw);
5696 DEBUGOUT(" Clearing MTA\n");
5697 num_mta_entry = E1000_NUM_MTA_REGISTERS;
5698 if (hw->mac_type == e1000_ich8lan)
5699 num_mta_entry = E1000_NUM_MTA_REGISTERS_ICH8LAN;
5700 for(i = 0; i < num_mta_entry; i++) {
5701 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
5702 E1000_WRITE_FLUSH(hw);
5705 /* Add the new addresses */
5706 for(i = 0; i < mc_addr_count; i++) {
5707 DEBUGOUT(" Adding the multicast addresses:\n");
5708 DEBUGOUT7(" MC Addr #%d =%.2X %.2X %.2X %.2X %.2X %.2X\n", i,
5709 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad)],
5710 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 1],
5711 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 2],
5712 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 3],
5713 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 4],
5714 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 5]);
5716 hash_value = e1000_hash_mc_addr(hw,
5718 (i * (ETH_LENGTH_OF_ADDRESS + pad)));
5720 DEBUGOUT1(" Hash value = 0x%03X\n", hash_value);
5722 /* Place this multicast address in the RAR if there is room, *
5723 * else put it in the MTA
5725 if (rar_used_count < num_rar_entry) {
5727 mc_addr_list + (i * (ETH_LENGTH_OF_ADDRESS + pad)),
5731 e1000_mta_set(hw, hash_value);
5734 DEBUGOUT("MC Update Complete\n");
5737 /******************************************************************************
5738 * Hashes an address to determine its location in the multicast table
5740 * hw - Struct containing variables accessed by shared code
5741 * mc_addr - the multicast address to hash
5742 *****************************************************************************/
5744 e1000_hash_mc_addr(struct e1000_hw *hw,
5747 uint32_t hash_value = 0;
5749 /* The portion of the address that is used for the hash table is
5750 * determined by the mc_filter_type setting.
5752 switch (hw->mc_filter_type) {
5753 /* [0] [1] [2] [3] [4] [5]
5758 if (hw->mac_type == e1000_ich8lan) {
5759 /* [47:38] i.e. 0x158 for above example address */
5760 hash_value = ((mc_addr[4] >> 6) | (((uint16_t) mc_addr[5]) << 2));
5762 /* [47:36] i.e. 0x563 for above example address */
5763 hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4));
5767 if (hw->mac_type == e1000_ich8lan) {
5768 /* [46:37] i.e. 0x2B1 for above example address */
5769 hash_value = ((mc_addr[4] >> 5) | (((uint16_t) mc_addr[5]) << 3));
5771 /* [46:35] i.e. 0xAC6 for above example address */
5772 hash_value = ((mc_addr[4] >> 3) | (((uint16_t) mc_addr[5]) << 5));
5776 if (hw->mac_type == e1000_ich8lan) {
5777 /*[45:36] i.e. 0x163 for above example address */
5778 hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4));
5780 /* [45:34] i.e. 0x5D8 for above example address */
5781 hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6));
5785 if (hw->mac_type == e1000_ich8lan) {
5786 /* [43:34] i.e. 0x18D for above example address */
5787 hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6));
5789 /* [43:32] i.e. 0x634 for above example address */
5790 hash_value = ((mc_addr[4]) | (((uint16_t) mc_addr[5]) << 8));
5795 hash_value &= 0xFFF;
5796 if (hw->mac_type == e1000_ich8lan)
5797 hash_value &= 0x3FF;
5802 /******************************************************************************
5803 * Sets the bit in the multicast table corresponding to the hash value.
5805 * hw - Struct containing variables accessed by shared code
5806 * hash_value - Multicast address hash value
5807 *****************************************************************************/
5809 e1000_mta_set(struct e1000_hw *hw,
5810 uint32_t hash_value)
5812 uint32_t hash_bit, hash_reg;
5816 /* The MTA is a register array of 128 32-bit registers.
5817 * It is treated like an array of 4096 bits. We want to set
5818 * bit BitArray[hash_value]. So we figure out what register
5819 * the bit is in, read it, OR in the new bit, then write
5820 * back the new value. The register is determined by the
5821 * upper 7 bits of the hash value and the bit within that
5822 * register are determined by the lower 5 bits of the value.
5824 hash_reg = (hash_value >> 5) & 0x7F;
5825 if (hw->mac_type == e1000_ich8lan)
5827 hash_bit = hash_value & 0x1F;
5829 mta = E1000_READ_REG_ARRAY(hw, MTA, hash_reg);
5831 mta |= (1 << hash_bit);
5833 /* If we are on an 82544 and we are trying to write an odd offset
5834 * in the MTA, save off the previous entry before writing and
5835 * restore the old value after writing.
5837 if((hw->mac_type == e1000_82544) && ((hash_reg & 0x1) == 1)) {
5838 temp = E1000_READ_REG_ARRAY(hw, MTA, (hash_reg - 1));
5839 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
5840 E1000_WRITE_FLUSH(hw);
5841 E1000_WRITE_REG_ARRAY(hw, MTA, (hash_reg - 1), temp);
5842 E1000_WRITE_FLUSH(hw);
5844 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
5845 E1000_WRITE_FLUSH(hw);
5849 /******************************************************************************
5850 * Puts an ethernet address into a receive address register.
5852 * hw - Struct containing variables accessed by shared code
5853 * addr - Address to put into receive address register
5854 * index - Receive address register to write
5855 *****************************************************************************/
5857 e1000_rar_set(struct e1000_hw *hw,
5861 uint32_t rar_low, rar_high;
5863 /* HW expects these in little endian so we reverse the byte order
5864 * from network order (big endian) to little endian
5866 rar_low = ((uint32_t) addr[0] |
5867 ((uint32_t) addr[1] << 8) |
5868 ((uint32_t) addr[2] << 16) | ((uint32_t) addr[3] << 24));
5869 rar_high = ((uint32_t) addr[4] | ((uint32_t) addr[5] << 8));
5871 /* Disable Rx and flush all Rx frames before enabling RSS to avoid Rx
5875 * If there are any Rx frames queued up or otherwise present in the HW
5876 * before RSS is enabled, and then we enable RSS, the HW Rx unit will
5877 * hang. To work around this issue, we have to disable receives and
5878 * flush out all Rx frames before we enable RSS. To do so, we modify we
5879 * redirect all Rx traffic to manageability and then reset the HW.
5880 * This flushes away Rx frames, and (since the redirections to
5881 * manageability persists across resets) keeps new ones from coming in
5882 * while we work. Then, we clear the Address Valid AV bit for all MAC
5883 * addresses and undo the re-direction to manageability.
5884 * Now, frames are coming in again, but the MAC won't accept them, so
5885 * far so good. We now proceed to initialize RSS (if necessary) and
5886 * configure the Rx unit. Last, we re-enable the AV bits and continue
5889 switch (hw->mac_type) {
5892 case e1000_80003es2lan:
5893 if (hw->leave_av_bit_off == TRUE)
5896 /* Indicate to hardware the Address is Valid. */
5897 rar_high |= E1000_RAH_AV;
5901 E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
5902 E1000_WRITE_FLUSH(hw);
5903 E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
5904 E1000_WRITE_FLUSH(hw);
5907 /******************************************************************************
5908 * Writes a value to the specified offset in the VLAN filter table.
5910 * hw - Struct containing variables accessed by shared code
5911 * offset - Offset in VLAN filer table to write
5912 * value - Value to write into VLAN filter table
5913 *****************************************************************************/
5915 e1000_write_vfta(struct e1000_hw *hw,
5921 if (hw->mac_type == e1000_ich8lan)
5924 if ((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) {
5925 temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1));
5926 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
5927 E1000_WRITE_FLUSH(hw);
5928 E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp);
5929 E1000_WRITE_FLUSH(hw);
5931 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
5932 E1000_WRITE_FLUSH(hw);
5936 /******************************************************************************
5937 * Clears the VLAN filer table
5939 * hw - Struct containing variables accessed by shared code
5940 *****************************************************************************/
5942 e1000_clear_vfta(struct e1000_hw *hw)
5945 uint32_t vfta_value = 0;
5946 uint32_t vfta_offset = 0;
5947 uint32_t vfta_bit_in_reg = 0;
5949 if (hw->mac_type == e1000_ich8lan)
5952 if (hw->mac_type == e1000_82573) {
5953 if (hw->mng_cookie.vlan_id != 0) {
5954 /* The VFTA is a 4096b bit-field, each identifying a single VLAN
5955 * ID. The following operations determine which 32b entry
5956 * (i.e. offset) into the array we want to set the VLAN ID
5957 * (i.e. bit) of the manageability unit. */
5958 vfta_offset = (hw->mng_cookie.vlan_id >>
5959 E1000_VFTA_ENTRY_SHIFT) &
5960 E1000_VFTA_ENTRY_MASK;
5961 vfta_bit_in_reg = 1 << (hw->mng_cookie.vlan_id &
5962 E1000_VFTA_ENTRY_BIT_SHIFT_MASK);
5965 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
5966 /* If the offset we want to clear is the same offset of the
5967 * manageability VLAN ID, then clear all bits except that of the
5968 * manageability unit */
5969 vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0;
5970 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, vfta_value);
5971 E1000_WRITE_FLUSH(hw);
5976 e1000_id_led_init(struct e1000_hw * hw)
5979 const uint32_t ledctl_mask = 0x000000FF;
5980 const uint32_t ledctl_on = E1000_LEDCTL_MODE_LED_ON;
5981 const uint32_t ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
5982 uint16_t eeprom_data, i, temp;
5983 const uint16_t led_mask = 0x0F;
5985 DEBUGFUNC("e1000_id_led_init");
5987 if(hw->mac_type < e1000_82540) {
5989 return E1000_SUCCESS;
5992 ledctl = E1000_READ_REG(hw, LEDCTL);
5993 hw->ledctl_default = ledctl;
5994 hw->ledctl_mode1 = hw->ledctl_default;
5995 hw->ledctl_mode2 = hw->ledctl_default;
5997 if(e1000_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, 1, &eeprom_data) < 0) {
5998 DEBUGOUT("EEPROM Read Error\n");
5999 return -E1000_ERR_EEPROM;
6002 if ((hw->mac_type == e1000_82573) &&
6003 (eeprom_data == ID_LED_RESERVED_82573))
6004 eeprom_data = ID_LED_DEFAULT_82573;
6005 else if ((eeprom_data == ID_LED_RESERVED_0000) ||
6006 (eeprom_data == ID_LED_RESERVED_FFFF)) {
6007 if (hw->mac_type == e1000_ich8lan)
6008 eeprom_data = ID_LED_DEFAULT_ICH8LAN;
6010 eeprom_data = ID_LED_DEFAULT;
6012 for (i = 0; i < 4; i++) {
6013 temp = (eeprom_data >> (i << 2)) & led_mask;
6015 case ID_LED_ON1_DEF2:
6016 case ID_LED_ON1_ON2:
6017 case ID_LED_ON1_OFF2:
6018 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
6019 hw->ledctl_mode1 |= ledctl_on << (i << 3);
6021 case ID_LED_OFF1_DEF2:
6022 case ID_LED_OFF1_ON2:
6023 case ID_LED_OFF1_OFF2:
6024 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
6025 hw->ledctl_mode1 |= ledctl_off << (i << 3);
6032 case ID_LED_DEF1_ON2:
6033 case ID_LED_ON1_ON2:
6034 case ID_LED_OFF1_ON2:
6035 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
6036 hw->ledctl_mode2 |= ledctl_on << (i << 3);
6038 case ID_LED_DEF1_OFF2:
6039 case ID_LED_ON1_OFF2:
6040 case ID_LED_OFF1_OFF2:
6041 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
6042 hw->ledctl_mode2 |= ledctl_off << (i << 3);
6049 return E1000_SUCCESS;
6052 /******************************************************************************
6053 * Prepares SW controlable LED for use and saves the current state of the LED.
6055 * hw - Struct containing variables accessed by shared code
6056 *****************************************************************************/
6058 e1000_setup_led(struct e1000_hw *hw)
6061 int32_t ret_val = E1000_SUCCESS;
6063 DEBUGFUNC("e1000_setup_led");
6065 switch(hw->mac_type) {
6066 case e1000_82542_rev2_0:
6067 case e1000_82542_rev2_1:
6070 /* No setup necessary */
6074 case e1000_82541_rev_2:
6075 case e1000_82547_rev_2:
6076 /* Turn off PHY Smart Power Down (if enabled) */
6077 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
6078 &hw->phy_spd_default);
6081 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
6082 (uint16_t)(hw->phy_spd_default &
6083 ~IGP01E1000_GMII_SPD));
6088 if(hw->media_type == e1000_media_type_fiber) {
6089 ledctl = E1000_READ_REG(hw, LEDCTL);
6090 /* Save current LEDCTL settings */
6091 hw->ledctl_default = ledctl;
6093 ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
6094 E1000_LEDCTL_LED0_BLINK |
6095 E1000_LEDCTL_LED0_MODE_MASK);
6096 ledctl |= (E1000_LEDCTL_MODE_LED_OFF <<
6097 E1000_LEDCTL_LED0_MODE_SHIFT);
6098 E1000_WRITE_REG(hw, LEDCTL, ledctl);
6099 } else if(hw->media_type == e1000_media_type_copper)
6100 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
6104 return E1000_SUCCESS;
6107 /******************************************************************************
6108 * Used on 82571 and later Si that has LED blink bits.
6109 * Callers must use their own timer and should have already called
6110 * e1000_id_led_init()
6111 * Call e1000_cleanup led() to stop blinking
6113 * hw - Struct containing variables accessed by shared code
6114 *****************************************************************************/
6116 e1000_blink_led_start(struct e1000_hw *hw)
6119 uint32_t ledctl_blink = 0;
6121 DEBUGFUNC("e1000_id_led_blink_on");
6123 if (hw->mac_type < e1000_82571) {
6125 return E1000_SUCCESS;
6127 if (hw->media_type == e1000_media_type_fiber) {
6128 /* always blink LED0 for PCI-E fiber */
6129 ledctl_blink = E1000_LEDCTL_LED0_BLINK |
6130 (E1000_LEDCTL_MODE_LED_ON << E1000_LEDCTL_LED0_MODE_SHIFT);
6132 /* set the blink bit for each LED that's "on" (0x0E) in ledctl_mode2 */
6133 ledctl_blink = hw->ledctl_mode2;
6134 for (i=0; i < 4; i++)
6135 if (((hw->ledctl_mode2 >> (i * 8)) & 0xFF) ==
6136 E1000_LEDCTL_MODE_LED_ON)
6137 ledctl_blink |= (E1000_LEDCTL_LED0_BLINK << (i * 8));
6140 E1000_WRITE_REG(hw, LEDCTL, ledctl_blink);
6142 return E1000_SUCCESS;
6145 /******************************************************************************
6146 * Restores the saved state of the SW controlable LED.
6148 * hw - Struct containing variables accessed by shared code
6149 *****************************************************************************/
6151 e1000_cleanup_led(struct e1000_hw *hw)
6153 int32_t ret_val = E1000_SUCCESS;
6155 DEBUGFUNC("e1000_cleanup_led");
6157 switch(hw->mac_type) {
6158 case e1000_82542_rev2_0:
6159 case e1000_82542_rev2_1:
6162 /* No cleanup necessary */
6166 case e1000_82541_rev_2:
6167 case e1000_82547_rev_2:
6168 /* Turn on PHY Smart Power Down (if previously enabled) */
6169 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
6170 hw->phy_spd_default);
6175 if (hw->phy_type == e1000_phy_ife) {
6176 e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
6179 /* Restore LEDCTL settings */
6180 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_default);
6184 return E1000_SUCCESS;
6187 /******************************************************************************
6188 * Turns on the software controllable LED
6190 * hw - Struct containing variables accessed by shared code
6191 *****************************************************************************/
6193 e1000_led_on(struct e1000_hw *hw)
6195 uint32_t ctrl = E1000_READ_REG(hw, CTRL);
6197 DEBUGFUNC("e1000_led_on");
6199 switch(hw->mac_type) {
6200 case e1000_82542_rev2_0:
6201 case e1000_82542_rev2_1:
6203 /* Set SW Defineable Pin 0 to turn on the LED */
6204 ctrl |= E1000_CTRL_SWDPIN0;
6205 ctrl |= E1000_CTRL_SWDPIO0;
6208 if(hw->media_type == e1000_media_type_fiber) {
6209 /* Set SW Defineable Pin 0 to turn on the LED */
6210 ctrl |= E1000_CTRL_SWDPIN0;
6211 ctrl |= E1000_CTRL_SWDPIO0;
6213 /* Clear SW Defineable Pin 0 to turn on the LED */
6214 ctrl &= ~E1000_CTRL_SWDPIN0;
6215 ctrl |= E1000_CTRL_SWDPIO0;
6219 if(hw->media_type == e1000_media_type_fiber) {
6220 /* Clear SW Defineable Pin 0 to turn on the LED */
6221 ctrl &= ~E1000_CTRL_SWDPIN0;
6222 ctrl |= E1000_CTRL_SWDPIO0;
6223 } else if (hw->phy_type == e1000_phy_ife) {
6224 e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED,
6225 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_ON));
6226 } else if (hw->media_type == e1000_media_type_copper) {
6227 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode2);
6228 return E1000_SUCCESS;
6233 E1000_WRITE_REG(hw, CTRL, ctrl);
6235 return E1000_SUCCESS;
6238 /******************************************************************************
6239 * Turns off the software controllable LED
6241 * hw - Struct containing variables accessed by shared code
6242 *****************************************************************************/
6244 e1000_led_off(struct e1000_hw *hw)
6246 uint32_t ctrl = E1000_READ_REG(hw, CTRL);
6248 DEBUGFUNC("e1000_led_off");
6250 switch(hw->mac_type) {
6251 case e1000_82542_rev2_0:
6252 case e1000_82542_rev2_1:
6254 /* Clear SW Defineable Pin 0 to turn off the LED */
6255 ctrl &= ~E1000_CTRL_SWDPIN0;
6256 ctrl |= E1000_CTRL_SWDPIO0;
6259 if(hw->media_type == e1000_media_type_fiber) {
6260 /* Clear SW Defineable Pin 0 to turn off the LED */
6261 ctrl &= ~E1000_CTRL_SWDPIN0;
6262 ctrl |= E1000_CTRL_SWDPIO0;
6264 /* Set SW Defineable Pin 0 to turn off the LED */
6265 ctrl |= E1000_CTRL_SWDPIN0;
6266 ctrl |= E1000_CTRL_SWDPIO0;
6270 if(hw->media_type == e1000_media_type_fiber) {
6271 /* Set SW Defineable Pin 0 to turn off the LED */
6272 ctrl |= E1000_CTRL_SWDPIN0;
6273 ctrl |= E1000_CTRL_SWDPIO0;
6274 } else if (hw->phy_type == e1000_phy_ife) {
6275 e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED,
6276 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_OFF));
6277 } else if (hw->media_type == e1000_media_type_copper) {
6278 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
6279 return E1000_SUCCESS;
6284 E1000_WRITE_REG(hw, CTRL, ctrl);
6286 return E1000_SUCCESS;
6289 /******************************************************************************
6290 * Clears all hardware statistics counters.
6292 * hw - Struct containing variables accessed by shared code
6293 *****************************************************************************/
6295 e1000_clear_hw_cntrs(struct e1000_hw *hw)
6297 volatile uint32_t temp;
6299 temp = E1000_READ_REG(hw, CRCERRS);
6300 temp = E1000_READ_REG(hw, SYMERRS);
6301 temp = E1000_READ_REG(hw, MPC);
6302 temp = E1000_READ_REG(hw, SCC);
6303 temp = E1000_READ_REG(hw, ECOL);
6304 temp = E1000_READ_REG(hw, MCC);
6305 temp = E1000_READ_REG(hw, LATECOL);
6306 temp = E1000_READ_REG(hw, COLC);
6307 temp = E1000_READ_REG(hw, DC);
6308 temp = E1000_READ_REG(hw, SEC);
6309 temp = E1000_READ_REG(hw, RLEC);
6310 temp = E1000_READ_REG(hw, XONRXC);
6311 temp = E1000_READ_REG(hw, XONTXC);
6312 temp = E1000_READ_REG(hw, XOFFRXC);
6313 temp = E1000_READ_REG(hw, XOFFTXC);
6314 temp = E1000_READ_REG(hw, FCRUC);
6316 if (hw->mac_type != e1000_ich8lan) {
6317 temp = E1000_READ_REG(hw, PRC64);
6318 temp = E1000_READ_REG(hw, PRC127);
6319 temp = E1000_READ_REG(hw, PRC255);
6320 temp = E1000_READ_REG(hw, PRC511);
6321 temp = E1000_READ_REG(hw, PRC1023);
6322 temp = E1000_READ_REG(hw, PRC1522);
6325 temp = E1000_READ_REG(hw, GPRC);
6326 temp = E1000_READ_REG(hw, BPRC);
6327 temp = E1000_READ_REG(hw, MPRC);
6328 temp = E1000_READ_REG(hw, GPTC);
6329 temp = E1000_READ_REG(hw, GORCL);
6330 temp = E1000_READ_REG(hw, GORCH);
6331 temp = E1000_READ_REG(hw, GOTCL);
6332 temp = E1000_READ_REG(hw, GOTCH);
6333 temp = E1000_READ_REG(hw, RNBC);
6334 temp = E1000_READ_REG(hw, RUC);
6335 temp = E1000_READ_REG(hw, RFC);
6336 temp = E1000_READ_REG(hw, ROC);
6337 temp = E1000_READ_REG(hw, RJC);
6338 temp = E1000_READ_REG(hw, TORL);
6339 temp = E1000_READ_REG(hw, TORH);
6340 temp = E1000_READ_REG(hw, TOTL);
6341 temp = E1000_READ_REG(hw, TOTH);
6342 temp = E1000_READ_REG(hw, TPR);
6343 temp = E1000_READ_REG(hw, TPT);
6345 if (hw->mac_type != e1000_ich8lan) {
6346 temp = E1000_READ_REG(hw, PTC64);
6347 temp = E1000_READ_REG(hw, PTC127);
6348 temp = E1000_READ_REG(hw, PTC255);
6349 temp = E1000_READ_REG(hw, PTC511);
6350 temp = E1000_READ_REG(hw, PTC1023);
6351 temp = E1000_READ_REG(hw, PTC1522);
6354 temp = E1000_READ_REG(hw, MPTC);
6355 temp = E1000_READ_REG(hw, BPTC);
6357 if(hw->mac_type < e1000_82543) return;
6359 temp = E1000_READ_REG(hw, ALGNERRC);
6360 temp = E1000_READ_REG(hw, RXERRC);
6361 temp = E1000_READ_REG(hw, TNCRS);
6362 temp = E1000_READ_REG(hw, CEXTERR);
6363 temp = E1000_READ_REG(hw, TSCTC);
6364 temp = E1000_READ_REG(hw, TSCTFC);
6366 if(hw->mac_type <= e1000_82544) return;
6368 temp = E1000_READ_REG(hw, MGTPRC);
6369 temp = E1000_READ_REG(hw, MGTPDC);
6370 temp = E1000_READ_REG(hw, MGTPTC);
6372 if(hw->mac_type <= e1000_82547_rev_2) return;
6374 temp = E1000_READ_REG(hw, IAC);
6375 temp = E1000_READ_REG(hw, ICRXOC);
6377 if (hw->mac_type == e1000_ich8lan) return;
6379 temp = E1000_READ_REG(hw, ICRXPTC);
6380 temp = E1000_READ_REG(hw, ICRXATC);
6381 temp = E1000_READ_REG(hw, ICTXPTC);
6382 temp = E1000_READ_REG(hw, ICTXATC);
6383 temp = E1000_READ_REG(hw, ICTXQEC);
6384 temp = E1000_READ_REG(hw, ICTXQMTC);
6385 temp = E1000_READ_REG(hw, ICRXDMTC);
6388 /******************************************************************************
6389 * Resets Adaptive IFS to its default state.
6391 * hw - Struct containing variables accessed by shared code
6393 * Call this after e1000_init_hw. You may override the IFS defaults by setting
6394 * hw->ifs_params_forced to TRUE. However, you must initialize hw->
6395 * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio
6396 * before calling this function.
6397 *****************************************************************************/
6399 e1000_reset_adaptive(struct e1000_hw *hw)
6401 DEBUGFUNC("e1000_reset_adaptive");
6403 if(hw->adaptive_ifs) {
6404 if(!hw->ifs_params_forced) {
6405 hw->current_ifs_val = 0;
6406 hw->ifs_min_val = IFS_MIN;
6407 hw->ifs_max_val = IFS_MAX;
6408 hw->ifs_step_size = IFS_STEP;
6409 hw->ifs_ratio = IFS_RATIO;
6411 hw->in_ifs_mode = FALSE;
6412 E1000_WRITE_REG(hw, AIT, 0);
6414 DEBUGOUT("Not in Adaptive IFS mode!\n");
6418 /******************************************************************************
6419 * Called during the callback/watchdog routine to update IFS value based on
6420 * the ratio of transmits to collisions.
6422 * hw - Struct containing variables accessed by shared code
6423 * tx_packets - Number of transmits since last callback
6424 * total_collisions - Number of collisions since last callback
6425 *****************************************************************************/
6427 e1000_update_adaptive(struct e1000_hw *hw)
6429 DEBUGFUNC("e1000_update_adaptive");
6431 if(hw->adaptive_ifs) {
6432 if((hw->collision_delta * hw->ifs_ratio) > hw->tx_packet_delta) {
6433 if(hw->tx_packet_delta > MIN_NUM_XMITS) {
6434 hw->in_ifs_mode = TRUE;
6435 if(hw->current_ifs_val < hw->ifs_max_val) {
6436 if(hw->current_ifs_val == 0)
6437 hw->current_ifs_val = hw->ifs_min_val;
6439 hw->current_ifs_val += hw->ifs_step_size;
6440 E1000_WRITE_REG(hw, AIT, hw->current_ifs_val);
6444 if(hw->in_ifs_mode && (hw->tx_packet_delta <= MIN_NUM_XMITS)) {
6445 hw->current_ifs_val = 0;
6446 hw->in_ifs_mode = FALSE;
6447 E1000_WRITE_REG(hw, AIT, 0);
6451 DEBUGOUT("Not in Adaptive IFS mode!\n");
6455 /******************************************************************************
6456 * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT
6458 * hw - Struct containing variables accessed by shared code
6459 * frame_len - The length of the frame in question
6460 * mac_addr - The Ethernet destination address of the frame in question
6461 *****************************************************************************/
6463 e1000_tbi_adjust_stats(struct e1000_hw *hw,
6464 struct e1000_hw_stats *stats,
6470 /* First adjust the frame length. */
6472 /* We need to adjust the statistics counters, since the hardware
6473 * counters overcount this packet as a CRC error and undercount
6474 * the packet as a good packet
6476 /* This packet should not be counted as a CRC error. */
6478 /* This packet does count as a Good Packet Received. */
6481 /* Adjust the Good Octets received counters */
6482 carry_bit = 0x80000000 & stats->gorcl;
6483 stats->gorcl += frame_len;
6484 /* If the high bit of Gorcl (the low 32 bits of the Good Octets
6485 * Received Count) was one before the addition,
6486 * AND it is zero after, then we lost the carry out,
6487 * need to add one to Gorch (Good Octets Received Count High).
6488 * This could be simplified if all environments supported
6491 if(carry_bit && ((stats->gorcl & 0x80000000) == 0))
6493 /* Is this a broadcast or multicast? Check broadcast first,
6494 * since the test for a multicast frame will test positive on
6495 * a broadcast frame.
6497 if((mac_addr[0] == (uint8_t) 0xff) && (mac_addr[1] == (uint8_t) 0xff))
6498 /* Broadcast packet */
6500 else if(*mac_addr & 0x01)
6501 /* Multicast packet */
6504 if(frame_len == hw->max_frame_size) {
6505 /* In this case, the hardware has overcounted the number of
6512 /* Adjust the bin counters when the extra byte put the frame in the
6513 * wrong bin. Remember that the frame_len was adjusted above.
6515 if(frame_len == 64) {
6518 } else if(frame_len == 127) {
6521 } else if(frame_len == 255) {
6524 } else if(frame_len == 511) {
6527 } else if(frame_len == 1023) {
6530 } else if(frame_len == 1522) {
6535 /******************************************************************************
6536 * Gets the current PCI bus type, speed, and width of the hardware
6538 * hw - Struct containing variables accessed by shared code
6539 *****************************************************************************/
6541 e1000_get_bus_info(struct e1000_hw *hw)
6545 switch (hw->mac_type) {
6546 case e1000_82542_rev2_0:
6547 case e1000_82542_rev2_1:
6548 hw->bus_type = e1000_bus_type_unknown;
6549 hw->bus_speed = e1000_bus_speed_unknown;
6550 hw->bus_width = e1000_bus_width_unknown;
6554 hw->bus_type = e1000_bus_type_pci_express;
6555 hw->bus_speed = e1000_bus_speed_2500;
6556 hw->bus_width = e1000_bus_width_pciex_1;
6560 case e1000_80003es2lan:
6561 hw->bus_type = e1000_bus_type_pci_express;
6562 hw->bus_speed = e1000_bus_speed_2500;
6563 hw->bus_width = e1000_bus_width_pciex_4;
6566 status = E1000_READ_REG(hw, STATUS);
6567 hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
6568 e1000_bus_type_pcix : e1000_bus_type_pci;
6570 if(hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) {
6571 hw->bus_speed = (hw->bus_type == e1000_bus_type_pci) ?
6572 e1000_bus_speed_66 : e1000_bus_speed_120;
6573 } else if(hw->bus_type == e1000_bus_type_pci) {
6574 hw->bus_speed = (status & E1000_STATUS_PCI66) ?
6575 e1000_bus_speed_66 : e1000_bus_speed_33;
6577 switch (status & E1000_STATUS_PCIX_SPEED) {
6578 case E1000_STATUS_PCIX_SPEED_66:
6579 hw->bus_speed = e1000_bus_speed_66;
6581 case E1000_STATUS_PCIX_SPEED_100:
6582 hw->bus_speed = e1000_bus_speed_100;
6584 case E1000_STATUS_PCIX_SPEED_133:
6585 hw->bus_speed = e1000_bus_speed_133;
6588 hw->bus_speed = e1000_bus_speed_reserved;
6592 hw->bus_width = (status & E1000_STATUS_BUS64) ?
6593 e1000_bus_width_64 : e1000_bus_width_32;
6597 /******************************************************************************
6598 * Reads a value from one of the devices registers using port I/O (as opposed
6599 * memory mapped I/O). Only 82544 and newer devices support port I/O.
6601 * hw - Struct containing variables accessed by shared code
6602 * offset - offset to read from
6603 *****************************************************************************/
6605 e1000_read_reg_io(struct e1000_hw *hw,
6608 unsigned long io_addr = hw->io_base;
6609 unsigned long io_data = hw->io_base + 4;
6611 e1000_io_write(hw, io_addr, offset);
6612 return e1000_io_read(hw, io_data);
6615 /******************************************************************************
6616 * Writes a value to one of the devices registers using port I/O (as opposed to
6617 * memory mapped I/O). Only 82544 and newer devices support port I/O.
6619 * hw - Struct containing variables accessed by shared code
6620 * offset - offset to write to
6621 * value - value to write
6622 *****************************************************************************/
6624 e1000_write_reg_io(struct e1000_hw *hw,
6628 unsigned long io_addr = hw->io_base;
6629 unsigned long io_data = hw->io_base + 4;
6631 e1000_io_write(hw, io_addr, offset);
6632 e1000_io_write(hw, io_data, value);
6636 /******************************************************************************
6637 * Estimates the cable length.
6639 * hw - Struct containing variables accessed by shared code
6640 * min_length - The estimated minimum length
6641 * max_length - The estimated maximum length
6643 * returns: - E1000_ERR_XXX
6646 * This function always returns a ranged length (minimum & maximum).
6647 * So for M88 phy's, this function interprets the one value returned from the
6648 * register to the minimum and maximum range.
6649 * For IGP phy's, the function calculates the range by the AGC registers.
6650 *****************************************************************************/
6652 e1000_get_cable_length(struct e1000_hw *hw,
6653 uint16_t *min_length,
6654 uint16_t *max_length)
6657 uint16_t agc_value = 0;
6658 uint16_t i, phy_data;
6659 uint16_t cable_length;
6661 DEBUGFUNC("e1000_get_cable_length");
6663 *min_length = *max_length = 0;
6665 /* Use old method for Phy older than IGP */
6666 if(hw->phy_type == e1000_phy_m88) {
6668 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6672 cable_length = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
6673 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
6675 /* Convert the enum value to ranged values */
6676 switch (cable_length) {
6677 case e1000_cable_length_50:
6679 *max_length = e1000_igp_cable_length_50;
6681 case e1000_cable_length_50_80:
6682 *min_length = e1000_igp_cable_length_50;
6683 *max_length = e1000_igp_cable_length_80;
6685 case e1000_cable_length_80_110:
6686 *min_length = e1000_igp_cable_length_80;
6687 *max_length = e1000_igp_cable_length_110;
6689 case e1000_cable_length_110_140:
6690 *min_length = e1000_igp_cable_length_110;
6691 *max_length = e1000_igp_cable_length_140;
6693 case e1000_cable_length_140:
6694 *min_length = e1000_igp_cable_length_140;
6695 *max_length = e1000_igp_cable_length_170;
6698 return -E1000_ERR_PHY;
6701 } else if (hw->phy_type == e1000_phy_gg82563) {
6702 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_DSP_DISTANCE,
6706 cable_length = phy_data & GG82563_DSPD_CABLE_LENGTH;
6708 switch (cable_length) {
6709 case e1000_gg_cable_length_60:
6711 *max_length = e1000_igp_cable_length_60;
6713 case e1000_gg_cable_length_60_115:
6714 *min_length = e1000_igp_cable_length_60;
6715 *max_length = e1000_igp_cable_length_115;
6717 case e1000_gg_cable_length_115_150:
6718 *min_length = e1000_igp_cable_length_115;
6719 *max_length = e1000_igp_cable_length_150;
6721 case e1000_gg_cable_length_150:
6722 *min_length = e1000_igp_cable_length_150;
6723 *max_length = e1000_igp_cable_length_180;
6726 return -E1000_ERR_PHY;
6729 } else if(hw->phy_type == e1000_phy_igp) { /* For IGP PHY */
6730 uint16_t cur_agc_value;
6731 uint16_t min_agc_value = IGP01E1000_AGC_LENGTH_TABLE_SIZE;
6732 uint16_t agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
6733 {IGP01E1000_PHY_AGC_A,
6734 IGP01E1000_PHY_AGC_B,
6735 IGP01E1000_PHY_AGC_C,
6736 IGP01E1000_PHY_AGC_D};
6737 /* Read the AGC registers for all channels */
6738 for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
6740 ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
6744 cur_agc_value = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT;
6746 /* Value bound check. */
6747 if ((cur_agc_value >= IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1) ||
6748 (cur_agc_value == 0))
6749 return -E1000_ERR_PHY;
6751 agc_value += cur_agc_value;
6753 /* Update minimal AGC value. */
6754 if (min_agc_value > cur_agc_value)
6755 min_agc_value = cur_agc_value;
6758 /* Remove the minimal AGC result for length < 50m */
6759 if (agc_value < IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) {
6760 agc_value -= min_agc_value;
6762 /* Get the average length of the remaining 3 channels */
6763 agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1);
6765 /* Get the average length of all the 4 channels. */
6766 agc_value /= IGP01E1000_PHY_CHANNEL_NUM;
6769 /* Set the range of the calculated length. */
6770 *min_length = ((e1000_igp_cable_length_table[agc_value] -
6771 IGP01E1000_AGC_RANGE) > 0) ?
6772 (e1000_igp_cable_length_table[agc_value] -
6773 IGP01E1000_AGC_RANGE) : 0;
6774 *max_length = e1000_igp_cable_length_table[agc_value] +
6775 IGP01E1000_AGC_RANGE;
6776 } else if (hw->phy_type == e1000_phy_igp_2 ||
6777 hw->phy_type == e1000_phy_igp_3) {
6778 uint16_t cur_agc_index, max_agc_index = 0;
6779 uint16_t min_agc_index = IGP02E1000_AGC_LENGTH_TABLE_SIZE - 1;
6780 uint16_t agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] =
6781 {IGP02E1000_PHY_AGC_A,
6782 IGP02E1000_PHY_AGC_B,
6783 IGP02E1000_PHY_AGC_C,
6784 IGP02E1000_PHY_AGC_D};
6785 /* Read the AGC registers for all channels */
6786 for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
6787 ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
6791 /* Getting bits 15:9, which represent the combination of course and
6792 * fine gain values. The result is a number that can be put into
6793 * the lookup table to obtain the approximate cable length. */
6794 cur_agc_index = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
6795 IGP02E1000_AGC_LENGTH_MASK;
6797 /* Array index bound check. */
6798 if ((cur_agc_index >= IGP02E1000_AGC_LENGTH_TABLE_SIZE) ||
6799 (cur_agc_index == 0))
6800 return -E1000_ERR_PHY;
6802 /* Remove min & max AGC values from calculation. */
6803 if (e1000_igp_2_cable_length_table[min_agc_index] >
6804 e1000_igp_2_cable_length_table[cur_agc_index])
6805 min_agc_index = cur_agc_index;
6806 if (e1000_igp_2_cable_length_table[max_agc_index] <
6807 e1000_igp_2_cable_length_table[cur_agc_index])
6808 max_agc_index = cur_agc_index;
6810 agc_value += e1000_igp_2_cable_length_table[cur_agc_index];
6813 agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] +
6814 e1000_igp_2_cable_length_table[max_agc_index]);
6815 agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
6817 /* Calculate cable length with the error range of +/- 10 meters. */
6818 *min_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
6819 (agc_value - IGP02E1000_AGC_RANGE) : 0;
6820 *max_length = agc_value + IGP02E1000_AGC_RANGE;
6823 return E1000_SUCCESS;
6826 /******************************************************************************
6827 * Check the cable polarity
6829 * hw - Struct containing variables accessed by shared code
6830 * polarity - output parameter : 0 - Polarity is not reversed
6831 * 1 - Polarity is reversed.
6833 * returns: - E1000_ERR_XXX
6836 * For phy's older then IGP, this function simply reads the polarity bit in the
6837 * Phy Status register. For IGP phy's, this bit is valid only if link speed is
6838 * 10 Mbps. If the link speed is 100 Mbps there is no polarity so this bit will
6839 * return 0. If the link speed is 1000 Mbps the polarity status is in the
6840 * IGP01E1000_PHY_PCS_INIT_REG.
6841 *****************************************************************************/
6843 e1000_check_polarity(struct e1000_hw *hw,
6849 DEBUGFUNC("e1000_check_polarity");
6851 if ((hw->phy_type == e1000_phy_m88) ||
6852 (hw->phy_type == e1000_phy_gg82563)) {
6853 /* return the Polarity bit in the Status register. */
6854 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6858 *polarity = (phy_data & M88E1000_PSSR_REV_POLARITY) >>
6859 M88E1000_PSSR_REV_POLARITY_SHIFT;
6860 } else if (hw->phy_type == e1000_phy_igp ||
6861 hw->phy_type == e1000_phy_igp_3 ||
6862 hw->phy_type == e1000_phy_igp_2) {
6863 /* Read the Status register to check the speed */
6864 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
6869 /* If speed is 1000 Mbps, must read the IGP01E1000_PHY_PCS_INIT_REG to
6870 * find the polarity status */
6871 if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
6872 IGP01E1000_PSSR_SPEED_1000MBPS) {
6874 /* Read the GIG initialization PCS register (0x00B4) */
6875 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG,
6880 /* Check the polarity bits */
6881 *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ? 1 : 0;
6883 /* For 10 Mbps, read the polarity bit in the status register. (for
6884 * 100 Mbps this bit is always 0) */
6885 *polarity = phy_data & IGP01E1000_PSSR_POLARITY_REVERSED;
6887 } else if (hw->phy_type == e1000_phy_ife) {
6888 ret_val = e1000_read_phy_reg(hw, IFE_PHY_EXTENDED_STATUS_CONTROL,
6892 *polarity = (phy_data & IFE_PESC_POLARITY_REVERSED) >>
6893 IFE_PESC_POLARITY_REVERSED_SHIFT;
6895 return E1000_SUCCESS;
6898 /******************************************************************************
6899 * Check if Downshift occured
6901 * hw - Struct containing variables accessed by shared code
6902 * downshift - output parameter : 0 - No Downshift ocured.
6903 * 1 - Downshift ocured.
6905 * returns: - E1000_ERR_XXX
6908 * For phy's older then IGP, this function reads the Downshift bit in the Phy
6909 * Specific Status register. For IGP phy's, it reads the Downgrade bit in the
6910 * Link Health register. In IGP this bit is latched high, so the driver must
6911 * read it immediately after link is established.
6912 *****************************************************************************/
6914 e1000_check_downshift(struct e1000_hw *hw)
6919 DEBUGFUNC("e1000_check_downshift");
6921 if (hw->phy_type == e1000_phy_igp ||
6922 hw->phy_type == e1000_phy_igp_3 ||
6923 hw->phy_type == e1000_phy_igp_2) {
6924 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH,
6929 hw->speed_downgraded = (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0;
6930 } else if ((hw->phy_type == e1000_phy_m88) ||
6931 (hw->phy_type == e1000_phy_gg82563)) {
6932 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6937 hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >>
6938 M88E1000_PSSR_DOWNSHIFT_SHIFT;
6939 } else if (hw->phy_type == e1000_phy_ife) {
6940 /* e1000_phy_ife supports 10/100 speed only */
6941 hw->speed_downgraded = FALSE;
6944 return E1000_SUCCESS;
6947 /*****************************************************************************
6949 * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a
6950 * gigabit link is achieved to improve link quality.
6952 * hw: Struct containing variables accessed by shared code
6954 * returns: - E1000_ERR_PHY if fail to read/write the PHY
6955 * E1000_SUCCESS at any other case.
6957 ****************************************************************************/
6960 e1000_config_dsp_after_link_change(struct e1000_hw *hw,
6964 uint16_t phy_data, phy_saved_data, speed, duplex, i;
6965 uint16_t dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
6966 {IGP01E1000_PHY_AGC_PARAM_A,
6967 IGP01E1000_PHY_AGC_PARAM_B,
6968 IGP01E1000_PHY_AGC_PARAM_C,
6969 IGP01E1000_PHY_AGC_PARAM_D};
6970 uint16_t min_length, max_length;
6972 DEBUGFUNC("e1000_config_dsp_after_link_change");
6974 if(hw->phy_type != e1000_phy_igp)
6975 return E1000_SUCCESS;
6978 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
6980 DEBUGOUT("Error getting link speed and duplex\n");
6984 if(speed == SPEED_1000) {
6986 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
6990 if((hw->dsp_config_state == e1000_dsp_config_enabled) &&
6991 min_length >= e1000_igp_cable_length_50) {
6993 for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
6994 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i],
6999 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
7001 ret_val = e1000_write_phy_reg(hw, dsp_reg_array[i],
7006 hw->dsp_config_state = e1000_dsp_config_activated;
7009 if((hw->ffe_config_state == e1000_ffe_config_enabled) &&
7010 (min_length < e1000_igp_cable_length_50)) {
7012 uint16_t ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_20;
7013 uint32_t idle_errs = 0;
7015 /* clear previous idle error counts */
7016 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
7021 for(i = 0; i < ffe_idle_err_timeout; i++) {
7023 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
7028 idle_errs += (phy_data & SR_1000T_IDLE_ERROR_CNT);
7029 if(idle_errs > SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT) {
7030 hw->ffe_config_state = e1000_ffe_config_active;
7032 ret_val = e1000_write_phy_reg(hw,
7033 IGP01E1000_PHY_DSP_FFE,
7034 IGP01E1000_PHY_DSP_FFE_CM_CP);
7041 ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_100;
7046 if(hw->dsp_config_state == e1000_dsp_config_activated) {
7047 /* Save off the current value of register 0x2F5B to be restored at
7048 * the end of the routines. */
7049 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
7054 /* Disable the PHY transmitter */
7055 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
7062 ret_val = e1000_write_phy_reg(hw, 0x0000,
7063 IGP01E1000_IEEE_FORCE_GIGA);
7066 for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
7067 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i], &phy_data);
7071 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
7072 phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS;
7074 ret_val = e1000_write_phy_reg(hw,dsp_reg_array[i], phy_data);
7079 ret_val = e1000_write_phy_reg(hw, 0x0000,
7080 IGP01E1000_IEEE_RESTART_AUTONEG);
7086 /* Now enable the transmitter */
7087 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
7092 hw->dsp_config_state = e1000_dsp_config_enabled;
7095 if(hw->ffe_config_state == e1000_ffe_config_active) {
7096 /* Save off the current value of register 0x2F5B to be restored at
7097 * the end of the routines. */
7098 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
7103 /* Disable the PHY transmitter */
7104 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
7111 ret_val = e1000_write_phy_reg(hw, 0x0000,
7112 IGP01E1000_IEEE_FORCE_GIGA);
7115 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE,
7116 IGP01E1000_PHY_DSP_FFE_DEFAULT);
7120 ret_val = e1000_write_phy_reg(hw, 0x0000,
7121 IGP01E1000_IEEE_RESTART_AUTONEG);
7127 /* Now enable the transmitter */
7128 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
7133 hw->ffe_config_state = e1000_ffe_config_enabled;
7136 return E1000_SUCCESS;
7139 /*****************************************************************************
7140 * Set PHY to class A mode
7141 * Assumes the following operations will follow to enable the new class mode.
7142 * 1. Do a PHY soft reset
7143 * 2. Restart auto-negotiation or force link.
7145 * hw - Struct containing variables accessed by shared code
7146 ****************************************************************************/
7148 e1000_set_phy_mode(struct e1000_hw *hw)
7151 uint16_t eeprom_data;
7153 DEBUGFUNC("e1000_set_phy_mode");
7155 if((hw->mac_type == e1000_82545_rev_3) &&
7156 (hw->media_type == e1000_media_type_copper)) {
7157 ret_val = e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, 1, &eeprom_data);
7162 if((eeprom_data != EEPROM_RESERVED_WORD) &&
7163 (eeprom_data & EEPROM_PHY_CLASS_A)) {
7164 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x000B);
7167 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x8104);
7171 hw->phy_reset_disable = FALSE;
7175 return E1000_SUCCESS;
7178 /*****************************************************************************
7180 * This function sets the lplu state according to the active flag. When
7181 * activating lplu this function also disables smart speed and vise versa.
7182 * lplu will not be activated unless the device autonegotiation advertisment
7183 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
7184 * hw: Struct containing variables accessed by shared code
7185 * active - true to enable lplu false to disable lplu.
7187 * returns: - E1000_ERR_PHY if fail to read/write the PHY
7188 * E1000_SUCCESS at any other case.
7190 ****************************************************************************/
7193 e1000_set_d3_lplu_state(struct e1000_hw *hw,
7196 uint32_t phy_ctrl = 0;
7199 DEBUGFUNC("e1000_set_d3_lplu_state");
7201 if (hw->phy_type != e1000_phy_igp && hw->phy_type != e1000_phy_igp_2
7202 && hw->phy_type != e1000_phy_igp_3)
7203 return E1000_SUCCESS;
7205 /* During driver activity LPLU should not be used or it will attain link
7206 * from the lowest speeds starting from 10Mbps. The capability is used for
7207 * Dx transitions and states */
7208 if (hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2) {
7209 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data);
7212 } else if (hw->mac_type == e1000_ich8lan) {
7213 /* MAC writes into PHY register based on the state transition
7214 * and start auto-negotiation. SW driver can overwrite the settings
7215 * in CSR PHY power control E1000_PHY_CTRL register. */
7216 phy_ctrl = E1000_READ_REG(hw, PHY_CTRL);
7218 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
7224 if(hw->mac_type == e1000_82541_rev_2 ||
7225 hw->mac_type == e1000_82547_rev_2) {
7226 phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
7227 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
7231 if (hw->mac_type == e1000_ich8lan) {
7232 phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
7233 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7235 phy_data &= ~IGP02E1000_PM_D3_LPLU;
7236 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
7243 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
7244 * Dx states where the power conservation is most important. During
7245 * driver activity we should enable SmartSpeed, so performance is
7247 if (hw->smart_speed == e1000_smart_speed_on) {
7248 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7253 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
7254 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7258 } else if (hw->smart_speed == e1000_smart_speed_off) {
7259 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7264 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7265 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7271 } else if((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT) ||
7272 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL ) ||
7273 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) {
7275 if(hw->mac_type == e1000_82541_rev_2 ||
7276 hw->mac_type == e1000_82547_rev_2) {
7277 phy_data |= IGP01E1000_GMII_FLEX_SPD;
7278 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
7282 if (hw->mac_type == e1000_ich8lan) {
7283 phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
7284 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7286 phy_data |= IGP02E1000_PM_D3_LPLU;
7287 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
7294 /* When LPLU is enabled we should disable SmartSpeed */
7295 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
7299 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7300 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
7305 return E1000_SUCCESS;
7308 /*****************************************************************************
7310 * This function sets the lplu d0 state according to the active flag. When
7311 * activating lplu this function also disables smart speed and vise versa.
7312 * lplu will not be activated unless the device autonegotiation advertisment
7313 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
7314 * hw: Struct containing variables accessed by shared code
7315 * active - true to enable lplu false to disable lplu.
7317 * returns: - E1000_ERR_PHY if fail to read/write the PHY
7318 * E1000_SUCCESS at any other case.
7320 ****************************************************************************/
7323 e1000_set_d0_lplu_state(struct e1000_hw *hw,
7326 uint32_t phy_ctrl = 0;
7329 DEBUGFUNC("e1000_set_d0_lplu_state");
7331 if(hw->mac_type <= e1000_82547_rev_2)
7332 return E1000_SUCCESS;
7334 if (hw->mac_type == e1000_ich8lan) {
7335 phy_ctrl = E1000_READ_REG(hw, PHY_CTRL);
7337 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
7343 if (hw->mac_type == e1000_ich8lan) {
7344 phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
7345 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7347 phy_data &= ~IGP02E1000_PM_D0_LPLU;
7348 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
7353 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
7354 * Dx states where the power conservation is most important. During
7355 * driver activity we should enable SmartSpeed, so performance is
7357 if (hw->smart_speed == e1000_smart_speed_on) {
7358 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7363 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
7364 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7368 } else if (hw->smart_speed == e1000_smart_speed_off) {
7369 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7374 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7375 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7384 if (hw->mac_type == e1000_ich8lan) {
7385 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
7386 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7388 phy_data |= IGP02E1000_PM_D0_LPLU;
7389 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
7394 /* When LPLU is enabled we should disable SmartSpeed */
7395 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
7399 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7400 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
7405 return E1000_SUCCESS;
7408 /******************************************************************************
7409 * Change VCO speed register to improve Bit Error Rate performance of SERDES.
7411 * hw - Struct containing variables accessed by shared code
7412 *****************************************************************************/
7414 e1000_set_vco_speed(struct e1000_hw *hw)
7417 uint16_t default_page = 0;
7420 DEBUGFUNC("e1000_set_vco_speed");
7422 switch(hw->mac_type) {
7423 case e1000_82545_rev_3:
7424 case e1000_82546_rev_3:
7427 return E1000_SUCCESS;
7430 /* Set PHY register 30, page 5, bit 8 to 0 */
7432 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, &default_page);
7436 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005);
7440 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
7444 phy_data &= ~M88E1000_PHY_VCO_REG_BIT8;
7445 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
7449 /* Set PHY register 30, page 4, bit 11 to 1 */
7451 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004);
7455 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
7459 phy_data |= M88E1000_PHY_VCO_REG_BIT11;
7460 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
7464 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, default_page);
7468 return E1000_SUCCESS;
7472 /*****************************************************************************
7473 * This function reads the cookie from ARC ram.
7475 * returns: - E1000_SUCCESS .
7476 ****************************************************************************/
7478 e1000_host_if_read_cookie(struct e1000_hw * hw, uint8_t *buffer)
7481 uint32_t offset = E1000_MNG_DHCP_COOKIE_OFFSET;
7482 uint8_t length = E1000_MNG_DHCP_COOKIE_LENGTH;
7484 length = (length >> 2);
7485 offset = (offset >> 2);
7487 for (i = 0; i < length; i++) {
7488 *((uint32_t *) buffer + i) =
7489 E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset + i);
7491 return E1000_SUCCESS;
7495 /*****************************************************************************
7496 * This function checks whether the HOST IF is enabled for command operaton
7497 * and also checks whether the previous command is completed.
7498 * It busy waits in case of previous command is not completed.
7500 * returns: - E1000_ERR_HOST_INTERFACE_COMMAND in case if is not ready or
7502 * - E1000_SUCCESS for success.
7503 ****************************************************************************/
7505 e1000_mng_enable_host_if(struct e1000_hw * hw)
7510 /* Check that the host interface is enabled. */
7511 hicr = E1000_READ_REG(hw, HICR);
7512 if ((hicr & E1000_HICR_EN) == 0) {
7513 DEBUGOUT("E1000_HOST_EN bit disabled.\n");
7514 return -E1000_ERR_HOST_INTERFACE_COMMAND;
7516 /* check the previous command is completed */
7517 for (i = 0; i < E1000_MNG_DHCP_COMMAND_TIMEOUT; i++) {
7518 hicr = E1000_READ_REG(hw, HICR);
7519 if (!(hicr & E1000_HICR_C))
7524 if (i == E1000_MNG_DHCP_COMMAND_TIMEOUT) {
7525 DEBUGOUT("Previous command timeout failed .\n");
7526 return -E1000_ERR_HOST_INTERFACE_COMMAND;
7528 return E1000_SUCCESS;
7531 /*****************************************************************************
7532 * This function writes the buffer content at the offset given on the host if.
7533 * It also does alignment considerations to do the writes in most efficient way.
7534 * Also fills up the sum of the buffer in *buffer parameter.
7536 * returns - E1000_SUCCESS for success.
7537 ****************************************************************************/
7539 e1000_mng_host_if_write(struct e1000_hw * hw, uint8_t *buffer,
7540 uint16_t length, uint16_t offset, uint8_t *sum)
7543 uint8_t *bufptr = buffer;
7545 uint16_t remaining, i, j, prev_bytes;
7547 /* sum = only sum of the data and it is not checksum */
7549 if (length == 0 || offset + length > E1000_HI_MAX_MNG_DATA_LENGTH) {
7550 return -E1000_ERR_PARAM;
7553 tmp = (uint8_t *)&data;
7554 prev_bytes = offset & 0x3;
7559 data = E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset);
7560 for (j = prev_bytes; j < sizeof(uint32_t); j++) {
7561 *(tmp + j) = *bufptr++;
7564 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset, data);
7565 length -= j - prev_bytes;
7569 remaining = length & 0x3;
7570 length -= remaining;
7572 /* Calculate length in DWORDs */
7575 /* The device driver writes the relevant command block into the
7577 for (i = 0; i < length; i++) {
7578 for (j = 0; j < sizeof(uint32_t); j++) {
7579 *(tmp + j) = *bufptr++;
7583 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data);
7586 for (j = 0; j < sizeof(uint32_t); j++) {
7588 *(tmp + j) = *bufptr++;
7594 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data);
7597 return E1000_SUCCESS;
7601 /*****************************************************************************
7602 * This function writes the command header after does the checksum calculation.
7604 * returns - E1000_SUCCESS for success.
7605 ****************************************************************************/
7607 e1000_mng_write_cmd_header(struct e1000_hw * hw,
7608 struct e1000_host_mng_command_header * hdr)
7614 /* Write the whole command header structure which includes sum of
7617 uint16_t length = sizeof(struct e1000_host_mng_command_header);
7619 sum = hdr->checksum;
7622 buffer = (uint8_t *) hdr;
7627 hdr->checksum = 0 - sum;
7630 /* The device driver writes the relevant command block into the ram area. */
7631 for (i = 0; i < length; i++) {
7632 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, i, *((uint32_t *) hdr + i));
7633 E1000_WRITE_FLUSH(hw);
7636 return E1000_SUCCESS;
7640 /*****************************************************************************
7641 * This function indicates to ARC that a new command is pending which completes
7642 * one write operation by the driver.
7644 * returns - E1000_SUCCESS for success.
7645 ****************************************************************************/
7647 e1000_mng_write_commit(
7648 struct e1000_hw * hw)
7652 hicr = E1000_READ_REG(hw, HICR);
7653 /* Setting this bit tells the ARC that a new command is pending. */
7654 E1000_WRITE_REG(hw, HICR, hicr | E1000_HICR_C);
7656 return E1000_SUCCESS;
7660 /*****************************************************************************
7661 * This function checks the mode of the firmware.
7663 * returns - TRUE when the mode is IAMT or FALSE.
7664 ****************************************************************************/
7666 e1000_check_mng_mode(struct e1000_hw *hw)
7670 fwsm = E1000_READ_REG(hw, FWSM);
7672 if (hw->mac_type == e1000_ich8lan) {
7673 if ((fwsm & E1000_FWSM_MODE_MASK) ==
7674 (E1000_MNG_ICH_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
7676 } else if ((fwsm & E1000_FWSM_MODE_MASK) ==
7677 (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
7684 /*****************************************************************************
7685 * This function writes the dhcp info .
7686 ****************************************************************************/
7688 e1000_mng_write_dhcp_info(struct e1000_hw * hw, uint8_t *buffer,
7692 struct e1000_host_mng_command_header hdr;
7694 hdr.command_id = E1000_MNG_DHCP_TX_PAYLOAD_CMD;
7695 hdr.command_length = length;
7700 ret_val = e1000_mng_enable_host_if(hw);
7701 if (ret_val == E1000_SUCCESS) {
7702 ret_val = e1000_mng_host_if_write(hw, buffer, length, sizeof(hdr),
7704 if (ret_val == E1000_SUCCESS) {
7705 ret_val = e1000_mng_write_cmd_header(hw, &hdr);
7706 if (ret_val == E1000_SUCCESS)
7707 ret_val = e1000_mng_write_commit(hw);
7714 /*****************************************************************************
7715 * This function calculates the checksum.
7717 * returns - checksum of buffer contents.
7718 ****************************************************************************/
7720 e1000_calculate_mng_checksum(char *buffer, uint32_t length)
7728 for (i=0; i < length; i++)
7731 return (uint8_t) (0 - sum);
7734 /*****************************************************************************
7735 * This function checks whether tx pkt filtering needs to be enabled or not.
7737 * returns - TRUE for packet filtering or FALSE.
7738 ****************************************************************************/
7740 e1000_enable_tx_pkt_filtering(struct e1000_hw *hw)
7742 /* called in init as well as watchdog timer functions */
7744 int32_t ret_val, checksum;
7745 boolean_t tx_filter = FALSE;
7746 struct e1000_host_mng_dhcp_cookie *hdr = &(hw->mng_cookie);
7747 uint8_t *buffer = (uint8_t *) &(hw->mng_cookie);
7749 if (e1000_check_mng_mode(hw)) {
7750 ret_val = e1000_mng_enable_host_if(hw);
7751 if (ret_val == E1000_SUCCESS) {
7752 ret_val = e1000_host_if_read_cookie(hw, buffer);
7753 if (ret_val == E1000_SUCCESS) {
7754 checksum = hdr->checksum;
7756 if ((hdr->signature == E1000_IAMT_SIGNATURE) &&
7757 checksum == e1000_calculate_mng_checksum((char *)buffer,
7758 E1000_MNG_DHCP_COOKIE_LENGTH)) {
7760 E1000_MNG_DHCP_COOKIE_STATUS_PARSING_SUPPORT)
7769 hw->tx_pkt_filtering = tx_filter;
7773 /******************************************************************************
7774 * Verifies the hardware needs to allow ARPs to be processed by the host
7776 * hw - Struct containing variables accessed by shared code
7778 * returns: - TRUE/FALSE
7780 *****************************************************************************/
7782 e1000_enable_mng_pass_thru(struct e1000_hw *hw)
7785 uint32_t fwsm, factps;
7787 if (hw->asf_firmware_present) {
7788 manc = E1000_READ_REG(hw, MANC);
7790 if (!(manc & E1000_MANC_RCV_TCO_EN) ||
7791 !(manc & E1000_MANC_EN_MAC_ADDR_FILTER))
7793 if (e1000_arc_subsystem_valid(hw) == TRUE) {
7794 fwsm = E1000_READ_REG(hw, FWSM);
7795 factps = E1000_READ_REG(hw, FACTPS);
7797 if (((fwsm & E1000_FWSM_MODE_MASK) ==
7798 (e1000_mng_mode_pt << E1000_FWSM_MODE_SHIFT)) &&
7799 (factps & E1000_FACTPS_MNGCG))
7802 if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN))
7809 e1000_polarity_reversal_workaround(struct e1000_hw *hw)
7812 uint16_t mii_status_reg;
7815 /* Polarity reversal workaround for forced 10F/10H links. */
7817 /* Disable the transmitter on the PHY */
7819 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
7822 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF);
7826 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
7830 /* This loop will early-out if the NO link condition has been met. */
7831 for(i = PHY_FORCE_TIME; i > 0; i--) {
7832 /* Read the MII Status Register and wait for Link Status bit
7836 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
7840 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
7844 if((mii_status_reg & ~MII_SR_LINK_STATUS) == 0) break;
7845 msec_delay_irq(100);
7848 /* Recommended delay time after link has been lost */
7849 msec_delay_irq(1000);
7851 /* Now we will re-enable th transmitter on the PHY */
7853 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
7857 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0);
7861 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00);
7865 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000);
7869 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
7873 /* This loop will early-out if the link condition has been met. */
7874 for(i = PHY_FORCE_TIME; i > 0; i--) {
7875 /* Read the MII Status Register and wait for Link Status bit
7879 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
7883 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
7887 if(mii_status_reg & MII_SR_LINK_STATUS) break;
7888 msec_delay_irq(100);
7890 return E1000_SUCCESS;
7893 /***************************************************************************
7895 * Disables PCI-Express master access.
7897 * hw: Struct containing variables accessed by shared code
7901 ***************************************************************************/
7903 e1000_set_pci_express_master_disable(struct e1000_hw *hw)
7907 DEBUGFUNC("e1000_set_pci_express_master_disable");
7909 if (hw->bus_type != e1000_bus_type_pci_express)
7912 ctrl = E1000_READ_REG(hw, CTRL);
7913 ctrl |= E1000_CTRL_GIO_MASTER_DISABLE;
7914 E1000_WRITE_REG(hw, CTRL, ctrl);
7917 /***************************************************************************
7919 * Enables PCI-Express master access.
7921 * hw: Struct containing variables accessed by shared code
7925 ***************************************************************************/
7927 e1000_enable_pciex_master(struct e1000_hw *hw)
7931 DEBUGFUNC("e1000_enable_pciex_master");
7933 if (hw->bus_type != e1000_bus_type_pci_express)
7936 ctrl = E1000_READ_REG(hw, CTRL);
7937 ctrl &= ~E1000_CTRL_GIO_MASTER_DISABLE;
7938 E1000_WRITE_REG(hw, CTRL, ctrl);
7941 /*******************************************************************************
7943 * Disables PCI-Express master access and verifies there are no pending requests
7945 * hw: Struct containing variables accessed by shared code
7947 * returns: - E1000_ERR_MASTER_REQUESTS_PENDING if master disable bit hasn't
7948 * caused the master requests to be disabled.
7949 * E1000_SUCCESS master requests disabled.
7951 ******************************************************************************/
7953 e1000_disable_pciex_master(struct e1000_hw *hw)
7955 int32_t timeout = MASTER_DISABLE_TIMEOUT; /* 80ms */
7957 DEBUGFUNC("e1000_disable_pciex_master");
7959 if (hw->bus_type != e1000_bus_type_pci_express)
7960 return E1000_SUCCESS;
7962 e1000_set_pci_express_master_disable(hw);
7965 if(!(E1000_READ_REG(hw, STATUS) & E1000_STATUS_GIO_MASTER_ENABLE))
7973 DEBUGOUT("Master requests are pending.\n");
7974 return -E1000_ERR_MASTER_REQUESTS_PENDING;
7977 return E1000_SUCCESS;
7980 /*******************************************************************************
7982 * Check for EEPROM Auto Read bit done.
7984 * hw: Struct containing variables accessed by shared code
7986 * returns: - E1000_ERR_RESET if fail to reset MAC
7987 * E1000_SUCCESS at any other case.
7989 ******************************************************************************/
7991 e1000_get_auto_rd_done(struct e1000_hw *hw)
7993 int32_t timeout = AUTO_READ_DONE_TIMEOUT;
7995 DEBUGFUNC("e1000_get_auto_rd_done");
7997 switch (hw->mac_type) {
8004 case e1000_80003es2lan:
8007 if (E1000_READ_REG(hw, EECD) & E1000_EECD_AUTO_RD)
8014 DEBUGOUT("Auto read by HW from EEPROM has not completed.\n");
8015 return -E1000_ERR_RESET;
8020 /* PHY configuration from NVM just starts after EECD_AUTO_RD sets to high.
8021 * Need to wait for PHY configuration completion before accessing NVM
8023 if (hw->mac_type == e1000_82573)
8026 return E1000_SUCCESS;
8029 /***************************************************************************
8030 * Checks if the PHY configuration is done
8032 * hw: Struct containing variables accessed by shared code
8034 * returns: - E1000_ERR_RESET if fail to reset MAC
8035 * E1000_SUCCESS at any other case.
8037 ***************************************************************************/
8039 e1000_get_phy_cfg_done(struct e1000_hw *hw)
8041 int32_t timeout = PHY_CFG_TIMEOUT;
8042 uint32_t cfg_mask = E1000_EEPROM_CFG_DONE;
8044 DEBUGFUNC("e1000_get_phy_cfg_done");
8046 switch (hw->mac_type) {
8050 case e1000_80003es2lan:
8051 /* Separate *_CFG_DONE_* bit for each port */
8052 if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
8053 cfg_mask = E1000_EEPROM_CFG_DONE_PORT_1;
8058 if (E1000_READ_REG(hw, EEMNGCTL) & cfg_mask)
8066 DEBUGOUT("MNG configuration cycle has not completed.\n");
8067 return -E1000_ERR_RESET;
8072 return E1000_SUCCESS;
8075 /***************************************************************************
8077 * Using the combination of SMBI and SWESMBI semaphore bits when resetting
8078 * adapter or Eeprom access.
8080 * hw: Struct containing variables accessed by shared code
8082 * returns: - E1000_ERR_EEPROM if fail to access EEPROM.
8083 * E1000_SUCCESS at any other case.
8085 ***************************************************************************/
8087 e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw)
8092 DEBUGFUNC("e1000_get_hw_eeprom_semaphore");
8094 if(!hw->eeprom_semaphore_present)
8095 return E1000_SUCCESS;
8097 if (hw->mac_type == e1000_80003es2lan) {
8098 /* Get the SW semaphore. */
8099 if (e1000_get_software_semaphore(hw) != E1000_SUCCESS)
8100 return -E1000_ERR_EEPROM;
8103 /* Get the FW semaphore. */
8104 timeout = hw->eeprom.word_size + 1;
8106 swsm = E1000_READ_REG(hw, SWSM);
8107 swsm |= E1000_SWSM_SWESMBI;
8108 E1000_WRITE_REG(hw, SWSM, swsm);
8109 /* if we managed to set the bit we got the semaphore. */
8110 swsm = E1000_READ_REG(hw, SWSM);
8111 if(swsm & E1000_SWSM_SWESMBI)
8119 /* Release semaphores */
8120 e1000_put_hw_eeprom_semaphore(hw);
8121 DEBUGOUT("Driver can't access the Eeprom - SWESMBI bit is set.\n");
8122 return -E1000_ERR_EEPROM;
8125 return E1000_SUCCESS;
8128 /***************************************************************************
8129 * This function clears HW semaphore bits.
8131 * hw: Struct containing variables accessed by shared code
8135 ***************************************************************************/
8137 e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw)
8141 DEBUGFUNC("e1000_put_hw_eeprom_semaphore");
8143 if(!hw->eeprom_semaphore_present)
8146 swsm = E1000_READ_REG(hw, SWSM);
8147 if (hw->mac_type == e1000_80003es2lan) {
8148 /* Release both semaphores. */
8149 swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
8151 swsm &= ~(E1000_SWSM_SWESMBI);
8152 E1000_WRITE_REG(hw, SWSM, swsm);
8155 /***************************************************************************
8157 * Obtaining software semaphore bit (SMBI) before resetting PHY.
8159 * hw: Struct containing variables accessed by shared code
8161 * returns: - E1000_ERR_RESET if fail to obtain semaphore.
8162 * E1000_SUCCESS at any other case.
8164 ***************************************************************************/
8166 e1000_get_software_semaphore(struct e1000_hw *hw)
8168 int32_t timeout = hw->eeprom.word_size + 1;
8171 DEBUGFUNC("e1000_get_software_semaphore");
8173 if (hw->mac_type != e1000_80003es2lan)
8174 return E1000_SUCCESS;
8177 swsm = E1000_READ_REG(hw, SWSM);
8178 /* If SMBI bit cleared, it is now set and we hold the semaphore */
8179 if(!(swsm & E1000_SWSM_SMBI))
8186 DEBUGOUT("Driver can't access device - SMBI bit is set.\n");
8187 return -E1000_ERR_RESET;
8190 return E1000_SUCCESS;
8193 /***************************************************************************
8195 * Release semaphore bit (SMBI).
8197 * hw: Struct containing variables accessed by shared code
8199 ***************************************************************************/
8201 e1000_release_software_semaphore(struct e1000_hw *hw)
8205 DEBUGFUNC("e1000_release_software_semaphore");
8207 if (hw->mac_type != e1000_80003es2lan)
8210 swsm = E1000_READ_REG(hw, SWSM);
8211 /* Release the SW semaphores.*/
8212 swsm &= ~E1000_SWSM_SMBI;
8213 E1000_WRITE_REG(hw, SWSM, swsm);
8216 /******************************************************************************
8217 * Checks if PHY reset is blocked due to SOL/IDER session, for example.
8218 * Returning E1000_BLK_PHY_RESET isn't necessarily an error. But it's up to
8219 * the caller to figure out how to deal with it.
8221 * hw - Struct containing variables accessed by shared code
8223 * returns: - E1000_BLK_PHY_RESET
8226 *****************************************************************************/
8228 e1000_check_phy_reset_block(struct e1000_hw *hw)
8233 if (hw->mac_type == e1000_ich8lan) {
8234 fwsm = E1000_READ_REG(hw, FWSM);
8235 return (fwsm & E1000_FWSM_RSPCIPHY) ? E1000_SUCCESS
8236 : E1000_BLK_PHY_RESET;
8239 if (hw->mac_type > e1000_82547_rev_2)
8240 manc = E1000_READ_REG(hw, MANC);
8241 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
8242 E1000_BLK_PHY_RESET : E1000_SUCCESS;
8246 e1000_arc_subsystem_valid(struct e1000_hw *hw)
8250 /* On 8257x silicon, registers in the range of 0x8800 - 0x8FFC
8251 * may not be provided a DMA clock when no manageability features are
8252 * enabled. We do not want to perform any reads/writes to these registers
8253 * if this is the case. We read FWSM to determine the manageability mode.
8255 switch (hw->mac_type) {
8259 case e1000_80003es2lan:
8260 fwsm = E1000_READ_REG(hw, FWSM);
8261 if((fwsm & E1000_FWSM_MODE_MASK) != 0)
8273 /******************************************************************************
8274 * Configure PCI-Ex no-snoop
8276 * hw - Struct containing variables accessed by shared code.
8277 * no_snoop - Bitmap of no-snoop events.
8279 * returns: E1000_SUCCESS
8281 *****************************************************************************/
8283 e1000_set_pci_ex_no_snoop(struct e1000_hw *hw, uint32_t no_snoop)
8285 uint32_t gcr_reg = 0;
8287 DEBUGFUNC("e1000_set_pci_ex_no_snoop");
8289 if (hw->bus_type == e1000_bus_type_unknown)
8290 e1000_get_bus_info(hw);
8292 if (hw->bus_type != e1000_bus_type_pci_express)
8293 return E1000_SUCCESS;
8296 gcr_reg = E1000_READ_REG(hw, GCR);
8297 gcr_reg &= ~(PCI_EX_NO_SNOOP_ALL);
8298 gcr_reg |= no_snoop;
8299 E1000_WRITE_REG(hw, GCR, gcr_reg);
8301 if (hw->mac_type == e1000_ich8lan) {
8304 E1000_WRITE_REG(hw, GCR, PCI_EX_82566_SNOOP_ALL);
8306 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
8307 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
8308 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
8311 return E1000_SUCCESS;
8314 /***************************************************************************
8316 * Get software semaphore FLAG bit (SWFLAG).
8317 * SWFLAG is used to synchronize the access to all shared resource between
8320 * hw: Struct containing variables accessed by shared code
8322 ***************************************************************************/
8324 e1000_get_software_flag(struct e1000_hw *hw)
8326 int32_t timeout = PHY_CFG_TIMEOUT;
8327 uint32_t extcnf_ctrl;
8329 DEBUGFUNC("e1000_get_software_flag");
8331 if (hw->mac_type == e1000_ich8lan) {
8333 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
8334 extcnf_ctrl |= E1000_EXTCNF_CTRL_SWFLAG;
8335 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
8337 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
8338 if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG)
8345 DEBUGOUT("FW or HW locks the resource too long.\n");
8346 return -E1000_ERR_CONFIG;
8350 return E1000_SUCCESS;
8353 /***************************************************************************
8355 * Release software semaphore FLAG bit (SWFLAG).
8356 * SWFLAG is used to synchronize the access to all shared resource between
8359 * hw: Struct containing variables accessed by shared code
8361 ***************************************************************************/
8363 e1000_release_software_flag(struct e1000_hw *hw)
8365 uint32_t extcnf_ctrl;
8367 DEBUGFUNC("e1000_release_software_flag");
8369 if (hw->mac_type == e1000_ich8lan) {
8370 extcnf_ctrl= E1000_READ_REG(hw, EXTCNF_CTRL);
8371 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
8372 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
8378 /***************************************************************************
8380 * Disable dynamic power down mode in ife PHY.
8381 * It can be used to workaround band-gap problem.
8383 * hw: Struct containing variables accessed by shared code
8385 ***************************************************************************/
8387 e1000_ife_disable_dynamic_power_down(struct e1000_hw *hw)
8390 int32_t ret_val = E1000_SUCCESS;
8392 DEBUGFUNC("e1000_ife_disable_dynamic_power_down");
8394 if (hw->phy_type == e1000_phy_ife) {
8395 ret_val = e1000_read_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL, &phy_data);
8399 phy_data |= IFE_PSC_DISABLE_DYNAMIC_POWER_DOWN;
8400 ret_val = e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL, phy_data);
8406 /***************************************************************************
8408 * Enable dynamic power down mode in ife PHY.
8409 * It can be used to workaround band-gap problem.
8411 * hw: Struct containing variables accessed by shared code
8413 ***************************************************************************/
8415 e1000_ife_enable_dynamic_power_down(struct e1000_hw *hw)
8418 int32_t ret_val = E1000_SUCCESS;
8420 DEBUGFUNC("e1000_ife_enable_dynamic_power_down");
8422 if (hw->phy_type == e1000_phy_ife) {
8423 ret_val = e1000_read_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL, &phy_data);
8427 phy_data &= ~IFE_PSC_DISABLE_DYNAMIC_POWER_DOWN;
8428 ret_val = e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL, phy_data);
8434 /******************************************************************************
8435 * Reads a 16 bit word or words from the EEPROM using the ICH8's flash access
8438 * hw - Struct containing variables accessed by shared code
8439 * offset - offset of word in the EEPROM to read
8440 * data - word read from the EEPROM
8441 * words - number of words to read
8442 *****************************************************************************/
8444 e1000_read_eeprom_ich8(struct e1000_hw *hw, uint16_t offset, uint16_t words,
8447 int32_t error = E1000_SUCCESS;
8448 uint32_t flash_bank = 0;
8449 uint32_t act_offset = 0;
8450 uint32_t bank_offset = 0;
8454 /* We need to know which is the valid flash bank. In the event
8455 * that we didn't allocate eeprom_shadow_ram, we may not be
8456 * managing flash_bank. So it cannot be trusted and needs
8457 * to be updated with each read.
8459 /* Value of bit 22 corresponds to the flash bank we're on. */
8460 flash_bank = (E1000_READ_REG(hw, EECD) & E1000_EECD_SEC1VAL) ? 1 : 0;
8462 /* Adjust offset appropriately if we're on bank 1 - adjust for word size */
8463 bank_offset = flash_bank * (hw->flash_bank_size * 2);
8465 error = e1000_get_software_flag(hw);
8466 if (error != E1000_SUCCESS)
8469 for (i = 0; i < words; i++) {
8470 if (hw->eeprom_shadow_ram != NULL &&
8471 hw->eeprom_shadow_ram[offset+i].modified == TRUE) {
8472 data[i] = hw->eeprom_shadow_ram[offset+i].eeprom_word;
8474 /* The NVM part needs a byte offset, hence * 2 */
8475 act_offset = bank_offset + ((offset + i) * 2);
8476 error = e1000_read_ich8_word(hw, act_offset, &word);
8477 if (error != E1000_SUCCESS)
8483 e1000_release_software_flag(hw);
8488 /******************************************************************************
8489 * Writes a 16 bit word or words to the EEPROM using the ICH8's flash access
8490 * register. Actually, writes are written to the shadow ram cache in the hw
8491 * structure hw->e1000_shadow_ram. e1000_commit_shadow_ram flushes this to
8492 * the NVM, which occurs when the NVM checksum is updated.
8494 * hw - Struct containing variables accessed by shared code
8495 * offset - offset of word in the EEPROM to write
8496 * words - number of words to write
8497 * data - words to write to the EEPROM
8498 *****************************************************************************/
8500 e1000_write_eeprom_ich8(struct e1000_hw *hw, uint16_t offset, uint16_t words,
8504 int32_t error = E1000_SUCCESS;
8506 error = e1000_get_software_flag(hw);
8507 if (error != E1000_SUCCESS)
8510 /* A driver can write to the NVM only if it has eeprom_shadow_ram
8511 * allocated. Subsequent reads to the modified words are read from
8512 * this cached structure as well. Writes will only go into this
8513 * cached structure unless it's followed by a call to
8514 * e1000_update_eeprom_checksum() where it will commit the changes
8515 * and clear the "modified" field.
8517 if (hw->eeprom_shadow_ram != NULL) {
8518 for (i = 0; i < words; i++) {
8519 if ((offset + i) < E1000_SHADOW_RAM_WORDS) {
8520 hw->eeprom_shadow_ram[offset+i].modified = TRUE;
8521 hw->eeprom_shadow_ram[offset+i].eeprom_word = data[i];
8523 error = -E1000_ERR_EEPROM;
8528 /* Drivers have the option to not allocate eeprom_shadow_ram as long
8529 * as they don't perform any NVM writes. An attempt in doing so
8530 * will result in this error.
8532 error = -E1000_ERR_EEPROM;
8535 e1000_release_software_flag(hw);
8540 /******************************************************************************
8541 * This function does initial flash setup so that a new read/write/erase cycle
8544 * hw - The pointer to the hw structure
8545 ****************************************************************************/
8547 e1000_ich8_cycle_init(struct e1000_hw *hw)
8549 union ich8_hws_flash_status hsfsts;
8550 int32_t error = E1000_ERR_EEPROM;
8553 DEBUGFUNC("e1000_ich8_cycle_init");
8555 hsfsts.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFSTS);
8557 /* May be check the Flash Des Valid bit in Hw status */
8558 if (hsfsts.hsf_status.fldesvalid == 0) {
8559 DEBUGOUT("Flash descriptor invalid. SW Sequencing must be used.");
8563 /* Clear FCERR in Hw status by writing 1 */
8564 /* Clear DAEL in Hw status by writing a 1 */
8565 hsfsts.hsf_status.flcerr = 1;
8566 hsfsts.hsf_status.dael = 1;
8568 E1000_WRITE_ICH8_REG16(hw, ICH8_FLASH_HSFSTS, hsfsts.regval);
8570 /* Either we should have a hardware SPI cycle in progress bit to check
8571 * against, in order to start a new cycle or FDONE bit should be changed
8572 * in the hardware so that it is 1 after harware reset, which can then be
8573 * used as an indication whether a cycle is in progress or has been
8574 * completed .. we should also have some software semaphore mechanism to
8575 * guard FDONE or the cycle in progress bit so that two threads access to
8576 * those bits can be sequentiallized or a way so that 2 threads dont
8577 * start the cycle at the same time */
8579 if (hsfsts.hsf_status.flcinprog == 0) {
8580 /* There is no cycle running at present, so we can start a cycle */
8581 /* Begin by setting Flash Cycle Done. */
8582 hsfsts.hsf_status.flcdone = 1;
8583 E1000_WRITE_ICH8_REG16(hw, ICH8_FLASH_HSFSTS, hsfsts.regval);
8584 error = E1000_SUCCESS;
8586 /* otherwise poll for sometime so the current cycle has a chance
8587 * to end before giving up. */
8588 for (i = 0; i < ICH8_FLASH_COMMAND_TIMEOUT; i++) {
8589 hsfsts.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFSTS);
8590 if (hsfsts.hsf_status.flcinprog == 0) {
8591 error = E1000_SUCCESS;
8596 if (error == E1000_SUCCESS) {
8597 /* Successful in waiting for previous cycle to timeout,
8598 * now set the Flash Cycle Done. */
8599 hsfsts.hsf_status.flcdone = 1;
8600 E1000_WRITE_ICH8_REG16(hw, ICH8_FLASH_HSFSTS, hsfsts.regval);
8602 DEBUGOUT("Flash controller busy, cannot get access");
8608 /******************************************************************************
8609 * This function starts a flash cycle and waits for its completion
8611 * hw - The pointer to the hw structure
8612 ****************************************************************************/
8614 e1000_ich8_flash_cycle(struct e1000_hw *hw, uint32_t timeout)
8616 union ich8_hws_flash_ctrl hsflctl;
8617 union ich8_hws_flash_status hsfsts;
8618 int32_t error = E1000_ERR_EEPROM;
8621 /* Start a cycle by writing 1 in Flash Cycle Go in Hw Flash Control */
8622 hsflctl.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFCTL);
8623 hsflctl.hsf_ctrl.flcgo = 1;
8624 E1000_WRITE_ICH8_REG16(hw, ICH8_FLASH_HSFCTL, hsflctl.regval);
8626 /* wait till FDONE bit is set to 1 */
8628 hsfsts.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFSTS);
8629 if (hsfsts.hsf_status.flcdone == 1)
8633 } while (i < timeout);
8634 if (hsfsts.hsf_status.flcdone == 1 && hsfsts.hsf_status.flcerr == 0) {
8635 error = E1000_SUCCESS;
8640 /******************************************************************************
8641 * Reads a byte or word from the NVM using the ICH8 flash access registers.
8643 * hw - The pointer to the hw structure
8644 * index - The index of the byte or word to read.
8645 * size - Size of data to read, 1=byte 2=word
8646 * data - Pointer to the word to store the value read.
8647 *****************************************************************************/
8649 e1000_read_ich8_data(struct e1000_hw *hw, uint32_t index,
8650 uint32_t size, uint16_t* data)
8652 union ich8_hws_flash_status hsfsts;
8653 union ich8_hws_flash_ctrl hsflctl;
8654 uint32_t flash_linear_address;
8655 uint32_t flash_data = 0;
8656 int32_t error = -E1000_ERR_EEPROM;
8659 DEBUGFUNC("e1000_read_ich8_data");
8661 if (size < 1 || size > 2 || data == 0x0 ||
8662 index > ICH8_FLASH_LINEAR_ADDR_MASK)
8665 flash_linear_address = (ICH8_FLASH_LINEAR_ADDR_MASK & index) +
8666 hw->flash_base_addr;
8671 error = e1000_ich8_cycle_init(hw);
8672 if (error != E1000_SUCCESS)
8675 hsflctl.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFCTL);
8676 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
8677 hsflctl.hsf_ctrl.fldbcount = size - 1;
8678 hsflctl.hsf_ctrl.flcycle = ICH8_CYCLE_READ;
8679 E1000_WRITE_ICH8_REG16(hw, ICH8_FLASH_HSFCTL, hsflctl.regval);
8681 /* Write the last 24 bits of index into Flash Linear address field in
8683 /* TODO: TBD maybe check the index against the size of flash */
8685 E1000_WRITE_ICH8_REG(hw, ICH8_FLASH_FADDR, flash_linear_address);
8687 error = e1000_ich8_flash_cycle(hw, ICH8_FLASH_COMMAND_TIMEOUT);
8689 /* Check if FCERR is set to 1, if set to 1, clear it and try the whole
8690 * sequence a few more times, else read in (shift in) the Flash Data0,
8691 * the order is least significant byte first msb to lsb */
8692 if (error == E1000_SUCCESS) {
8693 flash_data = E1000_READ_ICH8_REG(hw, ICH8_FLASH_FDATA0);
8695 *data = (uint8_t)(flash_data & 0x000000FF);
8696 } else if (size == 2) {
8697 *data = (uint16_t)(flash_data & 0x0000FFFF);
8701 /* If we've gotten here, then things are probably completely hosed,
8702 * but if the error condition is detected, it won't hurt to give
8703 * it another try...ICH8_FLASH_CYCLE_REPEAT_COUNT times.
8705 hsfsts.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFSTS);
8706 if (hsfsts.hsf_status.flcerr == 1) {
8707 /* Repeat for some time before giving up. */
8709 } else if (hsfsts.hsf_status.flcdone == 0) {
8710 DEBUGOUT("Timeout error - flash cycle did not complete.");
8714 } while (count++ < ICH8_FLASH_CYCLE_REPEAT_COUNT);
8719 /******************************************************************************
8720 * Writes One /two bytes to the NVM using the ICH8 flash access registers.
8722 * hw - The pointer to the hw structure
8723 * index - The index of the byte/word to read.
8724 * size - Size of data to read, 1=byte 2=word
8725 * data - The byte(s) to write to the NVM.
8726 *****************************************************************************/
8728 e1000_write_ich8_data(struct e1000_hw *hw, uint32_t index, uint32_t size,
8731 union ich8_hws_flash_status hsfsts;
8732 union ich8_hws_flash_ctrl hsflctl;
8733 uint32_t flash_linear_address;
8734 uint32_t flash_data = 0;
8735 int32_t error = -E1000_ERR_EEPROM;
8738 DEBUGFUNC("e1000_write_ich8_data");
8740 if (size < 1 || size > 2 || data > size * 0xff ||
8741 index > ICH8_FLASH_LINEAR_ADDR_MASK)
8744 flash_linear_address = (ICH8_FLASH_LINEAR_ADDR_MASK & index) +
8745 hw->flash_base_addr;
8750 error = e1000_ich8_cycle_init(hw);
8751 if (error != E1000_SUCCESS)
8754 hsflctl.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFCTL);
8755 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
8756 hsflctl.hsf_ctrl.fldbcount = size -1;
8757 hsflctl.hsf_ctrl.flcycle = ICH8_CYCLE_WRITE;
8758 E1000_WRITE_ICH8_REG16(hw, ICH8_FLASH_HSFCTL, hsflctl.regval);
8760 /* Write the last 24 bits of index into Flash Linear address field in
8762 E1000_WRITE_ICH8_REG(hw, ICH8_FLASH_FADDR, flash_linear_address);
8765 flash_data = (uint32_t)data & 0x00FF;
8767 flash_data = (uint32_t)data;
8769 E1000_WRITE_ICH8_REG(hw, ICH8_FLASH_FDATA0, flash_data);
8771 /* check if FCERR is set to 1 , if set to 1, clear it and try the whole
8772 * sequence a few more times else done */
8773 error = e1000_ich8_flash_cycle(hw, ICH8_FLASH_COMMAND_TIMEOUT);
8774 if (error == E1000_SUCCESS) {
8777 /* If we're here, then things are most likely completely hosed,
8778 * but if the error condition is detected, it won't hurt to give
8779 * it another try...ICH8_FLASH_CYCLE_REPEAT_COUNT times.
8781 hsfsts.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFSTS);
8782 if (hsfsts.hsf_status.flcerr == 1) {
8783 /* Repeat for some time before giving up. */
8785 } else if (hsfsts.hsf_status.flcdone == 0) {
8786 DEBUGOUT("Timeout error - flash cycle did not complete.");
8790 } while (count++ < ICH8_FLASH_CYCLE_REPEAT_COUNT);
8795 /******************************************************************************
8796 * Reads a single byte from the NVM using the ICH8 flash access registers.
8798 * hw - pointer to e1000_hw structure
8799 * index - The index of the byte to read.
8800 * data - Pointer to a byte to store the value read.
8801 *****************************************************************************/
8803 e1000_read_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t* data)
8805 int32_t status = E1000_SUCCESS;
8808 status = e1000_read_ich8_data(hw, index, 1, &word);
8809 if (status == E1000_SUCCESS) {
8810 *data = (uint8_t)word;
8816 /******************************************************************************
8817 * Writes a single byte to the NVM using the ICH8 flash access registers.
8818 * Performs verification by reading back the value and then going through
8819 * a retry algorithm before giving up.
8821 * hw - pointer to e1000_hw structure
8822 * index - The index of the byte to write.
8823 * byte - The byte to write to the NVM.
8824 *****************************************************************************/
8826 e1000_verify_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t byte)
8828 int32_t error = E1000_SUCCESS;
8829 int32_t program_retries;
8832 e1000_write_ich8_byte(hw, index, byte);
8835 for (program_retries = 0; program_retries < 100; program_retries++) {
8836 e1000_read_ich8_byte(hw, index, &temp_byte);
8837 if (temp_byte == byte)
8840 e1000_write_ich8_byte(hw, index, byte);
8843 if (program_retries == 100)
8844 error = E1000_ERR_EEPROM;
8849 /******************************************************************************
8850 * Writes a single byte to the NVM using the ICH8 flash access registers.
8852 * hw - pointer to e1000_hw structure
8853 * index - The index of the byte to read.
8854 * data - The byte to write to the NVM.
8855 *****************************************************************************/
8857 e1000_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t data)
8859 int32_t status = E1000_SUCCESS;
8860 uint16_t word = (uint16_t)data;
8862 status = e1000_write_ich8_data(hw, index, 1, word);
8867 /******************************************************************************
8868 * Reads a word from the NVM using the ICH8 flash access registers.
8870 * hw - pointer to e1000_hw structure
8871 * index - The starting byte index of the word to read.
8872 * data - Pointer to a word to store the value read.
8873 *****************************************************************************/
8875 e1000_read_ich8_word(struct e1000_hw *hw, uint32_t index, uint16_t *data)
8877 int32_t status = E1000_SUCCESS;
8878 status = e1000_read_ich8_data(hw, index, 2, data);
8882 /******************************************************************************
8883 * Writes a word to the NVM using the ICH8 flash access registers.
8885 * hw - pointer to e1000_hw structure
8886 * index - The starting byte index of the word to read.
8887 * data - The word to write to the NVM.
8888 *****************************************************************************/
8890 e1000_write_ich8_word(struct e1000_hw *hw, uint32_t index, uint16_t data)
8892 int32_t status = E1000_SUCCESS;
8893 status = e1000_write_ich8_data(hw, index, 2, data);
8897 /******************************************************************************
8898 * Erases the bank specified. Each bank is a 4k block. Segments are 0 based.
8899 * segment N is 4096 * N + flash_reg_addr.
8901 * hw - pointer to e1000_hw structure
8902 * segment - 0 for first segment, 1 for second segment, etc.
8903 *****************************************************************************/
8905 e1000_erase_ich8_4k_segment(struct e1000_hw *hw, uint32_t segment)
8907 union ich8_hws_flash_status hsfsts;
8908 union ich8_hws_flash_ctrl hsflctl;
8909 uint32_t flash_linear_address;
8911 int32_t error = E1000_ERR_EEPROM;
8912 int32_t iteration, seg_size;
8913 int32_t sector_size;
8915 int32_t error_flag = 0;
8917 hsfsts.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFSTS);
8919 /* Determine HW Sector size: Read BERASE bits of Hw flash Status register */
8920 /* 00: The Hw sector is 256 bytes, hence we need to erase 16
8921 * consecutive sectors. The start index for the nth Hw sector can be
8922 * calculated as = segment * 4096 + n * 256
8923 * 01: The Hw sector is 4K bytes, hence we need to erase 1 sector.
8924 * The start index for the nth Hw sector can be calculated
8925 * as = segment * 4096
8926 * 10: Error condition
8927 * 11: The Hw sector size is much bigger than the size asked to
8928 * erase...error condition */
8929 if (hsfsts.hsf_status.berasesz == 0x0) {
8930 /* Hw sector size 256 */
8931 sector_size = seg_size = ICH8_FLASH_SEG_SIZE_256;
8932 iteration = ICH8_FLASH_SECTOR_SIZE / ICH8_FLASH_SEG_SIZE_256;
8933 } else if (hsfsts.hsf_status.berasesz == 0x1) {
8934 sector_size = seg_size = ICH8_FLASH_SEG_SIZE_4K;
8936 } else if (hsfsts.hsf_status.berasesz == 0x3) {
8937 sector_size = seg_size = ICH8_FLASH_SEG_SIZE_64K;
8943 for (j = 0; j < iteration ; j++) {
8947 error = e1000_ich8_cycle_init(hw);
8948 if (error != E1000_SUCCESS) {
8953 /* Write a value 11 (block Erase) in Flash Cycle field in Hw flash
8955 hsflctl.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFCTL);
8956 hsflctl.hsf_ctrl.flcycle = ICH8_CYCLE_ERASE;
8957 E1000_WRITE_ICH8_REG16(hw, ICH8_FLASH_HSFCTL, hsflctl.regval);
8959 /* Write the last 24 bits of an index within the block into Flash
8960 * Linear address field in Flash Address. This probably needs to
8961 * be calculated here based off the on-chip segment size and the
8962 * software segment size assumed (4K) */
8964 flash_linear_address = segment * sector_size + j * seg_size;
8965 flash_linear_address &= ICH8_FLASH_LINEAR_ADDR_MASK;
8966 flash_linear_address += hw->flash_base_addr;
8968 E1000_WRITE_ICH8_REG(hw, ICH8_FLASH_FADDR, flash_linear_address);
8970 error = e1000_ich8_flash_cycle(hw, 1000000);
8971 /* Check if FCERR is set to 1. If 1, clear it and try the whole
8972 * sequence a few more times else Done */
8973 if (error == E1000_SUCCESS) {
8976 hsfsts.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFSTS);
8977 if (hsfsts.hsf_status.flcerr == 1) {
8978 /* repeat for some time before giving up */
8980 } else if (hsfsts.hsf_status.flcdone == 0) {
8985 } while ((count < ICH8_FLASH_CYCLE_REPEAT_COUNT) && !error_flag);
8986 if (error_flag == 1)
8989 if (error_flag != 1)
8990 error = E1000_SUCCESS;
8994 /******************************************************************************
8996 * Reverse duplex setting without breaking the link.
8998 * hw: Struct containing variables accessed by shared code
9000 *****************************************************************************/
9002 e1000_duplex_reversal(struct e1000_hw *hw)
9007 if (hw->phy_type != e1000_phy_igp_3)
9008 return E1000_SUCCESS;
9010 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
9014 phy_data ^= MII_CR_FULL_DUPLEX;
9016 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
9020 ret_val = e1000_read_phy_reg(hw, IGP3E1000_PHY_MISC_CTRL, &phy_data);
9024 phy_data |= IGP3_PHY_MISC_DUPLEX_MANUAL_SET;
9025 ret_val = e1000_write_phy_reg(hw, IGP3E1000_PHY_MISC_CTRL, phy_data);
9031 e1000_init_lcd_from_nvm_config_region(struct e1000_hw *hw,
9032 uint32_t cnf_base_addr, uint32_t cnf_size)
9034 uint32_t ret_val = E1000_SUCCESS;
9035 uint16_t word_addr, reg_data, reg_addr;
9038 /* cnf_base_addr is in DWORD */
9039 word_addr = (uint16_t)(cnf_base_addr << 1);
9041 /* cnf_size is returned in size of dwords */
9042 for (i = 0; i < cnf_size; i++) {
9043 ret_val = e1000_read_eeprom(hw, (word_addr + i*2), 1, ®_data);
9047 ret_val = e1000_read_eeprom(hw, (word_addr + i*2 + 1), 1, ®_addr);
9051 ret_val = e1000_get_software_flag(hw);
9052 if (ret_val != E1000_SUCCESS)
9055 ret_val = e1000_write_phy_reg_ex(hw, (uint32_t)reg_addr, reg_data);
9057 e1000_release_software_flag(hw);
9065 e1000_init_lcd_from_nvm(struct e1000_hw *hw)
9067 uint32_t reg_data, cnf_base_addr, cnf_size, ret_val, loop;
9069 if (hw->phy_type != e1000_phy_igp_3)
9070 return E1000_SUCCESS;
9072 /* Check if SW needs configure the PHY */
9073 reg_data = E1000_READ_REG(hw, FEXTNVM);
9074 if (!(reg_data & FEXTNVM_SW_CONFIG))
9075 return E1000_SUCCESS;
9077 /* Wait for basic configuration completes before proceeding*/
9080 reg_data = E1000_READ_REG(hw, STATUS) & E1000_STATUS_LAN_INIT_DONE;
9083 } while ((!reg_data) && (loop < 50));
9085 /* Clear the Init Done bit for the next init event */
9086 reg_data = E1000_READ_REG(hw, STATUS);
9087 reg_data &= ~E1000_STATUS_LAN_INIT_DONE;
9088 E1000_WRITE_REG(hw, STATUS, reg_data);
9090 /* Make sure HW does not configure LCD from PHY extended configuration
9091 before SW configuration */
9092 reg_data = E1000_READ_REG(hw, EXTCNF_CTRL);
9093 if ((reg_data & E1000_EXTCNF_CTRL_LCD_WRITE_ENABLE) == 0x0000) {
9094 reg_data = E1000_READ_REG(hw, EXTCNF_SIZE);
9095 cnf_size = reg_data & E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH;
9098 reg_data = E1000_READ_REG(hw, EXTCNF_CTRL);
9099 cnf_base_addr = reg_data & E1000_EXTCNF_CTRL_EXT_CNF_POINTER;
9100 /* cnf_base_addr is in DWORD */
9101 cnf_base_addr >>= 16;
9103 /* Configure LCD from extended configuration region. */
9104 ret_val = e1000_init_lcd_from_nvm_config_region(hw, cnf_base_addr,
9111 return E1000_SUCCESS;