1 /*******************************************************************************
3 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2006 Intel Corporation.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *******************************************************************************/
30 * Shared functions for accessing and configuring the MAC
36 static int32_t e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask);
37 static void e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask);
38 static int32_t e1000_read_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t *data);
39 static int32_t e1000_write_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t data);
40 static int32_t e1000_get_software_semaphore(struct e1000_hw *hw);
41 static void e1000_release_software_semaphore(struct e1000_hw *hw);
43 static uint8_t e1000_arc_subsystem_valid(struct e1000_hw *hw);
44 static int32_t e1000_check_downshift(struct e1000_hw *hw);
45 static int32_t e1000_check_polarity(struct e1000_hw *hw, e1000_rev_polarity *polarity);
46 static void e1000_clear_hw_cntrs(struct e1000_hw *hw);
47 static void e1000_clear_vfta(struct e1000_hw *hw);
48 static int32_t e1000_commit_shadow_ram(struct e1000_hw *hw);
49 static int32_t e1000_config_dsp_after_link_change(struct e1000_hw *hw, boolean_t link_up);
50 static int32_t e1000_config_fc_after_link_up(struct e1000_hw *hw);
51 static int32_t e1000_detect_gig_phy(struct e1000_hw *hw);
52 static int32_t e1000_erase_ich8_4k_segment(struct e1000_hw *hw, uint32_t bank);
53 static int32_t e1000_get_auto_rd_done(struct e1000_hw *hw);
54 static int32_t e1000_get_cable_length(struct e1000_hw *hw, uint16_t *min_length, uint16_t *max_length);
55 static int32_t e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw);
56 static int32_t e1000_get_phy_cfg_done(struct e1000_hw *hw);
57 static int32_t e1000_get_software_flag(struct e1000_hw *hw);
58 static int32_t e1000_ich8_cycle_init(struct e1000_hw *hw);
59 static int32_t e1000_ich8_flash_cycle(struct e1000_hw *hw, uint32_t timeout);
60 static int32_t e1000_id_led_init(struct e1000_hw *hw);
61 static int32_t e1000_init_lcd_from_nvm_config_region(struct e1000_hw *hw, uint32_t cnf_base_addr, uint32_t cnf_size);
62 static int32_t e1000_init_lcd_from_nvm(struct e1000_hw *hw);
63 static void e1000_init_rx_addrs(struct e1000_hw *hw);
64 static void e1000_initialize_hardware_bits(struct e1000_hw *hw);
65 static boolean_t e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw);
66 static int32_t e1000_kumeran_lock_loss_workaround(struct e1000_hw *hw);
67 static int32_t e1000_mng_enable_host_if(struct e1000_hw *hw);
68 static int32_t e1000_mng_host_if_write(struct e1000_hw *hw, uint8_t *buffer, uint16_t length, uint16_t offset, uint8_t *sum);
69 static int32_t e1000_mng_write_cmd_header(struct e1000_hw* hw, struct e1000_host_mng_command_header* hdr);
70 static int32_t e1000_mng_write_commit(struct e1000_hw *hw);
71 static int32_t e1000_phy_ife_get_info(struct e1000_hw *hw, struct e1000_phy_info *phy_info);
72 static int32_t e1000_phy_igp_get_info(struct e1000_hw *hw, struct e1000_phy_info *phy_info);
73 static int32_t e1000_read_eeprom_eerd(struct e1000_hw *hw, uint16_t offset, uint16_t words, uint16_t *data);
74 static int32_t e1000_write_eeprom_eewr(struct e1000_hw *hw, uint16_t offset, uint16_t words, uint16_t *data);
75 static int32_t e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd);
76 static int32_t e1000_phy_m88_get_info(struct e1000_hw *hw, struct e1000_phy_info *phy_info);
77 static void e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw);
78 static int32_t e1000_read_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t *data);
79 static int32_t e1000_verify_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t byte);
80 static int32_t e1000_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t byte);
81 static int32_t e1000_read_ich8_word(struct e1000_hw *hw, uint32_t index, uint16_t *data);
82 static int32_t e1000_read_ich8_data(struct e1000_hw *hw, uint32_t index, uint32_t size, uint16_t *data);
83 static int32_t e1000_write_ich8_data(struct e1000_hw *hw, uint32_t index, uint32_t size, uint16_t data);
84 static int32_t e1000_read_eeprom_ich8(struct e1000_hw *hw, uint16_t offset, uint16_t words, uint16_t *data);
85 static int32_t e1000_write_eeprom_ich8(struct e1000_hw *hw, uint16_t offset, uint16_t words, uint16_t *data);
86 static void e1000_release_software_flag(struct e1000_hw *hw);
87 static int32_t e1000_set_d3_lplu_state(struct e1000_hw *hw, boolean_t active);
88 static int32_t e1000_set_d0_lplu_state(struct e1000_hw *hw, boolean_t active);
89 static int32_t e1000_set_pci_ex_no_snoop(struct e1000_hw *hw, uint32_t no_snoop);
90 static void e1000_set_pci_express_master_disable(struct e1000_hw *hw);
91 static int32_t e1000_wait_autoneg(struct e1000_hw *hw);
92 static void e1000_write_reg_io(struct e1000_hw *hw, uint32_t offset, uint32_t value);
93 static int32_t e1000_set_phy_type(struct e1000_hw *hw);
94 static void e1000_phy_init_script(struct e1000_hw *hw);
95 static int32_t e1000_setup_copper_link(struct e1000_hw *hw);
96 static int32_t e1000_setup_fiber_serdes_link(struct e1000_hw *hw);
97 static int32_t e1000_adjust_serdes_amplitude(struct e1000_hw *hw);
98 static int32_t e1000_phy_force_speed_duplex(struct e1000_hw *hw);
99 static int32_t e1000_config_mac_to_phy(struct e1000_hw *hw);
100 static void e1000_raise_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl);
101 static void e1000_lower_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl);
102 static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, uint32_t data,
104 static uint16_t e1000_shift_in_mdi_bits(struct e1000_hw *hw);
105 static int32_t e1000_phy_reset_dsp(struct e1000_hw *hw);
106 static int32_t e1000_write_eeprom_spi(struct e1000_hw *hw, uint16_t offset,
107 uint16_t words, uint16_t *data);
108 static int32_t e1000_write_eeprom_microwire(struct e1000_hw *hw,
109 uint16_t offset, uint16_t words,
111 static int32_t e1000_spi_eeprom_ready(struct e1000_hw *hw);
112 static void e1000_raise_ee_clk(struct e1000_hw *hw, uint32_t *eecd);
113 static void e1000_lower_ee_clk(struct e1000_hw *hw, uint32_t *eecd);
114 static void e1000_shift_out_ee_bits(struct e1000_hw *hw, uint16_t data,
116 static int32_t e1000_write_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr,
118 static int32_t e1000_read_phy_reg_ex(struct e1000_hw *hw,uint32_t reg_addr,
120 static uint16_t e1000_shift_in_ee_bits(struct e1000_hw *hw, uint16_t count);
121 static int32_t e1000_acquire_eeprom(struct e1000_hw *hw);
122 static void e1000_release_eeprom(struct e1000_hw *hw);
123 static void e1000_standby_eeprom(struct e1000_hw *hw);
124 static int32_t e1000_set_vco_speed(struct e1000_hw *hw);
125 static int32_t e1000_polarity_reversal_workaround(struct e1000_hw *hw);
126 static int32_t e1000_set_phy_mode(struct e1000_hw *hw);
127 static int32_t e1000_host_if_read_cookie(struct e1000_hw *hw, uint8_t *buffer);
128 static uint8_t e1000_calculate_mng_checksum(char *buffer, uint32_t length);
129 static int32_t e1000_configure_kmrn_for_10_100(struct e1000_hw *hw,
131 static int32_t e1000_configure_kmrn_for_1000(struct e1000_hw *hw);
133 /* IGP cable length table */
135 uint16_t e1000_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] =
136 { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
137 5, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 25, 25, 25,
138 25, 25, 25, 25, 30, 30, 30, 30, 40, 40, 40, 40, 40, 40, 40, 40,
139 40, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60,
140 60, 70, 70, 70, 70, 70, 70, 80, 80, 80, 80, 80, 80, 90, 90, 90,
141 90, 90, 90, 90, 90, 90, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
142 100, 100, 100, 100, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,
143 110, 110, 110, 110, 110, 110, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120};
146 uint16_t e1000_igp_2_cable_length_table[IGP02E1000_AGC_LENGTH_TABLE_SIZE] =
147 { 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21,
148 0, 0, 0, 3, 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41,
149 6, 10, 14, 18, 22, 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61,
150 21, 26, 31, 35, 40, 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82,
151 40, 45, 51, 56, 61, 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104,
152 60, 66, 72, 77, 82, 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121,
153 83, 89, 95, 100, 105, 109, 113, 116, 119, 122, 124,
154 104, 109, 114, 118, 121, 124};
156 /******************************************************************************
157 * Set the phy type member in the hw struct.
159 * hw - Struct containing variables accessed by shared code
160 *****************************************************************************/
162 e1000_set_phy_type(struct e1000_hw *hw)
164 DEBUGFUNC("e1000_set_phy_type");
166 if (hw->mac_type == e1000_undefined)
167 return -E1000_ERR_PHY_TYPE;
169 switch (hw->phy_id) {
170 case M88E1000_E_PHY_ID:
171 case M88E1000_I_PHY_ID:
172 case M88E1011_I_PHY_ID:
173 case M88E1111_I_PHY_ID:
174 hw->phy_type = e1000_phy_m88;
176 case IGP01E1000_I_PHY_ID:
177 if (hw->mac_type == e1000_82541 ||
178 hw->mac_type == e1000_82541_rev_2 ||
179 hw->mac_type == e1000_82547 ||
180 hw->mac_type == e1000_82547_rev_2) {
181 hw->phy_type = e1000_phy_igp;
184 case IGP03E1000_E_PHY_ID:
185 hw->phy_type = e1000_phy_igp_3;
188 case IFE_PLUS_E_PHY_ID:
190 hw->phy_type = e1000_phy_ife;
192 case GG82563_E_PHY_ID:
193 if (hw->mac_type == e1000_80003es2lan) {
194 hw->phy_type = e1000_phy_gg82563;
199 /* Should never have loaded on this device */
200 hw->phy_type = e1000_phy_undefined;
201 return -E1000_ERR_PHY_TYPE;
204 return E1000_SUCCESS;
207 /******************************************************************************
208 * IGP phy init script - initializes the GbE PHY
210 * hw - Struct containing variables accessed by shared code
211 *****************************************************************************/
213 e1000_phy_init_script(struct e1000_hw *hw)
216 uint16_t phy_saved_data;
218 DEBUGFUNC("e1000_phy_init_script");
220 if (hw->phy_init_script) {
223 /* Save off the current value of register 0x2F5B to be restored at
224 * the end of this routine. */
225 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
227 /* Disabled the PHY transmitter */
228 e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
232 e1000_write_phy_reg(hw,0x0000,0x0140);
236 switch (hw->mac_type) {
239 e1000_write_phy_reg(hw, 0x1F95, 0x0001);
241 e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
243 e1000_write_phy_reg(hw, 0x1F79, 0x0018);
245 e1000_write_phy_reg(hw, 0x1F30, 0x1600);
247 e1000_write_phy_reg(hw, 0x1F31, 0x0014);
249 e1000_write_phy_reg(hw, 0x1F32, 0x161C);
251 e1000_write_phy_reg(hw, 0x1F94, 0x0003);
253 e1000_write_phy_reg(hw, 0x1F96, 0x003F);
255 e1000_write_phy_reg(hw, 0x2010, 0x0008);
258 case e1000_82541_rev_2:
259 case e1000_82547_rev_2:
260 e1000_write_phy_reg(hw, 0x1F73, 0x0099);
266 e1000_write_phy_reg(hw, 0x0000, 0x3300);
270 /* Now enable the transmitter */
271 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
273 if (hw->mac_type == e1000_82547) {
274 uint16_t fused, fine, coarse;
276 /* Move to analog registers page */
277 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_SPARE_FUSE_STATUS, &fused);
279 if (!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
280 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_FUSE_STATUS, &fused);
282 fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
283 coarse = fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
285 if (coarse > IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
286 coarse -= IGP01E1000_ANALOG_FUSE_COARSE_10;
287 fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
288 } else if (coarse == IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
289 fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
291 fused = (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
292 (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
293 (coarse & IGP01E1000_ANALOG_FUSE_COARSE_MASK);
295 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_CONTROL, fused);
296 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_BYPASS,
297 IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
303 /******************************************************************************
304 * Set the mac type member in the hw struct.
306 * hw - Struct containing variables accessed by shared code
307 *****************************************************************************/
309 e1000_set_mac_type(struct e1000_hw *hw)
311 DEBUGFUNC("e1000_set_mac_type");
313 switch (hw->device_id) {
314 case E1000_DEV_ID_82542:
315 switch (hw->revision_id) {
316 case E1000_82542_2_0_REV_ID:
317 hw->mac_type = e1000_82542_rev2_0;
319 case E1000_82542_2_1_REV_ID:
320 hw->mac_type = e1000_82542_rev2_1;
323 /* Invalid 82542 revision ID */
324 return -E1000_ERR_MAC_TYPE;
327 case E1000_DEV_ID_82543GC_FIBER:
328 case E1000_DEV_ID_82543GC_COPPER:
329 hw->mac_type = e1000_82543;
331 case E1000_DEV_ID_82544EI_COPPER:
332 case E1000_DEV_ID_82544EI_FIBER:
333 case E1000_DEV_ID_82544GC_COPPER:
334 case E1000_DEV_ID_82544GC_LOM:
335 hw->mac_type = e1000_82544;
337 case E1000_DEV_ID_82540EM:
338 case E1000_DEV_ID_82540EM_LOM:
339 case E1000_DEV_ID_82540EP:
340 case E1000_DEV_ID_82540EP_LOM:
341 case E1000_DEV_ID_82540EP_LP:
342 hw->mac_type = e1000_82540;
344 case E1000_DEV_ID_82545EM_COPPER:
345 case E1000_DEV_ID_82545EM_FIBER:
346 hw->mac_type = e1000_82545;
348 case E1000_DEV_ID_82545GM_COPPER:
349 case E1000_DEV_ID_82545GM_FIBER:
350 case E1000_DEV_ID_82545GM_SERDES:
351 hw->mac_type = e1000_82545_rev_3;
353 case E1000_DEV_ID_82546EB_COPPER:
354 case E1000_DEV_ID_82546EB_FIBER:
355 case E1000_DEV_ID_82546EB_QUAD_COPPER:
356 hw->mac_type = e1000_82546;
358 case E1000_DEV_ID_82546GB_COPPER:
359 case E1000_DEV_ID_82546GB_FIBER:
360 case E1000_DEV_ID_82546GB_SERDES:
361 case E1000_DEV_ID_82546GB_PCIE:
362 case E1000_DEV_ID_82546GB_QUAD_COPPER:
363 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
364 hw->mac_type = e1000_82546_rev_3;
366 case E1000_DEV_ID_82541EI:
367 case E1000_DEV_ID_82541EI_MOBILE:
368 case E1000_DEV_ID_82541ER_LOM:
369 hw->mac_type = e1000_82541;
371 case E1000_DEV_ID_82541ER:
372 case E1000_DEV_ID_82541GI:
373 case E1000_DEV_ID_82541GI_LF:
374 case E1000_DEV_ID_82541GI_MOBILE:
375 hw->mac_type = e1000_82541_rev_2;
377 case E1000_DEV_ID_82547EI:
378 case E1000_DEV_ID_82547EI_MOBILE:
379 hw->mac_type = e1000_82547;
381 case E1000_DEV_ID_82547GI:
382 hw->mac_type = e1000_82547_rev_2;
384 case E1000_DEV_ID_82571EB_COPPER:
385 case E1000_DEV_ID_82571EB_FIBER:
386 case E1000_DEV_ID_82571EB_SERDES:
387 case E1000_DEV_ID_82571EB_QUAD_COPPER:
388 case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE:
389 hw->mac_type = e1000_82571;
391 case E1000_DEV_ID_82572EI_COPPER:
392 case E1000_DEV_ID_82572EI_FIBER:
393 case E1000_DEV_ID_82572EI_SERDES:
394 case E1000_DEV_ID_82572EI:
395 hw->mac_type = e1000_82572;
397 case E1000_DEV_ID_82573E:
398 case E1000_DEV_ID_82573E_IAMT:
399 case E1000_DEV_ID_82573L:
400 hw->mac_type = e1000_82573;
402 case E1000_DEV_ID_80003ES2LAN_COPPER_SPT:
403 case E1000_DEV_ID_80003ES2LAN_SERDES_SPT:
404 case E1000_DEV_ID_80003ES2LAN_COPPER_DPT:
405 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
406 hw->mac_type = e1000_80003es2lan;
408 case E1000_DEV_ID_ICH8_IGP_M_AMT:
409 case E1000_DEV_ID_ICH8_IGP_AMT:
410 case E1000_DEV_ID_ICH8_IGP_C:
411 case E1000_DEV_ID_ICH8_IFE:
412 case E1000_DEV_ID_ICH8_IFE_GT:
413 case E1000_DEV_ID_ICH8_IFE_G:
414 case E1000_DEV_ID_ICH8_IGP_M:
415 hw->mac_type = e1000_ich8lan;
418 /* Should never have loaded on this device */
419 return -E1000_ERR_MAC_TYPE;
422 switch (hw->mac_type) {
424 hw->swfwhw_semaphore_present = TRUE;
425 hw->asf_firmware_present = TRUE;
427 case e1000_80003es2lan:
428 hw->swfw_sync_present = TRUE;
433 hw->eeprom_semaphore_present = TRUE;
437 case e1000_82541_rev_2:
438 case e1000_82547_rev_2:
439 hw->asf_firmware_present = TRUE;
445 /* The 82543 chip does not count tx_carrier_errors properly in
448 if (hw->mac_type == e1000_82543)
449 hw->bad_tx_carr_stats_fd = TRUE;
451 /* capable of receiving management packets to the host */
452 if (hw->mac_type >= e1000_82571)
453 hw->has_manc2h = TRUE;
455 /* In rare occasions, ESB2 systems would end up started without
456 * the RX unit being turned on.
458 if (hw->mac_type == e1000_80003es2lan)
459 hw->rx_needs_kicking = TRUE;
461 return E1000_SUCCESS;
464 /*****************************************************************************
465 * Set media type and TBI compatibility.
467 * hw - Struct containing variables accessed by shared code
468 * **************************************************************************/
470 e1000_set_media_type(struct e1000_hw *hw)
474 DEBUGFUNC("e1000_set_media_type");
476 if (hw->mac_type != e1000_82543) {
477 /* tbi_compatibility is only valid on 82543 */
478 hw->tbi_compatibility_en = FALSE;
481 switch (hw->device_id) {
482 case E1000_DEV_ID_82545GM_SERDES:
483 case E1000_DEV_ID_82546GB_SERDES:
484 case E1000_DEV_ID_82571EB_SERDES:
485 case E1000_DEV_ID_82572EI_SERDES:
486 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
487 hw->media_type = e1000_media_type_internal_serdes;
490 switch (hw->mac_type) {
491 case e1000_82542_rev2_0:
492 case e1000_82542_rev2_1:
493 hw->media_type = e1000_media_type_fiber;
497 /* The STATUS_TBIMODE bit is reserved or reused for the this
500 hw->media_type = e1000_media_type_copper;
503 status = E1000_READ_REG(hw, STATUS);
504 if (status & E1000_STATUS_TBIMODE) {
505 hw->media_type = e1000_media_type_fiber;
506 /* tbi_compatibility not valid on fiber */
507 hw->tbi_compatibility_en = FALSE;
509 hw->media_type = e1000_media_type_copper;
516 /******************************************************************************
517 * Reset the transmit and receive units; mask and clear all interrupts.
519 * hw - Struct containing variables accessed by shared code
520 *****************************************************************************/
522 e1000_reset_hw(struct e1000_hw *hw)
530 uint32_t extcnf_ctrl;
533 DEBUGFUNC("e1000_reset_hw");
535 /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
536 if (hw->mac_type == e1000_82542_rev2_0) {
537 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
538 e1000_pci_clear_mwi(hw);
541 if (hw->bus_type == e1000_bus_type_pci_express) {
542 /* Prevent the PCI-E bus from sticking if there is no TLP connection
543 * on the last TLP read/write transaction when MAC is reset.
545 if (e1000_disable_pciex_master(hw) != E1000_SUCCESS) {
546 DEBUGOUT("PCI-E Master disable polling has failed.\n");
550 /* Clear interrupt mask to stop board from generating interrupts */
551 DEBUGOUT("Masking off all interrupts\n");
552 E1000_WRITE_REG(hw, IMC, 0xffffffff);
554 /* Disable the Transmit and Receive units. Then delay to allow
555 * any pending transactions to complete before we hit the MAC with
558 E1000_WRITE_REG(hw, RCTL, 0);
559 E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP);
560 E1000_WRITE_FLUSH(hw);
562 /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
563 hw->tbi_compatibility_on = FALSE;
565 /* Delay to allow any outstanding PCI transactions to complete before
566 * resetting the device
570 ctrl = E1000_READ_REG(hw, CTRL);
572 /* Must reset the PHY before resetting the MAC */
573 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
574 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_PHY_RST));
578 /* Must acquire the MDIO ownership before MAC reset.
579 * Ownership defaults to firmware after a reset. */
580 if (hw->mac_type == e1000_82573) {
583 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
584 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
587 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
588 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
590 if (extcnf_ctrl & E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP)
593 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
600 /* Workaround for ICH8 bit corruption issue in FIFO memory */
601 if (hw->mac_type == e1000_ich8lan) {
602 /* Set Tx and Rx buffer allocation to 8k apiece. */
603 E1000_WRITE_REG(hw, PBA, E1000_PBA_8K);
604 /* Set Packet Buffer Size to 16k. */
605 E1000_WRITE_REG(hw, PBS, E1000_PBS_16K);
608 /* Issue a global reset to the MAC. This will reset the chip's
609 * transmit, receive, DMA, and link units. It will not effect
610 * the current PCI configuration. The global reset bit is self-
611 * clearing, and should clear within a microsecond.
613 DEBUGOUT("Issuing a global reset to MAC\n");
615 switch (hw->mac_type) {
621 case e1000_82541_rev_2:
622 /* These controllers can't ack the 64-bit write when issuing the
623 * reset, so use IO-mapping as a workaround to issue the reset */
624 E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
626 case e1000_82545_rev_3:
627 case e1000_82546_rev_3:
628 /* Reset is performed on a shadow of the control register */
629 E1000_WRITE_REG(hw, CTRL_DUP, (ctrl | E1000_CTRL_RST));
632 if (!hw->phy_reset_disable &&
633 e1000_check_phy_reset_block(hw) == E1000_SUCCESS) {
634 /* e1000_ich8lan PHY HW reset requires MAC CORE reset
635 * at the same time to make sure the interface between
636 * MAC and the external PHY is reset.
638 ctrl |= E1000_CTRL_PHY_RST;
641 e1000_get_software_flag(hw);
642 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
646 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
650 /* After MAC reset, force reload of EEPROM to restore power-on settings to
651 * device. Later controllers reload the EEPROM automatically, so just wait
652 * for reload to complete.
654 switch (hw->mac_type) {
655 case e1000_82542_rev2_0:
656 case e1000_82542_rev2_1:
659 /* Wait for reset to complete */
661 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
662 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
663 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
664 E1000_WRITE_FLUSH(hw);
665 /* Wait for EEPROM reload */
669 case e1000_82541_rev_2:
671 case e1000_82547_rev_2:
672 /* Wait for EEPROM reload */
676 if (e1000_is_onboard_nvm_eeprom(hw) == FALSE) {
678 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
679 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
680 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
681 E1000_WRITE_FLUSH(hw);
685 /* Auto read done will delay 5ms or poll based on mac type */
686 ret_val = e1000_get_auto_rd_done(hw);
692 /* Disable HW ARPs on ASF enabled adapters */
693 if (hw->mac_type >= e1000_82540 && hw->mac_type <= e1000_82547_rev_2) {
694 manc = E1000_READ_REG(hw, MANC);
695 manc &= ~(E1000_MANC_ARP_EN);
696 E1000_WRITE_REG(hw, MANC, manc);
699 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
700 e1000_phy_init_script(hw);
702 /* Configure activity LED after PHY reset */
703 led_ctrl = E1000_READ_REG(hw, LEDCTL);
704 led_ctrl &= IGP_ACTIVITY_LED_MASK;
705 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
706 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
709 /* Clear interrupt mask to stop board from generating interrupts */
710 DEBUGOUT("Masking off all interrupts\n");
711 E1000_WRITE_REG(hw, IMC, 0xffffffff);
713 /* Clear any pending interrupt events. */
714 icr = E1000_READ_REG(hw, ICR);
716 /* If MWI was previously enabled, reenable it. */
717 if (hw->mac_type == e1000_82542_rev2_0) {
718 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
719 e1000_pci_set_mwi(hw);
722 if (hw->mac_type == e1000_ich8lan) {
723 uint32_t kab = E1000_READ_REG(hw, KABGTXD);
724 kab |= E1000_KABGTXD_BGSQLBIAS;
725 E1000_WRITE_REG(hw, KABGTXD, kab);
728 return E1000_SUCCESS;
731 /******************************************************************************
733 * Initialize a number of hardware-dependent bits
735 * hw: Struct containing variables accessed by shared code
737 * This function contains hardware limitation workarounds for PCI-E adapters
739 *****************************************************************************/
741 e1000_initialize_hardware_bits(struct e1000_hw *hw)
743 if ((hw->mac_type >= e1000_82571) && (!hw->initialize_hw_bits_disable)) {
744 /* Settings common to all PCI-express silicon */
745 uint32_t reg_ctrl, reg_ctrl_ext;
746 uint32_t reg_tarc0, reg_tarc1;
748 uint32_t reg_txdctl, reg_txdctl1;
750 /* link autonegotiation/sync workarounds */
751 reg_tarc0 = E1000_READ_REG(hw, TARC0);
752 reg_tarc0 &= ~((1 << 30)|(1 << 29)|(1 << 28)|(1 << 27));
754 /* Enable not-done TX descriptor counting */
755 reg_txdctl = E1000_READ_REG(hw, TXDCTL);
756 reg_txdctl |= E1000_TXDCTL_COUNT_DESC;
757 E1000_WRITE_REG(hw, TXDCTL, reg_txdctl);
758 reg_txdctl1 = E1000_READ_REG(hw, TXDCTL1);
759 reg_txdctl1 |= E1000_TXDCTL_COUNT_DESC;
760 E1000_WRITE_REG(hw, TXDCTL1, reg_txdctl1);
762 switch (hw->mac_type) {
765 /* Clear PHY TX compatible mode bits */
766 reg_tarc1 = E1000_READ_REG(hw, TARC1);
767 reg_tarc1 &= ~((1 << 30)|(1 << 29));
769 /* link autonegotiation/sync workarounds */
770 reg_tarc0 |= ((1 << 26)|(1 << 25)|(1 << 24)|(1 << 23));
772 /* TX ring control fixes */
773 reg_tarc1 |= ((1 << 26)|(1 << 25)|(1 << 24));
775 /* Multiple read bit is reversed polarity */
776 reg_tctl = E1000_READ_REG(hw, TCTL);
777 if (reg_tctl & E1000_TCTL_MULR)
778 reg_tarc1 &= ~(1 << 28);
780 reg_tarc1 |= (1 << 28);
782 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
785 reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
786 reg_ctrl_ext &= ~(1 << 23);
787 reg_ctrl_ext |= (1 << 22);
789 /* TX byte count fix */
790 reg_ctrl = E1000_READ_REG(hw, CTRL);
791 reg_ctrl &= ~(1 << 29);
793 E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext);
794 E1000_WRITE_REG(hw, CTRL, reg_ctrl);
796 case e1000_80003es2lan:
797 /* improve small packet performace for fiber/serdes */
798 if ((hw->media_type == e1000_media_type_fiber) ||
799 (hw->media_type == e1000_media_type_internal_serdes)) {
800 reg_tarc0 &= ~(1 << 20);
803 /* Multiple read bit is reversed polarity */
804 reg_tctl = E1000_READ_REG(hw, TCTL);
805 reg_tarc1 = E1000_READ_REG(hw, TARC1);
806 if (reg_tctl & E1000_TCTL_MULR)
807 reg_tarc1 &= ~(1 << 28);
809 reg_tarc1 |= (1 << 28);
811 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
814 /* Reduce concurrent DMA requests to 3 from 4 */
815 if ((hw->revision_id < 3) ||
816 ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) &&
817 (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))
818 reg_tarc0 |= ((1 << 29)|(1 << 28));
820 reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
821 reg_ctrl_ext |= (1 << 22);
822 E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext);
824 /* workaround TX hang with TSO=on */
825 reg_tarc0 |= ((1 << 27)|(1 << 26)|(1 << 24)|(1 << 23));
827 /* Multiple read bit is reversed polarity */
828 reg_tctl = E1000_READ_REG(hw, TCTL);
829 reg_tarc1 = E1000_READ_REG(hw, TARC1);
830 if (reg_tctl & E1000_TCTL_MULR)
831 reg_tarc1 &= ~(1 << 28);
833 reg_tarc1 |= (1 << 28);
835 /* workaround TX hang with TSO=on */
836 reg_tarc1 |= ((1 << 30)|(1 << 26)|(1 << 24));
838 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
844 E1000_WRITE_REG(hw, TARC0, reg_tarc0);
848 /******************************************************************************
849 * Performs basic configuration of the adapter.
851 * hw - Struct containing variables accessed by shared code
853 * Assumes that the controller has previously been reset and is in a
854 * post-reset uninitialized state. Initializes the receive address registers,
855 * multicast table, and VLAN filter table. Calls routines to setup link
856 * configuration and flow control settings. Clears all on-chip counters. Leaves
857 * the transmit and receive units disabled and uninitialized.
858 *****************************************************************************/
860 e1000_init_hw(struct e1000_hw *hw)
865 uint16_t pcix_cmd_word;
866 uint16_t pcix_stat_hi_word;
873 DEBUGFUNC("e1000_init_hw");
875 /* force full DMA clock frequency for 10/100 on ICH8 A0-B0 */
876 if ((hw->mac_type == e1000_ich8lan) &&
877 ((hw->revision_id < 3) ||
878 ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) &&
879 (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))) {
880 reg_data = E1000_READ_REG(hw, STATUS);
881 reg_data &= ~0x80000000;
882 E1000_WRITE_REG(hw, STATUS, reg_data);
885 /* Initialize Identification LED */
886 ret_val = e1000_id_led_init(hw);
888 DEBUGOUT("Error Initializing Identification LED\n");
892 /* Set the media type and TBI compatibility */
893 e1000_set_media_type(hw);
895 /* Must be called after e1000_set_media_type because media_type is used */
896 e1000_initialize_hardware_bits(hw);
898 /* Disabling VLAN filtering. */
899 DEBUGOUT("Initializing the IEEE VLAN\n");
900 /* VET hardcoded to standard value and VFTA removed in ICH8 LAN */
901 if (hw->mac_type != e1000_ich8lan) {
902 if (hw->mac_type < e1000_82545_rev_3)
903 E1000_WRITE_REG(hw, VET, 0);
904 e1000_clear_vfta(hw);
907 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
908 if (hw->mac_type == e1000_82542_rev2_0) {
909 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
910 e1000_pci_clear_mwi(hw);
911 E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST);
912 E1000_WRITE_FLUSH(hw);
916 /* Setup the receive address. This involves initializing all of the Receive
917 * Address Registers (RARs 0 - 15).
919 e1000_init_rx_addrs(hw);
921 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
922 if (hw->mac_type == e1000_82542_rev2_0) {
923 E1000_WRITE_REG(hw, RCTL, 0);
924 E1000_WRITE_FLUSH(hw);
926 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
927 e1000_pci_set_mwi(hw);
930 /* Zero out the Multicast HASH table */
931 DEBUGOUT("Zeroing the MTA\n");
932 mta_size = E1000_MC_TBL_SIZE;
933 if (hw->mac_type == e1000_ich8lan)
934 mta_size = E1000_MC_TBL_SIZE_ICH8LAN;
935 for (i = 0; i < mta_size; i++) {
936 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
937 /* use write flush to prevent Memory Write Block (MWB) from
938 * occuring when accessing our register space */
939 E1000_WRITE_FLUSH(hw);
942 /* Set the PCI priority bit correctly in the CTRL register. This
943 * determines if the adapter gives priority to receives, or if it
944 * gives equal priority to transmits and receives. Valid only on
945 * 82542 and 82543 silicon.
947 if (hw->dma_fairness && hw->mac_type <= e1000_82543) {
948 ctrl = E1000_READ_REG(hw, CTRL);
949 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PRIOR);
952 switch (hw->mac_type) {
953 case e1000_82545_rev_3:
954 case e1000_82546_rev_3:
957 /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
958 if (hw->bus_type == e1000_bus_type_pcix) {
959 e1000_read_pci_cfg(hw, PCIX_COMMAND_REGISTER, &pcix_cmd_word);
960 e1000_read_pci_cfg(hw, PCIX_STATUS_REGISTER_HI,
962 cmd_mmrbc = (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >>
963 PCIX_COMMAND_MMRBC_SHIFT;
964 stat_mmrbc = (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
965 PCIX_STATUS_HI_MMRBC_SHIFT;
966 if (stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
967 stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
968 if (cmd_mmrbc > stat_mmrbc) {
969 pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK;
970 pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
971 e1000_write_pci_cfg(hw, PCIX_COMMAND_REGISTER,
978 /* More time needed for PHY to initialize */
979 if (hw->mac_type == e1000_ich8lan)
982 /* Call a subroutine to configure the link and setup flow control. */
983 ret_val = e1000_setup_link(hw);
985 /* Set the transmit descriptor write-back policy */
986 if (hw->mac_type > e1000_82544) {
987 ctrl = E1000_READ_REG(hw, TXDCTL);
988 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
989 E1000_WRITE_REG(hw, TXDCTL, ctrl);
992 if (hw->mac_type == e1000_82573) {
993 e1000_enable_tx_pkt_filtering(hw);
996 switch (hw->mac_type) {
999 case e1000_80003es2lan:
1000 /* Enable retransmit on late collisions */
1001 reg_data = E1000_READ_REG(hw, TCTL);
1002 reg_data |= E1000_TCTL_RTLC;
1003 E1000_WRITE_REG(hw, TCTL, reg_data);
1005 /* Configure Gigabit Carry Extend Padding */
1006 reg_data = E1000_READ_REG(hw, TCTL_EXT);
1007 reg_data &= ~E1000_TCTL_EXT_GCEX_MASK;
1008 reg_data |= DEFAULT_80003ES2LAN_TCTL_EXT_GCEX;
1009 E1000_WRITE_REG(hw, TCTL_EXT, reg_data);
1011 /* Configure Transmit Inter-Packet Gap */
1012 reg_data = E1000_READ_REG(hw, TIPG);
1013 reg_data &= ~E1000_TIPG_IPGT_MASK;
1014 reg_data |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
1015 E1000_WRITE_REG(hw, TIPG, reg_data);
1017 reg_data = E1000_READ_REG_ARRAY(hw, FFLT, 0x0001);
1018 reg_data &= ~0x00100000;
1019 E1000_WRITE_REG_ARRAY(hw, FFLT, 0x0001, reg_data);
1024 ctrl = E1000_READ_REG(hw, TXDCTL1);
1025 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
1026 E1000_WRITE_REG(hw, TXDCTL1, ctrl);
1031 if (hw->mac_type == e1000_82573) {
1032 uint32_t gcr = E1000_READ_REG(hw, GCR);
1033 gcr |= E1000_GCR_L1_ACT_WITHOUT_L0S_RX;
1034 E1000_WRITE_REG(hw, GCR, gcr);
1037 /* Clear all of the statistics registers (clear on read). It is
1038 * important that we do this after we have tried to establish link
1039 * because the symbol error count will increment wildly if there
1042 e1000_clear_hw_cntrs(hw);
1044 /* ICH8 No-snoop bits are opposite polarity.
1045 * Set to snoop by default after reset. */
1046 if (hw->mac_type == e1000_ich8lan)
1047 e1000_set_pci_ex_no_snoop(hw, PCI_EX_82566_SNOOP_ALL);
1049 if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER ||
1050 hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) {
1051 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
1052 /* Relaxed ordering must be disabled to avoid a parity
1053 * error crash in a PCI slot. */
1054 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
1055 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1061 /******************************************************************************
1062 * Adjust SERDES output amplitude based on EEPROM setting.
1064 * hw - Struct containing variables accessed by shared code.
1065 *****************************************************************************/
1067 e1000_adjust_serdes_amplitude(struct e1000_hw *hw)
1069 uint16_t eeprom_data;
1072 DEBUGFUNC("e1000_adjust_serdes_amplitude");
1074 if (hw->media_type != e1000_media_type_internal_serdes)
1075 return E1000_SUCCESS;
1077 switch (hw->mac_type) {
1078 case e1000_82545_rev_3:
1079 case e1000_82546_rev_3:
1082 return E1000_SUCCESS;
1085 ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1, &eeprom_data);
1090 if (eeprom_data != EEPROM_RESERVED_WORD) {
1091 /* Adjust SERDES output amplitude only. */
1092 eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK;
1093 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data);
1098 return E1000_SUCCESS;
1101 /******************************************************************************
1102 * Configures flow control and link settings.
1104 * hw - Struct containing variables accessed by shared code
1106 * Determines which flow control settings to use. Calls the apropriate media-
1107 * specific link configuration function. Configures the flow control settings.
1108 * Assuming the adapter has a valid link partner, a valid link should be
1109 * established. Assumes the hardware has previously been reset and the
1110 * transmitter and receiver are not enabled.
1111 *****************************************************************************/
1113 e1000_setup_link(struct e1000_hw *hw)
1117 uint16_t eeprom_data;
1119 DEBUGFUNC("e1000_setup_link");
1121 /* In the case of the phy reset being blocked, we already have a link.
1122 * We do not have to set it up again. */
1123 if (e1000_check_phy_reset_block(hw))
1124 return E1000_SUCCESS;
1126 /* Read and store word 0x0F of the EEPROM. This word contains bits
1127 * that determine the hardware's default PAUSE (flow control) mode,
1128 * a bit that determines whether the HW defaults to enabling or
1129 * disabling auto-negotiation, and the direction of the
1130 * SW defined pins. If there is no SW over-ride of the flow
1131 * control setting, then the variable hw->fc will
1132 * be initialized based on a value in the EEPROM.
1134 if (hw->fc == E1000_FC_DEFAULT) {
1135 switch (hw->mac_type) {
1138 hw->fc = E1000_FC_FULL;
1141 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
1144 DEBUGOUT("EEPROM Read Error\n");
1145 return -E1000_ERR_EEPROM;
1147 if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
1148 hw->fc = E1000_FC_NONE;
1149 else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
1150 EEPROM_WORD0F_ASM_DIR)
1151 hw->fc = E1000_FC_TX_PAUSE;
1153 hw->fc = E1000_FC_FULL;
1158 /* We want to save off the original Flow Control configuration just
1159 * in case we get disconnected and then reconnected into a different
1160 * hub or switch with different Flow Control capabilities.
1162 if (hw->mac_type == e1000_82542_rev2_0)
1163 hw->fc &= (~E1000_FC_TX_PAUSE);
1165 if ((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
1166 hw->fc &= (~E1000_FC_RX_PAUSE);
1168 hw->original_fc = hw->fc;
1170 DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc);
1172 /* Take the 4 bits from EEPROM word 0x0F that determine the initial
1173 * polarity value for the SW controlled pins, and setup the
1174 * Extended Device Control reg with that info.
1175 * This is needed because one of the SW controlled pins is used for
1176 * signal detection. So this should be done before e1000_setup_pcs_link()
1177 * or e1000_phy_setup() is called.
1179 if (hw->mac_type == e1000_82543) {
1180 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
1183 DEBUGOUT("EEPROM Read Error\n");
1184 return -E1000_ERR_EEPROM;
1186 ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
1188 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1191 /* Call the necessary subroutine to configure the link. */
1192 ret_val = (hw->media_type == e1000_media_type_copper) ?
1193 e1000_setup_copper_link(hw) :
1194 e1000_setup_fiber_serdes_link(hw);
1196 /* Initialize the flow control address, type, and PAUSE timer
1197 * registers to their default values. This is done even if flow
1198 * control is disabled, because it does not hurt anything to
1199 * initialize these registers.
1201 DEBUGOUT("Initializing the Flow Control address, type and timer regs\n");
1203 /* FCAL/H and FCT are hardcoded to standard values in e1000_ich8lan. */
1204 if (hw->mac_type != e1000_ich8lan) {
1205 E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
1206 E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
1207 E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
1210 E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
1212 /* Set the flow control receive threshold registers. Normally,
1213 * these registers will be set to a default threshold that may be
1214 * adjusted later by the driver's runtime code. However, if the
1215 * ability to transmit pause frames in not enabled, then these
1216 * registers will be set to 0.
1218 if (!(hw->fc & E1000_FC_TX_PAUSE)) {
1219 E1000_WRITE_REG(hw, FCRTL, 0);
1220 E1000_WRITE_REG(hw, FCRTH, 0);
1222 /* We need to set up the Receive Threshold high and low water marks
1223 * as well as (optionally) enabling the transmission of XON frames.
1225 if (hw->fc_send_xon) {
1226 E1000_WRITE_REG(hw, FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE));
1227 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
1229 E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water);
1230 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
1236 /******************************************************************************
1237 * Sets up link for a fiber based or serdes based adapter
1239 * hw - Struct containing variables accessed by shared code
1241 * Manipulates Physical Coding Sublayer functions in order to configure
1242 * link. Assumes the hardware has been previously reset and the transmitter
1243 * and receiver are not enabled.
1244 *****************************************************************************/
1246 e1000_setup_fiber_serdes_link(struct e1000_hw *hw)
1252 uint32_t signal = 0;
1255 DEBUGFUNC("e1000_setup_fiber_serdes_link");
1257 /* On 82571 and 82572 Fiber connections, SerDes loopback mode persists
1258 * until explicitly turned off or a power cycle is performed. A read to
1259 * the register does not indicate its status. Therefore, we ensure
1260 * loopback mode is disabled during initialization.
1262 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572)
1263 E1000_WRITE_REG(hw, SCTL, E1000_DISABLE_SERDES_LOOPBACK);
1265 /* On adapters with a MAC newer than 82544, SWDP 1 will be
1266 * set when the optics detect a signal. On older adapters, it will be
1267 * cleared when there is a signal. This applies to fiber media only.
1268 * If we're on serdes media, adjust the output amplitude to value
1269 * set in the EEPROM.
1271 ctrl = E1000_READ_REG(hw, CTRL);
1272 if (hw->media_type == e1000_media_type_fiber)
1273 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
1275 ret_val = e1000_adjust_serdes_amplitude(hw);
1279 /* Take the link out of reset */
1280 ctrl &= ~(E1000_CTRL_LRST);
1282 /* Adjust VCO speed to improve BER performance */
1283 ret_val = e1000_set_vco_speed(hw);
1287 e1000_config_collision_dist(hw);
1289 /* Check for a software override of the flow control settings, and setup
1290 * the device accordingly. If auto-negotiation is enabled, then software
1291 * will have to set the "PAUSE" bits to the correct value in the Tranmsit
1292 * Config Word Register (TXCW) and re-start auto-negotiation. However, if
1293 * auto-negotiation is disabled, then software will have to manually
1294 * configure the two flow control enable bits in the CTRL register.
1296 * The possible values of the "fc" parameter are:
1297 * 0: Flow control is completely disabled
1298 * 1: Rx flow control is enabled (we can receive pause frames, but
1299 * not send pause frames).
1300 * 2: Tx flow control is enabled (we can send pause frames but we do
1301 * not support receiving pause frames).
1302 * 3: Both Rx and TX flow control (symmetric) are enabled.
1306 /* Flow control is completely disabled by a software over-ride. */
1307 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
1309 case E1000_FC_RX_PAUSE:
1310 /* RX Flow control is enabled and TX Flow control is disabled by a
1311 * software over-ride. Since there really isn't a way to advertise
1312 * that we are capable of RX Pause ONLY, we will advertise that we
1313 * support both symmetric and asymmetric RX PAUSE. Later, we will
1314 * disable the adapter's ability to send PAUSE frames.
1316 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1318 case E1000_FC_TX_PAUSE:
1319 /* TX Flow control is enabled, and RX Flow control is disabled, by a
1320 * software over-ride.
1322 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
1325 /* Flow control (both RX and TX) is enabled by a software over-ride. */
1326 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1329 DEBUGOUT("Flow control param set incorrectly\n");
1330 return -E1000_ERR_CONFIG;
1334 /* Since auto-negotiation is enabled, take the link out of reset (the link
1335 * will be in reset, because we previously reset the chip). This will
1336 * restart auto-negotiation. If auto-neogtiation is successful then the
1337 * link-up status bit will be set and the flow control enable bits (RFCE
1338 * and TFCE) will be set according to their negotiated value.
1340 DEBUGOUT("Auto-negotiation enabled\n");
1342 E1000_WRITE_REG(hw, TXCW, txcw);
1343 E1000_WRITE_REG(hw, CTRL, ctrl);
1344 E1000_WRITE_FLUSH(hw);
1349 /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
1350 * indication in the Device Status Register. Time-out if a link isn't
1351 * seen in 500 milliseconds seconds (Auto-negotiation should complete in
1352 * less than 500 milliseconds even if the other end is doing it in SW).
1353 * For internal serdes, we just assume a signal is present, then poll.
1355 if (hw->media_type == e1000_media_type_internal_serdes ||
1356 (E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) {
1357 DEBUGOUT("Looking for Link\n");
1358 for (i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
1360 status = E1000_READ_REG(hw, STATUS);
1361 if (status & E1000_STATUS_LU) break;
1363 if (i == (LINK_UP_TIMEOUT / 10)) {
1364 DEBUGOUT("Never got a valid link from auto-neg!!!\n");
1365 hw->autoneg_failed = 1;
1366 /* AutoNeg failed to achieve a link, so we'll call
1367 * e1000_check_for_link. This routine will force the link up if
1368 * we detect a signal. This will allow us to communicate with
1369 * non-autonegotiating link partners.
1371 ret_val = e1000_check_for_link(hw);
1373 DEBUGOUT("Error while checking for link\n");
1376 hw->autoneg_failed = 0;
1378 hw->autoneg_failed = 0;
1379 DEBUGOUT("Valid Link Found\n");
1382 DEBUGOUT("No Signal Detected\n");
1384 return E1000_SUCCESS;
1387 /******************************************************************************
1388 * Make sure we have a valid PHY and change PHY mode before link setup.
1390 * hw - Struct containing variables accessed by shared code
1391 ******************************************************************************/
1393 e1000_copper_link_preconfig(struct e1000_hw *hw)
1399 DEBUGFUNC("e1000_copper_link_preconfig");
1401 ctrl = E1000_READ_REG(hw, CTRL);
1402 /* With 82543, we need to force speed and duplex on the MAC equal to what
1403 * the PHY speed and duplex configuration is. In addition, we need to
1404 * perform a hardware reset on the PHY to take it out of reset.
1406 if (hw->mac_type > e1000_82543) {
1407 ctrl |= E1000_CTRL_SLU;
1408 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1409 E1000_WRITE_REG(hw, CTRL, ctrl);
1411 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
1412 E1000_WRITE_REG(hw, CTRL, ctrl);
1413 ret_val = e1000_phy_hw_reset(hw);
1418 /* Make sure we have a valid PHY */
1419 ret_val = e1000_detect_gig_phy(hw);
1421 DEBUGOUT("Error, did not detect valid phy.\n");
1424 DEBUGOUT1("Phy ID = %x \n", hw->phy_id);
1426 /* Set PHY to class A mode (if necessary) */
1427 ret_val = e1000_set_phy_mode(hw);
1431 if ((hw->mac_type == e1000_82545_rev_3) ||
1432 (hw->mac_type == e1000_82546_rev_3)) {
1433 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1434 phy_data |= 0x00000008;
1435 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1438 if (hw->mac_type <= e1000_82543 ||
1439 hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
1440 hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2)
1441 hw->phy_reset_disable = FALSE;
1443 return E1000_SUCCESS;
1447 /********************************************************************
1448 * Copper link setup for e1000_phy_igp series.
1450 * hw - Struct containing variables accessed by shared code
1451 *********************************************************************/
1453 e1000_copper_link_igp_setup(struct e1000_hw *hw)
1459 DEBUGFUNC("e1000_copper_link_igp_setup");
1461 if (hw->phy_reset_disable)
1462 return E1000_SUCCESS;
1464 ret_val = e1000_phy_reset(hw);
1466 DEBUGOUT("Error Resetting the PHY\n");
1470 /* Wait 15ms for MAC to configure PHY from eeprom settings */
1472 if (hw->mac_type != e1000_ich8lan) {
1473 /* Configure activity LED after PHY reset */
1474 led_ctrl = E1000_READ_REG(hw, LEDCTL);
1475 led_ctrl &= IGP_ACTIVITY_LED_MASK;
1476 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
1477 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
1480 /* The NVM settings will configure LPLU in D3 for IGP2 and IGP3 PHYs */
1481 if (hw->phy_type == e1000_phy_igp) {
1482 /* disable lplu d3 during driver init */
1483 ret_val = e1000_set_d3_lplu_state(hw, FALSE);
1485 DEBUGOUT("Error Disabling LPLU D3\n");
1490 /* disable lplu d0 during driver init */
1491 ret_val = e1000_set_d0_lplu_state(hw, FALSE);
1493 DEBUGOUT("Error Disabling LPLU D0\n");
1496 /* Configure mdi-mdix settings */
1497 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1501 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
1502 hw->dsp_config_state = e1000_dsp_config_disabled;
1503 /* Force MDI for earlier revs of the IGP PHY */
1504 phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX | IGP01E1000_PSCR_FORCE_MDI_MDIX);
1508 hw->dsp_config_state = e1000_dsp_config_enabled;
1509 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1513 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1516 phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
1520 phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
1524 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1528 /* set auto-master slave resolution settings */
1530 e1000_ms_type phy_ms_setting = hw->master_slave;
1532 if (hw->ffe_config_state == e1000_ffe_config_active)
1533 hw->ffe_config_state = e1000_ffe_config_enabled;
1535 if (hw->dsp_config_state == e1000_dsp_config_activated)
1536 hw->dsp_config_state = e1000_dsp_config_enabled;
1538 /* when autonegotiation advertisment is only 1000Mbps then we
1539 * should disable SmartSpeed and enable Auto MasterSlave
1540 * resolution as hardware default. */
1541 if (hw->autoneg_advertised == ADVERTISE_1000_FULL) {
1542 /* Disable SmartSpeed */
1543 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1547 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1548 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1552 /* Set auto Master/Slave resolution process */
1553 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1556 phy_data &= ~CR_1000T_MS_ENABLE;
1557 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1562 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1566 /* load defaults for future use */
1567 hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
1568 ((phy_data & CR_1000T_MS_VALUE) ?
1569 e1000_ms_force_master :
1570 e1000_ms_force_slave) :
1573 switch (phy_ms_setting) {
1574 case e1000_ms_force_master:
1575 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
1577 case e1000_ms_force_slave:
1578 phy_data |= CR_1000T_MS_ENABLE;
1579 phy_data &= ~(CR_1000T_MS_VALUE);
1582 phy_data &= ~CR_1000T_MS_ENABLE;
1586 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1591 return E1000_SUCCESS;
1594 /********************************************************************
1595 * Copper link setup for e1000_phy_gg82563 series.
1597 * hw - Struct containing variables accessed by shared code
1598 *********************************************************************/
1600 e1000_copper_link_ggp_setup(struct e1000_hw *hw)
1606 DEBUGFUNC("e1000_copper_link_ggp_setup");
1608 if (!hw->phy_reset_disable) {
1610 /* Enable CRS on TX for half-duplex operation. */
1611 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL,
1616 phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
1617 /* Use 25MHz for both link down and 1000BASE-T for Tx clock */
1618 phy_data |= GG82563_MSCR_TX_CLK_1000MBPS_25MHZ;
1620 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL,
1626 * MDI/MDI-X = 0 (default)
1627 * 0 - Auto for all speeds
1630 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1632 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_SPEC_CTRL, &phy_data);
1636 phy_data &= ~GG82563_PSCR_CROSSOVER_MODE_MASK;
1640 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDI;
1643 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDIX;
1647 phy_data |= GG82563_PSCR_CROSSOVER_MODE_AUTO;
1652 * disable_polarity_correction = 0 (default)
1653 * Automatic Correction for Reversed Cable Polarity
1657 phy_data &= ~GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
1658 if (hw->disable_polarity_correction == 1)
1659 phy_data |= GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
1660 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_SPEC_CTRL, phy_data);
1665 /* SW Reset the PHY so all changes take effect */
1666 ret_val = e1000_phy_reset(hw);
1668 DEBUGOUT("Error Resetting the PHY\n");
1671 } /* phy_reset_disable */
1673 if (hw->mac_type == e1000_80003es2lan) {
1674 /* Bypass RX and TX FIFO's */
1675 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_FIFO_CTRL,
1676 E1000_KUMCTRLSTA_FIFO_CTRL_RX_BYPASS |
1677 E1000_KUMCTRLSTA_FIFO_CTRL_TX_BYPASS);
1681 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_SPEC_CTRL_2, &phy_data);
1685 phy_data &= ~GG82563_PSCR2_REVERSE_AUTO_NEG;
1686 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_SPEC_CTRL_2, phy_data);
1691 reg_data = E1000_READ_REG(hw, CTRL_EXT);
1692 reg_data &= ~(E1000_CTRL_EXT_LINK_MODE_MASK);
1693 E1000_WRITE_REG(hw, CTRL_EXT, reg_data);
1695 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_PWR_MGMT_CTRL,
1700 /* Do not init these registers when the HW is in IAMT mode, since the
1701 * firmware will have already initialized them. We only initialize
1702 * them if the HW is not in IAMT mode.
1704 if (e1000_check_mng_mode(hw) == FALSE) {
1705 /* Enable Electrical Idle on the PHY */
1706 phy_data |= GG82563_PMCR_ENABLE_ELECTRICAL_IDLE;
1707 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_PWR_MGMT_CTRL,
1712 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
1717 phy_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
1718 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
1725 /* Workaround: Disable padding in Kumeran interface in the MAC
1726 * and in the PHY to avoid CRC errors.
1728 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_INBAND_CTRL,
1732 phy_data |= GG82563_ICR_DIS_PADDING;
1733 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_INBAND_CTRL,
1739 return E1000_SUCCESS;
1742 /********************************************************************
1743 * Copper link setup for e1000_phy_m88 series.
1745 * hw - Struct containing variables accessed by shared code
1746 *********************************************************************/
1748 e1000_copper_link_mgp_setup(struct e1000_hw *hw)
1753 DEBUGFUNC("e1000_copper_link_mgp_setup");
1755 if (hw->phy_reset_disable)
1756 return E1000_SUCCESS;
1758 /* Enable CRS on TX. This must be set for half-duplex operation. */
1759 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1763 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1766 * MDI/MDI-X = 0 (default)
1767 * 0 - Auto for all speeds
1770 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1772 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1776 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
1779 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
1782 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
1786 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
1791 * disable_polarity_correction = 0 (default)
1792 * Automatic Correction for Reversed Cable Polarity
1796 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
1797 if (hw->disable_polarity_correction == 1)
1798 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
1799 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1803 if (hw->phy_revision < M88E1011_I_REV_4) {
1804 /* Force TX_CLK in the Extended PHY Specific Control Register
1807 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1811 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1813 if ((hw->phy_revision == E1000_REVISION_2) &&
1814 (hw->phy_id == M88E1111_I_PHY_ID)) {
1815 /* Vidalia Phy, set the downshift counter to 5x */
1816 phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK);
1817 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
1818 ret_val = e1000_write_phy_reg(hw,
1819 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1823 /* Configure Master and Slave downshift values */
1824 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
1825 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
1826 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
1827 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
1828 ret_val = e1000_write_phy_reg(hw,
1829 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1835 /* SW Reset the PHY so all changes take effect */
1836 ret_val = e1000_phy_reset(hw);
1838 DEBUGOUT("Error Resetting the PHY\n");
1842 return E1000_SUCCESS;
1845 /********************************************************************
1846 * Setup auto-negotiation and flow control advertisements,
1847 * and then perform auto-negotiation.
1849 * hw - Struct containing variables accessed by shared code
1850 *********************************************************************/
1852 e1000_copper_link_autoneg(struct e1000_hw *hw)
1857 DEBUGFUNC("e1000_copper_link_autoneg");
1859 /* Perform some bounds checking on the hw->autoneg_advertised
1860 * parameter. If this variable is zero, then set it to the default.
1862 hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
1864 /* If autoneg_advertised is zero, we assume it was not defaulted
1865 * by the calling code so we set to advertise full capability.
1867 if (hw->autoneg_advertised == 0)
1868 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
1870 /* IFE phy only supports 10/100 */
1871 if (hw->phy_type == e1000_phy_ife)
1872 hw->autoneg_advertised &= AUTONEG_ADVERTISE_10_100_ALL;
1874 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
1875 ret_val = e1000_phy_setup_autoneg(hw);
1877 DEBUGOUT("Error Setting up Auto-Negotiation\n");
1880 DEBUGOUT("Restarting Auto-Neg\n");
1882 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
1883 * the Auto Neg Restart bit in the PHY control register.
1885 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
1889 phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
1890 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
1894 /* Does the user want to wait for Auto-Neg to complete here, or
1895 * check at a later time (for example, callback routine).
1897 if (hw->wait_autoneg_complete) {
1898 ret_val = e1000_wait_autoneg(hw);
1900 DEBUGOUT("Error while waiting for autoneg to complete\n");
1905 hw->get_link_status = TRUE;
1907 return E1000_SUCCESS;
1910 /******************************************************************************
1911 * Config the MAC and the PHY after link is up.
1912 * 1) Set up the MAC to the current PHY speed/duplex
1913 * if we are on 82543. If we
1914 * are on newer silicon, we only need to configure
1915 * collision distance in the Transmit Control Register.
1916 * 2) Set up flow control on the MAC to that established with
1918 * 3) Config DSP to improve Gigabit link quality for some PHY revisions.
1920 * hw - Struct containing variables accessed by shared code
1921 ******************************************************************************/
1923 e1000_copper_link_postconfig(struct e1000_hw *hw)
1926 DEBUGFUNC("e1000_copper_link_postconfig");
1928 if (hw->mac_type >= e1000_82544) {
1929 e1000_config_collision_dist(hw);
1931 ret_val = e1000_config_mac_to_phy(hw);
1933 DEBUGOUT("Error configuring MAC to PHY settings\n");
1937 ret_val = e1000_config_fc_after_link_up(hw);
1939 DEBUGOUT("Error Configuring Flow Control\n");
1943 /* Config DSP to improve Giga link quality */
1944 if (hw->phy_type == e1000_phy_igp) {
1945 ret_val = e1000_config_dsp_after_link_change(hw, TRUE);
1947 DEBUGOUT("Error Configuring DSP after link up\n");
1952 return E1000_SUCCESS;
1955 /******************************************************************************
1956 * Detects which PHY is present and setup the speed and duplex
1958 * hw - Struct containing variables accessed by shared code
1959 ******************************************************************************/
1961 e1000_setup_copper_link(struct e1000_hw *hw)
1968 DEBUGFUNC("e1000_setup_copper_link");
1970 switch (hw->mac_type) {
1971 case e1000_80003es2lan:
1973 /* Set the mac to wait the maximum time between each
1974 * iteration and increase the max iterations when
1975 * polling the phy; this fixes erroneous timeouts at 10Mbps. */
1976 ret_val = e1000_write_kmrn_reg(hw, GG82563_REG(0x34, 4), 0xFFFF);
1979 ret_val = e1000_read_kmrn_reg(hw, GG82563_REG(0x34, 9), ®_data);
1983 ret_val = e1000_write_kmrn_reg(hw, GG82563_REG(0x34, 9), reg_data);
1990 /* Check if it is a valid PHY and set PHY mode if necessary. */
1991 ret_val = e1000_copper_link_preconfig(hw);
1995 switch (hw->mac_type) {
1996 case e1000_80003es2lan:
1997 /* Kumeran registers are written-only */
1998 reg_data = E1000_KUMCTRLSTA_INB_CTRL_LINK_STATUS_TX_TIMEOUT_DEFAULT;
1999 reg_data |= E1000_KUMCTRLSTA_INB_CTRL_DIS_PADDING;
2000 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_INB_CTRL,
2009 if (hw->phy_type == e1000_phy_igp ||
2010 hw->phy_type == e1000_phy_igp_3 ||
2011 hw->phy_type == e1000_phy_igp_2) {
2012 ret_val = e1000_copper_link_igp_setup(hw);
2015 } else if (hw->phy_type == e1000_phy_m88) {
2016 ret_val = e1000_copper_link_mgp_setup(hw);
2019 } else if (hw->phy_type == e1000_phy_gg82563) {
2020 ret_val = e1000_copper_link_ggp_setup(hw);
2026 /* Setup autoneg and flow control advertisement
2027 * and perform autonegotiation */
2028 ret_val = e1000_copper_link_autoneg(hw);
2032 /* PHY will be set to 10H, 10F, 100H,or 100F
2033 * depending on value from forced_speed_duplex. */
2034 DEBUGOUT("Forcing speed and duplex\n");
2035 ret_val = e1000_phy_force_speed_duplex(hw);
2037 DEBUGOUT("Error Forcing Speed and Duplex\n");
2042 /* Check link status. Wait up to 100 microseconds for link to become
2045 for (i = 0; i < 10; i++) {
2046 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2049 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2053 if (phy_data & MII_SR_LINK_STATUS) {
2054 /* Config the MAC and PHY after link is up */
2055 ret_val = e1000_copper_link_postconfig(hw);
2059 DEBUGOUT("Valid link established!!!\n");
2060 return E1000_SUCCESS;
2065 DEBUGOUT("Unable to establish link!!!\n");
2066 return E1000_SUCCESS;
2069 /******************************************************************************
2070 * Configure the MAC-to-PHY interface for 10/100Mbps
2072 * hw - Struct containing variables accessed by shared code
2073 ******************************************************************************/
2075 e1000_configure_kmrn_for_10_100(struct e1000_hw *hw, uint16_t duplex)
2077 int32_t ret_val = E1000_SUCCESS;
2081 DEBUGFUNC("e1000_configure_kmrn_for_10_100");
2083 reg_data = E1000_KUMCTRLSTA_HD_CTRL_10_100_DEFAULT;
2084 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_HD_CTRL,
2089 /* Configure Transmit Inter-Packet Gap */
2090 tipg = E1000_READ_REG(hw, TIPG);
2091 tipg &= ~E1000_TIPG_IPGT_MASK;
2092 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_10_100;
2093 E1000_WRITE_REG(hw, TIPG, tipg);
2095 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, ®_data);
2100 if (duplex == HALF_DUPLEX)
2101 reg_data |= GG82563_KMCR_PASS_FALSE_CARRIER;
2103 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
2105 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
2111 e1000_configure_kmrn_for_1000(struct e1000_hw *hw)
2113 int32_t ret_val = E1000_SUCCESS;
2117 DEBUGFUNC("e1000_configure_kmrn_for_1000");
2119 reg_data = E1000_KUMCTRLSTA_HD_CTRL_1000_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_1000;
2129 E1000_WRITE_REG(hw, TIPG, tipg);
2131 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, ®_data);
2136 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
2137 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
2142 /******************************************************************************
2143 * Configures PHY autoneg and flow control advertisement settings
2145 * hw - Struct containing variables accessed by shared code
2146 ******************************************************************************/
2148 e1000_phy_setup_autoneg(struct e1000_hw *hw)
2151 uint16_t mii_autoneg_adv_reg;
2152 uint16_t mii_1000t_ctrl_reg;
2154 DEBUGFUNC("e1000_phy_setup_autoneg");
2156 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
2157 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
2161 if (hw->phy_type != e1000_phy_ife) {
2162 /* Read the MII 1000Base-T Control Register (Address 9). */
2163 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
2167 mii_1000t_ctrl_reg=0;
2169 /* Need to parse both autoneg_advertised and fc and set up
2170 * the appropriate PHY registers. First we will parse for
2171 * autoneg_advertised software override. Since we can advertise
2172 * a plethora of combinations, we need to check each bit
2176 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
2177 * Advertisement Register (Address 4) and the 1000 mb speed bits in
2178 * the 1000Base-T Control Register (Address 9).
2180 mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
2181 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
2183 DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised);
2185 /* Do we want to advertise 10 Mb Half Duplex? */
2186 if (hw->autoneg_advertised & ADVERTISE_10_HALF) {
2187 DEBUGOUT("Advertise 10mb Half duplex\n");
2188 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
2191 /* Do we want to advertise 10 Mb Full Duplex? */
2192 if (hw->autoneg_advertised & ADVERTISE_10_FULL) {
2193 DEBUGOUT("Advertise 10mb Full duplex\n");
2194 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
2197 /* Do we want to advertise 100 Mb Half Duplex? */
2198 if (hw->autoneg_advertised & ADVERTISE_100_HALF) {
2199 DEBUGOUT("Advertise 100mb Half duplex\n");
2200 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
2203 /* Do we want to advertise 100 Mb Full Duplex? */
2204 if (hw->autoneg_advertised & ADVERTISE_100_FULL) {
2205 DEBUGOUT("Advertise 100mb Full duplex\n");
2206 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
2209 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
2210 if (hw->autoneg_advertised & ADVERTISE_1000_HALF) {
2211 DEBUGOUT("Advertise 1000mb Half duplex requested, request denied!\n");
2214 /* Do we want to advertise 1000 Mb Full Duplex? */
2215 if (hw->autoneg_advertised & ADVERTISE_1000_FULL) {
2216 DEBUGOUT("Advertise 1000mb Full duplex\n");
2217 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
2218 if (hw->phy_type == e1000_phy_ife) {
2219 DEBUGOUT("e1000_phy_ife is a 10/100 PHY. Gigabit speed is not supported.\n");
2223 /* Check for a software override of the flow control settings, and
2224 * setup the PHY advertisement registers accordingly. If
2225 * auto-negotiation is enabled, then software will have to set the
2226 * "PAUSE" bits to the correct value in the Auto-Negotiation
2227 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
2229 * The possible values of the "fc" parameter are:
2230 * 0: Flow control is completely disabled
2231 * 1: Rx flow control is enabled (we can receive pause frames
2232 * but not send pause frames).
2233 * 2: Tx flow control is enabled (we can send pause frames
2234 * but we do not support receiving pause frames).
2235 * 3: Both Rx and TX flow control (symmetric) are enabled.
2236 * other: No software override. The flow control configuration
2237 * in the EEPROM is used.
2240 case E1000_FC_NONE: /* 0 */
2241 /* Flow control (RX & TX) is completely disabled by a
2242 * software over-ride.
2244 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2246 case E1000_FC_RX_PAUSE: /* 1 */
2247 /* RX Flow control is enabled, and TX Flow control is
2248 * disabled, by a software over-ride.
2250 /* Since there really isn't a way to advertise that we are
2251 * capable of RX Pause ONLY, we will advertise that we
2252 * support both symmetric and asymmetric RX PAUSE. Later
2253 * (in e1000_config_fc_after_link_up) we will disable the
2254 *hw's ability to send PAUSE frames.
2256 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2258 case E1000_FC_TX_PAUSE: /* 2 */
2259 /* TX Flow control is enabled, and RX Flow control is
2260 * disabled, by a software over-ride.
2262 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
2263 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
2265 case E1000_FC_FULL: /* 3 */
2266 /* Flow control (both RX and TX) is enabled by a software
2269 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2272 DEBUGOUT("Flow control param set incorrectly\n");
2273 return -E1000_ERR_CONFIG;
2276 ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
2280 DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
2282 if (hw->phy_type != e1000_phy_ife) {
2283 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg);
2288 return E1000_SUCCESS;
2291 /******************************************************************************
2292 * Force PHY speed and duplex settings to hw->forced_speed_duplex
2294 * hw - Struct containing variables accessed by shared code
2295 ******************************************************************************/
2297 e1000_phy_force_speed_duplex(struct e1000_hw *hw)
2301 uint16_t mii_ctrl_reg;
2302 uint16_t mii_status_reg;
2306 DEBUGFUNC("e1000_phy_force_speed_duplex");
2308 /* Turn off Flow control if we are forcing speed and duplex. */
2309 hw->fc = E1000_FC_NONE;
2311 DEBUGOUT1("hw->fc = %d\n", hw->fc);
2313 /* Read the Device Control Register. */
2314 ctrl = E1000_READ_REG(hw, CTRL);
2316 /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */
2317 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2318 ctrl &= ~(DEVICE_SPEED_MASK);
2320 /* Clear the Auto Speed Detect Enable bit. */
2321 ctrl &= ~E1000_CTRL_ASDE;
2323 /* Read the MII Control Register. */
2324 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg);
2328 /* We need to disable autoneg in order to force link and duplex. */
2330 mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN;
2332 /* Are we forcing Full or Half Duplex? */
2333 if (hw->forced_speed_duplex == e1000_100_full ||
2334 hw->forced_speed_duplex == e1000_10_full) {
2335 /* We want to force full duplex so we SET the full duplex bits in the
2336 * Device and MII Control Registers.
2338 ctrl |= E1000_CTRL_FD;
2339 mii_ctrl_reg |= MII_CR_FULL_DUPLEX;
2340 DEBUGOUT("Full Duplex\n");
2342 /* We want to force half duplex so we CLEAR the full duplex bits in
2343 * the Device and MII Control Registers.
2345 ctrl &= ~E1000_CTRL_FD;
2346 mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX;
2347 DEBUGOUT("Half Duplex\n");
2350 /* Are we forcing 100Mbps??? */
2351 if (hw->forced_speed_duplex == e1000_100_full ||
2352 hw->forced_speed_duplex == e1000_100_half) {
2353 /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */
2354 ctrl |= E1000_CTRL_SPD_100;
2355 mii_ctrl_reg |= MII_CR_SPEED_100;
2356 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
2357 DEBUGOUT("Forcing 100mb ");
2359 /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */
2360 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
2361 mii_ctrl_reg |= MII_CR_SPEED_10;
2362 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
2363 DEBUGOUT("Forcing 10mb ");
2366 e1000_config_collision_dist(hw);
2368 /* Write the configured values back to the Device Control Reg. */
2369 E1000_WRITE_REG(hw, CTRL, ctrl);
2371 if ((hw->phy_type == e1000_phy_m88) ||
2372 (hw->phy_type == e1000_phy_gg82563)) {
2373 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
2377 /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
2378 * forced whenever speed are duplex are forced.
2380 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
2381 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
2385 DEBUGOUT1("M88E1000 PSCR: %x \n", phy_data);
2387 /* Need to reset the PHY or these changes will be ignored */
2388 mii_ctrl_reg |= MII_CR_RESET;
2390 /* Disable MDI-X support for 10/100 */
2391 } else if (hw->phy_type == e1000_phy_ife) {
2392 ret_val = e1000_read_phy_reg(hw, IFE_PHY_MDIX_CONTROL, &phy_data);
2396 phy_data &= ~IFE_PMC_AUTO_MDIX;
2397 phy_data &= ~IFE_PMC_FORCE_MDIX;
2399 ret_val = e1000_write_phy_reg(hw, IFE_PHY_MDIX_CONTROL, phy_data);
2404 /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
2405 * forced whenever speed or duplex are forced.
2407 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
2411 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
2412 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
2414 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
2419 /* Write back the modified PHY MII control register. */
2420 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg);
2426 /* The wait_autoneg_complete flag may be a little misleading here.
2427 * Since we are forcing speed and duplex, Auto-Neg is not enabled.
2428 * But we do want to delay for a period while forcing only so we
2429 * don't generate false No Link messages. So we will wait here
2430 * only if the user has set wait_autoneg_complete to 1, which is
2433 if (hw->wait_autoneg_complete) {
2434 /* We will wait for autoneg to complete. */
2435 DEBUGOUT("Waiting for forced speed/duplex link.\n");
2438 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
2439 for (i = PHY_FORCE_TIME; i > 0; i--) {
2440 /* Read the MII Status Register and wait for Auto-Neg Complete bit
2443 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2447 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2451 if (mii_status_reg & MII_SR_LINK_STATUS) break;
2455 ((hw->phy_type == e1000_phy_m88) ||
2456 (hw->phy_type == e1000_phy_gg82563))) {
2457 /* We didn't get link. Reset the DSP and wait again for link. */
2458 ret_val = e1000_phy_reset_dsp(hw);
2460 DEBUGOUT("Error Resetting PHY DSP\n");
2464 /* This loop will early-out if the link condition has been met. */
2465 for (i = PHY_FORCE_TIME; i > 0; i--) {
2466 if (mii_status_reg & MII_SR_LINK_STATUS) break;
2468 /* Read the MII Status Register and wait for Auto-Neg Complete bit
2471 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2475 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2481 if (hw->phy_type == e1000_phy_m88) {
2482 /* Because we reset the PHY above, we need to re-force TX_CLK in the
2483 * Extended PHY Specific Control Register to 25MHz clock. This value
2484 * defaults back to a 2.5MHz clock when the PHY is reset.
2486 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
2490 phy_data |= M88E1000_EPSCR_TX_CLK_25;
2491 ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
2495 /* In addition, because of the s/w reset above, we need to enable CRS on
2496 * TX. This must be set for both full and half duplex operation.
2498 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
2502 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
2503 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
2507 if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
2508 (!hw->autoneg) && (hw->forced_speed_duplex == e1000_10_full ||
2509 hw->forced_speed_duplex == e1000_10_half)) {
2510 ret_val = e1000_polarity_reversal_workaround(hw);
2514 } else if (hw->phy_type == e1000_phy_gg82563) {
2515 /* The TX_CLK of the Extended PHY Specific Control Register defaults
2516 * to 2.5MHz on a reset. We need to re-force it back to 25MHz, if
2517 * we're not in a forced 10/duplex configuration. */
2518 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, &phy_data);
2522 phy_data &= ~GG82563_MSCR_TX_CLK_MASK;
2523 if ((hw->forced_speed_duplex == e1000_10_full) ||
2524 (hw->forced_speed_duplex == e1000_10_half))
2525 phy_data |= GG82563_MSCR_TX_CLK_10MBPS_2_5MHZ;
2527 phy_data |= GG82563_MSCR_TX_CLK_100MBPS_25MHZ;
2529 /* Also due to the reset, we need to enable CRS on Tx. */
2530 phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
2532 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, phy_data);
2536 return E1000_SUCCESS;
2539 /******************************************************************************
2540 * Sets the collision distance in the Transmit Control register
2542 * hw - Struct containing variables accessed by shared code
2544 * Link should have been established previously. Reads the speed and duplex
2545 * information from the Device Status register.
2546 ******************************************************************************/
2548 e1000_config_collision_dist(struct e1000_hw *hw)
2550 uint32_t tctl, coll_dist;
2552 DEBUGFUNC("e1000_config_collision_dist");
2554 if (hw->mac_type < e1000_82543)
2555 coll_dist = E1000_COLLISION_DISTANCE_82542;
2557 coll_dist = E1000_COLLISION_DISTANCE;
2559 tctl = E1000_READ_REG(hw, TCTL);
2561 tctl &= ~E1000_TCTL_COLD;
2562 tctl |= coll_dist << E1000_COLD_SHIFT;
2564 E1000_WRITE_REG(hw, TCTL, tctl);
2565 E1000_WRITE_FLUSH(hw);
2568 /******************************************************************************
2569 * Sets MAC speed and duplex settings to reflect the those in the PHY
2571 * hw - Struct containing variables accessed by shared code
2572 * mii_reg - data to write to the MII control register
2574 * The contents of the PHY register containing the needed information need to
2576 ******************************************************************************/
2578 e1000_config_mac_to_phy(struct e1000_hw *hw)
2584 DEBUGFUNC("e1000_config_mac_to_phy");
2586 /* 82544 or newer MAC, Auto Speed Detection takes care of
2587 * MAC speed/duplex configuration.*/
2588 if (hw->mac_type >= e1000_82544)
2589 return E1000_SUCCESS;
2591 /* Read the Device Control Register and set the bits to Force Speed
2594 ctrl = E1000_READ_REG(hw, CTRL);
2595 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2596 ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
2598 /* Set up duplex in the Device Control and Transmit Control
2599 * registers depending on negotiated values.
2601 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
2605 if (phy_data & M88E1000_PSSR_DPLX)
2606 ctrl |= E1000_CTRL_FD;
2608 ctrl &= ~E1000_CTRL_FD;
2610 e1000_config_collision_dist(hw);
2612 /* Set up speed in the Device Control register depending on
2613 * negotiated values.
2615 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
2616 ctrl |= E1000_CTRL_SPD_1000;
2617 else if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
2618 ctrl |= E1000_CTRL_SPD_100;
2620 /* Write the configured values back to the Device Control Reg. */
2621 E1000_WRITE_REG(hw, CTRL, ctrl);
2622 return E1000_SUCCESS;
2625 /******************************************************************************
2626 * Forces the MAC's flow control settings.
2628 * hw - Struct containing variables accessed by shared code
2630 * Sets the TFCE and RFCE bits in the device control register to reflect
2631 * the adapter settings. TFCE and RFCE need to be explicitly set by
2632 * software when a Copper PHY is used because autonegotiation is managed
2633 * by the PHY rather than the MAC. Software must also configure these
2634 * bits when link is forced on a fiber connection.
2635 *****************************************************************************/
2637 e1000_force_mac_fc(struct e1000_hw *hw)
2641 DEBUGFUNC("e1000_force_mac_fc");
2643 /* Get the current configuration of the Device Control Register */
2644 ctrl = E1000_READ_REG(hw, CTRL);
2646 /* Because we didn't get link via the internal auto-negotiation
2647 * mechanism (we either forced link or we got link via PHY
2648 * auto-neg), we have to manually enable/disable transmit an
2649 * receive flow control.
2651 * The "Case" statement below enables/disable flow control
2652 * according to the "hw->fc" parameter.
2654 * The possible values of the "fc" parameter are:
2655 * 0: Flow control is completely disabled
2656 * 1: Rx flow control is enabled (we can receive pause
2657 * frames but not send pause frames).
2658 * 2: Tx flow control is enabled (we can send pause frames
2659 * frames but we do not receive pause frames).
2660 * 3: Both Rx and TX flow control (symmetric) is enabled.
2661 * other: No other values should be possible at this point.
2666 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
2668 case E1000_FC_RX_PAUSE:
2669 ctrl &= (~E1000_CTRL_TFCE);
2670 ctrl |= E1000_CTRL_RFCE;
2672 case E1000_FC_TX_PAUSE:
2673 ctrl &= (~E1000_CTRL_RFCE);
2674 ctrl |= E1000_CTRL_TFCE;
2677 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
2680 DEBUGOUT("Flow control param set incorrectly\n");
2681 return -E1000_ERR_CONFIG;
2684 /* Disable TX Flow Control for 82542 (rev 2.0) */
2685 if (hw->mac_type == e1000_82542_rev2_0)
2686 ctrl &= (~E1000_CTRL_TFCE);
2688 E1000_WRITE_REG(hw, CTRL, ctrl);
2689 return E1000_SUCCESS;
2692 /******************************************************************************
2693 * Configures flow control settings after link is established
2695 * hw - Struct containing variables accessed by shared code
2697 * Should be called immediately after a valid link has been established.
2698 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
2699 * and autonegotiation is enabled, the MAC flow control settings will be set
2700 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
2701 * and RFCE bits will be automaticaly set to the negotiated flow control mode.
2702 *****************************************************************************/
2704 e1000_config_fc_after_link_up(struct e1000_hw *hw)
2707 uint16_t mii_status_reg;
2708 uint16_t mii_nway_adv_reg;
2709 uint16_t mii_nway_lp_ability_reg;
2713 DEBUGFUNC("e1000_config_fc_after_link_up");
2715 /* Check for the case where we have fiber media and auto-neg failed
2716 * so we had to force link. In this case, we need to force the
2717 * configuration of the MAC to match the "fc" parameter.
2719 if (((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) ||
2720 ((hw->media_type == e1000_media_type_internal_serdes) &&
2721 (hw->autoneg_failed)) ||
2722 ((hw->media_type == e1000_media_type_copper) && (!hw->autoneg))) {
2723 ret_val = e1000_force_mac_fc(hw);
2725 DEBUGOUT("Error forcing flow control settings\n");
2730 /* Check for the case where we have copper media and auto-neg is
2731 * enabled. In this case, we need to check and see if Auto-Neg
2732 * has completed, and if so, how the PHY and link partner has
2733 * flow control configured.
2735 if ((hw->media_type == e1000_media_type_copper) && hw->autoneg) {
2736 /* Read the MII Status Register and check to see if AutoNeg
2737 * has completed. We read this twice because this reg has
2738 * some "sticky" (latched) bits.
2740 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2743 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2747 if (mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
2748 /* The AutoNeg process has completed, so we now need to
2749 * read both the Auto Negotiation Advertisement Register
2750 * (Address 4) and the Auto_Negotiation Base Page Ability
2751 * Register (Address 5) to determine how flow control was
2754 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV,
2758 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY,
2759 &mii_nway_lp_ability_reg);
2763 /* Two bits in the Auto Negotiation Advertisement Register
2764 * (Address 4) and two bits in the Auto Negotiation Base
2765 * Page Ability Register (Address 5) determine flow control
2766 * for both the PHY and the link partner. The following
2767 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
2768 * 1999, describes these PAUSE resolution bits and how flow
2769 * control is determined based upon these settings.
2770 * NOTE: DC = Don't Care
2772 * LOCAL DEVICE | LINK PARTNER
2773 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
2774 *-------|---------|-------|---------|--------------------
2775 * 0 | 0 | DC | DC | E1000_FC_NONE
2776 * 0 | 1 | 0 | DC | E1000_FC_NONE
2777 * 0 | 1 | 1 | 0 | E1000_FC_NONE
2778 * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
2779 * 1 | 0 | 0 | DC | E1000_FC_NONE
2780 * 1 | DC | 1 | DC | E1000_FC_FULL
2781 * 1 | 1 | 0 | 0 | E1000_FC_NONE
2782 * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
2785 /* Are both PAUSE bits set to 1? If so, this implies
2786 * Symmetric Flow Control is enabled at both ends. The
2787 * ASM_DIR bits are irrelevant per the spec.
2789 * For Symmetric Flow Control:
2791 * LOCAL DEVICE | LINK PARTNER
2792 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2793 *-------|---------|-------|---------|--------------------
2794 * 1 | DC | 1 | DC | E1000_FC_FULL
2797 if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2798 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
2799 /* Now we need to check if the user selected RX ONLY
2800 * of pause frames. In this case, we had to advertise
2801 * FULL flow control because we could not advertise RX
2802 * ONLY. Hence, we must now check to see if we need to
2803 * turn OFF the TRANSMISSION of PAUSE frames.
2805 if (hw->original_fc == E1000_FC_FULL) {
2806 hw->fc = E1000_FC_FULL;
2807 DEBUGOUT("Flow Control = FULL.\n");
2809 hw->fc = E1000_FC_RX_PAUSE;
2810 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
2813 /* For receiving PAUSE frames ONLY.
2815 * LOCAL DEVICE | LINK PARTNER
2816 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2817 *-------|---------|-------|---------|--------------------
2818 * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
2821 else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2822 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2823 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2824 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
2825 hw->fc = E1000_FC_TX_PAUSE;
2826 DEBUGOUT("Flow Control = TX PAUSE frames only.\n");
2828 /* For transmitting PAUSE frames ONLY.
2830 * LOCAL DEVICE | LINK PARTNER
2831 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2832 *-------|---------|-------|---------|--------------------
2833 * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
2836 else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2837 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2838 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2839 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
2840 hw->fc = E1000_FC_RX_PAUSE;
2841 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
2843 /* Per the IEEE spec, at this point flow control should be
2844 * disabled. However, we want to consider that we could
2845 * be connected to a legacy switch that doesn't advertise
2846 * desired flow control, but can be forced on the link
2847 * partner. So if we advertised no flow control, that is
2848 * what we will resolve to. If we advertised some kind of
2849 * receive capability (Rx Pause Only or Full Flow Control)
2850 * and the link partner advertised none, we will configure
2851 * ourselves to enable Rx Flow Control only. We can do
2852 * this safely for two reasons: If the link partner really
2853 * didn't want flow control enabled, and we enable Rx, no
2854 * harm done since we won't be receiving any PAUSE frames
2855 * anyway. If the intent on the link partner was to have
2856 * flow control enabled, then by us enabling RX only, we
2857 * can at least receive pause frames and process them.
2858 * This is a good idea because in most cases, since we are
2859 * predominantly a server NIC, more times than not we will
2860 * be asked to delay transmission of packets than asking
2861 * our link partner to pause transmission of frames.
2863 else if ((hw->original_fc == E1000_FC_NONE ||
2864 hw->original_fc == E1000_FC_TX_PAUSE) ||
2865 hw->fc_strict_ieee) {
2866 hw->fc = E1000_FC_NONE;
2867 DEBUGOUT("Flow Control = NONE.\n");
2869 hw->fc = E1000_FC_RX_PAUSE;
2870 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
2873 /* Now we need to do one last check... If we auto-
2874 * negotiated to HALF DUPLEX, flow control should not be
2875 * enabled per IEEE 802.3 spec.
2877 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
2879 DEBUGOUT("Error getting link speed and duplex\n");
2883 if (duplex == HALF_DUPLEX)
2884 hw->fc = E1000_FC_NONE;
2886 /* Now we call a subroutine to actually force the MAC
2887 * controller to use the correct flow control settings.
2889 ret_val = e1000_force_mac_fc(hw);
2891 DEBUGOUT("Error forcing flow control settings\n");
2895 DEBUGOUT("Copper PHY and Auto Neg has not completed.\n");
2898 return E1000_SUCCESS;
2901 /******************************************************************************
2902 * Checks to see if the link status of the hardware has changed.
2904 * hw - Struct containing variables accessed by shared code
2906 * Called by any function that needs to check the link status of the adapter.
2907 *****************************************************************************/
2909 e1000_check_for_link(struct e1000_hw *hw)
2916 uint32_t signal = 0;
2920 DEBUGFUNC("e1000_check_for_link");
2922 ctrl = E1000_READ_REG(hw, CTRL);
2923 status = E1000_READ_REG(hw, STATUS);
2925 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
2926 * set when the optics detect a signal. On older adapters, it will be
2927 * cleared when there is a signal. This applies to fiber media only.
2929 if ((hw->media_type == e1000_media_type_fiber) ||
2930 (hw->media_type == e1000_media_type_internal_serdes)) {
2931 rxcw = E1000_READ_REG(hw, RXCW);
2933 if (hw->media_type == e1000_media_type_fiber) {
2934 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
2935 if (status & E1000_STATUS_LU)
2936 hw->get_link_status = FALSE;
2940 /* If we have a copper PHY then we only want to go out to the PHY
2941 * registers to see if Auto-Neg has completed and/or if our link
2942 * status has changed. The get_link_status flag will be set if we
2943 * receive a Link Status Change interrupt or we have Rx Sequence
2946 if ((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
2947 /* First we want to see if the MII Status Register reports
2948 * link. If so, then we want to get the current speed/duplex
2950 * Read the register twice since the link bit is sticky.
2952 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2955 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2959 if (phy_data & MII_SR_LINK_STATUS) {
2960 hw->get_link_status = FALSE;
2961 /* Check if there was DownShift, must be checked immediately after
2963 e1000_check_downshift(hw);
2965 /* If we are on 82544 or 82543 silicon and speed/duplex
2966 * are forced to 10H or 10F, then we will implement the polarity
2967 * reversal workaround. We disable interrupts first, and upon
2968 * returning, place the devices interrupt state to its previous
2969 * value except for the link status change interrupt which will
2970 * happen due to the execution of this workaround.
2973 if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
2975 (hw->forced_speed_duplex == e1000_10_full ||
2976 hw->forced_speed_duplex == e1000_10_half)) {
2977 E1000_WRITE_REG(hw, IMC, 0xffffffff);
2978 ret_val = e1000_polarity_reversal_workaround(hw);
2979 icr = E1000_READ_REG(hw, ICR);
2980 E1000_WRITE_REG(hw, ICS, (icr & ~E1000_ICS_LSC));
2981 E1000_WRITE_REG(hw, IMS, IMS_ENABLE_MASK);
2985 /* No link detected */
2986 e1000_config_dsp_after_link_change(hw, FALSE);
2990 /* If we are forcing speed/duplex, then we simply return since
2991 * we have already determined whether we have link or not.
2993 if (!hw->autoneg) return -E1000_ERR_CONFIG;
2995 /* optimize the dsp settings for the igp phy */
2996 e1000_config_dsp_after_link_change(hw, TRUE);
2998 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
2999 * have Si on board that is 82544 or newer, Auto
3000 * Speed Detection takes care of MAC speed/duplex
3001 * configuration. So we only need to configure Collision
3002 * Distance in the MAC. Otherwise, we need to force
3003 * speed/duplex on the MAC to the current PHY speed/duplex
3006 if (hw->mac_type >= e1000_82544)
3007 e1000_config_collision_dist(hw);
3009 ret_val = e1000_config_mac_to_phy(hw);
3011 DEBUGOUT("Error configuring MAC to PHY settings\n");
3016 /* Configure Flow Control now that Auto-Neg has completed. First, we
3017 * need to restore the desired flow control settings because we may
3018 * have had to re-autoneg with a different link partner.
3020 ret_val = e1000_config_fc_after_link_up(hw);
3022 DEBUGOUT("Error configuring flow control\n");
3026 /* At this point we know that we are on copper and we have
3027 * auto-negotiated link. These are conditions for checking the link
3028 * partner capability register. We use the link speed to determine if
3029 * TBI compatibility needs to be turned on or off. If the link is not
3030 * at gigabit speed, then TBI compatibility is not needed. If we are
3031 * at gigabit speed, we turn on TBI compatibility.
3033 if (hw->tbi_compatibility_en) {
3034 uint16_t speed, duplex;
3035 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
3037 DEBUGOUT("Error getting link speed and duplex\n");
3040 if (speed != SPEED_1000) {
3041 /* If link speed is not set to gigabit speed, we do not need
3042 * to enable TBI compatibility.
3044 if (hw->tbi_compatibility_on) {
3045 /* If we previously were in the mode, turn it off. */
3046 rctl = E1000_READ_REG(hw, RCTL);
3047 rctl &= ~E1000_RCTL_SBP;
3048 E1000_WRITE_REG(hw, RCTL, rctl);
3049 hw->tbi_compatibility_on = FALSE;
3052 /* If TBI compatibility is was previously off, turn it on. For
3053 * compatibility with a TBI link partner, we will store bad
3054 * packets. Some frames have an additional byte on the end and
3055 * will look like CRC errors to to the hardware.
3057 if (!hw->tbi_compatibility_on) {
3058 hw->tbi_compatibility_on = TRUE;
3059 rctl = E1000_READ_REG(hw, RCTL);
3060 rctl |= E1000_RCTL_SBP;
3061 E1000_WRITE_REG(hw, RCTL, rctl);
3066 /* If we don't have link (auto-negotiation failed or link partner cannot
3067 * auto-negotiate), the cable is plugged in (we have signal), and our
3068 * link partner is not trying to auto-negotiate with us (we are receiving
3069 * idles or data), we need to force link up. We also need to give
3070 * auto-negotiation time to complete, in case the cable was just plugged
3071 * in. The autoneg_failed flag does this.
3073 else if ((((hw->media_type == e1000_media_type_fiber) &&
3074 ((ctrl & E1000_CTRL_SWDPIN1) == signal)) ||
3075 (hw->media_type == e1000_media_type_internal_serdes)) &&
3076 (!(status & E1000_STATUS_LU)) &&
3077 (!(rxcw & E1000_RXCW_C))) {
3078 if (hw->autoneg_failed == 0) {
3079 hw->autoneg_failed = 1;
3082 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\n");
3084 /* Disable auto-negotiation in the TXCW register */
3085 E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
3087 /* Force link-up and also force full-duplex. */
3088 ctrl = E1000_READ_REG(hw, CTRL);
3089 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
3090 E1000_WRITE_REG(hw, CTRL, ctrl);
3092 /* Configure Flow Control after forcing link up. */
3093 ret_val = e1000_config_fc_after_link_up(hw);
3095 DEBUGOUT("Error configuring flow control\n");
3099 /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
3100 * auto-negotiation in the TXCW register and disable forced link in the
3101 * Device Control register in an attempt to auto-negotiate with our link
3104 else if (((hw->media_type == e1000_media_type_fiber) ||
3105 (hw->media_type == e1000_media_type_internal_serdes)) &&
3106 (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
3107 DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\n");
3108 E1000_WRITE_REG(hw, TXCW, hw->txcw);
3109 E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
3111 hw->serdes_link_down = FALSE;
3113 /* If we force link for non-auto-negotiation switch, check link status
3114 * based on MAC synchronization for internal serdes media type.
3116 else if ((hw->media_type == e1000_media_type_internal_serdes) &&
3117 !(E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
3118 /* SYNCH bit and IV bit are sticky. */
3120 if (E1000_RXCW_SYNCH & E1000_READ_REG(hw, RXCW)) {
3121 if (!(rxcw & E1000_RXCW_IV)) {
3122 hw->serdes_link_down = FALSE;
3123 DEBUGOUT("SERDES: Link is up.\n");
3126 hw->serdes_link_down = TRUE;
3127 DEBUGOUT("SERDES: Link is down.\n");
3130 if ((hw->media_type == e1000_media_type_internal_serdes) &&
3131 (E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
3132 hw->serdes_link_down = !(E1000_STATUS_LU & E1000_READ_REG(hw, STATUS));
3134 return E1000_SUCCESS;
3137 /******************************************************************************
3138 * Detects the current speed and duplex settings of the hardware.
3140 * hw - Struct containing variables accessed by shared code
3141 * speed - Speed of the connection
3142 * duplex - Duplex setting of the connection
3143 *****************************************************************************/
3145 e1000_get_speed_and_duplex(struct e1000_hw *hw,
3153 DEBUGFUNC("e1000_get_speed_and_duplex");
3155 if (hw->mac_type >= e1000_82543) {
3156 status = E1000_READ_REG(hw, STATUS);
3157 if (status & E1000_STATUS_SPEED_1000) {
3158 *speed = SPEED_1000;
3159 DEBUGOUT("1000 Mbs, ");
3160 } else if (status & E1000_STATUS_SPEED_100) {
3162 DEBUGOUT("100 Mbs, ");
3165 DEBUGOUT("10 Mbs, ");
3168 if (status & E1000_STATUS_FD) {
3169 *duplex = FULL_DUPLEX;
3170 DEBUGOUT("Full Duplex\n");
3172 *duplex = HALF_DUPLEX;
3173 DEBUGOUT(" Half Duplex\n");
3176 DEBUGOUT("1000 Mbs, Full Duplex\n");
3177 *speed = SPEED_1000;
3178 *duplex = FULL_DUPLEX;
3181 /* IGP01 PHY may advertise full duplex operation after speed downgrade even
3182 * if it is operating at half duplex. Here we set the duplex settings to
3183 * match the duplex in the link partner's capabilities.
3185 if (hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
3186 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
3190 if (!(phy_data & NWAY_ER_LP_NWAY_CAPS))
3191 *duplex = HALF_DUPLEX;
3193 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data);
3196 if ((*speed == SPEED_100 && !(phy_data & NWAY_LPAR_100TX_FD_CAPS)) ||
3197 (*speed == SPEED_10 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
3198 *duplex = HALF_DUPLEX;
3202 if ((hw->mac_type == e1000_80003es2lan) &&
3203 (hw->media_type == e1000_media_type_copper)) {
3204 if (*speed == SPEED_1000)
3205 ret_val = e1000_configure_kmrn_for_1000(hw);
3207 ret_val = e1000_configure_kmrn_for_10_100(hw, *duplex);
3212 if ((hw->phy_type == e1000_phy_igp_3) && (*speed == SPEED_1000)) {
3213 ret_val = e1000_kumeran_lock_loss_workaround(hw);
3218 return E1000_SUCCESS;
3221 /******************************************************************************
3222 * Blocks until autoneg completes or times out (~4.5 seconds)
3224 * hw - Struct containing variables accessed by shared code
3225 ******************************************************************************/
3227 e1000_wait_autoneg(struct e1000_hw *hw)
3233 DEBUGFUNC("e1000_wait_autoneg");
3234 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
3236 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
3237 for (i = PHY_AUTO_NEG_TIME; i > 0; i--) {
3238 /* Read the MII Status Register and wait for Auto-Neg
3239 * Complete bit to be set.
3241 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3244 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3247 if (phy_data & MII_SR_AUTONEG_COMPLETE) {
3248 return E1000_SUCCESS;
3252 return E1000_SUCCESS;
3255 /******************************************************************************
3256 * Raises the Management Data Clock
3258 * hw - Struct containing variables accessed by shared code
3259 * ctrl - Device control register's current value
3260 ******************************************************************************/
3262 e1000_raise_mdi_clk(struct e1000_hw *hw,
3265 /* Raise the clock input to the Management Data Clock (by setting the MDC
3266 * bit), and then delay 10 microseconds.
3268 E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
3269 E1000_WRITE_FLUSH(hw);
3273 /******************************************************************************
3274 * Lowers the Management Data Clock
3276 * hw - Struct containing variables accessed by shared code
3277 * ctrl - Device control register's current value
3278 ******************************************************************************/
3280 e1000_lower_mdi_clk(struct e1000_hw *hw,
3283 /* Lower the clock input to the Management Data Clock (by clearing the MDC
3284 * bit), and then delay 10 microseconds.
3286 E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
3287 E1000_WRITE_FLUSH(hw);
3291 /******************************************************************************
3292 * Shifts data bits out to the PHY
3294 * hw - Struct containing variables accessed by shared code
3295 * data - Data to send out to the PHY
3296 * count - Number of bits to shift out
3298 * Bits are shifted out in MSB to LSB order.
3299 ******************************************************************************/
3301 e1000_shift_out_mdi_bits(struct e1000_hw *hw,
3308 /* We need to shift "count" number of bits out to the PHY. So, the value
3309 * in the "data" parameter will be shifted out to the PHY one bit at a
3310 * time. In order to do this, "data" must be broken down into bits.
3313 mask <<= (count - 1);
3315 ctrl = E1000_READ_REG(hw, CTRL);
3317 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
3318 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
3321 /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
3322 * then raising and lowering the Management Data Clock. A "0" is
3323 * shifted out to the PHY by setting the MDIO bit to "0" and then
3324 * raising and lowering the clock.
3327 ctrl |= E1000_CTRL_MDIO;
3329 ctrl &= ~E1000_CTRL_MDIO;
3331 E1000_WRITE_REG(hw, CTRL, ctrl);
3332 E1000_WRITE_FLUSH(hw);
3336 e1000_raise_mdi_clk(hw, &ctrl);
3337 e1000_lower_mdi_clk(hw, &ctrl);
3343 /******************************************************************************
3344 * Shifts data bits in from the PHY
3346 * hw - Struct containing variables accessed by shared code
3348 * Bits are shifted in in MSB to LSB order.
3349 ******************************************************************************/
3351 e1000_shift_in_mdi_bits(struct e1000_hw *hw)
3357 /* In order to read a register from the PHY, we need to shift in a total
3358 * of 18 bits from the PHY. The first two bit (turnaround) times are used
3359 * to avoid contention on the MDIO pin when a read operation is performed.
3360 * These two bits are ignored by us and thrown away. Bits are "shifted in"
3361 * by raising the input to the Management Data Clock (setting the MDC bit),
3362 * and then reading the value of the MDIO bit.
3364 ctrl = E1000_READ_REG(hw, CTRL);
3366 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
3367 ctrl &= ~E1000_CTRL_MDIO_DIR;
3368 ctrl &= ~E1000_CTRL_MDIO;
3370 E1000_WRITE_REG(hw, CTRL, ctrl);
3371 E1000_WRITE_FLUSH(hw);
3373 /* Raise and Lower the clock before reading in the data. This accounts for
3374 * the turnaround bits. The first clock occurred when we clocked out the
3375 * last bit of the Register Address.
3377 e1000_raise_mdi_clk(hw, &ctrl);
3378 e1000_lower_mdi_clk(hw, &ctrl);
3380 for (data = 0, i = 0; i < 16; i++) {
3382 e1000_raise_mdi_clk(hw, &ctrl);
3383 ctrl = E1000_READ_REG(hw, CTRL);
3384 /* Check to see if we shifted in a "1". */
3385 if (ctrl & E1000_CTRL_MDIO)
3387 e1000_lower_mdi_clk(hw, &ctrl);
3390 e1000_raise_mdi_clk(hw, &ctrl);
3391 e1000_lower_mdi_clk(hw, &ctrl);
3397 e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask)
3399 uint32_t swfw_sync = 0;
3400 uint32_t swmask = mask;
3401 uint32_t fwmask = mask << 16;
3402 int32_t timeout = 200;
3404 DEBUGFUNC("e1000_swfw_sync_acquire");
3406 if (hw->swfwhw_semaphore_present)
3407 return e1000_get_software_flag(hw);
3409 if (!hw->swfw_sync_present)
3410 return e1000_get_hw_eeprom_semaphore(hw);
3413 if (e1000_get_hw_eeprom_semaphore(hw))
3414 return -E1000_ERR_SWFW_SYNC;
3416 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
3417 if (!(swfw_sync & (fwmask | swmask))) {
3421 /* firmware currently using resource (fwmask) */
3422 /* or other software thread currently using resource (swmask) */
3423 e1000_put_hw_eeprom_semaphore(hw);
3429 DEBUGOUT("Driver can't access resource, SW_FW_SYNC timeout.\n");
3430 return -E1000_ERR_SWFW_SYNC;
3433 swfw_sync |= swmask;
3434 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
3436 e1000_put_hw_eeprom_semaphore(hw);
3437 return E1000_SUCCESS;
3441 e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask)
3444 uint32_t swmask = mask;
3446 DEBUGFUNC("e1000_swfw_sync_release");
3448 if (hw->swfwhw_semaphore_present) {
3449 e1000_release_software_flag(hw);
3453 if (!hw->swfw_sync_present) {
3454 e1000_put_hw_eeprom_semaphore(hw);
3458 /* if (e1000_get_hw_eeprom_semaphore(hw))
3459 * return -E1000_ERR_SWFW_SYNC; */
3460 while (e1000_get_hw_eeprom_semaphore(hw) != E1000_SUCCESS);
3463 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
3464 swfw_sync &= ~swmask;
3465 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
3467 e1000_put_hw_eeprom_semaphore(hw);
3470 /*****************************************************************************
3471 * Reads the value from a PHY register, if the value is on a specific non zero
3472 * page, sets the page first.
3473 * hw - Struct containing variables accessed by shared code
3474 * reg_addr - address of the PHY register to read
3475 ******************************************************************************/
3477 e1000_read_phy_reg(struct e1000_hw *hw,
3484 DEBUGFUNC("e1000_read_phy_reg");
3486 if ((hw->mac_type == e1000_80003es2lan) &&
3487 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3488 swfw = E1000_SWFW_PHY1_SM;
3490 swfw = E1000_SWFW_PHY0_SM;
3492 if (e1000_swfw_sync_acquire(hw, swfw))
3493 return -E1000_ERR_SWFW_SYNC;
3495 if ((hw->phy_type == e1000_phy_igp ||
3496 hw->phy_type == e1000_phy_igp_3 ||
3497 hw->phy_type == e1000_phy_igp_2) &&
3498 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
3499 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
3500 (uint16_t)reg_addr);
3502 e1000_swfw_sync_release(hw, swfw);
3505 } else if (hw->phy_type == e1000_phy_gg82563) {
3506 if (((reg_addr & MAX_PHY_REG_ADDRESS) > MAX_PHY_MULTI_PAGE_REG) ||
3507 (hw->mac_type == e1000_80003es2lan)) {
3508 /* Select Configuration Page */
3509 if ((reg_addr & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) {
3510 ret_val = e1000_write_phy_reg_ex(hw, GG82563_PHY_PAGE_SELECT,
3511 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3513 /* Use Alternative Page Select register to access
3514 * registers 30 and 31
3516 ret_val = e1000_write_phy_reg_ex(hw,
3517 GG82563_PHY_PAGE_SELECT_ALT,
3518 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3522 e1000_swfw_sync_release(hw, swfw);
3528 ret_val = e1000_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
3531 e1000_swfw_sync_release(hw, swfw);
3536 e1000_read_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr,
3541 const uint32_t phy_addr = 1;
3543 DEBUGFUNC("e1000_read_phy_reg_ex");
3545 if (reg_addr > MAX_PHY_REG_ADDRESS) {
3546 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
3547 return -E1000_ERR_PARAM;
3550 if (hw->mac_type > e1000_82543) {
3551 /* Set up Op-code, Phy Address, and register address in the MDI
3552 * Control register. The MAC will take care of interfacing with the
3553 * PHY to retrieve the desired data.
3555 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
3556 (phy_addr << E1000_MDIC_PHY_SHIFT) |
3557 (E1000_MDIC_OP_READ));
3559 E1000_WRITE_REG(hw, MDIC, mdic);
3561 /* Poll the ready bit to see if the MDI read completed */
3562 for (i = 0; i < 64; i++) {
3564 mdic = E1000_READ_REG(hw, MDIC);
3565 if (mdic & E1000_MDIC_READY) break;
3567 if (!(mdic & E1000_MDIC_READY)) {
3568 DEBUGOUT("MDI Read did not complete\n");
3569 return -E1000_ERR_PHY;
3571 if (mdic & E1000_MDIC_ERROR) {
3572 DEBUGOUT("MDI Error\n");
3573 return -E1000_ERR_PHY;
3575 *phy_data = (uint16_t) mdic;
3577 /* We must first send a preamble through the MDIO pin to signal the
3578 * beginning of an MII instruction. This is done by sending 32
3579 * consecutive "1" bits.
3581 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
3583 /* Now combine the next few fields that are required for a read
3584 * operation. We use this method instead of calling the
3585 * e1000_shift_out_mdi_bits routine five different times. The format of
3586 * a MII read instruction consists of a shift out of 14 bits and is
3587 * defined as follows:
3588 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
3589 * followed by a shift in of 18 bits. This first two bits shifted in
3590 * are TurnAround bits used to avoid contention on the MDIO pin when a
3591 * READ operation is performed. These two bits are thrown away
3592 * followed by a shift in of 16 bits which contains the desired data.
3594 mdic = ((reg_addr) | (phy_addr << 5) |
3595 (PHY_OP_READ << 10) | (PHY_SOF << 12));
3597 e1000_shift_out_mdi_bits(hw, mdic, 14);
3599 /* Now that we've shifted out the read command to the MII, we need to
3600 * "shift in" the 16-bit value (18 total bits) of the requested PHY
3603 *phy_data = e1000_shift_in_mdi_bits(hw);
3605 return E1000_SUCCESS;
3608 /******************************************************************************
3609 * Writes a value to a PHY register
3611 * hw - Struct containing variables accessed by shared code
3612 * reg_addr - address of the PHY register to write
3613 * data - data to write to the PHY
3614 ******************************************************************************/
3616 e1000_write_phy_reg(struct e1000_hw *hw, uint32_t reg_addr,
3622 DEBUGFUNC("e1000_write_phy_reg");
3624 if ((hw->mac_type == e1000_80003es2lan) &&
3625 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3626 swfw = E1000_SWFW_PHY1_SM;
3628 swfw = E1000_SWFW_PHY0_SM;
3630 if (e1000_swfw_sync_acquire(hw, swfw))
3631 return -E1000_ERR_SWFW_SYNC;
3633 if ((hw->phy_type == e1000_phy_igp ||
3634 hw->phy_type == e1000_phy_igp_3 ||
3635 hw->phy_type == e1000_phy_igp_2) &&
3636 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
3637 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
3638 (uint16_t)reg_addr);
3640 e1000_swfw_sync_release(hw, swfw);
3643 } else if (hw->phy_type == e1000_phy_gg82563) {
3644 if (((reg_addr & MAX_PHY_REG_ADDRESS) > MAX_PHY_MULTI_PAGE_REG) ||
3645 (hw->mac_type == e1000_80003es2lan)) {
3646 /* Select Configuration Page */
3647 if ((reg_addr & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) {
3648 ret_val = e1000_write_phy_reg_ex(hw, GG82563_PHY_PAGE_SELECT,
3649 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3651 /* Use Alternative Page Select register to access
3652 * registers 30 and 31
3654 ret_val = e1000_write_phy_reg_ex(hw,
3655 GG82563_PHY_PAGE_SELECT_ALT,
3656 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3660 e1000_swfw_sync_release(hw, swfw);
3666 ret_val = e1000_write_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
3669 e1000_swfw_sync_release(hw, swfw);
3674 e1000_write_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr,
3679 const uint32_t phy_addr = 1;
3681 DEBUGFUNC("e1000_write_phy_reg_ex");
3683 if (reg_addr > MAX_PHY_REG_ADDRESS) {
3684 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
3685 return -E1000_ERR_PARAM;
3688 if (hw->mac_type > e1000_82543) {
3689 /* Set up Op-code, Phy Address, register address, and data intended
3690 * for the PHY register in the MDI Control register. The MAC will take
3691 * care of interfacing with the PHY to send the desired data.
3693 mdic = (((uint32_t) phy_data) |
3694 (reg_addr << E1000_MDIC_REG_SHIFT) |
3695 (phy_addr << E1000_MDIC_PHY_SHIFT) |
3696 (E1000_MDIC_OP_WRITE));
3698 E1000_WRITE_REG(hw, MDIC, mdic);
3700 /* Poll the ready bit to see if the MDI read completed */
3701 for (i = 0; i < 641; i++) {
3703 mdic = E1000_READ_REG(hw, MDIC);
3704 if (mdic & E1000_MDIC_READY) break;
3706 if (!(mdic & E1000_MDIC_READY)) {
3707 DEBUGOUT("MDI Write did not complete\n");
3708 return -E1000_ERR_PHY;
3711 /* We'll need to use the SW defined pins to shift the write command
3712 * out to the PHY. We first send a preamble to the PHY to signal the
3713 * beginning of the MII instruction. This is done by sending 32
3714 * consecutive "1" bits.
3716 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
3718 /* Now combine the remaining required fields that will indicate a
3719 * write operation. We use this method instead of calling the
3720 * e1000_shift_out_mdi_bits routine for each field in the command. The
3721 * format of a MII write instruction is as follows:
3722 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
3724 mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
3725 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
3727 mdic |= (uint32_t) phy_data;
3729 e1000_shift_out_mdi_bits(hw, mdic, 32);
3732 return E1000_SUCCESS;
3736 e1000_read_kmrn_reg(struct e1000_hw *hw,
3742 DEBUGFUNC("e1000_read_kmrn_reg");
3744 if ((hw->mac_type == e1000_80003es2lan) &&
3745 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3746 swfw = E1000_SWFW_PHY1_SM;
3748 swfw = E1000_SWFW_PHY0_SM;
3750 if (e1000_swfw_sync_acquire(hw, swfw))
3751 return -E1000_ERR_SWFW_SYNC;
3753 /* Write register address */
3754 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
3755 E1000_KUMCTRLSTA_OFFSET) |
3756 E1000_KUMCTRLSTA_REN;
3757 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
3760 /* Read the data returned */
3761 reg_val = E1000_READ_REG(hw, KUMCTRLSTA);
3762 *data = (uint16_t)reg_val;
3764 e1000_swfw_sync_release(hw, swfw);
3765 return E1000_SUCCESS;
3769 e1000_write_kmrn_reg(struct e1000_hw *hw,
3775 DEBUGFUNC("e1000_write_kmrn_reg");
3777 if ((hw->mac_type == e1000_80003es2lan) &&
3778 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3779 swfw = E1000_SWFW_PHY1_SM;
3781 swfw = E1000_SWFW_PHY0_SM;
3783 if (e1000_swfw_sync_acquire(hw, swfw))
3784 return -E1000_ERR_SWFW_SYNC;
3786 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
3787 E1000_KUMCTRLSTA_OFFSET) | data;
3788 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
3791 e1000_swfw_sync_release(hw, swfw);
3792 return E1000_SUCCESS;
3795 /******************************************************************************
3796 * Returns the PHY to the power-on reset state
3798 * hw - Struct containing variables accessed by shared code
3799 ******************************************************************************/
3801 e1000_phy_hw_reset(struct e1000_hw *hw)
3803 uint32_t ctrl, ctrl_ext;
3808 DEBUGFUNC("e1000_phy_hw_reset");
3810 /* In the case of the phy reset being blocked, it's not an error, we
3811 * simply return success without performing the reset. */
3812 ret_val = e1000_check_phy_reset_block(hw);
3814 return E1000_SUCCESS;
3816 DEBUGOUT("Resetting Phy...\n");
3818 if (hw->mac_type > e1000_82543) {
3819 if ((hw->mac_type == e1000_80003es2lan) &&
3820 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3821 swfw = E1000_SWFW_PHY1_SM;
3823 swfw = E1000_SWFW_PHY0_SM;
3825 if (e1000_swfw_sync_acquire(hw, swfw)) {
3826 DEBUGOUT("Unable to acquire swfw sync\n");
3827 return -E1000_ERR_SWFW_SYNC;
3829 /* Read the device control register and assert the E1000_CTRL_PHY_RST
3830 * bit. Then, take it out of reset.
3831 * For pre-e1000_82571 hardware, we delay for 10ms between the assert
3832 * and deassert. For e1000_82571 hardware and later, we instead delay
3833 * for 50us between and 10ms after the deassertion.
3835 ctrl = E1000_READ_REG(hw, CTRL);
3836 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST);
3837 E1000_WRITE_FLUSH(hw);
3839 if (hw->mac_type < e1000_82571)
3844 E1000_WRITE_REG(hw, CTRL, ctrl);
3845 E1000_WRITE_FLUSH(hw);
3847 if (hw->mac_type >= e1000_82571)
3850 e1000_swfw_sync_release(hw, swfw);
3852 /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
3853 * bit to put the PHY into reset. Then, take it out of reset.
3855 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
3856 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
3857 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
3858 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
3859 E1000_WRITE_FLUSH(hw);
3861 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
3862 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
3863 E1000_WRITE_FLUSH(hw);
3867 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
3868 /* Configure activity LED after PHY reset */
3869 led_ctrl = E1000_READ_REG(hw, LEDCTL);
3870 led_ctrl &= IGP_ACTIVITY_LED_MASK;
3871 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
3872 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
3875 /* Wait for FW to finish PHY configuration. */
3876 ret_val = e1000_get_phy_cfg_done(hw);
3877 if (ret_val != E1000_SUCCESS)
3879 e1000_release_software_semaphore(hw);
3881 if ((hw->mac_type == e1000_ich8lan) && (hw->phy_type == e1000_phy_igp_3))
3882 ret_val = e1000_init_lcd_from_nvm(hw);
3887 /******************************************************************************
3890 * hw - Struct containing variables accessed by shared code
3892 * Sets bit 15 of the MII Control register
3893 ******************************************************************************/
3895 e1000_phy_reset(struct e1000_hw *hw)
3900 DEBUGFUNC("e1000_phy_reset");
3902 /* In the case of the phy reset being blocked, it's not an error, we
3903 * simply return success without performing the reset. */
3904 ret_val = e1000_check_phy_reset_block(hw);
3906 return E1000_SUCCESS;
3908 switch (hw->phy_type) {
3910 case e1000_phy_igp_2:
3911 case e1000_phy_igp_3:
3913 ret_val = e1000_phy_hw_reset(hw);
3918 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
3922 phy_data |= MII_CR_RESET;
3923 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
3931 if (hw->phy_type == e1000_phy_igp || hw->phy_type == e1000_phy_igp_2)
3932 e1000_phy_init_script(hw);
3934 return E1000_SUCCESS;
3937 /******************************************************************************
3938 * Work-around for 82566 power-down: on D3 entry-
3939 * 1) disable gigabit link
3940 * 2) write VR power-down enable
3942 * if successful continue, else issue LCD reset and repeat
3944 * hw - struct containing variables accessed by shared code
3945 ******************************************************************************/
3947 e1000_phy_powerdown_workaround(struct e1000_hw *hw)
3953 DEBUGFUNC("e1000_phy_powerdown_workaround");
3955 if (hw->phy_type != e1000_phy_igp_3)
3960 reg = E1000_READ_REG(hw, PHY_CTRL);
3961 E1000_WRITE_REG(hw, PHY_CTRL, reg | E1000_PHY_CTRL_GBE_DISABLE |
3962 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
3964 /* Write VR power-down enable - bits 9:8 should be 10b */
3965 e1000_read_phy_reg(hw, IGP3_VR_CTRL, &phy_data);
3966 phy_data |= (1 << 9);
3967 phy_data &= ~(1 << 8);
3968 e1000_write_phy_reg(hw, IGP3_VR_CTRL, phy_data);
3970 /* Read it back and test */
3971 e1000_read_phy_reg(hw, IGP3_VR_CTRL, &phy_data);
3972 if (((phy_data & IGP3_VR_CTRL_MODE_MASK) == IGP3_VR_CTRL_MODE_SHUT) || retry)
3975 /* Issue PHY reset and repeat at most one more time */
3976 reg = E1000_READ_REG(hw, CTRL);
3977 E1000_WRITE_REG(hw, CTRL, reg | E1000_CTRL_PHY_RST);
3985 /******************************************************************************
3986 * Work-around for 82566 Kumeran PCS lock loss:
3987 * On link status change (i.e. PCI reset, speed change) and link is up and
3989 * 0) if workaround is optionally disabled do nothing
3990 * 1) wait 1ms for Kumeran link to come up
3991 * 2) check Kumeran Diagnostic register PCS lock loss bit
3992 * 3) if not set the link is locked (all is good), otherwise...
3994 * 5) repeat up to 10 times
3995 * Note: this is only called for IGP3 copper when speed is 1gb.
3997 * hw - struct containing variables accessed by shared code
3998 ******************************************************************************/
4000 e1000_kumeran_lock_loss_workaround(struct e1000_hw *hw)
4007 if (hw->kmrn_lock_loss_workaround_disabled)
4008 return E1000_SUCCESS;
4010 /* Make sure link is up before proceeding. If not just return.
4011 * Attempting this while link is negotiating fouled up link
4013 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
4014 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
4016 if (phy_data & MII_SR_LINK_STATUS) {
4017 for (cnt = 0; cnt < 10; cnt++) {
4018 /* read once to clear */
4019 ret_val = e1000_read_phy_reg(hw, IGP3_KMRN_DIAG, &phy_data);
4022 /* and again to get new status */
4023 ret_val = e1000_read_phy_reg(hw, IGP3_KMRN_DIAG, &phy_data);
4027 /* check for PCS lock */
4028 if (!(phy_data & IGP3_KMRN_DIAG_PCS_LOCK_LOSS))
4029 return E1000_SUCCESS;
4031 /* Issue PHY reset */
4032 e1000_phy_hw_reset(hw);
4035 /* Disable GigE link negotiation */
4036 reg = E1000_READ_REG(hw, PHY_CTRL);
4037 E1000_WRITE_REG(hw, PHY_CTRL, reg | E1000_PHY_CTRL_GBE_DISABLE |
4038 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
4040 /* unable to acquire PCS lock */
4041 return E1000_ERR_PHY;
4044 return E1000_SUCCESS;
4047 /******************************************************************************
4048 * Probes the expected PHY address for known PHY IDs
4050 * hw - Struct containing variables accessed by shared code
4051 ******************************************************************************/
4053 e1000_detect_gig_phy(struct e1000_hw *hw)
4055 int32_t phy_init_status, ret_val;
4056 uint16_t phy_id_high, phy_id_low;
4057 boolean_t match = FALSE;
4059 DEBUGFUNC("e1000_detect_gig_phy");
4061 if (hw->phy_id != 0)
4062 return E1000_SUCCESS;
4064 /* The 82571 firmware may still be configuring the PHY. In this
4065 * case, we cannot access the PHY until the configuration is done. So
4066 * we explicitly set the PHY values. */
4067 if (hw->mac_type == e1000_82571 ||
4068 hw->mac_type == e1000_82572) {
4069 hw->phy_id = IGP01E1000_I_PHY_ID;
4070 hw->phy_type = e1000_phy_igp_2;
4071 return E1000_SUCCESS;
4074 /* ESB-2 PHY reads require e1000_phy_gg82563 to be set because of a work-
4075 * around that forces PHY page 0 to be set or the reads fail. The rest of
4076 * the code in this routine uses e1000_read_phy_reg to read the PHY ID.
4077 * So for ESB-2 we need to have this set so our reads won't fail. If the
4078 * attached PHY is not a e1000_phy_gg82563, the routines below will figure
4079 * this out as well. */
4080 if (hw->mac_type == e1000_80003es2lan)
4081 hw->phy_type = e1000_phy_gg82563;
4083 /* Read the PHY ID Registers to identify which PHY is onboard. */
4084 ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
4088 hw->phy_id = (uint32_t) (phy_id_high << 16);
4090 ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
4094 hw->phy_id |= (uint32_t) (phy_id_low & PHY_REVISION_MASK);
4095 hw->phy_revision = (uint32_t) phy_id_low & ~PHY_REVISION_MASK;
4097 switch (hw->mac_type) {
4099 if (hw->phy_id == M88E1000_E_PHY_ID) match = TRUE;
4102 if (hw->phy_id == M88E1000_I_PHY_ID) match = TRUE;
4106 case e1000_82545_rev_3:
4108 case e1000_82546_rev_3:
4109 if (hw->phy_id == M88E1011_I_PHY_ID) match = TRUE;
4112 case e1000_82541_rev_2:
4114 case e1000_82547_rev_2:
4115 if (hw->phy_id == IGP01E1000_I_PHY_ID) match = TRUE;
4118 if (hw->phy_id == M88E1111_I_PHY_ID) match = TRUE;
4120 case e1000_80003es2lan:
4121 if (hw->phy_id == GG82563_E_PHY_ID) match = TRUE;
4124 if (hw->phy_id == IGP03E1000_E_PHY_ID) match = TRUE;
4125 if (hw->phy_id == IFE_E_PHY_ID) match = TRUE;
4126 if (hw->phy_id == IFE_PLUS_E_PHY_ID) match = TRUE;
4127 if (hw->phy_id == IFE_C_E_PHY_ID) match = TRUE;
4130 DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type);
4131 return -E1000_ERR_CONFIG;
4133 phy_init_status = e1000_set_phy_type(hw);
4135 if ((match) && (phy_init_status == E1000_SUCCESS)) {
4136 DEBUGOUT1("PHY ID 0x%X detected\n", hw->phy_id);
4137 return E1000_SUCCESS;
4139 DEBUGOUT1("Invalid PHY ID 0x%X\n", hw->phy_id);
4140 return -E1000_ERR_PHY;
4143 /******************************************************************************
4144 * Resets the PHY's DSP
4146 * hw - Struct containing variables accessed by shared code
4147 ******************************************************************************/
4149 e1000_phy_reset_dsp(struct e1000_hw *hw)
4152 DEBUGFUNC("e1000_phy_reset_dsp");
4155 if (hw->phy_type != e1000_phy_gg82563) {
4156 ret_val = e1000_write_phy_reg(hw, 29, 0x001d);
4159 ret_val = e1000_write_phy_reg(hw, 30, 0x00c1);
4161 ret_val = e1000_write_phy_reg(hw, 30, 0x0000);
4163 ret_val = E1000_SUCCESS;
4169 /******************************************************************************
4170 * Get PHY information from various PHY registers for igp PHY only.
4172 * hw - Struct containing variables accessed by shared code
4173 * phy_info - PHY information structure
4174 ******************************************************************************/
4176 e1000_phy_igp_get_info(struct e1000_hw *hw,
4177 struct e1000_phy_info *phy_info)
4180 uint16_t phy_data, min_length, max_length, average;
4181 e1000_rev_polarity polarity;
4183 DEBUGFUNC("e1000_phy_igp_get_info");
4185 /* The downshift status is checked only once, after link is established,
4186 * and it stored in the hw->speed_downgraded parameter. */
4187 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
4189 /* IGP01E1000 does not need to support it. */
4190 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
4192 /* IGP01E1000 always correct polarity reversal */
4193 phy_info->polarity_correction = e1000_polarity_reversal_enabled;
4195 /* Check polarity status */
4196 ret_val = e1000_check_polarity(hw, &polarity);
4200 phy_info->cable_polarity = polarity;
4202 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, &phy_data);
4206 phy_info->mdix_mode = (e1000_auto_x_mode)((phy_data & IGP01E1000_PSSR_MDIX) >>
4207 IGP01E1000_PSSR_MDIX_SHIFT);
4209 if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
4210 IGP01E1000_PSSR_SPEED_1000MBPS) {
4211 /* Local/Remote Receiver Information are only valid at 1000 Mbps */
4212 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
4216 phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
4217 SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
4218 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
4219 phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
4220 SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
4221 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
4223 /* Get cable length */
4224 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
4228 /* Translate to old method */
4229 average = (max_length + min_length) / 2;
4231 if (average <= e1000_igp_cable_length_50)
4232 phy_info->cable_length = e1000_cable_length_50;
4233 else if (average <= e1000_igp_cable_length_80)
4234 phy_info->cable_length = e1000_cable_length_50_80;
4235 else if (average <= e1000_igp_cable_length_110)
4236 phy_info->cable_length = e1000_cable_length_80_110;
4237 else if (average <= e1000_igp_cable_length_140)
4238 phy_info->cable_length = e1000_cable_length_110_140;
4240 phy_info->cable_length = e1000_cable_length_140;
4243 return E1000_SUCCESS;
4246 /******************************************************************************
4247 * Get PHY information from various PHY registers for ife PHY only.
4249 * hw - Struct containing variables accessed by shared code
4250 * phy_info - PHY information structure
4251 ******************************************************************************/
4253 e1000_phy_ife_get_info(struct e1000_hw *hw,
4254 struct e1000_phy_info *phy_info)
4258 e1000_rev_polarity polarity;
4260 DEBUGFUNC("e1000_phy_ife_get_info");
4262 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
4263 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
4265 ret_val = e1000_read_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL, &phy_data);
4268 phy_info->polarity_correction =
4269 ((phy_data & IFE_PSC_AUTO_POLARITY_DISABLE) >>
4270 IFE_PSC_AUTO_POLARITY_DISABLE_SHIFT) ?
4271 e1000_polarity_reversal_disabled : e1000_polarity_reversal_enabled;
4273 if (phy_info->polarity_correction == e1000_polarity_reversal_enabled) {
4274 ret_val = e1000_check_polarity(hw, &polarity);
4278 /* Polarity is forced. */
4279 polarity = ((phy_data & IFE_PSC_FORCE_POLARITY) >>
4280 IFE_PSC_FORCE_POLARITY_SHIFT) ?
4281 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
4283 phy_info->cable_polarity = polarity;
4285 ret_val = e1000_read_phy_reg(hw, IFE_PHY_MDIX_CONTROL, &phy_data);
4289 phy_info->mdix_mode = (e1000_auto_x_mode)
4290 ((phy_data & (IFE_PMC_AUTO_MDIX | IFE_PMC_FORCE_MDIX)) >>
4291 IFE_PMC_MDIX_MODE_SHIFT);
4293 return E1000_SUCCESS;
4296 /******************************************************************************
4297 * Get PHY information from various PHY registers fot m88 PHY only.
4299 * hw - Struct containing variables accessed by shared code
4300 * phy_info - PHY information structure
4301 ******************************************************************************/
4303 e1000_phy_m88_get_info(struct e1000_hw *hw,
4304 struct e1000_phy_info *phy_info)
4308 e1000_rev_polarity polarity;
4310 DEBUGFUNC("e1000_phy_m88_get_info");
4312 /* The downshift status is checked only once, after link is established,
4313 * and it stored in the hw->speed_downgraded parameter. */
4314 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
4316 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
4320 phy_info->extended_10bt_distance =
4321 ((phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >>
4322 M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT) ?
4323 e1000_10bt_ext_dist_enable_lower : e1000_10bt_ext_dist_enable_normal;
4325 phy_info->polarity_correction =
4326 ((phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >>
4327 M88E1000_PSCR_POLARITY_REVERSAL_SHIFT) ?
4328 e1000_polarity_reversal_disabled : e1000_polarity_reversal_enabled;
4330 /* Check polarity status */
4331 ret_val = e1000_check_polarity(hw, &polarity);
4334 phy_info->cable_polarity = polarity;
4336 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
4340 phy_info->mdix_mode = (e1000_auto_x_mode)((phy_data & M88E1000_PSSR_MDIX) >>
4341 M88E1000_PSSR_MDIX_SHIFT);
4343 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
4344 /* Cable Length Estimation and Local/Remote Receiver Information
4345 * are only valid at 1000 Mbps.
4347 if (hw->phy_type != e1000_phy_gg82563) {
4348 phy_info->cable_length = (e1000_cable_length)((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
4349 M88E1000_PSSR_CABLE_LENGTH_SHIFT);
4351 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_DSP_DISTANCE,
4356 phy_info->cable_length = (e1000_cable_length)(phy_data & GG82563_DSPD_CABLE_LENGTH);
4359 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
4363 phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
4364 SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
4365 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
4366 phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
4367 SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
4368 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
4372 return E1000_SUCCESS;
4375 /******************************************************************************
4376 * Get PHY information from various PHY registers
4378 * hw - Struct containing variables accessed by shared code
4379 * phy_info - PHY information structure
4380 ******************************************************************************/
4382 e1000_phy_get_info(struct e1000_hw *hw,
4383 struct e1000_phy_info *phy_info)
4388 DEBUGFUNC("e1000_phy_get_info");
4390 phy_info->cable_length = e1000_cable_length_undefined;
4391 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined;
4392 phy_info->cable_polarity = e1000_rev_polarity_undefined;
4393 phy_info->downshift = e1000_downshift_undefined;
4394 phy_info->polarity_correction = e1000_polarity_reversal_undefined;
4395 phy_info->mdix_mode = e1000_auto_x_mode_undefined;
4396 phy_info->local_rx = e1000_1000t_rx_status_undefined;
4397 phy_info->remote_rx = e1000_1000t_rx_status_undefined;
4399 if (hw->media_type != e1000_media_type_copper) {
4400 DEBUGOUT("PHY info is only valid for copper media\n");
4401 return -E1000_ERR_CONFIG;
4404 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
4408 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
4412 if ((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) {
4413 DEBUGOUT("PHY info is only valid if link is up\n");
4414 return -E1000_ERR_CONFIG;
4417 if (hw->phy_type == e1000_phy_igp ||
4418 hw->phy_type == e1000_phy_igp_3 ||
4419 hw->phy_type == e1000_phy_igp_2)
4420 return e1000_phy_igp_get_info(hw, phy_info);
4421 else if (hw->phy_type == e1000_phy_ife)
4422 return e1000_phy_ife_get_info(hw, phy_info);
4424 return e1000_phy_m88_get_info(hw, phy_info);
4428 e1000_validate_mdi_setting(struct e1000_hw *hw)
4430 DEBUGFUNC("e1000_validate_mdi_settings");
4432 if (!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) {
4433 DEBUGOUT("Invalid MDI setting detected\n");
4435 return -E1000_ERR_CONFIG;
4437 return E1000_SUCCESS;
4441 /******************************************************************************
4442 * Sets up eeprom variables in the hw struct. Must be called after mac_type
4443 * is configured. Additionally, if this is ICH8, the flash controller GbE
4444 * registers must be mapped, or this will crash.
4446 * hw - Struct containing variables accessed by shared code
4447 *****************************************************************************/
4449 e1000_init_eeprom_params(struct e1000_hw *hw)
4451 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4452 uint32_t eecd = E1000_READ_REG(hw, EECD);
4453 int32_t ret_val = E1000_SUCCESS;
4454 uint16_t eeprom_size;
4456 DEBUGFUNC("e1000_init_eeprom_params");
4458 switch (hw->mac_type) {
4459 case e1000_82542_rev2_0:
4460 case e1000_82542_rev2_1:
4463 eeprom->type = e1000_eeprom_microwire;
4464 eeprom->word_size = 64;
4465 eeprom->opcode_bits = 3;
4466 eeprom->address_bits = 6;
4467 eeprom->delay_usec = 50;
4468 eeprom->use_eerd = FALSE;
4469 eeprom->use_eewr = FALSE;
4473 case e1000_82545_rev_3:
4475 case e1000_82546_rev_3:
4476 eeprom->type = e1000_eeprom_microwire;
4477 eeprom->opcode_bits = 3;
4478 eeprom->delay_usec = 50;
4479 if (eecd & E1000_EECD_SIZE) {
4480 eeprom->word_size = 256;
4481 eeprom->address_bits = 8;
4483 eeprom->word_size = 64;
4484 eeprom->address_bits = 6;
4486 eeprom->use_eerd = FALSE;
4487 eeprom->use_eewr = FALSE;
4490 case e1000_82541_rev_2:
4492 case e1000_82547_rev_2:
4493 if (eecd & E1000_EECD_TYPE) {
4494 eeprom->type = e1000_eeprom_spi;
4495 eeprom->opcode_bits = 8;
4496 eeprom->delay_usec = 1;
4497 if (eecd & E1000_EECD_ADDR_BITS) {
4498 eeprom->page_size = 32;
4499 eeprom->address_bits = 16;
4501 eeprom->page_size = 8;
4502 eeprom->address_bits = 8;
4505 eeprom->type = e1000_eeprom_microwire;
4506 eeprom->opcode_bits = 3;
4507 eeprom->delay_usec = 50;
4508 if (eecd & E1000_EECD_ADDR_BITS) {
4509 eeprom->word_size = 256;
4510 eeprom->address_bits = 8;
4512 eeprom->word_size = 64;
4513 eeprom->address_bits = 6;
4516 eeprom->use_eerd = FALSE;
4517 eeprom->use_eewr = FALSE;
4521 eeprom->type = e1000_eeprom_spi;
4522 eeprom->opcode_bits = 8;
4523 eeprom->delay_usec = 1;
4524 if (eecd & E1000_EECD_ADDR_BITS) {
4525 eeprom->page_size = 32;
4526 eeprom->address_bits = 16;
4528 eeprom->page_size = 8;
4529 eeprom->address_bits = 8;
4531 eeprom->use_eerd = FALSE;
4532 eeprom->use_eewr = FALSE;
4535 eeprom->type = e1000_eeprom_spi;
4536 eeprom->opcode_bits = 8;
4537 eeprom->delay_usec = 1;
4538 if (eecd & E1000_EECD_ADDR_BITS) {
4539 eeprom->page_size = 32;
4540 eeprom->address_bits = 16;
4542 eeprom->page_size = 8;
4543 eeprom->address_bits = 8;
4545 eeprom->use_eerd = TRUE;
4546 eeprom->use_eewr = TRUE;
4547 if (e1000_is_onboard_nvm_eeprom(hw) == FALSE) {
4548 eeprom->type = e1000_eeprom_flash;
4549 eeprom->word_size = 2048;
4551 /* Ensure that the Autonomous FLASH update bit is cleared due to
4552 * Flash update issue on parts which use a FLASH for NVM. */
4553 eecd &= ~E1000_EECD_AUPDEN;
4554 E1000_WRITE_REG(hw, EECD, eecd);
4557 case e1000_80003es2lan:
4558 eeprom->type = e1000_eeprom_spi;
4559 eeprom->opcode_bits = 8;
4560 eeprom->delay_usec = 1;
4561 if (eecd & E1000_EECD_ADDR_BITS) {
4562 eeprom->page_size = 32;
4563 eeprom->address_bits = 16;
4565 eeprom->page_size = 8;
4566 eeprom->address_bits = 8;
4568 eeprom->use_eerd = TRUE;
4569 eeprom->use_eewr = FALSE;
4574 uint32_t flash_size = E1000_READ_ICH_FLASH_REG(hw, ICH_FLASH_GFPREG);
4576 eeprom->type = e1000_eeprom_ich8;
4577 eeprom->use_eerd = FALSE;
4578 eeprom->use_eewr = FALSE;
4579 eeprom->word_size = E1000_SHADOW_RAM_WORDS;
4581 /* Zero the shadow RAM structure. But don't load it from NVM
4582 * so as to save time for driver init */
4583 if (hw->eeprom_shadow_ram != NULL) {
4584 for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
4585 hw->eeprom_shadow_ram[i].modified = FALSE;
4586 hw->eeprom_shadow_ram[i].eeprom_word = 0xFFFF;
4590 hw->flash_base_addr = (flash_size & ICH_GFPREG_BASE_MASK) *
4591 ICH_FLASH_SECTOR_SIZE;
4593 hw->flash_bank_size = ((flash_size >> 16) & ICH_GFPREG_BASE_MASK) + 1;
4594 hw->flash_bank_size -= (flash_size & ICH_GFPREG_BASE_MASK);
4596 hw->flash_bank_size *= ICH_FLASH_SECTOR_SIZE;
4598 hw->flash_bank_size /= 2 * sizeof(uint16_t);
4606 if (eeprom->type == e1000_eeprom_spi) {
4607 /* eeprom_size will be an enum [0..8] that maps to eeprom sizes 128B to
4608 * 32KB (incremented by powers of 2).
4610 if (hw->mac_type <= e1000_82547_rev_2) {
4611 /* Set to default value for initial eeprom read. */
4612 eeprom->word_size = 64;
4613 ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size);
4616 eeprom_size = (eeprom_size & EEPROM_SIZE_MASK) >> EEPROM_SIZE_SHIFT;
4617 /* 256B eeprom size was not supported in earlier hardware, so we
4618 * bump eeprom_size up one to ensure that "1" (which maps to 256B)
4619 * is never the result used in the shifting logic below. */
4623 eeprom_size = (uint16_t)((eecd & E1000_EECD_SIZE_EX_MASK) >>
4624 E1000_EECD_SIZE_EX_SHIFT);
4627 eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT);
4632 /******************************************************************************
4633 * Raises the EEPROM's clock input.
4635 * hw - Struct containing variables accessed by shared code
4636 * eecd - EECD's current value
4637 *****************************************************************************/
4639 e1000_raise_ee_clk(struct e1000_hw *hw,
4642 /* Raise the clock input to the EEPROM (by setting the SK bit), and then
4643 * wait <delay> microseconds.
4645 *eecd = *eecd | E1000_EECD_SK;
4646 E1000_WRITE_REG(hw, EECD, *eecd);
4647 E1000_WRITE_FLUSH(hw);
4648 udelay(hw->eeprom.delay_usec);
4651 /******************************************************************************
4652 * Lowers the EEPROM's clock input.
4654 * hw - Struct containing variables accessed by shared code
4655 * eecd - EECD's current value
4656 *****************************************************************************/
4658 e1000_lower_ee_clk(struct e1000_hw *hw,
4661 /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
4662 * wait 50 microseconds.
4664 *eecd = *eecd & ~E1000_EECD_SK;
4665 E1000_WRITE_REG(hw, EECD, *eecd);
4666 E1000_WRITE_FLUSH(hw);
4667 udelay(hw->eeprom.delay_usec);
4670 /******************************************************************************
4671 * Shift data bits out to the EEPROM.
4673 * hw - Struct containing variables accessed by shared code
4674 * data - data to send to the EEPROM
4675 * count - number of bits to shift out
4676 *****************************************************************************/
4678 e1000_shift_out_ee_bits(struct e1000_hw *hw,
4682 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4686 /* We need to shift "count" bits out to the EEPROM. So, value in the
4687 * "data" parameter will be shifted out to the EEPROM one bit at a time.
4688 * In order to do this, "data" must be broken down into bits.
4690 mask = 0x01 << (count - 1);
4691 eecd = E1000_READ_REG(hw, EECD);
4692 if (eeprom->type == e1000_eeprom_microwire) {
4693 eecd &= ~E1000_EECD_DO;
4694 } else if (eeprom->type == e1000_eeprom_spi) {
4695 eecd |= E1000_EECD_DO;
4698 /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
4699 * and then raising and then lowering the clock (the SK bit controls
4700 * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
4701 * by setting "DI" to "0" and then raising and then lowering the clock.
4703 eecd &= ~E1000_EECD_DI;
4706 eecd |= E1000_EECD_DI;
4708 E1000_WRITE_REG(hw, EECD, eecd);
4709 E1000_WRITE_FLUSH(hw);
4711 udelay(eeprom->delay_usec);
4713 e1000_raise_ee_clk(hw, &eecd);
4714 e1000_lower_ee_clk(hw, &eecd);
4720 /* We leave the "DI" bit set to "0" when we leave this routine. */
4721 eecd &= ~E1000_EECD_DI;
4722 E1000_WRITE_REG(hw, EECD, eecd);
4725 /******************************************************************************
4726 * Shift data bits in from the EEPROM
4728 * hw - Struct containing variables accessed by shared code
4729 *****************************************************************************/
4731 e1000_shift_in_ee_bits(struct e1000_hw *hw,
4738 /* In order to read a register from the EEPROM, we need to shift 'count'
4739 * bits in from the EEPROM. Bits are "shifted in" by raising the clock
4740 * input to the EEPROM (setting the SK bit), and then reading the value of
4741 * the "DO" bit. During this "shifting in" process the "DI" bit should
4745 eecd = E1000_READ_REG(hw, EECD);
4747 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
4750 for (i = 0; i < count; i++) {
4752 e1000_raise_ee_clk(hw, &eecd);
4754 eecd = E1000_READ_REG(hw, EECD);
4756 eecd &= ~(E1000_EECD_DI);
4757 if (eecd & E1000_EECD_DO)
4760 e1000_lower_ee_clk(hw, &eecd);
4766 /******************************************************************************
4767 * Prepares EEPROM for access
4769 * hw - Struct containing variables accessed by shared code
4771 * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
4772 * function should be called before issuing a command to the EEPROM.
4773 *****************************************************************************/
4775 e1000_acquire_eeprom(struct e1000_hw *hw)
4777 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4780 DEBUGFUNC("e1000_acquire_eeprom");
4782 if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
4783 return -E1000_ERR_SWFW_SYNC;
4784 eecd = E1000_READ_REG(hw, EECD);
4786 if (hw->mac_type != e1000_82573) {
4787 /* Request EEPROM Access */
4788 if (hw->mac_type > e1000_82544) {
4789 eecd |= E1000_EECD_REQ;
4790 E1000_WRITE_REG(hw, EECD, eecd);
4791 eecd = E1000_READ_REG(hw, EECD);
4792 while ((!(eecd & E1000_EECD_GNT)) &&
4793 (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
4796 eecd = E1000_READ_REG(hw, EECD);
4798 if (!(eecd & E1000_EECD_GNT)) {
4799 eecd &= ~E1000_EECD_REQ;
4800 E1000_WRITE_REG(hw, EECD, eecd);
4801 DEBUGOUT("Could not acquire EEPROM grant\n");
4802 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
4803 return -E1000_ERR_EEPROM;
4808 /* Setup EEPROM for Read/Write */
4810 if (eeprom->type == e1000_eeprom_microwire) {
4811 /* Clear SK and DI */
4812 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
4813 E1000_WRITE_REG(hw, EECD, eecd);
4816 eecd |= E1000_EECD_CS;
4817 E1000_WRITE_REG(hw, EECD, eecd);
4818 } else if (eeprom->type == e1000_eeprom_spi) {
4819 /* Clear SK and CS */
4820 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
4821 E1000_WRITE_REG(hw, EECD, eecd);
4825 return E1000_SUCCESS;
4828 /******************************************************************************
4829 * Returns EEPROM to a "standby" state
4831 * hw - Struct containing variables accessed by shared code
4832 *****************************************************************************/
4834 e1000_standby_eeprom(struct e1000_hw *hw)
4836 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4839 eecd = E1000_READ_REG(hw, EECD);
4841 if (eeprom->type == e1000_eeprom_microwire) {
4842 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
4843 E1000_WRITE_REG(hw, EECD, eecd);
4844 E1000_WRITE_FLUSH(hw);
4845 udelay(eeprom->delay_usec);
4848 eecd |= E1000_EECD_SK;
4849 E1000_WRITE_REG(hw, EECD, eecd);
4850 E1000_WRITE_FLUSH(hw);
4851 udelay(eeprom->delay_usec);
4854 eecd |= E1000_EECD_CS;
4855 E1000_WRITE_REG(hw, EECD, eecd);
4856 E1000_WRITE_FLUSH(hw);
4857 udelay(eeprom->delay_usec);
4860 eecd &= ~E1000_EECD_SK;
4861 E1000_WRITE_REG(hw, EECD, eecd);
4862 E1000_WRITE_FLUSH(hw);
4863 udelay(eeprom->delay_usec);
4864 } else if (eeprom->type == e1000_eeprom_spi) {
4865 /* Toggle CS to flush commands */
4866 eecd |= E1000_EECD_CS;
4867 E1000_WRITE_REG(hw, EECD, eecd);
4868 E1000_WRITE_FLUSH(hw);
4869 udelay(eeprom->delay_usec);
4870 eecd &= ~E1000_EECD_CS;
4871 E1000_WRITE_REG(hw, EECD, eecd);
4872 E1000_WRITE_FLUSH(hw);
4873 udelay(eeprom->delay_usec);
4877 /******************************************************************************
4878 * Terminates a command by inverting the EEPROM's chip select pin
4880 * hw - Struct containing variables accessed by shared code
4881 *****************************************************************************/
4883 e1000_release_eeprom(struct e1000_hw *hw)
4887 DEBUGFUNC("e1000_release_eeprom");
4889 eecd = E1000_READ_REG(hw, EECD);
4891 if (hw->eeprom.type == e1000_eeprom_spi) {
4892 eecd |= E1000_EECD_CS; /* Pull CS high */
4893 eecd &= ~E1000_EECD_SK; /* Lower SCK */
4895 E1000_WRITE_REG(hw, EECD, eecd);
4897 udelay(hw->eeprom.delay_usec);
4898 } else if (hw->eeprom.type == e1000_eeprom_microwire) {
4899 /* cleanup eeprom */
4901 /* CS on Microwire is active-high */
4902 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
4904 E1000_WRITE_REG(hw, EECD, eecd);
4906 /* Rising edge of clock */
4907 eecd |= E1000_EECD_SK;
4908 E1000_WRITE_REG(hw, EECD, eecd);
4909 E1000_WRITE_FLUSH(hw);
4910 udelay(hw->eeprom.delay_usec);
4912 /* Falling edge of clock */
4913 eecd &= ~E1000_EECD_SK;
4914 E1000_WRITE_REG(hw, EECD, eecd);
4915 E1000_WRITE_FLUSH(hw);
4916 udelay(hw->eeprom.delay_usec);
4919 /* Stop requesting EEPROM access */
4920 if (hw->mac_type > e1000_82544) {
4921 eecd &= ~E1000_EECD_REQ;
4922 E1000_WRITE_REG(hw, EECD, eecd);
4925 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
4928 /******************************************************************************
4929 * Reads a 16 bit word from the EEPROM.
4931 * hw - Struct containing variables accessed by shared code
4932 *****************************************************************************/
4934 e1000_spi_eeprom_ready(struct e1000_hw *hw)
4936 uint16_t retry_count = 0;
4937 uint8_t spi_stat_reg;
4939 DEBUGFUNC("e1000_spi_eeprom_ready");
4941 /* Read "Status Register" repeatedly until the LSB is cleared. The
4942 * EEPROM will signal that the command has been completed by clearing
4943 * bit 0 of the internal status register. If it's not cleared within
4944 * 5 milliseconds, then error out.
4948 e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
4949 hw->eeprom.opcode_bits);
4950 spi_stat_reg = (uint8_t)e1000_shift_in_ee_bits(hw, 8);
4951 if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
4957 e1000_standby_eeprom(hw);
4958 } while (retry_count < EEPROM_MAX_RETRY_SPI);
4960 /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
4961 * only 0-5mSec on 5V devices)
4963 if (retry_count >= EEPROM_MAX_RETRY_SPI) {
4964 DEBUGOUT("SPI EEPROM Status error\n");
4965 return -E1000_ERR_EEPROM;
4968 return E1000_SUCCESS;
4971 /******************************************************************************
4972 * Reads a 16 bit word from the EEPROM.
4974 * hw - Struct containing variables accessed by shared code
4975 * offset - offset of word in the EEPROM to read
4976 * data - word read from the EEPROM
4977 * words - number of words to read
4978 *****************************************************************************/
4980 e1000_read_eeprom(struct e1000_hw *hw,
4985 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4988 DEBUGFUNC("e1000_read_eeprom");
4990 /* If eeprom is not yet detected, do so now */
4991 if (eeprom->word_size == 0)
4992 e1000_init_eeprom_params(hw);
4994 /* A check for invalid values: offset too large, too many words, and not
4997 if ((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
4999 DEBUGOUT2("\"words\" parameter out of bounds. Words = %d, size = %d\n", offset, eeprom->word_size);
5000 return -E1000_ERR_EEPROM;
5003 /* EEPROM's that don't use EERD to read require us to bit-bang the SPI
5004 * directly. In this case, we need to acquire the EEPROM so that
5005 * FW or other port software does not interrupt.
5007 if (e1000_is_onboard_nvm_eeprom(hw) == TRUE &&
5008 hw->eeprom.use_eerd == FALSE) {
5009 /* Prepare the EEPROM for bit-bang reading */
5010 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
5011 return -E1000_ERR_EEPROM;
5014 /* Eerd register EEPROM access requires no eeprom aquire/release */
5015 if (eeprom->use_eerd == TRUE)
5016 return e1000_read_eeprom_eerd(hw, offset, words, data);
5018 /* ICH EEPROM access is done via the ICH flash controller */
5019 if (eeprom->type == e1000_eeprom_ich8)
5020 return e1000_read_eeprom_ich8(hw, offset, words, data);
5022 /* Set up the SPI or Microwire EEPROM for bit-bang reading. We have
5023 * acquired the EEPROM at this point, so any returns should relase it */
5024 if (eeprom->type == e1000_eeprom_spi) {
5026 uint8_t read_opcode = EEPROM_READ_OPCODE_SPI;
5028 if (e1000_spi_eeprom_ready(hw)) {
5029 e1000_release_eeprom(hw);
5030 return -E1000_ERR_EEPROM;
5033 e1000_standby_eeprom(hw);
5035 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
5036 if ((eeprom->address_bits == 8) && (offset >= 128))
5037 read_opcode |= EEPROM_A8_OPCODE_SPI;
5039 /* Send the READ command (opcode + addr) */
5040 e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
5041 e1000_shift_out_ee_bits(hw, (uint16_t)(offset*2), eeprom->address_bits);
5043 /* Read the data. The address of the eeprom internally increments with
5044 * each byte (spi) being read, saving on the overhead of eeprom setup
5045 * and tear-down. The address counter will roll over if reading beyond
5046 * the size of the eeprom, thus allowing the entire memory to be read
5047 * starting from any offset. */
5048 for (i = 0; i < words; i++) {
5049 word_in = e1000_shift_in_ee_bits(hw, 16);
5050 data[i] = (word_in >> 8) | (word_in << 8);
5052 } else if (eeprom->type == e1000_eeprom_microwire) {
5053 for (i = 0; i < words; i++) {
5054 /* Send the READ command (opcode + addr) */
5055 e1000_shift_out_ee_bits(hw, EEPROM_READ_OPCODE_MICROWIRE,
5056 eeprom->opcode_bits);
5057 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + i),
5058 eeprom->address_bits);
5060 /* Read the data. For microwire, each word requires the overhead
5061 * of eeprom setup and tear-down. */
5062 data[i] = e1000_shift_in_ee_bits(hw, 16);
5063 e1000_standby_eeprom(hw);
5067 /* End this read operation */
5068 e1000_release_eeprom(hw);
5070 return E1000_SUCCESS;
5073 /******************************************************************************
5074 * Reads a 16 bit word from the EEPROM using the EERD register.
5076 * hw - Struct containing variables accessed by shared code
5077 * offset - offset of word in the EEPROM to read
5078 * data - word read from the EEPROM
5079 * words - number of words to read
5080 *****************************************************************************/
5082 e1000_read_eeprom_eerd(struct e1000_hw *hw,
5087 uint32_t i, eerd = 0;
5090 for (i = 0; i < words; i++) {
5091 eerd = ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) +
5092 E1000_EEPROM_RW_REG_START;
5094 E1000_WRITE_REG(hw, EERD, eerd);
5095 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_READ);
5100 data[i] = (E1000_READ_REG(hw, EERD) >> E1000_EEPROM_RW_REG_DATA);
5107 /******************************************************************************
5108 * Writes a 16 bit word from the EEPROM using the EEWR register.
5110 * hw - Struct containing variables accessed by shared code
5111 * offset - offset of word in the EEPROM to read
5112 * data - word read from the EEPROM
5113 * words - number of words to read
5114 *****************************************************************************/
5116 e1000_write_eeprom_eewr(struct e1000_hw *hw,
5121 uint32_t register_value = 0;
5125 if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
5126 return -E1000_ERR_SWFW_SYNC;
5128 for (i = 0; i < words; i++) {
5129 register_value = (data[i] << E1000_EEPROM_RW_REG_DATA) |
5130 ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) |
5131 E1000_EEPROM_RW_REG_START;
5133 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
5138 E1000_WRITE_REG(hw, EEWR, register_value);
5140 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
5147 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
5151 /******************************************************************************
5152 * Polls the status bit (bit 1) of the EERD to determine when the read is done.
5154 * hw - Struct containing variables accessed by shared code
5155 *****************************************************************************/
5157 e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd)
5159 uint32_t attempts = 100000;
5160 uint32_t i, reg = 0;
5161 int32_t done = E1000_ERR_EEPROM;
5163 for (i = 0; i < attempts; i++) {
5164 if (eerd == E1000_EEPROM_POLL_READ)
5165 reg = E1000_READ_REG(hw, EERD);
5167 reg = E1000_READ_REG(hw, EEWR);
5169 if (reg & E1000_EEPROM_RW_REG_DONE) {
5170 done = E1000_SUCCESS;
5179 /***************************************************************************
5180 * Description: Determines if the onboard NVM is FLASH or EEPROM.
5182 * hw - Struct containing variables accessed by shared code
5183 ****************************************************************************/
5185 e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw)
5189 DEBUGFUNC("e1000_is_onboard_nvm_eeprom");
5191 if (hw->mac_type == e1000_ich8lan)
5194 if (hw->mac_type == e1000_82573) {
5195 eecd = E1000_READ_REG(hw, EECD);
5197 /* Isolate bits 15 & 16 */
5198 eecd = ((eecd >> 15) & 0x03);
5200 /* If both bits are set, device is Flash type */
5208 /******************************************************************************
5209 * Verifies that the EEPROM has a valid checksum
5211 * hw - Struct containing variables accessed by shared code
5213 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
5214 * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
5216 *****************************************************************************/
5218 e1000_validate_eeprom_checksum(struct e1000_hw *hw)
5220 uint16_t checksum = 0;
5221 uint16_t i, eeprom_data;
5223 DEBUGFUNC("e1000_validate_eeprom_checksum");
5225 if ((hw->mac_type == e1000_82573) &&
5226 (e1000_is_onboard_nvm_eeprom(hw) == FALSE)) {
5227 /* Check bit 4 of word 10h. If it is 0, firmware is done updating
5228 * 10h-12h. Checksum may need to be fixed. */
5229 e1000_read_eeprom(hw, 0x10, 1, &eeprom_data);
5230 if ((eeprom_data & 0x10) == 0) {
5231 /* Read 0x23 and check bit 15. This bit is a 1 when the checksum
5232 * has already been fixed. If the checksum is still wrong and this
5233 * bit is a 1, we need to return bad checksum. Otherwise, we need
5234 * to set this bit to a 1 and update the checksum. */
5235 e1000_read_eeprom(hw, 0x23, 1, &eeprom_data);
5236 if ((eeprom_data & 0x8000) == 0) {
5237 eeprom_data |= 0x8000;
5238 e1000_write_eeprom(hw, 0x23, 1, &eeprom_data);
5239 e1000_update_eeprom_checksum(hw);
5244 if (hw->mac_type == e1000_ich8lan) {
5245 /* Drivers must allocate the shadow ram structure for the
5246 * EEPROM checksum to be updated. Otherwise, this bit as well
5247 * as the checksum must both be set correctly for this
5248 * validation to pass.
5250 e1000_read_eeprom(hw, 0x19, 1, &eeprom_data);
5251 if ((eeprom_data & 0x40) == 0) {
5252 eeprom_data |= 0x40;
5253 e1000_write_eeprom(hw, 0x19, 1, &eeprom_data);
5254 e1000_update_eeprom_checksum(hw);
5258 for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
5259 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
5260 DEBUGOUT("EEPROM Read Error\n");
5261 return -E1000_ERR_EEPROM;
5263 checksum += eeprom_data;
5266 if (checksum == (uint16_t) EEPROM_SUM)
5267 return E1000_SUCCESS;
5269 DEBUGOUT("EEPROM Checksum Invalid\n");
5270 return -E1000_ERR_EEPROM;
5274 /******************************************************************************
5275 * Calculates the EEPROM checksum and writes it to the EEPROM
5277 * hw - Struct containing variables accessed by shared code
5279 * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA.
5280 * Writes the difference to word offset 63 of the EEPROM.
5281 *****************************************************************************/
5283 e1000_update_eeprom_checksum(struct e1000_hw *hw)
5286 uint16_t checksum = 0;
5287 uint16_t i, eeprom_data;
5289 DEBUGFUNC("e1000_update_eeprom_checksum");
5291 for (i = 0; i < EEPROM_CHECKSUM_REG; i++) {
5292 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
5293 DEBUGOUT("EEPROM Read Error\n");
5294 return -E1000_ERR_EEPROM;
5296 checksum += eeprom_data;
5298 checksum = (uint16_t) EEPROM_SUM - checksum;
5299 if (e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) {
5300 DEBUGOUT("EEPROM Write Error\n");
5301 return -E1000_ERR_EEPROM;
5302 } else if (hw->eeprom.type == e1000_eeprom_flash) {
5303 e1000_commit_shadow_ram(hw);
5304 } else if (hw->eeprom.type == e1000_eeprom_ich8) {
5305 e1000_commit_shadow_ram(hw);
5306 /* Reload the EEPROM, or else modifications will not appear
5307 * until after next adapter reset. */
5308 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
5309 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
5310 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
5313 return E1000_SUCCESS;
5316 /******************************************************************************
5317 * Parent function for writing words to the different EEPROM types.
5319 * hw - Struct containing variables accessed by shared code
5320 * offset - offset within the EEPROM to be written to
5321 * words - number of words to write
5322 * data - 16 bit word to be written to the EEPROM
5324 * If e1000_update_eeprom_checksum is not called after this function, the
5325 * EEPROM will most likely contain an invalid checksum.
5326 *****************************************************************************/
5328 e1000_write_eeprom(struct e1000_hw *hw,
5333 struct e1000_eeprom_info *eeprom = &hw->eeprom;
5336 DEBUGFUNC("e1000_write_eeprom");
5338 /* If eeprom is not yet detected, do so now */
5339 if (eeprom->word_size == 0)
5340 e1000_init_eeprom_params(hw);
5342 /* A check for invalid values: offset too large, too many words, and not
5345 if ((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
5347 DEBUGOUT("\"words\" parameter out of bounds\n");
5348 return -E1000_ERR_EEPROM;
5351 /* 82573 writes only through eewr */
5352 if (eeprom->use_eewr == TRUE)
5353 return e1000_write_eeprom_eewr(hw, offset, words, data);
5355 if (eeprom->type == e1000_eeprom_ich8)
5356 return e1000_write_eeprom_ich8(hw, offset, words, data);
5358 /* Prepare the EEPROM for writing */
5359 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
5360 return -E1000_ERR_EEPROM;
5362 if (eeprom->type == e1000_eeprom_microwire) {
5363 status = e1000_write_eeprom_microwire(hw, offset, words, data);
5365 status = e1000_write_eeprom_spi(hw, offset, words, data);
5369 /* Done with writing */
5370 e1000_release_eeprom(hw);
5375 /******************************************************************************
5376 * Writes a 16 bit word to a given offset in an SPI EEPROM.
5378 * hw - Struct containing variables accessed by shared code
5379 * offset - offset within the EEPROM to be written to
5380 * words - number of words to write
5381 * data - pointer to array of 8 bit words to be written to the EEPROM
5383 *****************************************************************************/
5385 e1000_write_eeprom_spi(struct e1000_hw *hw,
5390 struct e1000_eeprom_info *eeprom = &hw->eeprom;
5393 DEBUGFUNC("e1000_write_eeprom_spi");
5395 while (widx < words) {
5396 uint8_t write_opcode = EEPROM_WRITE_OPCODE_SPI;
5398 if (e1000_spi_eeprom_ready(hw)) return -E1000_ERR_EEPROM;
5400 e1000_standby_eeprom(hw);
5402 /* Send the WRITE ENABLE command (8 bit opcode ) */
5403 e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI,
5404 eeprom->opcode_bits);
5406 e1000_standby_eeprom(hw);
5408 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
5409 if ((eeprom->address_bits == 8) && (offset >= 128))
5410 write_opcode |= EEPROM_A8_OPCODE_SPI;
5412 /* Send the Write command (8-bit opcode + addr) */
5413 e1000_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits);
5415 e1000_shift_out_ee_bits(hw, (uint16_t)((offset + widx)*2),
5416 eeprom->address_bits);
5420 /* Loop to allow for up to whole page write (32 bytes) of eeprom */
5421 while (widx < words) {
5422 uint16_t word_out = data[widx];
5423 word_out = (word_out >> 8) | (word_out << 8);
5424 e1000_shift_out_ee_bits(hw, word_out, 16);
5427 /* Some larger eeprom sizes are capable of a 32-byte PAGE WRITE
5428 * operation, while the smaller eeproms are capable of an 8-byte
5429 * PAGE WRITE operation. Break the inner loop to pass new address
5431 if ((((offset + widx)*2) % eeprom->page_size) == 0) {
5432 e1000_standby_eeprom(hw);
5438 return E1000_SUCCESS;
5441 /******************************************************************************
5442 * Writes a 16 bit word to a given offset in a Microwire EEPROM.
5444 * hw - Struct containing variables accessed by shared code
5445 * offset - offset within the EEPROM to be written to
5446 * words - number of words to write
5447 * data - pointer to array of 16 bit words to be written to the EEPROM
5449 *****************************************************************************/
5451 e1000_write_eeprom_microwire(struct e1000_hw *hw,
5456 struct e1000_eeprom_info *eeprom = &hw->eeprom;
5458 uint16_t words_written = 0;
5461 DEBUGFUNC("e1000_write_eeprom_microwire");
5463 /* Send the write enable command to the EEPROM (3-bit opcode plus
5464 * 6/8-bit dummy address beginning with 11). It's less work to include
5465 * the 11 of the dummy address as part of the opcode than it is to shift
5466 * it over the correct number of bits for the address. This puts the
5467 * EEPROM into write/erase mode.
5469 e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE,
5470 (uint16_t)(eeprom->opcode_bits + 2));
5472 e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
5474 /* Prepare the EEPROM */
5475 e1000_standby_eeprom(hw);
5477 while (words_written < words) {
5478 /* Send the Write command (3-bit opcode + addr) */
5479 e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE,
5480 eeprom->opcode_bits);
5482 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + words_written),
5483 eeprom->address_bits);
5486 e1000_shift_out_ee_bits(hw, data[words_written], 16);
5488 /* Toggle the CS line. This in effect tells the EEPROM to execute
5489 * the previous command.
5491 e1000_standby_eeprom(hw);
5493 /* Read DO repeatedly until it is high (equal to '1'). The EEPROM will
5494 * signal that the command has been completed by raising the DO signal.
5495 * If DO does not go high in 10 milliseconds, then error out.
5497 for (i = 0; i < 200; i++) {
5498 eecd = E1000_READ_REG(hw, EECD);
5499 if (eecd & E1000_EECD_DO) break;
5503 DEBUGOUT("EEPROM Write did not complete\n");
5504 return -E1000_ERR_EEPROM;
5507 /* Recover from write */
5508 e1000_standby_eeprom(hw);
5513 /* Send the write disable command to the EEPROM (3-bit opcode plus
5514 * 6/8-bit dummy address beginning with 10). It's less work to include
5515 * the 10 of the dummy address as part of the opcode than it is to shift
5516 * it over the correct number of bits for the address. This takes the
5517 * EEPROM out of write/erase mode.
5519 e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE,
5520 (uint16_t)(eeprom->opcode_bits + 2));
5522 e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
5524 return E1000_SUCCESS;
5527 /******************************************************************************
5528 * Flushes the cached eeprom to NVM. This is done by saving the modified values
5529 * in the eeprom cache and the non modified values in the currently active bank
5532 * hw - Struct containing variables accessed by shared code
5533 * offset - offset of word in the EEPROM to read
5534 * data - word read from the EEPROM
5535 * words - number of words to read
5536 *****************************************************************************/
5538 e1000_commit_shadow_ram(struct e1000_hw *hw)
5540 uint32_t attempts = 100000;
5544 int32_t error = E1000_SUCCESS;
5545 uint32_t old_bank_offset = 0;
5546 uint32_t new_bank_offset = 0;
5547 uint8_t low_byte = 0;
5548 uint8_t high_byte = 0;
5549 boolean_t sector_write_failed = FALSE;
5551 if (hw->mac_type == e1000_82573) {
5552 /* The flop register will be used to determine if flash type is STM */
5553 flop = E1000_READ_REG(hw, FLOP);
5554 for (i=0; i < attempts; i++) {
5555 eecd = E1000_READ_REG(hw, EECD);
5556 if ((eecd & E1000_EECD_FLUPD) == 0) {
5562 if (i == attempts) {
5563 return -E1000_ERR_EEPROM;
5566 /* If STM opcode located in bits 15:8 of flop, reset firmware */
5567 if ((flop & 0xFF00) == E1000_STM_OPCODE) {
5568 E1000_WRITE_REG(hw, HICR, E1000_HICR_FW_RESET);
5571 /* Perform the flash update */
5572 E1000_WRITE_REG(hw, EECD, eecd | E1000_EECD_FLUPD);
5574 for (i=0; i < attempts; i++) {
5575 eecd = E1000_READ_REG(hw, EECD);
5576 if ((eecd & E1000_EECD_FLUPD) == 0) {
5582 if (i == attempts) {
5583 return -E1000_ERR_EEPROM;
5587 if (hw->mac_type == e1000_ich8lan && hw->eeprom_shadow_ram != NULL) {
5588 /* We're writing to the opposite bank so if we're on bank 1,
5589 * write to bank 0 etc. We also need to erase the segment that
5590 * is going to be written */
5591 if (!(E1000_READ_REG(hw, EECD) & E1000_EECD_SEC1VAL)) {
5592 new_bank_offset = hw->flash_bank_size * 2;
5593 old_bank_offset = 0;
5594 e1000_erase_ich8_4k_segment(hw, 1);
5596 old_bank_offset = hw->flash_bank_size * 2;
5597 new_bank_offset = 0;
5598 e1000_erase_ich8_4k_segment(hw, 0);
5601 sector_write_failed = FALSE;
5602 /* Loop for every byte in the shadow RAM,
5603 * which is in units of words. */
5604 for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
5605 /* Determine whether to write the value stored
5606 * in the other NVM bank or a modified value stored
5607 * in the shadow RAM */
5608 if (hw->eeprom_shadow_ram[i].modified == TRUE) {
5609 low_byte = (uint8_t)hw->eeprom_shadow_ram[i].eeprom_word;
5611 error = e1000_verify_write_ich8_byte(hw,
5612 (i << 1) + new_bank_offset, low_byte);
5614 if (error != E1000_SUCCESS)
5615 sector_write_failed = TRUE;
5618 (uint8_t)(hw->eeprom_shadow_ram[i].eeprom_word >> 8);
5622 e1000_read_ich8_byte(hw, (i << 1) + old_bank_offset,
5625 error = e1000_verify_write_ich8_byte(hw,
5626 (i << 1) + new_bank_offset, low_byte);
5628 if (error != E1000_SUCCESS)
5629 sector_write_failed = TRUE;
5631 e1000_read_ich8_byte(hw, (i << 1) + old_bank_offset + 1,
5637 /* If the write of the low byte was successful, go ahread and
5638 * write the high byte while checking to make sure that if it
5639 * is the signature byte, then it is handled properly */
5640 if (sector_write_failed == FALSE) {
5641 /* If the word is 0x13, then make sure the signature bits
5642 * (15:14) are 11b until the commit has completed.
5643 * This will allow us to write 10b which indicates the
5644 * signature is valid. We want to do this after the write
5645 * has completed so that we don't mark the segment valid
5646 * while the write is still in progress */
5647 if (i == E1000_ICH_NVM_SIG_WORD)
5648 high_byte = E1000_ICH_NVM_SIG_MASK | high_byte;
5650 error = e1000_verify_write_ich8_byte(hw,
5651 (i << 1) + new_bank_offset + 1, high_byte);
5652 if (error != E1000_SUCCESS)
5653 sector_write_failed = TRUE;
5656 /* If the write failed then break from the loop and
5657 * return an error */
5662 /* Don't bother writing the segment valid bits if sector
5663 * programming failed. */
5664 if (sector_write_failed == FALSE) {
5665 /* Finally validate the new segment by setting bit 15:14
5666 * to 10b in word 0x13 , this can be done without an
5667 * erase as well since these bits are 11 to start with
5668 * and we need to change bit 14 to 0b */
5669 e1000_read_ich8_byte(hw,
5670 E1000_ICH_NVM_SIG_WORD * 2 + 1 + new_bank_offset,
5673 error = e1000_verify_write_ich8_byte(hw,
5674 E1000_ICH_NVM_SIG_WORD * 2 + 1 + new_bank_offset, high_byte);
5675 /* And invalidate the previously valid segment by setting
5676 * its signature word (0x13) high_byte to 0b. This can be
5677 * done without an erase because flash erase sets all bits
5678 * to 1's. We can write 1's to 0's without an erase */
5679 if (error == E1000_SUCCESS) {
5680 error = e1000_verify_write_ich8_byte(hw,
5681 E1000_ICH_NVM_SIG_WORD * 2 + 1 + old_bank_offset, 0);
5684 /* Clear the now not used entry in the cache */
5685 for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
5686 hw->eeprom_shadow_ram[i].modified = FALSE;
5687 hw->eeprom_shadow_ram[i].eeprom_word = 0xFFFF;
5695 /******************************************************************************
5696 * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
5697 * second function of dual function devices
5699 * hw - Struct containing variables accessed by shared code
5700 *****************************************************************************/
5702 e1000_read_mac_addr(struct e1000_hw * hw)
5705 uint16_t eeprom_data, i;
5707 DEBUGFUNC("e1000_read_mac_addr");
5709 for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
5711 if (e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
5712 DEBUGOUT("EEPROM Read Error\n");
5713 return -E1000_ERR_EEPROM;
5715 hw->perm_mac_addr[i] = (uint8_t) (eeprom_data & 0x00FF);
5716 hw->perm_mac_addr[i+1] = (uint8_t) (eeprom_data >> 8);
5719 switch (hw->mac_type) {
5723 case e1000_82546_rev_3:
5725 case e1000_80003es2lan:
5726 if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
5727 hw->perm_mac_addr[5] ^= 0x01;
5731 for (i = 0; i < NODE_ADDRESS_SIZE; i++)
5732 hw->mac_addr[i] = hw->perm_mac_addr[i];
5733 return E1000_SUCCESS;
5736 /******************************************************************************
5737 * Initializes receive address filters.
5739 * hw - Struct containing variables accessed by shared code
5741 * Places the MAC address in receive address register 0 and clears the rest
5742 * of the receive addresss registers. Clears the multicast table. Assumes
5743 * the receiver is in reset when the routine is called.
5744 *****************************************************************************/
5746 e1000_init_rx_addrs(struct e1000_hw *hw)
5751 DEBUGFUNC("e1000_init_rx_addrs");
5753 /* Setup the receive address. */
5754 DEBUGOUT("Programming MAC Address into RAR[0]\n");
5756 e1000_rar_set(hw, hw->mac_addr, 0);
5758 rar_num = E1000_RAR_ENTRIES;
5760 /* Reserve a spot for the Locally Administered Address to work around
5761 * an 82571 issue in which a reset on one port will reload the MAC on
5762 * the other port. */
5763 if ((hw->mac_type == e1000_82571) && (hw->laa_is_present == TRUE))
5765 if (hw->mac_type == e1000_ich8lan)
5766 rar_num = E1000_RAR_ENTRIES_ICH8LAN;
5768 /* Zero out the other 15 receive addresses. */
5769 DEBUGOUT("Clearing RAR[1-15]\n");
5770 for (i = 1; i < rar_num; i++) {
5771 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
5772 E1000_WRITE_FLUSH(hw);
5773 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
5774 E1000_WRITE_FLUSH(hw);
5778 /******************************************************************************
5779 * Hashes an address to determine its location in the multicast table
5781 * hw - Struct containing variables accessed by shared code
5782 * mc_addr - the multicast address to hash
5783 *****************************************************************************/
5785 e1000_hash_mc_addr(struct e1000_hw *hw,
5788 uint32_t hash_value = 0;
5790 /* The portion of the address that is used for the hash table is
5791 * determined by the mc_filter_type setting.
5793 switch (hw->mc_filter_type) {
5794 /* [0] [1] [2] [3] [4] [5]
5799 if (hw->mac_type == e1000_ich8lan) {
5800 /* [47:38] i.e. 0x158 for above example address */
5801 hash_value = ((mc_addr[4] >> 6) | (((uint16_t) mc_addr[5]) << 2));
5803 /* [47:36] i.e. 0x563 for above example address */
5804 hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4));
5808 if (hw->mac_type == e1000_ich8lan) {
5809 /* [46:37] i.e. 0x2B1 for above example address */
5810 hash_value = ((mc_addr[4] >> 5) | (((uint16_t) mc_addr[5]) << 3));
5812 /* [46:35] i.e. 0xAC6 for above example address */
5813 hash_value = ((mc_addr[4] >> 3) | (((uint16_t) mc_addr[5]) << 5));
5817 if (hw->mac_type == e1000_ich8lan) {
5818 /*[45:36] i.e. 0x163 for above example address */
5819 hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4));
5821 /* [45:34] i.e. 0x5D8 for above example address */
5822 hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6));
5826 if (hw->mac_type == e1000_ich8lan) {
5827 /* [43:34] i.e. 0x18D for above example address */
5828 hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6));
5830 /* [43:32] i.e. 0x634 for above example address */
5831 hash_value = ((mc_addr[4]) | (((uint16_t) mc_addr[5]) << 8));
5836 hash_value &= 0xFFF;
5837 if (hw->mac_type == e1000_ich8lan)
5838 hash_value &= 0x3FF;
5843 /******************************************************************************
5844 * Sets the bit in the multicast table corresponding to the hash value.
5846 * hw - Struct containing variables accessed by shared code
5847 * hash_value - Multicast address hash value
5848 *****************************************************************************/
5850 e1000_mta_set(struct e1000_hw *hw,
5851 uint32_t hash_value)
5853 uint32_t hash_bit, hash_reg;
5857 /* The MTA is a register array of 128 32-bit registers.
5858 * It is treated like an array of 4096 bits. We want to set
5859 * bit BitArray[hash_value]. So we figure out what register
5860 * the bit is in, read it, OR in the new bit, then write
5861 * back the new value. The register is determined by the
5862 * upper 7 bits of the hash value and the bit within that
5863 * register are determined by the lower 5 bits of the value.
5865 hash_reg = (hash_value >> 5) & 0x7F;
5866 if (hw->mac_type == e1000_ich8lan)
5869 hash_bit = hash_value & 0x1F;
5871 mta = E1000_READ_REG_ARRAY(hw, MTA, hash_reg);
5873 mta |= (1 << hash_bit);
5875 /* If we are on an 82544 and we are trying to write an odd offset
5876 * in the MTA, save off the previous entry before writing and
5877 * restore the old value after writing.
5879 if ((hw->mac_type == e1000_82544) && ((hash_reg & 0x1) == 1)) {
5880 temp = E1000_READ_REG_ARRAY(hw, MTA, (hash_reg - 1));
5881 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
5882 E1000_WRITE_FLUSH(hw);
5883 E1000_WRITE_REG_ARRAY(hw, MTA, (hash_reg - 1), temp);
5884 E1000_WRITE_FLUSH(hw);
5886 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
5887 E1000_WRITE_FLUSH(hw);
5891 /******************************************************************************
5892 * Puts an ethernet address into a receive address register.
5894 * hw - Struct containing variables accessed by shared code
5895 * addr - Address to put into receive address register
5896 * index - Receive address register to write
5897 *****************************************************************************/
5899 e1000_rar_set(struct e1000_hw *hw,
5903 uint32_t rar_low, rar_high;
5905 /* HW expects these in little endian so we reverse the byte order
5906 * from network order (big endian) to little endian
5908 rar_low = ((uint32_t) addr[0] |
5909 ((uint32_t) addr[1] << 8) |
5910 ((uint32_t) addr[2] << 16) | ((uint32_t) addr[3] << 24));
5911 rar_high = ((uint32_t) addr[4] | ((uint32_t) addr[5] << 8));
5913 /* Disable Rx and flush all Rx frames before enabling RSS to avoid Rx
5917 * If there are any Rx frames queued up or otherwise present in the HW
5918 * before RSS is enabled, and then we enable RSS, the HW Rx unit will
5919 * hang. To work around this issue, we have to disable receives and
5920 * flush out all Rx frames before we enable RSS. To do so, we modify we
5921 * redirect all Rx traffic to manageability and then reset the HW.
5922 * This flushes away Rx frames, and (since the redirections to
5923 * manageability persists across resets) keeps new ones from coming in
5924 * while we work. Then, we clear the Address Valid AV bit for all MAC
5925 * addresses and undo the re-direction to manageability.
5926 * Now, frames are coming in again, but the MAC won't accept them, so
5927 * far so good. We now proceed to initialize RSS (if necessary) and
5928 * configure the Rx unit. Last, we re-enable the AV bits and continue
5931 switch (hw->mac_type) {
5934 case e1000_80003es2lan:
5935 if (hw->leave_av_bit_off == TRUE)
5938 /* Indicate to hardware the Address is Valid. */
5939 rar_high |= E1000_RAH_AV;
5943 E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
5944 E1000_WRITE_FLUSH(hw);
5945 E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
5946 E1000_WRITE_FLUSH(hw);
5949 /******************************************************************************
5950 * Writes a value to the specified offset in the VLAN filter table.
5952 * hw - Struct containing variables accessed by shared code
5953 * offset - Offset in VLAN filer table to write
5954 * value - Value to write into VLAN filter table
5955 *****************************************************************************/
5957 e1000_write_vfta(struct e1000_hw *hw,
5963 if (hw->mac_type == e1000_ich8lan)
5966 if ((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) {
5967 temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1));
5968 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
5969 E1000_WRITE_FLUSH(hw);
5970 E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp);
5971 E1000_WRITE_FLUSH(hw);
5973 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
5974 E1000_WRITE_FLUSH(hw);
5978 /******************************************************************************
5979 * Clears the VLAN filer table
5981 * hw - Struct containing variables accessed by shared code
5982 *****************************************************************************/
5984 e1000_clear_vfta(struct e1000_hw *hw)
5987 uint32_t vfta_value = 0;
5988 uint32_t vfta_offset = 0;
5989 uint32_t vfta_bit_in_reg = 0;
5991 if (hw->mac_type == e1000_ich8lan)
5994 if (hw->mac_type == e1000_82573) {
5995 if (hw->mng_cookie.vlan_id != 0) {
5996 /* The VFTA is a 4096b bit-field, each identifying a single VLAN
5997 * ID. The following operations determine which 32b entry
5998 * (i.e. offset) into the array we want to set the VLAN ID
5999 * (i.e. bit) of the manageability unit. */
6000 vfta_offset = (hw->mng_cookie.vlan_id >>
6001 E1000_VFTA_ENTRY_SHIFT) &
6002 E1000_VFTA_ENTRY_MASK;
6003 vfta_bit_in_reg = 1 << (hw->mng_cookie.vlan_id &
6004 E1000_VFTA_ENTRY_BIT_SHIFT_MASK);
6007 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
6008 /* If the offset we want to clear is the same offset of the
6009 * manageability VLAN ID, then clear all bits except that of the
6010 * manageability unit */
6011 vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0;
6012 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, vfta_value);
6013 E1000_WRITE_FLUSH(hw);
6018 e1000_id_led_init(struct e1000_hw * hw)
6021 const uint32_t ledctl_mask = 0x000000FF;
6022 const uint32_t ledctl_on = E1000_LEDCTL_MODE_LED_ON;
6023 const uint32_t ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
6024 uint16_t eeprom_data, i, temp;
6025 const uint16_t led_mask = 0x0F;
6027 DEBUGFUNC("e1000_id_led_init");
6029 if (hw->mac_type < e1000_82540) {
6031 return E1000_SUCCESS;
6034 ledctl = E1000_READ_REG(hw, LEDCTL);
6035 hw->ledctl_default = ledctl;
6036 hw->ledctl_mode1 = hw->ledctl_default;
6037 hw->ledctl_mode2 = hw->ledctl_default;
6039 if (e1000_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, 1, &eeprom_data) < 0) {
6040 DEBUGOUT("EEPROM Read Error\n");
6041 return -E1000_ERR_EEPROM;
6044 if ((hw->mac_type == e1000_82573) &&
6045 (eeprom_data == ID_LED_RESERVED_82573))
6046 eeprom_data = ID_LED_DEFAULT_82573;
6047 else if ((eeprom_data == ID_LED_RESERVED_0000) ||
6048 (eeprom_data == ID_LED_RESERVED_FFFF)) {
6049 if (hw->mac_type == e1000_ich8lan)
6050 eeprom_data = ID_LED_DEFAULT_ICH8LAN;
6052 eeprom_data = ID_LED_DEFAULT;
6055 for (i = 0; i < 4; i++) {
6056 temp = (eeprom_data >> (i << 2)) & led_mask;
6058 case ID_LED_ON1_DEF2:
6059 case ID_LED_ON1_ON2:
6060 case ID_LED_ON1_OFF2:
6061 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
6062 hw->ledctl_mode1 |= ledctl_on << (i << 3);
6064 case ID_LED_OFF1_DEF2:
6065 case ID_LED_OFF1_ON2:
6066 case ID_LED_OFF1_OFF2:
6067 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
6068 hw->ledctl_mode1 |= ledctl_off << (i << 3);
6075 case ID_LED_DEF1_ON2:
6076 case ID_LED_ON1_ON2:
6077 case ID_LED_OFF1_ON2:
6078 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
6079 hw->ledctl_mode2 |= ledctl_on << (i << 3);
6081 case ID_LED_DEF1_OFF2:
6082 case ID_LED_ON1_OFF2:
6083 case ID_LED_OFF1_OFF2:
6084 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
6085 hw->ledctl_mode2 |= ledctl_off << (i << 3);
6092 return E1000_SUCCESS;
6095 /******************************************************************************
6096 * Prepares SW controlable LED for use and saves the current state of the LED.
6098 * hw - Struct containing variables accessed by shared code
6099 *****************************************************************************/
6101 e1000_setup_led(struct e1000_hw *hw)
6104 int32_t ret_val = E1000_SUCCESS;
6106 DEBUGFUNC("e1000_setup_led");
6108 switch (hw->mac_type) {
6109 case e1000_82542_rev2_0:
6110 case e1000_82542_rev2_1:
6113 /* No setup necessary */
6117 case e1000_82541_rev_2:
6118 case e1000_82547_rev_2:
6119 /* Turn off PHY Smart Power Down (if enabled) */
6120 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
6121 &hw->phy_spd_default);
6124 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
6125 (uint16_t)(hw->phy_spd_default &
6126 ~IGP01E1000_GMII_SPD));
6131 if (hw->media_type == e1000_media_type_fiber) {
6132 ledctl = E1000_READ_REG(hw, LEDCTL);
6133 /* Save current LEDCTL settings */
6134 hw->ledctl_default = ledctl;
6136 ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
6137 E1000_LEDCTL_LED0_BLINK |
6138 E1000_LEDCTL_LED0_MODE_MASK);
6139 ledctl |= (E1000_LEDCTL_MODE_LED_OFF <<
6140 E1000_LEDCTL_LED0_MODE_SHIFT);
6141 E1000_WRITE_REG(hw, LEDCTL, ledctl);
6142 } else if (hw->media_type == e1000_media_type_copper)
6143 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
6147 return E1000_SUCCESS;
6151 /******************************************************************************
6152 * Used on 82571 and later Si that has LED blink bits.
6153 * Callers must use their own timer and should have already called
6154 * e1000_id_led_init()
6155 * Call e1000_cleanup led() to stop blinking
6157 * hw - Struct containing variables accessed by shared code
6158 *****************************************************************************/
6160 e1000_blink_led_start(struct e1000_hw *hw)
6163 uint32_t ledctl_blink = 0;
6165 DEBUGFUNC("e1000_id_led_blink_on");
6167 if (hw->mac_type < e1000_82571) {
6169 return E1000_SUCCESS;
6171 if (hw->media_type == e1000_media_type_fiber) {
6172 /* always blink LED0 for PCI-E fiber */
6173 ledctl_blink = E1000_LEDCTL_LED0_BLINK |
6174 (E1000_LEDCTL_MODE_LED_ON << E1000_LEDCTL_LED0_MODE_SHIFT);
6176 /* set the blink bit for each LED that's "on" (0x0E) in ledctl_mode2 */
6177 ledctl_blink = hw->ledctl_mode2;
6178 for (i=0; i < 4; i++)
6179 if (((hw->ledctl_mode2 >> (i * 8)) & 0xFF) ==
6180 E1000_LEDCTL_MODE_LED_ON)
6181 ledctl_blink |= (E1000_LEDCTL_LED0_BLINK << (i * 8));
6184 E1000_WRITE_REG(hw, LEDCTL, ledctl_blink);
6186 return E1000_SUCCESS;
6189 /******************************************************************************
6190 * Restores the saved state of the SW controlable LED.
6192 * hw - Struct containing variables accessed by shared code
6193 *****************************************************************************/
6195 e1000_cleanup_led(struct e1000_hw *hw)
6197 int32_t ret_val = E1000_SUCCESS;
6199 DEBUGFUNC("e1000_cleanup_led");
6201 switch (hw->mac_type) {
6202 case e1000_82542_rev2_0:
6203 case e1000_82542_rev2_1:
6206 /* No cleanup necessary */
6210 case e1000_82541_rev_2:
6211 case e1000_82547_rev_2:
6212 /* Turn on PHY Smart Power Down (if previously enabled) */
6213 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
6214 hw->phy_spd_default);
6219 if (hw->phy_type == e1000_phy_ife) {
6220 e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
6223 /* Restore LEDCTL settings */
6224 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_default);
6228 return E1000_SUCCESS;
6231 /******************************************************************************
6232 * Turns on the software controllable LED
6234 * hw - Struct containing variables accessed by shared code
6235 *****************************************************************************/
6237 e1000_led_on(struct e1000_hw *hw)
6239 uint32_t ctrl = E1000_READ_REG(hw, CTRL);
6241 DEBUGFUNC("e1000_led_on");
6243 switch (hw->mac_type) {
6244 case e1000_82542_rev2_0:
6245 case e1000_82542_rev2_1:
6247 /* Set SW Defineable Pin 0 to turn on the LED */
6248 ctrl |= E1000_CTRL_SWDPIN0;
6249 ctrl |= E1000_CTRL_SWDPIO0;
6252 if (hw->media_type == e1000_media_type_fiber) {
6253 /* Set SW Defineable Pin 0 to turn on the LED */
6254 ctrl |= E1000_CTRL_SWDPIN0;
6255 ctrl |= E1000_CTRL_SWDPIO0;
6257 /* Clear SW Defineable Pin 0 to turn on the LED */
6258 ctrl &= ~E1000_CTRL_SWDPIN0;
6259 ctrl |= E1000_CTRL_SWDPIO0;
6263 if (hw->media_type == e1000_media_type_fiber) {
6264 /* Clear SW Defineable Pin 0 to turn on the LED */
6265 ctrl &= ~E1000_CTRL_SWDPIN0;
6266 ctrl |= E1000_CTRL_SWDPIO0;
6267 } else if (hw->phy_type == e1000_phy_ife) {
6268 e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED,
6269 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_ON));
6270 } else if (hw->media_type == e1000_media_type_copper) {
6271 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode2);
6272 return E1000_SUCCESS;
6277 E1000_WRITE_REG(hw, CTRL, ctrl);
6279 return E1000_SUCCESS;
6282 /******************************************************************************
6283 * Turns off the software controllable LED
6285 * hw - Struct containing variables accessed by shared code
6286 *****************************************************************************/
6288 e1000_led_off(struct e1000_hw *hw)
6290 uint32_t ctrl = E1000_READ_REG(hw, CTRL);
6292 DEBUGFUNC("e1000_led_off");
6294 switch (hw->mac_type) {
6295 case e1000_82542_rev2_0:
6296 case e1000_82542_rev2_1:
6298 /* Clear SW Defineable Pin 0 to turn off the LED */
6299 ctrl &= ~E1000_CTRL_SWDPIN0;
6300 ctrl |= E1000_CTRL_SWDPIO0;
6303 if (hw->media_type == e1000_media_type_fiber) {
6304 /* Clear SW Defineable Pin 0 to turn off the LED */
6305 ctrl &= ~E1000_CTRL_SWDPIN0;
6306 ctrl |= E1000_CTRL_SWDPIO0;
6308 /* Set SW Defineable Pin 0 to turn off the LED */
6309 ctrl |= E1000_CTRL_SWDPIN0;
6310 ctrl |= E1000_CTRL_SWDPIO0;
6314 if (hw->media_type == e1000_media_type_fiber) {
6315 /* Set SW Defineable Pin 0 to turn off the LED */
6316 ctrl |= E1000_CTRL_SWDPIN0;
6317 ctrl |= E1000_CTRL_SWDPIO0;
6318 } else if (hw->phy_type == e1000_phy_ife) {
6319 e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED,
6320 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_OFF));
6321 } else if (hw->media_type == e1000_media_type_copper) {
6322 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
6323 return E1000_SUCCESS;
6328 E1000_WRITE_REG(hw, CTRL, ctrl);
6330 return E1000_SUCCESS;
6333 /******************************************************************************
6334 * Clears all hardware statistics counters.
6336 * hw - Struct containing variables accessed by shared code
6337 *****************************************************************************/
6339 e1000_clear_hw_cntrs(struct e1000_hw *hw)
6341 volatile uint32_t temp;
6343 temp = E1000_READ_REG(hw, CRCERRS);
6344 temp = E1000_READ_REG(hw, SYMERRS);
6345 temp = E1000_READ_REG(hw, MPC);
6346 temp = E1000_READ_REG(hw, SCC);
6347 temp = E1000_READ_REG(hw, ECOL);
6348 temp = E1000_READ_REG(hw, MCC);
6349 temp = E1000_READ_REG(hw, LATECOL);
6350 temp = E1000_READ_REG(hw, COLC);
6351 temp = E1000_READ_REG(hw, DC);
6352 temp = E1000_READ_REG(hw, SEC);
6353 temp = E1000_READ_REG(hw, RLEC);
6354 temp = E1000_READ_REG(hw, XONRXC);
6355 temp = E1000_READ_REG(hw, XONTXC);
6356 temp = E1000_READ_REG(hw, XOFFRXC);
6357 temp = E1000_READ_REG(hw, XOFFTXC);
6358 temp = E1000_READ_REG(hw, FCRUC);
6360 if (hw->mac_type != e1000_ich8lan) {
6361 temp = E1000_READ_REG(hw, PRC64);
6362 temp = E1000_READ_REG(hw, PRC127);
6363 temp = E1000_READ_REG(hw, PRC255);
6364 temp = E1000_READ_REG(hw, PRC511);
6365 temp = E1000_READ_REG(hw, PRC1023);
6366 temp = E1000_READ_REG(hw, PRC1522);
6369 temp = E1000_READ_REG(hw, GPRC);
6370 temp = E1000_READ_REG(hw, BPRC);
6371 temp = E1000_READ_REG(hw, MPRC);
6372 temp = E1000_READ_REG(hw, GPTC);
6373 temp = E1000_READ_REG(hw, GORCL);
6374 temp = E1000_READ_REG(hw, GORCH);
6375 temp = E1000_READ_REG(hw, GOTCL);
6376 temp = E1000_READ_REG(hw, GOTCH);
6377 temp = E1000_READ_REG(hw, RNBC);
6378 temp = E1000_READ_REG(hw, RUC);
6379 temp = E1000_READ_REG(hw, RFC);
6380 temp = E1000_READ_REG(hw, ROC);
6381 temp = E1000_READ_REG(hw, RJC);
6382 temp = E1000_READ_REG(hw, TORL);
6383 temp = E1000_READ_REG(hw, TORH);
6384 temp = E1000_READ_REG(hw, TOTL);
6385 temp = E1000_READ_REG(hw, TOTH);
6386 temp = E1000_READ_REG(hw, TPR);
6387 temp = E1000_READ_REG(hw, TPT);
6389 if (hw->mac_type != e1000_ich8lan) {
6390 temp = E1000_READ_REG(hw, PTC64);
6391 temp = E1000_READ_REG(hw, PTC127);
6392 temp = E1000_READ_REG(hw, PTC255);
6393 temp = E1000_READ_REG(hw, PTC511);
6394 temp = E1000_READ_REG(hw, PTC1023);
6395 temp = E1000_READ_REG(hw, PTC1522);
6398 temp = E1000_READ_REG(hw, MPTC);
6399 temp = E1000_READ_REG(hw, BPTC);
6401 if (hw->mac_type < e1000_82543) return;
6403 temp = E1000_READ_REG(hw, ALGNERRC);
6404 temp = E1000_READ_REG(hw, RXERRC);
6405 temp = E1000_READ_REG(hw, TNCRS);
6406 temp = E1000_READ_REG(hw, CEXTERR);
6407 temp = E1000_READ_REG(hw, TSCTC);
6408 temp = E1000_READ_REG(hw, TSCTFC);
6410 if (hw->mac_type <= e1000_82544) return;
6412 temp = E1000_READ_REG(hw, MGTPRC);
6413 temp = E1000_READ_REG(hw, MGTPDC);
6414 temp = E1000_READ_REG(hw, MGTPTC);
6416 if (hw->mac_type <= e1000_82547_rev_2) return;
6418 temp = E1000_READ_REG(hw, IAC);
6419 temp = E1000_READ_REG(hw, ICRXOC);
6421 if (hw->mac_type == e1000_ich8lan) return;
6423 temp = E1000_READ_REG(hw, ICRXPTC);
6424 temp = E1000_READ_REG(hw, ICRXATC);
6425 temp = E1000_READ_REG(hw, ICTXPTC);
6426 temp = E1000_READ_REG(hw, ICTXATC);
6427 temp = E1000_READ_REG(hw, ICTXQEC);
6428 temp = E1000_READ_REG(hw, ICTXQMTC);
6429 temp = E1000_READ_REG(hw, ICRXDMTC);
6432 /******************************************************************************
6433 * Resets Adaptive IFS to its default state.
6435 * hw - Struct containing variables accessed by shared code
6437 * Call this after e1000_init_hw. You may override the IFS defaults by setting
6438 * hw->ifs_params_forced to TRUE. However, you must initialize hw->
6439 * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio
6440 * before calling this function.
6441 *****************************************************************************/
6443 e1000_reset_adaptive(struct e1000_hw *hw)
6445 DEBUGFUNC("e1000_reset_adaptive");
6447 if (hw->adaptive_ifs) {
6448 if (!hw->ifs_params_forced) {
6449 hw->current_ifs_val = 0;
6450 hw->ifs_min_val = IFS_MIN;
6451 hw->ifs_max_val = IFS_MAX;
6452 hw->ifs_step_size = IFS_STEP;
6453 hw->ifs_ratio = IFS_RATIO;
6455 hw->in_ifs_mode = FALSE;
6456 E1000_WRITE_REG(hw, AIT, 0);
6458 DEBUGOUT("Not in Adaptive IFS mode!\n");
6462 /******************************************************************************
6463 * Called during the callback/watchdog routine to update IFS value based on
6464 * the ratio of transmits to collisions.
6466 * hw - Struct containing variables accessed by shared code
6467 * tx_packets - Number of transmits since last callback
6468 * total_collisions - Number of collisions since last callback
6469 *****************************************************************************/
6471 e1000_update_adaptive(struct e1000_hw *hw)
6473 DEBUGFUNC("e1000_update_adaptive");
6475 if (hw->adaptive_ifs) {
6476 if ((hw->collision_delta * hw->ifs_ratio) > hw->tx_packet_delta) {
6477 if (hw->tx_packet_delta > MIN_NUM_XMITS) {
6478 hw->in_ifs_mode = TRUE;
6479 if (hw->current_ifs_val < hw->ifs_max_val) {
6480 if (hw->current_ifs_val == 0)
6481 hw->current_ifs_val = hw->ifs_min_val;
6483 hw->current_ifs_val += hw->ifs_step_size;
6484 E1000_WRITE_REG(hw, AIT, hw->current_ifs_val);
6488 if (hw->in_ifs_mode && (hw->tx_packet_delta <= MIN_NUM_XMITS)) {
6489 hw->current_ifs_val = 0;
6490 hw->in_ifs_mode = FALSE;
6491 E1000_WRITE_REG(hw, AIT, 0);
6495 DEBUGOUT("Not in Adaptive IFS mode!\n");
6499 /******************************************************************************
6500 * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT
6502 * hw - Struct containing variables accessed by shared code
6503 * frame_len - The length of the frame in question
6504 * mac_addr - The Ethernet destination address of the frame in question
6505 *****************************************************************************/
6507 e1000_tbi_adjust_stats(struct e1000_hw *hw,
6508 struct e1000_hw_stats *stats,
6514 /* First adjust the frame length. */
6516 /* We need to adjust the statistics counters, since the hardware
6517 * counters overcount this packet as a CRC error and undercount
6518 * the packet as a good packet
6520 /* This packet should not be counted as a CRC error. */
6522 /* This packet does count as a Good Packet Received. */
6525 /* Adjust the Good Octets received counters */
6526 carry_bit = 0x80000000 & stats->gorcl;
6527 stats->gorcl += frame_len;
6528 /* If the high bit of Gorcl (the low 32 bits of the Good Octets
6529 * Received Count) was one before the addition,
6530 * AND it is zero after, then we lost the carry out,
6531 * need to add one to Gorch (Good Octets Received Count High).
6532 * This could be simplified if all environments supported
6535 if (carry_bit && ((stats->gorcl & 0x80000000) == 0))
6537 /* Is this a broadcast or multicast? Check broadcast first,
6538 * since the test for a multicast frame will test positive on
6539 * a broadcast frame.
6541 if ((mac_addr[0] == (uint8_t) 0xff) && (mac_addr[1] == (uint8_t) 0xff))
6542 /* Broadcast packet */
6544 else if (*mac_addr & 0x01)
6545 /* Multicast packet */
6548 if (frame_len == hw->max_frame_size) {
6549 /* In this case, the hardware has overcounted the number of
6556 /* Adjust the bin counters when the extra byte put the frame in the
6557 * wrong bin. Remember that the frame_len was adjusted above.
6559 if (frame_len == 64) {
6562 } else if (frame_len == 127) {
6565 } else if (frame_len == 255) {
6568 } else if (frame_len == 511) {
6571 } else if (frame_len == 1023) {
6574 } else if (frame_len == 1522) {
6579 /******************************************************************************
6580 * Gets the current PCI bus type, speed, and width of the hardware
6582 * hw - Struct containing variables accessed by shared code
6583 *****************************************************************************/
6585 e1000_get_bus_info(struct e1000_hw *hw)
6588 uint16_t pci_ex_link_status;
6591 switch (hw->mac_type) {
6592 case e1000_82542_rev2_0:
6593 case e1000_82542_rev2_1:
6594 hw->bus_type = e1000_bus_type_unknown;
6595 hw->bus_speed = e1000_bus_speed_unknown;
6596 hw->bus_width = e1000_bus_width_unknown;
6601 case e1000_80003es2lan:
6602 hw->bus_type = e1000_bus_type_pci_express;
6603 hw->bus_speed = e1000_bus_speed_2500;
6604 ret_val = e1000_read_pcie_cap_reg(hw,
6606 &pci_ex_link_status);
6608 hw->bus_width = e1000_bus_width_unknown;
6610 hw->bus_width = (pci_ex_link_status & PCI_EX_LINK_WIDTH_MASK) >>
6611 PCI_EX_LINK_WIDTH_SHIFT;
6614 hw->bus_type = e1000_bus_type_pci_express;
6615 hw->bus_speed = e1000_bus_speed_2500;
6616 hw->bus_width = e1000_bus_width_pciex_1;
6619 status = E1000_READ_REG(hw, STATUS);
6620 hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
6621 e1000_bus_type_pcix : e1000_bus_type_pci;
6623 if (hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) {
6624 hw->bus_speed = (hw->bus_type == e1000_bus_type_pci) ?
6625 e1000_bus_speed_66 : e1000_bus_speed_120;
6626 } else if (hw->bus_type == e1000_bus_type_pci) {
6627 hw->bus_speed = (status & E1000_STATUS_PCI66) ?
6628 e1000_bus_speed_66 : e1000_bus_speed_33;
6630 switch (status & E1000_STATUS_PCIX_SPEED) {
6631 case E1000_STATUS_PCIX_SPEED_66:
6632 hw->bus_speed = e1000_bus_speed_66;
6634 case E1000_STATUS_PCIX_SPEED_100:
6635 hw->bus_speed = e1000_bus_speed_100;
6637 case E1000_STATUS_PCIX_SPEED_133:
6638 hw->bus_speed = e1000_bus_speed_133;
6641 hw->bus_speed = e1000_bus_speed_reserved;
6645 hw->bus_width = (status & E1000_STATUS_BUS64) ?
6646 e1000_bus_width_64 : e1000_bus_width_32;
6651 /******************************************************************************
6652 * Writes a value to one of the devices registers using port I/O (as opposed to
6653 * memory mapped I/O). Only 82544 and newer devices support port I/O.
6655 * hw - Struct containing variables accessed by shared code
6656 * offset - offset to write to
6657 * value - value to write
6658 *****************************************************************************/
6660 e1000_write_reg_io(struct e1000_hw *hw,
6664 unsigned long io_addr = hw->io_base;
6665 unsigned long io_data = hw->io_base + 4;
6667 e1000_io_write(hw, io_addr, offset);
6668 e1000_io_write(hw, io_data, value);
6671 /******************************************************************************
6672 * Estimates the cable length.
6674 * hw - Struct containing variables accessed by shared code
6675 * min_length - The estimated minimum length
6676 * max_length - The estimated maximum length
6678 * returns: - E1000_ERR_XXX
6681 * This function always returns a ranged length (minimum & maximum).
6682 * So for M88 phy's, this function interprets the one value returned from the
6683 * register to the minimum and maximum range.
6684 * For IGP phy's, the function calculates the range by the AGC registers.
6685 *****************************************************************************/
6687 e1000_get_cable_length(struct e1000_hw *hw,
6688 uint16_t *min_length,
6689 uint16_t *max_length)
6692 uint16_t agc_value = 0;
6693 uint16_t i, phy_data;
6694 uint16_t cable_length;
6696 DEBUGFUNC("e1000_get_cable_length");
6698 *min_length = *max_length = 0;
6700 /* Use old method for Phy older than IGP */
6701 if (hw->phy_type == e1000_phy_m88) {
6703 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6707 cable_length = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
6708 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
6710 /* Convert the enum value to ranged values */
6711 switch (cable_length) {
6712 case e1000_cable_length_50:
6714 *max_length = e1000_igp_cable_length_50;
6716 case e1000_cable_length_50_80:
6717 *min_length = e1000_igp_cable_length_50;
6718 *max_length = e1000_igp_cable_length_80;
6720 case e1000_cable_length_80_110:
6721 *min_length = e1000_igp_cable_length_80;
6722 *max_length = e1000_igp_cable_length_110;
6724 case e1000_cable_length_110_140:
6725 *min_length = e1000_igp_cable_length_110;
6726 *max_length = e1000_igp_cable_length_140;
6728 case e1000_cable_length_140:
6729 *min_length = e1000_igp_cable_length_140;
6730 *max_length = e1000_igp_cable_length_170;
6733 return -E1000_ERR_PHY;
6736 } else if (hw->phy_type == e1000_phy_gg82563) {
6737 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_DSP_DISTANCE,
6741 cable_length = phy_data & GG82563_DSPD_CABLE_LENGTH;
6743 switch (cable_length) {
6744 case e1000_gg_cable_length_60:
6746 *max_length = e1000_igp_cable_length_60;
6748 case e1000_gg_cable_length_60_115:
6749 *min_length = e1000_igp_cable_length_60;
6750 *max_length = e1000_igp_cable_length_115;
6752 case e1000_gg_cable_length_115_150:
6753 *min_length = e1000_igp_cable_length_115;
6754 *max_length = e1000_igp_cable_length_150;
6756 case e1000_gg_cable_length_150:
6757 *min_length = e1000_igp_cable_length_150;
6758 *max_length = e1000_igp_cable_length_180;
6761 return -E1000_ERR_PHY;
6764 } else if (hw->phy_type == e1000_phy_igp) { /* For IGP PHY */
6765 uint16_t cur_agc_value;
6766 uint16_t min_agc_value = IGP01E1000_AGC_LENGTH_TABLE_SIZE;
6767 uint16_t agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
6768 {IGP01E1000_PHY_AGC_A,
6769 IGP01E1000_PHY_AGC_B,
6770 IGP01E1000_PHY_AGC_C,
6771 IGP01E1000_PHY_AGC_D};
6772 /* Read the AGC registers for all channels */
6773 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
6775 ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
6779 cur_agc_value = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT;
6781 /* Value bound check. */
6782 if ((cur_agc_value >= IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1) ||
6783 (cur_agc_value == 0))
6784 return -E1000_ERR_PHY;
6786 agc_value += cur_agc_value;
6788 /* Update minimal AGC value. */
6789 if (min_agc_value > cur_agc_value)
6790 min_agc_value = cur_agc_value;
6793 /* Remove the minimal AGC result for length < 50m */
6794 if (agc_value < IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) {
6795 agc_value -= min_agc_value;
6797 /* Get the average length of the remaining 3 channels */
6798 agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1);
6800 /* Get the average length of all the 4 channels. */
6801 agc_value /= IGP01E1000_PHY_CHANNEL_NUM;
6804 /* Set the range of the calculated length. */
6805 *min_length = ((e1000_igp_cable_length_table[agc_value] -
6806 IGP01E1000_AGC_RANGE) > 0) ?
6807 (e1000_igp_cable_length_table[agc_value] -
6808 IGP01E1000_AGC_RANGE) : 0;
6809 *max_length = e1000_igp_cable_length_table[agc_value] +
6810 IGP01E1000_AGC_RANGE;
6811 } else if (hw->phy_type == e1000_phy_igp_2 ||
6812 hw->phy_type == e1000_phy_igp_3) {
6813 uint16_t cur_agc_index, max_agc_index = 0;
6814 uint16_t min_agc_index = IGP02E1000_AGC_LENGTH_TABLE_SIZE - 1;
6815 uint16_t agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] =
6816 {IGP02E1000_PHY_AGC_A,
6817 IGP02E1000_PHY_AGC_B,
6818 IGP02E1000_PHY_AGC_C,
6819 IGP02E1000_PHY_AGC_D};
6820 /* Read the AGC registers for all channels */
6821 for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
6822 ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
6826 /* Getting bits 15:9, which represent the combination of course and
6827 * fine gain values. The result is a number that can be put into
6828 * the lookup table to obtain the approximate cable length. */
6829 cur_agc_index = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
6830 IGP02E1000_AGC_LENGTH_MASK;
6832 /* Array index bound check. */
6833 if ((cur_agc_index >= IGP02E1000_AGC_LENGTH_TABLE_SIZE) ||
6834 (cur_agc_index == 0))
6835 return -E1000_ERR_PHY;
6837 /* Remove min & max AGC values from calculation. */
6838 if (e1000_igp_2_cable_length_table[min_agc_index] >
6839 e1000_igp_2_cable_length_table[cur_agc_index])
6840 min_agc_index = cur_agc_index;
6841 if (e1000_igp_2_cable_length_table[max_agc_index] <
6842 e1000_igp_2_cable_length_table[cur_agc_index])
6843 max_agc_index = cur_agc_index;
6845 agc_value += e1000_igp_2_cable_length_table[cur_agc_index];
6848 agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] +
6849 e1000_igp_2_cable_length_table[max_agc_index]);
6850 agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
6852 /* Calculate cable length with the error range of +/- 10 meters. */
6853 *min_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
6854 (agc_value - IGP02E1000_AGC_RANGE) : 0;
6855 *max_length = agc_value + IGP02E1000_AGC_RANGE;
6858 return E1000_SUCCESS;
6861 /******************************************************************************
6862 * Check the cable polarity
6864 * hw - Struct containing variables accessed by shared code
6865 * polarity - output parameter : 0 - Polarity is not reversed
6866 * 1 - Polarity is reversed.
6868 * returns: - E1000_ERR_XXX
6871 * For phy's older then IGP, this function simply reads the polarity bit in the
6872 * Phy Status register. For IGP phy's, this bit is valid only if link speed is
6873 * 10 Mbps. If the link speed is 100 Mbps there is no polarity so this bit will
6874 * return 0. If the link speed is 1000 Mbps the polarity status is in the
6875 * IGP01E1000_PHY_PCS_INIT_REG.
6876 *****************************************************************************/
6878 e1000_check_polarity(struct e1000_hw *hw,
6879 e1000_rev_polarity *polarity)
6884 DEBUGFUNC("e1000_check_polarity");
6886 if ((hw->phy_type == e1000_phy_m88) ||
6887 (hw->phy_type == e1000_phy_gg82563)) {
6888 /* return the Polarity bit in the Status register. */
6889 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6893 *polarity = ((phy_data & M88E1000_PSSR_REV_POLARITY) >>
6894 M88E1000_PSSR_REV_POLARITY_SHIFT) ?
6895 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
6897 } else if (hw->phy_type == e1000_phy_igp ||
6898 hw->phy_type == e1000_phy_igp_3 ||
6899 hw->phy_type == e1000_phy_igp_2) {
6900 /* Read the Status register to check the speed */
6901 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
6906 /* If speed is 1000 Mbps, must read the IGP01E1000_PHY_PCS_INIT_REG to
6907 * find the polarity status */
6908 if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
6909 IGP01E1000_PSSR_SPEED_1000MBPS) {
6911 /* Read the GIG initialization PCS register (0x00B4) */
6912 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG,
6917 /* Check the polarity bits */
6918 *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ?
6919 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
6921 /* For 10 Mbps, read the polarity bit in the status register. (for
6922 * 100 Mbps this bit is always 0) */
6923 *polarity = (phy_data & IGP01E1000_PSSR_POLARITY_REVERSED) ?
6924 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
6926 } else if (hw->phy_type == e1000_phy_ife) {
6927 ret_val = e1000_read_phy_reg(hw, IFE_PHY_EXTENDED_STATUS_CONTROL,
6931 *polarity = ((phy_data & IFE_PESC_POLARITY_REVERSED) >>
6932 IFE_PESC_POLARITY_REVERSED_SHIFT) ?
6933 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
6935 return E1000_SUCCESS;
6938 /******************************************************************************
6939 * Check if Downshift occured
6941 * hw - Struct containing variables accessed by shared code
6942 * downshift - output parameter : 0 - No Downshift ocured.
6943 * 1 - Downshift ocured.
6945 * returns: - E1000_ERR_XXX
6948 * For phy's older then IGP, this function reads the Downshift bit in the Phy
6949 * Specific Status register. For IGP phy's, it reads the Downgrade bit in the
6950 * Link Health register. In IGP this bit is latched high, so the driver must
6951 * read it immediately after link is established.
6952 *****************************************************************************/
6954 e1000_check_downshift(struct e1000_hw *hw)
6959 DEBUGFUNC("e1000_check_downshift");
6961 if (hw->phy_type == e1000_phy_igp ||
6962 hw->phy_type == e1000_phy_igp_3 ||
6963 hw->phy_type == e1000_phy_igp_2) {
6964 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH,
6969 hw->speed_downgraded = (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0;
6970 } else if ((hw->phy_type == e1000_phy_m88) ||
6971 (hw->phy_type == e1000_phy_gg82563)) {
6972 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6977 hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >>
6978 M88E1000_PSSR_DOWNSHIFT_SHIFT;
6979 } else if (hw->phy_type == e1000_phy_ife) {
6980 /* e1000_phy_ife supports 10/100 speed only */
6981 hw->speed_downgraded = FALSE;
6984 return E1000_SUCCESS;
6987 /*****************************************************************************
6989 * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a
6990 * gigabit link is achieved to improve link quality.
6992 * hw: Struct containing variables accessed by shared code
6994 * returns: - E1000_ERR_PHY if fail to read/write the PHY
6995 * E1000_SUCCESS at any other case.
6997 ****************************************************************************/
7000 e1000_config_dsp_after_link_change(struct e1000_hw *hw,
7004 uint16_t phy_data, phy_saved_data, speed, duplex, i;
7005 uint16_t dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
7006 {IGP01E1000_PHY_AGC_PARAM_A,
7007 IGP01E1000_PHY_AGC_PARAM_B,
7008 IGP01E1000_PHY_AGC_PARAM_C,
7009 IGP01E1000_PHY_AGC_PARAM_D};
7010 uint16_t min_length, max_length;
7012 DEBUGFUNC("e1000_config_dsp_after_link_change");
7014 if (hw->phy_type != e1000_phy_igp)
7015 return E1000_SUCCESS;
7018 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
7020 DEBUGOUT("Error getting link speed and duplex\n");
7024 if (speed == SPEED_1000) {
7026 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
7030 if ((hw->dsp_config_state == e1000_dsp_config_enabled) &&
7031 min_length >= e1000_igp_cable_length_50) {
7033 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
7034 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i],
7039 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
7041 ret_val = e1000_write_phy_reg(hw, dsp_reg_array[i],
7046 hw->dsp_config_state = e1000_dsp_config_activated;
7049 if ((hw->ffe_config_state == e1000_ffe_config_enabled) &&
7050 (min_length < e1000_igp_cable_length_50)) {
7052 uint16_t ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_20;
7053 uint32_t idle_errs = 0;
7055 /* clear previous idle error counts */
7056 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
7061 for (i = 0; i < ffe_idle_err_timeout; i++) {
7063 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
7068 idle_errs += (phy_data & SR_1000T_IDLE_ERROR_CNT);
7069 if (idle_errs > SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT) {
7070 hw->ffe_config_state = e1000_ffe_config_active;
7072 ret_val = e1000_write_phy_reg(hw,
7073 IGP01E1000_PHY_DSP_FFE,
7074 IGP01E1000_PHY_DSP_FFE_CM_CP);
7081 ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_100;
7086 if (hw->dsp_config_state == e1000_dsp_config_activated) {
7087 /* Save off the current value of register 0x2F5B to be restored at
7088 * the end of the routines. */
7089 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
7094 /* Disable the PHY transmitter */
7095 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
7102 ret_val = e1000_write_phy_reg(hw, 0x0000,
7103 IGP01E1000_IEEE_FORCE_GIGA);
7106 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
7107 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i], &phy_data);
7111 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
7112 phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS;
7114 ret_val = e1000_write_phy_reg(hw,dsp_reg_array[i], phy_data);
7119 ret_val = e1000_write_phy_reg(hw, 0x0000,
7120 IGP01E1000_IEEE_RESTART_AUTONEG);
7126 /* Now enable the transmitter */
7127 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
7132 hw->dsp_config_state = e1000_dsp_config_enabled;
7135 if (hw->ffe_config_state == e1000_ffe_config_active) {
7136 /* Save off the current value of register 0x2F5B to be restored at
7137 * the end of the routines. */
7138 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
7143 /* Disable the PHY transmitter */
7144 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
7151 ret_val = e1000_write_phy_reg(hw, 0x0000,
7152 IGP01E1000_IEEE_FORCE_GIGA);
7155 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE,
7156 IGP01E1000_PHY_DSP_FFE_DEFAULT);
7160 ret_val = e1000_write_phy_reg(hw, 0x0000,
7161 IGP01E1000_IEEE_RESTART_AUTONEG);
7167 /* Now enable the transmitter */
7168 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
7173 hw->ffe_config_state = e1000_ffe_config_enabled;
7176 return E1000_SUCCESS;
7179 /*****************************************************************************
7180 * Set PHY to class A mode
7181 * Assumes the following operations will follow to enable the new class mode.
7182 * 1. Do a PHY soft reset
7183 * 2. Restart auto-negotiation or force link.
7185 * hw - Struct containing variables accessed by shared code
7186 ****************************************************************************/
7188 e1000_set_phy_mode(struct e1000_hw *hw)
7191 uint16_t eeprom_data;
7193 DEBUGFUNC("e1000_set_phy_mode");
7195 if ((hw->mac_type == e1000_82545_rev_3) &&
7196 (hw->media_type == e1000_media_type_copper)) {
7197 ret_val = e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, 1, &eeprom_data);
7202 if ((eeprom_data != EEPROM_RESERVED_WORD) &&
7203 (eeprom_data & EEPROM_PHY_CLASS_A)) {
7204 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x000B);
7207 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x8104);
7211 hw->phy_reset_disable = FALSE;
7215 return E1000_SUCCESS;
7218 /*****************************************************************************
7220 * This function sets the lplu state according to the active flag. When
7221 * activating lplu this function also disables smart speed and vise versa.
7222 * lplu will not be activated unless the device autonegotiation advertisment
7223 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
7224 * hw: Struct containing variables accessed by shared code
7225 * active - true to enable lplu false to disable lplu.
7227 * returns: - E1000_ERR_PHY if fail to read/write the PHY
7228 * E1000_SUCCESS at any other case.
7230 ****************************************************************************/
7233 e1000_set_d3_lplu_state(struct e1000_hw *hw,
7236 uint32_t phy_ctrl = 0;
7239 DEBUGFUNC("e1000_set_d3_lplu_state");
7241 if (hw->phy_type != e1000_phy_igp && hw->phy_type != e1000_phy_igp_2
7242 && hw->phy_type != e1000_phy_igp_3)
7243 return E1000_SUCCESS;
7245 /* During driver activity LPLU should not be used or it will attain link
7246 * from the lowest speeds starting from 10Mbps. The capability is used for
7247 * Dx transitions and states */
7248 if (hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2) {
7249 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data);
7252 } else if (hw->mac_type == e1000_ich8lan) {
7253 /* MAC writes into PHY register based on the state transition
7254 * and start auto-negotiation. SW driver can overwrite the settings
7255 * in CSR PHY power control E1000_PHY_CTRL register. */
7256 phy_ctrl = E1000_READ_REG(hw, PHY_CTRL);
7258 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
7264 if (hw->mac_type == e1000_82541_rev_2 ||
7265 hw->mac_type == e1000_82547_rev_2) {
7266 phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
7267 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
7271 if (hw->mac_type == e1000_ich8lan) {
7272 phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
7273 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7275 phy_data &= ~IGP02E1000_PM_D3_LPLU;
7276 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
7283 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
7284 * Dx states where the power conservation is most important. During
7285 * driver activity we should enable SmartSpeed, so performance is
7287 if (hw->smart_speed == e1000_smart_speed_on) {
7288 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7293 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
7294 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7298 } else if (hw->smart_speed == e1000_smart_speed_off) {
7299 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7304 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7305 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7311 } else if ((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT) ||
7312 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL ) ||
7313 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) {
7315 if (hw->mac_type == e1000_82541_rev_2 ||
7316 hw->mac_type == e1000_82547_rev_2) {
7317 phy_data |= IGP01E1000_GMII_FLEX_SPD;
7318 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
7322 if (hw->mac_type == e1000_ich8lan) {
7323 phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
7324 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7326 phy_data |= IGP02E1000_PM_D3_LPLU;
7327 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
7334 /* When LPLU is enabled we should disable SmartSpeed */
7335 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
7339 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7340 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
7345 return E1000_SUCCESS;
7348 /*****************************************************************************
7350 * This function sets the lplu d0 state according to the active flag. When
7351 * activating lplu this function also disables smart speed and vise versa.
7352 * lplu will not be activated unless the device autonegotiation advertisment
7353 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
7354 * hw: Struct containing variables accessed by shared code
7355 * active - true to enable lplu false to disable lplu.
7357 * returns: - E1000_ERR_PHY if fail to read/write the PHY
7358 * E1000_SUCCESS at any other case.
7360 ****************************************************************************/
7363 e1000_set_d0_lplu_state(struct e1000_hw *hw,
7366 uint32_t phy_ctrl = 0;
7369 DEBUGFUNC("e1000_set_d0_lplu_state");
7371 if (hw->mac_type <= e1000_82547_rev_2)
7372 return E1000_SUCCESS;
7374 if (hw->mac_type == e1000_ich8lan) {
7375 phy_ctrl = E1000_READ_REG(hw, PHY_CTRL);
7377 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
7383 if (hw->mac_type == e1000_ich8lan) {
7384 phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
7385 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7387 phy_data &= ~IGP02E1000_PM_D0_LPLU;
7388 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
7393 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
7394 * Dx states where the power conservation is most important. During
7395 * driver activity we should enable SmartSpeed, so performance is
7397 if (hw->smart_speed == e1000_smart_speed_on) {
7398 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7403 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
7404 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7408 } else if (hw->smart_speed == e1000_smart_speed_off) {
7409 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7414 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7415 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7424 if (hw->mac_type == e1000_ich8lan) {
7425 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
7426 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7428 phy_data |= IGP02E1000_PM_D0_LPLU;
7429 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
7434 /* When LPLU is enabled we should disable SmartSpeed */
7435 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
7439 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7440 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
7445 return E1000_SUCCESS;
7448 /******************************************************************************
7449 * Change VCO speed register to improve Bit Error Rate performance of SERDES.
7451 * hw - Struct containing variables accessed by shared code
7452 *****************************************************************************/
7454 e1000_set_vco_speed(struct e1000_hw *hw)
7457 uint16_t default_page = 0;
7460 DEBUGFUNC("e1000_set_vco_speed");
7462 switch (hw->mac_type) {
7463 case e1000_82545_rev_3:
7464 case e1000_82546_rev_3:
7467 return E1000_SUCCESS;
7470 /* Set PHY register 30, page 5, bit 8 to 0 */
7472 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, &default_page);
7476 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005);
7480 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
7484 phy_data &= ~M88E1000_PHY_VCO_REG_BIT8;
7485 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
7489 /* Set PHY register 30, page 4, bit 11 to 1 */
7491 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004);
7495 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
7499 phy_data |= M88E1000_PHY_VCO_REG_BIT11;
7500 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
7504 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, default_page);
7508 return E1000_SUCCESS;
7512 /*****************************************************************************
7513 * This function reads the cookie from ARC ram.
7515 * returns: - E1000_SUCCESS .
7516 ****************************************************************************/
7518 e1000_host_if_read_cookie(struct e1000_hw * hw, uint8_t *buffer)
7521 uint32_t offset = E1000_MNG_DHCP_COOKIE_OFFSET;
7522 uint8_t length = E1000_MNG_DHCP_COOKIE_LENGTH;
7524 length = (length >> 2);
7525 offset = (offset >> 2);
7527 for (i = 0; i < length; i++) {
7528 *((uint32_t *) buffer + i) =
7529 E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset + i);
7531 return E1000_SUCCESS;
7535 /*****************************************************************************
7536 * This function checks whether the HOST IF is enabled for command operaton
7537 * and also checks whether the previous command is completed.
7538 * It busy waits in case of previous command is not completed.
7540 * returns: - E1000_ERR_HOST_INTERFACE_COMMAND in case if is not ready or
7542 * - E1000_SUCCESS for success.
7543 ****************************************************************************/
7545 e1000_mng_enable_host_if(struct e1000_hw * hw)
7550 /* Check that the host interface is enabled. */
7551 hicr = E1000_READ_REG(hw, HICR);
7552 if ((hicr & E1000_HICR_EN) == 0) {
7553 DEBUGOUT("E1000_HOST_EN bit disabled.\n");
7554 return -E1000_ERR_HOST_INTERFACE_COMMAND;
7556 /* check the previous command is completed */
7557 for (i = 0; i < E1000_MNG_DHCP_COMMAND_TIMEOUT; i++) {
7558 hicr = E1000_READ_REG(hw, HICR);
7559 if (!(hicr & E1000_HICR_C))
7564 if (i == E1000_MNG_DHCP_COMMAND_TIMEOUT) {
7565 DEBUGOUT("Previous command timeout failed .\n");
7566 return -E1000_ERR_HOST_INTERFACE_COMMAND;
7568 return E1000_SUCCESS;
7571 /*****************************************************************************
7572 * This function writes the buffer content at the offset given on the host if.
7573 * It also does alignment considerations to do the writes in most efficient way.
7574 * Also fills up the sum of the buffer in *buffer parameter.
7576 * returns - E1000_SUCCESS for success.
7577 ****************************************************************************/
7579 e1000_mng_host_if_write(struct e1000_hw * hw, uint8_t *buffer,
7580 uint16_t length, uint16_t offset, uint8_t *sum)
7583 uint8_t *bufptr = buffer;
7585 uint16_t remaining, i, j, prev_bytes;
7587 /* sum = only sum of the data and it is not checksum */
7589 if (length == 0 || offset + length > E1000_HI_MAX_MNG_DATA_LENGTH) {
7590 return -E1000_ERR_PARAM;
7593 tmp = (uint8_t *)&data;
7594 prev_bytes = offset & 0x3;
7599 data = E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset);
7600 for (j = prev_bytes; j < sizeof(uint32_t); j++) {
7601 *(tmp + j) = *bufptr++;
7604 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset, data);
7605 length -= j - prev_bytes;
7609 remaining = length & 0x3;
7610 length -= remaining;
7612 /* Calculate length in DWORDs */
7615 /* The device driver writes the relevant command block into the
7617 for (i = 0; i < length; i++) {
7618 for (j = 0; j < sizeof(uint32_t); j++) {
7619 *(tmp + j) = *bufptr++;
7623 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data);
7626 for (j = 0; j < sizeof(uint32_t); j++) {
7628 *(tmp + j) = *bufptr++;
7634 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data);
7637 return E1000_SUCCESS;
7641 /*****************************************************************************
7642 * This function writes the command header after does the checksum calculation.
7644 * returns - E1000_SUCCESS for success.
7645 ****************************************************************************/
7647 e1000_mng_write_cmd_header(struct e1000_hw * hw,
7648 struct e1000_host_mng_command_header * hdr)
7654 /* Write the whole command header structure which includes sum of
7657 uint16_t length = sizeof(struct e1000_host_mng_command_header);
7659 sum = hdr->checksum;
7662 buffer = (uint8_t *) hdr;
7667 hdr->checksum = 0 - sum;
7670 /* The device driver writes the relevant command block into the ram area. */
7671 for (i = 0; i < length; i++) {
7672 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, i, *((uint32_t *) hdr + i));
7673 E1000_WRITE_FLUSH(hw);
7676 return E1000_SUCCESS;
7680 /*****************************************************************************
7681 * This function indicates to ARC that a new command is pending which completes
7682 * one write operation by the driver.
7684 * returns - E1000_SUCCESS for success.
7685 ****************************************************************************/
7687 e1000_mng_write_commit(struct e1000_hw * hw)
7691 hicr = E1000_READ_REG(hw, HICR);
7692 /* Setting this bit tells the ARC that a new command is pending. */
7693 E1000_WRITE_REG(hw, HICR, hicr | E1000_HICR_C);
7695 return E1000_SUCCESS;
7699 /*****************************************************************************
7700 * This function checks the mode of the firmware.
7702 * returns - TRUE when the mode is IAMT or FALSE.
7703 ****************************************************************************/
7705 e1000_check_mng_mode(struct e1000_hw *hw)
7709 fwsm = E1000_READ_REG(hw, FWSM);
7711 if (hw->mac_type == e1000_ich8lan) {
7712 if ((fwsm & E1000_FWSM_MODE_MASK) ==
7713 (E1000_MNG_ICH_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
7715 } else if ((fwsm & E1000_FWSM_MODE_MASK) ==
7716 (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
7723 /*****************************************************************************
7724 * This function writes the dhcp info .
7725 ****************************************************************************/
7727 e1000_mng_write_dhcp_info(struct e1000_hw * hw, uint8_t *buffer,
7731 struct e1000_host_mng_command_header hdr;
7733 hdr.command_id = E1000_MNG_DHCP_TX_PAYLOAD_CMD;
7734 hdr.command_length = length;
7739 ret_val = e1000_mng_enable_host_if(hw);
7740 if (ret_val == E1000_SUCCESS) {
7741 ret_val = e1000_mng_host_if_write(hw, buffer, length, sizeof(hdr),
7743 if (ret_val == E1000_SUCCESS) {
7744 ret_val = e1000_mng_write_cmd_header(hw, &hdr);
7745 if (ret_val == E1000_SUCCESS)
7746 ret_val = e1000_mng_write_commit(hw);
7753 /*****************************************************************************
7754 * This function calculates the checksum.
7756 * returns - checksum of buffer contents.
7757 ****************************************************************************/
7759 e1000_calculate_mng_checksum(char *buffer, uint32_t length)
7767 for (i=0; i < length; i++)
7770 return (uint8_t) (0 - sum);
7773 /*****************************************************************************
7774 * This function checks whether tx pkt filtering needs to be enabled or not.
7776 * returns - TRUE for packet filtering or FALSE.
7777 ****************************************************************************/
7779 e1000_enable_tx_pkt_filtering(struct e1000_hw *hw)
7781 /* called in init as well as watchdog timer functions */
7783 int32_t ret_val, checksum;
7784 boolean_t tx_filter = FALSE;
7785 struct e1000_host_mng_dhcp_cookie *hdr = &(hw->mng_cookie);
7786 uint8_t *buffer = (uint8_t *) &(hw->mng_cookie);
7788 if (e1000_check_mng_mode(hw)) {
7789 ret_val = e1000_mng_enable_host_if(hw);
7790 if (ret_val == E1000_SUCCESS) {
7791 ret_val = e1000_host_if_read_cookie(hw, buffer);
7792 if (ret_val == E1000_SUCCESS) {
7793 checksum = hdr->checksum;
7795 if ((hdr->signature == E1000_IAMT_SIGNATURE) &&
7796 checksum == e1000_calculate_mng_checksum((char *)buffer,
7797 E1000_MNG_DHCP_COOKIE_LENGTH)) {
7799 E1000_MNG_DHCP_COOKIE_STATUS_PARSING_SUPPORT)
7808 hw->tx_pkt_filtering = tx_filter;
7812 /******************************************************************************
7813 * Verifies the hardware needs to allow ARPs to be processed by the host
7815 * hw - Struct containing variables accessed by shared code
7817 * returns: - TRUE/FALSE
7819 *****************************************************************************/
7821 e1000_enable_mng_pass_thru(struct e1000_hw *hw)
7824 uint32_t fwsm, factps;
7826 if (hw->asf_firmware_present) {
7827 manc = E1000_READ_REG(hw, MANC);
7829 if (!(manc & E1000_MANC_RCV_TCO_EN) ||
7830 !(manc & E1000_MANC_EN_MAC_ADDR_FILTER))
7832 if (e1000_arc_subsystem_valid(hw) == TRUE) {
7833 fwsm = E1000_READ_REG(hw, FWSM);
7834 factps = E1000_READ_REG(hw, FACTPS);
7836 if ((((fwsm & E1000_FWSM_MODE_MASK) >> E1000_FWSM_MODE_SHIFT) ==
7837 e1000_mng_mode_pt) && !(factps & E1000_FACTPS_MNGCG))
7840 if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN))
7847 e1000_polarity_reversal_workaround(struct e1000_hw *hw)
7850 uint16_t mii_status_reg;
7853 /* Polarity reversal workaround for forced 10F/10H links. */
7855 /* Disable the transmitter on the PHY */
7857 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
7860 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF);
7864 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
7868 /* This loop will early-out if the NO link condition has been met. */
7869 for (i = PHY_FORCE_TIME; i > 0; i--) {
7870 /* Read the MII Status Register and wait for Link Status bit
7874 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
7878 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
7882 if ((mii_status_reg & ~MII_SR_LINK_STATUS) == 0) break;
7886 /* Recommended delay time after link has been lost */
7889 /* Now we will re-enable th transmitter on the PHY */
7891 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
7895 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0);
7899 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00);
7903 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000);
7907 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
7911 /* This loop will early-out if the link condition has been met. */
7912 for (i = PHY_FORCE_TIME; i > 0; i--) {
7913 /* Read the MII Status Register and wait for Link Status bit
7917 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
7921 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
7925 if (mii_status_reg & MII_SR_LINK_STATUS) break;
7928 return E1000_SUCCESS;
7931 /***************************************************************************
7933 * Disables PCI-Express master access.
7935 * hw: Struct containing variables accessed by shared code
7939 ***************************************************************************/
7941 e1000_set_pci_express_master_disable(struct e1000_hw *hw)
7945 DEBUGFUNC("e1000_set_pci_express_master_disable");
7947 if (hw->bus_type != e1000_bus_type_pci_express)
7950 ctrl = E1000_READ_REG(hw, CTRL);
7951 ctrl |= E1000_CTRL_GIO_MASTER_DISABLE;
7952 E1000_WRITE_REG(hw, CTRL, ctrl);
7955 /*******************************************************************************
7957 * Disables PCI-Express master access and verifies there are no pending requests
7959 * hw: Struct containing variables accessed by shared code
7961 * returns: - E1000_ERR_MASTER_REQUESTS_PENDING if master disable bit hasn't
7962 * caused the master requests to be disabled.
7963 * E1000_SUCCESS master requests disabled.
7965 ******************************************************************************/
7967 e1000_disable_pciex_master(struct e1000_hw *hw)
7969 int32_t timeout = MASTER_DISABLE_TIMEOUT; /* 80ms */
7971 DEBUGFUNC("e1000_disable_pciex_master");
7973 if (hw->bus_type != e1000_bus_type_pci_express)
7974 return E1000_SUCCESS;
7976 e1000_set_pci_express_master_disable(hw);
7979 if (!(E1000_READ_REG(hw, STATUS) & E1000_STATUS_GIO_MASTER_ENABLE))
7987 DEBUGOUT("Master requests are pending.\n");
7988 return -E1000_ERR_MASTER_REQUESTS_PENDING;
7991 return E1000_SUCCESS;
7994 /*******************************************************************************
7996 * Check for EEPROM Auto Read bit done.
7998 * hw: Struct containing variables accessed by shared code
8000 * returns: - E1000_ERR_RESET if fail to reset MAC
8001 * E1000_SUCCESS at any other case.
8003 ******************************************************************************/
8005 e1000_get_auto_rd_done(struct e1000_hw *hw)
8007 int32_t timeout = AUTO_READ_DONE_TIMEOUT;
8009 DEBUGFUNC("e1000_get_auto_rd_done");
8011 switch (hw->mac_type) {
8018 case e1000_80003es2lan:
8021 if (E1000_READ_REG(hw, EECD) & E1000_EECD_AUTO_RD)
8028 DEBUGOUT("Auto read by HW from EEPROM has not completed.\n");
8029 return -E1000_ERR_RESET;
8034 /* PHY configuration from NVM just starts after EECD_AUTO_RD sets to high.
8035 * Need to wait for PHY configuration completion before accessing NVM
8037 if (hw->mac_type == e1000_82573)
8040 return E1000_SUCCESS;
8043 /***************************************************************************
8044 * Checks if the PHY configuration is done
8046 * hw: Struct containing variables accessed by shared code
8048 * returns: - E1000_ERR_RESET if fail to reset MAC
8049 * E1000_SUCCESS at any other case.
8051 ***************************************************************************/
8053 e1000_get_phy_cfg_done(struct e1000_hw *hw)
8055 int32_t timeout = PHY_CFG_TIMEOUT;
8056 uint32_t cfg_mask = E1000_EEPROM_CFG_DONE;
8058 DEBUGFUNC("e1000_get_phy_cfg_done");
8060 switch (hw->mac_type) {
8064 case e1000_80003es2lan:
8065 /* Separate *_CFG_DONE_* bit for each port */
8066 if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
8067 cfg_mask = E1000_EEPROM_CFG_DONE_PORT_1;
8072 if (E1000_READ_REG(hw, EEMNGCTL) & cfg_mask)
8079 DEBUGOUT("MNG configuration cycle has not completed.\n");
8080 return -E1000_ERR_RESET;
8085 return E1000_SUCCESS;
8088 /***************************************************************************
8090 * Using the combination of SMBI and SWESMBI semaphore bits when resetting
8091 * adapter or Eeprom access.
8093 * hw: Struct containing variables accessed by shared code
8095 * returns: - E1000_ERR_EEPROM if fail to access EEPROM.
8096 * E1000_SUCCESS at any other case.
8098 ***************************************************************************/
8100 e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw)
8105 DEBUGFUNC("e1000_get_hw_eeprom_semaphore");
8107 if (!hw->eeprom_semaphore_present)
8108 return E1000_SUCCESS;
8110 if (hw->mac_type == e1000_80003es2lan) {
8111 /* Get the SW semaphore. */
8112 if (e1000_get_software_semaphore(hw) != E1000_SUCCESS)
8113 return -E1000_ERR_EEPROM;
8116 /* Get the FW semaphore. */
8117 timeout = hw->eeprom.word_size + 1;
8119 swsm = E1000_READ_REG(hw, SWSM);
8120 swsm |= E1000_SWSM_SWESMBI;
8121 E1000_WRITE_REG(hw, SWSM, swsm);
8122 /* if we managed to set the bit we got the semaphore. */
8123 swsm = E1000_READ_REG(hw, SWSM);
8124 if (swsm & E1000_SWSM_SWESMBI)
8132 /* Release semaphores */
8133 e1000_put_hw_eeprom_semaphore(hw);
8134 DEBUGOUT("Driver can't access the Eeprom - SWESMBI bit is set.\n");
8135 return -E1000_ERR_EEPROM;
8138 return E1000_SUCCESS;
8141 /***************************************************************************
8142 * This function clears HW semaphore bits.
8144 * hw: Struct containing variables accessed by shared code
8148 ***************************************************************************/
8150 e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw)
8154 DEBUGFUNC("e1000_put_hw_eeprom_semaphore");
8156 if (!hw->eeprom_semaphore_present)
8159 swsm = E1000_READ_REG(hw, SWSM);
8160 if (hw->mac_type == e1000_80003es2lan) {
8161 /* Release both semaphores. */
8162 swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
8164 swsm &= ~(E1000_SWSM_SWESMBI);
8165 E1000_WRITE_REG(hw, SWSM, swsm);
8168 /***************************************************************************
8170 * Obtaining software semaphore bit (SMBI) before resetting PHY.
8172 * hw: Struct containing variables accessed by shared code
8174 * returns: - E1000_ERR_RESET if fail to obtain semaphore.
8175 * E1000_SUCCESS at any other case.
8177 ***************************************************************************/
8179 e1000_get_software_semaphore(struct e1000_hw *hw)
8181 int32_t timeout = hw->eeprom.word_size + 1;
8184 DEBUGFUNC("e1000_get_software_semaphore");
8186 if (hw->mac_type != e1000_80003es2lan) {
8187 return E1000_SUCCESS;
8191 swsm = E1000_READ_REG(hw, SWSM);
8192 /* If SMBI bit cleared, it is now set and we hold the semaphore */
8193 if (!(swsm & E1000_SWSM_SMBI))
8200 DEBUGOUT("Driver can't access device - SMBI bit is set.\n");
8201 return -E1000_ERR_RESET;
8204 return E1000_SUCCESS;
8207 /***************************************************************************
8209 * Release semaphore bit (SMBI).
8211 * hw: Struct containing variables accessed by shared code
8213 ***************************************************************************/
8215 e1000_release_software_semaphore(struct e1000_hw *hw)
8219 DEBUGFUNC("e1000_release_software_semaphore");
8221 if (hw->mac_type != e1000_80003es2lan) {
8225 swsm = E1000_READ_REG(hw, SWSM);
8226 /* Release the SW semaphores.*/
8227 swsm &= ~E1000_SWSM_SMBI;
8228 E1000_WRITE_REG(hw, SWSM, swsm);
8231 /******************************************************************************
8232 * Checks if PHY reset is blocked due to SOL/IDER session, for example.
8233 * Returning E1000_BLK_PHY_RESET isn't necessarily an error. But it's up to
8234 * the caller to figure out how to deal with it.
8236 * hw - Struct containing variables accessed by shared code
8238 * returns: - E1000_BLK_PHY_RESET
8241 *****************************************************************************/
8243 e1000_check_phy_reset_block(struct e1000_hw *hw)
8248 if (hw->mac_type == e1000_ich8lan) {
8249 fwsm = E1000_READ_REG(hw, FWSM);
8250 return (fwsm & E1000_FWSM_RSPCIPHY) ? E1000_SUCCESS
8251 : E1000_BLK_PHY_RESET;
8254 if (hw->mac_type > e1000_82547_rev_2)
8255 manc = E1000_READ_REG(hw, MANC);
8256 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
8257 E1000_BLK_PHY_RESET : E1000_SUCCESS;
8261 e1000_arc_subsystem_valid(struct e1000_hw *hw)
8265 /* On 8257x silicon, registers in the range of 0x8800 - 0x8FFC
8266 * may not be provided a DMA clock when no manageability features are
8267 * enabled. We do not want to perform any reads/writes to these registers
8268 * if this is the case. We read FWSM to determine the manageability mode.
8270 switch (hw->mac_type) {
8274 case e1000_80003es2lan:
8275 fwsm = E1000_READ_REG(hw, FWSM);
8276 if ((fwsm & E1000_FWSM_MODE_MASK) != 0)
8288 /******************************************************************************
8289 * Configure PCI-Ex no-snoop
8291 * hw - Struct containing variables accessed by shared code.
8292 * no_snoop - Bitmap of no-snoop events.
8294 * returns: E1000_SUCCESS
8296 *****************************************************************************/
8298 e1000_set_pci_ex_no_snoop(struct e1000_hw *hw, uint32_t no_snoop)
8300 uint32_t gcr_reg = 0;
8302 DEBUGFUNC("e1000_set_pci_ex_no_snoop");
8304 if (hw->bus_type == e1000_bus_type_unknown)
8305 e1000_get_bus_info(hw);
8307 if (hw->bus_type != e1000_bus_type_pci_express)
8308 return E1000_SUCCESS;
8311 gcr_reg = E1000_READ_REG(hw, GCR);
8312 gcr_reg &= ~(PCI_EX_NO_SNOOP_ALL);
8313 gcr_reg |= no_snoop;
8314 E1000_WRITE_REG(hw, GCR, gcr_reg);
8316 if (hw->mac_type == e1000_ich8lan) {
8319 E1000_WRITE_REG(hw, GCR, PCI_EX_82566_SNOOP_ALL);
8321 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
8322 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
8323 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
8326 return E1000_SUCCESS;
8329 /***************************************************************************
8331 * Get software semaphore FLAG bit (SWFLAG).
8332 * SWFLAG is used to synchronize the access to all shared resource between
8335 * hw: Struct containing variables accessed by shared code
8337 ***************************************************************************/
8339 e1000_get_software_flag(struct e1000_hw *hw)
8341 int32_t timeout = PHY_CFG_TIMEOUT;
8342 uint32_t extcnf_ctrl;
8344 DEBUGFUNC("e1000_get_software_flag");
8346 if (hw->mac_type == e1000_ich8lan) {
8348 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
8349 extcnf_ctrl |= E1000_EXTCNF_CTRL_SWFLAG;
8350 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
8352 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
8353 if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG)
8360 DEBUGOUT("FW or HW locks the resource too long.\n");
8361 return -E1000_ERR_CONFIG;
8365 return E1000_SUCCESS;
8368 /***************************************************************************
8370 * Release software semaphore FLAG bit (SWFLAG).
8371 * SWFLAG is used to synchronize the access to all shared resource between
8374 * hw: Struct containing variables accessed by shared code
8376 ***************************************************************************/
8378 e1000_release_software_flag(struct e1000_hw *hw)
8380 uint32_t extcnf_ctrl;
8382 DEBUGFUNC("e1000_release_software_flag");
8384 if (hw->mac_type == e1000_ich8lan) {
8385 extcnf_ctrl= E1000_READ_REG(hw, EXTCNF_CTRL);
8386 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
8387 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
8393 /******************************************************************************
8394 * Reads a 16 bit word or words from the EEPROM using the ICH8's flash access
8397 * hw - Struct containing variables accessed by shared code
8398 * offset - offset of word in the EEPROM to read
8399 * data - word read from the EEPROM
8400 * words - number of words to read
8401 *****************************************************************************/
8403 e1000_read_eeprom_ich8(struct e1000_hw *hw, uint16_t offset, uint16_t words,
8406 int32_t error = E1000_SUCCESS;
8407 uint32_t flash_bank = 0;
8408 uint32_t act_offset = 0;
8409 uint32_t bank_offset = 0;
8413 /* We need to know which is the valid flash bank. In the event
8414 * that we didn't allocate eeprom_shadow_ram, we may not be
8415 * managing flash_bank. So it cannot be trusted and needs
8416 * to be updated with each read.
8418 /* Value of bit 22 corresponds to the flash bank we're on. */
8419 flash_bank = (E1000_READ_REG(hw, EECD) & E1000_EECD_SEC1VAL) ? 1 : 0;
8421 /* Adjust offset appropriately if we're on bank 1 - adjust for word size */
8422 bank_offset = flash_bank * (hw->flash_bank_size * 2);
8424 error = e1000_get_software_flag(hw);
8425 if (error != E1000_SUCCESS)
8428 for (i = 0; i < words; i++) {
8429 if (hw->eeprom_shadow_ram != NULL &&
8430 hw->eeprom_shadow_ram[offset+i].modified == TRUE) {
8431 data[i] = hw->eeprom_shadow_ram[offset+i].eeprom_word;
8433 /* The NVM part needs a byte offset, hence * 2 */
8434 act_offset = bank_offset + ((offset + i) * 2);
8435 error = e1000_read_ich8_word(hw, act_offset, &word);
8436 if (error != E1000_SUCCESS)
8442 e1000_release_software_flag(hw);
8447 /******************************************************************************
8448 * Writes a 16 bit word or words to the EEPROM using the ICH8's flash access
8449 * register. Actually, writes are written to the shadow ram cache in the hw
8450 * structure hw->e1000_shadow_ram. e1000_commit_shadow_ram flushes this to
8451 * the NVM, which occurs when the NVM checksum is updated.
8453 * hw - Struct containing variables accessed by shared code
8454 * offset - offset of word in the EEPROM to write
8455 * words - number of words to write
8456 * data - words to write to the EEPROM
8457 *****************************************************************************/
8459 e1000_write_eeprom_ich8(struct e1000_hw *hw, uint16_t offset, uint16_t words,
8463 int32_t error = E1000_SUCCESS;
8465 error = e1000_get_software_flag(hw);
8466 if (error != E1000_SUCCESS)
8469 /* A driver can write to the NVM only if it has eeprom_shadow_ram
8470 * allocated. Subsequent reads to the modified words are read from
8471 * this cached structure as well. Writes will only go into this
8472 * cached structure unless it's followed by a call to
8473 * e1000_update_eeprom_checksum() where it will commit the changes
8474 * and clear the "modified" field.
8476 if (hw->eeprom_shadow_ram != NULL) {
8477 for (i = 0; i < words; i++) {
8478 if ((offset + i) < E1000_SHADOW_RAM_WORDS) {
8479 hw->eeprom_shadow_ram[offset+i].modified = TRUE;
8480 hw->eeprom_shadow_ram[offset+i].eeprom_word = data[i];
8482 error = -E1000_ERR_EEPROM;
8487 /* Drivers have the option to not allocate eeprom_shadow_ram as long
8488 * as they don't perform any NVM writes. An attempt in doing so
8489 * will result in this error.
8491 error = -E1000_ERR_EEPROM;
8494 e1000_release_software_flag(hw);
8499 /******************************************************************************
8500 * This function does initial flash setup so that a new read/write/erase cycle
8503 * hw - The pointer to the hw structure
8504 ****************************************************************************/
8506 e1000_ich8_cycle_init(struct e1000_hw *hw)
8508 union ich8_hws_flash_status hsfsts;
8509 int32_t error = E1000_ERR_EEPROM;
8512 DEBUGFUNC("e1000_ich8_cycle_init");
8514 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
8516 /* May be check the Flash Des Valid bit in Hw status */
8517 if (hsfsts.hsf_status.fldesvalid == 0) {
8518 DEBUGOUT("Flash descriptor invalid. SW Sequencing must be used.");
8522 /* Clear FCERR in Hw status by writing 1 */
8523 /* Clear DAEL in Hw status by writing a 1 */
8524 hsfsts.hsf_status.flcerr = 1;
8525 hsfsts.hsf_status.dael = 1;
8527 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS, hsfsts.regval);
8529 /* Either we should have a hardware SPI cycle in progress bit to check
8530 * against, in order to start a new cycle or FDONE bit should be changed
8531 * in the hardware so that it is 1 after harware reset, which can then be
8532 * used as an indication whether a cycle is in progress or has been
8533 * completed .. we should also have some software semaphore mechanism to
8534 * guard FDONE or the cycle in progress bit so that two threads access to
8535 * those bits can be sequentiallized or a way so that 2 threads dont
8536 * start the cycle at the same time */
8538 if (hsfsts.hsf_status.flcinprog == 0) {
8539 /* There is no cycle running at present, so we can start a cycle */
8540 /* Begin by setting Flash Cycle Done. */
8541 hsfsts.hsf_status.flcdone = 1;
8542 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS, hsfsts.regval);
8543 error = E1000_SUCCESS;
8545 /* otherwise poll for sometime so the current cycle has a chance
8546 * to end before giving up. */
8547 for (i = 0; i < ICH_FLASH_COMMAND_TIMEOUT; i++) {
8548 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
8549 if (hsfsts.hsf_status.flcinprog == 0) {
8550 error = E1000_SUCCESS;
8555 if (error == E1000_SUCCESS) {
8556 /* Successful in waiting for previous cycle to timeout,
8557 * now set the Flash Cycle Done. */
8558 hsfsts.hsf_status.flcdone = 1;
8559 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS, hsfsts.regval);
8561 DEBUGOUT("Flash controller busy, cannot get access");
8567 /******************************************************************************
8568 * This function starts a flash cycle and waits for its completion
8570 * hw - The pointer to the hw structure
8571 ****************************************************************************/
8573 e1000_ich8_flash_cycle(struct e1000_hw *hw, uint32_t timeout)
8575 union ich8_hws_flash_ctrl hsflctl;
8576 union ich8_hws_flash_status hsfsts;
8577 int32_t error = E1000_ERR_EEPROM;
8580 /* Start a cycle by writing 1 in Flash Cycle Go in Hw Flash Control */
8581 hsflctl.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL);
8582 hsflctl.hsf_ctrl.flcgo = 1;
8583 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval);
8585 /* wait till FDONE bit is set to 1 */
8587 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
8588 if (hsfsts.hsf_status.flcdone == 1)
8592 } while (i < timeout);
8593 if (hsfsts.hsf_status.flcdone == 1 && hsfsts.hsf_status.flcerr == 0) {
8594 error = E1000_SUCCESS;
8599 /******************************************************************************
8600 * Reads a byte or word from the NVM using the ICH8 flash access registers.
8602 * hw - The pointer to the hw structure
8603 * index - The index of the byte or word to read.
8604 * size - Size of data to read, 1=byte 2=word
8605 * data - Pointer to the word to store the value read.
8606 *****************************************************************************/
8608 e1000_read_ich8_data(struct e1000_hw *hw, uint32_t index,
8609 uint32_t size, uint16_t* data)
8611 union ich8_hws_flash_status hsfsts;
8612 union ich8_hws_flash_ctrl hsflctl;
8613 uint32_t flash_linear_address;
8614 uint32_t flash_data = 0;
8615 int32_t error = -E1000_ERR_EEPROM;
8618 DEBUGFUNC("e1000_read_ich8_data");
8620 if (size < 1 || size > 2 || data == 0x0 ||
8621 index > ICH_FLASH_LINEAR_ADDR_MASK)
8624 flash_linear_address = (ICH_FLASH_LINEAR_ADDR_MASK & index) +
8625 hw->flash_base_addr;
8630 error = e1000_ich8_cycle_init(hw);
8631 if (error != E1000_SUCCESS)
8634 hsflctl.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL);
8635 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
8636 hsflctl.hsf_ctrl.fldbcount = size - 1;
8637 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_READ;
8638 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval);
8640 /* Write the last 24 bits of index into Flash Linear address field in
8642 /* TODO: TBD maybe check the index against the size of flash */
8644 E1000_WRITE_ICH_FLASH_REG(hw, ICH_FLASH_FADDR, flash_linear_address);
8646 error = e1000_ich8_flash_cycle(hw, ICH_FLASH_COMMAND_TIMEOUT);
8648 /* Check if FCERR is set to 1, if set to 1, clear it and try the whole
8649 * sequence a few more times, else read in (shift in) the Flash Data0,
8650 * the order is least significant byte first msb to lsb */
8651 if (error == E1000_SUCCESS) {
8652 flash_data = E1000_READ_ICH_FLASH_REG(hw, ICH_FLASH_FDATA0);
8654 *data = (uint8_t)(flash_data & 0x000000FF);
8655 } else if (size == 2) {
8656 *data = (uint16_t)(flash_data & 0x0000FFFF);
8660 /* If we've gotten here, then things are probably completely hosed,
8661 * but if the error condition is detected, it won't hurt to give
8662 * it another try...ICH_FLASH_CYCLE_REPEAT_COUNT times.
8664 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
8665 if (hsfsts.hsf_status.flcerr == 1) {
8666 /* Repeat for some time before giving up. */
8668 } else if (hsfsts.hsf_status.flcdone == 0) {
8669 DEBUGOUT("Timeout error - flash cycle did not complete.");
8673 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
8678 /******************************************************************************
8679 * Writes One /two bytes to the NVM using the ICH8 flash access registers.
8681 * hw - The pointer to the hw structure
8682 * index - The index of the byte/word to read.
8683 * size - Size of data to read, 1=byte 2=word
8684 * data - The byte(s) to write to the NVM.
8685 *****************************************************************************/
8687 e1000_write_ich8_data(struct e1000_hw *hw, uint32_t index, uint32_t size,
8690 union ich8_hws_flash_status hsfsts;
8691 union ich8_hws_flash_ctrl hsflctl;
8692 uint32_t flash_linear_address;
8693 uint32_t flash_data = 0;
8694 int32_t error = -E1000_ERR_EEPROM;
8697 DEBUGFUNC("e1000_write_ich8_data");
8699 if (size < 1 || size > 2 || data > size * 0xff ||
8700 index > ICH_FLASH_LINEAR_ADDR_MASK)
8703 flash_linear_address = (ICH_FLASH_LINEAR_ADDR_MASK & index) +
8704 hw->flash_base_addr;
8709 error = e1000_ich8_cycle_init(hw);
8710 if (error != E1000_SUCCESS)
8713 hsflctl.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL);
8714 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
8715 hsflctl.hsf_ctrl.fldbcount = size -1;
8716 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_WRITE;
8717 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval);
8719 /* Write the last 24 bits of index into Flash Linear address field in
8721 E1000_WRITE_ICH_FLASH_REG(hw, ICH_FLASH_FADDR, flash_linear_address);
8724 flash_data = (uint32_t)data & 0x00FF;
8726 flash_data = (uint32_t)data;
8728 E1000_WRITE_ICH_FLASH_REG(hw, ICH_FLASH_FDATA0, flash_data);
8730 /* check if FCERR is set to 1 , if set to 1, clear it and try the whole
8731 * sequence a few more times else done */
8732 error = e1000_ich8_flash_cycle(hw, ICH_FLASH_COMMAND_TIMEOUT);
8733 if (error == E1000_SUCCESS) {
8736 /* If we're here, then things are most likely completely hosed,
8737 * but if the error condition is detected, it won't hurt to give
8738 * it another try...ICH_FLASH_CYCLE_REPEAT_COUNT times.
8740 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
8741 if (hsfsts.hsf_status.flcerr == 1) {
8742 /* Repeat for some time before giving up. */
8744 } else if (hsfsts.hsf_status.flcdone == 0) {
8745 DEBUGOUT("Timeout error - flash cycle did not complete.");
8749 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
8754 /******************************************************************************
8755 * Reads a single byte from the NVM using the ICH8 flash access registers.
8757 * hw - pointer to e1000_hw structure
8758 * index - The index of the byte to read.
8759 * data - Pointer to a byte to store the value read.
8760 *****************************************************************************/
8762 e1000_read_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t* data)
8764 int32_t status = E1000_SUCCESS;
8767 status = e1000_read_ich8_data(hw, index, 1, &word);
8768 if (status == E1000_SUCCESS) {
8769 *data = (uint8_t)word;
8775 /******************************************************************************
8776 * Writes a single byte to the NVM using the ICH8 flash access registers.
8777 * Performs verification by reading back the value and then going through
8778 * a retry algorithm before giving up.
8780 * hw - pointer to e1000_hw structure
8781 * index - The index of the byte to write.
8782 * byte - The byte to write to the NVM.
8783 *****************************************************************************/
8785 e1000_verify_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t byte)
8787 int32_t error = E1000_SUCCESS;
8788 int32_t program_retries = 0;
8790 DEBUGOUT2("Byte := %2.2X Offset := %d\n", byte, index);
8792 error = e1000_write_ich8_byte(hw, index, byte);
8794 if (error != E1000_SUCCESS) {
8795 for (program_retries = 0; program_retries < 100; program_retries++) {
8796 DEBUGOUT2("Retrying \t Byte := %2.2X Offset := %d\n", byte, index);
8797 error = e1000_write_ich8_byte(hw, index, byte);
8799 if (error == E1000_SUCCESS)
8804 if (program_retries == 100)
8805 error = E1000_ERR_EEPROM;
8810 /******************************************************************************
8811 * Writes a single byte to the NVM using the ICH8 flash access registers.
8813 * hw - pointer to e1000_hw structure
8814 * index - The index of the byte to read.
8815 * data - The byte to write to the NVM.
8816 *****************************************************************************/
8818 e1000_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t data)
8820 int32_t status = E1000_SUCCESS;
8821 uint16_t word = (uint16_t)data;
8823 status = e1000_write_ich8_data(hw, index, 1, word);
8828 /******************************************************************************
8829 * Reads a word from the NVM using the ICH8 flash access registers.
8831 * hw - pointer to e1000_hw structure
8832 * index - The starting byte index of the word to read.
8833 * data - Pointer to a word to store the value read.
8834 *****************************************************************************/
8836 e1000_read_ich8_word(struct e1000_hw *hw, uint32_t index, uint16_t *data)
8838 int32_t status = E1000_SUCCESS;
8839 status = e1000_read_ich8_data(hw, index, 2, data);
8843 /******************************************************************************
8844 * Erases the bank specified. Each bank may be a 4, 8 or 64k block. Banks are 0
8847 * hw - pointer to e1000_hw structure
8848 * bank - 0 for first bank, 1 for second bank
8850 * Note that this function may actually erase as much as 8 or 64 KBytes. The
8851 * amount of NVM used in each bank is a *minimum* of 4 KBytes, but in fact the
8852 * bank size may be 4, 8 or 64 KBytes
8853 *****************************************************************************/
8855 e1000_erase_ich8_4k_segment(struct e1000_hw *hw, uint32_t bank)
8857 union ich8_hws_flash_status hsfsts;
8858 union ich8_hws_flash_ctrl hsflctl;
8859 uint32_t flash_linear_address;
8861 int32_t error = E1000_ERR_EEPROM;
8863 int32_t sub_sector_size = 0;
8866 int32_t error_flag = 0;
8868 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
8870 /* Determine HW Sector size: Read BERASE bits of Hw flash Status register */
8871 /* 00: The Hw sector is 256 bytes, hence we need to erase 16
8872 * consecutive sectors. The start index for the nth Hw sector can be
8873 * calculated as bank * 4096 + n * 256
8874 * 01: The Hw sector is 4K bytes, hence we need to erase 1 sector.
8875 * The start index for the nth Hw sector can be calculated
8877 * 10: The HW sector is 8K bytes
8878 * 11: The Hw sector size is 64K bytes */
8879 if (hsfsts.hsf_status.berasesz == 0x0) {
8880 /* Hw sector size 256 */
8881 sub_sector_size = ICH_FLASH_SEG_SIZE_256;
8882 bank_size = ICH_FLASH_SECTOR_SIZE;
8883 iteration = ICH_FLASH_SECTOR_SIZE / ICH_FLASH_SEG_SIZE_256;
8884 } else if (hsfsts.hsf_status.berasesz == 0x1) {
8885 bank_size = ICH_FLASH_SEG_SIZE_4K;
8887 } else if (hsfsts.hsf_status.berasesz == 0x3) {
8888 bank_size = ICH_FLASH_SEG_SIZE_64K;
8894 for (j = 0; j < iteration ; j++) {
8898 error = e1000_ich8_cycle_init(hw);
8899 if (error != E1000_SUCCESS) {
8904 /* Write a value 11 (block Erase) in Flash Cycle field in Hw flash
8906 hsflctl.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL);
8907 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_ERASE;
8908 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval);
8910 /* Write the last 24 bits of an index within the block into Flash
8911 * Linear address field in Flash Address. This probably needs to
8912 * be calculated here based off the on-chip erase sector size and
8913 * the software bank size (4, 8 or 64 KBytes) */
8914 flash_linear_address = bank * bank_size + j * sub_sector_size;
8915 flash_linear_address += hw->flash_base_addr;
8916 flash_linear_address &= ICH_FLASH_LINEAR_ADDR_MASK;
8918 E1000_WRITE_ICH_FLASH_REG(hw, ICH_FLASH_FADDR, flash_linear_address);
8920 error = e1000_ich8_flash_cycle(hw, ICH_FLASH_ERASE_TIMEOUT);
8921 /* Check if FCERR is set to 1. If 1, clear it and try the whole
8922 * sequence a few more times else Done */
8923 if (error == E1000_SUCCESS) {
8926 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
8927 if (hsfsts.hsf_status.flcerr == 1) {
8928 /* repeat for some time before giving up */
8930 } else if (hsfsts.hsf_status.flcdone == 0) {
8935 } while ((count < ICH_FLASH_CYCLE_REPEAT_COUNT) && !error_flag);
8936 if (error_flag == 1)
8939 if (error_flag != 1)
8940 error = E1000_SUCCESS;
8945 e1000_init_lcd_from_nvm_config_region(struct e1000_hw *hw,
8946 uint32_t cnf_base_addr, uint32_t cnf_size)
8948 uint32_t ret_val = E1000_SUCCESS;
8949 uint16_t word_addr, reg_data, reg_addr;
8952 /* cnf_base_addr is in DWORD */
8953 word_addr = (uint16_t)(cnf_base_addr << 1);
8955 /* cnf_size is returned in size of dwords */
8956 for (i = 0; i < cnf_size; i++) {
8957 ret_val = e1000_read_eeprom(hw, (word_addr + i*2), 1, ®_data);
8961 ret_val = e1000_read_eeprom(hw, (word_addr + i*2 + 1), 1, ®_addr);
8965 ret_val = e1000_get_software_flag(hw);
8966 if (ret_val != E1000_SUCCESS)
8969 ret_val = e1000_write_phy_reg_ex(hw, (uint32_t)reg_addr, reg_data);
8971 e1000_release_software_flag(hw);
8978 /******************************************************************************
8979 * This function initializes the PHY from the NVM on ICH8 platforms. This
8980 * is needed due to an issue where the NVM configuration is not properly
8981 * autoloaded after power transitions. Therefore, after each PHY reset, we
8982 * will load the configuration data out of the NVM manually.
8984 * hw: Struct containing variables accessed by shared code
8985 *****************************************************************************/
8987 e1000_init_lcd_from_nvm(struct e1000_hw *hw)
8989 uint32_t reg_data, cnf_base_addr, cnf_size, ret_val, loop;
8991 if (hw->phy_type != e1000_phy_igp_3)
8992 return E1000_SUCCESS;
8994 /* Check if SW needs configure the PHY */
8995 reg_data = E1000_READ_REG(hw, FEXTNVM);
8996 if (!(reg_data & FEXTNVM_SW_CONFIG))
8997 return E1000_SUCCESS;
8999 /* Wait for basic configuration completes before proceeding*/
9002 reg_data = E1000_READ_REG(hw, STATUS) & E1000_STATUS_LAN_INIT_DONE;
9005 } while ((!reg_data) && (loop < 50));
9007 /* Clear the Init Done bit for the next init event */
9008 reg_data = E1000_READ_REG(hw, STATUS);
9009 reg_data &= ~E1000_STATUS_LAN_INIT_DONE;
9010 E1000_WRITE_REG(hw, STATUS, reg_data);
9012 /* Make sure HW does not configure LCD from PHY extended configuration
9013 before SW configuration */
9014 reg_data = E1000_READ_REG(hw, EXTCNF_CTRL);
9015 if ((reg_data & E1000_EXTCNF_CTRL_LCD_WRITE_ENABLE) == 0x0000) {
9016 reg_data = E1000_READ_REG(hw, EXTCNF_SIZE);
9017 cnf_size = reg_data & E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH;
9020 reg_data = E1000_READ_REG(hw, EXTCNF_CTRL);
9021 cnf_base_addr = reg_data & E1000_EXTCNF_CTRL_EXT_CNF_POINTER;
9022 /* cnf_base_addr is in DWORD */
9023 cnf_base_addr >>= 16;
9025 /* Configure LCD from extended configuration region. */
9026 ret_val = e1000_init_lcd_from_nvm_config_region(hw, cnf_base_addr,
9033 return E1000_SUCCESS;