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)
878 DEBUGFUNC("e1000_init_hw");
880 /* force full DMA clock frequency for 10/100 on ICH8 A0-B0 */
881 if ((hw->mac_type == e1000_ich8lan) &&
882 ((hw->revision_id < 3) ||
883 ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) &&
884 (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))) {
885 reg_data = E1000_READ_REG(hw, STATUS);
886 reg_data &= ~0x80000000;
887 E1000_WRITE_REG(hw, STATUS, reg_data);
890 /* Initialize Identification LED */
891 ret_val = e1000_id_led_init(hw);
893 DEBUGOUT("Error Initializing Identification LED\n");
897 /* Set the media type and TBI compatibility */
898 e1000_set_media_type(hw);
900 /* Must be called after e1000_set_media_type because media_type is used */
901 e1000_initialize_hardware_bits(hw);
903 /* Disabling VLAN filtering. */
904 DEBUGOUT("Initializing the IEEE VLAN\n");
905 /* VET hardcoded to standard value and VFTA removed in ICH8 LAN */
906 if (hw->mac_type != e1000_ich8lan) {
907 if (hw->mac_type < e1000_82545_rev_3)
908 E1000_WRITE_REG(hw, VET, 0);
909 e1000_clear_vfta(hw);
912 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
913 if (hw->mac_type == e1000_82542_rev2_0) {
914 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
915 e1000_pci_clear_mwi(hw);
916 E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST);
917 E1000_WRITE_FLUSH(hw);
921 /* Setup the receive address. This involves initializing all of the Receive
922 * Address Registers (RARs 0 - 15).
924 e1000_init_rx_addrs(hw);
926 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
927 if (hw->mac_type == e1000_82542_rev2_0) {
928 E1000_WRITE_REG(hw, RCTL, 0);
929 E1000_WRITE_FLUSH(hw);
931 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
932 e1000_pci_set_mwi(hw);
935 /* Zero out the Multicast HASH table */
936 DEBUGOUT("Zeroing the MTA\n");
937 mta_size = E1000_MC_TBL_SIZE;
938 if (hw->mac_type == e1000_ich8lan)
939 mta_size = E1000_MC_TBL_SIZE_ICH8LAN;
940 for (i = 0; i < mta_size; i++) {
941 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
942 /* use write flush to prevent Memory Write Block (MWB) from
943 * occuring when accessing our register space */
944 E1000_WRITE_FLUSH(hw);
947 /* Set the PCI priority bit correctly in the CTRL register. This
948 * determines if the adapter gives priority to receives, or if it
949 * gives equal priority to transmits and receives. Valid only on
950 * 82542 and 82543 silicon.
952 if (hw->dma_fairness && hw->mac_type <= e1000_82543) {
953 ctrl = E1000_READ_REG(hw, CTRL);
954 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PRIOR);
957 switch (hw->mac_type) {
958 case e1000_82545_rev_3:
959 case e1000_82546_rev_3:
962 /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
963 if (hw->bus_type == e1000_bus_type_pcix && e1000_pcix_get_mmrbc(hw) > 2048)
964 e1000_pcix_set_mmrbc(hw, 2048);
968 /* More time needed for PHY to initialize */
969 if (hw->mac_type == e1000_ich8lan)
972 /* Call a subroutine to configure the link and setup flow control. */
973 ret_val = e1000_setup_link(hw);
975 /* Set the transmit descriptor write-back policy */
976 if (hw->mac_type > e1000_82544) {
977 ctrl = E1000_READ_REG(hw, TXDCTL);
978 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
979 E1000_WRITE_REG(hw, TXDCTL, ctrl);
982 if (hw->mac_type == e1000_82573) {
983 e1000_enable_tx_pkt_filtering(hw);
986 switch (hw->mac_type) {
989 case e1000_80003es2lan:
990 /* Enable retransmit on late collisions */
991 reg_data = E1000_READ_REG(hw, TCTL);
992 reg_data |= E1000_TCTL_RTLC;
993 E1000_WRITE_REG(hw, TCTL, reg_data);
995 /* Configure Gigabit Carry Extend Padding */
996 reg_data = E1000_READ_REG(hw, TCTL_EXT);
997 reg_data &= ~E1000_TCTL_EXT_GCEX_MASK;
998 reg_data |= DEFAULT_80003ES2LAN_TCTL_EXT_GCEX;
999 E1000_WRITE_REG(hw, TCTL_EXT, reg_data);
1001 /* Configure Transmit Inter-Packet Gap */
1002 reg_data = E1000_READ_REG(hw, TIPG);
1003 reg_data &= ~E1000_TIPG_IPGT_MASK;
1004 reg_data |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
1005 E1000_WRITE_REG(hw, TIPG, reg_data);
1007 reg_data = E1000_READ_REG_ARRAY(hw, FFLT, 0x0001);
1008 reg_data &= ~0x00100000;
1009 E1000_WRITE_REG_ARRAY(hw, FFLT, 0x0001, reg_data);
1014 ctrl = E1000_READ_REG(hw, TXDCTL1);
1015 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
1016 E1000_WRITE_REG(hw, TXDCTL1, ctrl);
1021 if (hw->mac_type == e1000_82573) {
1022 uint32_t gcr = E1000_READ_REG(hw, GCR);
1023 gcr |= E1000_GCR_L1_ACT_WITHOUT_L0S_RX;
1024 E1000_WRITE_REG(hw, GCR, gcr);
1027 /* Clear all of the statistics registers (clear on read). It is
1028 * important that we do this after we have tried to establish link
1029 * because the symbol error count will increment wildly if there
1032 e1000_clear_hw_cntrs(hw);
1034 /* ICH8 No-snoop bits are opposite polarity.
1035 * Set to snoop by default after reset. */
1036 if (hw->mac_type == e1000_ich8lan)
1037 e1000_set_pci_ex_no_snoop(hw, PCI_EX_82566_SNOOP_ALL);
1039 if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER ||
1040 hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) {
1041 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
1042 /* Relaxed ordering must be disabled to avoid a parity
1043 * error crash in a PCI slot. */
1044 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
1045 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1051 /******************************************************************************
1052 * Adjust SERDES output amplitude based on EEPROM setting.
1054 * hw - Struct containing variables accessed by shared code.
1055 *****************************************************************************/
1057 e1000_adjust_serdes_amplitude(struct e1000_hw *hw)
1059 uint16_t eeprom_data;
1062 DEBUGFUNC("e1000_adjust_serdes_amplitude");
1064 if (hw->media_type != e1000_media_type_internal_serdes)
1065 return E1000_SUCCESS;
1067 switch (hw->mac_type) {
1068 case e1000_82545_rev_3:
1069 case e1000_82546_rev_3:
1072 return E1000_SUCCESS;
1075 ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1, &eeprom_data);
1080 if (eeprom_data != EEPROM_RESERVED_WORD) {
1081 /* Adjust SERDES output amplitude only. */
1082 eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK;
1083 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data);
1088 return E1000_SUCCESS;
1091 /******************************************************************************
1092 * Configures flow control and link settings.
1094 * hw - Struct containing variables accessed by shared code
1096 * Determines which flow control settings to use. Calls the apropriate media-
1097 * specific link configuration function. Configures the flow control settings.
1098 * Assuming the adapter has a valid link partner, a valid link should be
1099 * established. Assumes the hardware has previously been reset and the
1100 * transmitter and receiver are not enabled.
1101 *****************************************************************************/
1103 e1000_setup_link(struct e1000_hw *hw)
1107 uint16_t eeprom_data;
1109 DEBUGFUNC("e1000_setup_link");
1111 /* In the case of the phy reset being blocked, we already have a link.
1112 * We do not have to set it up again. */
1113 if (e1000_check_phy_reset_block(hw))
1114 return E1000_SUCCESS;
1116 /* Read and store word 0x0F of the EEPROM. This word contains bits
1117 * that determine the hardware's default PAUSE (flow control) mode,
1118 * a bit that determines whether the HW defaults to enabling or
1119 * disabling auto-negotiation, and the direction of the
1120 * SW defined pins. If there is no SW over-ride of the flow
1121 * control setting, then the variable hw->fc will
1122 * be initialized based on a value in the EEPROM.
1124 if (hw->fc == E1000_FC_DEFAULT) {
1125 switch (hw->mac_type) {
1128 hw->fc = E1000_FC_FULL;
1131 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
1134 DEBUGOUT("EEPROM Read Error\n");
1135 return -E1000_ERR_EEPROM;
1137 if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
1138 hw->fc = E1000_FC_NONE;
1139 else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
1140 EEPROM_WORD0F_ASM_DIR)
1141 hw->fc = E1000_FC_TX_PAUSE;
1143 hw->fc = E1000_FC_FULL;
1148 /* We want to save off the original Flow Control configuration just
1149 * in case we get disconnected and then reconnected into a different
1150 * hub or switch with different Flow Control capabilities.
1152 if (hw->mac_type == e1000_82542_rev2_0)
1153 hw->fc &= (~E1000_FC_TX_PAUSE);
1155 if ((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
1156 hw->fc &= (~E1000_FC_RX_PAUSE);
1158 hw->original_fc = hw->fc;
1160 DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc);
1162 /* Take the 4 bits from EEPROM word 0x0F that determine the initial
1163 * polarity value for the SW controlled pins, and setup the
1164 * Extended Device Control reg with that info.
1165 * This is needed because one of the SW controlled pins is used for
1166 * signal detection. So this should be done before e1000_setup_pcs_link()
1167 * or e1000_phy_setup() is called.
1169 if (hw->mac_type == e1000_82543) {
1170 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
1173 DEBUGOUT("EEPROM Read Error\n");
1174 return -E1000_ERR_EEPROM;
1176 ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
1178 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1181 /* Call the necessary subroutine to configure the link. */
1182 ret_val = (hw->media_type == e1000_media_type_copper) ?
1183 e1000_setup_copper_link(hw) :
1184 e1000_setup_fiber_serdes_link(hw);
1186 /* Initialize the flow control address, type, and PAUSE timer
1187 * registers to their default values. This is done even if flow
1188 * control is disabled, because it does not hurt anything to
1189 * initialize these registers.
1191 DEBUGOUT("Initializing the Flow Control address, type and timer regs\n");
1193 /* FCAL/H and FCT are hardcoded to standard values in e1000_ich8lan. */
1194 if (hw->mac_type != e1000_ich8lan) {
1195 E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
1196 E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
1197 E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
1200 E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
1202 /* Set the flow control receive threshold registers. Normally,
1203 * these registers will be set to a default threshold that may be
1204 * adjusted later by the driver's runtime code. However, if the
1205 * ability to transmit pause frames in not enabled, then these
1206 * registers will be set to 0.
1208 if (!(hw->fc & E1000_FC_TX_PAUSE)) {
1209 E1000_WRITE_REG(hw, FCRTL, 0);
1210 E1000_WRITE_REG(hw, FCRTH, 0);
1212 /* We need to set up the Receive Threshold high and low water marks
1213 * as well as (optionally) enabling the transmission of XON frames.
1215 if (hw->fc_send_xon) {
1216 E1000_WRITE_REG(hw, FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE));
1217 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
1219 E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water);
1220 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
1226 /******************************************************************************
1227 * Sets up link for a fiber based or serdes based adapter
1229 * hw - Struct containing variables accessed by shared code
1231 * Manipulates Physical Coding Sublayer functions in order to configure
1232 * link. Assumes the hardware has been previously reset and the transmitter
1233 * and receiver are not enabled.
1234 *****************************************************************************/
1236 e1000_setup_fiber_serdes_link(struct e1000_hw *hw)
1242 uint32_t signal = 0;
1245 DEBUGFUNC("e1000_setup_fiber_serdes_link");
1247 /* On 82571 and 82572 Fiber connections, SerDes loopback mode persists
1248 * until explicitly turned off or a power cycle is performed. A read to
1249 * the register does not indicate its status. Therefore, we ensure
1250 * loopback mode is disabled during initialization.
1252 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572)
1253 E1000_WRITE_REG(hw, SCTL, E1000_DISABLE_SERDES_LOOPBACK);
1255 /* On adapters with a MAC newer than 82544, SWDP 1 will be
1256 * set when the optics detect a signal. On older adapters, it will be
1257 * cleared when there is a signal. This applies to fiber media only.
1258 * If we're on serdes media, adjust the output amplitude to value
1259 * set in the EEPROM.
1261 ctrl = E1000_READ_REG(hw, CTRL);
1262 if (hw->media_type == e1000_media_type_fiber)
1263 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
1265 ret_val = e1000_adjust_serdes_amplitude(hw);
1269 /* Take the link out of reset */
1270 ctrl &= ~(E1000_CTRL_LRST);
1272 /* Adjust VCO speed to improve BER performance */
1273 ret_val = e1000_set_vco_speed(hw);
1277 e1000_config_collision_dist(hw);
1279 /* Check for a software override of the flow control settings, and setup
1280 * the device accordingly. If auto-negotiation is enabled, then software
1281 * will have to set the "PAUSE" bits to the correct value in the Tranmsit
1282 * Config Word Register (TXCW) and re-start auto-negotiation. However, if
1283 * auto-negotiation is disabled, then software will have to manually
1284 * configure the two flow control enable bits in the CTRL register.
1286 * The possible values of the "fc" parameter are:
1287 * 0: Flow control is completely disabled
1288 * 1: Rx flow control is enabled (we can receive pause frames, but
1289 * not send pause frames).
1290 * 2: Tx flow control is enabled (we can send pause frames but we do
1291 * not support receiving pause frames).
1292 * 3: Both Rx and TX flow control (symmetric) are enabled.
1296 /* Flow control is completely disabled by a software over-ride. */
1297 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
1299 case E1000_FC_RX_PAUSE:
1300 /* RX Flow control is enabled and TX Flow control is disabled by a
1301 * software over-ride. Since there really isn't a way to advertise
1302 * that we are capable of RX Pause ONLY, we will advertise that we
1303 * support both symmetric and asymmetric RX PAUSE. Later, we will
1304 * disable the adapter's ability to send PAUSE frames.
1306 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1308 case E1000_FC_TX_PAUSE:
1309 /* TX Flow control is enabled, and RX Flow control is disabled, by a
1310 * software over-ride.
1312 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
1315 /* Flow control (both RX and TX) is enabled by a software over-ride. */
1316 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1319 DEBUGOUT("Flow control param set incorrectly\n");
1320 return -E1000_ERR_CONFIG;
1324 /* Since auto-negotiation is enabled, take the link out of reset (the link
1325 * will be in reset, because we previously reset the chip). This will
1326 * restart auto-negotiation. If auto-neogtiation is successful then the
1327 * link-up status bit will be set and the flow control enable bits (RFCE
1328 * and TFCE) will be set according to their negotiated value.
1330 DEBUGOUT("Auto-negotiation enabled\n");
1332 E1000_WRITE_REG(hw, TXCW, txcw);
1333 E1000_WRITE_REG(hw, CTRL, ctrl);
1334 E1000_WRITE_FLUSH(hw);
1339 /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
1340 * indication in the Device Status Register. Time-out if a link isn't
1341 * seen in 500 milliseconds seconds (Auto-negotiation should complete in
1342 * less than 500 milliseconds even if the other end is doing it in SW).
1343 * For internal serdes, we just assume a signal is present, then poll.
1345 if (hw->media_type == e1000_media_type_internal_serdes ||
1346 (E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) {
1347 DEBUGOUT("Looking for Link\n");
1348 for (i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
1350 status = E1000_READ_REG(hw, STATUS);
1351 if (status & E1000_STATUS_LU) break;
1353 if (i == (LINK_UP_TIMEOUT / 10)) {
1354 DEBUGOUT("Never got a valid link from auto-neg!!!\n");
1355 hw->autoneg_failed = 1;
1356 /* AutoNeg failed to achieve a link, so we'll call
1357 * e1000_check_for_link. This routine will force the link up if
1358 * we detect a signal. This will allow us to communicate with
1359 * non-autonegotiating link partners.
1361 ret_val = e1000_check_for_link(hw);
1363 DEBUGOUT("Error while checking for link\n");
1366 hw->autoneg_failed = 0;
1368 hw->autoneg_failed = 0;
1369 DEBUGOUT("Valid Link Found\n");
1372 DEBUGOUT("No Signal Detected\n");
1374 return E1000_SUCCESS;
1377 /******************************************************************************
1378 * Make sure we have a valid PHY and change PHY mode before link setup.
1380 * hw - Struct containing variables accessed by shared code
1381 ******************************************************************************/
1383 e1000_copper_link_preconfig(struct e1000_hw *hw)
1389 DEBUGFUNC("e1000_copper_link_preconfig");
1391 ctrl = E1000_READ_REG(hw, CTRL);
1392 /* With 82543, we need to force speed and duplex on the MAC equal to what
1393 * the PHY speed and duplex configuration is. In addition, we need to
1394 * perform a hardware reset on the PHY to take it out of reset.
1396 if (hw->mac_type > e1000_82543) {
1397 ctrl |= E1000_CTRL_SLU;
1398 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1399 E1000_WRITE_REG(hw, CTRL, ctrl);
1401 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
1402 E1000_WRITE_REG(hw, CTRL, ctrl);
1403 ret_val = e1000_phy_hw_reset(hw);
1408 /* Make sure we have a valid PHY */
1409 ret_val = e1000_detect_gig_phy(hw);
1411 DEBUGOUT("Error, did not detect valid phy.\n");
1414 DEBUGOUT1("Phy ID = %x \n", hw->phy_id);
1416 /* Set PHY to class A mode (if necessary) */
1417 ret_val = e1000_set_phy_mode(hw);
1421 if ((hw->mac_type == e1000_82545_rev_3) ||
1422 (hw->mac_type == e1000_82546_rev_3)) {
1423 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1424 phy_data |= 0x00000008;
1425 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1428 if (hw->mac_type <= e1000_82543 ||
1429 hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
1430 hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2)
1431 hw->phy_reset_disable = FALSE;
1433 return E1000_SUCCESS;
1437 /********************************************************************
1438 * Copper link setup for e1000_phy_igp series.
1440 * hw - Struct containing variables accessed by shared code
1441 *********************************************************************/
1443 e1000_copper_link_igp_setup(struct e1000_hw *hw)
1449 DEBUGFUNC("e1000_copper_link_igp_setup");
1451 if (hw->phy_reset_disable)
1452 return E1000_SUCCESS;
1454 ret_val = e1000_phy_reset(hw);
1456 DEBUGOUT("Error Resetting the PHY\n");
1460 /* Wait 15ms for MAC to configure PHY from eeprom settings */
1462 if (hw->mac_type != e1000_ich8lan) {
1463 /* Configure activity LED after PHY reset */
1464 led_ctrl = E1000_READ_REG(hw, LEDCTL);
1465 led_ctrl &= IGP_ACTIVITY_LED_MASK;
1466 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
1467 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
1470 /* The NVM settings will configure LPLU in D3 for IGP2 and IGP3 PHYs */
1471 if (hw->phy_type == e1000_phy_igp) {
1472 /* disable lplu d3 during driver init */
1473 ret_val = e1000_set_d3_lplu_state(hw, FALSE);
1475 DEBUGOUT("Error Disabling LPLU D3\n");
1480 /* disable lplu d0 during driver init */
1481 ret_val = e1000_set_d0_lplu_state(hw, FALSE);
1483 DEBUGOUT("Error Disabling LPLU D0\n");
1486 /* Configure mdi-mdix settings */
1487 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1491 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
1492 hw->dsp_config_state = e1000_dsp_config_disabled;
1493 /* Force MDI for earlier revs of the IGP PHY */
1494 phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX | IGP01E1000_PSCR_FORCE_MDI_MDIX);
1498 hw->dsp_config_state = e1000_dsp_config_enabled;
1499 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1503 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1506 phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
1510 phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
1514 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1518 /* set auto-master slave resolution settings */
1520 e1000_ms_type phy_ms_setting = hw->master_slave;
1522 if (hw->ffe_config_state == e1000_ffe_config_active)
1523 hw->ffe_config_state = e1000_ffe_config_enabled;
1525 if (hw->dsp_config_state == e1000_dsp_config_activated)
1526 hw->dsp_config_state = e1000_dsp_config_enabled;
1528 /* when autonegotiation advertisment is only 1000Mbps then we
1529 * should disable SmartSpeed and enable Auto MasterSlave
1530 * resolution as hardware default. */
1531 if (hw->autoneg_advertised == ADVERTISE_1000_FULL) {
1532 /* Disable SmartSpeed */
1533 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1537 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1538 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1542 /* Set auto Master/Slave resolution process */
1543 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1546 phy_data &= ~CR_1000T_MS_ENABLE;
1547 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1552 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1556 /* load defaults for future use */
1557 hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
1558 ((phy_data & CR_1000T_MS_VALUE) ?
1559 e1000_ms_force_master :
1560 e1000_ms_force_slave) :
1563 switch (phy_ms_setting) {
1564 case e1000_ms_force_master:
1565 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
1567 case e1000_ms_force_slave:
1568 phy_data |= CR_1000T_MS_ENABLE;
1569 phy_data &= ~(CR_1000T_MS_VALUE);
1572 phy_data &= ~CR_1000T_MS_ENABLE;
1576 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1581 return E1000_SUCCESS;
1584 /********************************************************************
1585 * Copper link setup for e1000_phy_gg82563 series.
1587 * hw - Struct containing variables accessed by shared code
1588 *********************************************************************/
1590 e1000_copper_link_ggp_setup(struct e1000_hw *hw)
1596 DEBUGFUNC("e1000_copper_link_ggp_setup");
1598 if (!hw->phy_reset_disable) {
1600 /* Enable CRS on TX for half-duplex operation. */
1601 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL,
1606 phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
1607 /* Use 25MHz for both link down and 1000BASE-T for Tx clock */
1608 phy_data |= GG82563_MSCR_TX_CLK_1000MBPS_25MHZ;
1610 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL,
1616 * MDI/MDI-X = 0 (default)
1617 * 0 - Auto for all speeds
1620 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1622 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_SPEC_CTRL, &phy_data);
1626 phy_data &= ~GG82563_PSCR_CROSSOVER_MODE_MASK;
1630 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDI;
1633 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDIX;
1637 phy_data |= GG82563_PSCR_CROSSOVER_MODE_AUTO;
1642 * disable_polarity_correction = 0 (default)
1643 * Automatic Correction for Reversed Cable Polarity
1647 phy_data &= ~GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
1648 if (hw->disable_polarity_correction == 1)
1649 phy_data |= GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
1650 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_SPEC_CTRL, phy_data);
1655 /* SW Reset the PHY so all changes take effect */
1656 ret_val = e1000_phy_reset(hw);
1658 DEBUGOUT("Error Resetting the PHY\n");
1661 } /* phy_reset_disable */
1663 if (hw->mac_type == e1000_80003es2lan) {
1664 /* Bypass RX and TX FIFO's */
1665 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_FIFO_CTRL,
1666 E1000_KUMCTRLSTA_FIFO_CTRL_RX_BYPASS |
1667 E1000_KUMCTRLSTA_FIFO_CTRL_TX_BYPASS);
1671 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_SPEC_CTRL_2, &phy_data);
1675 phy_data &= ~GG82563_PSCR2_REVERSE_AUTO_NEG;
1676 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_SPEC_CTRL_2, phy_data);
1681 reg_data = E1000_READ_REG(hw, CTRL_EXT);
1682 reg_data &= ~(E1000_CTRL_EXT_LINK_MODE_MASK);
1683 E1000_WRITE_REG(hw, CTRL_EXT, reg_data);
1685 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_PWR_MGMT_CTRL,
1690 /* Do not init these registers when the HW is in IAMT mode, since the
1691 * firmware will have already initialized them. We only initialize
1692 * them if the HW is not in IAMT mode.
1694 if (e1000_check_mng_mode(hw) == FALSE) {
1695 /* Enable Electrical Idle on the PHY */
1696 phy_data |= GG82563_PMCR_ENABLE_ELECTRICAL_IDLE;
1697 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_PWR_MGMT_CTRL,
1702 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
1707 phy_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
1708 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
1715 /* Workaround: Disable padding in Kumeran interface in the MAC
1716 * and in the PHY to avoid CRC errors.
1718 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_INBAND_CTRL,
1722 phy_data |= GG82563_ICR_DIS_PADDING;
1723 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_INBAND_CTRL,
1729 return E1000_SUCCESS;
1732 /********************************************************************
1733 * Copper link setup for e1000_phy_m88 series.
1735 * hw - Struct containing variables accessed by shared code
1736 *********************************************************************/
1738 e1000_copper_link_mgp_setup(struct e1000_hw *hw)
1743 DEBUGFUNC("e1000_copper_link_mgp_setup");
1745 if (hw->phy_reset_disable)
1746 return E1000_SUCCESS;
1748 /* Enable CRS on TX. This must be set for half-duplex operation. */
1749 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1753 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1756 * MDI/MDI-X = 0 (default)
1757 * 0 - Auto for all speeds
1760 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1762 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1766 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
1769 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
1772 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
1776 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
1781 * disable_polarity_correction = 0 (default)
1782 * Automatic Correction for Reversed Cable Polarity
1786 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
1787 if (hw->disable_polarity_correction == 1)
1788 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
1789 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1793 if (hw->phy_revision < M88E1011_I_REV_4) {
1794 /* Force TX_CLK in the Extended PHY Specific Control Register
1797 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1801 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1803 if ((hw->phy_revision == E1000_REVISION_2) &&
1804 (hw->phy_id == M88E1111_I_PHY_ID)) {
1805 /* Vidalia Phy, set the downshift counter to 5x */
1806 phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK);
1807 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
1808 ret_val = e1000_write_phy_reg(hw,
1809 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1813 /* Configure Master and Slave downshift values */
1814 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
1815 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
1816 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
1817 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
1818 ret_val = e1000_write_phy_reg(hw,
1819 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1825 /* SW Reset the PHY so all changes take effect */
1826 ret_val = e1000_phy_reset(hw);
1828 DEBUGOUT("Error Resetting the PHY\n");
1832 return E1000_SUCCESS;
1835 /********************************************************************
1836 * Setup auto-negotiation and flow control advertisements,
1837 * and then perform auto-negotiation.
1839 * hw - Struct containing variables accessed by shared code
1840 *********************************************************************/
1842 e1000_copper_link_autoneg(struct e1000_hw *hw)
1847 DEBUGFUNC("e1000_copper_link_autoneg");
1849 /* Perform some bounds checking on the hw->autoneg_advertised
1850 * parameter. If this variable is zero, then set it to the default.
1852 hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
1854 /* If autoneg_advertised is zero, we assume it was not defaulted
1855 * by the calling code so we set to advertise full capability.
1857 if (hw->autoneg_advertised == 0)
1858 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
1860 /* IFE phy only supports 10/100 */
1861 if (hw->phy_type == e1000_phy_ife)
1862 hw->autoneg_advertised &= AUTONEG_ADVERTISE_10_100_ALL;
1864 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
1865 ret_val = e1000_phy_setup_autoneg(hw);
1867 DEBUGOUT("Error Setting up Auto-Negotiation\n");
1870 DEBUGOUT("Restarting Auto-Neg\n");
1872 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
1873 * the Auto Neg Restart bit in the PHY control register.
1875 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
1879 phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
1880 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
1884 /* Does the user want to wait for Auto-Neg to complete here, or
1885 * check at a later time (for example, callback routine).
1887 if (hw->wait_autoneg_complete) {
1888 ret_val = e1000_wait_autoneg(hw);
1890 DEBUGOUT("Error while waiting for autoneg to complete\n");
1895 hw->get_link_status = TRUE;
1897 return E1000_SUCCESS;
1900 /******************************************************************************
1901 * Config the MAC and the PHY after link is up.
1902 * 1) Set up the MAC to the current PHY speed/duplex
1903 * if we are on 82543. If we
1904 * are on newer silicon, we only need to configure
1905 * collision distance in the Transmit Control Register.
1906 * 2) Set up flow control on the MAC to that established with
1908 * 3) Config DSP to improve Gigabit link quality for some PHY revisions.
1910 * hw - Struct containing variables accessed by shared code
1911 ******************************************************************************/
1913 e1000_copper_link_postconfig(struct e1000_hw *hw)
1916 DEBUGFUNC("e1000_copper_link_postconfig");
1918 if (hw->mac_type >= e1000_82544) {
1919 e1000_config_collision_dist(hw);
1921 ret_val = e1000_config_mac_to_phy(hw);
1923 DEBUGOUT("Error configuring MAC to PHY settings\n");
1927 ret_val = e1000_config_fc_after_link_up(hw);
1929 DEBUGOUT("Error Configuring Flow Control\n");
1933 /* Config DSP to improve Giga link quality */
1934 if (hw->phy_type == e1000_phy_igp) {
1935 ret_val = e1000_config_dsp_after_link_change(hw, TRUE);
1937 DEBUGOUT("Error Configuring DSP after link up\n");
1942 return E1000_SUCCESS;
1945 /******************************************************************************
1946 * Detects which PHY is present and setup the speed and duplex
1948 * hw - Struct containing variables accessed by shared code
1949 ******************************************************************************/
1951 e1000_setup_copper_link(struct e1000_hw *hw)
1958 DEBUGFUNC("e1000_setup_copper_link");
1960 switch (hw->mac_type) {
1961 case e1000_80003es2lan:
1963 /* Set the mac to wait the maximum time between each
1964 * iteration and increase the max iterations when
1965 * polling the phy; this fixes erroneous timeouts at 10Mbps. */
1966 ret_val = e1000_write_kmrn_reg(hw, GG82563_REG(0x34, 4), 0xFFFF);
1969 ret_val = e1000_read_kmrn_reg(hw, GG82563_REG(0x34, 9), ®_data);
1973 ret_val = e1000_write_kmrn_reg(hw, GG82563_REG(0x34, 9), reg_data);
1980 /* Check if it is a valid PHY and set PHY mode if necessary. */
1981 ret_val = e1000_copper_link_preconfig(hw);
1985 switch (hw->mac_type) {
1986 case e1000_80003es2lan:
1987 /* Kumeran registers are written-only */
1988 reg_data = E1000_KUMCTRLSTA_INB_CTRL_LINK_STATUS_TX_TIMEOUT_DEFAULT;
1989 reg_data |= E1000_KUMCTRLSTA_INB_CTRL_DIS_PADDING;
1990 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_INB_CTRL,
1999 if (hw->phy_type == e1000_phy_igp ||
2000 hw->phy_type == e1000_phy_igp_3 ||
2001 hw->phy_type == e1000_phy_igp_2) {
2002 ret_val = e1000_copper_link_igp_setup(hw);
2005 } else if (hw->phy_type == e1000_phy_m88) {
2006 ret_val = e1000_copper_link_mgp_setup(hw);
2009 } else if (hw->phy_type == e1000_phy_gg82563) {
2010 ret_val = e1000_copper_link_ggp_setup(hw);
2016 /* Setup autoneg and flow control advertisement
2017 * and perform autonegotiation */
2018 ret_val = e1000_copper_link_autoneg(hw);
2022 /* PHY will be set to 10H, 10F, 100H,or 100F
2023 * depending on value from forced_speed_duplex. */
2024 DEBUGOUT("Forcing speed and duplex\n");
2025 ret_val = e1000_phy_force_speed_duplex(hw);
2027 DEBUGOUT("Error Forcing Speed and Duplex\n");
2032 /* Check link status. Wait up to 100 microseconds for link to become
2035 for (i = 0; i < 10; i++) {
2036 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2039 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2043 if (phy_data & MII_SR_LINK_STATUS) {
2044 /* Config the MAC and PHY after link is up */
2045 ret_val = e1000_copper_link_postconfig(hw);
2049 DEBUGOUT("Valid link established!!!\n");
2050 return E1000_SUCCESS;
2055 DEBUGOUT("Unable to establish link!!!\n");
2056 return E1000_SUCCESS;
2059 /******************************************************************************
2060 * Configure the MAC-to-PHY interface for 10/100Mbps
2062 * hw - Struct containing variables accessed by shared code
2063 ******************************************************************************/
2065 e1000_configure_kmrn_for_10_100(struct e1000_hw *hw, uint16_t duplex)
2067 int32_t ret_val = E1000_SUCCESS;
2071 DEBUGFUNC("e1000_configure_kmrn_for_10_100");
2073 reg_data = E1000_KUMCTRLSTA_HD_CTRL_10_100_DEFAULT;
2074 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_HD_CTRL,
2079 /* Configure Transmit Inter-Packet Gap */
2080 tipg = E1000_READ_REG(hw, TIPG);
2081 tipg &= ~E1000_TIPG_IPGT_MASK;
2082 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_10_100;
2083 E1000_WRITE_REG(hw, TIPG, tipg);
2085 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, ®_data);
2090 if (duplex == HALF_DUPLEX)
2091 reg_data |= GG82563_KMCR_PASS_FALSE_CARRIER;
2093 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
2095 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
2101 e1000_configure_kmrn_for_1000(struct e1000_hw *hw)
2103 int32_t ret_val = E1000_SUCCESS;
2107 DEBUGFUNC("e1000_configure_kmrn_for_1000");
2109 reg_data = E1000_KUMCTRLSTA_HD_CTRL_1000_DEFAULT;
2110 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_HD_CTRL,
2115 /* Configure Transmit Inter-Packet Gap */
2116 tipg = E1000_READ_REG(hw, TIPG);
2117 tipg &= ~E1000_TIPG_IPGT_MASK;
2118 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
2119 E1000_WRITE_REG(hw, TIPG, tipg);
2121 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, ®_data);
2126 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
2127 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
2132 /******************************************************************************
2133 * Configures PHY autoneg and flow control advertisement settings
2135 * hw - Struct containing variables accessed by shared code
2136 ******************************************************************************/
2138 e1000_phy_setup_autoneg(struct e1000_hw *hw)
2141 uint16_t mii_autoneg_adv_reg;
2142 uint16_t mii_1000t_ctrl_reg;
2144 DEBUGFUNC("e1000_phy_setup_autoneg");
2146 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
2147 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
2151 if (hw->phy_type != e1000_phy_ife) {
2152 /* Read the MII 1000Base-T Control Register (Address 9). */
2153 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
2157 mii_1000t_ctrl_reg=0;
2159 /* Need to parse both autoneg_advertised and fc and set up
2160 * the appropriate PHY registers. First we will parse for
2161 * autoneg_advertised software override. Since we can advertise
2162 * a plethora of combinations, we need to check each bit
2166 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
2167 * Advertisement Register (Address 4) and the 1000 mb speed bits in
2168 * the 1000Base-T Control Register (Address 9).
2170 mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
2171 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
2173 DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised);
2175 /* Do we want to advertise 10 Mb Half Duplex? */
2176 if (hw->autoneg_advertised & ADVERTISE_10_HALF) {
2177 DEBUGOUT("Advertise 10mb Half duplex\n");
2178 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
2181 /* Do we want to advertise 10 Mb Full Duplex? */
2182 if (hw->autoneg_advertised & ADVERTISE_10_FULL) {
2183 DEBUGOUT("Advertise 10mb Full duplex\n");
2184 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
2187 /* Do we want to advertise 100 Mb Half Duplex? */
2188 if (hw->autoneg_advertised & ADVERTISE_100_HALF) {
2189 DEBUGOUT("Advertise 100mb Half duplex\n");
2190 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
2193 /* Do we want to advertise 100 Mb Full Duplex? */
2194 if (hw->autoneg_advertised & ADVERTISE_100_FULL) {
2195 DEBUGOUT("Advertise 100mb Full duplex\n");
2196 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
2199 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
2200 if (hw->autoneg_advertised & ADVERTISE_1000_HALF) {
2201 DEBUGOUT("Advertise 1000mb Half duplex requested, request denied!\n");
2204 /* Do we want to advertise 1000 Mb Full Duplex? */
2205 if (hw->autoneg_advertised & ADVERTISE_1000_FULL) {
2206 DEBUGOUT("Advertise 1000mb Full duplex\n");
2207 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
2208 if (hw->phy_type == e1000_phy_ife) {
2209 DEBUGOUT("e1000_phy_ife is a 10/100 PHY. Gigabit speed is not supported.\n");
2213 /* Check for a software override of the flow control settings, and
2214 * setup the PHY advertisement registers accordingly. If
2215 * auto-negotiation is enabled, then software will have to set the
2216 * "PAUSE" bits to the correct value in the Auto-Negotiation
2217 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
2219 * The possible values of the "fc" parameter are:
2220 * 0: Flow control is completely disabled
2221 * 1: Rx flow control is enabled (we can receive pause frames
2222 * but not send pause frames).
2223 * 2: Tx flow control is enabled (we can send pause frames
2224 * but we do not support receiving pause frames).
2225 * 3: Both Rx and TX flow control (symmetric) are enabled.
2226 * other: No software override. The flow control configuration
2227 * in the EEPROM is used.
2230 case E1000_FC_NONE: /* 0 */
2231 /* Flow control (RX & TX) is completely disabled by a
2232 * software over-ride.
2234 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2236 case E1000_FC_RX_PAUSE: /* 1 */
2237 /* RX Flow control is enabled, and TX Flow control is
2238 * disabled, by a software over-ride.
2240 /* Since there really isn't a way to advertise that we are
2241 * capable of RX Pause ONLY, we will advertise that we
2242 * support both symmetric and asymmetric RX PAUSE. Later
2243 * (in e1000_config_fc_after_link_up) we will disable the
2244 *hw's ability to send PAUSE frames.
2246 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2248 case E1000_FC_TX_PAUSE: /* 2 */
2249 /* TX Flow control is enabled, and RX Flow control is
2250 * disabled, by a software over-ride.
2252 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
2253 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
2255 case E1000_FC_FULL: /* 3 */
2256 /* Flow control (both RX and TX) is enabled by a software
2259 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2262 DEBUGOUT("Flow control param set incorrectly\n");
2263 return -E1000_ERR_CONFIG;
2266 ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
2270 DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
2272 if (hw->phy_type != e1000_phy_ife) {
2273 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg);
2278 return E1000_SUCCESS;
2281 /******************************************************************************
2282 * Force PHY speed and duplex settings to hw->forced_speed_duplex
2284 * hw - Struct containing variables accessed by shared code
2285 ******************************************************************************/
2287 e1000_phy_force_speed_duplex(struct e1000_hw *hw)
2291 uint16_t mii_ctrl_reg;
2292 uint16_t mii_status_reg;
2296 DEBUGFUNC("e1000_phy_force_speed_duplex");
2298 /* Turn off Flow control if we are forcing speed and duplex. */
2299 hw->fc = E1000_FC_NONE;
2301 DEBUGOUT1("hw->fc = %d\n", hw->fc);
2303 /* Read the Device Control Register. */
2304 ctrl = E1000_READ_REG(hw, CTRL);
2306 /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */
2307 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2308 ctrl &= ~(DEVICE_SPEED_MASK);
2310 /* Clear the Auto Speed Detect Enable bit. */
2311 ctrl &= ~E1000_CTRL_ASDE;
2313 /* Read the MII Control Register. */
2314 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg);
2318 /* We need to disable autoneg in order to force link and duplex. */
2320 mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN;
2322 /* Are we forcing Full or Half Duplex? */
2323 if (hw->forced_speed_duplex == e1000_100_full ||
2324 hw->forced_speed_duplex == e1000_10_full) {
2325 /* We want to force full duplex so we SET the full duplex bits in the
2326 * Device and MII Control Registers.
2328 ctrl |= E1000_CTRL_FD;
2329 mii_ctrl_reg |= MII_CR_FULL_DUPLEX;
2330 DEBUGOUT("Full Duplex\n");
2332 /* We want to force half duplex so we CLEAR the full duplex bits in
2333 * the Device and MII Control Registers.
2335 ctrl &= ~E1000_CTRL_FD;
2336 mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX;
2337 DEBUGOUT("Half Duplex\n");
2340 /* Are we forcing 100Mbps??? */
2341 if (hw->forced_speed_duplex == e1000_100_full ||
2342 hw->forced_speed_duplex == e1000_100_half) {
2343 /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */
2344 ctrl |= E1000_CTRL_SPD_100;
2345 mii_ctrl_reg |= MII_CR_SPEED_100;
2346 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
2347 DEBUGOUT("Forcing 100mb ");
2349 /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */
2350 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
2351 mii_ctrl_reg |= MII_CR_SPEED_10;
2352 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
2353 DEBUGOUT("Forcing 10mb ");
2356 e1000_config_collision_dist(hw);
2358 /* Write the configured values back to the Device Control Reg. */
2359 E1000_WRITE_REG(hw, CTRL, ctrl);
2361 if ((hw->phy_type == e1000_phy_m88) ||
2362 (hw->phy_type == e1000_phy_gg82563)) {
2363 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
2367 /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
2368 * forced whenever speed are duplex are forced.
2370 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
2371 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
2375 DEBUGOUT1("M88E1000 PSCR: %x \n", phy_data);
2377 /* Need to reset the PHY or these changes will be ignored */
2378 mii_ctrl_reg |= MII_CR_RESET;
2380 /* Disable MDI-X support for 10/100 */
2381 } else if (hw->phy_type == e1000_phy_ife) {
2382 ret_val = e1000_read_phy_reg(hw, IFE_PHY_MDIX_CONTROL, &phy_data);
2386 phy_data &= ~IFE_PMC_AUTO_MDIX;
2387 phy_data &= ~IFE_PMC_FORCE_MDIX;
2389 ret_val = e1000_write_phy_reg(hw, IFE_PHY_MDIX_CONTROL, phy_data);
2394 /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
2395 * forced whenever speed or duplex are forced.
2397 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
2401 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
2402 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
2404 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
2409 /* Write back the modified PHY MII control register. */
2410 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg);
2416 /* The wait_autoneg_complete flag may be a little misleading here.
2417 * Since we are forcing speed and duplex, Auto-Neg is not enabled.
2418 * But we do want to delay for a period while forcing only so we
2419 * don't generate false No Link messages. So we will wait here
2420 * only if the user has set wait_autoneg_complete to 1, which is
2423 if (hw->wait_autoneg_complete) {
2424 /* We will wait for autoneg to complete. */
2425 DEBUGOUT("Waiting for forced speed/duplex link.\n");
2428 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
2429 for (i = PHY_FORCE_TIME; i > 0; i--) {
2430 /* Read the MII Status Register and wait for Auto-Neg Complete bit
2433 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2437 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2441 if (mii_status_reg & MII_SR_LINK_STATUS) break;
2445 ((hw->phy_type == e1000_phy_m88) ||
2446 (hw->phy_type == e1000_phy_gg82563))) {
2447 /* We didn't get link. Reset the DSP and wait again for link. */
2448 ret_val = e1000_phy_reset_dsp(hw);
2450 DEBUGOUT("Error Resetting PHY DSP\n");
2454 /* This loop will early-out if the link condition has been met. */
2455 for (i = PHY_FORCE_TIME; i > 0; i--) {
2456 if (mii_status_reg & MII_SR_LINK_STATUS) break;
2458 /* Read the MII Status Register and wait for Auto-Neg Complete bit
2461 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2465 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2471 if (hw->phy_type == e1000_phy_m88) {
2472 /* Because we reset the PHY above, we need to re-force TX_CLK in the
2473 * Extended PHY Specific Control Register to 25MHz clock. This value
2474 * defaults back to a 2.5MHz clock when the PHY is reset.
2476 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
2480 phy_data |= M88E1000_EPSCR_TX_CLK_25;
2481 ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
2485 /* In addition, because of the s/w reset above, we need to enable CRS on
2486 * TX. This must be set for both full and half duplex operation.
2488 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
2492 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
2493 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
2497 if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
2498 (!hw->autoneg) && (hw->forced_speed_duplex == e1000_10_full ||
2499 hw->forced_speed_duplex == e1000_10_half)) {
2500 ret_val = e1000_polarity_reversal_workaround(hw);
2504 } else if (hw->phy_type == e1000_phy_gg82563) {
2505 /* The TX_CLK of the Extended PHY Specific Control Register defaults
2506 * to 2.5MHz on a reset. We need to re-force it back to 25MHz, if
2507 * we're not in a forced 10/duplex configuration. */
2508 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, &phy_data);
2512 phy_data &= ~GG82563_MSCR_TX_CLK_MASK;
2513 if ((hw->forced_speed_duplex == e1000_10_full) ||
2514 (hw->forced_speed_duplex == e1000_10_half))
2515 phy_data |= GG82563_MSCR_TX_CLK_10MBPS_2_5MHZ;
2517 phy_data |= GG82563_MSCR_TX_CLK_100MBPS_25MHZ;
2519 /* Also due to the reset, we need to enable CRS on Tx. */
2520 phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
2522 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, phy_data);
2526 return E1000_SUCCESS;
2529 /******************************************************************************
2530 * Sets the collision distance in the Transmit Control register
2532 * hw - Struct containing variables accessed by shared code
2534 * Link should have been established previously. Reads the speed and duplex
2535 * information from the Device Status register.
2536 ******************************************************************************/
2538 e1000_config_collision_dist(struct e1000_hw *hw)
2540 uint32_t tctl, coll_dist;
2542 DEBUGFUNC("e1000_config_collision_dist");
2544 if (hw->mac_type < e1000_82543)
2545 coll_dist = E1000_COLLISION_DISTANCE_82542;
2547 coll_dist = E1000_COLLISION_DISTANCE;
2549 tctl = E1000_READ_REG(hw, TCTL);
2551 tctl &= ~E1000_TCTL_COLD;
2552 tctl |= coll_dist << E1000_COLD_SHIFT;
2554 E1000_WRITE_REG(hw, TCTL, tctl);
2555 E1000_WRITE_FLUSH(hw);
2558 /******************************************************************************
2559 * Sets MAC speed and duplex settings to reflect the those in the PHY
2561 * hw - Struct containing variables accessed by shared code
2562 * mii_reg - data to write to the MII control register
2564 * The contents of the PHY register containing the needed information need to
2566 ******************************************************************************/
2568 e1000_config_mac_to_phy(struct e1000_hw *hw)
2574 DEBUGFUNC("e1000_config_mac_to_phy");
2576 /* 82544 or newer MAC, Auto Speed Detection takes care of
2577 * MAC speed/duplex configuration.*/
2578 if (hw->mac_type >= e1000_82544)
2579 return E1000_SUCCESS;
2581 /* Read the Device Control Register and set the bits to Force Speed
2584 ctrl = E1000_READ_REG(hw, CTRL);
2585 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2586 ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
2588 /* Set up duplex in the Device Control and Transmit Control
2589 * registers depending on negotiated values.
2591 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
2595 if (phy_data & M88E1000_PSSR_DPLX)
2596 ctrl |= E1000_CTRL_FD;
2598 ctrl &= ~E1000_CTRL_FD;
2600 e1000_config_collision_dist(hw);
2602 /* Set up speed in the Device Control register depending on
2603 * negotiated values.
2605 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
2606 ctrl |= E1000_CTRL_SPD_1000;
2607 else if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
2608 ctrl |= E1000_CTRL_SPD_100;
2610 /* Write the configured values back to the Device Control Reg. */
2611 E1000_WRITE_REG(hw, CTRL, ctrl);
2612 return E1000_SUCCESS;
2615 /******************************************************************************
2616 * Forces the MAC's flow control settings.
2618 * hw - Struct containing variables accessed by shared code
2620 * Sets the TFCE and RFCE bits in the device control register to reflect
2621 * the adapter settings. TFCE and RFCE need to be explicitly set by
2622 * software when a Copper PHY is used because autonegotiation is managed
2623 * by the PHY rather than the MAC. Software must also configure these
2624 * bits when link is forced on a fiber connection.
2625 *****************************************************************************/
2627 e1000_force_mac_fc(struct e1000_hw *hw)
2631 DEBUGFUNC("e1000_force_mac_fc");
2633 /* Get the current configuration of the Device Control Register */
2634 ctrl = E1000_READ_REG(hw, CTRL);
2636 /* Because we didn't get link via the internal auto-negotiation
2637 * mechanism (we either forced link or we got link via PHY
2638 * auto-neg), we have to manually enable/disable transmit an
2639 * receive flow control.
2641 * The "Case" statement below enables/disable flow control
2642 * according to the "hw->fc" parameter.
2644 * The possible values of the "fc" parameter are:
2645 * 0: Flow control is completely disabled
2646 * 1: Rx flow control is enabled (we can receive pause
2647 * frames but not send pause frames).
2648 * 2: Tx flow control is enabled (we can send pause frames
2649 * frames but we do not receive pause frames).
2650 * 3: Both Rx and TX flow control (symmetric) is enabled.
2651 * other: No other values should be possible at this point.
2656 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
2658 case E1000_FC_RX_PAUSE:
2659 ctrl &= (~E1000_CTRL_TFCE);
2660 ctrl |= E1000_CTRL_RFCE;
2662 case E1000_FC_TX_PAUSE:
2663 ctrl &= (~E1000_CTRL_RFCE);
2664 ctrl |= E1000_CTRL_TFCE;
2667 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
2670 DEBUGOUT("Flow control param set incorrectly\n");
2671 return -E1000_ERR_CONFIG;
2674 /* Disable TX Flow Control for 82542 (rev 2.0) */
2675 if (hw->mac_type == e1000_82542_rev2_0)
2676 ctrl &= (~E1000_CTRL_TFCE);
2678 E1000_WRITE_REG(hw, CTRL, ctrl);
2679 return E1000_SUCCESS;
2682 /******************************************************************************
2683 * Configures flow control settings after link is established
2685 * hw - Struct containing variables accessed by shared code
2687 * Should be called immediately after a valid link has been established.
2688 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
2689 * and autonegotiation is enabled, the MAC flow control settings will be set
2690 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
2691 * and RFCE bits will be automaticaly set to the negotiated flow control mode.
2692 *****************************************************************************/
2694 e1000_config_fc_after_link_up(struct e1000_hw *hw)
2697 uint16_t mii_status_reg;
2698 uint16_t mii_nway_adv_reg;
2699 uint16_t mii_nway_lp_ability_reg;
2703 DEBUGFUNC("e1000_config_fc_after_link_up");
2705 /* Check for the case where we have fiber media and auto-neg failed
2706 * so we had to force link. In this case, we need to force the
2707 * configuration of the MAC to match the "fc" parameter.
2709 if (((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) ||
2710 ((hw->media_type == e1000_media_type_internal_serdes) &&
2711 (hw->autoneg_failed)) ||
2712 ((hw->media_type == e1000_media_type_copper) && (!hw->autoneg))) {
2713 ret_val = e1000_force_mac_fc(hw);
2715 DEBUGOUT("Error forcing flow control settings\n");
2720 /* Check for the case where we have copper media and auto-neg is
2721 * enabled. In this case, we need to check and see if Auto-Neg
2722 * has completed, and if so, how the PHY and link partner has
2723 * flow control configured.
2725 if ((hw->media_type == e1000_media_type_copper) && hw->autoneg) {
2726 /* Read the MII Status Register and check to see if AutoNeg
2727 * has completed. We read this twice because this reg has
2728 * some "sticky" (latched) bits.
2730 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2733 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2737 if (mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
2738 /* The AutoNeg process has completed, so we now need to
2739 * read both the Auto Negotiation Advertisement Register
2740 * (Address 4) and the Auto_Negotiation Base Page Ability
2741 * Register (Address 5) to determine how flow control was
2744 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV,
2748 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY,
2749 &mii_nway_lp_ability_reg);
2753 /* Two bits in the Auto Negotiation Advertisement Register
2754 * (Address 4) and two bits in the Auto Negotiation Base
2755 * Page Ability Register (Address 5) determine flow control
2756 * for both the PHY and the link partner. The following
2757 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
2758 * 1999, describes these PAUSE resolution bits and how flow
2759 * control is determined based upon these settings.
2760 * NOTE: DC = Don't Care
2762 * LOCAL DEVICE | LINK PARTNER
2763 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
2764 *-------|---------|-------|---------|--------------------
2765 * 0 | 0 | DC | DC | E1000_FC_NONE
2766 * 0 | 1 | 0 | DC | E1000_FC_NONE
2767 * 0 | 1 | 1 | 0 | E1000_FC_NONE
2768 * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
2769 * 1 | 0 | 0 | DC | E1000_FC_NONE
2770 * 1 | DC | 1 | DC | E1000_FC_FULL
2771 * 1 | 1 | 0 | 0 | E1000_FC_NONE
2772 * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
2775 /* Are both PAUSE bits set to 1? If so, this implies
2776 * Symmetric Flow Control is enabled at both ends. The
2777 * ASM_DIR bits are irrelevant per the spec.
2779 * For Symmetric Flow Control:
2781 * LOCAL DEVICE | LINK PARTNER
2782 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2783 *-------|---------|-------|---------|--------------------
2784 * 1 | DC | 1 | DC | E1000_FC_FULL
2787 if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2788 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
2789 /* Now we need to check if the user selected RX ONLY
2790 * of pause frames. In this case, we had to advertise
2791 * FULL flow control because we could not advertise RX
2792 * ONLY. Hence, we must now check to see if we need to
2793 * turn OFF the TRANSMISSION of PAUSE frames.
2795 if (hw->original_fc == E1000_FC_FULL) {
2796 hw->fc = E1000_FC_FULL;
2797 DEBUGOUT("Flow Control = FULL.\n");
2799 hw->fc = E1000_FC_RX_PAUSE;
2800 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
2803 /* For receiving PAUSE frames ONLY.
2805 * LOCAL DEVICE | LINK PARTNER
2806 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2807 *-------|---------|-------|---------|--------------------
2808 * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
2811 else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2812 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2813 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2814 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
2815 hw->fc = E1000_FC_TX_PAUSE;
2816 DEBUGOUT("Flow Control = TX PAUSE frames only.\n");
2818 /* For transmitting PAUSE frames ONLY.
2820 * LOCAL DEVICE | LINK PARTNER
2821 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2822 *-------|---------|-------|---------|--------------------
2823 * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
2826 else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2827 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2828 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2829 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
2830 hw->fc = E1000_FC_RX_PAUSE;
2831 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
2833 /* Per the IEEE spec, at this point flow control should be
2834 * disabled. However, we want to consider that we could
2835 * be connected to a legacy switch that doesn't advertise
2836 * desired flow control, but can be forced on the link
2837 * partner. So if we advertised no flow control, that is
2838 * what we will resolve to. If we advertised some kind of
2839 * receive capability (Rx Pause Only or Full Flow Control)
2840 * and the link partner advertised none, we will configure
2841 * ourselves to enable Rx Flow Control only. We can do
2842 * this safely for two reasons: If the link partner really
2843 * didn't want flow control enabled, and we enable Rx, no
2844 * harm done since we won't be receiving any PAUSE frames
2845 * anyway. If the intent on the link partner was to have
2846 * flow control enabled, then by us enabling RX only, we
2847 * can at least receive pause frames and process them.
2848 * This is a good idea because in most cases, since we are
2849 * predominantly a server NIC, more times than not we will
2850 * be asked to delay transmission of packets than asking
2851 * our link partner to pause transmission of frames.
2853 else if ((hw->original_fc == E1000_FC_NONE ||
2854 hw->original_fc == E1000_FC_TX_PAUSE) ||
2855 hw->fc_strict_ieee) {
2856 hw->fc = E1000_FC_NONE;
2857 DEBUGOUT("Flow Control = NONE.\n");
2859 hw->fc = E1000_FC_RX_PAUSE;
2860 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
2863 /* Now we need to do one last check... If we auto-
2864 * negotiated to HALF DUPLEX, flow control should not be
2865 * enabled per IEEE 802.3 spec.
2867 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
2869 DEBUGOUT("Error getting link speed and duplex\n");
2873 if (duplex == HALF_DUPLEX)
2874 hw->fc = E1000_FC_NONE;
2876 /* Now we call a subroutine to actually force the MAC
2877 * controller to use the correct flow control settings.
2879 ret_val = e1000_force_mac_fc(hw);
2881 DEBUGOUT("Error forcing flow control settings\n");
2885 DEBUGOUT("Copper PHY and Auto Neg has not completed.\n");
2888 return E1000_SUCCESS;
2891 /******************************************************************************
2892 * Checks to see if the link status of the hardware has changed.
2894 * hw - Struct containing variables accessed by shared code
2896 * Called by any function that needs to check the link status of the adapter.
2897 *****************************************************************************/
2899 e1000_check_for_link(struct e1000_hw *hw)
2906 uint32_t signal = 0;
2910 DEBUGFUNC("e1000_check_for_link");
2912 ctrl = E1000_READ_REG(hw, CTRL);
2913 status = E1000_READ_REG(hw, STATUS);
2915 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
2916 * set when the optics detect a signal. On older adapters, it will be
2917 * cleared when there is a signal. This applies to fiber media only.
2919 if ((hw->media_type == e1000_media_type_fiber) ||
2920 (hw->media_type == e1000_media_type_internal_serdes)) {
2921 rxcw = E1000_READ_REG(hw, RXCW);
2923 if (hw->media_type == e1000_media_type_fiber) {
2924 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
2925 if (status & E1000_STATUS_LU)
2926 hw->get_link_status = FALSE;
2930 /* If we have a copper PHY then we only want to go out to the PHY
2931 * registers to see if Auto-Neg has completed and/or if our link
2932 * status has changed. The get_link_status flag will be set if we
2933 * receive a Link Status Change interrupt or we have Rx Sequence
2936 if ((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
2937 /* First we want to see if the MII Status Register reports
2938 * link. If so, then we want to get the current speed/duplex
2940 * Read the register twice since the link bit is sticky.
2942 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2945 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2949 if (phy_data & MII_SR_LINK_STATUS) {
2950 hw->get_link_status = FALSE;
2951 /* Check if there was DownShift, must be checked immediately after
2953 e1000_check_downshift(hw);
2955 /* If we are on 82544 or 82543 silicon and speed/duplex
2956 * are forced to 10H or 10F, then we will implement the polarity
2957 * reversal workaround. We disable interrupts first, and upon
2958 * returning, place the devices interrupt state to its previous
2959 * value except for the link status change interrupt which will
2960 * happen due to the execution of this workaround.
2963 if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
2965 (hw->forced_speed_duplex == e1000_10_full ||
2966 hw->forced_speed_duplex == e1000_10_half)) {
2967 E1000_WRITE_REG(hw, IMC, 0xffffffff);
2968 ret_val = e1000_polarity_reversal_workaround(hw);
2969 icr = E1000_READ_REG(hw, ICR);
2970 E1000_WRITE_REG(hw, ICS, (icr & ~E1000_ICS_LSC));
2971 E1000_WRITE_REG(hw, IMS, IMS_ENABLE_MASK);
2975 /* No link detected */
2976 e1000_config_dsp_after_link_change(hw, FALSE);
2980 /* If we are forcing speed/duplex, then we simply return since
2981 * we have already determined whether we have link or not.
2983 if (!hw->autoneg) return -E1000_ERR_CONFIG;
2985 /* optimize the dsp settings for the igp phy */
2986 e1000_config_dsp_after_link_change(hw, TRUE);
2988 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
2989 * have Si on board that is 82544 or newer, Auto
2990 * Speed Detection takes care of MAC speed/duplex
2991 * configuration. So we only need to configure Collision
2992 * Distance in the MAC. Otherwise, we need to force
2993 * speed/duplex on the MAC to the current PHY speed/duplex
2996 if (hw->mac_type >= e1000_82544)
2997 e1000_config_collision_dist(hw);
2999 ret_val = e1000_config_mac_to_phy(hw);
3001 DEBUGOUT("Error configuring MAC to PHY settings\n");
3006 /* Configure Flow Control now that Auto-Neg has completed. First, we
3007 * need to restore the desired flow control settings because we may
3008 * have had to re-autoneg with a different link partner.
3010 ret_val = e1000_config_fc_after_link_up(hw);
3012 DEBUGOUT("Error configuring flow control\n");
3016 /* At this point we know that we are on copper and we have
3017 * auto-negotiated link. These are conditions for checking the link
3018 * partner capability register. We use the link speed to determine if
3019 * TBI compatibility needs to be turned on or off. If the link is not
3020 * at gigabit speed, then TBI compatibility is not needed. If we are
3021 * at gigabit speed, we turn on TBI compatibility.
3023 if (hw->tbi_compatibility_en) {
3024 uint16_t speed, duplex;
3025 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
3027 DEBUGOUT("Error getting link speed and duplex\n");
3030 if (speed != SPEED_1000) {
3031 /* If link speed is not set to gigabit speed, we do not need
3032 * to enable TBI compatibility.
3034 if (hw->tbi_compatibility_on) {
3035 /* If we previously were in the mode, turn it off. */
3036 rctl = E1000_READ_REG(hw, RCTL);
3037 rctl &= ~E1000_RCTL_SBP;
3038 E1000_WRITE_REG(hw, RCTL, rctl);
3039 hw->tbi_compatibility_on = FALSE;
3042 /* If TBI compatibility is was previously off, turn it on. For
3043 * compatibility with a TBI link partner, we will store bad
3044 * packets. Some frames have an additional byte on the end and
3045 * will look like CRC errors to to the hardware.
3047 if (!hw->tbi_compatibility_on) {
3048 hw->tbi_compatibility_on = TRUE;
3049 rctl = E1000_READ_REG(hw, RCTL);
3050 rctl |= E1000_RCTL_SBP;
3051 E1000_WRITE_REG(hw, RCTL, rctl);
3056 /* If we don't have link (auto-negotiation failed or link partner cannot
3057 * auto-negotiate), the cable is plugged in (we have signal), and our
3058 * link partner is not trying to auto-negotiate with us (we are receiving
3059 * idles or data), we need to force link up. We also need to give
3060 * auto-negotiation time to complete, in case the cable was just plugged
3061 * in. The autoneg_failed flag does this.
3063 else if ((((hw->media_type == e1000_media_type_fiber) &&
3064 ((ctrl & E1000_CTRL_SWDPIN1) == signal)) ||
3065 (hw->media_type == e1000_media_type_internal_serdes)) &&
3066 (!(status & E1000_STATUS_LU)) &&
3067 (!(rxcw & E1000_RXCW_C))) {
3068 if (hw->autoneg_failed == 0) {
3069 hw->autoneg_failed = 1;
3072 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\n");
3074 /* Disable auto-negotiation in the TXCW register */
3075 E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
3077 /* Force link-up and also force full-duplex. */
3078 ctrl = E1000_READ_REG(hw, CTRL);
3079 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
3080 E1000_WRITE_REG(hw, CTRL, ctrl);
3082 /* Configure Flow Control after forcing link up. */
3083 ret_val = e1000_config_fc_after_link_up(hw);
3085 DEBUGOUT("Error configuring flow control\n");
3089 /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
3090 * auto-negotiation in the TXCW register and disable forced link in the
3091 * Device Control register in an attempt to auto-negotiate with our link
3094 else if (((hw->media_type == e1000_media_type_fiber) ||
3095 (hw->media_type == e1000_media_type_internal_serdes)) &&
3096 (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
3097 DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\n");
3098 E1000_WRITE_REG(hw, TXCW, hw->txcw);
3099 E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
3101 hw->serdes_link_down = FALSE;
3103 /* If we force link for non-auto-negotiation switch, check link status
3104 * based on MAC synchronization for internal serdes media type.
3106 else if ((hw->media_type == e1000_media_type_internal_serdes) &&
3107 !(E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
3108 /* SYNCH bit and IV bit are sticky. */
3110 if (E1000_RXCW_SYNCH & E1000_READ_REG(hw, RXCW)) {
3111 if (!(rxcw & E1000_RXCW_IV)) {
3112 hw->serdes_link_down = FALSE;
3113 DEBUGOUT("SERDES: Link is up.\n");
3116 hw->serdes_link_down = TRUE;
3117 DEBUGOUT("SERDES: Link is down.\n");
3120 if ((hw->media_type == e1000_media_type_internal_serdes) &&
3121 (E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
3122 hw->serdes_link_down = !(E1000_STATUS_LU & E1000_READ_REG(hw, STATUS));
3124 return E1000_SUCCESS;
3127 /******************************************************************************
3128 * Detects the current speed and duplex settings of the hardware.
3130 * hw - Struct containing variables accessed by shared code
3131 * speed - Speed of the connection
3132 * duplex - Duplex setting of the connection
3133 *****************************************************************************/
3135 e1000_get_speed_and_duplex(struct e1000_hw *hw,
3143 DEBUGFUNC("e1000_get_speed_and_duplex");
3145 if (hw->mac_type >= e1000_82543) {
3146 status = E1000_READ_REG(hw, STATUS);
3147 if (status & E1000_STATUS_SPEED_1000) {
3148 *speed = SPEED_1000;
3149 DEBUGOUT("1000 Mbs, ");
3150 } else if (status & E1000_STATUS_SPEED_100) {
3152 DEBUGOUT("100 Mbs, ");
3155 DEBUGOUT("10 Mbs, ");
3158 if (status & E1000_STATUS_FD) {
3159 *duplex = FULL_DUPLEX;
3160 DEBUGOUT("Full Duplex\n");
3162 *duplex = HALF_DUPLEX;
3163 DEBUGOUT(" Half Duplex\n");
3166 DEBUGOUT("1000 Mbs, Full Duplex\n");
3167 *speed = SPEED_1000;
3168 *duplex = FULL_DUPLEX;
3171 /* IGP01 PHY may advertise full duplex operation after speed downgrade even
3172 * if it is operating at half duplex. Here we set the duplex settings to
3173 * match the duplex in the link partner's capabilities.
3175 if (hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
3176 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
3180 if (!(phy_data & NWAY_ER_LP_NWAY_CAPS))
3181 *duplex = HALF_DUPLEX;
3183 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data);
3186 if ((*speed == SPEED_100 && !(phy_data & NWAY_LPAR_100TX_FD_CAPS)) ||
3187 (*speed == SPEED_10 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
3188 *duplex = HALF_DUPLEX;
3192 if ((hw->mac_type == e1000_80003es2lan) &&
3193 (hw->media_type == e1000_media_type_copper)) {
3194 if (*speed == SPEED_1000)
3195 ret_val = e1000_configure_kmrn_for_1000(hw);
3197 ret_val = e1000_configure_kmrn_for_10_100(hw, *duplex);
3202 if ((hw->phy_type == e1000_phy_igp_3) && (*speed == SPEED_1000)) {
3203 ret_val = e1000_kumeran_lock_loss_workaround(hw);
3208 return E1000_SUCCESS;
3211 /******************************************************************************
3212 * Blocks until autoneg completes or times out (~4.5 seconds)
3214 * hw - Struct containing variables accessed by shared code
3215 ******************************************************************************/
3217 e1000_wait_autoneg(struct e1000_hw *hw)
3223 DEBUGFUNC("e1000_wait_autoneg");
3224 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
3226 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
3227 for (i = PHY_AUTO_NEG_TIME; i > 0; i--) {
3228 /* Read the MII Status Register and wait for Auto-Neg
3229 * Complete bit to be set.
3231 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3234 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3237 if (phy_data & MII_SR_AUTONEG_COMPLETE) {
3238 return E1000_SUCCESS;
3242 return E1000_SUCCESS;
3245 /******************************************************************************
3246 * Raises the Management Data Clock
3248 * hw - Struct containing variables accessed by shared code
3249 * ctrl - Device control register's current value
3250 ******************************************************************************/
3252 e1000_raise_mdi_clk(struct e1000_hw *hw,
3255 /* Raise the clock input to the Management Data Clock (by setting the MDC
3256 * bit), and then delay 10 microseconds.
3258 E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
3259 E1000_WRITE_FLUSH(hw);
3263 /******************************************************************************
3264 * Lowers the Management Data Clock
3266 * hw - Struct containing variables accessed by shared code
3267 * ctrl - Device control register's current value
3268 ******************************************************************************/
3270 e1000_lower_mdi_clk(struct e1000_hw *hw,
3273 /* Lower the clock input to the Management Data Clock (by clearing the MDC
3274 * bit), and then delay 10 microseconds.
3276 E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
3277 E1000_WRITE_FLUSH(hw);
3281 /******************************************************************************
3282 * Shifts data bits out to the PHY
3284 * hw - Struct containing variables accessed by shared code
3285 * data - Data to send out to the PHY
3286 * count - Number of bits to shift out
3288 * Bits are shifted out in MSB to LSB order.
3289 ******************************************************************************/
3291 e1000_shift_out_mdi_bits(struct e1000_hw *hw,
3298 /* We need to shift "count" number of bits out to the PHY. So, the value
3299 * in the "data" parameter will be shifted out to the PHY one bit at a
3300 * time. In order to do this, "data" must be broken down into bits.
3303 mask <<= (count - 1);
3305 ctrl = E1000_READ_REG(hw, CTRL);
3307 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
3308 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
3311 /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
3312 * then raising and lowering the Management Data Clock. A "0" is
3313 * shifted out to the PHY by setting the MDIO bit to "0" and then
3314 * raising and lowering the clock.
3317 ctrl |= E1000_CTRL_MDIO;
3319 ctrl &= ~E1000_CTRL_MDIO;
3321 E1000_WRITE_REG(hw, CTRL, ctrl);
3322 E1000_WRITE_FLUSH(hw);
3326 e1000_raise_mdi_clk(hw, &ctrl);
3327 e1000_lower_mdi_clk(hw, &ctrl);
3333 /******************************************************************************
3334 * Shifts data bits in from the PHY
3336 * hw - Struct containing variables accessed by shared code
3338 * Bits are shifted in in MSB to LSB order.
3339 ******************************************************************************/
3341 e1000_shift_in_mdi_bits(struct e1000_hw *hw)
3347 /* In order to read a register from the PHY, we need to shift in a total
3348 * of 18 bits from the PHY. The first two bit (turnaround) times are used
3349 * to avoid contention on the MDIO pin when a read operation is performed.
3350 * These two bits are ignored by us and thrown away. Bits are "shifted in"
3351 * by raising the input to the Management Data Clock (setting the MDC bit),
3352 * and then reading the value of the MDIO bit.
3354 ctrl = E1000_READ_REG(hw, CTRL);
3356 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
3357 ctrl &= ~E1000_CTRL_MDIO_DIR;
3358 ctrl &= ~E1000_CTRL_MDIO;
3360 E1000_WRITE_REG(hw, CTRL, ctrl);
3361 E1000_WRITE_FLUSH(hw);
3363 /* Raise and Lower the clock before reading in the data. This accounts for
3364 * the turnaround bits. The first clock occurred when we clocked out the
3365 * last bit of the Register Address.
3367 e1000_raise_mdi_clk(hw, &ctrl);
3368 e1000_lower_mdi_clk(hw, &ctrl);
3370 for (data = 0, i = 0; i < 16; i++) {
3372 e1000_raise_mdi_clk(hw, &ctrl);
3373 ctrl = E1000_READ_REG(hw, CTRL);
3374 /* Check to see if we shifted in a "1". */
3375 if (ctrl & E1000_CTRL_MDIO)
3377 e1000_lower_mdi_clk(hw, &ctrl);
3380 e1000_raise_mdi_clk(hw, &ctrl);
3381 e1000_lower_mdi_clk(hw, &ctrl);
3387 e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask)
3389 uint32_t swfw_sync = 0;
3390 uint32_t swmask = mask;
3391 uint32_t fwmask = mask << 16;
3392 int32_t timeout = 200;
3394 DEBUGFUNC("e1000_swfw_sync_acquire");
3396 if (hw->swfwhw_semaphore_present)
3397 return e1000_get_software_flag(hw);
3399 if (!hw->swfw_sync_present)
3400 return e1000_get_hw_eeprom_semaphore(hw);
3403 if (e1000_get_hw_eeprom_semaphore(hw))
3404 return -E1000_ERR_SWFW_SYNC;
3406 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
3407 if (!(swfw_sync & (fwmask | swmask))) {
3411 /* firmware currently using resource (fwmask) */
3412 /* or other software thread currently using resource (swmask) */
3413 e1000_put_hw_eeprom_semaphore(hw);
3419 DEBUGOUT("Driver can't access resource, SW_FW_SYNC timeout.\n");
3420 return -E1000_ERR_SWFW_SYNC;
3423 swfw_sync |= swmask;
3424 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
3426 e1000_put_hw_eeprom_semaphore(hw);
3427 return E1000_SUCCESS;
3431 e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask)
3434 uint32_t swmask = mask;
3436 DEBUGFUNC("e1000_swfw_sync_release");
3438 if (hw->swfwhw_semaphore_present) {
3439 e1000_release_software_flag(hw);
3443 if (!hw->swfw_sync_present) {
3444 e1000_put_hw_eeprom_semaphore(hw);
3448 /* if (e1000_get_hw_eeprom_semaphore(hw))
3449 * return -E1000_ERR_SWFW_SYNC; */
3450 while (e1000_get_hw_eeprom_semaphore(hw) != E1000_SUCCESS);
3453 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
3454 swfw_sync &= ~swmask;
3455 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
3457 e1000_put_hw_eeprom_semaphore(hw);
3460 /*****************************************************************************
3461 * Reads the value from a PHY register, if the value is on a specific non zero
3462 * page, sets the page first.
3463 * hw - Struct containing variables accessed by shared code
3464 * reg_addr - address of the PHY register to read
3465 ******************************************************************************/
3467 e1000_read_phy_reg(struct e1000_hw *hw,
3474 DEBUGFUNC("e1000_read_phy_reg");
3476 if ((hw->mac_type == e1000_80003es2lan) &&
3477 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3478 swfw = E1000_SWFW_PHY1_SM;
3480 swfw = E1000_SWFW_PHY0_SM;
3482 if (e1000_swfw_sync_acquire(hw, swfw))
3483 return -E1000_ERR_SWFW_SYNC;
3485 if ((hw->phy_type == e1000_phy_igp ||
3486 hw->phy_type == e1000_phy_igp_3 ||
3487 hw->phy_type == e1000_phy_igp_2) &&
3488 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
3489 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
3490 (uint16_t)reg_addr);
3492 e1000_swfw_sync_release(hw, swfw);
3495 } else if (hw->phy_type == e1000_phy_gg82563) {
3496 if (((reg_addr & MAX_PHY_REG_ADDRESS) > MAX_PHY_MULTI_PAGE_REG) ||
3497 (hw->mac_type == e1000_80003es2lan)) {
3498 /* Select Configuration Page */
3499 if ((reg_addr & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) {
3500 ret_val = e1000_write_phy_reg_ex(hw, GG82563_PHY_PAGE_SELECT,
3501 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3503 /* Use Alternative Page Select register to access
3504 * registers 30 and 31
3506 ret_val = e1000_write_phy_reg_ex(hw,
3507 GG82563_PHY_PAGE_SELECT_ALT,
3508 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3512 e1000_swfw_sync_release(hw, swfw);
3518 ret_val = e1000_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
3521 e1000_swfw_sync_release(hw, swfw);
3526 e1000_read_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr,
3531 const uint32_t phy_addr = 1;
3533 DEBUGFUNC("e1000_read_phy_reg_ex");
3535 if (reg_addr > MAX_PHY_REG_ADDRESS) {
3536 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
3537 return -E1000_ERR_PARAM;
3540 if (hw->mac_type > e1000_82543) {
3541 /* Set up Op-code, Phy Address, and register address in the MDI
3542 * Control register. The MAC will take care of interfacing with the
3543 * PHY to retrieve the desired data.
3545 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
3546 (phy_addr << E1000_MDIC_PHY_SHIFT) |
3547 (E1000_MDIC_OP_READ));
3549 E1000_WRITE_REG(hw, MDIC, mdic);
3551 /* Poll the ready bit to see if the MDI read completed */
3552 for (i = 0; i < 64; i++) {
3554 mdic = E1000_READ_REG(hw, MDIC);
3555 if (mdic & E1000_MDIC_READY) break;
3557 if (!(mdic & E1000_MDIC_READY)) {
3558 DEBUGOUT("MDI Read did not complete\n");
3559 return -E1000_ERR_PHY;
3561 if (mdic & E1000_MDIC_ERROR) {
3562 DEBUGOUT("MDI Error\n");
3563 return -E1000_ERR_PHY;
3565 *phy_data = (uint16_t) mdic;
3567 /* We must first send a preamble through the MDIO pin to signal the
3568 * beginning of an MII instruction. This is done by sending 32
3569 * consecutive "1" bits.
3571 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
3573 /* Now combine the next few fields that are required for a read
3574 * operation. We use this method instead of calling the
3575 * e1000_shift_out_mdi_bits routine five different times. The format of
3576 * a MII read instruction consists of a shift out of 14 bits and is
3577 * defined as follows:
3578 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
3579 * followed by a shift in of 18 bits. This first two bits shifted in
3580 * are TurnAround bits used to avoid contention on the MDIO pin when a
3581 * READ operation is performed. These two bits are thrown away
3582 * followed by a shift in of 16 bits which contains the desired data.
3584 mdic = ((reg_addr) | (phy_addr << 5) |
3585 (PHY_OP_READ << 10) | (PHY_SOF << 12));
3587 e1000_shift_out_mdi_bits(hw, mdic, 14);
3589 /* Now that we've shifted out the read command to the MII, we need to
3590 * "shift in" the 16-bit value (18 total bits) of the requested PHY
3593 *phy_data = e1000_shift_in_mdi_bits(hw);
3595 return E1000_SUCCESS;
3598 /******************************************************************************
3599 * Writes a value to a PHY register
3601 * hw - Struct containing variables accessed by shared code
3602 * reg_addr - address of the PHY register to write
3603 * data - data to write to the PHY
3604 ******************************************************************************/
3606 e1000_write_phy_reg(struct e1000_hw *hw, uint32_t reg_addr,
3612 DEBUGFUNC("e1000_write_phy_reg");
3614 if ((hw->mac_type == e1000_80003es2lan) &&
3615 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3616 swfw = E1000_SWFW_PHY1_SM;
3618 swfw = E1000_SWFW_PHY0_SM;
3620 if (e1000_swfw_sync_acquire(hw, swfw))
3621 return -E1000_ERR_SWFW_SYNC;
3623 if ((hw->phy_type == e1000_phy_igp ||
3624 hw->phy_type == e1000_phy_igp_3 ||
3625 hw->phy_type == e1000_phy_igp_2) &&
3626 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
3627 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
3628 (uint16_t)reg_addr);
3630 e1000_swfw_sync_release(hw, swfw);
3633 } else if (hw->phy_type == e1000_phy_gg82563) {
3634 if (((reg_addr & MAX_PHY_REG_ADDRESS) > MAX_PHY_MULTI_PAGE_REG) ||
3635 (hw->mac_type == e1000_80003es2lan)) {
3636 /* Select Configuration Page */
3637 if ((reg_addr & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) {
3638 ret_val = e1000_write_phy_reg_ex(hw, GG82563_PHY_PAGE_SELECT,
3639 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3641 /* Use Alternative Page Select register to access
3642 * registers 30 and 31
3644 ret_val = e1000_write_phy_reg_ex(hw,
3645 GG82563_PHY_PAGE_SELECT_ALT,
3646 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3650 e1000_swfw_sync_release(hw, swfw);
3656 ret_val = e1000_write_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
3659 e1000_swfw_sync_release(hw, swfw);
3664 e1000_write_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr,
3669 const uint32_t phy_addr = 1;
3671 DEBUGFUNC("e1000_write_phy_reg_ex");
3673 if (reg_addr > MAX_PHY_REG_ADDRESS) {
3674 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
3675 return -E1000_ERR_PARAM;
3678 if (hw->mac_type > e1000_82543) {
3679 /* Set up Op-code, Phy Address, register address, and data intended
3680 * for the PHY register in the MDI Control register. The MAC will take
3681 * care of interfacing with the PHY to send the desired data.
3683 mdic = (((uint32_t) phy_data) |
3684 (reg_addr << E1000_MDIC_REG_SHIFT) |
3685 (phy_addr << E1000_MDIC_PHY_SHIFT) |
3686 (E1000_MDIC_OP_WRITE));
3688 E1000_WRITE_REG(hw, MDIC, mdic);
3690 /* Poll the ready bit to see if the MDI read completed */
3691 for (i = 0; i < 641; i++) {
3693 mdic = E1000_READ_REG(hw, MDIC);
3694 if (mdic & E1000_MDIC_READY) break;
3696 if (!(mdic & E1000_MDIC_READY)) {
3697 DEBUGOUT("MDI Write did not complete\n");
3698 return -E1000_ERR_PHY;
3701 /* We'll need to use the SW defined pins to shift the write command
3702 * out to the PHY. We first send a preamble to the PHY to signal the
3703 * beginning of the MII instruction. This is done by sending 32
3704 * consecutive "1" bits.
3706 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
3708 /* Now combine the remaining required fields that will indicate a
3709 * write operation. We use this method instead of calling the
3710 * e1000_shift_out_mdi_bits routine for each field in the command. The
3711 * format of a MII write instruction is as follows:
3712 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
3714 mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
3715 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
3717 mdic |= (uint32_t) phy_data;
3719 e1000_shift_out_mdi_bits(hw, mdic, 32);
3722 return E1000_SUCCESS;
3726 e1000_read_kmrn_reg(struct e1000_hw *hw,
3732 DEBUGFUNC("e1000_read_kmrn_reg");
3734 if ((hw->mac_type == e1000_80003es2lan) &&
3735 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3736 swfw = E1000_SWFW_PHY1_SM;
3738 swfw = E1000_SWFW_PHY0_SM;
3740 if (e1000_swfw_sync_acquire(hw, swfw))
3741 return -E1000_ERR_SWFW_SYNC;
3743 /* Write register address */
3744 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
3745 E1000_KUMCTRLSTA_OFFSET) |
3746 E1000_KUMCTRLSTA_REN;
3747 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
3750 /* Read the data returned */
3751 reg_val = E1000_READ_REG(hw, KUMCTRLSTA);
3752 *data = (uint16_t)reg_val;
3754 e1000_swfw_sync_release(hw, swfw);
3755 return E1000_SUCCESS;
3759 e1000_write_kmrn_reg(struct e1000_hw *hw,
3765 DEBUGFUNC("e1000_write_kmrn_reg");
3767 if ((hw->mac_type == e1000_80003es2lan) &&
3768 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3769 swfw = E1000_SWFW_PHY1_SM;
3771 swfw = E1000_SWFW_PHY0_SM;
3773 if (e1000_swfw_sync_acquire(hw, swfw))
3774 return -E1000_ERR_SWFW_SYNC;
3776 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
3777 E1000_KUMCTRLSTA_OFFSET) | data;
3778 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
3781 e1000_swfw_sync_release(hw, swfw);
3782 return E1000_SUCCESS;
3785 /******************************************************************************
3786 * Returns the PHY to the power-on reset state
3788 * hw - Struct containing variables accessed by shared code
3789 ******************************************************************************/
3791 e1000_phy_hw_reset(struct e1000_hw *hw)
3793 uint32_t ctrl, ctrl_ext;
3798 DEBUGFUNC("e1000_phy_hw_reset");
3800 /* In the case of the phy reset being blocked, it's not an error, we
3801 * simply return success without performing the reset. */
3802 ret_val = e1000_check_phy_reset_block(hw);
3804 return E1000_SUCCESS;
3806 DEBUGOUT("Resetting Phy...\n");
3808 if (hw->mac_type > e1000_82543) {
3809 if ((hw->mac_type == e1000_80003es2lan) &&
3810 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3811 swfw = E1000_SWFW_PHY1_SM;
3813 swfw = E1000_SWFW_PHY0_SM;
3815 if (e1000_swfw_sync_acquire(hw, swfw)) {
3816 DEBUGOUT("Unable to acquire swfw sync\n");
3817 return -E1000_ERR_SWFW_SYNC;
3819 /* Read the device control register and assert the E1000_CTRL_PHY_RST
3820 * bit. Then, take it out of reset.
3821 * For pre-e1000_82571 hardware, we delay for 10ms between the assert
3822 * and deassert. For e1000_82571 hardware and later, we instead delay
3823 * for 50us between and 10ms after the deassertion.
3825 ctrl = E1000_READ_REG(hw, CTRL);
3826 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST);
3827 E1000_WRITE_FLUSH(hw);
3829 if (hw->mac_type < e1000_82571)
3834 E1000_WRITE_REG(hw, CTRL, ctrl);
3835 E1000_WRITE_FLUSH(hw);
3837 if (hw->mac_type >= e1000_82571)
3840 e1000_swfw_sync_release(hw, swfw);
3842 /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
3843 * bit to put the PHY into reset. Then, take it out of reset.
3845 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
3846 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
3847 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
3848 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
3849 E1000_WRITE_FLUSH(hw);
3851 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
3852 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
3853 E1000_WRITE_FLUSH(hw);
3857 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
3858 /* Configure activity LED after PHY reset */
3859 led_ctrl = E1000_READ_REG(hw, LEDCTL);
3860 led_ctrl &= IGP_ACTIVITY_LED_MASK;
3861 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
3862 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
3865 /* Wait for FW to finish PHY configuration. */
3866 ret_val = e1000_get_phy_cfg_done(hw);
3867 if (ret_val != E1000_SUCCESS)
3869 e1000_release_software_semaphore(hw);
3871 if ((hw->mac_type == e1000_ich8lan) && (hw->phy_type == e1000_phy_igp_3))
3872 ret_val = e1000_init_lcd_from_nvm(hw);
3877 /******************************************************************************
3880 * hw - Struct containing variables accessed by shared code
3882 * Sets bit 15 of the MII Control register
3883 ******************************************************************************/
3885 e1000_phy_reset(struct e1000_hw *hw)
3890 DEBUGFUNC("e1000_phy_reset");
3892 /* In the case of the phy reset being blocked, it's not an error, we
3893 * simply return success without performing the reset. */
3894 ret_val = e1000_check_phy_reset_block(hw);
3896 return E1000_SUCCESS;
3898 switch (hw->phy_type) {
3900 case e1000_phy_igp_2:
3901 case e1000_phy_igp_3:
3903 ret_val = e1000_phy_hw_reset(hw);
3908 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
3912 phy_data |= MII_CR_RESET;
3913 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
3921 if (hw->phy_type == e1000_phy_igp || hw->phy_type == e1000_phy_igp_2)
3922 e1000_phy_init_script(hw);
3924 return E1000_SUCCESS;
3927 /******************************************************************************
3928 * Work-around for 82566 power-down: on D3 entry-
3929 * 1) disable gigabit link
3930 * 2) write VR power-down enable
3932 * if successful continue, else issue LCD reset and repeat
3934 * hw - struct containing variables accessed by shared code
3935 ******************************************************************************/
3937 e1000_phy_powerdown_workaround(struct e1000_hw *hw)
3943 DEBUGFUNC("e1000_phy_powerdown_workaround");
3945 if (hw->phy_type != e1000_phy_igp_3)
3950 reg = E1000_READ_REG(hw, PHY_CTRL);
3951 E1000_WRITE_REG(hw, PHY_CTRL, reg | E1000_PHY_CTRL_GBE_DISABLE |
3952 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
3954 /* Write VR power-down enable - bits 9:8 should be 10b */
3955 e1000_read_phy_reg(hw, IGP3_VR_CTRL, &phy_data);
3956 phy_data |= (1 << 9);
3957 phy_data &= ~(1 << 8);
3958 e1000_write_phy_reg(hw, IGP3_VR_CTRL, phy_data);
3960 /* Read it back and test */
3961 e1000_read_phy_reg(hw, IGP3_VR_CTRL, &phy_data);
3962 if (((phy_data & IGP3_VR_CTRL_MODE_MASK) == IGP3_VR_CTRL_MODE_SHUT) || retry)
3965 /* Issue PHY reset and repeat at most one more time */
3966 reg = E1000_READ_REG(hw, CTRL);
3967 E1000_WRITE_REG(hw, CTRL, reg | E1000_CTRL_PHY_RST);
3975 /******************************************************************************
3976 * Work-around for 82566 Kumeran PCS lock loss:
3977 * On link status change (i.e. PCI reset, speed change) and link is up and
3979 * 0) if workaround is optionally disabled do nothing
3980 * 1) wait 1ms for Kumeran link to come up
3981 * 2) check Kumeran Diagnostic register PCS lock loss bit
3982 * 3) if not set the link is locked (all is good), otherwise...
3984 * 5) repeat up to 10 times
3985 * Note: this is only called for IGP3 copper when speed is 1gb.
3987 * hw - struct containing variables accessed by shared code
3988 ******************************************************************************/
3990 e1000_kumeran_lock_loss_workaround(struct e1000_hw *hw)
3997 if (hw->kmrn_lock_loss_workaround_disabled)
3998 return E1000_SUCCESS;
4000 /* Make sure link is up before proceeding. If not just return.
4001 * Attempting this while link is negotiating fouled up link
4003 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
4004 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
4006 if (phy_data & MII_SR_LINK_STATUS) {
4007 for (cnt = 0; cnt < 10; cnt++) {
4008 /* read once to clear */
4009 ret_val = e1000_read_phy_reg(hw, IGP3_KMRN_DIAG, &phy_data);
4012 /* and again to get new status */
4013 ret_val = e1000_read_phy_reg(hw, IGP3_KMRN_DIAG, &phy_data);
4017 /* check for PCS lock */
4018 if (!(phy_data & IGP3_KMRN_DIAG_PCS_LOCK_LOSS))
4019 return E1000_SUCCESS;
4021 /* Issue PHY reset */
4022 e1000_phy_hw_reset(hw);
4025 /* Disable GigE link negotiation */
4026 reg = E1000_READ_REG(hw, PHY_CTRL);
4027 E1000_WRITE_REG(hw, PHY_CTRL, reg | E1000_PHY_CTRL_GBE_DISABLE |
4028 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
4030 /* unable to acquire PCS lock */
4031 return E1000_ERR_PHY;
4034 return E1000_SUCCESS;
4037 /******************************************************************************
4038 * Probes the expected PHY address for known PHY IDs
4040 * hw - Struct containing variables accessed by shared code
4041 ******************************************************************************/
4043 e1000_detect_gig_phy(struct e1000_hw *hw)
4045 int32_t phy_init_status, ret_val;
4046 uint16_t phy_id_high, phy_id_low;
4047 boolean_t match = FALSE;
4049 DEBUGFUNC("e1000_detect_gig_phy");
4051 if (hw->phy_id != 0)
4052 return E1000_SUCCESS;
4054 /* The 82571 firmware may still be configuring the PHY. In this
4055 * case, we cannot access the PHY until the configuration is done. So
4056 * we explicitly set the PHY values. */
4057 if (hw->mac_type == e1000_82571 ||
4058 hw->mac_type == e1000_82572) {
4059 hw->phy_id = IGP01E1000_I_PHY_ID;
4060 hw->phy_type = e1000_phy_igp_2;
4061 return E1000_SUCCESS;
4064 /* ESB-2 PHY reads require e1000_phy_gg82563 to be set because of a work-
4065 * around that forces PHY page 0 to be set or the reads fail. The rest of
4066 * the code in this routine uses e1000_read_phy_reg to read the PHY ID.
4067 * So for ESB-2 we need to have this set so our reads won't fail. If the
4068 * attached PHY is not a e1000_phy_gg82563, the routines below will figure
4069 * this out as well. */
4070 if (hw->mac_type == e1000_80003es2lan)
4071 hw->phy_type = e1000_phy_gg82563;
4073 /* Read the PHY ID Registers to identify which PHY is onboard. */
4074 ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
4078 hw->phy_id = (uint32_t) (phy_id_high << 16);
4080 ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
4084 hw->phy_id |= (uint32_t) (phy_id_low & PHY_REVISION_MASK);
4085 hw->phy_revision = (uint32_t) phy_id_low & ~PHY_REVISION_MASK;
4087 switch (hw->mac_type) {
4089 if (hw->phy_id == M88E1000_E_PHY_ID) match = TRUE;
4092 if (hw->phy_id == M88E1000_I_PHY_ID) match = TRUE;
4096 case e1000_82545_rev_3:
4098 case e1000_82546_rev_3:
4099 if (hw->phy_id == M88E1011_I_PHY_ID) match = TRUE;
4102 case e1000_82541_rev_2:
4104 case e1000_82547_rev_2:
4105 if (hw->phy_id == IGP01E1000_I_PHY_ID) match = TRUE;
4108 if (hw->phy_id == M88E1111_I_PHY_ID) match = TRUE;
4110 case e1000_80003es2lan:
4111 if (hw->phy_id == GG82563_E_PHY_ID) match = TRUE;
4114 if (hw->phy_id == IGP03E1000_E_PHY_ID) match = TRUE;
4115 if (hw->phy_id == IFE_E_PHY_ID) match = TRUE;
4116 if (hw->phy_id == IFE_PLUS_E_PHY_ID) match = TRUE;
4117 if (hw->phy_id == IFE_C_E_PHY_ID) match = TRUE;
4120 DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type);
4121 return -E1000_ERR_CONFIG;
4123 phy_init_status = e1000_set_phy_type(hw);
4125 if ((match) && (phy_init_status == E1000_SUCCESS)) {
4126 DEBUGOUT1("PHY ID 0x%X detected\n", hw->phy_id);
4127 return E1000_SUCCESS;
4129 DEBUGOUT1("Invalid PHY ID 0x%X\n", hw->phy_id);
4130 return -E1000_ERR_PHY;
4133 /******************************************************************************
4134 * Resets the PHY's DSP
4136 * hw - Struct containing variables accessed by shared code
4137 ******************************************************************************/
4139 e1000_phy_reset_dsp(struct e1000_hw *hw)
4142 DEBUGFUNC("e1000_phy_reset_dsp");
4145 if (hw->phy_type != e1000_phy_gg82563) {
4146 ret_val = e1000_write_phy_reg(hw, 29, 0x001d);
4149 ret_val = e1000_write_phy_reg(hw, 30, 0x00c1);
4151 ret_val = e1000_write_phy_reg(hw, 30, 0x0000);
4153 ret_val = E1000_SUCCESS;
4159 /******************************************************************************
4160 * Get PHY information from various PHY registers for igp PHY only.
4162 * hw - Struct containing variables accessed by shared code
4163 * phy_info - PHY information structure
4164 ******************************************************************************/
4166 e1000_phy_igp_get_info(struct e1000_hw *hw,
4167 struct e1000_phy_info *phy_info)
4170 uint16_t phy_data, min_length, max_length, average;
4171 e1000_rev_polarity polarity;
4173 DEBUGFUNC("e1000_phy_igp_get_info");
4175 /* The downshift status is checked only once, after link is established,
4176 * and it stored in the hw->speed_downgraded parameter. */
4177 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
4179 /* IGP01E1000 does not need to support it. */
4180 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
4182 /* IGP01E1000 always correct polarity reversal */
4183 phy_info->polarity_correction = e1000_polarity_reversal_enabled;
4185 /* Check polarity status */
4186 ret_val = e1000_check_polarity(hw, &polarity);
4190 phy_info->cable_polarity = polarity;
4192 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, &phy_data);
4196 phy_info->mdix_mode = (e1000_auto_x_mode)((phy_data & IGP01E1000_PSSR_MDIX) >>
4197 IGP01E1000_PSSR_MDIX_SHIFT);
4199 if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
4200 IGP01E1000_PSSR_SPEED_1000MBPS) {
4201 /* Local/Remote Receiver Information are only valid at 1000 Mbps */
4202 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
4206 phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
4207 SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
4208 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
4209 phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
4210 SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
4211 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
4213 /* Get cable length */
4214 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
4218 /* Translate to old method */
4219 average = (max_length + min_length) / 2;
4221 if (average <= e1000_igp_cable_length_50)
4222 phy_info->cable_length = e1000_cable_length_50;
4223 else if (average <= e1000_igp_cable_length_80)
4224 phy_info->cable_length = e1000_cable_length_50_80;
4225 else if (average <= e1000_igp_cable_length_110)
4226 phy_info->cable_length = e1000_cable_length_80_110;
4227 else if (average <= e1000_igp_cable_length_140)
4228 phy_info->cable_length = e1000_cable_length_110_140;
4230 phy_info->cable_length = e1000_cable_length_140;
4233 return E1000_SUCCESS;
4236 /******************************************************************************
4237 * Get PHY information from various PHY registers for ife PHY only.
4239 * hw - Struct containing variables accessed by shared code
4240 * phy_info - PHY information structure
4241 ******************************************************************************/
4243 e1000_phy_ife_get_info(struct e1000_hw *hw,
4244 struct e1000_phy_info *phy_info)
4248 e1000_rev_polarity polarity;
4250 DEBUGFUNC("e1000_phy_ife_get_info");
4252 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
4253 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
4255 ret_val = e1000_read_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL, &phy_data);
4258 phy_info->polarity_correction =
4259 ((phy_data & IFE_PSC_AUTO_POLARITY_DISABLE) >>
4260 IFE_PSC_AUTO_POLARITY_DISABLE_SHIFT) ?
4261 e1000_polarity_reversal_disabled : e1000_polarity_reversal_enabled;
4263 if (phy_info->polarity_correction == e1000_polarity_reversal_enabled) {
4264 ret_val = e1000_check_polarity(hw, &polarity);
4268 /* Polarity is forced. */
4269 polarity = ((phy_data & IFE_PSC_FORCE_POLARITY) >>
4270 IFE_PSC_FORCE_POLARITY_SHIFT) ?
4271 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
4273 phy_info->cable_polarity = polarity;
4275 ret_val = e1000_read_phy_reg(hw, IFE_PHY_MDIX_CONTROL, &phy_data);
4279 phy_info->mdix_mode = (e1000_auto_x_mode)
4280 ((phy_data & (IFE_PMC_AUTO_MDIX | IFE_PMC_FORCE_MDIX)) >>
4281 IFE_PMC_MDIX_MODE_SHIFT);
4283 return E1000_SUCCESS;
4286 /******************************************************************************
4287 * Get PHY information from various PHY registers fot m88 PHY only.
4289 * hw - Struct containing variables accessed by shared code
4290 * phy_info - PHY information structure
4291 ******************************************************************************/
4293 e1000_phy_m88_get_info(struct e1000_hw *hw,
4294 struct e1000_phy_info *phy_info)
4298 e1000_rev_polarity polarity;
4300 DEBUGFUNC("e1000_phy_m88_get_info");
4302 /* The downshift status is checked only once, after link is established,
4303 * and it stored in the hw->speed_downgraded parameter. */
4304 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
4306 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
4310 phy_info->extended_10bt_distance =
4311 ((phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >>
4312 M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT) ?
4313 e1000_10bt_ext_dist_enable_lower : e1000_10bt_ext_dist_enable_normal;
4315 phy_info->polarity_correction =
4316 ((phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >>
4317 M88E1000_PSCR_POLARITY_REVERSAL_SHIFT) ?
4318 e1000_polarity_reversal_disabled : e1000_polarity_reversal_enabled;
4320 /* Check polarity status */
4321 ret_val = e1000_check_polarity(hw, &polarity);
4324 phy_info->cable_polarity = polarity;
4326 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
4330 phy_info->mdix_mode = (e1000_auto_x_mode)((phy_data & M88E1000_PSSR_MDIX) >>
4331 M88E1000_PSSR_MDIX_SHIFT);
4333 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
4334 /* Cable Length Estimation and Local/Remote Receiver Information
4335 * are only valid at 1000 Mbps.
4337 if (hw->phy_type != e1000_phy_gg82563) {
4338 phy_info->cable_length = (e1000_cable_length)((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
4339 M88E1000_PSSR_CABLE_LENGTH_SHIFT);
4341 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_DSP_DISTANCE,
4346 phy_info->cable_length = (e1000_cable_length)(phy_data & GG82563_DSPD_CABLE_LENGTH);
4349 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
4353 phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
4354 SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
4355 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
4356 phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
4357 SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
4358 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
4362 return E1000_SUCCESS;
4365 /******************************************************************************
4366 * Get PHY information from various PHY registers
4368 * hw - Struct containing variables accessed by shared code
4369 * phy_info - PHY information structure
4370 ******************************************************************************/
4372 e1000_phy_get_info(struct e1000_hw *hw,
4373 struct e1000_phy_info *phy_info)
4378 DEBUGFUNC("e1000_phy_get_info");
4380 phy_info->cable_length = e1000_cable_length_undefined;
4381 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined;
4382 phy_info->cable_polarity = e1000_rev_polarity_undefined;
4383 phy_info->downshift = e1000_downshift_undefined;
4384 phy_info->polarity_correction = e1000_polarity_reversal_undefined;
4385 phy_info->mdix_mode = e1000_auto_x_mode_undefined;
4386 phy_info->local_rx = e1000_1000t_rx_status_undefined;
4387 phy_info->remote_rx = e1000_1000t_rx_status_undefined;
4389 if (hw->media_type != e1000_media_type_copper) {
4390 DEBUGOUT("PHY info is only valid for copper media\n");
4391 return -E1000_ERR_CONFIG;
4394 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
4398 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
4402 if ((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) {
4403 DEBUGOUT("PHY info is only valid if link is up\n");
4404 return -E1000_ERR_CONFIG;
4407 if (hw->phy_type == e1000_phy_igp ||
4408 hw->phy_type == e1000_phy_igp_3 ||
4409 hw->phy_type == e1000_phy_igp_2)
4410 return e1000_phy_igp_get_info(hw, phy_info);
4411 else if (hw->phy_type == e1000_phy_ife)
4412 return e1000_phy_ife_get_info(hw, phy_info);
4414 return e1000_phy_m88_get_info(hw, phy_info);
4418 e1000_validate_mdi_setting(struct e1000_hw *hw)
4420 DEBUGFUNC("e1000_validate_mdi_settings");
4422 if (!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) {
4423 DEBUGOUT("Invalid MDI setting detected\n");
4425 return -E1000_ERR_CONFIG;
4427 return E1000_SUCCESS;
4431 /******************************************************************************
4432 * Sets up eeprom variables in the hw struct. Must be called after mac_type
4433 * is configured. Additionally, if this is ICH8, the flash controller GbE
4434 * registers must be mapped, or this will crash.
4436 * hw - Struct containing variables accessed by shared code
4437 *****************************************************************************/
4439 e1000_init_eeprom_params(struct e1000_hw *hw)
4441 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4442 uint32_t eecd = E1000_READ_REG(hw, EECD);
4443 int32_t ret_val = E1000_SUCCESS;
4444 uint16_t eeprom_size;
4446 DEBUGFUNC("e1000_init_eeprom_params");
4448 switch (hw->mac_type) {
4449 case e1000_82542_rev2_0:
4450 case e1000_82542_rev2_1:
4453 eeprom->type = e1000_eeprom_microwire;
4454 eeprom->word_size = 64;
4455 eeprom->opcode_bits = 3;
4456 eeprom->address_bits = 6;
4457 eeprom->delay_usec = 50;
4458 eeprom->use_eerd = FALSE;
4459 eeprom->use_eewr = FALSE;
4463 case e1000_82545_rev_3:
4465 case e1000_82546_rev_3:
4466 eeprom->type = e1000_eeprom_microwire;
4467 eeprom->opcode_bits = 3;
4468 eeprom->delay_usec = 50;
4469 if (eecd & E1000_EECD_SIZE) {
4470 eeprom->word_size = 256;
4471 eeprom->address_bits = 8;
4473 eeprom->word_size = 64;
4474 eeprom->address_bits = 6;
4476 eeprom->use_eerd = FALSE;
4477 eeprom->use_eewr = FALSE;
4480 case e1000_82541_rev_2:
4482 case e1000_82547_rev_2:
4483 if (eecd & E1000_EECD_TYPE) {
4484 eeprom->type = e1000_eeprom_spi;
4485 eeprom->opcode_bits = 8;
4486 eeprom->delay_usec = 1;
4487 if (eecd & E1000_EECD_ADDR_BITS) {
4488 eeprom->page_size = 32;
4489 eeprom->address_bits = 16;
4491 eeprom->page_size = 8;
4492 eeprom->address_bits = 8;
4495 eeprom->type = e1000_eeprom_microwire;
4496 eeprom->opcode_bits = 3;
4497 eeprom->delay_usec = 50;
4498 if (eecd & E1000_EECD_ADDR_BITS) {
4499 eeprom->word_size = 256;
4500 eeprom->address_bits = 8;
4502 eeprom->word_size = 64;
4503 eeprom->address_bits = 6;
4506 eeprom->use_eerd = FALSE;
4507 eeprom->use_eewr = FALSE;
4511 eeprom->type = e1000_eeprom_spi;
4512 eeprom->opcode_bits = 8;
4513 eeprom->delay_usec = 1;
4514 if (eecd & E1000_EECD_ADDR_BITS) {
4515 eeprom->page_size = 32;
4516 eeprom->address_bits = 16;
4518 eeprom->page_size = 8;
4519 eeprom->address_bits = 8;
4521 eeprom->use_eerd = FALSE;
4522 eeprom->use_eewr = FALSE;
4525 eeprom->type = e1000_eeprom_spi;
4526 eeprom->opcode_bits = 8;
4527 eeprom->delay_usec = 1;
4528 if (eecd & E1000_EECD_ADDR_BITS) {
4529 eeprom->page_size = 32;
4530 eeprom->address_bits = 16;
4532 eeprom->page_size = 8;
4533 eeprom->address_bits = 8;
4535 eeprom->use_eerd = TRUE;
4536 eeprom->use_eewr = TRUE;
4537 if (e1000_is_onboard_nvm_eeprom(hw) == FALSE) {
4538 eeprom->type = e1000_eeprom_flash;
4539 eeprom->word_size = 2048;
4541 /* Ensure that the Autonomous FLASH update bit is cleared due to
4542 * Flash update issue on parts which use a FLASH for NVM. */
4543 eecd &= ~E1000_EECD_AUPDEN;
4544 E1000_WRITE_REG(hw, EECD, eecd);
4547 case e1000_80003es2lan:
4548 eeprom->type = e1000_eeprom_spi;
4549 eeprom->opcode_bits = 8;
4550 eeprom->delay_usec = 1;
4551 if (eecd & E1000_EECD_ADDR_BITS) {
4552 eeprom->page_size = 32;
4553 eeprom->address_bits = 16;
4555 eeprom->page_size = 8;
4556 eeprom->address_bits = 8;
4558 eeprom->use_eerd = TRUE;
4559 eeprom->use_eewr = FALSE;
4564 uint32_t flash_size = E1000_READ_ICH_FLASH_REG(hw, ICH_FLASH_GFPREG);
4566 eeprom->type = e1000_eeprom_ich8;
4567 eeprom->use_eerd = FALSE;
4568 eeprom->use_eewr = FALSE;
4569 eeprom->word_size = E1000_SHADOW_RAM_WORDS;
4571 /* Zero the shadow RAM structure. But don't load it from NVM
4572 * so as to save time for driver init */
4573 if (hw->eeprom_shadow_ram != NULL) {
4574 for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
4575 hw->eeprom_shadow_ram[i].modified = FALSE;
4576 hw->eeprom_shadow_ram[i].eeprom_word = 0xFFFF;
4580 hw->flash_base_addr = (flash_size & ICH_GFPREG_BASE_MASK) *
4581 ICH_FLASH_SECTOR_SIZE;
4583 hw->flash_bank_size = ((flash_size >> 16) & ICH_GFPREG_BASE_MASK) + 1;
4584 hw->flash_bank_size -= (flash_size & ICH_GFPREG_BASE_MASK);
4586 hw->flash_bank_size *= ICH_FLASH_SECTOR_SIZE;
4588 hw->flash_bank_size /= 2 * sizeof(uint16_t);
4596 if (eeprom->type == e1000_eeprom_spi) {
4597 /* eeprom_size will be an enum [0..8] that maps to eeprom sizes 128B to
4598 * 32KB (incremented by powers of 2).
4600 if (hw->mac_type <= e1000_82547_rev_2) {
4601 /* Set to default value for initial eeprom read. */
4602 eeprom->word_size = 64;
4603 ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size);
4606 eeprom_size = (eeprom_size & EEPROM_SIZE_MASK) >> EEPROM_SIZE_SHIFT;
4607 /* 256B eeprom size was not supported in earlier hardware, so we
4608 * bump eeprom_size up one to ensure that "1" (which maps to 256B)
4609 * is never the result used in the shifting logic below. */
4613 eeprom_size = (uint16_t)((eecd & E1000_EECD_SIZE_EX_MASK) >>
4614 E1000_EECD_SIZE_EX_SHIFT);
4617 eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT);
4622 /******************************************************************************
4623 * Raises the EEPROM's clock input.
4625 * hw - Struct containing variables accessed by shared code
4626 * eecd - EECD's current value
4627 *****************************************************************************/
4629 e1000_raise_ee_clk(struct e1000_hw *hw,
4632 /* Raise the clock input to the EEPROM (by setting the SK bit), and then
4633 * wait <delay> microseconds.
4635 *eecd = *eecd | E1000_EECD_SK;
4636 E1000_WRITE_REG(hw, EECD, *eecd);
4637 E1000_WRITE_FLUSH(hw);
4638 udelay(hw->eeprom.delay_usec);
4641 /******************************************************************************
4642 * Lowers the EEPROM's clock input.
4644 * hw - Struct containing variables accessed by shared code
4645 * eecd - EECD's current value
4646 *****************************************************************************/
4648 e1000_lower_ee_clk(struct e1000_hw *hw,
4651 /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
4652 * wait 50 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 * Shift data bits out to the EEPROM.
4663 * hw - Struct containing variables accessed by shared code
4664 * data - data to send to the EEPROM
4665 * count - number of bits to shift out
4666 *****************************************************************************/
4668 e1000_shift_out_ee_bits(struct e1000_hw *hw,
4672 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4676 /* We need to shift "count" bits out to the EEPROM. So, value in the
4677 * "data" parameter will be shifted out to the EEPROM one bit at a time.
4678 * In order to do this, "data" must be broken down into bits.
4680 mask = 0x01 << (count - 1);
4681 eecd = E1000_READ_REG(hw, EECD);
4682 if (eeprom->type == e1000_eeprom_microwire) {
4683 eecd &= ~E1000_EECD_DO;
4684 } else if (eeprom->type == e1000_eeprom_spi) {
4685 eecd |= E1000_EECD_DO;
4688 /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
4689 * and then raising and then lowering the clock (the SK bit controls
4690 * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
4691 * by setting "DI" to "0" and then raising and then lowering the clock.
4693 eecd &= ~E1000_EECD_DI;
4696 eecd |= E1000_EECD_DI;
4698 E1000_WRITE_REG(hw, EECD, eecd);
4699 E1000_WRITE_FLUSH(hw);
4701 udelay(eeprom->delay_usec);
4703 e1000_raise_ee_clk(hw, &eecd);
4704 e1000_lower_ee_clk(hw, &eecd);
4710 /* We leave the "DI" bit set to "0" when we leave this routine. */
4711 eecd &= ~E1000_EECD_DI;
4712 E1000_WRITE_REG(hw, EECD, eecd);
4715 /******************************************************************************
4716 * Shift data bits in from the EEPROM
4718 * hw - Struct containing variables accessed by shared code
4719 *****************************************************************************/
4721 e1000_shift_in_ee_bits(struct e1000_hw *hw,
4728 /* In order to read a register from the EEPROM, we need to shift 'count'
4729 * bits in from the EEPROM. Bits are "shifted in" by raising the clock
4730 * input to the EEPROM (setting the SK bit), and then reading the value of
4731 * the "DO" bit. During this "shifting in" process the "DI" bit should
4735 eecd = E1000_READ_REG(hw, EECD);
4737 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
4740 for (i = 0; i < count; i++) {
4742 e1000_raise_ee_clk(hw, &eecd);
4744 eecd = E1000_READ_REG(hw, EECD);
4746 eecd &= ~(E1000_EECD_DI);
4747 if (eecd & E1000_EECD_DO)
4750 e1000_lower_ee_clk(hw, &eecd);
4756 /******************************************************************************
4757 * Prepares EEPROM for access
4759 * hw - Struct containing variables accessed by shared code
4761 * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
4762 * function should be called before issuing a command to the EEPROM.
4763 *****************************************************************************/
4765 e1000_acquire_eeprom(struct e1000_hw *hw)
4767 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4770 DEBUGFUNC("e1000_acquire_eeprom");
4772 if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
4773 return -E1000_ERR_SWFW_SYNC;
4774 eecd = E1000_READ_REG(hw, EECD);
4776 if (hw->mac_type != e1000_82573) {
4777 /* Request EEPROM Access */
4778 if (hw->mac_type > e1000_82544) {
4779 eecd |= E1000_EECD_REQ;
4780 E1000_WRITE_REG(hw, EECD, eecd);
4781 eecd = E1000_READ_REG(hw, EECD);
4782 while ((!(eecd & E1000_EECD_GNT)) &&
4783 (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
4786 eecd = E1000_READ_REG(hw, EECD);
4788 if (!(eecd & E1000_EECD_GNT)) {
4789 eecd &= ~E1000_EECD_REQ;
4790 E1000_WRITE_REG(hw, EECD, eecd);
4791 DEBUGOUT("Could not acquire EEPROM grant\n");
4792 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
4793 return -E1000_ERR_EEPROM;
4798 /* Setup EEPROM for Read/Write */
4800 if (eeprom->type == e1000_eeprom_microwire) {
4801 /* Clear SK and DI */
4802 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
4803 E1000_WRITE_REG(hw, EECD, eecd);
4806 eecd |= E1000_EECD_CS;
4807 E1000_WRITE_REG(hw, EECD, eecd);
4808 } else if (eeprom->type == e1000_eeprom_spi) {
4809 /* Clear SK and CS */
4810 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
4811 E1000_WRITE_REG(hw, EECD, eecd);
4815 return E1000_SUCCESS;
4818 /******************************************************************************
4819 * Returns EEPROM to a "standby" state
4821 * hw - Struct containing variables accessed by shared code
4822 *****************************************************************************/
4824 e1000_standby_eeprom(struct e1000_hw *hw)
4826 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4829 eecd = E1000_READ_REG(hw, EECD);
4831 if (eeprom->type == e1000_eeprom_microwire) {
4832 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
4833 E1000_WRITE_REG(hw, EECD, eecd);
4834 E1000_WRITE_FLUSH(hw);
4835 udelay(eeprom->delay_usec);
4838 eecd |= E1000_EECD_SK;
4839 E1000_WRITE_REG(hw, EECD, eecd);
4840 E1000_WRITE_FLUSH(hw);
4841 udelay(eeprom->delay_usec);
4844 eecd |= E1000_EECD_CS;
4845 E1000_WRITE_REG(hw, EECD, eecd);
4846 E1000_WRITE_FLUSH(hw);
4847 udelay(eeprom->delay_usec);
4850 eecd &= ~E1000_EECD_SK;
4851 E1000_WRITE_REG(hw, EECD, eecd);
4852 E1000_WRITE_FLUSH(hw);
4853 udelay(eeprom->delay_usec);
4854 } else if (eeprom->type == e1000_eeprom_spi) {
4855 /* Toggle CS to flush commands */
4856 eecd |= E1000_EECD_CS;
4857 E1000_WRITE_REG(hw, EECD, eecd);
4858 E1000_WRITE_FLUSH(hw);
4859 udelay(eeprom->delay_usec);
4860 eecd &= ~E1000_EECD_CS;
4861 E1000_WRITE_REG(hw, EECD, eecd);
4862 E1000_WRITE_FLUSH(hw);
4863 udelay(eeprom->delay_usec);
4867 /******************************************************************************
4868 * Terminates a command by inverting the EEPROM's chip select pin
4870 * hw - Struct containing variables accessed by shared code
4871 *****************************************************************************/
4873 e1000_release_eeprom(struct e1000_hw *hw)
4877 DEBUGFUNC("e1000_release_eeprom");
4879 eecd = E1000_READ_REG(hw, EECD);
4881 if (hw->eeprom.type == e1000_eeprom_spi) {
4882 eecd |= E1000_EECD_CS; /* Pull CS high */
4883 eecd &= ~E1000_EECD_SK; /* Lower SCK */
4885 E1000_WRITE_REG(hw, EECD, eecd);
4887 udelay(hw->eeprom.delay_usec);
4888 } else if (hw->eeprom.type == e1000_eeprom_microwire) {
4889 /* cleanup eeprom */
4891 /* CS on Microwire is active-high */
4892 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
4894 E1000_WRITE_REG(hw, EECD, eecd);
4896 /* Rising edge of clock */
4897 eecd |= E1000_EECD_SK;
4898 E1000_WRITE_REG(hw, EECD, eecd);
4899 E1000_WRITE_FLUSH(hw);
4900 udelay(hw->eeprom.delay_usec);
4902 /* Falling edge of clock */
4903 eecd &= ~E1000_EECD_SK;
4904 E1000_WRITE_REG(hw, EECD, eecd);
4905 E1000_WRITE_FLUSH(hw);
4906 udelay(hw->eeprom.delay_usec);
4909 /* Stop requesting EEPROM access */
4910 if (hw->mac_type > e1000_82544) {
4911 eecd &= ~E1000_EECD_REQ;
4912 E1000_WRITE_REG(hw, EECD, eecd);
4915 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
4918 /******************************************************************************
4919 * Reads a 16 bit word from the EEPROM.
4921 * hw - Struct containing variables accessed by shared code
4922 *****************************************************************************/
4924 e1000_spi_eeprom_ready(struct e1000_hw *hw)
4926 uint16_t retry_count = 0;
4927 uint8_t spi_stat_reg;
4929 DEBUGFUNC("e1000_spi_eeprom_ready");
4931 /* Read "Status Register" repeatedly until the LSB is cleared. The
4932 * EEPROM will signal that the command has been completed by clearing
4933 * bit 0 of the internal status register. If it's not cleared within
4934 * 5 milliseconds, then error out.
4938 e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
4939 hw->eeprom.opcode_bits);
4940 spi_stat_reg = (uint8_t)e1000_shift_in_ee_bits(hw, 8);
4941 if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
4947 e1000_standby_eeprom(hw);
4948 } while (retry_count < EEPROM_MAX_RETRY_SPI);
4950 /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
4951 * only 0-5mSec on 5V devices)
4953 if (retry_count >= EEPROM_MAX_RETRY_SPI) {
4954 DEBUGOUT("SPI EEPROM Status error\n");
4955 return -E1000_ERR_EEPROM;
4958 return E1000_SUCCESS;
4961 /******************************************************************************
4962 * Reads a 16 bit word from the EEPROM.
4964 * hw - Struct containing variables accessed by shared code
4965 * offset - offset of word in the EEPROM to read
4966 * data - word read from the EEPROM
4967 * words - number of words to read
4968 *****************************************************************************/
4970 e1000_read_eeprom(struct e1000_hw *hw,
4975 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4978 DEBUGFUNC("e1000_read_eeprom");
4980 /* If eeprom is not yet detected, do so now */
4981 if (eeprom->word_size == 0)
4982 e1000_init_eeprom_params(hw);
4984 /* A check for invalid values: offset too large, too many words, and not
4987 if ((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
4989 DEBUGOUT2("\"words\" parameter out of bounds. Words = %d, size = %d\n", offset, eeprom->word_size);
4990 return -E1000_ERR_EEPROM;
4993 /* EEPROM's that don't use EERD to read require us to bit-bang the SPI
4994 * directly. In this case, we need to acquire the EEPROM so that
4995 * FW or other port software does not interrupt.
4997 if (e1000_is_onboard_nvm_eeprom(hw) == TRUE &&
4998 hw->eeprom.use_eerd == FALSE) {
4999 /* Prepare the EEPROM for bit-bang reading */
5000 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
5001 return -E1000_ERR_EEPROM;
5004 /* Eerd register EEPROM access requires no eeprom aquire/release */
5005 if (eeprom->use_eerd == TRUE)
5006 return e1000_read_eeprom_eerd(hw, offset, words, data);
5008 /* ICH EEPROM access is done via the ICH flash controller */
5009 if (eeprom->type == e1000_eeprom_ich8)
5010 return e1000_read_eeprom_ich8(hw, offset, words, data);
5012 /* Set up the SPI or Microwire EEPROM for bit-bang reading. We have
5013 * acquired the EEPROM at this point, so any returns should relase it */
5014 if (eeprom->type == e1000_eeprom_spi) {
5016 uint8_t read_opcode = EEPROM_READ_OPCODE_SPI;
5018 if (e1000_spi_eeprom_ready(hw)) {
5019 e1000_release_eeprom(hw);
5020 return -E1000_ERR_EEPROM;
5023 e1000_standby_eeprom(hw);
5025 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
5026 if ((eeprom->address_bits == 8) && (offset >= 128))
5027 read_opcode |= EEPROM_A8_OPCODE_SPI;
5029 /* Send the READ command (opcode + addr) */
5030 e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
5031 e1000_shift_out_ee_bits(hw, (uint16_t)(offset*2), eeprom->address_bits);
5033 /* Read the data. The address of the eeprom internally increments with
5034 * each byte (spi) being read, saving on the overhead of eeprom setup
5035 * and tear-down. The address counter will roll over if reading beyond
5036 * the size of the eeprom, thus allowing the entire memory to be read
5037 * starting from any offset. */
5038 for (i = 0; i < words; i++) {
5039 word_in = e1000_shift_in_ee_bits(hw, 16);
5040 data[i] = (word_in >> 8) | (word_in << 8);
5042 } else if (eeprom->type == e1000_eeprom_microwire) {
5043 for (i = 0; i < words; i++) {
5044 /* Send the READ command (opcode + addr) */
5045 e1000_shift_out_ee_bits(hw, EEPROM_READ_OPCODE_MICROWIRE,
5046 eeprom->opcode_bits);
5047 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + i),
5048 eeprom->address_bits);
5050 /* Read the data. For microwire, each word requires the overhead
5051 * of eeprom setup and tear-down. */
5052 data[i] = e1000_shift_in_ee_bits(hw, 16);
5053 e1000_standby_eeprom(hw);
5057 /* End this read operation */
5058 e1000_release_eeprom(hw);
5060 return E1000_SUCCESS;
5063 /******************************************************************************
5064 * Reads a 16 bit word from the EEPROM using the EERD register.
5066 * hw - Struct containing variables accessed by shared code
5067 * offset - offset of word in the EEPROM to read
5068 * data - word read from the EEPROM
5069 * words - number of words to read
5070 *****************************************************************************/
5072 e1000_read_eeprom_eerd(struct e1000_hw *hw,
5077 uint32_t i, eerd = 0;
5080 for (i = 0; i < words; i++) {
5081 eerd = ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) +
5082 E1000_EEPROM_RW_REG_START;
5084 E1000_WRITE_REG(hw, EERD, eerd);
5085 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_READ);
5090 data[i] = (E1000_READ_REG(hw, EERD) >> E1000_EEPROM_RW_REG_DATA);
5097 /******************************************************************************
5098 * Writes a 16 bit word from the EEPROM using the EEWR register.
5100 * hw - Struct containing variables accessed by shared code
5101 * offset - offset of word in the EEPROM to read
5102 * data - word read from the EEPROM
5103 * words - number of words to read
5104 *****************************************************************************/
5106 e1000_write_eeprom_eewr(struct e1000_hw *hw,
5111 uint32_t register_value = 0;
5115 if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
5116 return -E1000_ERR_SWFW_SYNC;
5118 for (i = 0; i < words; i++) {
5119 register_value = (data[i] << E1000_EEPROM_RW_REG_DATA) |
5120 ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) |
5121 E1000_EEPROM_RW_REG_START;
5123 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
5128 E1000_WRITE_REG(hw, EEWR, register_value);
5130 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
5137 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
5141 /******************************************************************************
5142 * Polls the status bit (bit 1) of the EERD to determine when the read is done.
5144 * hw - Struct containing variables accessed by shared code
5145 *****************************************************************************/
5147 e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd)
5149 uint32_t attempts = 100000;
5150 uint32_t i, reg = 0;
5151 int32_t done = E1000_ERR_EEPROM;
5153 for (i = 0; i < attempts; i++) {
5154 if (eerd == E1000_EEPROM_POLL_READ)
5155 reg = E1000_READ_REG(hw, EERD);
5157 reg = E1000_READ_REG(hw, EEWR);
5159 if (reg & E1000_EEPROM_RW_REG_DONE) {
5160 done = E1000_SUCCESS;
5169 /***************************************************************************
5170 * Description: Determines if the onboard NVM is FLASH or EEPROM.
5172 * hw - Struct containing variables accessed by shared code
5173 ****************************************************************************/
5175 e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw)
5179 DEBUGFUNC("e1000_is_onboard_nvm_eeprom");
5181 if (hw->mac_type == e1000_ich8lan)
5184 if (hw->mac_type == e1000_82573) {
5185 eecd = E1000_READ_REG(hw, EECD);
5187 /* Isolate bits 15 & 16 */
5188 eecd = ((eecd >> 15) & 0x03);
5190 /* If both bits are set, device is Flash type */
5198 /******************************************************************************
5199 * Verifies that the EEPROM has a valid checksum
5201 * hw - Struct containing variables accessed by shared code
5203 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
5204 * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
5206 *****************************************************************************/
5208 e1000_validate_eeprom_checksum(struct e1000_hw *hw)
5210 uint16_t checksum = 0;
5211 uint16_t i, eeprom_data;
5213 DEBUGFUNC("e1000_validate_eeprom_checksum");
5215 if ((hw->mac_type == e1000_82573) &&
5216 (e1000_is_onboard_nvm_eeprom(hw) == FALSE)) {
5217 /* Check bit 4 of word 10h. If it is 0, firmware is done updating
5218 * 10h-12h. Checksum may need to be fixed. */
5219 e1000_read_eeprom(hw, 0x10, 1, &eeprom_data);
5220 if ((eeprom_data & 0x10) == 0) {
5221 /* Read 0x23 and check bit 15. This bit is a 1 when the checksum
5222 * has already been fixed. If the checksum is still wrong and this
5223 * bit is a 1, we need to return bad checksum. Otherwise, we need
5224 * to set this bit to a 1 and update the checksum. */
5225 e1000_read_eeprom(hw, 0x23, 1, &eeprom_data);
5226 if ((eeprom_data & 0x8000) == 0) {
5227 eeprom_data |= 0x8000;
5228 e1000_write_eeprom(hw, 0x23, 1, &eeprom_data);
5229 e1000_update_eeprom_checksum(hw);
5234 if (hw->mac_type == e1000_ich8lan) {
5235 /* Drivers must allocate the shadow ram structure for the
5236 * EEPROM checksum to be updated. Otherwise, this bit as well
5237 * as the checksum must both be set correctly for this
5238 * validation to pass.
5240 e1000_read_eeprom(hw, 0x19, 1, &eeprom_data);
5241 if ((eeprom_data & 0x40) == 0) {
5242 eeprom_data |= 0x40;
5243 e1000_write_eeprom(hw, 0x19, 1, &eeprom_data);
5244 e1000_update_eeprom_checksum(hw);
5248 for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
5249 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
5250 DEBUGOUT("EEPROM Read Error\n");
5251 return -E1000_ERR_EEPROM;
5253 checksum += eeprom_data;
5256 if (checksum == (uint16_t) EEPROM_SUM)
5257 return E1000_SUCCESS;
5259 DEBUGOUT("EEPROM Checksum Invalid\n");
5260 return -E1000_ERR_EEPROM;
5264 /******************************************************************************
5265 * Calculates the EEPROM checksum and writes it to the EEPROM
5267 * hw - Struct containing variables accessed by shared code
5269 * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA.
5270 * Writes the difference to word offset 63 of the EEPROM.
5271 *****************************************************************************/
5273 e1000_update_eeprom_checksum(struct e1000_hw *hw)
5276 uint16_t checksum = 0;
5277 uint16_t i, eeprom_data;
5279 DEBUGFUNC("e1000_update_eeprom_checksum");
5281 for (i = 0; i < EEPROM_CHECKSUM_REG; i++) {
5282 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
5283 DEBUGOUT("EEPROM Read Error\n");
5284 return -E1000_ERR_EEPROM;
5286 checksum += eeprom_data;
5288 checksum = (uint16_t) EEPROM_SUM - checksum;
5289 if (e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) {
5290 DEBUGOUT("EEPROM Write Error\n");
5291 return -E1000_ERR_EEPROM;
5292 } else if (hw->eeprom.type == e1000_eeprom_flash) {
5293 e1000_commit_shadow_ram(hw);
5294 } else if (hw->eeprom.type == e1000_eeprom_ich8) {
5295 e1000_commit_shadow_ram(hw);
5296 /* Reload the EEPROM, or else modifications will not appear
5297 * until after next adapter reset. */
5298 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
5299 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
5300 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
5303 return E1000_SUCCESS;
5306 /******************************************************************************
5307 * Parent function for writing words to the different EEPROM types.
5309 * hw - Struct containing variables accessed by shared code
5310 * offset - offset within the EEPROM to be written to
5311 * words - number of words to write
5312 * data - 16 bit word to be written to the EEPROM
5314 * If e1000_update_eeprom_checksum is not called after this function, the
5315 * EEPROM will most likely contain an invalid checksum.
5316 *****************************************************************************/
5318 e1000_write_eeprom(struct e1000_hw *hw,
5323 struct e1000_eeprom_info *eeprom = &hw->eeprom;
5326 DEBUGFUNC("e1000_write_eeprom");
5328 /* If eeprom is not yet detected, do so now */
5329 if (eeprom->word_size == 0)
5330 e1000_init_eeprom_params(hw);
5332 /* A check for invalid values: offset too large, too many words, and not
5335 if ((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
5337 DEBUGOUT("\"words\" parameter out of bounds\n");
5338 return -E1000_ERR_EEPROM;
5341 /* 82573 writes only through eewr */
5342 if (eeprom->use_eewr == TRUE)
5343 return e1000_write_eeprom_eewr(hw, offset, words, data);
5345 if (eeprom->type == e1000_eeprom_ich8)
5346 return e1000_write_eeprom_ich8(hw, offset, words, data);
5348 /* Prepare the EEPROM for writing */
5349 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
5350 return -E1000_ERR_EEPROM;
5352 if (eeprom->type == e1000_eeprom_microwire) {
5353 status = e1000_write_eeprom_microwire(hw, offset, words, data);
5355 status = e1000_write_eeprom_spi(hw, offset, words, data);
5359 /* Done with writing */
5360 e1000_release_eeprom(hw);
5365 /******************************************************************************
5366 * Writes a 16 bit word to a given offset in an SPI EEPROM.
5368 * hw - Struct containing variables accessed by shared code
5369 * offset - offset within the EEPROM to be written to
5370 * words - number of words to write
5371 * data - pointer to array of 8 bit words to be written to the EEPROM
5373 *****************************************************************************/
5375 e1000_write_eeprom_spi(struct e1000_hw *hw,
5380 struct e1000_eeprom_info *eeprom = &hw->eeprom;
5383 DEBUGFUNC("e1000_write_eeprom_spi");
5385 while (widx < words) {
5386 uint8_t write_opcode = EEPROM_WRITE_OPCODE_SPI;
5388 if (e1000_spi_eeprom_ready(hw)) return -E1000_ERR_EEPROM;
5390 e1000_standby_eeprom(hw);
5392 /* Send the WRITE ENABLE command (8 bit opcode ) */
5393 e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI,
5394 eeprom->opcode_bits);
5396 e1000_standby_eeprom(hw);
5398 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
5399 if ((eeprom->address_bits == 8) && (offset >= 128))
5400 write_opcode |= EEPROM_A8_OPCODE_SPI;
5402 /* Send the Write command (8-bit opcode + addr) */
5403 e1000_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits);
5405 e1000_shift_out_ee_bits(hw, (uint16_t)((offset + widx)*2),
5406 eeprom->address_bits);
5410 /* Loop to allow for up to whole page write (32 bytes) of eeprom */
5411 while (widx < words) {
5412 uint16_t word_out = data[widx];
5413 word_out = (word_out >> 8) | (word_out << 8);
5414 e1000_shift_out_ee_bits(hw, word_out, 16);
5417 /* Some larger eeprom sizes are capable of a 32-byte PAGE WRITE
5418 * operation, while the smaller eeproms are capable of an 8-byte
5419 * PAGE WRITE operation. Break the inner loop to pass new address
5421 if ((((offset + widx)*2) % eeprom->page_size) == 0) {
5422 e1000_standby_eeprom(hw);
5428 return E1000_SUCCESS;
5431 /******************************************************************************
5432 * Writes a 16 bit word to a given offset in a Microwire EEPROM.
5434 * hw - Struct containing variables accessed by shared code
5435 * offset - offset within the EEPROM to be written to
5436 * words - number of words to write
5437 * data - pointer to array of 16 bit words to be written to the EEPROM
5439 *****************************************************************************/
5441 e1000_write_eeprom_microwire(struct e1000_hw *hw,
5446 struct e1000_eeprom_info *eeprom = &hw->eeprom;
5448 uint16_t words_written = 0;
5451 DEBUGFUNC("e1000_write_eeprom_microwire");
5453 /* Send the write enable command to the EEPROM (3-bit opcode plus
5454 * 6/8-bit dummy address beginning with 11). It's less work to include
5455 * the 11 of the dummy address as part of the opcode than it is to shift
5456 * it over the correct number of bits for the address. This puts the
5457 * EEPROM into write/erase mode.
5459 e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE,
5460 (uint16_t)(eeprom->opcode_bits + 2));
5462 e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
5464 /* Prepare the EEPROM */
5465 e1000_standby_eeprom(hw);
5467 while (words_written < words) {
5468 /* Send the Write command (3-bit opcode + addr) */
5469 e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE,
5470 eeprom->opcode_bits);
5472 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + words_written),
5473 eeprom->address_bits);
5476 e1000_shift_out_ee_bits(hw, data[words_written], 16);
5478 /* Toggle the CS line. This in effect tells the EEPROM to execute
5479 * the previous command.
5481 e1000_standby_eeprom(hw);
5483 /* Read DO repeatedly until it is high (equal to '1'). The EEPROM will
5484 * signal that the command has been completed by raising the DO signal.
5485 * If DO does not go high in 10 milliseconds, then error out.
5487 for (i = 0; i < 200; i++) {
5488 eecd = E1000_READ_REG(hw, EECD);
5489 if (eecd & E1000_EECD_DO) break;
5493 DEBUGOUT("EEPROM Write did not complete\n");
5494 return -E1000_ERR_EEPROM;
5497 /* Recover from write */
5498 e1000_standby_eeprom(hw);
5503 /* Send the write disable command to the EEPROM (3-bit opcode plus
5504 * 6/8-bit dummy address beginning with 10). It's less work to include
5505 * the 10 of the dummy address as part of the opcode than it is to shift
5506 * it over the correct number of bits for the address. This takes the
5507 * EEPROM out of write/erase mode.
5509 e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE,
5510 (uint16_t)(eeprom->opcode_bits + 2));
5512 e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
5514 return E1000_SUCCESS;
5517 /******************************************************************************
5518 * Flushes the cached eeprom to NVM. This is done by saving the modified values
5519 * in the eeprom cache and the non modified values in the currently active bank
5522 * hw - Struct containing variables accessed by shared code
5523 * offset - offset of word in the EEPROM to read
5524 * data - word read from the EEPROM
5525 * words - number of words to read
5526 *****************************************************************************/
5528 e1000_commit_shadow_ram(struct e1000_hw *hw)
5530 uint32_t attempts = 100000;
5534 int32_t error = E1000_SUCCESS;
5535 uint32_t old_bank_offset = 0;
5536 uint32_t new_bank_offset = 0;
5537 uint8_t low_byte = 0;
5538 uint8_t high_byte = 0;
5539 boolean_t sector_write_failed = FALSE;
5541 if (hw->mac_type == e1000_82573) {
5542 /* The flop register will be used to determine if flash type is STM */
5543 flop = E1000_READ_REG(hw, FLOP);
5544 for (i=0; i < attempts; i++) {
5545 eecd = E1000_READ_REG(hw, EECD);
5546 if ((eecd & E1000_EECD_FLUPD) == 0) {
5552 if (i == attempts) {
5553 return -E1000_ERR_EEPROM;
5556 /* If STM opcode located in bits 15:8 of flop, reset firmware */
5557 if ((flop & 0xFF00) == E1000_STM_OPCODE) {
5558 E1000_WRITE_REG(hw, HICR, E1000_HICR_FW_RESET);
5561 /* Perform the flash update */
5562 E1000_WRITE_REG(hw, EECD, eecd | E1000_EECD_FLUPD);
5564 for (i=0; i < attempts; i++) {
5565 eecd = E1000_READ_REG(hw, EECD);
5566 if ((eecd & E1000_EECD_FLUPD) == 0) {
5572 if (i == attempts) {
5573 return -E1000_ERR_EEPROM;
5577 if (hw->mac_type == e1000_ich8lan && hw->eeprom_shadow_ram != NULL) {
5578 /* We're writing to the opposite bank so if we're on bank 1,
5579 * write to bank 0 etc. We also need to erase the segment that
5580 * is going to be written */
5581 if (!(E1000_READ_REG(hw, EECD) & E1000_EECD_SEC1VAL)) {
5582 new_bank_offset = hw->flash_bank_size * 2;
5583 old_bank_offset = 0;
5584 e1000_erase_ich8_4k_segment(hw, 1);
5586 old_bank_offset = hw->flash_bank_size * 2;
5587 new_bank_offset = 0;
5588 e1000_erase_ich8_4k_segment(hw, 0);
5591 sector_write_failed = FALSE;
5592 /* Loop for every byte in the shadow RAM,
5593 * which is in units of words. */
5594 for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
5595 /* Determine whether to write the value stored
5596 * in the other NVM bank or a modified value stored
5597 * in the shadow RAM */
5598 if (hw->eeprom_shadow_ram[i].modified == TRUE) {
5599 low_byte = (uint8_t)hw->eeprom_shadow_ram[i].eeprom_word;
5601 error = e1000_verify_write_ich8_byte(hw,
5602 (i << 1) + new_bank_offset, low_byte);
5604 if (error != E1000_SUCCESS)
5605 sector_write_failed = TRUE;
5608 (uint8_t)(hw->eeprom_shadow_ram[i].eeprom_word >> 8);
5612 e1000_read_ich8_byte(hw, (i << 1) + old_bank_offset,
5615 error = e1000_verify_write_ich8_byte(hw,
5616 (i << 1) + new_bank_offset, low_byte);
5618 if (error != E1000_SUCCESS)
5619 sector_write_failed = TRUE;
5621 e1000_read_ich8_byte(hw, (i << 1) + old_bank_offset + 1,
5627 /* If the write of the low byte was successful, go ahread and
5628 * write the high byte while checking to make sure that if it
5629 * is the signature byte, then it is handled properly */
5630 if (sector_write_failed == FALSE) {
5631 /* If the word is 0x13, then make sure the signature bits
5632 * (15:14) are 11b until the commit has completed.
5633 * This will allow us to write 10b which indicates the
5634 * signature is valid. We want to do this after the write
5635 * has completed so that we don't mark the segment valid
5636 * while the write is still in progress */
5637 if (i == E1000_ICH_NVM_SIG_WORD)
5638 high_byte = E1000_ICH_NVM_SIG_MASK | high_byte;
5640 error = e1000_verify_write_ich8_byte(hw,
5641 (i << 1) + new_bank_offset + 1, high_byte);
5642 if (error != E1000_SUCCESS)
5643 sector_write_failed = TRUE;
5646 /* If the write failed then break from the loop and
5647 * return an error */
5652 /* Don't bother writing the segment valid bits if sector
5653 * programming failed. */
5654 if (sector_write_failed == FALSE) {
5655 /* Finally validate the new segment by setting bit 15:14
5656 * to 10b in word 0x13 , this can be done without an
5657 * erase as well since these bits are 11 to start with
5658 * and we need to change bit 14 to 0b */
5659 e1000_read_ich8_byte(hw,
5660 E1000_ICH_NVM_SIG_WORD * 2 + 1 + new_bank_offset,
5663 error = e1000_verify_write_ich8_byte(hw,
5664 E1000_ICH_NVM_SIG_WORD * 2 + 1 + new_bank_offset, high_byte);
5665 /* And invalidate the previously valid segment by setting
5666 * its signature word (0x13) high_byte to 0b. This can be
5667 * done without an erase because flash erase sets all bits
5668 * to 1's. We can write 1's to 0's without an erase */
5669 if (error == E1000_SUCCESS) {
5670 error = e1000_verify_write_ich8_byte(hw,
5671 E1000_ICH_NVM_SIG_WORD * 2 + 1 + old_bank_offset, 0);
5674 /* Clear the now not used entry in the cache */
5675 for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
5676 hw->eeprom_shadow_ram[i].modified = FALSE;
5677 hw->eeprom_shadow_ram[i].eeprom_word = 0xFFFF;
5685 /******************************************************************************
5686 * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
5687 * second function of dual function devices
5689 * hw - Struct containing variables accessed by shared code
5690 *****************************************************************************/
5692 e1000_read_mac_addr(struct e1000_hw * hw)
5695 uint16_t eeprom_data, i;
5697 DEBUGFUNC("e1000_read_mac_addr");
5699 for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
5701 if (e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
5702 DEBUGOUT("EEPROM Read Error\n");
5703 return -E1000_ERR_EEPROM;
5705 hw->perm_mac_addr[i] = (uint8_t) (eeprom_data & 0x00FF);
5706 hw->perm_mac_addr[i+1] = (uint8_t) (eeprom_data >> 8);
5709 switch (hw->mac_type) {
5713 case e1000_82546_rev_3:
5715 case e1000_80003es2lan:
5716 if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
5717 hw->perm_mac_addr[5] ^= 0x01;
5721 for (i = 0; i < NODE_ADDRESS_SIZE; i++)
5722 hw->mac_addr[i] = hw->perm_mac_addr[i];
5723 return E1000_SUCCESS;
5726 /******************************************************************************
5727 * Initializes receive address filters.
5729 * hw - Struct containing variables accessed by shared code
5731 * Places the MAC address in receive address register 0 and clears the rest
5732 * of the receive addresss registers. Clears the multicast table. Assumes
5733 * the receiver is in reset when the routine is called.
5734 *****************************************************************************/
5736 e1000_init_rx_addrs(struct e1000_hw *hw)
5741 DEBUGFUNC("e1000_init_rx_addrs");
5743 /* Setup the receive address. */
5744 DEBUGOUT("Programming MAC Address into RAR[0]\n");
5746 e1000_rar_set(hw, hw->mac_addr, 0);
5748 rar_num = E1000_RAR_ENTRIES;
5750 /* Reserve a spot for the Locally Administered Address to work around
5751 * an 82571 issue in which a reset on one port will reload the MAC on
5752 * the other port. */
5753 if ((hw->mac_type == e1000_82571) && (hw->laa_is_present == TRUE))
5755 if (hw->mac_type == e1000_ich8lan)
5756 rar_num = E1000_RAR_ENTRIES_ICH8LAN;
5758 /* Zero out the other 15 receive addresses. */
5759 DEBUGOUT("Clearing RAR[1-15]\n");
5760 for (i = 1; i < rar_num; i++) {
5761 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
5762 E1000_WRITE_FLUSH(hw);
5763 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
5764 E1000_WRITE_FLUSH(hw);
5768 /******************************************************************************
5769 * Hashes an address to determine its location in the multicast table
5771 * hw - Struct containing variables accessed by shared code
5772 * mc_addr - the multicast address to hash
5773 *****************************************************************************/
5775 e1000_hash_mc_addr(struct e1000_hw *hw,
5778 uint32_t hash_value = 0;
5780 /* The portion of the address that is used for the hash table is
5781 * determined by the mc_filter_type setting.
5783 switch (hw->mc_filter_type) {
5784 /* [0] [1] [2] [3] [4] [5]
5789 if (hw->mac_type == e1000_ich8lan) {
5790 /* [47:38] i.e. 0x158 for above example address */
5791 hash_value = ((mc_addr[4] >> 6) | (((uint16_t) mc_addr[5]) << 2));
5793 /* [47:36] i.e. 0x563 for above example address */
5794 hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4));
5798 if (hw->mac_type == e1000_ich8lan) {
5799 /* [46:37] i.e. 0x2B1 for above example address */
5800 hash_value = ((mc_addr[4] >> 5) | (((uint16_t) mc_addr[5]) << 3));
5802 /* [46:35] i.e. 0xAC6 for above example address */
5803 hash_value = ((mc_addr[4] >> 3) | (((uint16_t) mc_addr[5]) << 5));
5807 if (hw->mac_type == e1000_ich8lan) {
5808 /*[45:36] i.e. 0x163 for above example address */
5809 hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4));
5811 /* [45:34] i.e. 0x5D8 for above example address */
5812 hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6));
5816 if (hw->mac_type == e1000_ich8lan) {
5817 /* [43:34] i.e. 0x18D for above example address */
5818 hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6));
5820 /* [43:32] i.e. 0x634 for above example address */
5821 hash_value = ((mc_addr[4]) | (((uint16_t) mc_addr[5]) << 8));
5826 hash_value &= 0xFFF;
5827 if (hw->mac_type == e1000_ich8lan)
5828 hash_value &= 0x3FF;
5833 /******************************************************************************
5834 * Sets the bit in the multicast table corresponding to the hash value.
5836 * hw - Struct containing variables accessed by shared code
5837 * hash_value - Multicast address hash value
5838 *****************************************************************************/
5840 e1000_mta_set(struct e1000_hw *hw,
5841 uint32_t hash_value)
5843 uint32_t hash_bit, hash_reg;
5847 /* The MTA is a register array of 128 32-bit registers.
5848 * It is treated like an array of 4096 bits. We want to set
5849 * bit BitArray[hash_value]. So we figure out what register
5850 * the bit is in, read it, OR in the new bit, then write
5851 * back the new value. The register is determined by the
5852 * upper 7 bits of the hash value and the bit within that
5853 * register are determined by the lower 5 bits of the value.
5855 hash_reg = (hash_value >> 5) & 0x7F;
5856 if (hw->mac_type == e1000_ich8lan)
5859 hash_bit = hash_value & 0x1F;
5861 mta = E1000_READ_REG_ARRAY(hw, MTA, hash_reg);
5863 mta |= (1 << hash_bit);
5865 /* If we are on an 82544 and we are trying to write an odd offset
5866 * in the MTA, save off the previous entry before writing and
5867 * restore the old value after writing.
5869 if ((hw->mac_type == e1000_82544) && ((hash_reg & 0x1) == 1)) {
5870 temp = E1000_READ_REG_ARRAY(hw, MTA, (hash_reg - 1));
5871 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
5872 E1000_WRITE_FLUSH(hw);
5873 E1000_WRITE_REG_ARRAY(hw, MTA, (hash_reg - 1), temp);
5874 E1000_WRITE_FLUSH(hw);
5876 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
5877 E1000_WRITE_FLUSH(hw);
5881 /******************************************************************************
5882 * Puts an ethernet address into a receive address register.
5884 * hw - Struct containing variables accessed by shared code
5885 * addr - Address to put into receive address register
5886 * index - Receive address register to write
5887 *****************************************************************************/
5889 e1000_rar_set(struct e1000_hw *hw,
5893 uint32_t rar_low, rar_high;
5895 /* HW expects these in little endian so we reverse the byte order
5896 * from network order (big endian) to little endian
5898 rar_low = ((uint32_t) addr[0] |
5899 ((uint32_t) addr[1] << 8) |
5900 ((uint32_t) addr[2] << 16) | ((uint32_t) addr[3] << 24));
5901 rar_high = ((uint32_t) addr[4] | ((uint32_t) addr[5] << 8));
5903 /* Disable Rx and flush all Rx frames before enabling RSS to avoid Rx
5907 * If there are any Rx frames queued up or otherwise present in the HW
5908 * before RSS is enabled, and then we enable RSS, the HW Rx unit will
5909 * hang. To work around this issue, we have to disable receives and
5910 * flush out all Rx frames before we enable RSS. To do so, we modify we
5911 * redirect all Rx traffic to manageability and then reset the HW.
5912 * This flushes away Rx frames, and (since the redirections to
5913 * manageability persists across resets) keeps new ones from coming in
5914 * while we work. Then, we clear the Address Valid AV bit for all MAC
5915 * addresses and undo the re-direction to manageability.
5916 * Now, frames are coming in again, but the MAC won't accept them, so
5917 * far so good. We now proceed to initialize RSS (if necessary) and
5918 * configure the Rx unit. Last, we re-enable the AV bits and continue
5921 switch (hw->mac_type) {
5924 case e1000_80003es2lan:
5925 if (hw->leave_av_bit_off == TRUE)
5928 /* Indicate to hardware the Address is Valid. */
5929 rar_high |= E1000_RAH_AV;
5933 E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
5934 E1000_WRITE_FLUSH(hw);
5935 E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
5936 E1000_WRITE_FLUSH(hw);
5939 /******************************************************************************
5940 * Writes a value to the specified offset in the VLAN filter table.
5942 * hw - Struct containing variables accessed by shared code
5943 * offset - Offset in VLAN filer table to write
5944 * value - Value to write into VLAN filter table
5945 *****************************************************************************/
5947 e1000_write_vfta(struct e1000_hw *hw,
5953 if (hw->mac_type == e1000_ich8lan)
5956 if ((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) {
5957 temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1));
5958 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
5959 E1000_WRITE_FLUSH(hw);
5960 E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp);
5961 E1000_WRITE_FLUSH(hw);
5963 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
5964 E1000_WRITE_FLUSH(hw);
5968 /******************************************************************************
5969 * Clears the VLAN filer table
5971 * hw - Struct containing variables accessed by shared code
5972 *****************************************************************************/
5974 e1000_clear_vfta(struct e1000_hw *hw)
5977 uint32_t vfta_value = 0;
5978 uint32_t vfta_offset = 0;
5979 uint32_t vfta_bit_in_reg = 0;
5981 if (hw->mac_type == e1000_ich8lan)
5984 if (hw->mac_type == e1000_82573) {
5985 if (hw->mng_cookie.vlan_id != 0) {
5986 /* The VFTA is a 4096b bit-field, each identifying a single VLAN
5987 * ID. The following operations determine which 32b entry
5988 * (i.e. offset) into the array we want to set the VLAN ID
5989 * (i.e. bit) of the manageability unit. */
5990 vfta_offset = (hw->mng_cookie.vlan_id >>
5991 E1000_VFTA_ENTRY_SHIFT) &
5992 E1000_VFTA_ENTRY_MASK;
5993 vfta_bit_in_reg = 1 << (hw->mng_cookie.vlan_id &
5994 E1000_VFTA_ENTRY_BIT_SHIFT_MASK);
5997 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
5998 /* If the offset we want to clear is the same offset of the
5999 * manageability VLAN ID, then clear all bits except that of the
6000 * manageability unit */
6001 vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0;
6002 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, vfta_value);
6003 E1000_WRITE_FLUSH(hw);
6008 e1000_id_led_init(struct e1000_hw * hw)
6011 const uint32_t ledctl_mask = 0x000000FF;
6012 const uint32_t ledctl_on = E1000_LEDCTL_MODE_LED_ON;
6013 const uint32_t ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
6014 uint16_t eeprom_data, i, temp;
6015 const uint16_t led_mask = 0x0F;
6017 DEBUGFUNC("e1000_id_led_init");
6019 if (hw->mac_type < e1000_82540) {
6021 return E1000_SUCCESS;
6024 ledctl = E1000_READ_REG(hw, LEDCTL);
6025 hw->ledctl_default = ledctl;
6026 hw->ledctl_mode1 = hw->ledctl_default;
6027 hw->ledctl_mode2 = hw->ledctl_default;
6029 if (e1000_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, 1, &eeprom_data) < 0) {
6030 DEBUGOUT("EEPROM Read Error\n");
6031 return -E1000_ERR_EEPROM;
6034 if ((hw->mac_type == e1000_82573) &&
6035 (eeprom_data == ID_LED_RESERVED_82573))
6036 eeprom_data = ID_LED_DEFAULT_82573;
6037 else if ((eeprom_data == ID_LED_RESERVED_0000) ||
6038 (eeprom_data == ID_LED_RESERVED_FFFF)) {
6039 if (hw->mac_type == e1000_ich8lan)
6040 eeprom_data = ID_LED_DEFAULT_ICH8LAN;
6042 eeprom_data = ID_LED_DEFAULT;
6045 for (i = 0; i < 4; i++) {
6046 temp = (eeprom_data >> (i << 2)) & led_mask;
6048 case ID_LED_ON1_DEF2:
6049 case ID_LED_ON1_ON2:
6050 case ID_LED_ON1_OFF2:
6051 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
6052 hw->ledctl_mode1 |= ledctl_on << (i << 3);
6054 case ID_LED_OFF1_DEF2:
6055 case ID_LED_OFF1_ON2:
6056 case ID_LED_OFF1_OFF2:
6057 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
6058 hw->ledctl_mode1 |= ledctl_off << (i << 3);
6065 case ID_LED_DEF1_ON2:
6066 case ID_LED_ON1_ON2:
6067 case ID_LED_OFF1_ON2:
6068 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
6069 hw->ledctl_mode2 |= ledctl_on << (i << 3);
6071 case ID_LED_DEF1_OFF2:
6072 case ID_LED_ON1_OFF2:
6073 case ID_LED_OFF1_OFF2:
6074 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
6075 hw->ledctl_mode2 |= ledctl_off << (i << 3);
6082 return E1000_SUCCESS;
6085 /******************************************************************************
6086 * Prepares SW controlable LED for use and saves the current state of the LED.
6088 * hw - Struct containing variables accessed by shared code
6089 *****************************************************************************/
6091 e1000_setup_led(struct e1000_hw *hw)
6094 int32_t ret_val = E1000_SUCCESS;
6096 DEBUGFUNC("e1000_setup_led");
6098 switch (hw->mac_type) {
6099 case e1000_82542_rev2_0:
6100 case e1000_82542_rev2_1:
6103 /* No setup necessary */
6107 case e1000_82541_rev_2:
6108 case e1000_82547_rev_2:
6109 /* Turn off PHY Smart Power Down (if enabled) */
6110 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
6111 &hw->phy_spd_default);
6114 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
6115 (uint16_t)(hw->phy_spd_default &
6116 ~IGP01E1000_GMII_SPD));
6121 if (hw->media_type == e1000_media_type_fiber) {
6122 ledctl = E1000_READ_REG(hw, LEDCTL);
6123 /* Save current LEDCTL settings */
6124 hw->ledctl_default = ledctl;
6126 ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
6127 E1000_LEDCTL_LED0_BLINK |
6128 E1000_LEDCTL_LED0_MODE_MASK);
6129 ledctl |= (E1000_LEDCTL_MODE_LED_OFF <<
6130 E1000_LEDCTL_LED0_MODE_SHIFT);
6131 E1000_WRITE_REG(hw, LEDCTL, ledctl);
6132 } else if (hw->media_type == e1000_media_type_copper)
6133 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
6137 return E1000_SUCCESS;
6141 /******************************************************************************
6142 * Used on 82571 and later Si that has LED blink bits.
6143 * Callers must use their own timer and should have already called
6144 * e1000_id_led_init()
6145 * Call e1000_cleanup led() to stop blinking
6147 * hw - Struct containing variables accessed by shared code
6148 *****************************************************************************/
6150 e1000_blink_led_start(struct e1000_hw *hw)
6153 uint32_t ledctl_blink = 0;
6155 DEBUGFUNC("e1000_id_led_blink_on");
6157 if (hw->mac_type < e1000_82571) {
6159 return E1000_SUCCESS;
6161 if (hw->media_type == e1000_media_type_fiber) {
6162 /* always blink LED0 for PCI-E fiber */
6163 ledctl_blink = E1000_LEDCTL_LED0_BLINK |
6164 (E1000_LEDCTL_MODE_LED_ON << E1000_LEDCTL_LED0_MODE_SHIFT);
6166 /* set the blink bit for each LED that's "on" (0x0E) in ledctl_mode2 */
6167 ledctl_blink = hw->ledctl_mode2;
6168 for (i=0; i < 4; i++)
6169 if (((hw->ledctl_mode2 >> (i * 8)) & 0xFF) ==
6170 E1000_LEDCTL_MODE_LED_ON)
6171 ledctl_blink |= (E1000_LEDCTL_LED0_BLINK << (i * 8));
6174 E1000_WRITE_REG(hw, LEDCTL, ledctl_blink);
6176 return E1000_SUCCESS;
6179 /******************************************************************************
6180 * Restores the saved state of the SW controlable LED.
6182 * hw - Struct containing variables accessed by shared code
6183 *****************************************************************************/
6185 e1000_cleanup_led(struct e1000_hw *hw)
6187 int32_t ret_val = E1000_SUCCESS;
6189 DEBUGFUNC("e1000_cleanup_led");
6191 switch (hw->mac_type) {
6192 case e1000_82542_rev2_0:
6193 case e1000_82542_rev2_1:
6196 /* No cleanup necessary */
6200 case e1000_82541_rev_2:
6201 case e1000_82547_rev_2:
6202 /* Turn on PHY Smart Power Down (if previously enabled) */
6203 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
6204 hw->phy_spd_default);
6209 if (hw->phy_type == e1000_phy_ife) {
6210 e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
6213 /* Restore LEDCTL settings */
6214 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_default);
6218 return E1000_SUCCESS;
6221 /******************************************************************************
6222 * Turns on the software controllable LED
6224 * hw - Struct containing variables accessed by shared code
6225 *****************************************************************************/
6227 e1000_led_on(struct e1000_hw *hw)
6229 uint32_t ctrl = E1000_READ_REG(hw, CTRL);
6231 DEBUGFUNC("e1000_led_on");
6233 switch (hw->mac_type) {
6234 case e1000_82542_rev2_0:
6235 case e1000_82542_rev2_1:
6237 /* Set SW Defineable Pin 0 to turn on the LED */
6238 ctrl |= E1000_CTRL_SWDPIN0;
6239 ctrl |= E1000_CTRL_SWDPIO0;
6242 if (hw->media_type == e1000_media_type_fiber) {
6243 /* Set SW Defineable Pin 0 to turn on the LED */
6244 ctrl |= E1000_CTRL_SWDPIN0;
6245 ctrl |= E1000_CTRL_SWDPIO0;
6247 /* Clear SW Defineable Pin 0 to turn on the LED */
6248 ctrl &= ~E1000_CTRL_SWDPIN0;
6249 ctrl |= E1000_CTRL_SWDPIO0;
6253 if (hw->media_type == e1000_media_type_fiber) {
6254 /* Clear SW Defineable Pin 0 to turn on the LED */
6255 ctrl &= ~E1000_CTRL_SWDPIN0;
6256 ctrl |= E1000_CTRL_SWDPIO0;
6257 } else if (hw->phy_type == e1000_phy_ife) {
6258 e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED,
6259 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_ON));
6260 } else if (hw->media_type == e1000_media_type_copper) {
6261 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode2);
6262 return E1000_SUCCESS;
6267 E1000_WRITE_REG(hw, CTRL, ctrl);
6269 return E1000_SUCCESS;
6272 /******************************************************************************
6273 * Turns off the software controllable LED
6275 * hw - Struct containing variables accessed by shared code
6276 *****************************************************************************/
6278 e1000_led_off(struct e1000_hw *hw)
6280 uint32_t ctrl = E1000_READ_REG(hw, CTRL);
6282 DEBUGFUNC("e1000_led_off");
6284 switch (hw->mac_type) {
6285 case e1000_82542_rev2_0:
6286 case e1000_82542_rev2_1:
6288 /* Clear SW Defineable Pin 0 to turn off the LED */
6289 ctrl &= ~E1000_CTRL_SWDPIN0;
6290 ctrl |= E1000_CTRL_SWDPIO0;
6293 if (hw->media_type == e1000_media_type_fiber) {
6294 /* Clear SW Defineable Pin 0 to turn off the LED */
6295 ctrl &= ~E1000_CTRL_SWDPIN0;
6296 ctrl |= E1000_CTRL_SWDPIO0;
6298 /* Set SW Defineable Pin 0 to turn off the LED */
6299 ctrl |= E1000_CTRL_SWDPIN0;
6300 ctrl |= E1000_CTRL_SWDPIO0;
6304 if (hw->media_type == e1000_media_type_fiber) {
6305 /* Set SW Defineable Pin 0 to turn off the LED */
6306 ctrl |= E1000_CTRL_SWDPIN0;
6307 ctrl |= E1000_CTRL_SWDPIO0;
6308 } else if (hw->phy_type == e1000_phy_ife) {
6309 e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED,
6310 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_OFF));
6311 } else if (hw->media_type == e1000_media_type_copper) {
6312 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
6313 return E1000_SUCCESS;
6318 E1000_WRITE_REG(hw, CTRL, ctrl);
6320 return E1000_SUCCESS;
6323 /******************************************************************************
6324 * Clears all hardware statistics counters.
6326 * hw - Struct containing variables accessed by shared code
6327 *****************************************************************************/
6329 e1000_clear_hw_cntrs(struct e1000_hw *hw)
6331 volatile uint32_t temp;
6333 temp = E1000_READ_REG(hw, CRCERRS);
6334 temp = E1000_READ_REG(hw, SYMERRS);
6335 temp = E1000_READ_REG(hw, MPC);
6336 temp = E1000_READ_REG(hw, SCC);
6337 temp = E1000_READ_REG(hw, ECOL);
6338 temp = E1000_READ_REG(hw, MCC);
6339 temp = E1000_READ_REG(hw, LATECOL);
6340 temp = E1000_READ_REG(hw, COLC);
6341 temp = E1000_READ_REG(hw, DC);
6342 temp = E1000_READ_REG(hw, SEC);
6343 temp = E1000_READ_REG(hw, RLEC);
6344 temp = E1000_READ_REG(hw, XONRXC);
6345 temp = E1000_READ_REG(hw, XONTXC);
6346 temp = E1000_READ_REG(hw, XOFFRXC);
6347 temp = E1000_READ_REG(hw, XOFFTXC);
6348 temp = E1000_READ_REG(hw, FCRUC);
6350 if (hw->mac_type != e1000_ich8lan) {
6351 temp = E1000_READ_REG(hw, PRC64);
6352 temp = E1000_READ_REG(hw, PRC127);
6353 temp = E1000_READ_REG(hw, PRC255);
6354 temp = E1000_READ_REG(hw, PRC511);
6355 temp = E1000_READ_REG(hw, PRC1023);
6356 temp = E1000_READ_REG(hw, PRC1522);
6359 temp = E1000_READ_REG(hw, GPRC);
6360 temp = E1000_READ_REG(hw, BPRC);
6361 temp = E1000_READ_REG(hw, MPRC);
6362 temp = E1000_READ_REG(hw, GPTC);
6363 temp = E1000_READ_REG(hw, GORCL);
6364 temp = E1000_READ_REG(hw, GORCH);
6365 temp = E1000_READ_REG(hw, GOTCL);
6366 temp = E1000_READ_REG(hw, GOTCH);
6367 temp = E1000_READ_REG(hw, RNBC);
6368 temp = E1000_READ_REG(hw, RUC);
6369 temp = E1000_READ_REG(hw, RFC);
6370 temp = E1000_READ_REG(hw, ROC);
6371 temp = E1000_READ_REG(hw, RJC);
6372 temp = E1000_READ_REG(hw, TORL);
6373 temp = E1000_READ_REG(hw, TORH);
6374 temp = E1000_READ_REG(hw, TOTL);
6375 temp = E1000_READ_REG(hw, TOTH);
6376 temp = E1000_READ_REG(hw, TPR);
6377 temp = E1000_READ_REG(hw, TPT);
6379 if (hw->mac_type != e1000_ich8lan) {
6380 temp = E1000_READ_REG(hw, PTC64);
6381 temp = E1000_READ_REG(hw, PTC127);
6382 temp = E1000_READ_REG(hw, PTC255);
6383 temp = E1000_READ_REG(hw, PTC511);
6384 temp = E1000_READ_REG(hw, PTC1023);
6385 temp = E1000_READ_REG(hw, PTC1522);
6388 temp = E1000_READ_REG(hw, MPTC);
6389 temp = E1000_READ_REG(hw, BPTC);
6391 if (hw->mac_type < e1000_82543) return;
6393 temp = E1000_READ_REG(hw, ALGNERRC);
6394 temp = E1000_READ_REG(hw, RXERRC);
6395 temp = E1000_READ_REG(hw, TNCRS);
6396 temp = E1000_READ_REG(hw, CEXTERR);
6397 temp = E1000_READ_REG(hw, TSCTC);
6398 temp = E1000_READ_REG(hw, TSCTFC);
6400 if (hw->mac_type <= e1000_82544) return;
6402 temp = E1000_READ_REG(hw, MGTPRC);
6403 temp = E1000_READ_REG(hw, MGTPDC);
6404 temp = E1000_READ_REG(hw, MGTPTC);
6406 if (hw->mac_type <= e1000_82547_rev_2) return;
6408 temp = E1000_READ_REG(hw, IAC);
6409 temp = E1000_READ_REG(hw, ICRXOC);
6411 if (hw->mac_type == e1000_ich8lan) return;
6413 temp = E1000_READ_REG(hw, ICRXPTC);
6414 temp = E1000_READ_REG(hw, ICRXATC);
6415 temp = E1000_READ_REG(hw, ICTXPTC);
6416 temp = E1000_READ_REG(hw, ICTXATC);
6417 temp = E1000_READ_REG(hw, ICTXQEC);
6418 temp = E1000_READ_REG(hw, ICTXQMTC);
6419 temp = E1000_READ_REG(hw, ICRXDMTC);
6422 /******************************************************************************
6423 * Resets Adaptive IFS to its default state.
6425 * hw - Struct containing variables accessed by shared code
6427 * Call this after e1000_init_hw. You may override the IFS defaults by setting
6428 * hw->ifs_params_forced to TRUE. However, you must initialize hw->
6429 * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio
6430 * before calling this function.
6431 *****************************************************************************/
6433 e1000_reset_adaptive(struct e1000_hw *hw)
6435 DEBUGFUNC("e1000_reset_adaptive");
6437 if (hw->adaptive_ifs) {
6438 if (!hw->ifs_params_forced) {
6439 hw->current_ifs_val = 0;
6440 hw->ifs_min_val = IFS_MIN;
6441 hw->ifs_max_val = IFS_MAX;
6442 hw->ifs_step_size = IFS_STEP;
6443 hw->ifs_ratio = IFS_RATIO;
6445 hw->in_ifs_mode = FALSE;
6446 E1000_WRITE_REG(hw, AIT, 0);
6448 DEBUGOUT("Not in Adaptive IFS mode!\n");
6452 /******************************************************************************
6453 * Called during the callback/watchdog routine to update IFS value based on
6454 * the ratio of transmits to collisions.
6456 * hw - Struct containing variables accessed by shared code
6457 * tx_packets - Number of transmits since last callback
6458 * total_collisions - Number of collisions since last callback
6459 *****************************************************************************/
6461 e1000_update_adaptive(struct e1000_hw *hw)
6463 DEBUGFUNC("e1000_update_adaptive");
6465 if (hw->adaptive_ifs) {
6466 if ((hw->collision_delta * hw->ifs_ratio) > hw->tx_packet_delta) {
6467 if (hw->tx_packet_delta > MIN_NUM_XMITS) {
6468 hw->in_ifs_mode = TRUE;
6469 if (hw->current_ifs_val < hw->ifs_max_val) {
6470 if (hw->current_ifs_val == 0)
6471 hw->current_ifs_val = hw->ifs_min_val;
6473 hw->current_ifs_val += hw->ifs_step_size;
6474 E1000_WRITE_REG(hw, AIT, hw->current_ifs_val);
6478 if (hw->in_ifs_mode && (hw->tx_packet_delta <= MIN_NUM_XMITS)) {
6479 hw->current_ifs_val = 0;
6480 hw->in_ifs_mode = FALSE;
6481 E1000_WRITE_REG(hw, AIT, 0);
6485 DEBUGOUT("Not in Adaptive IFS mode!\n");
6489 /******************************************************************************
6490 * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT
6492 * hw - Struct containing variables accessed by shared code
6493 * frame_len - The length of the frame in question
6494 * mac_addr - The Ethernet destination address of the frame in question
6495 *****************************************************************************/
6497 e1000_tbi_adjust_stats(struct e1000_hw *hw,
6498 struct e1000_hw_stats *stats,
6504 /* First adjust the frame length. */
6506 /* We need to adjust the statistics counters, since the hardware
6507 * counters overcount this packet as a CRC error and undercount
6508 * the packet as a good packet
6510 /* This packet should not be counted as a CRC error. */
6512 /* This packet does count as a Good Packet Received. */
6515 /* Adjust the Good Octets received counters */
6516 carry_bit = 0x80000000 & stats->gorcl;
6517 stats->gorcl += frame_len;
6518 /* If the high bit of Gorcl (the low 32 bits of the Good Octets
6519 * Received Count) was one before the addition,
6520 * AND it is zero after, then we lost the carry out,
6521 * need to add one to Gorch (Good Octets Received Count High).
6522 * This could be simplified if all environments supported
6525 if (carry_bit && ((stats->gorcl & 0x80000000) == 0))
6527 /* Is this a broadcast or multicast? Check broadcast first,
6528 * since the test for a multicast frame will test positive on
6529 * a broadcast frame.
6531 if ((mac_addr[0] == (uint8_t) 0xff) && (mac_addr[1] == (uint8_t) 0xff))
6532 /* Broadcast packet */
6534 else if (*mac_addr & 0x01)
6535 /* Multicast packet */
6538 if (frame_len == hw->max_frame_size) {
6539 /* In this case, the hardware has overcounted the number of
6546 /* Adjust the bin counters when the extra byte put the frame in the
6547 * wrong bin. Remember that the frame_len was adjusted above.
6549 if (frame_len == 64) {
6552 } else if (frame_len == 127) {
6555 } else if (frame_len == 255) {
6558 } else if (frame_len == 511) {
6561 } else if (frame_len == 1023) {
6564 } else if (frame_len == 1522) {
6569 /******************************************************************************
6570 * Gets the current PCI bus type, speed, and width of the hardware
6572 * hw - Struct containing variables accessed by shared code
6573 *****************************************************************************/
6575 e1000_get_bus_info(struct e1000_hw *hw)
6578 uint16_t pci_ex_link_status;
6581 switch (hw->mac_type) {
6582 case e1000_82542_rev2_0:
6583 case e1000_82542_rev2_1:
6584 hw->bus_type = e1000_bus_type_pci;
6585 hw->bus_speed = e1000_bus_speed_unknown;
6586 hw->bus_width = e1000_bus_width_unknown;
6591 case e1000_80003es2lan:
6592 hw->bus_type = e1000_bus_type_pci_express;
6593 hw->bus_speed = e1000_bus_speed_2500;
6594 ret_val = e1000_read_pcie_cap_reg(hw,
6596 &pci_ex_link_status);
6598 hw->bus_width = e1000_bus_width_unknown;
6600 hw->bus_width = (pci_ex_link_status & PCI_EX_LINK_WIDTH_MASK) >>
6601 PCI_EX_LINK_WIDTH_SHIFT;
6604 hw->bus_type = e1000_bus_type_pci_express;
6605 hw->bus_speed = e1000_bus_speed_2500;
6606 hw->bus_width = e1000_bus_width_pciex_1;
6609 status = E1000_READ_REG(hw, STATUS);
6610 hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
6611 e1000_bus_type_pcix : e1000_bus_type_pci;
6613 if (hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) {
6614 hw->bus_speed = (hw->bus_type == e1000_bus_type_pci) ?
6615 e1000_bus_speed_66 : e1000_bus_speed_120;
6616 } else if (hw->bus_type == e1000_bus_type_pci) {
6617 hw->bus_speed = (status & E1000_STATUS_PCI66) ?
6618 e1000_bus_speed_66 : e1000_bus_speed_33;
6620 switch (status & E1000_STATUS_PCIX_SPEED) {
6621 case E1000_STATUS_PCIX_SPEED_66:
6622 hw->bus_speed = e1000_bus_speed_66;
6624 case E1000_STATUS_PCIX_SPEED_100:
6625 hw->bus_speed = e1000_bus_speed_100;
6627 case E1000_STATUS_PCIX_SPEED_133:
6628 hw->bus_speed = e1000_bus_speed_133;
6631 hw->bus_speed = e1000_bus_speed_reserved;
6635 hw->bus_width = (status & E1000_STATUS_BUS64) ?
6636 e1000_bus_width_64 : e1000_bus_width_32;
6641 /******************************************************************************
6642 * Writes a value to one of the devices registers using port I/O (as opposed to
6643 * memory mapped I/O). Only 82544 and newer devices support port I/O.
6645 * hw - Struct containing variables accessed by shared code
6646 * offset - offset to write to
6647 * value - value to write
6648 *****************************************************************************/
6650 e1000_write_reg_io(struct e1000_hw *hw,
6654 unsigned long io_addr = hw->io_base;
6655 unsigned long io_data = hw->io_base + 4;
6657 e1000_io_write(hw, io_addr, offset);
6658 e1000_io_write(hw, io_data, value);
6661 /******************************************************************************
6662 * Estimates the cable length.
6664 * hw - Struct containing variables accessed by shared code
6665 * min_length - The estimated minimum length
6666 * max_length - The estimated maximum length
6668 * returns: - E1000_ERR_XXX
6671 * This function always returns a ranged length (minimum & maximum).
6672 * So for M88 phy's, this function interprets the one value returned from the
6673 * register to the minimum and maximum range.
6674 * For IGP phy's, the function calculates the range by the AGC registers.
6675 *****************************************************************************/
6677 e1000_get_cable_length(struct e1000_hw *hw,
6678 uint16_t *min_length,
6679 uint16_t *max_length)
6682 uint16_t agc_value = 0;
6683 uint16_t i, phy_data;
6684 uint16_t cable_length;
6686 DEBUGFUNC("e1000_get_cable_length");
6688 *min_length = *max_length = 0;
6690 /* Use old method for Phy older than IGP */
6691 if (hw->phy_type == e1000_phy_m88) {
6693 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6697 cable_length = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
6698 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
6700 /* Convert the enum value to ranged values */
6701 switch (cable_length) {
6702 case e1000_cable_length_50:
6704 *max_length = e1000_igp_cable_length_50;
6706 case e1000_cable_length_50_80:
6707 *min_length = e1000_igp_cable_length_50;
6708 *max_length = e1000_igp_cable_length_80;
6710 case e1000_cable_length_80_110:
6711 *min_length = e1000_igp_cable_length_80;
6712 *max_length = e1000_igp_cable_length_110;
6714 case e1000_cable_length_110_140:
6715 *min_length = e1000_igp_cable_length_110;
6716 *max_length = e1000_igp_cable_length_140;
6718 case e1000_cable_length_140:
6719 *min_length = e1000_igp_cable_length_140;
6720 *max_length = e1000_igp_cable_length_170;
6723 return -E1000_ERR_PHY;
6726 } else if (hw->phy_type == e1000_phy_gg82563) {
6727 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_DSP_DISTANCE,
6731 cable_length = phy_data & GG82563_DSPD_CABLE_LENGTH;
6733 switch (cable_length) {
6734 case e1000_gg_cable_length_60:
6736 *max_length = e1000_igp_cable_length_60;
6738 case e1000_gg_cable_length_60_115:
6739 *min_length = e1000_igp_cable_length_60;
6740 *max_length = e1000_igp_cable_length_115;
6742 case e1000_gg_cable_length_115_150:
6743 *min_length = e1000_igp_cable_length_115;
6744 *max_length = e1000_igp_cable_length_150;
6746 case e1000_gg_cable_length_150:
6747 *min_length = e1000_igp_cable_length_150;
6748 *max_length = e1000_igp_cable_length_180;
6751 return -E1000_ERR_PHY;
6754 } else if (hw->phy_type == e1000_phy_igp) { /* For IGP PHY */
6755 uint16_t cur_agc_value;
6756 uint16_t min_agc_value = IGP01E1000_AGC_LENGTH_TABLE_SIZE;
6757 uint16_t agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
6758 {IGP01E1000_PHY_AGC_A,
6759 IGP01E1000_PHY_AGC_B,
6760 IGP01E1000_PHY_AGC_C,
6761 IGP01E1000_PHY_AGC_D};
6762 /* Read the AGC registers for all channels */
6763 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
6765 ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
6769 cur_agc_value = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT;
6771 /* Value bound check. */
6772 if ((cur_agc_value >= IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1) ||
6773 (cur_agc_value == 0))
6774 return -E1000_ERR_PHY;
6776 agc_value += cur_agc_value;
6778 /* Update minimal AGC value. */
6779 if (min_agc_value > cur_agc_value)
6780 min_agc_value = cur_agc_value;
6783 /* Remove the minimal AGC result for length < 50m */
6784 if (agc_value < IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) {
6785 agc_value -= min_agc_value;
6787 /* Get the average length of the remaining 3 channels */
6788 agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1);
6790 /* Get the average length of all the 4 channels. */
6791 agc_value /= IGP01E1000_PHY_CHANNEL_NUM;
6794 /* Set the range of the calculated length. */
6795 *min_length = ((e1000_igp_cable_length_table[agc_value] -
6796 IGP01E1000_AGC_RANGE) > 0) ?
6797 (e1000_igp_cable_length_table[agc_value] -
6798 IGP01E1000_AGC_RANGE) : 0;
6799 *max_length = e1000_igp_cable_length_table[agc_value] +
6800 IGP01E1000_AGC_RANGE;
6801 } else if (hw->phy_type == e1000_phy_igp_2 ||
6802 hw->phy_type == e1000_phy_igp_3) {
6803 uint16_t cur_agc_index, max_agc_index = 0;
6804 uint16_t min_agc_index = IGP02E1000_AGC_LENGTH_TABLE_SIZE - 1;
6805 uint16_t agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] =
6806 {IGP02E1000_PHY_AGC_A,
6807 IGP02E1000_PHY_AGC_B,
6808 IGP02E1000_PHY_AGC_C,
6809 IGP02E1000_PHY_AGC_D};
6810 /* Read the AGC registers for all channels */
6811 for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
6812 ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
6816 /* Getting bits 15:9, which represent the combination of course and
6817 * fine gain values. The result is a number that can be put into
6818 * the lookup table to obtain the approximate cable length. */
6819 cur_agc_index = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
6820 IGP02E1000_AGC_LENGTH_MASK;
6822 /* Array index bound check. */
6823 if ((cur_agc_index >= IGP02E1000_AGC_LENGTH_TABLE_SIZE) ||
6824 (cur_agc_index == 0))
6825 return -E1000_ERR_PHY;
6827 /* Remove min & max AGC values from calculation. */
6828 if (e1000_igp_2_cable_length_table[min_agc_index] >
6829 e1000_igp_2_cable_length_table[cur_agc_index])
6830 min_agc_index = cur_agc_index;
6831 if (e1000_igp_2_cable_length_table[max_agc_index] <
6832 e1000_igp_2_cable_length_table[cur_agc_index])
6833 max_agc_index = cur_agc_index;
6835 agc_value += e1000_igp_2_cable_length_table[cur_agc_index];
6838 agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] +
6839 e1000_igp_2_cable_length_table[max_agc_index]);
6840 agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
6842 /* Calculate cable length with the error range of +/- 10 meters. */
6843 *min_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
6844 (agc_value - IGP02E1000_AGC_RANGE) : 0;
6845 *max_length = agc_value + IGP02E1000_AGC_RANGE;
6848 return E1000_SUCCESS;
6851 /******************************************************************************
6852 * Check the cable polarity
6854 * hw - Struct containing variables accessed by shared code
6855 * polarity - output parameter : 0 - Polarity is not reversed
6856 * 1 - Polarity is reversed.
6858 * returns: - E1000_ERR_XXX
6861 * For phy's older then IGP, this function simply reads the polarity bit in the
6862 * Phy Status register. For IGP phy's, this bit is valid only if link speed is
6863 * 10 Mbps. If the link speed is 100 Mbps there is no polarity so this bit will
6864 * return 0. If the link speed is 1000 Mbps the polarity status is in the
6865 * IGP01E1000_PHY_PCS_INIT_REG.
6866 *****************************************************************************/
6868 e1000_check_polarity(struct e1000_hw *hw,
6869 e1000_rev_polarity *polarity)
6874 DEBUGFUNC("e1000_check_polarity");
6876 if ((hw->phy_type == e1000_phy_m88) ||
6877 (hw->phy_type == e1000_phy_gg82563)) {
6878 /* return the Polarity bit in the Status register. */
6879 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6883 *polarity = ((phy_data & M88E1000_PSSR_REV_POLARITY) >>
6884 M88E1000_PSSR_REV_POLARITY_SHIFT) ?
6885 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
6887 } else if (hw->phy_type == e1000_phy_igp ||
6888 hw->phy_type == e1000_phy_igp_3 ||
6889 hw->phy_type == e1000_phy_igp_2) {
6890 /* Read the Status register to check the speed */
6891 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
6896 /* If speed is 1000 Mbps, must read the IGP01E1000_PHY_PCS_INIT_REG to
6897 * find the polarity status */
6898 if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
6899 IGP01E1000_PSSR_SPEED_1000MBPS) {
6901 /* Read the GIG initialization PCS register (0x00B4) */
6902 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG,
6907 /* Check the polarity bits */
6908 *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ?
6909 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
6911 /* For 10 Mbps, read the polarity bit in the status register. (for
6912 * 100 Mbps this bit is always 0) */
6913 *polarity = (phy_data & IGP01E1000_PSSR_POLARITY_REVERSED) ?
6914 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
6916 } else if (hw->phy_type == e1000_phy_ife) {
6917 ret_val = e1000_read_phy_reg(hw, IFE_PHY_EXTENDED_STATUS_CONTROL,
6921 *polarity = ((phy_data & IFE_PESC_POLARITY_REVERSED) >>
6922 IFE_PESC_POLARITY_REVERSED_SHIFT) ?
6923 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
6925 return E1000_SUCCESS;
6928 /******************************************************************************
6929 * Check if Downshift occured
6931 * hw - Struct containing variables accessed by shared code
6932 * downshift - output parameter : 0 - No Downshift ocured.
6933 * 1 - Downshift ocured.
6935 * returns: - E1000_ERR_XXX
6938 * For phy's older then IGP, this function reads the Downshift bit in the Phy
6939 * Specific Status register. For IGP phy's, it reads the Downgrade bit in the
6940 * Link Health register. In IGP this bit is latched high, so the driver must
6941 * read it immediately after link is established.
6942 *****************************************************************************/
6944 e1000_check_downshift(struct e1000_hw *hw)
6949 DEBUGFUNC("e1000_check_downshift");
6951 if (hw->phy_type == e1000_phy_igp ||
6952 hw->phy_type == e1000_phy_igp_3 ||
6953 hw->phy_type == e1000_phy_igp_2) {
6954 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH,
6959 hw->speed_downgraded = (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0;
6960 } else if ((hw->phy_type == e1000_phy_m88) ||
6961 (hw->phy_type == e1000_phy_gg82563)) {
6962 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6967 hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >>
6968 M88E1000_PSSR_DOWNSHIFT_SHIFT;
6969 } else if (hw->phy_type == e1000_phy_ife) {
6970 /* e1000_phy_ife supports 10/100 speed only */
6971 hw->speed_downgraded = FALSE;
6974 return E1000_SUCCESS;
6977 /*****************************************************************************
6979 * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a
6980 * gigabit link is achieved to improve link quality.
6982 * hw: Struct containing variables accessed by shared code
6984 * returns: - E1000_ERR_PHY if fail to read/write the PHY
6985 * E1000_SUCCESS at any other case.
6987 ****************************************************************************/
6990 e1000_config_dsp_after_link_change(struct e1000_hw *hw,
6994 uint16_t phy_data, phy_saved_data, speed, duplex, i;
6995 uint16_t dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
6996 {IGP01E1000_PHY_AGC_PARAM_A,
6997 IGP01E1000_PHY_AGC_PARAM_B,
6998 IGP01E1000_PHY_AGC_PARAM_C,
6999 IGP01E1000_PHY_AGC_PARAM_D};
7000 uint16_t min_length, max_length;
7002 DEBUGFUNC("e1000_config_dsp_after_link_change");
7004 if (hw->phy_type != e1000_phy_igp)
7005 return E1000_SUCCESS;
7008 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
7010 DEBUGOUT("Error getting link speed and duplex\n");
7014 if (speed == SPEED_1000) {
7016 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
7020 if ((hw->dsp_config_state == e1000_dsp_config_enabled) &&
7021 min_length >= e1000_igp_cable_length_50) {
7023 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
7024 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i],
7029 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
7031 ret_val = e1000_write_phy_reg(hw, dsp_reg_array[i],
7036 hw->dsp_config_state = e1000_dsp_config_activated;
7039 if ((hw->ffe_config_state == e1000_ffe_config_enabled) &&
7040 (min_length < e1000_igp_cable_length_50)) {
7042 uint16_t ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_20;
7043 uint32_t idle_errs = 0;
7045 /* clear previous idle error counts */
7046 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
7051 for (i = 0; i < ffe_idle_err_timeout; i++) {
7053 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
7058 idle_errs += (phy_data & SR_1000T_IDLE_ERROR_CNT);
7059 if (idle_errs > SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT) {
7060 hw->ffe_config_state = e1000_ffe_config_active;
7062 ret_val = e1000_write_phy_reg(hw,
7063 IGP01E1000_PHY_DSP_FFE,
7064 IGP01E1000_PHY_DSP_FFE_CM_CP);
7071 ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_100;
7076 if (hw->dsp_config_state == e1000_dsp_config_activated) {
7077 /* Save off the current value of register 0x2F5B to be restored at
7078 * the end of the routines. */
7079 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
7084 /* Disable the PHY transmitter */
7085 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
7092 ret_val = e1000_write_phy_reg(hw, 0x0000,
7093 IGP01E1000_IEEE_FORCE_GIGA);
7096 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
7097 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i], &phy_data);
7101 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
7102 phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS;
7104 ret_val = e1000_write_phy_reg(hw,dsp_reg_array[i], phy_data);
7109 ret_val = e1000_write_phy_reg(hw, 0x0000,
7110 IGP01E1000_IEEE_RESTART_AUTONEG);
7116 /* Now enable the transmitter */
7117 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
7122 hw->dsp_config_state = e1000_dsp_config_enabled;
7125 if (hw->ffe_config_state == e1000_ffe_config_active) {
7126 /* Save off the current value of register 0x2F5B to be restored at
7127 * the end of the routines. */
7128 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
7133 /* Disable the PHY transmitter */
7134 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
7141 ret_val = e1000_write_phy_reg(hw, 0x0000,
7142 IGP01E1000_IEEE_FORCE_GIGA);
7145 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE,
7146 IGP01E1000_PHY_DSP_FFE_DEFAULT);
7150 ret_val = e1000_write_phy_reg(hw, 0x0000,
7151 IGP01E1000_IEEE_RESTART_AUTONEG);
7157 /* Now enable the transmitter */
7158 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
7163 hw->ffe_config_state = e1000_ffe_config_enabled;
7166 return E1000_SUCCESS;
7169 /*****************************************************************************
7170 * Set PHY to class A mode
7171 * Assumes the following operations will follow to enable the new class mode.
7172 * 1. Do a PHY soft reset
7173 * 2. Restart auto-negotiation or force link.
7175 * hw - Struct containing variables accessed by shared code
7176 ****************************************************************************/
7178 e1000_set_phy_mode(struct e1000_hw *hw)
7181 uint16_t eeprom_data;
7183 DEBUGFUNC("e1000_set_phy_mode");
7185 if ((hw->mac_type == e1000_82545_rev_3) &&
7186 (hw->media_type == e1000_media_type_copper)) {
7187 ret_val = e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, 1, &eeprom_data);
7192 if ((eeprom_data != EEPROM_RESERVED_WORD) &&
7193 (eeprom_data & EEPROM_PHY_CLASS_A)) {
7194 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x000B);
7197 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x8104);
7201 hw->phy_reset_disable = FALSE;
7205 return E1000_SUCCESS;
7208 /*****************************************************************************
7210 * This function sets the lplu state according to the active flag. When
7211 * activating lplu this function also disables smart speed and vise versa.
7212 * lplu will not be activated unless the device autonegotiation advertisment
7213 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
7214 * hw: Struct containing variables accessed by shared code
7215 * active - true to enable lplu false to disable lplu.
7217 * returns: - E1000_ERR_PHY if fail to read/write the PHY
7218 * E1000_SUCCESS at any other case.
7220 ****************************************************************************/
7223 e1000_set_d3_lplu_state(struct e1000_hw *hw,
7226 uint32_t phy_ctrl = 0;
7229 DEBUGFUNC("e1000_set_d3_lplu_state");
7231 if (hw->phy_type != e1000_phy_igp && hw->phy_type != e1000_phy_igp_2
7232 && hw->phy_type != e1000_phy_igp_3)
7233 return E1000_SUCCESS;
7235 /* During driver activity LPLU should not be used or it will attain link
7236 * from the lowest speeds starting from 10Mbps. The capability is used for
7237 * Dx transitions and states */
7238 if (hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2) {
7239 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data);
7242 } else if (hw->mac_type == e1000_ich8lan) {
7243 /* MAC writes into PHY register based on the state transition
7244 * and start auto-negotiation. SW driver can overwrite the settings
7245 * in CSR PHY power control E1000_PHY_CTRL register. */
7246 phy_ctrl = E1000_READ_REG(hw, PHY_CTRL);
7248 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
7254 if (hw->mac_type == e1000_82541_rev_2 ||
7255 hw->mac_type == e1000_82547_rev_2) {
7256 phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
7257 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
7261 if (hw->mac_type == e1000_ich8lan) {
7262 phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
7263 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7265 phy_data &= ~IGP02E1000_PM_D3_LPLU;
7266 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
7273 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
7274 * Dx states where the power conservation is most important. During
7275 * driver activity we should enable SmartSpeed, so performance is
7277 if (hw->smart_speed == e1000_smart_speed_on) {
7278 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7283 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
7284 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7288 } else if (hw->smart_speed == e1000_smart_speed_off) {
7289 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7294 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7295 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7301 } else if ((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT) ||
7302 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL ) ||
7303 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) {
7305 if (hw->mac_type == e1000_82541_rev_2 ||
7306 hw->mac_type == e1000_82547_rev_2) {
7307 phy_data |= IGP01E1000_GMII_FLEX_SPD;
7308 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
7312 if (hw->mac_type == e1000_ich8lan) {
7313 phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
7314 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7316 phy_data |= IGP02E1000_PM_D3_LPLU;
7317 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
7324 /* When LPLU is enabled we should disable SmartSpeed */
7325 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
7329 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7330 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
7335 return E1000_SUCCESS;
7338 /*****************************************************************************
7340 * This function sets the lplu d0 state according to the active flag. When
7341 * activating lplu this function also disables smart speed and vise versa.
7342 * lplu will not be activated unless the device autonegotiation advertisment
7343 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
7344 * hw: Struct containing variables accessed by shared code
7345 * active - true to enable lplu false to disable lplu.
7347 * returns: - E1000_ERR_PHY if fail to read/write the PHY
7348 * E1000_SUCCESS at any other case.
7350 ****************************************************************************/
7353 e1000_set_d0_lplu_state(struct e1000_hw *hw,
7356 uint32_t phy_ctrl = 0;
7359 DEBUGFUNC("e1000_set_d0_lplu_state");
7361 if (hw->mac_type <= e1000_82547_rev_2)
7362 return E1000_SUCCESS;
7364 if (hw->mac_type == e1000_ich8lan) {
7365 phy_ctrl = E1000_READ_REG(hw, PHY_CTRL);
7367 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
7373 if (hw->mac_type == e1000_ich8lan) {
7374 phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
7375 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7377 phy_data &= ~IGP02E1000_PM_D0_LPLU;
7378 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
7383 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
7384 * Dx states where the power conservation is most important. During
7385 * driver activity we should enable SmartSpeed, so performance is
7387 if (hw->smart_speed == e1000_smart_speed_on) {
7388 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7393 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
7394 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7398 } else if (hw->smart_speed == e1000_smart_speed_off) {
7399 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7404 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7405 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7414 if (hw->mac_type == e1000_ich8lan) {
7415 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
7416 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7418 phy_data |= IGP02E1000_PM_D0_LPLU;
7419 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
7424 /* When LPLU is enabled we should disable SmartSpeed */
7425 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
7429 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7430 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
7435 return E1000_SUCCESS;
7438 /******************************************************************************
7439 * Change VCO speed register to improve Bit Error Rate performance of SERDES.
7441 * hw - Struct containing variables accessed by shared code
7442 *****************************************************************************/
7444 e1000_set_vco_speed(struct e1000_hw *hw)
7447 uint16_t default_page = 0;
7450 DEBUGFUNC("e1000_set_vco_speed");
7452 switch (hw->mac_type) {
7453 case e1000_82545_rev_3:
7454 case e1000_82546_rev_3:
7457 return E1000_SUCCESS;
7460 /* Set PHY register 30, page 5, bit 8 to 0 */
7462 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, &default_page);
7466 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005);
7470 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
7474 phy_data &= ~M88E1000_PHY_VCO_REG_BIT8;
7475 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
7479 /* Set PHY register 30, page 4, bit 11 to 1 */
7481 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004);
7485 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
7489 phy_data |= M88E1000_PHY_VCO_REG_BIT11;
7490 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
7494 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, default_page);
7498 return E1000_SUCCESS;
7502 /*****************************************************************************
7503 * This function reads the cookie from ARC ram.
7505 * returns: - E1000_SUCCESS .
7506 ****************************************************************************/
7508 e1000_host_if_read_cookie(struct e1000_hw * hw, uint8_t *buffer)
7511 uint32_t offset = E1000_MNG_DHCP_COOKIE_OFFSET;
7512 uint8_t length = E1000_MNG_DHCP_COOKIE_LENGTH;
7514 length = (length >> 2);
7515 offset = (offset >> 2);
7517 for (i = 0; i < length; i++) {
7518 *((uint32_t *) buffer + i) =
7519 E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset + i);
7521 return E1000_SUCCESS;
7525 /*****************************************************************************
7526 * This function checks whether the HOST IF is enabled for command operaton
7527 * and also checks whether the previous command is completed.
7528 * It busy waits in case of previous command is not completed.
7530 * returns: - E1000_ERR_HOST_INTERFACE_COMMAND in case if is not ready or
7532 * - E1000_SUCCESS for success.
7533 ****************************************************************************/
7535 e1000_mng_enable_host_if(struct e1000_hw * hw)
7540 /* Check that the host interface is enabled. */
7541 hicr = E1000_READ_REG(hw, HICR);
7542 if ((hicr & E1000_HICR_EN) == 0) {
7543 DEBUGOUT("E1000_HOST_EN bit disabled.\n");
7544 return -E1000_ERR_HOST_INTERFACE_COMMAND;
7546 /* check the previous command is completed */
7547 for (i = 0; i < E1000_MNG_DHCP_COMMAND_TIMEOUT; i++) {
7548 hicr = E1000_READ_REG(hw, HICR);
7549 if (!(hicr & E1000_HICR_C))
7554 if (i == E1000_MNG_DHCP_COMMAND_TIMEOUT) {
7555 DEBUGOUT("Previous command timeout failed .\n");
7556 return -E1000_ERR_HOST_INTERFACE_COMMAND;
7558 return E1000_SUCCESS;
7561 /*****************************************************************************
7562 * This function writes the buffer content at the offset given on the host if.
7563 * It also does alignment considerations to do the writes in most efficient way.
7564 * Also fills up the sum of the buffer in *buffer parameter.
7566 * returns - E1000_SUCCESS for success.
7567 ****************************************************************************/
7569 e1000_mng_host_if_write(struct e1000_hw * hw, uint8_t *buffer,
7570 uint16_t length, uint16_t offset, uint8_t *sum)
7573 uint8_t *bufptr = buffer;
7575 uint16_t remaining, i, j, prev_bytes;
7577 /* sum = only sum of the data and it is not checksum */
7579 if (length == 0 || offset + length > E1000_HI_MAX_MNG_DATA_LENGTH) {
7580 return -E1000_ERR_PARAM;
7583 tmp = (uint8_t *)&data;
7584 prev_bytes = offset & 0x3;
7589 data = E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset);
7590 for (j = prev_bytes; j < sizeof(uint32_t); j++) {
7591 *(tmp + j) = *bufptr++;
7594 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset, data);
7595 length -= j - prev_bytes;
7599 remaining = length & 0x3;
7600 length -= remaining;
7602 /* Calculate length in DWORDs */
7605 /* The device driver writes the relevant command block into the
7607 for (i = 0; i < length; i++) {
7608 for (j = 0; j < sizeof(uint32_t); j++) {
7609 *(tmp + j) = *bufptr++;
7613 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data);
7616 for (j = 0; j < sizeof(uint32_t); j++) {
7618 *(tmp + j) = *bufptr++;
7624 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data);
7627 return E1000_SUCCESS;
7631 /*****************************************************************************
7632 * This function writes the command header after does the checksum calculation.
7634 * returns - E1000_SUCCESS for success.
7635 ****************************************************************************/
7637 e1000_mng_write_cmd_header(struct e1000_hw * hw,
7638 struct e1000_host_mng_command_header * hdr)
7644 /* Write the whole command header structure which includes sum of
7647 uint16_t length = sizeof(struct e1000_host_mng_command_header);
7649 sum = hdr->checksum;
7652 buffer = (uint8_t *) hdr;
7657 hdr->checksum = 0 - sum;
7660 /* The device driver writes the relevant command block into the ram area. */
7661 for (i = 0; i < length; i++) {
7662 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, i, *((uint32_t *) hdr + i));
7663 E1000_WRITE_FLUSH(hw);
7666 return E1000_SUCCESS;
7670 /*****************************************************************************
7671 * This function indicates to ARC that a new command is pending which completes
7672 * one write operation by the driver.
7674 * returns - E1000_SUCCESS for success.
7675 ****************************************************************************/
7677 e1000_mng_write_commit(struct e1000_hw * hw)
7681 hicr = E1000_READ_REG(hw, HICR);
7682 /* Setting this bit tells the ARC that a new command is pending. */
7683 E1000_WRITE_REG(hw, HICR, hicr | E1000_HICR_C);
7685 return E1000_SUCCESS;
7689 /*****************************************************************************
7690 * This function checks the mode of the firmware.
7692 * returns - TRUE when the mode is IAMT or FALSE.
7693 ****************************************************************************/
7695 e1000_check_mng_mode(struct e1000_hw *hw)
7699 fwsm = E1000_READ_REG(hw, FWSM);
7701 if (hw->mac_type == e1000_ich8lan) {
7702 if ((fwsm & E1000_FWSM_MODE_MASK) ==
7703 (E1000_MNG_ICH_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
7705 } else if ((fwsm & E1000_FWSM_MODE_MASK) ==
7706 (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
7713 /*****************************************************************************
7714 * This function writes the dhcp info .
7715 ****************************************************************************/
7717 e1000_mng_write_dhcp_info(struct e1000_hw * hw, uint8_t *buffer,
7721 struct e1000_host_mng_command_header hdr;
7723 hdr.command_id = E1000_MNG_DHCP_TX_PAYLOAD_CMD;
7724 hdr.command_length = length;
7729 ret_val = e1000_mng_enable_host_if(hw);
7730 if (ret_val == E1000_SUCCESS) {
7731 ret_val = e1000_mng_host_if_write(hw, buffer, length, sizeof(hdr),
7733 if (ret_val == E1000_SUCCESS) {
7734 ret_val = e1000_mng_write_cmd_header(hw, &hdr);
7735 if (ret_val == E1000_SUCCESS)
7736 ret_val = e1000_mng_write_commit(hw);
7743 /*****************************************************************************
7744 * This function calculates the checksum.
7746 * returns - checksum of buffer contents.
7747 ****************************************************************************/
7749 e1000_calculate_mng_checksum(char *buffer, uint32_t length)
7757 for (i=0; i < length; i++)
7760 return (uint8_t) (0 - sum);
7763 /*****************************************************************************
7764 * This function checks whether tx pkt filtering needs to be enabled or not.
7766 * returns - TRUE for packet filtering or FALSE.
7767 ****************************************************************************/
7769 e1000_enable_tx_pkt_filtering(struct e1000_hw *hw)
7771 /* called in init as well as watchdog timer functions */
7773 int32_t ret_val, checksum;
7774 boolean_t tx_filter = FALSE;
7775 struct e1000_host_mng_dhcp_cookie *hdr = &(hw->mng_cookie);
7776 uint8_t *buffer = (uint8_t *) &(hw->mng_cookie);
7778 if (e1000_check_mng_mode(hw)) {
7779 ret_val = e1000_mng_enable_host_if(hw);
7780 if (ret_val == E1000_SUCCESS) {
7781 ret_val = e1000_host_if_read_cookie(hw, buffer);
7782 if (ret_val == E1000_SUCCESS) {
7783 checksum = hdr->checksum;
7785 if ((hdr->signature == E1000_IAMT_SIGNATURE) &&
7786 checksum == e1000_calculate_mng_checksum((char *)buffer,
7787 E1000_MNG_DHCP_COOKIE_LENGTH)) {
7789 E1000_MNG_DHCP_COOKIE_STATUS_PARSING_SUPPORT)
7798 hw->tx_pkt_filtering = tx_filter;
7802 /******************************************************************************
7803 * Verifies the hardware needs to allow ARPs to be processed by the host
7805 * hw - Struct containing variables accessed by shared code
7807 * returns: - TRUE/FALSE
7809 *****************************************************************************/
7811 e1000_enable_mng_pass_thru(struct e1000_hw *hw)
7814 uint32_t fwsm, factps;
7816 if (hw->asf_firmware_present) {
7817 manc = E1000_READ_REG(hw, MANC);
7819 if (!(manc & E1000_MANC_RCV_TCO_EN) ||
7820 !(manc & E1000_MANC_EN_MAC_ADDR_FILTER))
7822 if (e1000_arc_subsystem_valid(hw) == TRUE) {
7823 fwsm = E1000_READ_REG(hw, FWSM);
7824 factps = E1000_READ_REG(hw, FACTPS);
7826 if ((((fwsm & E1000_FWSM_MODE_MASK) >> E1000_FWSM_MODE_SHIFT) ==
7827 e1000_mng_mode_pt) && !(factps & E1000_FACTPS_MNGCG))
7830 if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN))
7837 e1000_polarity_reversal_workaround(struct e1000_hw *hw)
7840 uint16_t mii_status_reg;
7843 /* Polarity reversal workaround for forced 10F/10H links. */
7845 /* Disable the transmitter on the PHY */
7847 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
7850 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF);
7854 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
7858 /* This loop will early-out if the NO link condition has been met. */
7859 for (i = PHY_FORCE_TIME; i > 0; i--) {
7860 /* Read the MII Status Register and wait for Link Status bit
7864 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
7868 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
7872 if ((mii_status_reg & ~MII_SR_LINK_STATUS) == 0) break;
7876 /* Recommended delay time after link has been lost */
7879 /* Now we will re-enable th transmitter on the PHY */
7881 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
7885 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0);
7889 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00);
7893 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000);
7897 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
7901 /* This loop will early-out if the link condition has been met. */
7902 for (i = PHY_FORCE_TIME; i > 0; i--) {
7903 /* Read the MII Status Register and wait for Link Status bit
7907 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
7911 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
7915 if (mii_status_reg & MII_SR_LINK_STATUS) break;
7918 return E1000_SUCCESS;
7921 /***************************************************************************
7923 * Disables PCI-Express master access.
7925 * hw: Struct containing variables accessed by shared code
7929 ***************************************************************************/
7931 e1000_set_pci_express_master_disable(struct e1000_hw *hw)
7935 DEBUGFUNC("e1000_set_pci_express_master_disable");
7937 if (hw->bus_type != e1000_bus_type_pci_express)
7940 ctrl = E1000_READ_REG(hw, CTRL);
7941 ctrl |= E1000_CTRL_GIO_MASTER_DISABLE;
7942 E1000_WRITE_REG(hw, CTRL, ctrl);
7945 /*******************************************************************************
7947 * Disables PCI-Express master access and verifies there are no pending requests
7949 * hw: Struct containing variables accessed by shared code
7951 * returns: - E1000_ERR_MASTER_REQUESTS_PENDING if master disable bit hasn't
7952 * caused the master requests to be disabled.
7953 * E1000_SUCCESS master requests disabled.
7955 ******************************************************************************/
7957 e1000_disable_pciex_master(struct e1000_hw *hw)
7959 int32_t timeout = MASTER_DISABLE_TIMEOUT; /* 80ms */
7961 DEBUGFUNC("e1000_disable_pciex_master");
7963 if (hw->bus_type != e1000_bus_type_pci_express)
7964 return E1000_SUCCESS;
7966 e1000_set_pci_express_master_disable(hw);
7969 if (!(E1000_READ_REG(hw, STATUS) & E1000_STATUS_GIO_MASTER_ENABLE))
7977 DEBUGOUT("Master requests are pending.\n");
7978 return -E1000_ERR_MASTER_REQUESTS_PENDING;
7981 return E1000_SUCCESS;
7984 /*******************************************************************************
7986 * Check for EEPROM Auto Read bit done.
7988 * hw: Struct containing variables accessed by shared code
7990 * returns: - E1000_ERR_RESET if fail to reset MAC
7991 * E1000_SUCCESS at any other case.
7993 ******************************************************************************/
7995 e1000_get_auto_rd_done(struct e1000_hw *hw)
7997 int32_t timeout = AUTO_READ_DONE_TIMEOUT;
7999 DEBUGFUNC("e1000_get_auto_rd_done");
8001 switch (hw->mac_type) {
8008 case e1000_80003es2lan:
8011 if (E1000_READ_REG(hw, EECD) & E1000_EECD_AUTO_RD)
8018 DEBUGOUT("Auto read by HW from EEPROM has not completed.\n");
8019 return -E1000_ERR_RESET;
8024 /* PHY configuration from NVM just starts after EECD_AUTO_RD sets to high.
8025 * Need to wait for PHY configuration completion before accessing NVM
8027 if (hw->mac_type == e1000_82573)
8030 return E1000_SUCCESS;
8033 /***************************************************************************
8034 * Checks if the PHY configuration is done
8036 * hw: Struct containing variables accessed by shared code
8038 * returns: - E1000_ERR_RESET if fail to reset MAC
8039 * E1000_SUCCESS at any other case.
8041 ***************************************************************************/
8043 e1000_get_phy_cfg_done(struct e1000_hw *hw)
8045 int32_t timeout = PHY_CFG_TIMEOUT;
8046 uint32_t cfg_mask = E1000_EEPROM_CFG_DONE;
8048 DEBUGFUNC("e1000_get_phy_cfg_done");
8050 switch (hw->mac_type) {
8054 case e1000_80003es2lan:
8055 /* Separate *_CFG_DONE_* bit for each port */
8056 if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
8057 cfg_mask = E1000_EEPROM_CFG_DONE_PORT_1;
8062 if (E1000_READ_REG(hw, EEMNGCTL) & cfg_mask)
8069 DEBUGOUT("MNG configuration cycle has not completed.\n");
8070 return -E1000_ERR_RESET;
8075 return E1000_SUCCESS;
8078 /***************************************************************************
8080 * Using the combination of SMBI and SWESMBI semaphore bits when resetting
8081 * adapter or Eeprom access.
8083 * hw: Struct containing variables accessed by shared code
8085 * returns: - E1000_ERR_EEPROM if fail to access EEPROM.
8086 * E1000_SUCCESS at any other case.
8088 ***************************************************************************/
8090 e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw)
8095 DEBUGFUNC("e1000_get_hw_eeprom_semaphore");
8097 if (!hw->eeprom_semaphore_present)
8098 return E1000_SUCCESS;
8100 if (hw->mac_type == e1000_80003es2lan) {
8101 /* Get the SW semaphore. */
8102 if (e1000_get_software_semaphore(hw) != E1000_SUCCESS)
8103 return -E1000_ERR_EEPROM;
8106 /* Get the FW semaphore. */
8107 timeout = hw->eeprom.word_size + 1;
8109 swsm = E1000_READ_REG(hw, SWSM);
8110 swsm |= E1000_SWSM_SWESMBI;
8111 E1000_WRITE_REG(hw, SWSM, swsm);
8112 /* if we managed to set the bit we got the semaphore. */
8113 swsm = E1000_READ_REG(hw, SWSM);
8114 if (swsm & E1000_SWSM_SWESMBI)
8122 /* Release semaphores */
8123 e1000_put_hw_eeprom_semaphore(hw);
8124 DEBUGOUT("Driver can't access the Eeprom - SWESMBI bit is set.\n");
8125 return -E1000_ERR_EEPROM;
8128 return E1000_SUCCESS;
8131 /***************************************************************************
8132 * This function clears HW semaphore bits.
8134 * hw: Struct containing variables accessed by shared code
8138 ***************************************************************************/
8140 e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw)
8144 DEBUGFUNC("e1000_put_hw_eeprom_semaphore");
8146 if (!hw->eeprom_semaphore_present)
8149 swsm = E1000_READ_REG(hw, SWSM);
8150 if (hw->mac_type == e1000_80003es2lan) {
8151 /* Release both semaphores. */
8152 swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
8154 swsm &= ~(E1000_SWSM_SWESMBI);
8155 E1000_WRITE_REG(hw, SWSM, swsm);
8158 /***************************************************************************
8160 * Obtaining software semaphore bit (SMBI) before resetting PHY.
8162 * hw: Struct containing variables accessed by shared code
8164 * returns: - E1000_ERR_RESET if fail to obtain semaphore.
8165 * E1000_SUCCESS at any other case.
8167 ***************************************************************************/
8169 e1000_get_software_semaphore(struct e1000_hw *hw)
8171 int32_t timeout = hw->eeprom.word_size + 1;
8174 DEBUGFUNC("e1000_get_software_semaphore");
8176 if (hw->mac_type != e1000_80003es2lan) {
8177 return E1000_SUCCESS;
8181 swsm = E1000_READ_REG(hw, SWSM);
8182 /* If SMBI bit cleared, it is now set and we hold the semaphore */
8183 if (!(swsm & E1000_SWSM_SMBI))
8190 DEBUGOUT("Driver can't access device - SMBI bit is set.\n");
8191 return -E1000_ERR_RESET;
8194 return E1000_SUCCESS;
8197 /***************************************************************************
8199 * Release semaphore bit (SMBI).
8201 * hw: Struct containing variables accessed by shared code
8203 ***************************************************************************/
8205 e1000_release_software_semaphore(struct e1000_hw *hw)
8209 DEBUGFUNC("e1000_release_software_semaphore");
8211 if (hw->mac_type != e1000_80003es2lan) {
8215 swsm = E1000_READ_REG(hw, SWSM);
8216 /* Release the SW semaphores.*/
8217 swsm &= ~E1000_SWSM_SMBI;
8218 E1000_WRITE_REG(hw, SWSM, swsm);
8221 /******************************************************************************
8222 * Checks if PHY reset is blocked due to SOL/IDER session, for example.
8223 * Returning E1000_BLK_PHY_RESET isn't necessarily an error. But it's up to
8224 * the caller to figure out how to deal with it.
8226 * hw - Struct containing variables accessed by shared code
8228 * returns: - E1000_BLK_PHY_RESET
8231 *****************************************************************************/
8233 e1000_check_phy_reset_block(struct e1000_hw *hw)
8238 if (hw->mac_type == e1000_ich8lan) {
8239 fwsm = E1000_READ_REG(hw, FWSM);
8240 return (fwsm & E1000_FWSM_RSPCIPHY) ? E1000_SUCCESS
8241 : E1000_BLK_PHY_RESET;
8244 if (hw->mac_type > e1000_82547_rev_2)
8245 manc = E1000_READ_REG(hw, MANC);
8246 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
8247 E1000_BLK_PHY_RESET : E1000_SUCCESS;
8251 e1000_arc_subsystem_valid(struct e1000_hw *hw)
8255 /* On 8257x silicon, registers in the range of 0x8800 - 0x8FFC
8256 * may not be provided a DMA clock when no manageability features are
8257 * enabled. We do not want to perform any reads/writes to these registers
8258 * if this is the case. We read FWSM to determine the manageability mode.
8260 switch (hw->mac_type) {
8264 case e1000_80003es2lan:
8265 fwsm = E1000_READ_REG(hw, FWSM);
8266 if ((fwsm & E1000_FWSM_MODE_MASK) != 0)
8278 /******************************************************************************
8279 * Configure PCI-Ex no-snoop
8281 * hw - Struct containing variables accessed by shared code.
8282 * no_snoop - Bitmap of no-snoop events.
8284 * returns: E1000_SUCCESS
8286 *****************************************************************************/
8288 e1000_set_pci_ex_no_snoop(struct e1000_hw *hw, uint32_t no_snoop)
8290 uint32_t gcr_reg = 0;
8292 DEBUGFUNC("e1000_set_pci_ex_no_snoop");
8294 if (hw->bus_type == e1000_bus_type_unknown)
8295 e1000_get_bus_info(hw);
8297 if (hw->bus_type != e1000_bus_type_pci_express)
8298 return E1000_SUCCESS;
8301 gcr_reg = E1000_READ_REG(hw, GCR);
8302 gcr_reg &= ~(PCI_EX_NO_SNOOP_ALL);
8303 gcr_reg |= no_snoop;
8304 E1000_WRITE_REG(hw, GCR, gcr_reg);
8306 if (hw->mac_type == e1000_ich8lan) {
8309 E1000_WRITE_REG(hw, GCR, PCI_EX_82566_SNOOP_ALL);
8311 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
8312 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
8313 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
8316 return E1000_SUCCESS;
8319 /***************************************************************************
8321 * Get software semaphore FLAG bit (SWFLAG).
8322 * SWFLAG is used to synchronize the access to all shared resource between
8325 * hw: Struct containing variables accessed by shared code
8327 ***************************************************************************/
8329 e1000_get_software_flag(struct e1000_hw *hw)
8331 int32_t timeout = PHY_CFG_TIMEOUT;
8332 uint32_t extcnf_ctrl;
8334 DEBUGFUNC("e1000_get_software_flag");
8336 if (hw->mac_type == e1000_ich8lan) {
8338 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
8339 extcnf_ctrl |= E1000_EXTCNF_CTRL_SWFLAG;
8340 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
8342 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
8343 if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG)
8350 DEBUGOUT("FW or HW locks the resource too long.\n");
8351 return -E1000_ERR_CONFIG;
8355 return E1000_SUCCESS;
8358 /***************************************************************************
8360 * Release software semaphore FLAG bit (SWFLAG).
8361 * SWFLAG is used to synchronize the access to all shared resource between
8364 * hw: Struct containing variables accessed by shared code
8366 ***************************************************************************/
8368 e1000_release_software_flag(struct e1000_hw *hw)
8370 uint32_t extcnf_ctrl;
8372 DEBUGFUNC("e1000_release_software_flag");
8374 if (hw->mac_type == e1000_ich8lan) {
8375 extcnf_ctrl= E1000_READ_REG(hw, EXTCNF_CTRL);
8376 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
8377 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
8383 /******************************************************************************
8384 * Reads a 16 bit word or words from the EEPROM using the ICH8's flash access
8387 * hw - Struct containing variables accessed by shared code
8388 * offset - offset of word in the EEPROM to read
8389 * data - word read from the EEPROM
8390 * words - number of words to read
8391 *****************************************************************************/
8393 e1000_read_eeprom_ich8(struct e1000_hw *hw, uint16_t offset, uint16_t words,
8396 int32_t error = E1000_SUCCESS;
8397 uint32_t flash_bank = 0;
8398 uint32_t act_offset = 0;
8399 uint32_t bank_offset = 0;
8403 /* We need to know which is the valid flash bank. In the event
8404 * that we didn't allocate eeprom_shadow_ram, we may not be
8405 * managing flash_bank. So it cannot be trusted and needs
8406 * to be updated with each read.
8408 /* Value of bit 22 corresponds to the flash bank we're on. */
8409 flash_bank = (E1000_READ_REG(hw, EECD) & E1000_EECD_SEC1VAL) ? 1 : 0;
8411 /* Adjust offset appropriately if we're on bank 1 - adjust for word size */
8412 bank_offset = flash_bank * (hw->flash_bank_size * 2);
8414 error = e1000_get_software_flag(hw);
8415 if (error != E1000_SUCCESS)
8418 for (i = 0; i < words; i++) {
8419 if (hw->eeprom_shadow_ram != NULL &&
8420 hw->eeprom_shadow_ram[offset+i].modified == TRUE) {
8421 data[i] = hw->eeprom_shadow_ram[offset+i].eeprom_word;
8423 /* The NVM part needs a byte offset, hence * 2 */
8424 act_offset = bank_offset + ((offset + i) * 2);
8425 error = e1000_read_ich8_word(hw, act_offset, &word);
8426 if (error != E1000_SUCCESS)
8432 e1000_release_software_flag(hw);
8437 /******************************************************************************
8438 * Writes a 16 bit word or words to the EEPROM using the ICH8's flash access
8439 * register. Actually, writes are written to the shadow ram cache in the hw
8440 * structure hw->e1000_shadow_ram. e1000_commit_shadow_ram flushes this to
8441 * the NVM, which occurs when the NVM checksum is updated.
8443 * hw - Struct containing variables accessed by shared code
8444 * offset - offset of word in the EEPROM to write
8445 * words - number of words to write
8446 * data - words to write to the EEPROM
8447 *****************************************************************************/
8449 e1000_write_eeprom_ich8(struct e1000_hw *hw, uint16_t offset, uint16_t words,
8453 int32_t error = E1000_SUCCESS;
8455 error = e1000_get_software_flag(hw);
8456 if (error != E1000_SUCCESS)
8459 /* A driver can write to the NVM only if it has eeprom_shadow_ram
8460 * allocated. Subsequent reads to the modified words are read from
8461 * this cached structure as well. Writes will only go into this
8462 * cached structure unless it's followed by a call to
8463 * e1000_update_eeprom_checksum() where it will commit the changes
8464 * and clear the "modified" field.
8466 if (hw->eeprom_shadow_ram != NULL) {
8467 for (i = 0; i < words; i++) {
8468 if ((offset + i) < E1000_SHADOW_RAM_WORDS) {
8469 hw->eeprom_shadow_ram[offset+i].modified = TRUE;
8470 hw->eeprom_shadow_ram[offset+i].eeprom_word = data[i];
8472 error = -E1000_ERR_EEPROM;
8477 /* Drivers have the option to not allocate eeprom_shadow_ram as long
8478 * as they don't perform any NVM writes. An attempt in doing so
8479 * will result in this error.
8481 error = -E1000_ERR_EEPROM;
8484 e1000_release_software_flag(hw);
8489 /******************************************************************************
8490 * This function does initial flash setup so that a new read/write/erase cycle
8493 * hw - The pointer to the hw structure
8494 ****************************************************************************/
8496 e1000_ich8_cycle_init(struct e1000_hw *hw)
8498 union ich8_hws_flash_status hsfsts;
8499 int32_t error = E1000_ERR_EEPROM;
8502 DEBUGFUNC("e1000_ich8_cycle_init");
8504 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
8506 /* May be check the Flash Des Valid bit in Hw status */
8507 if (hsfsts.hsf_status.fldesvalid == 0) {
8508 DEBUGOUT("Flash descriptor invalid. SW Sequencing must be used.");
8512 /* Clear FCERR in Hw status by writing 1 */
8513 /* Clear DAEL in Hw status by writing a 1 */
8514 hsfsts.hsf_status.flcerr = 1;
8515 hsfsts.hsf_status.dael = 1;
8517 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS, hsfsts.regval);
8519 /* Either we should have a hardware SPI cycle in progress bit to check
8520 * against, in order to start a new cycle or FDONE bit should be changed
8521 * in the hardware so that it is 1 after harware reset, which can then be
8522 * used as an indication whether a cycle is in progress or has been
8523 * completed .. we should also have some software semaphore mechanism to
8524 * guard FDONE or the cycle in progress bit so that two threads access to
8525 * those bits can be sequentiallized or a way so that 2 threads dont
8526 * start the cycle at the same time */
8528 if (hsfsts.hsf_status.flcinprog == 0) {
8529 /* There is no cycle running at present, so we can start a cycle */
8530 /* Begin by setting Flash Cycle Done. */
8531 hsfsts.hsf_status.flcdone = 1;
8532 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS, hsfsts.regval);
8533 error = E1000_SUCCESS;
8535 /* otherwise poll for sometime so the current cycle has a chance
8536 * to end before giving up. */
8537 for (i = 0; i < ICH_FLASH_COMMAND_TIMEOUT; i++) {
8538 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
8539 if (hsfsts.hsf_status.flcinprog == 0) {
8540 error = E1000_SUCCESS;
8545 if (error == E1000_SUCCESS) {
8546 /* Successful in waiting for previous cycle to timeout,
8547 * now set the Flash Cycle Done. */
8548 hsfsts.hsf_status.flcdone = 1;
8549 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS, hsfsts.regval);
8551 DEBUGOUT("Flash controller busy, cannot get access");
8557 /******************************************************************************
8558 * This function starts a flash cycle and waits for its completion
8560 * hw - The pointer to the hw structure
8561 ****************************************************************************/
8563 e1000_ich8_flash_cycle(struct e1000_hw *hw, uint32_t timeout)
8565 union ich8_hws_flash_ctrl hsflctl;
8566 union ich8_hws_flash_status hsfsts;
8567 int32_t error = E1000_ERR_EEPROM;
8570 /* Start a cycle by writing 1 in Flash Cycle Go in Hw Flash Control */
8571 hsflctl.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL);
8572 hsflctl.hsf_ctrl.flcgo = 1;
8573 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval);
8575 /* wait till FDONE bit is set to 1 */
8577 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
8578 if (hsfsts.hsf_status.flcdone == 1)
8582 } while (i < timeout);
8583 if (hsfsts.hsf_status.flcdone == 1 && hsfsts.hsf_status.flcerr == 0) {
8584 error = E1000_SUCCESS;
8589 /******************************************************************************
8590 * Reads a byte or word from the NVM using the ICH8 flash access registers.
8592 * hw - The pointer to the hw structure
8593 * index - The index of the byte or word to read.
8594 * size - Size of data to read, 1=byte 2=word
8595 * data - Pointer to the word to store the value read.
8596 *****************************************************************************/
8598 e1000_read_ich8_data(struct e1000_hw *hw, uint32_t index,
8599 uint32_t size, uint16_t* data)
8601 union ich8_hws_flash_status hsfsts;
8602 union ich8_hws_flash_ctrl hsflctl;
8603 uint32_t flash_linear_address;
8604 uint32_t flash_data = 0;
8605 int32_t error = -E1000_ERR_EEPROM;
8608 DEBUGFUNC("e1000_read_ich8_data");
8610 if (size < 1 || size > 2 || data == 0x0 ||
8611 index > ICH_FLASH_LINEAR_ADDR_MASK)
8614 flash_linear_address = (ICH_FLASH_LINEAR_ADDR_MASK & index) +
8615 hw->flash_base_addr;
8620 error = e1000_ich8_cycle_init(hw);
8621 if (error != E1000_SUCCESS)
8624 hsflctl.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL);
8625 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
8626 hsflctl.hsf_ctrl.fldbcount = size - 1;
8627 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_READ;
8628 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval);
8630 /* Write the last 24 bits of index into Flash Linear address field in
8632 /* TODO: TBD maybe check the index against the size of flash */
8634 E1000_WRITE_ICH_FLASH_REG(hw, ICH_FLASH_FADDR, flash_linear_address);
8636 error = e1000_ich8_flash_cycle(hw, ICH_FLASH_COMMAND_TIMEOUT);
8638 /* Check if FCERR is set to 1, if set to 1, clear it and try the whole
8639 * sequence a few more times, else read in (shift in) the Flash Data0,
8640 * the order is least significant byte first msb to lsb */
8641 if (error == E1000_SUCCESS) {
8642 flash_data = E1000_READ_ICH_FLASH_REG(hw, ICH_FLASH_FDATA0);
8644 *data = (uint8_t)(flash_data & 0x000000FF);
8645 } else if (size == 2) {
8646 *data = (uint16_t)(flash_data & 0x0000FFFF);
8650 /* If we've gotten here, then things are probably completely hosed,
8651 * but if the error condition is detected, it won't hurt to give
8652 * it another try...ICH_FLASH_CYCLE_REPEAT_COUNT times.
8654 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
8655 if (hsfsts.hsf_status.flcerr == 1) {
8656 /* Repeat for some time before giving up. */
8658 } else if (hsfsts.hsf_status.flcdone == 0) {
8659 DEBUGOUT("Timeout error - flash cycle did not complete.");
8663 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
8668 /******************************************************************************
8669 * Writes One /two bytes to the NVM using the ICH8 flash access registers.
8671 * hw - The pointer to the hw structure
8672 * index - The index of the byte/word to read.
8673 * size - Size of data to read, 1=byte 2=word
8674 * data - The byte(s) to write to the NVM.
8675 *****************************************************************************/
8677 e1000_write_ich8_data(struct e1000_hw *hw, uint32_t index, uint32_t size,
8680 union ich8_hws_flash_status hsfsts;
8681 union ich8_hws_flash_ctrl hsflctl;
8682 uint32_t flash_linear_address;
8683 uint32_t flash_data = 0;
8684 int32_t error = -E1000_ERR_EEPROM;
8687 DEBUGFUNC("e1000_write_ich8_data");
8689 if (size < 1 || size > 2 || data > size * 0xff ||
8690 index > ICH_FLASH_LINEAR_ADDR_MASK)
8693 flash_linear_address = (ICH_FLASH_LINEAR_ADDR_MASK & index) +
8694 hw->flash_base_addr;
8699 error = e1000_ich8_cycle_init(hw);
8700 if (error != E1000_SUCCESS)
8703 hsflctl.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL);
8704 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
8705 hsflctl.hsf_ctrl.fldbcount = size -1;
8706 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_WRITE;
8707 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval);
8709 /* Write the last 24 bits of index into Flash Linear address field in
8711 E1000_WRITE_ICH_FLASH_REG(hw, ICH_FLASH_FADDR, flash_linear_address);
8714 flash_data = (uint32_t)data & 0x00FF;
8716 flash_data = (uint32_t)data;
8718 E1000_WRITE_ICH_FLASH_REG(hw, ICH_FLASH_FDATA0, flash_data);
8720 /* check if FCERR is set to 1 , if set to 1, clear it and try the whole
8721 * sequence a few more times else done */
8722 error = e1000_ich8_flash_cycle(hw, ICH_FLASH_COMMAND_TIMEOUT);
8723 if (error == E1000_SUCCESS) {
8726 /* If we're here, then things are most likely completely hosed,
8727 * but if the error condition is detected, it won't hurt to give
8728 * it another try...ICH_FLASH_CYCLE_REPEAT_COUNT times.
8730 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
8731 if (hsfsts.hsf_status.flcerr == 1) {
8732 /* Repeat for some time before giving up. */
8734 } else if (hsfsts.hsf_status.flcdone == 0) {
8735 DEBUGOUT("Timeout error - flash cycle did not complete.");
8739 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
8744 /******************************************************************************
8745 * Reads a single byte from the NVM using the ICH8 flash access registers.
8747 * hw - pointer to e1000_hw structure
8748 * index - The index of the byte to read.
8749 * data - Pointer to a byte to store the value read.
8750 *****************************************************************************/
8752 e1000_read_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t* data)
8754 int32_t status = E1000_SUCCESS;
8757 status = e1000_read_ich8_data(hw, index, 1, &word);
8758 if (status == E1000_SUCCESS) {
8759 *data = (uint8_t)word;
8765 /******************************************************************************
8766 * Writes a single byte to the NVM using the ICH8 flash access registers.
8767 * Performs verification by reading back the value and then going through
8768 * a retry algorithm before giving up.
8770 * hw - pointer to e1000_hw structure
8771 * index - The index of the byte to write.
8772 * byte - The byte to write to the NVM.
8773 *****************************************************************************/
8775 e1000_verify_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t byte)
8777 int32_t error = E1000_SUCCESS;
8778 int32_t program_retries = 0;
8780 DEBUGOUT2("Byte := %2.2X Offset := %d\n", byte, index);
8782 error = e1000_write_ich8_byte(hw, index, byte);
8784 if (error != E1000_SUCCESS) {
8785 for (program_retries = 0; program_retries < 100; program_retries++) {
8786 DEBUGOUT2("Retrying \t Byte := %2.2X Offset := %d\n", byte, index);
8787 error = e1000_write_ich8_byte(hw, index, byte);
8789 if (error == E1000_SUCCESS)
8794 if (program_retries == 100)
8795 error = E1000_ERR_EEPROM;
8800 /******************************************************************************
8801 * Writes a single byte to the NVM using the ICH8 flash access registers.
8803 * hw - pointer to e1000_hw structure
8804 * index - The index of the byte to read.
8805 * data - The byte to write to the NVM.
8806 *****************************************************************************/
8808 e1000_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t data)
8810 int32_t status = E1000_SUCCESS;
8811 uint16_t word = (uint16_t)data;
8813 status = e1000_write_ich8_data(hw, index, 1, word);
8818 /******************************************************************************
8819 * Reads a word from the NVM using the ICH8 flash access registers.
8821 * hw - pointer to e1000_hw structure
8822 * index - The starting byte index of the word to read.
8823 * data - Pointer to a word to store the value read.
8824 *****************************************************************************/
8826 e1000_read_ich8_word(struct e1000_hw *hw, uint32_t index, uint16_t *data)
8828 int32_t status = E1000_SUCCESS;
8829 status = e1000_read_ich8_data(hw, index, 2, data);
8833 /******************************************************************************
8834 * Erases the bank specified. Each bank may be a 4, 8 or 64k block. Banks are 0
8837 * hw - pointer to e1000_hw structure
8838 * bank - 0 for first bank, 1 for second bank
8840 * Note that this function may actually erase as much as 8 or 64 KBytes. The
8841 * amount of NVM used in each bank is a *minimum* of 4 KBytes, but in fact the
8842 * bank size may be 4, 8 or 64 KBytes
8843 *****************************************************************************/
8845 e1000_erase_ich8_4k_segment(struct e1000_hw *hw, uint32_t bank)
8847 union ich8_hws_flash_status hsfsts;
8848 union ich8_hws_flash_ctrl hsflctl;
8849 uint32_t flash_linear_address;
8851 int32_t error = E1000_ERR_EEPROM;
8853 int32_t sub_sector_size = 0;
8856 int32_t error_flag = 0;
8858 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
8860 /* Determine HW Sector size: Read BERASE bits of Hw flash Status register */
8861 /* 00: The Hw sector is 256 bytes, hence we need to erase 16
8862 * consecutive sectors. The start index for the nth Hw sector can be
8863 * calculated as bank * 4096 + n * 256
8864 * 01: The Hw sector is 4K bytes, hence we need to erase 1 sector.
8865 * The start index for the nth Hw sector can be calculated
8867 * 10: The HW sector is 8K bytes
8868 * 11: The Hw sector size is 64K bytes */
8869 if (hsfsts.hsf_status.berasesz == 0x0) {
8870 /* Hw sector size 256 */
8871 sub_sector_size = ICH_FLASH_SEG_SIZE_256;
8872 bank_size = ICH_FLASH_SECTOR_SIZE;
8873 iteration = ICH_FLASH_SECTOR_SIZE / ICH_FLASH_SEG_SIZE_256;
8874 } else if (hsfsts.hsf_status.berasesz == 0x1) {
8875 bank_size = ICH_FLASH_SEG_SIZE_4K;
8877 } else if (hsfsts.hsf_status.berasesz == 0x3) {
8878 bank_size = ICH_FLASH_SEG_SIZE_64K;
8884 for (j = 0; j < iteration ; j++) {
8888 error = e1000_ich8_cycle_init(hw);
8889 if (error != E1000_SUCCESS) {
8894 /* Write a value 11 (block Erase) in Flash Cycle field in Hw flash
8896 hsflctl.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL);
8897 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_ERASE;
8898 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval);
8900 /* Write the last 24 bits of an index within the block into Flash
8901 * Linear address field in Flash Address. This probably needs to
8902 * be calculated here based off the on-chip erase sector size and
8903 * the software bank size (4, 8 or 64 KBytes) */
8904 flash_linear_address = bank * bank_size + j * sub_sector_size;
8905 flash_linear_address += hw->flash_base_addr;
8906 flash_linear_address &= ICH_FLASH_LINEAR_ADDR_MASK;
8908 E1000_WRITE_ICH_FLASH_REG(hw, ICH_FLASH_FADDR, flash_linear_address);
8910 error = e1000_ich8_flash_cycle(hw, ICH_FLASH_ERASE_TIMEOUT);
8911 /* Check if FCERR is set to 1. If 1, clear it and try the whole
8912 * sequence a few more times else Done */
8913 if (error == E1000_SUCCESS) {
8916 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
8917 if (hsfsts.hsf_status.flcerr == 1) {
8918 /* repeat for some time before giving up */
8920 } else if (hsfsts.hsf_status.flcdone == 0) {
8925 } while ((count < ICH_FLASH_CYCLE_REPEAT_COUNT) && !error_flag);
8926 if (error_flag == 1)
8929 if (error_flag != 1)
8930 error = E1000_SUCCESS;
8935 e1000_init_lcd_from_nvm_config_region(struct e1000_hw *hw,
8936 uint32_t cnf_base_addr, uint32_t cnf_size)
8938 uint32_t ret_val = E1000_SUCCESS;
8939 uint16_t word_addr, reg_data, reg_addr;
8942 /* cnf_base_addr is in DWORD */
8943 word_addr = (uint16_t)(cnf_base_addr << 1);
8945 /* cnf_size is returned in size of dwords */
8946 for (i = 0; i < cnf_size; i++) {
8947 ret_val = e1000_read_eeprom(hw, (word_addr + i*2), 1, ®_data);
8951 ret_val = e1000_read_eeprom(hw, (word_addr + i*2 + 1), 1, ®_addr);
8955 ret_val = e1000_get_software_flag(hw);
8956 if (ret_val != E1000_SUCCESS)
8959 ret_val = e1000_write_phy_reg_ex(hw, (uint32_t)reg_addr, reg_data);
8961 e1000_release_software_flag(hw);
8968 /******************************************************************************
8969 * This function initializes the PHY from the NVM on ICH8 platforms. This
8970 * is needed due to an issue where the NVM configuration is not properly
8971 * autoloaded after power transitions. Therefore, after each PHY reset, we
8972 * will load the configuration data out of the NVM manually.
8974 * hw: Struct containing variables accessed by shared code
8975 *****************************************************************************/
8977 e1000_init_lcd_from_nvm(struct e1000_hw *hw)
8979 uint32_t reg_data, cnf_base_addr, cnf_size, ret_val, loop;
8981 if (hw->phy_type != e1000_phy_igp_3)
8982 return E1000_SUCCESS;
8984 /* Check if SW needs configure the PHY */
8985 reg_data = E1000_READ_REG(hw, FEXTNVM);
8986 if (!(reg_data & FEXTNVM_SW_CONFIG))
8987 return E1000_SUCCESS;
8989 /* Wait for basic configuration completes before proceeding*/
8992 reg_data = E1000_READ_REG(hw, STATUS) & E1000_STATUS_LAN_INIT_DONE;
8995 } while ((!reg_data) && (loop < 50));
8997 /* Clear the Init Done bit for the next init event */
8998 reg_data = E1000_READ_REG(hw, STATUS);
8999 reg_data &= ~E1000_STATUS_LAN_INIT_DONE;
9000 E1000_WRITE_REG(hw, STATUS, reg_data);
9002 /* Make sure HW does not configure LCD from PHY extended configuration
9003 before SW configuration */
9004 reg_data = E1000_READ_REG(hw, EXTCNF_CTRL);
9005 if ((reg_data & E1000_EXTCNF_CTRL_LCD_WRITE_ENABLE) == 0x0000) {
9006 reg_data = E1000_READ_REG(hw, EXTCNF_SIZE);
9007 cnf_size = reg_data & E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH;
9010 reg_data = E1000_READ_REG(hw, EXTCNF_CTRL);
9011 cnf_base_addr = reg_data & E1000_EXTCNF_CTRL_EXT_CNF_POINTER;
9012 /* cnf_base_addr is in DWORD */
9013 cnf_base_addr >>= 16;
9015 /* Configure LCD from extended configuration region. */
9016 ret_val = e1000_init_lcd_from_nvm_config_region(hw, cnf_base_addr,
9023 return E1000_SUCCESS;