1 /*******************************************************************************
3 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2006 Intel Corporation.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *******************************************************************************/
30 * Shared functions for accessing and configuring the MAC
36 static int32_t e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask);
37 static void e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask);
38 static int32_t e1000_read_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t *data);
39 static int32_t e1000_write_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t data);
40 static int32_t e1000_get_software_semaphore(struct e1000_hw *hw);
41 static void e1000_release_software_semaphore(struct e1000_hw *hw);
43 static uint8_t e1000_arc_subsystem_valid(struct e1000_hw *hw);
44 static int32_t e1000_check_downshift(struct e1000_hw *hw);
45 static int32_t e1000_check_polarity(struct e1000_hw *hw, e1000_rev_polarity *polarity);
46 static void e1000_clear_hw_cntrs(struct e1000_hw *hw);
47 static void e1000_clear_vfta(struct e1000_hw *hw);
48 static int32_t e1000_commit_shadow_ram(struct e1000_hw *hw);
49 static int32_t e1000_config_dsp_after_link_change(struct e1000_hw *hw, boolean_t link_up);
50 static int32_t e1000_config_fc_after_link_up(struct e1000_hw *hw);
51 static int32_t e1000_detect_gig_phy(struct e1000_hw *hw);
52 static int32_t e1000_erase_ich8_4k_segment(struct e1000_hw *hw, uint32_t bank);
53 static int32_t e1000_get_auto_rd_done(struct e1000_hw *hw);
54 static int32_t e1000_get_cable_length(struct e1000_hw *hw, uint16_t *min_length, uint16_t *max_length);
55 static int32_t e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw);
56 static int32_t e1000_get_phy_cfg_done(struct e1000_hw *hw);
57 static int32_t e1000_get_software_flag(struct e1000_hw *hw);
58 static int32_t e1000_ich8_cycle_init(struct e1000_hw *hw);
59 static int32_t e1000_ich8_flash_cycle(struct e1000_hw *hw, uint32_t timeout);
60 static int32_t e1000_id_led_init(struct e1000_hw *hw);
61 static int32_t e1000_init_lcd_from_nvm_config_region(struct e1000_hw *hw, uint32_t cnf_base_addr, uint32_t cnf_size);
62 static int32_t e1000_init_lcd_from_nvm(struct e1000_hw *hw);
63 static void e1000_init_rx_addrs(struct e1000_hw *hw);
64 static void e1000_initialize_hardware_bits(struct e1000_hw *hw);
65 static boolean_t e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw);
66 static int32_t e1000_kumeran_lock_loss_workaround(struct e1000_hw *hw);
67 static int32_t e1000_mng_enable_host_if(struct e1000_hw *hw);
68 static int32_t e1000_mng_host_if_write(struct e1000_hw *hw, uint8_t *buffer, uint16_t length, uint16_t offset, uint8_t *sum);
69 static int32_t e1000_mng_write_cmd_header(struct e1000_hw* hw, struct e1000_host_mng_command_header* hdr);
70 static int32_t e1000_mng_write_commit(struct e1000_hw *hw);
71 static int32_t e1000_phy_ife_get_info(struct e1000_hw *hw, struct e1000_phy_info *phy_info);
72 static int32_t e1000_phy_igp_get_info(struct e1000_hw *hw, struct e1000_phy_info *phy_info);
73 static int32_t e1000_read_eeprom_eerd(struct e1000_hw *hw, uint16_t offset, uint16_t words, uint16_t *data);
74 static int32_t e1000_write_eeprom_eewr(struct e1000_hw *hw, uint16_t offset, uint16_t words, uint16_t *data);
75 static int32_t e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd);
76 static int32_t e1000_phy_m88_get_info(struct e1000_hw *hw, struct e1000_phy_info *phy_info);
77 static void e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw);
78 static int32_t e1000_read_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t *data);
79 static int32_t e1000_verify_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t byte);
80 static int32_t e1000_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t byte);
81 static int32_t e1000_read_ich8_word(struct e1000_hw *hw, uint32_t index, uint16_t *data);
82 static int32_t e1000_read_ich8_data(struct e1000_hw *hw, uint32_t index, uint32_t size, uint16_t *data);
83 static int32_t e1000_write_ich8_data(struct e1000_hw *hw, uint32_t index, uint32_t size, uint16_t data);
84 static int32_t e1000_read_eeprom_ich8(struct e1000_hw *hw, uint16_t offset, uint16_t words, uint16_t *data);
85 static int32_t e1000_write_eeprom_ich8(struct e1000_hw *hw, uint16_t offset, uint16_t words, uint16_t *data);
86 static void e1000_release_software_flag(struct e1000_hw *hw);
87 static int32_t e1000_set_d3_lplu_state(struct e1000_hw *hw, boolean_t active);
88 static int32_t e1000_set_d0_lplu_state(struct e1000_hw *hw, boolean_t active);
89 static int32_t e1000_set_pci_ex_no_snoop(struct e1000_hw *hw, uint32_t no_snoop);
90 static void e1000_set_pci_express_master_disable(struct e1000_hw *hw);
91 static int32_t e1000_wait_autoneg(struct e1000_hw *hw);
92 static void e1000_write_reg_io(struct e1000_hw *hw, uint32_t offset, uint32_t value);
93 static int32_t e1000_set_phy_type(struct e1000_hw *hw);
94 static void e1000_phy_init_script(struct e1000_hw *hw);
95 static int32_t e1000_setup_copper_link(struct e1000_hw *hw);
96 static int32_t e1000_setup_fiber_serdes_link(struct e1000_hw *hw);
97 static int32_t e1000_adjust_serdes_amplitude(struct e1000_hw *hw);
98 static int32_t e1000_phy_force_speed_duplex(struct e1000_hw *hw);
99 static int32_t e1000_config_mac_to_phy(struct e1000_hw *hw);
100 static void e1000_raise_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl);
101 static void e1000_lower_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl);
102 static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, uint32_t data,
104 static uint16_t e1000_shift_in_mdi_bits(struct e1000_hw *hw);
105 static int32_t e1000_phy_reset_dsp(struct e1000_hw *hw);
106 static int32_t e1000_write_eeprom_spi(struct e1000_hw *hw, uint16_t offset,
107 uint16_t words, uint16_t *data);
108 static int32_t e1000_write_eeprom_microwire(struct e1000_hw *hw,
109 uint16_t offset, uint16_t words,
111 static int32_t e1000_spi_eeprom_ready(struct e1000_hw *hw);
112 static void e1000_raise_ee_clk(struct e1000_hw *hw, uint32_t *eecd);
113 static void e1000_lower_ee_clk(struct e1000_hw *hw, uint32_t *eecd);
114 static void e1000_shift_out_ee_bits(struct e1000_hw *hw, uint16_t data,
116 static int32_t e1000_write_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr,
118 static int32_t e1000_read_phy_reg_ex(struct e1000_hw *hw,uint32_t reg_addr,
120 static uint16_t e1000_shift_in_ee_bits(struct e1000_hw *hw, uint16_t count);
121 static int32_t e1000_acquire_eeprom(struct e1000_hw *hw);
122 static void e1000_release_eeprom(struct e1000_hw *hw);
123 static void e1000_standby_eeprom(struct e1000_hw *hw);
124 static int32_t e1000_set_vco_speed(struct e1000_hw *hw);
125 static int32_t e1000_polarity_reversal_workaround(struct e1000_hw *hw);
126 static int32_t e1000_set_phy_mode(struct e1000_hw *hw);
127 static int32_t e1000_host_if_read_cookie(struct e1000_hw *hw, uint8_t *buffer);
128 static uint8_t e1000_calculate_mng_checksum(char *buffer, uint32_t length);
129 static int32_t e1000_configure_kmrn_for_10_100(struct e1000_hw *hw,
131 static int32_t e1000_configure_kmrn_for_1000(struct e1000_hw *hw);
133 /* IGP cable length table */
135 uint16_t e1000_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] =
136 { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
137 5, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 25, 25, 25,
138 25, 25, 25, 25, 30, 30, 30, 30, 40, 40, 40, 40, 40, 40, 40, 40,
139 40, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60,
140 60, 70, 70, 70, 70, 70, 70, 80, 80, 80, 80, 80, 80, 90, 90, 90,
141 90, 90, 90, 90, 90, 90, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
142 100, 100, 100, 100, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,
143 110, 110, 110, 110, 110, 110, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120};
146 uint16_t e1000_igp_2_cable_length_table[IGP02E1000_AGC_LENGTH_TABLE_SIZE] =
147 { 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21,
148 0, 0, 0, 3, 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41,
149 6, 10, 14, 18, 22, 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61,
150 21, 26, 31, 35, 40, 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82,
151 40, 45, 51, 56, 61, 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104,
152 60, 66, 72, 77, 82, 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121,
153 83, 89, 95, 100, 105, 109, 113, 116, 119, 122, 124,
154 104, 109, 114, 118, 121, 124};
156 /******************************************************************************
157 * Set the phy type member in the hw struct.
159 * hw - Struct containing variables accessed by shared code
160 *****************************************************************************/
162 e1000_set_phy_type(struct e1000_hw *hw)
164 DEBUGFUNC("e1000_set_phy_type");
166 if (hw->mac_type == e1000_undefined)
167 return -E1000_ERR_PHY_TYPE;
169 switch (hw->phy_id) {
170 case M88E1000_E_PHY_ID:
171 case M88E1000_I_PHY_ID:
172 case M88E1011_I_PHY_ID:
173 case M88E1111_I_PHY_ID:
174 hw->phy_type = e1000_phy_m88;
176 case IGP01E1000_I_PHY_ID:
177 if (hw->mac_type == e1000_82541 ||
178 hw->mac_type == e1000_82541_rev_2 ||
179 hw->mac_type == e1000_82547 ||
180 hw->mac_type == e1000_82547_rev_2) {
181 hw->phy_type = e1000_phy_igp;
184 case IGP03E1000_E_PHY_ID:
185 hw->phy_type = e1000_phy_igp_3;
188 case IFE_PLUS_E_PHY_ID:
190 hw->phy_type = e1000_phy_ife;
192 case GG82563_E_PHY_ID:
193 if (hw->mac_type == e1000_80003es2lan) {
194 hw->phy_type = e1000_phy_gg82563;
199 /* Should never have loaded on this device */
200 hw->phy_type = e1000_phy_undefined;
201 return -E1000_ERR_PHY_TYPE;
204 return E1000_SUCCESS;
207 /******************************************************************************
208 * IGP phy init script - initializes the GbE PHY
210 * hw - Struct containing variables accessed by shared code
211 *****************************************************************************/
213 e1000_phy_init_script(struct e1000_hw *hw)
216 uint16_t phy_saved_data;
218 DEBUGFUNC("e1000_phy_init_script");
220 if (hw->phy_init_script) {
223 /* Save off the current value of register 0x2F5B to be restored at
224 * the end of this routine. */
225 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
227 /* Disabled the PHY transmitter */
228 e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
232 e1000_write_phy_reg(hw,0x0000,0x0140);
236 switch (hw->mac_type) {
239 e1000_write_phy_reg(hw, 0x1F95, 0x0001);
241 e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
243 e1000_write_phy_reg(hw, 0x1F79, 0x0018);
245 e1000_write_phy_reg(hw, 0x1F30, 0x1600);
247 e1000_write_phy_reg(hw, 0x1F31, 0x0014);
249 e1000_write_phy_reg(hw, 0x1F32, 0x161C);
251 e1000_write_phy_reg(hw, 0x1F94, 0x0003);
253 e1000_write_phy_reg(hw, 0x1F96, 0x003F);
255 e1000_write_phy_reg(hw, 0x2010, 0x0008);
258 case e1000_82541_rev_2:
259 case e1000_82547_rev_2:
260 e1000_write_phy_reg(hw, 0x1F73, 0x0099);
266 e1000_write_phy_reg(hw, 0x0000, 0x3300);
270 /* Now enable the transmitter */
271 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
273 if (hw->mac_type == e1000_82547) {
274 uint16_t fused, fine, coarse;
276 /* Move to analog registers page */
277 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_SPARE_FUSE_STATUS, &fused);
279 if (!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
280 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_FUSE_STATUS, &fused);
282 fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
283 coarse = fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
285 if (coarse > IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
286 coarse -= IGP01E1000_ANALOG_FUSE_COARSE_10;
287 fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
288 } else if (coarse == IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
289 fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
291 fused = (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
292 (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
293 (coarse & IGP01E1000_ANALOG_FUSE_COARSE_MASK);
295 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_CONTROL, fused);
296 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_BYPASS,
297 IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
303 /******************************************************************************
304 * Set the mac type member in the hw struct.
306 * hw - Struct containing variables accessed by shared code
307 *****************************************************************************/
309 e1000_set_mac_type(struct e1000_hw *hw)
311 DEBUGFUNC("e1000_set_mac_type");
313 switch (hw->device_id) {
314 case E1000_DEV_ID_82542:
315 switch (hw->revision_id) {
316 case E1000_82542_2_0_REV_ID:
317 hw->mac_type = e1000_82542_rev2_0;
319 case E1000_82542_2_1_REV_ID:
320 hw->mac_type = e1000_82542_rev2_1;
323 /* Invalid 82542 revision ID */
324 return -E1000_ERR_MAC_TYPE;
327 case E1000_DEV_ID_82543GC_FIBER:
328 case E1000_DEV_ID_82543GC_COPPER:
329 hw->mac_type = e1000_82543;
331 case E1000_DEV_ID_82544EI_COPPER:
332 case E1000_DEV_ID_82544EI_FIBER:
333 case E1000_DEV_ID_82544GC_COPPER:
334 case E1000_DEV_ID_82544GC_LOM:
335 hw->mac_type = e1000_82544;
337 case E1000_DEV_ID_82540EM:
338 case E1000_DEV_ID_82540EM_LOM:
339 case E1000_DEV_ID_82540EP:
340 case E1000_DEV_ID_82540EP_LOM:
341 case E1000_DEV_ID_82540EP_LP:
342 hw->mac_type = e1000_82540;
344 case E1000_DEV_ID_82545EM_COPPER:
345 case E1000_DEV_ID_82545EM_FIBER:
346 hw->mac_type = e1000_82545;
348 case E1000_DEV_ID_82545GM_COPPER:
349 case E1000_DEV_ID_82545GM_FIBER:
350 case E1000_DEV_ID_82545GM_SERDES:
351 hw->mac_type = e1000_82545_rev_3;
353 case E1000_DEV_ID_82546EB_COPPER:
354 case E1000_DEV_ID_82546EB_FIBER:
355 case E1000_DEV_ID_82546EB_QUAD_COPPER:
356 hw->mac_type = e1000_82546;
358 case E1000_DEV_ID_82546GB_COPPER:
359 case E1000_DEV_ID_82546GB_FIBER:
360 case E1000_DEV_ID_82546GB_SERDES:
361 case E1000_DEV_ID_82546GB_PCIE:
362 case E1000_DEV_ID_82546GB_QUAD_COPPER:
363 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
364 hw->mac_type = e1000_82546_rev_3;
366 case E1000_DEV_ID_82541EI:
367 case E1000_DEV_ID_82541EI_MOBILE:
368 case E1000_DEV_ID_82541ER_LOM:
369 hw->mac_type = e1000_82541;
371 case E1000_DEV_ID_82541ER:
372 case E1000_DEV_ID_82541GI:
373 case E1000_DEV_ID_82541GI_LF:
374 case E1000_DEV_ID_82541GI_MOBILE:
375 hw->mac_type = e1000_82541_rev_2;
377 case E1000_DEV_ID_82547EI:
378 case E1000_DEV_ID_82547EI_MOBILE:
379 hw->mac_type = e1000_82547;
381 case E1000_DEV_ID_82547GI:
382 hw->mac_type = e1000_82547_rev_2;
384 case E1000_DEV_ID_82571EB_COPPER:
385 case E1000_DEV_ID_82571EB_FIBER:
386 case E1000_DEV_ID_82571EB_SERDES:
387 case E1000_DEV_ID_82571EB_SERDES_DUAL:
388 case E1000_DEV_ID_82571EB_SERDES_QUAD:
389 case E1000_DEV_ID_82571EB_QUAD_COPPER:
390 case E1000_DEV_ID_82571EB_QUAD_FIBER:
391 case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE:
392 hw->mac_type = e1000_82571;
394 case E1000_DEV_ID_82572EI_COPPER:
395 case E1000_DEV_ID_82572EI_FIBER:
396 case E1000_DEV_ID_82572EI_SERDES:
397 case E1000_DEV_ID_82572EI:
398 hw->mac_type = e1000_82572;
400 case E1000_DEV_ID_82573E:
401 case E1000_DEV_ID_82573E_IAMT:
402 case E1000_DEV_ID_82573L:
403 hw->mac_type = e1000_82573;
405 case E1000_DEV_ID_80003ES2LAN_COPPER_SPT:
406 case E1000_DEV_ID_80003ES2LAN_SERDES_SPT:
407 case E1000_DEV_ID_80003ES2LAN_COPPER_DPT:
408 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
409 hw->mac_type = e1000_80003es2lan;
411 case E1000_DEV_ID_ICH8_IGP_M_AMT:
412 case E1000_DEV_ID_ICH8_IGP_AMT:
413 case E1000_DEV_ID_ICH8_IGP_C:
414 case E1000_DEV_ID_ICH8_IFE:
415 case E1000_DEV_ID_ICH8_IFE_GT:
416 case E1000_DEV_ID_ICH8_IFE_G:
417 case E1000_DEV_ID_ICH8_IGP_M:
418 hw->mac_type = e1000_ich8lan;
421 /* Should never have loaded on this device */
422 return -E1000_ERR_MAC_TYPE;
425 switch (hw->mac_type) {
427 hw->swfwhw_semaphore_present = TRUE;
428 hw->asf_firmware_present = TRUE;
430 case e1000_80003es2lan:
431 hw->swfw_sync_present = TRUE;
436 hw->eeprom_semaphore_present = TRUE;
440 case e1000_82541_rev_2:
441 case e1000_82547_rev_2:
442 hw->asf_firmware_present = TRUE;
448 /* The 82543 chip does not count tx_carrier_errors properly in
451 if (hw->mac_type == e1000_82543)
452 hw->bad_tx_carr_stats_fd = TRUE;
454 /* capable of receiving management packets to the host */
455 if (hw->mac_type >= e1000_82571)
456 hw->has_manc2h = TRUE;
458 /* In rare occasions, ESB2 systems would end up started without
459 * the RX unit being turned on.
461 if (hw->mac_type == e1000_80003es2lan)
462 hw->rx_needs_kicking = TRUE;
464 if (hw->mac_type > e1000_82544)
465 hw->has_smbus = TRUE;
467 return E1000_SUCCESS;
470 /*****************************************************************************
471 * Set media type and TBI compatibility.
473 * hw - Struct containing variables accessed by shared code
474 * **************************************************************************/
476 e1000_set_media_type(struct e1000_hw *hw)
480 DEBUGFUNC("e1000_set_media_type");
482 if (hw->mac_type != e1000_82543) {
483 /* tbi_compatibility is only valid on 82543 */
484 hw->tbi_compatibility_en = FALSE;
487 switch (hw->device_id) {
488 case E1000_DEV_ID_82545GM_SERDES:
489 case E1000_DEV_ID_82546GB_SERDES:
490 case E1000_DEV_ID_82571EB_SERDES:
491 case E1000_DEV_ID_82571EB_SERDES_DUAL:
492 case E1000_DEV_ID_82571EB_SERDES_QUAD:
493 case E1000_DEV_ID_82572EI_SERDES:
494 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
495 hw->media_type = e1000_media_type_internal_serdes;
498 switch (hw->mac_type) {
499 case e1000_82542_rev2_0:
500 case e1000_82542_rev2_1:
501 hw->media_type = e1000_media_type_fiber;
505 /* The STATUS_TBIMODE bit is reserved or reused for the this
508 hw->media_type = e1000_media_type_copper;
511 status = E1000_READ_REG(hw, STATUS);
512 if (status & E1000_STATUS_TBIMODE) {
513 hw->media_type = e1000_media_type_fiber;
514 /* tbi_compatibility not valid on fiber */
515 hw->tbi_compatibility_en = FALSE;
517 hw->media_type = e1000_media_type_copper;
524 /******************************************************************************
525 * Reset the transmit and receive units; mask and clear all interrupts.
527 * hw - Struct containing variables accessed by shared code
528 *****************************************************************************/
530 e1000_reset_hw(struct e1000_hw *hw)
538 uint32_t extcnf_ctrl;
541 DEBUGFUNC("e1000_reset_hw");
543 /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
544 if (hw->mac_type == e1000_82542_rev2_0) {
545 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
546 e1000_pci_clear_mwi(hw);
549 if (hw->bus_type == e1000_bus_type_pci_express) {
550 /* Prevent the PCI-E bus from sticking if there is no TLP connection
551 * on the last TLP read/write transaction when MAC is reset.
553 if (e1000_disable_pciex_master(hw) != E1000_SUCCESS) {
554 DEBUGOUT("PCI-E Master disable polling has failed.\n");
558 /* Clear interrupt mask to stop board from generating interrupts */
559 DEBUGOUT("Masking off all interrupts\n");
560 E1000_WRITE_REG(hw, IMC, 0xffffffff);
562 /* Disable the Transmit and Receive units. Then delay to allow
563 * any pending transactions to complete before we hit the MAC with
566 E1000_WRITE_REG(hw, RCTL, 0);
567 E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP);
568 E1000_WRITE_FLUSH(hw);
570 /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
571 hw->tbi_compatibility_on = FALSE;
573 /* Delay to allow any outstanding PCI transactions to complete before
574 * resetting the device
578 ctrl = E1000_READ_REG(hw, CTRL);
580 /* Must reset the PHY before resetting the MAC */
581 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
582 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_PHY_RST));
586 /* Must acquire the MDIO ownership before MAC reset.
587 * Ownership defaults to firmware after a reset. */
588 if (hw->mac_type == e1000_82573) {
591 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
592 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
595 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
596 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
598 if (extcnf_ctrl & E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP)
601 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
608 /* Workaround for ICH8 bit corruption issue in FIFO memory */
609 if (hw->mac_type == e1000_ich8lan) {
610 /* Set Tx and Rx buffer allocation to 8k apiece. */
611 E1000_WRITE_REG(hw, PBA, E1000_PBA_8K);
612 /* Set Packet Buffer Size to 16k. */
613 E1000_WRITE_REG(hw, PBS, E1000_PBS_16K);
616 /* Issue a global reset to the MAC. This will reset the chip's
617 * transmit, receive, DMA, and link units. It will not effect
618 * the current PCI configuration. The global reset bit is self-
619 * clearing, and should clear within a microsecond.
621 DEBUGOUT("Issuing a global reset to MAC\n");
623 switch (hw->mac_type) {
629 case e1000_82541_rev_2:
630 /* These controllers can't ack the 64-bit write when issuing the
631 * reset, so use IO-mapping as a workaround to issue the reset */
632 E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
634 case e1000_82545_rev_3:
635 case e1000_82546_rev_3:
636 /* Reset is performed on a shadow of the control register */
637 E1000_WRITE_REG(hw, CTRL_DUP, (ctrl | E1000_CTRL_RST));
640 if (!hw->phy_reset_disable &&
641 e1000_check_phy_reset_block(hw) == E1000_SUCCESS) {
642 /* e1000_ich8lan PHY HW reset requires MAC CORE reset
643 * at the same time to make sure the interface between
644 * MAC and the external PHY is reset.
646 ctrl |= E1000_CTRL_PHY_RST;
649 e1000_get_software_flag(hw);
650 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
654 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
658 /* After MAC reset, force reload of EEPROM to restore power-on settings to
659 * device. Later controllers reload the EEPROM automatically, so just wait
660 * for reload to complete.
662 switch (hw->mac_type) {
663 case e1000_82542_rev2_0:
664 case e1000_82542_rev2_1:
667 /* Wait for reset to complete */
669 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
670 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
671 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
672 E1000_WRITE_FLUSH(hw);
673 /* Wait for EEPROM reload */
677 case e1000_82541_rev_2:
679 case e1000_82547_rev_2:
680 /* Wait for EEPROM reload */
684 if (e1000_is_onboard_nvm_eeprom(hw) == FALSE) {
686 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
687 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
688 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
689 E1000_WRITE_FLUSH(hw);
693 /* Auto read done will delay 5ms or poll based on mac type */
694 ret_val = e1000_get_auto_rd_done(hw);
700 /* Disable HW ARPs on ASF enabled adapters */
701 if (hw->mac_type >= e1000_82540 && hw->mac_type <= e1000_82547_rev_2) {
702 manc = E1000_READ_REG(hw, MANC);
703 manc &= ~(E1000_MANC_ARP_EN);
704 E1000_WRITE_REG(hw, MANC, manc);
707 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
708 e1000_phy_init_script(hw);
710 /* Configure activity LED after PHY reset */
711 led_ctrl = E1000_READ_REG(hw, LEDCTL);
712 led_ctrl &= IGP_ACTIVITY_LED_MASK;
713 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
714 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
717 /* Clear interrupt mask to stop board from generating interrupts */
718 DEBUGOUT("Masking off all interrupts\n");
719 E1000_WRITE_REG(hw, IMC, 0xffffffff);
721 /* Clear any pending interrupt events. */
722 icr = E1000_READ_REG(hw, ICR);
724 /* If MWI was previously enabled, reenable it. */
725 if (hw->mac_type == e1000_82542_rev2_0) {
726 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
727 e1000_pci_set_mwi(hw);
730 if (hw->mac_type == e1000_ich8lan) {
731 uint32_t kab = E1000_READ_REG(hw, KABGTXD);
732 kab |= E1000_KABGTXD_BGSQLBIAS;
733 E1000_WRITE_REG(hw, KABGTXD, kab);
736 return E1000_SUCCESS;
739 /******************************************************************************
741 * Initialize a number of hardware-dependent bits
743 * hw: Struct containing variables accessed by shared code
745 * This function contains hardware limitation workarounds for PCI-E adapters
747 *****************************************************************************/
749 e1000_initialize_hardware_bits(struct e1000_hw *hw)
751 if ((hw->mac_type >= e1000_82571) && (!hw->initialize_hw_bits_disable)) {
752 /* Settings common to all PCI-express silicon */
753 uint32_t reg_ctrl, reg_ctrl_ext;
754 uint32_t reg_tarc0, reg_tarc1;
756 uint32_t reg_txdctl, reg_txdctl1;
758 /* link autonegotiation/sync workarounds */
759 reg_tarc0 = E1000_READ_REG(hw, TARC0);
760 reg_tarc0 &= ~((1 << 30)|(1 << 29)|(1 << 28)|(1 << 27));
762 /* Enable not-done TX descriptor counting */
763 reg_txdctl = E1000_READ_REG(hw, TXDCTL);
764 reg_txdctl |= E1000_TXDCTL_COUNT_DESC;
765 E1000_WRITE_REG(hw, TXDCTL, reg_txdctl);
766 reg_txdctl1 = E1000_READ_REG(hw, TXDCTL1);
767 reg_txdctl1 |= E1000_TXDCTL_COUNT_DESC;
768 E1000_WRITE_REG(hw, TXDCTL1, reg_txdctl1);
770 switch (hw->mac_type) {
773 /* Clear PHY TX compatible mode bits */
774 reg_tarc1 = E1000_READ_REG(hw, TARC1);
775 reg_tarc1 &= ~((1 << 30)|(1 << 29));
777 /* link autonegotiation/sync workarounds */
778 reg_tarc0 |= ((1 << 26)|(1 << 25)|(1 << 24)|(1 << 23));
780 /* TX ring control fixes */
781 reg_tarc1 |= ((1 << 26)|(1 << 25)|(1 << 24));
783 /* Multiple read bit is reversed polarity */
784 reg_tctl = E1000_READ_REG(hw, TCTL);
785 if (reg_tctl & E1000_TCTL_MULR)
786 reg_tarc1 &= ~(1 << 28);
788 reg_tarc1 |= (1 << 28);
790 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
793 reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
794 reg_ctrl_ext &= ~(1 << 23);
795 reg_ctrl_ext |= (1 << 22);
797 /* TX byte count fix */
798 reg_ctrl = E1000_READ_REG(hw, CTRL);
799 reg_ctrl &= ~(1 << 29);
801 E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext);
802 E1000_WRITE_REG(hw, CTRL, reg_ctrl);
804 case e1000_80003es2lan:
805 /* improve small packet performace for fiber/serdes */
806 if ((hw->media_type == e1000_media_type_fiber) ||
807 (hw->media_type == e1000_media_type_internal_serdes)) {
808 reg_tarc0 &= ~(1 << 20);
811 /* Multiple read bit is reversed polarity */
812 reg_tctl = E1000_READ_REG(hw, TCTL);
813 reg_tarc1 = E1000_READ_REG(hw, TARC1);
814 if (reg_tctl & E1000_TCTL_MULR)
815 reg_tarc1 &= ~(1 << 28);
817 reg_tarc1 |= (1 << 28);
819 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
822 /* Reduce concurrent DMA requests to 3 from 4 */
823 if ((hw->revision_id < 3) ||
824 ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) &&
825 (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))
826 reg_tarc0 |= ((1 << 29)|(1 << 28));
828 reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
829 reg_ctrl_ext |= (1 << 22);
830 E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext);
832 /* workaround TX hang with TSO=on */
833 reg_tarc0 |= ((1 << 27)|(1 << 26)|(1 << 24)|(1 << 23));
835 /* Multiple read bit is reversed polarity */
836 reg_tctl = E1000_READ_REG(hw, TCTL);
837 reg_tarc1 = E1000_READ_REG(hw, TARC1);
838 if (reg_tctl & E1000_TCTL_MULR)
839 reg_tarc1 &= ~(1 << 28);
841 reg_tarc1 |= (1 << 28);
843 /* workaround TX hang with TSO=on */
844 reg_tarc1 |= ((1 << 30)|(1 << 26)|(1 << 24));
846 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
852 E1000_WRITE_REG(hw, TARC0, reg_tarc0);
856 /******************************************************************************
857 * Performs basic configuration of the adapter.
859 * hw - Struct containing variables accessed by shared code
861 * Assumes that the controller has previously been reset and is in a
862 * post-reset uninitialized state. Initializes the receive address registers,
863 * multicast table, and VLAN filter table. Calls routines to setup link
864 * configuration and flow control settings. Clears all on-chip counters. Leaves
865 * the transmit and receive units disabled and uninitialized.
866 *****************************************************************************/
868 e1000_init_hw(struct e1000_hw *hw)
873 uint16_t pcix_cmd_word;
874 uint16_t pcix_stat_hi_word;
881 DEBUGFUNC("e1000_init_hw");
883 /* force full DMA clock frequency for 10/100 on ICH8 A0-B0 */
884 if ((hw->mac_type == e1000_ich8lan) &&
885 ((hw->revision_id < 3) ||
886 ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) &&
887 (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))) {
888 reg_data = E1000_READ_REG(hw, STATUS);
889 reg_data &= ~0x80000000;
890 E1000_WRITE_REG(hw, STATUS, reg_data);
893 /* Initialize Identification LED */
894 ret_val = e1000_id_led_init(hw);
896 DEBUGOUT("Error Initializing Identification LED\n");
900 /* Set the media type and TBI compatibility */
901 e1000_set_media_type(hw);
903 /* Must be called after e1000_set_media_type because media_type is used */
904 e1000_initialize_hardware_bits(hw);
906 /* Disabling VLAN filtering. */
907 DEBUGOUT("Initializing the IEEE VLAN\n");
908 /* VET hardcoded to standard value and VFTA removed in ICH8 LAN */
909 if (hw->mac_type != e1000_ich8lan) {
910 if (hw->mac_type < e1000_82545_rev_3)
911 E1000_WRITE_REG(hw, VET, 0);
912 e1000_clear_vfta(hw);
915 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
916 if (hw->mac_type == e1000_82542_rev2_0) {
917 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
918 e1000_pci_clear_mwi(hw);
919 E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST);
920 E1000_WRITE_FLUSH(hw);
924 /* Setup the receive address. This involves initializing all of the Receive
925 * Address Registers (RARs 0 - 15).
927 e1000_init_rx_addrs(hw);
929 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
930 if (hw->mac_type == e1000_82542_rev2_0) {
931 E1000_WRITE_REG(hw, RCTL, 0);
932 E1000_WRITE_FLUSH(hw);
934 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
935 e1000_pci_set_mwi(hw);
938 /* Zero out the Multicast HASH table */
939 DEBUGOUT("Zeroing the MTA\n");
940 mta_size = E1000_MC_TBL_SIZE;
941 if (hw->mac_type == e1000_ich8lan)
942 mta_size = E1000_MC_TBL_SIZE_ICH8LAN;
943 for (i = 0; i < mta_size; i++) {
944 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
945 /* use write flush to prevent Memory Write Block (MWB) from
946 * occuring when accessing our register space */
947 E1000_WRITE_FLUSH(hw);
950 /* Set the PCI priority bit correctly in the CTRL register. This
951 * determines if the adapter gives priority to receives, or if it
952 * gives equal priority to transmits and receives. Valid only on
953 * 82542 and 82543 silicon.
955 if (hw->dma_fairness && hw->mac_type <= e1000_82543) {
956 ctrl = E1000_READ_REG(hw, CTRL);
957 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PRIOR);
960 switch (hw->mac_type) {
961 case e1000_82545_rev_3:
962 case e1000_82546_rev_3:
965 /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
966 if (hw->bus_type == e1000_bus_type_pcix) {
967 e1000_read_pci_cfg(hw, PCIX_COMMAND_REGISTER, &pcix_cmd_word);
968 e1000_read_pci_cfg(hw, PCIX_STATUS_REGISTER_HI,
970 cmd_mmrbc = (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >>
971 PCIX_COMMAND_MMRBC_SHIFT;
972 stat_mmrbc = (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
973 PCIX_STATUS_HI_MMRBC_SHIFT;
974 if (stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
975 stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
976 if (cmd_mmrbc > stat_mmrbc) {
977 pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK;
978 pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
979 e1000_write_pci_cfg(hw, PCIX_COMMAND_REGISTER,
986 /* More time needed for PHY to initialize */
987 if (hw->mac_type == e1000_ich8lan)
990 /* Call a subroutine to configure the link and setup flow control. */
991 ret_val = e1000_setup_link(hw);
993 /* Set the transmit descriptor write-back policy */
994 if (hw->mac_type > e1000_82544) {
995 ctrl = E1000_READ_REG(hw, TXDCTL);
996 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
997 E1000_WRITE_REG(hw, TXDCTL, ctrl);
1000 if (hw->mac_type == e1000_82573) {
1001 e1000_enable_tx_pkt_filtering(hw);
1004 switch (hw->mac_type) {
1007 case e1000_80003es2lan:
1008 /* Enable retransmit on late collisions */
1009 reg_data = E1000_READ_REG(hw, TCTL);
1010 reg_data |= E1000_TCTL_RTLC;
1011 E1000_WRITE_REG(hw, TCTL, reg_data);
1013 /* Configure Gigabit Carry Extend Padding */
1014 reg_data = E1000_READ_REG(hw, TCTL_EXT);
1015 reg_data &= ~E1000_TCTL_EXT_GCEX_MASK;
1016 reg_data |= DEFAULT_80003ES2LAN_TCTL_EXT_GCEX;
1017 E1000_WRITE_REG(hw, TCTL_EXT, reg_data);
1019 /* Configure Transmit Inter-Packet Gap */
1020 reg_data = E1000_READ_REG(hw, TIPG);
1021 reg_data &= ~E1000_TIPG_IPGT_MASK;
1022 reg_data |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
1023 E1000_WRITE_REG(hw, TIPG, reg_data);
1025 reg_data = E1000_READ_REG_ARRAY(hw, FFLT, 0x0001);
1026 reg_data &= ~0x00100000;
1027 E1000_WRITE_REG_ARRAY(hw, FFLT, 0x0001, reg_data);
1032 ctrl = E1000_READ_REG(hw, TXDCTL1);
1033 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
1034 E1000_WRITE_REG(hw, TXDCTL1, ctrl);
1039 if (hw->mac_type == e1000_82573) {
1040 uint32_t gcr = E1000_READ_REG(hw, GCR);
1041 gcr |= E1000_GCR_L1_ACT_WITHOUT_L0S_RX;
1042 E1000_WRITE_REG(hw, GCR, gcr);
1045 /* Clear all of the statistics registers (clear on read). It is
1046 * important that we do this after we have tried to establish link
1047 * because the symbol error count will increment wildly if there
1050 e1000_clear_hw_cntrs(hw);
1052 /* ICH8 No-snoop bits are opposite polarity.
1053 * Set to snoop by default after reset. */
1054 if (hw->mac_type == e1000_ich8lan)
1055 e1000_set_pci_ex_no_snoop(hw, PCI_EX_82566_SNOOP_ALL);
1057 if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER ||
1058 hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) {
1059 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
1060 /* Relaxed ordering must be disabled to avoid a parity
1061 * error crash in a PCI slot. */
1062 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
1063 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1069 /******************************************************************************
1070 * Adjust SERDES output amplitude based on EEPROM setting.
1072 * hw - Struct containing variables accessed by shared code.
1073 *****************************************************************************/
1075 e1000_adjust_serdes_amplitude(struct e1000_hw *hw)
1077 uint16_t eeprom_data;
1080 DEBUGFUNC("e1000_adjust_serdes_amplitude");
1082 if (hw->media_type != e1000_media_type_internal_serdes)
1083 return E1000_SUCCESS;
1085 switch (hw->mac_type) {
1086 case e1000_82545_rev_3:
1087 case e1000_82546_rev_3:
1090 return E1000_SUCCESS;
1093 ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1, &eeprom_data);
1098 if (eeprom_data != EEPROM_RESERVED_WORD) {
1099 /* Adjust SERDES output amplitude only. */
1100 eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK;
1101 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data);
1106 return E1000_SUCCESS;
1109 /******************************************************************************
1110 * Configures flow control and link settings.
1112 * hw - Struct containing variables accessed by shared code
1114 * Determines which flow control settings to use. Calls the apropriate media-
1115 * specific link configuration function. Configures the flow control settings.
1116 * Assuming the adapter has a valid link partner, a valid link should be
1117 * established. Assumes the hardware has previously been reset and the
1118 * transmitter and receiver are not enabled.
1119 *****************************************************************************/
1121 e1000_setup_link(struct e1000_hw *hw)
1125 uint16_t eeprom_data;
1127 DEBUGFUNC("e1000_setup_link");
1129 /* In the case of the phy reset being blocked, we already have a link.
1130 * We do not have to set it up again. */
1131 if (e1000_check_phy_reset_block(hw))
1132 return E1000_SUCCESS;
1134 /* Read and store word 0x0F of the EEPROM. This word contains bits
1135 * that determine the hardware's default PAUSE (flow control) mode,
1136 * a bit that determines whether the HW defaults to enabling or
1137 * disabling auto-negotiation, and the direction of the
1138 * SW defined pins. If there is no SW over-ride of the flow
1139 * control setting, then the variable hw->fc will
1140 * be initialized based on a value in the EEPROM.
1142 if (hw->fc == E1000_FC_DEFAULT) {
1143 switch (hw->mac_type) {
1146 hw->fc = E1000_FC_FULL;
1149 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
1152 DEBUGOUT("EEPROM Read Error\n");
1153 return -E1000_ERR_EEPROM;
1155 if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
1156 hw->fc = E1000_FC_NONE;
1157 else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
1158 EEPROM_WORD0F_ASM_DIR)
1159 hw->fc = E1000_FC_TX_PAUSE;
1161 hw->fc = E1000_FC_FULL;
1166 /* We want to save off the original Flow Control configuration just
1167 * in case we get disconnected and then reconnected into a different
1168 * hub or switch with different Flow Control capabilities.
1170 if (hw->mac_type == e1000_82542_rev2_0)
1171 hw->fc &= (~E1000_FC_TX_PAUSE);
1173 if ((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
1174 hw->fc &= (~E1000_FC_RX_PAUSE);
1176 hw->original_fc = hw->fc;
1178 DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc);
1180 /* Take the 4 bits from EEPROM word 0x0F that determine the initial
1181 * polarity value for the SW controlled pins, and setup the
1182 * Extended Device Control reg with that info.
1183 * This is needed because one of the SW controlled pins is used for
1184 * signal detection. So this should be done before e1000_setup_pcs_link()
1185 * or e1000_phy_setup() is called.
1187 if (hw->mac_type == e1000_82543) {
1188 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
1191 DEBUGOUT("EEPROM Read Error\n");
1192 return -E1000_ERR_EEPROM;
1194 ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
1196 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1199 /* Call the necessary subroutine to configure the link. */
1200 ret_val = (hw->media_type == e1000_media_type_copper) ?
1201 e1000_setup_copper_link(hw) :
1202 e1000_setup_fiber_serdes_link(hw);
1204 /* Initialize the flow control address, type, and PAUSE timer
1205 * registers to their default values. This is done even if flow
1206 * control is disabled, because it does not hurt anything to
1207 * initialize these registers.
1209 DEBUGOUT("Initializing the Flow Control address, type and timer regs\n");
1211 /* FCAL/H and FCT are hardcoded to standard values in e1000_ich8lan. */
1212 if (hw->mac_type != e1000_ich8lan) {
1213 E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
1214 E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
1215 E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
1218 E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
1220 /* Set the flow control receive threshold registers. Normally,
1221 * these registers will be set to a default threshold that may be
1222 * adjusted later by the driver's runtime code. However, if the
1223 * ability to transmit pause frames in not enabled, then these
1224 * registers will be set to 0.
1226 if (!(hw->fc & E1000_FC_TX_PAUSE)) {
1227 E1000_WRITE_REG(hw, FCRTL, 0);
1228 E1000_WRITE_REG(hw, FCRTH, 0);
1230 /* We need to set up the Receive Threshold high and low water marks
1231 * as well as (optionally) enabling the transmission of XON frames.
1233 if (hw->fc_send_xon) {
1234 E1000_WRITE_REG(hw, FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE));
1235 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
1237 E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water);
1238 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
1244 /******************************************************************************
1245 * Sets up link for a fiber based or serdes based adapter
1247 * hw - Struct containing variables accessed by shared code
1249 * Manipulates Physical Coding Sublayer functions in order to configure
1250 * link. Assumes the hardware has been previously reset and the transmitter
1251 * and receiver are not enabled.
1252 *****************************************************************************/
1254 e1000_setup_fiber_serdes_link(struct e1000_hw *hw)
1260 uint32_t signal = 0;
1263 DEBUGFUNC("e1000_setup_fiber_serdes_link");
1265 /* On 82571 and 82572 Fiber connections, SerDes loopback mode persists
1266 * until explicitly turned off or a power cycle is performed. A read to
1267 * the register does not indicate its status. Therefore, we ensure
1268 * loopback mode is disabled during initialization.
1270 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572)
1271 E1000_WRITE_REG(hw, SCTL, E1000_DISABLE_SERDES_LOOPBACK);
1273 /* On adapters with a MAC newer than 82544, SWDP 1 will be
1274 * set when the optics detect a signal. On older adapters, it will be
1275 * cleared when there is a signal. This applies to fiber media only.
1276 * If we're on serdes media, adjust the output amplitude to value
1277 * set in the EEPROM.
1279 ctrl = E1000_READ_REG(hw, CTRL);
1280 if (hw->media_type == e1000_media_type_fiber)
1281 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
1283 ret_val = e1000_adjust_serdes_amplitude(hw);
1287 /* Take the link out of reset */
1288 ctrl &= ~(E1000_CTRL_LRST);
1290 /* Adjust VCO speed to improve BER performance */
1291 ret_val = e1000_set_vco_speed(hw);
1295 e1000_config_collision_dist(hw);
1297 /* Check for a software override of the flow control settings, and setup
1298 * the device accordingly. If auto-negotiation is enabled, then software
1299 * will have to set the "PAUSE" bits to the correct value in the Tranmsit
1300 * Config Word Register (TXCW) and re-start auto-negotiation. However, if
1301 * auto-negotiation is disabled, then software will have to manually
1302 * configure the two flow control enable bits in the CTRL register.
1304 * The possible values of the "fc" parameter are:
1305 * 0: Flow control is completely disabled
1306 * 1: Rx flow control is enabled (we can receive pause frames, but
1307 * not send pause frames).
1308 * 2: Tx flow control is enabled (we can send pause frames but we do
1309 * not support receiving pause frames).
1310 * 3: Both Rx and TX flow control (symmetric) are enabled.
1314 /* Flow control is completely disabled by a software over-ride. */
1315 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
1317 case E1000_FC_RX_PAUSE:
1318 /* RX Flow control is enabled and TX Flow control is disabled by a
1319 * software over-ride. Since there really isn't a way to advertise
1320 * that we are capable of RX Pause ONLY, we will advertise that we
1321 * support both symmetric and asymmetric RX PAUSE. Later, we will
1322 * disable the adapter's ability to send PAUSE frames.
1324 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1326 case E1000_FC_TX_PAUSE:
1327 /* TX Flow control is enabled, and RX Flow control is disabled, by a
1328 * software over-ride.
1330 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
1333 /* Flow control (both RX and TX) is enabled by a software over-ride. */
1334 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1337 DEBUGOUT("Flow control param set incorrectly\n");
1338 return -E1000_ERR_CONFIG;
1342 /* Since auto-negotiation is enabled, take the link out of reset (the link
1343 * will be in reset, because we previously reset the chip). This will
1344 * restart auto-negotiation. If auto-neogtiation is successful then the
1345 * link-up status bit will be set and the flow control enable bits (RFCE
1346 * and TFCE) will be set according to their negotiated value.
1348 DEBUGOUT("Auto-negotiation enabled\n");
1350 E1000_WRITE_REG(hw, TXCW, txcw);
1351 E1000_WRITE_REG(hw, CTRL, ctrl);
1352 E1000_WRITE_FLUSH(hw);
1357 /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
1358 * indication in the Device Status Register. Time-out if a link isn't
1359 * seen in 500 milliseconds seconds (Auto-negotiation should complete in
1360 * less than 500 milliseconds even if the other end is doing it in SW).
1361 * For internal serdes, we just assume a signal is present, then poll.
1363 if (hw->media_type == e1000_media_type_internal_serdes ||
1364 (E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) {
1365 DEBUGOUT("Looking for Link\n");
1366 for (i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
1368 status = E1000_READ_REG(hw, STATUS);
1369 if (status & E1000_STATUS_LU) break;
1371 if (i == (LINK_UP_TIMEOUT / 10)) {
1372 DEBUGOUT("Never got a valid link from auto-neg!!!\n");
1373 hw->autoneg_failed = 1;
1374 /* AutoNeg failed to achieve a link, so we'll call
1375 * e1000_check_for_link. This routine will force the link up if
1376 * we detect a signal. This will allow us to communicate with
1377 * non-autonegotiating link partners.
1379 ret_val = e1000_check_for_link(hw);
1381 DEBUGOUT("Error while checking for link\n");
1384 hw->autoneg_failed = 0;
1386 hw->autoneg_failed = 0;
1387 DEBUGOUT("Valid Link Found\n");
1390 DEBUGOUT("No Signal Detected\n");
1392 return E1000_SUCCESS;
1395 /******************************************************************************
1396 * Make sure we have a valid PHY and change PHY mode before link setup.
1398 * hw - Struct containing variables accessed by shared code
1399 ******************************************************************************/
1401 e1000_copper_link_preconfig(struct e1000_hw *hw)
1407 DEBUGFUNC("e1000_copper_link_preconfig");
1409 ctrl = E1000_READ_REG(hw, CTRL);
1410 /* With 82543, we need to force speed and duplex on the MAC equal to what
1411 * the PHY speed and duplex configuration is. In addition, we need to
1412 * perform a hardware reset on the PHY to take it out of reset.
1414 if (hw->mac_type > e1000_82543) {
1415 ctrl |= E1000_CTRL_SLU;
1416 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1417 E1000_WRITE_REG(hw, CTRL, ctrl);
1419 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
1420 E1000_WRITE_REG(hw, CTRL, ctrl);
1421 ret_val = e1000_phy_hw_reset(hw);
1426 /* Make sure we have a valid PHY */
1427 ret_val = e1000_detect_gig_phy(hw);
1429 DEBUGOUT("Error, did not detect valid phy.\n");
1432 DEBUGOUT1("Phy ID = %#08lx \n", hw->phy_id);
1434 /* Set PHY to class A mode (if necessary) */
1435 ret_val = e1000_set_phy_mode(hw);
1439 if ((hw->mac_type == e1000_82545_rev_3) ||
1440 (hw->mac_type == e1000_82546_rev_3)) {
1441 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1442 phy_data |= 0x00000008;
1443 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1446 if (hw->mac_type <= e1000_82543 ||
1447 hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
1448 hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2)
1449 hw->phy_reset_disable = FALSE;
1451 return E1000_SUCCESS;
1455 /********************************************************************
1456 * Copper link setup for e1000_phy_igp series.
1458 * hw - Struct containing variables accessed by shared code
1459 *********************************************************************/
1461 e1000_copper_link_igp_setup(struct e1000_hw *hw)
1467 DEBUGFUNC("e1000_copper_link_igp_setup");
1469 if (hw->phy_reset_disable)
1470 return E1000_SUCCESS;
1472 ret_val = e1000_phy_reset(hw);
1474 DEBUGOUT("Error Resetting the PHY\n");
1478 /* Wait 15ms for MAC to configure PHY from eeprom settings */
1480 if (hw->mac_type != e1000_ich8lan) {
1481 /* Configure activity LED after PHY reset */
1482 led_ctrl = E1000_READ_REG(hw, LEDCTL);
1483 led_ctrl &= IGP_ACTIVITY_LED_MASK;
1484 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
1485 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
1488 /* The NVM settings will configure LPLU in D3 for IGP2 and IGP3 PHYs */
1489 if (hw->phy_type == e1000_phy_igp) {
1490 /* disable lplu d3 during driver init */
1491 ret_val = e1000_set_d3_lplu_state(hw, FALSE);
1493 DEBUGOUT("Error Disabling LPLU D3\n");
1498 /* disable lplu d0 during driver init */
1499 ret_val = e1000_set_d0_lplu_state(hw, FALSE);
1501 DEBUGOUT("Error Disabling LPLU D0\n");
1504 /* Configure mdi-mdix settings */
1505 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1509 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
1510 hw->dsp_config_state = e1000_dsp_config_disabled;
1511 /* Force MDI for earlier revs of the IGP PHY */
1512 phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX | IGP01E1000_PSCR_FORCE_MDI_MDIX);
1516 hw->dsp_config_state = e1000_dsp_config_enabled;
1517 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1521 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1524 phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
1528 phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
1532 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1536 /* set auto-master slave resolution settings */
1538 e1000_ms_type phy_ms_setting = hw->master_slave;
1540 if (hw->ffe_config_state == e1000_ffe_config_active)
1541 hw->ffe_config_state = e1000_ffe_config_enabled;
1543 if (hw->dsp_config_state == e1000_dsp_config_activated)
1544 hw->dsp_config_state = e1000_dsp_config_enabled;
1546 /* when autonegotiation advertisment is only 1000Mbps then we
1547 * should disable SmartSpeed and enable Auto MasterSlave
1548 * resolution as hardware default. */
1549 if (hw->autoneg_advertised == ADVERTISE_1000_FULL) {
1550 /* Disable SmartSpeed */
1551 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1555 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1556 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1560 /* Set auto Master/Slave resolution process */
1561 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1564 phy_data &= ~CR_1000T_MS_ENABLE;
1565 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1570 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1574 /* load defaults for future use */
1575 hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
1576 ((phy_data & CR_1000T_MS_VALUE) ?
1577 e1000_ms_force_master :
1578 e1000_ms_force_slave) :
1581 switch (phy_ms_setting) {
1582 case e1000_ms_force_master:
1583 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
1585 case e1000_ms_force_slave:
1586 phy_data |= CR_1000T_MS_ENABLE;
1587 phy_data &= ~(CR_1000T_MS_VALUE);
1590 phy_data &= ~CR_1000T_MS_ENABLE;
1594 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1599 return E1000_SUCCESS;
1602 /********************************************************************
1603 * Copper link setup for e1000_phy_gg82563 series.
1605 * hw - Struct containing variables accessed by shared code
1606 *********************************************************************/
1608 e1000_copper_link_ggp_setup(struct e1000_hw *hw)
1614 DEBUGFUNC("e1000_copper_link_ggp_setup");
1616 if (!hw->phy_reset_disable) {
1618 /* Enable CRS on TX for half-duplex operation. */
1619 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL,
1624 phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
1625 /* Use 25MHz for both link down and 1000BASE-T for Tx clock */
1626 phy_data |= GG82563_MSCR_TX_CLK_1000MBPS_25MHZ;
1628 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL,
1634 * MDI/MDI-X = 0 (default)
1635 * 0 - Auto for all speeds
1638 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1640 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_SPEC_CTRL, &phy_data);
1644 phy_data &= ~GG82563_PSCR_CROSSOVER_MODE_MASK;
1648 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDI;
1651 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDIX;
1655 phy_data |= GG82563_PSCR_CROSSOVER_MODE_AUTO;
1660 * disable_polarity_correction = 0 (default)
1661 * Automatic Correction for Reversed Cable Polarity
1665 phy_data &= ~GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
1666 if (hw->disable_polarity_correction == 1)
1667 phy_data |= GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
1668 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_SPEC_CTRL, phy_data);
1673 /* SW Reset the PHY so all changes take effect */
1674 ret_val = e1000_phy_reset(hw);
1676 DEBUGOUT("Error Resetting the PHY\n");
1679 } /* phy_reset_disable */
1681 if (hw->mac_type == e1000_80003es2lan) {
1682 /* Bypass RX and TX FIFO's */
1683 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_FIFO_CTRL,
1684 E1000_KUMCTRLSTA_FIFO_CTRL_RX_BYPASS |
1685 E1000_KUMCTRLSTA_FIFO_CTRL_TX_BYPASS);
1689 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_SPEC_CTRL_2, &phy_data);
1693 phy_data &= ~GG82563_PSCR2_REVERSE_AUTO_NEG;
1694 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_SPEC_CTRL_2, phy_data);
1699 reg_data = E1000_READ_REG(hw, CTRL_EXT);
1700 reg_data &= ~(E1000_CTRL_EXT_LINK_MODE_MASK);
1701 E1000_WRITE_REG(hw, CTRL_EXT, reg_data);
1703 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_PWR_MGMT_CTRL,
1708 /* Do not init these registers when the HW is in IAMT mode, since the
1709 * firmware will have already initialized them. We only initialize
1710 * them if the HW is not in IAMT mode.
1712 if (e1000_check_mng_mode(hw) == FALSE) {
1713 /* Enable Electrical Idle on the PHY */
1714 phy_data |= GG82563_PMCR_ENABLE_ELECTRICAL_IDLE;
1715 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_PWR_MGMT_CTRL,
1720 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
1725 phy_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
1726 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
1733 /* Workaround: Disable padding in Kumeran interface in the MAC
1734 * and in the PHY to avoid CRC errors.
1736 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_INBAND_CTRL,
1740 phy_data |= GG82563_ICR_DIS_PADDING;
1741 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_INBAND_CTRL,
1747 return E1000_SUCCESS;
1750 /********************************************************************
1751 * Copper link setup for e1000_phy_m88 series.
1753 * hw - Struct containing variables accessed by shared code
1754 *********************************************************************/
1756 e1000_copper_link_mgp_setup(struct e1000_hw *hw)
1761 DEBUGFUNC("e1000_copper_link_mgp_setup");
1763 if (hw->phy_reset_disable)
1764 return E1000_SUCCESS;
1766 /* Enable CRS on TX. This must be set for half-duplex operation. */
1767 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1771 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1774 * MDI/MDI-X = 0 (default)
1775 * 0 - Auto for all speeds
1778 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1780 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1784 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
1787 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
1790 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
1794 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
1799 * disable_polarity_correction = 0 (default)
1800 * Automatic Correction for Reversed Cable Polarity
1804 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
1805 if (hw->disable_polarity_correction == 1)
1806 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
1807 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1811 if (hw->phy_revision < M88E1011_I_REV_4) {
1812 /* Force TX_CLK in the Extended PHY Specific Control Register
1815 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1819 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1821 if ((hw->phy_revision == E1000_REVISION_2) &&
1822 (hw->phy_id == M88E1111_I_PHY_ID)) {
1823 /* Vidalia Phy, set the downshift counter to 5x */
1824 phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK);
1825 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
1826 ret_val = e1000_write_phy_reg(hw,
1827 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1831 /* Configure Master and Slave downshift values */
1832 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
1833 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
1834 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
1835 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
1836 ret_val = e1000_write_phy_reg(hw,
1837 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1843 /* SW Reset the PHY so all changes take effect */
1844 ret_val = e1000_phy_reset(hw);
1846 DEBUGOUT("Error Resetting the PHY\n");
1850 return E1000_SUCCESS;
1853 /********************************************************************
1854 * Setup auto-negotiation and flow control advertisements,
1855 * and then perform auto-negotiation.
1857 * hw - Struct containing variables accessed by shared code
1858 *********************************************************************/
1860 e1000_copper_link_autoneg(struct e1000_hw *hw)
1865 DEBUGFUNC("e1000_copper_link_autoneg");
1867 /* Perform some bounds checking on the hw->autoneg_advertised
1868 * parameter. If this variable is zero, then set it to the default.
1870 hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
1872 /* If autoneg_advertised is zero, we assume it was not defaulted
1873 * by the calling code so we set to advertise full capability.
1875 if (hw->autoneg_advertised == 0)
1876 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
1878 /* IFE phy only supports 10/100 */
1879 if (hw->phy_type == e1000_phy_ife)
1880 hw->autoneg_advertised &= AUTONEG_ADVERTISE_10_100_ALL;
1882 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
1883 ret_val = e1000_phy_setup_autoneg(hw);
1885 DEBUGOUT("Error Setting up Auto-Negotiation\n");
1888 DEBUGOUT("Restarting Auto-Neg\n");
1890 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
1891 * the Auto Neg Restart bit in the PHY control register.
1893 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
1897 phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
1898 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
1902 /* Does the user want to wait for Auto-Neg to complete here, or
1903 * check at a later time (for example, callback routine).
1905 if (hw->wait_autoneg_complete) {
1906 ret_val = e1000_wait_autoneg(hw);
1908 DEBUGOUT("Error while waiting for autoneg to complete\n");
1913 hw->get_link_status = TRUE;
1915 return E1000_SUCCESS;
1918 /******************************************************************************
1919 * Config the MAC and the PHY after link is up.
1920 * 1) Set up the MAC to the current PHY speed/duplex
1921 * if we are on 82543. If we
1922 * are on newer silicon, we only need to configure
1923 * collision distance in the Transmit Control Register.
1924 * 2) Set up flow control on the MAC to that established with
1926 * 3) Config DSP to improve Gigabit link quality for some PHY revisions.
1928 * hw - Struct containing variables accessed by shared code
1929 ******************************************************************************/
1931 e1000_copper_link_postconfig(struct e1000_hw *hw)
1934 DEBUGFUNC("e1000_copper_link_postconfig");
1936 if (hw->mac_type >= e1000_82544) {
1937 e1000_config_collision_dist(hw);
1939 ret_val = e1000_config_mac_to_phy(hw);
1941 DEBUGOUT("Error configuring MAC to PHY settings\n");
1945 ret_val = e1000_config_fc_after_link_up(hw);
1947 DEBUGOUT("Error Configuring Flow Control\n");
1951 /* Config DSP to improve Giga link quality */
1952 if (hw->phy_type == e1000_phy_igp) {
1953 ret_val = e1000_config_dsp_after_link_change(hw, TRUE);
1955 DEBUGOUT("Error Configuring DSP after link up\n");
1960 return E1000_SUCCESS;
1963 /******************************************************************************
1964 * Detects which PHY is present and setup the speed and duplex
1966 * hw - Struct containing variables accessed by shared code
1967 ******************************************************************************/
1969 e1000_setup_copper_link(struct e1000_hw *hw)
1976 DEBUGFUNC("e1000_setup_copper_link");
1978 switch (hw->mac_type) {
1979 case e1000_80003es2lan:
1981 /* Set the mac to wait the maximum time between each
1982 * iteration and increase the max iterations when
1983 * polling the phy; this fixes erroneous timeouts at 10Mbps. */
1984 ret_val = e1000_write_kmrn_reg(hw, GG82563_REG(0x34, 4), 0xFFFF);
1987 ret_val = e1000_read_kmrn_reg(hw, GG82563_REG(0x34, 9), ®_data);
1991 ret_val = e1000_write_kmrn_reg(hw, GG82563_REG(0x34, 9), reg_data);
1998 /* Check if it is a valid PHY and set PHY mode if necessary. */
1999 ret_val = e1000_copper_link_preconfig(hw);
2003 switch (hw->mac_type) {
2004 case e1000_80003es2lan:
2005 /* Kumeran registers are written-only */
2006 reg_data = E1000_KUMCTRLSTA_INB_CTRL_LINK_STATUS_TX_TIMEOUT_DEFAULT;
2007 reg_data |= E1000_KUMCTRLSTA_INB_CTRL_DIS_PADDING;
2008 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_INB_CTRL,
2017 if (hw->phy_type == e1000_phy_igp ||
2018 hw->phy_type == e1000_phy_igp_3 ||
2019 hw->phy_type == e1000_phy_igp_2) {
2020 ret_val = e1000_copper_link_igp_setup(hw);
2023 } else if (hw->phy_type == e1000_phy_m88) {
2024 ret_val = e1000_copper_link_mgp_setup(hw);
2027 } else if (hw->phy_type == e1000_phy_gg82563) {
2028 ret_val = e1000_copper_link_ggp_setup(hw);
2034 /* Setup autoneg and flow control advertisement
2035 * and perform autonegotiation */
2036 ret_val = e1000_copper_link_autoneg(hw);
2040 /* PHY will be set to 10H, 10F, 100H,or 100F
2041 * depending on value from forced_speed_duplex. */
2042 DEBUGOUT("Forcing speed and duplex\n");
2043 ret_val = e1000_phy_force_speed_duplex(hw);
2045 DEBUGOUT("Error Forcing Speed and Duplex\n");
2050 /* Check link status. Wait up to 100 microseconds for link to become
2053 for (i = 0; i < 10; i++) {
2054 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2057 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2061 if (phy_data & MII_SR_LINK_STATUS) {
2062 /* Config the MAC and PHY after link is up */
2063 ret_val = e1000_copper_link_postconfig(hw);
2067 DEBUGOUT("Valid link established!!!\n");
2068 return E1000_SUCCESS;
2073 DEBUGOUT("Unable to establish link!!!\n");
2074 return E1000_SUCCESS;
2077 /******************************************************************************
2078 * Configure the MAC-to-PHY interface for 10/100Mbps
2080 * hw - Struct containing variables accessed by shared code
2081 ******************************************************************************/
2083 e1000_configure_kmrn_for_10_100(struct e1000_hw *hw, uint16_t duplex)
2085 int32_t ret_val = E1000_SUCCESS;
2089 DEBUGFUNC("e1000_configure_kmrn_for_10_100");
2091 reg_data = E1000_KUMCTRLSTA_HD_CTRL_10_100_DEFAULT;
2092 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_HD_CTRL,
2097 /* Configure Transmit Inter-Packet Gap */
2098 tipg = E1000_READ_REG(hw, TIPG);
2099 tipg &= ~E1000_TIPG_IPGT_MASK;
2100 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_10_100;
2101 E1000_WRITE_REG(hw, TIPG, tipg);
2103 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, ®_data);
2108 if (duplex == HALF_DUPLEX)
2109 reg_data |= GG82563_KMCR_PASS_FALSE_CARRIER;
2111 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
2113 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
2119 e1000_configure_kmrn_for_1000(struct e1000_hw *hw)
2121 int32_t ret_val = E1000_SUCCESS;
2125 DEBUGFUNC("e1000_configure_kmrn_for_1000");
2127 reg_data = E1000_KUMCTRLSTA_HD_CTRL_1000_DEFAULT;
2128 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_HD_CTRL,
2133 /* Configure Transmit Inter-Packet Gap */
2134 tipg = E1000_READ_REG(hw, TIPG);
2135 tipg &= ~E1000_TIPG_IPGT_MASK;
2136 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
2137 E1000_WRITE_REG(hw, TIPG, tipg);
2139 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, ®_data);
2144 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
2145 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
2150 /******************************************************************************
2151 * Configures PHY autoneg and flow control advertisement settings
2153 * hw - Struct containing variables accessed by shared code
2154 ******************************************************************************/
2156 e1000_phy_setup_autoneg(struct e1000_hw *hw)
2159 uint16_t mii_autoneg_adv_reg;
2160 uint16_t mii_1000t_ctrl_reg;
2162 DEBUGFUNC("e1000_phy_setup_autoneg");
2164 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
2165 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
2169 if (hw->phy_type != e1000_phy_ife) {
2170 /* Read the MII 1000Base-T Control Register (Address 9). */
2171 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
2175 mii_1000t_ctrl_reg=0;
2177 /* Need to parse both autoneg_advertised and fc and set up
2178 * the appropriate PHY registers. First we will parse for
2179 * autoneg_advertised software override. Since we can advertise
2180 * a plethora of combinations, we need to check each bit
2184 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
2185 * Advertisement Register (Address 4) and the 1000 mb speed bits in
2186 * the 1000Base-T Control Register (Address 9).
2188 mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
2189 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
2191 DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised);
2193 /* Do we want to advertise 10 Mb Half Duplex? */
2194 if (hw->autoneg_advertised & ADVERTISE_10_HALF) {
2195 DEBUGOUT("Advertise 10mb Half duplex\n");
2196 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
2199 /* Do we want to advertise 10 Mb Full Duplex? */
2200 if (hw->autoneg_advertised & ADVERTISE_10_FULL) {
2201 DEBUGOUT("Advertise 10mb Full duplex\n");
2202 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
2205 /* Do we want to advertise 100 Mb Half Duplex? */
2206 if (hw->autoneg_advertised & ADVERTISE_100_HALF) {
2207 DEBUGOUT("Advertise 100mb Half duplex\n");
2208 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
2211 /* Do we want to advertise 100 Mb Full Duplex? */
2212 if (hw->autoneg_advertised & ADVERTISE_100_FULL) {
2213 DEBUGOUT("Advertise 100mb Full duplex\n");
2214 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
2217 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
2218 if (hw->autoneg_advertised & ADVERTISE_1000_HALF) {
2219 DEBUGOUT("Advertise 1000mb Half duplex requested, request denied!\n");
2222 /* Do we want to advertise 1000 Mb Full Duplex? */
2223 if (hw->autoneg_advertised & ADVERTISE_1000_FULL) {
2224 DEBUGOUT("Advertise 1000mb Full duplex\n");
2225 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
2226 if (hw->phy_type == e1000_phy_ife) {
2227 DEBUGOUT("e1000_phy_ife is a 10/100 PHY. Gigabit speed is not supported.\n");
2231 /* Check for a software override of the flow control settings, and
2232 * setup the PHY advertisement registers accordingly. If
2233 * auto-negotiation is enabled, then software will have to set the
2234 * "PAUSE" bits to the correct value in the Auto-Negotiation
2235 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
2237 * The possible values of the "fc" parameter are:
2238 * 0: Flow control is completely disabled
2239 * 1: Rx flow control is enabled (we can receive pause frames
2240 * but not send pause frames).
2241 * 2: Tx flow control is enabled (we can send pause frames
2242 * but we do not support receiving pause frames).
2243 * 3: Both Rx and TX flow control (symmetric) are enabled.
2244 * other: No software override. The flow control configuration
2245 * in the EEPROM is used.
2248 case E1000_FC_NONE: /* 0 */
2249 /* Flow control (RX & TX) is completely disabled by a
2250 * software over-ride.
2252 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2254 case E1000_FC_RX_PAUSE: /* 1 */
2255 /* RX Flow control is enabled, and TX Flow control is
2256 * disabled, by a software over-ride.
2258 /* Since there really isn't a way to advertise that we are
2259 * capable of RX Pause ONLY, we will advertise that we
2260 * support both symmetric and asymmetric RX PAUSE. Later
2261 * (in e1000_config_fc_after_link_up) we will disable the
2262 *hw's ability to send PAUSE frames.
2264 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2266 case E1000_FC_TX_PAUSE: /* 2 */
2267 /* TX Flow control is enabled, and RX Flow control is
2268 * disabled, by a software over-ride.
2270 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
2271 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
2273 case E1000_FC_FULL: /* 3 */
2274 /* Flow control (both RX and TX) is enabled by a software
2277 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2280 DEBUGOUT("Flow control param set incorrectly\n");
2281 return -E1000_ERR_CONFIG;
2284 ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
2288 DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
2290 if (hw->phy_type != e1000_phy_ife) {
2291 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg);
2296 return E1000_SUCCESS;
2299 /******************************************************************************
2300 * Force PHY speed and duplex settings to hw->forced_speed_duplex
2302 * hw - Struct containing variables accessed by shared code
2303 ******************************************************************************/
2305 e1000_phy_force_speed_duplex(struct e1000_hw *hw)
2309 uint16_t mii_ctrl_reg;
2310 uint16_t mii_status_reg;
2314 DEBUGFUNC("e1000_phy_force_speed_duplex");
2316 /* Turn off Flow control if we are forcing speed and duplex. */
2317 hw->fc = E1000_FC_NONE;
2319 DEBUGOUT1("hw->fc = %d\n", hw->fc);
2321 /* Read the Device Control Register. */
2322 ctrl = E1000_READ_REG(hw, CTRL);
2324 /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */
2325 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2326 ctrl &= ~(DEVICE_SPEED_MASK);
2328 /* Clear the Auto Speed Detect Enable bit. */
2329 ctrl &= ~E1000_CTRL_ASDE;
2331 /* Read the MII Control Register. */
2332 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg);
2336 /* We need to disable autoneg in order to force link and duplex. */
2338 mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN;
2340 /* Are we forcing Full or Half Duplex? */
2341 if (hw->forced_speed_duplex == e1000_100_full ||
2342 hw->forced_speed_duplex == e1000_10_full) {
2343 /* We want to force full duplex so we SET the full duplex bits in the
2344 * Device and MII Control Registers.
2346 ctrl |= E1000_CTRL_FD;
2347 mii_ctrl_reg |= MII_CR_FULL_DUPLEX;
2348 DEBUGOUT("Full Duplex\n");
2350 /* We want to force half duplex so we CLEAR the full duplex bits in
2351 * the Device and MII Control Registers.
2353 ctrl &= ~E1000_CTRL_FD;
2354 mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX;
2355 DEBUGOUT("Half Duplex\n");
2358 /* Are we forcing 100Mbps??? */
2359 if (hw->forced_speed_duplex == e1000_100_full ||
2360 hw->forced_speed_duplex == e1000_100_half) {
2361 /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */
2362 ctrl |= E1000_CTRL_SPD_100;
2363 mii_ctrl_reg |= MII_CR_SPEED_100;
2364 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
2365 DEBUGOUT("Forcing 100mb ");
2367 /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */
2368 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
2369 mii_ctrl_reg |= MII_CR_SPEED_10;
2370 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
2371 DEBUGOUT("Forcing 10mb ");
2374 e1000_config_collision_dist(hw);
2376 /* Write the configured values back to the Device Control Reg. */
2377 E1000_WRITE_REG(hw, CTRL, ctrl);
2379 if ((hw->phy_type == e1000_phy_m88) ||
2380 (hw->phy_type == e1000_phy_gg82563)) {
2381 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
2385 /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
2386 * forced whenever speed are duplex are forced.
2388 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
2389 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
2393 DEBUGOUT1("M88E1000 PSCR: %x \n", phy_data);
2395 /* Need to reset the PHY or these changes will be ignored */
2396 mii_ctrl_reg |= MII_CR_RESET;
2398 /* Disable MDI-X support for 10/100 */
2399 } else if (hw->phy_type == e1000_phy_ife) {
2400 ret_val = e1000_read_phy_reg(hw, IFE_PHY_MDIX_CONTROL, &phy_data);
2404 phy_data &= ~IFE_PMC_AUTO_MDIX;
2405 phy_data &= ~IFE_PMC_FORCE_MDIX;
2407 ret_val = e1000_write_phy_reg(hw, IFE_PHY_MDIX_CONTROL, phy_data);
2412 /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
2413 * forced whenever speed or duplex are forced.
2415 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
2419 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
2420 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
2422 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
2427 /* Write back the modified PHY MII control register. */
2428 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg);
2434 /* The wait_autoneg_complete flag may be a little misleading here.
2435 * Since we are forcing speed and duplex, Auto-Neg is not enabled.
2436 * But we do want to delay for a period while forcing only so we
2437 * don't generate false No Link messages. So we will wait here
2438 * only if the user has set wait_autoneg_complete to 1, which is
2441 if (hw->wait_autoneg_complete) {
2442 /* We will wait for autoneg to complete. */
2443 DEBUGOUT("Waiting for forced speed/duplex link.\n");
2446 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
2447 for (i = PHY_FORCE_TIME; i > 0; i--) {
2448 /* Read the MII Status Register and wait for Auto-Neg Complete bit
2451 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2455 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2459 if (mii_status_reg & MII_SR_LINK_STATUS) break;
2463 ((hw->phy_type == e1000_phy_m88) ||
2464 (hw->phy_type == e1000_phy_gg82563))) {
2465 /* We didn't get link. Reset the DSP and wait again for link. */
2466 ret_val = e1000_phy_reset_dsp(hw);
2468 DEBUGOUT("Error Resetting PHY DSP\n");
2472 /* This loop will early-out if the link condition has been met. */
2473 for (i = PHY_FORCE_TIME; i > 0; i--) {
2474 if (mii_status_reg & MII_SR_LINK_STATUS) break;
2476 /* Read the MII Status Register and wait for Auto-Neg Complete bit
2479 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2483 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2489 if (hw->phy_type == e1000_phy_m88) {
2490 /* Because we reset the PHY above, we need to re-force TX_CLK in the
2491 * Extended PHY Specific Control Register to 25MHz clock. This value
2492 * defaults back to a 2.5MHz clock when the PHY is reset.
2494 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
2498 phy_data |= M88E1000_EPSCR_TX_CLK_25;
2499 ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
2503 /* In addition, because of the s/w reset above, we need to enable CRS on
2504 * TX. This must be set for both full and half duplex operation.
2506 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
2510 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
2511 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
2515 if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
2516 (!hw->autoneg) && (hw->forced_speed_duplex == e1000_10_full ||
2517 hw->forced_speed_duplex == e1000_10_half)) {
2518 ret_val = e1000_polarity_reversal_workaround(hw);
2522 } else if (hw->phy_type == e1000_phy_gg82563) {
2523 /* The TX_CLK of the Extended PHY Specific Control Register defaults
2524 * to 2.5MHz on a reset. We need to re-force it back to 25MHz, if
2525 * we're not in a forced 10/duplex configuration. */
2526 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, &phy_data);
2530 phy_data &= ~GG82563_MSCR_TX_CLK_MASK;
2531 if ((hw->forced_speed_duplex == e1000_10_full) ||
2532 (hw->forced_speed_duplex == e1000_10_half))
2533 phy_data |= GG82563_MSCR_TX_CLK_10MBPS_2_5MHZ;
2535 phy_data |= GG82563_MSCR_TX_CLK_100MBPS_25MHZ;
2537 /* Also due to the reset, we need to enable CRS on Tx. */
2538 phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
2540 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, phy_data);
2544 return E1000_SUCCESS;
2547 /******************************************************************************
2548 * Sets the collision distance in the Transmit Control register
2550 * hw - Struct containing variables accessed by shared code
2552 * Link should have been established previously. Reads the speed and duplex
2553 * information from the Device Status register.
2554 ******************************************************************************/
2556 e1000_config_collision_dist(struct e1000_hw *hw)
2558 uint32_t tctl, coll_dist;
2560 DEBUGFUNC("e1000_config_collision_dist");
2562 if (hw->mac_type < e1000_82543)
2563 coll_dist = E1000_COLLISION_DISTANCE_82542;
2565 coll_dist = E1000_COLLISION_DISTANCE;
2567 tctl = E1000_READ_REG(hw, TCTL);
2569 tctl &= ~E1000_TCTL_COLD;
2570 tctl |= coll_dist << E1000_COLD_SHIFT;
2572 E1000_WRITE_REG(hw, TCTL, tctl);
2573 E1000_WRITE_FLUSH(hw);
2576 /******************************************************************************
2577 * Sets MAC speed and duplex settings to reflect the those in the PHY
2579 * hw - Struct containing variables accessed by shared code
2580 * mii_reg - data to write to the MII control register
2582 * The contents of the PHY register containing the needed information need to
2584 ******************************************************************************/
2586 e1000_config_mac_to_phy(struct e1000_hw *hw)
2592 DEBUGFUNC("e1000_config_mac_to_phy");
2594 /* 82544 or newer MAC, Auto Speed Detection takes care of
2595 * MAC speed/duplex configuration.*/
2596 if (hw->mac_type >= e1000_82544)
2597 return E1000_SUCCESS;
2599 /* Read the Device Control Register and set the bits to Force Speed
2602 ctrl = E1000_READ_REG(hw, CTRL);
2603 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2604 ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
2606 /* Set up duplex in the Device Control and Transmit Control
2607 * registers depending on negotiated values.
2609 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
2613 if (phy_data & M88E1000_PSSR_DPLX)
2614 ctrl |= E1000_CTRL_FD;
2616 ctrl &= ~E1000_CTRL_FD;
2618 e1000_config_collision_dist(hw);
2620 /* Set up speed in the Device Control register depending on
2621 * negotiated values.
2623 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
2624 ctrl |= E1000_CTRL_SPD_1000;
2625 else if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
2626 ctrl |= E1000_CTRL_SPD_100;
2628 /* Write the configured values back to the Device Control Reg. */
2629 E1000_WRITE_REG(hw, CTRL, ctrl);
2630 return E1000_SUCCESS;
2633 /******************************************************************************
2634 * Forces the MAC's flow control settings.
2636 * hw - Struct containing variables accessed by shared code
2638 * Sets the TFCE and RFCE bits in the device control register to reflect
2639 * the adapter settings. TFCE and RFCE need to be explicitly set by
2640 * software when a Copper PHY is used because autonegotiation is managed
2641 * by the PHY rather than the MAC. Software must also configure these
2642 * bits when link is forced on a fiber connection.
2643 *****************************************************************************/
2645 e1000_force_mac_fc(struct e1000_hw *hw)
2649 DEBUGFUNC("e1000_force_mac_fc");
2651 /* Get the current configuration of the Device Control Register */
2652 ctrl = E1000_READ_REG(hw, CTRL);
2654 /* Because we didn't get link via the internal auto-negotiation
2655 * mechanism (we either forced link or we got link via PHY
2656 * auto-neg), we have to manually enable/disable transmit an
2657 * receive flow control.
2659 * The "Case" statement below enables/disable flow control
2660 * according to the "hw->fc" parameter.
2662 * The possible values of the "fc" parameter are:
2663 * 0: Flow control is completely disabled
2664 * 1: Rx flow control is enabled (we can receive pause
2665 * frames but not send pause frames).
2666 * 2: Tx flow control is enabled (we can send pause frames
2667 * frames but we do not receive pause frames).
2668 * 3: Both Rx and TX flow control (symmetric) is enabled.
2669 * other: No other values should be possible at this point.
2674 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
2676 case E1000_FC_RX_PAUSE:
2677 ctrl &= (~E1000_CTRL_TFCE);
2678 ctrl |= E1000_CTRL_RFCE;
2680 case E1000_FC_TX_PAUSE:
2681 ctrl &= (~E1000_CTRL_RFCE);
2682 ctrl |= E1000_CTRL_TFCE;
2685 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
2688 DEBUGOUT("Flow control param set incorrectly\n");
2689 return -E1000_ERR_CONFIG;
2692 /* Disable TX Flow Control for 82542 (rev 2.0) */
2693 if (hw->mac_type == e1000_82542_rev2_0)
2694 ctrl &= (~E1000_CTRL_TFCE);
2696 E1000_WRITE_REG(hw, CTRL, ctrl);
2697 return E1000_SUCCESS;
2700 /******************************************************************************
2701 * Configures flow control settings after link is established
2703 * hw - Struct containing variables accessed by shared code
2705 * Should be called immediately after a valid link has been established.
2706 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
2707 * and autonegotiation is enabled, the MAC flow control settings will be set
2708 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
2709 * and RFCE bits will be automaticaly set to the negotiated flow control mode.
2710 *****************************************************************************/
2712 e1000_config_fc_after_link_up(struct e1000_hw *hw)
2715 uint16_t mii_status_reg;
2716 uint16_t mii_nway_adv_reg;
2717 uint16_t mii_nway_lp_ability_reg;
2721 DEBUGFUNC("e1000_config_fc_after_link_up");
2723 /* Check for the case where we have fiber media and auto-neg failed
2724 * so we had to force link. In this case, we need to force the
2725 * configuration of the MAC to match the "fc" parameter.
2727 if (((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) ||
2728 ((hw->media_type == e1000_media_type_internal_serdes) &&
2729 (hw->autoneg_failed)) ||
2730 ((hw->media_type == e1000_media_type_copper) && (!hw->autoneg))) {
2731 ret_val = e1000_force_mac_fc(hw);
2733 DEBUGOUT("Error forcing flow control settings\n");
2738 /* Check for the case where we have copper media and auto-neg is
2739 * enabled. In this case, we need to check and see if Auto-Neg
2740 * has completed, and if so, how the PHY and link partner has
2741 * flow control configured.
2743 if ((hw->media_type == e1000_media_type_copper) && hw->autoneg) {
2744 /* Read the MII Status Register and check to see if AutoNeg
2745 * has completed. We read this twice because this reg has
2746 * some "sticky" (latched) bits.
2748 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2751 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2755 if (mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
2756 /* The AutoNeg process has completed, so we now need to
2757 * read both the Auto Negotiation Advertisement Register
2758 * (Address 4) and the Auto_Negotiation Base Page Ability
2759 * Register (Address 5) to determine how flow control was
2762 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV,
2766 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY,
2767 &mii_nway_lp_ability_reg);
2771 /* Two bits in the Auto Negotiation Advertisement Register
2772 * (Address 4) and two bits in the Auto Negotiation Base
2773 * Page Ability Register (Address 5) determine flow control
2774 * for both the PHY and the link partner. The following
2775 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
2776 * 1999, describes these PAUSE resolution bits and how flow
2777 * control is determined based upon these settings.
2778 * NOTE: DC = Don't Care
2780 * LOCAL DEVICE | LINK PARTNER
2781 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
2782 *-------|---------|-------|---------|--------------------
2783 * 0 | 0 | DC | DC | E1000_FC_NONE
2784 * 0 | 1 | 0 | DC | E1000_FC_NONE
2785 * 0 | 1 | 1 | 0 | E1000_FC_NONE
2786 * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
2787 * 1 | 0 | 0 | DC | E1000_FC_NONE
2788 * 1 | DC | 1 | DC | E1000_FC_FULL
2789 * 1 | 1 | 0 | 0 | E1000_FC_NONE
2790 * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
2793 /* Are both PAUSE bits set to 1? If so, this implies
2794 * Symmetric Flow Control is enabled at both ends. The
2795 * ASM_DIR bits are irrelevant per the spec.
2797 * For Symmetric Flow Control:
2799 * LOCAL DEVICE | LINK PARTNER
2800 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2801 *-------|---------|-------|---------|--------------------
2802 * 1 | DC | 1 | DC | E1000_FC_FULL
2805 if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2806 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
2807 /* Now we need to check if the user selected RX ONLY
2808 * of pause frames. In this case, we had to advertise
2809 * FULL flow control because we could not advertise RX
2810 * ONLY. Hence, we must now check to see if we need to
2811 * turn OFF the TRANSMISSION of PAUSE frames.
2813 if (hw->original_fc == E1000_FC_FULL) {
2814 hw->fc = E1000_FC_FULL;
2815 DEBUGOUT("Flow Control = FULL.\n");
2817 hw->fc = E1000_FC_RX_PAUSE;
2818 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
2821 /* For receiving PAUSE frames ONLY.
2823 * LOCAL DEVICE | LINK PARTNER
2824 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2825 *-------|---------|-------|---------|--------------------
2826 * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
2829 else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2830 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2831 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2832 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
2833 hw->fc = E1000_FC_TX_PAUSE;
2834 DEBUGOUT("Flow Control = TX PAUSE frames only.\n");
2836 /* For transmitting PAUSE frames ONLY.
2838 * LOCAL DEVICE | LINK PARTNER
2839 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2840 *-------|---------|-------|---------|--------------------
2841 * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
2844 else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2845 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2846 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2847 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
2848 hw->fc = E1000_FC_RX_PAUSE;
2849 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
2851 /* Per the IEEE spec, at this point flow control should be
2852 * disabled. However, we want to consider that we could
2853 * be connected to a legacy switch that doesn't advertise
2854 * desired flow control, but can be forced on the link
2855 * partner. So if we advertised no flow control, that is
2856 * what we will resolve to. If we advertised some kind of
2857 * receive capability (Rx Pause Only or Full Flow Control)
2858 * and the link partner advertised none, we will configure
2859 * ourselves to enable Rx Flow Control only. We can do
2860 * this safely for two reasons: If the link partner really
2861 * didn't want flow control enabled, and we enable Rx, no
2862 * harm done since we won't be receiving any PAUSE frames
2863 * anyway. If the intent on the link partner was to have
2864 * flow control enabled, then by us enabling RX only, we
2865 * can at least receive pause frames and process them.
2866 * This is a good idea because in most cases, since we are
2867 * predominantly a server NIC, more times than not we will
2868 * be asked to delay transmission of packets than asking
2869 * our link partner to pause transmission of frames.
2871 else if ((hw->original_fc == E1000_FC_NONE ||
2872 hw->original_fc == E1000_FC_TX_PAUSE) ||
2873 hw->fc_strict_ieee) {
2874 hw->fc = E1000_FC_NONE;
2875 DEBUGOUT("Flow Control = NONE.\n");
2877 hw->fc = E1000_FC_RX_PAUSE;
2878 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
2881 /* Now we need to do one last check... If we auto-
2882 * negotiated to HALF DUPLEX, flow control should not be
2883 * enabled per IEEE 802.3 spec.
2885 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
2887 DEBUGOUT("Error getting link speed and duplex\n");
2891 if (duplex == HALF_DUPLEX)
2892 hw->fc = E1000_FC_NONE;
2894 /* Now we call a subroutine to actually force the MAC
2895 * controller to use the correct flow control settings.
2897 ret_val = e1000_force_mac_fc(hw);
2899 DEBUGOUT("Error forcing flow control settings\n");
2903 DEBUGOUT("Copper PHY and Auto Neg has not completed.\n");
2906 return E1000_SUCCESS;
2909 /******************************************************************************
2910 * Checks to see if the link status of the hardware has changed.
2912 * hw - Struct containing variables accessed by shared code
2914 * Called by any function that needs to check the link status of the adapter.
2915 *****************************************************************************/
2917 e1000_check_for_link(struct e1000_hw *hw)
2924 uint32_t signal = 0;
2928 DEBUGFUNC("e1000_check_for_link");
2930 ctrl = E1000_READ_REG(hw, CTRL);
2931 status = E1000_READ_REG(hw, STATUS);
2933 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
2934 * set when the optics detect a signal. On older adapters, it will be
2935 * cleared when there is a signal. This applies to fiber media only.
2937 if ((hw->media_type == e1000_media_type_fiber) ||
2938 (hw->media_type == e1000_media_type_internal_serdes)) {
2939 rxcw = E1000_READ_REG(hw, RXCW);
2941 if (hw->media_type == e1000_media_type_fiber) {
2942 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
2943 if (status & E1000_STATUS_LU)
2944 hw->get_link_status = FALSE;
2948 /* If we have a copper PHY then we only want to go out to the PHY
2949 * registers to see if Auto-Neg has completed and/or if our link
2950 * status has changed. The get_link_status flag will be set if we
2951 * receive a Link Status Change interrupt or we have Rx Sequence
2954 if ((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
2955 /* First we want to see if the MII Status Register reports
2956 * link. If so, then we want to get the current speed/duplex
2958 * Read the register twice since the link bit is sticky.
2960 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2963 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2967 if (phy_data & MII_SR_LINK_STATUS) {
2968 hw->get_link_status = FALSE;
2969 /* Check if there was DownShift, must be checked immediately after
2971 e1000_check_downshift(hw);
2973 /* If we are on 82544 or 82543 silicon and speed/duplex
2974 * are forced to 10H or 10F, then we will implement the polarity
2975 * reversal workaround. We disable interrupts first, and upon
2976 * returning, place the devices interrupt state to its previous
2977 * value except for the link status change interrupt which will
2978 * happen due to the execution of this workaround.
2981 if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
2983 (hw->forced_speed_duplex == e1000_10_full ||
2984 hw->forced_speed_duplex == e1000_10_half)) {
2985 E1000_WRITE_REG(hw, IMC, 0xffffffff);
2986 ret_val = e1000_polarity_reversal_workaround(hw);
2987 icr = E1000_READ_REG(hw, ICR);
2988 E1000_WRITE_REG(hw, ICS, (icr & ~E1000_ICS_LSC));
2989 E1000_WRITE_REG(hw, IMS, IMS_ENABLE_MASK);
2993 /* No link detected */
2994 e1000_config_dsp_after_link_change(hw, FALSE);
2998 /* If we are forcing speed/duplex, then we simply return since
2999 * we have already determined whether we have link or not.
3001 if (!hw->autoneg) return -E1000_ERR_CONFIG;
3003 /* optimize the dsp settings for the igp phy */
3004 e1000_config_dsp_after_link_change(hw, TRUE);
3006 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
3007 * have Si on board that is 82544 or newer, Auto
3008 * Speed Detection takes care of MAC speed/duplex
3009 * configuration. So we only need to configure Collision
3010 * Distance in the MAC. Otherwise, we need to force
3011 * speed/duplex on the MAC to the current PHY speed/duplex
3014 if (hw->mac_type >= e1000_82544)
3015 e1000_config_collision_dist(hw);
3017 ret_val = e1000_config_mac_to_phy(hw);
3019 DEBUGOUT("Error configuring MAC to PHY settings\n");
3024 /* Configure Flow Control now that Auto-Neg has completed. First, we
3025 * need to restore the desired flow control settings because we may
3026 * have had to re-autoneg with a different link partner.
3028 ret_val = e1000_config_fc_after_link_up(hw);
3030 DEBUGOUT("Error configuring flow control\n");
3034 /* At this point we know that we are on copper and we have
3035 * auto-negotiated link. These are conditions for checking the link
3036 * partner capability register. We use the link speed to determine if
3037 * TBI compatibility needs to be turned on or off. If the link is not
3038 * at gigabit speed, then TBI compatibility is not needed. If we are
3039 * at gigabit speed, we turn on TBI compatibility.
3041 if (hw->tbi_compatibility_en) {
3042 uint16_t speed, duplex;
3043 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
3045 DEBUGOUT("Error getting link speed and duplex\n");
3048 if (speed != SPEED_1000) {
3049 /* If link speed is not set to gigabit speed, we do not need
3050 * to enable TBI compatibility.
3052 if (hw->tbi_compatibility_on) {
3053 /* If we previously were in the mode, turn it off. */
3054 rctl = E1000_READ_REG(hw, RCTL);
3055 rctl &= ~E1000_RCTL_SBP;
3056 E1000_WRITE_REG(hw, RCTL, rctl);
3057 hw->tbi_compatibility_on = FALSE;
3060 /* If TBI compatibility is was previously off, turn it on. For
3061 * compatibility with a TBI link partner, we will store bad
3062 * packets. Some frames have an additional byte on the end and
3063 * will look like CRC errors to to the hardware.
3065 if (!hw->tbi_compatibility_on) {
3066 hw->tbi_compatibility_on = TRUE;
3067 rctl = E1000_READ_REG(hw, RCTL);
3068 rctl |= E1000_RCTL_SBP;
3069 E1000_WRITE_REG(hw, RCTL, rctl);
3074 /* If we don't have link (auto-negotiation failed or link partner cannot
3075 * auto-negotiate), the cable is plugged in (we have signal), and our
3076 * link partner is not trying to auto-negotiate with us (we are receiving
3077 * idles or data), we need to force link up. We also need to give
3078 * auto-negotiation time to complete, in case the cable was just plugged
3079 * in. The autoneg_failed flag does this.
3081 else if ((((hw->media_type == e1000_media_type_fiber) &&
3082 ((ctrl & E1000_CTRL_SWDPIN1) == signal)) ||
3083 (hw->media_type == e1000_media_type_internal_serdes)) &&
3084 (!(status & E1000_STATUS_LU)) &&
3085 (!(rxcw & E1000_RXCW_C))) {
3086 if (hw->autoneg_failed == 0) {
3087 hw->autoneg_failed = 1;
3090 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\n");
3092 /* Disable auto-negotiation in the TXCW register */
3093 E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
3095 /* Force link-up and also force full-duplex. */
3096 ctrl = E1000_READ_REG(hw, CTRL);
3097 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
3098 E1000_WRITE_REG(hw, CTRL, ctrl);
3100 /* Configure Flow Control after forcing link up. */
3101 ret_val = e1000_config_fc_after_link_up(hw);
3103 DEBUGOUT("Error configuring flow control\n");
3107 /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
3108 * auto-negotiation in the TXCW register and disable forced link in the
3109 * Device Control register in an attempt to auto-negotiate with our link
3112 else if (((hw->media_type == e1000_media_type_fiber) ||
3113 (hw->media_type == e1000_media_type_internal_serdes)) &&
3114 (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
3115 DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\n");
3116 E1000_WRITE_REG(hw, TXCW, hw->txcw);
3117 E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
3119 hw->serdes_link_down = FALSE;
3121 /* If we force link for non-auto-negotiation switch, check link status
3122 * based on MAC synchronization for internal serdes media type.
3124 else if ((hw->media_type == e1000_media_type_internal_serdes) &&
3125 !(E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
3126 /* SYNCH bit and IV bit are sticky. */
3128 if (E1000_RXCW_SYNCH & E1000_READ_REG(hw, RXCW)) {
3129 if (!(rxcw & E1000_RXCW_IV)) {
3130 hw->serdes_link_down = FALSE;
3131 DEBUGOUT("SERDES: Link is up.\n");
3134 hw->serdes_link_down = TRUE;
3135 DEBUGOUT("SERDES: Link is down.\n");
3138 if ((hw->media_type == e1000_media_type_internal_serdes) &&
3139 (E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
3140 hw->serdes_link_down = !(E1000_STATUS_LU & E1000_READ_REG(hw, STATUS));
3142 return E1000_SUCCESS;
3145 /******************************************************************************
3146 * Detects the current speed and duplex settings of the hardware.
3148 * hw - Struct containing variables accessed by shared code
3149 * speed - Speed of the connection
3150 * duplex - Duplex setting of the connection
3151 *****************************************************************************/
3153 e1000_get_speed_and_duplex(struct e1000_hw *hw,
3161 DEBUGFUNC("e1000_get_speed_and_duplex");
3163 if (hw->mac_type >= e1000_82543) {
3164 status = E1000_READ_REG(hw, STATUS);
3165 if (status & E1000_STATUS_SPEED_1000) {
3166 *speed = SPEED_1000;
3167 DEBUGOUT("1000 Mbs, ");
3168 } else if (status & E1000_STATUS_SPEED_100) {
3170 DEBUGOUT("100 Mbs, ");
3173 DEBUGOUT("10 Mbs, ");
3176 if (status & E1000_STATUS_FD) {
3177 *duplex = FULL_DUPLEX;
3178 DEBUGOUT("Full Duplex\n");
3180 *duplex = HALF_DUPLEX;
3181 DEBUGOUT(" Half Duplex\n");
3184 DEBUGOUT("1000 Mbs, Full Duplex\n");
3185 *speed = SPEED_1000;
3186 *duplex = FULL_DUPLEX;
3189 /* IGP01 PHY may advertise full duplex operation after speed downgrade even
3190 * if it is operating at half duplex. Here we set the duplex settings to
3191 * match the duplex in the link partner's capabilities.
3193 if (hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
3194 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
3198 if (!(phy_data & NWAY_ER_LP_NWAY_CAPS))
3199 *duplex = HALF_DUPLEX;
3201 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data);
3204 if ((*speed == SPEED_100 && !(phy_data & NWAY_LPAR_100TX_FD_CAPS)) ||
3205 (*speed == SPEED_10 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
3206 *duplex = HALF_DUPLEX;
3210 if ((hw->mac_type == e1000_80003es2lan) &&
3211 (hw->media_type == e1000_media_type_copper)) {
3212 if (*speed == SPEED_1000)
3213 ret_val = e1000_configure_kmrn_for_1000(hw);
3215 ret_val = e1000_configure_kmrn_for_10_100(hw, *duplex);
3220 if ((hw->phy_type == e1000_phy_igp_3) && (*speed == SPEED_1000)) {
3221 ret_val = e1000_kumeran_lock_loss_workaround(hw);
3226 return E1000_SUCCESS;
3229 /******************************************************************************
3230 * Blocks until autoneg completes or times out (~4.5 seconds)
3232 * hw - Struct containing variables accessed by shared code
3233 ******************************************************************************/
3235 e1000_wait_autoneg(struct e1000_hw *hw)
3241 DEBUGFUNC("e1000_wait_autoneg");
3242 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
3244 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
3245 for (i = PHY_AUTO_NEG_TIME; i > 0; i--) {
3246 /* Read the MII Status Register and wait for Auto-Neg
3247 * Complete bit to be set.
3249 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3252 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3255 if (phy_data & MII_SR_AUTONEG_COMPLETE) {
3256 return E1000_SUCCESS;
3260 return E1000_SUCCESS;
3263 /******************************************************************************
3264 * Raises the Management Data Clock
3266 * hw - Struct containing variables accessed by shared code
3267 * ctrl - Device control register's current value
3268 ******************************************************************************/
3270 e1000_raise_mdi_clk(struct e1000_hw *hw,
3273 /* Raise the clock input to the Management Data Clock (by setting the MDC
3274 * bit), and then delay 10 microseconds.
3276 E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
3277 E1000_WRITE_FLUSH(hw);
3281 /******************************************************************************
3282 * Lowers the Management Data Clock
3284 * hw - Struct containing variables accessed by shared code
3285 * ctrl - Device control register's current value
3286 ******************************************************************************/
3288 e1000_lower_mdi_clk(struct e1000_hw *hw,
3291 /* Lower the clock input to the Management Data Clock (by clearing the MDC
3292 * bit), and then delay 10 microseconds.
3294 E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
3295 E1000_WRITE_FLUSH(hw);
3299 /******************************************************************************
3300 * Shifts data bits out to the PHY
3302 * hw - Struct containing variables accessed by shared code
3303 * data - Data to send out to the PHY
3304 * count - Number of bits to shift out
3306 * Bits are shifted out in MSB to LSB order.
3307 ******************************************************************************/
3309 e1000_shift_out_mdi_bits(struct e1000_hw *hw,
3316 /* We need to shift "count" number of bits out to the PHY. So, the value
3317 * in the "data" parameter will be shifted out to the PHY one bit at a
3318 * time. In order to do this, "data" must be broken down into bits.
3321 mask <<= (count - 1);
3323 ctrl = E1000_READ_REG(hw, CTRL);
3325 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
3326 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
3329 /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
3330 * then raising and lowering the Management Data Clock. A "0" is
3331 * shifted out to the PHY by setting the MDIO bit to "0" and then
3332 * raising and lowering the clock.
3335 ctrl |= E1000_CTRL_MDIO;
3337 ctrl &= ~E1000_CTRL_MDIO;
3339 E1000_WRITE_REG(hw, CTRL, ctrl);
3340 E1000_WRITE_FLUSH(hw);
3344 e1000_raise_mdi_clk(hw, &ctrl);
3345 e1000_lower_mdi_clk(hw, &ctrl);
3351 /******************************************************************************
3352 * Shifts data bits in from the PHY
3354 * hw - Struct containing variables accessed by shared code
3356 * Bits are shifted in in MSB to LSB order.
3357 ******************************************************************************/
3359 e1000_shift_in_mdi_bits(struct e1000_hw *hw)
3365 /* In order to read a register from the PHY, we need to shift in a total
3366 * of 18 bits from the PHY. The first two bit (turnaround) times are used
3367 * to avoid contention on the MDIO pin when a read operation is performed.
3368 * These two bits are ignored by us and thrown away. Bits are "shifted in"
3369 * by raising the input to the Management Data Clock (setting the MDC bit),
3370 * and then reading the value of the MDIO bit.
3372 ctrl = E1000_READ_REG(hw, CTRL);
3374 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
3375 ctrl &= ~E1000_CTRL_MDIO_DIR;
3376 ctrl &= ~E1000_CTRL_MDIO;
3378 E1000_WRITE_REG(hw, CTRL, ctrl);
3379 E1000_WRITE_FLUSH(hw);
3381 /* Raise and Lower the clock before reading in the data. This accounts for
3382 * the turnaround bits. The first clock occurred when we clocked out the
3383 * last bit of the Register Address.
3385 e1000_raise_mdi_clk(hw, &ctrl);
3386 e1000_lower_mdi_clk(hw, &ctrl);
3388 for (data = 0, i = 0; i < 16; i++) {
3390 e1000_raise_mdi_clk(hw, &ctrl);
3391 ctrl = E1000_READ_REG(hw, CTRL);
3392 /* Check to see if we shifted in a "1". */
3393 if (ctrl & E1000_CTRL_MDIO)
3395 e1000_lower_mdi_clk(hw, &ctrl);
3398 e1000_raise_mdi_clk(hw, &ctrl);
3399 e1000_lower_mdi_clk(hw, &ctrl);
3405 e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask)
3407 uint32_t swfw_sync = 0;
3408 uint32_t swmask = mask;
3409 uint32_t fwmask = mask << 16;
3410 int32_t timeout = 200;
3412 DEBUGFUNC("e1000_swfw_sync_acquire");
3414 if (hw->swfwhw_semaphore_present)
3415 return e1000_get_software_flag(hw);
3417 if (!hw->swfw_sync_present)
3418 return e1000_get_hw_eeprom_semaphore(hw);
3421 if (e1000_get_hw_eeprom_semaphore(hw))
3422 return -E1000_ERR_SWFW_SYNC;
3424 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
3425 if (!(swfw_sync & (fwmask | swmask))) {
3429 /* firmware currently using resource (fwmask) */
3430 /* or other software thread currently using resource (swmask) */
3431 e1000_put_hw_eeprom_semaphore(hw);
3437 DEBUGOUT("Driver can't access resource, SW_FW_SYNC timeout.\n");
3438 return -E1000_ERR_SWFW_SYNC;
3441 swfw_sync |= swmask;
3442 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
3444 e1000_put_hw_eeprom_semaphore(hw);
3445 return E1000_SUCCESS;
3449 e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask)
3452 uint32_t swmask = mask;
3454 DEBUGFUNC("e1000_swfw_sync_release");
3456 if (hw->swfwhw_semaphore_present) {
3457 e1000_release_software_flag(hw);
3461 if (!hw->swfw_sync_present) {
3462 e1000_put_hw_eeprom_semaphore(hw);
3466 /* if (e1000_get_hw_eeprom_semaphore(hw))
3467 * return -E1000_ERR_SWFW_SYNC; */
3468 while (e1000_get_hw_eeprom_semaphore(hw) != E1000_SUCCESS);
3471 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
3472 swfw_sync &= ~swmask;
3473 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
3475 e1000_put_hw_eeprom_semaphore(hw);
3478 /*****************************************************************************
3479 * Reads the value from a PHY register, if the value is on a specific non zero
3480 * page, sets the page first.
3481 * hw - Struct containing variables accessed by shared code
3482 * reg_addr - address of the PHY register to read
3483 ******************************************************************************/
3485 e1000_read_phy_reg(struct e1000_hw *hw,
3492 DEBUGFUNC("e1000_read_phy_reg");
3494 if ((hw->mac_type == e1000_80003es2lan) &&
3495 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3496 swfw = E1000_SWFW_PHY1_SM;
3498 swfw = E1000_SWFW_PHY0_SM;
3500 if (e1000_swfw_sync_acquire(hw, swfw))
3501 return -E1000_ERR_SWFW_SYNC;
3503 if ((hw->phy_type == e1000_phy_igp ||
3504 hw->phy_type == e1000_phy_igp_3 ||
3505 hw->phy_type == e1000_phy_igp_2) &&
3506 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
3507 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
3508 (uint16_t)reg_addr);
3510 e1000_swfw_sync_release(hw, swfw);
3513 } else if (hw->phy_type == e1000_phy_gg82563) {
3514 if (((reg_addr & MAX_PHY_REG_ADDRESS) > MAX_PHY_MULTI_PAGE_REG) ||
3515 (hw->mac_type == e1000_80003es2lan)) {
3516 /* Select Configuration Page */
3517 if ((reg_addr & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) {
3518 ret_val = e1000_write_phy_reg_ex(hw, GG82563_PHY_PAGE_SELECT,
3519 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3521 /* Use Alternative Page Select register to access
3522 * registers 30 and 31
3524 ret_val = e1000_write_phy_reg_ex(hw,
3525 GG82563_PHY_PAGE_SELECT_ALT,
3526 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3530 e1000_swfw_sync_release(hw, swfw);
3536 ret_val = e1000_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
3539 e1000_swfw_sync_release(hw, swfw);
3544 e1000_read_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr,
3549 const uint32_t phy_addr = 1;
3551 DEBUGFUNC("e1000_read_phy_reg_ex");
3553 if (reg_addr > MAX_PHY_REG_ADDRESS) {
3554 DEBUGOUT1("PHY Address %ld is out of range\n", reg_addr);
3555 return -E1000_ERR_PARAM;
3558 if (hw->mac_type > e1000_82543) {
3559 /* Set up Op-code, Phy Address, and register address in the MDI
3560 * Control register. The MAC will take care of interfacing with the
3561 * PHY to retrieve the desired data.
3563 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
3564 (phy_addr << E1000_MDIC_PHY_SHIFT) |
3565 (E1000_MDIC_OP_READ));
3567 E1000_WRITE_REG(hw, MDIC, mdic);
3569 /* Poll the ready bit to see if the MDI read completed */
3570 for (i = 0; i < 64; i++) {
3572 mdic = E1000_READ_REG(hw, MDIC);
3573 if (mdic & E1000_MDIC_READY) break;
3575 if (!(mdic & E1000_MDIC_READY)) {
3576 DEBUGOUT("MDI Read did not complete\n");
3577 return -E1000_ERR_PHY;
3579 if (mdic & E1000_MDIC_ERROR) {
3580 DEBUGOUT("MDI Error\n");
3581 return -E1000_ERR_PHY;