1 /*******************************************************************************
3 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2006 Intel Corporation.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *******************************************************************************/
30 * Shared functions for accessing and configuring the MAC
36 static int32_t e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask);
37 static void e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask);
38 static int32_t e1000_read_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t *data);
39 static int32_t e1000_write_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t data);
40 static int32_t e1000_get_software_semaphore(struct e1000_hw *hw);
41 static void e1000_release_software_semaphore(struct e1000_hw *hw);
43 static uint8_t e1000_arc_subsystem_valid(struct e1000_hw *hw);
44 static int32_t e1000_check_downshift(struct e1000_hw *hw);
45 static int32_t e1000_check_polarity(struct e1000_hw *hw, e1000_rev_polarity *polarity);
46 static void e1000_clear_hw_cntrs(struct e1000_hw *hw);
47 static void e1000_clear_vfta(struct e1000_hw *hw);
48 static int32_t e1000_commit_shadow_ram(struct e1000_hw *hw);
49 static int32_t e1000_config_dsp_after_link_change(struct e1000_hw *hw, boolean_t link_up);
50 static int32_t e1000_config_fc_after_link_up(struct e1000_hw *hw);
51 static int32_t e1000_detect_gig_phy(struct e1000_hw *hw);
52 static int32_t e1000_erase_ich8_4k_segment(struct e1000_hw *hw, uint32_t bank);
53 static int32_t e1000_get_auto_rd_done(struct e1000_hw *hw);
54 static int32_t e1000_get_cable_length(struct e1000_hw *hw, uint16_t *min_length, uint16_t *max_length);
55 static int32_t e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw);
56 static int32_t e1000_get_phy_cfg_done(struct e1000_hw *hw);
57 static int32_t e1000_get_software_flag(struct e1000_hw *hw);
58 static int32_t e1000_ich8_cycle_init(struct e1000_hw *hw);
59 static int32_t e1000_ich8_flash_cycle(struct e1000_hw *hw, uint32_t timeout);
60 static int32_t e1000_id_led_init(struct e1000_hw *hw);
61 static int32_t e1000_init_lcd_from_nvm_config_region(struct e1000_hw *hw, uint32_t cnf_base_addr, uint32_t cnf_size);
62 static int32_t e1000_init_lcd_from_nvm(struct e1000_hw *hw);
63 static void e1000_init_rx_addrs(struct e1000_hw *hw);
64 static void e1000_initialize_hardware_bits(struct e1000_hw *hw);
65 static boolean_t e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw);
66 static int32_t e1000_kumeran_lock_loss_workaround(struct e1000_hw *hw);
67 static int32_t e1000_mng_enable_host_if(struct e1000_hw *hw);
68 static int32_t e1000_mng_host_if_write(struct e1000_hw *hw, uint8_t *buffer, uint16_t length, uint16_t offset, uint8_t *sum);
69 static int32_t e1000_mng_write_cmd_header(struct e1000_hw* hw, struct e1000_host_mng_command_header* hdr);
70 static int32_t e1000_mng_write_commit(struct e1000_hw *hw);
71 static int32_t e1000_phy_ife_get_info(struct e1000_hw *hw, struct e1000_phy_info *phy_info);
72 static int32_t e1000_phy_igp_get_info(struct e1000_hw *hw, struct e1000_phy_info *phy_info);
73 static int32_t e1000_read_eeprom_eerd(struct e1000_hw *hw, uint16_t offset, uint16_t words, uint16_t *data);
74 static int32_t e1000_write_eeprom_eewr(struct e1000_hw *hw, uint16_t offset, uint16_t words, uint16_t *data);
75 static int32_t e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd);
76 static int32_t e1000_phy_m88_get_info(struct e1000_hw *hw, struct e1000_phy_info *phy_info);
77 static void e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw);
78 static int32_t e1000_read_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t *data);
79 static int32_t e1000_verify_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t byte);
80 static int32_t e1000_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t byte);
81 static int32_t e1000_read_ich8_word(struct e1000_hw *hw, uint32_t index, uint16_t *data);
82 static int32_t e1000_read_ich8_data(struct e1000_hw *hw, uint32_t index, uint32_t size, uint16_t *data);
83 static int32_t e1000_write_ich8_data(struct e1000_hw *hw, uint32_t index, uint32_t size, uint16_t data);
84 static int32_t e1000_read_eeprom_ich8(struct e1000_hw *hw, uint16_t offset, uint16_t words, uint16_t *data);
85 static int32_t e1000_write_eeprom_ich8(struct e1000_hw *hw, uint16_t offset, uint16_t words, uint16_t *data);
86 static void e1000_release_software_flag(struct e1000_hw *hw);
87 static int32_t e1000_set_d3_lplu_state(struct e1000_hw *hw, boolean_t active);
88 static int32_t e1000_set_d0_lplu_state(struct e1000_hw *hw, boolean_t active);
89 static int32_t e1000_set_pci_ex_no_snoop(struct e1000_hw *hw, uint32_t no_snoop);
90 static void e1000_set_pci_express_master_disable(struct e1000_hw *hw);
91 static int32_t e1000_wait_autoneg(struct e1000_hw *hw);
92 static void e1000_write_reg_io(struct e1000_hw *hw, uint32_t offset, uint32_t value);
93 static int32_t e1000_set_phy_type(struct e1000_hw *hw);
94 static void e1000_phy_init_script(struct e1000_hw *hw);
95 static int32_t e1000_setup_copper_link(struct e1000_hw *hw);
96 static int32_t e1000_setup_fiber_serdes_link(struct e1000_hw *hw);
97 static int32_t e1000_adjust_serdes_amplitude(struct e1000_hw *hw);
98 static int32_t e1000_phy_force_speed_duplex(struct e1000_hw *hw);
99 static int32_t e1000_config_mac_to_phy(struct e1000_hw *hw);
100 static void e1000_raise_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl);
101 static void e1000_lower_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl);
102 static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, uint32_t data,
104 static uint16_t e1000_shift_in_mdi_bits(struct e1000_hw *hw);
105 static int32_t e1000_phy_reset_dsp(struct e1000_hw *hw);
106 static int32_t e1000_write_eeprom_spi(struct e1000_hw *hw, uint16_t offset,
107 uint16_t words, uint16_t *data);
108 static int32_t e1000_write_eeprom_microwire(struct e1000_hw *hw,
109 uint16_t offset, uint16_t words,
111 static int32_t e1000_spi_eeprom_ready(struct e1000_hw *hw);
112 static void e1000_raise_ee_clk(struct e1000_hw *hw, uint32_t *eecd);
113 static void e1000_lower_ee_clk(struct e1000_hw *hw, uint32_t *eecd);
114 static void e1000_shift_out_ee_bits(struct e1000_hw *hw, uint16_t data,
116 static int32_t e1000_write_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr,
118 static int32_t e1000_read_phy_reg_ex(struct e1000_hw *hw,uint32_t reg_addr,
120 static uint16_t e1000_shift_in_ee_bits(struct e1000_hw *hw, uint16_t count);
121 static int32_t e1000_acquire_eeprom(struct e1000_hw *hw);
122 static void e1000_release_eeprom(struct e1000_hw *hw);
123 static void e1000_standby_eeprom(struct e1000_hw *hw);
124 static int32_t e1000_set_vco_speed(struct e1000_hw *hw);
125 static int32_t e1000_polarity_reversal_workaround(struct e1000_hw *hw);
126 static int32_t e1000_set_phy_mode(struct e1000_hw *hw);
127 static int32_t e1000_host_if_read_cookie(struct e1000_hw *hw, uint8_t *buffer);
128 static uint8_t e1000_calculate_mng_checksum(char *buffer, uint32_t length);
129 static int32_t e1000_configure_kmrn_for_10_100(struct e1000_hw *hw,
131 static int32_t e1000_configure_kmrn_for_1000(struct e1000_hw *hw);
133 /* IGP cable length table */
135 uint16_t e1000_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] =
136 { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
137 5, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 25, 25, 25,
138 25, 25, 25, 25, 30, 30, 30, 30, 40, 40, 40, 40, 40, 40, 40, 40,
139 40, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60,
140 60, 70, 70, 70, 70, 70, 70, 80, 80, 80, 80, 80, 80, 90, 90, 90,
141 90, 90, 90, 90, 90, 90, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
142 100, 100, 100, 100, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,
143 110, 110, 110, 110, 110, 110, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120};
146 uint16_t e1000_igp_2_cable_length_table[IGP02E1000_AGC_LENGTH_TABLE_SIZE] =
147 { 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21,
148 0, 0, 0, 3, 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41,
149 6, 10, 14, 18, 22, 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61,
150 21, 26, 31, 35, 40, 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82,
151 40, 45, 51, 56, 61, 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104,
152 60, 66, 72, 77, 82, 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121,
153 83, 89, 95, 100, 105, 109, 113, 116, 119, 122, 124,
154 104, 109, 114, 118, 121, 124};
156 /******************************************************************************
157 * Set the phy type member in the hw struct.
159 * hw - Struct containing variables accessed by shared code
160 *****************************************************************************/
162 e1000_set_phy_type(struct e1000_hw *hw)
164 DEBUGFUNC("e1000_set_phy_type");
166 if (hw->mac_type == e1000_undefined)
167 return -E1000_ERR_PHY_TYPE;
169 switch (hw->phy_id) {
170 case M88E1000_E_PHY_ID:
171 case M88E1000_I_PHY_ID:
172 case M88E1011_I_PHY_ID:
173 case M88E1111_I_PHY_ID:
174 hw->phy_type = e1000_phy_m88;
176 case IGP01E1000_I_PHY_ID:
177 if (hw->mac_type == e1000_82541 ||
178 hw->mac_type == e1000_82541_rev_2 ||
179 hw->mac_type == e1000_82547 ||
180 hw->mac_type == e1000_82547_rev_2) {
181 hw->phy_type = e1000_phy_igp;
184 case IGP03E1000_E_PHY_ID:
185 hw->phy_type = e1000_phy_igp_3;
188 case IFE_PLUS_E_PHY_ID:
190 hw->phy_type = e1000_phy_ife;
192 case GG82563_E_PHY_ID:
193 if (hw->mac_type == e1000_80003es2lan) {
194 hw->phy_type = e1000_phy_gg82563;
199 /* Should never have loaded on this device */
200 hw->phy_type = e1000_phy_undefined;
201 return -E1000_ERR_PHY_TYPE;
204 return E1000_SUCCESS;
207 /******************************************************************************
208 * IGP phy init script - initializes the GbE PHY
210 * hw - Struct containing variables accessed by shared code
211 *****************************************************************************/
213 e1000_phy_init_script(struct e1000_hw *hw)
216 uint16_t phy_saved_data;
218 DEBUGFUNC("e1000_phy_init_script");
220 if (hw->phy_init_script) {
223 /* Save off the current value of register 0x2F5B to be restored at
224 * the end of this routine. */
225 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
227 /* Disabled the PHY transmitter */
228 e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
232 e1000_write_phy_reg(hw,0x0000,0x0140);
236 switch (hw->mac_type) {
239 e1000_write_phy_reg(hw, 0x1F95, 0x0001);
241 e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
243 e1000_write_phy_reg(hw, 0x1F79, 0x0018);
245 e1000_write_phy_reg(hw, 0x1F30, 0x1600);
247 e1000_write_phy_reg(hw, 0x1F31, 0x0014);
249 e1000_write_phy_reg(hw, 0x1F32, 0x161C);
251 e1000_write_phy_reg(hw, 0x1F94, 0x0003);
253 e1000_write_phy_reg(hw, 0x1F96, 0x003F);
255 e1000_write_phy_reg(hw, 0x2010, 0x0008);
258 case e1000_82541_rev_2:
259 case e1000_82547_rev_2:
260 e1000_write_phy_reg(hw, 0x1F73, 0x0099);
266 e1000_write_phy_reg(hw, 0x0000, 0x3300);
270 /* Now enable the transmitter */
271 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
273 if (hw->mac_type == e1000_82547) {
274 uint16_t fused, fine, coarse;
276 /* Move to analog registers page */
277 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_SPARE_FUSE_STATUS, &fused);
279 if (!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
280 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_FUSE_STATUS, &fused);
282 fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
283 coarse = fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
285 if (coarse > IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
286 coarse -= IGP01E1000_ANALOG_FUSE_COARSE_10;
287 fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
288 } else if (coarse == IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
289 fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
291 fused = (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
292 (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
293 (coarse & IGP01E1000_ANALOG_FUSE_COARSE_MASK);
295 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_CONTROL, fused);
296 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_BYPASS,
297 IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
303 /******************************************************************************
304 * Set the mac type member in the hw struct.
306 * hw - Struct containing variables accessed by shared code
307 *****************************************************************************/
309 e1000_set_mac_type(struct e1000_hw *hw)
311 DEBUGFUNC("e1000_set_mac_type");
313 switch (hw->device_id) {
314 case E1000_DEV_ID_82542:
315 switch (hw->revision_id) {
316 case E1000_82542_2_0_REV_ID:
317 hw->mac_type = e1000_82542_rev2_0;
319 case E1000_82542_2_1_REV_ID:
320 hw->mac_type = e1000_82542_rev2_1;
323 /* Invalid 82542 revision ID */
324 return -E1000_ERR_MAC_TYPE;
327 case E1000_DEV_ID_82543GC_FIBER:
328 case E1000_DEV_ID_82543GC_COPPER:
329 hw->mac_type = e1000_82543;
331 case E1000_DEV_ID_82544EI_COPPER:
332 case E1000_DEV_ID_82544EI_FIBER:
333 case E1000_DEV_ID_82544GC_COPPER:
334 case E1000_DEV_ID_82544GC_LOM:
335 hw->mac_type = e1000_82544;
337 case E1000_DEV_ID_82540EM:
338 case E1000_DEV_ID_82540EM_LOM:
339 case E1000_DEV_ID_82540EP:
340 case E1000_DEV_ID_82540EP_LOM:
341 case E1000_DEV_ID_82540EP_LP:
342 hw->mac_type = e1000_82540;
344 case E1000_DEV_ID_82545EM_COPPER:
345 case E1000_DEV_ID_82545EM_FIBER:
346 hw->mac_type = e1000_82545;
348 case E1000_DEV_ID_82545GM_COPPER:
349 case E1000_DEV_ID_82545GM_FIBER:
350 case E1000_DEV_ID_82545GM_SERDES:
351 hw->mac_type = e1000_82545_rev_3;
353 case E1000_DEV_ID_82546EB_COPPER:
354 case E1000_DEV_ID_82546EB_FIBER:
355 case E1000_DEV_ID_82546EB_QUAD_COPPER:
356 hw->mac_type = e1000_82546;
358 case E1000_DEV_ID_82546GB_COPPER:
359 case E1000_DEV_ID_82546GB_FIBER:
360 case E1000_DEV_ID_82546GB_SERDES:
361 case E1000_DEV_ID_82546GB_PCIE:
362 case E1000_DEV_ID_82546GB_QUAD_COPPER:
363 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
364 hw->mac_type = e1000_82546_rev_3;
366 case E1000_DEV_ID_82541EI:
367 case E1000_DEV_ID_82541EI_MOBILE:
368 case E1000_DEV_ID_82541ER_LOM:
369 hw->mac_type = e1000_82541;
371 case E1000_DEV_ID_82541ER:
372 case E1000_DEV_ID_82541GI:
373 case E1000_DEV_ID_82541GI_LF:
374 case E1000_DEV_ID_82541GI_MOBILE:
375 hw->mac_type = e1000_82541_rev_2;
377 case E1000_DEV_ID_82547EI:
378 case E1000_DEV_ID_82547EI_MOBILE:
379 hw->mac_type = e1000_82547;
381 case E1000_DEV_ID_82547GI:
382 hw->mac_type = e1000_82547_rev_2;
384 case E1000_DEV_ID_82571EB_COPPER:
385 case E1000_DEV_ID_82571EB_FIBER:
386 case E1000_DEV_ID_82571EB_SERDES:
387 case E1000_DEV_ID_82571EB_SERDES_DUAL:
388 case E1000_DEV_ID_82571EB_SERDES_QUAD:
389 case E1000_DEV_ID_82571EB_QUAD_COPPER:
390 case E1000_DEV_ID_82571EB_QUAD_FIBER:
391 case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE:
392 hw->mac_type = e1000_82571;
394 case E1000_DEV_ID_82572EI_COPPER:
395 case E1000_DEV_ID_82572EI_FIBER:
396 case E1000_DEV_ID_82572EI_SERDES:
397 case E1000_DEV_ID_82572EI:
398 hw->mac_type = e1000_82572;
400 case E1000_DEV_ID_82573E:
401 case E1000_DEV_ID_82573E_IAMT:
402 case E1000_DEV_ID_82573L:
403 hw->mac_type = e1000_82573;
405 case E1000_DEV_ID_80003ES2LAN_COPPER_SPT:
406 case E1000_DEV_ID_80003ES2LAN_SERDES_SPT:
407 case E1000_DEV_ID_80003ES2LAN_COPPER_DPT:
408 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
409 hw->mac_type = e1000_80003es2lan;
411 case E1000_DEV_ID_ICH8_IGP_M_AMT:
412 case E1000_DEV_ID_ICH8_IGP_AMT:
413 case E1000_DEV_ID_ICH8_IGP_C:
414 case E1000_DEV_ID_ICH8_IFE:
415 case E1000_DEV_ID_ICH8_IFE_GT:
416 case E1000_DEV_ID_ICH8_IFE_G:
417 case E1000_DEV_ID_ICH8_IGP_M:
418 hw->mac_type = e1000_ich8lan;
421 /* Should never have loaded on this device */
422 return -E1000_ERR_MAC_TYPE;
425 switch (hw->mac_type) {
427 hw->swfwhw_semaphore_present = TRUE;
428 hw->asf_firmware_present = TRUE;
430 case e1000_80003es2lan:
431 hw->swfw_sync_present = TRUE;
436 hw->eeprom_semaphore_present = TRUE;
440 case e1000_82541_rev_2:
441 case e1000_82547_rev_2:
442 hw->asf_firmware_present = TRUE;
448 /* The 82543 chip does not count tx_carrier_errors properly in
451 if (hw->mac_type == e1000_82543)
452 hw->bad_tx_carr_stats_fd = TRUE;
454 /* capable of receiving management packets to the host */
455 if (hw->mac_type >= e1000_82571)
456 hw->has_manc2h = TRUE;
458 /* In rare occasions, ESB2 systems would end up started without
459 * the RX unit being turned on.
461 if (hw->mac_type == e1000_80003es2lan)
462 hw->rx_needs_kicking = TRUE;
464 if (hw->mac_type > e1000_82544)
465 hw->has_smbus = TRUE;
467 return E1000_SUCCESS;
470 /*****************************************************************************
471 * Set media type and TBI compatibility.
473 * hw - Struct containing variables accessed by shared code
474 * **************************************************************************/
476 e1000_set_media_type(struct e1000_hw *hw)
480 DEBUGFUNC("e1000_set_media_type");
482 if (hw->mac_type != e1000_82543) {
483 /* tbi_compatibility is only valid on 82543 */
484 hw->tbi_compatibility_en = FALSE;
487 switch (hw->device_id) {
488 case E1000_DEV_ID_82545GM_SERDES:
489 case E1000_DEV_ID_82546GB_SERDES:
490 case E1000_DEV_ID_82571EB_SERDES:
491 case E1000_DEV_ID_82571EB_SERDES_DUAL:
492 case E1000_DEV_ID_82571EB_SERDES_QUAD:
493 case E1000_DEV_ID_82572EI_SERDES:
494 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
495 hw->media_type = e1000_media_type_internal_serdes;
498 switch (hw->mac_type) {
499 case e1000_82542_rev2_0:
500 case e1000_82542_rev2_1:
501 hw->media_type = e1000_media_type_fiber;
505 /* The STATUS_TBIMODE bit is reserved or reused for the this
508 hw->media_type = e1000_media_type_copper;
511 status = E1000_READ_REG(hw, STATUS);
512 if (status & E1000_STATUS_TBIMODE) {
513 hw->media_type = e1000_media_type_fiber;
514 /* tbi_compatibility not valid on fiber */
515 hw->tbi_compatibility_en = FALSE;
517 hw->media_type = e1000_media_type_copper;
524 /******************************************************************************
525 * Reset the transmit and receive units; mask and clear all interrupts.
527 * hw - Struct containing variables accessed by shared code
528 *****************************************************************************/
530 e1000_reset_hw(struct e1000_hw *hw)
538 uint32_t extcnf_ctrl;
541 DEBUGFUNC("e1000_reset_hw");
543 /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
544 if (hw->mac_type == e1000_82542_rev2_0) {
545 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
546 e1000_pci_clear_mwi(hw);
549 if (hw->bus_type == e1000_bus_type_pci_express) {
550 /* Prevent the PCI-E bus from sticking if there is no TLP connection
551 * on the last TLP read/write transaction when MAC is reset.
553 if (e1000_disable_pciex_master(hw) != E1000_SUCCESS) {
554 DEBUGOUT("PCI-E Master disable polling has failed.\n");
558 /* Clear interrupt mask to stop board from generating interrupts */
559 DEBUGOUT("Masking off all interrupts\n");
560 E1000_WRITE_REG(hw, IMC, 0xffffffff);
562 /* Disable the Transmit and Receive units. Then delay to allow
563 * any pending transactions to complete before we hit the MAC with
566 E1000_WRITE_REG(hw, RCTL, 0);
567 E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP);
568 E1000_WRITE_FLUSH(hw);
570 /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
571 hw->tbi_compatibility_on = FALSE;
573 /* Delay to allow any outstanding PCI transactions to complete before
574 * resetting the device
578 ctrl = E1000_READ_REG(hw, CTRL);
580 /* Must reset the PHY before resetting the MAC */
581 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
582 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_PHY_RST));
586 /* Must acquire the MDIO ownership before MAC reset.
587 * Ownership defaults to firmware after a reset. */
588 if (hw->mac_type == e1000_82573) {
591 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
592 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
595 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
596 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
598 if (extcnf_ctrl & E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP)
601 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
608 /* Workaround for ICH8 bit corruption issue in FIFO memory */
609 if (hw->mac_type == e1000_ich8lan) {
610 /* Set Tx and Rx buffer allocation to 8k apiece. */
611 E1000_WRITE_REG(hw, PBA, E1000_PBA_8K);
612 /* Set Packet Buffer Size to 16k. */
613 E1000_WRITE_REG(hw, PBS, E1000_PBS_16K);
616 /* Issue a global reset to the MAC. This will reset the chip's
617 * transmit, receive, DMA, and link units. It will not effect
618 * the current PCI configuration. The global reset bit is self-
619 * clearing, and should clear within a microsecond.
621 DEBUGOUT("Issuing a global reset to MAC\n");
623 switch (hw->mac_type) {
629 case e1000_82541_rev_2:
630 /* These controllers can't ack the 64-bit write when issuing the
631 * reset, so use IO-mapping as a workaround to issue the reset */
632 E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
634 case e1000_82545_rev_3:
635 case e1000_82546_rev_3:
636 /* Reset is performed on a shadow of the control register */
637 E1000_WRITE_REG(hw, CTRL_DUP, (ctrl | E1000_CTRL_RST));
640 if (!hw->phy_reset_disable &&
641 e1000_check_phy_reset_block(hw) == E1000_SUCCESS) {
642 /* e1000_ich8lan PHY HW reset requires MAC CORE reset
643 * at the same time to make sure the interface between
644 * MAC and the external PHY is reset.
646 ctrl |= E1000_CTRL_PHY_RST;
649 e1000_get_software_flag(hw);
650 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
654 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
658 /* After MAC reset, force reload of EEPROM to restore power-on settings to
659 * device. Later controllers reload the EEPROM automatically, so just wait
660 * for reload to complete.
662 switch (hw->mac_type) {
663 case e1000_82542_rev2_0:
664 case e1000_82542_rev2_1:
667 /* Wait for reset to complete */
669 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
670 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
671 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
672 E1000_WRITE_FLUSH(hw);
673 /* Wait for EEPROM reload */
677 case e1000_82541_rev_2:
679 case e1000_82547_rev_2:
680 /* Wait for EEPROM reload */
684 if (e1000_is_onboard_nvm_eeprom(hw) == FALSE) {
686 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
687 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
688 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
689 E1000_WRITE_FLUSH(hw);
693 /* Auto read done will delay 5ms or poll based on mac type */
694 ret_val = e1000_get_auto_rd_done(hw);
700 /* Disable HW ARPs on ASF enabled adapters */
701 if (hw->mac_type >= e1000_82540 && hw->mac_type <= e1000_82547_rev_2) {
702 manc = E1000_READ_REG(hw, MANC);
703 manc &= ~(E1000_MANC_ARP_EN);
704 E1000_WRITE_REG(hw, MANC, manc);
707 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
708 e1000_phy_init_script(hw);
710 /* Configure activity LED after PHY reset */
711 led_ctrl = E1000_READ_REG(hw, LEDCTL);
712 led_ctrl &= IGP_ACTIVITY_LED_MASK;
713 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
714 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
717 /* Clear interrupt mask to stop board from generating interrupts */
718 DEBUGOUT("Masking off all interrupts\n");
719 E1000_WRITE_REG(hw, IMC, 0xffffffff);
721 /* Clear any pending interrupt events. */
722 icr = E1000_READ_REG(hw, ICR);
724 /* If MWI was previously enabled, reenable it. */
725 if (hw->mac_type == e1000_82542_rev2_0) {
726 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
727 e1000_pci_set_mwi(hw);
730 if (hw->mac_type == e1000_ich8lan) {
731 uint32_t kab = E1000_READ_REG(hw, KABGTXD);
732 kab |= E1000_KABGTXD_BGSQLBIAS;
733 E1000_WRITE_REG(hw, KABGTXD, kab);
736 return E1000_SUCCESS;
739 /******************************************************************************
741 * Initialize a number of hardware-dependent bits
743 * hw: Struct containing variables accessed by shared code
745 * This function contains hardware limitation workarounds for PCI-E adapters
747 *****************************************************************************/
749 e1000_initialize_hardware_bits(struct e1000_hw *hw)
751 if ((hw->mac_type >= e1000_82571) && (!hw->initialize_hw_bits_disable)) {
752 /* Settings common to all PCI-express silicon */
753 uint32_t reg_ctrl, reg_ctrl_ext;
754 uint32_t reg_tarc0, reg_tarc1;
756 uint32_t reg_txdctl, reg_txdctl1;
758 /* link autonegotiation/sync workarounds */
759 reg_tarc0 = E1000_READ_REG(hw, TARC0);
760 reg_tarc0 &= ~((1 << 30)|(1 << 29)|(1 << 28)|(1 << 27));
762 /* Enable not-done TX descriptor counting */
763 reg_txdctl = E1000_READ_REG(hw, TXDCTL);
764 reg_txdctl |= E1000_TXDCTL_COUNT_DESC;
765 E1000_WRITE_REG(hw, TXDCTL, reg_txdctl);
766 reg_txdctl1 = E1000_READ_REG(hw, TXDCTL1);
767 reg_txdctl1 |= E1000_TXDCTL_COUNT_DESC;
768 E1000_WRITE_REG(hw, TXDCTL1, reg_txdctl1);
770 switch (hw->mac_type) {
773 /* Clear PHY TX compatible mode bits */
774 reg_tarc1 = E1000_READ_REG(hw, TARC1);
775 reg_tarc1 &= ~((1 << 30)|(1 << 29));
777 /* link autonegotiation/sync workarounds */
778 reg_tarc0 |= ((1 << 26)|(1 << 25)|(1 << 24)|(1 << 23));
780 /* TX ring control fixes */
781 reg_tarc1 |= ((1 << 26)|(1 << 25)|(1 << 24));
783 /* Multiple read bit is reversed polarity */
784 reg_tctl = E1000_READ_REG(hw, TCTL);
785 if (reg_tctl & E1000_TCTL_MULR)
786 reg_tarc1 &= ~(1 << 28);
788 reg_tarc1 |= (1 << 28);
790 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
793 reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
794 reg_ctrl_ext &= ~(1 << 23);
795 reg_ctrl_ext |= (1 << 22);
797 /* TX byte count fix */
798 reg_ctrl = E1000_READ_REG(hw, CTRL);
799 reg_ctrl &= ~(1 << 29);
801 E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext);
802 E1000_WRITE_REG(hw, CTRL, reg_ctrl);
804 case e1000_80003es2lan:
805 /* improve small packet performace for fiber/serdes */
806 if ((hw->media_type == e1000_media_type_fiber) ||
807 (hw->media_type == e1000_media_type_internal_serdes)) {
808 reg_tarc0 &= ~(1 << 20);
811 /* Multiple read bit is reversed polarity */
812 reg_tctl = E1000_READ_REG(hw, TCTL);
813 reg_tarc1 = E1000_READ_REG(hw, TARC1);
814 if (reg_tctl & E1000_TCTL_MULR)
815 reg_tarc1 &= ~(1 << 28);
817 reg_tarc1 |= (1 << 28);
819 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
822 /* Reduce concurrent DMA requests to 3 from 4 */
823 if ((hw->revision_id < 3) ||
824 ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) &&
825 (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))
826 reg_tarc0 |= ((1 << 29)|(1 << 28));
828 reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
829 reg_ctrl_ext |= (1 << 22);
830 E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext);
832 /* workaround TX hang with TSO=on */
833 reg_tarc0 |= ((1 << 27)|(1 << 26)|(1 << 24)|(1 << 23));
835 /* Multiple read bit is reversed polarity */
836 reg_tctl = E1000_READ_REG(hw, TCTL);
837 reg_tarc1 = E1000_READ_REG(hw, TARC1);
838 if (reg_tctl & E1000_TCTL_MULR)
839 reg_tarc1 &= ~(1 << 28);
841 reg_tarc1 |= (1 << 28);
843 /* workaround TX hang with TSO=on */
844 reg_tarc1 |= ((1 << 30)|(1 << 26)|(1 << 24));
846 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
852 E1000_WRITE_REG(hw, TARC0, reg_tarc0);
856 /******************************************************************************
857 * Performs basic configuration of the adapter.
859 * hw - Struct containing variables accessed by shared code
861 * Assumes that the controller has previously been reset and is in a
862 * post-reset uninitialized state. Initializes the receive address registers,
863 * multicast table, and VLAN filter table. Calls routines to setup link
864 * configuration and flow control settings. Clears all on-chip counters. Leaves
865 * the transmit and receive units disabled and uninitialized.
866 *****************************************************************************/
868 e1000_init_hw(struct e1000_hw *hw)
873 uint16_t pcix_cmd_word;
874 uint16_t pcix_stat_hi_word;
881 DEBUGFUNC("e1000_init_hw");
883 /* force full DMA clock frequency for 10/100 on ICH8 A0-B0 */
884 if ((hw->mac_type == e1000_ich8lan) &&
885 ((hw->revision_id < 3) ||
886 ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) &&
887 (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))) {
888 reg_data = E1000_READ_REG(hw, STATUS);
889 reg_data &= ~0x80000000;
890 E1000_WRITE_REG(hw, STATUS, reg_data);
893 /* Initialize Identification LED */
894 ret_val = e1000_id_led_init(hw);
896 DEBUGOUT("Error Initializing Identification LED\n");
900 /* Set the media type and TBI compatibility */
901 e1000_set_media_type(hw);
903 /* Must be called after e1000_set_media_type because media_type is used */
904 e1000_initialize_hardware_bits(hw);
906 /* Disabling VLAN filtering. */
907 DEBUGOUT("Initializing the IEEE VLAN\n");
908 /* VET hardcoded to standard value and VFTA removed in ICH8 LAN */
909 if (hw->mac_type != e1000_ich8lan) {
910 if (hw->mac_type < e1000_82545_rev_3)
911 E1000_WRITE_REG(hw, VET, 0);
912 e1000_clear_vfta(hw);
915 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
916 if (hw->mac_type == e1000_82542_rev2_0) {
917 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
918 e1000_pci_clear_mwi(hw);
919 E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST);
920 E1000_WRITE_FLUSH(hw);
924 /* Setup the receive address. This involves initializing all of the Receive
925 * Address Registers (RARs 0 - 15).
927 e1000_init_rx_addrs(hw);
929 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
930 if (hw->mac_type == e1000_82542_rev2_0) {
931 E1000_WRITE_REG(hw, RCTL, 0);
932 E1000_WRITE_FLUSH(hw);
934 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
935 e1000_pci_set_mwi(hw);
938 /* Zero out the Multicast HASH table */
939 DEBUGOUT("Zeroing the MTA\n");
940 mta_size = E1000_MC_TBL_SIZE;
941 if (hw->mac_type == e1000_ich8lan)
942 mta_size = E1000_MC_TBL_SIZE_ICH8LAN;
943 for (i = 0; i < mta_size; i++) {
944 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
945 /* use write flush to prevent Memory Write Block (MWB) from
946 * occuring when accessing our register space */
947 E1000_WRITE_FLUSH(hw);
950 /* Set the PCI priority bit correctly in the CTRL register. This
951 * determines if the adapter gives priority to receives, or if it
952 * gives equal priority to transmits and receives. Valid only on
953 * 82542 and 82543 silicon.
955 if (hw->dma_fairness && hw->mac_type <= e1000_82543) {
956 ctrl = E1000_READ_REG(hw, CTRL);
957 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PRIOR);
960 switch (hw->mac_type) {
961 case e1000_82545_rev_3:
962 case e1000_82546_rev_3:
965 /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
966 if (hw->bus_type == e1000_bus_type_pcix) {
967 e1000_read_pci_cfg(hw, PCIX_COMMAND_REGISTER, &pcix_cmd_word);
968 e1000_read_pci_cfg(hw, PCIX_STATUS_REGISTER_HI,
970 cmd_mmrbc = (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >>
971 PCIX_COMMAND_MMRBC_SHIFT;
972 stat_mmrbc = (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
973 PCIX_STATUS_HI_MMRBC_SHIFT;
974 if (stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
975 stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
976 if (cmd_mmrbc > stat_mmrbc) {
977 pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK;
978 pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
979 e1000_write_pci_cfg(hw, PCIX_COMMAND_REGISTER,
986 /* More time needed for PHY to initialize */
987 if (hw->mac_type == e1000_ich8lan)
990 /* Call a subroutine to configure the link and setup flow control. */
991 ret_val = e1000_setup_link(hw);
993 /* Set the transmit descriptor write-back policy */
994 if (hw->mac_type > e1000_82544) {
995 ctrl = E1000_READ_REG(hw, TXDCTL);
996 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
997 E1000_WRITE_REG(hw, TXDCTL, ctrl);
1000 if (hw->mac_type == e1000_82573) {
1001 e1000_enable_tx_pkt_filtering(hw);
1004 switch (hw->mac_type) {
1007 case e1000_80003es2lan:
1008 /* Enable retransmit on late collisions */
1009 reg_data = E1000_READ_REG(hw, TCTL);
1010 reg_data |= E1000_TCTL_RTLC;
1011 E1000_WRITE_REG(hw, TCTL, reg_data);
1013 /* Configure Gigabit Carry Extend Padding */
1014 reg_data = E1000_READ_REG(hw, TCTL_EXT);
1015 reg_data &= ~E1000_TCTL_EXT_GCEX_MASK;
1016 reg_data |= DEFAULT_80003ES2LAN_TCTL_EXT_GCEX;
1017 E1000_WRITE_REG(hw, TCTL_EXT, reg_data);
1019 /* Configure Transmit Inter-Packet Gap */
1020 reg_data = E1000_READ_REG(hw, TIPG);
1021 reg_data &= ~E1000_TIPG_IPGT_MASK;
1022 reg_data |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
1023 E1000_WRITE_REG(hw, TIPG, reg_data);
1025 reg_data = E1000_READ_REG_ARRAY(hw, FFLT, 0x0001);
1026 reg_data &= ~0x00100000;
1027 E1000_WRITE_REG_ARRAY(hw, FFLT, 0x0001, reg_data);
1032 ctrl = E1000_READ_REG(hw, TXDCTL1);
1033 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
1034 E1000_WRITE_REG(hw, TXDCTL1, ctrl);
1039 if (hw->mac_type == e1000_82573) {
1040 uint32_t gcr = E1000_READ_REG(hw, GCR);
1041 gcr |= E1000_GCR_L1_ACT_WITHOUT_L0S_RX;
1042 E1000_WRITE_REG(hw, GCR, gcr);
1045 /* Clear all of the statistics registers (clear on read). It is
1046 * important that we do this after we have tried to establish link
1047 * because the symbol error count will increment wildly if there
1050 e1000_clear_hw_cntrs(hw);
1052 /* ICH8 No-snoop bits are opposite polarity.
1053 * Set to snoop by default after reset. */
1054 if (hw->mac_type == e1000_ich8lan)
1055 e1000_set_pci_ex_no_snoop(hw, PCI_EX_82566_SNOOP_ALL);
1057 if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER ||
1058 hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) {
1059 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
1060 /* Relaxed ordering must be disabled to avoid a parity
1061 * error crash in a PCI slot. */
1062 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
1063 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1069 /******************************************************************************
1070 * Adjust SERDES output amplitude based on EEPROM setting.
1072 * hw - Struct containing variables accessed by shared code.
1073 *****************************************************************************/
1075 e1000_adjust_serdes_amplitude(struct e1000_hw *hw)
1077 uint16_t eeprom_data;
1080 DEBUGFUNC("e1000_adjust_serdes_amplitude");
1082 if (hw->media_type != e1000_media_type_internal_serdes)
1083 return E1000_SUCCESS;
1085 switch (hw->mac_type) {
1086 case e1000_82545_rev_3:
1087 case e1000_82546_rev_3:
1090 return E1000_SUCCESS;
1093 ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1, &eeprom_data);
1098 if (eeprom_data != EEPROM_RESERVED_WORD) {
1099 /* Adjust SERDES output amplitude only. */
1100 eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK;
1101 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data);
1106 return E1000_SUCCESS;
1109 /******************************************************************************
1110 * Configures flow control and link settings.
1112 * hw - Struct containing variables accessed by shared code
1114 * Determines which flow control settings to use. Calls the apropriate media-
1115 * specific link configuration function. Configures the flow control settings.
1116 * Assuming the adapter has a valid link partner, a valid link should be
1117 * established. Assumes the hardware has previously been reset and the
1118 * transmitter and receiver are not enabled.
1119 *****************************************************************************/
1121 e1000_setup_link(struct e1000_hw *hw)
1125 uint16_t eeprom_data;
1127 DEBUGFUNC("e1000_setup_link");
1129 /* In the case of the phy reset being blocked, we already have a link.
1130 * We do not have to set it up again. */
1131 if (e1000_check_phy_reset_block(hw))
1132 return E1000_SUCCESS;
1134 /* Read and store word 0x0F of the EEPROM. This word contains bits
1135 * that determine the hardware's default PAUSE (flow control) mode,
1136 * a bit that determines whether the HW defaults to enabling or
1137 * disabling auto-negotiation, and the direction of the
1138 * SW defined pins. If there is no SW over-ride of the flow
1139 * control setting, then the variable hw->fc will
1140 * be initialized based on a value in the EEPROM.
1142 if (hw->fc == E1000_FC_DEFAULT) {
1143 switch (hw->mac_type) {
1146 hw->fc = E1000_FC_FULL;
1149 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
1152 DEBUGOUT("EEPROM Read Error\n");
1153 return -E1000_ERR_EEPROM;
1155 if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
1156 hw->fc = E1000_FC_NONE;
1157 else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
1158 EEPROM_WORD0F_ASM_DIR)
1159 hw->fc = E1000_FC_TX_PAUSE;
1161 hw->fc = E1000_FC_FULL;
1166 /* We want to save off the original Flow Control configuration just
1167 * in case we get disconnected and then reconnected into a different
1168 * hub or switch with different Flow Control capabilities.
1170 if (hw->mac_type == e1000_82542_rev2_0)
1171 hw->fc &= (~E1000_FC_TX_PAUSE);
1173 if ((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
1174 hw->fc &= (~E1000_FC_RX_PAUSE);
1176 hw->original_fc = hw->fc;
1178 DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc);
1180 /* Take the 4 bits from EEPROM word 0x0F that determine the initial
1181 * polarity value for the SW controlled pins, and setup the
1182 * Extended Device Control reg with that info.
1183 * This is needed because one of the SW controlled pins is used for
1184 * signal detection. So this should be done before e1000_setup_pcs_link()
1185 * or e1000_phy_setup() is called.
1187 if (hw->mac_type == e1000_82543) {
1188 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
1191 DEBUGOUT("EEPROM Read Error\n");
1192 return -E1000_ERR_EEPROM;
1194 ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
1196 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1199 /* Call the necessary subroutine to configure the link. */
1200 ret_val = (hw->media_type == e1000_media_type_copper) ?
1201 e1000_setup_copper_link(hw) :
1202 e1000_setup_fiber_serdes_link(hw);
1204 /* Initialize the flow control address, type, and PAUSE timer
1205 * registers to their default values. This is done even if flow
1206 * control is disabled, because it does not hurt anything to
1207 * initialize these registers.
1209 DEBUGOUT("Initializing the Flow Control address, type and timer regs\n");
1211 /* FCAL/H and FCT are hardcoded to standard values in e1000_ich8lan. */
1212 if (hw->mac_type != e1000_ich8lan) {
1213 E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
1214 E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
1215 E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
1218 E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
1220 /* Set the flow control receive threshold registers. Normally,
1221 * these registers will be set to a default threshold that may be
1222 * adjusted later by the driver's runtime code. However, if the
1223 * ability to transmit pause frames in not enabled, then these
1224 * registers will be set to 0.
1226 if (!(hw->fc & E1000_FC_TX_PAUSE)) {
1227 E1000_WRITE_REG(hw, FCRTL, 0);
1228 E1000_WRITE_REG(hw, FCRTH, 0);
1230 /* We need to set up the Receive Threshold high and low water marks
1231 * as well as (optionally) enabling the transmission of XON frames.
1233 if (hw->fc_send_xon) {
1234 E1000_WRITE_REG(hw, FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE));
1235 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
1237 E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water);
1238 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
1244 /******************************************************************************
1245 * Sets up link for a fiber based or serdes based adapter
1247 * hw - Struct containing variables accessed by shared code
1249 * Manipulates Physical Coding Sublayer functions in order to configure
1250 * link. Assumes the hardware has been previously reset and the transmitter
1251 * and receiver are not enabled.
1252 *****************************************************************************/
1254 e1000_setup_fiber_serdes_link(struct e1000_hw *hw)
1260 uint32_t signal = 0;
1263 DEBUGFUNC("e1000_setup_fiber_serdes_link");
1265 /* On 82571 and 82572 Fiber connections, SerDes loopback mode persists
1266 * until explicitly turned off or a power cycle is performed. A read to
1267 * the register does not indicate its status. Therefore, we ensure
1268 * loopback mode is disabled during initialization.
1270 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572)
1271 E1000_WRITE_REG(hw, SCTL, E1000_DISABLE_SERDES_LOOPBACK);
1273 /* On adapters with a MAC newer than 82544, SWDP 1 will be
1274 * set when the optics detect a signal. On older adapters, it will be
1275 * cleared when there is a signal. This applies to fiber media only.
1276 * If we're on serdes media, adjust the output amplitude to value
1277 * set in the EEPROM.
1279 ctrl = E1000_READ_REG(hw, CTRL);
1280 if (hw->media_type == e1000_media_type_fiber)
1281 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
1283 ret_val = e1000_adjust_serdes_amplitude(hw);
1287 /* Take the link out of reset */
1288 ctrl &= ~(E1000_CTRL_LRST);
1290 /* Adjust VCO speed to improve BER performance */
1291 ret_val = e1000_set_vco_speed(hw);
1295 e1000_config_collision_dist(hw);
1297 /* Check for a software override of the flow control settings, and setup
1298 * the device accordingly. If auto-negotiation is enabled, then software
1299 * will have to set the "PAUSE" bits to the correct value in the Tranmsit
1300 * Config Word Register (TXCW) and re-start auto-negotiation. However, if
1301 * auto-negotiation is disabled, then software will have to manually
1302 * configure the two flow control enable bits in the CTRL register.
1304 * The possible values of the "fc" parameter are:
1305 * 0: Flow control is completely disabled
1306 * 1: Rx flow control is enabled (we can receive pause frames, but
1307 * not send pause frames).
1308 * 2: Tx flow control is enabled (we can send pause frames but we do
1309 * not support receiving pause frames).
1310 * 3: Both Rx and TX flow control (symmetric) are enabled.
1314 /* Flow control is completely disabled by a software over-ride. */
1315 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
1317 case E1000_FC_RX_PAUSE:
1318 /* RX Flow control is enabled and TX Flow control is disabled by a
1319 * software over-ride. Since there really isn't a way to advertise
1320 * that we are capable of RX Pause ONLY, we will advertise that we
1321 * support both symmetric and asymmetric RX PAUSE. Later, we will
1322 * disable the adapter's ability to send PAUSE frames.
1324 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1326 case E1000_FC_TX_PAUSE:
1327 /* TX Flow control is enabled, and RX Flow control is disabled, by a
1328 * software over-ride.
1330 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
1333 /* Flow control (both RX and TX) is enabled by a software over-ride. */
1334 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1337 DEBUGOUT("Flow control param set incorrectly\n");
1338 return -E1000_ERR_CONFIG;
1342 /* Since auto-negotiation is enabled, take the link out of reset (the link
1343 * will be in reset, because we previously reset the chip). This will
1344 * restart auto-negotiation. If auto-neogtiation is successful then the
1345 * link-up status bit will be set and the flow control enable bits (RFCE
1346 * and TFCE) will be set according to their negotiated value.
1348 DEBUGOUT("Auto-negotiation enabled\n");
1350 E1000_WRITE_REG(hw, TXCW, txcw);
1351 E1000_WRITE_REG(hw, CTRL, ctrl);
1352 E1000_WRITE_FLUSH(hw);
1357 /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
1358 * indication in the Device Status Register. Time-out if a link isn't
1359 * seen in 500 milliseconds seconds (Auto-negotiation should complete in
1360 * less than 500 milliseconds even if the other end is doing it in SW).
1361 * For internal serdes, we just assume a signal is present, then poll.
1363 if (hw->media_type == e1000_media_type_internal_serdes ||
1364 (E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) {
1365 DEBUGOUT("Looking for Link\n");
1366 for (i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
1368 status = E1000_READ_REG(hw, STATUS);
1369 if (status & E1000_STATUS_LU) break;
1371 if (i == (LINK_UP_TIMEOUT / 10)) {
1372 DEBUGOUT("Never got a valid link from auto-neg!!!\n");
1373 hw->autoneg_failed = 1;
1374 /* AutoNeg failed to achieve a link, so we'll call
1375 * e1000_check_for_link. This routine will force the link up if
1376 * we detect a signal. This will allow us to communicate with
1377 * non-autonegotiating link partners.
1379 ret_val = e1000_check_for_link(hw);
1381 DEBUGOUT("Error while checking for link\n");
1384 hw->autoneg_failed = 0;
1386 hw->autoneg_failed = 0;
1387 DEBUGOUT("Valid Link Found\n");
1390 DEBUGOUT("No Signal Detected\n");
1392 return E1000_SUCCESS;
1395 /******************************************************************************
1396 * Make sure we have a valid PHY and change PHY mode before link setup.
1398 * hw - Struct containing variables accessed by shared code
1399 ******************************************************************************/
1401 e1000_copper_link_preconfig(struct e1000_hw *hw)
1407 DEBUGFUNC("e1000_copper_link_preconfig");
1409 ctrl = E1000_READ_REG(hw, CTRL);
1410 /* With 82543, we need to force speed and duplex on the MAC equal to what
1411 * the PHY speed and duplex configuration is. In addition, we need to
1412 * perform a hardware reset on the PHY to take it out of reset.
1414 if (hw->mac_type > e1000_82543) {
1415 ctrl |= E1000_CTRL_SLU;
1416 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1417 E1000_WRITE_REG(hw, CTRL, ctrl);
1419 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
1420 E1000_WRITE_REG(hw, CTRL, ctrl);
1421 ret_val = e1000_phy_hw_reset(hw);
1426 /* Make sure we have a valid PHY */
1427 ret_val = e1000_detect_gig_phy(hw);
1429 DEBUGOUT("Error, did not detect valid phy.\n");
1432 DEBUGOUT1("Phy ID = %x \n", hw->phy_id);
1434 /* Set PHY to class A mode (if necessary) */
1435 ret_val = e1000_set_phy_mode(hw);
1439 if ((hw->mac_type == e1000_82545_rev_3) ||
1440 (hw->mac_type == e1000_82546_rev_3)) {
1441 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1442 phy_data |= 0x00000008;
1443 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1446 if (hw->mac_type <= e1000_82543 ||
1447 hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
1448 hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2)
1449 hw->phy_reset_disable = FALSE;
1451 return E1000_SUCCESS;
1455 /********************************************************************
1456 * Copper link setup for e1000_phy_igp series.
1458 * hw - Struct containing variables accessed by shared code
1459 *********************************************************************/
1461 e1000_copper_link_igp_setup(struct e1000_hw *hw)
1467 DEBUGFUNC("e1000_copper_link_igp_setup");
1469 if (hw->phy_reset_disable)
1470 return E1000_SUCCESS;
1472 ret_val = e1000_phy_reset(hw);
1474 DEBUGOUT("Error Resetting the PHY\n");
1478 /* Wait 15ms for MAC to configure PHY from eeprom settings */
1480 if (hw->mac_type != e1000_ich8lan) {
1481 /* Configure activity LED after PHY reset */
1482 led_ctrl = E1000_READ_REG(hw, LEDCTL);
1483 led_ctrl &= IGP_ACTIVITY_LED_MASK;
1484 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
1485 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
1488 /* The NVM settings will configure LPLU in D3 for IGP2 and IGP3 PHYs */
1489 if (hw->phy_type == e1000_phy_igp) {
1490 /* disable lplu d3 during driver init */
1491 ret_val = e1000_set_d3_lplu_state(hw, FALSE);
1493 DEBUGOUT("Error Disabling LPLU D3\n");
1498 /* disable lplu d0 during driver init */
1499 ret_val = e1000_set_d0_lplu_state(hw, FALSE);
1501 DEBUGOUT("Error Disabling LPLU D0\n");
1504 /* Configure mdi-mdix settings */
1505 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1509 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
1510 hw->dsp_config_state = e1000_dsp_config_disabled;
1511 /* Force MDI for earlier revs of the IGP PHY */
1512 phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX | IGP01E1000_PSCR_FORCE_MDI_MDIX);
1516 hw->dsp_config_state = e1000_dsp_config_enabled;
1517 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1521 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1524 phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
1528 phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
1532 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1536 /* set auto-master slave resolution settings */
1538 e1000_ms_type phy_ms_setting = hw->master_slave;
1540 if (hw->ffe_config_state == e1000_ffe_config_active)
1541 hw->ffe_config_state = e1000_ffe_config_enabled;
1543 if (hw->dsp_config_state == e1000_dsp_config_activated)
1544 hw->dsp_config_state = e1000_dsp_config_enabled;
1546 /* when autonegotiation advertisment is only 1000Mbps then we
1547 * should disable SmartSpeed and enable Auto MasterSlave
1548 * resolution as hardware default. */
1549 if (hw->autoneg_advertised == ADVERTISE_1000_FULL) {
1550 /* Disable SmartSpeed */
1551 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1555 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1556 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1560 /* Set auto Master/Slave resolution process */
1561 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1564 phy_data &= ~CR_1000T_MS_ENABLE;
1565 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1570 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1574 /* load defaults for future use */
1575 hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
1576 ((phy_data & CR_1000T_MS_VALUE) ?
1577 e1000_ms_force_master :
1578 e1000_ms_force_slave) :
1581 switch (phy_ms_setting) {
1582 case e1000_ms_force_master:
1583 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
1585 case e1000_ms_force_slave:
1586 phy_data |= CR_1000T_MS_ENABLE;
1587 phy_data &= ~(CR_1000T_MS_VALUE);
1590 phy_data &= ~CR_1000T_MS_ENABLE;
1594 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1599 return E1000_SUCCESS;
1602 /********************************************************************
1603 * Copper link setup for e1000_phy_gg82563 series.
1605 * hw - Struct containing variables accessed by shared code
1606 *********************************************************************/
1608 e1000_copper_link_ggp_setup(struct e1000_hw *hw)
1614 DEBUGFUNC("e1000_copper_link_ggp_setup");
1616 if (!hw->phy_reset_disable) {
1618 /* Enable CRS on TX for half-duplex operation. */
1619 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL,
1624 phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
1625 /* Use 25MHz for both link down and 1000BASE-T for Tx clock */
1626 phy_data |= GG82563_MSCR_TX_CLK_1000MBPS_25MHZ;
1628 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL,
1634 * MDI/MDI-X = 0 (default)
1635 * 0 - Auto for all speeds
1638 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1640 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_SPEC_CTRL, &phy_data);
1644 phy_data &= ~GG82563_PSCR_CROSSOVER_MODE_MASK;
1648 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDI;
1651 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDIX;
1655 phy_data |= GG82563_PSCR_CROSSOVER_MODE_AUTO;
1660 * disable_polarity_correction = 0 (default)
1661 * Automatic Correction for Reversed Cable Polarity
1665 phy_data &= ~GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
1666 if (hw->disable_polarity_correction == 1)
1667 phy_data |= GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
1668 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_SPEC_CTRL, phy_data);
1673 /* SW Reset the PHY so all changes take effect */
1674 ret_val = e1000_phy_reset(hw);
1676 DEBUGOUT("Error Resetting the PHY\n");
1679 } /* phy_reset_disable */
1681 if (hw->mac_type == e1000_80003es2lan) {
1682 /* Bypass RX and TX FIFO's */
1683 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_FIFO_CTRL,
1684 E1000_KUMCTRLSTA_FIFO_CTRL_RX_BYPASS |
1685 E1000_KUMCTRLSTA_FIFO_CTRL_TX_BYPASS);
1689 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_SPEC_CTRL_2, &phy_data);
1693 phy_data &= ~GG82563_PSCR2_REVERSE_AUTO_NEG;
1694 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_SPEC_CTRL_2, phy_data);
1699 reg_data = E1000_READ_REG(hw, CTRL_EXT);
1700 reg_data &= ~(E1000_CTRL_EXT_LINK_MODE_MASK);
1701 E1000_WRITE_REG(hw, CTRL_EXT, reg_data);
1703 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_PWR_MGMT_CTRL,
1708 /* Do not init these registers when the HW is in IAMT mode, since the
1709 * firmware will have already initialized them. We only initialize
1710 * them if the HW is not in IAMT mode.
1712 if (e1000_check_mng_mode(hw) == FALSE) {
1713 /* Enable Electrical Idle on the PHY */
1714 phy_data |= GG82563_PMCR_ENABLE_ELECTRICAL_IDLE;
1715 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_PWR_MGMT_CTRL,
1720 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
1725 phy_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
1726 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
1733 /* Workaround: Disable padding in Kumeran interface in the MAC
1734 * and in the PHY to avoid CRC errors.
1736 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_INBAND_CTRL,
1740 phy_data |= GG82563_ICR_DIS_PADDING;
1741 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_INBAND_CTRL,
1747 return E1000_SUCCESS;
1750 /********************************************************************
1751 * Copper link setup for e1000_phy_m88 series.
1753 * hw - Struct containing variables accessed by shared code
1754 *********************************************************************/
1756 e1000_copper_link_mgp_setup(struct e1000_hw *hw)
1761 DEBUGFUNC("e1000_copper_link_mgp_setup");
1763 if (hw->phy_reset_disable)
1764 return E1000_SUCCESS;
1766 /* Enable CRS on TX. This must be set for half-duplex operation. */
1767 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1771 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1774 * MDI/MDI-X = 0 (default)
1775 * 0 - Auto for all speeds
1778 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1780 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1784 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
1787 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
1790 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
1794 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
1799 * disable_polarity_correction = 0 (default)
1800 * Automatic Correction for Reversed Cable Polarity
1804 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
1805 if (hw->disable_polarity_correction == 1)
1806 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
1807 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1811 if (hw->phy_revision < M88E1011_I_REV_4) {
1812 /* Force TX_CLK in the Extended PHY Specific Control Register
1815 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1819 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1821 if ((hw->phy_revision == E1000_REVISION_2) &&
1822 (hw->phy_id == M88E1111_I_PHY_ID)) {
1823 /* Vidalia Phy, set the downshift counter to 5x */
1824 phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK);
1825 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
1826 ret_val = e1000_write_phy_reg(hw,
1827 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1831 /* Configure Master and Slave downshift values */
1832 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
1833 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
1834 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
1835 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
1836 ret_val = e1000_write_phy_reg(hw,
1837 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1843 /* SW Reset the PHY so all changes take effect */
1844 ret_val = e1000_phy_reset(hw);
1846 DEBUGOUT("Error Resetting the PHY\n");
1850 return E1000_SUCCESS;
1853 /********************************************************************
1854 * Setup auto-negotiation and flow control advertisements,
1855 * and then perform auto-negotiation.
1857 * hw - Struct containing variables accessed by shared code
1858 *********************************************************************/
1860 e1000_copper_link_autoneg(struct e1000_hw *hw)
1865 DEBUGFUNC("e1000_copper_link_autoneg");
1867 /* Perform some bounds checking on the hw->autoneg_advertised
1868 * parameter. If this variable is zero, then set it to the default.
1870 hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
1872 /* If autoneg_advertised is zero, we assume it was not defaulted
1873 * by the calling code so we set to advertise full capability.
1875 if (hw->autoneg_advertised == 0)
1876 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
1878 /* IFE phy only supports 10/100 */
1879 if (hw->phy_type == e1000_phy_ife)
1880 hw->autoneg_advertised &= AUTONEG_ADVERTISE_10_100_ALL;
1882 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
1883 ret_val = e1000_phy_setup_autoneg(hw);
1885 DEBUGOUT("Error Setting up Auto-Negotiation\n");
1888 DEBUGOUT("Restarting Auto-Neg\n");
1890 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
1891 * the Auto Neg Restart bit in the PHY control register.
1893 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
1897 phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
1898 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
1902 /* Does the user want to wait for Auto-Neg to complete here, or
1903 * check at a later time (for example, callback routine).
1905 if (hw->wait_autoneg_complete) {
1906 ret_val = e1000_wait_autoneg(hw);
1908 DEBUGOUT("Error while waiting for autoneg to complete\n");
1913 hw->get_link_status = TRUE;
1915 return E1000_SUCCESS;
1918 /******************************************************************************
1919 * Config the MAC and the PHY after link is up.
1920 * 1) Set up the MAC to the current PHY speed/duplex
1921 * if we are on 82543. If we
1922 * are on newer silicon, we only need to configure
1923 * collision distance in the Transmit Control Register.
1924 * 2) Set up flow control on the MAC to that established with
1926 * 3) Config DSP to improve Gigabit link quality for some PHY revisions.
1928 * hw - Struct containing variables accessed by shared code
1929 ******************************************************************************/
1931 e1000_copper_link_postconfig(struct e1000_hw *hw)
1934 DEBUGFUNC("e1000_copper_link_postconfig");
1936 if (hw->mac_type >= e1000_82544) {
1937 e1000_config_collision_dist(hw);
1939 ret_val = e1000_config_mac_to_phy(hw);
1941 DEBUGOUT("Error configuring MAC to PHY settings\n");
1945 ret_val = e1000_config_fc_after_link_up(hw);
1947 DEBUGOUT("Error Configuring Flow Control\n");
1951 /* Config DSP to improve Giga link quality */
1952 if (hw->phy_type == e1000_phy_igp) {
1953 ret_val = e1000_config_dsp_after_link_change(hw, TRUE);
1955 DEBUGOUT("Error Configuring DSP after link up\n");
1960 return E1000_SUCCESS;
1963 /******************************************************************************
1964 * Detects which PHY is present and setup the speed and duplex
1966 * hw - Struct containing variables accessed by shared code
1967 ******************************************************************************/
1969 e1000_setup_copper_link(struct e1000_hw *hw)
1976 DEBUGFUNC("e1000_setup_copper_link");
1978 switch (hw->mac_type) {
1979 case e1000_80003es2lan:
1981 /* Set the mac to wait the maximum time between each
1982 * iteration and increase the max iterations when
1983 * polling the phy; this fixes erroneous timeouts at 10Mbps. */
1984 ret_val = e1000_write_kmrn_reg(hw, GG82563_REG(0x34, 4), 0xFFFF);
1987 ret_val = e1000_read_kmrn_reg(hw, GG82563_REG(0x34, 9), ®_data);
1991 ret_val = e1000_write_kmrn_reg(hw, GG82563_REG(0x34, 9), reg_data);
1998 /* Check if it is a valid PHY and set PHY mode if necessary. */
1999 ret_val = e1000_copper_link_preconfig(hw);
2003 switch (hw->mac_type) {
2004 case e1000_80003es2lan:
2005 /* Kumeran registers are written-only */
2006 reg_data = E1000_KUMCTRLSTA_INB_CTRL_LINK_STATUS_TX_TIMEOUT_DEFAULT;
2007 reg_data |= E1000_KUMCTRLSTA_INB_CTRL_DIS_PADDING;
2008 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_INB_CTRL,
2017 if (hw->phy_type == e1000_phy_igp ||
2018 hw->phy_type == e1000_phy_igp_3 ||
2019 hw->phy_type == e1000_phy_igp_2) {
2020 ret_val = e1000_copper_link_igp_setup(hw);
2023 } else if (hw->phy_type == e1000_phy_m88) {
2024 ret_val = e1000_copper_link_mgp_setup(hw);
2027 } else if (hw->phy_type == e1000_phy_gg82563) {
2028 ret_val = e1000_copper_link_ggp_setup(hw);
2034 /* Setup autoneg and flow control advertisement
2035 * and perform autonegotiation */
2036 ret_val = e1000_copper_link_autoneg(hw);
2040 /* PHY will be set to 10H, 10F, 100H,or 100F
2041 * depending on value from forced_speed_duplex. */
2042 DEBUGOUT("Forcing speed and duplex\n");
2043 ret_val = e1000_phy_force_speed_duplex(hw);
2045 DEBUGOUT("Error Forcing Speed and Duplex\n");
2050 /* Check link status. Wait up to 100 microseconds for link to become
2053 for (i = 0; i < 10; i++) {
2054 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2057 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2061 if (phy_data & MII_SR_LINK_STATUS) {
2062 /* Config the MAC and PHY after link is up */
2063 ret_val = e1000_copper_link_postconfig(hw);
2067 DEBUGOUT("Valid link established!!!\n");
2068 return E1000_SUCCESS;
2073 DEBUGOUT("Unable to establish link!!!\n");
2074 return E1000_SUCCESS;
2077 /******************************************************************************
2078 * Configure the MAC-to-PHY interface for 10/100Mbps
2080 * hw - Struct containing variables accessed by shared code
2081 ******************************************************************************/
2083 e1000_configure_kmrn_for_10_100(struct e1000_hw *hw, uint16_t duplex)
2085 int32_t ret_val = E1000_SUCCESS;
2089 DEBUGFUNC("e1000_configure_kmrn_for_10_100");
2091 reg_data = E1000_KUMCTRLSTA_HD_CTRL_10_100_DEFAULT;
2092 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_HD_CTRL,
2097 /* Configure Transmit Inter-Packet Gap */
2098 tipg = E1000_READ_REG(hw, TIPG);
2099 tipg &= ~E1000_TIPG_IPGT_MASK;
2100 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_10_100;
2101 E1000_WRITE_REG(hw, TIPG, tipg);
2103 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, ®_data);
2108 if (duplex == HALF_DUPLEX)
2109 reg_data |= GG82563_KMCR_PASS_FALSE_CARRIER;
2111 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
2113 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
2119 e1000_configure_kmrn_for_1000(struct e1000_hw *hw)
2121 int32_t ret_val = E1000_SUCCESS;
2125 DEBUGFUNC("e1000_configure_kmrn_for_1000");
2127 reg_data = E1000_KUMCTRLSTA_HD_CTRL_1000_DEFAULT;
2128 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_HD_CTRL,
2133 /* Configure Transmit Inter-Packet Gap */
2134 tipg = E1000_READ_REG(hw, TIPG);
2135 tipg &= ~E1000_TIPG_IPGT_MASK;
2136 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
2137 E1000_WRITE_REG(hw, TIPG, tipg);
2139 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, ®_data);
2144 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
2145 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
2150 /******************************************************************************
2151 * Configures PHY autoneg and flow control advertisement settings
2153 * hw - Struct containing variables accessed by shared code
2154 ******************************************************************************/
2156 e1000_phy_setup_autoneg(struct e1000_hw *hw)
2159 uint16_t mii_autoneg_adv_reg;
2160 uint16_t mii_1000t_ctrl_reg;
2162 DEBUGFUNC("e1000_phy_setup_autoneg");
2164 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
2165 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
2169 if (hw->phy_type != e1000_phy_ife) {
2170 /* Read the MII 1000Base-T Control Register (Address 9). */
2171 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
2175 mii_1000t_ctrl_reg=0;
2177 /* Need to parse both autoneg_advertised and fc and set up
2178 * the appropriate PHY registers. First we will parse for
2179 * autoneg_advertised software override. Since we can advertise
2180 * a plethora of combinations, we need to check each bit
2184 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
2185 * Advertisement Register (Address 4) and the 1000 mb speed bits in
2186 * the 1000Base-T Control Register (Address 9).
2188 mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
2189 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
2191 DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised);
2193 /* Do we want to advertise 10 Mb Half Duplex? */
2194 if (hw->autoneg_advertised & ADVERTISE_10_HALF) {
2195 DEBUGOUT("Advertise 10mb Half duplex\n");
2196 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
2199 /* Do we want to advertise 10 Mb Full Duplex? */
2200 if (hw->autoneg_advertised & ADVERTISE_10_FULL) {
2201 DEBUGOUT("Advertise 10mb Full duplex\n");
2202 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
2205 /* Do we want to advertise 100 Mb Half Duplex? */
2206 if (hw->autoneg_advertised & ADVERTISE_100_HALF) {
2207 DEBUGOUT("Advertise 100mb Half duplex\n");
2208 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
2211 /* Do we want to advertise 100 Mb Full Duplex? */
2212 if (hw->autoneg_advertised & ADVERTISE_100_FULL) {
2213 DEBUGOUT("Advertise 100mb Full duplex\n");
2214 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
2217 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
2218 if (hw->autoneg_advertised & ADVERTISE_1000_HALF) {
2219 DEBUGOUT("Advertise 1000mb Half duplex requested, request denied!\n");
2222 /* Do we want to advertise 1000 Mb Full Duplex? */
2223 if (hw->autoneg_advertised & ADVERTISE_1000_FULL) {
2224 DEBUGOUT("Advertise 1000mb Full duplex\n");
2225 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
2226 if (hw->phy_type == e1000_phy_ife) {
2227 DEBUGOUT("e1000_phy_ife is a 10/100 PHY. Gigabit speed is not supported.\n");
2231 /* Check for a software override of the flow control settings, and
2232 * setup the PHY advertisement registers accordingly. If
2233 * auto-negotiation is enabled, then software will have to set the
2234 * "PAUSE" bits to the correct value in the Auto-Negotiation
2235 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
2237 * The possible values of the "fc" parameter are:
2238 * 0: Flow control is completely disabled
2239 * 1: Rx flow control is enabled (we can receive pause frames
2240 * but not send pause frames).
2241 * 2: Tx flow control is enabled (we can send pause frames
2242 * but we do not support receiving pause frames).
2243 * 3: Both Rx and TX flow control (symmetric) are enabled.
2244 * other: No software override. The flow control configuration
2245 * in the EEPROM is used.
2248 case E1000_FC_NONE: /* 0 */
2249 /* Flow control (RX & TX) is completely disabled by a
2250 * software over-ride.
2252 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2254 case E1000_FC_RX_PAUSE: /* 1 */
2255 /* RX Flow control is enabled, and TX Flow control is
2256 * disabled, by a software over-ride.
2258 /* Since there really isn't a way to advertise that we are
2259 * capable of RX Pause ONLY, we will advertise that we
2260 * support both symmetric and asymmetric RX PAUSE. Later
2261 * (in e1000_config_fc_after_link_up) we will disable the
2262 *hw's ability to send PAUSE frames.
2264 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2266 case E1000_FC_TX_PAUSE: /* 2 */
2267 /* TX Flow control is enabled, and RX Flow control is
2268 * disabled, by a software over-ride.
2270 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
2271 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
2273 case E1000_FC_FULL: /* 3 */
2274 /* Flow control (both RX and TX) is enabled by a software
2277 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2280 DEBUGOUT("Flow control param set incorrectly\n");
2281 return -E1000_ERR_CONFIG;
2284 ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
2288 DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
2290 if (hw->phy_type != e1000_phy_ife) {
2291 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg);
2296 return E1000_SUCCESS;
2299 /******************************************************************************
2300 * Force PHY speed and duplex settings to hw->forced_speed_duplex
2302 * hw - Struct containing variables accessed by shared code
2303 ******************************************************************************/
2305 e1000_phy_force_speed_duplex(struct e1000_hw *hw)
2309 uint16_t mii_ctrl_reg;
2310 uint16_t mii_status_reg;
2314 DEBUGFUNC("e1000_phy_force_speed_duplex");
2316 /* Turn off Flow control if we are forcing speed and duplex. */
2317 hw->fc = E1000_FC_NONE;
2319 DEBUGOUT1("hw->fc = %d\n", hw->fc);
2321 /* Read the Device Control Register. */
2322 ctrl = E1000_READ_REG(hw, CTRL);
2324 /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */
2325 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2326 ctrl &= ~(DEVICE_SPEED_MASK);
2328 /* Clear the Auto Speed Detect Enable bit. */
2329 ctrl &= ~E1000_CTRL_ASDE;
2331 /* Read the MII Control Register. */
2332 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg);
2336 /* We need to disable autoneg in order to force link and duplex. */
2338 mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN;
2340 /* Are we forcing Full or Half Duplex? */
2341 if (hw->forced_speed_duplex == e1000_100_full ||
2342 hw->forced_speed_duplex == e1000_10_full) {
2343 /* We want to force full duplex so we SET the full duplex bits in the
2344 * Device and MII Control Registers.
2346 ctrl |= E1000_CTRL_FD;
2347 mii_ctrl_reg |= MII_CR_FULL_DUPLEX;
2348 DEBUGOUT("Full Duplex\n");
2350 /* We want to force half duplex so we CLEAR the full duplex bits in
2351 * the Device and MII Control Registers.
2353 ctrl &= ~E1000_CTRL_FD;
2354 mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX;
2355 DEBUGOUT("Half Duplex\n");
2358 /* Are we forcing 100Mbps??? */
2359 if (hw->forced_speed_duplex == e1000_100_full ||
2360 hw->forced_speed_duplex == e1000_100_half) {
2361 /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */
2362 ctrl |= E1000_CTRL_SPD_100;
2363 mii_ctrl_reg |= MII_CR_SPEED_100;
2364 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
2365 DEBUGOUT("Forcing 100mb ");
2367 /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */
2368 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
2369 mii_ctrl_reg |= MII_CR_SPEED_10;
2370 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
2371 DEBUGOUT("Forcing 10mb ");
2374 e1000_config_collision_dist(hw);
2376 /* Write the configured values back to the Device Control Reg. */
2377 E1000_WRITE_REG(hw, CTRL, ctrl);
2379 if ((hw->phy_type == e1000_phy_m88) ||
2380 (hw->phy_type == e1000_phy_gg82563)) {
2381 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
2385 /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
2386 * forced whenever speed are duplex are forced.
2388 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
2389 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
2393 DEBUGOUT1("M88E1000 PSCR: %x \n", phy_data);
2395 /* Need to reset the PHY or these changes will be ignored */
2396 mii_ctrl_reg |= MII_CR_RESET;
2398 /* Disable MDI-X support for 10/100 */
2399 } else if (hw->phy_type == e1000_phy_ife) {
2400 ret_val = e1000_read_phy_reg(hw, IFE_PHY_MDIX_CONTROL, &phy_data);
2404 phy_data &= ~IFE_PMC_AUTO_MDIX;
2405 phy_data &= ~IFE_PMC_FORCE_MDIX;
2407 ret_val = e1000_write_phy_reg(hw, IFE_PHY_MDIX_CONTROL, phy_data);
2412 /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
2413 * forced whenever speed or duplex are forced.
2415 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
2419 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
2420 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
2422 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
2427 /* Write back the modified PHY MII control register. */
2428 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg);
2434 /* The wait_autoneg_complete flag may be a little misleading here.
2435 * Since we are forcing speed and duplex, Auto-Neg is not enabled.
2436 * But we do want to delay for a period while forcing only so we
2437 * don't generate false No Link messages. So we will wait here
2438 * only if the user has set wait_autoneg_complete to 1, which is
2441 if (hw->wait_autoneg_complete) {
2442 /* We will wait for autoneg to complete. */
2443 DEBUGOUT("Waiting for forced speed/duplex link.\n");
2446 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
2447 for (i = PHY_FORCE_TIME; i > 0; i--) {
2448 /* Read the MII Status Register and wait for Auto-Neg Complete bit
2451 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2455 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2459 if (mii_status_reg & MII_SR_LINK_STATUS) break;
2463 ((hw->phy_type == e1000_phy_m88) ||
2464 (hw->phy_type == e1000_phy_gg82563))) {
2465 /* We didn't get link. Reset the DSP and wait again for link. */
2466 ret_val = e1000_phy_reset_dsp(hw);
2468 DEBUGOUT("Error Resetting PHY DSP\n");
2472 /* This loop will early-out if the link condition has been met. */
2473 for (i = PHY_FORCE_TIME; i > 0; i--) {
2474 if (mii_status_reg & MII_SR_LINK_STATUS) break;
2476 /* Read the MII Status Register and wait for Auto-Neg Complete bit
2479 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2483 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2489 if (hw->phy_type == e1000_phy_m88) {
2490 /* Because we reset the PHY above, we need to re-force TX_CLK in the
2491 * Extended PHY Specific Control Register to 25MHz clock. This value
2492 * defaults back to a 2.5MHz clock when the PHY is reset.
2494 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
2498 phy_data |= M88E1000_EPSCR_TX_CLK_25;
2499 ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
2503 /* In addition, because of the s/w reset above, we need to enable CRS on
2504 * TX. This must be set for both full and half duplex operation.
2506 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
2510 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
2511 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
2515 if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
2516 (!hw->autoneg) && (hw->forced_speed_duplex == e1000_10_full ||
2517 hw->forced_speed_duplex == e1000_10_half)) {
2518 ret_val = e1000_polarity_reversal_workaround(hw);
2522 } else if (hw->phy_type == e1000_phy_gg82563) {
2523 /* The TX_CLK of the Extended PHY Specific Control Register defaults
2524 * to 2.5MHz on a reset. We need to re-force it back to 25MHz, if
2525 * we're not in a forced 10/duplex configuration. */
2526 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, &phy_data);
2530 phy_data &= ~GG82563_MSCR_TX_CLK_MASK;
2531 if ((hw->forced_speed_duplex == e1000_10_full) ||
2532 (hw->forced_speed_duplex == e1000_10_half))
2533 phy_data |= GG82563_MSCR_TX_CLK_10MBPS_2_5MHZ;
2535 phy_data |= GG82563_MSCR_TX_CLK_100MBPS_25MHZ;
2537 /* Also due to the reset, we need to enable CRS on Tx. */
2538 phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
2540 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, phy_data);
2544 return E1000_SUCCESS;
2547 /******************************************************************************
2548 * Sets the collision distance in the Transmit Control register
2550 * hw - Struct containing variables accessed by shared code
2552 * Link should have been established previously. Reads the speed and duplex
2553 * information from the Device Status register.
2554 ******************************************************************************/
2556 e1000_config_collision_dist(struct e1000_hw *hw)
2558 uint32_t tctl, coll_dist;
2560 DEBUGFUNC("e1000_config_collision_dist");
2562 if (hw->mac_type < e1000_82543)
2563 coll_dist = E1000_COLLISION_DISTANCE_82542;
2565 coll_dist = E1000_COLLISION_DISTANCE;
2567 tctl = E1000_READ_REG(hw, TCTL);
2569 tctl &= ~E1000_TCTL_COLD;
2570 tctl |= coll_dist << E1000_COLD_SHIFT;
2572 E1000_WRITE_REG(hw, TCTL, tctl);
2573 E1000_WRITE_FLUSH(hw);
2576 /******************************************************************************
2577 * Sets MAC speed and duplex settings to reflect the those in the PHY
2579 * hw - Struct containing variables accessed by shared code
2580 * mii_reg - data to write to the MII control register
2582 * The contents of the PHY register containing the needed information need to
2584 ******************************************************************************/
2586 e1000_config_mac_to_phy(struct e1000_hw *hw)
2592 DEBUGFUNC("e1000_config_mac_to_phy");
2594 /* 82544 or newer MAC, Auto Speed Detection takes care of
2595 * MAC speed/duplex configuration.*/
2596 if (hw->mac_type >= e1000_82544)
2597 return E1000_SUCCESS;
2599 /* Read the Device Control Register and set the bits to Force Speed
2602 ctrl = E1000_READ_REG(hw, CTRL);
2603 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2604 ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
2606 /* Set up duplex in the Device Control and Transmit Control
2607 * registers depending on negotiated values.
2609 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
2613 if (phy_data & M88E1000_PSSR_DPLX)
2614 ctrl |= E1000_CTRL_FD;
2616 ctrl &= ~E1000_CTRL_FD;
2618 e1000_config_collision_dist(hw);
2620 /* Set up speed in the Device Control register depending on
2621 * negotiated values.
2623 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
2624 ctrl |= E1000_CTRL_SPD_1000;
2625 else if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
2626 ctrl |= E1000_CTRL_SPD_100;
2628 /* Write the configured values back to the Device Control Reg. */
2629 E1000_WRITE_REG(hw, CTRL, ctrl);
2630 return E1000_SUCCESS;
2633 /******************************************************************************
2634 * Forces the MAC's flow control settings.
2636 * hw - Struct containing variables accessed by shared code
2638 * Sets the TFCE and RFCE bits in the device control register to reflect
2639 * the adapter settings. TFCE and RFCE need to be explicitly set by
2640 * software when a Copper PHY is used because autonegotiation is managed
2641 * by the PHY rather than the MAC. Software must also configure these
2642 * bits when link is forced on a fiber connection.
2643 *****************************************************************************/
2645 e1000_force_mac_fc(struct e1000_hw *hw)
2649 DEBUGFUNC("e1000_force_mac_fc");
2651 /* Get the current configuration of the Device Control Register */
2652 ctrl = E1000_READ_REG(hw, CTRL);
2654 /* Because we didn't get link via the internal auto-negotiation
2655 * mechanism (we either forced link or we got link via PHY
2656 * auto-neg), we have to manually enable/disable transmit an
2657 * receive flow control.
2659 * The "Case" statement below enables/disable flow control
2660 * according to the "hw->fc" parameter.
2662 * The possible values of the "fc" parameter are:
2663 * 0: Flow control is completely disabled
2664 * 1: Rx flow control is enabled (we can receive pause
2665 * frames but not send pause frames).
2666 * 2: Tx flow control is enabled (we can send pause frames
2667 * frames but we do not receive pause frames).
2668 * 3: Both Rx and TX flow control (symmetric) is enabled.
2669 * other: No other values should be possible at this point.
2674 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
2676 case E1000_FC_RX_PAUSE:
2677 ctrl &= (~E1000_CTRL_TFCE);
2678 ctrl |= E1000_CTRL_RFCE;
2680 case E1000_FC_TX_PAUSE:
2681 ctrl &= (~E1000_CTRL_RFCE);
2682 ctrl |= E1000_CTRL_TFCE;
2685 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
2688 DEBUGOUT("Flow control param set incorrectly\n");
2689 return -E1000_ERR_CONFIG;
2692 /* Disable TX Flow Control for 82542 (rev 2.0) */
2693 if (hw->mac_type == e1000_82542_rev2_0)
2694 ctrl &= (~E1000_CTRL_TFCE);
2696 E1000_WRITE_REG(hw, CTRL, ctrl);
2697 return E1000_SUCCESS;
2700 /******************************************************************************
2701 * Configures flow control settings after link is established
2703 * hw - Struct containing variables accessed by shared code
2705 * Should be called immediately after a valid link has been established.
2706 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
2707 * and autonegotiation is enabled, the MAC flow control settings will be set
2708 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
2709 * and RFCE bits will be automaticaly set to the negotiated flow control mode.
2710 *****************************************************************************/
2712 e1000_config_fc_after_link_up(struct e1000_hw *hw)
2715 uint16_t mii_status_reg;
2716 uint16_t mii_nway_adv_reg;
2717 uint16_t mii_nway_lp_ability_reg;
2721 DEBUGFUNC("e1000_config_fc_after_link_up");
2723 /* Check for the case where we have fiber media and auto-neg failed
2724 * so we had to force link. In this case, we need to force the
2725 * configuration of the MAC to match the "fc" parameter.
2727 if (((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) ||
2728 ((hw->media_type == e1000_media_type_internal_serdes) &&
2729 (hw->autoneg_failed)) ||
2730 ((hw->media_type == e1000_media_type_copper) && (!hw->autoneg))) {
2731 ret_val = e1000_force_mac_fc(hw);
2733 DEBUGOUT("Error forcing flow control settings\n");
2738 /* Check for the case where we have copper media and auto-neg is
2739 * enabled. In this case, we need to check and see if Auto-Neg
2740 * has completed, and if so, how the PHY and link partner has
2741 * flow control configured.
2743 if ((hw->media_type == e1000_media_type_copper) && hw->autoneg) {
2744 /* Read the MII Status Register and check to see if AutoNeg
2745 * has completed. We read this twice because this reg has
2746 * some "sticky" (latched) bits.
2748 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2751 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2755 if (mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
2756 /* The AutoNeg process has completed, so we now need to
2757 * read both the Auto Negotiation Advertisement Register
2758 * (Address 4) and the Auto_Negotiation Base Page Ability
2759 * Register (Address 5) to determine how flow control was
2762 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV,
2766 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY,
2767 &mii_nway_lp_ability_reg);
2771 /* Two bits in the Auto Negotiation Advertisement Register
2772 * (Address 4) and two bits in the Auto Negotiation Base
2773 * Page Ability Register (Address 5) determine flow control
2774 * for both the PHY and the link partner. The following
2775 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
2776 * 1999, describes these PAUSE resolution bits and how flow
2777 * control is determined based upon these settings.
2778 * NOTE: DC = Don't Care
2780 * LOCAL DEVICE | LINK PARTNER
2781 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
2782 *-------|---------|-------|---------|--------------------
2783 * 0 | 0 | DC | DC | E1000_FC_NONE
2784 * 0 | 1 | 0 | DC | E1000_FC_NONE
2785 * 0 | 1 | 1 | 0 | E1000_FC_NONE
2786 * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
2787 * 1 | 0 | 0 | DC | E1000_FC_NONE
2788 * 1 | DC | 1 | DC | E1000_FC_FULL
2789 * 1 | 1 | 0 | 0 | E1000_FC_NONE
2790 * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
2793 /* Are both PAUSE bits set to 1? If so, this implies
2794 * Symmetric Flow Control is enabled at both ends. The
2795 * ASM_DIR bits are irrelevant per the spec.
2797 * For Symmetric Flow Control:
2799 * LOCAL DEVICE | LINK PARTNER
2800 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2801 *-------|---------|-------|---------|--------------------
2802 * 1 | DC | 1 | DC | E1000_FC_FULL
2805 if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2806 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
2807 /* Now we need to check if the user selected RX ONLY
2808 * of pause frames. In this case, we had to advertise
2809 * FULL flow control because we could not advertise RX
2810 * ONLY. Hence, we must now check to see if we need to
2811 * turn OFF the TRANSMISSION of PAUSE frames.
2813 if (hw->original_fc == E1000_FC_FULL) {
2814 hw->fc = E1000_FC_FULL;
2815 DEBUGOUT("Flow Control = FULL.\n");
2817 hw->fc = E1000_FC_RX_PAUSE;
2818 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
2821 /* For receiving PAUSE frames ONLY.
2823 * LOCAL DEVICE | LINK PARTNER
2824 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2825 *-------|---------|-------|---------|--------------------
2826 * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
2829 else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2830 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2831 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2832 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
2833 hw->fc = E1000_FC_TX_PAUSE;
2834 DEBUGOUT("Flow Control = TX PAUSE frames only.\n");
2836 /* For transmitting PAUSE frames ONLY.
2838 * LOCAL DEVICE | LINK PARTNER
2839 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2840 *-------|---------|-------|---------|--------------------
2841 * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
2844 else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2845 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2846 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2847 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
2848 hw->fc = E1000_FC_RX_PAUSE;
2849 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
2851 /* Per the IEEE spec, at this point flow control should be
2852 * disabled. However, we want to consider that we could
2853 * be connected to a legacy switch that doesn't advertise
2854 * desired flow control, but can be forced on the link
2855 * partner. So if we advertised no flow control, that is
2856 * what we will resolve to. If we advertised some kind of
2857 * receive capability (Rx Pause Only or Full Flow Control)
2858 * and the link partner advertised none, we will configure
2859 * ourselves to enable Rx Flow Control only. We can do
2860 * this safely for two reasons: If the link partner really
2861 * didn't want flow control enabled, and we enable Rx, no
2862 * harm done since we won't be receiving any PAUSE frames
2863 * anyway. If the intent on the link partner was to have
2864 * flow control enabled, then by us enabling RX only, we
2865 * can at least receive pause frames and process them.
2866 * This is a good idea because in most cases, since we are
2867 * predominantly a server NIC, more times than not we will
2868 * be asked to delay transmission of packets than asking
2869 * our link partner to pause transmission of frames.
2871 else if ((hw->original_fc == E1000_FC_NONE ||
2872 hw->original_fc == E1000_FC_TX_PAUSE) ||
2873 hw->fc_strict_ieee) {
2874 hw->fc = E1000_FC_NONE;
2875 DEBUGOUT("Flow Control = NONE.\n");
2877 hw->fc = E1000_FC_RX_PAUSE;
2878 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
2881 /* Now we need to do one last check... If we auto-
2882 * negotiated to HALF DUPLEX, flow control should not be
2883 * enabled per IEEE 802.3 spec.
2885 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
2887 DEBUGOUT("Error getting link speed and duplex\n");
2891 if (duplex == HALF_DUPLEX)
2892 hw->fc = E1000_FC_NONE;
2894 /* Now we call a subroutine to actually force the MAC
2895 * controller to use the correct flow control settings.
2897 ret_val = e1000_force_mac_fc(hw);
2899 DEBUGOUT("Error forcing flow control settings\n");
2903 DEBUGOUT("Copper PHY and Auto Neg has not completed.\n");
2906 return E1000_SUCCESS;
2909 /******************************************************************************
2910 * Checks to see if the link status of the hardware has changed.
2912 * hw - Struct containing variables accessed by shared code
2914 * Called by any function that needs to check the link status of the adapter.
2915 *****************************************************************************/
2917 e1000_check_for_link(struct e1000_hw *hw)
2924 uint32_t signal = 0;
2928 DEBUGFUNC("e1000_check_for_link");
2930 ctrl = E1000_READ_REG(hw, CTRL);
2931 status = E1000_READ_REG(hw, STATUS);
2933 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
2934 * set when the optics detect a signal. On older adapters, it will be
2935 * cleared when there is a signal. This applies to fiber media only.
2937 if ((hw->media_type == e1000_media_type_fiber) ||
2938 (hw->media_type == e1000_media_type_internal_serdes)) {
2939 rxcw = E1000_READ_REG(hw, RXCW);
2941 if (hw->media_type == e1000_media_type_fiber) {
2942 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
2943 if (status & E1000_STATUS_LU)
2944 hw->get_link_status = FALSE;
2948 /* If we have a copper PHY then we only want to go out to the PHY
2949 * registers to see if Auto-Neg has completed and/or if our link
2950 * status has changed. The get_link_status flag will be set if we
2951 * receive a Link Status Change interrupt or we have Rx Sequence
2954 if ((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
2955 /* First we want to see if the MII Status Register reports
2956 * link. If so, then we want to get the current speed/duplex
2958 * Read the register twice since the link bit is sticky.
2960 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2963 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2967 if (phy_data & MII_SR_LINK_STATUS) {
2968 hw->get_link_status = FALSE;
2969 /* Check if there was DownShift, must be checked immediately after
2971 e1000_check_downshift(hw);
2973 /* If we are on 82544 or 82543 silicon and speed/duplex
2974 * are forced to 10H or 10F, then we will implement the polarity
2975 * reversal workaround. We disable interrupts first, and upon
2976 * returning, place the devices interrupt state to its previous
2977 * value except for the link status change interrupt which will
2978 * happen due to the execution of this workaround.
2981 if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
2983 (hw->forced_speed_duplex == e1000_10_full ||
2984 hw->forced_speed_duplex == e1000_10_half)) {
2985 E1000_WRITE_REG(hw, IMC, 0xffffffff);
2986 ret_val = e1000_polarity_reversal_workaround(hw);
2987 icr = E1000_READ_REG(hw, ICR);
2988 E1000_WRITE_REG(hw, ICS, (icr & ~E1000_ICS_LSC));
2989 E1000_WRITE_REG(hw, IMS, IMS_ENABLE_MASK);
2993 /* No link detected */
2994 e1000_config_dsp_after_link_change(hw, FALSE);
2998 /* If we are forcing speed/duplex, then we simply return since
2999 * we have already determined whether we have link or not.
3001 if (!hw->autoneg) return -E1000_ERR_CONFIG;
3003 /* optimize the dsp settings for the igp phy */
3004 e1000_config_dsp_after_link_change(hw, TRUE);
3006 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
3007 * have Si on board that is 82544 or newer, Auto
3008 * Speed Detection takes care of MAC speed/duplex
3009 * configuration. So we only need to configure Collision
3010 * Distance in the MAC. Otherwise, we need to force
3011 * speed/duplex on the MAC to the current PHY speed/duplex
3014 if (hw->mac_type >= e1000_82544)
3015 e1000_config_collision_dist(hw);
3017 ret_val = e1000_config_mac_to_phy(hw);
3019 DEBUGOUT("Error configuring MAC to PHY settings\n");
3024 /* Configure Flow Control now that Auto-Neg has completed. First, we
3025 * need to restore the desired flow control settings because we may
3026 * have had to re-autoneg with a different link partner.
3028 ret_val = e1000_config_fc_after_link_up(hw);
3030 DEBUGOUT("Error configuring flow control\n");
3034 /* At this point we know that we are on copper and we have
3035 * auto-negotiated link. These are conditions for checking the link
3036 * partner capability register. We use the link speed to determine if
3037 * TBI compatibility needs to be turned on or off. If the link is not
3038 * at gigabit speed, then TBI compatibility is not needed. If we are
3039 * at gigabit speed, we turn on TBI compatibility.
3041 if (hw->tbi_compatibility_en) {
3042 uint16_t speed, duplex;
3043 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
3045 DEBUGOUT("Error getting link speed and duplex\n");
3048 if (speed != SPEED_1000) {
3049 /* If link speed is not set to gigabit speed, we do not need
3050 * to enable TBI compatibility.
3052 if (hw->tbi_compatibility_on) {
3053 /* If we previously were in the mode, turn it off. */
3054 rctl = E1000_READ_REG(hw, RCTL);
3055 rctl &= ~E1000_RCTL_SBP;
3056 E1000_WRITE_REG(hw, RCTL, rctl);
3057 hw->tbi_compatibility_on = FALSE;
3060 /* If TBI compatibility is was previously off, turn it on. For
3061 * compatibility with a TBI link partner, we will store bad
3062 * packets. Some frames have an additional byte on the end and
3063 * will look like CRC errors to to the hardware.
3065 if (!hw->tbi_compatibility_on) {
3066 hw->tbi_compatibility_on = TRUE;
3067 rctl = E1000_READ_REG(hw, RCTL);
3068 rctl |= E1000_RCTL_SBP;
3069 E1000_WRITE_REG(hw, RCTL, rctl);
3074 /* If we don't have link (auto-negotiation failed or link partner cannot
3075 * auto-negotiate), the cable is plugged in (we have signal), and our
3076 * link partner is not trying to auto-negotiate with us (we are receiving
3077 * idles or data), we need to force link up. We also need to give
3078 * auto-negotiation time to complete, in case the cable was just plugged
3079 * in. The autoneg_failed flag does this.
3081 else if ((((hw->media_type == e1000_media_type_fiber) &&
3082 ((ctrl & E1000_CTRL_SWDPIN1) == signal)) ||
3083 (hw->media_type == e1000_media_type_internal_serdes)) &&
3084 (!(status & E1000_STATUS_LU)) &&
3085 (!(rxcw & E1000_RXCW_C))) {
3086 if (hw->autoneg_failed == 0) {
3087 hw->autoneg_failed = 1;
3090 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\n");
3092 /* Disable auto-negotiation in the TXCW register */
3093 E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
3095 /* Force link-up and also force full-duplex. */
3096 ctrl = E1000_READ_REG(hw, CTRL);
3097 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
3098 E1000_WRITE_REG(hw, CTRL, ctrl);
3100 /* Configure Flow Control after forcing link up. */
3101 ret_val = e1000_config_fc_after_link_up(hw);
3103 DEBUGOUT("Error configuring flow control\n");
3107 /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
3108 * auto-negotiation in the TXCW register and disable forced link in the
3109 * Device Control register in an attempt to auto-negotiate with our link
3112 else if (((hw->media_type == e1000_media_type_fiber) ||
3113 (hw->media_type == e1000_media_type_internal_serdes)) &&
3114 (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
3115 DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\n");
3116 E1000_WRITE_REG(hw, TXCW, hw->txcw);
3117 E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
3119 hw->serdes_link_down = FALSE;
3121 /* If we force link for non-auto-negotiation switch, check link status
3122 * based on MAC synchronization for internal serdes media type.
3124 else if ((hw->media_type == e1000_media_type_internal_serdes) &&
3125 !(E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
3126 /* SYNCH bit and IV bit are sticky. */
3128 if (E1000_RXCW_SYNCH & E1000_READ_REG(hw, RXCW)) {
3129 if (!(rxcw & E1000_RXCW_IV)) {
3130 hw->serdes_link_down = FALSE;
3131 DEBUGOUT("SERDES: Link is up.\n");
3134 hw->serdes_link_down = TRUE;
3135 DEBUGOUT("SERDES: Link is down.\n");
3138 if ((hw->media_type == e1000_media_type_internal_serdes) &&
3139 (E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
3140 hw->serdes_link_down = !(E1000_STATUS_LU & E1000_READ_REG(hw, STATUS));
3142 return E1000_SUCCESS;
3145 /******************************************************************************
3146 * Detects the current speed and duplex settings of the hardware.
3148 * hw - Struct containing variables accessed by shared code
3149 * speed - Speed of the connection
3150 * duplex - Duplex setting of the connection
3151 *****************************************************************************/
3153 e1000_get_speed_and_duplex(struct e1000_hw *hw,
3161 DEBUGFUNC("e1000_get_speed_and_duplex");
3163 if (hw->mac_type >= e1000_82543) {
3164 status = E1000_READ_REG(hw, STATUS);
3165 if (status & E1000_STATUS_SPEED_1000) {
3166 *speed = SPEED_1000;
3167 DEBUGOUT("1000 Mbs, ");
3168 } else if (status & E1000_STATUS_SPEED_100) {
3170 DEBUGOUT("100 Mbs, ");
3173 DEBUGOUT("10 Mbs, ");
3176 if (status & E1000_STATUS_FD) {
3177 *duplex = FULL_DUPLEX;
3178 DEBUGOUT("Full Duplex\n");
3180 *duplex = HALF_DUPLEX;
3181 DEBUGOUT(" Half Duplex\n");
3184 DEBUGOUT("1000 Mbs, Full Duplex\n");
3185 *speed = SPEED_1000;
3186 *duplex = FULL_DUPLEX;
3189 /* IGP01 PHY may advertise full duplex operation after speed downgrade even
3190 * if it is operating at half duplex. Here we set the duplex settings to
3191 * match the duplex in the link partner's capabilities.
3193 if (hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
3194 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
3198 if (!(phy_data & NWAY_ER_LP_NWAY_CAPS))
3199 *duplex = HALF_DUPLEX;
3201 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data);
3204 if ((*speed == SPEED_100 && !(phy_data & NWAY_LPAR_100TX_FD_CAPS)) ||
3205 (*speed == SPEED_10 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
3206 *duplex = HALF_DUPLEX;
3210 if ((hw->mac_type == e1000_80003es2lan) &&
3211 (hw->media_type == e1000_media_type_copper)) {
3212 if (*speed == SPEED_1000)
3213 ret_val = e1000_configure_kmrn_for_1000(hw);
3215 ret_val = e1000_configure_kmrn_for_10_100(hw, *duplex);
3220 if ((hw->phy_type == e1000_phy_igp_3) && (*speed == SPEED_1000)) {
3221 ret_val = e1000_kumeran_lock_loss_workaround(hw);
3226 return E1000_SUCCESS;
3229 /******************************************************************************
3230 * Blocks until autoneg completes or times out (~4.5 seconds)
3232 * hw - Struct containing variables accessed by shared code
3233 ******************************************************************************/
3235 e1000_wait_autoneg(struct e1000_hw *hw)
3241 DEBUGFUNC("e1000_wait_autoneg");
3242 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
3244 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
3245 for (i = PHY_AUTO_NEG_TIME; i > 0; i--) {
3246 /* Read the MII Status Register and wait for Auto-Neg
3247 * Complete bit to be set.
3249 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3252 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3255 if (phy_data & MII_SR_AUTONEG_COMPLETE) {
3256 return E1000_SUCCESS;
3260 return E1000_SUCCESS;
3263 /******************************************************************************
3264 * Raises the Management Data Clock
3266 * hw - Struct containing variables accessed by shared code
3267 * ctrl - Device control register's current value
3268 ******************************************************************************/
3270 e1000_raise_mdi_clk(struct e1000_hw *hw,
3273 /* Raise the clock input to the Management Data Clock (by setting the MDC
3274 * bit), and then delay 10 microseconds.
3276 E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
3277 E1000_WRITE_FLUSH(hw);
3281 /******************************************************************************
3282 * Lowers the Management Data Clock
3284 * hw - Struct containing variables accessed by shared code
3285 * ctrl - Device control register's current value
3286 ******************************************************************************/
3288 e1000_lower_mdi_clk(struct e1000_hw *hw,
3291 /* Lower the clock input to the Management Data Clock (by clearing the MDC
3292 * bit), and then delay 10 microseconds.
3294 E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
3295 E1000_WRITE_FLUSH(hw);
3299 /******************************************************************************
3300 * Shifts data bits out to the PHY
3302 * hw - Struct containing variables accessed by shared code
3303 * data - Data to send out to the PHY
3304 * count - Number of bits to shift out
3306 * Bits are shifted out in MSB to LSB order.
3307 ******************************************************************************/
3309 e1000_shift_out_mdi_bits(struct e1000_hw *hw,
3316 /* We need to shift "count" number of bits out to the PHY. So, the value
3317 * in the "data" parameter will be shifted out to the PHY one bit at a
3318 * time. In order to do this, "data" must be broken down into bits.
3321 mask <<= (count - 1);
3323 ctrl = E1000_READ_REG(hw, CTRL);
3325 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
3326 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
3329 /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
3330 * then raising and lowering the Management Data Clock. A "0" is
3331 * shifted out to the PHY by setting the MDIO bit to "0" and then
3332 * raising and lowering the clock.
3335 ctrl |= E1000_CTRL_MDIO;
3337 ctrl &= ~E1000_CTRL_MDIO;
3339 E1000_WRITE_REG(hw, CTRL, ctrl);
3340 E1000_WRITE_FLUSH(hw);
3344 e1000_raise_mdi_clk(hw, &ctrl);
3345 e1000_lower_mdi_clk(hw, &ctrl);
3351 /******************************************************************************
3352 * Shifts data bits in from the PHY
3354 * hw - Struct containing variables accessed by shared code
3356 * Bits are shifted in in MSB to LSB order.
3357 ******************************************************************************/
3359 e1000_shift_in_mdi_bits(struct e1000_hw *hw)
3365 /* In order to read a register from the PHY, we need to shift in a total
3366 * of 18 bits from the PHY. The first two bit (turnaround) times are used
3367 * to avoid contention on the MDIO pin when a read operation is performed.
3368 * These two bits are ignored by us and thrown away. Bits are "shifted in"
3369 * by raising the input to the Management Data Clock (setting the MDC bit),
3370 * and then reading the value of the MDIO bit.
3372 ctrl = E1000_READ_REG(hw, CTRL);
3374 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
3375 ctrl &= ~E1000_CTRL_MDIO_DIR;
3376 ctrl &= ~E1000_CTRL_MDIO;
3378 E1000_WRITE_REG(hw, CTRL, ctrl);
3379 E1000_WRITE_FLUSH(hw);
3381 /* Raise and Lower the clock before reading in the data. This accounts for
3382 * the turnaround bits. The first clock occurred when we clocked out the
3383 * last bit of the Register Address.
3385 e1000_raise_mdi_clk(hw, &ctrl);
3386 e1000_lower_mdi_clk(hw, &ctrl);
3388 for (data = 0, i = 0; i < 16; i++) {
3390 e1000_raise_mdi_clk(hw, &ctrl);
3391 ctrl = E1000_READ_REG(hw, CTRL);
3392 /* Check to see if we shifted in a "1". */
3393 if (ctrl & E1000_CTRL_MDIO)
3395 e1000_lower_mdi_clk(hw, &ctrl);
3398 e1000_raise_mdi_clk(hw, &ctrl);
3399 e1000_lower_mdi_clk(hw, &ctrl);
3405 e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask)
3407 uint32_t swfw_sync = 0;
3408 uint32_t swmask = mask;
3409 uint32_t fwmask = mask << 16;
3410 int32_t timeout = 200;
3412 DEBUGFUNC("e1000_swfw_sync_acquire");
3414 if (hw->swfwhw_semaphore_present)
3415 return e1000_get_software_flag(hw);
3417 if (!hw->swfw_sync_present)
3418 return e1000_get_hw_eeprom_semaphore(hw);
3421 if (e1000_get_hw_eeprom_semaphore(hw))
3422 return -E1000_ERR_SWFW_SYNC;
3424 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
3425 if (!(swfw_sync & (fwmask | swmask))) {
3429 /* firmware currently using resource (fwmask) */
3430 /* or other software thread currently using resource (swmask) */
3431 e1000_put_hw_eeprom_semaphore(hw);
3437 DEBUGOUT("Driver can't access resource, SW_FW_SYNC timeout.\n");
3438 return -E1000_ERR_SWFW_SYNC;
3441 swfw_sync |= swmask;
3442 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
3444 e1000_put_hw_eeprom_semaphore(hw);
3445 return E1000_SUCCESS;
3449 e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask)
3452 uint32_t swmask = mask;
3454 DEBUGFUNC("e1000_swfw_sync_release");
3456 if (hw->swfwhw_semaphore_present) {
3457 e1000_release_software_flag(hw);
3461 if (!hw->swfw_sync_present) {
3462 e1000_put_hw_eeprom_semaphore(hw);
3466 /* if (e1000_get_hw_eeprom_semaphore(hw))
3467 * return -E1000_ERR_SWFW_SYNC; */
3468 while (e1000_get_hw_eeprom_semaphore(hw) != E1000_SUCCESS);
3471 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
3472 swfw_sync &= ~swmask;
3473 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
3475 e1000_put_hw_eeprom_semaphore(hw);
3478 /*****************************************************************************
3479 * Reads the value from a PHY register, if the value is on a specific non zero
3480 * page, sets the page first.
3481 * hw - Struct containing variables accessed by shared code
3482 * reg_addr - address of the PHY register to read
3483 ******************************************************************************/
3485 e1000_read_phy_reg(struct e1000_hw *hw,
3492 DEBUGFUNC("e1000_read_phy_reg");
3494 if ((hw->mac_type == e1000_80003es2lan) &&
3495 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3496 swfw = E1000_SWFW_PHY1_SM;
3498 swfw = E1000_SWFW_PHY0_SM;
3500 if (e1000_swfw_sync_acquire(hw, swfw))
3501 return -E1000_ERR_SWFW_SYNC;
3503 if ((hw->phy_type == e1000_phy_igp ||
3504 hw->phy_type == e1000_phy_igp_3 ||
3505 hw->phy_type == e1000_phy_igp_2) &&
3506 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
3507 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
3508 (uint16_t)reg_addr);
3510 e1000_swfw_sync_release(hw, swfw);
3513 } else if (hw->phy_type == e1000_phy_gg82563) {
3514 if (((reg_addr & MAX_PHY_REG_ADDRESS) > MAX_PHY_MULTI_PAGE_REG) ||
3515 (hw->mac_type == e1000_80003es2lan)) {
3516 /* Select Configuration Page */
3517 if ((reg_addr & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) {
3518 ret_val = e1000_write_phy_reg_ex(hw, GG82563_PHY_PAGE_SELECT,
3519 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3521 /* Use Alternative Page Select register to access
3522 * registers 30 and 31
3524 ret_val = e1000_write_phy_reg_ex(hw,
3525 GG82563_PHY_PAGE_SELECT_ALT,
3526 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3530 e1000_swfw_sync_release(hw, swfw);
3536 ret_val = e1000_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
3539 e1000_swfw_sync_release(hw, swfw);
3544 e1000_read_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr,
3549 const uint32_t phy_addr = 1;
3551 DEBUGFUNC("e1000_read_phy_reg_ex");
3553 if (reg_addr > MAX_PHY_REG_ADDRESS) {
3554 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
3555 return -E1000_ERR_PARAM;
3558 if (hw->mac_type > e1000_82543) {
3559 /* Set up Op-code, Phy Address, and register address in the MDI
3560 * Control register. The MAC will take care of interfacing with the
3561 * PHY to retrieve the desired data.
3563 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
3564 (phy_addr << E1000_MDIC_PHY_SHIFT) |
3565 (E1000_MDIC_OP_READ));
3567 E1000_WRITE_REG(hw, MDIC, mdic);
3569 /* Poll the ready bit to see if the MDI read completed */
3570 for (i = 0; i < 64; i++) {
3572 mdic = E1000_READ_REG(hw, MDIC);
3573 if (mdic & E1000_MDIC_READY) break;
3575 if (!(mdic & E1000_MDIC_READY)) {
3576 DEBUGOUT("MDI Read did not complete\n");
3577 return -E1000_ERR_PHY;
3579 if (mdic & E1000_MDIC_ERROR) {
3580 DEBUGOUT("MDI Error\n");
3581 return -E1000_ERR_PHY;
3583 *phy_data = (uint16_t) mdic;
3585 /* We must first send a preamble through the MDIO pin to signal the
3586 * beginning of an MII instruction. This is done by sending 32
3587 * consecutive "1" bits.
3589 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
3591 /* Now combine the next few fields that are required for a read
3592 * operation. We use this method instead of calling the
3593 * e1000_shift_out_mdi_bits routine five different times. The format of
3594 * a MII read instruction consists of a shift out of 14 bits and is
3595 * defined as follows:
3596 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
3597 * followed by a shift in of 18 bits. This first two bits shifted in
3598 * are TurnAround bits used to avoid contention on the MDIO pin when a
3599 * READ operation is performed. These two bits are thrown away
3600 * followed by a shift in of 16 bits which contains the desired data.
3602 mdic = ((reg_addr) | (phy_addr << 5) |
3603 (PHY_OP_READ << 10) | (PHY_SOF << 12));
3605 e1000_shift_out_mdi_bits(hw, mdic, 14);
3607 /* Now that we've shifted out the read command to the MII, we need to
3608 * "shift in" the 16-bit value (18 total bits) of the requested PHY
3611 *phy_data = e1000_shift_in_mdi_bits(hw);
3613 return E1000_SUCCESS;
3616 /******************************************************************************
3617 * Writes a value to a PHY register
3619 * hw - Struct containing variables accessed by shared code
3620 * reg_addr - address of the PHY register to write
3621 * data - data to write to the PHY
3622 ******************************************************************************/
3624 e1000_write_phy_reg(struct e1000_hw *hw, uint32_t reg_addr,
3630 DEBUGFUNC("e1000_write_phy_reg");
3632 if ((hw->mac_type == e1000_80003es2lan) &&
3633 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3634 swfw = E1000_SWFW_PHY1_SM;
3636 swfw = E1000_SWFW_PHY0_SM;
3638 if (e1000_swfw_sync_acquire(hw, swfw))
3639 return -E1000_ERR_SWFW_SYNC;
3641 if ((hw->phy_type == e1000_phy_igp ||
3642 hw->phy_type == e1000_phy_igp_3 ||
3643 hw->phy_type == e1000_phy_igp_2) &&
3644 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
3645 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
3646 (uint16_t)reg_addr);
3648 e1000_swfw_sync_release(hw, swfw);
3651 } else if (hw->phy_type == e1000_phy_gg82563) {
3652 if (((reg_addr & MAX_PHY_REG_ADDRESS) > MAX_PHY_MULTI_PAGE_REG) ||
3653 (hw->mac_type == e1000_80003es2lan)) {
3654 /* Select Configuration Page */
3655 if ((reg_addr & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) {
3656 ret_val = e1000_write_phy_reg_ex(hw, GG82563_PHY_PAGE_SELECT,
3657 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3659 /* Use Alternative Page Select register to access
3660 * registers 30 and 31
3662 ret_val = e1000_write_phy_reg_ex(hw,
3663 GG82563_PHY_PAGE_SELECT_ALT,
3664 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3668 e1000_swfw_sync_release(hw, swfw);
3674 ret_val = e1000_write_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
3677 e1000_swfw_sync_release(hw, swfw);
3682 e1000_write_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr,
3687 const uint32_t phy_addr = 1;
3689 DEBUGFUNC("e1000_write_phy_reg_ex");
3691 if (reg_addr > MAX_PHY_REG_ADDRESS) {
3692 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
3693 return -E1000_ERR_PARAM;
3696 if (hw->mac_type > e1000_82543) {
3697 /* Set up Op-code, Phy Address, register address, and data intended
3698 * for the PHY register in the MDI Control register. The MAC will take
3699 * care of interfacing with the PHY to send the desired data.
3701 mdic = (((uint32_t) phy_data) |
3702 (reg_addr << E1000_MDIC_REG_SHIFT) |
3703 (phy_addr << E1000_MDIC_PHY_SHIFT) |
3704 (E1000_MDIC_OP_WRITE));
3706 E1000_WRITE_REG(hw, MDIC, mdic);
3708 /* Poll the ready bit to see if the MDI read completed */
3709 for (i = 0; i < 641; i++) {
3711 mdic = E1000_READ_REG(hw, MDIC);
3712 if (mdic & E1000_MDIC_READY) break;
3714 if (!(mdic & E1000_MDIC_READY)) {
3715 DEBUGOUT("MDI Write did not complete\n");
3716 return -E1000_ERR_PHY;
3719 /* We'll need to use the SW defined pins to shift the write command
3720 * out to the PHY. We first send a preamble to the PHY to signal the
3721 * beginning of the MII instruction. This is done by sending 32
3722 * consecutive "1" bits.
3724 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
3726 /* Now combine the remaining required fields that will indicate a
3727 * write operation. We use this method instead of calling the
3728 * e1000_shift_out_mdi_bits routine for each field in the command. The
3729 * format of a MII write instruction is as follows:
3730 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
3732 mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
3733 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
3735 mdic |= (uint32_t) phy_data;
3737 e1000_shift_out_mdi_bits(hw, mdic, 32);
3740 return E1000_SUCCESS;
3744 e1000_read_kmrn_reg(struct e1000_hw *hw,
3750 DEBUGFUNC("e1000_read_kmrn_reg");
3752 if ((hw->mac_type == e1000_80003es2lan) &&
3753 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3754 swfw = E1000_SWFW_PHY1_SM;
3756 swfw = E1000_SWFW_PHY0_SM;
3758 if (e1000_swfw_sync_acquire(hw, swfw))
3759 return -E1000_ERR_SWFW_SYNC;
3761 /* Write register address */
3762 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
3763 E1000_KUMCTRLSTA_OFFSET) |
3764 E1000_KUMCTRLSTA_REN;
3765 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
3768 /* Read the data returned */
3769 reg_val = E1000_READ_REG(hw, KUMCTRLSTA);
3770 *data = (uint16_t)reg_val;
3772 e1000_swfw_sync_release(hw, swfw);
3773 return E1000_SUCCESS;
3777 e1000_write_kmrn_reg(struct e1000_hw *hw,
3783 DEBUGFUNC("e1000_write_kmrn_reg");
3785 if ((hw->mac_type == e1000_80003es2lan) &&
3786 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3787 swfw = E1000_SWFW_PHY1_SM;
3789 swfw = E1000_SWFW_PHY0_SM;
3791 if (e1000_swfw_sync_acquire(hw, swfw))
3792 return -E1000_ERR_SWFW_SYNC;
3794 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
3795 E1000_KUMCTRLSTA_OFFSET) | data;
3796 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
3799 e1000_swfw_sync_release(hw, swfw);
3800 return E1000_SUCCESS;
3803 /******************************************************************************
3804 * Returns the PHY to the power-on reset state
3806 * hw - Struct containing variables accessed by shared code
3807 ******************************************************************************/
3809 e1000_phy_hw_reset(struct e1000_hw *hw)
3811 uint32_t ctrl, ctrl_ext;
3816 DEBUGFUNC("e1000_phy_hw_reset");
3818 /* In the case of the phy reset being blocked, it's not an error, we
3819 * simply return success without performing the reset. */
3820 ret_val = e1000_check_phy_reset_block(hw);
3822 return E1000_SUCCESS;
3824 DEBUGOUT("Resetting Phy...\n");
3826 if (hw->mac_type > e1000_82543) {
3827 if ((hw->mac_type == e1000_80003es2lan) &&
3828 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3829 swfw = E1000_SWFW_PHY1_SM;
3831 swfw = E1000_SWFW_PHY0_SM;
3833 if (e1000_swfw_sync_acquire(hw, swfw)) {
3834 DEBUGOUT("Unable to acquire swfw sync\n");
3835 return -E1000_ERR_SWFW_SYNC;
3837 /* Read the device control register and assert the E1000_CTRL_PHY_RST
3838 * bit. Then, take it out of reset.
3839 * For pre-e1000_82571 hardware, we delay for 10ms between the assert
3840 * and deassert. For e1000_82571 hardware and later, we instead delay
3841 * for 50us between and 10ms after the deassertion.
3843 ctrl = E1000_READ_REG(hw, CTRL);
3844 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST);
3845 E1000_WRITE_FLUSH(hw);
3847 if (hw->mac_type < e1000_82571)
3852 E1000_WRITE_REG(hw, CTRL, ctrl);
3853 E1000_WRITE_FLUSH(hw);
3855 if (hw->mac_type >= e1000_82571)
3858 e1000_swfw_sync_release(hw, swfw);
3860 /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
3861 * bit to put the PHY into reset. Then, take it out of reset.
3863 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
3864 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
3865 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
3866 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
3867 E1000_WRITE_FLUSH(hw);
3869 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
3870 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
3871 E1000_WRITE_FLUSH(hw);
3875 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
3876 /* Configure activity LED after PHY reset */
3877 led_ctrl = E1000_READ_REG(hw, LEDCTL);
3878 led_ctrl &= IGP_ACTIVITY_LED_MASK;
3879 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
3880 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
3883 /* Wait for FW to finish PHY configuration. */
3884 ret_val = e1000_get_phy_cfg_done(hw);
3885 if (ret_val != E1000_SUCCESS)
3887 e1000_release_software_semaphore(hw);
3889 if ((hw->mac_type == e1000_ich8lan) && (hw->phy_type == e1000_phy_igp_3))
3890 ret_val = e1000_init_lcd_from_nvm(hw);
3895 /******************************************************************************
3898 * hw - Struct containing variables accessed by shared code
3900 * Sets bit 15 of the MII Control register
3901 ******************************************************************************/
3903 e1000_phy_reset(struct e1000_hw *hw)
3908 DEBUGFUNC("e1000_phy_reset");
3910 /* In the case of the phy reset being blocked, it's not an error, we
3911 * simply return success without performing the reset. */
3912 ret_val = e1000_check_phy_reset_block(hw);
3914 return E1000_SUCCESS;
3916 switch (hw->phy_type) {
3918 case e1000_phy_igp_2:
3919 case e1000_phy_igp_3:
3921 ret_val = e1000_phy_hw_reset(hw);
3926 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
3930 phy_data |= MII_CR_RESET;
3931 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
3939 if (hw->phy_type == e1000_phy_igp || hw->phy_type == e1000_phy_igp_2)
3940 e1000_phy_init_script(hw);
3942 return E1000_SUCCESS;
3945 /******************************************************************************
3946 * Work-around for 82566 power-down: on D3 entry-
3947 * 1) disable gigabit link
3948 * 2) write VR power-down enable
3950 * if successful continue, else issue LCD reset and repeat
3952 * hw - struct containing variables accessed by shared code
3953 ******************************************************************************/
3955 e1000_phy_powerdown_workaround(struct e1000_hw *hw)
3961 DEBUGFUNC("e1000_phy_powerdown_workaround");
3963 if (hw->phy_type != e1000_phy_igp_3)
3968 reg = E1000_READ_REG(hw, PHY_CTRL);
3969 E1000_WRITE_REG(hw, PHY_CTRL, reg | E1000_PHY_CTRL_GBE_DISABLE |
3970 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
3972 /* Write VR power-down enable - bits 9:8 should be 10b */
3973 e1000_read_phy_reg(hw, IGP3_VR_CTRL, &phy_data);
3974 phy_data |= (1 << 9);
3975 phy_data &= ~(1 << 8);
3976 e1000_write_phy_reg(hw, IGP3_VR_CTRL, phy_data);
3978 /* Read it back and test */
3979 e1000_read_phy_reg(hw, IGP3_VR_CTRL, &phy_data);
3980 if (((phy_data & IGP3_VR_CTRL_MODE_MASK) == IGP3_VR_CTRL_MODE_SHUT) || retry)
3983 /* Issue PHY reset and repeat at most one more time */
3984 reg = E1000_READ_REG(hw, CTRL);
3985 E1000_WRITE_REG(hw, CTRL, reg | E1000_CTRL_PHY_RST);
3993 /******************************************************************************
3994 * Work-around for 82566 Kumeran PCS lock loss:
3995 * On link status change (i.e. PCI reset, speed change) and link is up and
3997 * 0) if workaround is optionally disabled do nothing
3998 * 1) wait 1ms for Kumeran link to come up
3999 * 2) check Kumeran Diagnostic register PCS lock loss bit
4000 * 3) if not set the link is locked (all is good), otherwise...
4002 * 5) repeat up to 10 times
4003 * Note: this is only called for IGP3 copper when speed is 1gb.
4005 * hw - struct containing variables accessed by shared code
4006 ******************************************************************************/
4008 e1000_kumeran_lock_loss_workaround(struct e1000_hw *hw)
4015 if (hw->kmrn_lock_loss_workaround_disabled)
4016 return E1000_SUCCESS;
4018 /* Make sure link is up before proceeding. If not just return.
4019 * Attempting this while link is negotiating fouled up link
4021 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
4022 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
4024 if (phy_data & MII_SR_LINK_STATUS) {
4025 for (cnt = 0; cnt < 10; cnt++) {
4026 /* read once to clear */
4027 ret_val = e1000_read_phy_reg(hw, IGP3_KMRN_DIAG, &phy_data);
4030 /* and again to get new status */
4031 ret_val = e1000_read_phy_reg(hw, IGP3_KMRN_DIAG, &phy_data);
4035 /* check for PCS lock */
4036 if (!(phy_data & IGP3_KMRN_DIAG_PCS_LOCK_LOSS))
4037 return E1000_SUCCESS;
4039 /* Issue PHY reset */
4040 e1000_phy_hw_reset(hw);
4043 /* Disable GigE link negotiation */
4044 reg = E1000_READ_REG(hw, PHY_CTRL);
4045 E1000_WRITE_REG(hw, PHY_CTRL, reg | E1000_PHY_CTRL_GBE_DISABLE |
4046 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
4048 /* unable to acquire PCS lock */
4049 return E1000_ERR_PHY;
4052 return E1000_SUCCESS;
4055 /******************************************************************************
4056 * Probes the expected PHY address for known PHY IDs
4058 * hw - Struct containing variables accessed by shared code
4059 ******************************************************************************/
4061 e1000_detect_gig_phy(struct e1000_hw *hw)
4063 int32_t phy_init_status, ret_val;
4064 uint16_t phy_id_high, phy_id_low;
4065 boolean_t match = FALSE;
4067 DEBUGFUNC("e1000_detect_gig_phy");
4069 if (hw->phy_id != 0)
4070 return E1000_SUCCESS;
4072 /* The 82571 firmware may still be configuring the PHY. In this
4073 * case, we cannot access the PHY until the configuration is done. So
4074 * we explicitly set the PHY values. */
4075 if (hw->mac_type == e1000_82571 ||
4076 hw->mac_type == e1000_82572) {
4077 hw->phy_id = IGP01E1000_I_PHY_ID;
4078 hw->phy_type = e1000_phy_igp_2;
4079 return E1000_SUCCESS;
4082 /* ESB-2 PHY reads require e1000_phy_gg82563 to be set because of a work-
4083 * around that forces PHY page 0 to be set or the reads fail. The rest of
4084 * the code in this routine uses e1000_read_phy_reg to read the PHY ID.
4085 * So for ESB-2 we need to have this set so our reads won't fail. If the
4086 * attached PHY is not a e1000_phy_gg82563, the routines below will figure
4087 * this out as well. */
4088 if (hw->mac_type == e1000_80003es2lan)
4089 hw->phy_type = e1000_phy_gg82563;
4091 /* Read the PHY ID Registers to identify which PHY is onboard. */
4092 ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
4096 hw->phy_id = (uint32_t) (phy_id_high << 16);
4098 ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
4102 hw->phy_id |= (uint32_t) (phy_id_low & PHY_REVISION_MASK);
4103 hw->phy_revision = (uint32_t) phy_id_low & ~PHY_REVISION_MASK;
4105 switch (hw->mac_type) {
4107 if (hw->phy_id == M88E1000_E_PHY_ID) match = TRUE;
4110 if (hw->phy_id == M88E1000_I_PHY_ID) match = TRUE;
4114 case e1000_82545_rev_3:
4116 case e1000_82546_rev_3:
4117 if (hw->phy_id == M88E1011_I_PHY_ID) match = TRUE;
4120 case e1000_82541_rev_2:
4122 case e1000_82547_rev_2:
4123 if (hw->phy_id == IGP01E1000_I_PHY_ID) match = TRUE;
4126 if (hw->phy_id == M88E1111_I_PHY_ID) match = TRUE;
4128 case e1000_80003es2lan:
4129 if (hw->phy_id == GG82563_E_PHY_ID) match = TRUE;
4132 if (hw->phy_id == IGP03E1000_E_PHY_ID) match = TRUE;
4133 if (hw->phy_id == IFE_E_PHY_ID) match = TRUE;
4134 if (hw->phy_id == IFE_PLUS_E_PHY_ID) match = TRUE;
4135 if (hw->phy_id == IFE_C_E_PHY_ID) match = TRUE;
4138 DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type);
4139 return -E1000_ERR_CONFIG;
4141 phy_init_status = e1000_set_phy_type(hw);
4143 if ((match) && (phy_init_status == E1000_SUCCESS)) {
4144 DEBUGOUT1("PHY ID 0x%X detected\n", hw->phy_id);
4145 return E1000_SUCCESS;
4147 DEBUGOUT1("Invalid PHY ID 0x%X\n", hw->phy_id);
4148 return -E1000_ERR_PHY;
4151 /******************************************************************************
4152 * Resets the PHY's DSP
4154 * hw - Struct containing variables accessed by shared code
4155 ******************************************************************************/
4157 e1000_phy_reset_dsp(struct e1000_hw *hw)
4160 DEBUGFUNC("e1000_phy_reset_dsp");
4163 if (hw->phy_type != e1000_phy_gg82563) {
4164 ret_val = e1000_write_phy_reg(hw, 29, 0x001d);
4167 ret_val = e1000_write_phy_reg(hw, 30, 0x00c1);
4169 ret_val = e1000_write_phy_reg(hw, 30, 0x0000);
4171 ret_val = E1000_SUCCESS;
4177 /******************************************************************************
4178 * Get PHY information from various PHY registers for igp PHY only.
4180 * hw - Struct containing variables accessed by shared code
4181 * phy_info - PHY information structure
4182 ******************************************************************************/
4184 e1000_phy_igp_get_info(struct e1000_hw *hw,
4185 struct e1000_phy_info *phy_info)
4188 uint16_t phy_data, min_length, max_length, average;
4189 e1000_rev_polarity polarity;
4191 DEBUGFUNC("e1000_phy_igp_get_info");
4193 /* The downshift status is checked only once, after link is established,
4194 * and it stored in the hw->speed_downgraded parameter. */
4195 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
4197 /* IGP01E1000 does not need to support it. */
4198 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
4200 /* IGP01E1000 always correct polarity reversal */
4201 phy_info->polarity_correction = e1000_polarity_reversal_enabled;
4203 /* Check polarity status */
4204 ret_val = e1000_check_polarity(hw, &polarity);
4208 phy_info->cable_polarity = polarity;
4210 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, &phy_data);
4214 phy_info->mdix_mode = (e1000_auto_x_mode)((phy_data & IGP01E1000_PSSR_MDIX) >>
4215 IGP01E1000_PSSR_MDIX_SHIFT);
4217 if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
4218 IGP01E1000_PSSR_SPEED_1000MBPS) {
4219 /* Local/Remote Receiver Information are only valid at 1000 Mbps */
4220 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
4224 phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
4225 SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
4226 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
4227 phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
4228 SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
4229 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
4231 /* Get cable length */
4232 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
4236 /* Translate to old method */
4237 average = (max_length + min_length) / 2;
4239 if (average <= e1000_igp_cable_length_50)
4240 phy_info->cable_length = e1000_cable_length_50;
4241 else if (average <= e1000_igp_cable_length_80)
4242 phy_info->cable_length = e1000_cable_length_50_80;
4243 else if (average <= e1000_igp_cable_length_110)
4244 phy_info->cable_length = e1000_cable_length_80_110;
4245 else if (average <= e1000_igp_cable_length_140)
4246 phy_info->cable_length = e1000_cable_length_110_140;
4248 phy_info->cable_length = e1000_cable_length_140;
4251 return E1000_SUCCESS;
4254 /******************************************************************************
4255 * Get PHY information from various PHY registers for ife PHY only.
4257 * hw - Struct containing variables accessed by shared code
4258 * phy_info - PHY information structure
4259 ******************************************************************************/
4261 e1000_phy_ife_get_info(struct e1000_hw *hw,
4262 struct e1000_phy_info *phy_info)
4266 e1000_rev_polarity polarity;
4268 DEBUGFUNC("e1000_phy_ife_get_info");
4270 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
4271 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
4273 ret_val = e1000_read_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL, &phy_data);
4276 phy_info->polarity_correction =
4277 ((phy_data & IFE_PSC_AUTO_POLARITY_DISABLE) >>
4278 IFE_PSC_AUTO_POLARITY_DISABLE_SHIFT) ?
4279 e1000_polarity_reversal_disabled : e1000_polarity_reversal_enabled;
4281 if (phy_info->polarity_correction == e1000_polarity_reversal_enabled) {
4282 ret_val = e1000_check_polarity(hw, &polarity);
4286 /* Polarity is forced. */
4287 polarity = ((phy_data & IFE_PSC_FORCE_POLARITY) >>
4288 IFE_PSC_FORCE_POLARITY_SHIFT) ?
4289 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
4291 phy_info->cable_polarity = polarity;
4293 ret_val = e1000_read_phy_reg(hw, IFE_PHY_MDIX_CONTROL, &phy_data);
4297 phy_info->mdix_mode = (e1000_auto_x_mode)
4298 ((phy_data & (IFE_PMC_AUTO_MDIX | IFE_PMC_FORCE_MDIX)) >>
4299 IFE_PMC_MDIX_MODE_SHIFT);
4301 return E1000_SUCCESS;
4304 /******************************************************************************
4305 * Get PHY information from various PHY registers fot m88 PHY only.
4307 * hw - Struct containing variables accessed by shared code
4308 * phy_info - PHY information structure
4309 ******************************************************************************/
4311 e1000_phy_m88_get_info(struct e1000_hw *hw,
4312 struct e1000_phy_info *phy_info)
4316 e1000_rev_polarity polarity;
4318 DEBUGFUNC("e1000_phy_m88_get_info");
4320 /* The downshift status is checked only once, after link is established,
4321 * and it stored in the hw->speed_downgraded parameter. */
4322 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
4324 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
4328 phy_info->extended_10bt_distance =
4329 ((phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >>
4330 M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT) ?
4331 e1000_10bt_ext_dist_enable_lower : e1000_10bt_ext_dist_enable_normal;
4333 phy_info->polarity_correction =
4334 ((phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >>
4335 M88E1000_PSCR_POLARITY_REVERSAL_SHIFT) ?
4336 e1000_polarity_reversal_disabled : e1000_polarity_reversal_enabled;
4338 /* Check polarity status */
4339 ret_val = e1000_check_polarity(hw, &polarity);
4342 phy_info->cable_polarity = polarity;
4344 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
4348 phy_info->mdix_mode = (e1000_auto_x_mode)((phy_data & M88E1000_PSSR_MDIX) >>
4349 M88E1000_PSSR_MDIX_SHIFT);
4351 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
4352 /* Cable Length Estimation and Local/Remote Receiver Information
4353 * are only valid at 1000 Mbps.
4355 if (hw->phy_type != e1000_phy_gg82563) {
4356 phy_info->cable_length = (e1000_cable_length)((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
4357 M88E1000_PSSR_CABLE_LENGTH_SHIFT);
4359 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_DSP_DISTANCE,
4364 phy_info->cable_length = (e1000_cable_length)(phy_data & GG82563_DSPD_CABLE_LENGTH);
4367 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
4371 phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
4372 SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
4373 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
4374 phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
4375 SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
4376 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
4380 return E1000_SUCCESS;
4383 /******************************************************************************
4384 * Get PHY information from various PHY registers
4386 * hw - Struct containing variables accessed by shared code
4387 * phy_info - PHY information structure
4388 ******************************************************************************/
4390 e1000_phy_get_info(struct e1000_hw *hw,
4391 struct e1000_phy_info *phy_info)
4396 DEBUGFUNC("e1000_phy_get_info");
4398 phy_info->cable_length = e1000_cable_length_undefined;
4399 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined;
4400 phy_info->cable_polarity = e1000_rev_polarity_undefined;
4401 phy_info->downshift = e1000_downshift_undefined;
4402 phy_info->polarity_correction = e1000_polarity_reversal_undefined;
4403 phy_info->mdix_mode = e1000_auto_x_mode_undefined;
4404 phy_info->local_rx = e1000_1000t_rx_status_undefined;
4405 phy_info->remote_rx = e1000_1000t_rx_status_undefined;
4407 if (hw->media_type != e1000_media_type_copper) {
4408 DEBUGOUT("PHY info is only valid for copper media\n");
4409 return -E1000_ERR_CONFIG;
4412 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
4416 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
4420 if ((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) {
4421 DEBUGOUT("PHY info is only valid if link is up\n");
4422 return -E1000_ERR_CONFIG;
4425 if (hw->phy_type == e1000_phy_igp ||
4426 hw->phy_type == e1000_phy_igp_3 ||
4427 hw->phy_type == e1000_phy_igp_2)
4428 return e1000_phy_igp_get_info(hw, phy_info);
4429 else if (hw->phy_type == e1000_phy_ife)
4430 return e1000_phy_ife_get_info(hw, phy_info);
4432 return e1000_phy_m88_get_info(hw, phy_info);
4436 e1000_validate_mdi_setting(struct e1000_hw *hw)
4438 DEBUGFUNC("e1000_validate_mdi_settings");
4440 if (!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) {
4441 DEBUGOUT("Invalid MDI setting detected\n");
4443 return -E1000_ERR_CONFIG;
4445 return E1000_SUCCESS;
4449 /******************************************************************************
4450 * Sets up eeprom variables in the hw struct. Must be called after mac_type
4451 * is configured. Additionally, if this is ICH8, the flash controller GbE
4452 * registers must be mapped, or this will crash.
4454 * hw - Struct containing variables accessed by shared code
4455 *****************************************************************************/
4457 e1000_init_eeprom_params(struct e1000_hw *hw)
4459 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4460 uint32_t eecd = E1000_READ_REG(hw, EECD);
4461 int32_t ret_val = E1000_SUCCESS;
4462 uint16_t eeprom_size;
4464 DEBUGFUNC("e1000_init_eeprom_params");
4466 switch (hw->mac_type) {
4467 case e1000_82542_rev2_0:
4468 case e1000_82542_rev2_1:
4471 eeprom->type = e1000_eeprom_microwire;
4472 eeprom->word_size = 64;
4473 eeprom->opcode_bits = 3;
4474 eeprom->address_bits = 6;
4475 eeprom->delay_usec = 50;
4476 eeprom->use_eerd = FALSE;
4477 eeprom->use_eewr = FALSE;
4481 case e1000_82545_rev_3:
4483 case e1000_82546_rev_3:
4484 eeprom->type = e1000_eeprom_microwire;
4485 eeprom->opcode_bits = 3;
4486 eeprom->delay_usec = 50;
4487 if (eecd & E1000_EECD_SIZE) {
4488 eeprom->word_size = 256;
4489 eeprom->address_bits = 8;
4491 eeprom->word_size = 64;
4492 eeprom->address_bits = 6;
4494 eeprom->use_eerd = FALSE;
4495 eeprom->use_eewr = FALSE;
4498 case e1000_82541_rev_2:
4500 case e1000_82547_rev_2:
4501 if (eecd & E1000_EECD_TYPE) {
4502 eeprom->type = e1000_eeprom_spi;
4503 eeprom->opcode_bits = 8;
4504 eeprom->delay_usec = 1;
4505 if (eecd & E1000_EECD_ADDR_BITS) {
4506 eeprom->page_size = 32;
4507 eeprom->address_bits = 16;
4509 eeprom->page_size = 8;
4510 eeprom->address_bits = 8;
4513 eeprom->type = e1000_eeprom_microwire;
4514 eeprom->opcode_bits = 3;
4515 eeprom->delay_usec = 50;
4516 if (eecd & E1000_EECD_ADDR_BITS) {
4517 eeprom->word_size = 256;
4518 eeprom->address_bits = 8;
4520 eeprom->word_size = 64;
4521 eeprom->address_bits = 6;
4524 eeprom->use_eerd = FALSE;
4525 eeprom->use_eewr = FALSE;
4529 eeprom->type = e1000_eeprom_spi;
4530 eeprom->opcode_bits = 8;
4531 eeprom->delay_usec = 1;
4532 if (eecd & E1000_EECD_ADDR_BITS) {
4533 eeprom->page_size = 32;
4534 eeprom->address_bits = 16;
4536 eeprom->page_size = 8;
4537 eeprom->address_bits = 8;
4539 eeprom->use_eerd = FALSE;
4540 eeprom->use_eewr = FALSE;
4543 eeprom->type = e1000_eeprom_spi;
4544 eeprom->opcode_bits = 8;
4545 eeprom->delay_usec = 1;
4546 if (eecd & E1000_EECD_ADDR_BITS) {
4547 eeprom->page_size = 32;
4548 eeprom->address_bits = 16;
4550 eeprom->page_size = 8;
4551 eeprom->address_bits = 8;
4553 eeprom->use_eerd = TRUE;
4554 eeprom->use_eewr = TRUE;
4555 if (e1000_is_onboard_nvm_eeprom(hw) == FALSE) {
4556 eeprom->type = e1000_eeprom_flash;
4557 eeprom->word_size = 2048;
4559 /* Ensure that the Autonomous FLASH update bit is cleared due to
4560 * Flash update issue on parts which use a FLASH for NVM. */
4561 eecd &= ~E1000_EECD_AUPDEN;
4562 E1000_WRITE_REG(hw, EECD, eecd);
4565 case e1000_80003es2lan:
4566 eeprom->type = e1000_eeprom_spi;
4567 eeprom->opcode_bits = 8;
4568 eeprom->delay_usec = 1;
4569 if (eecd & E1000_EECD_ADDR_BITS) {
4570 eeprom->page_size = 32;
4571 eeprom->address_bits = 16;
4573 eeprom->page_size = 8;
4574 eeprom->address_bits = 8;
4576 eeprom->use_eerd = TRUE;
4577 eeprom->use_eewr = FALSE;
4582 uint32_t flash_size = E1000_READ_ICH_FLASH_REG(hw, ICH_FLASH_GFPREG);
4584 eeprom->type = e1000_eeprom_ich8;
4585 eeprom->use_eerd = FALSE;
4586 eeprom->use_eewr = FALSE;
4587 eeprom->word_size = E1000_SHADOW_RAM_WORDS;
4589 /* Zero the shadow RAM structure. But don't load it from NVM
4590 * so as to save time for driver init */
4591 if (hw->eeprom_shadow_ram != NULL) {
4592 for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
4593 hw->eeprom_shadow_ram[i].modified = FALSE;
4594 hw->eeprom_shadow_ram[i].eeprom_word = 0xFFFF;
4598 hw->flash_base_addr = (flash_size & ICH_GFPREG_BASE_MASK) *
4599 ICH_FLASH_SECTOR_SIZE;
4601 hw->flash_bank_size = ((flash_size >> 16) & ICH_GFPREG_BASE_MASK) + 1;
4602 hw->flash_bank_size -= (flash_size & ICH_GFPREG_BASE_MASK);
4604 hw->flash_bank_size *= ICH_FLASH_SECTOR_SIZE;
4606 hw->flash_bank_size /= 2 * sizeof(uint16_t);
4614 if (eeprom->type == e1000_eeprom_spi) {
4615 /* eeprom_size will be an enum [0..8] that maps to eeprom sizes 128B to
4616 * 32KB (incremented by powers of 2).
4618 if (hw->mac_type <= e1000_82547_rev_2) {
4619 /* Set to default value for initial eeprom read. */
4620 eeprom->word_size = 64;
4621 ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size);
4624 eeprom_size = (eeprom_size & EEPROM_SIZE_MASK) >> EEPROM_SIZE_SHIFT;
4625 /* 256B eeprom size was not supported in earlier hardware, so we
4626 * bump eeprom_size up one to ensure that "1" (which maps to 256B)
4627 * is never the result used in the shifting logic below. */
4631 eeprom_size = (uint16_t)((eecd & E1000_EECD_SIZE_EX_MASK) >>
4632 E1000_EECD_SIZE_EX_SHIFT);
4635 eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT);
4640 /******************************************************************************
4641 * Raises the EEPROM's clock input.
4643 * hw - Struct containing variables accessed by shared code
4644 * eecd - EECD's current value
4645 *****************************************************************************/
4647 e1000_raise_ee_clk(struct e1000_hw *hw,
4650 /* Raise the clock input to the EEPROM (by setting the SK bit), and then
4651 * wait <delay> microseconds.
4653 *eecd = *eecd | E1000_EECD_SK;
4654 E1000_WRITE_REG(hw, EECD, *eecd);
4655 E1000_WRITE_FLUSH(hw);
4656 udelay(hw->eeprom.delay_usec);
4659 /******************************************************************************
4660 * Lowers the EEPROM's clock input.
4662 * hw - Struct containing variables accessed by shared code
4663 * eecd - EECD's current value
4664 *****************************************************************************/
4666 e1000_lower_ee_clk(struct e1000_hw *hw,
4669 /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
4670 * wait 50 microseconds.
4672 *eecd = *eecd & ~E1000_EECD_SK;
4673 E1000_WRITE_REG(hw, EECD, *eecd);
4674 E1000_WRITE_FLUSH(hw);
4675 udelay(hw->eeprom.delay_usec);
4678 /******************************************************************************
4679 * Shift data bits out to the EEPROM.
4681 * hw - Struct containing variables accessed by shared code
4682 * data - data to send to the EEPROM
4683 * count - number of bits to shift out
4684 *****************************************************************************/
4686 e1000_shift_out_ee_bits(struct e1000_hw *hw,
4690 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4694 /* We need to shift "count" bits out to the EEPROM. So, value in the
4695 * "data" parameter will be shifted out to the EEPROM one bit at a time.
4696 * In order to do this, "data" must be broken down into bits.
4698 mask = 0x01 << (count - 1);
4699 eecd = E1000_READ_REG(hw, EECD);
4700 if (eeprom->type == e1000_eeprom_microwire) {
4701 eecd &= ~E1000_EECD_DO;
4702 } else if (eeprom->type == e1000_eeprom_spi) {
4703 eecd |= E1000_EECD_DO;
4706 /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
4707 * and then raising and then lowering the clock (the SK bit controls
4708 * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
4709 * by setting "DI" to "0" and then raising and then lowering the clock.
4711 eecd &= ~E1000_EECD_DI;
4714 eecd |= E1000_EECD_DI;
4716 E1000_WRITE_REG(hw, EECD, eecd);
4717 E1000_WRITE_FLUSH(hw);
4719 udelay(eeprom->delay_usec);
4721 e1000_raise_ee_clk(hw, &eecd);
4722 e1000_lower_ee_clk(hw, &eecd);
4728 /* We leave the "DI" bit set to "0" when we leave this routine. */
4729 eecd &= ~E1000_EECD_DI;
4730 E1000_WRITE_REG(hw, EECD, eecd);
4733 /******************************************************************************
4734 * Shift data bits in from the EEPROM
4736 * hw - Struct containing variables accessed by shared code
4737 *****************************************************************************/
4739 e1000_shift_in_ee_bits(struct e1000_hw *hw,
4746 /* In order to read a register from the EEPROM, we need to shift 'count'
4747 * bits in from the EEPROM. Bits are "shifted in" by raising the clock
4748 * input to the EEPROM (setting the SK bit), and then reading the value of
4749 * the "DO" bit. During this "shifting in" process the "DI" bit should
4753 eecd = E1000_READ_REG(hw, EECD);
4755 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
4758 for (i = 0; i < count; i++) {
4760 e1000_raise_ee_clk(hw, &eecd);
4762 eecd = E1000_READ_REG(hw, EECD);
4764 eecd &= ~(E1000_EECD_DI);
4765 if (eecd & E1000_EECD_DO)
4768 e1000_lower_ee_clk(hw, &eecd);
4774 /******************************************************************************
4775 * Prepares EEPROM for access
4777 * hw - Struct containing variables accessed by shared code
4779 * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
4780 * function should be called before issuing a command to the EEPROM.
4781 *****************************************************************************/
4783 e1000_acquire_eeprom(struct e1000_hw *hw)
4785 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4788 DEBUGFUNC("e1000_acquire_eeprom");
4790 if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
4791 return -E1000_ERR_SWFW_SYNC;
4792 eecd = E1000_READ_REG(hw, EECD);
4794 if (hw->mac_type != e1000_82573) {
4795 /* Request EEPROM Access */
4796 if (hw->mac_type > e1000_82544) {
4797 eecd |= E1000_EECD_REQ;
4798 E1000_WRITE_REG(hw, EECD, eecd);
4799 eecd = E1000_READ_REG(hw, EECD);
4800 while ((!(eecd & E1000_EECD_GNT)) &&
4801 (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
4804 eecd = E1000_READ_REG(hw, EECD);
4806 if (!(eecd & E1000_EECD_GNT)) {
4807 eecd &= ~E1000_EECD_REQ;
4808 E1000_WRITE_REG(hw, EECD, eecd);
4809 DEBUGOUT("Could not acquire EEPROM grant\n");
4810 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
4811 return -E1000_ERR_EEPROM;
4816 /* Setup EEPROM for Read/Write */
4818 if (eeprom->type == e1000_eeprom_microwire) {
4819 /* Clear SK and DI */
4820 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
4821 E1000_WRITE_REG(hw, EECD, eecd);
4824 eecd |= E1000_EECD_CS;
4825 E1000_WRITE_REG(hw, EECD, eecd);
4826 } else if (eeprom->type == e1000_eeprom_spi) {
4827 /* Clear SK and CS */
4828 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
4829 E1000_WRITE_REG(hw, EECD, eecd);
4833 return E1000_SUCCESS;
4836 /******************************************************************************
4837 * Returns EEPROM to a "standby" state
4839 * hw - Struct containing variables accessed by shared code
4840 *****************************************************************************/
4842 e1000_standby_eeprom(struct e1000_hw *hw)
4844 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4847 eecd = E1000_READ_REG(hw, EECD);
4849 if (eeprom->type == e1000_eeprom_microwire) {
4850 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
4851 E1000_WRITE_REG(hw, EECD, eecd);
4852 E1000_WRITE_FLUSH(hw);
4853 udelay(eeprom->delay_usec);
4856 eecd |= E1000_EECD_SK;
4857 E1000_WRITE_REG(hw, EECD, eecd);
4858 E1000_WRITE_FLUSH(hw);
4859 udelay(eeprom->delay_usec);
4862 eecd |= E1000_EECD_CS;
4863 E1000_WRITE_REG(hw, EECD, eecd);
4864 E1000_WRITE_FLUSH(hw);
4865 udelay(eeprom->delay_usec);
4868 eecd &= ~E1000_EECD_SK;
4869 E1000_WRITE_REG(hw, EECD, eecd);
4870 E1000_WRITE_FLUSH(hw);
4871 udelay(eeprom->delay_usec);
4872 } else if (eeprom->type == e1000_eeprom_spi) {
4873 /* Toggle CS to flush commands */
4874 eecd |= E1000_EECD_CS;
4875 E1000_WRITE_REG(hw, EECD, eecd);
4876 E1000_WRITE_FLUSH(hw);
4877 udelay(eeprom->delay_usec);
4878 eecd &= ~E1000_EECD_CS;
4879 E1000_WRITE_REG(hw, EECD, eecd);
4880 E1000_WRITE_FLUSH(hw);
4881 udelay(eeprom->delay_usec);
4885 /******************************************************************************
4886 * Terminates a command by inverting the EEPROM's chip select pin
4888 * hw - Struct containing variables accessed by shared code
4889 *****************************************************************************/
4891 e1000_release_eeprom(struct e1000_hw *hw)
4895 DEBUGFUNC("e1000_release_eeprom");
4897 eecd = E1000_READ_REG(hw, EECD);
4899 if (hw->eeprom.type == e1000_eeprom_spi) {
4900 eecd |= E1000_EECD_CS; /* Pull CS high */
4901 eecd &= ~E1000_EECD_SK; /* Lower SCK */
4903 E1000_WRITE_REG(hw, EECD, eecd);
4905 udelay(hw->eeprom.delay_usec);
4906 } else if (hw->eeprom.type == e1000_eeprom_microwire) {
4907 /* cleanup eeprom */
4909 /* CS on Microwire is active-high */
4910 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
4912 E1000_WRITE_REG(hw, EECD, eecd);
4914 /* Rising edge of clock */
4915 eecd |= E1000_EECD_SK;
4916 E1000_WRITE_REG(hw, EECD, eecd);
4917 E1000_WRITE_FLUSH(hw);
4918 udelay(hw->eeprom.delay_usec);
4920 /* Falling edge of clock */
4921 eecd &= ~E1000_EECD_SK;
4922 E1000_WRITE_REG(hw, EECD, eecd);
4923 E1000_WRITE_FLUSH(hw);
4924 udelay(hw->eeprom.delay_usec);
4927 /* Stop requesting EEPROM access */
4928 if (hw->mac_type > e1000_82544) {
4929 eecd &= ~E1000_EECD_REQ;
4930 E1000_WRITE_REG(hw, EECD, eecd);
4933 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
4936 /******************************************************************************
4937 * Reads a 16 bit word from the EEPROM.
4939 * hw - Struct containing variables accessed by shared code
4940 *****************************************************************************/
4942 e1000_spi_eeprom_ready(struct e1000_hw *hw)
4944 uint16_t retry_count = 0;
4945 uint8_t spi_stat_reg;
4947 DEBUGFUNC("e1000_spi_eeprom_ready");
4949 /* Read "Status Register" repeatedly until the LSB is cleared. The
4950 * EEPROM will signal that the command has been completed by clearing
4951 * bit 0 of the internal status register. If it's not cleared within
4952 * 5 milliseconds, then error out.
4956 e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
4957 hw->eeprom.opcode_bits);
4958 spi_stat_reg = (uint8_t)e1000_shift_in_ee_bits(hw, 8);
4959 if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
4965 e1000_standby_eeprom(hw);
4966 } while (retry_count < EEPROM_MAX_RETRY_SPI);
4968 /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
4969 * only 0-5mSec on 5V devices)
4971 if (retry_count >= EEPROM_MAX_RETRY_SPI) {
4972 DEBUGOUT("SPI EEPROM Status error\n");
4973 return -E1000_ERR_EEPROM;
4976 return E1000_SUCCESS;
4979 /******************************************************************************
4980 * Reads a 16 bit word from the EEPROM.
4982 * hw - Struct containing variables accessed by shared code
4983 * offset - offset of word in the EEPROM to read
4984 * data - word read from the EEPROM
4985 * words - number of words to read
4986 *****************************************************************************/
4988 e1000_read_eeprom(struct e1000_hw *hw,
4993 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4996 DEBUGFUNC("e1000_read_eeprom");
4998 /* If eeprom is not yet detected, do so now */
4999 if (eeprom->word_size == 0)
5000 e1000_init_eeprom_params(hw);
5002 /* A check for invalid values: offset too large, too many words, and not
5005 if ((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
5007 DEBUGOUT2("\"words\" parameter out of bounds. Words = %d, size = %d\n", offset, eeprom->word_size);
5008 return -E1000_ERR_EEPROM;
5011 /* EEPROM's that don't use EERD to read require us to bit-bang the SPI
5012 * directly. In this case, we need to acquire the EEPROM so that
5013 * FW or other port software does not interrupt.
5015 if (e1000_is_onboard_nvm_eeprom(hw) == TRUE &&
5016 hw->eeprom.use_eerd == FALSE) {
5017 /* Prepare the EEPROM for bit-bang reading */
5018 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
5019 return -E1000_ERR_EEPROM;
5022 /* Eerd register EEPROM access requires no eeprom aquire/release */
5023 if (eeprom->use_eerd == TRUE)
5024 return e1000_read_eeprom_eerd(hw, offset, words, data);
5026 /* ICH EEPROM access is done via the ICH flash controller */
5027 if (eeprom->type == e1000_eeprom_ich8)
5028 return e1000_read_eeprom_ich8(hw, offset, words, data);
5030 /* Set up the SPI or Microwire EEPROM for bit-bang reading. We have
5031 * acquired the EEPROM at this point, so any returns should relase it */
5032 if (eeprom->type == e1000_eeprom_spi) {
5034 uint8_t read_opcode = EEPROM_READ_OPCODE_SPI;
5036 if (e1000_spi_eeprom_ready(hw)) {
5037 e1000_release_eeprom(hw);
5038 return -E1000_ERR_EEPROM;
5041 e1000_standby_eeprom(hw);
5043 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
5044 if ((eeprom->address_bits == 8) && (offset >= 128))
5045 read_opcode |= EEPROM_A8_OPCODE_SPI;
5047 /* Send the READ command (opcode + addr) */
5048 e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
5049 e1000_shift_out_ee_bits(hw, (uint16_t)(offset*2), eeprom->address_bits);
5051 /* Read the data. The address of the eeprom internally increments with
5052 * each byte (spi) being read, saving on the overhead of eeprom setup
5053 * and tear-down. The address counter will roll over if reading beyond
5054 * the size of the eeprom, thus allowing the entire memory to be read
5055 * starting from any offset. */
5056 for (i = 0; i < words; i++) {
5057 word_in = e1000_shift_in_ee_bits(hw, 16);
5058 data[i] = (word_in >> 8) | (word_in << 8);
5060 } else if (eeprom->type == e1000_eeprom_microwire) {
5061 for (i = 0; i < words; i++) {
5062 /* Send the READ command (opcode + addr) */
5063 e1000_shift_out_ee_bits(hw, EEPROM_READ_OPCODE_MICROWIRE,
5064 eeprom->opcode_bits);
5065 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + i),
5066 eeprom->address_bits);
5068 /* Read the data. For microwire, each word requires the overhead
5069 * of eeprom setup and tear-down. */
5070 data[i] = e1000_shift_in_ee_bits(hw, 16);
5071 e1000_standby_eeprom(hw);
5075 /* End this read operation */
5076 e1000_release_eeprom(hw);
5078 return E1000_SUCCESS;
5081 /******************************************************************************
5082 * Reads a 16 bit word from the EEPROM using the EERD register.
5084 * hw - Struct containing variables accessed by shared code
5085 * offset - offset of word in the EEPROM to read
5086 * data - word read from the EEPROM
5087 * words - number of words to read
5088 *****************************************************************************/
5090 e1000_read_eeprom_eerd(struct e1000_hw *hw,
5095 uint32_t i, eerd = 0;
5098 for (i = 0; i < words; i++) {
5099 eerd = ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) +
5100 E1000_EEPROM_RW_REG_START;
5102 E1000_WRITE_REG(hw, EERD, eerd);
5103 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_READ);
5108 data[i] = (E1000_READ_REG(hw, EERD) >> E1000_EEPROM_RW_REG_DATA);
5115 /******************************************************************************
5116 * Writes a 16 bit word from the EEPROM using the EEWR register.
5118 * hw - Struct containing variables accessed by shared code
5119 * offset - offset of word in the EEPROM to read
5120 * data - word read from the EEPROM
5121 * words - number of words to read
5122 *****************************************************************************/
5124 e1000_write_eeprom_eewr(struct e1000_hw *hw,
5129 uint32_t register_value = 0;
5133 if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
5134 return -E1000_ERR_SWFW_SYNC;
5136 for (i = 0; i < words; i++) {
5137 register_value = (data[i] << E1000_EEPROM_RW_REG_DATA) |
5138 ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) |
5139 E1000_EEPROM_RW_REG_START;
5141 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
5146 E1000_WRITE_REG(hw, EEWR, register_value);
5148 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
5155 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
5159 /******************************************************************************
5160 * Polls the status bit (bit 1) of the EERD to determine when the read is done.
5162 * hw - Struct containing variables accessed by shared code
5163 *****************************************************************************/
5165 e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd)
5167 uint32_t attempts = 100000;
5168 uint32_t i, reg = 0;
5169 int32_t done = E1000_ERR_EEPROM;
5171 for (i = 0; i < attempts; i++) {
5172 if (eerd == E1000_EEPROM_POLL_READ)
5173 reg = E1000_READ_REG(hw, EERD);
5175 reg = E1000_READ_REG(hw, EEWR);
5177 if (reg & E1000_EEPROM_RW_REG_DONE) {
5178 done = E1000_SUCCESS;
5187 /***************************************************************************
5188 * Description: Determines if the onboard NVM is FLASH or EEPROM.
5190 * hw - Struct containing variables accessed by shared code
5191 ****************************************************************************/
5193 e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw)
5197 DEBUGFUNC("e1000_is_onboard_nvm_eeprom");
5199 if (hw->mac_type == e1000_ich8lan)
5202 if (hw->mac_type == e1000_82573) {
5203 eecd = E1000_READ_REG(hw, EECD);
5205 /* Isolate bits 15 & 16 */
5206 eecd = ((eecd >> 15) & 0x03);
5208 /* If both bits are set, device is Flash type */
5216 /******************************************************************************
5217 * Verifies that the EEPROM has a valid checksum
5219 * hw - Struct containing variables accessed by shared code
5221 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
5222 * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
5224 *****************************************************************************/
5226 e1000_validate_eeprom_checksum(struct e1000_hw *hw)
5228 uint16_t checksum = 0;
5229 uint16_t i, eeprom_data;
5231 DEBUGFUNC("e1000_validate_eeprom_checksum");
5233 if ((hw->mac_type == e1000_82573) &&
5234 (e1000_is_onboard_nvm_eeprom(hw) == FALSE)) {
5235 /* Check bit 4 of word 10h. If it is 0, firmware is done updating
5236 * 10h-12h. Checksum may need to be fixed. */
5237 e1000_read_eeprom(hw, 0x10, 1, &eeprom_data);
5238 if ((eeprom_data & 0x10) == 0) {
5239 /* Read 0x23 and check bit 15. This bit is a 1 when the checksum
5240 * has already been fixed. If the checksum is still wrong and this
5241 * bit is a 1, we need to return bad checksum. Otherwise, we need
5242 * to set this bit to a 1 and update the checksum. */
5243 e1000_read_eeprom(hw, 0x23, 1, &eeprom_data);
5244 if ((eeprom_data & 0x8000) == 0) {
5245 eeprom_data |= 0x8000;
5246 e1000_write_eeprom(hw, 0x23, 1, &eeprom_data);
5247 e1000_update_eeprom_checksum(hw);
5252 if (hw->mac_type == e1000_ich8lan) {
5253 /* Drivers must allocate the shadow ram structure for the
5254 * EEPROM checksum to be updated. Otherwise, this bit as well
5255 * as the checksum must both be set correctly for this
5256 * validation to pass.
5258 e1000_read_eeprom(hw, 0x19, 1, &eeprom_data);
5259 if ((eeprom_data & 0x40) == 0) {
5260 eeprom_data |= 0x40;
5261 e1000_write_eeprom(hw, 0x19, 1, &eeprom_data);
5262 e1000_update_eeprom_checksum(hw);
5266 for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
5267 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
5268 DEBUGOUT("EEPROM Read Error\n");
5269 return -E1000_ERR_EEPROM;
5271 checksum += eeprom_data;
5274 if (checksum == (uint16_t) EEPROM_SUM)
5275 return E1000_SUCCESS;
5277 DEBUGOUT("EEPROM Checksum Invalid\n");
5278 return -E1000_ERR_EEPROM;
5282 /******************************************************************************
5283 * Calculates the EEPROM checksum and writes it to the EEPROM
5285 * hw - Struct containing variables accessed by shared code
5287 * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA.
5288 * Writes the difference to word offset 63 of the EEPROM.
5289 *****************************************************************************/
5291 e1000_update_eeprom_checksum(struct e1000_hw *hw)
5294 uint16_t checksum = 0;
5295 uint16_t i, eeprom_data;
5297 DEBUGFUNC("e1000_update_eeprom_checksum");
5299 for (i = 0; i < EEPROM_CHECKSUM_REG; i++) {
5300 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
5301 DEBUGOUT("EEPROM Read Error\n");
5302 return -E1000_ERR_EEPROM;
5304 checksum += eeprom_data;
5306 checksum = (uint16_t) EEPROM_SUM - checksum;
5307 if (e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) {
5308 DEBUGOUT("EEPROM Write Error\n");
5309 return -E1000_ERR_EEPROM;
5310 } else if (hw->eeprom.type == e1000_eeprom_flash) {
5311 e1000_commit_shadow_ram(hw);
5312 } else if (hw->eeprom.type == e1000_eeprom_ich8) {
5313 e1000_commit_shadow_ram(hw);
5314 /* Reload the EEPROM, or else modifications will not appear
5315 * until after next adapter reset. */
5316 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
5317 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
5318 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
5321 return E1000_SUCCESS;
5324 /******************************************************************************
5325 * Parent function for writing words to the different EEPROM types.
5327 * hw - Struct containing variables accessed by shared code
5328 * offset - offset within the EEPROM to be written to
5329 * words - number of words to write
5330 * data - 16 bit word to be written to the EEPROM
5332 * If e1000_update_eeprom_checksum is not called after this function, the
5333 * EEPROM will most likely contain an invalid checksum.
5334 *****************************************************************************/
5336 e1000_write_eeprom(struct e1000_hw *hw,
5341 struct e1000_eeprom_info *eeprom = &hw->eeprom;
5344 DEBUGFUNC("e1000_write_eeprom");
5346 /* If eeprom is not yet detected, do so now */
5347 if (eeprom->word_size == 0)
5348 e1000_init_eeprom_params(hw);
5350 /* A check for invalid values: offset too large, too many words, and not
5353 if ((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
5355 DEBUGOUT("\"words\" parameter out of bounds\n");
5356 return -E1000_ERR_EEPROM;
5359 /* 82573 writes only through eewr */
5360 if (eeprom->use_eewr == TRUE)
5361 return e1000_write_eeprom_eewr(hw, offset, words, data);
5363 if (eeprom->type == e1000_eeprom_ich8)
5364 return e1000_write_eeprom_ich8(hw, offset, words, data);
5366 /* Prepare the EEPROM for writing */
5367 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
5368 return -E1000_ERR_EEPROM;
5370 if (eeprom->type == e1000_eeprom_microwire) {
5371 status = e1000_write_eeprom_microwire(hw, offset, words, data);
5373 status = e1000_write_eeprom_spi(hw, offset, words, data);
5377 /* Done with writing */
5378 e1000_release_eeprom(hw);
5383 /******************************************************************************
5384 * Writes a 16 bit word to a given offset in an SPI EEPROM.
5386 * hw - Struct containing variables accessed by shared code
5387 * offset - offset within the EEPROM to be written to
5388 * words - number of words to write
5389 * data - pointer to array of 8 bit words to be written to the EEPROM
5391 *****************************************************************************/
5393 e1000_write_eeprom_spi(struct e1000_hw *hw,
5398 struct e1000_eeprom_info *eeprom = &hw->eeprom;
5401 DEBUGFUNC("e1000_write_eeprom_spi");
5403 while (widx < words) {
5404 uint8_t write_opcode = EEPROM_WRITE_OPCODE_SPI;
5406 if (e1000_spi_eeprom_ready(hw)) return -E1000_ERR_EEPROM;
5408 e1000_standby_eeprom(hw);
5410 /* Send the WRITE ENABLE command (8 bit opcode ) */
5411 e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI,
5412 eeprom->opcode_bits);
5414 e1000_standby_eeprom(hw);
5416 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
5417 if ((eeprom->address_bits == 8) && (offset >= 128))
5418 write_opcode |= EEPROM_A8_OPCODE_SPI;
5420 /* Send the Write command (8-bit opcode + addr) */
5421 e1000_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits);
5423 e1000_shift_out_ee_bits(hw, (uint16_t)((offset + widx)*2),
5424 eeprom->address_bits);
5428 /* Loop to allow for up to whole page write (32 bytes) of eeprom */
5429 while (widx < words) {
5430 uint16_t word_out = data[widx];
5431 word_out = (word_out >> 8) | (word_out << 8);
5432 e1000_shift_out_ee_bits(hw, word_out, 16);
5435 /* Some larger eeprom sizes are capable of a 32-byte PAGE WRITE
5436 * operation, while the smaller eeproms are capable of an 8-byte
5437 * PAGE WRITE operation. Break the inner loop to pass new address
5439 if ((((offset + widx)*2) % eeprom->page_size) == 0) {
5440 e1000_standby_eeprom(hw);
5446 return E1000_SUCCESS;
5449 /******************************************************************************
5450 * Writes a 16 bit word to a given offset in a Microwire EEPROM.
5452 * hw - Struct containing variables accessed by shared code
5453 * offset - offset within the EEPROM to be written to
5454 * words - number of words to write
5455 * data - pointer to array of 16 bit words to be written to the EEPROM
5457 *****************************************************************************/
5459 e1000_write_eeprom_microwire(struct e1000_hw *hw,
5464 struct e1000_eeprom_info *eeprom = &hw->eeprom;
5466 uint16_t words_written = 0;
5469 DEBUGFUNC("e1000_write_eeprom_microwire");
5471 /* Send the write enable command to the EEPROM (3-bit opcode plus
5472 * 6/8-bit dummy address beginning with 11). It's less work to include
5473 * the 11 of the dummy address as part of the opcode than it is to shift
5474 * it over the correct number of bits for the address. This puts the
5475 * EEPROM into write/erase mode.
5477 e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE,
5478 (uint16_t)(eeprom->opcode_bits + 2));
5480 e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
5482 /* Prepare the EEPROM */
5483 e1000_standby_eeprom(hw);
5485 while (words_written < words) {
5486 /* Send the Write command (3-bit opcode + addr) */
5487 e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE,
5488 eeprom->opcode_bits);
5490 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + words_written),
5491 eeprom->address_bits);
5494 e1000_shift_out_ee_bits(hw, data[words_written], 16);
5496 /* Toggle the CS line. This in effect tells the EEPROM to execute
5497 * the previous command.
5499 e1000_standby_eeprom(hw);
5501 /* Read DO repeatedly until it is high (equal to '1'). The EEPROM will
5502 * signal that the command has been completed by raising the DO signal.
5503 * If DO does not go high in 10 milliseconds, then error out.
5505 for (i = 0; i < 200; i++) {
5506 eecd = E1000_READ_REG(hw, EECD);
5507 if (eecd & E1000_EECD_DO) break;
5511 DEBUGOUT("EEPROM Write did not complete\n");
5512 return -E1000_ERR_EEPROM;
5515 /* Recover from write */
5516 e1000_standby_eeprom(hw);
5521 /* Send the write disable command to the EEPROM (3-bit opcode plus
5522 * 6/8-bit dummy address beginning with 10). It's less work to include
5523 * the 10 of the dummy address as part of the opcode than it is to shift
5524 * it over the correct number of bits for the address. This takes the
5525 * EEPROM out of write/erase mode.
5527 e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE,
5528 (uint16_t)(eeprom->opcode_bits + 2));
5530 e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
5532 return E1000_SUCCESS;
5535 /******************************************************************************
5536 * Flushes the cached eeprom to NVM. This is done by saving the modified values
5537 * in the eeprom cache and the non modified values in the currently active bank
5540 * hw - Struct containing variables accessed by shared code
5541 * offset - offset of word in the EEPROM to read
5542 * data - word read from the EEPROM
5543 * words - number of words to read
5544 *****************************************************************************/
5546 e1000_commit_shadow_ram(struct e1000_hw *hw)
5548 uint32_t attempts = 100000;
5552 int32_t error = E1000_SUCCESS;
5553 uint32_t old_bank_offset = 0;
5554 uint32_t new_bank_offset = 0;
5555 uint8_t low_byte = 0;
5556 uint8_t high_byte = 0;
5557 boolean_t sector_write_failed = FALSE;
5559 if (hw->mac_type == e1000_82573) {
5560 /* The flop register will be used to determine if flash type is STM */
5561 flop = E1000_READ_REG(hw, FLOP);
5562 for (i=0; i < attempts; i++) {
5563 eecd = E1000_READ_REG(hw, EECD);
5564 if ((eecd & E1000_EECD_FLUPD) == 0) {
5570 if (i == attempts) {
5571 return -E1000_ERR_EEPROM;
5574 /* If STM opcode located in bits 15:8 of flop, reset firmware */
5575 if ((flop & 0xFF00) == E1000_STM_OPCODE) {
5576 E1000_WRITE_REG(hw, HICR, E1000_HICR_FW_RESET);
5579 /* Perform the flash update */
5580 E1000_WRITE_REG(hw, EECD, eecd | E1000_EECD_FLUPD);
5582 for (i=0; i < attempts; i++) {
5583 eecd = E1000_READ_REG(hw, EECD);
5584 if ((eecd & E1000_EECD_FLUPD) == 0) {
5590 if (i == attempts) {
5591 return -E1000_ERR_EEPROM;
5595 if (hw->mac_type == e1000_ich8lan && hw->eeprom_shadow_ram != NULL) {
5596 /* We're writing to the opposite bank so if we're on bank 1,
5597 * write to bank 0 etc. We also need to erase the segment that
5598 * is going to be written */
5599 if (!(E1000_READ_REG(hw, EECD) & E1000_EECD_SEC1VAL)) {
5600 new_bank_offset = hw->flash_bank_size * 2;
5601 old_bank_offset = 0;
5602 e1000_erase_ich8_4k_segment(hw, 1);
5604 old_bank_offset = hw->flash_bank_size * 2;
5605 new_bank_offset = 0;
5606 e1000_erase_ich8_4k_segment(hw, 0);
5609 sector_write_failed = FALSE;
5610 /* Loop for every byte in the shadow RAM,
5611 * which is in units of words. */
5612 for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
5613 /* Determine whether to write the value stored
5614 * in the other NVM bank or a modified value stored
5615 * in the shadow RAM */
5616 if (hw->eeprom_shadow_ram[i].modified == TRUE) {
5617 low_byte = (uint8_t)hw->eeprom_shadow_ram[i].eeprom_word;
5619 error = e1000_verify_write_ich8_byte(hw,
5620 (i << 1) + new_bank_offset, low_byte);
5622 if (error != E1000_SUCCESS)
5623 sector_write_failed = TRUE;
5626 (uint8_t)(hw->eeprom_shadow_ram[i].eeprom_word >> 8);
5630 e1000_read_ich8_byte(hw, (i << 1) + old_bank_offset,
5633 error = e1000_verify_write_ich8_byte(hw,
5634 (i << 1) + new_bank_offset, low_byte);
5636 if (error != E1000_SUCCESS)
5637 sector_write_failed = TRUE;
5639 e1000_read_ich8_byte(hw, (i << 1) + old_bank_offset + 1,
5645 /* If the write of the low byte was successful, go ahread and
5646 * write the high byte while checking to make sure that if it
5647 * is the signature byte, then it is handled properly */
5648 if (sector_write_failed == FALSE) {
5649 /* If the word is 0x13, then make sure the signature bits
5650 * (15:14) are 11b until the commit has completed.
5651 * This will allow us to write 10b which indicates the
5652 * signature is valid. We want to do this after the write
5653 * has completed so that we don't mark the segment valid
5654 * while the write is still in progress */
5655 if (i == E1000_ICH_NVM_SIG_WORD)
5656 high_byte = E1000_ICH_NVM_SIG_MASK | high_byte;
5658 error = e1000_verify_write_ich8_byte(hw,
5659 (i << 1) + new_bank_offset + 1, high_byte);
5660 if (error != E1000_SUCCESS)
5661 sector_write_failed = TRUE;
5664 /* If the write failed then break from the loop and
5665 * return an error */
5670 /* Don't bother writing the segment valid bits if sector
5671 * programming failed. */
5672 if (sector_write_failed == FALSE) {
5673 /* Finally validate the new segment by setting bit 15:14
5674 * to 10b in word 0x13 , this can be done without an
5675 * erase as well since these bits are 11 to start with
5676 * and we need to change bit 14 to 0b */
5677 e1000_read_ich8_byte(hw,
5678 E1000_ICH_NVM_SIG_WORD * 2 + 1 + new_bank_offset,
5681 error = e1000_verify_write_ich8_byte(hw,
5682 E1000_ICH_NVM_SIG_WORD * 2 + 1 + new_bank_offset, high_byte);
5683 /* And invalidate the previously valid segment by setting
5684 * its signature word (0x13) high_byte to 0b. This can be
5685 * done without an erase because flash erase sets all bits
5686 * to 1's. We can write 1's to 0's without an erase */
5687 if (error == E1000_SUCCESS) {
5688 error = e1000_verify_write_ich8_byte(hw,
5689 E1000_ICH_NVM_SIG_WORD * 2 + 1 + old_bank_offset, 0);
5692 /* Clear the now not used entry in the cache */
5693 for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
5694 hw->eeprom_shadow_ram[i].modified = FALSE;
5695 hw->eeprom_shadow_ram[i].eeprom_word = 0xFFFF;
5703 /******************************************************************************
5704 * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
5705 * second function of dual function devices
5707 * hw - Struct containing variables accessed by shared code
5708 *****************************************************************************/
5710 e1000_read_mac_addr(struct e1000_hw * hw)
5713 uint16_t eeprom_data, i;
5715 DEBUGFUNC("e1000_read_mac_addr");
5717 for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
5719 if (e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
5720 DEBUGOUT("EEPROM Read Error\n");
5721 return -E1000_ERR_EEPROM;
5723 hw->perm_mac_addr[i] = (uint8_t) (eeprom_data & 0x00FF);
5724 hw->perm_mac_addr[i+1] = (uint8_t) (eeprom_data >> 8);
5727 switch (hw->mac_type) {
5731 case e1000_82546_rev_3:
5733 case e1000_80003es2lan:
5734 if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
5735 hw->perm_mac_addr[5] ^= 0x01;
5739 for (i = 0; i < NODE_ADDRESS_SIZE; i++)
5740 hw->mac_addr[i] = hw->perm_mac_addr[i];
5741 return E1000_SUCCESS;
5744 /******************************************************************************
5745 * Initializes receive address filters.
5747 * hw - Struct containing variables accessed by shared code
5749 * Places the MAC address in receive address register 0 and clears the rest
5750 * of the receive addresss registers. Clears the multicast table. Assumes
5751 * the receiver is in reset when the routine is called.
5752 *****************************************************************************/
5754 e1000_init_rx_addrs(struct e1000_hw *hw)
5759 DEBUGFUNC("e1000_init_rx_addrs");
5761 /* Setup the receive address. */
5762 DEBUGOUT("Programming MAC Address into RAR[0]\n");
5764 e1000_rar_set(hw, hw->mac_addr, 0);
5766 rar_num = E1000_RAR_ENTRIES;
5768 /* Reserve a spot for the Locally Administered Address to work around
5769 * an 82571 issue in which a reset on one port will reload the MAC on
5770 * the other port. */
5771 if ((hw->mac_type == e1000_82571) && (hw->laa_is_present == TRUE))
5773 if (hw->mac_type == e1000_ich8lan)
5774 rar_num = E1000_RAR_ENTRIES_ICH8LAN;
5776 /* Zero out the other 15 receive addresses. */
5777 DEBUGOUT("Clearing RAR[1-15]\n");
5778 for (i = 1; i < rar_num; i++) {
5779 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
5780 E1000_WRITE_FLUSH(hw);
5781 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
5782 E1000_WRITE_FLUSH(hw);
5786 /******************************************************************************
5787 * Hashes an address to determine its location in the multicast table
5789 * hw - Struct containing variables accessed by shared code
5790 * mc_addr - the multicast address to hash
5791 *****************************************************************************/
5793 e1000_hash_mc_addr(struct e1000_hw *hw,
5796 uint32_t hash_value = 0;
5798 /* The portion of the address that is used for the hash table is
5799 * determined by the mc_filter_type setting.
5801 switch (hw->mc_filter_type) {
5802 /* [0] [1] [2] [3] [4] [5]
5807 if (hw->mac_type == e1000_ich8lan) {
5808 /* [47:38] i.e. 0x158 for above example address */
5809 hash_value = ((mc_addr[4] >> 6) | (((uint16_t) mc_addr[5]) << 2));
5811 /* [47:36] i.e. 0x563 for above example address */
5812 hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4));
5816 if (hw->mac_type == e1000_ich8lan) {
5817 /* [46:37] i.e. 0x2B1 for above example address */
5818 hash_value = ((mc_addr[4] >> 5) | (((uint16_t) mc_addr[5]) << 3));
5820 /* [46:35] i.e. 0xAC6 for above example address */
5821 hash_value = ((mc_addr[4] >> 3) | (((uint16_t) mc_addr[5]) << 5));
5825 if (hw->mac_type == e1000_ich8lan) {
5826 /*[45:36] i.e. 0x163 for above example address */
5827 hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4));
5829 /* [45:34] i.e. 0x5D8 for above example address */
5830 hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6));
5834 if (hw->mac_type == e1000_ich8lan) {
5835 /* [43:34] i.e. 0x18D for above example address */
5836 hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6));
5838 /* [43:32] i.e. 0x634 for above example address */
5839 hash_value = ((mc_addr[4]) | (((uint16_t) mc_addr[5]) << 8));
5844 hash_value &= 0xFFF;
5845 if (hw->mac_type == e1000_ich8lan)
5846 hash_value &= 0x3FF;
5851 /******************************************************************************
5852 * Sets the bit in the multicast table corresponding to the hash value.
5854 * hw - Struct containing variables accessed by shared code
5855 * hash_value - Multicast address hash value
5856 *****************************************************************************/
5858 e1000_mta_set(struct e1000_hw *hw,
5859 uint32_t hash_value)
5861 uint32_t hash_bit, hash_reg;
5865 /* The MTA is a register array of 128 32-bit registers.
5866 * It is treated like an array of 4096 bits. We want to set
5867 * bit BitArray[hash_value]. So we figure out what register
5868 * the bit is in, read it, OR in the new bit, then write
5869 * back the new value. The register is determined by the
5870 * upper 7 bits of the hash value and the bit within that
5871 * register are determined by the lower 5 bits of the value.
5873 hash_reg = (hash_value >> 5) & 0x7F;
5874 if (hw->mac_type == e1000_ich8lan)
5877 hash_bit = hash_value & 0x1F;
5879 mta = E1000_READ_REG_ARRAY(hw, MTA, hash_reg);
5881 mta |= (1 << hash_bit);
5883 /* If we are on an 82544 and we are trying to write an odd offset
5884 * in the MTA, save off the previous entry before writing and
5885 * restore the old value after writing.
5887 if ((hw->mac_type == e1000_82544) && ((hash_reg & 0x1) == 1)) {
5888 temp = E1000_READ_REG_ARRAY(hw, MTA, (hash_reg - 1));
5889 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
5890 E1000_WRITE_FLUSH(hw);
5891 E1000_WRITE_REG_ARRAY(hw, MTA, (hash_reg - 1), temp);
5892 E1000_WRITE_FLUSH(hw);
5894 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
5895 E1000_WRITE_FLUSH(hw);
5899 /******************************************************************************
5900 * Puts an ethernet address into a receive address register.
5902 * hw - Struct containing variables accessed by shared code
5903 * addr - Address to put into receive address register
5904 * index - Receive address register to write
5905 *****************************************************************************/
5907 e1000_rar_set(struct e1000_hw *hw,
5911 uint32_t rar_low, rar_high;
5913 /* HW expects these in little endian so we reverse the byte order
5914 * from network order (big endian) to little endian
5916 rar_low = ((uint32_t) addr[0] |
5917 ((uint32_t) addr[1] << 8) |
5918 ((uint32_t) addr[2] << 16) | ((uint32_t) addr[3] << 24));
5919 rar_high = ((uint32_t) addr[4] | ((uint32_t) addr[5] << 8));
5921 /* Disable Rx and flush all Rx frames before enabling RSS to avoid Rx
5925 * If there are any Rx frames queued up or otherwise present in the HW
5926 * before RSS is enabled, and then we enable RSS, the HW Rx unit will
5927 * hang. To work around this issue, we have to disable receives and
5928 * flush out all Rx frames before we enable RSS. To do so, we modify we
5929 * redirect all Rx traffic to manageability and then reset the HW.
5930 * This flushes away Rx frames, and (since the redirections to
5931 * manageability persists across resets) keeps new ones from coming in
5932 * while we work. Then, we clear the Address Valid AV bit for all MAC
5933 * addresses and undo the re-direction to manageability.
5934 * Now, frames are coming in again, but the MAC won't accept them, so
5935 * far so good. We now proceed to initialize RSS (if necessary) and
5936 * configure the Rx unit. Last, we re-enable the AV bits and continue
5939 switch (hw->mac_type) {
5942 case e1000_80003es2lan:
5943 if (hw->leave_av_bit_off == TRUE)
5946 /* Indicate to hardware the Address is Valid. */
5947 rar_high |= E1000_RAH_AV;
5951 E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
5952 E1000_WRITE_FLUSH(hw);
5953 E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
5954 E1000_WRITE_FLUSH(hw);
5957 /******************************************************************************
5958 * Writes a value to the specified offset in the VLAN filter table.
5960 * hw - Struct containing variables accessed by shared code
5961 * offset - Offset in VLAN filer table to write
5962 * value - Value to write into VLAN filter table
5963 *****************************************************************************/
5965 e1000_write_vfta(struct e1000_hw *hw,
5971 if (hw->mac_type == e1000_ich8lan)
5974 if ((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) {
5975 temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1));
5976 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
5977 E1000_WRITE_FLUSH(hw);
5978 E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp);
5979 E1000_WRITE_FLUSH(hw);
5981 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
5982 E1000_WRITE_FLUSH(hw);
5986 /******************************************************************************
5987 * Clears the VLAN filer table
5989 * hw - Struct containing variables accessed by shared code
5990 *****************************************************************************/
5992 e1000_clear_vfta(struct e1000_hw *hw)
5995 uint32_t vfta_value = 0;
5996 uint32_t vfta_offset = 0;
5997 uint32_t vfta_bit_in_reg = 0;
5999 if (hw->mac_type == e1000_ich8lan)
6002 if (hw->mac_type == e1000_82573) {
6003 if (hw->mng_cookie.vlan_id != 0) {
6004 /* The VFTA is a 4096b bit-field, each identifying a single VLAN
6005 * ID. The following operations determine which 32b entry
6006 * (i.e. offset) into the array we want to set the VLAN ID
6007 * (i.e. bit) of the manageability unit. */
6008 vfta_offset = (hw->mng_cookie.vlan_id >>
6009 E1000_VFTA_ENTRY_SHIFT) &
6010 E1000_VFTA_ENTRY_MASK;
6011 vfta_bit_in_reg = 1 << (hw->mng_cookie.vlan_id &
6012 E1000_VFTA_ENTRY_BIT_SHIFT_MASK);
6015 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
6016 /* If the offset we want to clear is the same offset of the
6017 * manageability VLAN ID, then clear all bits except that of the
6018 * manageability unit */
6019 vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0;
6020 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, vfta_value);
6021 E1000_WRITE_FLUSH(hw);
6026 e1000_id_led_init(struct e1000_hw * hw)
6029 const uint32_t ledctl_mask = 0x000000FF;
6030 const uint32_t ledctl_on = E1000_LEDCTL_MODE_LED_ON;
6031 const uint32_t ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
6032 uint16_t eeprom_data, i, temp;
6033 const uint16_t led_mask = 0x0F;
6035 DEBUGFUNC("e1000_id_led_init");
6037 if (hw->mac_type < e1000_82540) {
6039 return E1000_SUCCESS;
6042 ledctl = E1000_READ_REG(hw, LEDCTL);
6043 hw->ledctl_default = ledctl;
6044 hw->ledctl_mode1 = hw->ledctl_default;
6045 hw->ledctl_mode2 = hw->ledctl_default;
6047 if (e1000_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, 1, &eeprom_data) < 0) {
6048 DEBUGOUT("EEPROM Read Error\n");
6049 return -E1000_ERR_EEPROM;
6052 if ((hw->mac_type == e1000_82573) &&
6053 (eeprom_data == ID_LED_RESERVED_82573))
6054 eeprom_data = ID_LED_DEFAULT_82573;
6055 else if ((eeprom_data == ID_LED_RESERVED_0000) ||
6056 (eeprom_data == ID_LED_RESERVED_FFFF)) {
6057 if (hw->mac_type == e1000_ich8lan)
6058 eeprom_data = ID_LED_DEFAULT_ICH8LAN;
6060 eeprom_data = ID_LED_DEFAULT;
6063 for (i = 0; i < 4; i++) {
6064 temp = (eeprom_data >> (i << 2)) & led_mask;
6066 case ID_LED_ON1_DEF2:
6067 case ID_LED_ON1_ON2:
6068 case ID_LED_ON1_OFF2:
6069 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
6070 hw->ledctl_mode1 |= ledctl_on << (i << 3);
6072 case ID_LED_OFF1_DEF2:
6073 case ID_LED_OFF1_ON2:
6074 case ID_LED_OFF1_OFF2:
6075 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
6076 hw->ledctl_mode1 |= ledctl_off << (i << 3);
6083 case ID_LED_DEF1_ON2:
6084 case ID_LED_ON1_ON2:
6085 case ID_LED_OFF1_ON2:
6086 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
6087 hw->ledctl_mode2 |= ledctl_on << (i << 3);
6089 case ID_LED_DEF1_OFF2:
6090 case ID_LED_ON1_OFF2:
6091 case ID_LED_OFF1_OFF2:
6092 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
6093 hw->ledctl_mode2 |= ledctl_off << (i << 3);
6100 return E1000_SUCCESS;
6103 /******************************************************************************
6104 * Prepares SW controlable LED for use and saves the current state of the LED.
6106 * hw - Struct containing variables accessed by shared code
6107 *****************************************************************************/
6109 e1000_setup_led(struct e1000_hw *hw)
6112 int32_t ret_val = E1000_SUCCESS;
6114 DEBUGFUNC("e1000_setup_led");
6116 switch (hw->mac_type) {
6117 case e1000_82542_rev2_0:
6118 case e1000_82542_rev2_1:
6121 /* No setup necessary */
6125 case e1000_82541_rev_2:
6126 case e1000_82547_rev_2:
6127 /* Turn off PHY Smart Power Down (if enabled) */
6128 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
6129 &hw->phy_spd_default);
6132 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
6133 (uint16_t)(hw->phy_spd_default &
6134 ~IGP01E1000_GMII_SPD));
6139 if (hw->media_type == e1000_media_type_fiber) {
6140 ledctl = E1000_READ_REG(hw, LEDCTL);
6141 /* Save current LEDCTL settings */
6142 hw->ledctl_default = ledctl;
6144 ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
6145 E1000_LEDCTL_LED0_BLINK |
6146 E1000_LEDCTL_LED0_MODE_MASK);
6147 ledctl |= (E1000_LEDCTL_MODE_LED_OFF <<
6148 E1000_LEDCTL_LED0_MODE_SHIFT);
6149 E1000_WRITE_REG(hw, LEDCTL, ledctl);
6150 } else if (hw->media_type == e1000_media_type_copper)
6151 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
6155 return E1000_SUCCESS;
6159 /******************************************************************************
6160 * Used on 82571 and later Si that has LED blink bits.
6161 * Callers must use their own timer and should have already called
6162 * e1000_id_led_init()
6163 * Call e1000_cleanup led() to stop blinking
6165 * hw - Struct containing variables accessed by shared code
6166 *****************************************************************************/
6168 e1000_blink_led_start(struct e1000_hw *hw)
6171 uint32_t ledctl_blink = 0;
6173 DEBUGFUNC("e1000_id_led_blink_on");
6175 if (hw->mac_type < e1000_82571) {
6177 return E1000_SUCCESS;
6179 if (hw->media_type == e1000_media_type_fiber) {
6180 /* always blink LED0 for PCI-E fiber */
6181 ledctl_blink = E1000_LEDCTL_LED0_BLINK |
6182 (E1000_LEDCTL_MODE_LED_ON << E1000_LEDCTL_LED0_MODE_SHIFT);
6184 /* set the blink bit for each LED that's "on" (0x0E) in ledctl_mode2 */
6185 ledctl_blink = hw->ledctl_mode2;
6186 for (i=0; i < 4; i++)
6187 if (((hw->ledctl_mode2 >> (i * 8)) & 0xFF) ==
6188 E1000_LEDCTL_MODE_LED_ON)
6189 ledctl_blink |= (E1000_LEDCTL_LED0_BLINK << (i * 8));
6192 E1000_WRITE_REG(hw, LEDCTL, ledctl_blink);
6194 return E1000_SUCCESS;
6197 /******************************************************************************
6198 * Restores the saved state of the SW controlable LED.
6200 * hw - Struct containing variables accessed by shared code
6201 *****************************************************************************/
6203 e1000_cleanup_led(struct e1000_hw *hw)
6205 int32_t ret_val = E1000_SUCCESS;
6207 DEBUGFUNC("e1000_cleanup_led");
6209 switch (hw->mac_type) {
6210 case e1000_82542_rev2_0:
6211 case e1000_82542_rev2_1:
6214 /* No cleanup necessary */
6218 case e1000_82541_rev_2:
6219 case e1000_82547_rev_2:
6220 /* Turn on PHY Smart Power Down (if previously enabled) */
6221 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
6222 hw->phy_spd_default);
6227 if (hw->phy_type == e1000_phy_ife) {
6228 e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
6231 /* Restore LEDCTL settings */
6232 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_default);
6236 return E1000_SUCCESS;
6239 /******************************************************************************
6240 * Turns on the software controllable LED
6242 * hw - Struct containing variables accessed by shared code
6243 *****************************************************************************/
6245 e1000_led_on(struct e1000_hw *hw)
6247 uint32_t ctrl = E1000_READ_REG(hw, CTRL);
6249 DEBUGFUNC("e1000_led_on");
6251 switch (hw->mac_type) {
6252 case e1000_82542_rev2_0:
6253 case e1000_82542_rev2_1:
6255 /* Set SW Defineable Pin 0 to turn on the LED */
6256 ctrl |= E1000_CTRL_SWDPIN0;
6257 ctrl |= E1000_CTRL_SWDPIO0;
6260 if (hw->media_type == e1000_media_type_fiber) {
6261 /* Set SW Defineable Pin 0 to turn on the LED */
6262 ctrl |= E1000_CTRL_SWDPIN0;
6263 ctrl |= E1000_CTRL_SWDPIO0;
6265 /* Clear SW Defineable Pin 0 to turn on the LED */
6266 ctrl &= ~E1000_CTRL_SWDPIN0;
6267 ctrl |= E1000_CTRL_SWDPIO0;
6271 if (hw->media_type == e1000_media_type_fiber) {
6272 /* Clear SW Defineable Pin 0 to turn on the LED */
6273 ctrl &= ~E1000_CTRL_SWDPIN0;
6274 ctrl |= E1000_CTRL_SWDPIO0;
6275 } else if (hw->phy_type == e1000_phy_ife) {
6276 e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED,
6277 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_ON));
6278 } else if (hw->media_type == e1000_media_type_copper) {
6279 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode2);
6280 return E1000_SUCCESS;
6285 E1000_WRITE_REG(hw, CTRL, ctrl);
6287 return E1000_SUCCESS;
6290 /******************************************************************************
6291 * Turns off the software controllable LED
6293 * hw - Struct containing variables accessed by shared code
6294 *****************************************************************************/
6296 e1000_led_off(struct e1000_hw *hw)
6298 uint32_t ctrl = E1000_READ_REG(hw, CTRL);
6300 DEBUGFUNC("e1000_led_off");
6302 switch (hw->mac_type) {
6303 case e1000_82542_rev2_0:
6304 case e1000_82542_rev2_1:
6306 /* Clear SW Defineable Pin 0 to turn off the LED */
6307 ctrl &= ~E1000_CTRL_SWDPIN0;
6308 ctrl |= E1000_CTRL_SWDPIO0;
6311 if (hw->media_type == e1000_media_type_fiber) {
6312 /* Clear SW Defineable Pin 0 to turn off the LED */
6313 ctrl &= ~E1000_CTRL_SWDPIN0;
6314 ctrl |= E1000_CTRL_SWDPIO0;
6316 /* Set SW Defineable Pin 0 to turn off the LED */
6317 ctrl |= E1000_CTRL_SWDPIN0;
6318 ctrl |= E1000_CTRL_SWDPIO0;
6322 if (hw->media_type == e1000_media_type_fiber) {
6323 /* Set SW Defineable Pin 0 to turn off the LED */
6324 ctrl |= E1000_CTRL_SWDPIN0;
6325 ctrl |= E1000_CTRL_SWDPIO0;
6326 } else if (hw->phy_type == e1000_phy_ife) {
6327 e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED,
6328 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_OFF));
6329 } else if (hw->media_type == e1000_media_type_copper) {
6330 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
6331 return E1000_SUCCESS;
6336 E1000_WRITE_REG(hw, CTRL, ctrl);
6338 return E1000_SUCCESS;
6341 /******************************************************************************
6342 * Clears all hardware statistics counters.
6344 * hw - Struct containing variables accessed by shared code
6345 *****************************************************************************/
6347 e1000_clear_hw_cntrs(struct e1000_hw *hw)
6349 volatile uint32_t temp;
6351 temp = E1000_READ_REG(hw, CRCERRS);
6352 temp = E1000_READ_REG(hw, SYMERRS);
6353 temp = E1000_READ_REG(hw, MPC);
6354 temp = E1000_READ_REG(hw, SCC);
6355 temp = E1000_READ_REG(hw, ECOL);
6356 temp = E1000_READ_REG(hw, MCC);
6357 temp = E1000_READ_REG(hw, LATECOL);
6358 temp = E1000_READ_REG(hw, COLC);
6359 temp = E1000_READ_REG(hw, DC);
6360 temp = E1000_READ_REG(hw, SEC);
6361 temp = E1000_READ_REG(hw, RLEC);
6362 temp = E1000_READ_REG(hw, XONRXC);
6363 temp = E1000_READ_REG(hw, XONTXC);
6364 temp = E1000_READ_REG(hw, XOFFRXC);
6365 temp = E1000_READ_REG(hw, XOFFTXC);
6366 temp = E1000_READ_REG(hw, FCRUC);
6368 if (hw->mac_type != e1000_ich8lan) {
6369 temp = E1000_READ_REG(hw, PRC64);
6370 temp = E1000_READ_REG(hw, PRC127);
6371 temp = E1000_READ_REG(hw, PRC255);
6372 temp = E1000_READ_REG(hw, PRC511);
6373 temp = E1000_READ_REG(hw, PRC1023);
6374 temp = E1000_READ_REG(hw, PRC1522);
6377 temp = E1000_READ_REG(hw, GPRC);
6378 temp = E1000_READ_REG(hw, BPRC);
6379 temp = E1000_READ_REG(hw, MPRC);
6380 temp = E1000_READ_REG(hw, GPTC);
6381 temp = E1000_READ_REG(hw, GORCL);
6382 temp = E1000_READ_REG(hw, GORCH);
6383 temp = E1000_READ_REG(hw, GOTCL);
6384 temp = E1000_READ_REG(hw, GOTCH);
6385 temp = E1000_READ_REG(hw, RNBC);
6386 temp = E1000_READ_REG(hw, RUC);
6387 temp = E1000_READ_REG(hw, RFC);
6388 temp = E1000_READ_REG(hw, ROC);
6389 temp = E1000_READ_REG(hw, RJC);
6390 temp = E1000_READ_REG(hw, TORL);
6391 temp = E1000_READ_REG(hw, TORH);
6392 temp = E1000_READ_REG(hw, TOTL);
6393 temp = E1000_READ_REG(hw, TOTH);
6394 temp = E1000_READ_REG(hw, TPR);
6395 temp = E1000_READ_REG(hw, TPT);
6397 if (hw->mac_type != e1000_ich8lan) {
6398 temp = E1000_READ_REG(hw, PTC64);
6399 temp = E1000_READ_REG(hw, PTC127);
6400 temp = E1000_READ_REG(hw, PTC255);
6401 temp = E1000_READ_REG(hw, PTC511);
6402 temp = E1000_READ_REG(hw, PTC1023);
6403 temp = E1000_READ_REG(hw, PTC1522);
6406 temp = E1000_READ_REG(hw, MPTC);
6407 temp = E1000_READ_REG(hw, BPTC);
6409 if (hw->mac_type < e1000_82543) return;
6411 temp = E1000_READ_REG(hw, ALGNERRC);
6412 temp = E1000_READ_REG(hw, RXERRC);
6413 temp = E1000_READ_REG(hw, TNCRS);
6414 temp = E1000_READ_REG(hw, CEXTERR);
6415 temp = E1000_READ_REG(hw, TSCTC);
6416 temp = E1000_READ_REG(hw, TSCTFC);
6418 if (hw->mac_type <= e1000_82544) return;
6420 temp = E1000_READ_REG(hw, MGTPRC);
6421 temp = E1000_READ_REG(hw, MGTPDC);
6422 temp = E1000_READ_REG(hw, MGTPTC);
6424 if (hw->mac_type <= e1000_82547_rev_2) return;
6426 temp = E1000_READ_REG(hw, IAC);
6427 temp = E1000_READ_REG(hw, ICRXOC);
6429 if (hw->mac_type == e1000_ich8lan) return;
6431 temp = E1000_READ_REG(hw, ICRXPTC);
6432 temp = E1000_READ_REG(hw, ICRXATC);
6433 temp = E1000_READ_REG(hw, ICTXPTC);
6434 temp = E1000_READ_REG(hw, ICTXATC);
6435 temp = E1000_READ_REG(hw, ICTXQEC);
6436 temp = E1000_READ_REG(hw, ICTXQMTC);
6437 temp = E1000_READ_REG(hw, ICRXDMTC);
6440 /******************************************************************************
6441 * Resets Adaptive IFS to its default state.
6443 * hw - Struct containing variables accessed by shared code
6445 * Call this after e1000_init_hw. You may override the IFS defaults by setting
6446 * hw->ifs_params_forced to TRUE. However, you must initialize hw->
6447 * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio
6448 * before calling this function.
6449 *****************************************************************************/
6451 e1000_reset_adaptive(struct e1000_hw *hw)
6453 DEBUGFUNC("e1000_reset_adaptive");
6455 if (hw->adaptive_ifs) {
6456 if (!hw->ifs_params_forced) {
6457 hw->current_ifs_val = 0;
6458 hw->ifs_min_val = IFS_MIN;
6459 hw->ifs_max_val = IFS_MAX;
6460 hw->ifs_step_size = IFS_STEP;
6461 hw->ifs_ratio = IFS_RATIO;
6463 hw->in_ifs_mode = FALSE;
6464 E1000_WRITE_REG(hw, AIT, 0);
6466 DEBUGOUT("Not in Adaptive IFS mode!\n");
6470 /******************************************************************************
6471 * Called during the callback/watchdog routine to update IFS value based on
6472 * the ratio of transmits to collisions.
6474 * hw - Struct containing variables accessed by shared code
6475 * tx_packets - Number of transmits since last callback
6476 * total_collisions - Number of collisions since last callback
6477 *****************************************************************************/
6479 e1000_update_adaptive(struct e1000_hw *hw)
6481 DEBUGFUNC("e1000_update_adaptive");
6483 if (hw->adaptive_ifs) {
6484 if ((hw->collision_delta * hw->ifs_ratio) > hw->tx_packet_delta) {
6485 if (hw->tx_packet_delta > MIN_NUM_XMITS) {
6486 hw->in_ifs_mode = TRUE;
6487 if (hw->current_ifs_val < hw->ifs_max_val) {
6488 if (hw->current_ifs_val == 0)
6489 hw->current_ifs_val = hw->ifs_min_val;
6491 hw->current_ifs_val += hw->ifs_step_size;
6492 E1000_WRITE_REG(hw, AIT, hw->current_ifs_val);
6496 if (hw->in_ifs_mode && (hw->tx_packet_delta <= MIN_NUM_XMITS)) {
6497 hw->current_ifs_val = 0;
6498 hw->in_ifs_mode = FALSE;
6499 E1000_WRITE_REG(hw, AIT, 0);
6503 DEBUGOUT("Not in Adaptive IFS mode!\n");
6507 /******************************************************************************
6508 * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT
6510 * hw - Struct containing variables accessed by shared code
6511 * frame_len - The length of the frame in question
6512 * mac_addr - The Ethernet destination address of the frame in question
6513 *****************************************************************************/
6515 e1000_tbi_adjust_stats(struct e1000_hw *hw,
6516 struct e1000_hw_stats *stats,
6522 /* First adjust the frame length. */
6524 /* We need to adjust the statistics counters, since the hardware
6525 * counters overcount this packet as a CRC error and undercount
6526 * the packet as a good packet
6528 /* This packet should not be counted as a CRC error. */
6530 /* This packet does count as a Good Packet Received. */
6533 /* Adjust the Good Octets received counters */
6534 carry_bit = 0x80000000 & stats->gorcl;
6535 stats->gorcl += frame_len;
6536 /* If the high bit of Gorcl (the low 32 bits of the Good Octets
6537 * Received Count) was one before the addition,
6538 * AND it is zero after, then we lost the carry out,
6539 * need to add one to Gorch (Good Octets Received Count High).
6540 * This could be simplified if all environments supported
6543 if (carry_bit && ((stats->gorcl & 0x80000000) == 0))
6545 /* Is this a broadcast or multicast? Check broadcast first,
6546 * since the test for a multicast frame will test positive on
6547 * a broadcast frame.
6549 if ((mac_addr[0] == (uint8_t) 0xff) && (mac_addr[1] == (uint8_t) 0xff))
6550 /* Broadcast packet */
6552 else if (*mac_addr & 0x01)
6553 /* Multicast packet */
6556 if (frame_len == hw->max_frame_size) {
6557 /* In this case, the hardware has overcounted the number of
6564 /* Adjust the bin counters when the extra byte put the frame in the
6565 * wrong bin. Remember that the frame_len was adjusted above.
6567 if (frame_len == 64) {
6570 } else if (frame_len == 127) {
6573 } else if (frame_len == 255) {
6576 } else if (frame_len == 511) {
6579 } else if (frame_len == 1023) {
6582 } else if (frame_len == 1522) {
6587 /******************************************************************************
6588 * Gets the current PCI bus type, speed, and width of the hardware
6590 * hw - Struct containing variables accessed by shared code
6591 *****************************************************************************/
6593 e1000_get_bus_info(struct e1000_hw *hw)
6596 uint16_t pci_ex_link_status;
6599 switch (hw->mac_type) {
6600 case e1000_82542_rev2_0:
6601 case e1000_82542_rev2_1:
6602 hw->bus_type = e1000_bus_type_pci;
6603 hw->bus_speed = e1000_bus_speed_unknown;
6604 hw->bus_width = e1000_bus_width_unknown;
6609 case e1000_80003es2lan:
6610 hw->bus_type = e1000_bus_type_pci_express;
6611 hw->bus_speed = e1000_bus_speed_2500;
6612 ret_val = e1000_read_pcie_cap_reg(hw,
6614 &pci_ex_link_status);
6616 hw->bus_width = e1000_bus_width_unknown;
6618 hw->bus_width = (pci_ex_link_status & PCI_EX_LINK_WIDTH_MASK) >>
6619 PCI_EX_LINK_WIDTH_SHIFT;
6622 hw->bus_type = e1000_bus_type_pci_express;
6623 hw->bus_speed = e1000_bus_speed_2500;
6624 hw->bus_width = e1000_bus_width_pciex_1;
6627 status = E1000_READ_REG(hw, STATUS);
6628 hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
6629 e1000_bus_type_pcix : e1000_bus_type_pci;
6631 if (hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) {
6632 hw->bus_speed = (hw->bus_type == e1000_bus_type_pci) ?
6633 e1000_bus_speed_66 : e1000_bus_speed_120;
6634 } else if (hw->bus_type == e1000_bus_type_pci) {
6635 hw->bus_speed = (status & E1000_STATUS_PCI66) ?
6636 e1000_bus_speed_66 : e1000_bus_speed_33;
6638 switch (status & E1000_STATUS_PCIX_SPEED) {
6639 case E1000_STATUS_PCIX_SPEED_66:
6640 hw->bus_speed = e1000_bus_speed_66;
6642 case E1000_STATUS_PCIX_SPEED_100:
6643 hw->bus_speed = e1000_bus_speed_100;
6645 case E1000_STATUS_PCIX_SPEED_133:
6646 hw->bus_speed = e1000_bus_speed_133;
6649 hw->bus_speed = e1000_bus_speed_reserved;
6653 hw->bus_width = (status & E1000_STATUS_BUS64) ?
6654 e1000_bus_width_64 : e1000_bus_width_32;
6659 /******************************************************************************
6660 * Writes a value to one of the devices registers using port I/O (as opposed to
6661 * memory mapped I/O). Only 82544 and newer devices support port I/O.
6663 * hw - Struct containing variables accessed by shared code
6664 * offset - offset to write to
6665 * value - value to write
6666 *****************************************************************************/
6668 e1000_write_reg_io(struct e1000_hw *hw,
6672 unsigned long io_addr = hw->io_base;
6673 unsigned long io_data = hw->io_base + 4;
6675 e1000_io_write(hw, io_addr, offset);
6676 e1000_io_write(hw, io_data, value);
6679 /******************************************************************************
6680 * Estimates the cable length.
6682 * hw - Struct containing variables accessed by shared code
6683 * min_length - The estimated minimum length
6684 * max_length - The estimated maximum length
6686 * returns: - E1000_ERR_XXX
6689 * This function always returns a ranged length (minimum & maximum).
6690 * So for M88 phy's, this function interprets the one value returned from the
6691 * register to the minimum and maximum range.
6692 * For IGP phy's, the function calculates the range by the AGC registers.
6693 *****************************************************************************/
6695 e1000_get_cable_length(struct e1000_hw *hw,
6696 uint16_t *min_length,
6697 uint16_t *max_length)
6700 uint16_t agc_value = 0;
6701 uint16_t i, phy_data;
6702 uint16_t cable_length;
6704 DEBUGFUNC("e1000_get_cable_length");
6706 *min_length = *max_length = 0;
6708 /* Use old method for Phy older than IGP */
6709 if (hw->phy_type == e1000_phy_m88) {
6711 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6715 cable_length = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
6716 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
6718 /* Convert the enum value to ranged values */
6719 switch (cable_length) {
6720 case e1000_cable_length_50:
6722 *max_length = e1000_igp_cable_length_50;
6724 case e1000_cable_length_50_80:
6725 *min_length = e1000_igp_cable_length_50;
6726 *max_length = e1000_igp_cable_length_80;
6728 case e1000_cable_length_80_110:
6729 *min_length = e1000_igp_cable_length_80;
6730 *max_length = e1000_igp_cable_length_110;
6732 case e1000_cable_length_110_140:
6733 *min_length = e1000_igp_cable_length_110;
6734 *max_length = e1000_igp_cable_length_140;
6736 case e1000_cable_length_140:
6737 *min_length = e1000_igp_cable_length_140;
6738 *max_length = e1000_igp_cable_length_170;
6741 return -E1000_ERR_PHY;
6744 } else if (hw->phy_type == e1000_phy_gg82563) {
6745 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_DSP_DISTANCE,
6749 cable_length = phy_data & GG82563_DSPD_CABLE_LENGTH;
6751 switch (cable_length) {
6752 case e1000_gg_cable_length_60:
6754 *max_length = e1000_igp_cable_length_60;
6756 case e1000_gg_cable_length_60_115:
6757 *min_length = e1000_igp_cable_length_60;
6758 *max_length = e1000_igp_cable_length_115;
6760 case e1000_gg_cable_length_115_150:
6761 *min_length = e1000_igp_cable_length_115;
6762 *max_length = e1000_igp_cable_length_150;
6764 case e1000_gg_cable_length_150:
6765 *min_length = e1000_igp_cable_length_150;
6766 *max_length = e1000_igp_cable_length_180;
6769 return -E1000_ERR_PHY;
6772 } else if (hw->phy_type == e1000_phy_igp) { /* For IGP PHY */
6773 uint16_t cur_agc_value;
6774 uint16_t min_agc_value = IGP01E1000_AGC_LENGTH_TABLE_SIZE;
6775 uint16_t agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
6776 {IGP01E1000_PHY_AGC_A,
6777 IGP01E1000_PHY_AGC_B,
6778 IGP01E1000_PHY_AGC_C,
6779 IGP01E1000_PHY_AGC_D};
6780 /* Read the AGC registers for all channels */
6781 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
6783 ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
6787 cur_agc_value = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT;
6789 /* Value bound check. */
6790 if ((cur_agc_value >= IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1) ||
6791 (cur_agc_value == 0))
6792 return -E1000_ERR_PHY;
6794 agc_value += cur_agc_value;
6796 /* Update minimal AGC value. */
6797 if (min_agc_value > cur_agc_value)
6798 min_agc_value = cur_agc_value;
6801 /* Remove the minimal AGC result for length < 50m */
6802 if (agc_value < IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) {
6803 agc_value -= min_agc_value;
6805 /* Get the average length of the remaining 3 channels */
6806 agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1);
6808 /* Get the average length of all the 4 channels. */
6809 agc_value /= IGP01E1000_PHY_CHANNEL_NUM;
6812 /* Set the range of the calculated length. */
6813 *min_length = ((e1000_igp_cable_length_table[agc_value] -
6814 IGP01E1000_AGC_RANGE) > 0) ?
6815 (e1000_igp_cable_length_table[agc_value] -
6816 IGP01E1000_AGC_RANGE) : 0;
6817 *max_length = e1000_igp_cable_length_table[agc_value] +
6818 IGP01E1000_AGC_RANGE;
6819 } else if (hw->phy_type == e1000_phy_igp_2 ||
6820 hw->phy_type == e1000_phy_igp_3) {
6821 uint16_t cur_agc_index, max_agc_index = 0;
6822 uint16_t min_agc_index = IGP02E1000_AGC_LENGTH_TABLE_SIZE - 1;
6823 uint16_t agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] =
6824 {IGP02E1000_PHY_AGC_A,
6825 IGP02E1000_PHY_AGC_B,
6826 IGP02E1000_PHY_AGC_C,
6827 IGP02E1000_PHY_AGC_D};
6828 /* Read the AGC registers for all channels */
6829 for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
6830 ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
6834 /* Getting bits 15:9, which represent the combination of course and
6835 * fine gain values. The result is a number that can be put into
6836 * the lookup table to obtain the approximate cable length. */
6837 cur_agc_index = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
6838 IGP02E1000_AGC_LENGTH_MASK;
6840 /* Array index bound check. */
6841 if ((cur_agc_index >= IGP02E1000_AGC_LENGTH_TABLE_SIZE) ||
6842 (cur_agc_index == 0))
6843 return -E1000_ERR_PHY;
6845 /* Remove min & max AGC values from calculation. */
6846 if (e1000_igp_2_cable_length_table[min_agc_index] >
6847 e1000_igp_2_cable_length_table[cur_agc_index])
6848 min_agc_index = cur_agc_index;
6849 if (e1000_igp_2_cable_length_table[max_agc_index] <
6850 e1000_igp_2_cable_length_table[cur_agc_index])
6851 max_agc_index = cur_agc_index;
6853 agc_value += e1000_igp_2_cable_length_table[cur_agc_index];
6856 agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] +
6857 e1000_igp_2_cable_length_table[max_agc_index]);
6858 agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
6860 /* Calculate cable length with the error range of +/- 10 meters. */
6861 *min_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
6862 (agc_value - IGP02E1000_AGC_RANGE) : 0;
6863 *max_length = agc_value + IGP02E1000_AGC_RANGE;
6866 return E1000_SUCCESS;
6869 /******************************************************************************
6870 * Check the cable polarity
6872 * hw - Struct containing variables accessed by shared code
6873 * polarity - output parameter : 0 - Polarity is not reversed
6874 * 1 - Polarity is reversed.
6876 * returns: - E1000_ERR_XXX
6879 * For phy's older then IGP, this function simply reads the polarity bit in the
6880 * Phy Status register. For IGP phy's, this bit is valid only if link speed is
6881 * 10 Mbps. If the link speed is 100 Mbps there is no polarity so this bit will
6882 * return 0. If the link speed is 1000 Mbps the polarity status is in the
6883 * IGP01E1000_PHY_PCS_INIT_REG.
6884 *****************************************************************************/
6886 e1000_check_polarity(struct e1000_hw *hw,
6887 e1000_rev_polarity *polarity)
6892 DEBUGFUNC("e1000_check_polarity");
6894 if ((hw->phy_type == e1000_phy_m88) ||
6895 (hw->phy_type == e1000_phy_gg82563)) {
6896 /* return the Polarity bit in the Status register. */
6897 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6901 *polarity = ((phy_data & M88E1000_PSSR_REV_POLARITY) >>
6902 M88E1000_PSSR_REV_POLARITY_SHIFT) ?
6903 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
6905 } else if (hw->phy_type == e1000_phy_igp ||
6906 hw->phy_type == e1000_phy_igp_3 ||
6907 hw->phy_type == e1000_phy_igp_2) {
6908 /* Read the Status register to check the speed */
6909 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
6914 /* If speed is 1000 Mbps, must read the IGP01E1000_PHY_PCS_INIT_REG to
6915 * find the polarity status */
6916 if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
6917 IGP01E1000_PSSR_SPEED_1000MBPS) {
6919 /* Read the GIG initialization PCS register (0x00B4) */
6920 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG,
6925 /* Check the polarity bits */
6926 *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ?
6927 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
6929 /* For 10 Mbps, read the polarity bit in the status register. (for
6930 * 100 Mbps this bit is always 0) */
6931 *polarity = (phy_data & IGP01E1000_PSSR_POLARITY_REVERSED) ?
6932 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
6934 } else if (hw->phy_type == e1000_phy_ife) {
6935 ret_val = e1000_read_phy_reg(hw, IFE_PHY_EXTENDED_STATUS_CONTROL,
6939 *polarity = ((phy_data & IFE_PESC_POLARITY_REVERSED) >>
6940 IFE_PESC_POLARITY_REVERSED_SHIFT) ?
6941 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
6943 return E1000_SUCCESS;
6946 /******************************************************************************
6947 * Check if Downshift occured
6949 * hw - Struct containing variables accessed by shared code
6950 * downshift - output parameter : 0 - No Downshift ocured.
6951 * 1 - Downshift ocured.
6953 * returns: - E1000_ERR_XXX
6956 * For phy's older then IGP, this function reads the Downshift bit in the Phy
6957 * Specific Status register. For IGP phy's, it reads the Downgrade bit in the
6958 * Link Health register. In IGP this bit is latched high, so the driver must
6959 * read it immediately after link is established.
6960 *****************************************************************************/
6962 e1000_check_downshift(struct e1000_hw *hw)
6967 DEBUGFUNC("e1000_check_downshift");
6969 if (hw->phy_type == e1000_phy_igp ||
6970 hw->phy_type == e1000_phy_igp_3 ||
6971 hw->phy_type == e1000_phy_igp_2) {
6972 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH,
6977 hw->speed_downgraded = (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0;
6978 } else if ((hw->phy_type == e1000_phy_m88) ||
6979 (hw->phy_type == e1000_phy_gg82563)) {
6980 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6985 hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >>
6986 M88E1000_PSSR_DOWNSHIFT_SHIFT;
6987 } else if (hw->phy_type == e1000_phy_ife) {
6988 /* e1000_phy_ife supports 10/100 speed only */
6989 hw->speed_downgraded = FALSE;
6992 return E1000_SUCCESS;
6995 /*****************************************************************************
6997 * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a
6998 * gigabit link is achieved to improve link quality.
7000 * hw: Struct containing variables accessed by shared code
7002 * returns: - E1000_ERR_PHY if fail to read/write the PHY
7003 * E1000_SUCCESS at any other case.
7005 ****************************************************************************/
7008 e1000_config_dsp_after_link_change(struct e1000_hw *hw,
7012 uint16_t phy_data, phy_saved_data, speed, duplex, i;
7013 uint16_t dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
7014 {IGP01E1000_PHY_AGC_PARAM_A,
7015 IGP01E1000_PHY_AGC_PARAM_B,
7016 IGP01E1000_PHY_AGC_PARAM_C,
7017 IGP01E1000_PHY_AGC_PARAM_D};
7018 uint16_t min_length, max_length;
7020 DEBUGFUNC("e1000_config_dsp_after_link_change");
7022 if (hw->phy_type != e1000_phy_igp)
7023 return E1000_SUCCESS;
7026 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
7028 DEBUGOUT("Error getting link speed and duplex\n");
7032 if (speed == SPEED_1000) {
7034 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
7038 if ((hw->dsp_config_state == e1000_dsp_config_enabled) &&
7039 min_length >= e1000_igp_cable_length_50) {
7041 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
7042 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i],
7047 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
7049 ret_val = e1000_write_phy_reg(hw, dsp_reg_array[i],
7054 hw->dsp_config_state = e1000_dsp_config_activated;
7057 if ((hw->ffe_config_state == e1000_ffe_config_enabled) &&
7058 (min_length < e1000_igp_cable_length_50)) {
7060 uint16_t ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_20;
7061 uint32_t idle_errs = 0;
7063 /* clear previous idle error counts */
7064 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
7069 for (i = 0; i < ffe_idle_err_timeout; i++) {
7071 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
7076 idle_errs += (phy_data & SR_1000T_IDLE_ERROR_CNT);
7077 if (idle_errs > SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT) {
7078 hw->ffe_config_state = e1000_ffe_config_active;
7080 ret_val = e1000_write_phy_reg(hw,
7081 IGP01E1000_PHY_DSP_FFE,
7082 IGP01E1000_PHY_DSP_FFE_CM_CP);
7089 ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_100;
7094 if (hw->dsp_config_state == e1000_dsp_config_activated) {
7095 /* Save off the current value of register 0x2F5B to be restored at
7096 * the end of the routines. */
7097 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
7102 /* Disable the PHY transmitter */
7103 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
7110 ret_val = e1000_write_phy_reg(hw, 0x0000,
7111 IGP01E1000_IEEE_FORCE_GIGA);
7114 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
7115 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i], &phy_data);
7119 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
7120 phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS;
7122 ret_val = e1000_write_phy_reg(hw,dsp_reg_array[i], phy_data);
7127 ret_val = e1000_write_phy_reg(hw, 0x0000,
7128 IGP01E1000_IEEE_RESTART_AUTONEG);
7134 /* Now enable the transmitter */
7135 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
7140 hw->dsp_config_state = e1000_dsp_config_enabled;
7143 if (hw->ffe_config_state == e1000_ffe_config_active) {
7144 /* Save off the current value of register 0x2F5B to be restored at
7145 * the end of the routines. */
7146 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
7151 /* Disable the PHY transmitter */
7152 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
7159 ret_val = e1000_write_phy_reg(hw, 0x0000,
7160 IGP01E1000_IEEE_FORCE_GIGA);
7163 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE,
7164 IGP01E1000_PHY_DSP_FFE_DEFAULT);
7168 ret_val = e1000_write_phy_reg(hw, 0x0000,
7169 IGP01E1000_IEEE_RESTART_AUTONEG);
7175 /* Now enable the transmitter */
7176 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
7181 hw->ffe_config_state = e1000_ffe_config_enabled;
7184 return E1000_SUCCESS;
7187 /*****************************************************************************
7188 * Set PHY to class A mode
7189 * Assumes the following operations will follow to enable the new class mode.
7190 * 1. Do a PHY soft reset
7191 * 2. Restart auto-negotiation or force link.
7193 * hw - Struct containing variables accessed by shared code
7194 ****************************************************************************/
7196 e1000_set_phy_mode(struct e1000_hw *hw)
7199 uint16_t eeprom_data;
7201 DEBUGFUNC("e1000_set_phy_mode");
7203 if ((hw->mac_type == e1000_82545_rev_3) &&
7204 (hw->media_type == e1000_media_type_copper)) {
7205 ret_val = e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, 1, &eeprom_data);
7210 if ((eeprom_data != EEPROM_RESERVED_WORD) &&
7211 (eeprom_data & EEPROM_PHY_CLASS_A)) {
7212 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x000B);
7215 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x8104);
7219 hw->phy_reset_disable = FALSE;
7223 return E1000_SUCCESS;
7226 /*****************************************************************************
7228 * This function sets the lplu state according to the active flag. When
7229 * activating lplu this function also disables smart speed and vise versa.
7230 * lplu will not be activated unless the device autonegotiation advertisment
7231 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
7232 * hw: Struct containing variables accessed by shared code
7233 * active - true to enable lplu false to disable lplu.
7235 * returns: - E1000_ERR_PHY if fail to read/write the PHY
7236 * E1000_SUCCESS at any other case.
7238 ****************************************************************************/
7241 e1000_set_d3_lplu_state(struct e1000_hw *hw,
7244 uint32_t phy_ctrl = 0;
7247 DEBUGFUNC("e1000_set_d3_lplu_state");
7249 if (hw->phy_type != e1000_phy_igp && hw->phy_type != e1000_phy_igp_2
7250 && hw->phy_type != e1000_phy_igp_3)
7251 return E1000_SUCCESS;
7253 /* During driver activity LPLU should not be used or it will attain link
7254 * from the lowest speeds starting from 10Mbps. The capability is used for
7255 * Dx transitions and states */
7256 if (hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2) {
7257 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data);
7260 } else if (hw->mac_type == e1000_ich8lan) {
7261 /* MAC writes into PHY register based on the state transition
7262 * and start auto-negotiation. SW driver can overwrite the settings
7263 * in CSR PHY power control E1000_PHY_CTRL register. */
7264 phy_ctrl = E1000_READ_REG(hw, PHY_CTRL);
7266 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
7272 if (hw->mac_type == e1000_82541_rev_2 ||
7273 hw->mac_type == e1000_82547_rev_2) {
7274 phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
7275 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
7279 if (hw->mac_type == e1000_ich8lan) {
7280 phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
7281 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7283 phy_data &= ~IGP02E1000_PM_D3_LPLU;
7284 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
7291 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
7292 * Dx states where the power conservation is most important. During
7293 * driver activity we should enable SmartSpeed, so performance is
7295 if (hw->smart_speed == e1000_smart_speed_on) {
7296 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7301 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
7302 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7306 } else if (hw->smart_speed == e1000_smart_speed_off) {
7307 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7312 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7313 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7319 } else if ((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT) ||
7320 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL ) ||
7321 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) {
7323 if (hw->mac_type == e1000_82541_rev_2 ||
7324 hw->mac_type == e1000_82547_rev_2) {
7325 phy_data |= IGP01E1000_GMII_FLEX_SPD;
7326 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
7330 if (hw->mac_type == e1000_ich8lan) {
7331 phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
7332 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7334 phy_data |= IGP02E1000_PM_D3_LPLU;
7335 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
7342 /* When LPLU is enabled we should disable SmartSpeed */
7343 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
7347 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7348 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
7353 return E1000_SUCCESS;
7356 /*****************************************************************************
7358 * This function sets the lplu d0 state according to the active flag. When
7359 * activating lplu this function also disables smart speed and vise versa.
7360 * lplu will not be activated unless the device autonegotiation advertisment
7361 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
7362 * hw: Struct containing variables accessed by shared code
7363 * active - true to enable lplu false to disable lplu.
7365 * returns: - E1000_ERR_PHY if fail to read/write the PHY
7366 * E1000_SUCCESS at any other case.
7368 ****************************************************************************/
7371 e1000_set_d0_lplu_state(struct e1000_hw *hw,
7374 uint32_t phy_ctrl = 0;
7377 DEBUGFUNC("e1000_set_d0_lplu_state");
7379 if (hw->mac_type <= e1000_82547_rev_2)
7380 return E1000_SUCCESS;
7382 if (hw->mac_type == e1000_ich8lan) {
7383 phy_ctrl = E1000_READ_REG(hw, PHY_CTRL);
7385 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
7391 if (hw->mac_type == e1000_ich8lan) {
7392 phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
7393 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7395 phy_data &= ~IGP02E1000_PM_D0_LPLU;
7396 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
7401 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
7402 * Dx states where the power conservation is most important. During
7403 * driver activity we should enable SmartSpeed, so performance is
7405 if (hw->smart_speed == e1000_smart_speed_on) {
7406 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7411 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
7412 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7416 } else if (hw->smart_speed == e1000_smart_speed_off) {
7417 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7422 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7423 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7432 if (hw->mac_type == e1000_ich8lan) {
7433 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
7434 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7436 phy_data |= IGP02E1000_PM_D0_LPLU;
7437 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
7442 /* When LPLU is enabled we should disable SmartSpeed */
7443 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
7447 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7448 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
7453 return E1000_SUCCESS;
7456 /******************************************************************************
7457 * Change VCO speed register to improve Bit Error Rate performance of SERDES.
7459 * hw - Struct containing variables accessed by shared code
7460 *****************************************************************************/
7462 e1000_set_vco_speed(struct e1000_hw *hw)
7465 uint16_t default_page = 0;
7468 DEBUGFUNC("e1000_set_vco_speed");
7470 switch (hw->mac_type) {
7471 case e1000_82545_rev_3:
7472 case e1000_82546_rev_3:
7475 return E1000_SUCCESS;
7478 /* Set PHY register 30, page 5, bit 8 to 0 */
7480 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, &default_page);
7484 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005);
7488 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
7492 phy_data &= ~M88E1000_PHY_VCO_REG_BIT8;
7493 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
7497 /* Set PHY register 30, page 4, bit 11 to 1 */
7499 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004);
7503 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
7507 phy_data |= M88E1000_PHY_VCO_REG_BIT11;
7508 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
7512 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, default_page);
7516 return E1000_SUCCESS;
7520 /*****************************************************************************
7521 * This function reads the cookie from ARC ram.
7523 * returns: - E1000_SUCCESS .
7524 ****************************************************************************/
7526 e1000_host_if_read_cookie(struct e1000_hw * hw, uint8_t *buffer)
7529 uint32_t offset = E1000_MNG_DHCP_COOKIE_OFFSET;
7530 uint8_t length = E1000_MNG_DHCP_COOKIE_LENGTH;
7532 length = (length >> 2);
7533 offset = (offset >> 2);
7535 for (i = 0; i < length; i++) {
7536 *((uint32_t *) buffer + i) =
7537 E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset + i);
7539 return E1000_SUCCESS;
7543 /*****************************************************************************
7544 * This function checks whether the HOST IF is enabled for command operaton
7545 * and also checks whether the previous command is completed.
7546 * It busy waits in case of previous command is not completed.
7548 * returns: - E1000_ERR_HOST_INTERFACE_COMMAND in case if is not ready or
7550 * - E1000_SUCCESS for success.
7551 ****************************************************************************/
7553 e1000_mng_enable_host_if(struct e1000_hw * hw)
7558 /* Check that the host interface is enabled. */
7559 hicr = E1000_READ_REG(hw, HICR);
7560 if ((hicr & E1000_HICR_EN) == 0) {
7561 DEBUGOUT("E1000_HOST_EN bit disabled.\n");
7562 return -E1000_ERR_HOST_INTERFACE_COMMAND;
7564 /* check the previous command is completed */
7565 for (i = 0; i < E1000_MNG_DHCP_COMMAND_TIMEOUT; i++) {
7566 hicr = E1000_READ_REG(hw, HICR);
7567 if (!(hicr & E1000_HICR_C))
7572 if (i == E1000_MNG_DHCP_COMMAND_TIMEOUT) {
7573 DEBUGOUT("Previous command timeout failed .\n");
7574 return -E1000_ERR_HOST_INTERFACE_COMMAND;
7576 return E1000_SUCCESS;
7579 /*****************************************************************************
7580 * This function writes the buffer content at the offset given on the host if.
7581 * It also does alignment considerations to do the writes in most efficient way.
7582 * Also fills up the sum of the buffer in *buffer parameter.
7584 * returns - E1000_SUCCESS for success.
7585 ****************************************************************************/
7587 e1000_mng_host_if_write(struct e1000_hw * hw, uint8_t *buffer,
7588 uint16_t length, uint16_t offset, uint8_t *sum)
7591 uint8_t *bufptr = buffer;
7593 uint16_t remaining, i, j, prev_bytes;
7595 /* sum = only sum of the data and it is not checksum */
7597 if (length == 0 || offset + length > E1000_HI_MAX_MNG_DATA_LENGTH) {
7598 return -E1000_ERR_PARAM;
7601 tmp = (uint8_t *)&data;
7602 prev_bytes = offset & 0x3;
7607 data = E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset);
7608 for (j = prev_bytes; j < sizeof(uint32_t); j++) {
7609 *(tmp + j) = *bufptr++;
7612 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset, data);
7613 length -= j - prev_bytes;
7617 remaining = length & 0x3;
7618 length -= remaining;
7620 /* Calculate length in DWORDs */
7623 /* The device driver writes the relevant command block into the
7625 for (i = 0; i < length; i++) {
7626 for (j = 0; j < sizeof(uint32_t); j++) {
7627 *(tmp + j) = *bufptr++;
7631 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data);
7634 for (j = 0; j < sizeof(uint32_t); j++) {
7636 *(tmp + j) = *bufptr++;
7642 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data);
7645 return E1000_SUCCESS;
7649 /*****************************************************************************
7650 * This function writes the command header after does the checksum calculation.
7652 * returns - E1000_SUCCESS for success.
7653 ****************************************************************************/
7655 e1000_mng_write_cmd_header(struct e1000_hw * hw,
7656 struct e1000_host_mng_command_header * hdr)
7662 /* Write the whole command header structure which includes sum of
7665 uint16_t length = sizeof(struct e1000_host_mng_command_header);
7667 sum = hdr->checksum;
7670 buffer = (uint8_t *) hdr;
7675 hdr->checksum = 0 - sum;
7678 /* The device driver writes the relevant command block into the ram area. */
7679 for (i = 0; i < length; i++) {
7680 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, i, *((uint32_t *) hdr + i));
7681 E1000_WRITE_FLUSH(hw);
7684 return E1000_SUCCESS;
7688 /*****************************************************************************
7689 * This function indicates to ARC that a new command is pending which completes
7690 * one write operation by the driver.
7692 * returns - E1000_SUCCESS for success.
7693 ****************************************************************************/
7695 e1000_mng_write_commit(struct e1000_hw * hw)
7699 hicr = E1000_READ_REG(hw, HICR);
7700 /* Setting this bit tells the ARC that a new command is pending. */
7701 E1000_WRITE_REG(hw, HICR, hicr | E1000_HICR_C);
7703 return E1000_SUCCESS;
7707 /*****************************************************************************
7708 * This function checks the mode of the firmware.
7710 * returns - TRUE when the mode is IAMT or FALSE.
7711 ****************************************************************************/
7713 e1000_check_mng_mode(struct e1000_hw *hw)
7717 fwsm = E1000_READ_REG(hw, FWSM);
7719 if (hw->mac_type == e1000_ich8lan) {
7720 if ((fwsm & E1000_FWSM_MODE_MASK) ==
7721 (E1000_MNG_ICH_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
7723 } else if ((fwsm & E1000_FWSM_MODE_MASK) ==
7724 (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
7731 /*****************************************************************************
7732 * This function writes the dhcp info .
7733 ****************************************************************************/
7735 e1000_mng_write_dhcp_info(struct e1000_hw * hw, uint8_t *buffer,
7739 struct e1000_host_mng_command_header hdr;
7741 hdr.command_id = E1000_MNG_DHCP_TX_PAYLOAD_CMD;
7742 hdr.command_length = length;
7747 ret_val = e1000_mng_enable_host_if(hw);
7748 if (ret_val == E1000_SUCCESS) {
7749 ret_val = e1000_mng_host_if_write(hw, buffer, length, sizeof(hdr),
7751 if (ret_val == E1000_SUCCESS) {
7752 ret_val = e1000_mng_write_cmd_header(hw, &hdr);
7753 if (ret_val == E1000_SUCCESS)
7754 ret_val = e1000_mng_write_commit(hw);
7761 /*****************************************************************************
7762 * This function calculates the checksum.
7764 * returns - checksum of buffer contents.
7765 ****************************************************************************/
7767 e1000_calculate_mng_checksum(char *buffer, uint32_t length)
7775 for (i=0; i < length; i++)
7778 return (uint8_t) (0 - sum);
7781 /*****************************************************************************
7782 * This function checks whether tx pkt filtering needs to be enabled or not.
7784 * returns - TRUE for packet filtering or FALSE.
7785 ****************************************************************************/
7787 e1000_enable_tx_pkt_filtering(struct e1000_hw *hw)
7789 /* called in init as well as watchdog timer functions */
7791 int32_t ret_val, checksum;
7792 boolean_t tx_filter = FALSE;
7793 struct e1000_host_mng_dhcp_cookie *hdr = &(hw->mng_cookie);
7794 uint8_t *buffer = (uint8_t *) &(hw->mng_cookie);
7796 if (e1000_check_mng_mode(hw)) {
7797 ret_val = e1000_mng_enable_host_if(hw);
7798 if (ret_val == E1000_SUCCESS) {
7799 ret_val = e1000_host_if_read_cookie(hw, buffer);
7800 if (ret_val == E1000_SUCCESS) {
7801 checksum = hdr->checksum;
7803 if ((hdr->signature == E1000_IAMT_SIGNATURE) &&
7804 checksum == e1000_calculate_mng_checksum((char *)buffer,
7805 E1000_MNG_DHCP_COOKIE_LENGTH)) {
7807 E1000_MNG_DHCP_COOKIE_STATUS_PARSING_SUPPORT)
7816 hw->tx_pkt_filtering = tx_filter;
7820 /******************************************************************************
7821 * Verifies the hardware needs to allow ARPs to be processed by the host
7823 * hw - Struct containing variables accessed by shared code
7825 * returns: - TRUE/FALSE
7827 *****************************************************************************/
7829 e1000_enable_mng_pass_thru(struct e1000_hw *hw)
7832 uint32_t fwsm, factps;
7834 if (hw->asf_firmware_present) {
7835 manc = E1000_READ_REG(hw, MANC);
7837 if (!(manc & E1000_MANC_RCV_TCO_EN) ||
7838 !(manc & E1000_MANC_EN_MAC_ADDR_FILTER))
7840 if (e1000_arc_subsystem_valid(hw) == TRUE) {
7841 fwsm = E1000_READ_REG(hw, FWSM);
7842 factps = E1000_READ_REG(hw, FACTPS);
7844 if ((((fwsm & E1000_FWSM_MODE_MASK) >> E1000_FWSM_MODE_SHIFT) ==
7845 e1000_mng_mode_pt) && !(factps & E1000_FACTPS_MNGCG))
7848 if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN))
7855 e1000_polarity_reversal_workaround(struct e1000_hw *hw)
7858 uint16_t mii_status_reg;
7861 /* Polarity reversal workaround for forced 10F/10H links. */
7863 /* Disable the transmitter on the PHY */
7865 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
7868 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF);
7872 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
7876 /* This loop will early-out if the NO link condition has been met. */
7877 for (i = PHY_FORCE_TIME; i > 0; i--) {
7878 /* Read the MII Status Register and wait for Link Status bit
7882 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
7886 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
7890 if ((mii_status_reg & ~MII_SR_LINK_STATUS) == 0) break;
7894 /* Recommended delay time after link has been lost */
7897 /* Now we will re-enable th transmitter on the PHY */
7899 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
7903 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0);
7907 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00);
7911 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000);
7915 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
7919 /* This loop will early-out if the link condition has been met. */
7920 for (i = PHY_FORCE_TIME; i > 0; i--) {
7921 /* Read the MII Status Register and wait for Link Status bit
7925 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
7929 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
7933 if (mii_status_reg & MII_SR_LINK_STATUS) break;
7936 return E1000_SUCCESS;
7939 /***************************************************************************
7941 * Disables PCI-Express master access.
7943 * hw: Struct containing variables accessed by shared code
7947 ***************************************************************************/
7949 e1000_set_pci_express_master_disable(struct e1000_hw *hw)
7953 DEBUGFUNC("e1000_set_pci_express_master_disable");
7955 if (hw->bus_type != e1000_bus_type_pci_express)
7958 ctrl = E1000_READ_REG(hw, CTRL);
7959 ctrl |= E1000_CTRL_GIO_MASTER_DISABLE;
7960 E1000_WRITE_REG(hw, CTRL, ctrl);
7963 /*******************************************************************************
7965 * Disables PCI-Express master access and verifies there are no pending requests
7967 * hw: Struct containing variables accessed by shared code
7969 * returns: - E1000_ERR_MASTER_REQUESTS_PENDING if master disable bit hasn't
7970 * caused the master requests to be disabled.
7971 * E1000_SUCCESS master requests disabled.
7973 ******************************************************************************/
7975 e1000_disable_pciex_master(struct e1000_hw *hw)
7977 int32_t timeout = MASTER_DISABLE_TIMEOUT; /* 80ms */
7979 DEBUGFUNC("e1000_disable_pciex_master");
7981 if (hw->bus_type != e1000_bus_type_pci_express)
7982 return E1000_SUCCESS;
7984 e1000_set_pci_express_master_disable(hw);
7987 if (!(E1000_READ_REG(hw, STATUS) & E1000_STATUS_GIO_MASTER_ENABLE))
7995 DEBUGOUT("Master requests are pending.\n");
7996 return -E1000_ERR_MASTER_REQUESTS_PENDING;
7999 return E1000_SUCCESS;
8002 /*******************************************************************************
8004 * Check for EEPROM Auto Read bit done.
8006 * hw: Struct containing variables accessed by shared code
8008 * returns: - E1000_ERR_RESET if fail to reset MAC
8009 * E1000_SUCCESS at any other case.
8011 ******************************************************************************/
8013 e1000_get_auto_rd_done(struct e1000_hw *hw)
8015 int32_t timeout = AUTO_READ_DONE_TIMEOUT;
8017 DEBUGFUNC("e1000_get_auto_rd_done");
8019 switch (hw->mac_type) {
8026 case e1000_80003es2lan:
8029 if (E1000_READ_REG(hw, EECD) & E1000_EECD_AUTO_RD)
8036 DEBUGOUT("Auto read by HW from EEPROM has not completed.\n");
8037 return -E1000_ERR_RESET;
8042 /* PHY configuration from NVM just starts after EECD_AUTO_RD sets to high.
8043 * Need to wait for PHY configuration completion before accessing NVM
8045 if (hw->mac_type == e1000_82573)
8048 return E1000_SUCCESS;
8051 /***************************************************************************
8052 * Checks if the PHY configuration is done
8054 * hw: Struct containing variables accessed by shared code
8056 * returns: - E1000_ERR_RESET if fail to reset MAC
8057 * E1000_SUCCESS at any other case.
8059 ***************************************************************************/
8061 e1000_get_phy_cfg_done(struct e1000_hw *hw)
8063 int32_t timeout = PHY_CFG_TIMEOUT;
8064 uint32_t cfg_mask = E1000_EEPROM_CFG_DONE;
8066 DEBUGFUNC("e1000_get_phy_cfg_done");
8068 switch (hw->mac_type) {
8072 case e1000_80003es2lan:
8073 /* Separate *_CFG_DONE_* bit for each port */
8074 if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
8075 cfg_mask = E1000_EEPROM_CFG_DONE_PORT_1;
8080 if (E1000_READ_REG(hw, EEMNGCTL) & cfg_mask)
8087 DEBUGOUT("MNG configuration cycle has not completed.\n");
8088 return -E1000_ERR_RESET;
8093 return E1000_SUCCESS;
8096 /***************************************************************************
8098 * Using the combination of SMBI and SWESMBI semaphore bits when resetting
8099 * adapter or Eeprom access.
8101 * hw: Struct containing variables accessed by shared code
8103 * returns: - E1000_ERR_EEPROM if fail to access EEPROM.
8104 * E1000_SUCCESS at any other case.
8106 ***************************************************************************/
8108 e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw)
8113 DEBUGFUNC("e1000_get_hw_eeprom_semaphore");
8115 if (!hw->eeprom_semaphore_present)
8116 return E1000_SUCCESS;
8118 if (hw->mac_type == e1000_80003es2lan) {
8119 /* Get the SW semaphore. */
8120 if (e1000_get_software_semaphore(hw) != E1000_SUCCESS)
8121 return -E1000_ERR_EEPROM;
8124 /* Get the FW semaphore. */
8125 timeout = hw->eeprom.word_size + 1;
8127 swsm = E1000_READ_REG(hw, SWSM);
8128 swsm |= E1000_SWSM_SWESMBI;
8129 E1000_WRITE_REG(hw, SWSM, swsm);
8130 /* if we managed to set the bit we got the semaphore. */
8131 swsm = E1000_READ_REG(hw, SWSM);
8132 if (swsm & E1000_SWSM_SWESMBI)
8140 /* Release semaphores */
8141 e1000_put_hw_eeprom_semaphore(hw);
8142 DEBUGOUT("Driver can't access the Eeprom - SWESMBI bit is set.\n");
8143 return -E1000_ERR_EEPROM;
8146 return E1000_SUCCESS;
8149 /***************************************************************************
8150 * This function clears HW semaphore bits.
8152 * hw: Struct containing variables accessed by shared code
8156 ***************************************************************************/
8158 e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw)
8162 DEBUGFUNC("e1000_put_hw_eeprom_semaphore");
8164 if (!hw->eeprom_semaphore_present)
8167 swsm = E1000_READ_REG(hw, SWSM);
8168 if (hw->mac_type == e1000_80003es2lan) {
8169 /* Release both semaphores. */
8170 swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
8172 swsm &= ~(E1000_SWSM_SWESMBI);
8173 E1000_WRITE_REG(hw, SWSM, swsm);
8176 /***************************************************************************
8178 * Obtaining software semaphore bit (SMBI) before resetting PHY.
8180 * hw: Struct containing variables accessed by shared code
8182 * returns: - E1000_ERR_RESET if fail to obtain semaphore.
8183 * E1000_SUCCESS at any other case.
8185 ***************************************************************************/
8187 e1000_get_software_semaphore(struct e1000_hw *hw)
8189 int32_t timeout = hw->eeprom.word_size + 1;
8192 DEBUGFUNC("e1000_get_software_semaphore");
8194 if (hw->mac_type != e1000_80003es2lan) {
8195 return E1000_SUCCESS;
8199 swsm = E1000_READ_REG(hw, SWSM);
8200 /* If SMBI bit cleared, it is now set and we hold the semaphore */
8201 if (!(swsm & E1000_SWSM_SMBI))
8208 DEBUGOUT("Driver can't access device - SMBI bit is set.\n");
8209 return -E1000_ERR_RESET;
8212 return E1000_SUCCESS;
8215 /***************************************************************************
8217 * Release semaphore bit (SMBI).
8219 * hw: Struct containing variables accessed by shared code
8221 ***************************************************************************/
8223 e1000_release_software_semaphore(struct e1000_hw *hw)
8227 DEBUGFUNC("e1000_release_software_semaphore");
8229 if (hw->mac_type != e1000_80003es2lan) {
8233 swsm = E1000_READ_REG(hw, SWSM);
8234 /* Release the SW semaphores.*/
8235 swsm &= ~E1000_SWSM_SMBI;
8236 E1000_WRITE_REG(hw, SWSM, swsm);
8239 /******************************************************************************
8240 * Checks if PHY reset is blocked due to SOL/IDER session, for example.
8241 * Returning E1000_BLK_PHY_RESET isn't necessarily an error. But it's up to
8242 * the caller to figure out how to deal with it.
8244 * hw - Struct containing variables accessed by shared code
8246 * returns: - E1000_BLK_PHY_RESET
8249 *****************************************************************************/
8251 e1000_check_phy_reset_block(struct e1000_hw *hw)
8256 if (hw->mac_type == e1000_ich8lan) {
8257 fwsm = E1000_READ_REG(hw, FWSM);
8258 return (fwsm & E1000_FWSM_RSPCIPHY) ? E1000_SUCCESS
8259 : E1000_BLK_PHY_RESET;
8262 if (hw->mac_type > e1000_82547_rev_2)
8263 manc = E1000_READ_REG(hw, MANC);
8264 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
8265 E1000_BLK_PHY_RESET : E1000_SUCCESS;
8269 e1000_arc_subsystem_valid(struct e1000_hw *hw)
8273 /* On 8257x silicon, registers in the range of 0x8800 - 0x8FFC
8274 * may not be provided a DMA clock when no manageability features are
8275 * enabled. We do not want to perform any reads/writes to these registers
8276 * if this is the case. We read FWSM to determine the manageability mode.
8278 switch (hw->mac_type) {
8282 case e1000_80003es2lan:
8283 fwsm = E1000_READ_REG(hw, FWSM);
8284 if ((fwsm & E1000_FWSM_MODE_MASK) != 0)
8296 /******************************************************************************
8297 * Configure PCI-Ex no-snoop
8299 * hw - Struct containing variables accessed by shared code.
8300 * no_snoop - Bitmap of no-snoop events.
8302 * returns: E1000_SUCCESS
8304 *****************************************************************************/
8306 e1000_set_pci_ex_no_snoop(struct e1000_hw *hw, uint32_t no_snoop)
8308 uint32_t gcr_reg = 0;
8310 DEBUGFUNC("e1000_set_pci_ex_no_snoop");
8312 if (hw->bus_type == e1000_bus_type_unknown)
8313 e1000_get_bus_info(hw);
8315 if (hw->bus_type != e1000_bus_type_pci_express)
8316 return E1000_SUCCESS;
8319 gcr_reg = E1000_READ_REG(hw, GCR);
8320 gcr_reg &= ~(PCI_EX_NO_SNOOP_ALL);
8321 gcr_reg |= no_snoop;
8322 E1000_WRITE_REG(hw, GCR, gcr_reg);
8324 if (hw->mac_type == e1000_ich8lan) {
8327 E1000_WRITE_REG(hw, GCR, PCI_EX_82566_SNOOP_ALL);
8329 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
8330 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
8331 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
8334 return E1000_SUCCESS;
8337 /***************************************************************************
8339 * Get software semaphore FLAG bit (SWFLAG).
8340 * SWFLAG is used to synchronize the access to all shared resource between
8343 * hw: Struct containing variables accessed by shared code
8345 ***************************************************************************/
8347 e1000_get_software_flag(struct e1000_hw *hw)
8349 int32_t timeout = PHY_CFG_TIMEOUT;
8350 uint32_t extcnf_ctrl;
8352 DEBUGFUNC("e1000_get_software_flag");
8354 if (hw->mac_type == e1000_ich8lan) {
8356 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
8357 extcnf_ctrl |= E1000_EXTCNF_CTRL_SWFLAG;
8358 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
8360 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
8361 if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG)
8368 DEBUGOUT("FW or HW locks the resource too long.\n");
8369 return -E1000_ERR_CONFIG;
8373 return E1000_SUCCESS;
8376 /***************************************************************************
8378 * Release software semaphore FLAG bit (SWFLAG).
8379 * SWFLAG is used to synchronize the access to all shared resource between
8382 * hw: Struct containing variables accessed by shared code
8384 ***************************************************************************/
8386 e1000_release_software_flag(struct e1000_hw *hw)
8388 uint32_t extcnf_ctrl;
8390 DEBUGFUNC("e1000_release_software_flag");
8392 if (hw->mac_type == e1000_ich8lan) {
8393 extcnf_ctrl= E1000_READ_REG(hw, EXTCNF_CTRL);
8394 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
8395 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
8401 /******************************************************************************
8402 * Reads a 16 bit word or words from the EEPROM using the ICH8's flash access
8405 * hw - Struct containing variables accessed by shared code
8406 * offset - offset of word in the EEPROM to read
8407 * data - word read from the EEPROM
8408 * words - number of words to read
8409 *****************************************************************************/
8411 e1000_read_eeprom_ich8(struct e1000_hw *hw, uint16_t offset, uint16_t words,
8414 int32_t error = E1000_SUCCESS;
8415 uint32_t flash_bank = 0;
8416 uint32_t act_offset = 0;
8417 uint32_t bank_offset = 0;
8421 /* We need to know which is the valid flash bank. In the event
8422 * that we didn't allocate eeprom_shadow_ram, we may not be
8423 * managing flash_bank. So it cannot be trusted and needs
8424 * to be updated with each read.
8426 /* Value of bit 22 corresponds to the flash bank we're on. */
8427 flash_bank = (E1000_READ_REG(hw, EECD) & E1000_EECD_SEC1VAL) ? 1 : 0;
8429 /* Adjust offset appropriately if we're on bank 1 - adjust for word size */
8430 bank_offset = flash_bank * (hw->flash_bank_size * 2);
8432 error = e1000_get_software_flag(hw);
8433 if (error != E1000_SUCCESS)
8436 for (i = 0; i < words; i++) {
8437 if (hw->eeprom_shadow_ram != NULL &&
8438 hw->eeprom_shadow_ram[offset+i].modified == TRUE) {
8439 data[i] = hw->eeprom_shadow_ram[offset+i].eeprom_word;
8441 /* The NVM part needs a byte offset, hence * 2 */
8442 act_offset = bank_offset + ((offset + i) * 2);
8443 error = e1000_read_ich8_word(hw, act_offset, &word);
8444 if (error != E1000_SUCCESS)
8450 e1000_release_software_flag(hw);
8455 /******************************************************************************
8456 * Writes a 16 bit word or words to the EEPROM using the ICH8's flash access
8457 * register. Actually, writes are written to the shadow ram cache in the hw
8458 * structure hw->e1000_shadow_ram. e1000_commit_shadow_ram flushes this to
8459 * the NVM, which occurs when the NVM checksum is updated.
8461 * hw - Struct containing variables accessed by shared code
8462 * offset - offset of word in the EEPROM to write
8463 * words - number of words to write
8464 * data - words to write to the EEPROM
8465 *****************************************************************************/
8467 e1000_write_eeprom_ich8(struct e1000_hw *hw, uint16_t offset, uint16_t words,
8471 int32_t error = E1000_SUCCESS;
8473 error = e1000_get_software_flag(hw);
8474 if (error != E1000_SUCCESS)
8477 /* A driver can write to the NVM only if it has eeprom_shadow_ram
8478 * allocated. Subsequent reads to the modified words are read from
8479 * this cached structure as well. Writes will only go into this
8480 * cached structure unless it's followed by a call to
8481 * e1000_update_eeprom_checksum() where it will commit the changes
8482 * and clear the "modified" field.
8484 if (hw->eeprom_shadow_ram != NULL) {
8485 for (i = 0; i < words; i++) {
8486 if ((offset + i) < E1000_SHADOW_RAM_WORDS) {
8487 hw->eeprom_shadow_ram[offset+i].modified = TRUE;
8488 hw->eeprom_shadow_ram[offset+i].eeprom_word = data[i];
8490 error = -E1000_ERR_EEPROM;
8495 /* Drivers have the option to not allocate eeprom_shadow_ram as long
8496 * as they don't perform any NVM writes. An attempt in doing so
8497 * will result in this error.
8499 error = -E1000_ERR_EEPROM;
8502 e1000_release_software_flag(hw);
8507 /******************************************************************************
8508 * This function does initial flash setup so that a new read/write/erase cycle
8511 * hw - The pointer to the hw structure
8512 ****************************************************************************/
8514 e1000_ich8_cycle_init(struct e1000_hw *hw)
8516 union ich8_hws_flash_status hsfsts;
8517 int32_t error = E1000_ERR_EEPROM;
8520 DEBUGFUNC("e1000_ich8_cycle_init");
8522 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
8524 /* May be check the Flash Des Valid bit in Hw status */
8525 if (hsfsts.hsf_status.fldesvalid == 0) {
8526 DEBUGOUT("Flash descriptor invalid. SW Sequencing must be used.");
8530 /* Clear FCERR in Hw status by writing 1 */
8531 /* Clear DAEL in Hw status by writing a 1 */
8532 hsfsts.hsf_status.flcerr = 1;
8533 hsfsts.hsf_status.dael = 1;
8535 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS, hsfsts.regval);
8537 /* Either we should have a hardware SPI cycle in progress bit to check
8538 * against, in order to start a new cycle or FDONE bit should be changed
8539 * in the hardware so that it is 1 after harware reset, which can then be
8540 * used as an indication whether a cycle is in progress or has been
8541 * completed .. we should also have some software semaphore mechanism to
8542 * guard FDONE or the cycle in progress bit so that two threads access to
8543 * those bits can be sequentiallized or a way so that 2 threads dont
8544 * start the cycle at the same time */
8546 if (hsfsts.hsf_status.flcinprog == 0) {
8547 /* There is no cycle running at present, so we can start a cycle */
8548 /* Begin by setting Flash Cycle Done. */
8549 hsfsts.hsf_status.flcdone = 1;
8550 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS, hsfsts.regval);
8551 error = E1000_SUCCESS;
8553 /* otherwise poll for sometime so the current cycle has a chance
8554 * to end before giving up. */
8555 for (i = 0; i < ICH_FLASH_COMMAND_TIMEOUT; i++) {
8556 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
8557 if (hsfsts.hsf_status.flcinprog == 0) {
8558 error = E1000_SUCCESS;
8563 if (error == E1000_SUCCESS) {
8564 /* Successful in waiting for previous cycle to timeout,
8565 * now set the Flash Cycle Done. */
8566 hsfsts.hsf_status.flcdone = 1;
8567 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS, hsfsts.regval);
8569 DEBUGOUT("Flash controller busy, cannot get access");
8575 /******************************************************************************
8576 * This function starts a flash cycle and waits for its completion
8578 * hw - The pointer to the hw structure
8579 ****************************************************************************/
8581 e1000_ich8_flash_cycle(struct e1000_hw *hw, uint32_t timeout)
8583 union ich8_hws_flash_ctrl hsflctl;
8584 union ich8_hws_flash_status hsfsts;
8585 int32_t error = E1000_ERR_EEPROM;
8588 /* Start a cycle by writing 1 in Flash Cycle Go in Hw Flash Control */
8589 hsflctl.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL);
8590 hsflctl.hsf_ctrl.flcgo = 1;
8591 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval);
8593 /* wait till FDONE bit is set to 1 */
8595 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
8596 if (hsfsts.hsf_status.flcdone == 1)
8600 } while (i < timeout);
8601 if (hsfsts.hsf_status.flcdone == 1 && hsfsts.hsf_status.flcerr == 0) {
8602 error = E1000_SUCCESS;
8607 /******************************************************************************
8608 * Reads a byte or word from the NVM using the ICH8 flash access registers.
8610 * hw - The pointer to the hw structure
8611 * index - The index of the byte or word to read.
8612 * size - Size of data to read, 1=byte 2=word
8613 * data - Pointer to the word to store the value read.
8614 *****************************************************************************/
8616 e1000_read_ich8_data(struct e1000_hw *hw, uint32_t index,
8617 uint32_t size, uint16_t* data)
8619 union ich8_hws_flash_status hsfsts;
8620 union ich8_hws_flash_ctrl hsflctl;
8621 uint32_t flash_linear_address;
8622 uint32_t flash_data = 0;
8623 int32_t error = -E1000_ERR_EEPROM;
8626 DEBUGFUNC("e1000_read_ich8_data");
8628 if (size < 1 || size > 2 || data == 0x0 ||
8629 index > ICH_FLASH_LINEAR_ADDR_MASK)
8632 flash_linear_address = (ICH_FLASH_LINEAR_ADDR_MASK & index) +
8633 hw->flash_base_addr;
8638 error = e1000_ich8_cycle_init(hw);
8639 if (error != E1000_SUCCESS)
8642 hsflctl.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL);
8643 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
8644 hsflctl.hsf_ctrl.fldbcount = size - 1;
8645 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_READ;
8646 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval);
8648 /* Write the last 24 bits of index into Flash Linear address field in
8650 /* TODO: TBD maybe check the index against the size of flash */
8652 E1000_WRITE_ICH_FLASH_REG(hw, ICH_FLASH_FADDR, flash_linear_address);
8654 error = e1000_ich8_flash_cycle(hw, ICH_FLASH_COMMAND_TIMEOUT);
8656 /* Check if FCERR is set to 1, if set to 1, clear it and try the whole
8657 * sequence a few more times, else read in (shift in) the Flash Data0,
8658 * the order is least significant byte first msb to lsb */
8659 if (error == E1000_SUCCESS) {
8660 flash_data = E1000_READ_ICH_FLASH_REG(hw, ICH_FLASH_FDATA0);
8662 *data = (uint8_t)(flash_data & 0x000000FF);
8663 } else if (size == 2) {
8664 *data = (uint16_t)(flash_data & 0x0000FFFF);
8668 /* If we've gotten here, then things are probably completely hosed,
8669 * but if the error condition is detected, it won't hurt to give
8670 * it another try...ICH_FLASH_CYCLE_REPEAT_COUNT times.
8672 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
8673 if (hsfsts.hsf_status.flcerr == 1) {
8674 /* Repeat for some time before giving up. */
8676 } else if (hsfsts.hsf_status.flcdone == 0) {
8677 DEBUGOUT("Timeout error - flash cycle did not complete.");
8681 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
8686 /******************************************************************************
8687 * Writes One /two bytes to the NVM using the ICH8 flash access registers.
8689 * hw - The pointer to the hw structure
8690 * index - The index of the byte/word to read.
8691 * size - Size of data to read, 1=byte 2=word
8692 * data - The byte(s) to write to the NVM.
8693 *****************************************************************************/
8695 e1000_write_ich8_data(struct e1000_hw *hw, uint32_t index, uint32_t size,
8698 union ich8_hws_flash_status hsfsts;
8699 union ich8_hws_flash_ctrl hsflctl;
8700 uint32_t flash_linear_address;
8701 uint32_t flash_data = 0;
8702 int32_t error = -E1000_ERR_EEPROM;
8705 DEBUGFUNC("e1000_write_ich8_data");
8707 if (size < 1 || size > 2 || data > size * 0xff ||
8708 index > ICH_FLASH_LINEAR_ADDR_MASK)
8711 flash_linear_address = (ICH_FLASH_LINEAR_ADDR_MASK & index) +
8712 hw->flash_base_addr;
8717 error = e1000_ich8_cycle_init(hw);
8718 if (error != E1000_SUCCESS)
8721 hsflctl.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL);
8722 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
8723 hsflctl.hsf_ctrl.fldbcount = size -1;
8724 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_WRITE;
8725 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval);
8727 /* Write the last 24 bits of index into Flash Linear address field in
8729 E1000_WRITE_ICH_FLASH_REG(hw, ICH_FLASH_FADDR, flash_linear_address);
8732 flash_data = (uint32_t)data & 0x00FF;
8734 flash_data = (uint32_t)data;
8736 E1000_WRITE_ICH_FLASH_REG(hw, ICH_FLASH_FDATA0, flash_data);
8738 /* check if FCERR is set to 1 , if set to 1, clear it and try the whole
8739 * sequence a few more times else done */
8740 error = e1000_ich8_flash_cycle(hw, ICH_FLASH_COMMAND_TIMEOUT);
8741 if (error == E1000_SUCCESS) {
8744 /* If we're here, then things are most likely completely hosed,
8745 * but if the error condition is detected, it won't hurt to give
8746 * it another try...ICH_FLASH_CYCLE_REPEAT_COUNT times.
8748 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
8749 if (hsfsts.hsf_status.flcerr == 1) {
8750 /* Repeat for some time before giving up. */
8752 } else if (hsfsts.hsf_status.flcdone == 0) {
8753 DEBUGOUT("Timeout error - flash cycle did not complete.");
8757 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
8762 /******************************************************************************
8763 * Reads a single byte from the NVM using the ICH8 flash access registers.
8765 * hw - pointer to e1000_hw structure
8766 * index - The index of the byte to read.
8767 * data - Pointer to a byte to store the value read.
8768 *****************************************************************************/
8770 e1000_read_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t* data)
8772 int32_t status = E1000_SUCCESS;
8775 status = e1000_read_ich8_data(hw, index, 1, &word);
8776 if (status == E1000_SUCCESS) {
8777 *data = (uint8_t)word;
8783 /******************************************************************************
8784 * Writes a single byte to the NVM using the ICH8 flash access registers.
8785 * Performs verification by reading back the value and then going through
8786 * a retry algorithm before giving up.
8788 * hw - pointer to e1000_hw structure
8789 * index - The index of the byte to write.
8790 * byte - The byte to write to the NVM.
8791 *****************************************************************************/
8793 e1000_verify_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t byte)
8795 int32_t error = E1000_SUCCESS;
8796 int32_t program_retries = 0;
8798 DEBUGOUT2("Byte := %2.2X Offset := %d\n", byte, index);
8800 error = e1000_write_ich8_byte(hw, index, byte);
8802 if (error != E1000_SUCCESS) {
8803 for (program_retries = 0; program_retries < 100; program_retries++) {
8804 DEBUGOUT2("Retrying \t Byte := %2.2X Offset := %d\n", byte, index);
8805 error = e1000_write_ich8_byte(hw, index, byte);
8807 if (error == E1000_SUCCESS)
8812 if (program_retries == 100)
8813 error = E1000_ERR_EEPROM;
8818 /******************************************************************************
8819 * Writes a single byte to the NVM using the ICH8 flash access registers.
8821 * hw - pointer to e1000_hw structure
8822 * index - The index of the byte to read.
8823 * data - The byte to write to the NVM.
8824 *****************************************************************************/
8826 e1000_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t data)
8828 int32_t status = E1000_SUCCESS;
8829 uint16_t word = (uint16_t)data;
8831 status = e1000_write_ich8_data(hw, index, 1, word);
8836 /******************************************************************************
8837 * Reads a word from the NVM using the ICH8 flash access registers.
8839 * hw - pointer to e1000_hw structure
8840 * index - The starting byte index of the word to read.
8841 * data - Pointer to a word to store the value read.
8842 *****************************************************************************/
8844 e1000_read_ich8_word(struct e1000_hw *hw, uint32_t index, uint16_t *data)
8846 int32_t status = E1000_SUCCESS;
8847 status = e1000_read_ich8_data(hw, index, 2, data);
8851 /******************************************************************************
8852 * Erases the bank specified. Each bank may be a 4, 8 or 64k block. Banks are 0
8855 * hw - pointer to e1000_hw structure
8856 * bank - 0 for first bank, 1 for second bank
8858 * Note that this function may actually erase as much as 8 or 64 KBytes. The
8859 * amount of NVM used in each bank is a *minimum* of 4 KBytes, but in fact the
8860 * bank size may be 4, 8 or 64 KBytes
8861 *****************************************************************************/
8863 e1000_erase_ich8_4k_segment(struct e1000_hw *hw, uint32_t bank)
8865 union ich8_hws_flash_status hsfsts;
8866 union ich8_hws_flash_ctrl hsflctl;
8867 uint32_t flash_linear_address;
8869 int32_t error = E1000_ERR_EEPROM;
8871 int32_t sub_sector_size = 0;
8874 int32_t error_flag = 0;
8876 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
8878 /* Determine HW Sector size: Read BERASE bits of Hw flash Status register */
8879 /* 00: The Hw sector is 256 bytes, hence we need to erase 16
8880 * consecutive sectors. The start index for the nth Hw sector can be
8881 * calculated as bank * 4096 + n * 256
8882 * 01: The Hw sector is 4K bytes, hence we need to erase 1 sector.
8883 * The start index for the nth Hw sector can be calculated
8885 * 10: The HW sector is 8K bytes
8886 * 11: The Hw sector size is 64K bytes */
8887 if (hsfsts.hsf_status.berasesz == 0x0) {
8888 /* Hw sector size 256 */
8889 sub_sector_size = ICH_FLASH_SEG_SIZE_256;
8890 bank_size = ICH_FLASH_SECTOR_SIZE;
8891 iteration = ICH_FLASH_SECTOR_SIZE / ICH_FLASH_SEG_SIZE_256;
8892 } else if (hsfsts.hsf_status.berasesz == 0x1) {
8893 bank_size = ICH_FLASH_SEG_SIZE_4K;
8895 } else if (hsfsts.hsf_status.berasesz == 0x3) {
8896 bank_size = ICH_FLASH_SEG_SIZE_64K;
8902 for (j = 0; j < iteration ; j++) {
8906 error = e1000_ich8_cycle_init(hw);
8907 if (error != E1000_SUCCESS) {
8912 /* Write a value 11 (block Erase) in Flash Cycle field in Hw flash
8914 hsflctl.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL);
8915 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_ERASE;
8916 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval);
8918 /* Write the last 24 bits of an index within the block into Flash
8919 * Linear address field in Flash Address. This probably needs to
8920 * be calculated here based off the on-chip erase sector size and
8921 * the software bank size (4, 8 or 64 KBytes) */
8922 flash_linear_address = bank * bank_size + j * sub_sector_size;
8923 flash_linear_address += hw->flash_base_addr;
8924 flash_linear_address &= ICH_FLASH_LINEAR_ADDR_MASK;
8926 E1000_WRITE_ICH_FLASH_REG(hw, ICH_FLASH_FADDR, flash_linear_address);
8928 error = e1000_ich8_flash_cycle(hw, ICH_FLASH_ERASE_TIMEOUT);
8929 /* Check if FCERR is set to 1. If 1, clear it and try the whole
8930 * sequence a few more times else Done */
8931 if (error == E1000_SUCCESS) {
8934 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
8935 if (hsfsts.hsf_status.flcerr == 1) {
8936 /* repeat for some time before giving up */
8938 } else if (hsfsts.hsf_status.flcdone == 0) {
8943 } while ((count < ICH_FLASH_CYCLE_REPEAT_COUNT) && !error_flag);
8944 if (error_flag == 1)
8947 if (error_flag != 1)
8948 error = E1000_SUCCESS;
8953 e1000_init_lcd_from_nvm_config_region(struct e1000_hw *hw,
8954 uint32_t cnf_base_addr, uint32_t cnf_size)
8956 uint32_t ret_val = E1000_SUCCESS;
8957 uint16_t word_addr, reg_data, reg_addr;
8960 /* cnf_base_addr is in DWORD */
8961 word_addr = (uint16_t)(cnf_base_addr << 1);
8963 /* cnf_size is returned in size of dwords */
8964 for (i = 0; i < cnf_size; i++) {
8965 ret_val = e1000_read_eeprom(hw, (word_addr + i*2), 1, ®_data);
8969 ret_val = e1000_read_eeprom(hw, (word_addr + i*2 + 1), 1, ®_addr);
8973 ret_val = e1000_get_software_flag(hw);
8974 if (ret_val != E1000_SUCCESS)
8977 ret_val = e1000_write_phy_reg_ex(hw, (uint32_t)reg_addr, reg_data);
8979 e1000_release_software_flag(hw);
8986 /******************************************************************************
8987 * This function initializes the PHY from the NVM on ICH8 platforms. This
8988 * is needed due to an issue where the NVM configuration is not properly
8989 * autoloaded after power transitions. Therefore, after each PHY reset, we
8990 * will load the configuration data out of the NVM manually.
8992 * hw: Struct containing variables accessed by shared code
8993 *****************************************************************************/
8995 e1000_init_lcd_from_nvm(struct e1000_hw *hw)
8997 uint32_t reg_data, cnf_base_addr, cnf_size, ret_val, loop;
8999 if (hw->phy_type != e1000_phy_igp_3)
9000 return E1000_SUCCESS;
9002 /* Check if SW needs configure the PHY */
9003 reg_data = E1000_READ_REG(hw, FEXTNVM);
9004 if (!(reg_data & FEXTNVM_SW_CONFIG))
9005 return E1000_SUCCESS;
9007 /* Wait for basic configuration completes before proceeding*/
9010 reg_data = E1000_READ_REG(hw, STATUS) & E1000_STATUS_LAN_INIT_DONE;
9013 } while ((!reg_data) && (loop < 50));
9015 /* Clear the Init Done bit for the next init event */
9016 reg_data = E1000_READ_REG(hw, STATUS);
9017 reg_data &= ~E1000_STATUS_LAN_INIT_DONE;
9018 E1000_WRITE_REG(hw, STATUS, reg_data);
9020 /* Make sure HW does not configure LCD from PHY extended configuration
9021 before SW configuration */
9022 reg_data = E1000_READ_REG(hw, EXTCNF_CTRL);
9023 if ((reg_data & E1000_EXTCNF_CTRL_LCD_WRITE_ENABLE) == 0x0000) {
9024 reg_data = E1000_READ_REG(hw, EXTCNF_SIZE);
9025 cnf_size = reg_data & E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH;
9028 reg_data = E1000_READ_REG(hw, EXTCNF_CTRL);
9029 cnf_base_addr = reg_data & E1000_EXTCNF_CTRL_EXT_CNF_POINTER;
9030 /* cnf_base_addr is in DWORD */
9031 cnf_base_addr >>= 16;
9033 /* Configure LCD from extended configuration region. */
9034 ret_val = e1000_init_lcd_from_nvm_config_region(hw, cnf_base_addr,
9041 return E1000_SUCCESS;