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 static int32_t e1000_erase_ich8_4k_segment(struct e1000_hw *hw,
110 static int32_t e1000_get_software_flag(struct e1000_hw *hw);
111 static int32_t e1000_get_software_semaphore(struct e1000_hw *hw);
112 static int32_t e1000_init_lcd_from_nvm(struct e1000_hw *hw);
113 static int32_t e1000_kumeran_lock_loss_workaround(struct e1000_hw *hw);
114 static int32_t e1000_read_eeprom_ich8(struct e1000_hw *hw, uint16_t offset,
115 uint16_t words, uint16_t *data);
116 static int32_t e1000_read_ich8_byte(struct e1000_hw *hw, uint32_t index,
118 static int32_t e1000_read_ich8_word(struct e1000_hw *hw, uint32_t index,
120 static int32_t e1000_read_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr,
122 static void e1000_release_software_flag(struct e1000_hw *hw);
123 static void e1000_release_software_semaphore(struct e1000_hw *hw);
124 static int32_t e1000_set_pci_ex_no_snoop(struct e1000_hw *hw,
126 static int32_t e1000_verify_write_ich8_byte(struct e1000_hw *hw,
127 uint32_t index, uint8_t byte);
128 static int32_t e1000_write_eeprom_ich8(struct e1000_hw *hw, uint16_t offset,
129 uint16_t words, uint16_t *data);
130 static int32_t e1000_write_ich8_byte(struct e1000_hw *hw, uint32_t index,
132 static int32_t e1000_write_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr,
135 /* IGP cable length table */
137 uint16_t e1000_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] =
138 { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
139 5, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 25, 25, 25,
140 25, 25, 25, 25, 30, 30, 30, 30, 40, 40, 40, 40, 40, 40, 40, 40,
141 40, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60,
142 60, 70, 70, 70, 70, 70, 70, 80, 80, 80, 80, 80, 80, 90, 90, 90,
143 90, 90, 90, 90, 90, 90, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
144 100, 100, 100, 100, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,
145 110, 110, 110, 110, 110, 110, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120};
148 uint16_t e1000_igp_2_cable_length_table[IGP02E1000_AGC_LENGTH_TABLE_SIZE] =
149 { 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21,
150 0, 0, 0, 3, 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41,
151 6, 10, 14, 18, 22, 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61,
152 21, 26, 31, 35, 40, 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82,
153 40, 45, 51, 56, 61, 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104,
154 60, 66, 72, 77, 82, 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121,
155 83, 89, 95, 100, 105, 109, 113, 116, 119, 122, 124,
156 104, 109, 114, 118, 121, 124};
159 /******************************************************************************
160 * Set the phy type member in the hw struct.
162 * hw - Struct containing variables accessed by shared code
163 *****************************************************************************/
165 e1000_set_phy_type(struct e1000_hw *hw)
167 DEBUGFUNC("e1000_set_phy_type");
169 if(hw->mac_type == e1000_undefined)
170 return -E1000_ERR_PHY_TYPE;
173 case M88E1000_E_PHY_ID:
174 case M88E1000_I_PHY_ID:
175 case M88E1011_I_PHY_ID:
176 case M88E1111_I_PHY_ID:
177 hw->phy_type = e1000_phy_m88;
179 case IGP01E1000_I_PHY_ID:
180 if(hw->mac_type == e1000_82541 ||
181 hw->mac_type == e1000_82541_rev_2 ||
182 hw->mac_type == e1000_82547 ||
183 hw->mac_type == e1000_82547_rev_2) {
184 hw->phy_type = e1000_phy_igp;
187 case IGP03E1000_E_PHY_ID:
188 hw->phy_type = e1000_phy_igp_3;
191 case IFE_PLUS_E_PHY_ID:
193 hw->phy_type = e1000_phy_ife;
195 case GG82563_E_PHY_ID:
196 if (hw->mac_type == e1000_80003es2lan) {
197 hw->phy_type = e1000_phy_gg82563;
202 /* Should never have loaded on this device */
203 hw->phy_type = e1000_phy_undefined;
204 return -E1000_ERR_PHY_TYPE;
207 return E1000_SUCCESS;
210 /******************************************************************************
211 * IGP phy init script - initializes the GbE PHY
213 * hw - Struct containing variables accessed by shared code
214 *****************************************************************************/
216 e1000_phy_init_script(struct e1000_hw *hw)
219 uint16_t phy_saved_data;
221 DEBUGFUNC("e1000_phy_init_script");
223 if(hw->phy_init_script) {
226 /* Save off the current value of register 0x2F5B to be restored at
227 * the end of this routine. */
228 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
230 /* Disabled the PHY transmitter */
231 e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
235 e1000_write_phy_reg(hw,0x0000,0x0140);
239 switch(hw->mac_type) {
242 e1000_write_phy_reg(hw, 0x1F95, 0x0001);
244 e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
246 e1000_write_phy_reg(hw, 0x1F79, 0x0018);
248 e1000_write_phy_reg(hw, 0x1F30, 0x1600);
250 e1000_write_phy_reg(hw, 0x1F31, 0x0014);
252 e1000_write_phy_reg(hw, 0x1F32, 0x161C);
254 e1000_write_phy_reg(hw, 0x1F94, 0x0003);
256 e1000_write_phy_reg(hw, 0x1F96, 0x003F);
258 e1000_write_phy_reg(hw, 0x2010, 0x0008);
261 case e1000_82541_rev_2:
262 case e1000_82547_rev_2:
263 e1000_write_phy_reg(hw, 0x1F73, 0x0099);
269 e1000_write_phy_reg(hw, 0x0000, 0x3300);
273 /* Now enable the transmitter */
274 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
276 if(hw->mac_type == e1000_82547) {
277 uint16_t fused, fine, coarse;
279 /* Move to analog registers page */
280 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_SPARE_FUSE_STATUS, &fused);
282 if(!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
283 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_FUSE_STATUS, &fused);
285 fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
286 coarse = fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
288 if(coarse > IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
289 coarse -= IGP01E1000_ANALOG_FUSE_COARSE_10;
290 fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
291 } else if(coarse == IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
292 fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
294 fused = (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
295 (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
296 (coarse & IGP01E1000_ANALOG_FUSE_COARSE_MASK);
298 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_CONTROL, fused);
299 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_BYPASS,
300 IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
306 /******************************************************************************
307 * Set the mac type member in the hw struct.
309 * hw - Struct containing variables accessed by shared code
310 *****************************************************************************/
312 e1000_set_mac_type(struct e1000_hw *hw)
314 DEBUGFUNC("e1000_set_mac_type");
316 switch (hw->device_id) {
317 case E1000_DEV_ID_82542:
318 switch (hw->revision_id) {
319 case E1000_82542_2_0_REV_ID:
320 hw->mac_type = e1000_82542_rev2_0;
322 case E1000_82542_2_1_REV_ID:
323 hw->mac_type = e1000_82542_rev2_1;
326 /* Invalid 82542 revision ID */
327 return -E1000_ERR_MAC_TYPE;
330 case E1000_DEV_ID_82543GC_FIBER:
331 case E1000_DEV_ID_82543GC_COPPER:
332 hw->mac_type = e1000_82543;
334 case E1000_DEV_ID_82544EI_COPPER:
335 case E1000_DEV_ID_82544EI_FIBER:
336 case E1000_DEV_ID_82544GC_COPPER:
337 case E1000_DEV_ID_82544GC_LOM:
338 hw->mac_type = e1000_82544;
340 case E1000_DEV_ID_82540EM:
341 case E1000_DEV_ID_82540EM_LOM:
342 case E1000_DEV_ID_82540EP:
343 case E1000_DEV_ID_82540EP_LOM:
344 case E1000_DEV_ID_82540EP_LP:
345 hw->mac_type = e1000_82540;
347 case E1000_DEV_ID_82545EM_COPPER:
348 case E1000_DEV_ID_82545EM_FIBER:
349 hw->mac_type = e1000_82545;
351 case E1000_DEV_ID_82545GM_COPPER:
352 case E1000_DEV_ID_82545GM_FIBER:
353 case E1000_DEV_ID_82545GM_SERDES:
354 hw->mac_type = e1000_82545_rev_3;
356 case E1000_DEV_ID_82546EB_COPPER:
357 case E1000_DEV_ID_82546EB_FIBER:
358 case E1000_DEV_ID_82546EB_QUAD_COPPER:
359 hw->mac_type = e1000_82546;
361 case E1000_DEV_ID_82546GB_COPPER:
362 case E1000_DEV_ID_82546GB_FIBER:
363 case E1000_DEV_ID_82546GB_SERDES:
364 case E1000_DEV_ID_82546GB_PCIE:
365 case E1000_DEV_ID_82546GB_QUAD_COPPER:
366 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
367 hw->mac_type = e1000_82546_rev_3;
369 case E1000_DEV_ID_82541EI:
370 case E1000_DEV_ID_82541EI_MOBILE:
371 case E1000_DEV_ID_82541ER_LOM:
372 hw->mac_type = e1000_82541;
374 case E1000_DEV_ID_82541ER:
375 case E1000_DEV_ID_82541GI:
376 case E1000_DEV_ID_82541GI_LF:
377 case E1000_DEV_ID_82541GI_MOBILE:
378 hw->mac_type = e1000_82541_rev_2;
380 case E1000_DEV_ID_82547EI:
381 case E1000_DEV_ID_82547EI_MOBILE:
382 hw->mac_type = e1000_82547;
384 case E1000_DEV_ID_82547GI:
385 hw->mac_type = e1000_82547_rev_2;
387 case E1000_DEV_ID_82571EB_COPPER:
388 case E1000_DEV_ID_82571EB_FIBER:
389 case E1000_DEV_ID_82571EB_SERDES:
390 hw->mac_type = e1000_82571;
392 case E1000_DEV_ID_82572EI_COPPER:
393 case E1000_DEV_ID_82572EI_FIBER:
394 case E1000_DEV_ID_82572EI_SERDES:
395 case E1000_DEV_ID_82572EI:
396 hw->mac_type = e1000_82572;
398 case E1000_DEV_ID_82573E:
399 case E1000_DEV_ID_82573E_IAMT:
400 case E1000_DEV_ID_82573L:
401 hw->mac_type = e1000_82573;
403 case E1000_DEV_ID_80003ES2LAN_COPPER_SPT:
404 case E1000_DEV_ID_80003ES2LAN_SERDES_SPT:
405 case E1000_DEV_ID_80003ES2LAN_COPPER_DPT:
406 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
407 hw->mac_type = e1000_80003es2lan;
409 case E1000_DEV_ID_ICH8_IGP_M_AMT:
410 case E1000_DEV_ID_ICH8_IGP_AMT:
411 case E1000_DEV_ID_ICH8_IGP_C:
412 case E1000_DEV_ID_ICH8_IFE:
413 case E1000_DEV_ID_ICH8_IGP_M:
414 hw->mac_type = e1000_ich8lan;
417 /* Should never have loaded on this device */
418 return -E1000_ERR_MAC_TYPE;
421 switch(hw->mac_type) {
423 hw->swfwhw_semaphore_present = TRUE;
424 hw->asf_firmware_present = TRUE;
426 case e1000_80003es2lan:
427 hw->swfw_sync_present = TRUE;
432 hw->eeprom_semaphore_present = TRUE;
436 case e1000_82541_rev_2:
437 case e1000_82547_rev_2:
438 hw->asf_firmware_present = TRUE;
444 return E1000_SUCCESS;
447 /*****************************************************************************
448 * Set media type and TBI compatibility.
450 * hw - Struct containing variables accessed by shared code
451 * **************************************************************************/
453 e1000_set_media_type(struct e1000_hw *hw)
457 DEBUGFUNC("e1000_set_media_type");
459 if(hw->mac_type != e1000_82543) {
460 /* tbi_compatibility is only valid on 82543 */
461 hw->tbi_compatibility_en = FALSE;
464 switch (hw->device_id) {
465 case E1000_DEV_ID_82545GM_SERDES:
466 case E1000_DEV_ID_82546GB_SERDES:
467 case E1000_DEV_ID_82571EB_SERDES:
468 case E1000_DEV_ID_82572EI_SERDES:
469 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
470 hw->media_type = e1000_media_type_internal_serdes;
473 switch (hw->mac_type) {
474 case e1000_82542_rev2_0:
475 case e1000_82542_rev2_1:
476 hw->media_type = e1000_media_type_fiber;
480 /* The STATUS_TBIMODE bit is reserved or reused for the this
483 hw->media_type = e1000_media_type_copper;
486 status = E1000_READ_REG(hw, STATUS);
487 if (status & E1000_STATUS_TBIMODE) {
488 hw->media_type = e1000_media_type_fiber;
489 /* tbi_compatibility not valid on fiber */
490 hw->tbi_compatibility_en = FALSE;
492 hw->media_type = e1000_media_type_copper;
499 /******************************************************************************
500 * Reset the transmit and receive units; mask and clear all interrupts.
502 * hw - Struct containing variables accessed by shared code
503 *****************************************************************************/
505 e1000_reset_hw(struct e1000_hw *hw)
513 uint32_t extcnf_ctrl;
516 DEBUGFUNC("e1000_reset_hw");
518 /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
519 if(hw->mac_type == e1000_82542_rev2_0) {
520 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
521 e1000_pci_clear_mwi(hw);
524 if(hw->bus_type == e1000_bus_type_pci_express) {
525 /* Prevent the PCI-E bus from sticking if there is no TLP connection
526 * on the last TLP read/write transaction when MAC is reset.
528 if(e1000_disable_pciex_master(hw) != E1000_SUCCESS) {
529 DEBUGOUT("PCI-E Master disable polling has failed.\n");
533 /* Clear interrupt mask to stop board from generating interrupts */
534 DEBUGOUT("Masking off all interrupts\n");
535 E1000_WRITE_REG(hw, IMC, 0xffffffff);
537 /* Disable the Transmit and Receive units. Then delay to allow
538 * any pending transactions to complete before we hit the MAC with
541 E1000_WRITE_REG(hw, RCTL, 0);
542 E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP);
543 E1000_WRITE_FLUSH(hw);
545 /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
546 hw->tbi_compatibility_on = FALSE;
548 /* Delay to allow any outstanding PCI transactions to complete before
549 * resetting the device
553 ctrl = E1000_READ_REG(hw, CTRL);
555 /* Must reset the PHY before resetting the MAC */
556 if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
557 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_PHY_RST));
561 /* Must acquire the MDIO ownership before MAC reset.
562 * Ownership defaults to firmware after a reset. */
563 if(hw->mac_type == e1000_82573) {
566 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
567 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
570 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
571 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
573 if(extcnf_ctrl & E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP)
576 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
583 /* Workaround for ICH8 bit corruption issue in FIFO memory */
584 if (hw->mac_type == e1000_ich8lan) {
585 /* Set Tx and Rx buffer allocation to 8k apiece. */
586 E1000_WRITE_REG(hw, PBA, E1000_PBA_8K);
587 /* Set Packet Buffer Size to 16k. */
588 E1000_WRITE_REG(hw, PBS, E1000_PBS_16K);
591 /* Issue a global reset to the MAC. This will reset the chip's
592 * transmit, receive, DMA, and link units. It will not effect
593 * the current PCI configuration. The global reset bit is self-
594 * clearing, and should clear within a microsecond.
596 DEBUGOUT("Issuing a global reset to MAC\n");
598 switch(hw->mac_type) {
604 case e1000_82541_rev_2:
605 /* These controllers can't ack the 64-bit write when issuing the
606 * reset, so use IO-mapping as a workaround to issue the reset */
607 E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
609 case e1000_82545_rev_3:
610 case e1000_82546_rev_3:
611 /* Reset is performed on a shadow of the control register */
612 E1000_WRITE_REG(hw, CTRL_DUP, (ctrl | E1000_CTRL_RST));
615 if (!hw->phy_reset_disable &&
616 e1000_check_phy_reset_block(hw) == E1000_SUCCESS) {
617 /* e1000_ich8lan PHY HW reset requires MAC CORE reset
618 * at the same time to make sure the interface between
619 * MAC and the external PHY is reset.
621 ctrl |= E1000_CTRL_PHY_RST;
624 e1000_get_software_flag(hw);
625 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
629 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
633 /* After MAC reset, force reload of EEPROM to restore power-on settings to
634 * device. Later controllers reload the EEPROM automatically, so just wait
635 * for reload to complete.
637 switch(hw->mac_type) {
638 case e1000_82542_rev2_0:
639 case e1000_82542_rev2_1:
642 /* Wait for reset to complete */
644 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
645 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
646 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
647 E1000_WRITE_FLUSH(hw);
648 /* Wait for EEPROM reload */
652 case e1000_82541_rev_2:
654 case e1000_82547_rev_2:
655 /* Wait for EEPROM reload */
659 if (e1000_is_onboard_nvm_eeprom(hw) == FALSE) {
661 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
662 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
663 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
664 E1000_WRITE_FLUSH(hw);
670 case e1000_80003es2lan:
671 ret_val = e1000_get_auto_rd_done(hw);
673 /* We don't want to continue accessing MAC registers. */
677 /* Wait for EEPROM reload (it happens automatically) */
682 /* Disable HW ARPs on ASF enabled adapters */
683 if(hw->mac_type >= e1000_82540 && hw->mac_type <= e1000_82547_rev_2) {
684 manc = E1000_READ_REG(hw, MANC);
685 manc &= ~(E1000_MANC_ARP_EN);
686 E1000_WRITE_REG(hw, MANC, manc);
689 if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
690 e1000_phy_init_script(hw);
692 /* Configure activity LED after PHY reset */
693 led_ctrl = E1000_READ_REG(hw, LEDCTL);
694 led_ctrl &= IGP_ACTIVITY_LED_MASK;
695 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
696 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
699 /* Clear interrupt mask to stop board from generating interrupts */
700 DEBUGOUT("Masking off all interrupts\n");
701 E1000_WRITE_REG(hw, IMC, 0xffffffff);
703 /* Clear any pending interrupt events. */
704 icr = E1000_READ_REG(hw, ICR);
706 /* If MWI was previously enabled, reenable it. */
707 if(hw->mac_type == e1000_82542_rev2_0) {
708 if(hw->pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
709 e1000_pci_set_mwi(hw);
712 if (hw->mac_type == e1000_ich8lan) {
713 uint32_t kab = E1000_READ_REG(hw, KABGTXD);
714 kab |= E1000_KABGTXD_BGSQLBIAS;
715 E1000_WRITE_REG(hw, KABGTXD, kab);
718 return E1000_SUCCESS;
721 /******************************************************************************
722 * Performs basic configuration of the adapter.
724 * hw - Struct containing variables accessed by shared code
726 * Assumes that the controller has previously been reset and is in a
727 * post-reset uninitialized state. Initializes the receive address registers,
728 * multicast table, and VLAN filter table. Calls routines to setup link
729 * configuration and flow control settings. Clears all on-chip counters. Leaves
730 * the transmit and receive units disabled and uninitialized.
731 *****************************************************************************/
733 e1000_init_hw(struct e1000_hw *hw)
738 uint16_t pcix_cmd_word;
739 uint16_t pcix_stat_hi_word;
746 DEBUGFUNC("e1000_init_hw");
748 /* force full DMA clock frequency for 10/100 on ICH8 A0-B0 */
749 if (hw->mac_type == e1000_ich8lan) {
750 reg_data = E1000_READ_REG(hw, TARC0);
751 reg_data |= 0x30000000;
752 E1000_WRITE_REG(hw, TARC0, reg_data);
754 reg_data = E1000_READ_REG(hw, STATUS);
755 reg_data &= ~0x80000000;
756 E1000_WRITE_REG(hw, STATUS, reg_data);
759 /* Initialize Identification LED */
760 ret_val = e1000_id_led_init(hw);
762 DEBUGOUT("Error Initializing Identification LED\n");
766 /* Set the media type and TBI compatibility */
767 e1000_set_media_type(hw);
769 /* Disabling VLAN filtering. */
770 DEBUGOUT("Initializing the IEEE VLAN\n");
771 /* VET hardcoded to standard value and VFTA removed in ICH8 LAN */
772 if (hw->mac_type != e1000_ich8lan) {
773 if (hw->mac_type < e1000_82545_rev_3)
774 E1000_WRITE_REG(hw, VET, 0);
775 e1000_clear_vfta(hw);
778 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
779 if(hw->mac_type == e1000_82542_rev2_0) {
780 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
781 e1000_pci_clear_mwi(hw);
782 E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST);
783 E1000_WRITE_FLUSH(hw);
787 /* Setup the receive address. This involves initializing all of the Receive
788 * Address Registers (RARs 0 - 15).
790 e1000_init_rx_addrs(hw);
792 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
793 if(hw->mac_type == e1000_82542_rev2_0) {
794 E1000_WRITE_REG(hw, RCTL, 0);
795 E1000_WRITE_FLUSH(hw);
797 if(hw->pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
798 e1000_pci_set_mwi(hw);
801 /* Zero out the Multicast HASH table */
802 DEBUGOUT("Zeroing the MTA\n");
803 mta_size = E1000_MC_TBL_SIZE;
804 if (hw->mac_type == e1000_ich8lan)
805 mta_size = E1000_MC_TBL_SIZE_ICH8LAN;
806 for(i = 0; i < mta_size; i++) {
807 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
808 /* use write flush to prevent Memory Write Block (MWB) from
809 * occuring when accessing our register space */
810 E1000_WRITE_FLUSH(hw);
813 /* Set the PCI priority bit correctly in the CTRL register. This
814 * determines if the adapter gives priority to receives, or if it
815 * gives equal priority to transmits and receives. Valid only on
816 * 82542 and 82543 silicon.
818 if(hw->dma_fairness && hw->mac_type <= e1000_82543) {
819 ctrl = E1000_READ_REG(hw, CTRL);
820 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PRIOR);
823 switch(hw->mac_type) {
824 case e1000_82545_rev_3:
825 case e1000_82546_rev_3:
828 /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
829 if(hw->bus_type == e1000_bus_type_pcix) {
830 e1000_read_pci_cfg(hw, PCIX_COMMAND_REGISTER, &pcix_cmd_word);
831 e1000_read_pci_cfg(hw, PCIX_STATUS_REGISTER_HI,
833 cmd_mmrbc = (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >>
834 PCIX_COMMAND_MMRBC_SHIFT;
835 stat_mmrbc = (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
836 PCIX_STATUS_HI_MMRBC_SHIFT;
837 if(stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
838 stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
839 if(cmd_mmrbc > stat_mmrbc) {
840 pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK;
841 pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
842 e1000_write_pci_cfg(hw, PCIX_COMMAND_REGISTER,
849 /* More time needed for PHY to initialize */
850 if (hw->mac_type == e1000_ich8lan)
853 /* Call a subroutine to configure the link and setup flow control. */
854 ret_val = e1000_setup_link(hw);
856 /* Set the transmit descriptor write-back policy */
857 if(hw->mac_type > e1000_82544) {
858 ctrl = E1000_READ_REG(hw, TXDCTL);
859 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
860 switch (hw->mac_type) {
867 case e1000_80003es2lan:
868 ctrl |= E1000_TXDCTL_COUNT_DESC;
871 E1000_WRITE_REG(hw, TXDCTL, ctrl);
874 if (hw->mac_type == e1000_82573) {
875 e1000_enable_tx_pkt_filtering(hw);
878 switch (hw->mac_type) {
881 case e1000_80003es2lan:
882 /* Enable retransmit on late collisions */
883 reg_data = E1000_READ_REG(hw, TCTL);
884 reg_data |= E1000_TCTL_RTLC;
885 E1000_WRITE_REG(hw, TCTL, reg_data);
887 /* Configure Gigabit Carry Extend Padding */
888 reg_data = E1000_READ_REG(hw, TCTL_EXT);
889 reg_data &= ~E1000_TCTL_EXT_GCEX_MASK;
890 reg_data |= DEFAULT_80003ES2LAN_TCTL_EXT_GCEX;
891 E1000_WRITE_REG(hw, TCTL_EXT, reg_data);
893 /* Configure Transmit Inter-Packet Gap */
894 reg_data = E1000_READ_REG(hw, TIPG);
895 reg_data &= ~E1000_TIPG_IPGT_MASK;
896 reg_data |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
897 E1000_WRITE_REG(hw, TIPG, reg_data);
899 reg_data = E1000_READ_REG_ARRAY(hw, FFLT, 0x0001);
900 reg_data &= ~0x00100000;
901 E1000_WRITE_REG_ARRAY(hw, FFLT, 0x0001, reg_data);
906 ctrl = E1000_READ_REG(hw, TXDCTL1);
907 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
908 if(hw->mac_type >= e1000_82571)
909 ctrl |= E1000_TXDCTL_COUNT_DESC;
910 E1000_WRITE_REG(hw, TXDCTL1, ctrl);
916 if (hw->mac_type == e1000_82573) {
917 uint32_t gcr = E1000_READ_REG(hw, GCR);
918 gcr |= E1000_GCR_L1_ACT_WITHOUT_L0S_RX;
919 E1000_WRITE_REG(hw, GCR, gcr);
922 /* Clear all of the statistics registers (clear on read). It is
923 * important that we do this after we have tried to establish link
924 * because the symbol error count will increment wildly if there
927 e1000_clear_hw_cntrs(hw);
929 /* ICH8 No-snoop bits are opposite polarity.
930 * Set to snoop by default after reset. */
931 if (hw->mac_type == e1000_ich8lan)
932 e1000_set_pci_ex_no_snoop(hw, PCI_EX_82566_SNOOP_ALL);
934 if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER ||
935 hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) {
936 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
937 /* Relaxed ordering must be disabled to avoid a parity
938 * error crash in a PCI slot. */
939 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
940 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
946 /******************************************************************************
947 * Adjust SERDES output amplitude based on EEPROM setting.
949 * hw - Struct containing variables accessed by shared code.
950 *****************************************************************************/
952 e1000_adjust_serdes_amplitude(struct e1000_hw *hw)
954 uint16_t eeprom_data;
957 DEBUGFUNC("e1000_adjust_serdes_amplitude");
959 if(hw->media_type != e1000_media_type_internal_serdes)
960 return E1000_SUCCESS;
962 switch(hw->mac_type) {
963 case e1000_82545_rev_3:
964 case e1000_82546_rev_3:
967 return E1000_SUCCESS;
970 ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1, &eeprom_data);
975 if(eeprom_data != EEPROM_RESERVED_WORD) {
976 /* Adjust SERDES output amplitude only. */
977 eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK;
978 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data);
983 return E1000_SUCCESS;
986 /******************************************************************************
987 * Configures flow control and link settings.
989 * hw - Struct containing variables accessed by shared code
991 * Determines which flow control settings to use. Calls the apropriate media-
992 * specific link configuration function. Configures the flow control settings.
993 * Assuming the adapter has a valid link partner, a valid link should be
994 * established. Assumes the hardware has previously been reset and the
995 * transmitter and receiver are not enabled.
996 *****************************************************************************/
998 e1000_setup_link(struct e1000_hw *hw)
1002 uint16_t eeprom_data;
1004 DEBUGFUNC("e1000_setup_link");
1006 /* In the case of the phy reset being blocked, we already have a link.
1007 * We do not have to set it up again. */
1008 if (e1000_check_phy_reset_block(hw))
1009 return E1000_SUCCESS;
1011 /* Read and store word 0x0F of the EEPROM. This word contains bits
1012 * that determine the hardware's default PAUSE (flow control) mode,
1013 * a bit that determines whether the HW defaults to enabling or
1014 * disabling auto-negotiation, and the direction of the
1015 * SW defined pins. If there is no SW over-ride of the flow
1016 * control setting, then the variable hw->fc will
1017 * be initialized based on a value in the EEPROM.
1019 if (hw->fc == e1000_fc_default) {
1020 switch (hw->mac_type) {
1023 hw->fc = e1000_fc_full;
1026 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
1029 DEBUGOUT("EEPROM Read Error\n");
1030 return -E1000_ERR_EEPROM;
1032 if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
1033 hw->fc = e1000_fc_none;
1034 else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
1035 EEPROM_WORD0F_ASM_DIR)
1036 hw->fc = e1000_fc_tx_pause;
1038 hw->fc = e1000_fc_full;
1043 /* We want to save off the original Flow Control configuration just
1044 * in case we get disconnected and then reconnected into a different
1045 * hub or switch with different Flow Control capabilities.
1047 if(hw->mac_type == e1000_82542_rev2_0)
1048 hw->fc &= (~e1000_fc_tx_pause);
1050 if((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
1051 hw->fc &= (~e1000_fc_rx_pause);
1053 hw->original_fc = hw->fc;
1055 DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc);
1057 /* Take the 4 bits from EEPROM word 0x0F that determine the initial
1058 * polarity value for the SW controlled pins, and setup the
1059 * Extended Device Control reg with that info.
1060 * This is needed because one of the SW controlled pins is used for
1061 * signal detection. So this should be done before e1000_setup_pcs_link()
1062 * or e1000_phy_setup() is called.
1064 if (hw->mac_type == e1000_82543) {
1065 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
1068 DEBUGOUT("EEPROM Read Error\n");
1069 return -E1000_ERR_EEPROM;
1071 ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
1073 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1076 /* Call the necessary subroutine to configure the link. */
1077 ret_val = (hw->media_type == e1000_media_type_copper) ?
1078 e1000_setup_copper_link(hw) :
1079 e1000_setup_fiber_serdes_link(hw);
1081 /* Initialize the flow control address, type, and PAUSE timer
1082 * registers to their default values. This is done even if flow
1083 * control is disabled, because it does not hurt anything to
1084 * initialize these registers.
1086 DEBUGOUT("Initializing the Flow Control address, type and timer regs\n");
1088 /* FCAL/H and FCT are hardcoded to standard values in e1000_ich8lan. */
1089 if (hw->mac_type != e1000_ich8lan) {
1090 E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
1091 E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
1092 E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
1095 E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
1097 /* Set the flow control receive threshold registers. Normally,
1098 * these registers will be set to a default threshold that may be
1099 * adjusted later by the driver's runtime code. However, if the
1100 * ability to transmit pause frames in not enabled, then these
1101 * registers will be set to 0.
1103 if(!(hw->fc & e1000_fc_tx_pause)) {
1104 E1000_WRITE_REG(hw, FCRTL, 0);
1105 E1000_WRITE_REG(hw, FCRTH, 0);
1107 /* We need to set up the Receive Threshold high and low water marks
1108 * as well as (optionally) enabling the transmission of XON frames.
1110 if(hw->fc_send_xon) {
1111 E1000_WRITE_REG(hw, FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE));
1112 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
1114 E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water);
1115 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
1121 /******************************************************************************
1122 * Sets up link for a fiber based or serdes based adapter
1124 * hw - Struct containing variables accessed by shared code
1126 * Manipulates Physical Coding Sublayer functions in order to configure
1127 * link. Assumes the hardware has been previously reset and the transmitter
1128 * and receiver are not enabled.
1129 *****************************************************************************/
1131 e1000_setup_fiber_serdes_link(struct e1000_hw *hw)
1137 uint32_t signal = 0;
1140 DEBUGFUNC("e1000_setup_fiber_serdes_link");
1142 /* On 82571 and 82572 Fiber connections, SerDes loopback mode persists
1143 * until explicitly turned off or a power cycle is performed. A read to
1144 * the register does not indicate its status. Therefore, we ensure
1145 * loopback mode is disabled during initialization.
1147 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572)
1148 E1000_WRITE_REG(hw, SCTL, E1000_DISABLE_SERDES_LOOPBACK);
1150 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
1151 * set when the optics detect a signal. On older adapters, it will be
1152 * cleared when there is a signal. This applies to fiber media only.
1153 * If we're on serdes media, adjust the output amplitude to value set in
1156 ctrl = E1000_READ_REG(hw, CTRL);
1157 if(hw->media_type == e1000_media_type_fiber)
1158 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
1160 ret_val = e1000_adjust_serdes_amplitude(hw);
1164 /* Take the link out of reset */
1165 ctrl &= ~(E1000_CTRL_LRST);
1167 /* Adjust VCO speed to improve BER performance */
1168 ret_val = e1000_set_vco_speed(hw);
1172 e1000_config_collision_dist(hw);
1174 /* Check for a software override of the flow control settings, and setup
1175 * the device accordingly. If auto-negotiation is enabled, then software
1176 * will have to set the "PAUSE" bits to the correct value in the Tranmsit
1177 * Config Word Register (TXCW) and re-start auto-negotiation. However, if
1178 * auto-negotiation is disabled, then software will have to manually
1179 * configure the two flow control enable bits in the CTRL register.
1181 * The possible values of the "fc" parameter are:
1182 * 0: Flow control is completely disabled
1183 * 1: Rx flow control is enabled (we can receive pause frames, but
1184 * not send pause frames).
1185 * 2: Tx flow control is enabled (we can send pause frames but we do
1186 * not support receiving pause frames).
1187 * 3: Both Rx and TX flow control (symmetric) are enabled.
1191 /* Flow control is completely disabled by a software over-ride. */
1192 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
1194 case e1000_fc_rx_pause:
1195 /* RX Flow control is enabled and TX Flow control is disabled by a
1196 * software over-ride. Since there really isn't a way to advertise
1197 * that we are capable of RX Pause ONLY, we will advertise that we
1198 * support both symmetric and asymmetric RX PAUSE. Later, we will
1199 * disable the adapter's ability to send PAUSE frames.
1201 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1203 case e1000_fc_tx_pause:
1204 /* TX Flow control is enabled, and RX Flow control is disabled, by a
1205 * software over-ride.
1207 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
1210 /* Flow control (both RX and TX) is enabled by a software over-ride. */
1211 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1214 DEBUGOUT("Flow control param set incorrectly\n");
1215 return -E1000_ERR_CONFIG;
1219 /* Since auto-negotiation is enabled, take the link out of reset (the link
1220 * will be in reset, because we previously reset the chip). This will
1221 * restart auto-negotiation. If auto-neogtiation is successful then the
1222 * link-up status bit will be set and the flow control enable bits (RFCE
1223 * and TFCE) will be set according to their negotiated value.
1225 DEBUGOUT("Auto-negotiation enabled\n");
1227 E1000_WRITE_REG(hw, TXCW, txcw);
1228 E1000_WRITE_REG(hw, CTRL, ctrl);
1229 E1000_WRITE_FLUSH(hw);
1234 /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
1235 * indication in the Device Status Register. Time-out if a link isn't
1236 * seen in 500 milliseconds seconds (Auto-negotiation should complete in
1237 * less than 500 milliseconds even if the other end is doing it in SW).
1238 * For internal serdes, we just assume a signal is present, then poll.
1240 if(hw->media_type == e1000_media_type_internal_serdes ||
1241 (E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) {
1242 DEBUGOUT("Looking for Link\n");
1243 for(i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
1245 status = E1000_READ_REG(hw, STATUS);
1246 if(status & E1000_STATUS_LU) break;
1248 if(i == (LINK_UP_TIMEOUT / 10)) {
1249 DEBUGOUT("Never got a valid link from auto-neg!!!\n");
1250 hw->autoneg_failed = 1;
1251 /* AutoNeg failed to achieve a link, so we'll call
1252 * e1000_check_for_link. This routine will force the link up if
1253 * we detect a signal. This will allow us to communicate with
1254 * non-autonegotiating link partners.
1256 ret_val = e1000_check_for_link(hw);
1258 DEBUGOUT("Error while checking for link\n");
1261 hw->autoneg_failed = 0;
1263 hw->autoneg_failed = 0;
1264 DEBUGOUT("Valid Link Found\n");
1267 DEBUGOUT("No Signal Detected\n");
1269 return E1000_SUCCESS;
1272 /******************************************************************************
1273 * Make sure we have a valid PHY and change PHY mode before link setup.
1275 * hw - Struct containing variables accessed by shared code
1276 ******************************************************************************/
1278 e1000_copper_link_preconfig(struct e1000_hw *hw)
1284 DEBUGFUNC("e1000_copper_link_preconfig");
1286 ctrl = E1000_READ_REG(hw, CTRL);
1287 /* With 82543, we need to force speed and duplex on the MAC equal to what
1288 * the PHY speed and duplex configuration is. In addition, we need to
1289 * perform a hardware reset on the PHY to take it out of reset.
1291 if(hw->mac_type > e1000_82543) {
1292 ctrl |= E1000_CTRL_SLU;
1293 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1294 E1000_WRITE_REG(hw, CTRL, ctrl);
1296 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
1297 E1000_WRITE_REG(hw, CTRL, ctrl);
1298 ret_val = e1000_phy_hw_reset(hw);
1303 /* Make sure we have a valid PHY */
1304 ret_val = e1000_detect_gig_phy(hw);
1306 DEBUGOUT("Error, did not detect valid phy.\n");
1309 DEBUGOUT1("Phy ID = %x \n", hw->phy_id);
1311 /* Set PHY to class A mode (if necessary) */
1312 ret_val = e1000_set_phy_mode(hw);
1316 if((hw->mac_type == e1000_82545_rev_3) ||
1317 (hw->mac_type == e1000_82546_rev_3)) {
1318 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1319 phy_data |= 0x00000008;
1320 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1323 if(hw->mac_type <= e1000_82543 ||
1324 hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
1325 hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2)
1326 hw->phy_reset_disable = FALSE;
1328 return E1000_SUCCESS;
1332 /********************************************************************
1333 * Copper link setup for e1000_phy_igp series.
1335 * hw - Struct containing variables accessed by shared code
1336 *********************************************************************/
1338 e1000_copper_link_igp_setup(struct e1000_hw *hw)
1344 DEBUGFUNC("e1000_copper_link_igp_setup");
1346 if (hw->phy_reset_disable)
1347 return E1000_SUCCESS;
1349 ret_val = e1000_phy_reset(hw);
1351 DEBUGOUT("Error Resetting the PHY\n");
1355 /* Wait 10ms for MAC to configure PHY from eeprom settings */
1357 if (hw->mac_type != e1000_ich8lan) {
1358 /* Configure activity LED after PHY reset */
1359 led_ctrl = E1000_READ_REG(hw, LEDCTL);
1360 led_ctrl &= IGP_ACTIVITY_LED_MASK;
1361 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
1362 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
1365 /* The NVM settings will configure LPLU in D3 for IGP2 and IGP3 PHYs */
1366 if (hw->phy_type == e1000_phy_igp) {
1367 /* disable lplu d3 during driver init */
1368 ret_val = e1000_set_d3_lplu_state(hw, FALSE);
1370 DEBUGOUT("Error Disabling LPLU D3\n");
1375 /* disable lplu d0 during driver init */
1376 ret_val = e1000_set_d0_lplu_state(hw, FALSE);
1378 DEBUGOUT("Error Disabling LPLU D0\n");
1381 /* Configure mdi-mdix settings */
1382 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1386 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
1387 hw->dsp_config_state = e1000_dsp_config_disabled;
1388 /* Force MDI for earlier revs of the IGP PHY */
1389 phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX | IGP01E1000_PSCR_FORCE_MDI_MDIX);
1393 hw->dsp_config_state = e1000_dsp_config_enabled;
1394 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1398 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1401 phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
1405 phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
1409 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1413 /* set auto-master slave resolution settings */
1415 e1000_ms_type phy_ms_setting = hw->master_slave;
1417 if(hw->ffe_config_state == e1000_ffe_config_active)
1418 hw->ffe_config_state = e1000_ffe_config_enabled;
1420 if(hw->dsp_config_state == e1000_dsp_config_activated)
1421 hw->dsp_config_state = e1000_dsp_config_enabled;
1423 /* when autonegotiation advertisment is only 1000Mbps then we
1424 * should disable SmartSpeed and enable Auto MasterSlave
1425 * resolution as hardware default. */
1426 if(hw->autoneg_advertised == ADVERTISE_1000_FULL) {
1427 /* Disable SmartSpeed */
1428 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
1431 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1432 ret_val = e1000_write_phy_reg(hw,
1433 IGP01E1000_PHY_PORT_CONFIG,
1437 /* Set auto Master/Slave resolution process */
1438 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1441 phy_data &= ~CR_1000T_MS_ENABLE;
1442 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1447 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1451 /* load defaults for future use */
1452 hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
1453 ((phy_data & CR_1000T_MS_VALUE) ?
1454 e1000_ms_force_master :
1455 e1000_ms_force_slave) :
1458 switch (phy_ms_setting) {
1459 case e1000_ms_force_master:
1460 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
1462 case e1000_ms_force_slave:
1463 phy_data |= CR_1000T_MS_ENABLE;
1464 phy_data &= ~(CR_1000T_MS_VALUE);
1467 phy_data &= ~CR_1000T_MS_ENABLE;
1471 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1476 return E1000_SUCCESS;
1479 /********************************************************************
1480 * Copper link setup for e1000_phy_gg82563 series.
1482 * hw - Struct containing variables accessed by shared code
1483 *********************************************************************/
1485 e1000_copper_link_ggp_setup(struct e1000_hw *hw)
1491 DEBUGFUNC("e1000_copper_link_ggp_setup");
1493 if(!hw->phy_reset_disable) {
1495 /* Enable CRS on TX for half-duplex operation. */
1496 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL,
1501 phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
1502 /* Use 25MHz for both link down and 1000BASE-T for Tx clock */
1503 phy_data |= GG82563_MSCR_TX_CLK_1000MBPS_25MHZ;
1505 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL,
1511 * MDI/MDI-X = 0 (default)
1512 * 0 - Auto for all speeds
1515 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1517 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_SPEC_CTRL, &phy_data);
1521 phy_data &= ~GG82563_PSCR_CROSSOVER_MODE_MASK;
1525 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDI;
1528 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDIX;
1532 phy_data |= GG82563_PSCR_CROSSOVER_MODE_AUTO;
1537 * disable_polarity_correction = 0 (default)
1538 * Automatic Correction for Reversed Cable Polarity
1542 phy_data &= ~GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
1543 if(hw->disable_polarity_correction == 1)
1544 phy_data |= GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
1545 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_SPEC_CTRL, phy_data);
1550 /* SW Reset the PHY so all changes take effect */
1551 ret_val = e1000_phy_reset(hw);
1553 DEBUGOUT("Error Resetting the PHY\n");
1556 } /* phy_reset_disable */
1558 if (hw->mac_type == e1000_80003es2lan) {
1559 /* Bypass RX and TX FIFO's */
1560 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_FIFO_CTRL,
1561 E1000_KUMCTRLSTA_FIFO_CTRL_RX_BYPASS |
1562 E1000_KUMCTRLSTA_FIFO_CTRL_TX_BYPASS);
1566 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_SPEC_CTRL_2, &phy_data);
1570 phy_data &= ~GG82563_PSCR2_REVERSE_AUTO_NEG;
1571 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_SPEC_CTRL_2, phy_data);
1576 reg_data = E1000_READ_REG(hw, CTRL_EXT);
1577 reg_data &= ~(E1000_CTRL_EXT_LINK_MODE_MASK);
1578 E1000_WRITE_REG(hw, CTRL_EXT, reg_data);
1580 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_PWR_MGMT_CTRL,
1585 /* Do not init these registers when the HW is in IAMT mode, since the
1586 * firmware will have already initialized them. We only initialize
1587 * them if the HW is not in IAMT mode.
1589 if (e1000_check_mng_mode(hw) == FALSE) {
1590 /* Enable Electrical Idle on the PHY */
1591 phy_data |= GG82563_PMCR_ENABLE_ELECTRICAL_IDLE;
1592 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_PWR_MGMT_CTRL,
1597 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
1602 phy_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
1604 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
1610 /* Workaround: Disable padding in Kumeran interface in the MAC
1611 * and in the PHY to avoid CRC errors.
1613 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_INBAND_CTRL,
1617 phy_data |= GG82563_ICR_DIS_PADDING;
1618 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_INBAND_CTRL,
1624 return E1000_SUCCESS;
1627 /********************************************************************
1628 * Copper link setup for e1000_phy_m88 series.
1630 * hw - Struct containing variables accessed by shared code
1631 *********************************************************************/
1633 e1000_copper_link_mgp_setup(struct e1000_hw *hw)
1638 DEBUGFUNC("e1000_copper_link_mgp_setup");
1640 if(hw->phy_reset_disable)
1641 return E1000_SUCCESS;
1643 /* Enable CRS on TX. This must be set for half-duplex operation. */
1644 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1648 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1651 * MDI/MDI-X = 0 (default)
1652 * 0 - Auto for all speeds
1655 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1657 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1661 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
1664 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
1667 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
1671 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
1676 * disable_polarity_correction = 0 (default)
1677 * Automatic Correction for Reversed Cable Polarity
1681 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
1682 if(hw->disable_polarity_correction == 1)
1683 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
1684 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1688 if (hw->phy_revision < M88E1011_I_REV_4) {
1689 /* Force TX_CLK in the Extended PHY Specific Control Register
1692 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1696 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1698 if ((hw->phy_revision == E1000_REVISION_2) &&
1699 (hw->phy_id == M88E1111_I_PHY_ID)) {
1700 /* Vidalia Phy, set the downshift counter to 5x */
1701 phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK);
1702 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
1703 ret_val = e1000_write_phy_reg(hw,
1704 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1708 /* Configure Master and Slave downshift values */
1709 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
1710 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
1711 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
1712 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
1713 ret_val = e1000_write_phy_reg(hw,
1714 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1720 /* SW Reset the PHY so all changes take effect */
1721 ret_val = e1000_phy_reset(hw);
1723 DEBUGOUT("Error Resetting the PHY\n");
1727 return E1000_SUCCESS;
1730 /********************************************************************
1731 * Setup auto-negotiation and flow control advertisements,
1732 * and then perform auto-negotiation.
1734 * hw - Struct containing variables accessed by shared code
1735 *********************************************************************/
1737 e1000_copper_link_autoneg(struct e1000_hw *hw)
1742 DEBUGFUNC("e1000_copper_link_autoneg");
1744 /* Perform some bounds checking on the hw->autoneg_advertised
1745 * parameter. If this variable is zero, then set it to the default.
1747 hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
1749 /* If autoneg_advertised is zero, we assume it was not defaulted
1750 * by the calling code so we set to advertise full capability.
1752 if(hw->autoneg_advertised == 0)
1753 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
1755 /* IFE phy only supports 10/100 */
1756 if (hw->phy_type == e1000_phy_ife)
1757 hw->autoneg_advertised &= AUTONEG_ADVERTISE_10_100_ALL;
1759 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
1760 ret_val = e1000_phy_setup_autoneg(hw);
1762 DEBUGOUT("Error Setting up Auto-Negotiation\n");
1765 DEBUGOUT("Restarting Auto-Neg\n");
1767 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
1768 * the Auto Neg Restart bit in the PHY control register.
1770 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
1774 phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
1775 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
1779 /* Does the user want to wait for Auto-Neg to complete here, or
1780 * check at a later time (for example, callback routine).
1782 if(hw->wait_autoneg_complete) {
1783 ret_val = e1000_wait_autoneg(hw);
1785 DEBUGOUT("Error while waiting for autoneg to complete\n");
1790 hw->get_link_status = TRUE;
1792 return E1000_SUCCESS;
1796 /******************************************************************************
1797 * Config the MAC and the PHY after link is up.
1798 * 1) Set up the MAC to the current PHY speed/duplex
1799 * if we are on 82543. If we
1800 * are on newer silicon, we only need to configure
1801 * collision distance in the Transmit Control Register.
1802 * 2) Set up flow control on the MAC to that established with
1804 * 3) Config DSP to improve Gigabit link quality for some PHY revisions.
1806 * hw - Struct containing variables accessed by shared code
1807 ******************************************************************************/
1809 e1000_copper_link_postconfig(struct e1000_hw *hw)
1812 DEBUGFUNC("e1000_copper_link_postconfig");
1814 if(hw->mac_type >= e1000_82544) {
1815 e1000_config_collision_dist(hw);
1817 ret_val = e1000_config_mac_to_phy(hw);
1819 DEBUGOUT("Error configuring MAC to PHY settings\n");
1823 ret_val = e1000_config_fc_after_link_up(hw);
1825 DEBUGOUT("Error Configuring Flow Control\n");
1829 /* Config DSP to improve Giga link quality */
1830 if(hw->phy_type == e1000_phy_igp) {
1831 ret_val = e1000_config_dsp_after_link_change(hw, TRUE);
1833 DEBUGOUT("Error Configuring DSP after link up\n");
1838 return E1000_SUCCESS;
1841 /******************************************************************************
1842 * Detects which PHY is present and setup the speed and duplex
1844 * hw - Struct containing variables accessed by shared code
1845 ******************************************************************************/
1847 e1000_setup_copper_link(struct e1000_hw *hw)
1854 DEBUGFUNC("e1000_setup_copper_link");
1856 switch (hw->mac_type) {
1857 case e1000_80003es2lan:
1859 /* Set the mac to wait the maximum time between each
1860 * iteration and increase the max iterations when
1861 * polling the phy; this fixes erroneous timeouts at 10Mbps. */
1862 ret_val = e1000_write_kmrn_reg(hw, GG82563_REG(0x34, 4), 0xFFFF);
1865 ret_val = e1000_read_kmrn_reg(hw, GG82563_REG(0x34, 9), ®_data);
1869 ret_val = e1000_write_kmrn_reg(hw, GG82563_REG(0x34, 9), reg_data);
1876 /* Check if it is a valid PHY and set PHY mode if necessary. */
1877 ret_val = e1000_copper_link_preconfig(hw);
1881 switch (hw->mac_type) {
1882 case e1000_80003es2lan:
1883 /* Kumeran registers are written-only */
1884 reg_data = E1000_KUMCTRLSTA_INB_CTRL_LINK_STATUS_TX_TIMEOUT_DEFAULT;
1885 reg_data |= E1000_KUMCTRLSTA_INB_CTRL_DIS_PADDING;
1886 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_INB_CTRL,
1895 if (hw->phy_type == e1000_phy_igp ||
1896 hw->phy_type == e1000_phy_igp_3 ||
1897 hw->phy_type == e1000_phy_igp_2) {
1898 ret_val = e1000_copper_link_igp_setup(hw);
1901 } else if (hw->phy_type == e1000_phy_m88) {
1902 ret_val = e1000_copper_link_mgp_setup(hw);
1905 } else if (hw->phy_type == e1000_phy_gg82563) {
1906 ret_val = e1000_copper_link_ggp_setup(hw);
1912 /* Setup autoneg and flow control advertisement
1913 * and perform autonegotiation */
1914 ret_val = e1000_copper_link_autoneg(hw);
1918 /* PHY will be set to 10H, 10F, 100H,or 100F
1919 * depending on value from forced_speed_duplex. */
1920 DEBUGOUT("Forcing speed and duplex\n");
1921 ret_val = e1000_phy_force_speed_duplex(hw);
1923 DEBUGOUT("Error Forcing Speed and Duplex\n");
1928 /* Check link status. Wait up to 100 microseconds for link to become
1931 for(i = 0; i < 10; i++) {
1932 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
1935 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
1939 if(phy_data & MII_SR_LINK_STATUS) {
1940 /* Config the MAC and PHY after link is up */
1941 ret_val = e1000_copper_link_postconfig(hw);
1945 DEBUGOUT("Valid link established!!!\n");
1946 return E1000_SUCCESS;
1951 DEBUGOUT("Unable to establish link!!!\n");
1952 return E1000_SUCCESS;
1955 /******************************************************************************
1956 * Configure the MAC-to-PHY interface for 10/100Mbps
1958 * hw - Struct containing variables accessed by shared code
1959 ******************************************************************************/
1961 e1000_configure_kmrn_for_10_100(struct e1000_hw *hw, uint16_t duplex)
1963 int32_t ret_val = E1000_SUCCESS;
1967 DEBUGFUNC("e1000_configure_kmrn_for_10_100");
1969 reg_data = E1000_KUMCTRLSTA_HD_CTRL_10_100_DEFAULT;
1970 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_HD_CTRL,
1975 /* Configure Transmit Inter-Packet Gap */
1976 tipg = E1000_READ_REG(hw, TIPG);
1977 tipg &= ~E1000_TIPG_IPGT_MASK;
1978 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_10_100;
1979 E1000_WRITE_REG(hw, TIPG, tipg);
1981 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, ®_data);
1986 if (duplex == HALF_DUPLEX)
1987 reg_data |= GG82563_KMCR_PASS_FALSE_CARRIER;
1989 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
1991 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
1997 e1000_configure_kmrn_for_1000(struct e1000_hw *hw)
1999 int32_t ret_val = E1000_SUCCESS;
2003 DEBUGFUNC("e1000_configure_kmrn_for_1000");
2005 reg_data = E1000_KUMCTRLSTA_HD_CTRL_1000_DEFAULT;
2006 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_HD_CTRL,
2011 /* Configure Transmit Inter-Packet Gap */
2012 tipg = E1000_READ_REG(hw, TIPG);
2013 tipg &= ~E1000_TIPG_IPGT_MASK;
2014 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
2015 E1000_WRITE_REG(hw, TIPG, tipg);
2017 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, ®_data);
2022 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
2023 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
2028 /******************************************************************************
2029 * Configures PHY autoneg and flow control advertisement settings
2031 * hw - Struct containing variables accessed by shared code
2032 ******************************************************************************/
2034 e1000_phy_setup_autoneg(struct e1000_hw *hw)
2037 uint16_t mii_autoneg_adv_reg;
2038 uint16_t mii_1000t_ctrl_reg;
2040 DEBUGFUNC("e1000_phy_setup_autoneg");
2042 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
2043 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
2047 if (hw->phy_type != e1000_phy_ife) {
2048 /* Read the MII 1000Base-T Control Register (Address 9). */
2049 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
2053 mii_1000t_ctrl_reg=0;
2055 /* Need to parse both autoneg_advertised and fc and set up
2056 * the appropriate PHY registers. First we will parse for
2057 * autoneg_advertised software override. Since we can advertise
2058 * a plethora of combinations, we need to check each bit
2062 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
2063 * Advertisement Register (Address 4) and the 1000 mb speed bits in
2064 * the 1000Base-T Control Register (Address 9).
2066 mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
2067 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
2069 DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised);
2071 /* Do we want to advertise 10 Mb Half Duplex? */
2072 if(hw->autoneg_advertised & ADVERTISE_10_HALF) {
2073 DEBUGOUT("Advertise 10mb Half duplex\n");
2074 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
2077 /* Do we want to advertise 10 Mb Full Duplex? */
2078 if(hw->autoneg_advertised & ADVERTISE_10_FULL) {
2079 DEBUGOUT("Advertise 10mb Full duplex\n");
2080 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
2083 /* Do we want to advertise 100 Mb Half Duplex? */
2084 if(hw->autoneg_advertised & ADVERTISE_100_HALF) {
2085 DEBUGOUT("Advertise 100mb Half duplex\n");
2086 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
2089 /* Do we want to advertise 100 Mb Full Duplex? */
2090 if(hw->autoneg_advertised & ADVERTISE_100_FULL) {
2091 DEBUGOUT("Advertise 100mb Full duplex\n");
2092 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
2095 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
2096 if(hw->autoneg_advertised & ADVERTISE_1000_HALF) {
2097 DEBUGOUT("Advertise 1000mb Half duplex requested, request denied!\n");
2100 /* Do we want to advertise 1000 Mb Full Duplex? */
2101 if(hw->autoneg_advertised & ADVERTISE_1000_FULL) {
2102 DEBUGOUT("Advertise 1000mb Full duplex\n");
2103 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
2104 if (hw->phy_type == e1000_phy_ife) {
2105 DEBUGOUT("e1000_phy_ife is a 10/100 PHY. Gigabit speed is not supported.\n");
2109 /* Check for a software override of the flow control settings, and
2110 * setup the PHY advertisement registers accordingly. If
2111 * auto-negotiation is enabled, then software will have to set the
2112 * "PAUSE" bits to the correct value in the Auto-Negotiation
2113 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
2115 * The possible values of the "fc" parameter are:
2116 * 0: Flow control is completely disabled
2117 * 1: Rx flow control is enabled (we can receive pause frames
2118 * but not send pause frames).
2119 * 2: Tx flow control is enabled (we can send pause frames
2120 * but we do not support receiving pause frames).
2121 * 3: Both Rx and TX flow control (symmetric) are enabled.
2122 * other: No software override. The flow control configuration
2123 * in the EEPROM is used.
2126 case e1000_fc_none: /* 0 */
2127 /* Flow control (RX & TX) is completely disabled by a
2128 * software over-ride.
2130 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2132 case e1000_fc_rx_pause: /* 1 */
2133 /* RX Flow control is enabled, and TX Flow control is
2134 * disabled, by a software over-ride.
2136 /* Since there really isn't a way to advertise that we are
2137 * capable of RX Pause ONLY, we will advertise that we
2138 * support both symmetric and asymmetric RX PAUSE. Later
2139 * (in e1000_config_fc_after_link_up) we will disable the
2140 *hw's ability to send PAUSE frames.
2142 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2144 case e1000_fc_tx_pause: /* 2 */
2145 /* TX Flow control is enabled, and RX Flow control is
2146 * disabled, by a software over-ride.
2148 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
2149 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
2151 case e1000_fc_full: /* 3 */
2152 /* Flow control (both RX and TX) is enabled by a software
2155 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2158 DEBUGOUT("Flow control param set incorrectly\n");
2159 return -E1000_ERR_CONFIG;
2162 ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
2166 DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
2168 if (hw->phy_type != e1000_phy_ife) {
2169 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg);
2174 return E1000_SUCCESS;
2177 /******************************************************************************
2178 * Force PHY speed and duplex settings to hw->forced_speed_duplex
2180 * hw - Struct containing variables accessed by shared code
2181 ******************************************************************************/
2183 e1000_phy_force_speed_duplex(struct e1000_hw *hw)
2187 uint16_t mii_ctrl_reg;
2188 uint16_t mii_status_reg;
2192 DEBUGFUNC("e1000_phy_force_speed_duplex");
2194 /* Turn off Flow control if we are forcing speed and duplex. */
2195 hw->fc = e1000_fc_none;
2197 DEBUGOUT1("hw->fc = %d\n", hw->fc);
2199 /* Read the Device Control Register. */
2200 ctrl = E1000_READ_REG(hw, CTRL);
2202 /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */
2203 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2204 ctrl &= ~(DEVICE_SPEED_MASK);
2206 /* Clear the Auto Speed Detect Enable bit. */
2207 ctrl &= ~E1000_CTRL_ASDE;
2209 /* Read the MII Control Register. */
2210 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg);
2214 /* We need to disable autoneg in order to force link and duplex. */
2216 mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN;
2218 /* Are we forcing Full or Half Duplex? */
2219 if(hw->forced_speed_duplex == e1000_100_full ||
2220 hw->forced_speed_duplex == e1000_10_full) {
2221 /* We want to force full duplex so we SET the full duplex bits in the
2222 * Device and MII Control Registers.
2224 ctrl |= E1000_CTRL_FD;
2225 mii_ctrl_reg |= MII_CR_FULL_DUPLEX;
2226 DEBUGOUT("Full Duplex\n");
2228 /* We want to force half duplex so we CLEAR the full duplex bits in
2229 * the Device and MII Control Registers.
2231 ctrl &= ~E1000_CTRL_FD;
2232 mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX;
2233 DEBUGOUT("Half Duplex\n");
2236 /* Are we forcing 100Mbps??? */
2237 if(hw->forced_speed_duplex == e1000_100_full ||
2238 hw->forced_speed_duplex == e1000_100_half) {
2239 /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */
2240 ctrl |= E1000_CTRL_SPD_100;
2241 mii_ctrl_reg |= MII_CR_SPEED_100;
2242 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
2243 DEBUGOUT("Forcing 100mb ");
2245 /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */
2246 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
2247 mii_ctrl_reg |= MII_CR_SPEED_10;
2248 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
2249 DEBUGOUT("Forcing 10mb ");
2252 e1000_config_collision_dist(hw);
2254 /* Write the configured values back to the Device Control Reg. */
2255 E1000_WRITE_REG(hw, CTRL, ctrl);
2257 if ((hw->phy_type == e1000_phy_m88) ||
2258 (hw->phy_type == e1000_phy_gg82563)) {
2259 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
2263 /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
2264 * forced whenever speed are duplex are forced.
2266 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
2267 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
2271 DEBUGOUT1("M88E1000 PSCR: %x \n", phy_data);
2273 /* Need to reset the PHY or these changes will be ignored */
2274 mii_ctrl_reg |= MII_CR_RESET;
2275 /* Disable MDI-X support for 10/100 */
2276 } else if (hw->phy_type == e1000_phy_ife) {
2277 ret_val = e1000_read_phy_reg(hw, IFE_PHY_MDIX_CONTROL, &phy_data);
2281 phy_data &= ~IFE_PMC_AUTO_MDIX;
2282 phy_data &= ~IFE_PMC_FORCE_MDIX;
2284 ret_val = e1000_write_phy_reg(hw, IFE_PHY_MDIX_CONTROL, phy_data);
2288 /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
2289 * forced whenever speed or duplex are forced.
2291 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
2295 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
2296 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
2298 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
2303 /* Write back the modified PHY MII control register. */
2304 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg);
2310 /* The wait_autoneg_complete flag may be a little misleading here.
2311 * Since we are forcing speed and duplex, Auto-Neg is not enabled.
2312 * But we do want to delay for a period while forcing only so we
2313 * don't generate false No Link messages. So we will wait here
2314 * only if the user has set wait_autoneg_complete to 1, which is
2317 if(hw->wait_autoneg_complete) {
2318 /* We will wait for autoneg to complete. */
2319 DEBUGOUT("Waiting for forced speed/duplex link.\n");
2322 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
2323 for(i = PHY_FORCE_TIME; i > 0; i--) {
2324 /* Read the MII Status Register and wait for Auto-Neg Complete bit
2327 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2331 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2335 if(mii_status_reg & MII_SR_LINK_STATUS) break;
2339 ((hw->phy_type == e1000_phy_m88) ||
2340 (hw->phy_type == e1000_phy_gg82563))) {
2341 /* We didn't get link. Reset the DSP and wait again for link. */
2342 ret_val = e1000_phy_reset_dsp(hw);
2344 DEBUGOUT("Error Resetting PHY DSP\n");
2348 /* This loop will early-out if the link condition has been met. */
2349 for(i = PHY_FORCE_TIME; i > 0; i--) {
2350 if(mii_status_reg & MII_SR_LINK_STATUS) break;
2352 /* Read the MII Status Register and wait for Auto-Neg Complete bit
2355 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2359 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2365 if (hw->phy_type == e1000_phy_m88) {
2366 /* Because we reset the PHY above, we need to re-force TX_CLK in the
2367 * Extended PHY Specific Control Register to 25MHz clock. This value
2368 * defaults back to a 2.5MHz clock when the PHY is reset.
2370 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
2374 phy_data |= M88E1000_EPSCR_TX_CLK_25;
2375 ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
2379 /* In addition, because of the s/w reset above, we need to enable CRS on
2380 * TX. This must be set for both full and half duplex operation.
2382 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
2386 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
2387 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
2391 if((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
2393 (hw->forced_speed_duplex == e1000_10_full ||
2394 hw->forced_speed_duplex == e1000_10_half)) {
2395 ret_val = e1000_polarity_reversal_workaround(hw);
2399 } else if (hw->phy_type == e1000_phy_gg82563) {
2400 /* The TX_CLK of the Extended PHY Specific Control Register defaults
2401 * to 2.5MHz on a reset. We need to re-force it back to 25MHz, if
2402 * we're not in a forced 10/duplex configuration. */
2403 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, &phy_data);
2407 phy_data &= ~GG82563_MSCR_TX_CLK_MASK;
2408 if ((hw->forced_speed_duplex == e1000_10_full) ||
2409 (hw->forced_speed_duplex == e1000_10_half))
2410 phy_data |= GG82563_MSCR_TX_CLK_10MBPS_2_5MHZ;
2412 phy_data |= GG82563_MSCR_TX_CLK_100MBPS_25MHZ;
2414 /* Also due to the reset, we need to enable CRS on Tx. */
2415 phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
2417 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, phy_data);
2421 return E1000_SUCCESS;
2424 /******************************************************************************
2425 * Sets the collision distance in the Transmit Control register
2427 * hw - Struct containing variables accessed by shared code
2429 * Link should have been established previously. Reads the speed and duplex
2430 * information from the Device Status register.
2431 ******************************************************************************/
2433 e1000_config_collision_dist(struct e1000_hw *hw)
2435 uint32_t tctl, coll_dist;
2437 DEBUGFUNC("e1000_config_collision_dist");
2439 if (hw->mac_type < e1000_82543)
2440 coll_dist = E1000_COLLISION_DISTANCE_82542;
2442 coll_dist = E1000_COLLISION_DISTANCE;
2444 tctl = E1000_READ_REG(hw, TCTL);
2446 tctl &= ~E1000_TCTL_COLD;
2447 tctl |= coll_dist << E1000_COLD_SHIFT;
2449 E1000_WRITE_REG(hw, TCTL, tctl);
2450 E1000_WRITE_FLUSH(hw);
2453 /******************************************************************************
2454 * Sets MAC speed and duplex settings to reflect the those in the PHY
2456 * hw - Struct containing variables accessed by shared code
2457 * mii_reg - data to write to the MII control register
2459 * The contents of the PHY register containing the needed information need to
2461 ******************************************************************************/
2463 e1000_config_mac_to_phy(struct e1000_hw *hw)
2469 DEBUGFUNC("e1000_config_mac_to_phy");
2471 /* 82544 or newer MAC, Auto Speed Detection takes care of
2472 * MAC speed/duplex configuration.*/
2473 if (hw->mac_type >= e1000_82544)
2474 return E1000_SUCCESS;
2476 /* Read the Device Control Register and set the bits to Force Speed
2479 ctrl = E1000_READ_REG(hw, CTRL);
2480 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2481 ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
2483 /* Set up duplex in the Device Control and Transmit Control
2484 * registers depending on negotiated values.
2486 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
2490 if(phy_data & M88E1000_PSSR_DPLX)
2491 ctrl |= E1000_CTRL_FD;
2493 ctrl &= ~E1000_CTRL_FD;
2495 e1000_config_collision_dist(hw);
2497 /* Set up speed in the Device Control register depending on
2498 * negotiated values.
2500 if((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
2501 ctrl |= E1000_CTRL_SPD_1000;
2502 else if((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
2503 ctrl |= E1000_CTRL_SPD_100;
2505 /* Write the configured values back to the Device Control Reg. */
2506 E1000_WRITE_REG(hw, CTRL, ctrl);
2507 return E1000_SUCCESS;
2510 /******************************************************************************
2511 * Forces the MAC's flow control settings.
2513 * hw - Struct containing variables accessed by shared code
2515 * Sets the TFCE and RFCE bits in the device control register to reflect
2516 * the adapter settings. TFCE and RFCE need to be explicitly set by
2517 * software when a Copper PHY is used because autonegotiation is managed
2518 * by the PHY rather than the MAC. Software must also configure these
2519 * bits when link is forced on a fiber connection.
2520 *****************************************************************************/
2522 e1000_force_mac_fc(struct e1000_hw *hw)
2526 DEBUGFUNC("e1000_force_mac_fc");
2528 /* Get the current configuration of the Device Control Register */
2529 ctrl = E1000_READ_REG(hw, CTRL);
2531 /* Because we didn't get link via the internal auto-negotiation
2532 * mechanism (we either forced link or we got link via PHY
2533 * auto-neg), we have to manually enable/disable transmit an
2534 * receive flow control.
2536 * The "Case" statement below enables/disable flow control
2537 * according to the "hw->fc" parameter.
2539 * The possible values of the "fc" parameter are:
2540 * 0: Flow control is completely disabled
2541 * 1: Rx flow control is enabled (we can receive pause
2542 * frames but not send pause frames).
2543 * 2: Tx flow control is enabled (we can send pause frames
2544 * frames but we do not receive pause frames).
2545 * 3: Both Rx and TX flow control (symmetric) is enabled.
2546 * other: No other values should be possible at this point.
2551 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
2553 case e1000_fc_rx_pause:
2554 ctrl &= (~E1000_CTRL_TFCE);
2555 ctrl |= E1000_CTRL_RFCE;
2557 case e1000_fc_tx_pause:
2558 ctrl &= (~E1000_CTRL_RFCE);
2559 ctrl |= E1000_CTRL_TFCE;
2562 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
2565 DEBUGOUT("Flow control param set incorrectly\n");
2566 return -E1000_ERR_CONFIG;
2569 /* Disable TX Flow Control for 82542 (rev 2.0) */
2570 if(hw->mac_type == e1000_82542_rev2_0)
2571 ctrl &= (~E1000_CTRL_TFCE);
2573 E1000_WRITE_REG(hw, CTRL, ctrl);
2574 return E1000_SUCCESS;
2577 /******************************************************************************
2578 * Configures flow control settings after link is established
2580 * hw - Struct containing variables accessed by shared code
2582 * Should be called immediately after a valid link has been established.
2583 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
2584 * and autonegotiation is enabled, the MAC flow control settings will be set
2585 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
2586 * and RFCE bits will be automaticaly set to the negotiated flow control mode.
2587 *****************************************************************************/
2589 e1000_config_fc_after_link_up(struct e1000_hw *hw)
2592 uint16_t mii_status_reg;
2593 uint16_t mii_nway_adv_reg;
2594 uint16_t mii_nway_lp_ability_reg;
2598 DEBUGFUNC("e1000_config_fc_after_link_up");
2600 /* Check for the case where we have fiber media and auto-neg failed
2601 * so we had to force link. In this case, we need to force the
2602 * configuration of the MAC to match the "fc" parameter.
2604 if(((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) ||
2605 ((hw->media_type == e1000_media_type_internal_serdes) && (hw->autoneg_failed)) ||
2606 ((hw->media_type == e1000_media_type_copper) && (!hw->autoneg))) {
2607 ret_val = e1000_force_mac_fc(hw);
2609 DEBUGOUT("Error forcing flow control settings\n");
2614 /* Check for the case where we have copper media and auto-neg is
2615 * enabled. In this case, we need to check and see if Auto-Neg
2616 * has completed, and if so, how the PHY and link partner has
2617 * flow control configured.
2619 if((hw->media_type == e1000_media_type_copper) && hw->autoneg) {
2620 /* Read the MII Status Register and check to see if AutoNeg
2621 * has completed. We read this twice because this reg has
2622 * some "sticky" (latched) bits.
2624 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2627 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2631 if(mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
2632 /* The AutoNeg process has completed, so we now need to
2633 * read both the Auto Negotiation Advertisement Register
2634 * (Address 4) and the Auto_Negotiation Base Page Ability
2635 * Register (Address 5) to determine how flow control was
2638 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV,
2642 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY,
2643 &mii_nway_lp_ability_reg);
2647 /* Two bits in the Auto Negotiation Advertisement Register
2648 * (Address 4) and two bits in the Auto Negotiation Base
2649 * Page Ability Register (Address 5) determine flow control
2650 * for both the PHY and the link partner. The following
2651 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
2652 * 1999, describes these PAUSE resolution bits and how flow
2653 * control is determined based upon these settings.
2654 * NOTE: DC = Don't Care
2656 * LOCAL DEVICE | LINK PARTNER
2657 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
2658 *-------|---------|-------|---------|--------------------
2659 * 0 | 0 | DC | DC | e1000_fc_none
2660 * 0 | 1 | 0 | DC | e1000_fc_none
2661 * 0 | 1 | 1 | 0 | e1000_fc_none
2662 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
2663 * 1 | 0 | 0 | DC | e1000_fc_none
2664 * 1 | DC | 1 | DC | e1000_fc_full
2665 * 1 | 1 | 0 | 0 | e1000_fc_none
2666 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
2669 /* Are both PAUSE bits set to 1? If so, this implies
2670 * Symmetric Flow Control is enabled at both ends. The
2671 * ASM_DIR bits are irrelevant per the spec.
2673 * For Symmetric Flow Control:
2675 * LOCAL DEVICE | LINK PARTNER
2676 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2677 *-------|---------|-------|---------|--------------------
2678 * 1 | DC | 1 | DC | e1000_fc_full
2681 if((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2682 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
2683 /* Now we need to check if the user selected RX ONLY
2684 * of pause frames. In this case, we had to advertise
2685 * FULL flow control because we could not advertise RX
2686 * ONLY. Hence, we must now check to see if we need to
2687 * turn OFF the TRANSMISSION of PAUSE frames.
2689 if(hw->original_fc == e1000_fc_full) {
2690 hw->fc = e1000_fc_full;
2691 DEBUGOUT("Flow Control = FULL.\n");
2693 hw->fc = e1000_fc_rx_pause;
2694 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
2697 /* For receiving PAUSE frames ONLY.
2699 * LOCAL DEVICE | LINK PARTNER
2700 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2701 *-------|---------|-------|---------|--------------------
2702 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
2705 else if(!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2706 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2707 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2708 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
2709 hw->fc = e1000_fc_tx_pause;
2710 DEBUGOUT("Flow Control = TX PAUSE frames only.\n");
2712 /* For transmitting PAUSE frames ONLY.
2714 * LOCAL DEVICE | LINK PARTNER
2715 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2716 *-------|---------|-------|---------|--------------------
2717 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
2720 else if((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2721 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2722 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2723 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
2724 hw->fc = e1000_fc_rx_pause;
2725 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
2727 /* Per the IEEE spec, at this point flow control should be
2728 * disabled. However, we want to consider that we could
2729 * be connected to a legacy switch that doesn't advertise
2730 * desired flow control, but can be forced on the link
2731 * partner. So if we advertised no flow control, that is
2732 * what we will resolve to. If we advertised some kind of
2733 * receive capability (Rx Pause Only or Full Flow Control)
2734 * and the link partner advertised none, we will configure
2735 * ourselves to enable Rx Flow Control only. We can do
2736 * this safely for two reasons: If the link partner really
2737 * didn't want flow control enabled, and we enable Rx, no
2738 * harm done since we won't be receiving any PAUSE frames
2739 * anyway. If the intent on the link partner was to have
2740 * flow control enabled, then by us enabling RX only, we
2741 * can at least receive pause frames and process them.
2742 * This is a good idea because in most cases, since we are
2743 * predominantly a server NIC, more times than not we will
2744 * be asked to delay transmission of packets than asking
2745 * our link partner to pause transmission of frames.
2747 else if((hw->original_fc == e1000_fc_none ||
2748 hw->original_fc == e1000_fc_tx_pause) ||
2749 hw->fc_strict_ieee) {
2750 hw->fc = e1000_fc_none;
2751 DEBUGOUT("Flow Control = NONE.\n");
2753 hw->fc = e1000_fc_rx_pause;
2754 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
2757 /* Now we need to do one last check... If we auto-
2758 * negotiated to HALF DUPLEX, flow control should not be
2759 * enabled per IEEE 802.3 spec.
2761 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
2763 DEBUGOUT("Error getting link speed and duplex\n");
2767 if(duplex == HALF_DUPLEX)
2768 hw->fc = e1000_fc_none;
2770 /* Now we call a subroutine to actually force the MAC
2771 * controller to use the correct flow control settings.
2773 ret_val = e1000_force_mac_fc(hw);
2775 DEBUGOUT("Error forcing flow control settings\n");
2779 DEBUGOUT("Copper PHY and Auto Neg has not completed.\n");
2782 return E1000_SUCCESS;
2785 /******************************************************************************
2786 * Checks to see if the link status of the hardware has changed.
2788 * hw - Struct containing variables accessed by shared code
2790 * Called by any function that needs to check the link status of the adapter.
2791 *****************************************************************************/
2793 e1000_check_for_link(struct e1000_hw *hw)
2800 uint32_t signal = 0;
2804 DEBUGFUNC("e1000_check_for_link");
2806 ctrl = E1000_READ_REG(hw, CTRL);
2807 status = E1000_READ_REG(hw, STATUS);
2809 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
2810 * set when the optics detect a signal. On older adapters, it will be
2811 * cleared when there is a signal. This applies to fiber media only.
2813 if((hw->media_type == e1000_media_type_fiber) ||
2814 (hw->media_type == e1000_media_type_internal_serdes)) {
2815 rxcw = E1000_READ_REG(hw, RXCW);
2817 if(hw->media_type == e1000_media_type_fiber) {
2818 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
2819 if(status & E1000_STATUS_LU)
2820 hw->get_link_status = FALSE;
2824 /* If we have a copper PHY then we only want to go out to the PHY
2825 * registers to see if Auto-Neg has completed and/or if our link
2826 * status has changed. The get_link_status flag will be set if we
2827 * receive a Link Status Change interrupt or we have Rx Sequence
2830 if((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
2831 /* First we want to see if the MII Status Register reports
2832 * link. If so, then we want to get the current speed/duplex
2834 * Read the register twice since the link bit is sticky.
2836 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2839 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2843 if(phy_data & MII_SR_LINK_STATUS) {
2844 hw->get_link_status = FALSE;
2845 /* Check if there was DownShift, must be checked immediately after
2847 e1000_check_downshift(hw);
2849 /* If we are on 82544 or 82543 silicon and speed/duplex
2850 * are forced to 10H or 10F, then we will implement the polarity
2851 * reversal workaround. We disable interrupts first, and upon
2852 * returning, place the devices interrupt state to its previous
2853 * value except for the link status change interrupt which will
2854 * happen due to the execution of this workaround.
2857 if((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
2859 (hw->forced_speed_duplex == e1000_10_full ||
2860 hw->forced_speed_duplex == e1000_10_half)) {
2861 E1000_WRITE_REG(hw, IMC, 0xffffffff);
2862 ret_val = e1000_polarity_reversal_workaround(hw);
2863 icr = E1000_READ_REG(hw, ICR);
2864 E1000_WRITE_REG(hw, ICS, (icr & ~E1000_ICS_LSC));
2865 E1000_WRITE_REG(hw, IMS, IMS_ENABLE_MASK);
2869 /* No link detected */
2870 e1000_config_dsp_after_link_change(hw, FALSE);
2874 /* If we are forcing speed/duplex, then we simply return since
2875 * we have already determined whether we have link or not.
2877 if(!hw->autoneg) return -E1000_ERR_CONFIG;
2879 /* optimize the dsp settings for the igp phy */
2880 e1000_config_dsp_after_link_change(hw, TRUE);
2882 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
2883 * have Si on board that is 82544 or newer, Auto
2884 * Speed Detection takes care of MAC speed/duplex
2885 * configuration. So we only need to configure Collision
2886 * Distance in the MAC. Otherwise, we need to force
2887 * speed/duplex on the MAC to the current PHY speed/duplex
2890 if(hw->mac_type >= e1000_82544)
2891 e1000_config_collision_dist(hw);
2893 ret_val = e1000_config_mac_to_phy(hw);
2895 DEBUGOUT("Error configuring MAC to PHY settings\n");
2900 /* Configure Flow Control now that Auto-Neg has completed. First, we
2901 * need to restore the desired flow control settings because we may
2902 * have had to re-autoneg with a different link partner.
2904 ret_val = e1000_config_fc_after_link_up(hw);
2906 DEBUGOUT("Error configuring flow control\n");
2910 /* At this point we know that we are on copper and we have
2911 * auto-negotiated link. These are conditions for checking the link
2912 * partner capability register. We use the link speed to determine if
2913 * TBI compatibility needs to be turned on or off. If the link is not
2914 * at gigabit speed, then TBI compatibility is not needed. If we are
2915 * at gigabit speed, we turn on TBI compatibility.
2917 if(hw->tbi_compatibility_en) {
2918 uint16_t speed, duplex;
2919 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
2921 DEBUGOUT("Error getting link speed and duplex\n");
2924 if (speed != SPEED_1000) {
2925 /* If link speed is not set to gigabit speed, we do not need
2926 * to enable TBI compatibility.
2928 if(hw->tbi_compatibility_on) {
2929 /* If we previously were in the mode, turn it off. */
2930 rctl = E1000_READ_REG(hw, RCTL);
2931 rctl &= ~E1000_RCTL_SBP;
2932 E1000_WRITE_REG(hw, RCTL, rctl);
2933 hw->tbi_compatibility_on = FALSE;
2936 /* If TBI compatibility is was previously off, turn it on. For
2937 * compatibility with a TBI link partner, we will store bad
2938 * packets. Some frames have an additional byte on the end and
2939 * will look like CRC errors to to the hardware.
2941 if(!hw->tbi_compatibility_on) {
2942 hw->tbi_compatibility_on = TRUE;
2943 rctl = E1000_READ_REG(hw, RCTL);
2944 rctl |= E1000_RCTL_SBP;
2945 E1000_WRITE_REG(hw, RCTL, rctl);
2950 /* If we don't have link (auto-negotiation failed or link partner cannot
2951 * auto-negotiate), the cable is plugged in (we have signal), and our
2952 * link partner is not trying to auto-negotiate with us (we are receiving
2953 * idles or data), we need to force link up. We also need to give
2954 * auto-negotiation time to complete, in case the cable was just plugged
2955 * in. The autoneg_failed flag does this.
2957 else if((((hw->media_type == e1000_media_type_fiber) &&
2958 ((ctrl & E1000_CTRL_SWDPIN1) == signal)) ||
2959 (hw->media_type == e1000_media_type_internal_serdes)) &&
2960 (!(status & E1000_STATUS_LU)) &&
2961 (!(rxcw & E1000_RXCW_C))) {
2962 if(hw->autoneg_failed == 0) {
2963 hw->autoneg_failed = 1;
2966 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\n");
2968 /* Disable auto-negotiation in the TXCW register */
2969 E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
2971 /* Force link-up and also force full-duplex. */
2972 ctrl = E1000_READ_REG(hw, CTRL);
2973 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
2974 E1000_WRITE_REG(hw, CTRL, ctrl);
2976 /* Configure Flow Control after forcing link up. */
2977 ret_val = e1000_config_fc_after_link_up(hw);
2979 DEBUGOUT("Error configuring flow control\n");
2983 /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
2984 * auto-negotiation in the TXCW register and disable forced link in the
2985 * Device Control register in an attempt to auto-negotiate with our link
2988 else if(((hw->media_type == e1000_media_type_fiber) ||
2989 (hw->media_type == e1000_media_type_internal_serdes)) &&
2990 (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
2991 DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\n");
2992 E1000_WRITE_REG(hw, TXCW, hw->txcw);
2993 E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
2995 hw->serdes_link_down = FALSE;
2997 /* If we force link for non-auto-negotiation switch, check link status
2998 * based on MAC synchronization for internal serdes media type.
3000 else if((hw->media_type == e1000_media_type_internal_serdes) &&
3001 !(E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
3002 /* SYNCH bit and IV bit are sticky. */
3004 if(E1000_RXCW_SYNCH & E1000_READ_REG(hw, RXCW)) {
3005 if(!(rxcw & E1000_RXCW_IV)) {
3006 hw->serdes_link_down = FALSE;
3007 DEBUGOUT("SERDES: Link is up.\n");
3010 hw->serdes_link_down = TRUE;
3011 DEBUGOUT("SERDES: Link is down.\n");
3014 if((hw->media_type == e1000_media_type_internal_serdes) &&
3015 (E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
3016 hw->serdes_link_down = !(E1000_STATUS_LU & E1000_READ_REG(hw, STATUS));
3018 return E1000_SUCCESS;
3021 /******************************************************************************
3022 * Detects the current speed and duplex settings of the hardware.
3024 * hw - Struct containing variables accessed by shared code
3025 * speed - Speed of the connection
3026 * duplex - Duplex setting of the connection
3027 *****************************************************************************/
3029 e1000_get_speed_and_duplex(struct e1000_hw *hw,
3037 DEBUGFUNC("e1000_get_speed_and_duplex");
3039 if(hw->mac_type >= e1000_82543) {
3040 status = E1000_READ_REG(hw, STATUS);
3041 if(status & E1000_STATUS_SPEED_1000) {
3042 *speed = SPEED_1000;
3043 DEBUGOUT("1000 Mbs, ");
3044 } else if(status & E1000_STATUS_SPEED_100) {
3046 DEBUGOUT("100 Mbs, ");
3049 DEBUGOUT("10 Mbs, ");
3052 if(status & E1000_STATUS_FD) {
3053 *duplex = FULL_DUPLEX;
3054 DEBUGOUT("Full Duplex\n");
3056 *duplex = HALF_DUPLEX;
3057 DEBUGOUT(" Half Duplex\n");
3060 DEBUGOUT("1000 Mbs, Full Duplex\n");
3061 *speed = SPEED_1000;
3062 *duplex = FULL_DUPLEX;
3065 /* IGP01 PHY may advertise full duplex operation after speed downgrade even
3066 * if it is operating at half duplex. Here we set the duplex settings to
3067 * match the duplex in the link partner's capabilities.
3069 if(hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
3070 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
3074 if(!(phy_data & NWAY_ER_LP_NWAY_CAPS))
3075 *duplex = HALF_DUPLEX;
3077 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data);
3080 if((*speed == SPEED_100 && !(phy_data & NWAY_LPAR_100TX_FD_CAPS)) ||
3081 (*speed == SPEED_10 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
3082 *duplex = HALF_DUPLEX;
3086 if ((hw->mac_type == e1000_80003es2lan) &&
3087 (hw->media_type == e1000_media_type_copper)) {
3088 if (*speed == SPEED_1000)
3089 ret_val = e1000_configure_kmrn_for_1000(hw);
3091 ret_val = e1000_configure_kmrn_for_10_100(hw, *duplex);
3096 if ((hw->phy_type == e1000_phy_igp_3) && (*speed == SPEED_1000)) {
3097 ret_val = e1000_kumeran_lock_loss_workaround(hw);
3102 return E1000_SUCCESS;
3105 /******************************************************************************
3106 * Blocks until autoneg completes or times out (~4.5 seconds)
3108 * hw - Struct containing variables accessed by shared code
3109 ******************************************************************************/
3111 e1000_wait_autoneg(struct e1000_hw *hw)
3117 DEBUGFUNC("e1000_wait_autoneg");
3118 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
3120 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
3121 for(i = PHY_AUTO_NEG_TIME; i > 0; i--) {
3122 /* Read the MII Status Register and wait for Auto-Neg
3123 * Complete bit to be set.
3125 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3128 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3131 if(phy_data & MII_SR_AUTONEG_COMPLETE) {
3132 return E1000_SUCCESS;
3136 return E1000_SUCCESS;
3139 /******************************************************************************
3140 * Raises the Management Data Clock
3142 * hw - Struct containing variables accessed by shared code
3143 * ctrl - Device control register's current value
3144 ******************************************************************************/
3146 e1000_raise_mdi_clk(struct e1000_hw *hw,
3149 /* Raise the clock input to the Management Data Clock (by setting the MDC
3150 * bit), and then delay 10 microseconds.
3152 E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
3153 E1000_WRITE_FLUSH(hw);
3157 /******************************************************************************
3158 * Lowers the Management Data Clock
3160 * hw - Struct containing variables accessed by shared code
3161 * ctrl - Device control register's current value
3162 ******************************************************************************/
3164 e1000_lower_mdi_clk(struct e1000_hw *hw,
3167 /* Lower the clock input to the Management Data Clock (by clearing the MDC
3168 * bit), and then delay 10 microseconds.
3170 E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
3171 E1000_WRITE_FLUSH(hw);
3175 /******************************************************************************
3176 * Shifts data bits out to the PHY
3178 * hw - Struct containing variables accessed by shared code
3179 * data - Data to send out to the PHY
3180 * count - Number of bits to shift out
3182 * Bits are shifted out in MSB to LSB order.
3183 ******************************************************************************/
3185 e1000_shift_out_mdi_bits(struct e1000_hw *hw,
3192 /* We need to shift "count" number of bits out to the PHY. So, the value
3193 * in the "data" parameter will be shifted out to the PHY one bit at a
3194 * time. In order to do this, "data" must be broken down into bits.
3197 mask <<= (count - 1);
3199 ctrl = E1000_READ_REG(hw, CTRL);
3201 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
3202 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
3205 /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
3206 * then raising and lowering the Management Data Clock. A "0" is
3207 * shifted out to the PHY by setting the MDIO bit to "0" and then
3208 * raising and lowering the clock.
3210 if(data & mask) ctrl |= E1000_CTRL_MDIO;
3211 else ctrl &= ~E1000_CTRL_MDIO;
3213 E1000_WRITE_REG(hw, CTRL, ctrl);
3214 E1000_WRITE_FLUSH(hw);
3218 e1000_raise_mdi_clk(hw, &ctrl);
3219 e1000_lower_mdi_clk(hw, &ctrl);
3225 /******************************************************************************
3226 * Shifts data bits in from the PHY
3228 * hw - Struct containing variables accessed by shared code
3230 * Bits are shifted in in MSB to LSB order.
3231 ******************************************************************************/
3233 e1000_shift_in_mdi_bits(struct e1000_hw *hw)
3239 /* In order to read a register from the PHY, we need to shift in a total
3240 * of 18 bits from the PHY. The first two bit (turnaround) times are used
3241 * to avoid contention on the MDIO pin when a read operation is performed.
3242 * These two bits are ignored by us and thrown away. Bits are "shifted in"
3243 * by raising the input to the Management Data Clock (setting the MDC bit),
3244 * and then reading the value of the MDIO bit.
3246 ctrl = E1000_READ_REG(hw, CTRL);
3248 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
3249 ctrl &= ~E1000_CTRL_MDIO_DIR;
3250 ctrl &= ~E1000_CTRL_MDIO;
3252 E1000_WRITE_REG(hw, CTRL, ctrl);
3253 E1000_WRITE_FLUSH(hw);
3255 /* Raise and Lower the clock before reading in the data. This accounts for
3256 * the turnaround bits. The first clock occurred when we clocked out the
3257 * last bit of the Register Address.
3259 e1000_raise_mdi_clk(hw, &ctrl);
3260 e1000_lower_mdi_clk(hw, &ctrl);
3262 for(data = 0, i = 0; i < 16; i++) {
3264 e1000_raise_mdi_clk(hw, &ctrl);
3265 ctrl = E1000_READ_REG(hw, CTRL);
3266 /* Check to see if we shifted in a "1". */
3267 if(ctrl & E1000_CTRL_MDIO) data |= 1;
3268 e1000_lower_mdi_clk(hw, &ctrl);
3271 e1000_raise_mdi_clk(hw, &ctrl);
3272 e1000_lower_mdi_clk(hw, &ctrl);
3278 e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask)
3280 uint32_t swfw_sync = 0;
3281 uint32_t swmask = mask;
3282 uint32_t fwmask = mask << 16;
3283 int32_t timeout = 200;
3285 DEBUGFUNC("e1000_swfw_sync_acquire");
3287 if (hw->swfwhw_semaphore_present)
3288 return e1000_get_software_flag(hw);
3290 if (!hw->swfw_sync_present)
3291 return e1000_get_hw_eeprom_semaphore(hw);
3294 if (e1000_get_hw_eeprom_semaphore(hw))
3295 return -E1000_ERR_SWFW_SYNC;
3297 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
3298 if (!(swfw_sync & (fwmask | swmask))) {
3302 /* firmware currently using resource (fwmask) */
3303 /* or other software thread currently using resource (swmask) */
3304 e1000_put_hw_eeprom_semaphore(hw);
3310 DEBUGOUT("Driver can't access resource, SW_FW_SYNC timeout.\n");
3311 return -E1000_ERR_SWFW_SYNC;
3314 swfw_sync |= swmask;
3315 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
3317 e1000_put_hw_eeprom_semaphore(hw);
3318 return E1000_SUCCESS;
3322 e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask)
3325 uint32_t swmask = mask;
3327 DEBUGFUNC("e1000_swfw_sync_release");
3329 if (hw->swfwhw_semaphore_present) {
3330 e1000_release_software_flag(hw);
3334 if (!hw->swfw_sync_present) {
3335 e1000_put_hw_eeprom_semaphore(hw);
3339 /* if (e1000_get_hw_eeprom_semaphore(hw))
3340 * return -E1000_ERR_SWFW_SYNC; */
3341 while (e1000_get_hw_eeprom_semaphore(hw) != E1000_SUCCESS);
3344 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
3345 swfw_sync &= ~swmask;
3346 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
3348 e1000_put_hw_eeprom_semaphore(hw);
3351 /*****************************************************************************
3352 * Reads the value from a PHY register, if the value is on a specific non zero
3353 * page, sets the page first.
3354 * hw - Struct containing variables accessed by shared code
3355 * reg_addr - address of the PHY register to read
3356 ******************************************************************************/
3358 e1000_read_phy_reg(struct e1000_hw *hw,
3365 DEBUGFUNC("e1000_read_phy_reg");
3367 if ((hw->mac_type == e1000_80003es2lan) &&
3368 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3369 swfw = E1000_SWFW_PHY1_SM;
3371 swfw = E1000_SWFW_PHY0_SM;
3373 if (e1000_swfw_sync_acquire(hw, swfw))
3374 return -E1000_ERR_SWFW_SYNC;
3376 if ((hw->phy_type == e1000_phy_igp ||
3377 hw->phy_type == e1000_phy_igp_3 ||
3378 hw->phy_type == e1000_phy_igp_2) &&
3379 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
3380 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
3381 (uint16_t)reg_addr);
3383 e1000_swfw_sync_release(hw, swfw);
3386 } else if (hw->phy_type == e1000_phy_gg82563) {
3387 if (((reg_addr & MAX_PHY_REG_ADDRESS) > MAX_PHY_MULTI_PAGE_REG) ||
3388 (hw->mac_type == e1000_80003es2lan)) {
3389 /* Select Configuration Page */
3390 if ((reg_addr & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) {
3391 ret_val = e1000_write_phy_reg_ex(hw, GG82563_PHY_PAGE_SELECT,
3392 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3394 /* Use Alternative Page Select register to access
3395 * registers 30 and 31
3397 ret_val = e1000_write_phy_reg_ex(hw,
3398 GG82563_PHY_PAGE_SELECT_ALT,
3399 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3403 e1000_swfw_sync_release(hw, swfw);
3409 ret_val = e1000_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
3412 e1000_swfw_sync_release(hw, swfw);
3417 e1000_read_phy_reg_ex(struct e1000_hw *hw,
3423 const uint32_t phy_addr = 1;
3425 DEBUGFUNC("e1000_read_phy_reg_ex");
3427 if(reg_addr > MAX_PHY_REG_ADDRESS) {
3428 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
3429 return -E1000_ERR_PARAM;
3432 if(hw->mac_type > e1000_82543) {
3433 /* Set up Op-code, Phy Address, and register address in the MDI
3434 * Control register. The MAC will take care of interfacing with the
3435 * PHY to retrieve the desired data.
3437 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
3438 (phy_addr << E1000_MDIC_PHY_SHIFT) |
3439 (E1000_MDIC_OP_READ));
3441 E1000_WRITE_REG(hw, MDIC, mdic);
3443 /* Poll the ready bit to see if the MDI read completed */
3444 for(i = 0; i < 64; i++) {
3446 mdic = E1000_READ_REG(hw, MDIC);
3447 if(mdic & E1000_MDIC_READY) break;
3449 if(!(mdic & E1000_MDIC_READY)) {
3450 DEBUGOUT("MDI Read did not complete\n");
3451 return -E1000_ERR_PHY;
3453 if(mdic & E1000_MDIC_ERROR) {
3454 DEBUGOUT("MDI Error\n");
3455 return -E1000_ERR_PHY;
3457 *phy_data = (uint16_t) mdic;
3459 /* We must first send a preamble through the MDIO pin to signal the
3460 * beginning of an MII instruction. This is done by sending 32
3461 * consecutive "1" bits.
3463 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
3465 /* Now combine the next few fields that are required for a read
3466 * operation. We use this method instead of calling the
3467 * e1000_shift_out_mdi_bits routine five different times. The format of
3468 * a MII read instruction consists of a shift out of 14 bits and is
3469 * defined as follows:
3470 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
3471 * followed by a shift in of 18 bits. This first two bits shifted in
3472 * are TurnAround bits used to avoid contention on the MDIO pin when a
3473 * READ operation is performed. These two bits are thrown away
3474 * followed by a shift in of 16 bits which contains the desired data.
3476 mdic = ((reg_addr) | (phy_addr << 5) |
3477 (PHY_OP_READ << 10) | (PHY_SOF << 12));
3479 e1000_shift_out_mdi_bits(hw, mdic, 14);
3481 /* Now that we've shifted out the read command to the MII, we need to
3482 * "shift in" the 16-bit value (18 total bits) of the requested PHY
3485 *phy_data = e1000_shift_in_mdi_bits(hw);
3487 return E1000_SUCCESS;
3490 /******************************************************************************
3491 * Writes a value to a PHY register
3493 * hw - Struct containing variables accessed by shared code
3494 * reg_addr - address of the PHY register to write
3495 * data - data to write to the PHY
3496 ******************************************************************************/
3498 e1000_write_phy_reg(struct e1000_hw *hw,
3505 DEBUGFUNC("e1000_write_phy_reg");
3507 if ((hw->mac_type == e1000_80003es2lan) &&
3508 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3509 swfw = E1000_SWFW_PHY1_SM;
3511 swfw = E1000_SWFW_PHY0_SM;
3513 if (e1000_swfw_sync_acquire(hw, swfw))
3514 return -E1000_ERR_SWFW_SYNC;
3516 if ((hw->phy_type == e1000_phy_igp ||
3517 hw->phy_type == e1000_phy_igp_3 ||
3518 hw->phy_type == e1000_phy_igp_2) &&
3519 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
3520 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
3521 (uint16_t)reg_addr);
3523 e1000_swfw_sync_release(hw, swfw);
3526 } else if (hw->phy_type == e1000_phy_gg82563) {
3527 if (((reg_addr & MAX_PHY_REG_ADDRESS) > MAX_PHY_MULTI_PAGE_REG) ||
3528 (hw->mac_type == e1000_80003es2lan)) {
3529 /* Select Configuration Page */
3530 if ((reg_addr & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) {
3531 ret_val = e1000_write_phy_reg_ex(hw, GG82563_PHY_PAGE_SELECT,
3532 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3534 /* Use Alternative Page Select register to access
3535 * registers 30 and 31
3537 ret_val = e1000_write_phy_reg_ex(hw,
3538 GG82563_PHY_PAGE_SELECT_ALT,
3539 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3543 e1000_swfw_sync_release(hw, swfw);
3549 ret_val = e1000_write_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
3552 e1000_swfw_sync_release(hw, swfw);
3557 e1000_write_phy_reg_ex(struct e1000_hw *hw,
3563 const uint32_t phy_addr = 1;
3565 DEBUGFUNC("e1000_write_phy_reg_ex");
3567 if(reg_addr > MAX_PHY_REG_ADDRESS) {
3568 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
3569 return -E1000_ERR_PARAM;
3572 if(hw->mac_type > e1000_82543) {
3573 /* Set up Op-code, Phy Address, register address, and data intended
3574 * for the PHY register in the MDI Control register. The MAC will take
3575 * care of interfacing with the PHY to send the desired data.
3577 mdic = (((uint32_t) phy_data) |
3578 (reg_addr << E1000_MDIC_REG_SHIFT) |
3579 (phy_addr << E1000_MDIC_PHY_SHIFT) |
3580 (E1000_MDIC_OP_WRITE));
3582 E1000_WRITE_REG(hw, MDIC, mdic);
3584 /* Poll the ready bit to see if the MDI read completed */
3585 for(i = 0; i < 640; i++) {
3587 mdic = E1000_READ_REG(hw, MDIC);
3588 if(mdic & E1000_MDIC_READY) break;
3590 if(!(mdic & E1000_MDIC_READY)) {
3591 DEBUGOUT("MDI Write did not complete\n");
3592 return -E1000_ERR_PHY;
3595 /* We'll need to use the SW defined pins to shift the write command
3596 * out to the PHY. We first send a preamble to the PHY to signal the
3597 * beginning of the MII instruction. This is done by sending 32
3598 * consecutive "1" bits.
3600 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
3602 /* Now combine the remaining required fields that will indicate a
3603 * write operation. We use this method instead of calling the
3604 * e1000_shift_out_mdi_bits routine for each field in the command. The
3605 * format of a MII write instruction is as follows:
3606 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
3608 mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
3609 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
3611 mdic |= (uint32_t) phy_data;
3613 e1000_shift_out_mdi_bits(hw, mdic, 32);
3616 return E1000_SUCCESS;
3620 e1000_read_kmrn_reg(struct e1000_hw *hw,
3626 DEBUGFUNC("e1000_read_kmrn_reg");
3628 if ((hw->mac_type == e1000_80003es2lan) &&
3629 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3630 swfw = E1000_SWFW_PHY1_SM;
3632 swfw = E1000_SWFW_PHY0_SM;
3634 if (e1000_swfw_sync_acquire(hw, swfw))
3635 return -E1000_ERR_SWFW_SYNC;
3637 /* Write register address */
3638 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
3639 E1000_KUMCTRLSTA_OFFSET) |
3640 E1000_KUMCTRLSTA_REN;
3641 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
3644 /* Read the data returned */
3645 reg_val = E1000_READ_REG(hw, KUMCTRLSTA);
3646 *data = (uint16_t)reg_val;
3648 e1000_swfw_sync_release(hw, swfw);
3649 return E1000_SUCCESS;
3653 e1000_write_kmrn_reg(struct e1000_hw *hw,
3659 DEBUGFUNC("e1000_write_kmrn_reg");
3661 if ((hw->mac_type == e1000_80003es2lan) &&
3662 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3663 swfw = E1000_SWFW_PHY1_SM;
3665 swfw = E1000_SWFW_PHY0_SM;
3667 if (e1000_swfw_sync_acquire(hw, swfw))
3668 return -E1000_ERR_SWFW_SYNC;
3670 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
3671 E1000_KUMCTRLSTA_OFFSET) | data;
3672 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
3675 e1000_swfw_sync_release(hw, swfw);
3676 return E1000_SUCCESS;
3679 /******************************************************************************
3680 * Returns the PHY to the power-on reset state
3682 * hw - Struct containing variables accessed by shared code
3683 ******************************************************************************/
3685 e1000_phy_hw_reset(struct e1000_hw *hw)
3687 uint32_t ctrl, ctrl_ext;
3692 DEBUGFUNC("e1000_phy_hw_reset");
3694 /* In the case of the phy reset being blocked, it's not an error, we
3695 * simply return success without performing the reset. */
3696 ret_val = e1000_check_phy_reset_block(hw);
3698 return E1000_SUCCESS;
3700 DEBUGOUT("Resetting Phy...\n");
3702 if(hw->mac_type > e1000_82543) {
3703 if ((hw->mac_type == e1000_80003es2lan) &&
3704 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3705 swfw = E1000_SWFW_PHY1_SM;
3707 swfw = E1000_SWFW_PHY0_SM;
3709 if (e1000_swfw_sync_acquire(hw, swfw)) {
3710 e1000_release_software_semaphore(hw);
3711 return -E1000_ERR_SWFW_SYNC;
3713 /* Read the device control register and assert the E1000_CTRL_PHY_RST
3714 * bit. Then, take it out of reset.
3715 * For pre-e1000_82571 hardware, we delay for 10ms between the assert
3716 * and deassert. For e1000_82571 hardware and later, we instead delay
3717 * for 50us between and 10ms after the deassertion.
3719 ctrl = E1000_READ_REG(hw, CTRL);
3720 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST);
3721 E1000_WRITE_FLUSH(hw);
3723 if (hw->mac_type < e1000_82571)
3728 E1000_WRITE_REG(hw, CTRL, ctrl);
3729 E1000_WRITE_FLUSH(hw);
3731 if (hw->mac_type >= e1000_82571)
3733 e1000_swfw_sync_release(hw, swfw);
3735 /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
3736 * bit to put the PHY into reset. Then, take it out of reset.
3738 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
3739 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
3740 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
3741 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
3742 E1000_WRITE_FLUSH(hw);
3744 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
3745 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
3746 E1000_WRITE_FLUSH(hw);
3750 if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
3751 /* Configure activity LED after PHY reset */
3752 led_ctrl = E1000_READ_REG(hw, LEDCTL);
3753 led_ctrl &= IGP_ACTIVITY_LED_MASK;
3754 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
3755 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
3758 /* Wait for FW to finish PHY configuration. */
3759 ret_val = e1000_get_phy_cfg_done(hw);
3760 e1000_release_software_semaphore(hw);
3762 if ((hw->mac_type == e1000_ich8lan) &&
3763 (hw->phy_type == e1000_phy_igp_3)) {
3764 ret_val = e1000_init_lcd_from_nvm(hw);
3771 /******************************************************************************
3774 * hw - Struct containing variables accessed by shared code
3776 * Sets bit 15 of the MII Control regiser
3777 ******************************************************************************/
3779 e1000_phy_reset(struct e1000_hw *hw)
3784 DEBUGFUNC("e1000_phy_reset");
3786 /* In the case of the phy reset being blocked, it's not an error, we
3787 * simply return success without performing the reset. */
3788 ret_val = e1000_check_phy_reset_block(hw);
3790 return E1000_SUCCESS;
3792 switch (hw->mac_type) {
3793 case e1000_82541_rev_2:
3797 ret_val = e1000_phy_hw_reset(hw);
3803 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
3807 phy_data |= MII_CR_RESET;
3808 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
3816 if(hw->phy_type == e1000_phy_igp || hw->phy_type == e1000_phy_igp_2)
3817 e1000_phy_init_script(hw);
3819 return E1000_SUCCESS;
3822 /******************************************************************************
3823 * Work-around for 82566 power-down: on D3 entry-
3824 * 1) disable gigabit link
3825 * 2) write VR power-down enable
3827 * if successful continue, else issue LCD reset and repeat
3829 * hw - struct containing variables accessed by shared code
3830 ******************************************************************************/
3832 e1000_phy_powerdown_workaround(struct e1000_hw *hw)
3838 DEBUGFUNC("e1000_phy_powerdown_workaround");
3840 if (hw->phy_type != e1000_phy_igp_3)
3845 reg = E1000_READ_REG(hw, PHY_CTRL);
3846 E1000_WRITE_REG(hw, PHY_CTRL, reg | E1000_PHY_CTRL_GBE_DISABLE |
3847 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
3849 /* Write VR power-down enable */
3850 e1000_read_phy_reg(hw, IGP3_VR_CTRL, &phy_data);
3851 e1000_write_phy_reg(hw, IGP3_VR_CTRL, phy_data |
3852 IGP3_VR_CTRL_MODE_SHUT);
3854 /* Read it back and test */
3855 e1000_read_phy_reg(hw, IGP3_VR_CTRL, &phy_data);
3856 if ((phy_data & IGP3_VR_CTRL_MODE_SHUT) || retry)
3859 /* Issue PHY reset and repeat at most one more time */
3860 reg = E1000_READ_REG(hw, CTRL);
3861 E1000_WRITE_REG(hw, CTRL, reg | E1000_CTRL_PHY_RST);
3869 /******************************************************************************
3870 * Work-around for 82566 Kumeran PCS lock loss:
3871 * On link status change (i.e. PCI reset, speed change) and link is up and
3873 * 0) if workaround is optionally disabled do nothing
3874 * 1) wait 1ms for Kumeran link to come up
3875 * 2) check Kumeran Diagnostic register PCS lock loss bit
3876 * 3) if not set the link is locked (all is good), otherwise...
3878 * 5) repeat up to 10 times
3879 * Note: this is only called for IGP3 copper when speed is 1gb.
3881 * hw - struct containing variables accessed by shared code
3882 ******************************************************************************/
3884 e1000_kumeran_lock_loss_workaround(struct e1000_hw *hw)
3891 if (hw->kmrn_lock_loss_workaround_disabled)
3892 return E1000_SUCCESS;
3894 /* Make sure link is up before proceeding. If not just return.
3895 * Attempting this while link is negotiating fouls up link
3897 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3898 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3900 if (phy_data & MII_SR_LINK_STATUS) {
3901 for (cnt = 0; cnt < 10; cnt++) {
3902 /* read once to clear */
3903 ret_val = e1000_read_phy_reg(hw, IGP3_KMRN_DIAG, &phy_data);
3906 /* and again to get new status */
3907 ret_val = e1000_read_phy_reg(hw, IGP3_KMRN_DIAG, &phy_data);
3911 /* check for PCS lock */
3912 if (!(phy_data & IGP3_KMRN_DIAG_PCS_LOCK_LOSS))
3913 return E1000_SUCCESS;
3915 /* Issue PHY reset */
3916 e1000_phy_hw_reset(hw);
3919 /* Disable GigE link negotiation */
3920 reg = E1000_READ_REG(hw, PHY_CTRL);
3921 E1000_WRITE_REG(hw, PHY_CTRL, reg | E1000_PHY_CTRL_GBE_DISABLE |
3922 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
3924 /* unable to acquire PCS lock */
3925 return E1000_ERR_PHY;
3928 return E1000_SUCCESS;
3931 /******************************************************************************
3932 * Probes the expected PHY address for known PHY IDs
3934 * hw - Struct containing variables accessed by shared code
3935 ******************************************************************************/
3937 e1000_detect_gig_phy(struct e1000_hw *hw)
3939 int32_t phy_init_status, ret_val;
3940 uint16_t phy_id_high, phy_id_low;
3941 boolean_t match = FALSE;
3943 DEBUGFUNC("e1000_detect_gig_phy");
3945 /* The 82571 firmware may still be configuring the PHY. In this
3946 * case, we cannot access the PHY until the configuration is done. So
3947 * we explicitly set the PHY values. */
3948 if (hw->mac_type == e1000_82571 ||
3949 hw->mac_type == e1000_82572) {
3950 hw->phy_id = IGP01E1000_I_PHY_ID;
3951 hw->phy_type = e1000_phy_igp_2;
3952 return E1000_SUCCESS;
3955 /* ESB-2 PHY reads require e1000_phy_gg82563 to be set because of a work-
3956 * around that forces PHY page 0 to be set or the reads fail. The rest of
3957 * the code in this routine uses e1000_read_phy_reg to read the PHY ID.
3958 * So for ESB-2 we need to have this set so our reads won't fail. If the
3959 * attached PHY is not a e1000_phy_gg82563, the routines below will figure
3960 * this out as well. */
3961 if (hw->mac_type == e1000_80003es2lan)
3962 hw->phy_type = e1000_phy_gg82563;
3964 /* Read the PHY ID Registers to identify which PHY is onboard. */
3965 ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
3969 hw->phy_id = (uint32_t) (phy_id_high << 16);
3971 ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
3975 hw->phy_id |= (uint32_t) (phy_id_low & PHY_REVISION_MASK);
3976 hw->phy_revision = (uint32_t) phy_id_low & ~PHY_REVISION_MASK;
3978 switch(hw->mac_type) {
3980 if(hw->phy_id == M88E1000_E_PHY_ID) match = TRUE;
3983 if(hw->phy_id == M88E1000_I_PHY_ID) match = TRUE;
3987 case e1000_82545_rev_3:
3989 case e1000_82546_rev_3:
3990 if(hw->phy_id == M88E1011_I_PHY_ID) match = TRUE;
3993 case e1000_82541_rev_2:
3995 case e1000_82547_rev_2:
3996 if(hw->phy_id == IGP01E1000_I_PHY_ID) match = TRUE;
3999 if(hw->phy_id == M88E1111_I_PHY_ID) match = TRUE;
4001 case e1000_80003es2lan:
4002 if (hw->phy_id == GG82563_E_PHY_ID) match = TRUE;
4005 if (hw->phy_id == IGP03E1000_E_PHY_ID) match = TRUE;
4006 if (hw->phy_id == IFE_E_PHY_ID) match = TRUE;
4007 if (hw->phy_id == IFE_PLUS_E_PHY_ID) match = TRUE;
4008 if (hw->phy_id == IFE_C_E_PHY_ID) match = TRUE;
4011 DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type);
4012 return -E1000_ERR_CONFIG;
4014 phy_init_status = e1000_set_phy_type(hw);
4016 if ((match) && (phy_init_status == E1000_SUCCESS)) {
4017 DEBUGOUT1("PHY ID 0x%X detected\n", hw->phy_id);
4018 return E1000_SUCCESS;
4020 DEBUGOUT1("Invalid PHY ID 0x%X\n", hw->phy_id);
4021 return -E1000_ERR_PHY;
4024 /******************************************************************************
4025 * Resets the PHY's DSP
4027 * hw - Struct containing variables accessed by shared code
4028 ******************************************************************************/
4030 e1000_phy_reset_dsp(struct e1000_hw *hw)
4033 DEBUGFUNC("e1000_phy_reset_dsp");
4036 if (hw->phy_type != e1000_phy_gg82563) {
4037 ret_val = e1000_write_phy_reg(hw, 29, 0x001d);
4040 ret_val = e1000_write_phy_reg(hw, 30, 0x00c1);
4042 ret_val = e1000_write_phy_reg(hw, 30, 0x0000);
4044 ret_val = E1000_SUCCESS;
4050 /******************************************************************************
4051 * Get PHY information from various PHY registers for igp PHY only.
4053 * hw - Struct containing variables accessed by shared code
4054 * phy_info - PHY information structure
4055 ******************************************************************************/
4057 e1000_phy_igp_get_info(struct e1000_hw *hw,
4058 struct e1000_phy_info *phy_info)
4061 uint16_t phy_data, polarity, min_length, max_length, average;
4063 DEBUGFUNC("e1000_phy_igp_get_info");
4065 /* The downshift status is checked only once, after link is established,
4066 * and it stored in the hw->speed_downgraded parameter. */
4067 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
4069 /* IGP01E1000 does not need to support it. */
4070 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
4072 /* IGP01E1000 always correct polarity reversal */
4073 phy_info->polarity_correction = e1000_polarity_reversal_enabled;
4075 /* Check polarity status */
4076 ret_val = e1000_check_polarity(hw, &polarity);
4080 phy_info->cable_polarity = polarity;
4082 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, &phy_data);
4086 phy_info->mdix_mode = (phy_data & IGP01E1000_PSSR_MDIX) >>
4087 IGP01E1000_PSSR_MDIX_SHIFT;
4089 if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
4090 IGP01E1000_PSSR_SPEED_1000MBPS) {
4091 /* Local/Remote Receiver Information are only valid at 1000 Mbps */
4092 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
4096 phy_info->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS) >>
4097 SR_1000T_LOCAL_RX_STATUS_SHIFT;
4098 phy_info->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS) >>
4099 SR_1000T_REMOTE_RX_STATUS_SHIFT;
4101 /* Get cable length */
4102 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
4106 /* Translate to old method */
4107 average = (max_length + min_length) / 2;
4109 if(average <= e1000_igp_cable_length_50)
4110 phy_info->cable_length = e1000_cable_length_50;
4111 else if(average <= e1000_igp_cable_length_80)
4112 phy_info->cable_length = e1000_cable_length_50_80;
4113 else if(average <= e1000_igp_cable_length_110)
4114 phy_info->cable_length = e1000_cable_length_80_110;
4115 else if(average <= e1000_igp_cable_length_140)
4116 phy_info->cable_length = e1000_cable_length_110_140;
4118 phy_info->cable_length = e1000_cable_length_140;
4121 return E1000_SUCCESS;
4124 /******************************************************************************
4125 * Get PHY information from various PHY registers for ife PHY only.
4127 * hw - Struct containing variables accessed by shared code
4128 * phy_info - PHY information structure
4129 ******************************************************************************/
4131 e1000_phy_ife_get_info(struct e1000_hw *hw,
4132 struct e1000_phy_info *phy_info)
4135 uint16_t phy_data, polarity;
4137 DEBUGFUNC("e1000_phy_ife_get_info");
4139 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
4140 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
4142 ret_val = e1000_read_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL, &phy_data);
4145 phy_info->polarity_correction =
4146 (phy_data & IFE_PSC_AUTO_POLARITY_DISABLE) >>
4147 IFE_PSC_AUTO_POLARITY_DISABLE_SHIFT;
4149 if (phy_info->polarity_correction == e1000_polarity_reversal_enabled) {
4150 ret_val = e1000_check_polarity(hw, &polarity);
4154 /* Polarity is forced. */
4155 polarity = (phy_data & IFE_PSC_FORCE_POLARITY) >>
4156 IFE_PSC_FORCE_POLARITY_SHIFT;
4158 phy_info->cable_polarity = polarity;
4160 ret_val = e1000_read_phy_reg(hw, IFE_PHY_MDIX_CONTROL, &phy_data);
4164 phy_info->mdix_mode =
4165 (phy_data & (IFE_PMC_AUTO_MDIX | IFE_PMC_FORCE_MDIX)) >>
4166 IFE_PMC_MDIX_MODE_SHIFT;
4168 return E1000_SUCCESS;
4171 /******************************************************************************
4172 * Get PHY information from various PHY registers fot m88 PHY only.
4174 * hw - Struct containing variables accessed by shared code
4175 * phy_info - PHY information structure
4176 ******************************************************************************/
4178 e1000_phy_m88_get_info(struct e1000_hw *hw,
4179 struct e1000_phy_info *phy_info)
4182 uint16_t phy_data, polarity;
4184 DEBUGFUNC("e1000_phy_m88_get_info");
4186 /* The downshift status is checked only once, after link is established,
4187 * and it stored in the hw->speed_downgraded parameter. */
4188 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
4190 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
4194 phy_info->extended_10bt_distance =
4195 (phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >>
4196 M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT;
4197 phy_info->polarity_correction =
4198 (phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >>
4199 M88E1000_PSCR_POLARITY_REVERSAL_SHIFT;
4201 /* Check polarity status */
4202 ret_val = e1000_check_polarity(hw, &polarity);
4205 phy_info->cable_polarity = polarity;
4207 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
4211 phy_info->mdix_mode = (phy_data & M88E1000_PSSR_MDIX) >>
4212 M88E1000_PSSR_MDIX_SHIFT;
4214 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
4215 /* Cable Length Estimation and Local/Remote Receiver Information
4216 * are only valid at 1000 Mbps.
4218 if (hw->phy_type != e1000_phy_gg82563) {
4219 phy_info->cable_length = ((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
4220 M88E1000_PSSR_CABLE_LENGTH_SHIFT);
4222 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_DSP_DISTANCE,
4227 phy_info->cable_length = phy_data & GG82563_DSPD_CABLE_LENGTH;
4230 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
4234 phy_info->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS) >>
4235 SR_1000T_LOCAL_RX_STATUS_SHIFT;
4237 phy_info->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS) >>
4238 SR_1000T_REMOTE_RX_STATUS_SHIFT;
4241 return E1000_SUCCESS;
4244 /******************************************************************************
4245 * Get PHY information from various PHY registers
4247 * hw - Struct containing variables accessed by shared code
4248 * phy_info - PHY information structure
4249 ******************************************************************************/
4251 e1000_phy_get_info(struct e1000_hw *hw,
4252 struct e1000_phy_info *phy_info)
4257 DEBUGFUNC("e1000_phy_get_info");
4259 phy_info->cable_length = e1000_cable_length_undefined;
4260 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined;
4261 phy_info->cable_polarity = e1000_rev_polarity_undefined;
4262 phy_info->downshift = e1000_downshift_undefined;
4263 phy_info->polarity_correction = e1000_polarity_reversal_undefined;
4264 phy_info->mdix_mode = e1000_auto_x_mode_undefined;
4265 phy_info->local_rx = e1000_1000t_rx_status_undefined;
4266 phy_info->remote_rx = e1000_1000t_rx_status_undefined;
4268 if(hw->media_type != e1000_media_type_copper) {
4269 DEBUGOUT("PHY info is only valid for copper media\n");
4270 return -E1000_ERR_CONFIG;
4273 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
4277 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
4281 if((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) {
4282 DEBUGOUT("PHY info is only valid if link is up\n");
4283 return -E1000_ERR_CONFIG;
4286 if (hw->phy_type == e1000_phy_igp ||
4287 hw->phy_type == e1000_phy_igp_3 ||
4288 hw->phy_type == e1000_phy_igp_2)
4289 return e1000_phy_igp_get_info(hw, phy_info);
4290 else if (hw->phy_type == e1000_phy_ife)
4291 return e1000_phy_ife_get_info(hw, phy_info);
4293 return e1000_phy_m88_get_info(hw, phy_info);
4297 e1000_validate_mdi_setting(struct e1000_hw *hw)
4299 DEBUGFUNC("e1000_validate_mdi_settings");
4301 if(!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) {
4302 DEBUGOUT("Invalid MDI setting detected\n");
4304 return -E1000_ERR_CONFIG;
4306 return E1000_SUCCESS;
4310 /******************************************************************************
4311 * Sets up eeprom variables in the hw struct. Must be called after mac_type
4312 * is configured. Additionally, if this is ICH8, the flash controller GbE
4313 * registers must be mapped, or this will crash.
4315 * hw - Struct containing variables accessed by shared code
4316 *****************************************************************************/
4318 e1000_init_eeprom_params(struct e1000_hw *hw)
4320 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4321 uint32_t eecd = E1000_READ_REG(hw, EECD);
4322 int32_t ret_val = E1000_SUCCESS;
4323 uint16_t eeprom_size;
4325 DEBUGFUNC("e1000_init_eeprom_params");
4327 switch (hw->mac_type) {
4328 case e1000_82542_rev2_0:
4329 case e1000_82542_rev2_1:
4332 eeprom->type = e1000_eeprom_microwire;
4333 eeprom->word_size = 64;
4334 eeprom->opcode_bits = 3;
4335 eeprom->address_bits = 6;
4336 eeprom->delay_usec = 50;
4337 eeprom->use_eerd = FALSE;
4338 eeprom->use_eewr = FALSE;
4342 case e1000_82545_rev_3:
4344 case e1000_82546_rev_3:
4345 eeprom->type = e1000_eeprom_microwire;
4346 eeprom->opcode_bits = 3;
4347 eeprom->delay_usec = 50;
4348 if(eecd & E1000_EECD_SIZE) {
4349 eeprom->word_size = 256;
4350 eeprom->address_bits = 8;
4352 eeprom->word_size = 64;
4353 eeprom->address_bits = 6;
4355 eeprom->use_eerd = FALSE;
4356 eeprom->use_eewr = FALSE;
4359 case e1000_82541_rev_2:
4361 case e1000_82547_rev_2:
4362 if (eecd & E1000_EECD_TYPE) {
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;
4374 eeprom->type = e1000_eeprom_microwire;
4375 eeprom->opcode_bits = 3;
4376 eeprom->delay_usec = 50;
4377 if (eecd & E1000_EECD_ADDR_BITS) {
4378 eeprom->word_size = 256;
4379 eeprom->address_bits = 8;
4381 eeprom->word_size = 64;
4382 eeprom->address_bits = 6;
4385 eeprom->use_eerd = FALSE;
4386 eeprom->use_eewr = FALSE;
4390 eeprom->type = e1000_eeprom_spi;
4391 eeprom->opcode_bits = 8;
4392 eeprom->delay_usec = 1;
4393 if (eecd & E1000_EECD_ADDR_BITS) {
4394 eeprom->page_size = 32;
4395 eeprom->address_bits = 16;
4397 eeprom->page_size = 8;
4398 eeprom->address_bits = 8;
4400 eeprom->use_eerd = FALSE;
4401 eeprom->use_eewr = FALSE;
4404 eeprom->type = e1000_eeprom_spi;
4405 eeprom->opcode_bits = 8;
4406 eeprom->delay_usec = 1;
4407 if (eecd & E1000_EECD_ADDR_BITS) {
4408 eeprom->page_size = 32;
4409 eeprom->address_bits = 16;
4411 eeprom->page_size = 8;
4412 eeprom->address_bits = 8;
4414 eeprom->use_eerd = TRUE;
4415 eeprom->use_eewr = TRUE;
4416 if(e1000_is_onboard_nvm_eeprom(hw) == FALSE) {
4417 eeprom->type = e1000_eeprom_flash;
4418 eeprom->word_size = 2048;
4420 /* Ensure that the Autonomous FLASH update bit is cleared due to
4421 * Flash update issue on parts which use a FLASH for NVM. */
4422 eecd &= ~E1000_EECD_AUPDEN;
4423 E1000_WRITE_REG(hw, EECD, eecd);
4426 case e1000_80003es2lan:
4427 eeprom->type = e1000_eeprom_spi;
4428 eeprom->opcode_bits = 8;
4429 eeprom->delay_usec = 1;
4430 if (eecd & E1000_EECD_ADDR_BITS) {
4431 eeprom->page_size = 32;
4432 eeprom->address_bits = 16;
4434 eeprom->page_size = 8;
4435 eeprom->address_bits = 8;
4437 eeprom->use_eerd = TRUE;
4438 eeprom->use_eewr = FALSE;
4443 uint32_t flash_size = E1000_READ_ICH8_REG(hw, ICH8_FLASH_GFPREG);
4445 eeprom->type = e1000_eeprom_ich8;
4446 eeprom->use_eerd = FALSE;
4447 eeprom->use_eewr = FALSE;
4448 eeprom->word_size = E1000_SHADOW_RAM_WORDS;
4450 /* Zero the shadow RAM structure. But don't load it from NVM
4451 * so as to save time for driver init */
4452 if (hw->eeprom_shadow_ram != NULL) {
4453 for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
4454 hw->eeprom_shadow_ram[i].modified = FALSE;
4455 hw->eeprom_shadow_ram[i].eeprom_word = 0xFFFF;
4459 hw->flash_base_addr = (flash_size & ICH8_GFPREG_BASE_MASK) *
4460 ICH8_FLASH_SECTOR_SIZE;
4462 hw->flash_bank_size = ((flash_size >> 16) & ICH8_GFPREG_BASE_MASK) + 1;
4463 hw->flash_bank_size -= (flash_size & ICH8_GFPREG_BASE_MASK);
4464 hw->flash_bank_size *= ICH8_FLASH_SECTOR_SIZE;
4465 hw->flash_bank_size /= 2 * sizeof(uint16_t);
4473 if (eeprom->type == e1000_eeprom_spi) {
4474 /* eeprom_size will be an enum [0..8] that maps to eeprom sizes 128B to
4475 * 32KB (incremented by powers of 2).
4477 if(hw->mac_type <= e1000_82547_rev_2) {
4478 /* Set to default value for initial eeprom read. */
4479 eeprom->word_size = 64;
4480 ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size);
4483 eeprom_size = (eeprom_size & EEPROM_SIZE_MASK) >> EEPROM_SIZE_SHIFT;
4484 /* 256B eeprom size was not supported in earlier hardware, so we
4485 * bump eeprom_size up one to ensure that "1" (which maps to 256B)
4486 * is never the result used in the shifting logic below. */
4490 eeprom_size = (uint16_t)((eecd & E1000_EECD_SIZE_EX_MASK) >>
4491 E1000_EECD_SIZE_EX_SHIFT);
4494 eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT);
4499 /******************************************************************************
4500 * Raises the EEPROM's clock input.
4502 * hw - Struct containing variables accessed by shared code
4503 * eecd - EECD's current value
4504 *****************************************************************************/
4506 e1000_raise_ee_clk(struct e1000_hw *hw,
4509 /* Raise the clock input to the EEPROM (by setting the SK bit), and then
4510 * wait <delay> microseconds.
4512 *eecd = *eecd | E1000_EECD_SK;
4513 E1000_WRITE_REG(hw, EECD, *eecd);
4514 E1000_WRITE_FLUSH(hw);
4515 udelay(hw->eeprom.delay_usec);
4518 /******************************************************************************
4519 * Lowers the EEPROM's clock input.
4521 * hw - Struct containing variables accessed by shared code
4522 * eecd - EECD's current value
4523 *****************************************************************************/
4525 e1000_lower_ee_clk(struct e1000_hw *hw,
4528 /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
4529 * wait 50 microseconds.
4531 *eecd = *eecd & ~E1000_EECD_SK;
4532 E1000_WRITE_REG(hw, EECD, *eecd);
4533 E1000_WRITE_FLUSH(hw);
4534 udelay(hw->eeprom.delay_usec);
4537 /******************************************************************************
4538 * Shift data bits out to the EEPROM.
4540 * hw - Struct containing variables accessed by shared code
4541 * data - data to send to the EEPROM
4542 * count - number of bits to shift out
4543 *****************************************************************************/
4545 e1000_shift_out_ee_bits(struct e1000_hw *hw,
4549 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4553 /* We need to shift "count" bits out to the EEPROM. So, value in the
4554 * "data" parameter will be shifted out to the EEPROM one bit at a time.
4555 * In order to do this, "data" must be broken down into bits.
4557 mask = 0x01 << (count - 1);
4558 eecd = E1000_READ_REG(hw, EECD);
4559 if (eeprom->type == e1000_eeprom_microwire) {
4560 eecd &= ~E1000_EECD_DO;
4561 } else if (eeprom->type == e1000_eeprom_spi) {
4562 eecd |= E1000_EECD_DO;
4565 /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
4566 * and then raising and then lowering the clock (the SK bit controls
4567 * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
4568 * by setting "DI" to "0" and then raising and then lowering the clock.
4570 eecd &= ~E1000_EECD_DI;
4573 eecd |= E1000_EECD_DI;
4575 E1000_WRITE_REG(hw, EECD, eecd);
4576 E1000_WRITE_FLUSH(hw);
4578 udelay(eeprom->delay_usec);
4580 e1000_raise_ee_clk(hw, &eecd);
4581 e1000_lower_ee_clk(hw, &eecd);
4587 /* We leave the "DI" bit set to "0" when we leave this routine. */
4588 eecd &= ~E1000_EECD_DI;
4589 E1000_WRITE_REG(hw, EECD, eecd);
4592 /******************************************************************************
4593 * Shift data bits in from the EEPROM
4595 * hw - Struct containing variables accessed by shared code
4596 *****************************************************************************/
4598 e1000_shift_in_ee_bits(struct e1000_hw *hw,
4605 /* In order to read a register from the EEPROM, we need to shift 'count'
4606 * bits in from the EEPROM. Bits are "shifted in" by raising the clock
4607 * input to the EEPROM (setting the SK bit), and then reading the value of
4608 * the "DO" bit. During this "shifting in" process the "DI" bit should
4612 eecd = E1000_READ_REG(hw, EECD);
4614 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
4617 for(i = 0; i < count; i++) {
4619 e1000_raise_ee_clk(hw, &eecd);
4621 eecd = E1000_READ_REG(hw, EECD);
4623 eecd &= ~(E1000_EECD_DI);
4624 if(eecd & E1000_EECD_DO)
4627 e1000_lower_ee_clk(hw, &eecd);
4633 /******************************************************************************
4634 * Prepares EEPROM for access
4636 * hw - Struct containing variables accessed by shared code
4638 * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
4639 * function should be called before issuing a command to the EEPROM.
4640 *****************************************************************************/
4642 e1000_acquire_eeprom(struct e1000_hw *hw)
4644 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4647 DEBUGFUNC("e1000_acquire_eeprom");
4649 if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
4650 return -E1000_ERR_SWFW_SYNC;
4651 eecd = E1000_READ_REG(hw, EECD);
4653 if (hw->mac_type != e1000_82573) {
4654 /* Request EEPROM Access */
4655 if(hw->mac_type > e1000_82544) {
4656 eecd |= E1000_EECD_REQ;
4657 E1000_WRITE_REG(hw, EECD, eecd);
4658 eecd = E1000_READ_REG(hw, EECD);
4659 while((!(eecd & E1000_EECD_GNT)) &&
4660 (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
4663 eecd = E1000_READ_REG(hw, EECD);
4665 if(!(eecd & E1000_EECD_GNT)) {
4666 eecd &= ~E1000_EECD_REQ;
4667 E1000_WRITE_REG(hw, EECD, eecd);
4668 DEBUGOUT("Could not acquire EEPROM grant\n");
4669 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
4670 return -E1000_ERR_EEPROM;
4675 /* Setup EEPROM for Read/Write */
4677 if (eeprom->type == e1000_eeprom_microwire) {
4678 /* Clear SK and DI */
4679 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
4680 E1000_WRITE_REG(hw, EECD, eecd);
4683 eecd |= E1000_EECD_CS;
4684 E1000_WRITE_REG(hw, EECD, eecd);
4685 } else if (eeprom->type == e1000_eeprom_spi) {
4686 /* Clear SK and CS */
4687 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
4688 E1000_WRITE_REG(hw, EECD, eecd);
4692 return E1000_SUCCESS;
4695 /******************************************************************************
4696 * Returns EEPROM to a "standby" state
4698 * hw - Struct containing variables accessed by shared code
4699 *****************************************************************************/
4701 e1000_standby_eeprom(struct e1000_hw *hw)
4703 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4706 eecd = E1000_READ_REG(hw, EECD);
4708 if(eeprom->type == e1000_eeprom_microwire) {
4709 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
4710 E1000_WRITE_REG(hw, EECD, eecd);
4711 E1000_WRITE_FLUSH(hw);
4712 udelay(eeprom->delay_usec);
4715 eecd |= E1000_EECD_SK;
4716 E1000_WRITE_REG(hw, EECD, eecd);
4717 E1000_WRITE_FLUSH(hw);
4718 udelay(eeprom->delay_usec);
4721 eecd |= E1000_EECD_CS;
4722 E1000_WRITE_REG(hw, EECD, eecd);
4723 E1000_WRITE_FLUSH(hw);
4724 udelay(eeprom->delay_usec);
4727 eecd &= ~E1000_EECD_SK;
4728 E1000_WRITE_REG(hw, EECD, eecd);
4729 E1000_WRITE_FLUSH(hw);
4730 udelay(eeprom->delay_usec);
4731 } else if(eeprom->type == e1000_eeprom_spi) {
4732 /* Toggle CS to flush commands */
4733 eecd |= E1000_EECD_CS;
4734 E1000_WRITE_REG(hw, EECD, eecd);
4735 E1000_WRITE_FLUSH(hw);
4736 udelay(eeprom->delay_usec);
4737 eecd &= ~E1000_EECD_CS;
4738 E1000_WRITE_REG(hw, EECD, eecd);
4739 E1000_WRITE_FLUSH(hw);
4740 udelay(eeprom->delay_usec);
4744 /******************************************************************************
4745 * Terminates a command by inverting the EEPROM's chip select pin
4747 * hw - Struct containing variables accessed by shared code
4748 *****************************************************************************/
4750 e1000_release_eeprom(struct e1000_hw *hw)
4754 DEBUGFUNC("e1000_release_eeprom");
4756 eecd = E1000_READ_REG(hw, EECD);
4758 if (hw->eeprom.type == e1000_eeprom_spi) {
4759 eecd |= E1000_EECD_CS; /* Pull CS high */
4760 eecd &= ~E1000_EECD_SK; /* Lower SCK */
4762 E1000_WRITE_REG(hw, EECD, eecd);
4764 udelay(hw->eeprom.delay_usec);
4765 } else if(hw->eeprom.type == e1000_eeprom_microwire) {
4766 /* cleanup eeprom */
4768 /* CS on Microwire is active-high */
4769 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
4771 E1000_WRITE_REG(hw, EECD, eecd);
4773 /* Rising edge of clock */
4774 eecd |= E1000_EECD_SK;
4775 E1000_WRITE_REG(hw, EECD, eecd);
4776 E1000_WRITE_FLUSH(hw);
4777 udelay(hw->eeprom.delay_usec);
4779 /* Falling edge of clock */
4780 eecd &= ~E1000_EECD_SK;
4781 E1000_WRITE_REG(hw, EECD, eecd);
4782 E1000_WRITE_FLUSH(hw);
4783 udelay(hw->eeprom.delay_usec);
4786 /* Stop requesting EEPROM access */
4787 if(hw->mac_type > e1000_82544) {
4788 eecd &= ~E1000_EECD_REQ;
4789 E1000_WRITE_REG(hw, EECD, eecd);
4792 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
4795 /******************************************************************************
4796 * Reads a 16 bit word from the EEPROM.
4798 * hw - Struct containing variables accessed by shared code
4799 *****************************************************************************/
4801 e1000_spi_eeprom_ready(struct e1000_hw *hw)
4803 uint16_t retry_count = 0;
4804 uint8_t spi_stat_reg;
4806 DEBUGFUNC("e1000_spi_eeprom_ready");
4808 /* Read "Status Register" repeatedly until the LSB is cleared. The
4809 * EEPROM will signal that the command has been completed by clearing
4810 * bit 0 of the internal status register. If it's not cleared within
4811 * 5 milliseconds, then error out.
4815 e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
4816 hw->eeprom.opcode_bits);
4817 spi_stat_reg = (uint8_t)e1000_shift_in_ee_bits(hw, 8);
4818 if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
4824 e1000_standby_eeprom(hw);
4825 } while(retry_count < EEPROM_MAX_RETRY_SPI);
4827 /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
4828 * only 0-5mSec on 5V devices)
4830 if(retry_count >= EEPROM_MAX_RETRY_SPI) {
4831 DEBUGOUT("SPI EEPROM Status error\n");
4832 return -E1000_ERR_EEPROM;
4835 return E1000_SUCCESS;
4838 /******************************************************************************
4839 * Reads a 16 bit word from the EEPROM.
4841 * hw - Struct containing variables accessed by shared code
4842 * offset - offset of word in the EEPROM to read
4843 * data - word read from the EEPROM
4844 * words - number of words to read
4845 *****************************************************************************/
4847 e1000_read_eeprom(struct e1000_hw *hw,
4852 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4856 DEBUGFUNC("e1000_read_eeprom");
4858 /* A check for invalid values: offset too large, too many words, and not
4861 if((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
4863 DEBUGOUT("\"words\" parameter out of bounds\n");
4864 return -E1000_ERR_EEPROM;
4867 /* FLASH reads without acquiring the semaphore are safe */
4868 if (e1000_is_onboard_nvm_eeprom(hw) == TRUE &&
4869 hw->eeprom.use_eerd == FALSE) {
4870 switch (hw->mac_type) {
4871 case e1000_80003es2lan:
4874 /* Prepare the EEPROM for reading */
4875 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
4876 return -E1000_ERR_EEPROM;
4881 if (eeprom->use_eerd == TRUE) {
4882 ret_val = e1000_read_eeprom_eerd(hw, offset, words, data);
4883 if ((e1000_is_onboard_nvm_eeprom(hw) == TRUE) ||
4884 (hw->mac_type != e1000_82573))
4885 e1000_release_eeprom(hw);
4889 if (eeprom->type == e1000_eeprom_ich8)
4890 return e1000_read_eeprom_ich8(hw, offset, words, data);
4892 if (eeprom->type == e1000_eeprom_spi) {
4894 uint8_t read_opcode = EEPROM_READ_OPCODE_SPI;
4896 if(e1000_spi_eeprom_ready(hw)) {
4897 e1000_release_eeprom(hw);
4898 return -E1000_ERR_EEPROM;
4901 e1000_standby_eeprom(hw);
4903 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
4904 if((eeprom->address_bits == 8) && (offset >= 128))
4905 read_opcode |= EEPROM_A8_OPCODE_SPI;
4907 /* Send the READ command (opcode + addr) */
4908 e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
4909 e1000_shift_out_ee_bits(hw, (uint16_t)(offset*2), eeprom->address_bits);
4911 /* Read the data. The address of the eeprom internally increments with
4912 * each byte (spi) being read, saving on the overhead of eeprom setup
4913 * and tear-down. The address counter will roll over if reading beyond
4914 * the size of the eeprom, thus allowing the entire memory to be read
4915 * starting from any offset. */
4916 for (i = 0; i < words; i++) {
4917 word_in = e1000_shift_in_ee_bits(hw, 16);
4918 data[i] = (word_in >> 8) | (word_in << 8);
4920 } else if(eeprom->type == e1000_eeprom_microwire) {
4921 for (i = 0; i < words; i++) {
4922 /* Send the READ command (opcode + addr) */
4923 e1000_shift_out_ee_bits(hw, EEPROM_READ_OPCODE_MICROWIRE,
4924 eeprom->opcode_bits);
4925 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + i),
4926 eeprom->address_bits);
4928 /* Read the data. For microwire, each word requires the overhead
4929 * of eeprom setup and tear-down. */
4930 data[i] = e1000_shift_in_ee_bits(hw, 16);
4931 e1000_standby_eeprom(hw);
4935 /* End this read operation */
4936 e1000_release_eeprom(hw);
4938 return E1000_SUCCESS;
4941 /******************************************************************************
4942 * Reads a 16 bit word from the EEPROM using the EERD register.
4944 * hw - Struct containing variables accessed by shared code
4945 * offset - offset of word in the EEPROM to read
4946 * data - word read from the EEPROM
4947 * words - number of words to read
4948 *****************************************************************************/
4950 e1000_read_eeprom_eerd(struct e1000_hw *hw,
4955 uint32_t i, eerd = 0;
4958 for (i = 0; i < words; i++) {
4959 eerd = ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) +
4960 E1000_EEPROM_RW_REG_START;
4962 E1000_WRITE_REG(hw, EERD, eerd);
4963 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_READ);
4968 data[i] = (E1000_READ_REG(hw, EERD) >> E1000_EEPROM_RW_REG_DATA);
4975 /******************************************************************************
4976 * Writes a 16 bit word from the EEPROM using the EEWR register.
4978 * hw - Struct containing variables accessed by shared code
4979 * offset - offset of word in the EEPROM to read
4980 * data - word read from the EEPROM
4981 * words - number of words to read
4982 *****************************************************************************/
4984 e1000_write_eeprom_eewr(struct e1000_hw *hw,
4989 uint32_t register_value = 0;
4993 if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
4994 return -E1000_ERR_SWFW_SYNC;
4996 for (i = 0; i < words; i++) {
4997 register_value = (data[i] << E1000_EEPROM_RW_REG_DATA) |
4998 ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) |
4999 E1000_EEPROM_RW_REG_START;
5001 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
5006 E1000_WRITE_REG(hw, EEWR, register_value);
5008 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
5015 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
5019 /******************************************************************************
5020 * Polls the status bit (bit 1) of the EERD to determine when the read is done.
5022 * hw - Struct containing variables accessed by shared code
5023 *****************************************************************************/
5025 e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd)
5027 uint32_t attempts = 100000;
5028 uint32_t i, reg = 0;
5029 int32_t done = E1000_ERR_EEPROM;
5031 for(i = 0; i < attempts; i++) {
5032 if(eerd == E1000_EEPROM_POLL_READ)
5033 reg = E1000_READ_REG(hw, EERD);
5035 reg = E1000_READ_REG(hw, EEWR);
5037 if(reg & E1000_EEPROM_RW_REG_DONE) {
5038 done = E1000_SUCCESS;
5047 /***************************************************************************
5048 * Description: Determines if the onboard NVM is FLASH or EEPROM.
5050 * hw - Struct containing variables accessed by shared code
5051 ****************************************************************************/
5053 e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw)
5057 DEBUGFUNC("e1000_is_onboard_nvm_eeprom");
5059 if (hw->mac_type == e1000_ich8lan)
5062 if (hw->mac_type == e1000_82573) {
5063 eecd = E1000_READ_REG(hw, EECD);
5065 /* Isolate bits 15 & 16 */
5066 eecd = ((eecd >> 15) & 0x03);
5068 /* If both bits are set, device is Flash type */
5076 /******************************************************************************
5077 * Verifies that the EEPROM has a valid checksum
5079 * hw - Struct containing variables accessed by shared code
5081 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
5082 * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
5084 *****************************************************************************/
5086 e1000_validate_eeprom_checksum(struct e1000_hw *hw)
5088 uint16_t checksum = 0;
5089 uint16_t i, eeprom_data;
5091 DEBUGFUNC("e1000_validate_eeprom_checksum");
5093 if ((hw->mac_type == e1000_82573) &&
5094 (e1000_is_onboard_nvm_eeprom(hw) == FALSE)) {
5095 /* Check bit 4 of word 10h. If it is 0, firmware is done updating
5096 * 10h-12h. Checksum may need to be fixed. */
5097 e1000_read_eeprom(hw, 0x10, 1, &eeprom_data);
5098 if ((eeprom_data & 0x10) == 0) {
5099 /* Read 0x23 and check bit 15. This bit is a 1 when the checksum
5100 * has already been fixed. If the checksum is still wrong and this
5101 * bit is a 1, we need to return bad checksum. Otherwise, we need
5102 * to set this bit to a 1 and update the checksum. */
5103 e1000_read_eeprom(hw, 0x23, 1, &eeprom_data);
5104 if ((eeprom_data & 0x8000) == 0) {
5105 eeprom_data |= 0x8000;
5106 e1000_write_eeprom(hw, 0x23, 1, &eeprom_data);
5107 e1000_update_eeprom_checksum(hw);
5112 if (hw->mac_type == e1000_ich8lan) {
5113 /* Drivers must allocate the shadow ram structure for the
5114 * EEPROM checksum to be updated. Otherwise, this bit as well
5115 * as the checksum must both be set correctly for this
5116 * validation to pass.
5118 e1000_read_eeprom(hw, 0x19, 1, &eeprom_data);
5119 if ((eeprom_data & 0x40) == 0) {
5120 eeprom_data |= 0x40;
5121 e1000_write_eeprom(hw, 0x19, 1, &eeprom_data);
5122 e1000_update_eeprom_checksum(hw);
5126 for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
5127 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
5128 DEBUGOUT("EEPROM Read Error\n");
5129 return -E1000_ERR_EEPROM;
5131 checksum += eeprom_data;
5134 if(checksum == (uint16_t) EEPROM_SUM)
5135 return E1000_SUCCESS;
5137 DEBUGOUT("EEPROM Checksum Invalid\n");
5138 return -E1000_ERR_EEPROM;
5142 /******************************************************************************
5143 * Calculates the EEPROM checksum and writes it to the EEPROM
5145 * hw - Struct containing variables accessed by shared code
5147 * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA.
5148 * Writes the difference to word offset 63 of the EEPROM.
5149 *****************************************************************************/
5151 e1000_update_eeprom_checksum(struct e1000_hw *hw)
5154 uint16_t checksum = 0;
5155 uint16_t i, eeprom_data;
5157 DEBUGFUNC("e1000_update_eeprom_checksum");
5159 for(i = 0; i < EEPROM_CHECKSUM_REG; i++) {
5160 if(e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
5161 DEBUGOUT("EEPROM Read Error\n");
5162 return -E1000_ERR_EEPROM;
5164 checksum += eeprom_data;
5166 checksum = (uint16_t) EEPROM_SUM - checksum;
5167 if(e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) {
5168 DEBUGOUT("EEPROM Write Error\n");
5169 return -E1000_ERR_EEPROM;
5170 } else if (hw->eeprom.type == e1000_eeprom_flash) {
5171 e1000_commit_shadow_ram(hw);
5172 } else if (hw->eeprom.type == e1000_eeprom_ich8) {
5173 e1000_commit_shadow_ram(hw);
5174 /* Reload the EEPROM, or else modifications will not appear
5175 * until after next adapter reset. */
5176 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
5177 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
5178 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
5181 return E1000_SUCCESS;
5184 /******************************************************************************
5185 * Parent function for writing words to the different EEPROM types.
5187 * hw - Struct containing variables accessed by shared code
5188 * offset - offset within the EEPROM to be written to
5189 * words - number of words to write
5190 * data - 16 bit word to be written to the EEPROM
5192 * If e1000_update_eeprom_checksum is not called after this function, the
5193 * EEPROM will most likely contain an invalid checksum.
5194 *****************************************************************************/
5196 e1000_write_eeprom(struct e1000_hw *hw,
5201 struct e1000_eeprom_info *eeprom = &hw->eeprom;
5204 DEBUGFUNC("e1000_write_eeprom");
5206 /* A check for invalid values: offset too large, too many words, and not
5209 if((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
5211 DEBUGOUT("\"words\" parameter out of bounds\n");
5212 return -E1000_ERR_EEPROM;
5215 /* 82573 writes only through eewr */
5216 if(eeprom->use_eewr == TRUE)
5217 return e1000_write_eeprom_eewr(hw, offset, words, data);
5219 if (eeprom->type == e1000_eeprom_ich8)
5220 return e1000_write_eeprom_ich8(hw, offset, words, data);
5222 /* Prepare the EEPROM for writing */
5223 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
5224 return -E1000_ERR_EEPROM;
5226 if(eeprom->type == e1000_eeprom_microwire) {
5227 status = e1000_write_eeprom_microwire(hw, offset, words, data);
5229 status = e1000_write_eeprom_spi(hw, offset, words, data);
5233 /* Done with writing */
5234 e1000_release_eeprom(hw);
5239 /******************************************************************************
5240 * Writes a 16 bit word to a given offset in an SPI EEPROM.
5242 * hw - Struct containing variables accessed by shared code
5243 * offset - offset within the EEPROM to be written to
5244 * words - number of words to write
5245 * data - pointer to array of 8 bit words to be written to the EEPROM
5247 *****************************************************************************/
5249 e1000_write_eeprom_spi(struct e1000_hw *hw,
5254 struct e1000_eeprom_info *eeprom = &hw->eeprom;
5257 DEBUGFUNC("e1000_write_eeprom_spi");
5259 while (widx < words) {
5260 uint8_t write_opcode = EEPROM_WRITE_OPCODE_SPI;
5262 if(e1000_spi_eeprom_ready(hw)) return -E1000_ERR_EEPROM;
5264 e1000_standby_eeprom(hw);
5266 /* Send the WRITE ENABLE command (8 bit opcode ) */
5267 e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI,
5268 eeprom->opcode_bits);
5270 e1000_standby_eeprom(hw);
5272 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
5273 if((eeprom->address_bits == 8) && (offset >= 128))
5274 write_opcode |= EEPROM_A8_OPCODE_SPI;
5276 /* Send the Write command (8-bit opcode + addr) */
5277 e1000_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits);
5279 e1000_shift_out_ee_bits(hw, (uint16_t)((offset + widx)*2),
5280 eeprom->address_bits);
5284 /* Loop to allow for up to whole page write (32 bytes) of eeprom */
5285 while (widx < words) {
5286 uint16_t word_out = data[widx];
5287 word_out = (word_out >> 8) | (word_out << 8);
5288 e1000_shift_out_ee_bits(hw, word_out, 16);
5291 /* Some larger eeprom sizes are capable of a 32-byte PAGE WRITE
5292 * operation, while the smaller eeproms are capable of an 8-byte
5293 * PAGE WRITE operation. Break the inner loop to pass new address
5295 if((((offset + widx)*2) % eeprom->page_size) == 0) {
5296 e1000_standby_eeprom(hw);
5302 return E1000_SUCCESS;
5305 /******************************************************************************
5306 * Writes a 16 bit word to a given offset in a Microwire EEPROM.
5308 * hw - Struct containing variables accessed by shared code
5309 * offset - offset within the EEPROM to be written to
5310 * words - number of words to write
5311 * data - pointer to array of 16 bit words to be written to the EEPROM
5313 *****************************************************************************/
5315 e1000_write_eeprom_microwire(struct e1000_hw *hw,
5320 struct e1000_eeprom_info *eeprom = &hw->eeprom;
5322 uint16_t words_written = 0;
5325 DEBUGFUNC("e1000_write_eeprom_microwire");
5327 /* Send the write enable command to the EEPROM (3-bit opcode plus
5328 * 6/8-bit dummy address beginning with 11). It's less work to include
5329 * the 11 of the dummy address as part of the opcode than it is to shift
5330 * it over the correct number of bits for the address. This puts the
5331 * EEPROM into write/erase mode.
5333 e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE,
5334 (uint16_t)(eeprom->opcode_bits + 2));
5336 e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
5338 /* Prepare the EEPROM */
5339 e1000_standby_eeprom(hw);
5341 while (words_written < words) {
5342 /* Send the Write command (3-bit opcode + addr) */
5343 e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE,
5344 eeprom->opcode_bits);
5346 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + words_written),
5347 eeprom->address_bits);
5350 e1000_shift_out_ee_bits(hw, data[words_written], 16);
5352 /* Toggle the CS line. This in effect tells the EEPROM to execute
5353 * the previous command.
5355 e1000_standby_eeprom(hw);
5357 /* Read DO repeatedly until it is high (equal to '1'). The EEPROM will
5358 * signal that the command has been completed by raising the DO signal.
5359 * If DO does not go high in 10 milliseconds, then error out.
5361 for(i = 0; i < 200; i++) {
5362 eecd = E1000_READ_REG(hw, EECD);
5363 if(eecd & E1000_EECD_DO) break;
5367 DEBUGOUT("EEPROM Write did not complete\n");
5368 return -E1000_ERR_EEPROM;
5371 /* Recover from write */
5372 e1000_standby_eeprom(hw);
5377 /* Send the write disable command to the EEPROM (3-bit opcode plus
5378 * 6/8-bit dummy address beginning with 10). It's less work to include
5379 * the 10 of the dummy address as part of the opcode than it is to shift
5380 * it over the correct number of bits for the address. This takes the
5381 * EEPROM out of write/erase mode.
5383 e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE,
5384 (uint16_t)(eeprom->opcode_bits + 2));
5386 e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
5388 return E1000_SUCCESS;
5391 /******************************************************************************
5392 * Flushes the cached eeprom to NVM. This is done by saving the modified values
5393 * in the eeprom cache and the non modified values in the currently active bank
5396 * hw - Struct containing variables accessed by shared code
5397 * offset - offset of word in the EEPROM to read
5398 * data - word read from the EEPROM
5399 * words - number of words to read
5400 *****************************************************************************/
5402 e1000_commit_shadow_ram(struct e1000_hw *hw)
5404 uint32_t attempts = 100000;
5408 int32_t error = E1000_SUCCESS;
5409 uint32_t old_bank_offset = 0;
5410 uint32_t new_bank_offset = 0;
5411 uint32_t sector_retries = 0;
5412 uint8_t low_byte = 0;
5413 uint8_t high_byte = 0;
5414 uint8_t temp_byte = 0;
5415 boolean_t sector_write_failed = FALSE;
5417 if (hw->mac_type == e1000_82573) {
5418 /* The flop register will be used to determine if flash type is STM */
5419 flop = E1000_READ_REG(hw, FLOP);
5420 for (i=0; i < attempts; i++) {
5421 eecd = E1000_READ_REG(hw, EECD);
5422 if ((eecd & E1000_EECD_FLUPD) == 0) {
5428 if (i == attempts) {
5429 return -E1000_ERR_EEPROM;
5432 /* If STM opcode located in bits 15:8 of flop, reset firmware */
5433 if ((flop & 0xFF00) == E1000_STM_OPCODE) {
5434 E1000_WRITE_REG(hw, HICR, E1000_HICR_FW_RESET);
5437 /* Perform the flash update */
5438 E1000_WRITE_REG(hw, EECD, eecd | E1000_EECD_FLUPD);
5440 for (i=0; i < attempts; i++) {
5441 eecd = E1000_READ_REG(hw, EECD);
5442 if ((eecd & E1000_EECD_FLUPD) == 0) {
5448 if (i == attempts) {
5449 return -E1000_ERR_EEPROM;
5453 if (hw->mac_type == e1000_ich8lan && hw->eeprom_shadow_ram != NULL) {
5454 /* We're writing to the opposite bank so if we're on bank 1,
5455 * write to bank 0 etc. We also need to erase the segment that
5456 * is going to be written */
5457 if (!(E1000_READ_REG(hw, EECD) & E1000_EECD_SEC1VAL)) {
5458 new_bank_offset = hw->flash_bank_size * 2;
5459 old_bank_offset = 0;
5460 e1000_erase_ich8_4k_segment(hw, 1);
5462 old_bank_offset = hw->flash_bank_size * 2;
5463 new_bank_offset = 0;
5464 e1000_erase_ich8_4k_segment(hw, 0);
5468 sector_write_failed = FALSE;
5469 /* Loop for every byte in the shadow RAM,
5470 * which is in units of words. */
5471 for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
5472 /* Determine whether to write the value stored
5473 * in the other NVM bank or a modified value stored
5474 * in the shadow RAM */
5475 if (hw->eeprom_shadow_ram[i].modified == TRUE) {
5476 low_byte = (uint8_t)hw->eeprom_shadow_ram[i].eeprom_word;
5477 e1000_read_ich8_byte(hw, (i << 1) + old_bank_offset,
5480 error = e1000_verify_write_ich8_byte(hw,
5481 (i << 1) + new_bank_offset,
5483 if (error != E1000_SUCCESS)
5484 sector_write_failed = TRUE;
5486 (uint8_t)(hw->eeprom_shadow_ram[i].eeprom_word >> 8);
5487 e1000_read_ich8_byte(hw, (i << 1) + old_bank_offset + 1,
5491 e1000_read_ich8_byte(hw, (i << 1) + old_bank_offset,
5494 error = e1000_verify_write_ich8_byte(hw,
5495 (i << 1) + new_bank_offset, low_byte);
5496 if (error != E1000_SUCCESS)
5497 sector_write_failed = TRUE;
5498 e1000_read_ich8_byte(hw, (i << 1) + old_bank_offset + 1,
5502 /* If the word is 0x13, then make sure the signature bits
5503 * (15:14) are 11b until the commit has completed.
5504 * This will allow us to write 10b which indicates the
5505 * signature is valid. We want to do this after the write
5506 * has completed so that we don't mark the segment valid
5507 * while the write is still in progress */
5508 if (i == E1000_ICH8_NVM_SIG_WORD)
5509 high_byte = E1000_ICH8_NVM_SIG_MASK | high_byte;
5511 error = e1000_verify_write_ich8_byte(hw,
5512 (i << 1) + new_bank_offset + 1, high_byte);
5513 if (error != E1000_SUCCESS)
5514 sector_write_failed = TRUE;
5516 if (sector_write_failed == FALSE) {
5517 /* Clear the now not used entry in the cache */
5518 hw->eeprom_shadow_ram[i].modified = FALSE;
5519 hw->eeprom_shadow_ram[i].eeprom_word = 0xFFFF;
5523 /* Don't bother writing the segment valid bits if sector
5524 * programming failed. */
5525 if (sector_write_failed == FALSE) {
5526 /* Finally validate the new segment by setting bit 15:14
5527 * to 10b in word 0x13 , this can be done without an
5528 * erase as well since these bits are 11 to start with
5529 * and we need to change bit 14 to 0b */
5530 e1000_read_ich8_byte(hw,
5531 E1000_ICH8_NVM_SIG_WORD * 2 + 1 + new_bank_offset,
5534 error = e1000_verify_write_ich8_byte(hw,
5535 E1000_ICH8_NVM_SIG_WORD * 2 + 1 + new_bank_offset,
5537 if (error != E1000_SUCCESS)
5538 sector_write_failed = TRUE;
5540 /* And invalidate the previously valid segment by setting
5541 * its signature word (0x13) high_byte to 0b. This can be
5542 * done without an erase because flash erase sets all bits
5543 * to 1's. We can write 1's to 0's without an erase */
5544 error = e1000_verify_write_ich8_byte(hw,
5545 E1000_ICH8_NVM_SIG_WORD * 2 + 1 + old_bank_offset,
5547 if (error != E1000_SUCCESS)
5548 sector_write_failed = TRUE;
5550 } while (++sector_retries < 10 && sector_write_failed == TRUE);
5556 /******************************************************************************
5557 * Reads the adapter's part number from the EEPROM
5559 * hw - Struct containing variables accessed by shared code
5560 * part_num - Adapter's part number
5561 *****************************************************************************/
5563 e1000_read_part_num(struct e1000_hw *hw,
5566 uint16_t offset = EEPROM_PBA_BYTE_1;
5567 uint16_t eeprom_data;
5569 DEBUGFUNC("e1000_read_part_num");
5571 /* Get word 0 from EEPROM */
5572 if(e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
5573 DEBUGOUT("EEPROM Read Error\n");
5574 return -E1000_ERR_EEPROM;
5576 /* Save word 0 in upper half of part_num */
5577 *part_num = (uint32_t) (eeprom_data << 16);
5579 /* Get word 1 from EEPROM */
5580 if(e1000_read_eeprom(hw, ++offset, 1, &eeprom_data) < 0) {
5581 DEBUGOUT("EEPROM Read Error\n");
5582 return -E1000_ERR_EEPROM;
5584 /* Save word 1 in lower half of part_num */
5585 *part_num |= eeprom_data;
5587 return E1000_SUCCESS;
5590 /******************************************************************************
5591 * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
5592 * second function of dual function devices
5594 * hw - Struct containing variables accessed by shared code
5595 *****************************************************************************/
5597 e1000_read_mac_addr(struct e1000_hw * hw)
5600 uint16_t eeprom_data, i;
5602 DEBUGFUNC("e1000_read_mac_addr");
5604 for(i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
5606 if(e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
5607 DEBUGOUT("EEPROM Read Error\n");
5608 return -E1000_ERR_EEPROM;
5610 hw->perm_mac_addr[i] = (uint8_t) (eeprom_data & 0x00FF);
5611 hw->perm_mac_addr[i+1] = (uint8_t) (eeprom_data >> 8);
5614 switch (hw->mac_type) {
5618 case e1000_82546_rev_3:
5620 case e1000_80003es2lan:
5621 if(E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
5622 hw->perm_mac_addr[5] ^= 0x01;
5626 for(i = 0; i < NODE_ADDRESS_SIZE; i++)
5627 hw->mac_addr[i] = hw->perm_mac_addr[i];
5628 return E1000_SUCCESS;
5631 /******************************************************************************
5632 * Initializes receive address filters.
5634 * hw - Struct containing variables accessed by shared code
5636 * Places the MAC address in receive address register 0 and clears the rest
5637 * of the receive addresss registers. Clears the multicast table. Assumes
5638 * the receiver is in reset when the routine is called.
5639 *****************************************************************************/
5641 e1000_init_rx_addrs(struct e1000_hw *hw)
5646 DEBUGFUNC("e1000_init_rx_addrs");
5648 /* Setup the receive address. */
5649 DEBUGOUT("Programming MAC Address into RAR[0]\n");
5651 e1000_rar_set(hw, hw->mac_addr, 0);
5653 rar_num = E1000_RAR_ENTRIES;
5655 /* Reserve a spot for the Locally Administered Address to work around
5656 * an 82571 issue in which a reset on one port will reload the MAC on
5657 * the other port. */
5658 if ((hw->mac_type == e1000_82571) && (hw->laa_is_present == TRUE))
5660 if (hw->mac_type == e1000_ich8lan)
5661 rar_num = E1000_RAR_ENTRIES_ICH8LAN;
5663 /* Zero out the other 15 receive addresses. */
5664 DEBUGOUT("Clearing RAR[1-15]\n");
5665 for(i = 1; i < rar_num; i++) {
5666 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
5667 E1000_WRITE_FLUSH(hw);
5668 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
5669 E1000_WRITE_FLUSH(hw);
5673 /******************************************************************************
5674 * Updates the MAC's list of multicast addresses.
5676 * hw - Struct containing variables accessed by shared code
5677 * mc_addr_list - the list of new multicast addresses
5678 * mc_addr_count - number of addresses
5679 * pad - number of bytes between addresses in the list
5680 * rar_used_count - offset where to start adding mc addresses into the RAR's
5682 * The given list replaces any existing list. Clears the last 15 receive
5683 * address registers and the multicast table. Uses receive address registers
5684 * for the first 15 multicast addresses, and hashes the rest into the
5686 *****************************************************************************/
5689 e1000_mc_addr_list_update(struct e1000_hw *hw,
5690 uint8_t *mc_addr_list,
5691 uint32_t mc_addr_count,
5693 uint32_t rar_used_count)
5695 uint32_t hash_value;
5697 uint32_t num_rar_entry;
5698 uint32_t num_mta_entry;
5700 DEBUGFUNC("e1000_mc_addr_list_update");
5702 /* Set the new number of MC addresses that we are being requested to use. */
5703 hw->num_mc_addrs = mc_addr_count;
5705 /* Clear RAR[1-15] */
5706 DEBUGOUT(" Clearing RAR[1-15]\n");
5707 num_rar_entry = E1000_RAR_ENTRIES;
5708 if (hw->mac_type == e1000_ich8lan)
5709 num_rar_entry = E1000_RAR_ENTRIES_ICH8LAN;
5710 /* Reserve a spot for the Locally Administered Address to work around
5711 * an 82571 issue in which a reset on one port will reload the MAC on
5712 * the other port. */
5713 if ((hw->mac_type == e1000_82571) && (hw->laa_is_present == TRUE))
5716 for(i = rar_used_count; i < num_rar_entry; i++) {
5717 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
5718 E1000_WRITE_FLUSH(hw);
5719 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
5720 E1000_WRITE_FLUSH(hw);
5724 DEBUGOUT(" Clearing MTA\n");
5725 num_mta_entry = E1000_NUM_MTA_REGISTERS;
5726 if (hw->mac_type == e1000_ich8lan)
5727 num_mta_entry = E1000_NUM_MTA_REGISTERS_ICH8LAN;
5728 for(i = 0; i < num_mta_entry; i++) {
5729 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
5730 E1000_WRITE_FLUSH(hw);
5733 /* Add the new addresses */
5734 for(i = 0; i < mc_addr_count; i++) {
5735 DEBUGOUT(" Adding the multicast addresses:\n");
5736 DEBUGOUT7(" MC Addr #%d =%.2X %.2X %.2X %.2X %.2X %.2X\n", i,
5737 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad)],
5738 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 1],
5739 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 2],
5740 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 3],
5741 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 4],
5742 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 5]);
5744 hash_value = e1000_hash_mc_addr(hw,
5746 (i * (ETH_LENGTH_OF_ADDRESS + pad)));
5748 DEBUGOUT1(" Hash value = 0x%03X\n", hash_value);
5750 /* Place this multicast address in the RAR if there is room, *
5751 * else put it in the MTA
5753 if (rar_used_count < num_rar_entry) {
5755 mc_addr_list + (i * (ETH_LENGTH_OF_ADDRESS + pad)),
5759 e1000_mta_set(hw, hash_value);
5762 DEBUGOUT("MC Update Complete\n");
5766 /******************************************************************************
5767 * Hashes an address to determine its location in the multicast table
5769 * hw - Struct containing variables accessed by shared code
5770 * mc_addr - the multicast address to hash
5771 *****************************************************************************/
5773 e1000_hash_mc_addr(struct e1000_hw *hw,
5776 uint32_t hash_value = 0;
5778 /* The portion of the address that is used for the hash table is
5779 * determined by the mc_filter_type setting.
5781 switch (hw->mc_filter_type) {
5782 /* [0] [1] [2] [3] [4] [5]
5787 if (hw->mac_type == e1000_ich8lan) {
5788 /* [47:38] i.e. 0x158 for above example address */
5789 hash_value = ((mc_addr[4] >> 6) | (((uint16_t) mc_addr[5]) << 2));
5791 /* [47:36] i.e. 0x563 for above example address */
5792 hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4));
5796 if (hw->mac_type == e1000_ich8lan) {
5797 /* [46:37] i.e. 0x2B1 for above example address */
5798 hash_value = ((mc_addr[4] >> 5) | (((uint16_t) mc_addr[5]) << 3));
5800 /* [46:35] i.e. 0xAC6 for above example address */
5801 hash_value = ((mc_addr[4] >> 3) | (((uint16_t) mc_addr[5]) << 5));
5805 if (hw->mac_type == e1000_ich8lan) {
5806 /*[45:36] i.e. 0x163 for above example address */
5807 hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4));
5809 /* [45:34] i.e. 0x5D8 for above example address */
5810 hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6));
5814 if (hw->mac_type == e1000_ich8lan) {
5815 /* [43:34] i.e. 0x18D for above example address */
5816 hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6));
5818 /* [43:32] i.e. 0x634 for above example address */
5819 hash_value = ((mc_addr[4]) | (((uint16_t) mc_addr[5]) << 8));
5824 hash_value &= 0xFFF;
5825 if (hw->mac_type == e1000_ich8lan)
5826 hash_value &= 0x3FF;
5831 /******************************************************************************
5832 * Sets the bit in the multicast table corresponding to the hash value.
5834 * hw - Struct containing variables accessed by shared code
5835 * hash_value - Multicast address hash value
5836 *****************************************************************************/
5838 e1000_mta_set(struct e1000_hw *hw,
5839 uint32_t hash_value)
5841 uint32_t hash_bit, hash_reg;
5845 /* The MTA is a register array of 128 32-bit registers.
5846 * It is treated like an array of 4096 bits. We want to set
5847 * bit BitArray[hash_value]. So we figure out what register
5848 * the bit is in, read it, OR in the new bit, then write
5849 * back the new value. The register is determined by the
5850 * upper 7 bits of the hash value and the bit within that
5851 * register are determined by the lower 5 bits of the value.
5853 hash_reg = (hash_value >> 5) & 0x7F;
5854 if (hw->mac_type == e1000_ich8lan)
5856 hash_bit = hash_value & 0x1F;
5858 mta = E1000_READ_REG_ARRAY(hw, MTA, hash_reg);
5860 mta |= (1 << hash_bit);
5862 /* If we are on an 82544 and we are trying to write an odd offset
5863 * in the MTA, save off the previous entry before writing and
5864 * restore the old value after writing.
5866 if((hw->mac_type == e1000_82544) && ((hash_reg & 0x1) == 1)) {
5867 temp = E1000_READ_REG_ARRAY(hw, MTA, (hash_reg - 1));
5868 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
5869 E1000_WRITE_FLUSH(hw);
5870 E1000_WRITE_REG_ARRAY(hw, MTA, (hash_reg - 1), temp);
5871 E1000_WRITE_FLUSH(hw);
5873 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
5874 E1000_WRITE_FLUSH(hw);
5878 /******************************************************************************
5879 * Puts an ethernet address into a receive address register.
5881 * hw - Struct containing variables accessed by shared code
5882 * addr - Address to put into receive address register
5883 * index - Receive address register to write
5884 *****************************************************************************/
5886 e1000_rar_set(struct e1000_hw *hw,
5890 uint32_t rar_low, rar_high;
5892 /* HW expects these in little endian so we reverse the byte order
5893 * from network order (big endian) to little endian
5895 rar_low = ((uint32_t) addr[0] |
5896 ((uint32_t) addr[1] << 8) |
5897 ((uint32_t) addr[2] << 16) | ((uint32_t) addr[3] << 24));
5898 rar_high = ((uint32_t) addr[4] | ((uint32_t) addr[5] << 8));
5900 /* Disable Rx and flush all Rx frames before enabling RSS to avoid Rx
5904 * If there are any Rx frames queued up or otherwise present in the HW
5905 * before RSS is enabled, and then we enable RSS, the HW Rx unit will
5906 * hang. To work around this issue, we have to disable receives and
5907 * flush out all Rx frames before we enable RSS. To do so, we modify we
5908 * redirect all Rx traffic to manageability and then reset the HW.
5909 * This flushes away Rx frames, and (since the redirections to
5910 * manageability persists across resets) keeps new ones from coming in
5911 * while we work. Then, we clear the Address Valid AV bit for all MAC
5912 * addresses and undo the re-direction to manageability.
5913 * Now, frames are coming in again, but the MAC won't accept them, so
5914 * far so good. We now proceed to initialize RSS (if necessary) and
5915 * configure the Rx unit. Last, we re-enable the AV bits and continue
5918 switch (hw->mac_type) {
5921 case e1000_80003es2lan:
5922 if (hw->leave_av_bit_off == TRUE)
5925 /* Indicate to hardware the Address is Valid. */
5926 rar_high |= E1000_RAH_AV;
5930 E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
5931 E1000_WRITE_FLUSH(hw);
5932 E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
5933 E1000_WRITE_FLUSH(hw);
5936 /******************************************************************************
5937 * Writes a value to the specified offset in the VLAN filter table.
5939 * hw - Struct containing variables accessed by shared code
5940 * offset - Offset in VLAN filer table to write
5941 * value - Value to write into VLAN filter table
5942 *****************************************************************************/
5944 e1000_write_vfta(struct e1000_hw *hw,
5950 if (hw->mac_type == e1000_ich8lan)
5953 if ((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) {
5954 temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1));
5955 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
5956 E1000_WRITE_FLUSH(hw);
5957 E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp);
5958 E1000_WRITE_FLUSH(hw);
5960 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
5961 E1000_WRITE_FLUSH(hw);
5965 /******************************************************************************
5966 * Clears the VLAN filer table
5968 * hw - Struct containing variables accessed by shared code
5969 *****************************************************************************/
5971 e1000_clear_vfta(struct e1000_hw *hw)
5974 uint32_t vfta_value = 0;
5975 uint32_t vfta_offset = 0;
5976 uint32_t vfta_bit_in_reg = 0;
5978 if (hw->mac_type == e1000_ich8lan)
5981 if (hw->mac_type == e1000_82573) {
5982 if (hw->mng_cookie.vlan_id != 0) {
5983 /* The VFTA is a 4096b bit-field, each identifying a single VLAN
5984 * ID. The following operations determine which 32b entry
5985 * (i.e. offset) into the array we want to set the VLAN ID
5986 * (i.e. bit) of the manageability unit. */
5987 vfta_offset = (hw->mng_cookie.vlan_id >>
5988 E1000_VFTA_ENTRY_SHIFT) &
5989 E1000_VFTA_ENTRY_MASK;
5990 vfta_bit_in_reg = 1 << (hw->mng_cookie.vlan_id &
5991 E1000_VFTA_ENTRY_BIT_SHIFT_MASK);
5994 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
5995 /* If the offset we want to clear is the same offset of the
5996 * manageability VLAN ID, then clear all bits except that of the
5997 * manageability unit */
5998 vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0;
5999 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, vfta_value);
6000 E1000_WRITE_FLUSH(hw);
6005 e1000_id_led_init(struct e1000_hw * hw)
6008 const uint32_t ledctl_mask = 0x000000FF;
6009 const uint32_t ledctl_on = E1000_LEDCTL_MODE_LED_ON;
6010 const uint32_t ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
6011 uint16_t eeprom_data, i, temp;
6012 const uint16_t led_mask = 0x0F;
6014 DEBUGFUNC("e1000_id_led_init");
6016 if(hw->mac_type < e1000_82540) {
6018 return E1000_SUCCESS;
6021 ledctl = E1000_READ_REG(hw, LEDCTL);
6022 hw->ledctl_default = ledctl;
6023 hw->ledctl_mode1 = hw->ledctl_default;
6024 hw->ledctl_mode2 = hw->ledctl_default;
6026 if(e1000_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, 1, &eeprom_data) < 0) {
6027 DEBUGOUT("EEPROM Read Error\n");
6028 return -E1000_ERR_EEPROM;
6031 if ((hw->mac_type == e1000_82573) &&
6032 (eeprom_data == ID_LED_RESERVED_82573))
6033 eeprom_data = ID_LED_DEFAULT_82573;
6034 else if ((eeprom_data == ID_LED_RESERVED_0000) ||
6035 (eeprom_data == ID_LED_RESERVED_FFFF)) {
6036 if (hw->mac_type == e1000_ich8lan)
6037 eeprom_data = ID_LED_DEFAULT_ICH8LAN;
6039 eeprom_data = ID_LED_DEFAULT;
6041 for (i = 0; i < 4; i++) {
6042 temp = (eeprom_data >> (i << 2)) & led_mask;
6044 case ID_LED_ON1_DEF2:
6045 case ID_LED_ON1_ON2:
6046 case ID_LED_ON1_OFF2:
6047 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
6048 hw->ledctl_mode1 |= ledctl_on << (i << 3);
6050 case ID_LED_OFF1_DEF2:
6051 case ID_LED_OFF1_ON2:
6052 case ID_LED_OFF1_OFF2:
6053 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
6054 hw->ledctl_mode1 |= ledctl_off << (i << 3);
6061 case ID_LED_DEF1_ON2:
6062 case ID_LED_ON1_ON2:
6063 case ID_LED_OFF1_ON2:
6064 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
6065 hw->ledctl_mode2 |= ledctl_on << (i << 3);
6067 case ID_LED_DEF1_OFF2:
6068 case ID_LED_ON1_OFF2:
6069 case ID_LED_OFF1_OFF2:
6070 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
6071 hw->ledctl_mode2 |= ledctl_off << (i << 3);
6078 return E1000_SUCCESS;
6081 /******************************************************************************
6082 * Prepares SW controlable LED for use and saves the current state of the LED.
6084 * hw - Struct containing variables accessed by shared code
6085 *****************************************************************************/
6087 e1000_setup_led(struct e1000_hw *hw)
6090 int32_t ret_val = E1000_SUCCESS;
6092 DEBUGFUNC("e1000_setup_led");
6094 switch(hw->mac_type) {
6095 case e1000_82542_rev2_0:
6096 case e1000_82542_rev2_1:
6099 /* No setup necessary */
6103 case e1000_82541_rev_2:
6104 case e1000_82547_rev_2:
6105 /* Turn off PHY Smart Power Down (if enabled) */
6106 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
6107 &hw->phy_spd_default);
6110 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
6111 (uint16_t)(hw->phy_spd_default &
6112 ~IGP01E1000_GMII_SPD));
6117 if(hw->media_type == e1000_media_type_fiber) {
6118 ledctl = E1000_READ_REG(hw, LEDCTL);
6119 /* Save current LEDCTL settings */
6120 hw->ledctl_default = ledctl;
6122 ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
6123 E1000_LEDCTL_LED0_BLINK |
6124 E1000_LEDCTL_LED0_MODE_MASK);
6125 ledctl |= (E1000_LEDCTL_MODE_LED_OFF <<
6126 E1000_LEDCTL_LED0_MODE_SHIFT);
6127 E1000_WRITE_REG(hw, LEDCTL, ledctl);
6128 } else if(hw->media_type == e1000_media_type_copper)
6129 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
6133 return E1000_SUCCESS;
6136 /******************************************************************************
6137 * Used on 82571 and later Si that has LED blink bits.
6138 * Callers must use their own timer and should have already called
6139 * e1000_id_led_init()
6140 * Call e1000_cleanup led() to stop blinking
6142 * hw - Struct containing variables accessed by shared code
6143 *****************************************************************************/
6145 e1000_blink_led_start(struct e1000_hw *hw)
6148 uint32_t ledctl_blink = 0;
6150 DEBUGFUNC("e1000_id_led_blink_on");
6152 if (hw->mac_type < e1000_82571) {
6154 return E1000_SUCCESS;
6156 if (hw->media_type == e1000_media_type_fiber) {
6157 /* always blink LED0 for PCI-E fiber */
6158 ledctl_blink = E1000_LEDCTL_LED0_BLINK |
6159 (E1000_LEDCTL_MODE_LED_ON << E1000_LEDCTL_LED0_MODE_SHIFT);
6161 /* set the blink bit for each LED that's "on" (0x0E) in ledctl_mode2 */
6162 ledctl_blink = hw->ledctl_mode2;
6163 for (i=0; i < 4; i++)
6164 if (((hw->ledctl_mode2 >> (i * 8)) & 0xFF) ==
6165 E1000_LEDCTL_MODE_LED_ON)
6166 ledctl_blink |= (E1000_LEDCTL_LED0_BLINK << (i * 8));
6169 E1000_WRITE_REG(hw, LEDCTL, ledctl_blink);
6171 return E1000_SUCCESS;
6174 /******************************************************************************
6175 * Restores the saved state of the SW controlable LED.
6177 * hw - Struct containing variables accessed by shared code
6178 *****************************************************************************/
6180 e1000_cleanup_led(struct e1000_hw *hw)
6182 int32_t ret_val = E1000_SUCCESS;
6184 DEBUGFUNC("e1000_cleanup_led");
6186 switch(hw->mac_type) {
6187 case e1000_82542_rev2_0:
6188 case e1000_82542_rev2_1:
6191 /* No cleanup necessary */
6195 case e1000_82541_rev_2:
6196 case e1000_82547_rev_2:
6197 /* Turn on PHY Smart Power Down (if previously enabled) */
6198 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
6199 hw->phy_spd_default);
6204 if (hw->phy_type == e1000_phy_ife) {
6205 e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
6208 /* Restore LEDCTL settings */
6209 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_default);
6213 return E1000_SUCCESS;
6216 /******************************************************************************
6217 * Turns on the software controllable LED
6219 * hw - Struct containing variables accessed by shared code
6220 *****************************************************************************/
6222 e1000_led_on(struct e1000_hw *hw)
6224 uint32_t ctrl = E1000_READ_REG(hw, CTRL);
6226 DEBUGFUNC("e1000_led_on");
6228 switch(hw->mac_type) {
6229 case e1000_82542_rev2_0:
6230 case e1000_82542_rev2_1:
6232 /* Set SW Defineable Pin 0 to turn on the LED */
6233 ctrl |= E1000_CTRL_SWDPIN0;
6234 ctrl |= E1000_CTRL_SWDPIO0;
6237 if(hw->media_type == e1000_media_type_fiber) {
6238 /* Set SW Defineable Pin 0 to turn on the LED */
6239 ctrl |= E1000_CTRL_SWDPIN0;
6240 ctrl |= E1000_CTRL_SWDPIO0;
6242 /* Clear SW Defineable Pin 0 to turn on the LED */
6243 ctrl &= ~E1000_CTRL_SWDPIN0;
6244 ctrl |= E1000_CTRL_SWDPIO0;
6248 if(hw->media_type == e1000_media_type_fiber) {
6249 /* Clear SW Defineable Pin 0 to turn on the LED */
6250 ctrl &= ~E1000_CTRL_SWDPIN0;
6251 ctrl |= E1000_CTRL_SWDPIO0;
6252 } else if (hw->phy_type == e1000_phy_ife) {
6253 e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED,
6254 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_ON));
6255 } else if (hw->media_type == e1000_media_type_copper) {
6256 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode2);
6257 return E1000_SUCCESS;
6262 E1000_WRITE_REG(hw, CTRL, ctrl);
6264 return E1000_SUCCESS;
6267 /******************************************************************************
6268 * Turns off the software controllable LED
6270 * hw - Struct containing variables accessed by shared code
6271 *****************************************************************************/
6273 e1000_led_off(struct e1000_hw *hw)
6275 uint32_t ctrl = E1000_READ_REG(hw, CTRL);
6277 DEBUGFUNC("e1000_led_off");
6279 switch(hw->mac_type) {
6280 case e1000_82542_rev2_0:
6281 case e1000_82542_rev2_1:
6283 /* Clear SW Defineable Pin 0 to turn off the LED */
6284 ctrl &= ~E1000_CTRL_SWDPIN0;
6285 ctrl |= E1000_CTRL_SWDPIO0;
6288 if(hw->media_type == e1000_media_type_fiber) {
6289 /* Clear SW Defineable Pin 0 to turn off the LED */
6290 ctrl &= ~E1000_CTRL_SWDPIN0;
6291 ctrl |= E1000_CTRL_SWDPIO0;
6293 /* Set SW Defineable Pin 0 to turn off the LED */
6294 ctrl |= E1000_CTRL_SWDPIN0;
6295 ctrl |= E1000_CTRL_SWDPIO0;
6299 if(hw->media_type == e1000_media_type_fiber) {
6300 /* Set SW Defineable Pin 0 to turn off the LED */
6301 ctrl |= E1000_CTRL_SWDPIN0;
6302 ctrl |= E1000_CTRL_SWDPIO0;
6303 } else if (hw->phy_type == e1000_phy_ife) {
6304 e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED,
6305 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_OFF));
6306 } else if (hw->media_type == e1000_media_type_copper) {
6307 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
6308 return E1000_SUCCESS;
6313 E1000_WRITE_REG(hw, CTRL, ctrl);
6315 return E1000_SUCCESS;
6318 /******************************************************************************
6319 * Clears all hardware statistics counters.
6321 * hw - Struct containing variables accessed by shared code
6322 *****************************************************************************/
6324 e1000_clear_hw_cntrs(struct e1000_hw *hw)
6326 volatile uint32_t temp;
6328 temp = E1000_READ_REG(hw, CRCERRS);
6329 temp = E1000_READ_REG(hw, SYMERRS);
6330 temp = E1000_READ_REG(hw, MPC);
6331 temp = E1000_READ_REG(hw, SCC);
6332 temp = E1000_READ_REG(hw, ECOL);
6333 temp = E1000_READ_REG(hw, MCC);
6334 temp = E1000_READ_REG(hw, LATECOL);
6335 temp = E1000_READ_REG(hw, COLC);
6336 temp = E1000_READ_REG(hw, DC);
6337 temp = E1000_READ_REG(hw, SEC);
6338 temp = E1000_READ_REG(hw, RLEC);
6339 temp = E1000_READ_REG(hw, XONRXC);
6340 temp = E1000_READ_REG(hw, XONTXC);
6341 temp = E1000_READ_REG(hw, XOFFRXC);
6342 temp = E1000_READ_REG(hw, XOFFTXC);
6343 temp = E1000_READ_REG(hw, FCRUC);
6345 if (hw->mac_type != e1000_ich8lan) {
6346 temp = E1000_READ_REG(hw, PRC64);
6347 temp = E1000_READ_REG(hw, PRC127);
6348 temp = E1000_READ_REG(hw, PRC255);
6349 temp = E1000_READ_REG(hw, PRC511);
6350 temp = E1000_READ_REG(hw, PRC1023);
6351 temp = E1000_READ_REG(hw, PRC1522);
6354 temp = E1000_READ_REG(hw, GPRC);
6355 temp = E1000_READ_REG(hw, BPRC);
6356 temp = E1000_READ_REG(hw, MPRC);
6357 temp = E1000_READ_REG(hw, GPTC);
6358 temp = E1000_READ_REG(hw, GORCL);
6359 temp = E1000_READ_REG(hw, GORCH);
6360 temp = E1000_READ_REG(hw, GOTCL);
6361 temp = E1000_READ_REG(hw, GOTCH);
6362 temp = E1000_READ_REG(hw, RNBC);
6363 temp = E1000_READ_REG(hw, RUC);
6364 temp = E1000_READ_REG(hw, RFC);
6365 temp = E1000_READ_REG(hw, ROC);
6366 temp = E1000_READ_REG(hw, RJC);
6367 temp = E1000_READ_REG(hw, TORL);
6368 temp = E1000_READ_REG(hw, TORH);
6369 temp = E1000_READ_REG(hw, TOTL);
6370 temp = E1000_READ_REG(hw, TOTH);
6371 temp = E1000_READ_REG(hw, TPR);
6372 temp = E1000_READ_REG(hw, TPT);
6374 if (hw->mac_type != e1000_ich8lan) {
6375 temp = E1000_READ_REG(hw, PTC64);
6376 temp = E1000_READ_REG(hw, PTC127);
6377 temp = E1000_READ_REG(hw, PTC255);
6378 temp = E1000_READ_REG(hw, PTC511);
6379 temp = E1000_READ_REG(hw, PTC1023);
6380 temp = E1000_READ_REG(hw, PTC1522);
6383 temp = E1000_READ_REG(hw, MPTC);
6384 temp = E1000_READ_REG(hw, BPTC);
6386 if(hw->mac_type < e1000_82543) return;
6388 temp = E1000_READ_REG(hw, ALGNERRC);
6389 temp = E1000_READ_REG(hw, RXERRC);
6390 temp = E1000_READ_REG(hw, TNCRS);
6391 temp = E1000_READ_REG(hw, CEXTERR);
6392 temp = E1000_READ_REG(hw, TSCTC);
6393 temp = E1000_READ_REG(hw, TSCTFC);
6395 if(hw->mac_type <= e1000_82544) return;
6397 temp = E1000_READ_REG(hw, MGTPRC);
6398 temp = E1000_READ_REG(hw, MGTPDC);
6399 temp = E1000_READ_REG(hw, MGTPTC);
6401 if(hw->mac_type <= e1000_82547_rev_2) return;
6403 temp = E1000_READ_REG(hw, IAC);
6404 temp = E1000_READ_REG(hw, ICRXOC);
6406 if (hw->mac_type == e1000_ich8lan) return;
6408 temp = E1000_READ_REG(hw, ICRXPTC);
6409 temp = E1000_READ_REG(hw, ICRXATC);
6410 temp = E1000_READ_REG(hw, ICTXPTC);
6411 temp = E1000_READ_REG(hw, ICTXATC);
6412 temp = E1000_READ_REG(hw, ICTXQEC);
6413 temp = E1000_READ_REG(hw, ICTXQMTC);
6414 temp = E1000_READ_REG(hw, ICRXDMTC);
6417 /******************************************************************************
6418 * Resets Adaptive IFS to its default state.
6420 * hw - Struct containing variables accessed by shared code
6422 * Call this after e1000_init_hw. You may override the IFS defaults by setting
6423 * hw->ifs_params_forced to TRUE. However, you must initialize hw->
6424 * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio
6425 * before calling this function.
6426 *****************************************************************************/
6428 e1000_reset_adaptive(struct e1000_hw *hw)
6430 DEBUGFUNC("e1000_reset_adaptive");
6432 if(hw->adaptive_ifs) {
6433 if(!hw->ifs_params_forced) {
6434 hw->current_ifs_val = 0;
6435 hw->ifs_min_val = IFS_MIN;
6436 hw->ifs_max_val = IFS_MAX;
6437 hw->ifs_step_size = IFS_STEP;
6438 hw->ifs_ratio = IFS_RATIO;
6440 hw->in_ifs_mode = FALSE;
6441 E1000_WRITE_REG(hw, AIT, 0);
6443 DEBUGOUT("Not in Adaptive IFS mode!\n");
6447 /******************************************************************************
6448 * Called during the callback/watchdog routine to update IFS value based on
6449 * the ratio of transmits to collisions.
6451 * hw - Struct containing variables accessed by shared code
6452 * tx_packets - Number of transmits since last callback
6453 * total_collisions - Number of collisions since last callback
6454 *****************************************************************************/
6456 e1000_update_adaptive(struct e1000_hw *hw)
6458 DEBUGFUNC("e1000_update_adaptive");
6460 if(hw->adaptive_ifs) {
6461 if((hw->collision_delta * hw->ifs_ratio) > hw->tx_packet_delta) {
6462 if(hw->tx_packet_delta > MIN_NUM_XMITS) {
6463 hw->in_ifs_mode = TRUE;
6464 if(hw->current_ifs_val < hw->ifs_max_val) {
6465 if(hw->current_ifs_val == 0)
6466 hw->current_ifs_val = hw->ifs_min_val;
6468 hw->current_ifs_val += hw->ifs_step_size;
6469 E1000_WRITE_REG(hw, AIT, hw->current_ifs_val);
6473 if(hw->in_ifs_mode && (hw->tx_packet_delta <= MIN_NUM_XMITS)) {
6474 hw->current_ifs_val = 0;
6475 hw->in_ifs_mode = FALSE;
6476 E1000_WRITE_REG(hw, AIT, 0);
6480 DEBUGOUT("Not in Adaptive IFS mode!\n");
6484 /******************************************************************************
6485 * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT
6487 * hw - Struct containing variables accessed by shared code
6488 * frame_len - The length of the frame in question
6489 * mac_addr - The Ethernet destination address of the frame in question
6490 *****************************************************************************/
6492 e1000_tbi_adjust_stats(struct e1000_hw *hw,
6493 struct e1000_hw_stats *stats,
6499 /* First adjust the frame length. */
6501 /* We need to adjust the statistics counters, since the hardware
6502 * counters overcount this packet as a CRC error and undercount
6503 * the packet as a good packet
6505 /* This packet should not be counted as a CRC error. */
6507 /* This packet does count as a Good Packet Received. */
6510 /* Adjust the Good Octets received counters */
6511 carry_bit = 0x80000000 & stats->gorcl;
6512 stats->gorcl += frame_len;
6513 /* If the high bit of Gorcl (the low 32 bits of the Good Octets
6514 * Received Count) was one before the addition,
6515 * AND it is zero after, then we lost the carry out,
6516 * need to add one to Gorch (Good Octets Received Count High).
6517 * This could be simplified if all environments supported
6520 if(carry_bit && ((stats->gorcl & 0x80000000) == 0))
6522 /* Is this a broadcast or multicast? Check broadcast first,
6523 * since the test for a multicast frame will test positive on
6524 * a broadcast frame.
6526 if((mac_addr[0] == (uint8_t) 0xff) && (mac_addr[1] == (uint8_t) 0xff))
6527 /* Broadcast packet */
6529 else if(*mac_addr & 0x01)
6530 /* Multicast packet */
6533 if(frame_len == hw->max_frame_size) {
6534 /* In this case, the hardware has overcounted the number of
6541 /* Adjust the bin counters when the extra byte put the frame in the
6542 * wrong bin. Remember that the frame_len was adjusted above.
6544 if(frame_len == 64) {
6547 } else if(frame_len == 127) {
6550 } else if(frame_len == 255) {
6553 } else if(frame_len == 511) {
6556 } else if(frame_len == 1023) {
6559 } else if(frame_len == 1522) {
6564 /******************************************************************************
6565 * Gets the current PCI bus type, speed, and width of the hardware
6567 * hw - Struct containing variables accessed by shared code
6568 *****************************************************************************/
6570 e1000_get_bus_info(struct e1000_hw *hw)
6574 switch (hw->mac_type) {
6575 case e1000_82542_rev2_0:
6576 case e1000_82542_rev2_1:
6577 hw->bus_type = e1000_bus_type_unknown;
6578 hw->bus_speed = e1000_bus_speed_unknown;
6579 hw->bus_width = e1000_bus_width_unknown;
6583 hw->bus_type = e1000_bus_type_pci_express;
6584 hw->bus_speed = e1000_bus_speed_2500;
6585 hw->bus_width = e1000_bus_width_pciex_1;
6589 case e1000_80003es2lan:
6590 hw->bus_type = e1000_bus_type_pci_express;
6591 hw->bus_speed = e1000_bus_speed_2500;
6592 hw->bus_width = e1000_bus_width_pciex_4;
6595 status = E1000_READ_REG(hw, STATUS);
6596 hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
6597 e1000_bus_type_pcix : e1000_bus_type_pci;
6599 if(hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) {
6600 hw->bus_speed = (hw->bus_type == e1000_bus_type_pci) ?
6601 e1000_bus_speed_66 : e1000_bus_speed_120;
6602 } else if(hw->bus_type == e1000_bus_type_pci) {
6603 hw->bus_speed = (status & E1000_STATUS_PCI66) ?
6604 e1000_bus_speed_66 : e1000_bus_speed_33;
6606 switch (status & E1000_STATUS_PCIX_SPEED) {
6607 case E1000_STATUS_PCIX_SPEED_66:
6608 hw->bus_speed = e1000_bus_speed_66;
6610 case E1000_STATUS_PCIX_SPEED_100:
6611 hw->bus_speed = e1000_bus_speed_100;
6613 case E1000_STATUS_PCIX_SPEED_133:
6614 hw->bus_speed = e1000_bus_speed_133;
6617 hw->bus_speed = e1000_bus_speed_reserved;
6621 hw->bus_width = (status & E1000_STATUS_BUS64) ?
6622 e1000_bus_width_64 : e1000_bus_width_32;
6626 /******************************************************************************
6627 * Reads a value from one of the devices registers using port I/O (as opposed
6628 * memory mapped I/O). Only 82544 and newer devices support port I/O.
6630 * hw - Struct containing variables accessed by shared code
6631 * offset - offset to read from
6632 *****************************************************************************/
6635 e1000_read_reg_io(struct e1000_hw *hw,
6638 unsigned long io_addr = hw->io_base;
6639 unsigned long io_data = hw->io_base + 4;
6641 e1000_io_write(hw, io_addr, offset);
6642 return e1000_io_read(hw, io_data);
6646 /******************************************************************************
6647 * Writes a value to one of the devices registers using port I/O (as opposed to
6648 * memory mapped I/O). Only 82544 and newer devices support port I/O.
6650 * hw - Struct containing variables accessed by shared code
6651 * offset - offset to write to
6652 * value - value to write
6653 *****************************************************************************/
6655 e1000_write_reg_io(struct e1000_hw *hw,
6659 unsigned long io_addr = hw->io_base;
6660 unsigned long io_data = hw->io_base + 4;
6662 e1000_io_write(hw, io_addr, offset);
6663 e1000_io_write(hw, io_data, value);
6667 /******************************************************************************
6668 * Estimates the cable length.
6670 * hw - Struct containing variables accessed by shared code
6671 * min_length - The estimated minimum length
6672 * max_length - The estimated maximum length
6674 * returns: - E1000_ERR_XXX
6677 * This function always returns a ranged length (minimum & maximum).
6678 * So for M88 phy's, this function interprets the one value returned from the
6679 * register to the minimum and maximum range.
6680 * For IGP phy's, the function calculates the range by the AGC registers.
6681 *****************************************************************************/
6683 e1000_get_cable_length(struct e1000_hw *hw,
6684 uint16_t *min_length,
6685 uint16_t *max_length)
6688 uint16_t agc_value = 0;
6689 uint16_t i, phy_data;
6690 uint16_t cable_length;
6692 DEBUGFUNC("e1000_get_cable_length");
6694 *min_length = *max_length = 0;
6696 /* Use old method for Phy older than IGP */
6697 if(hw->phy_type == e1000_phy_m88) {
6699 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6703 cable_length = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
6704 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
6706 /* Convert the enum value to ranged values */
6707 switch (cable_length) {
6708 case e1000_cable_length_50:
6710 *max_length = e1000_igp_cable_length_50;
6712 case e1000_cable_length_50_80:
6713 *min_length = e1000_igp_cable_length_50;
6714 *max_length = e1000_igp_cable_length_80;
6716 case e1000_cable_length_80_110:
6717 *min_length = e1000_igp_cable_length_80;
6718 *max_length = e1000_igp_cable_length_110;
6720 case e1000_cable_length_110_140:
6721 *min_length = e1000_igp_cable_length_110;
6722 *max_length = e1000_igp_cable_length_140;
6724 case e1000_cable_length_140:
6725 *min_length = e1000_igp_cable_length_140;
6726 *max_length = e1000_igp_cable_length_170;
6729 return -E1000_ERR_PHY;
6732 } else if (hw->phy_type == e1000_phy_gg82563) {
6733 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_DSP_DISTANCE,
6737 cable_length = phy_data & GG82563_DSPD_CABLE_LENGTH;
6739 switch (cable_length) {
6740 case e1000_gg_cable_length_60:
6742 *max_length = e1000_igp_cable_length_60;
6744 case e1000_gg_cable_length_60_115:
6745 *min_length = e1000_igp_cable_length_60;
6746 *max_length = e1000_igp_cable_length_115;
6748 case e1000_gg_cable_length_115_150:
6749 *min_length = e1000_igp_cable_length_115;
6750 *max_length = e1000_igp_cable_length_150;
6752 case e1000_gg_cable_length_150:
6753 *min_length = e1000_igp_cable_length_150;
6754 *max_length = e1000_igp_cable_length_180;
6757 return -E1000_ERR_PHY;
6760 } else if(hw->phy_type == e1000_phy_igp) { /* For IGP PHY */
6761 uint16_t cur_agc_value;
6762 uint16_t min_agc_value = IGP01E1000_AGC_LENGTH_TABLE_SIZE;
6763 uint16_t agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
6764 {IGP01E1000_PHY_AGC_A,
6765 IGP01E1000_PHY_AGC_B,
6766 IGP01E1000_PHY_AGC_C,
6767 IGP01E1000_PHY_AGC_D};
6768 /* Read the AGC registers for all channels */
6769 for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
6771 ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
6775 cur_agc_value = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT;
6777 /* Value bound check. */
6778 if ((cur_agc_value >= IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1) ||
6779 (cur_agc_value == 0))
6780 return -E1000_ERR_PHY;
6782 agc_value += cur_agc_value;
6784 /* Update minimal AGC value. */
6785 if (min_agc_value > cur_agc_value)
6786 min_agc_value = cur_agc_value;
6789 /* Remove the minimal AGC result for length < 50m */
6790 if (agc_value < IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) {
6791 agc_value -= min_agc_value;
6793 /* Get the average length of the remaining 3 channels */
6794 agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1);
6796 /* Get the average length of all the 4 channels. */
6797 agc_value /= IGP01E1000_PHY_CHANNEL_NUM;
6800 /* Set the range of the calculated length. */
6801 *min_length = ((e1000_igp_cable_length_table[agc_value] -
6802 IGP01E1000_AGC_RANGE) > 0) ?
6803 (e1000_igp_cable_length_table[agc_value] -
6804 IGP01E1000_AGC_RANGE) : 0;
6805 *max_length = e1000_igp_cable_length_table[agc_value] +
6806 IGP01E1000_AGC_RANGE;
6807 } else if (hw->phy_type == e1000_phy_igp_2 ||
6808 hw->phy_type == e1000_phy_igp_3) {
6809 uint16_t cur_agc_index, max_agc_index = 0;
6810 uint16_t min_agc_index = IGP02E1000_AGC_LENGTH_TABLE_SIZE - 1;
6811 uint16_t agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] =
6812 {IGP02E1000_PHY_AGC_A,
6813 IGP02E1000_PHY_AGC_B,
6814 IGP02E1000_PHY_AGC_C,
6815 IGP02E1000_PHY_AGC_D};
6816 /* Read the AGC registers for all channels */
6817 for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
6818 ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
6822 /* Getting bits 15:9, which represent the combination of course and
6823 * fine gain values. The result is a number that can be put into
6824 * the lookup table to obtain the approximate cable length. */
6825 cur_agc_index = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
6826 IGP02E1000_AGC_LENGTH_MASK;
6828 /* Array index bound check. */
6829 if ((cur_agc_index >= IGP02E1000_AGC_LENGTH_TABLE_SIZE) ||
6830 (cur_agc_index == 0))
6831 return -E1000_ERR_PHY;
6833 /* Remove min & max AGC values from calculation. */
6834 if (e1000_igp_2_cable_length_table[min_agc_index] >
6835 e1000_igp_2_cable_length_table[cur_agc_index])
6836 min_agc_index = cur_agc_index;
6837 if (e1000_igp_2_cable_length_table[max_agc_index] <
6838 e1000_igp_2_cable_length_table[cur_agc_index])
6839 max_agc_index = cur_agc_index;
6841 agc_value += e1000_igp_2_cable_length_table[cur_agc_index];
6844 agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] +
6845 e1000_igp_2_cable_length_table[max_agc_index]);
6846 agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
6848 /* Calculate cable length with the error range of +/- 10 meters. */
6849 *min_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
6850 (agc_value - IGP02E1000_AGC_RANGE) : 0;
6851 *max_length = agc_value + IGP02E1000_AGC_RANGE;
6854 return E1000_SUCCESS;
6857 /******************************************************************************
6858 * Check the cable polarity
6860 * hw - Struct containing variables accessed by shared code
6861 * polarity - output parameter : 0 - Polarity is not reversed
6862 * 1 - Polarity is reversed.
6864 * returns: - E1000_ERR_XXX
6867 * For phy's older then IGP, this function simply reads the polarity bit in the
6868 * Phy Status register. For IGP phy's, this bit is valid only if link speed is
6869 * 10 Mbps. If the link speed is 100 Mbps there is no polarity so this bit will
6870 * return 0. If the link speed is 1000 Mbps the polarity status is in the
6871 * IGP01E1000_PHY_PCS_INIT_REG.
6872 *****************************************************************************/
6874 e1000_check_polarity(struct e1000_hw *hw,
6880 DEBUGFUNC("e1000_check_polarity");
6882 if ((hw->phy_type == e1000_phy_m88) ||
6883 (hw->phy_type == e1000_phy_gg82563)) {
6884 /* return the Polarity bit in the Status register. */
6885 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6889 *polarity = (phy_data & M88E1000_PSSR_REV_POLARITY) >>
6890 M88E1000_PSSR_REV_POLARITY_SHIFT;
6891 } else if (hw->phy_type == e1000_phy_igp ||
6892 hw->phy_type == e1000_phy_igp_3 ||
6893 hw->phy_type == e1000_phy_igp_2) {
6894 /* Read the Status register to check the speed */
6895 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
6900 /* If speed is 1000 Mbps, must read the IGP01E1000_PHY_PCS_INIT_REG to
6901 * find the polarity status */
6902 if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
6903 IGP01E1000_PSSR_SPEED_1000MBPS) {
6905 /* Read the GIG initialization PCS register (0x00B4) */
6906 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG,
6911 /* Check the polarity bits */
6912 *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ? 1 : 0;
6914 /* For 10 Mbps, read the polarity bit in the status register. (for
6915 * 100 Mbps this bit is always 0) */
6916 *polarity = phy_data & IGP01E1000_PSSR_POLARITY_REVERSED;
6918 } else if (hw->phy_type == e1000_phy_ife) {
6919 ret_val = e1000_read_phy_reg(hw, IFE_PHY_EXTENDED_STATUS_CONTROL,
6923 *polarity = (phy_data & IFE_PESC_POLARITY_REVERSED) >>
6924 IFE_PESC_POLARITY_REVERSED_SHIFT;
6926 return E1000_SUCCESS;
6929 /******************************************************************************
6930 * Check if Downshift occured
6932 * hw - Struct containing variables accessed by shared code
6933 * downshift - output parameter : 0 - No Downshift ocured.
6934 * 1 - Downshift ocured.
6936 * returns: - E1000_ERR_XXX
6939 * For phy's older then IGP, this function reads the Downshift bit in the Phy
6940 * Specific Status register. For IGP phy's, it reads the Downgrade bit in the
6941 * Link Health register. In IGP this bit is latched high, so the driver must
6942 * read it immediately after link is established.
6943 *****************************************************************************/
6945 e1000_check_downshift(struct e1000_hw *hw)
6950 DEBUGFUNC("e1000_check_downshift");
6952 if (hw->phy_type == e1000_phy_igp ||
6953 hw->phy_type == e1000_phy_igp_3 ||
6954 hw->phy_type == e1000_phy_igp_2) {
6955 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH,
6960 hw->speed_downgraded = (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0;
6961 } else if ((hw->phy_type == e1000_phy_m88) ||
6962 (hw->phy_type == e1000_phy_gg82563)) {
6963 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6968 hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >>
6969 M88E1000_PSSR_DOWNSHIFT_SHIFT;
6970 } else if (hw->phy_type == e1000_phy_ife) {
6971 /* e1000_phy_ife supports 10/100 speed only */
6972 hw->speed_downgraded = FALSE;
6975 return E1000_SUCCESS;
6978 /*****************************************************************************
6980 * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a
6981 * gigabit link is achieved to improve link quality.
6983 * hw: Struct containing variables accessed by shared code
6985 * returns: - E1000_ERR_PHY if fail to read/write the PHY
6986 * E1000_SUCCESS at any other case.
6988 ****************************************************************************/
6991 e1000_config_dsp_after_link_change(struct e1000_hw *hw,
6995 uint16_t phy_data, phy_saved_data, speed, duplex, i;
6996 uint16_t dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
6997 {IGP01E1000_PHY_AGC_PARAM_A,
6998 IGP01E1000_PHY_AGC_PARAM_B,
6999 IGP01E1000_PHY_AGC_PARAM_C,
7000 IGP01E1000_PHY_AGC_PARAM_D};
7001 uint16_t min_length, max_length;
7003 DEBUGFUNC("e1000_config_dsp_after_link_change");
7005 if(hw->phy_type != e1000_phy_igp)
7006 return E1000_SUCCESS;
7009 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
7011 DEBUGOUT("Error getting link speed and duplex\n");
7015 if(speed == SPEED_1000) {
7017 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
7021 if((hw->dsp_config_state == e1000_dsp_config_enabled) &&
7022 min_length >= e1000_igp_cable_length_50) {
7024 for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
7025 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i],
7030 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
7032 ret_val = e1000_write_phy_reg(hw, dsp_reg_array[i],
7037 hw->dsp_config_state = e1000_dsp_config_activated;
7040 if((hw->ffe_config_state == e1000_ffe_config_enabled) &&
7041 (min_length < e1000_igp_cable_length_50)) {
7043 uint16_t ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_20;
7044 uint32_t idle_errs = 0;
7046 /* clear previous idle error counts */
7047 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
7052 for(i = 0; i < ffe_idle_err_timeout; i++) {
7054 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
7059 idle_errs += (phy_data & SR_1000T_IDLE_ERROR_CNT);
7060 if(idle_errs > SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT) {
7061 hw->ffe_config_state = e1000_ffe_config_active;
7063 ret_val = e1000_write_phy_reg(hw,
7064 IGP01E1000_PHY_DSP_FFE,
7065 IGP01E1000_PHY_DSP_FFE_CM_CP);
7072 ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_100;
7077 if(hw->dsp_config_state == e1000_dsp_config_activated) {
7078 /* Save off the current value of register 0x2F5B to be restored at
7079 * the end of the routines. */
7080 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
7085 /* Disable the PHY transmitter */
7086 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
7093 ret_val = e1000_write_phy_reg(hw, 0x0000,
7094 IGP01E1000_IEEE_FORCE_GIGA);
7097 for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
7098 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i], &phy_data);
7102 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
7103 phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS;
7105 ret_val = e1000_write_phy_reg(hw,dsp_reg_array[i], phy_data);
7110 ret_val = e1000_write_phy_reg(hw, 0x0000,
7111 IGP01E1000_IEEE_RESTART_AUTONEG);
7117 /* Now enable the transmitter */
7118 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
7123 hw->dsp_config_state = e1000_dsp_config_enabled;
7126 if(hw->ffe_config_state == e1000_ffe_config_active) {
7127 /* Save off the current value of register 0x2F5B to be restored at
7128 * the end of the routines. */
7129 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
7134 /* Disable the PHY transmitter */
7135 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
7142 ret_val = e1000_write_phy_reg(hw, 0x0000,
7143 IGP01E1000_IEEE_FORCE_GIGA);
7146 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE,
7147 IGP01E1000_PHY_DSP_FFE_DEFAULT);
7151 ret_val = e1000_write_phy_reg(hw, 0x0000,
7152 IGP01E1000_IEEE_RESTART_AUTONEG);
7158 /* Now enable the transmitter */
7159 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
7164 hw->ffe_config_state = e1000_ffe_config_enabled;
7167 return E1000_SUCCESS;
7170 /*****************************************************************************
7171 * Set PHY to class A mode
7172 * Assumes the following operations will follow to enable the new class mode.
7173 * 1. Do a PHY soft reset
7174 * 2. Restart auto-negotiation or force link.
7176 * hw - Struct containing variables accessed by shared code
7177 ****************************************************************************/
7179 e1000_set_phy_mode(struct e1000_hw *hw)
7182 uint16_t eeprom_data;
7184 DEBUGFUNC("e1000_set_phy_mode");
7186 if((hw->mac_type == e1000_82545_rev_3) &&
7187 (hw->media_type == e1000_media_type_copper)) {
7188 ret_val = e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, 1, &eeprom_data);
7193 if((eeprom_data != EEPROM_RESERVED_WORD) &&
7194 (eeprom_data & EEPROM_PHY_CLASS_A)) {
7195 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x000B);
7198 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x8104);
7202 hw->phy_reset_disable = FALSE;
7206 return E1000_SUCCESS;
7209 /*****************************************************************************
7211 * This function sets the lplu state according to the active flag. When
7212 * activating lplu this function also disables smart speed and vise versa.
7213 * lplu will not be activated unless the device autonegotiation advertisment
7214 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
7215 * hw: Struct containing variables accessed by shared code
7216 * active - true to enable lplu false to disable lplu.
7218 * returns: - E1000_ERR_PHY if fail to read/write the PHY
7219 * E1000_SUCCESS at any other case.
7221 ****************************************************************************/
7224 e1000_set_d3_lplu_state(struct e1000_hw *hw,
7227 uint32_t phy_ctrl = 0;
7230 DEBUGFUNC("e1000_set_d3_lplu_state");
7232 if (hw->phy_type != e1000_phy_igp && hw->phy_type != e1000_phy_igp_2
7233 && hw->phy_type != e1000_phy_igp_3)
7234 return E1000_SUCCESS;
7236 /* During driver activity LPLU should not be used or it will attain link
7237 * from the lowest speeds starting from 10Mbps. The capability is used for
7238 * Dx transitions and states */
7239 if (hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2) {
7240 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data);
7243 } else if (hw->mac_type == e1000_ich8lan) {
7244 /* MAC writes into PHY register based on the state transition
7245 * and start auto-negotiation. SW driver can overwrite the settings
7246 * in CSR PHY power control E1000_PHY_CTRL register. */
7247 phy_ctrl = E1000_READ_REG(hw, PHY_CTRL);
7249 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
7255 if(hw->mac_type == e1000_82541_rev_2 ||
7256 hw->mac_type == e1000_82547_rev_2) {
7257 phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
7258 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
7262 if (hw->mac_type == e1000_ich8lan) {
7263 phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
7264 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7266 phy_data &= ~IGP02E1000_PM_D3_LPLU;
7267 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
7274 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
7275 * Dx states where the power conservation is most important. During
7276 * driver activity we should enable SmartSpeed, so performance is
7278 if (hw->smart_speed == e1000_smart_speed_on) {
7279 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7284 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
7285 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7289 } else if (hw->smart_speed == e1000_smart_speed_off) {
7290 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7295 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7296 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7302 } else if((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT) ||
7303 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL ) ||
7304 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) {
7306 if(hw->mac_type == e1000_82541_rev_2 ||
7307 hw->mac_type == e1000_82547_rev_2) {
7308 phy_data |= IGP01E1000_GMII_FLEX_SPD;
7309 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
7313 if (hw->mac_type == e1000_ich8lan) {
7314 phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
7315 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7317 phy_data |= IGP02E1000_PM_D3_LPLU;
7318 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
7325 /* When LPLU is enabled we should disable SmartSpeed */
7326 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
7330 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7331 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
7336 return E1000_SUCCESS;
7339 /*****************************************************************************
7341 * This function sets the lplu d0 state according to the active flag. When
7342 * activating lplu this function also disables smart speed and vise versa.
7343 * lplu will not be activated unless the device autonegotiation advertisment
7344 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
7345 * hw: Struct containing variables accessed by shared code
7346 * active - true to enable lplu false to disable lplu.
7348 * returns: - E1000_ERR_PHY if fail to read/write the PHY
7349 * E1000_SUCCESS at any other case.
7351 ****************************************************************************/
7354 e1000_set_d0_lplu_state(struct e1000_hw *hw,
7357 uint32_t phy_ctrl = 0;
7360 DEBUGFUNC("e1000_set_d0_lplu_state");
7362 if(hw->mac_type <= e1000_82547_rev_2)
7363 return E1000_SUCCESS;
7365 if (hw->mac_type == e1000_ich8lan) {
7366 phy_ctrl = E1000_READ_REG(hw, PHY_CTRL);
7368 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
7374 if (hw->mac_type == e1000_ich8lan) {
7375 phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
7376 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7378 phy_data &= ~IGP02E1000_PM_D0_LPLU;
7379 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
7384 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
7385 * Dx states where the power conservation is most important. During
7386 * driver activity we should enable SmartSpeed, so performance is
7388 if (hw->smart_speed == e1000_smart_speed_on) {
7389 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7394 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
7395 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7399 } else if (hw->smart_speed == e1000_smart_speed_off) {
7400 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7405 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7406 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7415 if (hw->mac_type == e1000_ich8lan) {
7416 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
7417 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7419 phy_data |= IGP02E1000_PM_D0_LPLU;
7420 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
7425 /* When LPLU is enabled we should disable SmartSpeed */
7426 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
7430 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7431 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
7436 return E1000_SUCCESS;
7439 /******************************************************************************
7440 * Change VCO speed register to improve Bit Error Rate performance of SERDES.
7442 * hw - Struct containing variables accessed by shared code
7443 *****************************************************************************/
7445 e1000_set_vco_speed(struct e1000_hw *hw)
7448 uint16_t default_page = 0;
7451 DEBUGFUNC("e1000_set_vco_speed");
7453 switch(hw->mac_type) {
7454 case e1000_82545_rev_3:
7455 case e1000_82546_rev_3:
7458 return E1000_SUCCESS;
7461 /* Set PHY register 30, page 5, bit 8 to 0 */
7463 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, &default_page);
7467 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005);
7471 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
7475 phy_data &= ~M88E1000_PHY_VCO_REG_BIT8;
7476 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
7480 /* Set PHY register 30, page 4, bit 11 to 1 */
7482 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004);
7486 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
7490 phy_data |= M88E1000_PHY_VCO_REG_BIT11;
7491 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
7495 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, default_page);
7499 return E1000_SUCCESS;
7503 /*****************************************************************************
7504 * This function reads the cookie from ARC ram.
7506 * returns: - E1000_SUCCESS .
7507 ****************************************************************************/
7509 e1000_host_if_read_cookie(struct e1000_hw * hw, uint8_t *buffer)
7512 uint32_t offset = E1000_MNG_DHCP_COOKIE_OFFSET;
7513 uint8_t length = E1000_MNG_DHCP_COOKIE_LENGTH;
7515 length = (length >> 2);
7516 offset = (offset >> 2);
7518 for (i = 0; i < length; i++) {
7519 *((uint32_t *) buffer + i) =
7520 E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset + i);
7522 return E1000_SUCCESS;
7526 /*****************************************************************************
7527 * This function checks whether the HOST IF is enabled for command operaton
7528 * and also checks whether the previous command is completed.
7529 * It busy waits in case of previous command is not completed.
7531 * returns: - E1000_ERR_HOST_INTERFACE_COMMAND in case if is not ready or
7533 * - E1000_SUCCESS for success.
7534 ****************************************************************************/
7536 e1000_mng_enable_host_if(struct e1000_hw * hw)
7541 /* Check that the host interface is enabled. */
7542 hicr = E1000_READ_REG(hw, HICR);
7543 if ((hicr & E1000_HICR_EN) == 0) {
7544 DEBUGOUT("E1000_HOST_EN bit disabled.\n");
7545 return -E1000_ERR_HOST_INTERFACE_COMMAND;
7547 /* check the previous command is completed */
7548 for (i = 0; i < E1000_MNG_DHCP_COMMAND_TIMEOUT; i++) {
7549 hicr = E1000_READ_REG(hw, HICR);
7550 if (!(hicr & E1000_HICR_C))
7555 if (i == E1000_MNG_DHCP_COMMAND_TIMEOUT) {
7556 DEBUGOUT("Previous command timeout failed .\n");
7557 return -E1000_ERR_HOST_INTERFACE_COMMAND;
7559 return E1000_SUCCESS;
7562 /*****************************************************************************
7563 * This function writes the buffer content at the offset given on the host if.
7564 * It also does alignment considerations to do the writes in most efficient way.
7565 * Also fills up the sum of the buffer in *buffer parameter.
7567 * returns - E1000_SUCCESS for success.
7568 ****************************************************************************/
7570 e1000_mng_host_if_write(struct e1000_hw * hw, uint8_t *buffer,
7571 uint16_t length, uint16_t offset, uint8_t *sum)
7574 uint8_t *bufptr = buffer;
7576 uint16_t remaining, i, j, prev_bytes;
7578 /* sum = only sum of the data and it is not checksum */
7580 if (length == 0 || offset + length > E1000_HI_MAX_MNG_DATA_LENGTH) {
7581 return -E1000_ERR_PARAM;
7584 tmp = (uint8_t *)&data;
7585 prev_bytes = offset & 0x3;
7590 data = E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset);
7591 for (j = prev_bytes; j < sizeof(uint32_t); j++) {
7592 *(tmp + j) = *bufptr++;
7595 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset, data);
7596 length -= j - prev_bytes;
7600 remaining = length & 0x3;
7601 length -= remaining;
7603 /* Calculate length in DWORDs */
7606 /* The device driver writes the relevant command block into the
7608 for (i = 0; i < length; i++) {
7609 for (j = 0; j < sizeof(uint32_t); j++) {
7610 *(tmp + j) = *bufptr++;
7614 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data);
7617 for (j = 0; j < sizeof(uint32_t); j++) {
7619 *(tmp + j) = *bufptr++;
7625 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data);
7628 return E1000_SUCCESS;
7632 /*****************************************************************************
7633 * This function writes the command header after does the checksum calculation.
7635 * returns - E1000_SUCCESS for success.
7636 ****************************************************************************/
7638 e1000_mng_write_cmd_header(struct e1000_hw * hw,
7639 struct e1000_host_mng_command_header * hdr)
7645 /* Write the whole command header structure which includes sum of
7648 uint16_t length = sizeof(struct e1000_host_mng_command_header);
7650 sum = hdr->checksum;
7653 buffer = (uint8_t *) hdr;
7658 hdr->checksum = 0 - sum;
7661 /* The device driver writes the relevant command block into the ram area. */
7662 for (i = 0; i < length; i++) {
7663 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, i, *((uint32_t *) hdr + i));
7664 E1000_WRITE_FLUSH(hw);
7667 return E1000_SUCCESS;
7671 /*****************************************************************************
7672 * This function indicates to ARC that a new command is pending which completes
7673 * one write operation by the driver.
7675 * returns - E1000_SUCCESS for success.
7676 ****************************************************************************/
7678 e1000_mng_write_commit(
7679 struct e1000_hw * hw)
7683 hicr = E1000_READ_REG(hw, HICR);
7684 /* Setting this bit tells the ARC that a new command is pending. */
7685 E1000_WRITE_REG(hw, HICR, hicr | E1000_HICR_C);
7687 return E1000_SUCCESS;
7691 /*****************************************************************************
7692 * This function checks the mode of the firmware.
7694 * returns - TRUE when the mode is IAMT or FALSE.
7695 ****************************************************************************/
7697 e1000_check_mng_mode(struct e1000_hw *hw)
7701 fwsm = E1000_READ_REG(hw, FWSM);
7703 if (hw->mac_type == e1000_ich8lan) {
7704 if ((fwsm & E1000_FWSM_MODE_MASK) ==
7705 (E1000_MNG_ICH_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
7707 } else if ((fwsm & E1000_FWSM_MODE_MASK) ==
7708 (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
7715 /*****************************************************************************
7716 * This function writes the dhcp info .
7717 ****************************************************************************/
7719 e1000_mng_write_dhcp_info(struct e1000_hw * hw, uint8_t *buffer,
7723 struct e1000_host_mng_command_header hdr;
7725 hdr.command_id = E1000_MNG_DHCP_TX_PAYLOAD_CMD;
7726 hdr.command_length = length;
7731 ret_val = e1000_mng_enable_host_if(hw);
7732 if (ret_val == E1000_SUCCESS) {
7733 ret_val = e1000_mng_host_if_write(hw, buffer, length, sizeof(hdr),
7735 if (ret_val == E1000_SUCCESS) {
7736 ret_val = e1000_mng_write_cmd_header(hw, &hdr);
7737 if (ret_val == E1000_SUCCESS)
7738 ret_val = e1000_mng_write_commit(hw);
7745 /*****************************************************************************
7746 * This function calculates the checksum.
7748 * returns - checksum of buffer contents.
7749 ****************************************************************************/
7751 e1000_calculate_mng_checksum(char *buffer, uint32_t length)
7759 for (i=0; i < length; i++)
7762 return (uint8_t) (0 - sum);
7765 /*****************************************************************************
7766 * This function checks whether tx pkt filtering needs to be enabled or not.
7768 * returns - TRUE for packet filtering or FALSE.
7769 ****************************************************************************/
7771 e1000_enable_tx_pkt_filtering(struct e1000_hw *hw)
7773 /* called in init as well as watchdog timer functions */
7775 int32_t ret_val, checksum;
7776 boolean_t tx_filter = FALSE;
7777 struct e1000_host_mng_dhcp_cookie *hdr = &(hw->mng_cookie);
7778 uint8_t *buffer = (uint8_t *) &(hw->mng_cookie);
7780 if (e1000_check_mng_mode(hw)) {
7781 ret_val = e1000_mng_enable_host_if(hw);
7782 if (ret_val == E1000_SUCCESS) {
7783 ret_val = e1000_host_if_read_cookie(hw, buffer);
7784 if (ret_val == E1000_SUCCESS) {
7785 checksum = hdr->checksum;
7787 if ((hdr->signature == E1000_IAMT_SIGNATURE) &&
7788 checksum == e1000_calculate_mng_checksum((char *)buffer,
7789 E1000_MNG_DHCP_COOKIE_LENGTH)) {
7791 E1000_MNG_DHCP_COOKIE_STATUS_PARSING_SUPPORT)
7800 hw->tx_pkt_filtering = tx_filter;
7804 /******************************************************************************
7805 * Verifies the hardware needs to allow ARPs to be processed by the host
7807 * hw - Struct containing variables accessed by shared code
7809 * returns: - TRUE/FALSE
7811 *****************************************************************************/
7813 e1000_enable_mng_pass_thru(struct e1000_hw *hw)
7816 uint32_t fwsm, factps;
7818 if (hw->asf_firmware_present) {
7819 manc = E1000_READ_REG(hw, MANC);
7821 if (!(manc & E1000_MANC_RCV_TCO_EN) ||
7822 !(manc & E1000_MANC_EN_MAC_ADDR_FILTER))
7824 if (e1000_arc_subsystem_valid(hw) == TRUE) {
7825 fwsm = E1000_READ_REG(hw, FWSM);
7826 factps = E1000_READ_REG(hw, FACTPS);
7828 if (((fwsm & E1000_FWSM_MODE_MASK) ==
7829 (e1000_mng_mode_pt << E1000_FWSM_MODE_SHIFT)) &&
7830 (factps & E1000_FACTPS_MNGCG))
7833 if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN))
7840 e1000_polarity_reversal_workaround(struct e1000_hw *hw)
7843 uint16_t mii_status_reg;
7846 /* Polarity reversal workaround for forced 10F/10H links. */
7848 /* Disable the transmitter on the PHY */
7850 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
7853 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF);
7857 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
7861 /* This loop will early-out if the NO link condition has been met. */
7862 for(i = PHY_FORCE_TIME; i > 0; i--) {
7863 /* Read the MII Status Register and wait for Link Status bit
7867 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
7871 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
7875 if((mii_status_reg & ~MII_SR_LINK_STATUS) == 0) break;
7876 msec_delay_irq(100);
7879 /* Recommended delay time after link has been lost */
7880 msec_delay_irq(1000);
7882 /* Now we will re-enable th transmitter on the PHY */
7884 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
7888 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0);
7892 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00);
7896 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000);
7900 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
7904 /* This loop will early-out if the link condition has been met. */
7905 for(i = PHY_FORCE_TIME; i > 0; i--) {
7906 /* Read the MII Status Register and wait for Link Status bit
7910 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
7914 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
7918 if(mii_status_reg & MII_SR_LINK_STATUS) break;
7919 msec_delay_irq(100);
7921 return E1000_SUCCESS;
7924 /***************************************************************************
7926 * Disables PCI-Express master access.
7928 * hw: Struct containing variables accessed by shared code
7932 ***************************************************************************/
7934 e1000_set_pci_express_master_disable(struct e1000_hw *hw)
7938 DEBUGFUNC("e1000_set_pci_express_master_disable");
7940 if (hw->bus_type != e1000_bus_type_pci_express)
7943 ctrl = E1000_READ_REG(hw, CTRL);
7944 ctrl |= E1000_CTRL_GIO_MASTER_DISABLE;
7945 E1000_WRITE_REG(hw, CTRL, ctrl);
7948 /***************************************************************************
7950 * Enables PCI-Express master access.
7952 * hw: Struct containing variables accessed by shared code
7956 ***************************************************************************/
7959 e1000_enable_pciex_master(struct e1000_hw *hw)
7963 DEBUGFUNC("e1000_enable_pciex_master");
7965 if (hw->bus_type != e1000_bus_type_pci_express)
7968 ctrl = E1000_READ_REG(hw, CTRL);
7969 ctrl &= ~E1000_CTRL_GIO_MASTER_DISABLE;
7970 E1000_WRITE_REG(hw, CTRL, ctrl);
7974 /*******************************************************************************
7976 * Disables PCI-Express master access and verifies there are no pending requests
7978 * hw: Struct containing variables accessed by shared code
7980 * returns: - E1000_ERR_MASTER_REQUESTS_PENDING if master disable bit hasn't
7981 * caused the master requests to be disabled.
7982 * E1000_SUCCESS master requests disabled.
7984 ******************************************************************************/
7986 e1000_disable_pciex_master(struct e1000_hw *hw)
7988 int32_t timeout = MASTER_DISABLE_TIMEOUT; /* 80ms */
7990 DEBUGFUNC("e1000_disable_pciex_master");
7992 if (hw->bus_type != e1000_bus_type_pci_express)
7993 return E1000_SUCCESS;
7995 e1000_set_pci_express_master_disable(hw);
7998 if(!(E1000_READ_REG(hw, STATUS) & E1000_STATUS_GIO_MASTER_ENABLE))
8006 DEBUGOUT("Master requests are pending.\n");
8007 return -E1000_ERR_MASTER_REQUESTS_PENDING;
8010 return E1000_SUCCESS;
8013 /*******************************************************************************
8015 * Check for EEPROM Auto Read bit done.
8017 * hw: Struct containing variables accessed by shared code
8019 * returns: - E1000_ERR_RESET if fail to reset MAC
8020 * E1000_SUCCESS at any other case.
8022 ******************************************************************************/
8024 e1000_get_auto_rd_done(struct e1000_hw *hw)
8026 int32_t timeout = AUTO_READ_DONE_TIMEOUT;
8028 DEBUGFUNC("e1000_get_auto_rd_done");
8030 switch (hw->mac_type) {
8037 case e1000_80003es2lan:
8040 if (E1000_READ_REG(hw, EECD) & E1000_EECD_AUTO_RD)
8047 DEBUGOUT("Auto read by HW from EEPROM has not completed.\n");
8048 return -E1000_ERR_RESET;
8053 /* PHY configuration from NVM just starts after EECD_AUTO_RD sets to high.
8054 * Need to wait for PHY configuration completion before accessing NVM
8056 if (hw->mac_type == e1000_82573)
8059 return E1000_SUCCESS;
8062 /***************************************************************************
8063 * Checks if the PHY configuration is done
8065 * hw: Struct containing variables accessed by shared code
8067 * returns: - E1000_ERR_RESET if fail to reset MAC
8068 * E1000_SUCCESS at any other case.
8070 ***************************************************************************/
8072 e1000_get_phy_cfg_done(struct e1000_hw *hw)
8074 int32_t timeout = PHY_CFG_TIMEOUT;
8075 uint32_t cfg_mask = E1000_EEPROM_CFG_DONE;
8077 DEBUGFUNC("e1000_get_phy_cfg_done");
8079 switch (hw->mac_type) {
8083 case e1000_80003es2lan:
8084 /* Separate *_CFG_DONE_* bit for each port */
8085 if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
8086 cfg_mask = E1000_EEPROM_CFG_DONE_PORT_1;
8091 if (E1000_READ_REG(hw, EEMNGCTL) & cfg_mask)
8099 DEBUGOUT("MNG configuration cycle has not completed.\n");
8100 return -E1000_ERR_RESET;
8105 return E1000_SUCCESS;
8108 /***************************************************************************
8110 * Using the combination of SMBI and SWESMBI semaphore bits when resetting
8111 * adapter or Eeprom access.
8113 * hw: Struct containing variables accessed by shared code
8115 * returns: - E1000_ERR_EEPROM if fail to access EEPROM.
8116 * E1000_SUCCESS at any other case.
8118 ***************************************************************************/
8120 e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw)
8125 DEBUGFUNC("e1000_get_hw_eeprom_semaphore");
8127 if(!hw->eeprom_semaphore_present)
8128 return E1000_SUCCESS;
8130 if (hw->mac_type == e1000_80003es2lan) {
8131 /* Get the SW semaphore. */
8132 if (e1000_get_software_semaphore(hw) != E1000_SUCCESS)
8133 return -E1000_ERR_EEPROM;
8136 /* Get the FW semaphore. */
8137 timeout = hw->eeprom.word_size + 1;
8139 swsm = E1000_READ_REG(hw, SWSM);
8140 swsm |= E1000_SWSM_SWESMBI;
8141 E1000_WRITE_REG(hw, SWSM, swsm);
8142 /* if we managed to set the bit we got the semaphore. */
8143 swsm = E1000_READ_REG(hw, SWSM);
8144 if(swsm & E1000_SWSM_SWESMBI)
8152 /* Release semaphores */
8153 e1000_put_hw_eeprom_semaphore(hw);
8154 DEBUGOUT("Driver can't access the Eeprom - SWESMBI bit is set.\n");
8155 return -E1000_ERR_EEPROM;
8158 return E1000_SUCCESS;
8161 /***************************************************************************
8162 * This function clears HW semaphore bits.
8164 * hw: Struct containing variables accessed by shared code
8168 ***************************************************************************/
8170 e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw)
8174 DEBUGFUNC("e1000_put_hw_eeprom_semaphore");
8176 if(!hw->eeprom_semaphore_present)
8179 swsm = E1000_READ_REG(hw, SWSM);
8180 if (hw->mac_type == e1000_80003es2lan) {
8181 /* Release both semaphores. */
8182 swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
8184 swsm &= ~(E1000_SWSM_SWESMBI);
8185 E1000_WRITE_REG(hw, SWSM, swsm);
8188 /***************************************************************************
8190 * Obtaining software semaphore bit (SMBI) before resetting PHY.
8192 * hw: Struct containing variables accessed by shared code
8194 * returns: - E1000_ERR_RESET if fail to obtain semaphore.
8195 * E1000_SUCCESS at any other case.
8197 ***************************************************************************/
8199 e1000_get_software_semaphore(struct e1000_hw *hw)
8201 int32_t timeout = hw->eeprom.word_size + 1;
8204 DEBUGFUNC("e1000_get_software_semaphore");
8206 if (hw->mac_type != e1000_80003es2lan)
8207 return E1000_SUCCESS;
8210 swsm = E1000_READ_REG(hw, SWSM);
8211 /* If SMBI bit cleared, it is now set and we hold the semaphore */
8212 if(!(swsm & E1000_SWSM_SMBI))
8219 DEBUGOUT("Driver can't access device - SMBI bit is set.\n");
8220 return -E1000_ERR_RESET;
8223 return E1000_SUCCESS;
8226 /***************************************************************************
8228 * Release semaphore bit (SMBI).
8230 * hw: Struct containing variables accessed by shared code
8232 ***************************************************************************/
8234 e1000_release_software_semaphore(struct e1000_hw *hw)
8238 DEBUGFUNC("e1000_release_software_semaphore");
8240 if (hw->mac_type != e1000_80003es2lan)
8243 swsm = E1000_READ_REG(hw, SWSM);
8244 /* Release the SW semaphores.*/
8245 swsm &= ~E1000_SWSM_SMBI;
8246 E1000_WRITE_REG(hw, SWSM, swsm);
8249 /******************************************************************************
8250 * Checks if PHY reset is blocked due to SOL/IDER session, for example.
8251 * Returning E1000_BLK_PHY_RESET isn't necessarily an error. But it's up to
8252 * the caller to figure out how to deal with it.
8254 * hw - Struct containing variables accessed by shared code
8256 * returns: - E1000_BLK_PHY_RESET
8259 *****************************************************************************/
8261 e1000_check_phy_reset_block(struct e1000_hw *hw)
8266 if (hw->mac_type == e1000_ich8lan) {
8267 fwsm = E1000_READ_REG(hw, FWSM);
8268 return (fwsm & E1000_FWSM_RSPCIPHY) ? E1000_SUCCESS
8269 : E1000_BLK_PHY_RESET;
8272 if (hw->mac_type > e1000_82547_rev_2)
8273 manc = E1000_READ_REG(hw, MANC);
8274 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
8275 E1000_BLK_PHY_RESET : E1000_SUCCESS;
8279 e1000_arc_subsystem_valid(struct e1000_hw *hw)
8283 /* On 8257x silicon, registers in the range of 0x8800 - 0x8FFC
8284 * may not be provided a DMA clock when no manageability features are
8285 * enabled. We do not want to perform any reads/writes to these registers
8286 * if this is the case. We read FWSM to determine the manageability mode.
8288 switch (hw->mac_type) {
8292 case e1000_80003es2lan:
8293 fwsm = E1000_READ_REG(hw, FWSM);
8294 if((fwsm & E1000_FWSM_MODE_MASK) != 0)
8306 /******************************************************************************
8307 * Configure PCI-Ex no-snoop
8309 * hw - Struct containing variables accessed by shared code.
8310 * no_snoop - Bitmap of no-snoop events.
8312 * returns: E1000_SUCCESS
8314 *****************************************************************************/
8316 e1000_set_pci_ex_no_snoop(struct e1000_hw *hw, uint32_t no_snoop)
8318 uint32_t gcr_reg = 0;
8320 DEBUGFUNC("e1000_set_pci_ex_no_snoop");
8322 if (hw->bus_type == e1000_bus_type_unknown)
8323 e1000_get_bus_info(hw);
8325 if (hw->bus_type != e1000_bus_type_pci_express)
8326 return E1000_SUCCESS;
8329 gcr_reg = E1000_READ_REG(hw, GCR);
8330 gcr_reg &= ~(PCI_EX_NO_SNOOP_ALL);
8331 gcr_reg |= no_snoop;
8332 E1000_WRITE_REG(hw, GCR, gcr_reg);
8334 if (hw->mac_type == e1000_ich8lan) {
8337 E1000_WRITE_REG(hw, GCR, PCI_EX_82566_SNOOP_ALL);
8339 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
8340 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
8341 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
8344 return E1000_SUCCESS;
8347 /***************************************************************************
8349 * Get software semaphore FLAG bit (SWFLAG).
8350 * SWFLAG is used to synchronize the access to all shared resource between
8353 * hw: Struct containing variables accessed by shared code
8355 ***************************************************************************/
8357 e1000_get_software_flag(struct e1000_hw *hw)
8359 int32_t timeout = PHY_CFG_TIMEOUT;
8360 uint32_t extcnf_ctrl;
8362 DEBUGFUNC("e1000_get_software_flag");
8364 if (hw->mac_type == e1000_ich8lan) {
8366 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
8367 extcnf_ctrl |= E1000_EXTCNF_CTRL_SWFLAG;
8368 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
8370 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
8371 if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG)
8378 DEBUGOUT("FW or HW locks the resource too long.\n");
8379 return -E1000_ERR_CONFIG;
8383 return E1000_SUCCESS;
8386 /***************************************************************************
8388 * Release software semaphore FLAG bit (SWFLAG).
8389 * SWFLAG is used to synchronize the access to all shared resource between
8392 * hw: Struct containing variables accessed by shared code
8394 ***************************************************************************/
8396 e1000_release_software_flag(struct e1000_hw *hw)
8398 uint32_t extcnf_ctrl;
8400 DEBUGFUNC("e1000_release_software_flag");
8402 if (hw->mac_type == e1000_ich8lan) {
8403 extcnf_ctrl= E1000_READ_REG(hw, EXTCNF_CTRL);
8404 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
8405 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
8411 /***************************************************************************
8413 * Disable dynamic power down mode in ife PHY.
8414 * It can be used to workaround band-gap problem.
8416 * hw: Struct containing variables accessed by shared code
8418 ***************************************************************************/
8421 e1000_ife_disable_dynamic_power_down(struct e1000_hw *hw)
8424 int32_t ret_val = E1000_SUCCESS;
8426 DEBUGFUNC("e1000_ife_disable_dynamic_power_down");
8428 if (hw->phy_type == e1000_phy_ife) {
8429 ret_val = e1000_read_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL, &phy_data);
8433 phy_data |= IFE_PSC_DISABLE_DYNAMIC_POWER_DOWN;
8434 ret_val = e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL, phy_data);
8441 /***************************************************************************
8443 * Enable dynamic power down mode in ife PHY.
8444 * It can be used to workaround band-gap problem.
8446 * hw: Struct containing variables accessed by shared code
8448 ***************************************************************************/
8451 e1000_ife_enable_dynamic_power_down(struct e1000_hw *hw)
8454 int32_t ret_val = E1000_SUCCESS;
8456 DEBUGFUNC("e1000_ife_enable_dynamic_power_down");
8458 if (hw->phy_type == e1000_phy_ife) {
8459 ret_val = e1000_read_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL, &phy_data);
8463 phy_data &= ~IFE_PSC_DISABLE_DYNAMIC_POWER_DOWN;
8464 ret_val = e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL, phy_data);
8471 /******************************************************************************
8472 * Reads a 16 bit word or words from the EEPROM using the ICH8's flash access
8475 * hw - Struct containing variables accessed by shared code
8476 * offset - offset of word in the EEPROM to read
8477 * data - word read from the EEPROM
8478 * words - number of words to read
8479 *****************************************************************************/
8481 e1000_read_eeprom_ich8(struct e1000_hw *hw, uint16_t offset, uint16_t words,
8484 int32_t error = E1000_SUCCESS;
8485 uint32_t flash_bank = 0;
8486 uint32_t act_offset = 0;
8487 uint32_t bank_offset = 0;
8491 /* We need to know which is the valid flash bank. In the event
8492 * that we didn't allocate eeprom_shadow_ram, we may not be
8493 * managing flash_bank. So it cannot be trusted and needs
8494 * to be updated with each read.
8496 /* Value of bit 22 corresponds to the flash bank we're on. */
8497 flash_bank = (E1000_READ_REG(hw, EECD) & E1000_EECD_SEC1VAL) ? 1 : 0;
8499 /* Adjust offset appropriately if we're on bank 1 - adjust for word size */
8500 bank_offset = flash_bank * (hw->flash_bank_size * 2);
8502 error = e1000_get_software_flag(hw);
8503 if (error != E1000_SUCCESS)
8506 for (i = 0; i < words; i++) {
8507 if (hw->eeprom_shadow_ram != NULL &&
8508 hw->eeprom_shadow_ram[offset+i].modified == TRUE) {
8509 data[i] = hw->eeprom_shadow_ram[offset+i].eeprom_word;
8511 /* The NVM part needs a byte offset, hence * 2 */
8512 act_offset = bank_offset + ((offset + i) * 2);
8513 error = e1000_read_ich8_word(hw, act_offset, &word);
8514 if (error != E1000_SUCCESS)
8520 e1000_release_software_flag(hw);
8525 /******************************************************************************
8526 * Writes a 16 bit word or words to the EEPROM using the ICH8's flash access
8527 * register. Actually, writes are written to the shadow ram cache in the hw
8528 * structure hw->e1000_shadow_ram. e1000_commit_shadow_ram flushes this to
8529 * the NVM, which occurs when the NVM checksum is updated.
8531 * hw - Struct containing variables accessed by shared code
8532 * offset - offset of word in the EEPROM to write
8533 * words - number of words to write
8534 * data - words to write to the EEPROM
8535 *****************************************************************************/
8537 e1000_write_eeprom_ich8(struct e1000_hw *hw, uint16_t offset, uint16_t words,
8541 int32_t error = E1000_SUCCESS;
8543 error = e1000_get_software_flag(hw);
8544 if (error != E1000_SUCCESS)
8547 /* A driver can write to the NVM only if it has eeprom_shadow_ram
8548 * allocated. Subsequent reads to the modified words are read from
8549 * this cached structure as well. Writes will only go into this
8550 * cached structure unless it's followed by a call to
8551 * e1000_update_eeprom_checksum() where it will commit the changes
8552 * and clear the "modified" field.
8554 if (hw->eeprom_shadow_ram != NULL) {
8555 for (i = 0; i < words; i++) {
8556 if ((offset + i) < E1000_SHADOW_RAM_WORDS) {
8557 hw->eeprom_shadow_ram[offset+i].modified = TRUE;
8558 hw->eeprom_shadow_ram[offset+i].eeprom_word = data[i];
8560 error = -E1000_ERR_EEPROM;
8565 /* Drivers have the option to not allocate eeprom_shadow_ram as long
8566 * as they don't perform any NVM writes. An attempt in doing so
8567 * will result in this error.
8569 error = -E1000_ERR_EEPROM;
8572 e1000_release_software_flag(hw);
8577 /******************************************************************************
8578 * This function does initial flash setup so that a new read/write/erase cycle
8581 * hw - The pointer to the hw structure
8582 ****************************************************************************/
8584 e1000_ich8_cycle_init(struct e1000_hw *hw)
8586 union ich8_hws_flash_status hsfsts;
8587 int32_t error = E1000_ERR_EEPROM;
8590 DEBUGFUNC("e1000_ich8_cycle_init");
8592 hsfsts.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFSTS);
8594 /* May be check the Flash Des Valid bit in Hw status */
8595 if (hsfsts.hsf_status.fldesvalid == 0) {
8596 DEBUGOUT("Flash descriptor invalid. SW Sequencing must be used.");
8600 /* Clear FCERR in Hw status by writing 1 */
8601 /* Clear DAEL in Hw status by writing a 1 */
8602 hsfsts.hsf_status.flcerr = 1;
8603 hsfsts.hsf_status.dael = 1;
8605 E1000_WRITE_ICH8_REG16(hw, ICH8_FLASH_HSFSTS, hsfsts.regval);
8607 /* Either we should have a hardware SPI cycle in progress bit to check
8608 * against, in order to start a new cycle or FDONE bit should be changed
8609 * in the hardware so that it is 1 after harware reset, which can then be
8610 * used as an indication whether a cycle is in progress or has been
8611 * completed .. we should also have some software semaphore mechanism to
8612 * guard FDONE or the cycle in progress bit so that two threads access to
8613 * those bits can be sequentiallized or a way so that 2 threads dont
8614 * start the cycle at the same time */
8616 if (hsfsts.hsf_status.flcinprog == 0) {
8617 /* There is no cycle running at present, so we can start a cycle */
8618 /* Begin by setting Flash Cycle Done. */
8619 hsfsts.hsf_status.flcdone = 1;
8620 E1000_WRITE_ICH8_REG16(hw, ICH8_FLASH_HSFSTS, hsfsts.regval);
8621 error = E1000_SUCCESS;
8623 /* otherwise poll for sometime so the current cycle has a chance
8624 * to end before giving up. */
8625 for (i = 0; i < ICH8_FLASH_COMMAND_TIMEOUT; i++) {
8626 hsfsts.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFSTS);
8627 if (hsfsts.hsf_status.flcinprog == 0) {
8628 error = E1000_SUCCESS;
8633 if (error == E1000_SUCCESS) {
8634 /* Successful in waiting for previous cycle to timeout,
8635 * now set the Flash Cycle Done. */
8636 hsfsts.hsf_status.flcdone = 1;
8637 E1000_WRITE_ICH8_REG16(hw, ICH8_FLASH_HSFSTS, hsfsts.regval);
8639 DEBUGOUT("Flash controller busy, cannot get access");
8645 /******************************************************************************
8646 * This function starts a flash cycle and waits for its completion
8648 * hw - The pointer to the hw structure
8649 ****************************************************************************/
8651 e1000_ich8_flash_cycle(struct e1000_hw *hw, uint32_t timeout)
8653 union ich8_hws_flash_ctrl hsflctl;
8654 union ich8_hws_flash_status hsfsts;
8655 int32_t error = E1000_ERR_EEPROM;
8658 /* Start a cycle by writing 1 in Flash Cycle Go in Hw Flash Control */
8659 hsflctl.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFCTL);
8660 hsflctl.hsf_ctrl.flcgo = 1;
8661 E1000_WRITE_ICH8_REG16(hw, ICH8_FLASH_HSFCTL, hsflctl.regval);
8663 /* wait till FDONE bit is set to 1 */
8665 hsfsts.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFSTS);
8666 if (hsfsts.hsf_status.flcdone == 1)
8670 } while (i < timeout);
8671 if (hsfsts.hsf_status.flcdone == 1 && hsfsts.hsf_status.flcerr == 0) {
8672 error = E1000_SUCCESS;
8677 /******************************************************************************
8678 * Reads a byte or word from the NVM using the ICH8 flash access registers.
8680 * hw - The pointer to the hw structure
8681 * index - The index of the byte or word to read.
8682 * size - Size of data to read, 1=byte 2=word
8683 * data - Pointer to the word to store the value read.
8684 *****************************************************************************/
8686 e1000_read_ich8_data(struct e1000_hw *hw, uint32_t index,
8687 uint32_t size, uint16_t* data)
8689 union ich8_hws_flash_status hsfsts;
8690 union ich8_hws_flash_ctrl hsflctl;
8691 uint32_t flash_linear_address;
8692 uint32_t flash_data = 0;
8693 int32_t error = -E1000_ERR_EEPROM;
8696 DEBUGFUNC("e1000_read_ich8_data");
8698 if (size < 1 || size > 2 || data == 0x0 ||
8699 index > ICH8_FLASH_LINEAR_ADDR_MASK)
8702 flash_linear_address = (ICH8_FLASH_LINEAR_ADDR_MASK & index) +
8703 hw->flash_base_addr;
8708 error = e1000_ich8_cycle_init(hw);
8709 if (error != E1000_SUCCESS)
8712 hsflctl.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFCTL);
8713 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
8714 hsflctl.hsf_ctrl.fldbcount = size - 1;
8715 hsflctl.hsf_ctrl.flcycle = ICH8_CYCLE_READ;
8716 E1000_WRITE_ICH8_REG16(hw, ICH8_FLASH_HSFCTL, hsflctl.regval);
8718 /* Write the last 24 bits of index into Flash Linear address field in
8720 /* TODO: TBD maybe check the index against the size of flash */
8722 E1000_WRITE_ICH8_REG(hw, ICH8_FLASH_FADDR, flash_linear_address);
8724 error = e1000_ich8_flash_cycle(hw, ICH8_FLASH_COMMAND_TIMEOUT);
8726 /* Check if FCERR is set to 1, if set to 1, clear it and try the whole
8727 * sequence a few more times, else read in (shift in) the Flash Data0,
8728 * the order is least significant byte first msb to lsb */
8729 if (error == E1000_SUCCESS) {
8730 flash_data = E1000_READ_ICH8_REG(hw, ICH8_FLASH_FDATA0);
8732 *data = (uint8_t)(flash_data & 0x000000FF);
8733 } else if (size == 2) {
8734 *data = (uint16_t)(flash_data & 0x0000FFFF);
8738 /* If we've gotten here, then things are probably completely hosed,
8739 * but if the error condition is detected, it won't hurt to give
8740 * it another try...ICH8_FLASH_CYCLE_REPEAT_COUNT times.
8742 hsfsts.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFSTS);
8743 if (hsfsts.hsf_status.flcerr == 1) {
8744 /* Repeat for some time before giving up. */
8746 } else if (hsfsts.hsf_status.flcdone == 0) {
8747 DEBUGOUT("Timeout error - flash cycle did not complete.");
8751 } while (count++ < ICH8_FLASH_CYCLE_REPEAT_COUNT);
8756 /******************************************************************************
8757 * Writes One /two bytes to the NVM using the ICH8 flash access registers.
8759 * hw - The pointer to the hw structure
8760 * index - The index of the byte/word to read.
8761 * size - Size of data to read, 1=byte 2=word
8762 * data - The byte(s) to write to the NVM.
8763 *****************************************************************************/
8765 e1000_write_ich8_data(struct e1000_hw *hw, uint32_t index, uint32_t size,
8768 union ich8_hws_flash_status hsfsts;
8769 union ich8_hws_flash_ctrl hsflctl;
8770 uint32_t flash_linear_address;
8771 uint32_t flash_data = 0;
8772 int32_t error = -E1000_ERR_EEPROM;
8775 DEBUGFUNC("e1000_write_ich8_data");
8777 if (size < 1 || size > 2 || data > size * 0xff ||
8778 index > ICH8_FLASH_LINEAR_ADDR_MASK)
8781 flash_linear_address = (ICH8_FLASH_LINEAR_ADDR_MASK & index) +
8782 hw->flash_base_addr;
8787 error = e1000_ich8_cycle_init(hw);
8788 if (error != E1000_SUCCESS)
8791 hsflctl.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFCTL);
8792 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
8793 hsflctl.hsf_ctrl.fldbcount = size -1;
8794 hsflctl.hsf_ctrl.flcycle = ICH8_CYCLE_WRITE;
8795 E1000_WRITE_ICH8_REG16(hw, ICH8_FLASH_HSFCTL, hsflctl.regval);
8797 /* Write the last 24 bits of index into Flash Linear address field in
8799 E1000_WRITE_ICH8_REG(hw, ICH8_FLASH_FADDR, flash_linear_address);
8802 flash_data = (uint32_t)data & 0x00FF;
8804 flash_data = (uint32_t)data;
8806 E1000_WRITE_ICH8_REG(hw, ICH8_FLASH_FDATA0, flash_data);
8808 /* check if FCERR is set to 1 , if set to 1, clear it and try the whole
8809 * sequence a few more times else done */
8810 error = e1000_ich8_flash_cycle(hw, ICH8_FLASH_COMMAND_TIMEOUT);
8811 if (error == E1000_SUCCESS) {
8814 /* If we're here, then things are most likely completely hosed,
8815 * but if the error condition is detected, it won't hurt to give
8816 * it another try...ICH8_FLASH_CYCLE_REPEAT_COUNT times.
8818 hsfsts.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFSTS);
8819 if (hsfsts.hsf_status.flcerr == 1) {
8820 /* Repeat for some time before giving up. */
8822 } else if (hsfsts.hsf_status.flcdone == 0) {
8823 DEBUGOUT("Timeout error - flash cycle did not complete.");
8827 } while (count++ < ICH8_FLASH_CYCLE_REPEAT_COUNT);
8832 /******************************************************************************
8833 * Reads a single byte from the NVM using the ICH8 flash access registers.
8835 * hw - pointer to e1000_hw structure
8836 * index - The index of the byte to read.
8837 * data - Pointer to a byte to store the value read.
8838 *****************************************************************************/
8840 e1000_read_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t* data)
8842 int32_t status = E1000_SUCCESS;
8845 status = e1000_read_ich8_data(hw, index, 1, &word);
8846 if (status == E1000_SUCCESS) {
8847 *data = (uint8_t)word;
8853 /******************************************************************************
8854 * Writes a single byte to the NVM using the ICH8 flash access registers.
8855 * Performs verification by reading back the value and then going through
8856 * a retry algorithm before giving up.
8858 * hw - pointer to e1000_hw structure
8859 * index - The index of the byte to write.
8860 * byte - The byte to write to the NVM.
8861 *****************************************************************************/
8863 e1000_verify_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t byte)
8865 int32_t error = E1000_SUCCESS;
8866 int32_t program_retries;
8869 e1000_write_ich8_byte(hw, index, byte);
8872 for (program_retries = 0; program_retries < 100; program_retries++) {
8873 e1000_read_ich8_byte(hw, index, &temp_byte);
8874 if (temp_byte == byte)
8877 e1000_write_ich8_byte(hw, index, byte);
8880 if (program_retries == 100)
8881 error = E1000_ERR_EEPROM;
8886 /******************************************************************************
8887 * Writes a single byte to the NVM using the ICH8 flash access registers.
8889 * hw - pointer to e1000_hw structure
8890 * index - The index of the byte to read.
8891 * data - The byte to write to the NVM.
8892 *****************************************************************************/
8894 e1000_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t data)
8896 int32_t status = E1000_SUCCESS;
8897 uint16_t word = (uint16_t)data;
8899 status = e1000_write_ich8_data(hw, index, 1, word);
8904 /******************************************************************************
8905 * Reads a word from the NVM using the ICH8 flash access registers.
8907 * hw - pointer to e1000_hw structure
8908 * index - The starting byte index of the word to read.
8909 * data - Pointer to a word to store the value read.
8910 *****************************************************************************/
8912 e1000_read_ich8_word(struct e1000_hw *hw, uint32_t index, uint16_t *data)
8914 int32_t status = E1000_SUCCESS;
8915 status = e1000_read_ich8_data(hw, index, 2, data);
8919 /******************************************************************************
8920 * Writes a word to the NVM using the ICH8 flash access registers.
8922 * hw - pointer to e1000_hw structure
8923 * index - The starting byte index of the word to read.
8924 * data - The word to write to the NVM.
8925 *****************************************************************************/
8928 e1000_write_ich8_word(struct e1000_hw *hw, uint32_t index, uint16_t data)
8930 int32_t status = E1000_SUCCESS;
8931 status = e1000_write_ich8_data(hw, index, 2, data);
8936 /******************************************************************************
8937 * Erases the bank specified. Each bank is a 4k block. Segments are 0 based.
8938 * segment N is 4096 * N + flash_reg_addr.
8940 * hw - pointer to e1000_hw structure
8941 * segment - 0 for first segment, 1 for second segment, etc.
8942 *****************************************************************************/
8944 e1000_erase_ich8_4k_segment(struct e1000_hw *hw, uint32_t segment)
8946 union ich8_hws_flash_status hsfsts;
8947 union ich8_hws_flash_ctrl hsflctl;
8948 uint32_t flash_linear_address;
8950 int32_t error = E1000_ERR_EEPROM;
8951 int32_t iteration, seg_size;
8952 int32_t sector_size;
8954 int32_t error_flag = 0;
8956 hsfsts.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFSTS);
8958 /* Determine HW Sector size: Read BERASE bits of Hw flash Status register */
8959 /* 00: The Hw sector is 256 bytes, hence we need to erase 16
8960 * consecutive sectors. The start index for the nth Hw sector can be
8961 * calculated as = segment * 4096 + n * 256
8962 * 01: The Hw sector is 4K bytes, hence we need to erase 1 sector.
8963 * The start index for the nth Hw sector can be calculated
8964 * as = segment * 4096
8965 * 10: Error condition
8966 * 11: The Hw sector size is much bigger than the size asked to
8967 * erase...error condition */
8968 if (hsfsts.hsf_status.berasesz == 0x0) {
8969 /* Hw sector size 256 */
8970 sector_size = seg_size = ICH8_FLASH_SEG_SIZE_256;
8971 iteration = ICH8_FLASH_SECTOR_SIZE / ICH8_FLASH_SEG_SIZE_256;
8972 } else if (hsfsts.hsf_status.berasesz == 0x1) {
8973 sector_size = seg_size = ICH8_FLASH_SEG_SIZE_4K;
8975 } else if (hsfsts.hsf_status.berasesz == 0x3) {
8976 sector_size = seg_size = ICH8_FLASH_SEG_SIZE_64K;
8982 for (j = 0; j < iteration ; j++) {
8986 error = e1000_ich8_cycle_init(hw);
8987 if (error != E1000_SUCCESS) {
8992 /* Write a value 11 (block Erase) in Flash Cycle field in Hw flash
8994 hsflctl.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFCTL);
8995 hsflctl.hsf_ctrl.flcycle = ICH8_CYCLE_ERASE;
8996 E1000_WRITE_ICH8_REG16(hw, ICH8_FLASH_HSFCTL, hsflctl.regval);
8998 /* Write the last 24 bits of an index within the block into Flash
8999 * Linear address field in Flash Address. This probably needs to
9000 * be calculated here based off the on-chip segment size and the
9001 * software segment size assumed (4K) */
9003 flash_linear_address = segment * sector_size + j * seg_size;
9004 flash_linear_address &= ICH8_FLASH_LINEAR_ADDR_MASK;
9005 flash_linear_address += hw->flash_base_addr;
9007 E1000_WRITE_ICH8_REG(hw, ICH8_FLASH_FADDR, flash_linear_address);
9009 error = e1000_ich8_flash_cycle(hw, 1000000);
9010 /* Check if FCERR is set to 1. If 1, clear it and try the whole
9011 * sequence a few more times else Done */
9012 if (error == E1000_SUCCESS) {
9015 hsfsts.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFSTS);
9016 if (hsfsts.hsf_status.flcerr == 1) {
9017 /* repeat for some time before giving up */
9019 } else if (hsfsts.hsf_status.flcdone == 0) {
9024 } while ((count < ICH8_FLASH_CYCLE_REPEAT_COUNT) && !error_flag);
9025 if (error_flag == 1)
9028 if (error_flag != 1)
9029 error = E1000_SUCCESS;
9033 /******************************************************************************
9035 * Reverse duplex setting without breaking the link.
9037 * hw: Struct containing variables accessed by shared code
9039 *****************************************************************************/
9042 e1000_duplex_reversal(struct e1000_hw *hw)
9047 if (hw->phy_type != e1000_phy_igp_3)
9048 return E1000_SUCCESS;
9050 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
9054 phy_data ^= MII_CR_FULL_DUPLEX;
9056 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
9060 ret_val = e1000_read_phy_reg(hw, IGP3E1000_PHY_MISC_CTRL, &phy_data);
9064 phy_data |= IGP3_PHY_MISC_DUPLEX_MANUAL_SET;
9065 ret_val = e1000_write_phy_reg(hw, IGP3E1000_PHY_MISC_CTRL, phy_data);
9072 e1000_init_lcd_from_nvm_config_region(struct e1000_hw *hw,
9073 uint32_t cnf_base_addr, uint32_t cnf_size)
9075 uint32_t ret_val = E1000_SUCCESS;
9076 uint16_t word_addr, reg_data, reg_addr;
9079 /* cnf_base_addr is in DWORD */
9080 word_addr = (uint16_t)(cnf_base_addr << 1);
9082 /* cnf_size is returned in size of dwords */
9083 for (i = 0; i < cnf_size; i++) {
9084 ret_val = e1000_read_eeprom(hw, (word_addr + i*2), 1, ®_data);
9088 ret_val = e1000_read_eeprom(hw, (word_addr + i*2 + 1), 1, ®_addr);
9092 ret_val = e1000_get_software_flag(hw);
9093 if (ret_val != E1000_SUCCESS)
9096 ret_val = e1000_write_phy_reg_ex(hw, (uint32_t)reg_addr, reg_data);
9098 e1000_release_software_flag(hw);
9106 e1000_init_lcd_from_nvm(struct e1000_hw *hw)
9108 uint32_t reg_data, cnf_base_addr, cnf_size, ret_val, loop;
9110 if (hw->phy_type != e1000_phy_igp_3)
9111 return E1000_SUCCESS;
9113 /* Check if SW needs configure the PHY */
9114 reg_data = E1000_READ_REG(hw, FEXTNVM);
9115 if (!(reg_data & FEXTNVM_SW_CONFIG))
9116 return E1000_SUCCESS;
9118 /* Wait for basic configuration completes before proceeding*/
9121 reg_data = E1000_READ_REG(hw, STATUS) & E1000_STATUS_LAN_INIT_DONE;
9124 } while ((!reg_data) && (loop < 50));
9126 /* Clear the Init Done bit for the next init event */
9127 reg_data = E1000_READ_REG(hw, STATUS);
9128 reg_data &= ~E1000_STATUS_LAN_INIT_DONE;
9129 E1000_WRITE_REG(hw, STATUS, reg_data);
9131 /* Make sure HW does not configure LCD from PHY extended configuration
9132 before SW configuration */
9133 reg_data = E1000_READ_REG(hw, EXTCNF_CTRL);
9134 if ((reg_data & E1000_EXTCNF_CTRL_LCD_WRITE_ENABLE) == 0x0000) {
9135 reg_data = E1000_READ_REG(hw, EXTCNF_SIZE);
9136 cnf_size = reg_data & E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH;
9139 reg_data = E1000_READ_REG(hw, EXTCNF_CTRL);
9140 cnf_base_addr = reg_data & E1000_EXTCNF_CTRL_EXT_CNF_POINTER;
9141 /* cnf_base_addr is in DWORD */
9142 cnf_base_addr >>= 16;
9144 /* Configure LCD from extended configuration region. */
9145 ret_val = e1000_init_lcd_from_nvm_config_region(hw, cnf_base_addr,
9152 return E1000_SUCCESS;