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 *******************************************************************************/
29 FILE_LICENCE ( GPL2_ONLY );
32 * Shared functions for accessing and configuring the MAC
38 static int32_t e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask);
39 static void e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask);
40 static int32_t e1000_read_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t *data);
41 static int32_t e1000_write_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t data);
42 static int32_t e1000_get_software_semaphore(struct e1000_hw *hw);
43 static void e1000_release_software_semaphore(struct e1000_hw *hw);
45 static uint8_t e1000_arc_subsystem_valid(struct e1000_hw *hw);
46 static int32_t e1000_check_downshift(struct e1000_hw *hw);
47 static int32_t e1000_check_polarity(struct e1000_hw *hw, e1000_rev_polarity *polarity);
48 static void e1000_clear_hw_cntrs(struct e1000_hw *hw);
49 static void e1000_clear_vfta(struct e1000_hw *hw);
50 static int32_t e1000_commit_shadow_ram(struct e1000_hw *hw);
51 static int32_t e1000_config_dsp_after_link_change(struct e1000_hw *hw, boolean_t link_up);
52 static int32_t e1000_config_fc_after_link_up(struct e1000_hw *hw);
53 static int32_t e1000_detect_gig_phy(struct e1000_hw *hw);
54 static int32_t e1000_erase_ich8_4k_segment(struct e1000_hw *hw, uint32_t bank);
55 static int32_t e1000_get_auto_rd_done(struct e1000_hw *hw);
56 static int32_t e1000_get_cable_length(struct e1000_hw *hw, uint16_t *min_length, uint16_t *max_length);
57 static int32_t e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw);
58 static int32_t e1000_get_phy_cfg_done(struct e1000_hw *hw);
59 static int32_t e1000_get_software_flag(struct e1000_hw *hw);
60 static int32_t e1000_ich8_cycle_init(struct e1000_hw *hw);
61 static int32_t e1000_ich8_flash_cycle(struct e1000_hw *hw, uint32_t timeout);
62 static int32_t e1000_id_led_init(struct e1000_hw *hw);
63 static int32_t e1000_init_lcd_from_nvm_config_region(struct e1000_hw *hw, uint32_t cnf_base_addr, uint32_t cnf_size);
64 static int32_t e1000_init_lcd_from_nvm(struct e1000_hw *hw);
65 static void e1000_init_rx_addrs(struct e1000_hw *hw);
66 static void e1000_initialize_hardware_bits(struct e1000_hw *hw);
67 static boolean_t e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw);
68 static int32_t e1000_kumeran_lock_loss_workaround(struct e1000_hw *hw);
69 static int32_t e1000_mng_enable_host_if(struct e1000_hw *hw);
70 static int32_t e1000_mng_host_if_write(struct e1000_hw *hw, uint8_t *buffer, uint16_t length, uint16_t offset, uint8_t *sum);
71 static int32_t e1000_mng_write_cmd_header(struct e1000_hw* hw, struct e1000_host_mng_command_header* hdr);
72 static int32_t e1000_mng_write_commit(struct e1000_hw *hw);
73 static int32_t e1000_phy_ife_get_info(struct e1000_hw *hw, struct e1000_phy_info *phy_info);
74 static int32_t e1000_phy_igp_get_info(struct e1000_hw *hw, struct e1000_phy_info *phy_info);
75 static int32_t e1000_read_eeprom_eerd(struct e1000_hw *hw, uint16_t offset, uint16_t words, uint16_t *data);
76 static int32_t e1000_write_eeprom_eewr(struct e1000_hw *hw, uint16_t offset, uint16_t words, uint16_t *data);
77 static int32_t e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd);
78 static int32_t e1000_phy_m88_get_info(struct e1000_hw *hw, struct e1000_phy_info *phy_info);
79 static void e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw);
80 static int32_t e1000_read_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t *data);
81 static int32_t e1000_verify_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t byte);
82 static int32_t e1000_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t byte);
83 static int32_t e1000_read_ich8_word(struct e1000_hw *hw, uint32_t index, uint16_t *data);
84 static int32_t e1000_read_ich8_data(struct e1000_hw *hw, uint32_t index, uint32_t size, uint16_t *data);
85 static int32_t e1000_write_ich8_data(struct e1000_hw *hw, uint32_t index, uint32_t size, uint16_t data);
86 static int32_t e1000_read_eeprom_ich8(struct e1000_hw *hw, uint16_t offset, uint16_t words, uint16_t *data);
87 static int32_t e1000_write_eeprom_ich8(struct e1000_hw *hw, uint16_t offset, uint16_t words, uint16_t *data);
88 static void e1000_release_software_flag(struct e1000_hw *hw);
89 static int32_t e1000_set_d3_lplu_state(struct e1000_hw *hw, boolean_t active);
90 static int32_t e1000_set_d0_lplu_state(struct e1000_hw *hw, boolean_t active);
91 static int32_t e1000_set_pci_ex_no_snoop(struct e1000_hw *hw, uint32_t no_snoop);
92 static void e1000_set_pci_express_master_disable(struct e1000_hw *hw);
93 static int32_t e1000_wait_autoneg(struct e1000_hw *hw);
94 static void e1000_write_reg_io(struct e1000_hw *hw, uint32_t offset, uint32_t value);
95 static int32_t e1000_set_phy_type(struct e1000_hw *hw);
96 static void e1000_phy_init_script(struct e1000_hw *hw);
97 static int32_t e1000_setup_copper_link(struct e1000_hw *hw);
98 static int32_t e1000_setup_fiber_serdes_link(struct e1000_hw *hw);
99 static int32_t e1000_adjust_serdes_amplitude(struct e1000_hw *hw);
100 static int32_t e1000_phy_force_speed_duplex(struct e1000_hw *hw);
101 static int32_t e1000_config_mac_to_phy(struct e1000_hw *hw);
102 static void e1000_raise_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl);
103 static void e1000_lower_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl);
104 static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, uint32_t data,
106 static uint16_t e1000_shift_in_mdi_bits(struct e1000_hw *hw);
107 static int32_t e1000_phy_reset_dsp(struct e1000_hw *hw);
108 static int32_t e1000_write_eeprom_spi(struct e1000_hw *hw, uint16_t offset,
109 uint16_t words, uint16_t *data);
110 static int32_t e1000_write_eeprom_microwire(struct e1000_hw *hw,
111 uint16_t offset, uint16_t words,
113 static int32_t e1000_spi_eeprom_ready(struct e1000_hw *hw);
114 static void e1000_raise_ee_clk(struct e1000_hw *hw, uint32_t *eecd);
115 static void e1000_lower_ee_clk(struct e1000_hw *hw, uint32_t *eecd);
116 static void e1000_shift_out_ee_bits(struct e1000_hw *hw, uint16_t data,
118 static int32_t e1000_write_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr,
120 static int32_t e1000_read_phy_reg_ex(struct e1000_hw *hw,uint32_t reg_addr,
122 static uint16_t e1000_shift_in_ee_bits(struct e1000_hw *hw, uint16_t count);
123 static int32_t e1000_acquire_eeprom(struct e1000_hw *hw);
124 static void e1000_release_eeprom(struct e1000_hw *hw);
125 static void e1000_standby_eeprom(struct e1000_hw *hw);
126 static int32_t e1000_set_vco_speed(struct e1000_hw *hw);
127 static int32_t e1000_polarity_reversal_workaround(struct e1000_hw *hw);
128 static int32_t e1000_set_phy_mode(struct e1000_hw *hw);
129 static int32_t e1000_host_if_read_cookie(struct e1000_hw *hw, uint8_t *buffer);
130 static uint8_t e1000_calculate_mng_checksum(char *buffer, uint32_t length);
131 static int32_t e1000_configure_kmrn_for_10_100(struct e1000_hw *hw,
133 static int32_t e1000_configure_kmrn_for_1000(struct e1000_hw *hw);
135 /* IGP cable length table */
137 uint16_t e1000_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] =
138 { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
139 5, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 25, 25, 25,
140 25, 25, 25, 25, 30, 30, 30, 30, 40, 40, 40, 40, 40, 40, 40, 40,
141 40, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60,
142 60, 70, 70, 70, 70, 70, 70, 80, 80, 80, 80, 80, 80, 90, 90, 90,
143 90, 90, 90, 90, 90, 90, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
144 100, 100, 100, 100, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,
145 110, 110, 110, 110, 110, 110, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120};
148 uint16_t e1000_igp_2_cable_length_table[IGP02E1000_AGC_LENGTH_TABLE_SIZE] =
149 { 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21,
150 0, 0, 0, 3, 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41,
151 6, 10, 14, 18, 22, 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61,
152 21, 26, 31, 35, 40, 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82,
153 40, 45, 51, 56, 61, 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104,
154 60, 66, 72, 77, 82, 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121,
155 83, 89, 95, 100, 105, 109, 113, 116, 119, 122, 124,
156 104, 109, 114, 118, 121, 124};
158 /******************************************************************************
159 * Set the phy type member in the hw struct.
161 * hw - Struct containing variables accessed by shared code
162 *****************************************************************************/
164 e1000_set_phy_type(struct e1000_hw *hw)
166 DEBUGFUNC("e1000_set_phy_type");
168 if (hw->mac_type == e1000_undefined)
169 return -E1000_ERR_PHY_TYPE;
171 switch (hw->phy_id) {
172 case M88E1000_E_PHY_ID:
173 case M88E1000_I_PHY_ID:
174 case M88E1011_I_PHY_ID:
175 case M88E1111_I_PHY_ID:
176 hw->phy_type = e1000_phy_m88;
178 case IGP01E1000_I_PHY_ID:
179 if (hw->mac_type == e1000_82541 ||
180 hw->mac_type == e1000_82541_rev_2 ||
181 hw->mac_type == e1000_82547 ||
182 hw->mac_type == e1000_82547_rev_2) {
183 hw->phy_type = e1000_phy_igp;
186 case IGP03E1000_E_PHY_ID:
187 hw->phy_type = e1000_phy_igp_3;
190 case IFE_PLUS_E_PHY_ID:
192 hw->phy_type = e1000_phy_ife;
194 case GG82563_E_PHY_ID:
195 if (hw->mac_type == e1000_80003es2lan) {
196 hw->phy_type = e1000_phy_gg82563;
201 /* Should never have loaded on this device */
202 hw->phy_type = e1000_phy_undefined;
203 return -E1000_ERR_PHY_TYPE;
206 return E1000_SUCCESS;
209 /******************************************************************************
210 * IGP phy init script - initializes the GbE PHY
212 * hw - Struct containing variables accessed by shared code
213 *****************************************************************************/
215 e1000_phy_init_script(struct e1000_hw *hw)
218 uint16_t phy_saved_data;
220 DEBUGFUNC("e1000_phy_init_script");
222 if (hw->phy_init_script) {
225 /* Save off the current value of register 0x2F5B to be restored at
226 * the end of this routine. */
227 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
229 /* Disabled the PHY transmitter */
230 e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
234 e1000_write_phy_reg(hw,0x0000,0x0140);
238 switch (hw->mac_type) {
241 e1000_write_phy_reg(hw, 0x1F95, 0x0001);
243 e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
245 e1000_write_phy_reg(hw, 0x1F79, 0x0018);
247 e1000_write_phy_reg(hw, 0x1F30, 0x1600);
249 e1000_write_phy_reg(hw, 0x1F31, 0x0014);
251 e1000_write_phy_reg(hw, 0x1F32, 0x161C);
253 e1000_write_phy_reg(hw, 0x1F94, 0x0003);
255 e1000_write_phy_reg(hw, 0x1F96, 0x003F);
257 e1000_write_phy_reg(hw, 0x2010, 0x0008);
260 case e1000_82541_rev_2:
261 case e1000_82547_rev_2:
262 e1000_write_phy_reg(hw, 0x1F73, 0x0099);
268 e1000_write_phy_reg(hw, 0x0000, 0x3300);
272 /* Now enable the transmitter */
273 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
275 if (hw->mac_type == e1000_82547) {
276 uint16_t fused, fine, coarse;
278 /* Move to analog registers page */
279 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_SPARE_FUSE_STATUS, &fused);
281 if (!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
282 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_FUSE_STATUS, &fused);
284 fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
285 coarse = fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
287 if (coarse > IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
288 coarse -= IGP01E1000_ANALOG_FUSE_COARSE_10;
289 fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
290 } else if (coarse == IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
291 fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
293 fused = (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
294 (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
295 (coarse & IGP01E1000_ANALOG_FUSE_COARSE_MASK);
297 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_CONTROL, fused);
298 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_BYPASS,
299 IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
305 /******************************************************************************
306 * Set the mac type member in the hw struct.
308 * hw - Struct containing variables accessed by shared code
309 *****************************************************************************/
311 e1000_set_mac_type(struct e1000_hw *hw)
313 DEBUGFUNC("e1000_set_mac_type");
315 switch (hw->device_id) {
316 case E1000_DEV_ID_82542:
317 switch (hw->revision_id) {
318 case E1000_82542_2_0_REV_ID:
319 hw->mac_type = e1000_82542_rev2_0;
321 case E1000_82542_2_1_REV_ID:
322 hw->mac_type = e1000_82542_rev2_1;
325 /* Invalid 82542 revision ID */
326 return -E1000_ERR_MAC_TYPE;
329 case E1000_DEV_ID_82543GC_FIBER:
330 case E1000_DEV_ID_82543GC_COPPER:
331 hw->mac_type = e1000_82543;
333 case E1000_DEV_ID_82544EI_COPPER:
334 case E1000_DEV_ID_82544EI_FIBER:
335 case E1000_DEV_ID_82544GC_COPPER:
336 case E1000_DEV_ID_82544GC_LOM:
337 hw->mac_type = e1000_82544;
339 case E1000_DEV_ID_82540EM:
340 case E1000_DEV_ID_82540EM_LOM:
341 case E1000_DEV_ID_82540EP:
342 case E1000_DEV_ID_82540EP_LOM:
343 case E1000_DEV_ID_82540EP_LP:
344 hw->mac_type = e1000_82540;
346 case E1000_DEV_ID_82545EM_COPPER:
347 case E1000_DEV_ID_82545EM_FIBER:
348 hw->mac_type = e1000_82545;
350 case E1000_DEV_ID_82545GM_COPPER:
351 case E1000_DEV_ID_82545GM_FIBER:
352 case E1000_DEV_ID_82545GM_SERDES:
353 hw->mac_type = e1000_82545_rev_3;
355 case E1000_DEV_ID_82546EB_COPPER:
356 case E1000_DEV_ID_82546EB_FIBER:
357 case E1000_DEV_ID_82546EB_QUAD_COPPER:
358 hw->mac_type = e1000_82546;
360 case E1000_DEV_ID_82546GB_COPPER:
361 case E1000_DEV_ID_82546GB_FIBER:
362 case E1000_DEV_ID_82546GB_SERDES:
363 case E1000_DEV_ID_82546GB_PCIE:
364 case E1000_DEV_ID_82546GB_QUAD_COPPER:
365 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
366 hw->mac_type = e1000_82546_rev_3;
368 case E1000_DEV_ID_82541EI:
369 case E1000_DEV_ID_82541EI_MOBILE:
370 case E1000_DEV_ID_82541ER_LOM:
371 hw->mac_type = e1000_82541;
373 case E1000_DEV_ID_82541ER:
374 case E1000_DEV_ID_82541GI:
375 case E1000_DEV_ID_82541GI_LF:
376 case E1000_DEV_ID_82541GI_MOBILE:
377 hw->mac_type = e1000_82541_rev_2;
379 case E1000_DEV_ID_82547EI:
380 case E1000_DEV_ID_82547EI_MOBILE:
381 hw->mac_type = e1000_82547;
383 case E1000_DEV_ID_82547GI:
384 hw->mac_type = e1000_82547_rev_2;
386 case E1000_DEV_ID_82571EB_COPPER:
387 case E1000_DEV_ID_82571EB_FIBER:
388 case E1000_DEV_ID_82571EB_SERDES:
389 case E1000_DEV_ID_82571EB_SERDES_DUAL:
390 case E1000_DEV_ID_82571EB_SERDES_QUAD:
391 case E1000_DEV_ID_82571EB_QUAD_COPPER:
392 case E1000_DEV_ID_82571EB_QUAD_FIBER:
393 case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE:
394 hw->mac_type = e1000_82571;
396 case E1000_DEV_ID_82572EI_COPPER:
397 case E1000_DEV_ID_82572EI_FIBER:
398 case E1000_DEV_ID_82572EI_SERDES:
399 case E1000_DEV_ID_82572EI:
400 hw->mac_type = e1000_82572;
402 case E1000_DEV_ID_82573E:
403 case E1000_DEV_ID_82573E_IAMT:
404 case E1000_DEV_ID_82573L:
405 hw->mac_type = e1000_82573;
407 case E1000_DEV_ID_80003ES2LAN_COPPER_SPT:
408 case E1000_DEV_ID_80003ES2LAN_SERDES_SPT:
409 case E1000_DEV_ID_80003ES2LAN_COPPER_DPT:
410 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
411 hw->mac_type = e1000_80003es2lan;
413 case E1000_DEV_ID_ICH8_IGP_M_AMT:
414 case E1000_DEV_ID_ICH8_IGP_AMT:
415 case E1000_DEV_ID_ICH8_IGP_C:
416 case E1000_DEV_ID_ICH8_IFE:
417 case E1000_DEV_ID_ICH8_IFE_GT:
418 case E1000_DEV_ID_ICH8_IFE_G:
419 case E1000_DEV_ID_ICH8_IGP_M:
420 hw->mac_type = e1000_ich8lan;
422 case E1000_DEV_ID_82576:
423 hw->mac_type = e1000_82576;
426 /* Should never have loaded on this device */
427 return -E1000_ERR_MAC_TYPE;
430 switch (hw->mac_type) {
433 hw->swfwhw_semaphore_present = TRUE;
434 hw->asf_firmware_present = TRUE;
436 case e1000_80003es2lan:
437 hw->swfw_sync_present = TRUE;
442 hw->eeprom_semaphore_present = TRUE;
446 case e1000_82541_rev_2:
447 case e1000_82547_rev_2:
448 hw->asf_firmware_present = TRUE;
454 /* The 82543 chip does not count tx_carrier_errors properly in
457 if (hw->mac_type == e1000_82543)
458 hw->bad_tx_carr_stats_fd = TRUE;
460 /* capable of receiving management packets to the host */
461 if (hw->mac_type >= e1000_82571)
462 hw->has_manc2h = TRUE;
464 /* In rare occasions, ESB2 systems would end up started without
465 * the RX unit being turned on.
467 if (hw->mac_type == e1000_80003es2lan)
468 hw->rx_needs_kicking = TRUE;
470 if (hw->mac_type > e1000_82544)
471 hw->has_smbus = TRUE;
473 return E1000_SUCCESS;
476 /*****************************************************************************
477 * Set media type and TBI compatibility.
479 * hw - Struct containing variables accessed by shared code
480 * **************************************************************************/
482 e1000_set_media_type(struct e1000_hw *hw)
486 DEBUGFUNC("e1000_set_media_type");
488 if (hw->mac_type != e1000_82543) {
489 /* tbi_compatibility is only valid on 82543 */
490 hw->tbi_compatibility_en = FALSE;
493 switch (hw->device_id) {
494 case E1000_DEV_ID_82545GM_SERDES:
495 case E1000_DEV_ID_82546GB_SERDES:
496 case E1000_DEV_ID_82571EB_SERDES:
497 case E1000_DEV_ID_82571EB_SERDES_DUAL:
498 case E1000_DEV_ID_82571EB_SERDES_QUAD:
499 case E1000_DEV_ID_82572EI_SERDES:
500 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
501 hw->media_type = e1000_media_type_internal_serdes;
504 switch (hw->mac_type) {
505 case e1000_82542_rev2_0:
506 case e1000_82542_rev2_1:
507 hw->media_type = e1000_media_type_fiber;
512 /* The STATUS_TBIMODE bit is reserved or reused for the this
515 hw->media_type = e1000_media_type_copper;
518 status = E1000_READ_REG(hw, STATUS);
519 if (status & E1000_STATUS_TBIMODE) {
520 hw->media_type = e1000_media_type_fiber;
521 /* tbi_compatibility not valid on fiber */
522 hw->tbi_compatibility_en = FALSE;
524 hw->media_type = e1000_media_type_copper;
531 /******************************************************************************
532 * Reset the transmit and receive units; mask and clear all interrupts.
534 * hw - Struct containing variables accessed by shared code
535 *****************************************************************************/
537 e1000_reset_hw(struct e1000_hw *hw)
545 uint32_t extcnf_ctrl;
548 DEBUGFUNC("e1000_reset_hw");
550 /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
551 if (hw->mac_type == e1000_82542_rev2_0) {
552 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
553 e1000_pci_clear_mwi(hw);
556 if (hw->bus_type == e1000_bus_type_pci_express) {
557 /* Prevent the PCI-E bus from sticking if there is no TLP connection
558 * on the last TLP read/write transaction when MAC is reset.
560 if (e1000_disable_pciex_master(hw) != E1000_SUCCESS) {
561 DEBUGOUT("PCI-E Master disable polling has failed.\n");
565 /* Clear interrupt mask to stop board from generating interrupts */
566 DEBUGOUT("Masking off all interrupts\n");
567 E1000_WRITE_REG(hw, IMC, 0xffffffff);
569 /* Disable the Transmit and Receive units. Then delay to allow
570 * any pending transactions to complete before we hit the MAC with
573 E1000_WRITE_REG(hw, RCTL, 0);
574 E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP);
575 E1000_WRITE_FLUSH(hw);
577 /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
578 hw->tbi_compatibility_on = FALSE;
580 /* Delay to allow any outstanding PCI transactions to complete before
581 * resetting the device
585 ctrl = E1000_READ_REG(hw, CTRL);
587 /* Must reset the PHY before resetting the MAC */
588 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
589 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_PHY_RST));
593 /* Must acquire the MDIO ownership before MAC reset.
594 * Ownership defaults to firmware after a reset. */
595 if (hw->mac_type == e1000_82573) {
598 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
599 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
602 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
603 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
605 if (extcnf_ctrl & E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP)
608 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
615 /* Workaround for ICH8 bit corruption issue in FIFO memory */
616 if (hw->mac_type == e1000_ich8lan) {
617 /* Set Tx and Rx buffer allocation to 8k apiece. */
618 E1000_WRITE_REG(hw, PBA, E1000_PBA_8K);
619 /* Set Packet Buffer Size to 16k. */
620 E1000_WRITE_REG(hw, PBS, E1000_PBS_16K);
623 /* Issue a global reset to the MAC. This will reset the chip's
624 * transmit, receive, DMA, and link units. It will not effect
625 * the current PCI configuration. The global reset bit is self-
626 * clearing, and should clear within a microsecond.
628 DEBUGOUT("Issuing a global reset to MAC\n");
630 switch (hw->mac_type) {
636 case e1000_82541_rev_2:
637 /* These controllers can't ack the 64-bit write when issuing the
638 * reset, so use IO-mapping as a workaround to issue the reset */
639 E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
641 case e1000_82545_rev_3:
642 case e1000_82546_rev_3:
643 /* Reset is performed on a shadow of the control register */
644 E1000_WRITE_REG(hw, CTRL_DUP, (ctrl | E1000_CTRL_RST));
647 if (!hw->phy_reset_disable &&
648 e1000_check_phy_reset_block(hw) == E1000_SUCCESS) {
649 /* e1000_ich8lan PHY HW reset requires MAC CORE reset
650 * at the same time to make sure the interface between
651 * MAC and the external PHY is reset.
653 ctrl |= E1000_CTRL_PHY_RST;
656 e1000_get_software_flag(hw);
657 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
661 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
665 /* After MAC reset, force reload of EEPROM to restore power-on settings to
666 * device. Later controllers reload the EEPROM automatically, so just wait
667 * for reload to complete.
669 switch (hw->mac_type) {
670 case e1000_82542_rev2_0:
671 case e1000_82542_rev2_1:
674 /* Wait for reset to complete */
676 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
677 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
678 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
679 E1000_WRITE_FLUSH(hw);
680 /* Wait for EEPROM reload */
684 case e1000_82541_rev_2:
686 case e1000_82547_rev_2:
687 /* Wait for EEPROM reload */
691 if (e1000_is_onboard_nvm_eeprom(hw) == FALSE) {
693 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
694 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
695 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
696 E1000_WRITE_FLUSH(hw);
700 /* Auto read done will delay 5ms or poll based on mac type */
701 ret_val = e1000_get_auto_rd_done(hw);
707 /* Disable HW ARPs on ASF enabled adapters */
708 if (hw->mac_type >= e1000_82540 && hw->mac_type <= e1000_82547_rev_2) {
709 manc = E1000_READ_REG(hw, MANC);
710 manc &= ~(E1000_MANC_ARP_EN);
711 E1000_WRITE_REG(hw, MANC, manc);
714 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
715 e1000_phy_init_script(hw);
717 /* Configure activity LED after PHY reset */
718 led_ctrl = E1000_READ_REG(hw, LEDCTL);
719 led_ctrl &= IGP_ACTIVITY_LED_MASK;
720 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
721 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
724 /* Clear interrupt mask to stop board from generating interrupts */
725 DEBUGOUT("Masking off all interrupts\n");
726 E1000_WRITE_REG(hw, IMC, 0xffffffff);
728 /* Clear any pending interrupt events. */
729 icr = E1000_READ_REG(hw, ICR);
731 /* If MWI was previously enabled, reenable it. */
732 if (hw->mac_type == e1000_82542_rev2_0) {
733 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
734 e1000_pci_set_mwi(hw);
737 if (hw->mac_type == e1000_ich8lan) {
738 uint32_t kab = E1000_READ_REG(hw, KABGTXD);
739 kab |= E1000_KABGTXD_BGSQLBIAS;
740 E1000_WRITE_REG(hw, KABGTXD, kab);
743 return E1000_SUCCESS;
746 /******************************************************************************
748 * Initialize a number of hardware-dependent bits
750 * hw: Struct containing variables accessed by shared code
752 * This function contains hardware limitation workarounds for PCI-E adapters
754 *****************************************************************************/
756 e1000_initialize_hardware_bits(struct e1000_hw *hw)
758 if ((hw->mac_type >= e1000_82571 && hw->mac_type < e1000_82576) &&
759 (!hw->initialize_hw_bits_disable)) {
760 /* Settings common to all PCI-express silicon */
761 uint32_t reg_ctrl, reg_ctrl_ext;
762 uint32_t reg_tarc0, reg_tarc1;
764 uint32_t reg_txdctl, reg_txdctl1;
766 /* link autonegotiation/sync workarounds */
767 reg_tarc0 = E1000_READ_REG(hw, TARC0);
768 reg_tarc0 &= ~((1 << 30)|(1 << 29)|(1 << 28)|(1 << 27));
770 /* Enable not-done TX descriptor counting */
771 reg_txdctl = E1000_READ_REG(hw, TXDCTL);
772 reg_txdctl |= E1000_TXDCTL_COUNT_DESC;
773 E1000_WRITE_REG(hw, TXDCTL, reg_txdctl);
774 reg_txdctl1 = E1000_READ_REG(hw, TXDCTL1);
775 reg_txdctl1 |= E1000_TXDCTL_COUNT_DESC;
776 E1000_WRITE_REG(hw, TXDCTL1, reg_txdctl1);
778 switch (hw->mac_type) {
781 /* Clear PHY TX compatible mode bits */
782 reg_tarc1 = E1000_READ_REG(hw, TARC1);
783 reg_tarc1 &= ~((1 << 30)|(1 << 29));
785 /* link autonegotiation/sync workarounds */
786 reg_tarc0 |= ((1 << 26)|(1 << 25)|(1 << 24)|(1 << 23));
788 /* TX ring control fixes */
789 reg_tarc1 |= ((1 << 26)|(1 << 25)|(1 << 24));
791 /* Multiple read bit is reversed polarity */
792 reg_tctl = E1000_READ_REG(hw, TCTL);
793 if (reg_tctl & E1000_TCTL_MULR)
794 reg_tarc1 &= ~(1 << 28);
796 reg_tarc1 |= (1 << 28);
798 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
801 reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
802 reg_ctrl_ext &= ~(1 << 23);
803 reg_ctrl_ext |= (1 << 22);
805 /* TX byte count fix */
806 reg_ctrl = E1000_READ_REG(hw, CTRL);
807 reg_ctrl &= ~(1 << 29);
809 E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext);
810 E1000_WRITE_REG(hw, CTRL, reg_ctrl);
812 case e1000_80003es2lan:
813 /* improve small packet performace for fiber/serdes */
814 if ((hw->media_type == e1000_media_type_fiber) ||
815 (hw->media_type == e1000_media_type_internal_serdes)) {
816 reg_tarc0 &= ~(1 << 20);
819 /* Multiple read bit is reversed polarity */
820 reg_tctl = E1000_READ_REG(hw, TCTL);
821 reg_tarc1 = E1000_READ_REG(hw, TARC1);
822 if (reg_tctl & E1000_TCTL_MULR)
823 reg_tarc1 &= ~(1 << 28);
825 reg_tarc1 |= (1 << 28);
827 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
830 /* Reduce concurrent DMA requests to 3 from 4 */
831 if ((hw->revision_id < 3) ||
832 ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) &&
833 (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))
834 reg_tarc0 |= ((1 << 29)|(1 << 28));
836 reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
837 reg_ctrl_ext |= (1 << 22);
838 E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext);
840 /* workaround TX hang with TSO=on */
841 reg_tarc0 |= ((1 << 27)|(1 << 26)|(1 << 24)|(1 << 23));
843 /* Multiple read bit is reversed polarity */
844 reg_tctl = E1000_READ_REG(hw, TCTL);
845 reg_tarc1 = E1000_READ_REG(hw, TARC1);
846 if (reg_tctl & E1000_TCTL_MULR)
847 reg_tarc1 &= ~(1 << 28);
849 reg_tarc1 |= (1 << 28);
851 /* workaround TX hang with TSO=on */
852 reg_tarc1 |= ((1 << 30)|(1 << 26)|(1 << 24));
854 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
860 E1000_WRITE_REG(hw, TARC0, reg_tarc0);
864 /******************************************************************************
865 * Performs basic configuration of the adapter.
867 * hw - Struct containing variables accessed by shared code
869 * Assumes that the controller has previously been reset and is in a
870 * post-reset uninitialized state. Initializes the receive address registers,
871 * multicast table, and VLAN filter table. Calls routines to setup link
872 * configuration and flow control settings. Clears all on-chip counters. Leaves
873 * the transmit and receive units disabled and uninitialized.
874 *****************************************************************************/
876 e1000_init_hw(struct e1000_hw *hw)
881 uint16_t pcix_cmd_word;
882 uint16_t pcix_stat_hi_word;
889 DEBUGFUNC("e1000_init_hw");
891 /* force full DMA clock frequency for 10/100 on ICH8 A0-B0 */
892 if ((hw->mac_type == e1000_ich8lan) &&
893 ((hw->revision_id < 3) ||
894 ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) &&
895 (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))) {
896 reg_data = E1000_READ_REG(hw, STATUS);
897 reg_data &= ~0x80000000;
898 E1000_WRITE_REG(hw, STATUS, reg_data);
901 /* Initialize Identification LED */
902 ret_val = e1000_id_led_init(hw);
904 DEBUGOUT("Error Initializing Identification LED\n");
908 /* Set the media type and TBI compatibility */
909 e1000_set_media_type(hw);
911 /* Must be called after e1000_set_media_type because media_type is used */
912 e1000_initialize_hardware_bits(hw);
914 /* Disabling VLAN filtering. */
915 DEBUGOUT("Initializing the IEEE VLAN\n");
916 switch (hw->mac_type) {
918 /* VET hardcoded to standard value and VFTA removed in ICH8 LAN */
921 /* There is no need to clear vfta on 82576 if VLANs are not used.
922 * - Intel® 82576 Gigabit Ethernet Controller Datasheet r2.41
923 * Section 8.10.19 Table Array - VFTA
925 * Setting VET may also be unnecessary, however the documentation
926 * isn't specific on this point. The value used here is as advised in
927 * - Intel® 82576 Gigabit Ethernet Controller Datasheet r2.41
928 * Section 8.2.7 VLAN Ether Type - VET
930 E1000_WRITE_REG(hw, VET, ETHERNET_IEEE_VLAN_TYPE);
933 if (hw->mac_type < e1000_82545_rev_3)
934 E1000_WRITE_REG(hw, VET, 0);
935 e1000_clear_vfta(hw);
939 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
940 if (hw->mac_type == e1000_82542_rev2_0) {
941 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
942 e1000_pci_clear_mwi(hw);
943 E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST);
944 E1000_WRITE_FLUSH(hw);
948 /* Setup the receive address. This involves initializing all of the Receive
949 * Address Registers (RARs 0 - 15).
951 e1000_init_rx_addrs(hw);
953 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
954 if (hw->mac_type == e1000_82542_rev2_0) {
955 E1000_WRITE_REG(hw, RCTL, 0);
956 E1000_WRITE_FLUSH(hw);
958 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
959 e1000_pci_set_mwi(hw);
962 /* Zero out the Multicast HASH table */
963 DEBUGOUT("Zeroing the MTA\n");
964 mta_size = E1000_MC_TBL_SIZE;
965 if (hw->mac_type == e1000_ich8lan)
966 mta_size = E1000_MC_TBL_SIZE_ICH8LAN;
967 for (i = 0; i < mta_size; i++) {
968 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
969 /* use write flush to prevent Memory Write Block (MWB) from
970 * occuring when accessing our register space */
971 E1000_WRITE_FLUSH(hw);
974 /* Set the PCI priority bit correctly in the CTRL register. This
975 * determines if the adapter gives priority to receives, or if it
976 * gives equal priority to transmits and receives. Valid only on
977 * 82542 and 82543 silicon.
979 if (hw->dma_fairness && hw->mac_type <= e1000_82543) {
980 ctrl = E1000_READ_REG(hw, CTRL);
981 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PRIOR);
984 switch (hw->mac_type) {
985 case e1000_82545_rev_3:
986 case e1000_82546_rev_3:
989 /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
990 if (hw->bus_type == e1000_bus_type_pcix) {
991 e1000_read_pci_cfg(hw, PCIX_COMMAND_REGISTER, &pcix_cmd_word);
992 e1000_read_pci_cfg(hw, PCIX_STATUS_REGISTER_HI,
994 cmd_mmrbc = (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >>
995 PCIX_COMMAND_MMRBC_SHIFT;
996 stat_mmrbc = (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
997 PCIX_STATUS_HI_MMRBC_SHIFT;
998 if (stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
999 stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
1000 if (cmd_mmrbc > stat_mmrbc) {
1001 pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK;
1002 pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
1003 e1000_write_pci_cfg(hw, PCIX_COMMAND_REGISTER,
1010 /* More time needed for PHY to initialize */
1011 if (hw->mac_type == e1000_ich8lan)
1014 /* Call a subroutine to configure the link and setup flow control. */
1015 ret_val = e1000_setup_link(hw);
1017 /* Set the transmit descriptor write-back policy */
1018 if (hw->mac_type > e1000_82544) {
1019 ctrl = E1000_READ_REG(hw, TXDCTL);
1020 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
1021 E1000_WRITE_REG(hw, TXDCTL, ctrl);
1024 if (hw->mac_type == e1000_82573) {
1025 e1000_enable_tx_pkt_filtering(hw);
1028 switch (hw->mac_type) {
1031 case e1000_80003es2lan:
1032 /* Enable retransmit on late collisions */
1033 reg_data = E1000_READ_REG(hw, TCTL);
1034 reg_data |= E1000_TCTL_RTLC;
1035 E1000_WRITE_REG(hw, TCTL, reg_data);
1037 /* Configure Gigabit Carry Extend Padding */
1038 reg_data = E1000_READ_REG(hw, TCTL_EXT);
1039 reg_data &= ~E1000_TCTL_EXT_GCEX_MASK;
1040 reg_data |= DEFAULT_80003ES2LAN_TCTL_EXT_GCEX;
1041 E1000_WRITE_REG(hw, TCTL_EXT, reg_data);
1043 /* Configure Transmit Inter-Packet Gap */
1044 reg_data = E1000_READ_REG(hw, TIPG);
1045 reg_data &= ~E1000_TIPG_IPGT_MASK;
1046 reg_data |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
1047 E1000_WRITE_REG(hw, TIPG, reg_data);
1049 reg_data = E1000_READ_REG_ARRAY(hw, FFLT, 0x0001);
1050 reg_data &= ~0x00100000;
1051 E1000_WRITE_REG_ARRAY(hw, FFLT, 0x0001, reg_data);
1056 ctrl = E1000_READ_REG(hw, TXDCTL1);
1057 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
1058 E1000_WRITE_REG(hw, TXDCTL1, ctrl);
1063 if (hw->mac_type == e1000_82573) {
1064 uint32_t gcr = E1000_READ_REG(hw, GCR);
1065 gcr |= E1000_GCR_L1_ACT_WITHOUT_L0S_RX;
1066 E1000_WRITE_REG(hw, GCR, gcr);
1069 /* Clear all of the statistics registers (clear on read). It is
1070 * important that we do this after we have tried to establish link
1071 * because the symbol error count will increment wildly if there
1074 e1000_clear_hw_cntrs(hw);
1076 /* ICH8 No-snoop bits are opposite polarity.
1077 * Set to snoop by default after reset. */
1078 if (hw->mac_type == e1000_ich8lan)
1079 e1000_set_pci_ex_no_snoop(hw, PCI_EX_82566_SNOOP_ALL);
1081 if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER ||
1082 hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) {
1083 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
1084 /* Relaxed ordering must be disabled to avoid a parity
1085 * error crash in a PCI slot. */
1086 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
1087 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1093 /******************************************************************************
1094 * Adjust SERDES output amplitude based on EEPROM setting.
1096 * hw - Struct containing variables accessed by shared code.
1097 *****************************************************************************/
1099 e1000_adjust_serdes_amplitude(struct e1000_hw *hw)
1101 uint16_t eeprom_data;
1104 DEBUGFUNC("e1000_adjust_serdes_amplitude");
1106 if (hw->media_type != e1000_media_type_internal_serdes)
1107 return E1000_SUCCESS;
1109 switch (hw->mac_type) {
1110 case e1000_82545_rev_3:
1111 case e1000_82546_rev_3:
1114 return E1000_SUCCESS;
1117 ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1, &eeprom_data);
1122 if (eeprom_data != EEPROM_RESERVED_WORD) {
1123 /* Adjust SERDES output amplitude only. */
1124 eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK;
1125 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data);
1130 return E1000_SUCCESS;
1133 /******************************************************************************
1134 * Configures flow control and link settings.
1136 * hw - Struct containing variables accessed by shared code
1138 * Determines which flow control settings to use. Calls the apropriate media-
1139 * specific link configuration function. Configures the flow control settings.
1140 * Assuming the adapter has a valid link partner, a valid link should be
1141 * established. Assumes the hardware has previously been reset and the
1142 * transmitter and receiver are not enabled.
1143 *****************************************************************************/
1145 e1000_setup_link(struct e1000_hw *hw)
1149 uint16_t eeprom_data;
1151 DEBUGFUNC("e1000_setup_link");
1153 /* In the case of the phy reset being blocked, we already have a link.
1154 * We do not have to set it up again. */
1155 if (e1000_check_phy_reset_block(hw))
1156 return E1000_SUCCESS;
1158 /* Read and store word 0x0F of the EEPROM. This word contains bits
1159 * that determine the hardware's default PAUSE (flow control) mode,
1160 * a bit that determines whether the HW defaults to enabling or
1161 * disabling auto-negotiation, and the direction of the
1162 * SW defined pins. If there is no SW over-ride of the flow
1163 * control setting, then the variable hw->fc will
1164 * be initialized based on a value in the EEPROM.
1166 if (hw->fc == E1000_FC_DEFAULT) {
1167 switch (hw->mac_type) {
1170 hw->fc = E1000_FC_FULL;
1173 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
1176 DEBUGOUT("EEPROM Read Error\n");
1177 return -E1000_ERR_EEPROM;
1179 if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
1180 hw->fc = E1000_FC_NONE;
1181 else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
1182 EEPROM_WORD0F_ASM_DIR)
1183 hw->fc = E1000_FC_TX_PAUSE;
1185 hw->fc = E1000_FC_FULL;
1190 /* We want to save off the original Flow Control configuration just
1191 * in case we get disconnected and then reconnected into a different
1192 * hub or switch with different Flow Control capabilities.
1194 if (hw->mac_type == e1000_82542_rev2_0)
1195 hw->fc &= (~E1000_FC_TX_PAUSE);
1197 if ((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
1198 hw->fc &= (~E1000_FC_RX_PAUSE);
1200 hw->original_fc = hw->fc;
1202 DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc);
1204 /* Take the 4 bits from EEPROM word 0x0F that determine the initial
1205 * polarity value for the SW controlled pins, and setup the
1206 * Extended Device Control reg with that info.
1207 * This is needed because one of the SW controlled pins is used for
1208 * signal detection. So this should be done before e1000_setup_pcs_link()
1209 * or e1000_phy_setup() is called.
1211 if (hw->mac_type == e1000_82543) {
1212 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
1215 DEBUGOUT("EEPROM Read Error\n");
1216 return -E1000_ERR_EEPROM;
1218 ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
1220 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1223 /* Call the necessary subroutine to configure the link. */
1224 ret_val = (hw->media_type == e1000_media_type_copper) ?
1225 e1000_setup_copper_link(hw) :
1226 e1000_setup_fiber_serdes_link(hw);
1228 /* Initialize the flow control address, type, and PAUSE timer
1229 * registers to their default values. This is done even if flow
1230 * control is disabled, because it does not hurt anything to
1231 * initialize these registers.
1233 DEBUGOUT("Initializing the Flow Control address, type and timer regs\n");
1235 /* FCAL/H and FCT are hardcoded to standard values in e1000_ich8lan. */
1236 if (hw->mac_type != e1000_ich8lan) {
1237 E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
1238 E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
1239 E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
1242 E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
1244 /* Set the flow control receive threshold registers. Normally,
1245 * these registers will be set to a default threshold that may be
1246 * adjusted later by the driver's runtime code. However, if the
1247 * ability to transmit pause frames in not enabled, then these
1248 * registers will be set to 0.
1250 if (!(hw->fc & E1000_FC_TX_PAUSE)) {
1251 E1000_WRITE_REG(hw, FCRTL, 0);
1252 E1000_WRITE_REG(hw, FCRTH, 0);
1254 /* We need to set up the Receive Threshold high and low water marks
1255 * as well as (optionally) enabling the transmission of XON frames.
1257 if (hw->fc_send_xon) {
1258 E1000_WRITE_REG(hw, FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE));
1259 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
1261 E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water);
1262 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
1268 /******************************************************************************
1269 * Sets up link for a fiber based or serdes based adapter
1271 * hw - Struct containing variables accessed by shared code
1273 * Manipulates Physical Coding Sublayer functions in order to configure
1274 * link. Assumes the hardware has been previously reset and the transmitter
1275 * and receiver are not enabled.
1276 *****************************************************************************/
1278 e1000_setup_fiber_serdes_link(struct e1000_hw *hw)
1284 uint32_t signal = 0;
1287 DEBUGFUNC("e1000_setup_fiber_serdes_link");
1289 /* On 82571 and 82572 Fiber connections, SerDes loopback mode persists
1290 * until explicitly turned off or a power cycle is performed. A read to
1291 * the register does not indicate its status. Therefore, we ensure
1292 * loopback mode is disabled during initialization.
1294 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572)
1295 E1000_WRITE_REG(hw, SCTL, E1000_DISABLE_SERDES_LOOPBACK);
1297 /* On adapters with a MAC newer than 82544, SWDP 1 will be
1298 * set when the optics detect a signal. On older adapters, it will be
1299 * cleared when there is a signal. This applies to fiber media only.
1300 * If we're on serdes media, adjust the output amplitude to value
1301 * set in the EEPROM.
1303 ctrl = E1000_READ_REG(hw, CTRL);
1304 if (hw->media_type == e1000_media_type_fiber)
1305 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
1307 ret_val = e1000_adjust_serdes_amplitude(hw);
1311 /* Take the link out of reset */
1312 ctrl &= ~(E1000_CTRL_LRST);
1314 /* Adjust VCO speed to improve BER performance */
1315 ret_val = e1000_set_vco_speed(hw);
1319 e1000_config_collision_dist(hw);
1321 /* Check for a software override of the flow control settings, and setup
1322 * the device accordingly. If auto-negotiation is enabled, then software
1323 * will have to set the "PAUSE" bits to the correct value in the Tranmsit
1324 * Config Word Register (TXCW) and re-start auto-negotiation. However, if
1325 * auto-negotiation is disabled, then software will have to manually
1326 * configure the two flow control enable bits in the CTRL register.
1328 * The possible values of the "fc" parameter are:
1329 * 0: Flow control is completely disabled
1330 * 1: Rx flow control is enabled (we can receive pause frames, but
1331 * not send pause frames).
1332 * 2: Tx flow control is enabled (we can send pause frames but we do
1333 * not support receiving pause frames).
1334 * 3: Both Rx and TX flow control (symmetric) are enabled.
1338 /* Flow control is completely disabled by a software over-ride. */
1339 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
1341 case E1000_FC_RX_PAUSE:
1342 /* RX Flow control is enabled and TX Flow control is disabled by a
1343 * software over-ride. Since there really isn't a way to advertise
1344 * that we are capable of RX Pause ONLY, we will advertise that we
1345 * support both symmetric and asymmetric RX PAUSE. Later, we will
1346 * disable the adapter's ability to send PAUSE frames.
1348 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1350 case E1000_FC_TX_PAUSE:
1351 /* TX Flow control is enabled, and RX Flow control is disabled, by a
1352 * software over-ride.
1354 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
1357 /* Flow control (both RX and TX) is enabled by a software over-ride. */
1358 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1361 DEBUGOUT("Flow control param set incorrectly\n");
1362 return -E1000_ERR_CONFIG;
1366 /* Since auto-negotiation is enabled, take the link out of reset (the link
1367 * will be in reset, because we previously reset the chip). This will
1368 * restart auto-negotiation. If auto-neogtiation is successful then the
1369 * link-up status bit will be set and the flow control enable bits (RFCE
1370 * and TFCE) will be set according to their negotiated value.
1372 DEBUGOUT("Auto-negotiation enabled\n");
1374 E1000_WRITE_REG(hw, TXCW, txcw);
1375 E1000_WRITE_REG(hw, CTRL, ctrl);
1376 E1000_WRITE_FLUSH(hw);
1381 /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
1382 * indication in the Device Status Register. Time-out if a link isn't
1383 * seen in 500 milliseconds seconds (Auto-negotiation should complete in
1384 * less than 500 milliseconds even if the other end is doing it in SW).
1385 * For internal serdes, we just assume a signal is present, then poll.
1387 if (hw->media_type == e1000_media_type_internal_serdes ||
1388 (E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) {
1389 DEBUGOUT("Looking for Link\n");
1390 for (i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
1392 status = E1000_READ_REG(hw, STATUS);
1393 if (status & E1000_STATUS_LU) break;
1395 if (i == (LINK_UP_TIMEOUT / 10)) {
1396 DEBUGOUT("Never got a valid link from auto-neg!!!\n");
1397 hw->autoneg_failed = 1;
1398 /* AutoNeg failed to achieve a link, so we'll call
1399 * e1000_check_for_link. This routine will force the link up if
1400 * we detect a signal. This will allow us to communicate with
1401 * non-autonegotiating link partners.
1403 ret_val = e1000_check_for_link(hw);
1405 DEBUGOUT("Error while checking for link\n");
1408 hw->autoneg_failed = 0;
1410 hw->autoneg_failed = 0;
1411 DEBUGOUT("Valid Link Found\n");
1414 DEBUGOUT("No Signal Detected\n");
1416 return E1000_SUCCESS;
1419 /******************************************************************************
1420 * Make sure we have a valid PHY and change PHY mode before link setup.
1422 * hw - Struct containing variables accessed by shared code
1423 ******************************************************************************/
1425 e1000_copper_link_preconfig(struct e1000_hw *hw)
1431 DEBUGFUNC("e1000_copper_link_preconfig");
1433 ctrl = E1000_READ_REG(hw, CTRL);
1434 /* With 82543, we need to force speed and duplex on the MAC equal to what
1435 * the PHY speed and duplex configuration is. In addition, we need to
1436 * perform a hardware reset on the PHY to take it out of reset.
1438 if (hw->mac_type > e1000_82543) {
1439 ctrl |= E1000_CTRL_SLU;
1440 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1441 E1000_WRITE_REG(hw, CTRL, ctrl);
1443 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
1444 E1000_WRITE_REG(hw, CTRL, ctrl);
1445 ret_val = e1000_phy_hw_reset(hw);
1450 /* Make sure we have a valid PHY */
1451 ret_val = e1000_detect_gig_phy(hw);
1453 DEBUGOUT("Error, did not detect valid phy.\n");
1456 DEBUGOUT1("Phy ID = %#08x \n", hw->phy_id);
1458 /* Set PHY to class A mode (if necessary) */
1459 ret_val = e1000_set_phy_mode(hw);
1463 if ((hw->mac_type == e1000_82545_rev_3) ||
1464 (hw->mac_type == e1000_82546_rev_3)) {
1465 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1466 phy_data |= 0x00000008;
1467 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1470 if (hw->mac_type <= e1000_82543 ||
1471 hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
1472 hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2)
1473 hw->phy_reset_disable = FALSE;
1475 return E1000_SUCCESS;
1479 /********************************************************************
1480 * Copper link setup for e1000_phy_igp series.
1482 * hw - Struct containing variables accessed by shared code
1483 *********************************************************************/
1485 e1000_copper_link_igp_setup(struct e1000_hw *hw)
1491 DEBUGFUNC("e1000_copper_link_igp_setup");
1493 if (hw->phy_reset_disable)
1494 return E1000_SUCCESS;
1496 ret_val = e1000_phy_reset(hw);
1498 DEBUGOUT("Error Resetting the PHY\n");
1503 * Wait 100ms for MAC to configure PHY from NVM settings, to avoid
1504 * timeout issues when LFS is enabled.
1508 if (hw->mac_type != e1000_ich8lan && hw->mac_type != e1000_82576) {
1509 /* Configure activity LED after PHY reset */
1510 led_ctrl = E1000_READ_REG(hw, LEDCTL);
1511 led_ctrl &= IGP_ACTIVITY_LED_MASK;
1512 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
1513 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
1516 /* The NVM settings will configure LPLU in D3 for IGP2 and IGP3 PHYs */
1517 if (hw->phy_type == e1000_phy_igp) {
1518 /* disable lplu d3 during driver init */
1519 ret_val = e1000_set_d3_lplu_state(hw, FALSE);
1521 DEBUGOUT("Error Disabling LPLU D3\n");
1526 /* disable lplu d0 during driver init */
1527 ret_val = e1000_set_d0_lplu_state(hw, FALSE);
1529 DEBUGOUT("Error Disabling LPLU D0\n");
1532 /* Configure mdi-mdix settings */
1533 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1537 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
1538 hw->dsp_config_state = e1000_dsp_config_disabled;
1539 /* Force MDI for earlier revs of the IGP PHY */
1540 phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX | IGP01E1000_PSCR_FORCE_MDI_MDIX);
1544 hw->dsp_config_state = e1000_dsp_config_enabled;
1545 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1549 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1552 phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
1556 phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
1560 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1564 /* set auto-master slave resolution settings */
1566 e1000_ms_type phy_ms_setting = hw->master_slave;
1568 if (hw->ffe_config_state == e1000_ffe_config_active)
1569 hw->ffe_config_state = e1000_ffe_config_enabled;
1571 if (hw->dsp_config_state == e1000_dsp_config_activated)
1572 hw->dsp_config_state = e1000_dsp_config_enabled;
1574 /* when autonegotiation advertisment is only 1000Mbps then we
1575 * should disable SmartSpeed and enable Auto MasterSlave
1576 * resolution as hardware default. */
1577 if (hw->autoneg_advertised == ADVERTISE_1000_FULL) {
1578 /* Disable SmartSpeed */
1579 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1583 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1584 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1588 /* Set auto Master/Slave resolution process */
1589 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1592 phy_data &= ~CR_1000T_MS_ENABLE;
1593 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1598 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1602 /* load defaults for future use */
1603 hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
1604 ((phy_data & CR_1000T_MS_VALUE) ?
1605 e1000_ms_force_master :
1606 e1000_ms_force_slave) :
1609 switch (phy_ms_setting) {
1610 case e1000_ms_force_master:
1611 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
1613 case e1000_ms_force_slave:
1614 phy_data |= CR_1000T_MS_ENABLE;
1615 phy_data &= ~(CR_1000T_MS_VALUE);
1618 phy_data &= ~CR_1000T_MS_ENABLE;
1622 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1627 return E1000_SUCCESS;
1630 /********************************************************************
1631 * Copper link setup for e1000_phy_gg82563 series.
1633 * hw - Struct containing variables accessed by shared code
1634 *********************************************************************/
1636 e1000_copper_link_ggp_setup(struct e1000_hw *hw)
1642 DEBUGFUNC("e1000_copper_link_ggp_setup");
1644 if (!hw->phy_reset_disable) {
1646 /* Enable CRS on TX for half-duplex operation. */
1647 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL,
1652 phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
1653 /* Use 25MHz for both link down and 1000BASE-T for Tx clock */
1654 phy_data |= GG82563_MSCR_TX_CLK_1000MBPS_25MHZ;
1656 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL,
1662 * MDI/MDI-X = 0 (default)
1663 * 0 - Auto for all speeds
1666 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1668 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_SPEC_CTRL, &phy_data);
1672 phy_data &= ~GG82563_PSCR_CROSSOVER_MODE_MASK;
1676 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDI;
1679 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDIX;
1683 phy_data |= GG82563_PSCR_CROSSOVER_MODE_AUTO;
1688 * disable_polarity_correction = 0 (default)
1689 * Automatic Correction for Reversed Cable Polarity
1693 phy_data &= ~GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
1694 if (hw->disable_polarity_correction == 1)
1695 phy_data |= GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
1696 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_SPEC_CTRL, phy_data);
1701 /* SW Reset the PHY so all changes take effect */
1702 ret_val = e1000_phy_reset(hw);
1704 DEBUGOUT("Error Resetting the PHY\n");
1707 } /* phy_reset_disable */
1709 if (hw->mac_type == e1000_80003es2lan) {
1710 /* Bypass RX and TX FIFO's */
1711 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_FIFO_CTRL,
1712 E1000_KUMCTRLSTA_FIFO_CTRL_RX_BYPASS |
1713 E1000_KUMCTRLSTA_FIFO_CTRL_TX_BYPASS);
1717 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_SPEC_CTRL_2, &phy_data);
1721 phy_data &= ~GG82563_PSCR2_REVERSE_AUTO_NEG;
1722 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_SPEC_CTRL_2, phy_data);
1727 reg_data = E1000_READ_REG(hw, CTRL_EXT);
1728 reg_data &= ~(E1000_CTRL_EXT_LINK_MODE_MASK);
1729 E1000_WRITE_REG(hw, CTRL_EXT, reg_data);
1731 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_PWR_MGMT_CTRL,
1736 /* Do not init these registers when the HW is in IAMT mode, since the
1737 * firmware will have already initialized them. We only initialize
1738 * them if the HW is not in IAMT mode.
1740 if (e1000_check_mng_mode(hw) == FALSE) {
1741 /* Enable Electrical Idle on the PHY */
1742 phy_data |= GG82563_PMCR_ENABLE_ELECTRICAL_IDLE;
1743 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_PWR_MGMT_CTRL,
1748 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
1753 phy_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
1754 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
1761 /* Workaround: Disable padding in Kumeran interface in the MAC
1762 * and in the PHY to avoid CRC errors.
1764 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_INBAND_CTRL,
1768 phy_data |= GG82563_ICR_DIS_PADDING;
1769 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_INBAND_CTRL,
1775 return E1000_SUCCESS;
1778 /********************************************************************
1779 * Copper link setup for e1000_phy_m88 series.
1781 * hw - Struct containing variables accessed by shared code
1782 *********************************************************************/
1784 e1000_copper_link_mgp_setup(struct e1000_hw *hw)
1789 DEBUGFUNC("e1000_copper_link_mgp_setup");
1791 if (hw->phy_reset_disable)
1792 return E1000_SUCCESS;
1794 /* Enable CRS on TX. This must be set for half-duplex operation. */
1795 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1799 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1802 * MDI/MDI-X = 0 (default)
1803 * 0 - Auto for all speeds
1806 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1808 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1812 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
1815 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
1818 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
1822 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
1827 * disable_polarity_correction = 0 (default)
1828 * Automatic Correction for Reversed Cable Polarity
1832 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
1833 if (hw->disable_polarity_correction == 1)
1834 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
1835 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1839 if (hw->phy_revision < M88E1011_I_REV_4) {
1840 /* Force TX_CLK in the Extended PHY Specific Control Register
1843 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1847 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1849 if ((hw->phy_revision == E1000_REVISION_2) &&
1850 (hw->phy_id == M88E1111_I_PHY_ID)) {
1851 /* Vidalia Phy, set the downshift counter to 5x */
1852 phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK);
1853 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
1854 ret_val = e1000_write_phy_reg(hw,
1855 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1859 /* Configure Master and Slave downshift values */
1860 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
1861 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
1862 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
1863 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
1864 ret_val = e1000_write_phy_reg(hw,
1865 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1871 /* SW Reset the PHY so all changes take effect */
1872 ret_val = e1000_phy_reset(hw);
1874 DEBUGOUT("Error Resetting the PHY\n");
1878 return E1000_SUCCESS;
1881 /********************************************************************
1882 * Setup auto-negotiation and flow control advertisements,
1883 * and then perform auto-negotiation.
1885 * hw - Struct containing variables accessed by shared code
1886 *********************************************************************/
1888 e1000_copper_link_autoneg(struct e1000_hw *hw)
1893 DEBUGFUNC("e1000_copper_link_autoneg");
1895 /* Perform some bounds checking on the hw->autoneg_advertised
1896 * parameter. If this variable is zero, then set it to the default.
1898 hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
1900 /* If autoneg_advertised is zero, we assume it was not defaulted
1901 * by the calling code so we set to advertise full capability.
1903 if (hw->autoneg_advertised == 0)
1904 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
1906 /* IFE phy only supports 10/100 */
1907 if (hw->phy_type == e1000_phy_ife)
1908 hw->autoneg_advertised &= AUTONEG_ADVERTISE_10_100_ALL;
1910 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
1911 ret_val = e1000_phy_setup_autoneg(hw);
1913 DEBUGOUT("Error Setting up Auto-Negotiation\n");
1916 DEBUGOUT("Restarting Auto-Neg\n");
1918 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
1919 * the Auto Neg Restart bit in the PHY control register.
1921 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
1925 phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
1926 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
1930 /* Does the user want to wait for Auto-Neg to complete here, or
1931 * check at a later time (for example, callback routine).
1933 if (hw->wait_autoneg_complete) {
1934 ret_val = e1000_wait_autoneg(hw);
1936 DEBUGOUT("Error while waiting for autoneg to complete\n");
1941 hw->get_link_status = TRUE;
1943 return E1000_SUCCESS;
1946 /******************************************************************************
1947 * Config the MAC and the PHY after link is up.
1948 * 1) Set up the MAC to the current PHY speed/duplex
1949 * if we are on 82543. If we
1950 * are on newer silicon, we only need to configure
1951 * collision distance in the Transmit Control Register.
1952 * 2) Set up flow control on the MAC to that established with
1954 * 3) Config DSP to improve Gigabit link quality for some PHY revisions.
1956 * hw - Struct containing variables accessed by shared code
1957 ******************************************************************************/
1959 e1000_copper_link_postconfig(struct e1000_hw *hw)
1962 DEBUGFUNC("e1000_copper_link_postconfig");
1964 if (hw->mac_type >= e1000_82544) {
1965 e1000_config_collision_dist(hw);
1967 ret_val = e1000_config_mac_to_phy(hw);
1969 DEBUGOUT("Error configuring MAC to PHY settings\n");
1973 ret_val = e1000_config_fc_after_link_up(hw);
1975 DEBUGOUT("Error Configuring Flow Control\n");
1979 /* Config DSP to improve Giga link quality */
1980 if (hw->phy_type == e1000_phy_igp) {
1981 ret_val = e1000_config_dsp_after_link_change(hw, TRUE);
1983 DEBUGOUT("Error Configuring DSP after link up\n");
1988 return E1000_SUCCESS;
1991 /******************************************************************************
1992 * Detects which PHY is present and setup the speed and duplex
1994 * hw - Struct containing variables accessed by shared code
1995 ******************************************************************************/
1997 e1000_setup_copper_link(struct e1000_hw *hw)
2004 DEBUGFUNC("e1000_setup_copper_link");
2006 switch (hw->mac_type) {
2007 case e1000_80003es2lan:
2009 /* Set the mac to wait the maximum time between each
2010 * iteration and increase the max iterations when
2011 * polling the phy; this fixes erroneous timeouts at 10Mbps. */
2012 ret_val = e1000_write_kmrn_reg(hw, GG82563_REG(0x34, 4), 0xFFFF);
2015 ret_val = e1000_read_kmrn_reg(hw, GG82563_REG(0x34, 9), ®_data);
2019 ret_val = e1000_write_kmrn_reg(hw, GG82563_REG(0x34, 9), reg_data);
2026 /* Check if it is a valid PHY and set PHY mode if necessary. */
2027 ret_val = e1000_copper_link_preconfig(hw);
2031 switch (hw->mac_type) {
2032 case e1000_80003es2lan:
2033 /* Kumeran registers are written-only */
2034 reg_data = E1000_KUMCTRLSTA_INB_CTRL_LINK_STATUS_TX_TIMEOUT_DEFAULT;
2035 reg_data |= E1000_KUMCTRLSTA_INB_CTRL_DIS_PADDING;
2036 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_INB_CTRL,
2045 if (hw->phy_type == e1000_phy_igp ||
2046 hw->phy_type == e1000_phy_igp_3 ||
2047 hw->phy_type == e1000_phy_igp_2) {
2048 ret_val = e1000_copper_link_igp_setup(hw);
2051 } else if (hw->phy_type == e1000_phy_m88) {
2052 ret_val = e1000_copper_link_mgp_setup(hw);
2055 } else if (hw->phy_type == e1000_phy_gg82563) {
2056 ret_val = e1000_copper_link_ggp_setup(hw);
2062 /* Setup autoneg and flow control advertisement
2063 * and perform autonegotiation */
2064 ret_val = e1000_copper_link_autoneg(hw);
2068 /* PHY will be set to 10H, 10F, 100H,or 100F
2069 * depending on value from forced_speed_duplex. */
2070 DEBUGOUT("Forcing speed and duplex\n");
2071 ret_val = e1000_phy_force_speed_duplex(hw);
2073 DEBUGOUT("Error Forcing Speed and Duplex\n");
2078 /* Check link status. Wait up to 100 microseconds for link to become
2081 for (i = 0; i < 10; i++) {
2082 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2085 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2089 if (phy_data & MII_SR_LINK_STATUS) {
2090 /* Config the MAC and PHY after link is up */
2091 ret_val = e1000_copper_link_postconfig(hw);
2095 DEBUGOUT("Valid link established!!!\n");
2096 return E1000_SUCCESS;
2101 DEBUGOUT("Unable to establish link!!!\n");
2102 return E1000_SUCCESS;
2105 /******************************************************************************
2106 * Configure the MAC-to-PHY interface for 10/100Mbps
2108 * hw - Struct containing variables accessed by shared code
2109 ******************************************************************************/
2111 e1000_configure_kmrn_for_10_100(struct e1000_hw *hw, uint16_t duplex)
2113 int32_t ret_val = E1000_SUCCESS;
2117 DEBUGFUNC("e1000_configure_kmrn_for_10_100");
2119 reg_data = E1000_KUMCTRLSTA_HD_CTRL_10_100_DEFAULT;
2120 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_HD_CTRL,
2125 /* Configure Transmit Inter-Packet Gap */
2126 tipg = E1000_READ_REG(hw, TIPG);
2127 tipg &= ~E1000_TIPG_IPGT_MASK;
2128 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_10_100;
2129 E1000_WRITE_REG(hw, TIPG, tipg);
2131 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, ®_data);
2136 if (duplex == HALF_DUPLEX)
2137 reg_data |= GG82563_KMCR_PASS_FALSE_CARRIER;
2139 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
2141 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
2147 e1000_configure_kmrn_for_1000(struct e1000_hw *hw)
2149 int32_t ret_val = E1000_SUCCESS;
2153 DEBUGFUNC("e1000_configure_kmrn_for_1000");
2155 reg_data = E1000_KUMCTRLSTA_HD_CTRL_1000_DEFAULT;
2156 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_HD_CTRL,
2161 /* Configure Transmit Inter-Packet Gap */
2162 tipg = E1000_READ_REG(hw, TIPG);
2163 tipg &= ~E1000_TIPG_IPGT_MASK;
2164 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
2165 E1000_WRITE_REG(hw, TIPG, tipg);
2167 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, ®_data);
2172 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
2173 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
2178 /******************************************************************************
2179 * Configures PHY autoneg and flow control advertisement settings
2181 * hw - Struct containing variables accessed by shared code
2182 ******************************************************************************/
2184 e1000_phy_setup_autoneg(struct e1000_hw *hw)
2187 uint16_t mii_autoneg_adv_reg;
2188 uint16_t mii_1000t_ctrl_reg;
2190 DEBUGFUNC("e1000_phy_setup_autoneg");
2192 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
2193 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
2197 if (hw->phy_type != e1000_phy_ife) {
2198 /* Read the MII 1000Base-T Control Register (Address 9). */
2199 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
2203 mii_1000t_ctrl_reg=0;
2205 /* Need to parse both autoneg_advertised and fc and set up
2206 * the appropriate PHY registers. First we will parse for
2207 * autoneg_advertised software override. Since we can advertise
2208 * a plethora of combinations, we need to check each bit
2212 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
2213 * Advertisement Register (Address 4) and the 1000 mb speed bits in
2214 * the 1000Base-T Control Register (Address 9).
2216 mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
2217 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
2219 DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised);
2221 /* Do we want to advertise 10 Mb Half Duplex? */
2222 if (hw->autoneg_advertised & ADVERTISE_10_HALF) {
2223 DEBUGOUT("Advertise 10mb Half duplex\n");
2224 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
2227 /* Do we want to advertise 10 Mb Full Duplex? */
2228 if (hw->autoneg_advertised & ADVERTISE_10_FULL) {
2229 DEBUGOUT("Advertise 10mb Full duplex\n");
2230 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
2233 /* Do we want to advertise 100 Mb Half Duplex? */
2234 if (hw->autoneg_advertised & ADVERTISE_100_HALF) {
2235 DEBUGOUT("Advertise 100mb Half duplex\n");
2236 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
2239 /* Do we want to advertise 100 Mb Full Duplex? */
2240 if (hw->autoneg_advertised & ADVERTISE_100_FULL) {
2241 DEBUGOUT("Advertise 100mb Full duplex\n");
2242 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
2245 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
2246 if (hw->autoneg_advertised & ADVERTISE_1000_HALF) {
2247 DEBUGOUT("Advertise 1000mb Half duplex requested, request denied!\n");
2250 /* Do we want to advertise 1000 Mb Full Duplex? */
2251 if (hw->autoneg_advertised & ADVERTISE_1000_FULL) {
2252 DEBUGOUT("Advertise 1000mb Full duplex\n");
2253 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
2254 if (hw->phy_type == e1000_phy_ife) {
2255 DEBUGOUT("e1000_phy_ife is a 10/100 PHY. Gigabit speed is not supported.\n");
2259 /* Check for a software override of the flow control settings, and
2260 * setup the PHY advertisement registers accordingly. If
2261 * auto-negotiation is enabled, then software will have to set the
2262 * "PAUSE" bits to the correct value in the Auto-Negotiation
2263 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
2265 * The possible values of the "fc" parameter are:
2266 * 0: Flow control is completely disabled
2267 * 1: Rx flow control is enabled (we can receive pause frames
2268 * but not send pause frames).
2269 * 2: Tx flow control is enabled (we can send pause frames
2270 * but we do not support receiving pause frames).
2271 * 3: Both Rx and TX flow control (symmetric) are enabled.
2272 * other: No software override. The flow control configuration
2273 * in the EEPROM is used.
2276 case E1000_FC_NONE: /* 0 */
2277 /* Flow control (RX & TX) is completely disabled by a
2278 * software over-ride.
2280 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2282 case E1000_FC_RX_PAUSE: /* 1 */
2283 /* RX Flow control is enabled, and TX Flow control is
2284 * disabled, by a software over-ride.
2286 /* Since there really isn't a way to advertise that we are
2287 * capable of RX Pause ONLY, we will advertise that we
2288 * support both symmetric and asymmetric RX PAUSE. Later
2289 * (in e1000_config_fc_after_link_up) we will disable the
2290 *hw's ability to send PAUSE frames.
2292 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2294 case E1000_FC_TX_PAUSE: /* 2 */
2295 /* TX Flow control is enabled, and RX Flow control is
2296 * disabled, by a software over-ride.
2298 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
2299 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
2301 case E1000_FC_FULL: /* 3 */
2302 /* Flow control (both RX and TX) is enabled by a software
2305 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2308 DEBUGOUT("Flow control param set incorrectly\n");
2309 return -E1000_ERR_CONFIG;
2312 ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
2316 DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
2318 if (hw->phy_type != e1000_phy_ife) {
2319 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg);
2324 return E1000_SUCCESS;
2327 /******************************************************************************
2328 * Force PHY speed and duplex settings to hw->forced_speed_duplex
2330 * hw - Struct containing variables accessed by shared code
2331 ******************************************************************************/
2333 e1000_phy_force_speed_duplex(struct e1000_hw *hw)
2337 uint16_t mii_ctrl_reg;
2338 uint16_t mii_status_reg;
2342 DEBUGFUNC("e1000_phy_force_speed_duplex");
2344 /* Turn off Flow control if we are forcing speed and duplex. */
2345 hw->fc = E1000_FC_NONE;
2347 DEBUGOUT1("hw->fc = %d\n", hw->fc);
2349 /* Read the Device Control Register. */
2350 ctrl = E1000_READ_REG(hw, CTRL);
2352 /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */
2353 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2354 ctrl &= ~(DEVICE_SPEED_MASK);
2356 /* Clear the Auto Speed Detect Enable bit. */
2357 ctrl &= ~E1000_CTRL_ASDE;
2359 /* Read the MII Control Register. */
2360 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg);
2364 /* We need to disable autoneg in order to force link and duplex. */
2366 mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN;
2368 /* Are we forcing Full or Half Duplex? */
2369 if (hw->forced_speed_duplex == e1000_100_full ||
2370 hw->forced_speed_duplex == e1000_10_full) {
2371 /* We want to force full duplex so we SET the full duplex bits in the
2372 * Device and MII Control Registers.
2374 ctrl |= E1000_CTRL_FD;
2375 mii_ctrl_reg |= MII_CR_FULL_DUPLEX;
2376 DEBUGOUT("Full Duplex\n");
2378 /* We want to force half duplex so we CLEAR the full duplex bits in
2379 * the Device and MII Control Registers.
2381 ctrl &= ~E1000_CTRL_FD;
2382 mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX;
2383 DEBUGOUT("Half Duplex\n");
2386 /* Are we forcing 100Mbps??? */
2387 if (hw->forced_speed_duplex == e1000_100_full ||
2388 hw->forced_speed_duplex == e1000_100_half) {
2389 /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */
2390 ctrl |= E1000_CTRL_SPD_100;
2391 mii_ctrl_reg |= MII_CR_SPEED_100;
2392 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
2393 DEBUGOUT("Forcing 100mb ");
2395 /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */
2396 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
2397 mii_ctrl_reg |= MII_CR_SPEED_10;
2398 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
2399 DEBUGOUT("Forcing 10mb ");
2402 e1000_config_collision_dist(hw);
2404 /* Write the configured values back to the Device Control Reg. */
2405 E1000_WRITE_REG(hw, CTRL, ctrl);
2407 if ((hw->phy_type == e1000_phy_m88) ||
2408 (hw->phy_type == e1000_phy_gg82563)) {
2409 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
2413 /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
2414 * forced whenever speed are duplex are forced.
2416 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
2417 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
2421 DEBUGOUT1("M88E1000 PSCR: %x \n", phy_data);
2423 /* Need to reset the PHY or these changes will be ignored */
2424 mii_ctrl_reg |= MII_CR_RESET;
2426 /* Disable MDI-X support for 10/100 */
2427 } else if (hw->phy_type == e1000_phy_ife) {
2428 ret_val = e1000_read_phy_reg(hw, IFE_PHY_MDIX_CONTROL, &phy_data);
2432 phy_data &= ~IFE_PMC_AUTO_MDIX;
2433 phy_data &= ~IFE_PMC_FORCE_MDIX;
2435 ret_val = e1000_write_phy_reg(hw, IFE_PHY_MDIX_CONTROL, phy_data);
2440 /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
2441 * forced whenever speed or duplex are forced.
2443 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
2447 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
2448 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
2450 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
2455 /* Write back the modified PHY MII control register. */
2456 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg);
2462 /* The wait_autoneg_complete flag may be a little misleading here.
2463 * Since we are forcing speed and duplex, Auto-Neg is not enabled.
2464 * But we do want to delay for a period while forcing only so we
2465 * don't generate false No Link messages. So we will wait here
2466 * only if the user has set wait_autoneg_complete to 1, which is
2469 if (hw->wait_autoneg_complete) {
2470 /* We will wait for autoneg to complete. */
2471 DEBUGOUT("Waiting for forced speed/duplex link.\n");
2474 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
2475 for (i = PHY_FORCE_TIME; i > 0; i--) {
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);
2487 if (mii_status_reg & MII_SR_LINK_STATUS) break;
2491 ((hw->phy_type == e1000_phy_m88) ||
2492 (hw->phy_type == e1000_phy_gg82563))) {
2493 /* We didn't get link. Reset the DSP and wait again for link. */
2494 ret_val = e1000_phy_reset_dsp(hw);
2496 DEBUGOUT("Error Resetting PHY DSP\n");
2500 /* This loop will early-out if the link condition has been met. */
2501 for (i = PHY_FORCE_TIME; i > 0; i--) {
2502 if (mii_status_reg & MII_SR_LINK_STATUS) break;
2504 /* Read the MII Status Register and wait for Auto-Neg Complete bit
2507 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2511 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2517 if (hw->phy_type == e1000_phy_m88) {
2518 /* Because we reset the PHY above, we need to re-force TX_CLK in the
2519 * Extended PHY Specific Control Register to 25MHz clock. This value
2520 * defaults back to a 2.5MHz clock when the PHY is reset.
2522 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
2526 phy_data |= M88E1000_EPSCR_TX_CLK_25;
2527 ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
2531 /* In addition, because of the s/w reset above, we need to enable CRS on
2532 * TX. This must be set for both full and half duplex operation.
2534 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
2538 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
2539 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
2543 if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
2544 (!hw->autoneg) && (hw->forced_speed_duplex == e1000_10_full ||
2545 hw->forced_speed_duplex == e1000_10_half)) {
2546 ret_val = e1000_polarity_reversal_workaround(hw);
2550 } else if (hw->phy_type == e1000_phy_gg82563) {
2551 /* The TX_CLK of the Extended PHY Specific Control Register defaults
2552 * to 2.5MHz on a reset. We need to re-force it back to 25MHz, if
2553 * we're not in a forced 10/duplex configuration. */
2554 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, &phy_data);
2558 phy_data &= ~GG82563_MSCR_TX_CLK_MASK;
2559 if ((hw->forced_speed_duplex == e1000_10_full) ||
2560 (hw->forced_speed_duplex == e1000_10_half))
2561 phy_data |= GG82563_MSCR_TX_CLK_10MBPS_2_5MHZ;
2563 phy_data |= GG82563_MSCR_TX_CLK_100MBPS_25MHZ;
2565 /* Also due to the reset, we need to enable CRS on Tx. */
2566 phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
2568 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, phy_data);
2572 return E1000_SUCCESS;
2575 /******************************************************************************
2576 * Sets the collision distance in the Transmit Control register
2578 * hw - Struct containing variables accessed by shared code
2580 * Link should have been established previously. Reads the speed and duplex
2581 * information from the Device Status register.
2582 ******************************************************************************/
2584 e1000_config_collision_dist(struct e1000_hw *hw)
2586 uint32_t tctl, coll_dist;
2588 DEBUGFUNC("e1000_config_collision_dist");
2590 if (hw->mac_type < e1000_82543)
2591 coll_dist = E1000_COLLISION_DISTANCE_82542;
2593 coll_dist = E1000_COLLISION_DISTANCE;
2595 tctl = E1000_READ_REG(hw, TCTL);
2597 tctl &= ~E1000_TCTL_COLD;
2598 tctl |= coll_dist << E1000_COLD_SHIFT;
2600 E1000_WRITE_REG(hw, TCTL, tctl);
2601 E1000_WRITE_FLUSH(hw);
2604 /******************************************************************************
2605 * Sets MAC speed and duplex settings to reflect the those in the PHY
2607 * hw - Struct containing variables accessed by shared code
2608 * mii_reg - data to write to the MII control register
2610 * The contents of the PHY register containing the needed information need to
2612 ******************************************************************************/
2614 e1000_config_mac_to_phy(struct e1000_hw *hw)
2620 DEBUGFUNC("e1000_config_mac_to_phy");
2622 /* 82544 or newer MAC, Auto Speed Detection takes care of
2623 * MAC speed/duplex configuration.*/
2624 if (hw->mac_type >= e1000_82544)
2625 return E1000_SUCCESS;
2627 /* Read the Device Control Register and set the bits to Force Speed
2630 ctrl = E1000_READ_REG(hw, CTRL);
2631 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2632 ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
2634 /* Set up duplex in the Device Control and Transmit Control
2635 * registers depending on negotiated values.
2637 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
2641 if (phy_data & M88E1000_PSSR_DPLX)
2642 ctrl |= E1000_CTRL_FD;
2644 ctrl &= ~E1000_CTRL_FD;
2646 e1000_config_collision_dist(hw);
2648 /* Set up speed in the Device Control register depending on
2649 * negotiated values.
2651 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
2652 ctrl |= E1000_CTRL_SPD_1000;
2653 else if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
2654 ctrl |= E1000_CTRL_SPD_100;
2656 /* Write the configured values back to the Device Control Reg. */
2657 E1000_WRITE_REG(hw, CTRL, ctrl);
2658 return E1000_SUCCESS;
2661 /******************************************************************************
2662 * Forces the MAC's flow control settings.
2664 * hw - Struct containing variables accessed by shared code
2666 * Sets the TFCE and RFCE bits in the device control register to reflect
2667 * the adapter settings. TFCE and RFCE need to be explicitly set by
2668 * software when a Copper PHY is used because autonegotiation is managed
2669 * by the PHY rather than the MAC. Software must also configure these
2670 * bits when link is forced on a fiber connection.
2671 *****************************************************************************/
2673 e1000_force_mac_fc(struct e1000_hw *hw)
2677 DEBUGFUNC("e1000_force_mac_fc");
2679 /* Get the current configuration of the Device Control Register */
2680 ctrl = E1000_READ_REG(hw, CTRL);
2682 /* Because we didn't get link via the internal auto-negotiation
2683 * mechanism (we either forced link or we got link via PHY
2684 * auto-neg), we have to manually enable/disable transmit an
2685 * receive flow control.
2687 * The "Case" statement below enables/disable flow control
2688 * according to the "hw->fc" parameter.
2690 * The possible values of the "fc" parameter are:
2691 * 0: Flow control is completely disabled
2692 * 1: Rx flow control is enabled (we can receive pause
2693 * frames but not send pause frames).
2694 * 2: Tx flow control is enabled (we can send pause frames
2695 * frames but we do not receive pause frames).
2696 * 3: Both Rx and TX flow control (symmetric) is enabled.
2697 * other: No other values should be possible at this point.
2702 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
2704 case E1000_FC_RX_PAUSE:
2705 ctrl &= (~E1000_CTRL_TFCE);
2706 ctrl |= E1000_CTRL_RFCE;
2708 case E1000_FC_TX_PAUSE:
2709 ctrl &= (~E1000_CTRL_RFCE);
2710 ctrl |= E1000_CTRL_TFCE;
2713 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
2716 DEBUGOUT("Flow control param set incorrectly\n");
2717 return -E1000_ERR_CONFIG;
2720 /* Disable TX Flow Control for 82542 (rev 2.0) */
2721 if (hw->mac_type == e1000_82542_rev2_0)
2722 ctrl &= (~E1000_CTRL_TFCE);
2724 E1000_WRITE_REG(hw, CTRL, ctrl);
2725 return E1000_SUCCESS;
2728 /******************************************************************************
2729 * Configures flow control settings after link is established
2731 * hw - Struct containing variables accessed by shared code
2733 * Should be called immediately after a valid link has been established.
2734 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
2735 * and autonegotiation is enabled, the MAC flow control settings will be set
2736 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
2737 * and RFCE bits will be automaticaly set to the negotiated flow control mode.
2738 *****************************************************************************/
2740 e1000_config_fc_after_link_up(struct e1000_hw *hw)
2743 uint16_t mii_status_reg;
2744 uint16_t mii_nway_adv_reg;
2745 uint16_t mii_nway_lp_ability_reg;
2749 DEBUGFUNC("e1000_config_fc_after_link_up");
2751 /* Check for the case where we have fiber media and auto-neg failed
2752 * so we had to force link. In this case, we need to force the
2753 * configuration of the MAC to match the "fc" parameter.
2755 if (((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) ||
2756 ((hw->media_type == e1000_media_type_internal_serdes) &&
2757 (hw->autoneg_failed)) ||
2758 ((hw->media_type == e1000_media_type_copper) && (!hw->autoneg))) {
2759 ret_val = e1000_force_mac_fc(hw);
2761 DEBUGOUT("Error forcing flow control settings\n");
2766 /* Check for the case where we have copper media and auto-neg is
2767 * enabled. In this case, we need to check and see if Auto-Neg
2768 * has completed, and if so, how the PHY and link partner has
2769 * flow control configured.
2771 if ((hw->media_type == e1000_media_type_copper) && hw->autoneg) {
2772 /* Read the MII Status Register and check to see if AutoNeg
2773 * has completed. We read this twice because this reg has
2774 * some "sticky" (latched) bits.
2776 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2779 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2783 if (mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
2784 /* The AutoNeg process has completed, so we now need to
2785 * read both the Auto Negotiation Advertisement Register
2786 * (Address 4) and the Auto_Negotiation Base Page Ability
2787 * Register (Address 5) to determine how flow control was
2790 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV,
2794 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY,
2795 &mii_nway_lp_ability_reg);
2799 /* Two bits in the Auto Negotiation Advertisement Register
2800 * (Address 4) and two bits in the Auto Negotiation Base
2801 * Page Ability Register (Address 5) determine flow control
2802 * for both the PHY and the link partner. The following
2803 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
2804 * 1999, describes these PAUSE resolution bits and how flow
2805 * control is determined based upon these settings.
2806 * NOTE: DC = Don't Care
2808 * LOCAL DEVICE | LINK PARTNER
2809 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
2810 *-------|---------|-------|---------|--------------------
2811 * 0 | 0 | DC | DC | E1000_FC_NONE
2812 * 0 | 1 | 0 | DC | E1000_FC_NONE
2813 * 0 | 1 | 1 | 0 | E1000_FC_NONE
2814 * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
2815 * 1 | 0 | 0 | DC | E1000_FC_NONE
2816 * 1 | DC | 1 | DC | E1000_FC_FULL
2817 * 1 | 1 | 0 | 0 | E1000_FC_NONE
2818 * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
2821 /* Are both PAUSE bits set to 1? If so, this implies
2822 * Symmetric Flow Control is enabled at both ends. The
2823 * ASM_DIR bits are irrelevant per the spec.
2825 * For Symmetric Flow Control:
2827 * LOCAL DEVICE | LINK PARTNER
2828 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2829 *-------|---------|-------|---------|--------------------
2830 * 1 | DC | 1 | DC | E1000_FC_FULL
2833 if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2834 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
2835 /* Now we need to check if the user selected RX ONLY
2836 * of pause frames. In this case, we had to advertise
2837 * FULL flow control because we could not advertise RX
2838 * ONLY. Hence, we must now check to see if we need to
2839 * turn OFF the TRANSMISSION of PAUSE frames.
2841 if (hw->original_fc == E1000_FC_FULL) {
2842 hw->fc = E1000_FC_FULL;
2843 DEBUGOUT("Flow Control = FULL.\n");
2845 hw->fc = E1000_FC_RX_PAUSE;
2846 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
2849 /* For receiving PAUSE frames ONLY.
2851 * LOCAL DEVICE | LINK PARTNER
2852 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2853 *-------|---------|-------|---------|--------------------
2854 * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
2857 else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2858 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2859 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2860 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
2861 hw->fc = E1000_FC_TX_PAUSE;
2862 DEBUGOUT("Flow Control = TX PAUSE frames only.\n");
2864 /* For transmitting PAUSE frames ONLY.
2866 * LOCAL DEVICE | LINK PARTNER
2867 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2868 *-------|---------|-------|---------|--------------------
2869 * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
2872 else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2873 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2874 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2875 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
2876 hw->fc = E1000_FC_RX_PAUSE;
2877 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
2879 /* Per the IEEE spec, at this point flow control should be
2880 * disabled. However, we want to consider that we could
2881 * be connected to a legacy switch that doesn't advertise
2882 * desired flow control, but can be forced on the link
2883 * partner. So if we advertised no flow control, that is
2884 * what we will resolve to. If we advertised some kind of
2885 * receive capability (Rx Pause Only or Full Flow Control)
2886 * and the link partner advertised none, we will configure
2887 * ourselves to enable Rx Flow Control only. We can do
2888 * this safely for two reasons: If the link partner really
2889 * didn't want flow control enabled, and we enable Rx, no
2890 * harm done since we won't be receiving any PAUSE frames
2891 * anyway. If the intent on the link partner was to have
2892 * flow control enabled, then by us enabling RX only, we
2893 * can at least receive pause frames and process them.
2894 * This is a good idea because in most cases, since we are
2895 * predominantly a server NIC, more times than not we will
2896 * be asked to delay transmission of packets than asking
2897 * our link partner to pause transmission of frames.
2899 else if ((hw->original_fc == E1000_FC_NONE ||
2900 hw->original_fc == E1000_FC_TX_PAUSE) ||
2901 hw->fc_strict_ieee) {
2902 hw->fc = E1000_FC_NONE;
2903 DEBUGOUT("Flow Control = NONE.\n");
2905 hw->fc = E1000_FC_RX_PAUSE;
2906 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
2909 /* Now we need to do one last check... If we auto-
2910 * negotiated to HALF DUPLEX, flow control should not be
2911 * enabled per IEEE 802.3 spec.
2913 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
2915 DEBUGOUT("Error getting link speed and duplex\n");
2919 if (duplex == HALF_DUPLEX)
2920 hw->fc = E1000_FC_NONE;
2922 /* Now we call a subroutine to actually force the MAC
2923 * controller to use the correct flow control settings.
2925 ret_val = e1000_force_mac_fc(hw);
2927 DEBUGOUT("Error forcing flow control settings\n");
2931 DEBUGOUT("Copper PHY and Auto Neg has not completed.\n");
2934 return E1000_SUCCESS;
2937 /******************************************************************************
2938 * Checks to see if the link status of the hardware has changed.
2940 * hw - Struct containing variables accessed by shared code
2942 * Called by any function that needs to check the link status of the adapter.
2943 *****************************************************************************/
2945 e1000_check_for_link(struct e1000_hw *hw)
2952 uint32_t signal = 0;
2956 DEBUGFUNC("e1000_check_for_link");
2958 ctrl = E1000_READ_REG(hw, CTRL);
2959 status = E1000_READ_REG(hw, STATUS);
2961 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
2962 * set when the optics detect a signal. On older adapters, it will be
2963 * cleared when there is a signal. This applies to fiber media only.
2965 if ((hw->media_type == e1000_media_type_fiber) ||
2966 (hw->media_type == e1000_media_type_internal_serdes)) {
2967 rxcw = E1000_READ_REG(hw, RXCW);
2969 if (hw->media_type == e1000_media_type_fiber) {
2970 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
2971 if (status & E1000_STATUS_LU)
2972 hw->get_link_status = FALSE;
2976 /* If we have a copper PHY then we only want to go out to the PHY
2977 * registers to see if Auto-Neg has completed and/or if our link
2978 * status has changed. The get_link_status flag will be set if we
2979 * receive a Link Status Change interrupt or we have Rx Sequence
2982 if ((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
2983 /* First we want to see if the MII Status Register reports
2984 * link. If so, then we want to get the current speed/duplex
2986 * Read the register twice since the link bit is sticky.
2988 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2991 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2995 if (phy_data & MII_SR_LINK_STATUS) {
2996 hw->get_link_status = FALSE;
2997 /* Check if there was DownShift, must be checked immediately after
2999 e1000_check_downshift(hw);
3001 /* If we are on 82544 or 82543 silicon and speed/duplex
3002 * are forced to 10H or 10F, then we will implement the polarity
3003 * reversal workaround. We disable interrupts first, and upon
3004 * returning, place the devices interrupt state to its previous
3005 * value except for the link status change interrupt which will
3006 * happen due to the execution of this workaround.
3009 if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
3011 (hw->forced_speed_duplex == e1000_10_full ||
3012 hw->forced_speed_duplex == e1000_10_half)) {
3013 E1000_WRITE_REG(hw, IMC, 0xffffffff);
3014 ret_val = e1000_polarity_reversal_workaround(hw);
3015 icr = E1000_READ_REG(hw, ICR);
3016 E1000_WRITE_REG(hw, ICS, (icr & ~E1000_ICS_LSC));
3017 E1000_WRITE_REG(hw, IMS, IMS_ENABLE_MASK);
3021 /* No link detected */
3022 e1000_config_dsp_after_link_change(hw, FALSE);
3026 /* If we are forcing speed/duplex, then we simply return since
3027 * we have already determined whether we have link or not.
3029 if (!hw->autoneg) return -E1000_ERR_CONFIG;
3031 /* optimize the dsp settings for the igp phy */
3032 e1000_config_dsp_after_link_change(hw, TRUE);
3034 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
3035 * have Si on board that is 82544 or newer, Auto
3036 * Speed Detection takes care of MAC speed/duplex
3037 * configuration. So we only need to configure Collision
3038 * Distance in the MAC. Otherwise, we need to force
3039 * speed/duplex on the MAC to the current PHY speed/duplex
3042 if (hw->mac_type >= e1000_82544)
3043 e1000_config_collision_dist(hw);
3045 ret_val = e1000_config_mac_to_phy(hw);
3047 DEBUGOUT("Error configuring MAC to PHY settings\n");
3052 /* Configure Flow Control now that Auto-Neg has completed. First, we
3053 * need to restore the desired flow control settings because we may
3054 * have had to re-autoneg with a different link partner.
3056 ret_val = e1000_config_fc_after_link_up(hw);
3058 DEBUGOUT("Error configuring flow control\n");
3062 /* At this point we know that we are on copper and we have
3063 * auto-negotiated link. These are conditions for checking the link
3064 * partner capability register. We use the link speed to determine if
3065 * TBI compatibility needs to be turned on or off. If the link is not
3066 * at gigabit speed, then TBI compatibility is not needed. If we are
3067 * at gigabit speed, we turn on TBI compatibility.
3069 if (hw->tbi_compatibility_en) {
3070 uint16_t speed, duplex;
3071 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
3073 DEBUGOUT("Error getting link speed and duplex\n");
3076 if (speed != SPEED_1000) {
3077 /* If link speed is not set to gigabit speed, we do not need
3078 * to enable TBI compatibility.
3080 if (hw->tbi_compatibility_on) {
3081 /* If we previously were in the mode, turn it off. */
3082 rctl = E1000_READ_REG(hw, RCTL);
3083 rctl &= ~E1000_RCTL_SBP;
3084 E1000_WRITE_REG(hw, RCTL, rctl);
3085 hw->tbi_compatibility_on = FALSE;
3088 /* If TBI compatibility is was previously off, turn it on. For
3089 * compatibility with a TBI link partner, we will store bad
3090 * packets. Some frames have an additional byte on the end and
3091 * will look like CRC errors to to the hardware.
3093 if (!hw->tbi_compatibility_on) {
3094 hw->tbi_compatibility_on = TRUE;
3095 rctl = E1000_READ_REG(hw, RCTL);
3096 rctl |= E1000_RCTL_SBP;
3097 E1000_WRITE_REG(hw, RCTL, rctl);
3102 /* If we don't have link (auto-negotiation failed or link partner cannot
3103 * auto-negotiate), the cable is plugged in (we have signal), and our
3104 * link partner is not trying to auto-negotiate with us (we are receiving
3105 * idles or data), we need to force link up. We also need to give
3106 * auto-negotiation time to complete, in case the cable was just plugged
3107 * in. The autoneg_failed flag does this.
3109 else if ((((hw->media_type == e1000_media_type_fiber) &&
3110 ((ctrl & E1000_CTRL_SWDPIN1) == signal)) ||
3111 (hw->media_type == e1000_media_type_internal_serdes)) &&
3112 (!(status & E1000_STATUS_LU)) &&
3113 (!(rxcw & E1000_RXCW_C))) {
3114 if (hw->autoneg_failed == 0) {
3115 hw->autoneg_failed = 1;
3118 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\n");
3120 /* Disable auto-negotiation in the TXCW register */
3121 E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
3123 /* Force link-up and also force full-duplex. */
3124 ctrl = E1000_READ_REG(hw, CTRL);
3125 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
3126 E1000_WRITE_REG(hw, CTRL, ctrl);
3128 /* Configure Flow Control after forcing link up. */
3129 ret_val = e1000_config_fc_after_link_up(hw);
3131 DEBUGOUT("Error configuring flow control\n");
3135 /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
3136 * auto-negotiation in the TXCW register and disable forced link in the
3137 * Device Control register in an attempt to auto-negotiate with our link
3140 else if (((hw->media_type == e1000_media_type_fiber) ||
3141 (hw->media_type == e1000_media_type_internal_serdes)) &&
3142 (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
3143 DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\n");
3144 E1000_WRITE_REG(hw, TXCW, hw->txcw);
3145 E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
3147 hw->serdes_link_down = FALSE;
3149 /* If we force link for non-auto-negotiation switch, check link status
3150 * based on MAC synchronization for internal serdes media type.
3152 else if ((hw->media_type == e1000_media_type_internal_serdes) &&
3153 !(E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
3154 /* SYNCH bit and IV bit are sticky. */
3156 if (E1000_RXCW_SYNCH & E1000_READ_REG(hw, RXCW)) {
3157 if (!(rxcw & E1000_RXCW_IV)) {
3158 hw->serdes_link_down = FALSE;
3159 DEBUGOUT("SERDES: Link is up.\n");
3162 hw->serdes_link_down = TRUE;
3163 DEBUGOUT("SERDES: Link is down.\n");
3166 if ((hw->media_type == e1000_media_type_internal_serdes) &&
3167 (E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
3168 hw->serdes_link_down = !(E1000_STATUS_LU & E1000_READ_REG(hw, STATUS));
3170 return E1000_SUCCESS;
3173 /******************************************************************************
3174 * Detects the current speed and duplex settings of the hardware.
3176 * hw - Struct containing variables accessed by shared code
3177 * speed - Speed of the connection
3178 * duplex - Duplex setting of the connection
3179 *****************************************************************************/
3181 e1000_get_speed_and_duplex(struct e1000_hw *hw,
3189 DEBUGFUNC("e1000_get_speed_and_duplex");
3191 if (hw->mac_type >= e1000_82543) {
3192 status = E1000_READ_REG(hw, STATUS);
3193 if (status & E1000_STATUS_SPEED_1000) {
3194 *speed = SPEED_1000;
3195 DEBUGOUT("1000 Mbs, ");
3196 } else if (status & E1000_STATUS_SPEED_100) {
3198 DEBUGOUT("100 Mbs, ");
3201 DEBUGOUT("10 Mbs, ");
3204 if (status & E1000_STATUS_FD) {
3205 *duplex = FULL_DUPLEX;
3206 DEBUGOUT("Full Duplex\n");
3208 *duplex = HALF_DUPLEX;
3209 DEBUGOUT(" Half Duplex\n");
3212 DEBUGOUT("1000 Mbs, Full Duplex\n");
3213 *speed = SPEED_1000;
3214 *duplex = FULL_DUPLEX;
3217 /* IGP01 PHY may advertise full duplex operation after speed downgrade even
3218 * if it is operating at half duplex. Here we set the duplex settings to
3219 * match the duplex in the link partner's capabilities.
3221 if (hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
3222 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
3226 if (!(phy_data & NWAY_ER_LP_NWAY_CAPS))
3227 *duplex = HALF_DUPLEX;
3229 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data);
3232 if ((*speed == SPEED_100 && !(phy_data & NWAY_LPAR_100TX_FD_CAPS)) ||
3233 (*speed == SPEED_10 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
3234 *duplex = HALF_DUPLEX;
3238 if ((hw->mac_type == e1000_80003es2lan) &&
3239 (hw->media_type == e1000_media_type_copper)) {
3240 if (*speed == SPEED_1000)
3241 ret_val = e1000_configure_kmrn_for_1000(hw);
3243 ret_val = e1000_configure_kmrn_for_10_100(hw, *duplex);
3248 if ((hw->phy_type == e1000_phy_igp_3) && (*speed == SPEED_1000)) {
3249 ret_val = e1000_kumeran_lock_loss_workaround(hw);
3254 return E1000_SUCCESS;
3257 /******************************************************************************
3258 * Blocks until autoneg completes or times out (~4.5 seconds)
3260 * hw - Struct containing variables accessed by shared code
3261 ******************************************************************************/
3263 e1000_wait_autoneg(struct e1000_hw *hw)
3269 DEBUGFUNC("e1000_wait_autoneg");
3270 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
3272 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
3273 for (i = PHY_AUTO_NEG_TIME; i > 0; i--) {
3274 /* Read the MII Status Register and wait for Auto-Neg
3275 * Complete bit to be set.
3277 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3280 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3283 if (phy_data & MII_SR_AUTONEG_COMPLETE) {
3284 return E1000_SUCCESS;
3288 return E1000_SUCCESS;
3291 /******************************************************************************
3292 * Raises the Management Data Clock
3294 * hw - Struct containing variables accessed by shared code
3295 * ctrl - Device control register's current value
3296 ******************************************************************************/
3298 e1000_raise_mdi_clk(struct e1000_hw *hw,
3301 /* Raise the clock input to the Management Data Clock (by setting the MDC
3302 * bit), and then delay 10 microseconds.
3304 E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
3305 E1000_WRITE_FLUSH(hw);
3309 /******************************************************************************
3310 * Lowers the Management Data Clock
3312 * hw - Struct containing variables accessed by shared code
3313 * ctrl - Device control register's current value
3314 ******************************************************************************/
3316 e1000_lower_mdi_clk(struct e1000_hw *hw,
3319 /* Lower the clock input to the Management Data Clock (by clearing the MDC
3320 * bit), and then delay 10 microseconds.
3322 E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
3323 E1000_WRITE_FLUSH(hw);
3327 /******************************************************************************
3328 * Shifts data bits out to the PHY
3330 * hw - Struct containing variables accessed by shared code
3331 * data - Data to send out to the PHY
3332 * count - Number of bits to shift out
3334 * Bits are shifted out in MSB to LSB order.
3335 ******************************************************************************/
3337 e1000_shift_out_mdi_bits(struct e1000_hw *hw,
3344 /* We need to shift "count" number of bits out to the PHY. So, the value
3345 * in the "data" parameter will be shifted out to the PHY one bit at a
3346 * time. In order to do this, "data" must be broken down into bits.
3349 mask <<= (count - 1);
3351 ctrl = E1000_READ_REG(hw, CTRL);
3353 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
3354 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
3357 /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
3358 * then raising and lowering the Management Data Clock. A "0" is
3359 * shifted out to the PHY by setting the MDIO bit to "0" and then
3360 * raising and lowering the clock.
3363 ctrl |= E1000_CTRL_MDIO;
3365 ctrl &= ~E1000_CTRL_MDIO;
3367 E1000_WRITE_REG(hw, CTRL, ctrl);
3368 E1000_WRITE_FLUSH(hw);
3372 e1000_raise_mdi_clk(hw, &ctrl);
3373 e1000_lower_mdi_clk(hw, &ctrl);
3379 /******************************************************************************
3380 * Shifts data bits in from the PHY
3382 * hw - Struct containing variables accessed by shared code
3384 * Bits are shifted in in MSB to LSB order.
3385 ******************************************************************************/
3387 e1000_shift_in_mdi_bits(struct e1000_hw *hw)
3393 /* In order to read a register from the PHY, we need to shift in a total
3394 * of 18 bits from the PHY. The first two bit (turnaround) times are used
3395 * to avoid contention on the MDIO pin when a read operation is performed.
3396 * These two bits are ignored by us and thrown away. Bits are "shifted in"
3397 * by raising the input to the Management Data Clock (setting the MDC bit),
3398 * and then reading the value of the MDIO bit.
3400 ctrl = E1000_READ_REG(hw, CTRL);
3402 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
3403 ctrl &= ~E1000_CTRL_MDIO_DIR;
3404 ctrl &= ~E1000_CTRL_MDIO;
3406 E1000_WRITE_REG(hw, CTRL, ctrl);
3407 E1000_WRITE_FLUSH(hw);
3409 /* Raise and Lower the clock before reading in the data. This accounts for
3410 * the turnaround bits. The first clock occurred when we clocked out the
3411 * last bit of the Register Address.
3413 e1000_raise_mdi_clk(hw, &ctrl);
3414 e1000_lower_mdi_clk(hw, &ctrl);
3416 for (data = 0, i = 0; i < 16; i++) {
3418 e1000_raise_mdi_clk(hw, &ctrl);
3419 ctrl = E1000_READ_REG(hw, CTRL);
3420 /* Check to see if we shifted in a "1". */
3421 if (ctrl & E1000_CTRL_MDIO)
3423 e1000_lower_mdi_clk(hw, &ctrl);
3426 e1000_raise_mdi_clk(hw, &ctrl);
3427 e1000_lower_mdi_clk(hw, &ctrl);
3433 e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask)
3435 uint32_t swfw_sync = 0;
3436 uint32_t swmask = mask;
3437 uint32_t fwmask = mask << 16;
3438 int32_t timeout = 200;
3440 DEBUGFUNC("e1000_swfw_sync_acquire");
3442 if (hw->swfwhw_semaphore_present)
3443 return e1000_get_software_flag(hw);
3445 if (!hw->swfw_sync_present)
3446 return e1000_get_hw_eeprom_semaphore(hw);
3449 if (e1000_get_hw_eeprom_semaphore(hw))
3450 return -E1000_ERR_SWFW_SYNC;
3452 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
3453 if (!(swfw_sync & (fwmask | swmask))) {
3457 /* firmware currently using resource (fwmask) */
3458 /* or other software thread currently using resource (swmask) */
3459 e1000_put_hw_eeprom_semaphore(hw);
3465 DEBUGOUT("Driver can't access resource, SW_FW_SYNC timeout.\n");
3466 return -E1000_ERR_SWFW_SYNC;
3469 swfw_sync |= swmask;
3470 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
3472 e1000_put_hw_eeprom_semaphore(hw);
3473 return E1000_SUCCESS;
3477 e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask)
3480 uint32_t swmask = mask;
3482 DEBUGFUNC("e1000_swfw_sync_release");
3484 if (hw->swfwhw_semaphore_present) {
3485 e1000_release_software_flag(hw);
3489 if (!hw->swfw_sync_present) {
3490 e1000_put_hw_eeprom_semaphore(hw);
3494 /* if (e1000_get_hw_eeprom_semaphore(hw))
3495 * return -E1000_ERR_SWFW_SYNC; */
3496 while (e1000_get_hw_eeprom_semaphore(hw) != E1000_SUCCESS);
3499 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
3500 swfw_sync &= ~swmask;
3501 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
3503 e1000_put_hw_eeprom_semaphore(hw);
3506 /*****************************************************************************
3507 * Reads the value from a PHY register, if the value is on a specific non zero
3508 * page, sets the page first.
3509 * hw - Struct containing variables accessed by shared code
3510 * reg_addr - address of the PHY register to read
3511 ******************************************************************************/
3513 e1000_read_phy_reg(struct e1000_hw *hw,
3520 DEBUGFUNC("e1000_read_phy_reg");
3522 if ((hw->mac_type == e1000_80003es2lan || hw->mac_type == e1000_82576) &&
3523 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3524 swfw = E1000_SWFW_PHY1_SM;
3526 swfw = E1000_SWFW_PHY0_SM;
3528 if (e1000_swfw_sync_acquire(hw, swfw))
3529 return -E1000_ERR_SWFW_SYNC;
3531 if ((hw->phy_type == e1000_phy_igp ||
3532 hw->phy_type == e1000_phy_igp_3 ||
3533 hw->phy_type == e1000_phy_igp_2) &&
3534 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
3535 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
3536 (uint16_t)reg_addr);
3538 e1000_swfw_sync_release(hw, swfw);
3541 } else if (hw->phy_type == e1000_phy_gg82563) {
3542 if (((reg_addr & MAX_PHY_REG_ADDRESS) > MAX_PHY_MULTI_PAGE_REG) ||
3543 (hw->mac_type == e1000_80003es2lan)) {
3544 /* Select Configuration Page */
3545 if ((reg_addr & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) {
3546 ret_val = e1000_write_phy_reg_ex(hw, GG82563_PHY_PAGE_SELECT,
3547 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3549 /* Use Alternative Page Select register to access
3550 * registers 30 and 31
3552 ret_val = e1000_write_phy_reg_ex(hw,
3553 GG82563_PHY_PAGE_SELECT_ALT,
3554 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3558 e1000_swfw_sync_release(hw, swfw);
3564 ret_val = e1000_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
3567 e1000_swfw_sync_release(hw, swfw);
3572 e1000_read_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr,
3577 const uint32_t phy_addr = 1;
3579 DEBUGFUNC("e1000_read_phy_reg_ex");
3581 if (reg_addr > MAX_PHY_REG_ADDRESS) {
3582 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
3583 return -E1000_ERR_PARAM;