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_82571PT_QUAD_COPPER:
391 case E1000_DEV_ID_82571EB_QUAD_FIBER:
392 case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE:
393 hw->mac_type = e1000_82571;
395 case E1000_DEV_ID_82572EI_COPPER:
396 case E1000_DEV_ID_82572EI_FIBER:
397 case E1000_DEV_ID_82572EI_SERDES:
398 case E1000_DEV_ID_82572EI:
399 hw->mac_type = e1000_82572;
401 case E1000_DEV_ID_82573E:
402 case E1000_DEV_ID_82573E_IAMT:
403 case E1000_DEV_ID_82573L:
404 hw->mac_type = e1000_82573;
406 case E1000_DEV_ID_80003ES2LAN_COPPER_SPT:
407 case E1000_DEV_ID_80003ES2LAN_SERDES_SPT:
408 case E1000_DEV_ID_80003ES2LAN_COPPER_DPT:
409 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
410 hw->mac_type = e1000_80003es2lan;
412 case E1000_DEV_ID_ICH8_IGP_M_AMT:
413 case E1000_DEV_ID_ICH8_IGP_AMT:
414 case E1000_DEV_ID_ICH8_IGP_C:
415 case E1000_DEV_ID_ICH8_IFE:
416 case E1000_DEV_ID_ICH8_IFE_GT:
417 case E1000_DEV_ID_ICH8_IFE_G:
418 case E1000_DEV_ID_ICH8_IGP_M:
419 hw->mac_type = e1000_ich8lan;
422 /* Should never have loaded on this device */
423 return -E1000_ERR_MAC_TYPE;
426 switch (hw->mac_type) {
428 hw->swfwhw_semaphore_present = TRUE;
429 hw->asf_firmware_present = TRUE;
431 case e1000_80003es2lan:
432 hw->swfw_sync_present = TRUE;
437 hw->eeprom_semaphore_present = TRUE;
441 case e1000_82541_rev_2:
442 case e1000_82547_rev_2:
443 hw->asf_firmware_present = TRUE;
449 /* The 82543 chip does not count tx_carrier_errors properly in
452 if (hw->mac_type == e1000_82543)
453 hw->bad_tx_carr_stats_fd = TRUE;
455 /* capable of receiving management packets to the host */
456 if (hw->mac_type >= e1000_82571)
457 hw->has_manc2h = TRUE;
459 /* In rare occasions, ESB2 systems would end up started without
460 * the RX unit being turned on.
462 if (hw->mac_type == e1000_80003es2lan)
463 hw->rx_needs_kicking = TRUE;
465 if (hw->mac_type > e1000_82544)
466 hw->has_smbus = TRUE;
468 return E1000_SUCCESS;
471 /*****************************************************************************
472 * Set media type and TBI compatibility.
474 * hw - Struct containing variables accessed by shared code
475 * **************************************************************************/
477 e1000_set_media_type(struct e1000_hw *hw)
481 DEBUGFUNC("e1000_set_media_type");
483 if (hw->mac_type != e1000_82543) {
484 /* tbi_compatibility is only valid on 82543 */
485 hw->tbi_compatibility_en = FALSE;
488 switch (hw->device_id) {
489 case E1000_DEV_ID_82545GM_SERDES:
490 case E1000_DEV_ID_82546GB_SERDES:
491 case E1000_DEV_ID_82571EB_SERDES:
492 case E1000_DEV_ID_82571EB_SERDES_DUAL:
493 case E1000_DEV_ID_82571EB_SERDES_QUAD:
494 case E1000_DEV_ID_82572EI_SERDES:
495 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
496 hw->media_type = e1000_media_type_internal_serdes;
499 switch (hw->mac_type) {
500 case e1000_82542_rev2_0:
501 case e1000_82542_rev2_1:
502 hw->media_type = e1000_media_type_fiber;
506 /* The STATUS_TBIMODE bit is reserved or reused for the this
509 hw->media_type = e1000_media_type_copper;
512 status = E1000_READ_REG(hw, STATUS);
513 if (status & E1000_STATUS_TBIMODE) {
514 hw->media_type = e1000_media_type_fiber;
515 /* tbi_compatibility not valid on fiber */
516 hw->tbi_compatibility_en = FALSE;
518 hw->media_type = e1000_media_type_copper;
525 /******************************************************************************
526 * Reset the transmit and receive units; mask and clear all interrupts.
528 * hw - Struct containing variables accessed by shared code
529 *****************************************************************************/
531 e1000_reset_hw(struct e1000_hw *hw)
539 uint32_t extcnf_ctrl;
542 DEBUGFUNC("e1000_reset_hw");
544 /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
545 if (hw->mac_type == e1000_82542_rev2_0) {
546 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
547 e1000_pci_clear_mwi(hw);
550 if (hw->bus_type == e1000_bus_type_pci_express) {
551 /* Prevent the PCI-E bus from sticking if there is no TLP connection
552 * on the last TLP read/write transaction when MAC is reset.
554 if (e1000_disable_pciex_master(hw) != E1000_SUCCESS) {
555 DEBUGOUT("PCI-E Master disable polling has failed.\n");
559 /* Clear interrupt mask to stop board from generating interrupts */
560 DEBUGOUT("Masking off all interrupts\n");
561 E1000_WRITE_REG(hw, IMC, 0xffffffff);
563 /* Disable the Transmit and Receive units. Then delay to allow
564 * any pending transactions to complete before we hit the MAC with
567 E1000_WRITE_REG(hw, RCTL, 0);
568 E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP);
569 E1000_WRITE_FLUSH(hw);
571 /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
572 hw->tbi_compatibility_on = FALSE;
574 /* Delay to allow any outstanding PCI transactions to complete before
575 * resetting the device
579 ctrl = E1000_READ_REG(hw, CTRL);
581 /* Must reset the PHY before resetting the MAC */
582 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
583 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_PHY_RST));
587 /* Must acquire the MDIO ownership before MAC reset.
588 * Ownership defaults to firmware after a reset. */
589 if (hw->mac_type == e1000_82573) {
592 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
593 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
596 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
597 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
599 if (extcnf_ctrl & E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP)
602 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
609 /* Workaround for ICH8 bit corruption issue in FIFO memory */
610 if (hw->mac_type == e1000_ich8lan) {
611 /* Set Tx and Rx buffer allocation to 8k apiece. */
612 E1000_WRITE_REG(hw, PBA, E1000_PBA_8K);
613 /* Set Packet Buffer Size to 16k. */
614 E1000_WRITE_REG(hw, PBS, E1000_PBS_16K);
617 /* Issue a global reset to the MAC. This will reset the chip's
618 * transmit, receive, DMA, and link units. It will not effect
619 * the current PCI configuration. The global reset bit is self-
620 * clearing, and should clear within a microsecond.
622 DEBUGOUT("Issuing a global reset to MAC\n");
624 switch (hw->mac_type) {
630 case e1000_82541_rev_2:
631 /* These controllers can't ack the 64-bit write when issuing the
632 * reset, so use IO-mapping as a workaround to issue the reset */
633 E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
635 case e1000_82545_rev_3:
636 case e1000_82546_rev_3:
637 /* Reset is performed on a shadow of the control register */
638 E1000_WRITE_REG(hw, CTRL_DUP, (ctrl | E1000_CTRL_RST));
641 if (!hw->phy_reset_disable &&
642 e1000_check_phy_reset_block(hw) == E1000_SUCCESS) {
643 /* e1000_ich8lan PHY HW reset requires MAC CORE reset
644 * at the same time to make sure the interface between
645 * MAC and the external PHY is reset.
647 ctrl |= E1000_CTRL_PHY_RST;
650 e1000_get_software_flag(hw);
651 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
655 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
659 /* After MAC reset, force reload of EEPROM to restore power-on settings to
660 * device. Later controllers reload the EEPROM automatically, so just wait
661 * for reload to complete.
663 switch (hw->mac_type) {
664 case e1000_82542_rev2_0:
665 case e1000_82542_rev2_1:
668 /* Wait for reset to complete */
670 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
671 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
672 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
673 E1000_WRITE_FLUSH(hw);
674 /* Wait for EEPROM reload */
678 case e1000_82541_rev_2:
680 case e1000_82547_rev_2:
681 /* Wait for EEPROM reload */
685 if (e1000_is_onboard_nvm_eeprom(hw) == FALSE) {
687 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
688 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
689 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
690 E1000_WRITE_FLUSH(hw);
694 /* Auto read done will delay 5ms or poll based on mac type */
695 ret_val = e1000_get_auto_rd_done(hw);
701 /* Disable HW ARPs on ASF enabled adapters */
702 if (hw->mac_type >= e1000_82540 && hw->mac_type <= e1000_82547_rev_2) {
703 manc = E1000_READ_REG(hw, MANC);
704 manc &= ~(E1000_MANC_ARP_EN);
705 E1000_WRITE_REG(hw, MANC, manc);
708 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
709 e1000_phy_init_script(hw);
711 /* Configure activity LED after PHY reset */
712 led_ctrl = E1000_READ_REG(hw, LEDCTL);
713 led_ctrl &= IGP_ACTIVITY_LED_MASK;
714 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
715 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
718 /* Clear interrupt mask to stop board from generating interrupts */
719 DEBUGOUT("Masking off all interrupts\n");
720 E1000_WRITE_REG(hw, IMC, 0xffffffff);
722 /* Clear any pending interrupt events. */
723 icr = E1000_READ_REG(hw, ICR);
725 /* If MWI was previously enabled, reenable it. */
726 if (hw->mac_type == e1000_82542_rev2_0) {
727 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
728 e1000_pci_set_mwi(hw);
731 if (hw->mac_type == e1000_ich8lan) {
732 uint32_t kab = E1000_READ_REG(hw, KABGTXD);
733 kab |= E1000_KABGTXD_BGSQLBIAS;
734 E1000_WRITE_REG(hw, KABGTXD, kab);
737 return E1000_SUCCESS;
740 /******************************************************************************
742 * Initialize a number of hardware-dependent bits
744 * hw: Struct containing variables accessed by shared code
746 * This function contains hardware limitation workarounds for PCI-E adapters
748 *****************************************************************************/
750 e1000_initialize_hardware_bits(struct e1000_hw *hw)
752 if ((hw->mac_type >= e1000_82571) && (!hw->initialize_hw_bits_disable)) {
753 /* Settings common to all PCI-express silicon */
754 uint32_t reg_ctrl, reg_ctrl_ext;
755 uint32_t reg_tarc0, reg_tarc1;
757 uint32_t reg_txdctl, reg_txdctl1;
759 /* link autonegotiation/sync workarounds */
760 reg_tarc0 = E1000_READ_REG(hw, TARC0);
761 reg_tarc0 &= ~((1 << 30)|(1 << 29)|(1 << 28)|(1 << 27));
763 /* Enable not-done TX descriptor counting */
764 reg_txdctl = E1000_READ_REG(hw, TXDCTL);
765 reg_txdctl |= E1000_TXDCTL_COUNT_DESC;
766 E1000_WRITE_REG(hw, TXDCTL, reg_txdctl);
767 reg_txdctl1 = E1000_READ_REG(hw, TXDCTL1);
768 reg_txdctl1 |= E1000_TXDCTL_COUNT_DESC;
769 E1000_WRITE_REG(hw, TXDCTL1, reg_txdctl1);
771 switch (hw->mac_type) {
774 /* Clear PHY TX compatible mode bits */
775 reg_tarc1 = E1000_READ_REG(hw, TARC1);
776 reg_tarc1 &= ~((1 << 30)|(1 << 29));
778 /* link autonegotiation/sync workarounds */
779 reg_tarc0 |= ((1 << 26)|(1 << 25)|(1 << 24)|(1 << 23));
781 /* TX ring control fixes */
782 reg_tarc1 |= ((1 << 26)|(1 << 25)|(1 << 24));
784 /* Multiple read bit is reversed polarity */
785 reg_tctl = E1000_READ_REG(hw, TCTL);
786 if (reg_tctl & E1000_TCTL_MULR)
787 reg_tarc1 &= ~(1 << 28);
789 reg_tarc1 |= (1 << 28);
791 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
794 reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
795 reg_ctrl_ext &= ~(1 << 23);
796 reg_ctrl_ext |= (1 << 22);
798 /* TX byte count fix */
799 reg_ctrl = E1000_READ_REG(hw, CTRL);
800 reg_ctrl &= ~(1 << 29);
802 E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext);
803 E1000_WRITE_REG(hw, CTRL, reg_ctrl);
805 case e1000_80003es2lan:
806 /* improve small packet performace for fiber/serdes */
807 if ((hw->media_type == e1000_media_type_fiber) ||
808 (hw->media_type == e1000_media_type_internal_serdes)) {
809 reg_tarc0 &= ~(1 << 20);
812 /* Multiple read bit is reversed polarity */
813 reg_tctl = E1000_READ_REG(hw, TCTL);
814 reg_tarc1 = E1000_READ_REG(hw, TARC1);
815 if (reg_tctl & E1000_TCTL_MULR)
816 reg_tarc1 &= ~(1 << 28);
818 reg_tarc1 |= (1 << 28);
820 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
823 /* Reduce concurrent DMA requests to 3 from 4 */
824 if ((hw->revision_id < 3) ||
825 ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) &&
826 (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))
827 reg_tarc0 |= ((1 << 29)|(1 << 28));
829 reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
830 reg_ctrl_ext |= (1 << 22);
831 E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext);
833 /* workaround TX hang with TSO=on */
834 reg_tarc0 |= ((1 << 27)|(1 << 26)|(1 << 24)|(1 << 23));
836 /* Multiple read bit is reversed polarity */
837 reg_tctl = E1000_READ_REG(hw, TCTL);
838 reg_tarc1 = E1000_READ_REG(hw, TARC1);
839 if (reg_tctl & E1000_TCTL_MULR)
840 reg_tarc1 &= ~(1 << 28);
842 reg_tarc1 |= (1 << 28);
844 /* workaround TX hang with TSO=on */
845 reg_tarc1 |= ((1 << 30)|(1 << 26)|(1 << 24));
847 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
853 E1000_WRITE_REG(hw, TARC0, reg_tarc0);
857 /******************************************************************************
858 * Performs basic configuration of the adapter.
860 * hw - Struct containing variables accessed by shared code
862 * Assumes that the controller has previously been reset and is in a
863 * post-reset uninitialized state. Initializes the receive address registers,
864 * multicast table, and VLAN filter table. Calls routines to setup link
865 * configuration and flow control settings. Clears all on-chip counters. Leaves
866 * the transmit and receive units disabled and uninitialized.
867 *****************************************************************************/
869 e1000_init_hw(struct e1000_hw *hw)
874 uint16_t pcix_cmd_word;
875 uint16_t pcix_stat_hi_word;
882 DEBUGFUNC("e1000_init_hw");
884 /* force full DMA clock frequency for 10/100 on ICH8 A0-B0 */
885 if ((hw->mac_type == e1000_ich8lan) &&
886 ((hw->revision_id < 3) ||
887 ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) &&
888 (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))) {
889 reg_data = E1000_READ_REG(hw, STATUS);
890 reg_data &= ~0x80000000;
891 E1000_WRITE_REG(hw, STATUS, reg_data);
894 /* Initialize Identification LED */
895 ret_val = e1000_id_led_init(hw);
897 DEBUGOUT("Error Initializing Identification LED\n");
901 /* Set the media type and TBI compatibility */
902 e1000_set_media_type(hw);
904 /* Must be called after e1000_set_media_type because media_type is used */
905 e1000_initialize_hardware_bits(hw);
907 /* Disabling VLAN filtering. */
908 DEBUGOUT("Initializing the IEEE VLAN\n");
909 /* VET hardcoded to standard value and VFTA removed in ICH8 LAN */
910 if (hw->mac_type != e1000_ich8lan) {
911 if (hw->mac_type < e1000_82545_rev_3)
912 E1000_WRITE_REG(hw, VET, 0);
913 e1000_clear_vfta(hw);
916 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
917 if (hw->mac_type == e1000_82542_rev2_0) {
918 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
919 e1000_pci_clear_mwi(hw);
920 E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST);
921 E1000_WRITE_FLUSH(hw);
925 /* Setup the receive address. This involves initializing all of the Receive
926 * Address Registers (RARs 0 - 15).
928 e1000_init_rx_addrs(hw);
930 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
931 if (hw->mac_type == e1000_82542_rev2_0) {
932 E1000_WRITE_REG(hw, RCTL, 0);
933 E1000_WRITE_FLUSH(hw);
935 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
936 e1000_pci_set_mwi(hw);
939 /* Zero out the Multicast HASH table */
940 DEBUGOUT("Zeroing the MTA\n");
941 mta_size = E1000_MC_TBL_SIZE;
942 if (hw->mac_type == e1000_ich8lan)
943 mta_size = E1000_MC_TBL_SIZE_ICH8LAN;
944 for (i = 0; i < mta_size; i++) {
945 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
946 /* use write flush to prevent Memory Write Block (MWB) from
947 * occuring when accessing our register space */
948 E1000_WRITE_FLUSH(hw);
951 /* Set the PCI priority bit correctly in the CTRL register. This
952 * determines if the adapter gives priority to receives, or if it
953 * gives equal priority to transmits and receives. Valid only on
954 * 82542 and 82543 silicon.
956 if (hw->dma_fairness && hw->mac_type <= e1000_82543) {
957 ctrl = E1000_READ_REG(hw, CTRL);
958 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PRIOR);
961 switch (hw->mac_type) {
962 case e1000_82545_rev_3:
963 case e1000_82546_rev_3:
966 /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
967 if (hw->bus_type == e1000_bus_type_pcix) {
968 e1000_read_pci_cfg(hw, PCIX_COMMAND_REGISTER, &pcix_cmd_word);
969 e1000_read_pci_cfg(hw, PCIX_STATUS_REGISTER_HI,
971 cmd_mmrbc = (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >>
972 PCIX_COMMAND_MMRBC_SHIFT;
973 stat_mmrbc = (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
974 PCIX_STATUS_HI_MMRBC_SHIFT;
975 if (stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
976 stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
977 if (cmd_mmrbc > stat_mmrbc) {
978 pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK;
979 pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
980 e1000_write_pci_cfg(hw, PCIX_COMMAND_REGISTER,
987 /* More time needed for PHY to initialize */
988 if (hw->mac_type == e1000_ich8lan)
991 /* Call a subroutine to configure the link and setup flow control. */
992 ret_val = e1000_setup_link(hw);
994 /* Set the transmit descriptor write-back policy */
995 if (hw->mac_type > e1000_82544) {
996 ctrl = E1000_READ_REG(hw, TXDCTL);
997 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
998 E1000_WRITE_REG(hw, TXDCTL, ctrl);
1001 if (hw->mac_type == e1000_82573) {
1002 e1000_enable_tx_pkt_filtering(hw);
1005 switch (hw->mac_type) {
1008 case e1000_80003es2lan:
1009 /* Enable retransmit on late collisions */
1010 reg_data = E1000_READ_REG(hw, TCTL);
1011 reg_data |= E1000_TCTL_RTLC;
1012 E1000_WRITE_REG(hw, TCTL, reg_data);
1014 /* Configure Gigabit Carry Extend Padding */
1015 reg_data = E1000_READ_REG(hw, TCTL_EXT);
1016 reg_data &= ~E1000_TCTL_EXT_GCEX_MASK;
1017 reg_data |= DEFAULT_80003ES2LAN_TCTL_EXT_GCEX;
1018 E1000_WRITE_REG(hw, TCTL_EXT, reg_data);
1020 /* Configure Transmit Inter-Packet Gap */
1021 reg_data = E1000_READ_REG(hw, TIPG);
1022 reg_data &= ~E1000_TIPG_IPGT_MASK;
1023 reg_data |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
1024 E1000_WRITE_REG(hw, TIPG, reg_data);
1026 reg_data = E1000_READ_REG_ARRAY(hw, FFLT, 0x0001);
1027 reg_data &= ~0x00100000;
1028 E1000_WRITE_REG_ARRAY(hw, FFLT, 0x0001, reg_data);
1033 ctrl = E1000_READ_REG(hw, TXDCTL1);
1034 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
1035 E1000_WRITE_REG(hw, TXDCTL1, ctrl);
1040 if (hw->mac_type == e1000_82573) {
1041 uint32_t gcr = E1000_READ_REG(hw, GCR);
1042 gcr |= E1000_GCR_L1_ACT_WITHOUT_L0S_RX;
1043 E1000_WRITE_REG(hw, GCR, gcr);
1046 /* Clear all of the statistics registers (clear on read). It is
1047 * important that we do this after we have tried to establish link
1048 * because the symbol error count will increment wildly if there
1051 e1000_clear_hw_cntrs(hw);
1053 /* ICH8 No-snoop bits are opposite polarity.
1054 * Set to snoop by default after reset. */
1055 if (hw->mac_type == e1000_ich8lan)
1056 e1000_set_pci_ex_no_snoop(hw, PCI_EX_82566_SNOOP_ALL);
1058 if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER ||
1059 hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) {
1060 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
1061 /* Relaxed ordering must be disabled to avoid a parity
1062 * error crash in a PCI slot. */
1063 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
1064 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1070 /******************************************************************************
1071 * Adjust SERDES output amplitude based on EEPROM setting.
1073 * hw - Struct containing variables accessed by shared code.
1074 *****************************************************************************/
1076 e1000_adjust_serdes_amplitude(struct e1000_hw *hw)
1078 uint16_t eeprom_data;
1081 DEBUGFUNC("e1000_adjust_serdes_amplitude");
1083 if (hw->media_type != e1000_media_type_internal_serdes)
1084 return E1000_SUCCESS;
1086 switch (hw->mac_type) {
1087 case e1000_82545_rev_3:
1088 case e1000_82546_rev_3:
1091 return E1000_SUCCESS;
1094 ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1, &eeprom_data);
1099 if (eeprom_data != EEPROM_RESERVED_WORD) {
1100 /* Adjust SERDES output amplitude only. */
1101 eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK;
1102 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data);
1107 return E1000_SUCCESS;
1110 /******************************************************************************
1111 * Configures flow control and link settings.
1113 * hw - Struct containing variables accessed by shared code
1115 * Determines which flow control settings to use. Calls the apropriate media-
1116 * specific link configuration function. Configures the flow control settings.
1117 * Assuming the adapter has a valid link partner, a valid link should be
1118 * established. Assumes the hardware has previously been reset and the
1119 * transmitter and receiver are not enabled.
1120 *****************************************************************************/
1122 e1000_setup_link(struct e1000_hw *hw)
1126 uint16_t eeprom_data;
1128 DEBUGFUNC("e1000_setup_link");
1130 /* In the case of the phy reset being blocked, we already have a link.
1131 * We do not have to set it up again. */
1132 if (e1000_check_phy_reset_block(hw))
1133 return E1000_SUCCESS;
1135 /* Read and store word 0x0F of the EEPROM. This word contains bits
1136 * that determine the hardware's default PAUSE (flow control) mode,
1137 * a bit that determines whether the HW defaults to enabling or
1138 * disabling auto-negotiation, and the direction of the
1139 * SW defined pins. If there is no SW over-ride of the flow
1140 * control setting, then the variable hw->fc will
1141 * be initialized based on a value in the EEPROM.
1143 if (hw->fc == E1000_FC_DEFAULT) {
1144 switch (hw->mac_type) {
1147 hw->fc = E1000_FC_FULL;
1150 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
1153 DEBUGOUT("EEPROM Read Error\n");
1154 return -E1000_ERR_EEPROM;
1156 if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
1157 hw->fc = E1000_FC_NONE;
1158 else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
1159 EEPROM_WORD0F_ASM_DIR)
1160 hw->fc = E1000_FC_TX_PAUSE;
1162 hw->fc = E1000_FC_FULL;
1167 /* We want to save off the original Flow Control configuration just
1168 * in case we get disconnected and then reconnected into a different
1169 * hub or switch with different Flow Control capabilities.
1171 if (hw->mac_type == e1000_82542_rev2_0)
1172 hw->fc &= (~E1000_FC_TX_PAUSE);
1174 if ((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
1175 hw->fc &= (~E1000_FC_RX_PAUSE);
1177 hw->original_fc = hw->fc;
1179 DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc);
1181 /* Take the 4 bits from EEPROM word 0x0F that determine the initial
1182 * polarity value for the SW controlled pins, and setup the
1183 * Extended Device Control reg with that info.
1184 * This is needed because one of the SW controlled pins is used for
1185 * signal detection. So this should be done before e1000_setup_pcs_link()
1186 * or e1000_phy_setup() is called.
1188 if (hw->mac_type == e1000_82543) {
1189 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
1192 DEBUGOUT("EEPROM Read Error\n");
1193 return -E1000_ERR_EEPROM;
1195 ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
1197 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1200 /* Call the necessary subroutine to configure the link. */
1201 ret_val = (hw->media_type == e1000_media_type_copper) ?
1202 e1000_setup_copper_link(hw) :
1203 e1000_setup_fiber_serdes_link(hw);
1205 /* Initialize the flow control address, type, and PAUSE timer
1206 * registers to their default values. This is done even if flow
1207 * control is disabled, because it does not hurt anything to
1208 * initialize these registers.
1210 DEBUGOUT("Initializing the Flow Control address, type and timer regs\n");
1212 /* FCAL/H and FCT are hardcoded to standard values in e1000_ich8lan. */
1213 if (hw->mac_type != e1000_ich8lan) {
1214 E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
1215 E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
1216 E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
1219 E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
1221 /* Set the flow control receive threshold registers. Normally,
1222 * these registers will be set to a default threshold that may be
1223 * adjusted later by the driver's runtime code. However, if the
1224 * ability to transmit pause frames in not enabled, then these
1225 * registers will be set to 0.
1227 if (!(hw->fc & E1000_FC_TX_PAUSE)) {
1228 E1000_WRITE_REG(hw, FCRTL, 0);
1229 E1000_WRITE_REG(hw, FCRTH, 0);
1231 /* We need to set up the Receive Threshold high and low water marks
1232 * as well as (optionally) enabling the transmission of XON frames.
1234 if (hw->fc_send_xon) {
1235 E1000_WRITE_REG(hw, FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE));
1236 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
1238 E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water);
1239 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
1245 /******************************************************************************
1246 * Sets up link for a fiber based or serdes based adapter
1248 * hw - Struct containing variables accessed by shared code
1250 * Manipulates Physical Coding Sublayer functions in order to configure
1251 * link. Assumes the hardware has been previously reset and the transmitter
1252 * and receiver are not enabled.
1253 *****************************************************************************/
1255 e1000_setup_fiber_serdes_link(struct e1000_hw *hw)
1261 uint32_t signal = 0;
1264 DEBUGFUNC("e1000_setup_fiber_serdes_link");
1266 /* On 82571 and 82572 Fiber connections, SerDes loopback mode persists
1267 * until explicitly turned off or a power cycle is performed. A read to
1268 * the register does not indicate its status. Therefore, we ensure
1269 * loopback mode is disabled during initialization.
1271 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572)
1272 E1000_WRITE_REG(hw, SCTL, E1000_DISABLE_SERDES_LOOPBACK);
1274 /* On adapters with a MAC newer than 82544, SWDP 1 will be
1275 * set when the optics detect a signal. On older adapters, it will be
1276 * cleared when there is a signal. This applies to fiber media only.
1277 * If we're on serdes media, adjust the output amplitude to value
1278 * set in the EEPROM.
1280 ctrl = E1000_READ_REG(hw, CTRL);
1281 if (hw->media_type == e1000_media_type_fiber)
1282 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
1284 ret_val = e1000_adjust_serdes_amplitude(hw);
1288 /* Take the link out of reset */
1289 ctrl &= ~(E1000_CTRL_LRST);
1291 /* Adjust VCO speed to improve BER performance */
1292 ret_val = e1000_set_vco_speed(hw);
1296 e1000_config_collision_dist(hw);
1298 /* Check for a software override of the flow control settings, and setup
1299 * the device accordingly. If auto-negotiation is enabled, then software
1300 * will have to set the "PAUSE" bits to the correct value in the Tranmsit
1301 * Config Word Register (TXCW) and re-start auto-negotiation. However, if
1302 * auto-negotiation is disabled, then software will have to manually
1303 * configure the two flow control enable bits in the CTRL register.
1305 * The possible values of the "fc" parameter are:
1306 * 0: Flow control is completely disabled
1307 * 1: Rx flow control is enabled (we can receive pause frames, but
1308 * not send pause frames).
1309 * 2: Tx flow control is enabled (we can send pause frames but we do
1310 * not support receiving pause frames).
1311 * 3: Both Rx and TX flow control (symmetric) are enabled.
1315 /* Flow control is completely disabled by a software over-ride. */
1316 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
1318 case E1000_FC_RX_PAUSE:
1319 /* RX Flow control is enabled and TX Flow control is disabled by a
1320 * software over-ride. Since there really isn't a way to advertise
1321 * that we are capable of RX Pause ONLY, we will advertise that we
1322 * support both symmetric and asymmetric RX PAUSE. Later, we will
1323 * disable the adapter's ability to send PAUSE frames.
1325 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1327 case E1000_FC_TX_PAUSE:
1328 /* TX Flow control is enabled, and RX Flow control is disabled, by a
1329 * software over-ride.
1331 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
1334 /* Flow control (both RX and TX) is enabled by a software over-ride. */
1335 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1338 DEBUGOUT("Flow control param set incorrectly\n");
1339 return -E1000_ERR_CONFIG;
1343 /* Since auto-negotiation is enabled, take the link out of reset (the link
1344 * will be in reset, because we previously reset the chip). This will
1345 * restart auto-negotiation. If auto-neogtiation is successful then the
1346 * link-up status bit will be set and the flow control enable bits (RFCE
1347 * and TFCE) will be set according to their negotiated value.
1349 DEBUGOUT("Auto-negotiation enabled\n");
1351 E1000_WRITE_REG(hw, TXCW, txcw);
1352 E1000_WRITE_REG(hw, CTRL, ctrl);
1353 E1000_WRITE_FLUSH(hw);
1358 /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
1359 * indication in the Device Status Register. Time-out if a link isn't
1360 * seen in 500 milliseconds seconds (Auto-negotiation should complete in
1361 * less than 500 milliseconds even if the other end is doing it in SW).
1362 * For internal serdes, we just assume a signal is present, then poll.
1364 if (hw->media_type == e1000_media_type_internal_serdes ||
1365 (E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) {
1366 DEBUGOUT("Looking for Link\n");
1367 for (i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
1369 status = E1000_READ_REG(hw, STATUS);
1370 if (status & E1000_STATUS_LU) break;
1372 if (i == (LINK_UP_TIMEOUT / 10)) {
1373 DEBUGOUT("Never got a valid link from auto-neg!!!\n");
1374 hw->autoneg_failed = 1;
1375 /* AutoNeg failed to achieve a link, so we'll call
1376 * e1000_check_for_link. This routine will force the link up if
1377 * we detect a signal. This will allow us to communicate with
1378 * non-autonegotiating link partners.
1380 ret_val = e1000_check_for_link(hw);
1382 DEBUGOUT("Error while checking for link\n");
1385 hw->autoneg_failed = 0;
1387 hw->autoneg_failed = 0;
1388 DEBUGOUT("Valid Link Found\n");
1391 DEBUGOUT("No Signal Detected\n");
1393 return E1000_SUCCESS;
1396 /******************************************************************************
1397 * Make sure we have a valid PHY and change PHY mode before link setup.
1399 * hw - Struct containing variables accessed by shared code
1400 ******************************************************************************/
1402 e1000_copper_link_preconfig(struct e1000_hw *hw)
1408 DEBUGFUNC("e1000_copper_link_preconfig");
1410 ctrl = E1000_READ_REG(hw, CTRL);
1411 /* With 82543, we need to force speed and duplex on the MAC equal to what
1412 * the PHY speed and duplex configuration is. In addition, we need to
1413 * perform a hardware reset on the PHY to take it out of reset.
1415 if (hw->mac_type > e1000_82543) {
1416 ctrl |= E1000_CTRL_SLU;
1417 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1418 E1000_WRITE_REG(hw, CTRL, ctrl);
1420 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
1421 E1000_WRITE_REG(hw, CTRL, ctrl);
1422 ret_val = e1000_phy_hw_reset(hw);
1427 /* Make sure we have a valid PHY */
1428 ret_val = e1000_detect_gig_phy(hw);
1430 DEBUGOUT("Error, did not detect valid phy.\n");
1433 DEBUGOUT1("Phy ID = %x \n", hw->phy_id);
1435 /* Set PHY to class A mode (if necessary) */
1436 ret_val = e1000_set_phy_mode(hw);
1440 if ((hw->mac_type == e1000_82545_rev_3) ||
1441 (hw->mac_type == e1000_82546_rev_3)) {
1442 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1443 phy_data |= 0x00000008;
1444 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1447 if (hw->mac_type <= e1000_82543 ||
1448 hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
1449 hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2)
1450 hw->phy_reset_disable = FALSE;
1452 return E1000_SUCCESS;
1456 /********************************************************************
1457 * Copper link setup for e1000_phy_igp series.
1459 * hw - Struct containing variables accessed by shared code
1460 *********************************************************************/
1462 e1000_copper_link_igp_setup(struct e1000_hw *hw)
1468 DEBUGFUNC("e1000_copper_link_igp_setup");
1470 if (hw->phy_reset_disable)
1471 return E1000_SUCCESS;
1473 ret_val = e1000_phy_reset(hw);
1475 DEBUGOUT("Error Resetting the PHY\n");
1479 /* Wait 15ms for MAC to configure PHY from eeprom settings */
1481 if (hw->mac_type != e1000_ich8lan) {
1482 /* Configure activity LED after PHY reset */
1483 led_ctrl = E1000_READ_REG(hw, LEDCTL);
1484 led_ctrl &= IGP_ACTIVITY_LED_MASK;
1485 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
1486 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
1489 /* The NVM settings will configure LPLU in D3 for IGP2 and IGP3 PHYs */
1490 if (hw->phy_type == e1000_phy_igp) {
1491 /* disable lplu d3 during driver init */
1492 ret_val = e1000_set_d3_lplu_state(hw, FALSE);
1494 DEBUGOUT("Error Disabling LPLU D3\n");
1499 /* disable lplu d0 during driver init */
1500 ret_val = e1000_set_d0_lplu_state(hw, FALSE);
1502 DEBUGOUT("Error Disabling LPLU D0\n");
1505 /* Configure mdi-mdix settings */
1506 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1510 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
1511 hw->dsp_config_state = e1000_dsp_config_disabled;
1512 /* Force MDI for earlier revs of the IGP PHY */
1513 phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX | IGP01E1000_PSCR_FORCE_MDI_MDIX);
1517 hw->dsp_config_state = e1000_dsp_config_enabled;
1518 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1522 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1525 phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
1529 phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
1533 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1537 /* set auto-master slave resolution settings */
1539 e1000_ms_type phy_ms_setting = hw->master_slave;
1541 if (hw->ffe_config_state == e1000_ffe_config_active)
1542 hw->ffe_config_state = e1000_ffe_config_enabled;
1544 if (hw->dsp_config_state == e1000_dsp_config_activated)
1545 hw->dsp_config_state = e1000_dsp_config_enabled;
1547 /* when autonegotiation advertisment is only 1000Mbps then we
1548 * should disable SmartSpeed and enable Auto MasterSlave
1549 * resolution as hardware default. */
1550 if (hw->autoneg_advertised == ADVERTISE_1000_FULL) {
1551 /* Disable SmartSpeed */
1552 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1556 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1557 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1561 /* Set auto Master/Slave resolution process */
1562 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1565 phy_data &= ~CR_1000T_MS_ENABLE;
1566 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1571 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1575 /* load defaults for future use */
1576 hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
1577 ((phy_data & CR_1000T_MS_VALUE) ?
1578 e1000_ms_force_master :
1579 e1000_ms_force_slave) :
1582 switch (phy_ms_setting) {
1583 case e1000_ms_force_master:
1584 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
1586 case e1000_ms_force_slave:
1587 phy_data |= CR_1000T_MS_ENABLE;
1588 phy_data &= ~(CR_1000T_MS_VALUE);
1591 phy_data &= ~CR_1000T_MS_ENABLE;
1595 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1600 return E1000_SUCCESS;
1603 /********************************************************************
1604 * Copper link setup for e1000_phy_gg82563 series.
1606 * hw - Struct containing variables accessed by shared code
1607 *********************************************************************/
1609 e1000_copper_link_ggp_setup(struct e1000_hw *hw)
1615 DEBUGFUNC("e1000_copper_link_ggp_setup");
1617 if (!hw->phy_reset_disable) {
1619 /* Enable CRS on TX for half-duplex operation. */
1620 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL,
1625 phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
1626 /* Use 25MHz for both link down and 1000BASE-T for Tx clock */
1627 phy_data |= GG82563_MSCR_TX_CLK_1000MBPS_25MHZ;
1629 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL,
1635 * MDI/MDI-X = 0 (default)
1636 * 0 - Auto for all speeds
1639 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1641 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_SPEC_CTRL, &phy_data);
1645 phy_data &= ~GG82563_PSCR_CROSSOVER_MODE_MASK;
1649 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDI;
1652 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDIX;
1656 phy_data |= GG82563_PSCR_CROSSOVER_MODE_AUTO;
1661 * disable_polarity_correction = 0 (default)
1662 * Automatic Correction for Reversed Cable Polarity
1666 phy_data &= ~GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
1667 if (hw->disable_polarity_correction == 1)
1668 phy_data |= GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
1669 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_SPEC_CTRL, phy_data);
1674 /* SW Reset the PHY so all changes take effect */
1675 ret_val = e1000_phy_reset(hw);
1677 DEBUGOUT("Error Resetting the PHY\n");
1680 } /* phy_reset_disable */
1682 if (hw->mac_type == e1000_80003es2lan) {
1683 /* Bypass RX and TX FIFO's */
1684 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_FIFO_CTRL,
1685 E1000_KUMCTRLSTA_FIFO_CTRL_RX_BYPASS |
1686 E1000_KUMCTRLSTA_FIFO_CTRL_TX_BYPASS);
1690 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_SPEC_CTRL_2, &phy_data);
1694 phy_data &= ~GG82563_PSCR2_REVERSE_AUTO_NEG;
1695 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_SPEC_CTRL_2, phy_data);
1700 reg_data = E1000_READ_REG(hw, CTRL_EXT);
1701 reg_data &= ~(E1000_CTRL_EXT_LINK_MODE_MASK);
1702 E1000_WRITE_REG(hw, CTRL_EXT, reg_data);
1704 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_PWR_MGMT_CTRL,
1709 /* Do not init these registers when the HW is in IAMT mode, since the
1710 * firmware will have already initialized them. We only initialize
1711 * them if the HW is not in IAMT mode.
1713 if (e1000_check_mng_mode(hw) == FALSE) {
1714 /* Enable Electrical Idle on the PHY */
1715 phy_data |= GG82563_PMCR_ENABLE_ELECTRICAL_IDLE;
1716 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_PWR_MGMT_CTRL,
1721 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
1726 phy_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
1727 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
1734 /* Workaround: Disable padding in Kumeran interface in the MAC
1735 * and in the PHY to avoid CRC errors.
1737 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_INBAND_CTRL,
1741 phy_data |= GG82563_ICR_DIS_PADDING;
1742 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_INBAND_CTRL,
1748 return E1000_SUCCESS;
1751 /********************************************************************
1752 * Copper link setup for e1000_phy_m88 series.
1754 * hw - Struct containing variables accessed by shared code
1755 *********************************************************************/
1757 e1000_copper_link_mgp_setup(struct e1000_hw *hw)
1762 DEBUGFUNC("e1000_copper_link_mgp_setup");
1764 if (hw->phy_reset_disable)
1765 return E1000_SUCCESS;
1767 /* Enable CRS on TX. This must be set for half-duplex operation. */
1768 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1772 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1775 * MDI/MDI-X = 0 (default)
1776 * 0 - Auto for all speeds
1779 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1781 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1785 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
1788 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
1791 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
1795 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
1800 * disable_polarity_correction = 0 (default)
1801 * Automatic Correction for Reversed Cable Polarity
1805 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
1806 if (hw->disable_polarity_correction == 1)
1807 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
1808 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1812 if (hw->phy_revision < M88E1011_I_REV_4) {
1813 /* Force TX_CLK in the Extended PHY Specific Control Register
1816 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1820 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1822 if ((hw->phy_revision == E1000_REVISION_2) &&
1823 (hw->phy_id == M88E1111_I_PHY_ID)) {
1824 /* Vidalia Phy, set the downshift counter to 5x */
1825 phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK);
1826 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
1827 ret_val = e1000_write_phy_reg(hw,
1828 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1832 /* Configure Master and Slave downshift values */
1833 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
1834 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
1835 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
1836 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
1837 ret_val = e1000_write_phy_reg(hw,
1838 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1844 /* SW Reset the PHY so all changes take effect */
1845 ret_val = e1000_phy_reset(hw);
1847 DEBUGOUT("Error Resetting the PHY\n");
1851 return E1000_SUCCESS;
1854 /********************************************************************
1855 * Setup auto-negotiation and flow control advertisements,
1856 * and then perform auto-negotiation.
1858 * hw - Struct containing variables accessed by shared code
1859 *********************************************************************/
1861 e1000_copper_link_autoneg(struct e1000_hw *hw)
1866 DEBUGFUNC("e1000_copper_link_autoneg");
1868 /* Perform some bounds checking on the hw->autoneg_advertised
1869 * parameter. If this variable is zero, then set it to the default.
1871 hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
1873 /* If autoneg_advertised is zero, we assume it was not defaulted
1874 * by the calling code so we set to advertise full capability.
1876 if (hw->autoneg_advertised == 0)
1877 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
1879 /* IFE phy only supports 10/100 */
1880 if (hw->phy_type == e1000_phy_ife)
1881 hw->autoneg_advertised &= AUTONEG_ADVERTISE_10_100_ALL;
1883 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
1884 ret_val = e1000_phy_setup_autoneg(hw);
1886 DEBUGOUT("Error Setting up Auto-Negotiation\n");
1889 DEBUGOUT("Restarting Auto-Neg\n");
1891 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
1892 * the Auto Neg Restart bit in the PHY control register.
1894 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
1898 phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
1899 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
1903 /* Does the user want to wait for Auto-Neg to complete here, or
1904 * check at a later time (for example, callback routine).
1906 if (hw->wait_autoneg_complete) {
1907 ret_val = e1000_wait_autoneg(hw);
1909 DEBUGOUT("Error while waiting for autoneg to complete\n");
1914 hw->get_link_status = TRUE;
1916 return E1000_SUCCESS;
1919 /******************************************************************************
1920 * Config the MAC and the PHY after link is up.
1921 * 1) Set up the MAC to the current PHY speed/duplex
1922 * if we are on 82543. If we
1923 * are on newer silicon, we only need to configure
1924 * collision distance in the Transmit Control Register.
1925 * 2) Set up flow control on the MAC to that established with
1927 * 3) Config DSP to improve Gigabit link quality for some PHY revisions.
1929 * hw - Struct containing variables accessed by shared code
1930 ******************************************************************************/
1932 e1000_copper_link_postconfig(struct e1000_hw *hw)
1935 DEBUGFUNC("e1000_copper_link_postconfig");
1937 if (hw->mac_type >= e1000_82544) {
1938 e1000_config_collision_dist(hw);
1940 ret_val = e1000_config_mac_to_phy(hw);
1942 DEBUGOUT("Error configuring MAC to PHY settings\n");
1946 ret_val = e1000_config_fc_after_link_up(hw);
1948 DEBUGOUT("Error Configuring Flow Control\n");
1952 /* Config DSP to improve Giga link quality */
1953 if (hw->phy_type == e1000_phy_igp) {
1954 ret_val = e1000_config_dsp_after_link_change(hw, TRUE);
1956 DEBUGOUT("Error Configuring DSP after link up\n");
1961 return E1000_SUCCESS;
1964 /******************************************************************************
1965 * Detects which PHY is present and setup the speed and duplex
1967 * hw - Struct containing variables accessed by shared code
1968 ******************************************************************************/
1970 e1000_setup_copper_link(struct e1000_hw *hw)
1977 DEBUGFUNC("e1000_setup_copper_link");
1979 switch (hw->mac_type) {
1980 case e1000_80003es2lan:
1982 /* Set the mac to wait the maximum time between each
1983 * iteration and increase the max iterations when
1984 * polling the phy; this fixes erroneous timeouts at 10Mbps. */
1985 ret_val = e1000_write_kmrn_reg(hw, GG82563_REG(0x34, 4), 0xFFFF);
1988 ret_val = e1000_read_kmrn_reg(hw, GG82563_REG(0x34, 9), ®_data);
1992 ret_val = e1000_write_kmrn_reg(hw, GG82563_REG(0x34, 9), reg_data);
1999 /* Check if it is a valid PHY and set PHY mode if necessary. */
2000 ret_val = e1000_copper_link_preconfig(hw);
2004 switch (hw->mac_type) {
2005 case e1000_80003es2lan:
2006 /* Kumeran registers are written-only */
2007 reg_data = E1000_KUMCTRLSTA_INB_CTRL_LINK_STATUS_TX_TIMEOUT_DEFAULT;
2008 reg_data |= E1000_KUMCTRLSTA_INB_CTRL_DIS_PADDING;
2009 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_INB_CTRL,
2018 if (hw->phy_type == e1000_phy_igp ||
2019 hw->phy_type == e1000_phy_igp_3 ||
2020 hw->phy_type == e1000_phy_igp_2) {
2021 ret_val = e1000_copper_link_igp_setup(hw);
2024 } else if (hw->phy_type == e1000_phy_m88) {
2025 ret_val = e1000_copper_link_mgp_setup(hw);
2028 } else if (hw->phy_type == e1000_phy_gg82563) {
2029 ret_val = e1000_copper_link_ggp_setup(hw);
2035 /* Setup autoneg and flow control advertisement
2036 * and perform autonegotiation */
2037 ret_val = e1000_copper_link_autoneg(hw);
2041 /* PHY will be set to 10H, 10F, 100H,or 100F
2042 * depending on value from forced_speed_duplex. */
2043 DEBUGOUT("Forcing speed and duplex\n");
2044 ret_val = e1000_phy_force_speed_duplex(hw);
2046 DEBUGOUT("Error Forcing Speed and Duplex\n");
2051 /* Check link status. Wait up to 100 microseconds for link to become
2054 for (i = 0; i < 10; i++) {
2055 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2058 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2062 if (phy_data & MII_SR_LINK_STATUS) {
2063 /* Config the MAC and PHY after link is up */
2064 ret_val = e1000_copper_link_postconfig(hw);
2068 DEBUGOUT("Valid link established!!!\n");
2069 return E1000_SUCCESS;
2074 DEBUGOUT("Unable to establish link!!!\n");
2075 return E1000_SUCCESS;
2078 /******************************************************************************
2079 * Configure the MAC-to-PHY interface for 10/100Mbps
2081 * hw - Struct containing variables accessed by shared code
2082 ******************************************************************************/
2084 e1000_configure_kmrn_for_10_100(struct e1000_hw *hw, uint16_t duplex)
2086 int32_t ret_val = E1000_SUCCESS;
2090 DEBUGFUNC("e1000_configure_kmrn_for_10_100");
2092 reg_data = E1000_KUMCTRLSTA_HD_CTRL_10_100_DEFAULT;
2093 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_HD_CTRL,
2098 /* Configure Transmit Inter-Packet Gap */
2099 tipg = E1000_READ_REG(hw, TIPG);
2100 tipg &= ~E1000_TIPG_IPGT_MASK;
2101 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_10_100;
2102 E1000_WRITE_REG(hw, TIPG, tipg);
2104 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, ®_data);
2109 if (duplex == HALF_DUPLEX)
2110 reg_data |= GG82563_KMCR_PASS_FALSE_CARRIER;
2112 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
2114 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
2120 e1000_configure_kmrn_for_1000(struct e1000_hw *hw)
2122 int32_t ret_val = E1000_SUCCESS;
2126 DEBUGFUNC("e1000_configure_kmrn_for_1000");
2128 reg_data = E1000_KUMCTRLSTA_HD_CTRL_1000_DEFAULT;
2129 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_HD_CTRL,
2134 /* Configure Transmit Inter-Packet Gap */
2135 tipg = E1000_READ_REG(hw, TIPG);
2136 tipg &= ~E1000_TIPG_IPGT_MASK;
2137 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
2138 E1000_WRITE_REG(hw, TIPG, tipg);
2140 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, ®_data);
2145 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
2146 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
2151 /******************************************************************************
2152 * Configures PHY autoneg and flow control advertisement settings
2154 * hw - Struct containing variables accessed by shared code
2155 ******************************************************************************/
2157 e1000_phy_setup_autoneg(struct e1000_hw *hw)
2160 uint16_t mii_autoneg_adv_reg;
2161 uint16_t mii_1000t_ctrl_reg;
2163 DEBUGFUNC("e1000_phy_setup_autoneg");
2165 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
2166 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
2170 if (hw->phy_type != e1000_phy_ife) {
2171 /* Read the MII 1000Base-T Control Register (Address 9). */
2172 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
2176 mii_1000t_ctrl_reg=0;
2178 /* Need to parse both autoneg_advertised and fc and set up
2179 * the appropriate PHY registers. First we will parse for
2180 * autoneg_advertised software override. Since we can advertise
2181 * a plethora of combinations, we need to check each bit
2185 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
2186 * Advertisement Register (Address 4) and the 1000 mb speed bits in
2187 * the 1000Base-T Control Register (Address 9).
2189 mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
2190 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
2192 DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised);
2194 /* Do we want to advertise 10 Mb Half Duplex? */
2195 if (hw->autoneg_advertised & ADVERTISE_10_HALF) {
2196 DEBUGOUT("Advertise 10mb Half duplex\n");
2197 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
2200 /* Do we want to advertise 10 Mb Full Duplex? */
2201 if (hw->autoneg_advertised & ADVERTISE_10_FULL) {
2202 DEBUGOUT("Advertise 10mb Full duplex\n");
2203 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
2206 /* Do we want to advertise 100 Mb Half Duplex? */
2207 if (hw->autoneg_advertised & ADVERTISE_100_HALF) {
2208 DEBUGOUT("Advertise 100mb Half duplex\n");
2209 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
2212 /* Do we want to advertise 100 Mb Full Duplex? */
2213 if (hw->autoneg_advertised & ADVERTISE_100_FULL) {
2214 DEBUGOUT("Advertise 100mb Full duplex\n");
2215 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
2218 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
2219 if (hw->autoneg_advertised & ADVERTISE_1000_HALF) {
2220 DEBUGOUT("Advertise 1000mb Half duplex requested, request denied!\n");
2223 /* Do we want to advertise 1000 Mb Full Duplex? */
2224 if (hw->autoneg_advertised & ADVERTISE_1000_FULL) {
2225 DEBUGOUT("Advertise 1000mb Full duplex\n");
2226 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
2227 if (hw->phy_type == e1000_phy_ife) {
2228 DEBUGOUT("e1000_phy_ife is a 10/100 PHY. Gigabit speed is not supported.\n");
2232 /* Check for a software override of the flow control settings, and
2233 * setup the PHY advertisement registers accordingly. If
2234 * auto-negotiation is enabled, then software will have to set the
2235 * "PAUSE" bits to the correct value in the Auto-Negotiation
2236 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
2238 * The possible values of the "fc" parameter are:
2239 * 0: Flow control is completely disabled
2240 * 1: Rx flow control is enabled (we can receive pause frames
2241 * but not send pause frames).
2242 * 2: Tx flow control is enabled (we can send pause frames
2243 * but we do not support receiving pause frames).
2244 * 3: Both Rx and TX flow control (symmetric) are enabled.
2245 * other: No software override. The flow control configuration
2246 * in the EEPROM is used.
2249 case E1000_FC_NONE: /* 0 */
2250 /* Flow control (RX & TX) is completely disabled by a
2251 * software over-ride.
2253 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2255 case E1000_FC_RX_PAUSE: /* 1 */
2256 /* RX Flow control is enabled, and TX Flow control is
2257 * disabled, by a software over-ride.
2259 /* Since there really isn't a way to advertise that we are
2260 * capable of RX Pause ONLY, we will advertise that we
2261 * support both symmetric and asymmetric RX PAUSE. Later
2262 * (in e1000_config_fc_after_link_up) we will disable the
2263 *hw's ability to send PAUSE frames.
2265 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2267 case E1000_FC_TX_PAUSE: /* 2 */
2268 /* TX Flow control is enabled, and RX Flow control is
2269 * disabled, by a software over-ride.
2271 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
2272 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
2274 case E1000_FC_FULL: /* 3 */
2275 /* Flow control (both RX and TX) is enabled by a software
2278 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2281 DEBUGOUT("Flow control param set incorrectly\n");
2282 return -E1000_ERR_CONFIG;
2285 ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
2289 DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
2291 if (hw->phy_type != e1000_phy_ife) {
2292 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg);
2297 return E1000_SUCCESS;
2300 /******************************************************************************
2301 * Force PHY speed and duplex settings to hw->forced_speed_duplex
2303 * hw - Struct containing variables accessed by shared code
2304 ******************************************************************************/
2306 e1000_phy_force_speed_duplex(struct e1000_hw *hw)
2310 uint16_t mii_ctrl_reg;
2311 uint16_t mii_status_reg;
2315 DEBUGFUNC("e1000_phy_force_speed_duplex");
2317 /* Turn off Flow control if we are forcing speed and duplex. */
2318 hw->fc = E1000_FC_NONE;
2320 DEBUGOUT1("hw->fc = %d\n", hw->fc);
2322 /* Read the Device Control Register. */
2323 ctrl = E1000_READ_REG(hw, CTRL);
2325 /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */
2326 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2327 ctrl &= ~(DEVICE_SPEED_MASK);
2329 /* Clear the Auto Speed Detect Enable bit. */
2330 ctrl &= ~E1000_CTRL_ASDE;
2332 /* Read the MII Control Register. */
2333 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg);
2337 /* We need to disable autoneg in order to force link and duplex. */
2339 mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN;
2341 /* Are we forcing Full or Half Duplex? */
2342 if (hw->forced_speed_duplex == e1000_100_full ||
2343 hw->forced_speed_duplex == e1000_10_full) {
2344 /* We want to force full duplex so we SET the full duplex bits in the
2345 * Device and MII Control Registers.
2347 ctrl |= E1000_CTRL_FD;
2348 mii_ctrl_reg |= MII_CR_FULL_DUPLEX;
2349 DEBUGOUT("Full Duplex\n");
2351 /* We want to force half duplex so we CLEAR the full duplex bits in
2352 * the Device and MII Control Registers.
2354 ctrl &= ~E1000_CTRL_FD;
2355 mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX;
2356 DEBUGOUT("Half Duplex\n");
2359 /* Are we forcing 100Mbps??? */
2360 if (hw->forced_speed_duplex == e1000_100_full ||
2361 hw->forced_speed_duplex == e1000_100_half) {
2362 /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */
2363 ctrl |= E1000_CTRL_SPD_100;
2364 mii_ctrl_reg |= MII_CR_SPEED_100;
2365 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
2366 DEBUGOUT("Forcing 100mb ");
2368 /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */
2369 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
2370 mii_ctrl_reg |= MII_CR_SPEED_10;
2371 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
2372 DEBUGOUT("Forcing 10mb ");
2375 e1000_config_collision_dist(hw);
2377 /* Write the configured values back to the Device Control Reg. */
2378 E1000_WRITE_REG(hw, CTRL, ctrl);
2380 if ((hw->phy_type == e1000_phy_m88) ||
2381 (hw->phy_type == e1000_phy_gg82563)) {
2382 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
2386 /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
2387 * forced whenever speed are duplex are forced.
2389 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
2390 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
2394 DEBUGOUT1("M88E1000 PSCR: %x \n", phy_data);
2396 /* Need to reset the PHY or these changes will be ignored */
2397 mii_ctrl_reg |= MII_CR_RESET;
2399 /* Disable MDI-X support for 10/100 */
2400 } else if (hw->phy_type == e1000_phy_ife) {
2401 ret_val = e1000_read_phy_reg(hw, IFE_PHY_MDIX_CONTROL, &phy_data);
2405 phy_data &= ~IFE_PMC_AUTO_MDIX;
2406 phy_data &= ~IFE_PMC_FORCE_MDIX;
2408 ret_val = e1000_write_phy_reg(hw, IFE_PHY_MDIX_CONTROL, phy_data);
2413 /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
2414 * forced whenever speed or duplex are forced.
2416 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
2420 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
2421 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
2423 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
2428 /* Write back the modified PHY MII control register. */
2429 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg);
2435 /* The wait_autoneg_complete flag may be a little misleading here.
2436 * Since we are forcing speed and duplex, Auto-Neg is not enabled.
2437 * But we do want to delay for a period while forcing only so we
2438 * don't generate false No Link messages. So we will wait here
2439 * only if the user has set wait_autoneg_complete to 1, which is
2442 if (hw->wait_autoneg_complete) {
2443 /* We will wait for autoneg to complete. */
2444 DEBUGOUT("Waiting for forced speed/duplex link.\n");
2447 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
2448 for (i = PHY_FORCE_TIME; i > 0; i--) {
2449 /* Read the MII Status Register and wait for Auto-Neg Complete bit
2452 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2456 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2460 if (mii_status_reg & MII_SR_LINK_STATUS) break;
2464 ((hw->phy_type == e1000_phy_m88) ||
2465 (hw->phy_type == e1000_phy_gg82563))) {
2466 /* We didn't get link. Reset the DSP and wait again for link. */
2467 ret_val = e1000_phy_reset_dsp(hw);
2469 DEBUGOUT("Error Resetting PHY DSP\n");
2473 /* This loop will early-out if the link condition has been met. */
2474 for (i = PHY_FORCE_TIME; i > 0; i--) {
2475 if (mii_status_reg & MII_SR_LINK_STATUS) break;
2477 /* Read the MII Status Register and wait for Auto-Neg Complete bit
2480 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2484 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2490 if (hw->phy_type == e1000_phy_m88) {
2491 /* Because we reset the PHY above, we need to re-force TX_CLK in the
2492 * Extended PHY Specific Control Register to 25MHz clock. This value
2493 * defaults back to a 2.5MHz clock when the PHY is reset.
2495 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
2499 phy_data |= M88E1000_EPSCR_TX_CLK_25;
2500 ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
2504 /* In addition, because of the s/w reset above, we need to enable CRS on
2505 * TX. This must be set for both full and half duplex operation.
2507 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
2511 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
2512 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
2516 if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
2517 (!hw->autoneg) && (hw->forced_speed_duplex == e1000_10_full ||
2518 hw->forced_speed_duplex == e1000_10_half)) {
2519 ret_val = e1000_polarity_reversal_workaround(hw);
2523 } else if (hw->phy_type == e1000_phy_gg82563) {
2524 /* The TX_CLK of the Extended PHY Specific Control Register defaults
2525 * to 2.5MHz on a reset. We need to re-force it back to 25MHz, if
2526 * we're not in a forced 10/duplex configuration. */
2527 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, &phy_data);
2531 phy_data &= ~GG82563_MSCR_TX_CLK_MASK;
2532 if ((hw->forced_speed_duplex == e1000_10_full) ||
2533 (hw->forced_speed_duplex == e1000_10_half))
2534 phy_data |= GG82563_MSCR_TX_CLK_10MBPS_2_5MHZ;
2536 phy_data |= GG82563_MSCR_TX_CLK_100MBPS_25MHZ;
2538 /* Also due to the reset, we need to enable CRS on Tx. */
2539 phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
2541 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, phy_data);
2545 return E1000_SUCCESS;
2548 /******************************************************************************
2549 * Sets the collision distance in the Transmit Control register
2551 * hw - Struct containing variables accessed by shared code
2553 * Link should have been established previously. Reads the speed and duplex
2554 * information from the Device Status register.
2555 ******************************************************************************/
2557 e1000_config_collision_dist(struct e1000_hw *hw)
2559 uint32_t tctl, coll_dist;
2561 DEBUGFUNC("e1000_config_collision_dist");
2563 if (hw->mac_type < e1000_82543)
2564 coll_dist = E1000_COLLISION_DISTANCE_82542;
2566 coll_dist = E1000_COLLISION_DISTANCE;
2568 tctl = E1000_READ_REG(hw, TCTL);
2570 tctl &= ~E1000_TCTL_COLD;
2571 tctl |= coll_dist << E1000_COLD_SHIFT;
2573 E1000_WRITE_REG(hw, TCTL, tctl);
2574 E1000_WRITE_FLUSH(hw);
2577 /******************************************************************************
2578 * Sets MAC speed and duplex settings to reflect the those in the PHY
2580 * hw - Struct containing variables accessed by shared code
2581 * mii_reg - data to write to the MII control register
2583 * The contents of the PHY register containing the needed information need to
2585 ******************************************************************************/
2587 e1000_config_mac_to_phy(struct e1000_hw *hw)
2593 DEBUGFUNC("e1000_config_mac_to_phy");
2595 /* 82544 or newer MAC, Auto Speed Detection takes care of
2596 * MAC speed/duplex configuration.*/
2597 if (hw->mac_type >= e1000_82544)
2598 return E1000_SUCCESS;
2600 /* Read the Device Control Register and set the bits to Force Speed
2603 ctrl = E1000_READ_REG(hw, CTRL);
2604 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2605 ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
2607 /* Set up duplex in the Device Control and Transmit Control
2608 * registers depending on negotiated values.
2610 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
2614 if (phy_data & M88E1000_PSSR_DPLX)
2615 ctrl |= E1000_CTRL_FD;
2617 ctrl &= ~E1000_CTRL_FD;
2619 e1000_config_collision_dist(hw);
2621 /* Set up speed in the Device Control register depending on
2622 * negotiated values.
2624 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
2625 ctrl |= E1000_CTRL_SPD_1000;
2626 else if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
2627 ctrl |= E1000_CTRL_SPD_100;
2629 /* Write the configured values back to the Device Control Reg. */
2630 E1000_WRITE_REG(hw, CTRL, ctrl);
2631 return E1000_SUCCESS;
2634 /******************************************************************************
2635 * Forces the MAC's flow control settings.
2637 * hw - Struct containing variables accessed by shared code
2639 * Sets the TFCE and RFCE bits in the device control register to reflect
2640 * the adapter settings. TFCE and RFCE need to be explicitly set by
2641 * software when a Copper PHY is used because autonegotiation is managed
2642 * by the PHY rather than the MAC. Software must also configure these
2643 * bits when link is forced on a fiber connection.
2644 *****************************************************************************/
2646 e1000_force_mac_fc(struct e1000_hw *hw)
2650 DEBUGFUNC("e1000_force_mac_fc");
2652 /* Get the current configuration of the Device Control Register */
2653 ctrl = E1000_READ_REG(hw, CTRL);
2655 /* Because we didn't get link via the internal auto-negotiation
2656 * mechanism (we either forced link or we got link via PHY
2657 * auto-neg), we have to manually enable/disable transmit an
2658 * receive flow control.
2660 * The "Case" statement below enables/disable flow control
2661 * according to the "hw->fc" parameter.
2663 * The possible values of the "fc" parameter are:
2664 * 0: Flow control is completely disabled
2665 * 1: Rx flow control is enabled (we can receive pause
2666 * frames but not send pause frames).
2667 * 2: Tx flow control is enabled (we can send pause frames
2668 * frames but we do not receive pause frames).
2669 * 3: Both Rx and TX flow control (symmetric) is enabled.
2670 * other: No other values should be possible at this point.
2675 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
2677 case E1000_FC_RX_PAUSE:
2678 ctrl &= (~E1000_CTRL_TFCE);
2679 ctrl |= E1000_CTRL_RFCE;
2681 case E1000_FC_TX_PAUSE:
2682 ctrl &= (~E1000_CTRL_RFCE);
2683 ctrl |= E1000_CTRL_TFCE;
2686 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
2689 DEBUGOUT("Flow control param set incorrectly\n");
2690 return -E1000_ERR_CONFIG;
2693 /* Disable TX Flow Control for 82542 (rev 2.0) */
2694 if (hw->mac_type == e1000_82542_rev2_0)
2695 ctrl &= (~E1000_CTRL_TFCE);
2697 E1000_WRITE_REG(hw, CTRL, ctrl);
2698 return E1000_SUCCESS;
2701 /******************************************************************************
2702 * Configures flow control settings after link is established
2704 * hw - Struct containing variables accessed by shared code
2706 * Should be called immediately after a valid link has been established.
2707 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
2708 * and autonegotiation is enabled, the MAC flow control settings will be set
2709 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
2710 * and RFCE bits will be automaticaly set to the negotiated flow control mode.
2711 *****************************************************************************/
2713 e1000_config_fc_after_link_up(struct e1000_hw *hw)
2716 uint16_t mii_status_reg;
2717 uint16_t mii_nway_adv_reg;
2718 uint16_t mii_nway_lp_ability_reg;
2722 DEBUGFUNC("e1000_config_fc_after_link_up");
2724 /* Check for the case where we have fiber media and auto-neg failed
2725 * so we had to force link. In this case, we need to force the
2726 * configuration of the MAC to match the "fc" parameter.
2728 if (((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) ||
2729 ((hw->media_type == e1000_media_type_internal_serdes) &&
2730 (hw->autoneg_failed)) ||
2731 ((hw->media_type == e1000_media_type_copper) && (!hw->autoneg))) {
2732 ret_val = e1000_force_mac_fc(hw);
2734 DEBUGOUT("Error forcing flow control settings\n");
2739 /* Check for the case where we have copper media and auto-neg is
2740 * enabled. In this case, we need to check and see if Auto-Neg
2741 * has completed, and if so, how the PHY and link partner has
2742 * flow control configured.
2744 if ((hw->media_type == e1000_media_type_copper) && hw->autoneg) {
2745 /* Read the MII Status Register and check to see if AutoNeg
2746 * has completed. We read this twice because this reg has
2747 * some "sticky" (latched) bits.
2749 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2752 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2756 if (mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
2757 /* The AutoNeg process has completed, so we now need to
2758 * read both the Auto Negotiation Advertisement Register
2759 * (Address 4) and the Auto_Negotiation Base Page Ability
2760 * Register (Address 5) to determine how flow control was
2763 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV,
2767 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY,
2768 &mii_nway_lp_ability_reg);
2772 /* Two bits in the Auto Negotiation Advertisement Register
2773 * (Address 4) and two bits in the Auto Negotiation Base
2774 * Page Ability Register (Address 5) determine flow control
2775 * for both the PHY and the link partner. The following
2776 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
2777 * 1999, describes these PAUSE resolution bits and how flow
2778 * control is determined based upon these settings.
2779 * NOTE: DC = Don't Care
2781 * LOCAL DEVICE | LINK PARTNER
2782 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
2783 *-------|---------|-------|---------|--------------------
2784 * 0 | 0 | DC | DC | E1000_FC_NONE
2785 * 0 | 1 | 0 | DC | E1000_FC_NONE
2786 * 0 | 1 | 1 | 0 | E1000_FC_NONE
2787 * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
2788 * 1 | 0 | 0 | DC | E1000_FC_NONE
2789 * 1 | DC | 1 | DC | E1000_FC_FULL
2790 * 1 | 1 | 0 | 0 | E1000_FC_NONE
2791 * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
2794 /* Are both PAUSE bits set to 1? If so, this implies
2795 * Symmetric Flow Control is enabled at both ends. The
2796 * ASM_DIR bits are irrelevant per the spec.
2798 * For Symmetric Flow Control:
2800 * LOCAL DEVICE | LINK PARTNER
2801 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2802 *-------|---------|-------|---------|--------------------
2803 * 1 | DC | 1 | DC | E1000_FC_FULL
2806 if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2807 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
2808 /* Now we need to check if the user selected RX ONLY
2809 * of pause frames. In this case, we had to advertise
2810 * FULL flow control because we could not advertise RX
2811 * ONLY. Hence, we must now check to see if we need to
2812 * turn OFF the TRANSMISSION of PAUSE frames.
2814 if (hw->original_fc == E1000_FC_FULL) {
2815 hw->fc = E1000_FC_FULL;
2816 DEBUGOUT("Flow Control = FULL.\n");
2818 hw->fc = E1000_FC_RX_PAUSE;
2819 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
2822 /* For receiving PAUSE frames ONLY.
2824 * LOCAL DEVICE | LINK PARTNER
2825 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2826 *-------|---------|-------|---------|--------------------
2827 * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
2830 else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2831 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2832 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2833 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
2834 hw->fc = E1000_FC_TX_PAUSE;
2835 DEBUGOUT("Flow Control = TX PAUSE frames only.\n");
2837 /* For transmitting PAUSE frames ONLY.
2839 * LOCAL DEVICE | LINK PARTNER
2840 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2841 *-------|---------|-------|---------|--------------------
2842 * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
2845 else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2846 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2847 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2848 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
2849 hw->fc = E1000_FC_RX_PAUSE;
2850 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
2852 /* Per the IEEE spec, at this point flow control should be
2853 * disabled. However, we want to consider that we could
2854 * be connected to a legacy switch that doesn't advertise
2855 * desired flow control, but can be forced on the link
2856 * partner. So if we advertised no flow control, that is
2857 * what we will resolve to. If we advertised some kind of
2858 * receive capability (Rx Pause Only or Full Flow Control)
2859 * and the link partner advertised none, we will configure
2860 * ourselves to enable Rx Flow Control only. We can do
2861 * this safely for two reasons: If the link partner really
2862 * didn't want flow control enabled, and we enable Rx, no
2863 * harm done since we won't be receiving any PAUSE frames
2864 * anyway. If the intent on the link partner was to have
2865 * flow control enabled, then by us enabling RX only, we
2866 * can at least receive pause frames and process them.
2867 * This is a good idea because in most cases, since we are
2868 * predominantly a server NIC, more times than not we will
2869 * be asked to delay transmission of packets than asking
2870 * our link partner to pause transmission of frames.
2872 else if ((hw->original_fc == E1000_FC_NONE ||
2873 hw->original_fc == E1000_FC_TX_PAUSE) ||
2874 hw->fc_strict_ieee) {
2875 hw->fc = E1000_FC_NONE;
2876 DEBUGOUT("Flow Control = NONE.\n");
2878 hw->fc = E1000_FC_RX_PAUSE;
2879 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
2882 /* Now we need to do one last check... If we auto-
2883 * negotiated to HALF DUPLEX, flow control should not be
2884 * enabled per IEEE 802.3 spec.
2886 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
2888 DEBUGOUT("Error getting link speed and duplex\n");
2892 if (duplex == HALF_DUPLEX)
2893 hw->fc = E1000_FC_NONE;
2895 /* Now we call a subroutine to actually force the MAC
2896 * controller to use the correct flow control settings.
2898 ret_val = e1000_force_mac_fc(hw);
2900 DEBUGOUT("Error forcing flow control settings\n");
2904 DEBUGOUT("Copper PHY and Auto Neg has not completed.\n");
2907 return E1000_SUCCESS;
2910 /******************************************************************************
2911 * Checks to see if the link status of the hardware has changed.
2913 * hw - Struct containing variables accessed by shared code
2915 * Called by any function that needs to check the link status of the adapter.
2916 *****************************************************************************/
2918 e1000_check_for_link(struct e1000_hw *hw)
2925 uint32_t signal = 0;
2929 DEBUGFUNC("e1000_check_for_link");
2931 ctrl = E1000_READ_REG(hw, CTRL);
2932 status = E1000_READ_REG(hw, STATUS);
2934 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
2935 * set when the optics detect a signal. On older adapters, it will be
2936 * cleared when there is a signal. This applies to fiber media only.
2938 if ((hw->media_type == e1000_media_type_fiber) ||
2939 (hw->media_type == e1000_media_type_internal_serdes)) {
2940 rxcw = E1000_READ_REG(hw, RXCW);
2942 if (hw->media_type == e1000_media_type_fiber) {
2943 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
2944 if (status & E1000_STATUS_LU)
2945 hw->get_link_status = FALSE;
2949 /* If we have a copper PHY then we only want to go out to the PHY
2950 * registers to see if Auto-Neg has completed and/or if our link
2951 * status has changed. The get_link_status flag will be set if we
2952 * receive a Link Status Change interrupt or we have Rx Sequence
2955 if ((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
2956 /* First we want to see if the MII Status Register reports
2957 * link. If so, then we want to get the current speed/duplex
2959 * Read the register twice since the link bit is sticky.
2961 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2964 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2968 if (phy_data & MII_SR_LINK_STATUS) {
2969 hw->get_link_status = FALSE;
2970 /* Check if there was DownShift, must be checked immediately after
2972 e1000_check_downshift(hw);
2974 /* If we are on 82544 or 82543 silicon and speed/duplex
2975 * are forced to 10H or 10F, then we will implement the polarity
2976 * reversal workaround. We disable interrupts first, and upon
2977 * returning, place the devices interrupt state to its previous
2978 * value except for the link status change interrupt which will
2979 * happen due to the execution of this workaround.
2982 if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
2984 (hw->forced_speed_duplex == e1000_10_full ||
2985 hw->forced_speed_duplex == e1000_10_half)) {
2986 E1000_WRITE_REG(hw, IMC, 0xffffffff);
2987 ret_val = e1000_polarity_reversal_workaround(hw);
2988 icr = E1000_READ_REG(hw, ICR);
2989 E1000_WRITE_REG(hw, ICS, (icr & ~E1000_ICS_LSC));
2990 E1000_WRITE_REG(hw, IMS, IMS_ENABLE_MASK);
2994 /* No link detected */
2995 e1000_config_dsp_after_link_change(hw, FALSE);
2999 /* If we are forcing speed/duplex, then we simply return since
3000 * we have already determined whether we have link or not.
3002 if (!hw->autoneg) return -E1000_ERR_CONFIG;
3004 /* optimize the dsp settings for the igp phy */
3005 e1000_config_dsp_after_link_change(hw, TRUE);
3007 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
3008 * have Si on board that is 82544 or newer, Auto
3009 * Speed Detection takes care of MAC speed/duplex
3010 * configuration. So we only need to configure Collision
3011 * Distance in the MAC. Otherwise, we need to force
3012 * speed/duplex on the MAC to the current PHY speed/duplex
3015 if (hw->mac_type >= e1000_82544)
3016 e1000_config_collision_dist(hw);
3018 ret_val = e1000_config_mac_to_phy(hw);
3020 DEBUGOUT("Error configuring MAC to PHY settings\n");
3025 /* Configure Flow Control now that Auto-Neg has completed. First, we
3026 * need to restore the desired flow control settings because we may
3027 * have had to re-autoneg with a different link partner.
3029 ret_val = e1000_config_fc_after_link_up(hw);
3031 DEBUGOUT("Error configuring flow control\n");
3035 /* At this point we know that we are on copper and we have
3036 * auto-negotiated link. These are conditions for checking the link
3037 * partner capability register. We use the link speed to determine if
3038 * TBI compatibility needs to be turned on or off. If the link is not
3039 * at gigabit speed, then TBI compatibility is not needed. If we are
3040 * at gigabit speed, we turn on TBI compatibility.
3042 if (hw->tbi_compatibility_en) {
3043 uint16_t speed, duplex;
3044 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
3046 DEBUGOUT("Error getting link speed and duplex\n");
3049 if (speed != SPEED_1000) {
3050 /* If link speed is not set to gigabit speed, we do not need
3051 * to enable TBI compatibility.
3053 if (hw->tbi_compatibility_on) {
3054 /* If we previously were in the mode, turn it off. */
3055 rctl = E1000_READ_REG(hw, RCTL);
3056 rctl &= ~E1000_RCTL_SBP;
3057 E1000_WRITE_REG(hw, RCTL, rctl);
3058 hw->tbi_compatibility_on = FALSE;
3061 /* If TBI compatibility is was previously off, turn it on. For
3062 * compatibility with a TBI link partner, we will store bad
3063 * packets. Some frames have an additional byte on the end and
3064 * will look like CRC errors to to the hardware.
3066 if (!hw->tbi_compatibility_on) {
3067 hw->tbi_compatibility_on = TRUE;
3068 rctl = E1000_READ_REG(hw, RCTL);
3069 rctl |= E1000_RCTL_SBP;
3070 E1000_WRITE_REG(hw, RCTL, rctl);
3075 /* If we don't have link (auto-negotiation failed or link partner cannot
3076 * auto-negotiate), the cable is plugged in (we have signal), and our
3077 * link partner is not trying to auto-negotiate with us (we are receiving
3078 * idles or data), we need to force link up. We also need to give
3079 * auto-negotiation time to complete, in case the cable was just plugged
3080 * in. The autoneg_failed flag does this.
3082 else if ((((hw->media_type == e1000_media_type_fiber) &&
3083 ((ctrl & E1000_CTRL_SWDPIN1) == signal)) ||
3084 (hw->media_type == e1000_media_type_internal_serdes)) &&
3085 (!(status & E1000_STATUS_LU)) &&
3086 (!(rxcw & E1000_RXCW_C))) {
3087 if (hw->autoneg_failed == 0) {
3088 hw->autoneg_failed = 1;
3091 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\n");
3093 /* Disable auto-negotiation in the TXCW register */
3094 E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
3096 /* Force link-up and also force full-duplex. */
3097 ctrl = E1000_READ_REG(hw, CTRL);
3098 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
3099 E1000_WRITE_REG(hw, CTRL, ctrl);
3101 /* Configure Flow Control after forcing link up. */
3102 ret_val = e1000_config_fc_after_link_up(hw);
3104 DEBUGOUT("Error configuring flow control\n");
3108 /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
3109 * auto-negotiation in the TXCW register and disable forced link in the
3110 * Device Control register in an attempt to auto-negotiate with our link
3113 else if (((hw->media_type == e1000_media_type_fiber) ||
3114 (hw->media_type == e1000_media_type_internal_serdes)) &&
3115 (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
3116 DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\n");
3117 E1000_WRITE_REG(hw, TXCW, hw->txcw);
3118 E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
3120 hw->serdes_link_down = FALSE;
3122 /* If we force link for non-auto-negotiation switch, check link status
3123 * based on MAC synchronization for internal serdes media type.
3125 else if ((hw->media_type == e1000_media_type_internal_serdes) &&
3126 !(E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
3127 /* SYNCH bit and IV bit are sticky. */
3129 if (E1000_RXCW_SYNCH & E1000_READ_REG(hw, RXCW)) {
3130 if (!(rxcw & E1000_RXCW_IV)) {
3131 hw->serdes_link_down = FALSE;
3132 DEBUGOUT("SERDES: Link is up.\n");
3135 hw->serdes_link_down = TRUE;
3136 DEBUGOUT("SERDES: Link is down.\n");
3139 if ((hw->media_type == e1000_media_type_internal_serdes) &&
3140 (E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
3141 hw->serdes_link_down = !(E1000_STATUS_LU & E1000_READ_REG(hw, STATUS));
3143 return E1000_SUCCESS;
3146 /******************************************************************************
3147 * Detects the current speed and duplex settings of the hardware.
3149 * hw - Struct containing variables accessed by shared code
3150 * speed - Speed of the connection
3151 * duplex - Duplex setting of the connection
3152 *****************************************************************************/
3154 e1000_get_speed_and_duplex(struct e1000_hw *hw,
3162 DEBUGFUNC("e1000_get_speed_and_duplex");
3164 if (hw->mac_type >= e1000_82543) {
3165 status = E1000_READ_REG(hw, STATUS);
3166 if (status & E1000_STATUS_SPEED_1000) {
3167 *speed = SPEED_1000;
3168 DEBUGOUT("1000 Mbs, ");
3169 } else if (status & E1000_STATUS_SPEED_100) {
3171 DEBUGOUT("100 Mbs, ");
3174 DEBUGOUT("10 Mbs, ");
3177 if (status & E1000_STATUS_FD) {
3178 *duplex = FULL_DUPLEX;
3179 DEBUGOUT("Full Duplex\n");
3181 *duplex = HALF_DUPLEX;
3182 DEBUGOUT(" Half Duplex\n");
3185 DEBUGOUT("1000 Mbs, Full Duplex\n");
3186 *speed = SPEED_1000;
3187 *duplex = FULL_DUPLEX;
3190 /* IGP01 PHY may advertise full duplex operation after speed downgrade even
3191 * if it is operating at half duplex. Here we set the duplex settings to
3192 * match the duplex in the link partner's capabilities.
3194 if (hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
3195 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
3199 if (!(phy_data & NWAY_ER_LP_NWAY_CAPS))
3200 *duplex = HALF_DUPLEX;
3202 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data);
3205 if ((*speed == SPEED_100 && !(phy_data & NWAY_LPAR_100TX_FD_CAPS)) ||
3206 (*speed == SPEED_10 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
3207 *duplex = HALF_DUPLEX;
3211 if ((hw->mac_type == e1000_80003es2lan) &&
3212 (hw->media_type == e1000_media_type_copper)) {
3213 if (*speed == SPEED_1000)
3214 ret_val = e1000_configure_kmrn_for_1000(hw);
3216 ret_val = e1000_configure_kmrn_for_10_100(hw, *duplex);
3221 if ((hw->phy_type == e1000_phy_igp_3) && (*speed == SPEED_1000)) {
3222 ret_val = e1000_kumeran_lock_loss_workaround(hw);
3227 return E1000_SUCCESS;
3230 /******************************************************************************
3231 * Blocks until autoneg completes or times out (~4.5 seconds)
3233 * hw - Struct containing variables accessed by shared code
3234 ******************************************************************************/
3236 e1000_wait_autoneg(struct e1000_hw *hw)
3242 DEBUGFUNC("e1000_wait_autoneg");
3243 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
3245 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
3246 for (i = PHY_AUTO_NEG_TIME; i > 0; i--) {
3247 /* Read the MII Status Register and wait for Auto-Neg
3248 * Complete bit to be set.
3250 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3253 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3256 if (phy_data & MII_SR_AUTONEG_COMPLETE) {
3257 return E1000_SUCCESS;
3261 return E1000_SUCCESS;
3264 /******************************************************************************
3265 * Raises the Management Data Clock
3267 * hw - Struct containing variables accessed by shared code
3268 * ctrl - Device control register's current value
3269 ******************************************************************************/
3271 e1000_raise_mdi_clk(struct e1000_hw *hw,
3274 /* Raise the clock input to the Management Data Clock (by setting the MDC
3275 * bit), and then delay 10 microseconds.
3277 E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
3278 E1000_WRITE_FLUSH(hw);
3282 /******************************************************************************
3283 * Lowers the Management Data Clock
3285 * hw - Struct containing variables accessed by shared code
3286 * ctrl - Device control register's current value
3287 ******************************************************************************/
3289 e1000_lower_mdi_clk(struct e1000_hw *hw,
3292 /* Lower the clock input to the Management Data Clock (by clearing the MDC
3293 * bit), and then delay 10 microseconds.
3295 E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
3296 E1000_WRITE_FLUSH(hw);
3300 /******************************************************************************
3301 * Shifts data bits out to the PHY
3303 * hw - Struct containing variables accessed by shared code
3304 * data - Data to send out to the PHY
3305 * count - Number of bits to shift out
3307 * Bits are shifted out in MSB to LSB order.
3308 ******************************************************************************/
3310 e1000_shift_out_mdi_bits(struct e1000_hw *hw,
3317 /* We need to shift "count" number of bits out to the PHY. So, the value
3318 * in the "data" parameter will be shifted out to the PHY one bit at a
3319 * time. In order to do this, "data" must be broken down into bits.
3322 mask <<= (count - 1);
3324 ctrl = E1000_READ_REG(hw, CTRL);
3326 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
3327 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
3330 /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
3331 * then raising and lowering the Management Data Clock. A "0" is
3332 * shifted out to the PHY by setting the MDIO bit to "0" and then
3333 * raising and lowering the clock.
3336 ctrl |= E1000_CTRL_MDIO;
3338 ctrl &= ~E1000_CTRL_MDIO;
3340 E1000_WRITE_REG(hw, CTRL, ctrl);
3341 E1000_WRITE_FLUSH(hw);
3345 e1000_raise_mdi_clk(hw, &ctrl);
3346 e1000_lower_mdi_clk(hw, &ctrl);
3352 /******************************************************************************
3353 * Shifts data bits in from the PHY
3355 * hw - Struct containing variables accessed by shared code
3357 * Bits are shifted in in MSB to LSB order.
3358 ******************************************************************************/
3360 e1000_shift_in_mdi_bits(struct e1000_hw *hw)
3366 /* In order to read a register from the PHY, we need to shift in a total
3367 * of 18 bits from the PHY. The first two bit (turnaround) times are used
3368 * to avoid contention on the MDIO pin when a read operation is performed.
3369 * These two bits are ignored by us and thrown away. Bits are "shifted in"
3370 * by raising the input to the Management Data Clock (setting the MDC bit),
3371 * and then reading the value of the MDIO bit.
3373 ctrl = E1000_READ_REG(hw, CTRL);
3375 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
3376 ctrl &= ~E1000_CTRL_MDIO_DIR;
3377 ctrl &= ~E1000_CTRL_MDIO;
3379 E1000_WRITE_REG(hw, CTRL, ctrl);
3380 E1000_WRITE_FLUSH(hw);
3382 /* Raise and Lower the clock before reading in the data. This accounts for
3383 * the turnaround bits. The first clock occurred when we clocked out the
3384 * last bit of the Register Address.
3386 e1000_raise_mdi_clk(hw, &ctrl);
3387 e1000_lower_mdi_clk(hw, &ctrl);
3389 for (data = 0, i = 0; i < 16; i++) {
3391 e1000_raise_mdi_clk(hw, &ctrl);
3392 ctrl = E1000_READ_REG(hw, CTRL);
3393 /* Check to see if we shifted in a "1". */
3394 if (ctrl & E1000_CTRL_MDIO)
3396 e1000_lower_mdi_clk(hw, &ctrl);
3399 e1000_raise_mdi_clk(hw, &ctrl);
3400 e1000_lower_mdi_clk(hw, &ctrl);
3406 e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask)
3408 uint32_t swfw_sync = 0;
3409 uint32_t swmask = mask;
3410 uint32_t fwmask = mask << 16;
3411 int32_t timeout = 200;
3413 DEBUGFUNC("e1000_swfw_sync_acquire");
3415 if (hw->swfwhw_semaphore_present)
3416 return e1000_get_software_flag(hw);
3418 if (!hw->swfw_sync_present)
3419 return e1000_get_hw_eeprom_semaphore(hw);
3422 if (e1000_get_hw_eeprom_semaphore(hw))
3423 return -E1000_ERR_SWFW_SYNC;
3425 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
3426 if (!(swfw_sync & (fwmask | swmask))) {
3430 /* firmware currently using resource (fwmask) */
3431 /* or other software thread currently using resource (swmask) */
3432 e1000_put_hw_eeprom_semaphore(hw);
3438 DEBUGOUT("Driver can't access resource, SW_FW_SYNC timeout.\n");
3439 return -E1000_ERR_SWFW_SYNC;
3442 swfw_sync |= swmask;
3443 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
3445 e1000_put_hw_eeprom_semaphore(hw);
3446 return E1000_SUCCESS;
3450 e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask)
3453 uint32_t swmask = mask;
3455 DEBUGFUNC("e1000_swfw_sync_release");
3457 if (hw->swfwhw_semaphore_present) {
3458 e1000_release_software_flag(hw);
3462 if (!hw->swfw_sync_present) {
3463 e1000_put_hw_eeprom_semaphore(hw);
3467 /* if (e1000_get_hw_eeprom_semaphore(hw))
3468 * return -E1000_ERR_SWFW_SYNC; */
3469 while (e1000_get_hw_eeprom_semaphore(hw) != E1000_SUCCESS);
3472 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
3473 swfw_sync &= ~swmask;
3474 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
3476 e1000_put_hw_eeprom_semaphore(hw);
3479 /*****************************************************************************
3480 * Reads the value from a PHY register, if the value is on a specific non zero
3481 * page, sets the page first.
3482 * hw - Struct containing variables accessed by shared code
3483 * reg_addr - address of the PHY register to read
3484 ******************************************************************************/
3486 e1000_read_phy_reg(struct e1000_hw *hw,
3493 DEBUGFUNC("e1000_read_phy_reg");
3495 if ((hw->mac_type == e1000_80003es2lan) &&
3496 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3497 swfw = E1000_SWFW_PHY1_SM;
3499 swfw = E1000_SWFW_PHY0_SM;
3501 if (e1000_swfw_sync_acquire(hw, swfw))
3502 return -E1000_ERR_SWFW_SYNC;
3504 if ((hw->phy_type == e1000_phy_igp ||
3505 hw->phy_type == e1000_phy_igp_3 ||
3506 hw->phy_type == e1000_phy_igp_2) &&
3507 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
3508 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
3509 (uint16_t)reg_addr);
3511 e1000_swfw_sync_release(hw, swfw);
3514 } else if (hw->phy_type == e1000_phy_gg82563) {
3515 if (((reg_addr & MAX_PHY_REG_ADDRESS) > MAX_PHY_MULTI_PAGE_REG) ||
3516 (hw->mac_type == e1000_80003es2lan)) {
3517 /* Select Configuration Page */
3518 if ((reg_addr & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) {
3519 ret_val = e1000_write_phy_reg_ex(hw, GG82563_PHY_PAGE_SELECT,
3520 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3522 /* Use Alternative Page Select register to access
3523 * registers 30 and 31
3525 ret_val = e1000_write_phy_reg_ex(hw,
3526 GG82563_PHY_PAGE_SELECT_ALT,
3527 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3531 e1000_swfw_sync_release(hw, swfw);
3537 ret_val = e1000_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
3540 e1000_swfw_sync_release(hw, swfw);
3545 e1000_read_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr,
3550 const uint32_t phy_addr = 1;
3552 DEBUGFUNC("e1000_read_phy_reg_ex");
3554 if (reg_addr > MAX_PHY_REG_ADDRESS) {
3555 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
3556 return -E1000_ERR_PARAM;
3559 if (hw->mac_type > e1000_82543) {
3560 /* Set up Op-code, Phy Address, and register address in the MDI
3561 * Control register. The MAC will take care of interfacing with the
3562 * PHY to retrieve the desired data.
3564 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
3565 (phy_addr << E1000_MDIC_PHY_SHIFT) |
3566 (E1000_MDIC_OP_READ));
3568 E1000_WRITE_REG(hw, MDIC, mdic);
3570 /* Poll the ready bit to see if the MDI read completed */
3571 for (i = 0; i < 64; i++) {
3573 mdic = E1000_READ_REG(hw, MDIC);
3574 if (mdic & E1000_MDIC_READY) break;
3576 if (!(mdic & E1000_MDIC_READY)) {
3577 DEBUGOUT("MDI Read did not complete\n");
3578 return -E1000_ERR_PHY;
3580 if (mdic & E1000_MDIC_ERROR) {
3581 DEBUGOUT("MDI Error\n");
3582 return -E1000_ERR_PHY;
3584 *phy_data = (uint16_t) mdic;
3586 /* We must first send a preamble through the MDIO pin to signal the
3587 * beginning of an MII instruction. This is done by sending 32
3588 * consecutive "1" bits.
3590 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
3592 /* Now combine the next few fields that are required for a read
3593 * operation. We use this method instead of calling the
3594 * e1000_shift_out_mdi_bits routine five different times. The format of
3595 * a MII read instruction consists of a shift out of 14 bits and is
3596 * defined as follows:
3597 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
3598 * followed by a shift in of 18 bits. This first two bits shifted in
3599 * are TurnAround bits used to avoid contention on the MDIO pin when a
3600 * READ operation is performed. These two bits are thrown away
3601 * followed by a shift in of 16 bits which contains the desired data.
3603 mdic = ((reg_addr) | (phy_addr << 5) |
3604 (PHY_OP_READ << 10) | (PHY_SOF << 12));
3606 e1000_shift_out_mdi_bits(hw, mdic, 14);
3608 /* Now that we've shifted out the read command to the MII, we need to
3609 * "shift in" the 16-bit value (18 total bits) of the requested PHY
3612 *phy_data = e1000_shift_in_mdi_bits(hw);
3614 return E1000_SUCCESS;
3617 /******************************************************************************
3618 * Writes a value to a PHY register
3620 * hw - Struct containing variables accessed by shared code
3621 * reg_addr - address of the PHY register to write
3622 * data - data to write to the PHY
3623 ******************************************************************************/
3625 e1000_write_phy_reg(struct e1000_hw *hw, uint32_t reg_addr,
3631 DEBUGFUNC("e1000_write_phy_reg");
3633 if ((hw->mac_type == e1000_80003es2lan) &&
3634 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3635 swfw = E1000_SWFW_PHY1_SM;
3637 swfw = E1000_SWFW_PHY0_SM;
3639 if (e1000_swfw_sync_acquire(hw, swfw))
3640 return -E1000_ERR_SWFW_SYNC;
3642 if ((hw->phy_type == e1000_phy_igp ||
3643 hw->phy_type == e1000_phy_igp_3 ||
3644 hw->phy_type == e1000_phy_igp_2) &&
3645 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
3646 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
3647 (uint16_t)reg_addr);
3649 e1000_swfw_sync_release(hw, swfw);
3652 } else if (hw->phy_type == e1000_phy_gg82563) {
3653 if (((reg_addr & MAX_PHY_REG_ADDRESS) > MAX_PHY_MULTI_PAGE_REG) ||
3654 (hw->mac_type == e1000_80003es2lan)) {
3655 /* Select Configuration Page */
3656 if ((reg_addr & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) {
3657 ret_val = e1000_write_phy_reg_ex(hw, GG82563_PHY_PAGE_SELECT,
3658 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3660 /* Use Alternative Page Select register to access
3661 * registers 30 and 31
3663 ret_val = e1000_write_phy_reg_ex(hw,
3664 GG82563_PHY_PAGE_SELECT_ALT,
3665 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3669 e1000_swfw_sync_release(hw, swfw);
3675 ret_val = e1000_write_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
3678 e1000_swfw_sync_release(hw, swfw);
3683 e1000_write_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr,
3688 const uint32_t phy_addr = 1;
3690 DEBUGFUNC("e1000_write_phy_reg_ex");
3692 if (reg_addr > MAX_PHY_REG_ADDRESS) {
3693 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
3694 return -E1000_ERR_PARAM;
3697 if (hw->mac_type > e1000_82543) {
3698 /* Set up Op-code, Phy Address, register address, and data intended
3699 * for the PHY register in the MDI Control register. The MAC will take
3700 * care of interfacing with the PHY to send the desired data.
3702 mdic = (((uint32_t) phy_data) |
3703 (reg_addr << E1000_MDIC_REG_SHIFT) |
3704 (phy_addr << E1000_MDIC_PHY_SHIFT) |
3705 (E1000_MDIC_OP_WRITE));
3707 E1000_WRITE_REG(hw, MDIC, mdic);
3709 /* Poll the ready bit to see if the MDI read completed */
3710 for (i = 0; i < 641; i++) {
3712 mdic = E1000_READ_REG(hw, MDIC);
3713 if (mdic & E1000_MDIC_READY) break;
3715 if (!(mdic & E1000_MDIC_READY)) {
3716 DEBUGOUT("MDI Write did not complete\n");
3717 return -E1000_ERR_PHY;
3720 /* We'll need to use the SW defined pins to shift the write command
3721 * out to the PHY. We first send a preamble to the PHY to signal the
3722 * beginning of the MII instruction. This is done by sending 32
3723 * consecutive "1" bits.
3725 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
3727 /* Now combine the remaining required fields that will indicate a
3728 * write operation. We use this method instead of calling the
3729 * e1000_shift_out_mdi_bits routine for each field in the command. The
3730 * format of a MII write instruction is as follows:
3731 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
3733 mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
3734 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
3736 mdic |= (uint32_t) phy_data;
3738 e1000_shift_out_mdi_bits(hw, mdic, 32);
3741 return E1000_SUCCESS;
3745 e1000_read_kmrn_reg(struct e1000_hw *hw,
3751 DEBUGFUNC("e1000_read_kmrn_reg");
3753 if ((hw->mac_type == e1000_80003es2lan) &&
3754 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3755 swfw = E1000_SWFW_PHY1_SM;
3757 swfw = E1000_SWFW_PHY0_SM;
3759 if (e1000_swfw_sync_acquire(hw, swfw))
3760 return -E1000_ERR_SWFW_SYNC;
3762 /* Write register address */
3763 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
3764 E1000_KUMCTRLSTA_OFFSET) |
3765 E1000_KUMCTRLSTA_REN;
3766 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
3769 /* Read the data returned */
3770 reg_val = E1000_READ_REG(hw, KUMCTRLSTA);
3771 *data = (uint16_t)reg_val;
3773 e1000_swfw_sync_release(hw, swfw);
3774 return E1000_SUCCESS;
3778 e1000_write_kmrn_reg(struct e1000_hw *hw,
3784 DEBUGFUNC("e1000_write_kmrn_reg");
3786 if ((hw->mac_type == e1000_80003es2lan) &&
3787 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3788 swfw = E1000_SWFW_PHY1_SM;
3790 swfw = E1000_SWFW_PHY0_SM;
3792 if (e1000_swfw_sync_acquire(hw, swfw))
3793 return -E1000_ERR_SWFW_SYNC;
3795 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
3796 E1000_KUMCTRLSTA_OFFSET) | data;
3797 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
3800 e1000_swfw_sync_release(hw, swfw);
3801 return E1000_SUCCESS;
3804 /******************************************************************************
3805 * Returns the PHY to the power-on reset state
3807 * hw - Struct containing variables accessed by shared code
3808 ******************************************************************************/
3810 e1000_phy_hw_reset(struct e1000_hw *hw)
3812 uint32_t ctrl, ctrl_ext;
3817 DEBUGFUNC("e1000_phy_hw_reset");
3819 /* In the case of the phy reset being blocked, it's not an error, we
3820 * simply return success without performing the reset. */
3821 ret_val = e1000_check_phy_reset_block(hw);
3823 return E1000_SUCCESS;
3825 DEBUGOUT("Resetting Phy...\n");
3827 if (hw->mac_type > e1000_82543) {
3828 if ((hw->mac_type == e1000_80003es2lan) &&
3829 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3830 swfw = E1000_SWFW_PHY1_SM;
3832 swfw = E1000_SWFW_PHY0_SM;
3834 if (e1000_swfw_sync_acquire(hw, swfw)) {
3835 DEBUGOUT("Unable to acquire swfw sync\n");
3836 return -E1000_ERR_SWFW_SYNC;
3838 /* Read the device control register and assert the E1000_CTRL_PHY_RST
3839 * bit. Then, take it out of reset.
3840 * For pre-e1000_82571 hardware, we delay for 10ms between the assert
3841 * and deassert. For e1000_82571 hardware and later, we instead delay
3842 * for 50us between and 10ms after the deassertion.
3844 ctrl = E1000_READ_REG(hw, CTRL);
3845 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST);
3846 E1000_WRITE_FLUSH(hw);
3848 if (hw->mac_type < e1000_82571)
3853 E1000_WRITE_REG(hw, CTRL, ctrl);
3854 E1000_WRITE_FLUSH(hw);
3856 if (hw->mac_type >= e1000_82571)
3859 e1000_swfw_sync_release(hw, swfw);
3861 /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
3862 * bit to put the PHY into reset. Then, take it out of reset.
3864 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
3865 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
3866 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
3867 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
3868 E1000_WRITE_FLUSH(hw);
3870 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
3871 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
3872 E1000_WRITE_FLUSH(hw);
3876 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
3877 /* Configure activity LED after PHY reset */
3878 led_ctrl = E1000_READ_REG(hw, LEDCTL);
3879 led_ctrl &= IGP_ACTIVITY_LED_MASK;
3880 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
3881 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
3884 /* Wait for FW to finish PHY configuration. */
3885 ret_val = e1000_get_phy_cfg_done(hw);
3886 if (ret_val != E1000_SUCCESS)
3888 e1000_release_software_semaphore(hw);
3890 if ((hw->mac_type == e1000_ich8lan) && (hw->phy_type == e1000_phy_igp_3))
3891 ret_val = e1000_init_lcd_from_nvm(hw);
3896 /******************************************************************************
3899 * hw - Struct containing variables accessed by shared code
3901 * Sets bit 15 of the MII Control register
3902 ******************************************************************************/
3904 e1000_phy_reset(struct e1000_hw *hw)
3909 DEBUGFUNC("e1000_phy_reset");
3911 /* In the case of the phy reset being blocked, it's not an error, we
3912 * simply return success without performing the reset. */
3913 ret_val = e1000_check_phy_reset_block(hw);
3915 return E1000_SUCCESS;
3917 switch (hw->phy_type) {
3919 case e1000_phy_igp_2:
3920 case e1000_phy_igp_3:
3922 ret_val = e1000_phy_hw_reset(hw);
3927 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
3931 phy_data |= MII_CR_RESET;
3932 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
3940 if (hw->phy_type == e1000_phy_igp || hw->phy_type == e1000_phy_igp_2)
3941 e1000_phy_init_script(hw);
3943 return E1000_SUCCESS;
3946 /******************************************************************************
3947 * Work-around for 82566 power-down: on D3 entry-
3948 * 1) disable gigabit link
3949 * 2) write VR power-down enable
3951 * if successful continue, else issue LCD reset and repeat
3953 * hw - struct containing variables accessed by shared code
3954 ******************************************************************************/
3956 e1000_phy_powerdown_workaround(struct e1000_hw *hw)
3962 DEBUGFUNC("e1000_phy_powerdown_workaround");
3964 if (hw->phy_type != e1000_phy_igp_3)
3969 reg = E1000_READ_REG(hw, PHY_CTRL);
3970 E1000_WRITE_REG(hw, PHY_CTRL, reg | E1000_PHY_CTRL_GBE_DISABLE |
3971 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
3973 /* Write VR power-down enable - bits 9:8 should be 10b */
3974 e1000_read_phy_reg(hw, IGP3_VR_CTRL, &phy_data);
3975 phy_data |= (1 << 9);
3976 phy_data &= ~(1 << 8);
3977 e1000_write_phy_reg(hw, IGP3_VR_CTRL, phy_data);
3979 /* Read it back and test */
3980 e1000_read_phy_reg(hw, IGP3_VR_CTRL, &phy_data);
3981 if (((phy_data & IGP3_VR_CTRL_MODE_MASK) == IGP3_VR_CTRL_MODE_SHUT) || retry)
3984 /* Issue PHY reset and repeat at most one more time */
3985 reg = E1000_READ_REG(hw, CTRL);
3986 E1000_WRITE_REG(hw, CTRL, reg | E1000_CTRL_PHY_RST);
3994 /******************************************************************************
3995 * Work-around for 82566 Kumeran PCS lock loss:
3996 * On link status change (i.e. PCI reset, speed change) and link is up and
3998 * 0) if workaround is optionally disabled do nothing
3999 * 1) wait 1ms for Kumeran link to come up
4000 * 2) check Kumeran Diagnostic register PCS lock loss bit
4001 * 3) if not set the link is locked (all is good), otherwise...
4003 * 5) repeat up to 10 times
4004 * Note: this is only called for IGP3 copper when speed is 1gb.
4006 * hw - struct containing variables accessed by shared code
4007 ******************************************************************************/
4009 e1000_kumeran_lock_loss_workaround(struct e1000_hw *hw)
4016 if (hw->kmrn_lock_loss_workaround_disabled)
4017 return E1000_SUCCESS;
4019 /* Make sure link is up before proceeding. If not just return.
4020 * Attempting this while link is negotiating fouled up link
4022 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
4023 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
4025 if (phy_data & MII_SR_LINK_STATUS) {
4026 for (cnt = 0; cnt < 10; cnt++) {
4027 /* read once to clear */
4028 ret_val = e1000_read_phy_reg(hw, IGP3_KMRN_DIAG, &phy_data);
4031 /* and again to get new status */
4032 ret_val = e1000_read_phy_reg(hw, IGP3_KMRN_DIAG, &phy_data);
4036 /* check for PCS lock */
4037 if (!(phy_data & IGP3_KMRN_DIAG_PCS_LOCK_LOSS))
4038 return E1000_SUCCESS;
4040 /* Issue PHY reset */
4041 e1000_phy_hw_reset(hw);
4044 /* Disable GigE link negotiation */
4045 reg = E1000_READ_REG(hw, PHY_CTRL);
4046 E1000_WRITE_REG(hw, PHY_CTRL, reg | E1000_PHY_CTRL_GBE_DISABLE |
4047 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
4049 /* unable to acquire PCS lock */
4050 return E1000_ERR_PHY;
4053 return E1000_SUCCESS;
4056 /******************************************************************************
4057 * Probes the expected PHY address for known PHY IDs
4059 * hw - Struct containing variables accessed by shared code
4060 ******************************************************************************/
4062 e1000_detect_gig_phy(struct e1000_hw *hw)
4064 int32_t phy_init_status, ret_val;
4065 uint16_t phy_id_high, phy_id_low;
4066 boolean_t match = FALSE;
4068 DEBUGFUNC("e1000_detect_gig_phy");
4070 if (hw->phy_id != 0)
4071 return E1000_SUCCESS;
4073 /* The 82571 firmware may still be configuring the PHY. In this
4074 * case, we cannot access the PHY until the configuration is done. So
4075 * we explicitly set the PHY values. */
4076 if (hw->mac_type == e1000_82571 ||
4077 hw->mac_type == e1000_82572) {
4078 hw->phy_id = IGP01E1000_I_PHY_ID;
4079 hw->phy_type = e1000_phy_igp_2;
4080 return E1000_SUCCESS;
4083 /* ESB-2 PHY reads require e1000_phy_gg82563 to be set because of a work-
4084 * around that forces PHY page 0 to be set or the reads fail. The rest of
4085 * the code in this routine uses e1000_read_phy_reg to read the PHY ID.
4086 * So for ESB-2 we need to have this set so our reads won't fail. If the
4087 * attached PHY is not a e1000_phy_gg82563, the routines below will figure
4088 * this out as well. */
4089 if (hw->mac_type == e1000_80003es2lan)
4090 hw->phy_type = e1000_phy_gg82563;
4092 /* Read the PHY ID Registers to identify which PHY is onboard. */
4093 ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
4097 hw->phy_id = (uint32_t) (phy_id_high << 16);
4099 ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
4103 hw->phy_id |= (uint32_t) (phy_id_low & PHY_REVISION_MASK);
4104 hw->phy_revision = (uint32_t) phy_id_low & ~PHY_REVISION_MASK;
4106 switch (hw->mac_type) {
4108 if (hw->phy_id == M88E1000_E_PHY_ID) match = TRUE;
4111 if (hw->phy_id == M88E1000_I_PHY_ID) match = TRUE;
4115 case e1000_82545_rev_3:
4117 case e1000_82546_rev_3:
4118 if (hw->phy_id == M88E1011_I_PHY_ID) match = TRUE;
4121 case e1000_82541_rev_2:
4123 case e1000_82547_rev_2:
4124 if (hw->phy_id == IGP01E1000_I_PHY_ID) match = TRUE;
4127 if (hw->phy_id == M88E1111_I_PHY_ID) match = TRUE;
4129 case e1000_80003es2lan:
4130 if (hw->phy_id == GG82563_E_PHY_ID) match = TRUE;
4133 if (hw->phy_id == IGP03E1000_E_PHY_ID) match = TRUE;
4134 if (hw->phy_id == IFE_E_PHY_ID) match = TRUE;
4135 if (hw->phy_id == IFE_PLUS_E_PHY_ID) match = TRUE;
4136 if (hw->phy_id == IFE_C_E_PHY_ID) match = TRUE;
4139 DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type);
4140 return -E1000_ERR_CONFIG;
4142 phy_init_status = e1000_set_phy_type(hw);
4144 if ((match) && (phy_init_status == E1000_SUCCESS)) {
4145 DEBUGOUT1("PHY ID 0x%X detected\n", hw->phy_id);
4146 return E1000_SUCCESS;
4148 DEBUGOUT1("Invalid PHY ID 0x%X\n", hw->phy_id);
4149 return -E1000_ERR_PHY;
4152 /******************************************************************************
4153 * Resets the PHY's DSP
4155 * hw - Struct containing variables accessed by shared code
4156 ******************************************************************************/
4158 e1000_phy_reset_dsp(struct e1000_hw *hw)
4161 DEBUGFUNC("e1000_phy_reset_dsp");
4164 if (hw->phy_type != e1000_phy_gg82563) {
4165 ret_val = e1000_write_phy_reg(hw, 29, 0x001d);
4168 ret_val = e1000_write_phy_reg(hw, 30, 0x00c1);
4170 ret_val = e1000_write_phy_reg(hw, 30, 0x0000);
4172 ret_val = E1000_SUCCESS;
4178 /******************************************************************************
4179 * Get PHY information from various PHY registers for igp PHY only.
4181 * hw - Struct containing variables accessed by shared code
4182 * phy_info - PHY information structure
4183 ******************************************************************************/
4185 e1000_phy_igp_get_info(struct e1000_hw *hw,
4186 struct e1000_phy_info *phy_info)
4189 uint16_t phy_data, min_length, max_length, average;
4190 e1000_rev_polarity polarity;
4192 DEBUGFUNC("e1000_phy_igp_get_info");
4194 /* The downshift status is checked only once, after link is established,
4195 * and it stored in the hw->speed_downgraded parameter. */
4196 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
4198 /* IGP01E1000 does not need to support it. */
4199 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
4201 /* IGP01E1000 always correct polarity reversal */
4202 phy_info->polarity_correction = e1000_polarity_reversal_enabled;
4204 /* Check polarity status */
4205 ret_val = e1000_check_polarity(hw, &polarity);
4209 phy_info->cable_polarity = polarity;
4211 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, &phy_data);
4215 phy_info->mdix_mode = (e1000_auto_x_mode)((phy_data & IGP01E1000_PSSR_MDIX) >>
4216 IGP01E1000_PSSR_MDIX_SHIFT);
4218 if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
4219 IGP01E1000_PSSR_SPEED_1000MBPS) {
4220 /* Local/Remote Receiver Information are only valid at 1000 Mbps */
4221 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
4225 phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
4226 SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
4227 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
4228 phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
4229 SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
4230 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
4232 /* Get cable length */
4233 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
4237 /* Translate to old method */
4238 average = (max_length + min_length) / 2;
4240 if (average <= e1000_igp_cable_length_50)
4241 phy_info->cable_length = e1000_cable_length_50;
4242 else if (average <= e1000_igp_cable_length_80)
4243 phy_info->cable_length = e1000_cable_length_50_80;
4244 else if (average <= e1000_igp_cable_length_110)
4245 phy_info->cable_length = e1000_cable_length_80_110;
4246 else if (average <= e1000_igp_cable_length_140)
4247 phy_info->cable_length = e1000_cable_length_110_140;
4249 phy_info->cable_length = e1000_cable_length_140;
4252 return E1000_SUCCESS;
4255 /******************************************************************************
4256 * Get PHY information from various PHY registers for ife PHY only.
4258 * hw - Struct containing variables accessed by shared code
4259 * phy_info - PHY information structure
4260 ******************************************************************************/
4262 e1000_phy_ife_get_info(struct e1000_hw *hw,
4263 struct e1000_phy_info *phy_info)
4267 e1000_rev_polarity polarity;
4269 DEBUGFUNC("e1000_phy_ife_get_info");
4271 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
4272 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
4274 ret_val = e1000_read_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL, &phy_data);
4277 phy_info->polarity_correction =
4278 ((phy_data & IFE_PSC_AUTO_POLARITY_DISABLE) >>
4279 IFE_PSC_AUTO_POLARITY_DISABLE_SHIFT) ?
4280 e1000_polarity_reversal_disabled : e1000_polarity_reversal_enabled;
4282 if (phy_info->polarity_correction == e1000_polarity_reversal_enabled) {
4283 ret_val = e1000_check_polarity(hw, &polarity);
4287 /* Polarity is forced. */
4288 polarity = ((phy_data & IFE_PSC_FORCE_POLARITY) >>
4289 IFE_PSC_FORCE_POLARITY_SHIFT) ?
4290 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
4292 phy_info->cable_polarity = polarity;
4294 ret_val = e1000_read_phy_reg(hw, IFE_PHY_MDIX_CONTROL, &phy_data);
4298 phy_info->mdix_mode = (e1000_auto_x_mode)
4299 ((phy_data & (IFE_PMC_AUTO_MDIX | IFE_PMC_FORCE_MDIX)) >>
4300 IFE_PMC_MDIX_MODE_SHIFT);
4302 return E1000_SUCCESS;
4305 /******************************************************************************
4306 * Get PHY information from various PHY registers fot m88 PHY only.
4308 * hw - Struct containing variables accessed by shared code
4309 * phy_info - PHY information structure
4310 ******************************************************************************/
4312 e1000_phy_m88_get_info(struct e1000_hw *hw,
4313 struct e1000_phy_info *phy_info)
4317 e1000_rev_polarity polarity;
4319 DEBUGFUNC("e1000_phy_m88_get_info");
4321 /* The downshift status is checked only once, after link is established,
4322 * and it stored in the hw->speed_downgraded parameter. */
4323 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
4325 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
4329 phy_info->extended_10bt_distance =
4330 ((phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >>
4331 M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT) ?
4332 e1000_10bt_ext_dist_enable_lower : e1000_10bt_ext_dist_enable_normal;
4334 phy_info->polarity_correction =
4335 ((phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >>
4336 M88E1000_PSCR_POLARITY_REVERSAL_SHIFT) ?
4337 e1000_polarity_reversal_disabled : e1000_polarity_reversal_enabled;
4339 /* Check polarity status */
4340 ret_val = e1000_check_polarity(hw, &polarity);
4343 phy_info->cable_polarity = polarity;
4345 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
4349 phy_info->mdix_mode = (e1000_auto_x_mode)((phy_data & M88E1000_PSSR_MDIX) >>
4350 M88E1000_PSSR_MDIX_SHIFT);
4352 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
4353 /* Cable Length Estimation and Local/Remote Receiver Information
4354 * are only valid at 1000 Mbps.
4356 if (hw->phy_type != e1000_phy_gg82563) {
4357 phy_info->cable_length = (e1000_cable_length)((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
4358 M88E1000_PSSR_CABLE_LENGTH_SHIFT);
4360 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_DSP_DISTANCE,
4365 phy_info->cable_length = (e1000_cable_length)(phy_data & GG82563_DSPD_CABLE_LENGTH);
4368 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
4372 phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
4373 SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
4374 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
4375 phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
4376 SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
4377 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
4381 return E1000_SUCCESS;
4384 /******************************************************************************
4385 * Get PHY information from various PHY registers
4387 * hw - Struct containing variables accessed by shared code
4388 * phy_info - PHY information structure
4389 ******************************************************************************/
4391 e1000_phy_get_info(struct e1000_hw *hw,
4392 struct e1000_phy_info *phy_info)
4397 DEBUGFUNC("e1000_phy_get_info");
4399 phy_info->cable_length = e1000_cable_length_undefined;
4400 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined;
4401 phy_info->cable_polarity = e1000_rev_polarity_undefined;
4402 phy_info->downshift = e1000_downshift_undefined;
4403 phy_info->polarity_correction = e1000_polarity_reversal_undefined;
4404 phy_info->mdix_mode = e1000_auto_x_mode_undefined;
4405 phy_info->local_rx = e1000_1000t_rx_status_undefined;
4406 phy_info->remote_rx = e1000_1000t_rx_status_undefined;
4408 if (hw->media_type != e1000_media_type_copper) {
4409 DEBUGOUT("PHY info is only valid for copper media\n");
4410 return -E1000_ERR_CONFIG;
4413 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
4417 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
4421 if ((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) {
4422 DEBUGOUT("PHY info is only valid if link is up\n");
4423 return -E1000_ERR_CONFIG;
4426 if (hw->phy_type == e1000_phy_igp ||
4427 hw->phy_type == e1000_phy_igp_3 ||
4428 hw->phy_type == e1000_phy_igp_2)
4429 return e1000_phy_igp_get_info(hw, phy_info);
4430 else if (hw->phy_type == e1000_phy_ife)
4431 return e1000_phy_ife_get_info(hw, phy_info);
4433 return e1000_phy_m88_get_info(hw, phy_info);
4437 e1000_validate_mdi_setting(struct e1000_hw *hw)
4439 DEBUGFUNC("e1000_validate_mdi_settings");
4441 if (!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) {
4442 DEBUGOUT("Invalid MDI setting detected\n");
4444 return -E1000_ERR_CONFIG;
4446 return E1000_SUCCESS;
4450 /******************************************************************************
4451 * Sets up eeprom variables in the hw struct. Must be called after mac_type
4452 * is configured. Additionally, if this is ICH8, the flash controller GbE
4453 * registers must be mapped, or this will crash.
4455 * hw - Struct containing variables accessed by shared code
4456 *****************************************************************************/
4458 e1000_init_eeprom_params(struct e1000_hw *hw)
4460 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4461 uint32_t eecd = E1000_READ_REG(hw, EECD);
4462 int32_t ret_val = E1000_SUCCESS;
4463 uint16_t eeprom_size;
4465 DEBUGFUNC("e1000_init_eeprom_params");
4467 switch (hw->mac_type) {
4468 case e1000_82542_rev2_0:
4469 case e1000_82542_rev2_1:
4472 eeprom->type = e1000_eeprom_microwire;
4473 eeprom->word_size = 64;
4474 eeprom->opcode_bits = 3;
4475 eeprom->address_bits = 6;
4476 eeprom->delay_usec = 50;
4477 eeprom->use_eerd = FALSE;
4478 eeprom->use_eewr = FALSE;
4482 case e1000_82545_rev_3:
4484 case e1000_82546_rev_3:
4485 eeprom->type = e1000_eeprom_microwire;
4486 eeprom->opcode_bits = 3;
4487 eeprom->delay_usec = 50;
4488 if (eecd & E1000_EECD_SIZE) {
4489 eeprom->word_size = 256;
4490 eeprom->address_bits = 8;
4492 eeprom->word_size = 64;
4493 eeprom->address_bits = 6;
4495 eeprom->use_eerd = FALSE;
4496 eeprom->use_eewr = FALSE;
4499 case e1000_82541_rev_2:
4501 case e1000_82547_rev_2:
4502 if (eecd & E1000_EECD_TYPE) {
4503 eeprom->type = e1000_eeprom_spi;
4504 eeprom->opcode_bits = 8;
4505 eeprom->delay_usec = 1;
4506 if (eecd & E1000_EECD_ADDR_BITS) {
4507 eeprom->page_size = 32;
4508 eeprom->address_bits = 16;
4510 eeprom->page_size = 8;
4511 eeprom->address_bits = 8;
4514 eeprom->type = e1000_eeprom_microwire;
4515 eeprom->opcode_bits = 3;
4516 eeprom->delay_usec = 50;
4517 if (eecd & E1000_EECD_ADDR_BITS) {
4518 eeprom->word_size = 256;
4519 eeprom->address_bits = 8;
4521 eeprom->word_size = 64;
4522 eeprom->address_bits = 6;
4525 eeprom->use_eerd = FALSE;
4526 eeprom->use_eewr = FALSE;
4530 eeprom->type = e1000_eeprom_spi;
4531 eeprom->opcode_bits = 8;
4532 eeprom->delay_usec = 1;
4533 if (eecd & E1000_EECD_ADDR_BITS) {
4534 eeprom->page_size = 32;
4535 eeprom->address_bits = 16;
4537 eeprom->page_size = 8;
4538 eeprom->address_bits = 8;
4540 eeprom->use_eerd = FALSE;
4541 eeprom->use_eewr = FALSE;
4544 eeprom->type = e1000_eeprom_spi;
4545 eeprom->opcode_bits = 8;
4546 eeprom->delay_usec = 1;
4547 if (eecd & E1000_EECD_ADDR_BITS) {
4548 eeprom->page_size = 32;
4549 eeprom->address_bits = 16;
4551 eeprom->page_size = 8;
4552 eeprom->address_bits = 8;
4554 eeprom->use_eerd = TRUE;
4555 eeprom->use_eewr = TRUE;
4556 if (e1000_is_onboard_nvm_eeprom(hw) == FALSE) {
4557 eeprom->type = e1000_eeprom_flash;
4558 eeprom->word_size = 2048;
4560 /* Ensure that the Autonomous FLASH update bit is cleared due to
4561 * Flash update issue on parts which use a FLASH for NVM. */
4562 eecd &= ~E1000_EECD_AUPDEN;
4563 E1000_WRITE_REG(hw, EECD, eecd);
4566 case e1000_80003es2lan:
4567 eeprom->type = e1000_eeprom_spi;
4568 eeprom->opcode_bits = 8;
4569 eeprom->delay_usec = 1;
4570 if (eecd & E1000_EECD_ADDR_BITS) {
4571 eeprom->page_size = 32;
4572 eeprom->address_bits = 16;
4574 eeprom->page_size = 8;
4575 eeprom->address_bits = 8;
4577 eeprom->use_eerd = TRUE;
4578 eeprom->use_eewr = FALSE;
4583 uint32_t flash_size = E1000_READ_ICH_FLASH_REG(hw, ICH_FLASH_GFPREG);
4585 eeprom->type = e1000_eeprom_ich8;
4586 eeprom->use_eerd = FALSE;
4587 eeprom->use_eewr = FALSE;
4588 eeprom->word_size = E1000_SHADOW_RAM_WORDS;
4590 /* Zero the shadow RAM structure. But don't load it from NVM
4591 * so as to save time for driver init */
4592 if (hw->eeprom_shadow_ram != NULL) {
4593 for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
4594 hw->eeprom_shadow_ram[i].modified = FALSE;
4595 hw->eeprom_shadow_ram[i].eeprom_word = 0xFFFF;
4599 hw->flash_base_addr = (flash_size & ICH_GFPREG_BASE_MASK) *
4600 ICH_FLASH_SECTOR_SIZE;
4602 hw->flash_bank_size = ((flash_size >> 16) & ICH_GFPREG_BASE_MASK) + 1;
4603 hw->flash_bank_size -= (flash_size & ICH_GFPREG_BASE_MASK);
4605 hw->flash_bank_size *= ICH_FLASH_SECTOR_SIZE;
4607 hw->flash_bank_size /= 2 * sizeof(uint16_t);
4615 if (eeprom->type == e1000_eeprom_spi) {
4616 /* eeprom_size will be an enum [0..8] that maps to eeprom sizes 128B to
4617 * 32KB (incremented by powers of 2).
4619 if (hw->mac_type <= e1000_82547_rev_2) {
4620 /* Set to default value for initial eeprom read. */
4621 eeprom->word_size = 64;
4622 ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size);
4625 eeprom_size = (eeprom_size & EEPROM_SIZE_MASK) >> EEPROM_SIZE_SHIFT;
4626 /* 256B eeprom size was not supported in earlier hardware, so we
4627 * bump eeprom_size up one to ensure that "1" (which maps to 256B)
4628 * is never the result used in the shifting logic below. */
4632 eeprom_size = (uint16_t)((eecd & E1000_EECD_SIZE_EX_MASK) >>
4633 E1000_EECD_SIZE_EX_SHIFT);
4636 eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT);
4641 /******************************************************************************
4642 * Raises the EEPROM's clock input.
4644 * hw - Struct containing variables accessed by shared code
4645 * eecd - EECD's current value
4646 *****************************************************************************/
4648 e1000_raise_ee_clk(struct e1000_hw *hw,
4651 /* Raise the clock input to the EEPROM (by setting the SK bit), and then
4652 * wait <delay> microseconds.
4654 *eecd = *eecd | E1000_EECD_SK;
4655 E1000_WRITE_REG(hw, EECD, *eecd);
4656 E1000_WRITE_FLUSH(hw);
4657 udelay(hw->eeprom.delay_usec);
4660 /******************************************************************************
4661 * Lowers the EEPROM's clock input.
4663 * hw - Struct containing variables accessed by shared code
4664 * eecd - EECD's current value
4665 *****************************************************************************/
4667 e1000_lower_ee_clk(struct e1000_hw *hw,
4670 /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
4671 * wait 50 microseconds.
4673 *eecd = *eecd & ~E1000_EECD_SK;
4674 E1000_WRITE_REG(hw, EECD, *eecd);
4675 E1000_WRITE_FLUSH(hw);
4676 udelay(hw->eeprom.delay_usec);
4679 /******************************************************************************
4680 * Shift data bits out to the EEPROM.
4682 * hw - Struct containing variables accessed by shared code
4683 * data - data to send to the EEPROM
4684 * count - number of bits to shift out
4685 *****************************************************************************/
4687 e1000_shift_out_ee_bits(struct e1000_hw *hw,
4691 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4695 /* We need to shift "count" bits out to the EEPROM. So, value in the
4696 * "data" parameter will be shifted out to the EEPROM one bit at a time.
4697 * In order to do this, "data" must be broken down into bits.
4699 mask = 0x01 << (count - 1);
4700 eecd = E1000_READ_REG(hw, EECD);
4701 if (eeprom->type == e1000_eeprom_microwire) {
4702 eecd &= ~E1000_EECD_DO;
4703 } else if (eeprom->type == e1000_eeprom_spi) {
4704 eecd |= E1000_EECD_DO;
4707 /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
4708 * and then raising and then lowering the clock (the SK bit controls
4709 * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
4710 * by setting "DI" to "0" and then raising and then lowering the clock.
4712 eecd &= ~E1000_EECD_DI;
4715 eecd |= E1000_EECD_DI;
4717 E1000_WRITE_REG(hw, EECD, eecd);
4718 E1000_WRITE_FLUSH(hw);
4720 udelay(eeprom->delay_usec);
4722 e1000_raise_ee_clk(hw, &eecd);
4723 e1000_lower_ee_clk(hw, &eecd);
4729 /* We leave the "DI" bit set to "0" when we leave this routine. */
4730 eecd &= ~E1000_EECD_DI;
4731 E1000_WRITE_REG(hw, EECD, eecd);
4734 /******************************************************************************
4735 * Shift data bits in from the EEPROM
4737 * hw - Struct containing variables accessed by shared code
4738 *****************************************************************************/
4740 e1000_shift_in_ee_bits(struct e1000_hw *hw,
4747 /* In order to read a register from the EEPROM, we need to shift 'count'
4748 * bits in from the EEPROM. Bits are "shifted in" by raising the clock
4749 * input to the EEPROM (setting the SK bit), and then reading the value of
4750 * the "DO" bit. During this "shifting in" process the "DI" bit should
4754 eecd = E1000_READ_REG(hw, EECD);
4756 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
4759 for (i = 0; i < count; i++) {
4761 e1000_raise_ee_clk(hw, &eecd);
4763 eecd = E1000_READ_REG(hw, EECD);
4765 eecd &= ~(E1000_EECD_DI);
4766 if (eecd & E1000_EECD_DO)
4769 e1000_lower_ee_clk(hw, &eecd);
4775 /******************************************************************************
4776 * Prepares EEPROM for access
4778 * hw - Struct containing variables accessed by shared code
4780 * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
4781 * function should be called before issuing a command to the EEPROM.
4782 *****************************************************************************/
4784 e1000_acquire_eeprom(struct e1000_hw *hw)
4786 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4789 DEBUGFUNC("e1000_acquire_eeprom");
4791 if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
4792 return -E1000_ERR_SWFW_SYNC;
4793 eecd = E1000_READ_REG(hw, EECD);
4795 if (hw->mac_type != e1000_82573) {
4796 /* Request EEPROM Access */
4797 if (hw->mac_type > e1000_82544) {
4798 eecd |= E1000_EECD_REQ;
4799 E1000_WRITE_REG(hw, EECD, eecd);
4800 eecd = E1000_READ_REG(hw, EECD);
4801 while ((!(eecd & E1000_EECD_GNT)) &&
4802 (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
4805 eecd = E1000_READ_REG(hw, EECD);
4807 if (!(eecd & E1000_EECD_GNT)) {
4808 eecd &= ~E1000_EECD_REQ;
4809 E1000_WRITE_REG(hw, EECD, eecd);
4810 DEBUGOUT("Could not acquire EEPROM grant\n");
4811 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
4812 return -E1000_ERR_EEPROM;
4817 /* Setup EEPROM for Read/Write */
4819 if (eeprom->type == e1000_eeprom_microwire) {
4820 /* Clear SK and DI */
4821 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
4822 E1000_WRITE_REG(hw, EECD, eecd);
4825 eecd |= E1000_EECD_CS;
4826 E1000_WRITE_REG(hw, EECD, eecd);
4827 } else if (eeprom->type == e1000_eeprom_spi) {
4828 /* Clear SK and CS */
4829 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
4830 E1000_WRITE_REG(hw, EECD, eecd);
4834 return E1000_SUCCESS;
4837 /******************************************************************************
4838 * Returns EEPROM to a "standby" state
4840 * hw - Struct containing variables accessed by shared code
4841 *****************************************************************************/
4843 e1000_standby_eeprom(struct e1000_hw *hw)
4845 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4848 eecd = E1000_READ_REG(hw, EECD);
4850 if (eeprom->type == e1000_eeprom_microwire) {
4851 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
4852 E1000_WRITE_REG(hw, EECD, eecd);
4853 E1000_WRITE_FLUSH(hw);
4854 udelay(eeprom->delay_usec);
4857 eecd |= E1000_EECD_SK;
4858 E1000_WRITE_REG(hw, EECD, eecd);
4859 E1000_WRITE_FLUSH(hw);
4860 udelay(eeprom->delay_usec);
4863 eecd |= E1000_EECD_CS;
4864 E1000_WRITE_REG(hw, EECD, eecd);
4865 E1000_WRITE_FLUSH(hw);
4866 udelay(eeprom->delay_usec);
4869 eecd &= ~E1000_EECD_SK;
4870 E1000_WRITE_REG(hw, EECD, eecd);
4871 E1000_WRITE_FLUSH(hw);
4872 udelay(eeprom->delay_usec);
4873 } else if (eeprom->type == e1000_eeprom_spi) {
4874 /* Toggle CS to flush commands */
4875 eecd |= E1000_EECD_CS;
4876 E1000_WRITE_REG(hw, EECD, eecd);
4877 E1000_WRITE_FLUSH(hw);
4878 udelay(eeprom->delay_usec);
4879 eecd &= ~E1000_EECD_CS;
4880 E1000_WRITE_REG(hw, EECD, eecd);
4881 E1000_WRITE_FLUSH(hw);
4882 udelay(eeprom->delay_usec);
4886 /******************************************************************************
4887 * Terminates a command by inverting the EEPROM's chip select pin
4889 * hw - Struct containing variables accessed by shared code
4890 *****************************************************************************/
4892 e1000_release_eeprom(struct e1000_hw *hw)
4896 DEBUGFUNC("e1000_release_eeprom");
4898 eecd = E1000_READ_REG(hw, EECD);
4900 if (hw->eeprom.type == e1000_eeprom_spi) {
4901 eecd |= E1000_EECD_CS; /* Pull CS high */
4902 eecd &= ~E1000_EECD_SK; /* Lower SCK */
4904 E1000_WRITE_REG(hw, EECD, eecd);
4906 udelay(hw->eeprom.delay_usec);
4907 } else if (hw->eeprom.type == e1000_eeprom_microwire) {
4908 /* cleanup eeprom */
4910 /* CS on Microwire is active-high */
4911 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
4913 E1000_WRITE_REG(hw, EECD, eecd);
4915 /* Rising edge of clock */
4916 eecd |= E1000_EECD_SK;
4917 E1000_WRITE_REG(hw, EECD, eecd);
4918 E1000_WRITE_FLUSH(hw);
4919 udelay(hw->eeprom.delay_usec);
4921 /* Falling edge of clock */
4922 eecd &= ~E1000_EECD_SK;
4923 E1000_WRITE_REG(hw, EECD, eecd);
4924 E1000_WRITE_FLUSH(hw);
4925 udelay(hw->eeprom.delay_usec);
4928 /* Stop requesting EEPROM access */
4929 if (hw->mac_type > e1000_82544) {
4930 eecd &= ~E1000_EECD_REQ;
4931 E1000_WRITE_REG(hw, EECD, eecd);
4934 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
4937 /******************************************************************************
4938 * Reads a 16 bit word from the EEPROM.
4940 * hw - Struct containing variables accessed by shared code
4941 *****************************************************************************/
4943 e1000_spi_eeprom_ready(struct e1000_hw *hw)
4945 uint16_t retry_count = 0;
4946 uint8_t spi_stat_reg;
4948 DEBUGFUNC("e1000_spi_eeprom_ready");
4950 /* Read "Status Register" repeatedly until the LSB is cleared. The
4951 * EEPROM will signal that the command has been completed by clearing
4952 * bit 0 of the internal status register. If it's not cleared within
4953 * 5 milliseconds, then error out.
4957 e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
4958 hw->eeprom.opcode_bits);
4959 spi_stat_reg = (uint8_t)e1000_shift_in_ee_bits(hw, 8);
4960 if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
4966 e1000_standby_eeprom(hw);
4967 } while (retry_count < EEPROM_MAX_RETRY_SPI);
4969 /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
4970 * only 0-5mSec on 5V devices)
4972 if (retry_count >= EEPROM_MAX_RETRY_SPI) {
4973 DEBUGOUT("SPI EEPROM Status error\n");
4974 return -E1000_ERR_EEPROM;
4977 return E1000_SUCCESS;
4980 /******************************************************************************
4981 * Reads a 16 bit word from the EEPROM.
4983 * hw - Struct containing variables accessed by shared code
4984 * offset - offset of word in the EEPROM to read
4985 * data - word read from the EEPROM
4986 * words - number of words to read
4987 *****************************************************************************/
4989 e1000_read_eeprom(struct e1000_hw *hw,
4994 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4997 DEBUGFUNC("e1000_read_eeprom");
4999 /* If eeprom is not yet detected, do so now */
5000 if (eeprom->word_size == 0)
5001 e1000_init_eeprom_params(hw);
5003 /* A check for invalid values: offset too large, too many words, and not
5006 if ((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
5008 DEBUGOUT2("\"words\" parameter out of bounds. Words = %d, size = %d\n", offset, eeprom->word_size);
5009 return -E1000_ERR_EEPROM;
5012 /* EEPROM's that don't use EERD to read require us to bit-bang the SPI
5013 * directly. In this case, we need to acquire the EEPROM so that
5014 * FW or other port software does not interrupt.
5016 if (e1000_is_onboard_nvm_eeprom(hw) == TRUE &&
5017 hw->eeprom.use_eerd == FALSE) {
5018 /* Prepare the EEPROM for bit-bang reading */
5019 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
5020 return -E1000_ERR_EEPROM;
5023 /* Eerd register EEPROM access requires no eeprom aquire/release */
5024 if (eeprom->use_eerd == TRUE)
5025 return e1000_read_eeprom_eerd(hw, offset, words, data);
5027 /* ICH EEPROM access is done via the ICH flash controller */
5028 if (eeprom->type == e1000_eeprom_ich8)
5029 return e1000_read_eeprom_ich8(hw, offset, words, data);
5031 /* Set up the SPI or Microwire EEPROM for bit-bang reading. We have
5032 * acquired the EEPROM at this point, so any returns should relase it */
5033 if (eeprom->type == e1000_eeprom_spi) {
5035 uint8_t read_opcode = EEPROM_READ_OPCODE_SPI;
5037 if (e1000_spi_eeprom_ready(hw)) {
5038 e1000_release_eeprom(hw);
5039 return -E1000_ERR_EEPROM;
5042 e1000_standby_eeprom(hw);
5044 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
5045 if ((eeprom->address_bits == 8) && (offset >= 128))
5046 read_opcode |= EEPROM_A8_OPCODE_SPI;
5048 /* Send the READ command (opcode + addr) */
5049 e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
5050 e1000_shift_out_ee_bits(hw, (uint16_t)(offset*2), eeprom->address_bits);
5052 /* Read the data. The address of the eeprom internally increments with
5053 * each byte (spi) being read, saving on the overhead of eeprom setup
5054 * and tear-down. The address counter will roll over if reading beyond
5055 * the size of the eeprom, thus allowing the entire memory to be read
5056 * starting from any offset. */
5057 for (i = 0; i < words; i++) {
5058 word_in = e1000_shift_in_ee_bits(hw, 16);
5059 data[i] = (word_in >> 8) | (word_in << 8);
5061 } else if (eeprom->type == e1000_eeprom_microwire) {
5062 for (i = 0; i < words; i++) {
5063 /* Send the READ command (opcode + addr) */
5064 e1000_shift_out_ee_bits(hw, EEPROM_READ_OPCODE_MICROWIRE,
5065 eeprom->opcode_bits);
5066 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + i),
5067 eeprom->address_bits);
5069 /* Read the data. For microwire, each word requires the overhead
5070 * of eeprom setup and tear-down. */
5071 data[i] = e1000_shift_in_ee_bits(hw, 16);
5072 e1000_standby_eeprom(hw);
5076 /* End this read operation */
5077 e1000_release_eeprom(hw);
5079 return E1000_SUCCESS;
5082 /******************************************************************************
5083 * Reads a 16 bit word from the EEPROM using the EERD register.
5085 * hw - Struct containing variables accessed by shared code
5086 * offset - offset of word in the EEPROM to read
5087 * data - word read from the EEPROM
5088 * words - number of words to read
5089 *****************************************************************************/
5091 e1000_read_eeprom_eerd(struct e1000_hw *hw,
5096 uint32_t i, eerd = 0;
5099 for (i = 0; i < words; i++) {
5100 eerd = ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) +
5101 E1000_EEPROM_RW_REG_START;
5103 E1000_WRITE_REG(hw, EERD, eerd);
5104 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_READ);
5109 data[i] = (E1000_READ_REG(hw, EERD) >> E1000_EEPROM_RW_REG_DATA);
5116 /******************************************************************************
5117 * Writes a 16 bit word from the EEPROM using the EEWR register.
5119 * hw - Struct containing variables accessed by shared code
5120 * offset - offset of word in the EEPROM to read
5121 * data - word read from the EEPROM
5122 * words - number of words to read
5123 *****************************************************************************/
5125 e1000_write_eeprom_eewr(struct e1000_hw *hw,
5130 uint32_t register_value = 0;
5134 if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
5135 return -E1000_ERR_SWFW_SYNC;
5137 for (i = 0; i < words; i++) {
5138 register_value = (data[i] << E1000_EEPROM_RW_REG_DATA) |
5139 ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) |
5140 E1000_EEPROM_RW_REG_START;
5142 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
5147 E1000_WRITE_REG(hw, EEWR, register_value);
5149 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
5156 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
5160 /******************************************************************************
5161 * Polls the status bit (bit 1) of the EERD to determine when the read is done.
5163 * hw - Struct containing variables accessed by shared code
5164 *****************************************************************************/
5166 e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd)
5168 uint32_t attempts = 100000;
5169 uint32_t i, reg = 0;
5170 int32_t done = E1000_ERR_EEPROM;
5172 for (i = 0; i < attempts; i++) {
5173 if (eerd == E1000_EEPROM_POLL_READ)
5174 reg = E1000_READ_REG(hw, EERD);
5176 reg = E1000_READ_REG(hw, EEWR);
5178 if (reg & E1000_EEPROM_RW_REG_DONE) {
5179 done = E1000_SUCCESS;
5188 /***************************************************************************
5189 * Description: Determines if the onboard NVM is FLASH or EEPROM.
5191 * hw - Struct containing variables accessed by shared code
5192 ****************************************************************************/
5194 e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw)
5198 DEBUGFUNC("e1000_is_onboard_nvm_eeprom");
5200 if (hw->mac_type == e1000_ich8lan)
5203 if (hw->mac_type == e1000_82573) {
5204 eecd = E1000_READ_REG(hw, EECD);
5206 /* Isolate bits 15 & 16 */
5207 eecd = ((eecd >> 15) & 0x03);
5209 /* If both bits are set, device is Flash type */
5217 /******************************************************************************
5218 * Verifies that the EEPROM has a valid checksum
5220 * hw - Struct containing variables accessed by shared code
5222 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
5223 * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
5225 *****************************************************************************/
5227 e1000_validate_eeprom_checksum(struct e1000_hw *hw)
5229 uint16_t checksum = 0;
5230 uint16_t i, eeprom_data;
5232 DEBUGFUNC("e1000_validate_eeprom_checksum");
5234 if ((hw->mac_type == e1000_82573) &&
5235 (e1000_is_onboard_nvm_eeprom(hw) == FALSE)) {
5236 /* Check bit 4 of word 10h. If it is 0, firmware is done updating
5237 * 10h-12h. Checksum may need to be fixed. */
5238 e1000_read_eeprom(hw, 0x10, 1, &eeprom_data);
5239 if ((eeprom_data & 0x10) == 0) {
5240 /* Read 0x23 and check bit 15. This bit is a 1 when the checksum
5241 * has already been fixed. If the checksum is still wrong and this
5242 * bit is a 1, we need to return bad checksum. Otherwise, we need
5243 * to set this bit to a 1 and update the checksum. */
5244 e1000_read_eeprom(hw, 0x23, 1, &eeprom_data);
5245 if ((eeprom_data & 0x8000) == 0) {
5246 eeprom_data |= 0x8000;
5247 e1000_write_eeprom(hw, 0x23, 1, &eeprom_data);
5248 e1000_update_eeprom_checksum(hw);
5253 if (hw->mac_type == e1000_ich8lan) {
5254 /* Drivers must allocate the shadow ram structure for the
5255 * EEPROM checksum to be updated. Otherwise, this bit as well
5256 * as the checksum must both be set correctly for this
5257 * validation to pass.
5259 e1000_read_eeprom(hw, 0x19, 1, &eeprom_data);
5260 if ((eeprom_data & 0x40) == 0) {
5261 eeprom_data |= 0x40;
5262 e1000_write_eeprom(hw, 0x19, 1, &eeprom_data);
5263 e1000_update_eeprom_checksum(hw);
5267 for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
5268 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
5269 DEBUGOUT("EEPROM Read Error\n");
5270 return -E1000_ERR_EEPROM;
5272 checksum += eeprom_data;
5275 if (checksum == (uint16_t) EEPROM_SUM)
5276 return E1000_SUCCESS;
5278 DEBUGOUT("EEPROM Checksum Invalid\n");
5279 return -E1000_ERR_EEPROM;
5283 /******************************************************************************
5284 * Calculates the EEPROM checksum and writes it to the EEPROM
5286 * hw - Struct containing variables accessed by shared code
5288 * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA.
5289 * Writes the difference to word offset 63 of the EEPROM.
5290 *****************************************************************************/
5292 e1000_update_eeprom_checksum(struct e1000_hw *hw)
5295 uint16_t checksum = 0;
5296 uint16_t i, eeprom_data;
5298 DEBUGFUNC("e1000_update_eeprom_checksum");
5300 for (i = 0; i < EEPROM_CHECKSUM_REG; i++) {
5301 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
5302 DEBUGOUT("EEPROM Read Error\n");
5303 return -E1000_ERR_EEPROM;
5305 checksum += eeprom_data;
5307 checksum = (uint16_t) EEPROM_SUM - checksum;
5308 if (e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) {
5309 DEBUGOUT("EEPROM Write Error\n");
5310 return -E1000_ERR_EEPROM;
5311 } else if (hw->eeprom.type == e1000_eeprom_flash) {
5312 e1000_commit_shadow_ram(hw);
5313 } else if (hw->eeprom.type == e1000_eeprom_ich8) {
5314 e1000_commit_shadow_ram(hw);
5315 /* Reload the EEPROM, or else modifications will not appear
5316 * until after next adapter reset. */
5317 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
5318 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
5319 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
5322 return E1000_SUCCESS;
5325 /******************************************************************************
5326 * Parent function for writing words to the different EEPROM types.
5328 * hw - Struct containing variables accessed by shared code
5329 * offset - offset within the EEPROM to be written to
5330 * words - number of words to write
5331 * data - 16 bit word to be written to the EEPROM
5333 * If e1000_update_eeprom_checksum is not called after this function, the
5334 * EEPROM will most likely contain an invalid checksum.
5335 *****************************************************************************/
5337 e1000_write_eeprom(struct e1000_hw *hw,
5342 struct e1000_eeprom_info *eeprom = &hw->eeprom;
5345 DEBUGFUNC("e1000_write_eeprom");
5347 /* If eeprom is not yet detected, do so now */
5348 if (eeprom->word_size == 0)
5349 e1000_init_eeprom_params(hw);
5351 /* A check for invalid values: offset too large, too many words, and not
5354 if ((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
5356 DEBUGOUT("\"words\" parameter out of bounds\n");
5357 return -E1000_ERR_EEPROM;
5360 /* 82573 writes only through eewr */
5361 if (eeprom->use_eewr == TRUE)
5362 return e1000_write_eeprom_eewr(hw, offset, words, data);
5364 if (eeprom->type == e1000_eeprom_ich8)
5365 return e1000_write_eeprom_ich8(hw, offset, words, data);
5367 /* Prepare the EEPROM for writing */
5368 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
5369 return -E1000_ERR_EEPROM;
5371 if (eeprom->type == e1000_eeprom_microwire) {
5372 status = e1000_write_eeprom_microwire(hw, offset, words, data);
5374 status = e1000_write_eeprom_spi(hw, offset, words, data);
5378 /* Done with writing */
5379 e1000_release_eeprom(hw);
5384 /******************************************************************************
5385 * Writes a 16 bit word to a given offset in an SPI EEPROM.
5387 * hw - Struct containing variables accessed by shared code
5388 * offset - offset within the EEPROM to be written to
5389 * words - number of words to write
5390 * data - pointer to array of 8 bit words to be written to the EEPROM
5392 *****************************************************************************/
5394 e1000_write_eeprom_spi(struct e1000_hw *hw,
5399 struct e1000_eeprom_info *eeprom = &hw->eeprom;
5402 DEBUGFUNC("e1000_write_eeprom_spi");
5404 while (widx < words) {
5405 uint8_t write_opcode = EEPROM_WRITE_OPCODE_SPI;
5407 if (e1000_spi_eeprom_ready(hw)) return -E1000_ERR_EEPROM;
5409 e1000_standby_eeprom(hw);
5411 /* Send the WRITE ENABLE command (8 bit opcode ) */
5412 e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI,
5413 eeprom->opcode_bits);
5415 e1000_standby_eeprom(hw);
5417 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
5418 if ((eeprom->address_bits == 8) && (offset >= 128))
5419 write_opcode |= EEPROM_A8_OPCODE_SPI;
5421 /* Send the Write command (8-bit opcode + addr) */
5422 e1000_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits);
5424 e1000_shift_out_ee_bits(hw, (uint16_t)((offset + widx)*2),
5425 eeprom->address_bits);
5429 /* Loop to allow for up to whole page write (32 bytes) of eeprom */
5430 while (widx < words) {
5431 uint16_t word_out = data[widx];
5432 word_out = (word_out >> 8) | (word_out << 8);
5433 e1000_shift_out_ee_bits(hw, word_out, 16);
5436 /* Some larger eeprom sizes are capable of a 32-byte PAGE WRITE
5437 * operation, while the smaller eeproms are capable of an 8-byte
5438 * PAGE WRITE operation. Break the inner loop to pass new address
5440 if ((((offset + widx)*2) % eeprom->page_size) == 0) {
5441 e1000_standby_eeprom(hw);
5447 return E1000_SUCCESS;
5450 /******************************************************************************
5451 * Writes a 16 bit word to a given offset in a Microwire EEPROM.
5453 * hw - Struct containing variables accessed by shared code
5454 * offset - offset within the EEPROM to be written to
5455 * words - number of words to write
5456 * data - pointer to array of 16 bit words to be written to the EEPROM
5458 *****************************************************************************/
5460 e1000_write_eeprom_microwire(struct e1000_hw *hw,
5465 struct e1000_eeprom_info *eeprom = &hw->eeprom;
5467 uint16_t words_written = 0;
5470 DEBUGFUNC("e1000_write_eeprom_microwire");
5472 /* Send the write enable command to the EEPROM (3-bit opcode plus
5473 * 6/8-bit dummy address beginning with 11). It's less work to include
5474 * the 11 of the dummy address as part of the opcode than it is to shift
5475 * it over the correct number of bits for the address. This puts the
5476 * EEPROM into write/erase mode.
5478 e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE,
5479 (uint16_t)(eeprom->opcode_bits + 2));
5481 e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
5483 /* Prepare the EEPROM */
5484 e1000_standby_eeprom(hw);
5486 while (words_written < words) {
5487 /* Send the Write command (3-bit opcode + addr) */
5488 e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE,
5489 eeprom->opcode_bits);
5491 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + words_written),
5492 eeprom->address_bits);
5495 e1000_shift_out_ee_bits(hw, data[words_written], 16);
5497 /* Toggle the CS line. This in effect tells the EEPROM to execute
5498 * the previous command.
5500 e1000_standby_eeprom(hw);
5502 /* Read DO repeatedly until it is high (equal to '1'). The EEPROM will
5503 * signal that the command has been completed by raising the DO signal.
5504 * If DO does not go high in 10 milliseconds, then error out.
5506 for (i = 0; i < 200; i++) {
5507 eecd = E1000_READ_REG(hw, EECD);
5508 if (eecd & E1000_EECD_DO) break;
5512 DEBUGOUT("EEPROM Write did not complete\n");
5513 return -E1000_ERR_EEPROM;
5516 /* Recover from write */
5517 e1000_standby_eeprom(hw);
5522 /* Send the write disable command to the EEPROM (3-bit opcode plus
5523 * 6/8-bit dummy address beginning with 10). It's less work to include
5524 * the 10 of the dummy address as part of the opcode than it is to shift
5525 * it over the correct number of bits for the address. This takes the
5526 * EEPROM out of write/erase mode.
5528 e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE,
5529 (uint16_t)(eeprom->opcode_bits + 2));
5531 e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
5533 return E1000_SUCCESS;
5536 /******************************************************************************
5537 * Flushes the cached eeprom to NVM. This is done by saving the modified values
5538 * in the eeprom cache and the non modified values in the currently active bank
5541 * hw - Struct containing variables accessed by shared code
5542 * offset - offset of word in the EEPROM to read
5543 * data - word read from the EEPROM
5544 * words - number of words to read
5545 *****************************************************************************/
5547 e1000_commit_shadow_ram(struct e1000_hw *hw)
5549 uint32_t attempts = 100000;
5553 int32_t error = E1000_SUCCESS;
5554 uint32_t old_bank_offset = 0;
5555 uint32_t new_bank_offset = 0;
5556 uint8_t low_byte = 0;
5557 uint8_t high_byte = 0;
5558 boolean_t sector_write_failed = FALSE;
5560 if (hw->mac_type == e1000_82573) {
5561 /* The flop register will be used to determine if flash type is STM */
5562 flop = E1000_READ_REG(hw, FLOP);
5563 for (i=0; i < attempts; i++) {
5564 eecd = E1000_READ_REG(hw, EECD);
5565 if ((eecd & E1000_EECD_FLUPD) == 0) {
5571 if (i == attempts) {
5572 return -E1000_ERR_EEPROM;
5575 /* If STM opcode located in bits 15:8 of flop, reset firmware */
5576 if ((flop & 0xFF00) == E1000_STM_OPCODE) {
5577 E1000_WRITE_REG(hw, HICR, E1000_HICR_FW_RESET);
5580 /* Perform the flash update */
5581 E1000_WRITE_REG(hw, EECD, eecd | E1000_EECD_FLUPD);
5583 for (i=0; i < attempts; i++) {
5584 eecd = E1000_READ_REG(hw, EECD);
5585 if ((eecd & E1000_EECD_FLUPD) == 0) {
5591 if (i == attempts) {
5592 return -E1000_ERR_EEPROM;
5596 if (hw->mac_type == e1000_ich8lan && hw->eeprom_shadow_ram != NULL) {
5597 /* We're writing to the opposite bank so if we're on bank 1,
5598 * write to bank 0 etc. We also need to erase the segment that
5599 * is going to be written */
5600 if (!(E1000_READ_REG(hw, EECD) & E1000_EECD_SEC1VAL)) {
5601 new_bank_offset = hw->flash_bank_size * 2;
5602 old_bank_offset = 0;
5603 e1000_erase_ich8_4k_segment(hw, 1);
5605 old_bank_offset = hw->flash_bank_size * 2;
5606 new_bank_offset = 0;
5607 e1000_erase_ich8_4k_segment(hw, 0);
5610 sector_write_failed = FALSE;
5611 /* Loop for every byte in the shadow RAM,
5612 * which is in units of words. */
5613 for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
5614 /* Determine whether to write the value stored
5615 * in the other NVM bank or a modified value stored
5616 * in the shadow RAM */
5617 if (hw->eeprom_shadow_ram[i].modified == TRUE) {
5618 low_byte = (uint8_t)hw->eeprom_shadow_ram[i].eeprom_word;
5620 error = e1000_verify_write_ich8_byte(hw,
5621 (i << 1) + new_bank_offset, low_byte);
5623 if (error != E1000_SUCCESS)
5624 sector_write_failed = TRUE;
5627 (uint8_t)(hw->eeprom_shadow_ram[i].eeprom_word >> 8);
5631 e1000_read_ich8_byte(hw, (i << 1) + old_bank_offset,
5634 error = e1000_verify_write_ich8_byte(hw,
5635 (i << 1) + new_bank_offset, low_byte);
5637 if (error != E1000_SUCCESS)
5638 sector_write_failed = TRUE;
5640 e1000_read_ich8_byte(hw, (i << 1) + old_bank_offset + 1,
5646 /* If the write of the low byte was successful, go ahread and
5647 * write the high byte while checking to make sure that if it
5648 * is the signature byte, then it is handled properly */
5649 if (sector_write_failed == FALSE) {
5650 /* If the word is 0x13, then make sure the signature bits
5651 * (15:14) are 11b until the commit has completed.
5652 * This will allow us to write 10b which indicates the
5653 * signature is valid. We want to do this after the write
5654 * has completed so that we don't mark the segment valid
5655 * while the write is still in progress */
5656 if (i == E1000_ICH_NVM_SIG_WORD)
5657 high_byte = E1000_ICH_NVM_SIG_MASK | high_byte;
5659 error = e1000_verify_write_ich8_byte(hw,
5660 (i << 1) + new_bank_offset + 1, high_byte);
5661 if (error != E1000_SUCCESS)
5662 sector_write_failed = TRUE;
5665 /* If the write failed then break from the loop and
5666 * return an error */
5671 /* Don't bother writing the segment valid bits if sector
5672 * programming failed. */
5673 if (sector_write_failed == FALSE) {
5674 /* Finally validate the new segment by setting bit 15:14
5675 * to 10b in word 0x13 , this can be done without an
5676 * erase as well since these bits are 11 to start with
5677 * and we need to change bit 14 to 0b */
5678 e1000_read_ich8_byte(hw,
5679 E1000_ICH_NVM_SIG_WORD * 2 + 1 + new_bank_offset,
5682 error = e1000_verify_write_ich8_byte(hw,
5683 E1000_ICH_NVM_SIG_WORD * 2 + 1 + new_bank_offset, high_byte);
5684 /* And invalidate the previously valid segment by setting
5685 * its signature word (0x13) high_byte to 0b. This can be
5686 * done without an erase because flash erase sets all bits
5687 * to 1's. We can write 1's to 0's without an erase */
5688 if (error == E1000_SUCCESS) {
5689 error = e1000_verify_write_ich8_byte(hw,
5690 E1000_ICH_NVM_SIG_WORD * 2 + 1 + old_bank_offset, 0);
5693 /* Clear the now not used entry in the cache */
5694 for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
5695 hw->eeprom_shadow_ram[i].modified = FALSE;
5696 hw->eeprom_shadow_ram[i].eeprom_word = 0xFFFF;
5704 /******************************************************************************
5705 * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
5706 * second function of dual function devices
5708 * hw - Struct containing variables accessed by shared code
5709 *****************************************************************************/
5711 e1000_read_mac_addr(struct e1000_hw * hw)
5714 uint16_t eeprom_data, i;
5716 DEBUGFUNC("e1000_read_mac_addr");
5718 for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
5720 if (e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
5721 DEBUGOUT("EEPROM Read Error\n");
5722 return -E1000_ERR_EEPROM;
5724 hw->perm_mac_addr[i] = (uint8_t) (eeprom_data & 0x00FF);
5725 hw->perm_mac_addr[i+1] = (uint8_t) (eeprom_data >> 8);
5728 switch (hw->mac_type) {
5732 case e1000_82546_rev_3:
5734 case e1000_80003es2lan:
5735 if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
5736 hw->perm_mac_addr[5] ^= 0x01;
5740 for (i = 0; i < NODE_ADDRESS_SIZE; i++)
5741 hw->mac_addr[i] = hw->perm_mac_addr[i];
5742 return E1000_SUCCESS;
5745 /******************************************************************************
5746 * Initializes receive address filters.
5748 * hw - Struct containing variables accessed by shared code
5750 * Places the MAC address in receive address register 0 and clears the rest
5751 * of the receive addresss registers. Clears the multicast table. Assumes
5752 * the receiver is in reset when the routine is called.
5753 *****************************************************************************/
5755 e1000_init_rx_addrs(struct e1000_hw *hw)
5760 DEBUGFUNC("e1000_init_rx_addrs");
5762 /* Setup the receive address. */
5763 DEBUGOUT("Programming MAC Address into RAR[0]\n");
5765 e1000_rar_set(hw, hw->mac_addr, 0);
5767 rar_num = E1000_RAR_ENTRIES;
5769 /* Reserve a spot for the Locally Administered Address to work around
5770 * an 82571 issue in which a reset on one port will reload the MAC on
5771 * the other port. */
5772 if ((hw->mac_type == e1000_82571) && (hw->laa_is_present == TRUE))
5774 if (hw->mac_type == e1000_ich8lan)
5775 rar_num = E1000_RAR_ENTRIES_ICH8LAN;
5777 /* Zero out the other 15 receive addresses. */
5778 DEBUGOUT("Clearing RAR[1-15]\n");
5779 for (i = 1; i < rar_num; i++) {
5780 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
5781 E1000_WRITE_FLUSH(hw);
5782 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
5783 E1000_WRITE_FLUSH(hw);
5787 /******************************************************************************
5788 * Hashes an address to determine its location in the multicast table
5790 * hw - Struct containing variables accessed by shared code
5791 * mc_addr - the multicast address to hash
5792 *****************************************************************************/
5794 e1000_hash_mc_addr(struct e1000_hw *hw,
5797 uint32_t hash_value = 0;
5799 /* The portion of the address that is used for the hash table is
5800 * determined by the mc_filter_type setting.
5802 switch (hw->mc_filter_type) {
5803 /* [0] [1] [2] [3] [4] [5]
5808 if (hw->mac_type == e1000_ich8lan) {
5809 /* [47:38] i.e. 0x158 for above example address */
5810 hash_value = ((mc_addr[4] >> 6) | (((uint16_t) mc_addr[5]) << 2));
5812 /* [47:36] i.e. 0x563 for above example address */
5813 hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4));
5817 if (hw->mac_type == e1000_ich8lan) {
5818 /* [46:37] i.e. 0x2B1 for above example address */
5819 hash_value = ((mc_addr[4] >> 5) | (((uint16_t) mc_addr[5]) << 3));
5821 /* [46:35] i.e. 0xAC6 for above example address */
5822 hash_value = ((mc_addr[4] >> 3) | (((uint16_t) mc_addr[5]) << 5));
5826 if (hw->mac_type == e1000_ich8lan) {
5827 /*[45:36] i.e. 0x163 for above example address */
5828 hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4));
5830 /* [45:34] i.e. 0x5D8 for above example address */
5831 hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6));
5835 if (hw->mac_type == e1000_ich8lan) {
5836 /* [43:34] i.e. 0x18D for above example address */
5837 hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6));
5839 /* [43:32] i.e. 0x634 for above example address */
5840 hash_value = ((mc_addr[4]) | (((uint16_t) mc_addr[5]) << 8));
5845 hash_value &= 0xFFF;
5846 if (hw->mac_type == e1000_ich8lan)
5847 hash_value &= 0x3FF;
5852 /******************************************************************************
5853 * Sets the bit in the multicast table corresponding to the hash value.
5855 * hw - Struct containing variables accessed by shared code
5856 * hash_value - Multicast address hash value
5857 *****************************************************************************/
5859 e1000_mta_set(struct e1000_hw *hw,
5860 uint32_t hash_value)
5862 uint32_t hash_bit, hash_reg;
5866 /* The MTA is a register array of 128 32-bit registers.
5867 * It is treated like an array of 4096 bits. We want to set
5868 * bit BitArray[hash_value]. So we figure out what register
5869 * the bit is in, read it, OR in the new bit, then write
5870 * back the new value. The register is determined by the
5871 * upper 7 bits of the hash value and the bit within that
5872 * register are determined by the lower 5 bits of the value.
5874 hash_reg = (hash_value >> 5) & 0x7F;
5875 if (hw->mac_type == e1000_ich8lan)
5878 hash_bit = hash_value & 0x1F;
5880 mta = E1000_READ_REG_ARRAY(hw, MTA, hash_reg);
5882 mta |= (1 << hash_bit);
5884 /* If we are on an 82544 and we are trying to write an odd offset
5885 * in the MTA, save off the previous entry before writing and
5886 * restore the old value after writing.
5888 if ((hw->mac_type == e1000_82544) && ((hash_reg & 0x1) == 1)) {
5889 temp = E1000_READ_REG_ARRAY(hw, MTA, (hash_reg - 1));
5890 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
5891 E1000_WRITE_FLUSH(hw);
5892 E1000_WRITE_REG_ARRAY(hw, MTA, (hash_reg - 1), temp);
5893 E1000_WRITE_FLUSH(hw);
5895 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
5896 E1000_WRITE_FLUSH(hw);
5900 /******************************************************************************
5901 * Puts an ethernet address into a receive address register.
5903 * hw - Struct containing variables accessed by shared code
5904 * addr - Address to put into receive address register
5905 * index - Receive address register to write
5906 *****************************************************************************/
5908 e1000_rar_set(struct e1000_hw *hw,
5912 uint32_t rar_low, rar_high;
5914 /* HW expects these in little endian so we reverse the byte order
5915 * from network order (big endian) to little endian
5917 rar_low = ((uint32_t) addr[0] |
5918 ((uint32_t) addr[1] << 8) |
5919 ((uint32_t) addr[2] << 16) | ((uint32_t) addr[3] << 24));
5920 rar_high = ((uint32_t) addr[4] | ((uint32_t) addr[5] << 8));
5922 /* Disable Rx and flush all Rx frames before enabling RSS to avoid Rx
5926 * If there are any Rx frames queued up or otherwise present in the HW
5927 * before RSS is enabled, and then we enable RSS, the HW Rx unit will
5928 * hang. To work around this issue, we have to disable receives and
5929 * flush out all Rx frames before we enable RSS. To do so, we modify we
5930 * redirect all Rx traffic to manageability and then reset the HW.
5931 * This flushes away Rx frames, and (since the redirections to
5932 * manageability persists across resets) keeps new ones from coming in
5933 * while we work. Then, we clear the Address Valid AV bit for all MAC
5934 * addresses and undo the re-direction to manageability.
5935 * Now, frames are coming in again, but the MAC won't accept them, so
5936 * far so good. We now proceed to initialize RSS (if necessary) and
5937 * configure the Rx unit. Last, we re-enable the AV bits and continue
5940 switch (hw->mac_type) {
5943 case e1000_80003es2lan:
5944 if (hw->leave_av_bit_off == TRUE)
5947 /* Indicate to hardware the Address is Valid. */
5948 rar_high |= E1000_RAH_AV;
5952 E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
5953 E1000_WRITE_FLUSH(hw);
5954 E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
5955 E1000_WRITE_FLUSH(hw);
5958 /******************************************************************************
5959 * Writes a value to the specified offset in the VLAN filter table.
5961 * hw - Struct containing variables accessed by shared code
5962 * offset - Offset in VLAN filer table to write
5963 * value - Value to write into VLAN filter table
5964 *****************************************************************************/
5966 e1000_write_vfta(struct e1000_hw *hw,
5972 if (hw->mac_type == e1000_ich8lan)
5975 if ((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) {
5976 temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1));
5977 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
5978 E1000_WRITE_FLUSH(hw);
5979 E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp);
5980 E1000_WRITE_FLUSH(hw);
5982 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
5983 E1000_WRITE_FLUSH(hw);
5987 /******************************************************************************
5988 * Clears the VLAN filer table
5990 * hw - Struct containing variables accessed by shared code
5991 *****************************************************************************/
5993 e1000_clear_vfta(struct e1000_hw *hw)
5996 uint32_t vfta_value = 0;
5997 uint32_t vfta_offset = 0;
5998 uint32_t vfta_bit_in_reg = 0;
6000 if (hw->mac_type == e1000_ich8lan)
6003 if (hw->mac_type == e1000_82573) {
6004 if (hw->mng_cookie.vlan_id != 0) {
6005 /* The VFTA is a 4096b bit-field, each identifying a single VLAN
6006 * ID. The following operations determine which 32b entry
6007 * (i.e. offset) into the array we want to set the VLAN ID
6008 * (i.e. bit) of the manageability unit. */
6009 vfta_offset = (hw->mng_cookie.vlan_id >>
6010 E1000_VFTA_ENTRY_SHIFT) &
6011 E1000_VFTA_ENTRY_MASK;
6012 vfta_bit_in_reg = 1 << (hw->mng_cookie.vlan_id &
6013 E1000_VFTA_ENTRY_BIT_SHIFT_MASK);
6016 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
6017 /* If the offset we want to clear is the same offset of the
6018 * manageability VLAN ID, then clear all bits except that of the
6019 * manageability unit */
6020 vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0;
6021 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, vfta_value);
6022 E1000_WRITE_FLUSH(hw);
6027 e1000_id_led_init(struct e1000_hw * hw)
6030 const uint32_t ledctl_mask = 0x000000FF;
6031 const uint32_t ledctl_on = E1000_LEDCTL_MODE_LED_ON;
6032 const uint32_t ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
6033 uint16_t eeprom_data, i, temp;
6034 const uint16_t led_mask = 0x0F;
6036 DEBUGFUNC("e1000_id_led_init");
6038 if (hw->mac_type < e1000_82540) {
6040 return E1000_SUCCESS;
6043 ledctl = E1000_READ_REG(hw, LEDCTL);
6044 hw->ledctl_default = ledctl;
6045 hw->ledctl_mode1 = hw->ledctl_default;
6046 hw->ledctl_mode2 = hw->ledctl_default;
6048 if (e1000_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, 1, &eeprom_data) < 0) {
6049 DEBUGOUT("EEPROM Read Error\n");
6050 return -E1000_ERR_EEPROM;
6053 if ((hw->mac_type == e1000_82573) &&
6054 (eeprom_data == ID_LED_RESERVED_82573))
6055 eeprom_data = ID_LED_DEFAULT_82573;
6056 else if ((eeprom_data == ID_LED_RESERVED_0000) ||
6057 (eeprom_data == ID_LED_RESERVED_FFFF)) {
6058 if (hw->mac_type == e1000_ich8lan)
6059 eeprom_data = ID_LED_DEFAULT_ICH8LAN;
6061 eeprom_data = ID_LED_DEFAULT;
6064 for (i = 0; i < 4; i++) {
6065 temp = (eeprom_data >> (i << 2)) & led_mask;
6067 case ID_LED_ON1_DEF2:
6068 case ID_LED_ON1_ON2:
6069 case ID_LED_ON1_OFF2:
6070 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
6071 hw->ledctl_mode1 |= ledctl_on << (i << 3);
6073 case ID_LED_OFF1_DEF2:
6074 case ID_LED_OFF1_ON2:
6075 case ID_LED_OFF1_OFF2:
6076 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
6077 hw->ledctl_mode1 |= ledctl_off << (i << 3);
6084 case ID_LED_DEF1_ON2:
6085 case ID_LED_ON1_ON2:
6086 case ID_LED_OFF1_ON2:
6087 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
6088 hw->ledctl_mode2 |= ledctl_on << (i << 3);
6090 case ID_LED_DEF1_OFF2:
6091 case ID_LED_ON1_OFF2:
6092 case ID_LED_OFF1_OFF2:
6093 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
6094 hw->ledctl_mode2 |= ledctl_off << (i << 3);
6101 return E1000_SUCCESS;
6104 /******************************************************************************
6105 * Prepares SW controlable LED for use and saves the current state of the LED.
6107 * hw - Struct containing variables accessed by shared code
6108 *****************************************************************************/
6110 e1000_setup_led(struct e1000_hw *hw)
6113 int32_t ret_val = E1000_SUCCESS;
6115 DEBUGFUNC("e1000_setup_led");
6117 switch (hw->mac_type) {
6118 case e1000_82542_rev2_0:
6119 case e1000_82542_rev2_1:
6122 /* No setup necessary */
6126 case e1000_82541_rev_2:
6127 case e1000_82547_rev_2:
6128 /* Turn off PHY Smart Power Down (if enabled) */
6129 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
6130 &hw->phy_spd_default);
6133 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
6134 (uint16_t)(hw->phy_spd_default &
6135 ~IGP01E1000_GMII_SPD));
6140 if (hw->media_type == e1000_media_type_fiber) {
6141 ledctl = E1000_READ_REG(hw, LEDCTL);
6142 /* Save current LEDCTL settings */
6143 hw->ledctl_default = ledctl;
6145 ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
6146 E1000_LEDCTL_LED0_BLINK |
6147 E1000_LEDCTL_LED0_MODE_MASK);
6148 ledctl |= (E1000_LEDCTL_MODE_LED_OFF <<
6149 E1000_LEDCTL_LED0_MODE_SHIFT);
6150 E1000_WRITE_REG(hw, LEDCTL, ledctl);
6151 } else if (hw->media_type == e1000_media_type_copper)
6152 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
6156 return E1000_SUCCESS;
6160 /******************************************************************************
6161 * Used on 82571 and later Si that has LED blink bits.
6162 * Callers must use their own timer and should have already called
6163 * e1000_id_led_init()
6164 * Call e1000_cleanup led() to stop blinking
6166 * hw - Struct containing variables accessed by shared code
6167 *****************************************************************************/
6169 e1000_blink_led_start(struct e1000_hw *hw)
6172 uint32_t ledctl_blink = 0;
6174 DEBUGFUNC("e1000_id_led_blink_on");
6176 if (hw->mac_type < e1000_82571) {
6178 return E1000_SUCCESS;
6180 if (hw->media_type == e1000_media_type_fiber) {
6181 /* always blink LED0 for PCI-E fiber */
6182 ledctl_blink = E1000_LEDCTL_LED0_BLINK |
6183 (E1000_LEDCTL_MODE_LED_ON << E1000_LEDCTL_LED0_MODE_SHIFT);
6185 /* set the blink bit for each LED that's "on" (0x0E) in ledctl_mode2 */
6186 ledctl_blink = hw->ledctl_mode2;
6187 for (i=0; i < 4; i++)
6188 if (((hw->ledctl_mode2 >> (i * 8)) & 0xFF) ==
6189 E1000_LEDCTL_MODE_LED_ON)
6190 ledctl_blink |= (E1000_LEDCTL_LED0_BLINK << (i * 8));
6193 E1000_WRITE_REG(hw, LEDCTL, ledctl_blink);
6195 return E1000_SUCCESS;
6198 /******************************************************************************
6199 * Restores the saved state of the SW controlable LED.
6201 * hw - Struct containing variables accessed by shared code
6202 *****************************************************************************/
6204 e1000_cleanup_led(struct e1000_hw *hw)
6206 int32_t ret_val = E1000_SUCCESS;
6208 DEBUGFUNC("e1000_cleanup_led");
6210 switch (hw->mac_type) {
6211 case e1000_82542_rev2_0:
6212 case e1000_82542_rev2_1:
6215 /* No cleanup necessary */
6219 case e1000_82541_rev_2:
6220 case e1000_82547_rev_2:
6221 /* Turn on PHY Smart Power Down (if previously enabled) */
6222 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
6223 hw->phy_spd_default);
6228 if (hw->phy_type == e1000_phy_ife) {
6229 e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
6232 /* Restore LEDCTL settings */
6233 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_default);
6237 return E1000_SUCCESS;
6240 /******************************************************************************
6241 * Turns on the software controllable LED
6243 * hw - Struct containing variables accessed by shared code
6244 *****************************************************************************/
6246 e1000_led_on(struct e1000_hw *hw)
6248 uint32_t ctrl = E1000_READ_REG(hw, CTRL);
6250 DEBUGFUNC("e1000_led_on");
6252 switch (hw->mac_type) {
6253 case e1000_82542_rev2_0:
6254 case e1000_82542_rev2_1:
6256 /* Set SW Defineable Pin 0 to turn on the LED */
6257 ctrl |= E1000_CTRL_SWDPIN0;
6258 ctrl |= E1000_CTRL_SWDPIO0;
6261 if (hw->media_type == e1000_media_type_fiber) {
6262 /* Set SW Defineable Pin 0 to turn on the LED */
6263 ctrl |= E1000_CTRL_SWDPIN0;
6264 ctrl |= E1000_CTRL_SWDPIO0;
6266 /* Clear SW Defineable Pin 0 to turn on the LED */
6267 ctrl &= ~E1000_CTRL_SWDPIN0;
6268 ctrl |= E1000_CTRL_SWDPIO0;
6272 if (hw->media_type == e1000_media_type_fiber) {
6273 /* Clear SW Defineable Pin 0 to turn on the LED */
6274 ctrl &= ~E1000_CTRL_SWDPIN0;
6275 ctrl |= E1000_CTRL_SWDPIO0;
6276 } else if (hw->phy_type == e1000_phy_ife) {
6277 e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED,
6278 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_ON));
6279 } else if (hw->media_type == e1000_media_type_copper) {
6280 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode2);
6281 return E1000_SUCCESS;
6286 E1000_WRITE_REG(hw, CTRL, ctrl);
6288 return E1000_SUCCESS;
6291 /******************************************************************************
6292 * Turns off the software controllable LED
6294 * hw - Struct containing variables accessed by shared code
6295 *****************************************************************************/
6297 e1000_led_off(struct e1000_hw *hw)
6299 uint32_t ctrl = E1000_READ_REG(hw, CTRL);
6301 DEBUGFUNC("e1000_led_off");
6303 switch (hw->mac_type) {
6304 case e1000_82542_rev2_0:
6305 case e1000_82542_rev2_1:
6307 /* Clear SW Defineable Pin 0 to turn off the LED */
6308 ctrl &= ~E1000_CTRL_SWDPIN0;
6309 ctrl |= E1000_CTRL_SWDPIO0;
6312 if (hw->media_type == e1000_media_type_fiber) {
6313 /* Clear SW Defineable Pin 0 to turn off the LED */
6314 ctrl &= ~E1000_CTRL_SWDPIN0;
6315 ctrl |= E1000_CTRL_SWDPIO0;
6317 /* Set SW Defineable Pin 0 to turn off the LED */
6318 ctrl |= E1000_CTRL_SWDPIN0;
6319 ctrl |= E1000_CTRL_SWDPIO0;
6323 if (hw->media_type == e1000_media_type_fiber) {
6324 /* Set SW Defineable Pin 0 to turn off the LED */
6325 ctrl |= E1000_CTRL_SWDPIN0;
6326 ctrl |= E1000_CTRL_SWDPIO0;
6327 } else if (hw->phy_type == e1000_phy_ife) {
6328 e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED,
6329 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_OFF));
6330 } else if (hw->media_type == e1000_media_type_copper) {
6331 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
6332 return E1000_SUCCESS;
6337 E1000_WRITE_REG(hw, CTRL, ctrl);
6339 return E1000_SUCCESS;
6342 /******************************************************************************
6343 * Clears all hardware statistics counters.
6345 * hw - Struct containing variables accessed by shared code
6346 *****************************************************************************/
6348 e1000_clear_hw_cntrs(struct e1000_hw *hw)
6350 volatile uint32_t temp;
6352 temp = E1000_READ_REG(hw, CRCERRS);
6353 temp = E1000_READ_REG(hw, SYMERRS);
6354 temp = E1000_READ_REG(hw, MPC);
6355 temp = E1000_READ_REG(hw, SCC);
6356 temp = E1000_READ_REG(hw, ECOL);
6357 temp = E1000_READ_REG(hw, MCC);
6358 temp = E1000_READ_REG(hw, LATECOL);
6359 temp = E1000_READ_REG(hw, COLC);
6360 temp = E1000_READ_REG(hw, DC);
6361 temp = E1000_READ_REG(hw, SEC);
6362 temp = E1000_READ_REG(hw, RLEC);
6363 temp = E1000_READ_REG(hw, XONRXC);
6364 temp = E1000_READ_REG(hw, XONTXC);
6365 temp = E1000_READ_REG(hw, XOFFRXC);
6366 temp = E1000_READ_REG(hw, XOFFTXC);
6367 temp = E1000_READ_REG(hw, FCRUC);
6369 if (hw->mac_type != e1000_ich8lan) {
6370 temp = E1000_READ_REG(hw, PRC64);
6371 temp = E1000_READ_REG(hw, PRC127);
6372 temp = E1000_READ_REG(hw, PRC255);
6373 temp = E1000_READ_REG(hw, PRC511);
6374 temp = E1000_READ_REG(hw, PRC1023);
6375 temp = E1000_READ_REG(hw, PRC1522);
6378 temp = E1000_READ_REG(hw, GPRC);
6379 temp = E1000_READ_REG(hw, BPRC);
6380 temp = E1000_READ_REG(hw, MPRC);
6381 temp = E1000_READ_REG(hw, GPTC);
6382 temp = E1000_READ_REG(hw, GORCL);
6383 temp = E1000_READ_REG(hw, GORCH);
6384 temp = E1000_READ_REG(hw, GOTCL);
6385 temp = E1000_READ_REG(hw, GOTCH);
6386 temp = E1000_READ_REG(hw, RNBC);
6387 temp = E1000_READ_REG(hw, RUC);
6388 temp = E1000_READ_REG(hw, RFC);
6389 temp = E1000_READ_REG(hw, ROC);
6390 temp = E1000_READ_REG(hw, RJC);
6391 temp = E1000_READ_REG(hw, TORL);
6392 temp = E1000_READ_REG(hw, TORH);
6393 temp = E1000_READ_REG(hw, TOTL);
6394 temp = E1000_READ_REG(hw, TOTH);
6395 temp = E1000_READ_REG(hw, TPR);
6396 temp = E1000_READ_REG(hw, TPT);
6398 if (hw->mac_type != e1000_ich8lan) {
6399 temp = E1000_READ_REG(hw, PTC64);
6400 temp = E1000_READ_REG(hw, PTC127);
6401 temp = E1000_READ_REG(hw, PTC255);
6402 temp = E1000_READ_REG(hw, PTC511);
6403 temp = E1000_READ_REG(hw, PTC1023);
6404 temp = E1000_READ_REG(hw, PTC1522);
6407 temp = E1000_READ_REG(hw, MPTC);
6408 temp = E1000_READ_REG(hw, BPTC);
6410 if (hw->mac_type < e1000_82543) return;
6412 temp = E1000_READ_REG(hw, ALGNERRC);
6413 temp = E1000_READ_REG(hw, RXERRC);
6414 temp = E1000_READ_REG(hw, TNCRS);
6415 temp = E1000_READ_REG(hw, CEXTERR);
6416 temp = E1000_READ_REG(hw, TSCTC);
6417 temp = E1000_READ_REG(hw, TSCTFC);
6419 if (hw->mac_type <= e1000_82544) return;
6421 temp = E1000_READ_REG(hw, MGTPRC);
6422 temp = E1000_READ_REG(hw, MGTPDC);
6423 temp = E1000_READ_REG(hw, MGTPTC);
6425 if (hw->mac_type <= e1000_82547_rev_2) return;
6427 temp = E1000_READ_REG(hw, IAC);
6428 temp = E1000_READ_REG(hw, ICRXOC);
6430 if (hw->mac_type == e1000_ich8lan) return;
6432 temp = E1000_READ_REG(hw, ICRXPTC);
6433 temp = E1000_READ_REG(hw, ICRXATC);
6434 temp = E1000_READ_REG(hw, ICTXPTC);
6435 temp = E1000_READ_REG(hw, ICTXATC);
6436 temp = E1000_READ_REG(hw, ICTXQEC);
6437 temp = E1000_READ_REG(hw, ICTXQMTC);
6438 temp = E1000_READ_REG(hw, ICRXDMTC);
6441 /******************************************************************************
6442 * Resets Adaptive IFS to its default state.
6444 * hw - Struct containing variables accessed by shared code
6446 * Call this after e1000_init_hw. You may override the IFS defaults by setting
6447 * hw->ifs_params_forced to TRUE. However, you must initialize hw->
6448 * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio
6449 * before calling this function.
6450 *****************************************************************************/
6452 e1000_reset_adaptive(struct e1000_hw *hw)
6454 DEBUGFUNC("e1000_reset_adaptive");
6456 if (hw->adaptive_ifs) {
6457 if (!hw->ifs_params_forced) {
6458 hw->current_ifs_val = 0;
6459 hw->ifs_min_val = IFS_MIN;
6460 hw->ifs_max_val = IFS_MAX;
6461 hw->ifs_step_size = IFS_STEP;
6462 hw->ifs_ratio = IFS_RATIO;
6464 hw->in_ifs_mode = FALSE;
6465 E1000_WRITE_REG(hw, AIT, 0);
6467 DEBUGOUT("Not in Adaptive IFS mode!\n");
6471 /******************************************************************************
6472 * Called during the callback/watchdog routine to update IFS value based on
6473 * the ratio of transmits to collisions.
6475 * hw - Struct containing variables accessed by shared code
6476 * tx_packets - Number of transmits since last callback
6477 * total_collisions - Number of collisions since last callback
6478 *****************************************************************************/
6480 e1000_update_adaptive(struct e1000_hw *hw)
6482 DEBUGFUNC("e1000_update_adaptive");
6484 if (hw->adaptive_ifs) {
6485 if ((hw->collision_delta * hw->ifs_ratio) > hw->tx_packet_delta) {
6486 if (hw->tx_packet_delta > MIN_NUM_XMITS) {
6487 hw->in_ifs_mode = TRUE;
6488 if (hw->current_ifs_val < hw->ifs_max_val) {
6489 if (hw->current_ifs_val == 0)
6490 hw->current_ifs_val = hw->ifs_min_val;
6492 hw->current_ifs_val += hw->ifs_step_size;
6493 E1000_WRITE_REG(hw, AIT, hw->current_ifs_val);
6497 if (hw->in_ifs_mode && (hw->tx_packet_delta <= MIN_NUM_XMITS)) {
6498 hw->current_ifs_val = 0;
6499 hw->in_ifs_mode = FALSE;
6500 E1000_WRITE_REG(hw, AIT, 0);
6504 DEBUGOUT("Not in Adaptive IFS mode!\n");
6508 /******************************************************************************
6509 * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT
6511 * hw - Struct containing variables accessed by shared code
6512 * frame_len - The length of the frame in question
6513 * mac_addr - The Ethernet destination address of the frame in question
6514 *****************************************************************************/
6516 e1000_tbi_adjust_stats(struct e1000_hw *hw,
6517 struct e1000_hw_stats *stats,
6523 /* First adjust the frame length. */
6525 /* We need to adjust the statistics counters, since the hardware
6526 * counters overcount this packet as a CRC error and undercount
6527 * the packet as a good packet
6529 /* This packet should not be counted as a CRC error. */
6531 /* This packet does count as a Good Packet Received. */
6534 /* Adjust the Good Octets received counters */
6535 carry_bit = 0x80000000 & stats->gorcl;
6536 stats->gorcl += frame_len;
6537 /* If the high bit of Gorcl (the low 32 bits of the Good Octets
6538 * Received Count) was one before the addition,
6539 * AND it is zero after, then we lost the carry out,
6540 * need to add one to Gorch (Good Octets Received Count High).
6541 * This could be simplified if all environments supported
6544 if (carry_bit && ((stats->gorcl & 0x80000000) == 0))
6546 /* Is this a broadcast or multicast? Check broadcast first,
6547 * since the test for a multicast frame will test positive on
6548 * a broadcast frame.
6550 if ((mac_addr[0] == (uint8_t) 0xff) && (mac_addr[1] == (uint8_t) 0xff))
6551 /* Broadcast packet */
6553 else if (*mac_addr & 0x01)
6554 /* Multicast packet */
6557 if (frame_len == hw->max_frame_size) {
6558 /* In this case, the hardware has overcounted the number of
6565 /* Adjust the bin counters when the extra byte put the frame in the
6566 * wrong bin. Remember that the frame_len was adjusted above.
6568 if (frame_len == 64) {
6571 } else if (frame_len == 127) {
6574 } else if (frame_len == 255) {
6577 } else if (frame_len == 511) {
6580 } else if (frame_len == 1023) {
6583 } else if (frame_len == 1522) {
6588 /******************************************************************************
6589 * Gets the current PCI bus type, speed, and width of the hardware
6591 * hw - Struct containing variables accessed by shared code
6592 *****************************************************************************/
6594 e1000_get_bus_info(struct e1000_hw *hw)
6597 uint16_t pci_ex_link_status;
6600 switch (hw->mac_type) {
6601 case e1000_82542_rev2_0:
6602 case e1000_82542_rev2_1:
6603 hw->bus_type = e1000_bus_type_pci;
6604 hw->bus_speed = e1000_bus_speed_unknown;
6605 hw->bus_width = e1000_bus_width_unknown;
6610 case e1000_80003es2lan:
6611 hw->bus_type = e1000_bus_type_pci_express;
6612 hw->bus_speed = e1000_bus_speed_2500;
6613 ret_val = e1000_read_pcie_cap_reg(hw,
6615 &pci_ex_link_status);
6617 hw->bus_width = e1000_bus_width_unknown;
6619 hw->bus_width = (pci_ex_link_status & PCI_EX_LINK_WIDTH_MASK) >>
6620 PCI_EX_LINK_WIDTH_SHIFT;
6623 hw->bus_type = e1000_bus_type_pci_express;
6624 hw->bus_speed = e1000_bus_speed_2500;
6625 hw->bus_width = e1000_bus_width_pciex_1;
6628 status = E1000_READ_REG(hw, STATUS);
6629 hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
6630 e1000_bus_type_pcix : e1000_bus_type_pci;
6632 if (hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) {
6633 hw->bus_speed = (hw->bus_type == e1000_bus_type_pci) ?
6634 e1000_bus_speed_66 : e1000_bus_speed_120;
6635 } else if (hw->bus_type == e1000_bus_type_pci) {
6636 hw->bus_speed = (status & E1000_STATUS_PCI66) ?
6637 e1000_bus_speed_66 : e1000_bus_speed_33;
6639 switch (status & E1000_STATUS_PCIX_SPEED) {
6640 case E1000_STATUS_PCIX_SPEED_66:
6641 hw->bus_speed = e1000_bus_speed_66;
6643 case E1000_STATUS_PCIX_SPEED_100:
6644 hw->bus_speed = e1000_bus_speed_100;
6646 case E1000_STATUS_PCIX_SPEED_133:
6647 hw->bus_speed = e1000_bus_speed_133;
6650 hw->bus_speed = e1000_bus_speed_reserved;
6654 hw->bus_width = (status & E1000_STATUS_BUS64) ?
6655 e1000_bus_width_64 : e1000_bus_width_32;
6660 /******************************************************************************
6661 * Writes a value to one of the devices registers using port I/O (as opposed to
6662 * memory mapped I/O). Only 82544 and newer devices support port I/O.
6664 * hw - Struct containing variables accessed by shared code
6665 * offset - offset to write to
6666 * value - value to write
6667 *****************************************************************************/
6669 e1000_write_reg_io(struct e1000_hw *hw,
6673 unsigned long io_addr = hw->io_base;
6674 unsigned long io_data = hw->io_base + 4;
6676 e1000_io_write(hw, io_addr, offset);
6677 e1000_io_write(hw, io_data, value);
6680 /******************************************************************************
6681 * Estimates the cable length.
6683 * hw - Struct containing variables accessed by shared code
6684 * min_length - The estimated minimum length
6685 * max_length - The estimated maximum length
6687 * returns: - E1000_ERR_XXX
6690 * This function always returns a ranged length (minimum & maximum).
6691 * So for M88 phy's, this function interprets the one value returned from the
6692 * register to the minimum and maximum range.
6693 * For IGP phy's, the function calculates the range by the AGC registers.
6694 *****************************************************************************/
6696 e1000_get_cable_length(struct e1000_hw *hw,
6697 uint16_t *min_length,
6698 uint16_t *max_length)
6701 uint16_t agc_value = 0;
6702 uint16_t i, phy_data;
6703 uint16_t cable_length;
6705 DEBUGFUNC("e1000_get_cable_length");
6707 *min_length = *max_length = 0;
6709 /* Use old method for Phy older than IGP */
6710 if (hw->phy_type == e1000_phy_m88) {
6712 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6716 cable_length = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
6717 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
6719 /* Convert the enum value to ranged values */
6720 switch (cable_length) {
6721 case e1000_cable_length_50:
6723 *max_length = e1000_igp_cable_length_50;
6725 case e1000_cable_length_50_80:
6726 *min_length = e1000_igp_cable_length_50;
6727 *max_length = e1000_igp_cable_length_80;
6729 case e1000_cable_length_80_110:
6730 *min_length = e1000_igp_cable_length_80;
6731 *max_length = e1000_igp_cable_length_110;
6733 case e1000_cable_length_110_140:
6734 *min_length = e1000_igp_cable_length_110;
6735 *max_length = e1000_igp_cable_length_140;
6737 case e1000_cable_length_140:
6738 *min_length = e1000_igp_cable_length_140;
6739 *max_length = e1000_igp_cable_length_170;
6742 return -E1000_ERR_PHY;
6745 } else if (hw->phy_type == e1000_phy_gg82563) {
6746 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_DSP_DISTANCE,
6750 cable_length = phy_data & GG82563_DSPD_CABLE_LENGTH;
6752 switch (cable_length) {
6753 case e1000_gg_cable_length_60:
6755 *max_length = e1000_igp_cable_length_60;
6757 case e1000_gg_cable_length_60_115:
6758 *min_length = e1000_igp_cable_length_60;
6759 *max_length = e1000_igp_cable_length_115;
6761 case e1000_gg_cable_length_115_150:
6762 *min_length = e1000_igp_cable_length_115;
6763 *max_length = e1000_igp_cable_length_150;
6765 case e1000_gg_cable_length_150:
6766 *min_length = e1000_igp_cable_length_150;
6767 *max_length = e1000_igp_cable_length_180;
6770 return -E1000_ERR_PHY;
6773 } else if (hw->phy_type == e1000_phy_igp) { /* For IGP PHY */
6774 uint16_t cur_agc_value;
6775 uint16_t min_agc_value = IGP01E1000_AGC_LENGTH_TABLE_SIZE;
6776 uint16_t agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
6777 {IGP01E1000_PHY_AGC_A,
6778 IGP01E1000_PHY_AGC_B,
6779 IGP01E1000_PHY_AGC_C,
6780 IGP01E1000_PHY_AGC_D};
6781 /* Read the AGC registers for all channels */
6782 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
6784 ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
6788 cur_agc_value = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT;
6790 /* Value bound check. */
6791 if ((cur_agc_value >= IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1) ||
6792 (cur_agc_value == 0))
6793 return -E1000_ERR_PHY;
6795 agc_value += cur_agc_value;
6797 /* Update minimal AGC value. */
6798 if (min_agc_value > cur_agc_value)
6799 min_agc_value = cur_agc_value;
6802 /* Remove the minimal AGC result for length < 50m */
6803 if (agc_value < IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) {
6804 agc_value -= min_agc_value;
6806 /* Get the average length of the remaining 3 channels */
6807 agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1);
6809 /* Get the average length of all the 4 channels. */
6810 agc_value /= IGP01E1000_PHY_CHANNEL_NUM;
6813 /* Set the range of the calculated length. */
6814 *min_length = ((e1000_igp_cable_length_table[agc_value] -
6815 IGP01E1000_AGC_RANGE) > 0) ?
6816 (e1000_igp_cable_length_table[agc_value] -
6817 IGP01E1000_AGC_RANGE) : 0;
6818 *max_length = e1000_igp_cable_length_table[agc_value] +
6819 IGP01E1000_AGC_RANGE;
6820 } else if (hw->phy_type == e1000_phy_igp_2 ||
6821 hw->phy_type == e1000_phy_igp_3) {
6822 uint16_t cur_agc_index, max_agc_index = 0;
6823 uint16_t min_agc_index = IGP02E1000_AGC_LENGTH_TABLE_SIZE - 1;
6824 uint16_t agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] =
6825 {IGP02E1000_PHY_AGC_A,
6826 IGP02E1000_PHY_AGC_B,
6827 IGP02E1000_PHY_AGC_C,
6828 IGP02E1000_PHY_AGC_D};
6829 /* Read the AGC registers for all channels */
6830 for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
6831 ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
6835 /* Getting bits 15:9, which represent the combination of course and
6836 * fine gain values. The result is a number that can be put into
6837 * the lookup table to obtain the approximate cable length. */
6838 cur_agc_index = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
6839 IGP02E1000_AGC_LENGTH_MASK;
6841 /* Array index bound check. */
6842 if ((cur_agc_index >= IGP02E1000_AGC_LENGTH_TABLE_SIZE) ||
6843 (cur_agc_index == 0))
6844 return -E1000_ERR_PHY;
6846 /* Remove min & max AGC values from calculation. */
6847 if (e1000_igp_2_cable_length_table[min_agc_index] >
6848 e1000_igp_2_cable_length_table[cur_agc_index])
6849 min_agc_index = cur_agc_index;
6850 if (e1000_igp_2_cable_length_table[max_agc_index] <
6851 e1000_igp_2_cable_length_table[cur_agc_index])
6852 max_agc_index = cur_agc_index;
6854 agc_value += e1000_igp_2_cable_length_table[cur_agc_index];
6857 agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] +
6858 e1000_igp_2_cable_length_table[max_agc_index]);
6859 agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
6861 /* Calculate cable length with the error range of +/- 10 meters. */
6862 *min_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
6863 (agc_value - IGP02E1000_AGC_RANGE) : 0;
6864 *max_length = agc_value + IGP02E1000_AGC_RANGE;
6867 return E1000_SUCCESS;
6870 /******************************************************************************
6871 * Check the cable polarity
6873 * hw - Struct containing variables accessed by shared code
6874 * polarity - output parameter : 0 - Polarity is not reversed
6875 * 1 - Polarity is reversed.
6877 * returns: - E1000_ERR_XXX
6880 * For phy's older then IGP, this function simply reads the polarity bit in the
6881 * Phy Status register. For IGP phy's, this bit is valid only if link speed is
6882 * 10 Mbps. If the link speed is 100 Mbps there is no polarity so this bit will
6883 * return 0. If the link speed is 1000 Mbps the polarity status is in the
6884 * IGP01E1000_PHY_PCS_INIT_REG.
6885 *****************************************************************************/
6887 e1000_check_polarity(struct e1000_hw *hw,
6888 e1000_rev_polarity *polarity)
6893 DEBUGFUNC("e1000_check_polarity");
6895 if ((hw->phy_type == e1000_phy_m88) ||
6896 (hw->phy_type == e1000_phy_gg82563)) {
6897 /* return the Polarity bit in the Status register. */
6898 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6902 *polarity = ((phy_data & M88E1000_PSSR_REV_POLARITY) >>
6903 M88E1000_PSSR_REV_POLARITY_SHIFT) ?
6904 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
6906 } else if (hw->phy_type == e1000_phy_igp ||
6907 hw->phy_type == e1000_phy_igp_3 ||
6908 hw->phy_type == e1000_phy_igp_2) {
6909 /* Read the Status register to check the speed */
6910 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
6915 /* If speed is 1000 Mbps, must read the IGP01E1000_PHY_PCS_INIT_REG to
6916 * find the polarity status */
6917 if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
6918 IGP01E1000_PSSR_SPEED_1000MBPS) {
6920 /* Read the GIG initialization PCS register (0x00B4) */
6921 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG,
6926 /* Check the polarity bits */
6927 *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ?
6928 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
6930 /* For 10 Mbps, read the polarity bit in the status register. (for
6931 * 100 Mbps this bit is always 0) */
6932 *polarity = (phy_data & IGP01E1000_PSSR_POLARITY_REVERSED) ?
6933 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
6935 } else if (hw->phy_type == e1000_phy_ife) {
6936 ret_val = e1000_read_phy_reg(hw, IFE_PHY_EXTENDED_STATUS_CONTROL,
6940 *polarity = ((phy_data & IFE_PESC_POLARITY_REVERSED) >>
6941 IFE_PESC_POLARITY_REVERSED_SHIFT) ?
6942 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
6944 return E1000_SUCCESS;
6947 /******************************************************************************
6948 * Check if Downshift occured
6950 * hw - Struct containing variables accessed by shared code
6951 * downshift - output parameter : 0 - No Downshift ocured.
6952 * 1 - Downshift ocured.
6954 * returns: - E1000_ERR_XXX
6957 * For phy's older then IGP, this function reads the Downshift bit in the Phy
6958 * Specific Status register. For IGP phy's, it reads the Downgrade bit in the
6959 * Link Health register. In IGP this bit is latched high, so the driver must
6960 * read it immediately after link is established.
6961 *****************************************************************************/
6963 e1000_check_downshift(struct e1000_hw *hw)
6968 DEBUGFUNC("e1000_check_downshift");
6970 if (hw->phy_type == e1000_phy_igp ||
6971 hw->phy_type == e1000_phy_igp_3 ||
6972 hw->phy_type == e1000_phy_igp_2) {
6973 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH,
6978 hw->speed_downgraded = (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0;
6979 } else if ((hw->phy_type == e1000_phy_m88) ||
6980 (hw->phy_type == e1000_phy_gg82563)) {
6981 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6986 hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >>
6987 M88E1000_PSSR_DOWNSHIFT_SHIFT;
6988 } else if (hw->phy_type == e1000_phy_ife) {
6989 /* e1000_phy_ife supports 10/100 speed only */
6990 hw->speed_downgraded = FALSE;
6993 return E1000_SUCCESS;
6996 /*****************************************************************************
6998 * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a
6999 * gigabit link is achieved to improve link quality.
7001 * hw: Struct containing variables accessed by shared code
7003 * returns: - E1000_ERR_PHY if fail to read/write the PHY
7004 * E1000_SUCCESS at any other case.
7006 ****************************************************************************/
7009 e1000_config_dsp_after_link_change(struct e1000_hw *hw,
7013 uint16_t phy_data, phy_saved_data, speed, duplex, i;
7014 uint16_t dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
7015 {IGP01E1000_PHY_AGC_PARAM_A,
7016 IGP01E1000_PHY_AGC_PARAM_B,
7017 IGP01E1000_PHY_AGC_PARAM_C,
7018 IGP01E1000_PHY_AGC_PARAM_D};
7019 uint16_t min_length, max_length;
7021 DEBUGFUNC("e1000_config_dsp_after_link_change");
7023 if (hw->phy_type != e1000_phy_igp)
7024 return E1000_SUCCESS;
7027 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
7029 DEBUGOUT("Error getting link speed and duplex\n");
7033 if (speed == SPEED_1000) {
7035 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
7039 if ((hw->dsp_config_state == e1000_dsp_config_enabled) &&
7040 min_length >= e1000_igp_cable_length_50) {
7042 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
7043 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i],
7048 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
7050 ret_val = e1000_write_phy_reg(hw, dsp_reg_array[i],
7055 hw->dsp_config_state = e1000_dsp_config_activated;
7058 if ((hw->ffe_config_state == e1000_ffe_config_enabled) &&
7059 (min_length < e1000_igp_cable_length_50)) {
7061 uint16_t ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_20;
7062 uint32_t idle_errs = 0;
7064 /* clear previous idle error counts */
7065 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
7070 for (i = 0; i < ffe_idle_err_timeout; i++) {
7072 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
7077 idle_errs += (phy_data & SR_1000T_IDLE_ERROR_CNT);
7078 if (idle_errs > SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT) {
7079 hw->ffe_config_state = e1000_ffe_config_active;
7081 ret_val = e1000_write_phy_reg(hw,
7082 IGP01E1000_PHY_DSP_FFE,
7083 IGP01E1000_PHY_DSP_FFE_CM_CP);
7090 ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_100;
7095 if (hw->dsp_config_state == e1000_dsp_config_activated) {
7096 /* Save off the current value of register 0x2F5B to be restored at
7097 * the end of the routines. */
7098 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
7103 /* Disable the PHY transmitter */
7104 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
7111 ret_val = e1000_write_phy_reg(hw, 0x0000,
7112 IGP01E1000_IEEE_FORCE_GIGA);
7115 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
7116 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i], &phy_data);
7120 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
7121 phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS;
7123 ret_val = e1000_write_phy_reg(hw,dsp_reg_array[i], phy_data);
7128 ret_val = e1000_write_phy_reg(hw, 0x0000,
7129 IGP01E1000_IEEE_RESTART_AUTONEG);
7135 /* Now enable the transmitter */
7136 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
7141 hw->dsp_config_state = e1000_dsp_config_enabled;
7144 if (hw->ffe_config_state == e1000_ffe_config_active) {
7145 /* Save off the current value of register 0x2F5B to be restored at
7146 * the end of the routines. */
7147 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
7152 /* Disable the PHY transmitter */
7153 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
7160 ret_val = e1000_write_phy_reg(hw, 0x0000,
7161 IGP01E1000_IEEE_FORCE_GIGA);
7164 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE,
7165 IGP01E1000_PHY_DSP_FFE_DEFAULT);
7169 ret_val = e1000_write_phy_reg(hw, 0x0000,
7170 IGP01E1000_IEEE_RESTART_AUTONEG);
7176 /* Now enable the transmitter */
7177 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
7182 hw->ffe_config_state = e1000_ffe_config_enabled;
7185 return E1000_SUCCESS;
7188 /*****************************************************************************
7189 * Set PHY to class A mode
7190 * Assumes the following operations will follow to enable the new class mode.
7191 * 1. Do a PHY soft reset
7192 * 2. Restart auto-negotiation or force link.
7194 * hw - Struct containing variables accessed by shared code
7195 ****************************************************************************/
7197 e1000_set_phy_mode(struct e1000_hw *hw)
7200 uint16_t eeprom_data;
7202 DEBUGFUNC("e1000_set_phy_mode");
7204 if ((hw->mac_type == e1000_82545_rev_3) &&
7205 (hw->media_type == e1000_media_type_copper)) {
7206 ret_val = e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, 1, &eeprom_data);
7211 if ((eeprom_data != EEPROM_RESERVED_WORD) &&
7212 (eeprom_data & EEPROM_PHY_CLASS_A)) {
7213 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x000B);
7216 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x8104);
7220 hw->phy_reset_disable = FALSE;
7224 return E1000_SUCCESS;
7227 /*****************************************************************************
7229 * This function sets the lplu state according to the active flag. When
7230 * activating lplu this function also disables smart speed and vise versa.
7231 * lplu will not be activated unless the device autonegotiation advertisment
7232 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
7233 * hw: Struct containing variables accessed by shared code
7234 * active - true to enable lplu false to disable lplu.
7236 * returns: - E1000_ERR_PHY if fail to read/write the PHY
7237 * E1000_SUCCESS at any other case.
7239 ****************************************************************************/
7242 e1000_set_d3_lplu_state(struct e1000_hw *hw,
7245 uint32_t phy_ctrl = 0;
7248 DEBUGFUNC("e1000_set_d3_lplu_state");
7250 if (hw->phy_type != e1000_phy_igp && hw->phy_type != e1000_phy_igp_2
7251 && hw->phy_type != e1000_phy_igp_3)
7252 return E1000_SUCCESS;
7254 /* During driver activity LPLU should not be used or it will attain link
7255 * from the lowest speeds starting from 10Mbps. The capability is used for
7256 * Dx transitions and states */
7257 if (hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2) {
7258 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data);
7261 } else if (hw->mac_type == e1000_ich8lan) {
7262 /* MAC writes into PHY register based on the state transition
7263 * and start auto-negotiation. SW driver can overwrite the settings
7264 * in CSR PHY power control E1000_PHY_CTRL register. */
7265 phy_ctrl = E1000_READ_REG(hw, PHY_CTRL);
7267 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
7273 if (hw->mac_type == e1000_82541_rev_2 ||
7274 hw->mac_type == e1000_82547_rev_2) {
7275 phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
7276 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
7280 if (hw->mac_type == e1000_ich8lan) {
7281 phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
7282 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7284 phy_data &= ~IGP02E1000_PM_D3_LPLU;
7285 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
7292 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
7293 * Dx states where the power conservation is most important. During
7294 * driver activity we should enable SmartSpeed, so performance is
7296 if (hw->smart_speed == e1000_smart_speed_on) {
7297 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7302 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
7303 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7307 } else if (hw->smart_speed == e1000_smart_speed_off) {
7308 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7313 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7314 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7320 } else if ((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT) ||
7321 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL ) ||
7322 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) {
7324 if (hw->mac_type == e1000_82541_rev_2 ||
7325 hw->mac_type == e1000_82547_rev_2) {
7326 phy_data |= IGP01E1000_GMII_FLEX_SPD;
7327 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
7331 if (hw->mac_type == e1000_ich8lan) {
7332 phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
7333 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7335 phy_data |= IGP02E1000_PM_D3_LPLU;
7336 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
7343 /* When LPLU is enabled we should disable SmartSpeed */
7344 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
7348 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7349 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
7354 return E1000_SUCCESS;
7357 /*****************************************************************************
7359 * This function sets the lplu d0 state according to the active flag. When
7360 * activating lplu this function also disables smart speed and vise versa.
7361 * lplu will not be activated unless the device autonegotiation advertisment
7362 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
7363 * hw: Struct containing variables accessed by shared code
7364 * active - true to enable lplu false to disable lplu.
7366 * returns: - E1000_ERR_PHY if fail to read/write the PHY
7367 * E1000_SUCCESS at any other case.
7369 ****************************************************************************/
7372 e1000_set_d0_lplu_state(struct e1000_hw *hw,
7375 uint32_t phy_ctrl = 0;
7378 DEBUGFUNC("e1000_set_d0_lplu_state");
7380 if (hw->mac_type <= e1000_82547_rev_2)
7381 return E1000_SUCCESS;
7383 if (hw->mac_type == e1000_ich8lan) {
7384 phy_ctrl = E1000_READ_REG(hw, PHY_CTRL);
7386 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
7392 if (hw->mac_type == e1000_ich8lan) {
7393 phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
7394 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7396 phy_data &= ~IGP02E1000_PM_D0_LPLU;
7397 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
7402 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
7403 * Dx states where the power conservation is most important. During
7404 * driver activity we should enable SmartSpeed, so performance is
7406 if (hw->smart_speed == e1000_smart_speed_on) {
7407 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7412 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
7413 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7417 } else if (hw->smart_speed == e1000_smart_speed_off) {
7418 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7423 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7424 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7433 if (hw->mac_type == e1000_ich8lan) {
7434 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
7435 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7437 phy_data |= IGP02E1000_PM_D0_LPLU;
7438 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
7443 /* When LPLU is enabled we should disable SmartSpeed */
7444 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
7448 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7449 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
7454 return E1000_SUCCESS;
7457 /******************************************************************************
7458 * Change VCO speed register to improve Bit Error Rate performance of SERDES.
7460 * hw - Struct containing variables accessed by shared code
7461 *****************************************************************************/
7463 e1000_set_vco_speed(struct e1000_hw *hw)
7466 uint16_t default_page = 0;
7469 DEBUGFUNC("e1000_set_vco_speed");
7471 switch (hw->mac_type) {
7472 case e1000_82545_rev_3:
7473 case e1000_82546_rev_3:
7476 return E1000_SUCCESS;
7479 /* Set PHY register 30, page 5, bit 8 to 0 */
7481 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, &default_page);
7485 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005);
7489 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
7493 phy_data &= ~M88E1000_PHY_VCO_REG_BIT8;
7494 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
7498 /* Set PHY register 30, page 4, bit 11 to 1 */
7500 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004);
7504 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
7508 phy_data |= M88E1000_PHY_VCO_REG_BIT11;
7509 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
7513 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, default_page);
7517 return E1000_SUCCESS;
7521 /*****************************************************************************
7522 * This function reads the cookie from ARC ram.
7524 * returns: - E1000_SUCCESS .
7525 ****************************************************************************/
7527 e1000_host_if_read_cookie(struct e1000_hw * hw, uint8_t *buffer)
7530 uint32_t offset = E1000_MNG_DHCP_COOKIE_OFFSET;
7531 uint8_t length = E1000_MNG_DHCP_COOKIE_LENGTH;
7533 length = (length >> 2);
7534 offset = (offset >> 2);
7536 for (i = 0; i < length; i++) {
7537 *((uint32_t *) buffer + i) =
7538 E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset + i);
7540 return E1000_SUCCESS;
7544 /*****************************************************************************
7545 * This function checks whether the HOST IF is enabled for command operaton
7546 * and also checks whether the previous command is completed.
7547 * It busy waits in case of previous command is not completed.
7549 * returns: - E1000_ERR_HOST_INTERFACE_COMMAND in case if is not ready or
7551 * - E1000_SUCCESS for success.
7552 ****************************************************************************/
7554 e1000_mng_enable_host_if(struct e1000_hw * hw)
7559 /* Check that the host interface is enabled. */
7560 hicr = E1000_READ_REG(hw, HICR);
7561 if ((hicr & E1000_HICR_EN) == 0) {
7562 DEBUGOUT("E1000_HOST_EN bit disabled.\n");
7563 return -E1000_ERR_HOST_INTERFACE_COMMAND;
7565 /* check the previous command is completed */
7566 for (i = 0; i < E1000_MNG_DHCP_COMMAND_TIMEOUT; i++) {
7567 hicr = E1000_READ_REG(hw, HICR);
7568 if (!(hicr & E1000_HICR_C))
7573 if (i == E1000_MNG_DHCP_COMMAND_TIMEOUT) {
7574 DEBUGOUT("Previous command timeout failed .\n");
7575 return -E1000_ERR_HOST_INTERFACE_COMMAND;
7577 return E1000_SUCCESS;
7580 /*****************************************************************************
7581 * This function writes the buffer content at the offset given on the host if.
7582 * It also does alignment considerations to do the writes in most efficient way.
7583 * Also fills up the sum of the buffer in *buffer parameter.
7585 * returns - E1000_SUCCESS for success.
7586 ****************************************************************************/
7588 e1000_mng_host_if_write(struct e1000_hw * hw, uint8_t *buffer,
7589 uint16_t length, uint16_t offset, uint8_t *sum)
7592 uint8_t *bufptr = buffer;
7594 uint16_t remaining, i, j, prev_bytes;
7596 /* sum = only sum of the data and it is not checksum */
7598 if (length == 0 || offset + length > E1000_HI_MAX_MNG_DATA_LENGTH) {
7599 return -E1000_ERR_PARAM;
7602 tmp = (uint8_t *)&data;
7603 prev_bytes = offset & 0x3;
7608 data = E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset);
7609 for (j = prev_bytes; j < sizeof(uint32_t); j++) {
7610 *(tmp + j) = *bufptr++;
7613 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset, data);
7614 length -= j - prev_bytes;
7618 remaining = length & 0x3;
7619 length -= remaining;
7621 /* Calculate length in DWORDs */
7624 /* The device driver writes the relevant command block into the
7626 for (i = 0; i < length; i++) {
7627 for (j = 0; j < sizeof(uint32_t); j++) {
7628 *(tmp + j) = *bufptr++;
7632 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data);
7635 for (j = 0; j < sizeof(uint32_t); j++) {
7637 *(tmp + j) = *bufptr++;
7643 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data);
7646 return E1000_SUCCESS;
7650 /*****************************************************************************
7651 * This function writes the command header after does the checksum calculation.
7653 * returns - E1000_SUCCESS for success.
7654 ****************************************************************************/
7656 e1000_mng_write_cmd_header(struct e1000_hw * hw,
7657 struct e1000_host_mng_command_header * hdr)
7663 /* Write the whole command header structure which includes sum of
7666 uint16_t length = sizeof(struct e1000_host_mng_command_header);
7668 sum = hdr->checksum;
7671 buffer = (uint8_t *) hdr;
7676 hdr->checksum = 0 - sum;
7679 /* The device driver writes the relevant command block into the ram area. */
7680 for (i = 0; i < length; i++) {
7681 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, i, *((uint32_t *) hdr + i));
7682 E1000_WRITE_FLUSH(hw);
7685 return E1000_SUCCESS;
7689 /*****************************************************************************
7690 * This function indicates to ARC that a new command is pending which completes
7691 * one write operation by the driver.
7693 * returns - E1000_SUCCESS for success.
7694 ****************************************************************************/
7696 e1000_mng_write_commit(struct e1000_hw * hw)
7700 hicr = E1000_READ_REG(hw, HICR);
7701 /* Setting this bit tells the ARC that a new command is pending. */
7702 E1000_WRITE_REG(hw, HICR, hicr | E1000_HICR_C);
7704 return E1000_SUCCESS;
7708 /*****************************************************************************
7709 * This function checks the mode of the firmware.
7711 * returns - TRUE when the mode is IAMT or FALSE.
7712 ****************************************************************************/
7714 e1000_check_mng_mode(struct e1000_hw *hw)
7718 fwsm = E1000_READ_REG(hw, FWSM);
7720 if (hw->mac_type == e1000_ich8lan) {
7721 if ((fwsm & E1000_FWSM_MODE_MASK) ==
7722 (E1000_MNG_ICH_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
7724 } else if ((fwsm & E1000_FWSM_MODE_MASK) ==
7725 (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
7732 /*****************************************************************************
7733 * This function writes the dhcp info .
7734 ****************************************************************************/
7736 e1000_mng_write_dhcp_info(struct e1000_hw * hw, uint8_t *buffer,
7740 struct e1000_host_mng_command_header hdr;
7742 hdr.command_id = E1000_MNG_DHCP_TX_PAYLOAD_CMD;
7743 hdr.command_length = length;
7748 ret_val = e1000_mng_enable_host_if(hw);
7749 if (ret_val == E1000_SUCCESS) {
7750 ret_val = e1000_mng_host_if_write(hw, buffer, length, sizeof(hdr),
7752 if (ret_val == E1000_SUCCESS) {
7753 ret_val = e1000_mng_write_cmd_header(hw, &hdr);
7754 if (ret_val == E1000_SUCCESS)
7755 ret_val = e1000_mng_write_commit(hw);
7762 /*****************************************************************************
7763 * This function calculates the checksum.
7765 * returns - checksum of buffer contents.
7766 ****************************************************************************/
7768 e1000_calculate_mng_checksum(char *buffer, uint32_t length)
7776 for (i=0; i < length; i++)
7779 return (uint8_t) (0 - sum);
7782 /*****************************************************************************
7783 * This function checks whether tx pkt filtering needs to be enabled or not.
7785 * returns - TRUE for packet filtering or FALSE.
7786 ****************************************************************************/
7788 e1000_enable_tx_pkt_filtering(struct e1000_hw *hw)
7790 /* called in init as well as watchdog timer functions */
7792 int32_t ret_val, checksum;
7793 boolean_t tx_filter = FALSE;
7794 struct e1000_host_mng_dhcp_cookie *hdr = &(hw->mng_cookie);
7795 uint8_t *buffer = (uint8_t *) &(hw->mng_cookie);
7797 if (e1000_check_mng_mode(hw)) {
7798 ret_val = e1000_mng_enable_host_if(hw);
7799 if (ret_val == E1000_SUCCESS) {
7800 ret_val = e1000_host_if_read_cookie(hw, buffer);
7801 if (ret_val == E1000_SUCCESS) {
7802 checksum = hdr->checksum;
7804 if ((hdr->signature == E1000_IAMT_SIGNATURE) &&
7805 checksum == e1000_calculate_mng_checksum((char *)buffer,
7806 E1000_MNG_DHCP_COOKIE_LENGTH)) {
7808 E1000_MNG_DHCP_COOKIE_STATUS_PARSING_SUPPORT)
7817 hw->tx_pkt_filtering = tx_filter;
7821 /******************************************************************************
7822 * Verifies the hardware needs to allow ARPs to be processed by the host
7824 * hw - Struct containing variables accessed by shared code
7826 * returns: - TRUE/FALSE
7828 *****************************************************************************/
7830 e1000_enable_mng_pass_thru(struct e1000_hw *hw)
7833 uint32_t fwsm, factps;
7835 if (hw->asf_firmware_present) {
7836 manc = E1000_READ_REG(hw, MANC);
7838 if (!(manc & E1000_MANC_RCV_TCO_EN) ||
7839 !(manc & E1000_MANC_EN_MAC_ADDR_FILTER))
7841 if (e1000_arc_subsystem_valid(hw) == TRUE) {
7842 fwsm = E1000_READ_REG(hw, FWSM);
7843 factps = E1000_READ_REG(hw, FACTPS);
7845 if ((((fwsm & E1000_FWSM_MODE_MASK) >> E1000_FWSM_MODE_SHIFT) ==
7846 e1000_mng_mode_pt) && !(factps & E1000_FACTPS_MNGCG))
7849 if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN))
7856 e1000_polarity_reversal_workaround(struct e1000_hw *hw)
7859 uint16_t mii_status_reg;
7862 /* Polarity reversal workaround for forced 10F/10H links. */
7864 /* Disable the transmitter on the PHY */
7866 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
7869 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF);
7873 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
7877 /* This loop will early-out if the NO link condition has been met. */
7878 for (i = PHY_FORCE_TIME; i > 0; i--) {
7879 /* Read the MII Status Register and wait for Link Status bit
7883 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
7887 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
7891 if ((mii_status_reg & ~MII_SR_LINK_STATUS) == 0) break;
7895 /* Recommended delay time after link has been lost */
7898 /* Now we will re-enable th transmitter on the PHY */
7900 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
7904 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0);
7908 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00);
7912 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000);
7916 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
7920 /* This loop will early-out if the link condition has been met. */
7921 for (i = PHY_FORCE_TIME; i > 0; i--) {
7922 /* Read the MII Status Register and wait for Link Status bit
7926 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
7930 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
7934 if (mii_status_reg & MII_SR_LINK_STATUS) break;
7937 return E1000_SUCCESS;
7940 /***************************************************************************
7942 * Disables PCI-Express master access.
7944 * hw: Struct containing variables accessed by shared code
7948 ***************************************************************************/
7950 e1000_set_pci_express_master_disable(struct e1000_hw *hw)
7954 DEBUGFUNC("e1000_set_pci_express_master_disable");
7956 if (hw->bus_type != e1000_bus_type_pci_express)
7959 ctrl = E1000_READ_REG(hw, CTRL);
7960 ctrl |= E1000_CTRL_GIO_MASTER_DISABLE;
7961 E1000_WRITE_REG(hw, CTRL, ctrl);
7964 /*******************************************************************************
7966 * Disables PCI-Express master access and verifies there are no pending requests
7968 * hw: Struct containing variables accessed by shared code
7970 * returns: - E1000_ERR_MASTER_REQUESTS_PENDING if master disable bit hasn't
7971 * caused the master requests to be disabled.
7972 * E1000_SUCCESS master requests disabled.
7974 ******************************************************************************/
7976 e1000_disable_pciex_master(struct e1000_hw *hw)
7978 int32_t timeout = MASTER_DISABLE_TIMEOUT; /* 80ms */
7980 DEBUGFUNC("e1000_disable_pciex_master");
7982 if (hw->bus_type != e1000_bus_type_pci_express)
7983 return E1000_SUCCESS;
7985 e1000_set_pci_express_master_disable(hw);
7988 if (!(E1000_READ_REG(hw, STATUS) & E1000_STATUS_GIO_MASTER_ENABLE))
7996 DEBUGOUT("Master requests are pending.\n");
7997 return -E1000_ERR_MASTER_REQUESTS_PENDING;
8000 return E1000_SUCCESS;
8003 /*******************************************************************************
8005 * Check for EEPROM Auto Read bit done.
8007 * hw: Struct containing variables accessed by shared code
8009 * returns: - E1000_ERR_RESET if fail to reset MAC
8010 * E1000_SUCCESS at any other case.
8012 ******************************************************************************/
8014 e1000_get_auto_rd_done(struct e1000_hw *hw)
8016 int32_t timeout = AUTO_READ_DONE_TIMEOUT;
8018 DEBUGFUNC("e1000_get_auto_rd_done");
8020 switch (hw->mac_type) {
8027 case e1000_80003es2lan:
8030 if (E1000_READ_REG(hw, EECD) & E1000_EECD_AUTO_RD)
8037 DEBUGOUT("Auto read by HW from EEPROM has not completed.\n");
8038 return -E1000_ERR_RESET;
8043 /* PHY configuration from NVM just starts after EECD_AUTO_RD sets to high.
8044 * Need to wait for PHY configuration completion before accessing NVM
8046 if (hw->mac_type == e1000_82573)
8049 return E1000_SUCCESS;
8052 /***************************************************************************
8053 * Checks if the PHY configuration is done
8055 * hw: Struct containing variables accessed by shared code
8057 * returns: - E1000_ERR_RESET if fail to reset MAC
8058 * E1000_SUCCESS at any other case.
8060 ***************************************************************************/
8062 e1000_get_phy_cfg_done(struct e1000_hw *hw)
8064 int32_t timeout = PHY_CFG_TIMEOUT;
8065 uint32_t cfg_mask = E1000_EEPROM_CFG_DONE;
8067 DEBUGFUNC("e1000_get_phy_cfg_done");
8069 switch (hw->mac_type) {
8073 case e1000_80003es2lan:
8074 /* Separate *_CFG_DONE_* bit for each port */
8075 if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
8076 cfg_mask = E1000_EEPROM_CFG_DONE_PORT_1;
8081 if (E1000_READ_REG(hw, EEMNGCTL) & cfg_mask)
8088 DEBUGOUT("MNG configuration cycle has not completed.\n");
8089 return -E1000_ERR_RESET;
8094 return E1000_SUCCESS;
8097 /***************************************************************************
8099 * Using the combination of SMBI and SWESMBI semaphore bits when resetting
8100 * adapter or Eeprom access.
8102 * hw: Struct containing variables accessed by shared code
8104 * returns: - E1000_ERR_EEPROM if fail to access EEPROM.
8105 * E1000_SUCCESS at any other case.
8107 ***************************************************************************/
8109 e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw)
8114 DEBUGFUNC("e1000_get_hw_eeprom_semaphore");
8116 if (!hw->eeprom_semaphore_present)
8117 return E1000_SUCCESS;
8119 if (hw->mac_type == e1000_80003es2lan) {
8120 /* Get the SW semaphore. */
8121 if (e1000_get_software_semaphore(hw) != E1000_SUCCESS)
8122 return -E1000_ERR_EEPROM;
8125 /* Get the FW semaphore. */
8126 timeout = hw->eeprom.word_size + 1;
8128 swsm = E1000_READ_REG(hw, SWSM);
8129 swsm |= E1000_SWSM_SWESMBI;
8130 E1000_WRITE_REG(hw, SWSM, swsm);
8131 /* if we managed to set the bit we got the semaphore. */
8132 swsm = E1000_READ_REG(hw, SWSM);
8133 if (swsm & E1000_SWSM_SWESMBI)
8141 /* Release semaphores */
8142 e1000_put_hw_eeprom_semaphore(hw);
8143 DEBUGOUT("Driver can't access the Eeprom - SWESMBI bit is set.\n");
8144 return -E1000_ERR_EEPROM;
8147 return E1000_SUCCESS;
8150 /***************************************************************************
8151 * This function clears HW semaphore bits.
8153 * hw: Struct containing variables accessed by shared code
8157 ***************************************************************************/
8159 e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw)
8163 DEBUGFUNC("e1000_put_hw_eeprom_semaphore");
8165 if (!hw->eeprom_semaphore_present)
8168 swsm = E1000_READ_REG(hw, SWSM);
8169 if (hw->mac_type == e1000_80003es2lan) {
8170 /* Release both semaphores. */
8171 swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
8173 swsm &= ~(E1000_SWSM_SWESMBI);
8174 E1000_WRITE_REG(hw, SWSM, swsm);
8177 /***************************************************************************
8179 * Obtaining software semaphore bit (SMBI) before resetting PHY.
8181 * hw: Struct containing variables accessed by shared code
8183 * returns: - E1000_ERR_RESET if fail to obtain semaphore.
8184 * E1000_SUCCESS at any other case.
8186 ***************************************************************************/
8188 e1000_get_software_semaphore(struct e1000_hw *hw)
8190 int32_t timeout = hw->eeprom.word_size + 1;
8193 DEBUGFUNC("e1000_get_software_semaphore");
8195 if (hw->mac_type != e1000_80003es2lan) {
8196 return E1000_SUCCESS;
8200 swsm = E1000_READ_REG(hw, SWSM);
8201 /* If SMBI bit cleared, it is now set and we hold the semaphore */
8202 if (!(swsm & E1000_SWSM_SMBI))
8209 DEBUGOUT("Driver can't access device - SMBI bit is set.\n");
8210 return -E1000_ERR_RESET;
8213 return E1000_SUCCESS;
8216 /***************************************************************************
8218 * Release semaphore bit (SMBI).
8220 * hw: Struct containing variables accessed by shared code
8222 ***************************************************************************/
8224 e1000_release_software_semaphore(struct e1000_hw *hw)
8228 DEBUGFUNC("e1000_release_software_semaphore");
8230 if (hw->mac_type != e1000_80003es2lan) {
8234 swsm = E1000_READ_REG(hw, SWSM);
8235 /* Release the SW semaphores.*/
8236 swsm &= ~E1000_SWSM_SMBI;
8237 E1000_WRITE_REG(hw, SWSM, swsm);
8240 /******************************************************************************
8241 * Checks if PHY reset is blocked due to SOL/IDER session, for example.
8242 * Returning E1000_BLK_PHY_RESET isn't necessarily an error. But it's up to
8243 * the caller to figure out how to deal with it.
8245 * hw - Struct containing variables accessed by shared code
8247 * returns: - E1000_BLK_PHY_RESET
8250 *****************************************************************************/
8252 e1000_check_phy_reset_block(struct e1000_hw *hw)
8257 if (hw->mac_type == e1000_ich8lan) {
8258 fwsm = E1000_READ_REG(hw, FWSM);
8259 return (fwsm & E1000_FWSM_RSPCIPHY) ? E1000_SUCCESS
8260 : E1000_BLK_PHY_RESET;
8263 if (hw->mac_type > e1000_82547_rev_2)
8264 manc = E1000_READ_REG(hw, MANC);
8265 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
8266 E1000_BLK_PHY_RESET : E1000_SUCCESS;
8270 e1000_arc_subsystem_valid(struct e1000_hw *hw)
8274 /* On 8257x silicon, registers in the range of 0x8800 - 0x8FFC
8275 * may not be provided a DMA clock when no manageability features are
8276 * enabled. We do not want to perform any reads/writes to these registers
8277 * if this is the case. We read FWSM to determine the manageability mode.
8279 switch (hw->mac_type) {
8283 case e1000_80003es2lan:
8284 fwsm = E1000_READ_REG(hw, FWSM);
8285 if ((fwsm & E1000_FWSM_MODE_MASK) != 0)
8297 /******************************************************************************
8298 * Configure PCI-Ex no-snoop
8300 * hw - Struct containing variables accessed by shared code.
8301 * no_snoop - Bitmap of no-snoop events.
8303 * returns: E1000_SUCCESS
8305 *****************************************************************************/
8307 e1000_set_pci_ex_no_snoop(struct e1000_hw *hw, uint32_t no_snoop)
8309 uint32_t gcr_reg = 0;
8311 DEBUGFUNC("e1000_set_pci_ex_no_snoop");
8313 if (hw->bus_type == e1000_bus_type_unknown)
8314 e1000_get_bus_info(hw);
8316 if (hw->bus_type != e1000_bus_type_pci_express)
8317 return E1000_SUCCESS;
8320 gcr_reg = E1000_READ_REG(hw, GCR);
8321 gcr_reg &= ~(PCI_EX_NO_SNOOP_ALL);
8322 gcr_reg |= no_snoop;
8323 E1000_WRITE_REG(hw, GCR, gcr_reg);
8325 if (hw->mac_type == e1000_ich8lan) {
8328 E1000_WRITE_REG(hw, GCR, PCI_EX_82566_SNOOP_ALL);
8330 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
8331 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
8332 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
8335 return E1000_SUCCESS;
8338 /***************************************************************************
8340 * Get software semaphore FLAG bit (SWFLAG).
8341 * SWFLAG is used to synchronize the access to all shared resource between
8344 * hw: Struct containing variables accessed by shared code
8346 ***************************************************************************/
8348 e1000_get_software_flag(struct e1000_hw *hw)
8350 int32_t timeout = PHY_CFG_TIMEOUT;
8351 uint32_t extcnf_ctrl;
8353 DEBUGFUNC("e1000_get_software_flag");
8355 if (hw->mac_type == e1000_ich8lan) {
8357 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
8358 extcnf_ctrl |= E1000_EXTCNF_CTRL_SWFLAG;
8359 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
8361 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
8362 if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG)
8369 DEBUGOUT("FW or HW locks the resource too long.\n");
8370 return -E1000_ERR_CONFIG;
8374 return E1000_SUCCESS;
8377 /***************************************************************************
8379 * Release software semaphore FLAG bit (SWFLAG).
8380 * SWFLAG is used to synchronize the access to all shared resource between
8383 * hw: Struct containing variables accessed by shared code
8385 ***************************************************************************/
8387 e1000_release_software_flag(struct e1000_hw *hw)
8389 uint32_t extcnf_ctrl;
8391 DEBUGFUNC("e1000_release_software_flag");
8393 if (hw->mac_type == e1000_ich8lan) {
8394 extcnf_ctrl= E1000_READ_REG(hw, EXTCNF_CTRL);
8395 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
8396 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
8402 /******************************************************************************
8403 * Reads a 16 bit word or words from the EEPROM using the ICH8's flash access
8406 * hw - Struct containing variables accessed by shared code
8407 * offset - offset of word in the EEPROM to read
8408 * data - word read from the EEPROM
8409 * words - number of words to read
8410 *****************************************************************************/
8412 e1000_read_eeprom_ich8(struct e1000_hw *hw, uint16_t offset, uint16_t words,
8415 int32_t error = E1000_SUCCESS;
8416 uint32_t flash_bank = 0;
8417 uint32_t act_offset = 0;
8418 uint32_t bank_offset = 0;
8422 /* We need to know which is the valid flash bank. In the event
8423 * that we didn't allocate eeprom_shadow_ram, we may not be
8424 * managing flash_bank. So it cannot be trusted and needs
8425 * to be updated with each read.
8427 /* Value of bit 22 corresponds to the flash bank we're on. */
8428 flash_bank = (E1000_READ_REG(hw, EECD) & E1000_EECD_SEC1VAL) ? 1 : 0;
8430 /* Adjust offset appropriately if we're on bank 1 - adjust for word size */
8431 bank_offset = flash_bank * (hw->flash_bank_size * 2);
8433 error = e1000_get_software_flag(hw);
8434 if (error != E1000_SUCCESS)
8437 for (i = 0; i < words; i++) {
8438 if (hw->eeprom_shadow_ram != NULL &&
8439 hw->eeprom_shadow_ram[offset+i].modified == TRUE) {
8440 data[i] = hw->eeprom_shadow_ram[offset+i].eeprom_word;
8442 /* The NVM part needs a byte offset, hence * 2 */
8443 act_offset = bank_offset + ((offset + i) * 2);
8444 error = e1000_read_ich8_word(hw, act_offset, &word);
8445 if (error != E1000_SUCCESS)
8451 e1000_release_software_flag(hw);
8456 /******************************************************************************
8457 * Writes a 16 bit word or words to the EEPROM using the ICH8's flash access
8458 * register. Actually, writes are written to the shadow ram cache in the hw
8459 * structure hw->e1000_shadow_ram. e1000_commit_shadow_ram flushes this to
8460 * the NVM, which occurs when the NVM checksum is updated.
8462 * hw - Struct containing variables accessed by shared code
8463 * offset - offset of word in the EEPROM to write
8464 * words - number of words to write
8465 * data - words to write to the EEPROM
8466 *****************************************************************************/
8468 e1000_write_eeprom_ich8(struct e1000_hw *hw, uint16_t offset, uint16_t words,
8472 int32_t error = E1000_SUCCESS;
8474 error = e1000_get_software_flag(hw);
8475 if (error != E1000_SUCCESS)
8478 /* A driver can write to the NVM only if it has eeprom_shadow_ram
8479 * allocated. Subsequent reads to the modified words are read from
8480 * this cached structure as well. Writes will only go into this
8481 * cached structure unless it's followed by a call to
8482 * e1000_update_eeprom_checksum() where it will commit the changes
8483 * and clear the "modified" field.
8485 if (hw->eeprom_shadow_ram != NULL) {
8486 for (i = 0; i < words; i++) {
8487 if ((offset + i) < E1000_SHADOW_RAM_WORDS) {
8488 hw->eeprom_shadow_ram[offset+i].modified = TRUE;
8489 hw->eeprom_shadow_ram[offset+i].eeprom_word = data[i];
8491 error = -E1000_ERR_EEPROM;
8496 /* Drivers have the option to not allocate eeprom_shadow_ram as long
8497 * as they don't perform any NVM writes. An attempt in doing so
8498 * will result in this error.
8500 error = -E1000_ERR_EEPROM;
8503 e1000_release_software_flag(hw);
8508 /******************************************************************************
8509 * This function does initial flash setup so that a new read/write/erase cycle
8512 * hw - The pointer to the hw structure
8513 ****************************************************************************/
8515 e1000_ich8_cycle_init(struct e1000_hw *hw)
8517 union ich8_hws_flash_status hsfsts;
8518 int32_t error = E1000_ERR_EEPROM;
8521 DEBUGFUNC("e1000_ich8_cycle_init");
8523 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
8525 /* May be check the Flash Des Valid bit in Hw status */
8526 if (hsfsts.hsf_status.fldesvalid == 0) {
8527 DEBUGOUT("Flash descriptor invalid. SW Sequencing must be used.");
8531 /* Clear FCERR in Hw status by writing 1 */
8532 /* Clear DAEL in Hw status by writing a 1 */
8533 hsfsts.hsf_status.flcerr = 1;
8534 hsfsts.hsf_status.dael = 1;
8536 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS, hsfsts.regval);
8538 /* Either we should have a hardware SPI cycle in progress bit to check
8539 * against, in order to start a new cycle or FDONE bit should be changed
8540 * in the hardware so that it is 1 after harware reset, which can then be
8541 * used as an indication whether a cycle is in progress or has been
8542 * completed .. we should also have some software semaphore mechanism to
8543 * guard FDONE or the cycle in progress bit so that two threads access to
8544 * those bits can be sequentiallized or a way so that 2 threads dont
8545 * start the cycle at the same time */
8547 if (hsfsts.hsf_status.flcinprog == 0) {
8548 /* There is no cycle running at present, so we can start a cycle */
8549 /* Begin by setting Flash Cycle Done. */
8550 hsfsts.hsf_status.flcdone = 1;
8551 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS, hsfsts.regval);
8552 error = E1000_SUCCESS;
8554 /* otherwise poll for sometime so the current cycle has a chance
8555 * to end before giving up. */
8556 for (i = 0; i < ICH_FLASH_COMMAND_TIMEOUT; i++) {
8557 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
8558 if (hsfsts.hsf_status.flcinprog == 0) {
8559 error = E1000_SUCCESS;
8564 if (error == E1000_SUCCESS) {
8565 /* Successful in waiting for previous cycle to timeout,
8566 * now set the Flash Cycle Done. */
8567 hsfsts.hsf_status.flcdone = 1;
8568 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS, hsfsts.regval);
8570 DEBUGOUT("Flash controller busy, cannot get access");
8576 /******************************************************************************
8577 * This function starts a flash cycle and waits for its completion
8579 * hw - The pointer to the hw structure
8580 ****************************************************************************/
8582 e1000_ich8_flash_cycle(struct e1000_hw *hw, uint32_t timeout)
8584 union ich8_hws_flash_ctrl hsflctl;
8585 union ich8_hws_flash_status hsfsts;
8586 int32_t error = E1000_ERR_EEPROM;
8589 /* Start a cycle by writing 1 in Flash Cycle Go in Hw Flash Control */
8590 hsflctl.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL);
8591 hsflctl.hsf_ctrl.flcgo = 1;
8592 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval);
8594 /* wait till FDONE bit is set to 1 */
8596 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
8597 if (hsfsts.hsf_status.flcdone == 1)
8601 } while (i < timeout);
8602 if (hsfsts.hsf_status.flcdone == 1 && hsfsts.hsf_status.flcerr == 0) {
8603 error = E1000_SUCCESS;
8608 /******************************************************************************
8609 * Reads a byte or word from the NVM using the ICH8 flash access registers.
8611 * hw - The pointer to the hw structure
8612 * index - The index of the byte or word to read.
8613 * size - Size of data to read, 1=byte 2=word
8614 * data - Pointer to the word to store the value read.
8615 *****************************************************************************/
8617 e1000_read_ich8_data(struct e1000_hw *hw, uint32_t index,
8618 uint32_t size, uint16_t* data)
8620 union ich8_hws_flash_status hsfsts;
8621 union ich8_hws_flash_ctrl hsflctl;
8622 uint32_t flash_linear_address;
8623 uint32_t flash_data = 0;
8624 int32_t error = -E1000_ERR_EEPROM;
8627 DEBUGFUNC("e1000_read_ich8_data");
8629 if (size < 1 || size > 2 || data == 0x0 ||
8630 index > ICH_FLASH_LINEAR_ADDR_MASK)
8633 flash_linear_address = (ICH_FLASH_LINEAR_ADDR_MASK & index) +
8634 hw->flash_base_addr;
8639 error = e1000_ich8_cycle_init(hw);
8640 if (error != E1000_SUCCESS)
8643 hsflctl.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL);
8644 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
8645 hsflctl.hsf_ctrl.fldbcount = size - 1;
8646 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_READ;
8647 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval);
8649 /* Write the last 24 bits of index into Flash Linear address field in
8651 /* TODO: TBD maybe check the index against the size of flash */
8653 E1000_WRITE_ICH_FLASH_REG(hw, ICH_FLASH_FADDR, flash_linear_address);
8655 error = e1000_ich8_flash_cycle(hw, ICH_FLASH_COMMAND_TIMEOUT);
8657 /* Check if FCERR is set to 1, if set to 1, clear it and try the whole
8658 * sequence a few more times, else read in (shift in) the Flash Data0,
8659 * the order is least significant byte first msb to lsb */
8660 if (error == E1000_SUCCESS) {
8661 flash_data = E1000_READ_ICH_FLASH_REG(hw, ICH_FLASH_FDATA0);
8663 *data = (uint8_t)(flash_data & 0x000000FF);
8664 } else if (size == 2) {
8665 *data = (uint16_t)(flash_data & 0x0000FFFF);
8669 /* If we've gotten here, then things are probably completely hosed,
8670 * but if the error condition is detected, it won't hurt to give
8671 * it another try...ICH_FLASH_CYCLE_REPEAT_COUNT times.
8673 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
8674 if (hsfsts.hsf_status.flcerr == 1) {
8675 /* Repeat for some time before giving up. */
8677 } else if (hsfsts.hsf_status.flcdone == 0) {
8678 DEBUGOUT("Timeout error - flash cycle did not complete.");
8682 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
8687 /******************************************************************************
8688 * Writes One /two bytes to the NVM using the ICH8 flash access registers.
8690 * hw - The pointer to the hw structure
8691 * index - The index of the byte/word to read.
8692 * size - Size of data to read, 1=byte 2=word
8693 * data - The byte(s) to write to the NVM.
8694 *****************************************************************************/
8696 e1000_write_ich8_data(struct e1000_hw *hw, uint32_t index, uint32_t size,
8699 union ich8_hws_flash_status hsfsts;
8700 union ich8_hws_flash_ctrl hsflctl;
8701 uint32_t flash_linear_address;
8702 uint32_t flash_data = 0;
8703 int32_t error = -E1000_ERR_EEPROM;
8706 DEBUGFUNC("e1000_write_ich8_data");
8708 if (size < 1 || size > 2 || data > size * 0xff ||
8709 index > ICH_FLASH_LINEAR_ADDR_MASK)
8712 flash_linear_address = (ICH_FLASH_LINEAR_ADDR_MASK & index) +
8713 hw->flash_base_addr;
8718 error = e1000_ich8_cycle_init(hw);
8719 if (error != E1000_SUCCESS)
8722 hsflctl.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL);
8723 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
8724 hsflctl.hsf_ctrl.fldbcount = size -1;
8725 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_WRITE;
8726 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval);
8728 /* Write the last 24 bits of index into Flash Linear address field in
8730 E1000_WRITE_ICH_FLASH_REG(hw, ICH_FLASH_FADDR, flash_linear_address);
8733 flash_data = (uint32_t)data & 0x00FF;
8735 flash_data = (uint32_t)data;
8737 E1000_WRITE_ICH_FLASH_REG(hw, ICH_FLASH_FDATA0, flash_data);
8739 /* check if FCERR is set to 1 , if set to 1, clear it and try the whole
8740 * sequence a few more times else done */
8741 error = e1000_ich8_flash_cycle(hw, ICH_FLASH_COMMAND_TIMEOUT);
8742 if (error == E1000_SUCCESS) {
8745 /* If we're here, then things are most likely completely hosed,
8746 * but if the error condition is detected, it won't hurt to give
8747 * it another try...ICH_FLASH_CYCLE_REPEAT_COUNT times.
8749 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
8750 if (hsfsts.hsf_status.flcerr == 1) {
8751 /* Repeat for some time before giving up. */
8753 } else if (hsfsts.hsf_status.flcdone == 0) {
8754 DEBUGOUT("Timeout error - flash cycle did not complete.");
8758 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
8763 /******************************************************************************
8764 * Reads a single byte from the NVM using the ICH8 flash access registers.
8766 * hw - pointer to e1000_hw structure
8767 * index - The index of the byte to read.
8768 * data - Pointer to a byte to store the value read.
8769 *****************************************************************************/
8771 e1000_read_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t* data)
8773 int32_t status = E1000_SUCCESS;
8776 status = e1000_read_ich8_data(hw, index, 1, &word);
8777 if (status == E1000_SUCCESS) {
8778 *data = (uint8_t)word;
8784 /******************************************************************************
8785 * Writes a single byte to the NVM using the ICH8 flash access registers.
8786 * Performs verification by reading back the value and then going through
8787 * a retry algorithm before giving up.
8789 * hw - pointer to e1000_hw structure
8790 * index - The index of the byte to write.
8791 * byte - The byte to write to the NVM.
8792 *****************************************************************************/
8794 e1000_verify_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t byte)
8796 int32_t error = E1000_SUCCESS;
8797 int32_t program_retries = 0;
8799 DEBUGOUT2("Byte := %2.2X Offset := %d\n", byte, index);
8801 error = e1000_write_ich8_byte(hw, index, byte);
8803 if (error != E1000_SUCCESS) {
8804 for (program_retries = 0; program_retries < 100; program_retries++) {
8805 DEBUGOUT2("Retrying \t Byte := %2.2X Offset := %d\n", byte, index);
8806 error = e1000_write_ich8_byte(hw, index, byte);
8808 if (error == E1000_SUCCESS)
8813 if (program_retries == 100)
8814 error = E1000_ERR_EEPROM;
8819 /******************************************************************************
8820 * Writes a single byte to the NVM using the ICH8 flash access registers.
8822 * hw - pointer to e1000_hw structure
8823 * index - The index of the byte to read.
8824 * data - The byte to write to the NVM.
8825 *****************************************************************************/
8827 e1000_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t data)
8829 int32_t status = E1000_SUCCESS;
8830 uint16_t word = (uint16_t)data;
8832 status = e1000_write_ich8_data(hw, index, 1, word);
8837 /******************************************************************************
8838 * Reads a word from the NVM using the ICH8 flash access registers.
8840 * hw - pointer to e1000_hw structure
8841 * index - The starting byte index of the word to read.
8842 * data - Pointer to a word to store the value read.
8843 *****************************************************************************/
8845 e1000_read_ich8_word(struct e1000_hw *hw, uint32_t index, uint16_t *data)
8847 int32_t status = E1000_SUCCESS;
8848 status = e1000_read_ich8_data(hw, index, 2, data);
8852 /******************************************************************************
8853 * Erases the bank specified. Each bank may be a 4, 8 or 64k block. Banks are 0
8856 * hw - pointer to e1000_hw structure
8857 * bank - 0 for first bank, 1 for second bank
8859 * Note that this function may actually erase as much as 8 or 64 KBytes. The
8860 * amount of NVM used in each bank is a *minimum* of 4 KBytes, but in fact the
8861 * bank size may be 4, 8 or 64 KBytes
8862 *****************************************************************************/
8864 e1000_erase_ich8_4k_segment(struct e1000_hw *hw, uint32_t bank)
8866 union ich8_hws_flash_status hsfsts;
8867 union ich8_hws_flash_ctrl hsflctl;
8868 uint32_t flash_linear_address;
8870 int32_t error = E1000_ERR_EEPROM;
8872 int32_t sub_sector_size = 0;
8875 int32_t error_flag = 0;
8877 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
8879 /* Determine HW Sector size: Read BERASE bits of Hw flash Status register */
8880 /* 00: The Hw sector is 256 bytes, hence we need to erase 16
8881 * consecutive sectors. The start index for the nth Hw sector can be
8882 * calculated as bank * 4096 + n * 256
8883 * 01: The Hw sector is 4K bytes, hence we need to erase 1 sector.
8884 * The start index for the nth Hw sector can be calculated
8886 * 10: The HW sector is 8K bytes
8887 * 11: The Hw sector size is 64K bytes */
8888 if (hsfsts.hsf_status.berasesz == 0x0) {
8889 /* Hw sector size 256 */
8890 sub_sector_size = ICH_FLASH_SEG_SIZE_256;
8891 bank_size = ICH_FLASH_SECTOR_SIZE;
8892 iteration = ICH_FLASH_SECTOR_SIZE / ICH_FLASH_SEG_SIZE_256;
8893 } else if (hsfsts.hsf_status.berasesz == 0x1) {
8894 bank_size = ICH_FLASH_SEG_SIZE_4K;
8896 } else if (hsfsts.hsf_status.berasesz == 0x3) {
8897 bank_size = ICH_FLASH_SEG_SIZE_64K;
8903 for (j = 0; j < iteration ; j++) {
8907 error = e1000_ich8_cycle_init(hw);
8908 if (error != E1000_SUCCESS) {
8913 /* Write a value 11 (block Erase) in Flash Cycle field in Hw flash
8915 hsflctl.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL);
8916 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_ERASE;
8917 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval);
8919 /* Write the last 24 bits of an index within the block into Flash
8920 * Linear address field in Flash Address. This probably needs to
8921 * be calculated here based off the on-chip erase sector size and
8922 * the software bank size (4, 8 or 64 KBytes) */
8923 flash_linear_address = bank * bank_size + j * sub_sector_size;
8924 flash_linear_address += hw->flash_base_addr;
8925 flash_linear_address &= ICH_FLASH_LINEAR_ADDR_MASK;
8927 E1000_WRITE_ICH_FLASH_REG(hw, ICH_FLASH_FADDR, flash_linear_address);
8929 error = e1000_ich8_flash_cycle(hw, ICH_FLASH_ERASE_TIMEOUT);
8930 /* Check if FCERR is set to 1. If 1, clear it and try the whole
8931 * sequence a few more times else Done */
8932 if (error == E1000_SUCCESS) {
8935 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
8936 if (hsfsts.hsf_status.flcerr == 1) {
8937 /* repeat for some time before giving up */
8939 } else if (hsfsts.hsf_status.flcdone == 0) {
8944 } while ((count < ICH_FLASH_CYCLE_REPEAT_COUNT) && !error_flag);
8945 if (error_flag == 1)
8948 if (error_flag != 1)
8949 error = E1000_SUCCESS;
8954 e1000_init_lcd_from_nvm_config_region(struct e1000_hw *hw,
8955 uint32_t cnf_base_addr, uint32_t cnf_size)
8957 uint32_t ret_val = E1000_SUCCESS;
8958 uint16_t word_addr, reg_data, reg_addr;
8961 /* cnf_base_addr is in DWORD */
8962 word_addr = (uint16_t)(cnf_base_addr << 1);
8964 /* cnf_size is returned in size of dwords */
8965 for (i = 0; i < cnf_size; i++) {
8966 ret_val = e1000_read_eeprom(hw, (word_addr + i*2), 1, ®_data);
8970 ret_val = e1000_read_eeprom(hw, (word_addr + i*2 + 1), 1, ®_addr);
8974 ret_val = e1000_get_software_flag(hw);
8975 if (ret_val != E1000_SUCCESS)
8978 ret_val = e1000_write_phy_reg_ex(hw, (uint32_t)reg_addr, reg_data);
8980 e1000_release_software_flag(hw);
8987 /******************************************************************************
8988 * This function initializes the PHY from the NVM on ICH8 platforms. This
8989 * is needed due to an issue where the NVM configuration is not properly
8990 * autoloaded after power transitions. Therefore, after each PHY reset, we
8991 * will load the configuration data out of the NVM manually.
8993 * hw: Struct containing variables accessed by shared code
8994 *****************************************************************************/
8996 e1000_init_lcd_from_nvm(struct e1000_hw *hw)
8998 uint32_t reg_data, cnf_base_addr, cnf_size, ret_val, loop;
9000 if (hw->phy_type != e1000_phy_igp_3)
9001 return E1000_SUCCESS;
9003 /* Check if SW needs configure the PHY */
9004 reg_data = E1000_READ_REG(hw, FEXTNVM);
9005 if (!(reg_data & FEXTNVM_SW_CONFIG))
9006 return E1000_SUCCESS;
9008 /* Wait for basic configuration completes before proceeding*/
9011 reg_data = E1000_READ_REG(hw, STATUS) & E1000_STATUS_LAN_INIT_DONE;
9014 } while ((!reg_data) && (loop < 50));
9016 /* Clear the Init Done bit for the next init event */
9017 reg_data = E1000_READ_REG(hw, STATUS);
9018 reg_data &= ~E1000_STATUS_LAN_INIT_DONE;
9019 E1000_WRITE_REG(hw, STATUS, reg_data);
9021 /* Make sure HW does not configure LCD from PHY extended configuration
9022 before SW configuration */
9023 reg_data = E1000_READ_REG(hw, EXTCNF_CTRL);
9024 if ((reg_data & E1000_EXTCNF_CTRL_LCD_WRITE_ENABLE) == 0x0000) {
9025 reg_data = E1000_READ_REG(hw, EXTCNF_SIZE);
9026 cnf_size = reg_data & E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH;
9029 reg_data = E1000_READ_REG(hw, EXTCNF_CTRL);
9030 cnf_base_addr = reg_data & E1000_EXTCNF_CTRL_EXT_CNF_POINTER;
9031 /* cnf_base_addr is in DWORD */
9032 cnf_base_addr >>= 16;
9034 /* Configure LCD from extended configuration region. */
9035 ret_val = e1000_init_lcd_from_nvm_config_region(hw, cnf_base_addr,
9042 return E1000_SUCCESS;