blob: 45ac225a7aaa5c241a90e042ccac8738c8643a67 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*******************************************************************************
2
Auke Kok0abb6eb2006-09-27 12:53:14 -07003 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2006 Intel Corporation.
5
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.
9
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 more details.
Auke Kok0abb6eb2006-09-27 12:53:14 -070014
Linus Torvalds1da177e2005-04-16 15:20:36 -070015 You should have received a copy of the GNU General Public License along with
Auke Kok0abb6eb2006-09-27 12:53:14 -070016 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 Contact Information:
23 Linux NICS <linux.nics@intel.com>
Auke Kok3d41e302006-04-14 19:05:31 -070024 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26
27*******************************************************************************/
28
29/* e1000_hw.c
30 * Shared functions for accessing and configuring the MAC
31 */
32
Auke Kok8fc897b2006-08-28 14:56:16 -070033
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include "e1000_hw.h"
35
Joe Perches406874a2008-04-03 10:06:32 -070036static s32 e1000_swfw_sync_acquire(struct e1000_hw *hw, u16 mask);
37static void e1000_swfw_sync_release(struct e1000_hw *hw, u16 mask);
38static s32 e1000_read_kmrn_reg(struct e1000_hw *hw, u32 reg_addr, u16 *data);
39static s32 e1000_write_kmrn_reg(struct e1000_hw *hw, u32 reg_addr, u16 data);
40static s32 e1000_get_software_semaphore(struct e1000_hw *hw);
Nicholas Nunley35574762006-09-27 12:53:34 -070041static void e1000_release_software_semaphore(struct e1000_hw *hw);
42
Joe Perches406874a2008-04-03 10:06:32 -070043static u8 e1000_arc_subsystem_valid(struct e1000_hw *hw);
44static s32 e1000_check_downshift(struct e1000_hw *hw);
Joe Perches64798842008-07-11 15:17:02 -070045static s32 e1000_check_polarity(struct e1000_hw *hw,
46 e1000_rev_polarity *polarity);
Nicholas Nunley35574762006-09-27 12:53:34 -070047static void e1000_clear_hw_cntrs(struct e1000_hw *hw);
48static void e1000_clear_vfta(struct e1000_hw *hw);
Joe Perches406874a2008-04-03 10:06:32 -070049static s32 e1000_commit_shadow_ram(struct e1000_hw *hw);
50static s32 e1000_config_dsp_after_link_change(struct e1000_hw *hw,
Joe Perches64798842008-07-11 15:17:02 -070051 bool link_up);
Joe Perches406874a2008-04-03 10:06:32 -070052static s32 e1000_config_fc_after_link_up(struct e1000_hw *hw);
53static s32 e1000_detect_gig_phy(struct e1000_hw *hw);
54static s32 e1000_erase_ich8_4k_segment(struct e1000_hw *hw, u32 bank);
55static s32 e1000_get_auto_rd_done(struct e1000_hw *hw);
Joe Perches64798842008-07-11 15:17:02 -070056static s32 e1000_get_cable_length(struct e1000_hw *hw, u16 *min_length,
57 u16 *max_length);
Joe Perches406874a2008-04-03 10:06:32 -070058static s32 e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw);
59static s32 e1000_get_phy_cfg_done(struct e1000_hw *hw);
60static s32 e1000_get_software_flag(struct e1000_hw *hw);
61static s32 e1000_ich8_cycle_init(struct e1000_hw *hw);
62static s32 e1000_ich8_flash_cycle(struct e1000_hw *hw, u32 timeout);
63static s32 e1000_id_led_init(struct e1000_hw *hw);
Joe Perches64798842008-07-11 15:17:02 -070064static s32 e1000_init_lcd_from_nvm_config_region(struct e1000_hw *hw,
65 u32 cnf_base_addr,
66 u32 cnf_size);
Joe Perches406874a2008-04-03 10:06:32 -070067static s32 e1000_init_lcd_from_nvm(struct e1000_hw *hw);
Nicholas Nunley35574762006-09-27 12:53:34 -070068static void e1000_init_rx_addrs(struct e1000_hw *hw);
Jeff Kirsher09ae3e82006-09-27 12:53:51 -070069static void e1000_initialize_hardware_bits(struct e1000_hw *hw);
Joe Perchesc3033b02008-03-21 11:06:25 -070070static bool e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw);
Joe Perches406874a2008-04-03 10:06:32 -070071static s32 e1000_kumeran_lock_loss_workaround(struct e1000_hw *hw);
72static s32 e1000_mng_enable_host_if(struct e1000_hw *hw);
Joe Perches64798842008-07-11 15:17:02 -070073static s32 e1000_mng_host_if_write(struct e1000_hw *hw, u8 *buffer, u16 length,
74 u16 offset, u8 *sum);
75static s32 e1000_mng_write_cmd_header(struct e1000_hw* hw,
76 struct e1000_host_mng_command_header
77 *hdr);
Joe Perches406874a2008-04-03 10:06:32 -070078static s32 e1000_mng_write_commit(struct e1000_hw *hw);
Joe Perches64798842008-07-11 15:17:02 -070079static s32 e1000_phy_ife_get_info(struct e1000_hw *hw,
80 struct e1000_phy_info *phy_info);
81static s32 e1000_phy_igp_get_info(struct e1000_hw *hw,
82 struct e1000_phy_info *phy_info);
83static s32 e1000_read_eeprom_eerd(struct e1000_hw *hw, u16 offset, u16 words,
84 u16 *data);
85static s32 e1000_write_eeprom_eewr(struct e1000_hw *hw, u16 offset, u16 words,
86 u16 *data);
Joe Perches406874a2008-04-03 10:06:32 -070087static s32 e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd);
Joe Perches64798842008-07-11 15:17:02 -070088static s32 e1000_phy_m88_get_info(struct e1000_hw *hw,
89 struct e1000_phy_info *phy_info);
Nicholas Nunley35574762006-09-27 12:53:34 -070090static void e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw);
Joe Perches406874a2008-04-03 10:06:32 -070091static s32 e1000_read_ich8_byte(struct e1000_hw *hw, u32 index, u8 *data);
Joe Perches64798842008-07-11 15:17:02 -070092static s32 e1000_verify_write_ich8_byte(struct e1000_hw *hw, u32 index,
93 u8 byte);
Joe Perches406874a2008-04-03 10:06:32 -070094static s32 e1000_write_ich8_byte(struct e1000_hw *hw, u32 index, u8 byte);
95static s32 e1000_read_ich8_word(struct e1000_hw *hw, u32 index, u16 *data);
Joe Perches64798842008-07-11 15:17:02 -070096static s32 e1000_read_ich8_data(struct e1000_hw *hw, u32 index, u32 size,
97 u16 *data);
98static s32 e1000_write_ich8_data(struct e1000_hw *hw, u32 index, u32 size,
99 u16 data);
100static s32 e1000_read_eeprom_ich8(struct e1000_hw *hw, u16 offset, u16 words,
101 u16 *data);
102static s32 e1000_write_eeprom_ich8(struct e1000_hw *hw, u16 offset, u16 words,
103 u16 *data);
Nicholas Nunley35574762006-09-27 12:53:34 -0700104static void e1000_release_software_flag(struct e1000_hw *hw);
Joe Perches406874a2008-04-03 10:06:32 -0700105static s32 e1000_set_d3_lplu_state(struct e1000_hw *hw, bool active);
106static s32 e1000_set_d0_lplu_state(struct e1000_hw *hw, bool active);
107static s32 e1000_set_pci_ex_no_snoop(struct e1000_hw *hw, u32 no_snoop);
Nicholas Nunley35574762006-09-27 12:53:34 -0700108static void e1000_set_pci_express_master_disable(struct e1000_hw *hw);
Joe Perches406874a2008-04-03 10:06:32 -0700109static s32 e1000_wait_autoneg(struct e1000_hw *hw);
110static void e1000_write_reg_io(struct e1000_hw *hw, u32 offset, u32 value);
111static s32 e1000_set_phy_type(struct e1000_hw *hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112static void e1000_phy_init_script(struct e1000_hw *hw);
Joe Perches406874a2008-04-03 10:06:32 -0700113static s32 e1000_setup_copper_link(struct e1000_hw *hw);
114static s32 e1000_setup_fiber_serdes_link(struct e1000_hw *hw);
115static s32 e1000_adjust_serdes_amplitude(struct e1000_hw *hw);
116static s32 e1000_phy_force_speed_duplex(struct e1000_hw *hw);
117static s32 e1000_config_mac_to_phy(struct e1000_hw *hw);
118static void e1000_raise_mdi_clk(struct e1000_hw *hw, u32 *ctrl);
119static void e1000_lower_mdi_clk(struct e1000_hw *hw, u32 *ctrl);
120static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, u32 data,
Joe Perches64798842008-07-11 15:17:02 -0700121 u16 count);
Joe Perches406874a2008-04-03 10:06:32 -0700122static u16 e1000_shift_in_mdi_bits(struct e1000_hw *hw);
123static s32 e1000_phy_reset_dsp(struct e1000_hw *hw);
124static s32 e1000_write_eeprom_spi(struct e1000_hw *hw, u16 offset,
125 u16 words, u16 *data);
Joe Perches64798842008-07-11 15:17:02 -0700126static s32 e1000_write_eeprom_microwire(struct e1000_hw *hw, u16 offset,
127 u16 words, u16 *data);
Joe Perches406874a2008-04-03 10:06:32 -0700128static s32 e1000_spi_eeprom_ready(struct e1000_hw *hw);
129static void e1000_raise_ee_clk(struct e1000_hw *hw, u32 *eecd);
130static void e1000_lower_ee_clk(struct e1000_hw *hw, u32 *eecd);
Joe Perches64798842008-07-11 15:17:02 -0700131static void e1000_shift_out_ee_bits(struct e1000_hw *hw, u16 data, u16 count);
Joe Perches406874a2008-04-03 10:06:32 -0700132static s32 e1000_write_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr,
Joe Perches64798842008-07-11 15:17:02 -0700133 u16 phy_data);
Joe Perches406874a2008-04-03 10:06:32 -0700134static s32 e1000_read_phy_reg_ex(struct e1000_hw *hw,u32 reg_addr,
Joe Perches64798842008-07-11 15:17:02 -0700135 u16 *phy_data);
Joe Perches406874a2008-04-03 10:06:32 -0700136static u16 e1000_shift_in_ee_bits(struct e1000_hw *hw, u16 count);
137static s32 e1000_acquire_eeprom(struct e1000_hw *hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138static void e1000_release_eeprom(struct e1000_hw *hw);
139static void e1000_standby_eeprom(struct e1000_hw *hw);
Joe Perches406874a2008-04-03 10:06:32 -0700140static s32 e1000_set_vco_speed(struct e1000_hw *hw);
141static s32 e1000_polarity_reversal_workaround(struct e1000_hw *hw);
142static s32 e1000_set_phy_mode(struct e1000_hw *hw);
143static s32 e1000_host_if_read_cookie(struct e1000_hw *hw, u8 *buffer);
144static u8 e1000_calculate_mng_checksum(char *buffer, u32 length);
Joe Perches64798842008-07-11 15:17:02 -0700145static s32 e1000_configure_kmrn_for_10_100(struct e1000_hw *hw, u16 duplex);
Joe Perches406874a2008-04-03 10:06:32 -0700146static s32 e1000_configure_kmrn_for_1000(struct e1000_hw *hw);
Christopher Li78566fe2008-09-05 14:04:05 -0700147static s32 e1000_do_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data);
148static s32 e1000_do_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
150/* IGP cable length table */
151static const
Joe Perches406874a2008-04-03 10:06:32 -0700152u16 e1000_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
154 5, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 25, 25, 25,
155 25, 25, 25, 25, 30, 30, 30, 30, 40, 40, 40, 40, 40, 40, 40, 40,
156 40, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60,
157 60, 70, 70, 70, 70, 70, 70, 80, 80, 80, 80, 80, 80, 90, 90, 90,
158 90, 90, 90, 90, 90, 90, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
159 100, 100, 100, 100, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,
160 110, 110, 110, 110, 110, 110, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120};
161
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700162static const
Joe Perches406874a2008-04-03 10:06:32 -0700163u16 e1000_igp_2_cable_length_table[IGP02E1000_AGC_LENGTH_TABLE_SIZE] =
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400164 { 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21,
165 0, 0, 0, 3, 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41,
166 6, 10, 14, 18, 22, 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61,
167 21, 26, 31, 35, 40, 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82,
168 40, 45, 51, 56, 61, 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104,
169 60, 66, 72, 77, 82, 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121,
170 83, 89, 95, 100, 105, 109, 113, 116, 119, 122, 124,
171 104, 109, 114, 118, 121, 124};
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700172
Christopher Li78566fe2008-09-05 14:04:05 -0700173static DEFINE_SPINLOCK(e1000_eeprom_lock);
174
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175/******************************************************************************
176 * Set the phy type member in the hw struct.
177 *
178 * hw - Struct containing variables accessed by shared code
179 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -0700180static s32 e1000_set_phy_type(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181{
182 DEBUGFUNC("e1000_set_phy_type");
183
Auke Kok8fc897b2006-08-28 14:56:16 -0700184 if (hw->mac_type == e1000_undefined)
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700185 return -E1000_ERR_PHY_TYPE;
186
Auke Kok8fc897b2006-08-28 14:56:16 -0700187 switch (hw->phy_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 case M88E1000_E_PHY_ID:
189 case M88E1000_I_PHY_ID:
190 case M88E1011_I_PHY_ID:
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700191 case M88E1111_I_PHY_ID:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 hw->phy_type = e1000_phy_m88;
193 break;
194 case IGP01E1000_I_PHY_ID:
Auke Kok8fc897b2006-08-28 14:56:16 -0700195 if (hw->mac_type == e1000_82541 ||
196 hw->mac_type == e1000_82541_rev_2 ||
197 hw->mac_type == e1000_82547 ||
198 hw->mac_type == e1000_82547_rev_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 hw->phy_type = e1000_phy_igp;
200 break;
201 }
Auke Kokcd94dd02006-06-27 09:08:22 -0700202 case IGP03E1000_E_PHY_ID:
203 hw->phy_type = e1000_phy_igp_3;
204 break;
205 case IFE_E_PHY_ID:
206 case IFE_PLUS_E_PHY_ID:
207 case IFE_C_E_PHY_ID:
208 hw->phy_type = e1000_phy_ife;
209 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800210 case GG82563_E_PHY_ID:
211 if (hw->mac_type == e1000_80003es2lan) {
212 hw->phy_type = e1000_phy_gg82563;
213 break;
214 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 /* Fall Through */
216 default:
217 /* Should never have loaded on this device */
218 hw->phy_type = e1000_phy_undefined;
219 return -E1000_ERR_PHY_TYPE;
220 }
221
222 return E1000_SUCCESS;
223}
224
225/******************************************************************************
226 * IGP phy init script - initializes the GbE PHY
227 *
228 * hw - Struct containing variables accessed by shared code
229 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -0700230static void e1000_phy_init_script(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231{
Joe Perches406874a2008-04-03 10:06:32 -0700232 u32 ret_val;
233 u16 phy_saved_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234
235 DEBUGFUNC("e1000_phy_init_script");
236
Auke Kok8fc897b2006-08-28 14:56:16 -0700237 if (hw->phy_init_script) {
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400238 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239
240 /* Save off the current value of register 0x2F5B to be restored at
241 * the end of this routine. */
242 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
243
244 /* Disabled the PHY transmitter */
245 e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
246
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400247 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
249 e1000_write_phy_reg(hw,0x0000,0x0140);
250
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400251 msleep(5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252
Auke Kok8fc897b2006-08-28 14:56:16 -0700253 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 case e1000_82541:
255 case e1000_82547:
256 e1000_write_phy_reg(hw, 0x1F95, 0x0001);
257
258 e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
259
260 e1000_write_phy_reg(hw, 0x1F79, 0x0018);
261
262 e1000_write_phy_reg(hw, 0x1F30, 0x1600);
263
264 e1000_write_phy_reg(hw, 0x1F31, 0x0014);
265
266 e1000_write_phy_reg(hw, 0x1F32, 0x161C);
267
268 e1000_write_phy_reg(hw, 0x1F94, 0x0003);
269
270 e1000_write_phy_reg(hw, 0x1F96, 0x003F);
271
272 e1000_write_phy_reg(hw, 0x2010, 0x0008);
273 break;
274
275 case e1000_82541_rev_2:
276 case e1000_82547_rev_2:
277 e1000_write_phy_reg(hw, 0x1F73, 0x0099);
278 break;
279 default:
280 break;
281 }
282
283 e1000_write_phy_reg(hw, 0x0000, 0x3300);
284
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400285 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286
287 /* Now enable the transmitter */
288 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
289
Auke Kok8fc897b2006-08-28 14:56:16 -0700290 if (hw->mac_type == e1000_82547) {
Joe Perches406874a2008-04-03 10:06:32 -0700291 u16 fused, fine, coarse;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292
293 /* Move to analog registers page */
294 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_SPARE_FUSE_STATUS, &fused);
295
Auke Kok8fc897b2006-08-28 14:56:16 -0700296 if (!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_FUSE_STATUS, &fused);
298
299 fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
300 coarse = fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
301
Auke Kok8fc897b2006-08-28 14:56:16 -0700302 if (coarse > IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 coarse -= IGP01E1000_ANALOG_FUSE_COARSE_10;
304 fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
Auke Kok8fc897b2006-08-28 14:56:16 -0700305 } else if (coarse == IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
307
308 fused = (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
309 (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
310 (coarse & IGP01E1000_ANALOG_FUSE_COARSE_MASK);
311
312 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_CONTROL, fused);
313 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_BYPASS,
314 IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
315 }
316 }
317 }
318}
319
320/******************************************************************************
321 * Set the mac type member in the hw struct.
322 *
323 * hw - Struct containing variables accessed by shared code
324 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -0700325s32 e1000_set_mac_type(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326{
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500327 DEBUGFUNC("e1000_set_mac_type");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500329 switch (hw->device_id) {
330 case E1000_DEV_ID_82542:
331 switch (hw->revision_id) {
332 case E1000_82542_2_0_REV_ID:
333 hw->mac_type = e1000_82542_rev2_0;
334 break;
335 case E1000_82542_2_1_REV_ID:
336 hw->mac_type = e1000_82542_rev2_1;
337 break;
338 default:
339 /* Invalid 82542 revision ID */
340 return -E1000_ERR_MAC_TYPE;
341 }
342 break;
343 case E1000_DEV_ID_82543GC_FIBER:
344 case E1000_DEV_ID_82543GC_COPPER:
345 hw->mac_type = e1000_82543;
346 break;
347 case E1000_DEV_ID_82544EI_COPPER:
348 case E1000_DEV_ID_82544EI_FIBER:
349 case E1000_DEV_ID_82544GC_COPPER:
350 case E1000_DEV_ID_82544GC_LOM:
351 hw->mac_type = e1000_82544;
352 break;
353 case E1000_DEV_ID_82540EM:
354 case E1000_DEV_ID_82540EM_LOM:
355 case E1000_DEV_ID_82540EP:
356 case E1000_DEV_ID_82540EP_LOM:
357 case E1000_DEV_ID_82540EP_LP:
358 hw->mac_type = e1000_82540;
359 break;
360 case E1000_DEV_ID_82545EM_COPPER:
361 case E1000_DEV_ID_82545EM_FIBER:
362 hw->mac_type = e1000_82545;
363 break;
364 case E1000_DEV_ID_82545GM_COPPER:
365 case E1000_DEV_ID_82545GM_FIBER:
366 case E1000_DEV_ID_82545GM_SERDES:
367 hw->mac_type = e1000_82545_rev_3;
368 break;
369 case E1000_DEV_ID_82546EB_COPPER:
370 case E1000_DEV_ID_82546EB_FIBER:
371 case E1000_DEV_ID_82546EB_QUAD_COPPER:
372 hw->mac_type = e1000_82546;
373 break;
374 case E1000_DEV_ID_82546GB_COPPER:
375 case E1000_DEV_ID_82546GB_FIBER:
376 case E1000_DEV_ID_82546GB_SERDES:
377 case E1000_DEV_ID_82546GB_PCIE:
378 case E1000_DEV_ID_82546GB_QUAD_COPPER:
379 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
380 hw->mac_type = e1000_82546_rev_3;
381 break;
382 case E1000_DEV_ID_82541EI:
383 case E1000_DEV_ID_82541EI_MOBILE:
384 case E1000_DEV_ID_82541ER_LOM:
385 hw->mac_type = e1000_82541;
386 break;
387 case E1000_DEV_ID_82541ER:
388 case E1000_DEV_ID_82541GI:
389 case E1000_DEV_ID_82541GI_LF:
390 case E1000_DEV_ID_82541GI_MOBILE:
391 hw->mac_type = e1000_82541_rev_2;
392 break;
393 case E1000_DEV_ID_82547EI:
394 case E1000_DEV_ID_82547EI_MOBILE:
395 hw->mac_type = e1000_82547;
396 break;
397 case E1000_DEV_ID_82547GI:
398 hw->mac_type = e1000_82547_rev_2;
399 break;
400 case E1000_DEV_ID_82571EB_COPPER:
401 case E1000_DEV_ID_82571EB_FIBER:
402 case E1000_DEV_ID_82571EB_SERDES:
Auke Kokce57a022007-08-09 14:09:34 -0700403 case E1000_DEV_ID_82571EB_SERDES_DUAL:
404 case E1000_DEV_ID_82571EB_SERDES_QUAD:
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500405 case E1000_DEV_ID_82571EB_QUAD_COPPER:
Auke Kokf4ec7f92007-08-30 11:23:58 -0700406 case E1000_DEV_ID_82571PT_QUAD_COPPER:
Auke Kokce57a022007-08-09 14:09:34 -0700407 case E1000_DEV_ID_82571EB_QUAD_FIBER:
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500408 case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE:
409 hw->mac_type = e1000_82571;
410 break;
411 case E1000_DEV_ID_82572EI_COPPER:
412 case E1000_DEV_ID_82572EI_FIBER:
413 case E1000_DEV_ID_82572EI_SERDES:
414 case E1000_DEV_ID_82572EI:
415 hw->mac_type = e1000_82572;
416 break;
417 case E1000_DEV_ID_82573E:
418 case E1000_DEV_ID_82573E_IAMT:
419 case E1000_DEV_ID_82573L:
420 hw->mac_type = e1000_82573;
421 break;
422 case E1000_DEV_ID_80003ES2LAN_COPPER_SPT:
423 case E1000_DEV_ID_80003ES2LAN_SERDES_SPT:
424 case E1000_DEV_ID_80003ES2LAN_COPPER_DPT:
425 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
426 hw->mac_type = e1000_80003es2lan;
427 break;
428 case E1000_DEV_ID_ICH8_IGP_M_AMT:
429 case E1000_DEV_ID_ICH8_IGP_AMT:
430 case E1000_DEV_ID_ICH8_IGP_C:
431 case E1000_DEV_ID_ICH8_IFE:
432 case E1000_DEV_ID_ICH8_IFE_GT:
433 case E1000_DEV_ID_ICH8_IFE_G:
434 case E1000_DEV_ID_ICH8_IGP_M:
435 hw->mac_type = e1000_ich8lan;
436 break;
437 default:
438 /* Should never have loaded on this device */
439 return -E1000_ERR_MAC_TYPE;
440 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500442 switch (hw->mac_type) {
443 case e1000_ich8lan:
Joe Perchesc3033b02008-03-21 11:06:25 -0700444 hw->swfwhw_semaphore_present = true;
445 hw->asf_firmware_present = true;
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500446 break;
447 case e1000_80003es2lan:
Joe Perchesc3033b02008-03-21 11:06:25 -0700448 hw->swfw_sync_present = true;
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500449 /* fall through */
450 case e1000_82571:
451 case e1000_82572:
452 case e1000_82573:
Joe Perchesc3033b02008-03-21 11:06:25 -0700453 hw->eeprom_semaphore_present = true;
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500454 /* fall through */
455 case e1000_82541:
456 case e1000_82547:
457 case e1000_82541_rev_2:
458 case e1000_82547_rev_2:
Joe Perchesc3033b02008-03-21 11:06:25 -0700459 hw->asf_firmware_present = true;
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500460 break;
461 default:
462 break;
463 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464
Jeff Garzik167fb282006-12-15 10:41:15 -0500465 /* The 82543 chip does not count tx_carrier_errors properly in
466 * FD mode
467 */
468 if (hw->mac_type == e1000_82543)
Joe Perchesc3033b02008-03-21 11:06:25 -0700469 hw->bad_tx_carr_stats_fd = true;
Jeff Garzik167fb282006-12-15 10:41:15 -0500470
Jeff Garzik0fccd0e2006-12-15 10:56:10 -0500471 /* capable of receiving management packets to the host */
472 if (hw->mac_type >= e1000_82571)
Joe Perchesc3033b02008-03-21 11:06:25 -0700473 hw->has_manc2h = true;
Jeff Garzik0fccd0e2006-12-15 10:56:10 -0500474
Jeff Garzikbb8e3312006-12-15 11:06:17 -0500475 /* In rare occasions, ESB2 systems would end up started without
476 * the RX unit being turned on.
477 */
478 if (hw->mac_type == e1000_80003es2lan)
Joe Perchesc3033b02008-03-21 11:06:25 -0700479 hw->rx_needs_kicking = true;
Jeff Garzikbb8e3312006-12-15 11:06:17 -0500480
Jeff Garzik15e376b2006-12-15 11:16:33 -0500481 if (hw->mac_type > e1000_82544)
Joe Perchesc3033b02008-03-21 11:06:25 -0700482 hw->has_smbus = true;
Jeff Garzik15e376b2006-12-15 11:16:33 -0500483
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500484 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485}
486
487/*****************************************************************************
488 * Set media type and TBI compatibility.
489 *
490 * hw - Struct containing variables accessed by shared code
491 * **************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -0700492void e1000_set_media_type(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493{
Joe Perches406874a2008-04-03 10:06:32 -0700494 u32 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495
496 DEBUGFUNC("e1000_set_media_type");
497
Auke Kok8fc897b2006-08-28 14:56:16 -0700498 if (hw->mac_type != e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 /* tbi_compatibility is only valid on 82543 */
Joe Perchesc3033b02008-03-21 11:06:25 -0700500 hw->tbi_compatibility_en = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 }
502
503 switch (hw->device_id) {
504 case E1000_DEV_ID_82545GM_SERDES:
505 case E1000_DEV_ID_82546GB_SERDES:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400506 case E1000_DEV_ID_82571EB_SERDES:
Auke Kokce57a022007-08-09 14:09:34 -0700507 case E1000_DEV_ID_82571EB_SERDES_DUAL:
508 case E1000_DEV_ID_82571EB_SERDES_QUAD:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400509 case E1000_DEV_ID_82572EI_SERDES:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800510 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 hw->media_type = e1000_media_type_internal_serdes;
512 break;
513 default:
Malli Chilakala3893d542005-06-17 17:44:49 -0700514 switch (hw->mac_type) {
515 case e1000_82542_rev2_0:
516 case e1000_82542_rev2_1:
517 hw->media_type = e1000_media_type_fiber;
518 break;
Auke Kokcd94dd02006-06-27 09:08:22 -0700519 case e1000_ich8lan:
Malli Chilakala3893d542005-06-17 17:44:49 -0700520 case e1000_82573:
521 /* The STATUS_TBIMODE bit is reserved or reused for the this
522 * device.
523 */
524 hw->media_type = e1000_media_type_copper;
525 break;
526 default:
Joe Perches1dc32912008-07-11 15:17:08 -0700527 status = er32(STATUS);
Malli Chilakala3893d542005-06-17 17:44:49 -0700528 if (status & E1000_STATUS_TBIMODE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 hw->media_type = e1000_media_type_fiber;
530 /* tbi_compatibility not valid on fiber */
Joe Perchesc3033b02008-03-21 11:06:25 -0700531 hw->tbi_compatibility_en = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 } else {
533 hw->media_type = e1000_media_type_copper;
534 }
Malli Chilakala3893d542005-06-17 17:44:49 -0700535 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 }
537 }
538}
539
540/******************************************************************************
541 * Reset the transmit and receive units; mask and clear all interrupts.
542 *
543 * hw - Struct containing variables accessed by shared code
544 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -0700545s32 e1000_reset_hw(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546{
Joe Perches406874a2008-04-03 10:06:32 -0700547 u32 ctrl;
548 u32 ctrl_ext;
549 u32 icr;
550 u32 manc;
551 u32 led_ctrl;
552 u32 timeout;
553 u32 extcnf_ctrl;
554 s32 ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555
556 DEBUGFUNC("e1000_reset_hw");
557
558 /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
Auke Kok8fc897b2006-08-28 14:56:16 -0700559 if (hw->mac_type == e1000_82542_rev2_0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
561 e1000_pci_clear_mwi(hw);
562 }
563
Auke Kok8fc897b2006-08-28 14:56:16 -0700564 if (hw->bus_type == e1000_bus_type_pci_express) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700565 /* Prevent the PCI-E bus from sticking if there is no TLP connection
566 * on the last TLP read/write transaction when MAC is reset.
567 */
Auke Kok8fc897b2006-08-28 14:56:16 -0700568 if (e1000_disable_pciex_master(hw) != E1000_SUCCESS) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700569 DEBUGOUT("PCI-E Master disable polling has failed.\n");
570 }
571 }
572
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 /* Clear interrupt mask to stop board from generating interrupts */
574 DEBUGOUT("Masking off all interrupts\n");
Joe Perches1dc32912008-07-11 15:17:08 -0700575 ew32(IMC, 0xffffffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576
577 /* Disable the Transmit and Receive units. Then delay to allow
578 * any pending transactions to complete before we hit the MAC with
579 * the global reset.
580 */
Joe Perches1dc32912008-07-11 15:17:08 -0700581 ew32(RCTL, 0);
582 ew32(TCTL, E1000_TCTL_PSP);
583 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584
585 /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
Joe Perchesc3033b02008-03-21 11:06:25 -0700586 hw->tbi_compatibility_on = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587
588 /* Delay to allow any outstanding PCI transactions to complete before
589 * resetting the device
590 */
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400591 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592
Joe Perches1dc32912008-07-11 15:17:08 -0700593 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594
595 /* Must reset the PHY before resetting the MAC */
Auke Kok8fc897b2006-08-28 14:56:16 -0700596 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
Joe Perches1dc32912008-07-11 15:17:08 -0700597 ew32(CTRL, (ctrl | E1000_CTRL_PHY_RST));
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400598 msleep(5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 }
600
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700601 /* Must acquire the MDIO ownership before MAC reset.
602 * Ownership defaults to firmware after a reset. */
Auke Kok8fc897b2006-08-28 14:56:16 -0700603 if (hw->mac_type == e1000_82573) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700604 timeout = 10;
605
Joe Perches1dc32912008-07-11 15:17:08 -0700606 extcnf_ctrl = er32(EXTCNF_CTRL);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700607 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
608
609 do {
Joe Perches1dc32912008-07-11 15:17:08 -0700610 ew32(EXTCNF_CTRL, extcnf_ctrl);
611 extcnf_ctrl = er32(EXTCNF_CTRL);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700612
Auke Kok8fc897b2006-08-28 14:56:16 -0700613 if (extcnf_ctrl & E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP)
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700614 break;
615 else
616 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
617
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400618 msleep(2);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700619 timeout--;
Auke Kok8fc897b2006-08-28 14:56:16 -0700620 } while (timeout);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700621 }
622
Auke Kokcd94dd02006-06-27 09:08:22 -0700623 /* Workaround for ICH8 bit corruption issue in FIFO memory */
624 if (hw->mac_type == e1000_ich8lan) {
625 /* Set Tx and Rx buffer allocation to 8k apiece. */
Joe Perches1dc32912008-07-11 15:17:08 -0700626 ew32(PBA, E1000_PBA_8K);
Auke Kokcd94dd02006-06-27 09:08:22 -0700627 /* Set Packet Buffer Size to 16k. */
Joe Perches1dc32912008-07-11 15:17:08 -0700628 ew32(PBS, E1000_PBS_16K);
Auke Kokcd94dd02006-06-27 09:08:22 -0700629 }
630
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 /* Issue a global reset to the MAC. This will reset the chip's
632 * transmit, receive, DMA, and link units. It will not effect
633 * the current PCI configuration. The global reset bit is self-
634 * clearing, and should clear within a microsecond.
635 */
636 DEBUGOUT("Issuing a global reset to MAC\n");
637
Auke Kok8fc897b2006-08-28 14:56:16 -0700638 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 case e1000_82544:
640 case e1000_82540:
641 case e1000_82545:
642 case e1000_82546:
643 case e1000_82541:
644 case e1000_82541_rev_2:
645 /* These controllers can't ack the 64-bit write when issuing the
646 * reset, so use IO-mapping as a workaround to issue the reset */
647 E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
648 break;
649 case e1000_82545_rev_3:
650 case e1000_82546_rev_3:
651 /* Reset is performed on a shadow of the control register */
Joe Perches1dc32912008-07-11 15:17:08 -0700652 ew32(CTRL_DUP, (ctrl | E1000_CTRL_RST));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 break;
Auke Kokcd94dd02006-06-27 09:08:22 -0700654 case e1000_ich8lan:
655 if (!hw->phy_reset_disable &&
656 e1000_check_phy_reset_block(hw) == E1000_SUCCESS) {
657 /* e1000_ich8lan PHY HW reset requires MAC CORE reset
658 * at the same time to make sure the interface between
659 * MAC and the external PHY is reset.
660 */
661 ctrl |= E1000_CTRL_PHY_RST;
662 }
663
664 e1000_get_software_flag(hw);
Joe Perches1dc32912008-07-11 15:17:08 -0700665 ew32(CTRL, (ctrl | E1000_CTRL_RST));
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400666 msleep(5);
Auke Kokcd94dd02006-06-27 09:08:22 -0700667 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 default:
Joe Perches1dc32912008-07-11 15:17:08 -0700669 ew32(CTRL, (ctrl | E1000_CTRL_RST));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 break;
671 }
672
673 /* After MAC reset, force reload of EEPROM to restore power-on settings to
674 * device. Later controllers reload the EEPROM automatically, so just wait
675 * for reload to complete.
676 */
Auke Kok8fc897b2006-08-28 14:56:16 -0700677 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 case e1000_82542_rev2_0:
679 case e1000_82542_rev2_1:
680 case e1000_82543:
681 case e1000_82544:
682 /* Wait for reset to complete */
683 udelay(10);
Joe Perches1dc32912008-07-11 15:17:08 -0700684 ctrl_ext = er32(CTRL_EXT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
Joe Perches1dc32912008-07-11 15:17:08 -0700686 ew32(CTRL_EXT, ctrl_ext);
687 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 /* Wait for EEPROM reload */
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400689 msleep(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 break;
691 case e1000_82541:
692 case e1000_82541_rev_2:
693 case e1000_82547:
694 case e1000_82547_rev_2:
695 /* Wait for EEPROM reload */
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400696 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700698 case e1000_82573:
Joe Perchesc3033b02008-03-21 11:06:25 -0700699 if (!e1000_is_onboard_nvm_eeprom(hw)) {
Jeff Kirsherfd803242005-12-13 00:06:22 -0500700 udelay(10);
Joe Perches1dc32912008-07-11 15:17:08 -0700701 ctrl_ext = er32(CTRL_EXT);
Jeff Kirsherfd803242005-12-13 00:06:22 -0500702 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
Joe Perches1dc32912008-07-11 15:17:08 -0700703 ew32(CTRL_EXT, ctrl_ext);
704 E1000_WRITE_FLUSH();
Jeff Kirsherfd803242005-12-13 00:06:22 -0500705 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700706 /* fall through */
Jeff Kirsher2a88c172006-09-27 12:54:05 -0700707 default:
708 /* Auto read done will delay 5ms or poll based on mac type */
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700709 ret_val = e1000_get_auto_rd_done(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -0700710 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700711 return ret_val;
712 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 }
714
715 /* Disable HW ARPs on ASF enabled adapters */
Auke Kok8fc897b2006-08-28 14:56:16 -0700716 if (hw->mac_type >= e1000_82540 && hw->mac_type <= e1000_82547_rev_2) {
Joe Perches1dc32912008-07-11 15:17:08 -0700717 manc = er32(MANC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 manc &= ~(E1000_MANC_ARP_EN);
Joe Perches1dc32912008-07-11 15:17:08 -0700719 ew32(MANC, manc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 }
721
Auke Kok8fc897b2006-08-28 14:56:16 -0700722 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 e1000_phy_init_script(hw);
724
725 /* Configure activity LED after PHY reset */
Joe Perches1dc32912008-07-11 15:17:08 -0700726 led_ctrl = er32(LEDCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 led_ctrl &= IGP_ACTIVITY_LED_MASK;
728 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
Joe Perches1dc32912008-07-11 15:17:08 -0700729 ew32(LEDCTL, led_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 }
731
732 /* Clear interrupt mask to stop board from generating interrupts */
733 DEBUGOUT("Masking off all interrupts\n");
Joe Perches1dc32912008-07-11 15:17:08 -0700734 ew32(IMC, 0xffffffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735
736 /* Clear any pending interrupt events. */
Joe Perches1dc32912008-07-11 15:17:08 -0700737 icr = er32(ICR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738
739 /* If MWI was previously enabled, reenable it. */
Auke Kok8fc897b2006-08-28 14:56:16 -0700740 if (hw->mac_type == e1000_82542_rev2_0) {
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400741 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 e1000_pci_set_mwi(hw);
743 }
744
Auke Kokcd94dd02006-06-27 09:08:22 -0700745 if (hw->mac_type == e1000_ich8lan) {
Joe Perches1dc32912008-07-11 15:17:08 -0700746 u32 kab = er32(KABGTXD);
Auke Kokcd94dd02006-06-27 09:08:22 -0700747 kab |= E1000_KABGTXD_BGSQLBIAS;
Joe Perches1dc32912008-07-11 15:17:08 -0700748 ew32(KABGTXD, kab);
Auke Kokcd94dd02006-06-27 09:08:22 -0700749 }
750
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 return E1000_SUCCESS;
752}
753
754/******************************************************************************
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700755 *
756 * Initialize a number of hardware-dependent bits
757 *
758 * hw: Struct containing variables accessed by shared code
759 *
760 * This function contains hardware limitation workarounds for PCI-E adapters
761 *
762 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -0700763static void e1000_initialize_hardware_bits(struct e1000_hw *hw)
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700764{
765 if ((hw->mac_type >= e1000_82571) && (!hw->initialize_hw_bits_disable)) {
766 /* Settings common to all PCI-express silicon */
Joe Perches406874a2008-04-03 10:06:32 -0700767 u32 reg_ctrl, reg_ctrl_ext;
768 u32 reg_tarc0, reg_tarc1;
769 u32 reg_tctl;
770 u32 reg_txdctl, reg_txdctl1;
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700771
772 /* link autonegotiation/sync workarounds */
Joe Perches1dc32912008-07-11 15:17:08 -0700773 reg_tarc0 = er32(TARC0);
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700774 reg_tarc0 &= ~((1 << 30)|(1 << 29)|(1 << 28)|(1 << 27));
775
776 /* Enable not-done TX descriptor counting */
Joe Perches1dc32912008-07-11 15:17:08 -0700777 reg_txdctl = er32(TXDCTL);
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700778 reg_txdctl |= E1000_TXDCTL_COUNT_DESC;
Joe Perches1dc32912008-07-11 15:17:08 -0700779 ew32(TXDCTL, reg_txdctl);
780 reg_txdctl1 = er32(TXDCTL1);
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700781 reg_txdctl1 |= E1000_TXDCTL_COUNT_DESC;
Joe Perches1dc32912008-07-11 15:17:08 -0700782 ew32(TXDCTL1, reg_txdctl1);
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700783
784 switch (hw->mac_type) {
785 case e1000_82571:
786 case e1000_82572:
787 /* Clear PHY TX compatible mode bits */
Joe Perches1dc32912008-07-11 15:17:08 -0700788 reg_tarc1 = er32(TARC1);
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700789 reg_tarc1 &= ~((1 << 30)|(1 << 29));
790
791 /* link autonegotiation/sync workarounds */
792 reg_tarc0 |= ((1 << 26)|(1 << 25)|(1 << 24)|(1 << 23));
793
794 /* TX ring control fixes */
795 reg_tarc1 |= ((1 << 26)|(1 << 25)|(1 << 24));
796
797 /* Multiple read bit is reversed polarity */
Joe Perches1dc32912008-07-11 15:17:08 -0700798 reg_tctl = er32(TCTL);
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700799 if (reg_tctl & E1000_TCTL_MULR)
800 reg_tarc1 &= ~(1 << 28);
801 else
802 reg_tarc1 |= (1 << 28);
803
Joe Perches1dc32912008-07-11 15:17:08 -0700804 ew32(TARC1, reg_tarc1);
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700805 break;
806 case e1000_82573:
Joe Perches1dc32912008-07-11 15:17:08 -0700807 reg_ctrl_ext = er32(CTRL_EXT);
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700808 reg_ctrl_ext &= ~(1 << 23);
809 reg_ctrl_ext |= (1 << 22);
810
811 /* TX byte count fix */
Joe Perches1dc32912008-07-11 15:17:08 -0700812 reg_ctrl = er32(CTRL);
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700813 reg_ctrl &= ~(1 << 29);
814
Joe Perches1dc32912008-07-11 15:17:08 -0700815 ew32(CTRL_EXT, reg_ctrl_ext);
816 ew32(CTRL, reg_ctrl);
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700817 break;
818 case e1000_80003es2lan:
819 /* improve small packet performace for fiber/serdes */
820 if ((hw->media_type == e1000_media_type_fiber) ||
821 (hw->media_type == e1000_media_type_internal_serdes)) {
822 reg_tarc0 &= ~(1 << 20);
823 }
824
825 /* Multiple read bit is reversed polarity */
Joe Perches1dc32912008-07-11 15:17:08 -0700826 reg_tctl = er32(TCTL);
827 reg_tarc1 = er32(TARC1);
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700828 if (reg_tctl & E1000_TCTL_MULR)
829 reg_tarc1 &= ~(1 << 28);
830 else
831 reg_tarc1 |= (1 << 28);
832
Joe Perches1dc32912008-07-11 15:17:08 -0700833 ew32(TARC1, reg_tarc1);
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700834 break;
835 case e1000_ich8lan:
836 /* Reduce concurrent DMA requests to 3 from 4 */
837 if ((hw->revision_id < 3) ||
838 ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) &&
839 (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))
840 reg_tarc0 |= ((1 << 29)|(1 << 28));
841
Joe Perches1dc32912008-07-11 15:17:08 -0700842 reg_ctrl_ext = er32(CTRL_EXT);
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700843 reg_ctrl_ext |= (1 << 22);
Joe Perches1dc32912008-07-11 15:17:08 -0700844 ew32(CTRL_EXT, reg_ctrl_ext);
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700845
846 /* workaround TX hang with TSO=on */
847 reg_tarc0 |= ((1 << 27)|(1 << 26)|(1 << 24)|(1 << 23));
848
849 /* Multiple read bit is reversed polarity */
Joe Perches1dc32912008-07-11 15:17:08 -0700850 reg_tctl = er32(TCTL);
851 reg_tarc1 = er32(TARC1);
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700852 if (reg_tctl & E1000_TCTL_MULR)
853 reg_tarc1 &= ~(1 << 28);
854 else
855 reg_tarc1 |= (1 << 28);
856
857 /* workaround TX hang with TSO=on */
858 reg_tarc1 |= ((1 << 30)|(1 << 26)|(1 << 24));
859
Joe Perches1dc32912008-07-11 15:17:08 -0700860 ew32(TARC1, reg_tarc1);
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700861 break;
862 default:
863 break;
864 }
865
Joe Perches1dc32912008-07-11 15:17:08 -0700866 ew32(TARC0, reg_tarc0);
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700867 }
868}
869
870/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 * Performs basic configuration of the adapter.
872 *
873 * hw - Struct containing variables accessed by shared code
874 *
875 * Assumes that the controller has previously been reset and is in a
876 * post-reset uninitialized state. Initializes the receive address registers,
877 * multicast table, and VLAN filter table. Calls routines to setup link
878 * configuration and flow control settings. Clears all on-chip counters. Leaves
879 * the transmit and receive units disabled and uninitialized.
880 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -0700881s32 e1000_init_hw(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882{
Joe Perches406874a2008-04-03 10:06:32 -0700883 u32 ctrl;
884 u32 i;
885 s32 ret_val;
886 u32 mta_size;
887 u32 reg_data;
888 u32 ctrl_ext;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700889
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 DEBUGFUNC("e1000_init_hw");
891
Jeff Kirsher7820d422006-08-16 13:39:00 -0700892 /* force full DMA clock frequency for 10/100 on ICH8 A0-B0 */
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700893 if ((hw->mac_type == e1000_ich8lan) &&
894 ((hw->revision_id < 3) ||
895 ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) &&
896 (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))) {
Joe Perches1dc32912008-07-11 15:17:08 -0700897 reg_data = er32(STATUS);
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700898 reg_data &= ~0x80000000;
Joe Perches1dc32912008-07-11 15:17:08 -0700899 ew32(STATUS, reg_data);
Jeff Kirsher7820d422006-08-16 13:39:00 -0700900 }
901
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 /* Initialize Identification LED */
903 ret_val = e1000_id_led_init(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -0700904 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 DEBUGOUT("Error Initializing Identification LED\n");
906 return ret_val;
907 }
908
909 /* Set the media type and TBI compatibility */
910 e1000_set_media_type(hw);
911
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700912 /* Must be called after e1000_set_media_type because media_type is used */
913 e1000_initialize_hardware_bits(hw);
914
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 /* Disabling VLAN filtering. */
916 DEBUGOUT("Initializing the IEEE VLAN\n");
Auke Kokcd94dd02006-06-27 09:08:22 -0700917 /* VET hardcoded to standard value and VFTA removed in ICH8 LAN */
918 if (hw->mac_type != e1000_ich8lan) {
919 if (hw->mac_type < e1000_82545_rev_3)
Joe Perches1dc32912008-07-11 15:17:08 -0700920 ew32(VET, 0);
Auke Kokcd94dd02006-06-27 09:08:22 -0700921 e1000_clear_vfta(hw);
922 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923
924 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
Auke Kok8fc897b2006-08-28 14:56:16 -0700925 if (hw->mac_type == e1000_82542_rev2_0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
927 e1000_pci_clear_mwi(hw);
Joe Perches1dc32912008-07-11 15:17:08 -0700928 ew32(RCTL, E1000_RCTL_RST);
929 E1000_WRITE_FLUSH();
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400930 msleep(5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 }
932
933 /* Setup the receive address. This involves initializing all of the Receive
934 * Address Registers (RARs 0 - 15).
935 */
936 e1000_init_rx_addrs(hw);
937
938 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
Auke Kok8fc897b2006-08-28 14:56:16 -0700939 if (hw->mac_type == e1000_82542_rev2_0) {
Joe Perches1dc32912008-07-11 15:17:08 -0700940 ew32(RCTL, 0);
941 E1000_WRITE_FLUSH();
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400942 msleep(1);
943 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944 e1000_pci_set_mwi(hw);
945 }
946
947 /* Zero out the Multicast HASH table */
948 DEBUGOUT("Zeroing the MTA\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700949 mta_size = E1000_MC_TBL_SIZE;
Auke Kokcd94dd02006-06-27 09:08:22 -0700950 if (hw->mac_type == e1000_ich8lan)
951 mta_size = E1000_MC_TBL_SIZE_ICH8LAN;
Auke Kok8fc897b2006-08-28 14:56:16 -0700952 for (i = 0; i < mta_size; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -0700954 /* use write flush to prevent Memory Write Block (MWB) from
955 * occuring when accessing our register space */
Joe Perches1dc32912008-07-11 15:17:08 -0700956 E1000_WRITE_FLUSH();
Auke Kok4ca213a2006-06-27 09:07:08 -0700957 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958
959 /* Set the PCI priority bit correctly in the CTRL register. This
960 * determines if the adapter gives priority to receives, or if it
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700961 * gives equal priority to transmits and receives. Valid only on
962 * 82542 and 82543 silicon.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 */
Auke Kok8fc897b2006-08-28 14:56:16 -0700964 if (hw->dma_fairness && hw->mac_type <= e1000_82543) {
Joe Perches1dc32912008-07-11 15:17:08 -0700965 ctrl = er32(CTRL);
966 ew32(CTRL, ctrl | E1000_CTRL_PRIOR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 }
968
Auke Kok8fc897b2006-08-28 14:56:16 -0700969 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 case e1000_82545_rev_3:
971 case e1000_82546_rev_3:
972 break;
973 default:
974 /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
Peter Oruba007755e2007-09-28 22:42:06 -0700975 if (hw->bus_type == e1000_bus_type_pcix && e1000_pcix_get_mmrbc(hw) > 2048)
976 e1000_pcix_set_mmrbc(hw, 2048);
977 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978 }
979
Auke Kokcd94dd02006-06-27 09:08:22 -0700980 /* More time needed for PHY to initialize */
981 if (hw->mac_type == e1000_ich8lan)
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400982 msleep(15);
Auke Kokcd94dd02006-06-27 09:08:22 -0700983
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 /* Call a subroutine to configure the link and setup flow control. */
985 ret_val = e1000_setup_link(hw);
986
987 /* Set the transmit descriptor write-back policy */
Auke Kok8fc897b2006-08-28 14:56:16 -0700988 if (hw->mac_type > e1000_82544) {
Joe Perches1dc32912008-07-11 15:17:08 -0700989 ctrl = er32(TXDCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
Joe Perches1dc32912008-07-11 15:17:08 -0700991 ew32(TXDCTL, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 }
993
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700994 if (hw->mac_type == e1000_82573) {
Auke Kok76c224b2006-05-23 13:36:06 -0700995 e1000_enable_tx_pkt_filtering(hw);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700996 }
997
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400998 switch (hw->mac_type) {
999 default:
1000 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001001 case e1000_80003es2lan:
1002 /* Enable retransmit on late collisions */
Joe Perches1dc32912008-07-11 15:17:08 -07001003 reg_data = er32(TCTL);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001004 reg_data |= E1000_TCTL_RTLC;
Joe Perches1dc32912008-07-11 15:17:08 -07001005 ew32(TCTL, reg_data);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001006
1007 /* Configure Gigabit Carry Extend Padding */
Joe Perches1dc32912008-07-11 15:17:08 -07001008 reg_data = er32(TCTL_EXT);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001009 reg_data &= ~E1000_TCTL_EXT_GCEX_MASK;
1010 reg_data |= DEFAULT_80003ES2LAN_TCTL_EXT_GCEX;
Joe Perches1dc32912008-07-11 15:17:08 -07001011 ew32(TCTL_EXT, reg_data);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001012
1013 /* Configure Transmit Inter-Packet Gap */
Joe Perches1dc32912008-07-11 15:17:08 -07001014 reg_data = er32(TIPG);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001015 reg_data &= ~E1000_TIPG_IPGT_MASK;
1016 reg_data |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
Joe Perches1dc32912008-07-11 15:17:08 -07001017 ew32(TIPG, reg_data);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001018
1019 reg_data = E1000_READ_REG_ARRAY(hw, FFLT, 0x0001);
1020 reg_data &= ~0x00100000;
1021 E1000_WRITE_REG_ARRAY(hw, FFLT, 0x0001, reg_data);
1022 /* Fall through */
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001023 case e1000_82571:
Mallikarjuna R Chilakalaa7990ba2005-10-04 07:08:19 -04001024 case e1000_82572:
Auke Kokcd94dd02006-06-27 09:08:22 -07001025 case e1000_ich8lan:
Joe Perches1dc32912008-07-11 15:17:08 -07001026 ctrl = er32(TXDCTL1);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001027 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
Joe Perches1dc32912008-07-11 15:17:08 -07001028 ew32(TXDCTL1, ctrl);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001029 break;
1030 }
1031
1032
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001033 if (hw->mac_type == e1000_82573) {
Joe Perches1dc32912008-07-11 15:17:08 -07001034 u32 gcr = er32(GCR);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001035 gcr |= E1000_GCR_L1_ACT_WITHOUT_L0S_RX;
Joe Perches1dc32912008-07-11 15:17:08 -07001036 ew32(GCR, gcr);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001037 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001038
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 /* Clear all of the statistics registers (clear on read). It is
1040 * important that we do this after we have tried to establish link
1041 * because the symbol error count will increment wildly if there
1042 * is no link.
1043 */
1044 e1000_clear_hw_cntrs(hw);
1045
Auke Kokcd94dd02006-06-27 09:08:22 -07001046 /* ICH8 No-snoop bits are opposite polarity.
1047 * Set to snoop by default after reset. */
1048 if (hw->mac_type == e1000_ich8lan)
1049 e1000_set_pci_ex_no_snoop(hw, PCI_EX_82566_SNOOP_ALL);
1050
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -08001051 if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER ||
1052 hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) {
Joe Perches1dc32912008-07-11 15:17:08 -07001053 ctrl_ext = er32(CTRL_EXT);
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -08001054 /* Relaxed ordering must be disabled to avoid a parity
1055 * error crash in a PCI slot. */
1056 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
Joe Perches1dc32912008-07-11 15:17:08 -07001057 ew32(CTRL_EXT, ctrl_ext);
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -08001058 }
1059
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 return ret_val;
1061}
1062
1063/******************************************************************************
1064 * Adjust SERDES output amplitude based on EEPROM setting.
1065 *
1066 * hw - Struct containing variables accessed by shared code.
1067 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07001068static s32 e1000_adjust_serdes_amplitude(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069{
Joe Perches406874a2008-04-03 10:06:32 -07001070 u16 eeprom_data;
1071 s32 ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072
1073 DEBUGFUNC("e1000_adjust_serdes_amplitude");
1074
Auke Kok8fc897b2006-08-28 14:56:16 -07001075 if (hw->media_type != e1000_media_type_internal_serdes)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 return E1000_SUCCESS;
1077
Auke Kok8fc897b2006-08-28 14:56:16 -07001078 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 case e1000_82545_rev_3:
1080 case e1000_82546_rev_3:
1081 break;
1082 default:
1083 return E1000_SUCCESS;
1084 }
1085
1086 ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1, &eeprom_data);
1087 if (ret_val) {
1088 return ret_val;
1089 }
1090
Auke Kok8fc897b2006-08-28 14:56:16 -07001091 if (eeprom_data != EEPROM_RESERVED_WORD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 /* Adjust SERDES output amplitude only. */
Auke Kok76c224b2006-05-23 13:36:06 -07001093 eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001095 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 return ret_val;
1097 }
1098
1099 return E1000_SUCCESS;
1100}
1101
1102/******************************************************************************
1103 * Configures flow control and link settings.
1104 *
1105 * hw - Struct containing variables accessed by shared code
1106 *
1107 * Determines which flow control settings to use. Calls the apropriate media-
1108 * specific link configuration function. Configures the flow control settings.
1109 * Assuming the adapter has a valid link partner, a valid link should be
1110 * established. Assumes the hardware has previously been reset and the
1111 * transmitter and receiver are not enabled.
1112 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07001113s32 e1000_setup_link(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114{
Joe Perches406874a2008-04-03 10:06:32 -07001115 u32 ctrl_ext;
1116 s32 ret_val;
1117 u16 eeprom_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118
1119 DEBUGFUNC("e1000_setup_link");
1120
Jeff Kirsher526f9952006-01-12 16:50:46 -08001121 /* In the case of the phy reset being blocked, we already have a link.
1122 * We do not have to set it up again. */
1123 if (e1000_check_phy_reset_block(hw))
1124 return E1000_SUCCESS;
1125
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 /* Read and store word 0x0F of the EEPROM. This word contains bits
1127 * that determine the hardware's default PAUSE (flow control) mode,
1128 * a bit that determines whether the HW defaults to enabling or
1129 * disabling auto-negotiation, and the direction of the
1130 * SW defined pins. If there is no SW over-ride of the flow
1131 * control setting, then the variable hw->fc will
1132 * be initialized based on a value in the EEPROM.
1133 */
Jeff Kirsher11241b12006-09-27 12:53:28 -07001134 if (hw->fc == E1000_FC_DEFAULT) {
Jeff Kirsherfd803242005-12-13 00:06:22 -05001135 switch (hw->mac_type) {
Auke Kokcd94dd02006-06-27 09:08:22 -07001136 case e1000_ich8lan:
Jeff Kirsherfd803242005-12-13 00:06:22 -05001137 case e1000_82573:
Jeff Kirsher11241b12006-09-27 12:53:28 -07001138 hw->fc = E1000_FC_FULL;
Jeff Kirsherfd803242005-12-13 00:06:22 -05001139 break;
1140 default:
1141 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
1142 1, &eeprom_data);
1143 if (ret_val) {
1144 DEBUGOUT("EEPROM Read Error\n");
1145 return -E1000_ERR_EEPROM;
1146 }
1147 if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
Jeff Kirsher11241b12006-09-27 12:53:28 -07001148 hw->fc = E1000_FC_NONE;
Jeff Kirsherfd803242005-12-13 00:06:22 -05001149 else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
1150 EEPROM_WORD0F_ASM_DIR)
Jeff Kirsher11241b12006-09-27 12:53:28 -07001151 hw->fc = E1000_FC_TX_PAUSE;
Jeff Kirsherfd803242005-12-13 00:06:22 -05001152 else
Jeff Kirsher11241b12006-09-27 12:53:28 -07001153 hw->fc = E1000_FC_FULL;
Jeff Kirsherfd803242005-12-13 00:06:22 -05001154 break;
1155 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156 }
1157
1158 /* We want to save off the original Flow Control configuration just
1159 * in case we get disconnected and then reconnected into a different
1160 * hub or switch with different Flow Control capabilities.
1161 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001162 if (hw->mac_type == e1000_82542_rev2_0)
Jeff Kirsher11241b12006-09-27 12:53:28 -07001163 hw->fc &= (~E1000_FC_TX_PAUSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164
Auke Kok8fc897b2006-08-28 14:56:16 -07001165 if ((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
Jeff Kirsher11241b12006-09-27 12:53:28 -07001166 hw->fc &= (~E1000_FC_RX_PAUSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167
1168 hw->original_fc = hw->fc;
1169
1170 DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc);
1171
1172 /* Take the 4 bits from EEPROM word 0x0F that determine the initial
1173 * polarity value for the SW controlled pins, and setup the
1174 * Extended Device Control reg with that info.
1175 * This is needed because one of the SW controlled pins is used for
1176 * signal detection. So this should be done before e1000_setup_pcs_link()
1177 * or e1000_phy_setup() is called.
1178 */
Jeff Kirsher497fce52006-03-02 18:18:20 -08001179 if (hw->mac_type == e1000_82543) {
Auke Kok8fc897b2006-08-28 14:56:16 -07001180 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
1181 1, &eeprom_data);
1182 if (ret_val) {
1183 DEBUGOUT("EEPROM Read Error\n");
1184 return -E1000_ERR_EEPROM;
1185 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186 ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
1187 SWDPIO__EXT_SHIFT);
Joe Perches1dc32912008-07-11 15:17:08 -07001188 ew32(CTRL_EXT, ctrl_ext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 }
1190
1191 /* Call the necessary subroutine to configure the link. */
1192 ret_val = (hw->media_type == e1000_media_type_copper) ?
1193 e1000_setup_copper_link(hw) :
1194 e1000_setup_fiber_serdes_link(hw);
1195
1196 /* Initialize the flow control address, type, and PAUSE timer
1197 * registers to their default values. This is done even if flow
1198 * control is disabled, because it does not hurt anything to
1199 * initialize these registers.
1200 */
1201 DEBUGOUT("Initializing the Flow Control address, type and timer regs\n");
1202
Auke Kokcd94dd02006-06-27 09:08:22 -07001203 /* FCAL/H and FCT are hardcoded to standard values in e1000_ich8lan. */
1204 if (hw->mac_type != e1000_ich8lan) {
Joe Perches1dc32912008-07-11 15:17:08 -07001205 ew32(FCT, FLOW_CONTROL_TYPE);
1206 ew32(FCAH, FLOW_CONTROL_ADDRESS_HIGH);
1207 ew32(FCAL, FLOW_CONTROL_ADDRESS_LOW);
Auke Kokcd94dd02006-06-27 09:08:22 -07001208 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001209
Joe Perches1dc32912008-07-11 15:17:08 -07001210 ew32(FCTTV, hw->fc_pause_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211
1212 /* Set the flow control receive threshold registers. Normally,
1213 * these registers will be set to a default threshold that may be
1214 * adjusted later by the driver's runtime code. However, if the
1215 * ability to transmit pause frames in not enabled, then these
1216 * registers will be set to 0.
1217 */
Jeff Kirsher11241b12006-09-27 12:53:28 -07001218 if (!(hw->fc & E1000_FC_TX_PAUSE)) {
Joe Perches1dc32912008-07-11 15:17:08 -07001219 ew32(FCRTL, 0);
1220 ew32(FCRTH, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221 } else {
1222 /* We need to set up the Receive Threshold high and low water marks
1223 * as well as (optionally) enabling the transmission of XON frames.
1224 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001225 if (hw->fc_send_xon) {
Joe Perches1dc32912008-07-11 15:17:08 -07001226 ew32(FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE));
1227 ew32(FCRTH, hw->fc_high_water);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228 } else {
Joe Perches1dc32912008-07-11 15:17:08 -07001229 ew32(FCRTL, hw->fc_low_water);
1230 ew32(FCRTH, hw->fc_high_water);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231 }
1232 }
1233 return ret_val;
1234}
1235
1236/******************************************************************************
1237 * Sets up link for a fiber based or serdes based adapter
1238 *
1239 * hw - Struct containing variables accessed by shared code
1240 *
1241 * Manipulates Physical Coding Sublayer functions in order to configure
1242 * link. Assumes the hardware has been previously reset and the transmitter
1243 * and receiver are not enabled.
1244 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07001245static s32 e1000_setup_fiber_serdes_link(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246{
Joe Perches406874a2008-04-03 10:06:32 -07001247 u32 ctrl;
1248 u32 status;
1249 u32 txcw = 0;
1250 u32 i;
1251 u32 signal = 0;
1252 s32 ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253
1254 DEBUGFUNC("e1000_setup_fiber_serdes_link");
1255
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001256 /* On 82571 and 82572 Fiber connections, SerDes loopback mode persists
1257 * until explicitly turned off or a power cycle is performed. A read to
1258 * the register does not indicate its status. Therefore, we ensure
1259 * loopback mode is disabled during initialization.
1260 */
1261 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572)
Joe Perches1dc32912008-07-11 15:17:08 -07001262 ew32(SCTL, E1000_DISABLE_SERDES_LOOPBACK);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001263
Jeff Kirsher09ae3e82006-09-27 12:53:51 -07001264 /* On adapters with a MAC newer than 82544, SWDP 1 will be
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265 * set when the optics detect a signal. On older adapters, it will be
1266 * cleared when there is a signal. This applies to fiber media only.
Jeff Kirsher09ae3e82006-09-27 12:53:51 -07001267 * If we're on serdes media, adjust the output amplitude to value
1268 * set in the EEPROM.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 */
Joe Perches1dc32912008-07-11 15:17:08 -07001270 ctrl = er32(CTRL);
Auke Kok8fc897b2006-08-28 14:56:16 -07001271 if (hw->media_type == e1000_media_type_fiber)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
1273
1274 ret_val = e1000_adjust_serdes_amplitude(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001275 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276 return ret_val;
1277
1278 /* Take the link out of reset */
1279 ctrl &= ~(E1000_CTRL_LRST);
1280
1281 /* Adjust VCO speed to improve BER performance */
1282 ret_val = e1000_set_vco_speed(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001283 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284 return ret_val;
1285
1286 e1000_config_collision_dist(hw);
1287
1288 /* Check for a software override of the flow control settings, and setup
1289 * the device accordingly. If auto-negotiation is enabled, then software
1290 * will have to set the "PAUSE" bits to the correct value in the Tranmsit
1291 * Config Word Register (TXCW) and re-start auto-negotiation. However, if
1292 * auto-negotiation is disabled, then software will have to manually
1293 * configure the two flow control enable bits in the CTRL register.
1294 *
1295 * The possible values of the "fc" parameter are:
1296 * 0: Flow control is completely disabled
1297 * 1: Rx flow control is enabled (we can receive pause frames, but
1298 * not send pause frames).
1299 * 2: Tx flow control is enabled (we can send pause frames but we do
1300 * not support receiving pause frames).
1301 * 3: Both Rx and TX flow control (symmetric) are enabled.
1302 */
1303 switch (hw->fc) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07001304 case E1000_FC_NONE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305 /* Flow control is completely disabled by a software over-ride. */
1306 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
1307 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07001308 case E1000_FC_RX_PAUSE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309 /* RX Flow control is enabled and TX Flow control is disabled by a
1310 * software over-ride. Since there really isn't a way to advertise
1311 * that we are capable of RX Pause ONLY, we will advertise that we
1312 * support both symmetric and asymmetric RX PAUSE. Later, we will
1313 * disable the adapter's ability to send PAUSE frames.
1314 */
1315 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1316 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07001317 case E1000_FC_TX_PAUSE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 /* TX Flow control is enabled, and RX Flow control is disabled, by a
1319 * software over-ride.
1320 */
1321 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
1322 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07001323 case E1000_FC_FULL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324 /* Flow control (both RX and TX) is enabled by a software over-ride. */
1325 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1326 break;
1327 default:
1328 DEBUGOUT("Flow control param set incorrectly\n");
1329 return -E1000_ERR_CONFIG;
1330 break;
1331 }
1332
1333 /* Since auto-negotiation is enabled, take the link out of reset (the link
1334 * will be in reset, because we previously reset the chip). This will
1335 * restart auto-negotiation. If auto-neogtiation is successful then the
1336 * link-up status bit will be set and the flow control enable bits (RFCE
1337 * and TFCE) will be set according to their negotiated value.
1338 */
1339 DEBUGOUT("Auto-negotiation enabled\n");
1340
Joe Perches1dc32912008-07-11 15:17:08 -07001341 ew32(TXCW, txcw);
1342 ew32(CTRL, ctrl);
1343 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344
1345 hw->txcw = txcw;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001346 msleep(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347
1348 /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
1349 * indication in the Device Status Register. Time-out if a link isn't
1350 * seen in 500 milliseconds seconds (Auto-negotiation should complete in
1351 * less than 500 milliseconds even if the other end is doing it in SW).
1352 * For internal serdes, we just assume a signal is present, then poll.
1353 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001354 if (hw->media_type == e1000_media_type_internal_serdes ||
Joe Perches1dc32912008-07-11 15:17:08 -07001355 (er32(CTRL) & E1000_CTRL_SWDPIN1) == signal) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356 DEBUGOUT("Looking for Link\n");
Auke Kok8fc897b2006-08-28 14:56:16 -07001357 for (i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001358 msleep(10);
Joe Perches1dc32912008-07-11 15:17:08 -07001359 status = er32(STATUS);
Auke Kok8fc897b2006-08-28 14:56:16 -07001360 if (status & E1000_STATUS_LU) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 }
Auke Kok8fc897b2006-08-28 14:56:16 -07001362 if (i == (LINK_UP_TIMEOUT / 10)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 DEBUGOUT("Never got a valid link from auto-neg!!!\n");
1364 hw->autoneg_failed = 1;
1365 /* AutoNeg failed to achieve a link, so we'll call
1366 * e1000_check_for_link. This routine will force the link up if
1367 * we detect a signal. This will allow us to communicate with
1368 * non-autonegotiating link partners.
1369 */
1370 ret_val = e1000_check_for_link(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001371 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 DEBUGOUT("Error while checking for link\n");
1373 return ret_val;
1374 }
1375 hw->autoneg_failed = 0;
1376 } else {
1377 hw->autoneg_failed = 0;
1378 DEBUGOUT("Valid Link Found\n");
1379 }
1380 } else {
1381 DEBUGOUT("No Signal Detected\n");
1382 }
1383 return E1000_SUCCESS;
1384}
1385
1386/******************************************************************************
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001387* Make sure we have a valid PHY and change PHY mode before link setup.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388*
1389* hw - Struct containing variables accessed by shared code
1390******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07001391static s32 e1000_copper_link_preconfig(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392{
Joe Perches406874a2008-04-03 10:06:32 -07001393 u32 ctrl;
1394 s32 ret_val;
1395 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001397 DEBUGFUNC("e1000_copper_link_preconfig");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398
Joe Perches1dc32912008-07-11 15:17:08 -07001399 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400 /* With 82543, we need to force speed and duplex on the MAC equal to what
1401 * the PHY speed and duplex configuration is. In addition, we need to
1402 * perform a hardware reset on the PHY to take it out of reset.
1403 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001404 if (hw->mac_type > e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405 ctrl |= E1000_CTRL_SLU;
1406 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
Joe Perches1dc32912008-07-11 15:17:08 -07001407 ew32(CTRL, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408 } else {
1409 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
Joe Perches1dc32912008-07-11 15:17:08 -07001410 ew32(CTRL, ctrl);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001411 ret_val = e1000_phy_hw_reset(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001412 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001413 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 }
1415
1416 /* Make sure we have a valid PHY */
1417 ret_val = e1000_detect_gig_phy(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001418 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 DEBUGOUT("Error, did not detect valid phy.\n");
1420 return ret_val;
1421 }
1422 DEBUGOUT1("Phy ID = %x \n", hw->phy_id);
1423
1424 /* Set PHY to class A mode (if necessary) */
1425 ret_val = e1000_set_phy_mode(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001426 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 return ret_val;
1428
Auke Kok8fc897b2006-08-28 14:56:16 -07001429 if ((hw->mac_type == e1000_82545_rev_3) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 (hw->mac_type == e1000_82546_rev_3)) {
1431 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1432 phy_data |= 0x00000008;
1433 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1434 }
1435
Auke Kok8fc897b2006-08-28 14:56:16 -07001436 if (hw->mac_type <= e1000_82543 ||
1437 hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
1438 hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2)
Joe Perchesc3033b02008-03-21 11:06:25 -07001439 hw->phy_reset_disable = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001441 return E1000_SUCCESS;
1442}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001445/********************************************************************
1446* Copper link setup for e1000_phy_igp series.
1447*
1448* hw - Struct containing variables accessed by shared code
1449*********************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07001450static s32 e1000_copper_link_igp_setup(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001451{
Joe Perches406874a2008-04-03 10:06:32 -07001452 u32 led_ctrl;
1453 s32 ret_val;
1454 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001456 DEBUGFUNC("e1000_copper_link_igp_setup");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001458 if (hw->phy_reset_disable)
1459 return E1000_SUCCESS;
Auke Kok76c224b2006-05-23 13:36:06 -07001460
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001461 ret_val = e1000_phy_reset(hw);
1462 if (ret_val) {
1463 DEBUGOUT("Error Resetting the PHY\n");
1464 return ret_val;
1465 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466
Auke Kok8fc897b2006-08-28 14:56:16 -07001467 /* Wait 15ms for MAC to configure PHY from eeprom settings */
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001468 msleep(15);
Auke Kokcd94dd02006-06-27 09:08:22 -07001469 if (hw->mac_type != e1000_ich8lan) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001470 /* Configure activity LED after PHY reset */
Joe Perches1dc32912008-07-11 15:17:08 -07001471 led_ctrl = er32(LEDCTL);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001472 led_ctrl &= IGP_ACTIVITY_LED_MASK;
1473 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
Joe Perches1dc32912008-07-11 15:17:08 -07001474 ew32(LEDCTL, led_ctrl);
Auke Kokcd94dd02006-06-27 09:08:22 -07001475 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001476
Jeff Kirsherc9c1b832006-08-16 13:38:54 -07001477 /* The NVM settings will configure LPLU in D3 for IGP2 and IGP3 PHYs */
1478 if (hw->phy_type == e1000_phy_igp) {
1479 /* disable lplu d3 during driver init */
Joe Perchesc3033b02008-03-21 11:06:25 -07001480 ret_val = e1000_set_d3_lplu_state(hw, false);
Jeff Kirsherc9c1b832006-08-16 13:38:54 -07001481 if (ret_val) {
1482 DEBUGOUT("Error Disabling LPLU D3\n");
1483 return ret_val;
1484 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001485 }
1486
1487 /* disable lplu d0 during driver init */
Joe Perchesc3033b02008-03-21 11:06:25 -07001488 ret_val = e1000_set_d0_lplu_state(hw, false);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001489 if (ret_val) {
1490 DEBUGOUT("Error Disabling LPLU D0\n");
1491 return ret_val;
1492 }
1493 /* Configure mdi-mdix settings */
1494 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1495 if (ret_val)
1496 return ret_val;
1497
1498 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
1499 hw->dsp_config_state = e1000_dsp_config_disabled;
1500 /* Force MDI for earlier revs of the IGP PHY */
1501 phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX | IGP01E1000_PSCR_FORCE_MDI_MDIX);
1502 hw->mdix = 1;
1503
1504 } else {
1505 hw->dsp_config_state = e1000_dsp_config_enabled;
1506 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1507
1508 switch (hw->mdix) {
1509 case 1:
1510 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1511 break;
1512 case 2:
1513 phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
1514 break;
1515 case 0:
1516 default:
1517 phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
1518 break;
1519 }
1520 }
1521 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001522 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001523 return ret_val;
1524
1525 /* set auto-master slave resolution settings */
Auke Kok8fc897b2006-08-28 14:56:16 -07001526 if (hw->autoneg) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001527 e1000_ms_type phy_ms_setting = hw->master_slave;
1528
Auke Kok8fc897b2006-08-28 14:56:16 -07001529 if (hw->ffe_config_state == e1000_ffe_config_active)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001530 hw->ffe_config_state = e1000_ffe_config_enabled;
1531
Auke Kok8fc897b2006-08-28 14:56:16 -07001532 if (hw->dsp_config_state == e1000_dsp_config_activated)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001533 hw->dsp_config_state = e1000_dsp_config_enabled;
1534
1535 /* when autonegotiation advertisment is only 1000Mbps then we
1536 * should disable SmartSpeed and enable Auto MasterSlave
1537 * resolution as hardware default. */
Auke Kok8fc897b2006-08-28 14:56:16 -07001538 if (hw->autoneg_advertised == ADVERTISE_1000_FULL) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001539 /* Disable SmartSpeed */
Auke Kok8fc897b2006-08-28 14:56:16 -07001540 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1541 &phy_data);
1542 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001544 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Auke Kok8fc897b2006-08-28 14:56:16 -07001545 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1546 phy_data);
1547 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001549 /* Set auto Master/Slave resolution process */
1550 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001551 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001552 return ret_val;
1553 phy_data &= ~CR_1000T_MS_ENABLE;
1554 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001555 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001556 return ret_val;
1557 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001559 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001560 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001561 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001563 /* load defaults for future use */
1564 hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
1565 ((phy_data & CR_1000T_MS_VALUE) ?
1566 e1000_ms_force_master :
1567 e1000_ms_force_slave) :
1568 e1000_ms_auto;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001570 switch (phy_ms_setting) {
1571 case e1000_ms_force_master:
1572 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
1573 break;
1574 case e1000_ms_force_slave:
1575 phy_data |= CR_1000T_MS_ENABLE;
1576 phy_data &= ~(CR_1000T_MS_VALUE);
1577 break;
1578 case e1000_ms_auto:
1579 phy_data &= ~CR_1000T_MS_ENABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580 default:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001581 break;
1582 }
1583 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001584 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001585 return ret_val;
Malli Chilakala2b028932005-06-17 17:46:06 -07001586 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587
Malli Chilakala2b028932005-06-17 17:46:06 -07001588 return E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001589}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001591/********************************************************************
1592* Copper link setup for e1000_phy_gg82563 series.
1593*
1594* hw - Struct containing variables accessed by shared code
1595*********************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07001596static s32 e1000_copper_link_ggp_setup(struct e1000_hw *hw)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001597{
Joe Perches406874a2008-04-03 10:06:32 -07001598 s32 ret_val;
1599 u16 phy_data;
1600 u32 reg_data;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001601
1602 DEBUGFUNC("e1000_copper_link_ggp_setup");
1603
Auke Kok8fc897b2006-08-28 14:56:16 -07001604 if (!hw->phy_reset_disable) {
Auke Kok76c224b2006-05-23 13:36:06 -07001605
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001606 /* Enable CRS on TX for half-duplex operation. */
1607 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL,
1608 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001609 if (ret_val)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001610 return ret_val;
1611
1612 phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
1613 /* Use 25MHz for both link down and 1000BASE-T for Tx clock */
1614 phy_data |= GG82563_MSCR_TX_CLK_1000MBPS_25MHZ;
1615
1616 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL,
1617 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001618 if (ret_val)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001619 return ret_val;
1620
1621 /* Options:
1622 * MDI/MDI-X = 0 (default)
1623 * 0 - Auto for all speeds
1624 * 1 - MDI mode
1625 * 2 - MDI-X mode
1626 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1627 */
1628 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001629 if (ret_val)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001630 return ret_val;
1631
1632 phy_data &= ~GG82563_PSCR_CROSSOVER_MODE_MASK;
1633
1634 switch (hw->mdix) {
1635 case 1:
1636 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDI;
1637 break;
1638 case 2:
1639 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDIX;
1640 break;
1641 case 0:
1642 default:
1643 phy_data |= GG82563_PSCR_CROSSOVER_MODE_AUTO;
1644 break;
1645 }
1646
1647 /* Options:
1648 * disable_polarity_correction = 0 (default)
1649 * Automatic Correction for Reversed Cable Polarity
1650 * 0 - Disabled
1651 * 1 - Enabled
1652 */
1653 phy_data &= ~GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
Auke Kok8fc897b2006-08-28 14:56:16 -07001654 if (hw->disable_polarity_correction == 1)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001655 phy_data |= GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
1656 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_SPEC_CTRL, phy_data);
1657
Auke Kok8fc897b2006-08-28 14:56:16 -07001658 if (ret_val)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001659 return ret_val;
1660
1661 /* SW Reset the PHY so all changes take effect */
1662 ret_val = e1000_phy_reset(hw);
1663 if (ret_val) {
1664 DEBUGOUT("Error Resetting the PHY\n");
1665 return ret_val;
1666 }
1667 } /* phy_reset_disable */
1668
1669 if (hw->mac_type == e1000_80003es2lan) {
1670 /* Bypass RX and TX FIFO's */
1671 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_FIFO_CTRL,
1672 E1000_KUMCTRLSTA_FIFO_CTRL_RX_BYPASS |
1673 E1000_KUMCTRLSTA_FIFO_CTRL_TX_BYPASS);
1674 if (ret_val)
1675 return ret_val;
1676
1677 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_SPEC_CTRL_2, &phy_data);
1678 if (ret_val)
1679 return ret_val;
1680
1681 phy_data &= ~GG82563_PSCR2_REVERSE_AUTO_NEG;
1682 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_SPEC_CTRL_2, phy_data);
1683
1684 if (ret_val)
1685 return ret_val;
1686
Joe Perches1dc32912008-07-11 15:17:08 -07001687 reg_data = er32(CTRL_EXT);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001688 reg_data &= ~(E1000_CTRL_EXT_LINK_MODE_MASK);
Joe Perches1dc32912008-07-11 15:17:08 -07001689 ew32(CTRL_EXT, reg_data);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001690
1691 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_PWR_MGMT_CTRL,
1692 &phy_data);
1693 if (ret_val)
1694 return ret_val;
1695
1696 /* Do not init these registers when the HW is in IAMT mode, since the
1697 * firmware will have already initialized them. We only initialize
1698 * them if the HW is not in IAMT mode.
1699 */
Joe Perchesc3033b02008-03-21 11:06:25 -07001700 if (!e1000_check_mng_mode(hw)) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001701 /* Enable Electrical Idle on the PHY */
1702 phy_data |= GG82563_PMCR_ENABLE_ELECTRICAL_IDLE;
1703 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_PWR_MGMT_CTRL,
1704 phy_data);
1705 if (ret_val)
1706 return ret_val;
1707
1708 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
1709 &phy_data);
1710 if (ret_val)
1711 return ret_val;
1712
Auke Kokcd94dd02006-06-27 09:08:22 -07001713 phy_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001714 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
1715 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001716
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001717 if (ret_val)
1718 return ret_val;
1719 }
1720
1721 /* Workaround: Disable padding in Kumeran interface in the MAC
1722 * and in the PHY to avoid CRC errors.
1723 */
1724 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_INBAND_CTRL,
1725 &phy_data);
1726 if (ret_val)
1727 return ret_val;
1728 phy_data |= GG82563_ICR_DIS_PADDING;
1729 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_INBAND_CTRL,
1730 phy_data);
1731 if (ret_val)
1732 return ret_val;
1733 }
1734
1735 return E1000_SUCCESS;
1736}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001738/********************************************************************
1739* Copper link setup for e1000_phy_m88 series.
1740*
1741* hw - Struct containing variables accessed by shared code
1742*********************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07001743static s32 e1000_copper_link_mgp_setup(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001744{
Joe Perches406874a2008-04-03 10:06:32 -07001745 s32 ret_val;
1746 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001748 DEBUGFUNC("e1000_copper_link_mgp_setup");
1749
Auke Kok8fc897b2006-08-28 14:56:16 -07001750 if (hw->phy_reset_disable)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001751 return E1000_SUCCESS;
Auke Kok76c224b2006-05-23 13:36:06 -07001752
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001753 /* Enable CRS on TX. This must be set for half-duplex operation. */
1754 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001755 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001756 return ret_val;
1757
1758 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1759
1760 /* Options:
1761 * MDI/MDI-X = 0 (default)
1762 * 0 - Auto for all speeds
1763 * 1 - MDI mode
1764 * 2 - MDI-X mode
1765 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1766 */
1767 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1768
1769 switch (hw->mdix) {
1770 case 1:
1771 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
1772 break;
1773 case 2:
1774 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
1775 break;
1776 case 3:
1777 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
1778 break;
1779 case 0:
1780 default:
1781 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
1782 break;
1783 }
1784
1785 /* Options:
1786 * disable_polarity_correction = 0 (default)
1787 * Automatic Correction for Reversed Cable Polarity
1788 * 0 - Disabled
1789 * 1 - Enabled
1790 */
1791 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
Auke Kok8fc897b2006-08-28 14:56:16 -07001792 if (hw->disable_polarity_correction == 1)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001793 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
Auke Kokee040222006-06-27 09:08:03 -07001794 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1795 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001796 return ret_val;
1797
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001798 if (hw->phy_revision < M88E1011_I_REV_4) {
Auke Kokee040222006-06-27 09:08:03 -07001799 /* Force TX_CLK in the Extended PHY Specific Control Register
1800 * to 25MHz clock.
1801 */
1802 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1803 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001804 return ret_val;
Auke Kokee040222006-06-27 09:08:03 -07001805
1806 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1807
1808 if ((hw->phy_revision == E1000_REVISION_2) &&
1809 (hw->phy_id == M88E1111_I_PHY_ID)) {
1810 /* Vidalia Phy, set the downshift counter to 5x */
1811 phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK);
1812 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
1813 ret_val = e1000_write_phy_reg(hw,
1814 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1815 if (ret_val)
1816 return ret_val;
1817 } else {
1818 /* Configure Master and Slave downshift values */
1819 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
1820 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
1821 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
1822 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
1823 ret_val = e1000_write_phy_reg(hw,
1824 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1825 if (ret_val)
1826 return ret_val;
1827 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001828 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001830 /* SW Reset the PHY so all changes take effect */
1831 ret_val = e1000_phy_reset(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001832 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001833 DEBUGOUT("Error Resetting the PHY\n");
1834 return ret_val;
1835 }
1836
1837 return E1000_SUCCESS;
1838}
1839
1840/********************************************************************
1841* Setup auto-negotiation and flow control advertisements,
1842* and then perform auto-negotiation.
1843*
1844* hw - Struct containing variables accessed by shared code
1845*********************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07001846static s32 e1000_copper_link_autoneg(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001847{
Joe Perches406874a2008-04-03 10:06:32 -07001848 s32 ret_val;
1849 u16 phy_data;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001850
1851 DEBUGFUNC("e1000_copper_link_autoneg");
1852
1853 /* Perform some bounds checking on the hw->autoneg_advertised
1854 * parameter. If this variable is zero, then set it to the default.
1855 */
1856 hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
1857
1858 /* If autoneg_advertised is zero, we assume it was not defaulted
1859 * by the calling code so we set to advertise full capability.
1860 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001861 if (hw->autoneg_advertised == 0)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001862 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
1863
Auke Kokcd94dd02006-06-27 09:08:22 -07001864 /* IFE phy only supports 10/100 */
1865 if (hw->phy_type == e1000_phy_ife)
1866 hw->autoneg_advertised &= AUTONEG_ADVERTISE_10_100_ALL;
1867
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001868 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
1869 ret_val = e1000_phy_setup_autoneg(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001870 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001871 DEBUGOUT("Error Setting up Auto-Negotiation\n");
1872 return ret_val;
1873 }
1874 DEBUGOUT("Restarting Auto-Neg\n");
1875
1876 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
1877 * the Auto Neg Restart bit in the PHY control register.
1878 */
1879 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001880 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001881 return ret_val;
1882
1883 phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
1884 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001885 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001886 return ret_val;
1887
1888 /* Does the user want to wait for Auto-Neg to complete here, or
1889 * check at a later time (for example, callback routine).
1890 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001891 if (hw->wait_autoneg_complete) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001892 ret_val = e1000_wait_autoneg(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001893 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001894 DEBUGOUT("Error while waiting for autoneg to complete\n");
1895 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001897 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898
Joe Perchesc3033b02008-03-21 11:06:25 -07001899 hw->get_link_status = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001901 return E1000_SUCCESS;
1902}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001904/******************************************************************************
1905* Config the MAC and the PHY after link is up.
1906* 1) Set up the MAC to the current PHY speed/duplex
1907* if we are on 82543. If we
1908* are on newer silicon, we only need to configure
1909* collision distance in the Transmit Control Register.
1910* 2) Set up flow control on the MAC to that established with
1911* the link partner.
Auke Kok76c224b2006-05-23 13:36:06 -07001912* 3) Config DSP to improve Gigabit link quality for some PHY revisions.
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001913*
1914* hw - Struct containing variables accessed by shared code
1915******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07001916static s32 e1000_copper_link_postconfig(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001917{
Joe Perches406874a2008-04-03 10:06:32 -07001918 s32 ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001919 DEBUGFUNC("e1000_copper_link_postconfig");
Auke Kok76c224b2006-05-23 13:36:06 -07001920
Auke Kok8fc897b2006-08-28 14:56:16 -07001921 if (hw->mac_type >= e1000_82544) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001922 e1000_config_collision_dist(hw);
1923 } else {
1924 ret_val = e1000_config_mac_to_phy(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001925 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001926 DEBUGOUT("Error configuring MAC to PHY settings\n");
1927 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001929 }
1930 ret_val = e1000_config_fc_after_link_up(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001931 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001932 DEBUGOUT("Error Configuring Flow Control\n");
1933 return ret_val;
1934 }
1935
1936 /* Config DSP to improve Giga link quality */
Auke Kok8fc897b2006-08-28 14:56:16 -07001937 if (hw->phy_type == e1000_phy_igp) {
Joe Perchesc3033b02008-03-21 11:06:25 -07001938 ret_val = e1000_config_dsp_after_link_change(hw, true);
Auke Kok8fc897b2006-08-28 14:56:16 -07001939 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001940 DEBUGOUT("Error Configuring DSP after link up\n");
1941 return ret_val;
1942 }
1943 }
Auke Kok76c224b2006-05-23 13:36:06 -07001944
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001945 return E1000_SUCCESS;
1946}
1947
1948/******************************************************************************
1949* Detects which PHY is present and setup the speed and duplex
1950*
1951* hw - Struct containing variables accessed by shared code
1952******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07001953static s32 e1000_setup_copper_link(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001954{
Joe Perches406874a2008-04-03 10:06:32 -07001955 s32 ret_val;
1956 u16 i;
1957 u16 phy_data;
Jesse Brandeburgb7cb8c22009-07-06 10:45:01 +00001958 u16 reg_data = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001959
1960 DEBUGFUNC("e1000_setup_copper_link");
1961
Auke Kokcd94dd02006-06-27 09:08:22 -07001962 switch (hw->mac_type) {
1963 case e1000_80003es2lan:
1964 case e1000_ich8lan:
1965 /* Set the mac to wait the maximum time between each
1966 * iteration and increase the max iterations when
1967 * polling the phy; this fixes erroneous timeouts at 10Mbps. */
1968 ret_val = e1000_write_kmrn_reg(hw, GG82563_REG(0x34, 4), 0xFFFF);
1969 if (ret_val)
1970 return ret_val;
1971 ret_val = e1000_read_kmrn_reg(hw, GG82563_REG(0x34, 9), &reg_data);
1972 if (ret_val)
1973 return ret_val;
1974 reg_data |= 0x3F;
1975 ret_val = e1000_write_kmrn_reg(hw, GG82563_REG(0x34, 9), reg_data);
1976 if (ret_val)
1977 return ret_val;
1978 default:
1979 break;
1980 }
1981
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001982 /* Check if it is a valid PHY and set PHY mode if necessary. */
1983 ret_val = e1000_copper_link_preconfig(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001984 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001985 return ret_val;
1986
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001987 switch (hw->mac_type) {
1988 case e1000_80003es2lan:
Auke Kokcd94dd02006-06-27 09:08:22 -07001989 /* Kumeran registers are written-only */
1990 reg_data = E1000_KUMCTRLSTA_INB_CTRL_LINK_STATUS_TX_TIMEOUT_DEFAULT;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001991 reg_data |= E1000_KUMCTRLSTA_INB_CTRL_DIS_PADDING;
1992 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_INB_CTRL,
1993 reg_data);
1994 if (ret_val)
1995 return ret_val;
1996 break;
1997 default:
1998 break;
1999 }
2000
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002001 if (hw->phy_type == e1000_phy_igp ||
Auke Kokcd94dd02006-06-27 09:08:22 -07002002 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002003 hw->phy_type == e1000_phy_igp_2) {
2004 ret_val = e1000_copper_link_igp_setup(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002005 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002006 return ret_val;
2007 } else if (hw->phy_type == e1000_phy_m88) {
2008 ret_val = e1000_copper_link_mgp_setup(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002009 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002010 return ret_val;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002011 } else if (hw->phy_type == e1000_phy_gg82563) {
2012 ret_val = e1000_copper_link_ggp_setup(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002013 if (ret_val)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002014 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002015 }
2016
Auke Kok8fc897b2006-08-28 14:56:16 -07002017 if (hw->autoneg) {
Auke Kok76c224b2006-05-23 13:36:06 -07002018 /* Setup autoneg and flow control advertisement
2019 * and perform autonegotiation */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002020 ret_val = e1000_copper_link_autoneg(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002021 if (ret_val)
Auke Kok76c224b2006-05-23 13:36:06 -07002022 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002023 } else {
2024 /* PHY will be set to 10H, 10F, 100H,or 100F
2025 * depending on value from forced_speed_duplex. */
2026 DEBUGOUT("Forcing speed and duplex\n");
2027 ret_val = e1000_phy_force_speed_duplex(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002028 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002029 DEBUGOUT("Error Forcing Speed and Duplex\n");
2030 return ret_val;
2031 }
2032 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033
2034 /* Check link status. Wait up to 100 microseconds for link to become
2035 * valid.
2036 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002037 for (i = 0; i < 10; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002039 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040 return ret_val;
2041 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002042 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043 return ret_val;
2044
Auke Kok8fc897b2006-08-28 14:56:16 -07002045 if (phy_data & MII_SR_LINK_STATUS) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002046 /* Config the MAC and PHY after link is up */
2047 ret_val = e1000_copper_link_postconfig(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002048 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049 return ret_val;
Auke Kok76c224b2006-05-23 13:36:06 -07002050
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051 DEBUGOUT("Valid link established!!!\n");
2052 return E1000_SUCCESS;
2053 }
2054 udelay(10);
2055 }
2056
2057 DEBUGOUT("Unable to establish link!!!\n");
2058 return E1000_SUCCESS;
2059}
2060
2061/******************************************************************************
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002062* Configure the MAC-to-PHY interface for 10/100Mbps
2063*
2064* hw - Struct containing variables accessed by shared code
2065******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07002066static s32 e1000_configure_kmrn_for_10_100(struct e1000_hw *hw, u16 duplex)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002067{
Joe Perches406874a2008-04-03 10:06:32 -07002068 s32 ret_val = E1000_SUCCESS;
2069 u32 tipg;
2070 u16 reg_data;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002071
2072 DEBUGFUNC("e1000_configure_kmrn_for_10_100");
2073
2074 reg_data = E1000_KUMCTRLSTA_HD_CTRL_10_100_DEFAULT;
2075 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_HD_CTRL,
2076 reg_data);
2077 if (ret_val)
2078 return ret_val;
2079
2080 /* Configure Transmit Inter-Packet Gap */
Joe Perches1dc32912008-07-11 15:17:08 -07002081 tipg = er32(TIPG);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002082 tipg &= ~E1000_TIPG_IPGT_MASK;
2083 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_10_100;
Joe Perches1dc32912008-07-11 15:17:08 -07002084 ew32(TIPG, tipg);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002085
Auke Kokcd94dd02006-06-27 09:08:22 -07002086 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, &reg_data);
2087
2088 if (ret_val)
2089 return ret_val;
2090
2091 if (duplex == HALF_DUPLEX)
2092 reg_data |= GG82563_KMCR_PASS_FALSE_CARRIER;
2093 else
2094 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
2095
2096 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
2097
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002098 return ret_val;
2099}
2100
Joe Perches64798842008-07-11 15:17:02 -07002101static s32 e1000_configure_kmrn_for_1000(struct e1000_hw *hw)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002102{
Joe Perches406874a2008-04-03 10:06:32 -07002103 s32 ret_val = E1000_SUCCESS;
2104 u16 reg_data;
2105 u32 tipg;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002106
2107 DEBUGFUNC("e1000_configure_kmrn_for_1000");
2108
2109 reg_data = E1000_KUMCTRLSTA_HD_CTRL_1000_DEFAULT;
2110 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_HD_CTRL,
2111 reg_data);
2112 if (ret_val)
2113 return ret_val;
2114
2115 /* Configure Transmit Inter-Packet Gap */
Joe Perches1dc32912008-07-11 15:17:08 -07002116 tipg = er32(TIPG);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002117 tipg &= ~E1000_TIPG_IPGT_MASK;
2118 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
Joe Perches1dc32912008-07-11 15:17:08 -07002119 ew32(TIPG, tipg);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002120
Auke Kokcd94dd02006-06-27 09:08:22 -07002121 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, &reg_data);
2122
2123 if (ret_val)
2124 return ret_val;
2125
2126 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
2127 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
2128
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002129 return ret_val;
2130}
2131
2132/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133* Configures PHY autoneg and flow control advertisement settings
2134*
2135* hw - Struct containing variables accessed by shared code
2136******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07002137s32 e1000_phy_setup_autoneg(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138{
Joe Perches406874a2008-04-03 10:06:32 -07002139 s32 ret_val;
2140 u16 mii_autoneg_adv_reg;
2141 u16 mii_1000t_ctrl_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142
2143 DEBUGFUNC("e1000_phy_setup_autoneg");
2144
2145 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
2146 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002147 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148 return ret_val;
2149
Auke Kokcd94dd02006-06-27 09:08:22 -07002150 if (hw->phy_type != e1000_phy_ife) {
2151 /* Read the MII 1000Base-T Control Register (Address 9). */
2152 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
2153 if (ret_val)
2154 return ret_val;
2155 } else
2156 mii_1000t_ctrl_reg=0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157
2158 /* Need to parse both autoneg_advertised and fc and set up
2159 * the appropriate PHY registers. First we will parse for
2160 * autoneg_advertised software override. Since we can advertise
2161 * a plethora of combinations, we need to check each bit
2162 * individually.
2163 */
2164
2165 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
2166 * Advertisement Register (Address 4) and the 1000 mb speed bits in
2167 * the 1000Base-T Control Register (Address 9).
2168 */
2169 mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
2170 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
2171
2172 DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised);
2173
2174 /* Do we want to advertise 10 Mb Half Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002175 if (hw->autoneg_advertised & ADVERTISE_10_HALF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176 DEBUGOUT("Advertise 10mb Half duplex\n");
2177 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
2178 }
2179
2180 /* Do we want to advertise 10 Mb Full Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002181 if (hw->autoneg_advertised & ADVERTISE_10_FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182 DEBUGOUT("Advertise 10mb Full duplex\n");
2183 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
2184 }
2185
2186 /* Do we want to advertise 100 Mb Half Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002187 if (hw->autoneg_advertised & ADVERTISE_100_HALF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188 DEBUGOUT("Advertise 100mb Half duplex\n");
2189 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
2190 }
2191
2192 /* Do we want to advertise 100 Mb Full Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002193 if (hw->autoneg_advertised & ADVERTISE_100_FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194 DEBUGOUT("Advertise 100mb Full duplex\n");
2195 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
2196 }
2197
2198 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
Auke Kok8fc897b2006-08-28 14:56:16 -07002199 if (hw->autoneg_advertised & ADVERTISE_1000_HALF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200 DEBUGOUT("Advertise 1000mb Half duplex requested, request denied!\n");
2201 }
2202
2203 /* Do we want to advertise 1000 Mb Full Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002204 if (hw->autoneg_advertised & ADVERTISE_1000_FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205 DEBUGOUT("Advertise 1000mb Full duplex\n");
2206 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
Auke Kokcd94dd02006-06-27 09:08:22 -07002207 if (hw->phy_type == e1000_phy_ife) {
2208 DEBUGOUT("e1000_phy_ife is a 10/100 PHY. Gigabit speed is not supported.\n");
2209 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210 }
2211
2212 /* Check for a software override of the flow control settings, and
2213 * setup the PHY advertisement registers accordingly. If
2214 * auto-negotiation is enabled, then software will have to set the
2215 * "PAUSE" bits to the correct value in the Auto-Negotiation
2216 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
2217 *
2218 * The possible values of the "fc" parameter are:
2219 * 0: Flow control is completely disabled
2220 * 1: Rx flow control is enabled (we can receive pause frames
2221 * but not send pause frames).
2222 * 2: Tx flow control is enabled (we can send pause frames
2223 * but we do not support receiving pause frames).
2224 * 3: Both Rx and TX flow control (symmetric) are enabled.
2225 * other: No software override. The flow control configuration
2226 * in the EEPROM is used.
2227 */
2228 switch (hw->fc) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002229 case E1000_FC_NONE: /* 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230 /* Flow control (RX & TX) is completely disabled by a
2231 * software over-ride.
2232 */
2233 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2234 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07002235 case E1000_FC_RX_PAUSE: /* 1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236 /* RX Flow control is enabled, and TX Flow control is
2237 * disabled, by a software over-ride.
2238 */
2239 /* Since there really isn't a way to advertise that we are
2240 * capable of RX Pause ONLY, we will advertise that we
2241 * support both symmetric and asymmetric RX PAUSE. Later
2242 * (in e1000_config_fc_after_link_up) we will disable the
2243 *hw's ability to send PAUSE frames.
2244 */
2245 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2246 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07002247 case E1000_FC_TX_PAUSE: /* 2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248 /* TX Flow control is enabled, and RX Flow control is
2249 * disabled, by a software over-ride.
2250 */
2251 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
2252 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
2253 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07002254 case E1000_FC_FULL: /* 3 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255 /* Flow control (both RX and TX) is enabled by a software
2256 * over-ride.
2257 */
2258 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2259 break;
2260 default:
2261 DEBUGOUT("Flow control param set incorrectly\n");
2262 return -E1000_ERR_CONFIG;
2263 }
2264
2265 ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002266 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267 return ret_val;
2268
2269 DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
2270
Auke Kokcd94dd02006-06-27 09:08:22 -07002271 if (hw->phy_type != e1000_phy_ife) {
2272 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg);
2273 if (ret_val)
2274 return ret_val;
2275 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276
2277 return E1000_SUCCESS;
2278}
2279
2280/******************************************************************************
2281* Force PHY speed and duplex settings to hw->forced_speed_duplex
2282*
2283* hw - Struct containing variables accessed by shared code
2284******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07002285static s32 e1000_phy_force_speed_duplex(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286{
Joe Perches406874a2008-04-03 10:06:32 -07002287 u32 ctrl;
2288 s32 ret_val;
2289 u16 mii_ctrl_reg;
2290 u16 mii_status_reg;
2291 u16 phy_data;
2292 u16 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293
2294 DEBUGFUNC("e1000_phy_force_speed_duplex");
2295
2296 /* Turn off Flow control if we are forcing speed and duplex. */
Jeff Kirsher11241b12006-09-27 12:53:28 -07002297 hw->fc = E1000_FC_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298
2299 DEBUGOUT1("hw->fc = %d\n", hw->fc);
2300
2301 /* Read the Device Control Register. */
Joe Perches1dc32912008-07-11 15:17:08 -07002302 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303
2304 /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */
2305 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2306 ctrl &= ~(DEVICE_SPEED_MASK);
2307
2308 /* Clear the Auto Speed Detect Enable bit. */
2309 ctrl &= ~E1000_CTRL_ASDE;
2310
2311 /* Read the MII Control Register. */
2312 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002313 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314 return ret_val;
2315
2316 /* We need to disable autoneg in order to force link and duplex. */
2317
2318 mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN;
2319
2320 /* Are we forcing Full or Half Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002321 if (hw->forced_speed_duplex == e1000_100_full ||
2322 hw->forced_speed_duplex == e1000_10_full) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323 /* We want to force full duplex so we SET the full duplex bits in the
2324 * Device and MII Control Registers.
2325 */
2326 ctrl |= E1000_CTRL_FD;
2327 mii_ctrl_reg |= MII_CR_FULL_DUPLEX;
2328 DEBUGOUT("Full Duplex\n");
2329 } else {
2330 /* We want to force half duplex so we CLEAR the full duplex bits in
2331 * the Device and MII Control Registers.
2332 */
2333 ctrl &= ~E1000_CTRL_FD;
2334 mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX;
2335 DEBUGOUT("Half Duplex\n");
2336 }
2337
2338 /* Are we forcing 100Mbps??? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002339 if (hw->forced_speed_duplex == e1000_100_full ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340 hw->forced_speed_duplex == e1000_100_half) {
2341 /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */
2342 ctrl |= E1000_CTRL_SPD_100;
2343 mii_ctrl_reg |= MII_CR_SPEED_100;
2344 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
2345 DEBUGOUT("Forcing 100mb ");
2346 } else {
2347 /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */
2348 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
2349 mii_ctrl_reg |= MII_CR_SPEED_10;
2350 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
2351 DEBUGOUT("Forcing 10mb ");
2352 }
2353
2354 e1000_config_collision_dist(hw);
2355
2356 /* Write the configured values back to the Device Control Reg. */
Joe Perches1dc32912008-07-11 15:17:08 -07002357 ew32(CTRL, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002359 if ((hw->phy_type == e1000_phy_m88) ||
2360 (hw->phy_type == e1000_phy_gg82563)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002362 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363 return ret_val;
2364
2365 /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
2366 * forced whenever speed are duplex are forced.
2367 */
2368 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
2369 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002370 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371 return ret_val;
2372
2373 DEBUGOUT1("M88E1000 PSCR: %x \n", phy_data);
2374
2375 /* Need to reset the PHY or these changes will be ignored */
2376 mii_ctrl_reg |= MII_CR_RESET;
Auke Kok90fb5132006-11-01 08:47:30 -08002377
Auke Kokcd94dd02006-06-27 09:08:22 -07002378 /* Disable MDI-X support for 10/100 */
2379 } else if (hw->phy_type == e1000_phy_ife) {
2380 ret_val = e1000_read_phy_reg(hw, IFE_PHY_MDIX_CONTROL, &phy_data);
2381 if (ret_val)
2382 return ret_val;
2383
2384 phy_data &= ~IFE_PMC_AUTO_MDIX;
2385 phy_data &= ~IFE_PMC_FORCE_MDIX;
2386
2387 ret_val = e1000_write_phy_reg(hw, IFE_PHY_MDIX_CONTROL, phy_data);
2388 if (ret_val)
2389 return ret_val;
Auke Kok90fb5132006-11-01 08:47:30 -08002390
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391 } else {
2392 /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
2393 * forced whenever speed or duplex are forced.
2394 */
2395 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002396 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397 return ret_val;
2398
2399 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
2400 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
2401
2402 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002403 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404 return ret_val;
2405 }
2406
2407 /* Write back the modified PHY MII control register. */
2408 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002409 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410 return ret_val;
2411
2412 udelay(1);
2413
2414 /* The wait_autoneg_complete flag may be a little misleading here.
2415 * Since we are forcing speed and duplex, Auto-Neg is not enabled.
2416 * But we do want to delay for a period while forcing only so we
2417 * don't generate false No Link messages. So we will wait here
2418 * only if the user has set wait_autoneg_complete to 1, which is
2419 * the default.
2420 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002421 if (hw->wait_autoneg_complete) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422 /* We will wait for autoneg to complete. */
2423 DEBUGOUT("Waiting for forced speed/duplex link.\n");
2424 mii_status_reg = 0;
2425
2426 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
Auke Kok8fc897b2006-08-28 14:56:16 -07002427 for (i = PHY_FORCE_TIME; i > 0; i--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428 /* Read the MII Status Register and wait for Auto-Neg Complete bit
2429 * to be set.
2430 */
2431 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002432 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433 return ret_val;
2434
2435 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002436 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437 return ret_val;
2438
Auke Kok8fc897b2006-08-28 14:56:16 -07002439 if (mii_status_reg & MII_SR_LINK_STATUS) break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04002440 msleep(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441 }
Auke Kok8fc897b2006-08-28 14:56:16 -07002442 if ((i == 0) &&
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002443 ((hw->phy_type == e1000_phy_m88) ||
2444 (hw->phy_type == e1000_phy_gg82563))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445 /* We didn't get link. Reset the DSP and wait again for link. */
2446 ret_val = e1000_phy_reset_dsp(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002447 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448 DEBUGOUT("Error Resetting PHY DSP\n");
2449 return ret_val;
2450 }
2451 }
2452 /* This loop will early-out if the link condition has been met. */
Auke Kok8fc897b2006-08-28 14:56:16 -07002453 for (i = PHY_FORCE_TIME; i > 0; i--) {
2454 if (mii_status_reg & MII_SR_LINK_STATUS) break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04002455 msleep(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456 /* Read the MII Status Register and wait for Auto-Neg Complete bit
2457 * to be set.
2458 */
2459 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002460 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461 return ret_val;
2462
2463 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002464 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002465 return ret_val;
2466 }
2467 }
2468
2469 if (hw->phy_type == e1000_phy_m88) {
2470 /* Because we reset the PHY above, we need to re-force TX_CLK in the
2471 * Extended PHY Specific Control Register to 25MHz clock. This value
2472 * defaults back to a 2.5MHz clock when the PHY is reset.
2473 */
2474 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002475 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002476 return ret_val;
2477
2478 phy_data |= M88E1000_EPSCR_TX_CLK_25;
2479 ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002480 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481 return ret_val;
2482
2483 /* In addition, because of the s/w reset above, we need to enable CRS on
2484 * TX. This must be set for both full and half duplex operation.
2485 */
2486 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002487 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488 return ret_val;
2489
2490 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
2491 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002492 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493 return ret_val;
2494
Auke Kok8fc897b2006-08-28 14:56:16 -07002495 if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
2496 (!hw->autoneg) && (hw->forced_speed_duplex == e1000_10_full ||
2497 hw->forced_speed_duplex == e1000_10_half)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498 ret_val = e1000_polarity_reversal_workaround(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002499 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500 return ret_val;
2501 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002502 } else if (hw->phy_type == e1000_phy_gg82563) {
2503 /* The TX_CLK of the Extended PHY Specific Control Register defaults
2504 * to 2.5MHz on a reset. We need to re-force it back to 25MHz, if
2505 * we're not in a forced 10/duplex configuration. */
2506 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, &phy_data);
2507 if (ret_val)
2508 return ret_val;
2509
2510 phy_data &= ~GG82563_MSCR_TX_CLK_MASK;
2511 if ((hw->forced_speed_duplex == e1000_10_full) ||
2512 (hw->forced_speed_duplex == e1000_10_half))
2513 phy_data |= GG82563_MSCR_TX_CLK_10MBPS_2_5MHZ;
2514 else
2515 phy_data |= GG82563_MSCR_TX_CLK_100MBPS_25MHZ;
2516
2517 /* Also due to the reset, we need to enable CRS on Tx. */
2518 phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
2519
2520 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, phy_data);
2521 if (ret_val)
2522 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002523 }
2524 return E1000_SUCCESS;
2525}
2526
2527/******************************************************************************
2528* Sets the collision distance in the Transmit Control register
2529*
2530* hw - Struct containing variables accessed by shared code
2531*
2532* Link should have been established previously. Reads the speed and duplex
2533* information from the Device Status register.
2534******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07002535void e1000_config_collision_dist(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536{
Joe Perches406874a2008-04-03 10:06:32 -07002537 u32 tctl, coll_dist;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538
2539 DEBUGFUNC("e1000_config_collision_dist");
2540
Jeff Kirsher0fadb052006-01-12 16:51:05 -08002541 if (hw->mac_type < e1000_82543)
2542 coll_dist = E1000_COLLISION_DISTANCE_82542;
2543 else
2544 coll_dist = E1000_COLLISION_DISTANCE;
2545
Joe Perches1dc32912008-07-11 15:17:08 -07002546 tctl = er32(TCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547
2548 tctl &= ~E1000_TCTL_COLD;
Jeff Kirsher0fadb052006-01-12 16:51:05 -08002549 tctl |= coll_dist << E1000_COLD_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550
Joe Perches1dc32912008-07-11 15:17:08 -07002551 ew32(TCTL, tctl);
2552 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553}
2554
2555/******************************************************************************
2556* Sets MAC speed and duplex settings to reflect the those in the PHY
2557*
2558* hw - Struct containing variables accessed by shared code
2559* mii_reg - data to write to the MII control register
2560*
2561* The contents of the PHY register containing the needed information need to
2562* be passed in.
2563******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07002564static s32 e1000_config_mac_to_phy(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565{
Joe Perches406874a2008-04-03 10:06:32 -07002566 u32 ctrl;
2567 s32 ret_val;
2568 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002569
2570 DEBUGFUNC("e1000_config_mac_to_phy");
2571
Auke Kok76c224b2006-05-23 13:36:06 -07002572 /* 82544 or newer MAC, Auto Speed Detection takes care of
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002573 * MAC speed/duplex configuration.*/
2574 if (hw->mac_type >= e1000_82544)
2575 return E1000_SUCCESS;
2576
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577 /* Read the Device Control Register and set the bits to Force Speed
2578 * and Duplex.
2579 */
Joe Perches1dc32912008-07-11 15:17:08 -07002580 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002581 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2582 ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
2583
2584 /* Set up duplex in the Device Control and Transmit Control
2585 * registers depending on negotiated values.
2586 */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002587 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002588 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002589 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590
Auke Kok8fc897b2006-08-28 14:56:16 -07002591 if (phy_data & M88E1000_PSSR_DPLX)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002592 ctrl |= E1000_CTRL_FD;
Auke Kok76c224b2006-05-23 13:36:06 -07002593 else
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002594 ctrl &= ~E1000_CTRL_FD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002596 e1000_config_collision_dist(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002598 /* Set up speed in the Device Control register depending on
2599 * negotiated values.
2600 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002601 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002602 ctrl |= E1000_CTRL_SPD_1000;
Auke Kok8fc897b2006-08-28 14:56:16 -07002603 else if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002604 ctrl |= E1000_CTRL_SPD_100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606 /* Write the configured values back to the Device Control Reg. */
Joe Perches1dc32912008-07-11 15:17:08 -07002607 ew32(CTRL, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608 return E1000_SUCCESS;
2609}
2610
2611/******************************************************************************
2612 * Forces the MAC's flow control settings.
2613 *
2614 * hw - Struct containing variables accessed by shared code
2615 *
2616 * Sets the TFCE and RFCE bits in the device control register to reflect
2617 * the adapter settings. TFCE and RFCE need to be explicitly set by
2618 * software when a Copper PHY is used because autonegotiation is managed
2619 * by the PHY rather than the MAC. Software must also configure these
2620 * bits when link is forced on a fiber connection.
2621 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07002622s32 e1000_force_mac_fc(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002623{
Joe Perches406874a2008-04-03 10:06:32 -07002624 u32 ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625
2626 DEBUGFUNC("e1000_force_mac_fc");
2627
2628 /* Get the current configuration of the Device Control Register */
Joe Perches1dc32912008-07-11 15:17:08 -07002629 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630
2631 /* Because we didn't get link via the internal auto-negotiation
2632 * mechanism (we either forced link or we got link via PHY
2633 * auto-neg), we have to manually enable/disable transmit an
2634 * receive flow control.
2635 *
2636 * The "Case" statement below enables/disable flow control
2637 * according to the "hw->fc" parameter.
2638 *
2639 * The possible values of the "fc" parameter are:
2640 * 0: Flow control is completely disabled
2641 * 1: Rx flow control is enabled (we can receive pause
2642 * frames but not send pause frames).
2643 * 2: Tx flow control is enabled (we can send pause frames
2644 * frames but we do not receive pause frames).
2645 * 3: Both Rx and TX flow control (symmetric) is enabled.
2646 * other: No other values should be possible at this point.
2647 */
2648
2649 switch (hw->fc) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002650 case E1000_FC_NONE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
2652 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07002653 case E1000_FC_RX_PAUSE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654 ctrl &= (~E1000_CTRL_TFCE);
2655 ctrl |= E1000_CTRL_RFCE;
2656 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07002657 case E1000_FC_TX_PAUSE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658 ctrl &= (~E1000_CTRL_RFCE);
2659 ctrl |= E1000_CTRL_TFCE;
2660 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07002661 case E1000_FC_FULL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
2663 break;
2664 default:
2665 DEBUGOUT("Flow control param set incorrectly\n");
2666 return -E1000_ERR_CONFIG;
2667 }
2668
2669 /* Disable TX Flow Control for 82542 (rev 2.0) */
Auke Kok8fc897b2006-08-28 14:56:16 -07002670 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671 ctrl &= (~E1000_CTRL_TFCE);
2672
Joe Perches1dc32912008-07-11 15:17:08 -07002673 ew32(CTRL, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002674 return E1000_SUCCESS;
2675}
2676
2677/******************************************************************************
2678 * Configures flow control settings after link is established
2679 *
2680 * hw - Struct containing variables accessed by shared code
2681 *
2682 * Should be called immediately after a valid link has been established.
2683 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
2684 * and autonegotiation is enabled, the MAC flow control settings will be set
2685 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
2686 * and RFCE bits will be automaticaly set to the negotiated flow control mode.
2687 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07002688static s32 e1000_config_fc_after_link_up(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002689{
Joe Perches406874a2008-04-03 10:06:32 -07002690 s32 ret_val;
2691 u16 mii_status_reg;
2692 u16 mii_nway_adv_reg;
2693 u16 mii_nway_lp_ability_reg;
2694 u16 speed;
2695 u16 duplex;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002696
2697 DEBUGFUNC("e1000_config_fc_after_link_up");
2698
2699 /* Check for the case where we have fiber media and auto-neg failed
2700 * so we had to force link. In this case, we need to force the
2701 * configuration of the MAC to match the "fc" parameter.
2702 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002703 if (((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) ||
2704 ((hw->media_type == e1000_media_type_internal_serdes) &&
2705 (hw->autoneg_failed)) ||
2706 ((hw->media_type == e1000_media_type_copper) && (!hw->autoneg))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002707 ret_val = e1000_force_mac_fc(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002708 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709 DEBUGOUT("Error forcing flow control settings\n");
2710 return ret_val;
2711 }
2712 }
2713
2714 /* Check for the case where we have copper media and auto-neg is
2715 * enabled. In this case, we need to check and see if Auto-Neg
2716 * has completed, and if so, how the PHY and link partner has
2717 * flow control configured.
2718 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002719 if ((hw->media_type == e1000_media_type_copper) && hw->autoneg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002720 /* Read the MII Status Register and check to see if AutoNeg
2721 * has completed. We read this twice because this reg has
2722 * some "sticky" (latched) bits.
2723 */
2724 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002725 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726 return ret_val;
2727 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002728 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002729 return ret_val;
2730
Auke Kok8fc897b2006-08-28 14:56:16 -07002731 if (mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732 /* The AutoNeg process has completed, so we now need to
2733 * read both the Auto Negotiation Advertisement Register
2734 * (Address 4) and the Auto_Negotiation Base Page Ability
2735 * Register (Address 5) to determine how flow control was
2736 * negotiated.
2737 */
2738 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV,
2739 &mii_nway_adv_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002740 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002741 return ret_val;
2742 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY,
2743 &mii_nway_lp_ability_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002744 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745 return ret_val;
2746
2747 /* Two bits in the Auto Negotiation Advertisement Register
2748 * (Address 4) and two bits in the Auto Negotiation Base
2749 * Page Ability Register (Address 5) determine flow control
2750 * for both the PHY and the link partner. The following
2751 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
2752 * 1999, describes these PAUSE resolution bits and how flow
2753 * control is determined based upon these settings.
2754 * NOTE: DC = Don't Care
2755 *
2756 * LOCAL DEVICE | LINK PARTNER
2757 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
2758 *-------|---------|-------|---------|--------------------
Jeff Kirsher11241b12006-09-27 12:53:28 -07002759 * 0 | 0 | DC | DC | E1000_FC_NONE
2760 * 0 | 1 | 0 | DC | E1000_FC_NONE
2761 * 0 | 1 | 1 | 0 | E1000_FC_NONE
2762 * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
2763 * 1 | 0 | 0 | DC | E1000_FC_NONE
2764 * 1 | DC | 1 | DC | E1000_FC_FULL
2765 * 1 | 1 | 0 | 0 | E1000_FC_NONE
2766 * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767 *
2768 */
2769 /* Are both PAUSE bits set to 1? If so, this implies
2770 * Symmetric Flow Control is enabled at both ends. The
2771 * ASM_DIR bits are irrelevant per the spec.
2772 *
2773 * For Symmetric Flow Control:
2774 *
2775 * LOCAL DEVICE | LINK PARTNER
2776 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2777 *-------|---------|-------|---------|--------------------
Jeff Kirsher11241b12006-09-27 12:53:28 -07002778 * 1 | DC | 1 | DC | E1000_FC_FULL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002779 *
2780 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002781 if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2782 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002783 /* Now we need to check if the user selected RX ONLY
2784 * of pause frames. In this case, we had to advertise
2785 * FULL flow control because we could not advertise RX
2786 * ONLY. Hence, we must now check to see if we need to
2787 * turn OFF the TRANSMISSION of PAUSE frames.
2788 */
Jeff Kirsher11241b12006-09-27 12:53:28 -07002789 if (hw->original_fc == E1000_FC_FULL) {
2790 hw->fc = E1000_FC_FULL;
Auke Koka42a5072006-05-23 13:36:01 -07002791 DEBUGOUT("Flow Control = FULL.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002792 } else {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002793 hw->fc = E1000_FC_RX_PAUSE;
Auke Koka42a5072006-05-23 13:36:01 -07002794 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002795 }
2796 }
2797 /* For receiving PAUSE frames ONLY.
2798 *
2799 * LOCAL DEVICE | LINK PARTNER
2800 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2801 *-------|---------|-------|---------|--------------------
Jeff Kirsher11241b12006-09-27 12:53:28 -07002802 * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803 *
2804 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002805 else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2806 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2807 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2808 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002809 hw->fc = E1000_FC_TX_PAUSE;
Auke Koka42a5072006-05-23 13:36:01 -07002810 DEBUGOUT("Flow Control = TX PAUSE frames only.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002811 }
2812 /* For transmitting PAUSE frames ONLY.
2813 *
2814 * LOCAL DEVICE | LINK PARTNER
2815 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2816 *-------|---------|-------|---------|--------------------
Jeff Kirsher11241b12006-09-27 12:53:28 -07002817 * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
Linus Torvalds1da177e2005-04-16 15:20:36 -07002818 *
2819 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002820 else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2821 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2822 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2823 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002824 hw->fc = E1000_FC_RX_PAUSE;
Auke Koka42a5072006-05-23 13:36:01 -07002825 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002826 }
2827 /* Per the IEEE spec, at this point flow control should be
2828 * disabled. However, we want to consider that we could
2829 * be connected to a legacy switch that doesn't advertise
2830 * desired flow control, but can be forced on the link
2831 * partner. So if we advertised no flow control, that is
2832 * what we will resolve to. If we advertised some kind of
2833 * receive capability (Rx Pause Only or Full Flow Control)
2834 * and the link partner advertised none, we will configure
2835 * ourselves to enable Rx Flow Control only. We can do
2836 * this safely for two reasons: If the link partner really
2837 * didn't want flow control enabled, and we enable Rx, no
2838 * harm done since we won't be receiving any PAUSE frames
2839 * anyway. If the intent on the link partner was to have
2840 * flow control enabled, then by us enabling RX only, we
2841 * can at least receive pause frames and process them.
2842 * This is a good idea because in most cases, since we are
2843 * predominantly a server NIC, more times than not we will
2844 * be asked to delay transmission of packets than asking
2845 * our link partner to pause transmission of frames.
2846 */
Jeff Kirsher11241b12006-09-27 12:53:28 -07002847 else if ((hw->original_fc == E1000_FC_NONE ||
2848 hw->original_fc == E1000_FC_TX_PAUSE) ||
Auke Kok8fc897b2006-08-28 14:56:16 -07002849 hw->fc_strict_ieee) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002850 hw->fc = E1000_FC_NONE;
Auke Koka42a5072006-05-23 13:36:01 -07002851 DEBUGOUT("Flow Control = NONE.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002852 } else {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002853 hw->fc = E1000_FC_RX_PAUSE;
Auke Koka42a5072006-05-23 13:36:01 -07002854 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002855 }
2856
2857 /* Now we need to do one last check... If we auto-
2858 * negotiated to HALF DUPLEX, flow control should not be
2859 * enabled per IEEE 802.3 spec.
2860 */
2861 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
Auke Kok8fc897b2006-08-28 14:56:16 -07002862 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002863 DEBUGOUT("Error getting link speed and duplex\n");
2864 return ret_val;
2865 }
2866
Auke Kok8fc897b2006-08-28 14:56:16 -07002867 if (duplex == HALF_DUPLEX)
Jeff Kirsher11241b12006-09-27 12:53:28 -07002868 hw->fc = E1000_FC_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002869
2870 /* Now we call a subroutine to actually force the MAC
2871 * controller to use the correct flow control settings.
2872 */
2873 ret_val = e1000_force_mac_fc(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002874 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002875 DEBUGOUT("Error forcing flow control settings\n");
2876 return ret_val;
2877 }
2878 } else {
Auke Koka42a5072006-05-23 13:36:01 -07002879 DEBUGOUT("Copper PHY and Auto Neg has not completed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002880 }
2881 }
2882 return E1000_SUCCESS;
2883}
2884
2885/******************************************************************************
2886 * Checks to see if the link status of the hardware has changed.
2887 *
2888 * hw - Struct containing variables accessed by shared code
2889 *
2890 * Called by any function that needs to check the link status of the adapter.
2891 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07002892s32 e1000_check_for_link(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002893{
Joe Perches406874a2008-04-03 10:06:32 -07002894 u32 rxcw = 0;
2895 u32 ctrl;
2896 u32 status;
2897 u32 rctl;
2898 u32 icr;
2899 u32 signal = 0;
2900 s32 ret_val;
2901 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002902
2903 DEBUGFUNC("e1000_check_for_link");
2904
Joe Perches1dc32912008-07-11 15:17:08 -07002905 ctrl = er32(CTRL);
2906 status = er32(STATUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002907
2908 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
2909 * set when the optics detect a signal. On older adapters, it will be
2910 * cleared when there is a signal. This applies to fiber media only.
2911 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002912 if ((hw->media_type == e1000_media_type_fiber) ||
2913 (hw->media_type == e1000_media_type_internal_serdes)) {
Joe Perches1dc32912008-07-11 15:17:08 -07002914 rxcw = er32(RXCW);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002915
Auke Kok8fc897b2006-08-28 14:56:16 -07002916 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002917 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
Auke Kok8fc897b2006-08-28 14:56:16 -07002918 if (status & E1000_STATUS_LU)
Joe Perchesc3033b02008-03-21 11:06:25 -07002919 hw->get_link_status = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002920 }
2921 }
2922
2923 /* If we have a copper PHY then we only want to go out to the PHY
2924 * registers to see if Auto-Neg has completed and/or if our link
2925 * status has changed. The get_link_status flag will be set if we
2926 * receive a Link Status Change interrupt or we have Rx Sequence
2927 * Errors.
2928 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002929 if ((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002930 /* First we want to see if the MII Status Register reports
2931 * link. If so, then we want to get the current speed/duplex
2932 * of the PHY.
2933 * Read the register twice since the link bit is sticky.
2934 */
2935 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002936 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002937 return ret_val;
2938 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002939 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002940 return ret_val;
2941
Auke Kok8fc897b2006-08-28 14:56:16 -07002942 if (phy_data & MII_SR_LINK_STATUS) {
Joe Perchesc3033b02008-03-21 11:06:25 -07002943 hw->get_link_status = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002944 /* Check if there was DownShift, must be checked immediately after
2945 * link-up */
2946 e1000_check_downshift(hw);
2947
2948 /* If we are on 82544 or 82543 silicon and speed/duplex
2949 * are forced to 10H or 10F, then we will implement the polarity
2950 * reversal workaround. We disable interrupts first, and upon
2951 * returning, place the devices interrupt state to its previous
2952 * value except for the link status change interrupt which will
2953 * happen due to the execution of this workaround.
2954 */
2955
Auke Kok8fc897b2006-08-28 14:56:16 -07002956 if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
2957 (!hw->autoneg) &&
2958 (hw->forced_speed_duplex == e1000_10_full ||
2959 hw->forced_speed_duplex == e1000_10_half)) {
Joe Perches1dc32912008-07-11 15:17:08 -07002960 ew32(IMC, 0xffffffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002961 ret_val = e1000_polarity_reversal_workaround(hw);
Joe Perches1dc32912008-07-11 15:17:08 -07002962 icr = er32(ICR);
2963 ew32(ICS, (icr & ~E1000_ICS_LSC));
2964 ew32(IMS, IMS_ENABLE_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002965 }
2966
2967 } else {
2968 /* No link detected */
Joe Perchesc3033b02008-03-21 11:06:25 -07002969 e1000_config_dsp_after_link_change(hw, false);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002970 return 0;
2971 }
2972
2973 /* If we are forcing speed/duplex, then we simply return since
2974 * we have already determined whether we have link or not.
2975 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002976 if (!hw->autoneg) return -E1000_ERR_CONFIG;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002977
2978 /* optimize the dsp settings for the igp phy */
Joe Perchesc3033b02008-03-21 11:06:25 -07002979 e1000_config_dsp_after_link_change(hw, true);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002980
2981 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
2982 * have Si on board that is 82544 or newer, Auto
2983 * Speed Detection takes care of MAC speed/duplex
2984 * configuration. So we only need to configure Collision
2985 * Distance in the MAC. Otherwise, we need to force
2986 * speed/duplex on the MAC to the current PHY speed/duplex
2987 * settings.
2988 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002989 if (hw->mac_type >= e1000_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002990 e1000_config_collision_dist(hw);
2991 else {
2992 ret_val = e1000_config_mac_to_phy(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002993 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002994 DEBUGOUT("Error configuring MAC to PHY settings\n");
2995 return ret_val;
2996 }
2997 }
2998
2999 /* Configure Flow Control now that Auto-Neg has completed. First, we
3000 * need to restore the desired flow control settings because we may
3001 * have had to re-autoneg with a different link partner.
3002 */
3003 ret_val = e1000_config_fc_after_link_up(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07003004 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003005 DEBUGOUT("Error configuring flow control\n");
3006 return ret_val;
3007 }
3008
3009 /* At this point we know that we are on copper and we have
3010 * auto-negotiated link. These are conditions for checking the link
3011 * partner capability register. We use the link speed to determine if
3012 * TBI compatibility needs to be turned on or off. If the link is not
3013 * at gigabit speed, then TBI compatibility is not needed. If we are
3014 * at gigabit speed, we turn on TBI compatibility.
3015 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003016 if (hw->tbi_compatibility_en) {
Joe Perches406874a2008-04-03 10:06:32 -07003017 u16 speed, duplex;
Auke Kok592600a2006-06-27 09:08:09 -07003018 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
3019 if (ret_val) {
3020 DEBUGOUT("Error getting link speed and duplex\n");
3021 return ret_val;
3022 }
3023 if (speed != SPEED_1000) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003024 /* If link speed is not set to gigabit speed, we do not need
3025 * to enable TBI compatibility.
3026 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003027 if (hw->tbi_compatibility_on) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003028 /* If we previously were in the mode, turn it off. */
Joe Perches1dc32912008-07-11 15:17:08 -07003029 rctl = er32(RCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003030 rctl &= ~E1000_RCTL_SBP;
Joe Perches1dc32912008-07-11 15:17:08 -07003031 ew32(RCTL, rctl);
Joe Perchesc3033b02008-03-21 11:06:25 -07003032 hw->tbi_compatibility_on = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003033 }
3034 } else {
3035 /* If TBI compatibility is was previously off, turn it on. For
3036 * compatibility with a TBI link partner, we will store bad
3037 * packets. Some frames have an additional byte on the end and
Anand Gadiyarfd589a82009-07-16 17:13:03 +02003038 * will look like CRC errors to the hardware.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003039 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003040 if (!hw->tbi_compatibility_on) {
Joe Perchesc3033b02008-03-21 11:06:25 -07003041 hw->tbi_compatibility_on = true;
Joe Perches1dc32912008-07-11 15:17:08 -07003042 rctl = er32(RCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003043 rctl |= E1000_RCTL_SBP;
Joe Perches1dc32912008-07-11 15:17:08 -07003044 ew32(RCTL, rctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003045 }
3046 }
3047 }
3048 }
3049 /* If we don't have link (auto-negotiation failed or link partner cannot
3050 * auto-negotiate), the cable is plugged in (we have signal), and our
3051 * link partner is not trying to auto-negotiate with us (we are receiving
3052 * idles or data), we need to force link up. We also need to give
3053 * auto-negotiation time to complete, in case the cable was just plugged
3054 * in. The autoneg_failed flag does this.
3055 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003056 else if ((((hw->media_type == e1000_media_type_fiber) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003057 ((ctrl & E1000_CTRL_SWDPIN1) == signal)) ||
Auke Kok8fc897b2006-08-28 14:56:16 -07003058 (hw->media_type == e1000_media_type_internal_serdes)) &&
3059 (!(status & E1000_STATUS_LU)) &&
3060 (!(rxcw & E1000_RXCW_C))) {
3061 if (hw->autoneg_failed == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003062 hw->autoneg_failed = 1;
3063 return 0;
3064 }
Auke Koka42a5072006-05-23 13:36:01 -07003065 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003066
3067 /* Disable auto-negotiation in the TXCW register */
Joe Perches1dc32912008-07-11 15:17:08 -07003068 ew32(TXCW, (hw->txcw & ~E1000_TXCW_ANE));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003069
3070 /* Force link-up and also force full-duplex. */
Joe Perches1dc32912008-07-11 15:17:08 -07003071 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003072 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
Joe Perches1dc32912008-07-11 15:17:08 -07003073 ew32(CTRL, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003074
3075 /* Configure Flow Control after forcing link up. */
3076 ret_val = e1000_config_fc_after_link_up(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07003077 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003078 DEBUGOUT("Error configuring flow control\n");
3079 return ret_val;
3080 }
3081 }
3082 /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
3083 * auto-negotiation in the TXCW register and disable forced link in the
3084 * Device Control register in an attempt to auto-negotiate with our link
3085 * partner.
3086 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003087 else if (((hw->media_type == e1000_media_type_fiber) ||
3088 (hw->media_type == e1000_media_type_internal_serdes)) &&
3089 (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
Auke Koka42a5072006-05-23 13:36:01 -07003090 DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\n");
Joe Perches1dc32912008-07-11 15:17:08 -07003091 ew32(TXCW, hw->txcw);
3092 ew32(CTRL, (ctrl & ~E1000_CTRL_SLU));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003093
Joe Perchesc3033b02008-03-21 11:06:25 -07003094 hw->serdes_link_down = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003095 }
3096 /* If we force link for non-auto-negotiation switch, check link status
3097 * based on MAC synchronization for internal serdes media type.
3098 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003099 else if ((hw->media_type == e1000_media_type_internal_serdes) &&
Joe Perches1dc32912008-07-11 15:17:08 -07003100 !(E1000_TXCW_ANE & er32(TXCW))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003101 /* SYNCH bit and IV bit are sticky. */
3102 udelay(10);
Joe Perches1dc32912008-07-11 15:17:08 -07003103 if (E1000_RXCW_SYNCH & er32(RXCW)) {
Auke Kok8fc897b2006-08-28 14:56:16 -07003104 if (!(rxcw & E1000_RXCW_IV)) {
Joe Perchesc3033b02008-03-21 11:06:25 -07003105 hw->serdes_link_down = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003106 DEBUGOUT("SERDES: Link is up.\n");
3107 }
3108 } else {
Joe Perchesc3033b02008-03-21 11:06:25 -07003109 hw->serdes_link_down = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003110 DEBUGOUT("SERDES: Link is down.\n");
3111 }
3112 }
Auke Kok8fc897b2006-08-28 14:56:16 -07003113 if ((hw->media_type == e1000_media_type_internal_serdes) &&
Joe Perches1dc32912008-07-11 15:17:08 -07003114 (E1000_TXCW_ANE & er32(TXCW))) {
3115 hw->serdes_link_down = !(E1000_STATUS_LU & er32(STATUS));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003116 }
3117 return E1000_SUCCESS;
3118}
3119
3120/******************************************************************************
3121 * Detects the current speed and duplex settings of the hardware.
3122 *
3123 * hw - Struct containing variables accessed by shared code
3124 * speed - Speed of the connection
3125 * duplex - Duplex setting of the connection
3126 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003127s32 e1000_get_speed_and_duplex(struct e1000_hw *hw, u16 *speed, u16 *duplex)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003128{
Joe Perches406874a2008-04-03 10:06:32 -07003129 u32 status;
3130 s32 ret_val;
3131 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003132
3133 DEBUGFUNC("e1000_get_speed_and_duplex");
3134
Auke Kok8fc897b2006-08-28 14:56:16 -07003135 if (hw->mac_type >= e1000_82543) {
Joe Perches1dc32912008-07-11 15:17:08 -07003136 status = er32(STATUS);
Auke Kok8fc897b2006-08-28 14:56:16 -07003137 if (status & E1000_STATUS_SPEED_1000) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003138 *speed = SPEED_1000;
3139 DEBUGOUT("1000 Mbs, ");
Auke Kok8fc897b2006-08-28 14:56:16 -07003140 } else if (status & E1000_STATUS_SPEED_100) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003141 *speed = SPEED_100;
3142 DEBUGOUT("100 Mbs, ");
3143 } else {
3144 *speed = SPEED_10;
3145 DEBUGOUT("10 Mbs, ");
3146 }
3147
Auke Kok8fc897b2006-08-28 14:56:16 -07003148 if (status & E1000_STATUS_FD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003149 *duplex = FULL_DUPLEX;
Auke Koka42a5072006-05-23 13:36:01 -07003150 DEBUGOUT("Full Duplex\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003151 } else {
3152 *duplex = HALF_DUPLEX;
Auke Koka42a5072006-05-23 13:36:01 -07003153 DEBUGOUT(" Half Duplex\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003154 }
3155 } else {
Auke Koka42a5072006-05-23 13:36:01 -07003156 DEBUGOUT("1000 Mbs, Full Duplex\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003157 *speed = SPEED_1000;
3158 *duplex = FULL_DUPLEX;
3159 }
3160
3161 /* IGP01 PHY may advertise full duplex operation after speed downgrade even
3162 * if it is operating at half duplex. Here we set the duplex settings to
3163 * match the duplex in the link partner's capabilities.
3164 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003165 if (hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003166 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003167 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003168 return ret_val;
3169
Auke Kok8fc897b2006-08-28 14:56:16 -07003170 if (!(phy_data & NWAY_ER_LP_NWAY_CAPS))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003171 *duplex = HALF_DUPLEX;
3172 else {
3173 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003174 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003175 return ret_val;
Auke Kok8fc897b2006-08-28 14:56:16 -07003176 if ((*speed == SPEED_100 && !(phy_data & NWAY_LPAR_100TX_FD_CAPS)) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177 (*speed == SPEED_10 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
3178 *duplex = HALF_DUPLEX;
3179 }
3180 }
3181
Auke Kok76c224b2006-05-23 13:36:06 -07003182 if ((hw->mac_type == e1000_80003es2lan) &&
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003183 (hw->media_type == e1000_media_type_copper)) {
3184 if (*speed == SPEED_1000)
3185 ret_val = e1000_configure_kmrn_for_1000(hw);
3186 else
Auke Kokcd94dd02006-06-27 09:08:22 -07003187 ret_val = e1000_configure_kmrn_for_10_100(hw, *duplex);
3188 if (ret_val)
3189 return ret_val;
3190 }
3191
3192 if ((hw->phy_type == e1000_phy_igp_3) && (*speed == SPEED_1000)) {
3193 ret_val = e1000_kumeran_lock_loss_workaround(hw);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003194 if (ret_val)
3195 return ret_val;
3196 }
3197
Linus Torvalds1da177e2005-04-16 15:20:36 -07003198 return E1000_SUCCESS;
3199}
3200
3201/******************************************************************************
3202* Blocks until autoneg completes or times out (~4.5 seconds)
3203*
3204* hw - Struct containing variables accessed by shared code
3205******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003206static s32 e1000_wait_autoneg(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003207{
Joe Perches406874a2008-04-03 10:06:32 -07003208 s32 ret_val;
3209 u16 i;
3210 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003211
3212 DEBUGFUNC("e1000_wait_autoneg");
3213 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
3214
3215 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
Auke Kok8fc897b2006-08-28 14:56:16 -07003216 for (i = PHY_AUTO_NEG_TIME; i > 0; i--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003217 /* Read the MII Status Register and wait for Auto-Neg
3218 * Complete bit to be set.
3219 */
3220 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003221 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003222 return ret_val;
3223 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003224 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003225 return ret_val;
Auke Kok8fc897b2006-08-28 14:56:16 -07003226 if (phy_data & MII_SR_AUTONEG_COMPLETE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003227 return E1000_SUCCESS;
3228 }
Jeff Garzikf8ec4732006-09-19 15:27:07 -04003229 msleep(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003230 }
3231 return E1000_SUCCESS;
3232}
3233
3234/******************************************************************************
3235* Raises the Management Data Clock
3236*
3237* hw - Struct containing variables accessed by shared code
3238* ctrl - Device control register's current value
3239******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003240static void e1000_raise_mdi_clk(struct e1000_hw *hw, u32 *ctrl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003241{
3242 /* Raise the clock input to the Management Data Clock (by setting the MDC
3243 * bit), and then delay 10 microseconds.
3244 */
Joe Perches1dc32912008-07-11 15:17:08 -07003245 ew32(CTRL, (*ctrl | E1000_CTRL_MDC));
3246 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003247 udelay(10);
3248}
3249
3250/******************************************************************************
3251* Lowers the Management Data Clock
3252*
3253* hw - Struct containing variables accessed by shared code
3254* ctrl - Device control register's current value
3255******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003256static void e1000_lower_mdi_clk(struct e1000_hw *hw, u32 *ctrl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003257{
3258 /* Lower the clock input to the Management Data Clock (by clearing the MDC
3259 * bit), and then delay 10 microseconds.
3260 */
Joe Perches1dc32912008-07-11 15:17:08 -07003261 ew32(CTRL, (*ctrl & ~E1000_CTRL_MDC));
3262 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003263 udelay(10);
3264}
3265
3266/******************************************************************************
3267* Shifts data bits out to the PHY
3268*
3269* hw - Struct containing variables accessed by shared code
3270* data - Data to send out to the PHY
3271* count - Number of bits to shift out
3272*
3273* Bits are shifted out in MSB to LSB order.
3274******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003275static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, u32 data, u16 count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003276{
Joe Perches406874a2008-04-03 10:06:32 -07003277 u32 ctrl;
3278 u32 mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003279
3280 /* We need to shift "count" number of bits out to the PHY. So, the value
3281 * in the "data" parameter will be shifted out to the PHY one bit at a
3282 * time. In order to do this, "data" must be broken down into bits.
3283 */
3284 mask = 0x01;
3285 mask <<= (count - 1);
3286
Joe Perches1dc32912008-07-11 15:17:08 -07003287 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003288
3289 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
3290 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
3291
Auke Kok8fc897b2006-08-28 14:56:16 -07003292 while (mask) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003293 /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
3294 * then raising and lowering the Management Data Clock. A "0" is
3295 * shifted out to the PHY by setting the MDIO bit to "0" and then
3296 * raising and lowering the clock.
3297 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003298 if (data & mask)
3299 ctrl |= E1000_CTRL_MDIO;
3300 else
3301 ctrl &= ~E1000_CTRL_MDIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003302
Joe Perches1dc32912008-07-11 15:17:08 -07003303 ew32(CTRL, ctrl);
3304 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003305
3306 udelay(10);
3307
3308 e1000_raise_mdi_clk(hw, &ctrl);
3309 e1000_lower_mdi_clk(hw, &ctrl);
3310
3311 mask = mask >> 1;
3312 }
3313}
3314
3315/******************************************************************************
3316* Shifts data bits in from the PHY
3317*
3318* hw - Struct containing variables accessed by shared code
3319*
3320* Bits are shifted in in MSB to LSB order.
3321******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003322static u16 e1000_shift_in_mdi_bits(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003323{
Joe Perches406874a2008-04-03 10:06:32 -07003324 u32 ctrl;
3325 u16 data = 0;
3326 u8 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003327
3328 /* In order to read a register from the PHY, we need to shift in a total
3329 * of 18 bits from the PHY. The first two bit (turnaround) times are used
3330 * to avoid contention on the MDIO pin when a read operation is performed.
3331 * These two bits are ignored by us and thrown away. Bits are "shifted in"
3332 * by raising the input to the Management Data Clock (setting the MDC bit),
3333 * and then reading the value of the MDIO bit.
3334 */
Joe Perches1dc32912008-07-11 15:17:08 -07003335 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003336
3337 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
3338 ctrl &= ~E1000_CTRL_MDIO_DIR;
3339 ctrl &= ~E1000_CTRL_MDIO;
3340
Joe Perches1dc32912008-07-11 15:17:08 -07003341 ew32(CTRL, ctrl);
3342 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003343
3344 /* Raise and Lower the clock before reading in the data. This accounts for
3345 * the turnaround bits. The first clock occurred when we clocked out the
3346 * last bit of the Register Address.
3347 */
3348 e1000_raise_mdi_clk(hw, &ctrl);
3349 e1000_lower_mdi_clk(hw, &ctrl);
3350
Auke Kok8fc897b2006-08-28 14:56:16 -07003351 for (data = 0, i = 0; i < 16; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003352 data = data << 1;
3353 e1000_raise_mdi_clk(hw, &ctrl);
Joe Perches1dc32912008-07-11 15:17:08 -07003354 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003355 /* Check to see if we shifted in a "1". */
Auke Kok8fc897b2006-08-28 14:56:16 -07003356 if (ctrl & E1000_CTRL_MDIO)
3357 data |= 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003358 e1000_lower_mdi_clk(hw, &ctrl);
3359 }
3360
3361 e1000_raise_mdi_clk(hw, &ctrl);
3362 e1000_lower_mdi_clk(hw, &ctrl);
3363
3364 return data;
3365}
3366
Joe Perches64798842008-07-11 15:17:02 -07003367static s32 e1000_swfw_sync_acquire(struct e1000_hw *hw, u16 mask)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003368{
Joe Perches406874a2008-04-03 10:06:32 -07003369 u32 swfw_sync = 0;
3370 u32 swmask = mask;
3371 u32 fwmask = mask << 16;
3372 s32 timeout = 200;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003373
3374 DEBUGFUNC("e1000_swfw_sync_acquire");
3375
Auke Kokcd94dd02006-06-27 09:08:22 -07003376 if (hw->swfwhw_semaphore_present)
3377 return e1000_get_software_flag(hw);
3378
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003379 if (!hw->swfw_sync_present)
3380 return e1000_get_hw_eeprom_semaphore(hw);
3381
Auke Kok8fc897b2006-08-28 14:56:16 -07003382 while (timeout) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003383 if (e1000_get_hw_eeprom_semaphore(hw))
3384 return -E1000_ERR_SWFW_SYNC;
3385
Joe Perches1dc32912008-07-11 15:17:08 -07003386 swfw_sync = er32(SW_FW_SYNC);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003387 if (!(swfw_sync & (fwmask | swmask))) {
3388 break;
3389 }
3390
3391 /* firmware currently using resource (fwmask) */
3392 /* or other software thread currently using resource (swmask) */
3393 e1000_put_hw_eeprom_semaphore(hw);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04003394 mdelay(5);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003395 timeout--;
3396 }
3397
3398 if (!timeout) {
3399 DEBUGOUT("Driver can't access resource, SW_FW_SYNC timeout.\n");
3400 return -E1000_ERR_SWFW_SYNC;
3401 }
3402
3403 swfw_sync |= swmask;
Joe Perches1dc32912008-07-11 15:17:08 -07003404 ew32(SW_FW_SYNC, swfw_sync);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003405
3406 e1000_put_hw_eeprom_semaphore(hw);
3407 return E1000_SUCCESS;
3408}
3409
Joe Perches64798842008-07-11 15:17:02 -07003410static void e1000_swfw_sync_release(struct e1000_hw *hw, u16 mask)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003411{
Joe Perches406874a2008-04-03 10:06:32 -07003412 u32 swfw_sync;
3413 u32 swmask = mask;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003414
3415 DEBUGFUNC("e1000_swfw_sync_release");
3416
Auke Kokcd94dd02006-06-27 09:08:22 -07003417 if (hw->swfwhw_semaphore_present) {
3418 e1000_release_software_flag(hw);
3419 return;
3420 }
3421
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003422 if (!hw->swfw_sync_present) {
3423 e1000_put_hw_eeprom_semaphore(hw);
3424 return;
3425 }
3426
3427 /* if (e1000_get_hw_eeprom_semaphore(hw))
3428 * return -E1000_ERR_SWFW_SYNC; */
3429 while (e1000_get_hw_eeprom_semaphore(hw) != E1000_SUCCESS);
3430 /* empty */
3431
Joe Perches1dc32912008-07-11 15:17:08 -07003432 swfw_sync = er32(SW_FW_SYNC);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003433 swfw_sync &= ~swmask;
Joe Perches1dc32912008-07-11 15:17:08 -07003434 ew32(SW_FW_SYNC, swfw_sync);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003435
3436 e1000_put_hw_eeprom_semaphore(hw);
3437}
3438
Linus Torvalds1da177e2005-04-16 15:20:36 -07003439/*****************************************************************************
3440* Reads the value from a PHY register, if the value is on a specific non zero
3441* page, sets the page first.
3442* hw - Struct containing variables accessed by shared code
3443* reg_addr - address of the PHY register to read
3444******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003445s32 e1000_read_phy_reg(struct e1000_hw *hw, u32 reg_addr, u16 *phy_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003446{
Joe Perches406874a2008-04-03 10:06:32 -07003447 u32 ret_val;
3448 u16 swfw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003449
3450 DEBUGFUNC("e1000_read_phy_reg");
3451
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003452 if ((hw->mac_type == e1000_80003es2lan) &&
Joe Perches1dc32912008-07-11 15:17:08 -07003453 (er32(STATUS) & E1000_STATUS_FUNC_1)) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003454 swfw = E1000_SWFW_PHY1_SM;
3455 } else {
3456 swfw = E1000_SWFW_PHY0_SM;
3457 }
3458 if (e1000_swfw_sync_acquire(hw, swfw))
3459 return -E1000_ERR_SWFW_SYNC;
3460
Auke Kokcd94dd02006-06-27 09:08:22 -07003461 if ((hw->phy_type == e1000_phy_igp ||
3462 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003463 hw->phy_type == e1000_phy_igp_2) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003464 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
3465 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
Joe Perches406874a2008-04-03 10:06:32 -07003466 (u16)reg_addr);
Auke Kok8fc897b2006-08-28 14:56:16 -07003467 if (ret_val) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003468 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003469 return ret_val;
3470 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003471 } else if (hw->phy_type == e1000_phy_gg82563) {
3472 if (((reg_addr & MAX_PHY_REG_ADDRESS) > MAX_PHY_MULTI_PAGE_REG) ||
3473 (hw->mac_type == e1000_80003es2lan)) {
3474 /* Select Configuration Page */
3475 if ((reg_addr & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) {
3476 ret_val = e1000_write_phy_reg_ex(hw, GG82563_PHY_PAGE_SELECT,
Joe Perches406874a2008-04-03 10:06:32 -07003477 (u16)((u16)reg_addr >> GG82563_PAGE_SHIFT));
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003478 } else {
3479 /* Use Alternative Page Select register to access
3480 * registers 30 and 31
3481 */
3482 ret_val = e1000_write_phy_reg_ex(hw,
3483 GG82563_PHY_PAGE_SELECT_ALT,
Joe Perches406874a2008-04-03 10:06:32 -07003484 (u16)((u16)reg_addr >> GG82563_PAGE_SHIFT));
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003485 }
3486
3487 if (ret_val) {
3488 e1000_swfw_sync_release(hw, swfw);
3489 return ret_val;
3490 }
3491 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003492 }
3493
3494 ret_val = e1000_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
3495 phy_data);
3496
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003497 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003498 return ret_val;
3499}
3500
Joe Perches64798842008-07-11 15:17:02 -07003501static s32 e1000_read_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr,
3502 u16 *phy_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003503{
Joe Perches406874a2008-04-03 10:06:32 -07003504 u32 i;
3505 u32 mdic = 0;
3506 const u32 phy_addr = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003507
3508 DEBUGFUNC("e1000_read_phy_reg_ex");
3509
Auke Kok8fc897b2006-08-28 14:56:16 -07003510 if (reg_addr > MAX_PHY_REG_ADDRESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003511 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
3512 return -E1000_ERR_PARAM;
3513 }
3514
Auke Kok8fc897b2006-08-28 14:56:16 -07003515 if (hw->mac_type > e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003516 /* Set up Op-code, Phy Address, and register address in the MDI
3517 * Control register. The MAC will take care of interfacing with the
3518 * PHY to retrieve the desired data.
3519 */
3520 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
3521 (phy_addr << E1000_MDIC_PHY_SHIFT) |
3522 (E1000_MDIC_OP_READ));
3523
Joe Perches1dc32912008-07-11 15:17:08 -07003524 ew32(MDIC, mdic);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003525
3526 /* Poll the ready bit to see if the MDI read completed */
Auke Kok8fc897b2006-08-28 14:56:16 -07003527 for (i = 0; i < 64; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003528 udelay(50);
Joe Perches1dc32912008-07-11 15:17:08 -07003529 mdic = er32(MDIC);
Auke Kok8fc897b2006-08-28 14:56:16 -07003530 if (mdic & E1000_MDIC_READY) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003531 }
Auke Kok8fc897b2006-08-28 14:56:16 -07003532 if (!(mdic & E1000_MDIC_READY)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003533 DEBUGOUT("MDI Read did not complete\n");
3534 return -E1000_ERR_PHY;
3535 }
Auke Kok8fc897b2006-08-28 14:56:16 -07003536 if (mdic & E1000_MDIC_ERROR) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003537 DEBUGOUT("MDI Error\n");
3538 return -E1000_ERR_PHY;
3539 }
Joe Perchese982f172008-07-11 15:17:18 -07003540 *phy_data = (u16)mdic;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003541 } else {
3542 /* We must first send a preamble through the MDIO pin to signal the
3543 * beginning of an MII instruction. This is done by sending 32
3544 * consecutive "1" bits.
3545 */
3546 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
3547
3548 /* Now combine the next few fields that are required for a read
3549 * operation. We use this method instead of calling the
3550 * e1000_shift_out_mdi_bits routine five different times. The format of
3551 * a MII read instruction consists of a shift out of 14 bits and is
3552 * defined as follows:
3553 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
3554 * followed by a shift in of 18 bits. This first two bits shifted in
3555 * are TurnAround bits used to avoid contention on the MDIO pin when a
3556 * READ operation is performed. These two bits are thrown away
3557 * followed by a shift in of 16 bits which contains the desired data.
3558 */
3559 mdic = ((reg_addr) | (phy_addr << 5) |
3560 (PHY_OP_READ << 10) | (PHY_SOF << 12));
3561
3562 e1000_shift_out_mdi_bits(hw, mdic, 14);
3563
3564 /* Now that we've shifted out the read command to the MII, we need to
3565 * "shift in" the 16-bit value (18 total bits) of the requested PHY
3566 * register address.
3567 */
3568 *phy_data = e1000_shift_in_mdi_bits(hw);
3569 }
3570 return E1000_SUCCESS;
3571}
3572
3573/******************************************************************************
3574* Writes a value to a PHY register
3575*
3576* hw - Struct containing variables accessed by shared code
3577* reg_addr - address of the PHY register to write
3578* data - data to write to the PHY
3579******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003580s32 e1000_write_phy_reg(struct e1000_hw *hw, u32 reg_addr, u16 phy_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003581{
Joe Perches406874a2008-04-03 10:06:32 -07003582 u32 ret_val;
3583 u16 swfw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003584
3585 DEBUGFUNC("e1000_write_phy_reg");
3586
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003587 if ((hw->mac_type == e1000_80003es2lan) &&
Joe Perches1dc32912008-07-11 15:17:08 -07003588 (er32(STATUS) & E1000_STATUS_FUNC_1)) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003589 swfw = E1000_SWFW_PHY1_SM;
3590 } else {
3591 swfw = E1000_SWFW_PHY0_SM;
3592 }
3593 if (e1000_swfw_sync_acquire(hw, swfw))
3594 return -E1000_ERR_SWFW_SYNC;
3595
Auke Kokcd94dd02006-06-27 09:08:22 -07003596 if ((hw->phy_type == e1000_phy_igp ||
3597 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003598 hw->phy_type == e1000_phy_igp_2) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003599 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
3600 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
Joe Perches406874a2008-04-03 10:06:32 -07003601 (u16)reg_addr);
Auke Kok8fc897b2006-08-28 14:56:16 -07003602 if (ret_val) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003603 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003604 return ret_val;
3605 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003606 } else if (hw->phy_type == e1000_phy_gg82563) {
3607 if (((reg_addr & MAX_PHY_REG_ADDRESS) > MAX_PHY_MULTI_PAGE_REG) ||
3608 (hw->mac_type == e1000_80003es2lan)) {
3609 /* Select Configuration Page */
3610 if ((reg_addr & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) {
3611 ret_val = e1000_write_phy_reg_ex(hw, GG82563_PHY_PAGE_SELECT,
Joe Perches406874a2008-04-03 10:06:32 -07003612 (u16)((u16)reg_addr >> GG82563_PAGE_SHIFT));
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003613 } else {
3614 /* Use Alternative Page Select register to access
3615 * registers 30 and 31
3616 */
3617 ret_val = e1000_write_phy_reg_ex(hw,
3618 GG82563_PHY_PAGE_SELECT_ALT,
Joe Perches406874a2008-04-03 10:06:32 -07003619 (u16)((u16)reg_addr >> GG82563_PAGE_SHIFT));
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003620 }
3621
3622 if (ret_val) {
3623 e1000_swfw_sync_release(hw, swfw);
3624 return ret_val;
3625 }
3626 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003627 }
3628
3629 ret_val = e1000_write_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
3630 phy_data);
3631
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003632 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003633 return ret_val;
3634}
3635
Joe Perches64798842008-07-11 15:17:02 -07003636static s32 e1000_write_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr,
3637 u16 phy_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003638{
Joe Perches406874a2008-04-03 10:06:32 -07003639 u32 i;
3640 u32 mdic = 0;
3641 const u32 phy_addr = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003642
3643 DEBUGFUNC("e1000_write_phy_reg_ex");
3644
Auke Kok8fc897b2006-08-28 14:56:16 -07003645 if (reg_addr > MAX_PHY_REG_ADDRESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003646 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
3647 return -E1000_ERR_PARAM;
3648 }
3649
Auke Kok8fc897b2006-08-28 14:56:16 -07003650 if (hw->mac_type > e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003651 /* Set up Op-code, Phy Address, register address, and data intended
3652 * for the PHY register in the MDI Control register. The MAC will take
3653 * care of interfacing with the PHY to send the desired data.
3654 */
Joe Perchese982f172008-07-11 15:17:18 -07003655 mdic = (((u32)phy_data) |
Linus Torvalds1da177e2005-04-16 15:20:36 -07003656 (reg_addr << E1000_MDIC_REG_SHIFT) |
3657 (phy_addr << E1000_MDIC_PHY_SHIFT) |
3658 (E1000_MDIC_OP_WRITE));
3659
Joe Perches1dc32912008-07-11 15:17:08 -07003660 ew32(MDIC, mdic);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003661
3662 /* Poll the ready bit to see if the MDI read completed */
Auke Kok8fc897b2006-08-28 14:56:16 -07003663 for (i = 0; i < 641; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003664 udelay(5);
Joe Perches1dc32912008-07-11 15:17:08 -07003665 mdic = er32(MDIC);
Auke Kok8fc897b2006-08-28 14:56:16 -07003666 if (mdic & E1000_MDIC_READY) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003667 }
Auke Kok8fc897b2006-08-28 14:56:16 -07003668 if (!(mdic & E1000_MDIC_READY)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003669 DEBUGOUT("MDI Write did not complete\n");
3670 return -E1000_ERR_PHY;
3671 }
3672 } else {
3673 /* We'll need to use the SW defined pins to shift the write command
3674 * out to the PHY. We first send a preamble to the PHY to signal the
3675 * beginning of the MII instruction. This is done by sending 32
3676 * consecutive "1" bits.
3677 */
3678 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
3679
3680 /* Now combine the remaining required fields that will indicate a
3681 * write operation. We use this method instead of calling the
3682 * e1000_shift_out_mdi_bits routine for each field in the command. The
3683 * format of a MII write instruction is as follows:
3684 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
3685 */
3686 mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
3687 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
3688 mdic <<= 16;
Joe Perchese982f172008-07-11 15:17:18 -07003689 mdic |= (u32)phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003690
3691 e1000_shift_out_mdi_bits(hw, mdic, 32);
3692 }
3693
3694 return E1000_SUCCESS;
3695}
3696
Joe Perches64798842008-07-11 15:17:02 -07003697static s32 e1000_read_kmrn_reg(struct e1000_hw *hw, u32 reg_addr, u16 *data)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003698{
Joe Perches406874a2008-04-03 10:06:32 -07003699 u32 reg_val;
3700 u16 swfw;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003701 DEBUGFUNC("e1000_read_kmrn_reg");
3702
3703 if ((hw->mac_type == e1000_80003es2lan) &&
Joe Perches1dc32912008-07-11 15:17:08 -07003704 (er32(STATUS) & E1000_STATUS_FUNC_1)) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003705 swfw = E1000_SWFW_PHY1_SM;
3706 } else {
3707 swfw = E1000_SWFW_PHY0_SM;
3708 }
3709 if (e1000_swfw_sync_acquire(hw, swfw))
3710 return -E1000_ERR_SWFW_SYNC;
3711
3712 /* Write register address */
3713 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
3714 E1000_KUMCTRLSTA_OFFSET) |
3715 E1000_KUMCTRLSTA_REN;
Joe Perches1dc32912008-07-11 15:17:08 -07003716 ew32(KUMCTRLSTA, reg_val);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003717 udelay(2);
3718
3719 /* Read the data returned */
Joe Perches1dc32912008-07-11 15:17:08 -07003720 reg_val = er32(KUMCTRLSTA);
Joe Perches406874a2008-04-03 10:06:32 -07003721 *data = (u16)reg_val;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003722
3723 e1000_swfw_sync_release(hw, swfw);
3724 return E1000_SUCCESS;
3725}
3726
Joe Perches64798842008-07-11 15:17:02 -07003727static s32 e1000_write_kmrn_reg(struct e1000_hw *hw, u32 reg_addr, u16 data)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003728{
Joe Perches406874a2008-04-03 10:06:32 -07003729 u32 reg_val;
3730 u16 swfw;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003731 DEBUGFUNC("e1000_write_kmrn_reg");
3732
3733 if ((hw->mac_type == e1000_80003es2lan) &&
Joe Perches1dc32912008-07-11 15:17:08 -07003734 (er32(STATUS) & E1000_STATUS_FUNC_1)) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003735 swfw = E1000_SWFW_PHY1_SM;
3736 } else {
3737 swfw = E1000_SWFW_PHY0_SM;
3738 }
3739 if (e1000_swfw_sync_acquire(hw, swfw))
3740 return -E1000_ERR_SWFW_SYNC;
3741
3742 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
3743 E1000_KUMCTRLSTA_OFFSET) | data;
Joe Perches1dc32912008-07-11 15:17:08 -07003744 ew32(KUMCTRLSTA, reg_val);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003745 udelay(2);
3746
3747 e1000_swfw_sync_release(hw, swfw);
3748 return E1000_SUCCESS;
3749}
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003750
Linus Torvalds1da177e2005-04-16 15:20:36 -07003751/******************************************************************************
3752* Returns the PHY to the power-on reset state
3753*
3754* hw - Struct containing variables accessed by shared code
3755******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003756s32 e1000_phy_hw_reset(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003757{
Joe Perches406874a2008-04-03 10:06:32 -07003758 u32 ctrl, ctrl_ext;
3759 u32 led_ctrl;
3760 s32 ret_val;
3761 u16 swfw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003762
3763 DEBUGFUNC("e1000_phy_hw_reset");
3764
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003765 /* In the case of the phy reset being blocked, it's not an error, we
3766 * simply return success without performing the reset. */
3767 ret_val = e1000_check_phy_reset_block(hw);
3768 if (ret_val)
3769 return E1000_SUCCESS;
3770
Linus Torvalds1da177e2005-04-16 15:20:36 -07003771 DEBUGOUT("Resetting Phy...\n");
3772
Auke Kok8fc897b2006-08-28 14:56:16 -07003773 if (hw->mac_type > e1000_82543) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003774 if ((hw->mac_type == e1000_80003es2lan) &&
Joe Perches1dc32912008-07-11 15:17:08 -07003775 (er32(STATUS) & E1000_STATUS_FUNC_1)) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003776 swfw = E1000_SWFW_PHY1_SM;
3777 } else {
3778 swfw = E1000_SWFW_PHY0_SM;
3779 }
3780 if (e1000_swfw_sync_acquire(hw, swfw)) {
Jeff Kirsher2a88c172006-09-27 12:54:05 -07003781 DEBUGOUT("Unable to acquire swfw sync\n");
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003782 return -E1000_ERR_SWFW_SYNC;
3783 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003784 /* Read the device control register and assert the E1000_CTRL_PHY_RST
3785 * bit. Then, take it out of reset.
Auke Kok76c224b2006-05-23 13:36:06 -07003786 * For pre-e1000_82571 hardware, we delay for 10ms between the assert
Jeff Kirsherfd803242005-12-13 00:06:22 -05003787 * and deassert. For e1000_82571 hardware and later, we instead delay
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08003788 * for 50us between and 10ms after the deassertion.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003789 */
Joe Perches1dc32912008-07-11 15:17:08 -07003790 ctrl = er32(CTRL);
3791 ew32(CTRL, ctrl | E1000_CTRL_PHY_RST);
3792 E1000_WRITE_FLUSH();
Auke Kok76c224b2006-05-23 13:36:06 -07003793
3794 if (hw->mac_type < e1000_82571)
Jeff Garzikf8ec4732006-09-19 15:27:07 -04003795 msleep(10);
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08003796 else
3797 udelay(100);
Auke Kok76c224b2006-05-23 13:36:06 -07003798
Joe Perches1dc32912008-07-11 15:17:08 -07003799 ew32(CTRL, ctrl);
3800 E1000_WRITE_FLUSH();
Auke Kok76c224b2006-05-23 13:36:06 -07003801
Jeff Kirsherfd803242005-12-13 00:06:22 -05003802 if (hw->mac_type >= e1000_82571)
Jeff Garzikf8ec4732006-09-19 15:27:07 -04003803 mdelay(10);
Nicholas Nunley35574762006-09-27 12:53:34 -07003804
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003805 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003806 } else {
3807 /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
3808 * bit to put the PHY into reset. Then, take it out of reset.
3809 */
Joe Perches1dc32912008-07-11 15:17:08 -07003810 ctrl_ext = er32(CTRL_EXT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003811 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
3812 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
Joe Perches1dc32912008-07-11 15:17:08 -07003813 ew32(CTRL_EXT, ctrl_ext);
3814 E1000_WRITE_FLUSH();
Jeff Garzikf8ec4732006-09-19 15:27:07 -04003815 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003816 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
Joe Perches1dc32912008-07-11 15:17:08 -07003817 ew32(CTRL_EXT, ctrl_ext);
3818 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003819 }
3820 udelay(150);
3821
Auke Kok8fc897b2006-08-28 14:56:16 -07003822 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003823 /* Configure activity LED after PHY reset */
Joe Perches1dc32912008-07-11 15:17:08 -07003824 led_ctrl = er32(LEDCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003825 led_ctrl &= IGP_ACTIVITY_LED_MASK;
3826 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
Joe Perches1dc32912008-07-11 15:17:08 -07003827 ew32(LEDCTL, led_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003828 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003829
3830 /* Wait for FW to finish PHY configuration. */
3831 ret_val = e1000_get_phy_cfg_done(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07003832 if (ret_val != E1000_SUCCESS)
3833 return ret_val;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003834 e1000_release_software_semaphore(hw);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003835
Auke Kok8fc897b2006-08-28 14:56:16 -07003836 if ((hw->mac_type == e1000_ich8lan) && (hw->phy_type == e1000_phy_igp_3))
3837 ret_val = e1000_init_lcd_from_nvm(hw);
3838
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003839 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003840}
3841
3842/******************************************************************************
3843* Resets the PHY
3844*
3845* hw - Struct containing variables accessed by shared code
3846*
Matt LaPlante0779bf22006-11-30 05:24:39 +01003847* Sets bit 15 of the MII Control register
Linus Torvalds1da177e2005-04-16 15:20:36 -07003848******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003849s32 e1000_phy_reset(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003850{
Joe Perches406874a2008-04-03 10:06:32 -07003851 s32 ret_val;
3852 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003853
3854 DEBUGFUNC("e1000_phy_reset");
3855
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003856 /* In the case of the phy reset being blocked, it's not an error, we
3857 * simply return success without performing the reset. */
3858 ret_val = e1000_check_phy_reset_block(hw);
3859 if (ret_val)
3860 return E1000_SUCCESS;
3861
Jeff Kirsher2a88c172006-09-27 12:54:05 -07003862 switch (hw->phy_type) {
3863 case e1000_phy_igp:
3864 case e1000_phy_igp_2:
3865 case e1000_phy_igp_3:
3866 case e1000_phy_ife:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003867 ret_val = e1000_phy_hw_reset(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07003868 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003869 return ret_val;
3870 break;
3871 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003872 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003873 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003874 return ret_val;
3875
3876 phy_data |= MII_CR_RESET;
3877 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003878 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003879 return ret_val;
3880
3881 udelay(1);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003882 break;
3883 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003884
Auke Kok8fc897b2006-08-28 14:56:16 -07003885 if (hw->phy_type == e1000_phy_igp || hw->phy_type == e1000_phy_igp_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003886 e1000_phy_init_script(hw);
3887
3888 return E1000_SUCCESS;
3889}
3890
3891/******************************************************************************
Auke Kokd37ea5d2006-06-27 09:08:17 -07003892* Work-around for 82566 power-down: on D3 entry-
3893* 1) disable gigabit link
3894* 2) write VR power-down enable
3895* 3) read it back
3896* if successful continue, else issue LCD reset and repeat
3897*
3898* hw - struct containing variables accessed by shared code
3899******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003900void e1000_phy_powerdown_workaround(struct e1000_hw *hw)
Auke Kokd37ea5d2006-06-27 09:08:17 -07003901{
Joe Perches406874a2008-04-03 10:06:32 -07003902 s32 reg;
3903 u16 phy_data;
3904 s32 retry = 0;
Auke Kokd37ea5d2006-06-27 09:08:17 -07003905
3906 DEBUGFUNC("e1000_phy_powerdown_workaround");
3907
3908 if (hw->phy_type != e1000_phy_igp_3)
3909 return;
3910
3911 do {
3912 /* Disable link */
Joe Perches1dc32912008-07-11 15:17:08 -07003913 reg = er32(PHY_CTRL);
3914 ew32(PHY_CTRL, reg | E1000_PHY_CTRL_GBE_DISABLE |
Auke Kokd37ea5d2006-06-27 09:08:17 -07003915 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
3916
Jeff Kirsher070f6ff2006-11-01 08:47:44 -08003917 /* Write VR power-down enable - bits 9:8 should be 10b */
Auke Kokd37ea5d2006-06-27 09:08:17 -07003918 e1000_read_phy_reg(hw, IGP3_VR_CTRL, &phy_data);
Jeff Kirsher070f6ff2006-11-01 08:47:44 -08003919 phy_data |= (1 << 9);
3920 phy_data &= ~(1 << 8);
3921 e1000_write_phy_reg(hw, IGP3_VR_CTRL, phy_data);
Auke Kokd37ea5d2006-06-27 09:08:17 -07003922
3923 /* Read it back and test */
3924 e1000_read_phy_reg(hw, IGP3_VR_CTRL, &phy_data);
Jeff Kirsher070f6ff2006-11-01 08:47:44 -08003925 if (((phy_data & IGP3_VR_CTRL_MODE_MASK) == IGP3_VR_CTRL_MODE_SHUT) || retry)
Auke Kokd37ea5d2006-06-27 09:08:17 -07003926 break;
3927
3928 /* Issue PHY reset and repeat at most one more time */
Joe Perches1dc32912008-07-11 15:17:08 -07003929 reg = er32(CTRL);
3930 ew32(CTRL, reg | E1000_CTRL_PHY_RST);
Auke Kokd37ea5d2006-06-27 09:08:17 -07003931 retry++;
3932 } while (retry);
3933
3934 return;
3935
3936}
3937
3938/******************************************************************************
3939* Work-around for 82566 Kumeran PCS lock loss:
3940* On link status change (i.e. PCI reset, speed change) and link is up and
3941* speed is gigabit-
3942* 0) if workaround is optionally disabled do nothing
3943* 1) wait 1ms for Kumeran link to come up
3944* 2) check Kumeran Diagnostic register PCS lock loss bit
3945* 3) if not set the link is locked (all is good), otherwise...
3946* 4) reset the PHY
3947* 5) repeat up to 10 times
3948* Note: this is only called for IGP3 copper when speed is 1gb.
3949*
3950* hw - struct containing variables accessed by shared code
3951******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003952static s32 e1000_kumeran_lock_loss_workaround(struct e1000_hw *hw)
Auke Kokd37ea5d2006-06-27 09:08:17 -07003953{
Joe Perches406874a2008-04-03 10:06:32 -07003954 s32 ret_val;
3955 s32 reg;
3956 s32 cnt;
3957 u16 phy_data;
Auke Kokd37ea5d2006-06-27 09:08:17 -07003958
3959 if (hw->kmrn_lock_loss_workaround_disabled)
3960 return E1000_SUCCESS;
3961
Auke Kok8fc897b2006-08-28 14:56:16 -07003962 /* Make sure link is up before proceeding. If not just return.
3963 * Attempting this while link is negotiating fouled up link
Auke Kokd37ea5d2006-06-27 09:08:17 -07003964 * stability */
3965 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3966 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3967
3968 if (phy_data & MII_SR_LINK_STATUS) {
3969 for (cnt = 0; cnt < 10; cnt++) {
3970 /* read once to clear */
3971 ret_val = e1000_read_phy_reg(hw, IGP3_KMRN_DIAG, &phy_data);
3972 if (ret_val)
3973 return ret_val;
3974 /* and again to get new status */
3975 ret_val = e1000_read_phy_reg(hw, IGP3_KMRN_DIAG, &phy_data);
3976 if (ret_val)
3977 return ret_val;
3978
3979 /* check for PCS lock */
3980 if (!(phy_data & IGP3_KMRN_DIAG_PCS_LOCK_LOSS))
3981 return E1000_SUCCESS;
3982
3983 /* Issue PHY reset */
3984 e1000_phy_hw_reset(hw);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04003985 mdelay(5);
Auke Kokd37ea5d2006-06-27 09:08:17 -07003986 }
3987 /* Disable GigE link negotiation */
Joe Perches1dc32912008-07-11 15:17:08 -07003988 reg = er32(PHY_CTRL);
3989 ew32(PHY_CTRL, reg | E1000_PHY_CTRL_GBE_DISABLE |
Auke Kokd37ea5d2006-06-27 09:08:17 -07003990 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
3991
3992 /* unable to acquire PCS lock */
3993 return E1000_ERR_PHY;
3994 }
3995
3996 return E1000_SUCCESS;
3997}
3998
3999/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07004000* Probes the expected PHY address for known PHY IDs
4001*
4002* hw - Struct containing variables accessed by shared code
4003******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004004static s32 e1000_detect_gig_phy(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004005{
Joe Perches406874a2008-04-03 10:06:32 -07004006 s32 phy_init_status, ret_val;
4007 u16 phy_id_high, phy_id_low;
Joe Perchesc3033b02008-03-21 11:06:25 -07004008 bool match = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004009
4010 DEBUGFUNC("e1000_detect_gig_phy");
4011
Jeff Kirsher2a88c172006-09-27 12:54:05 -07004012 if (hw->phy_id != 0)
4013 return E1000_SUCCESS;
4014
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004015 /* The 82571 firmware may still be configuring the PHY. In this
4016 * case, we cannot access the PHY until the configuration is done. So
4017 * we explicitly set the PHY values. */
Auke Kokcd94dd02006-06-27 09:08:22 -07004018 if (hw->mac_type == e1000_82571 ||
4019 hw->mac_type == e1000_82572) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004020 hw->phy_id = IGP01E1000_I_PHY_ID;
4021 hw->phy_type = e1000_phy_igp_2;
4022 return E1000_SUCCESS;
4023 }
4024
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004025 /* ESB-2 PHY reads require e1000_phy_gg82563 to be set because of a work-
4026 * around that forces PHY page 0 to be set or the reads fail. The rest of
4027 * the code in this routine uses e1000_read_phy_reg to read the PHY ID.
4028 * So for ESB-2 we need to have this set so our reads won't fail. If the
4029 * attached PHY is not a e1000_phy_gg82563, the routines below will figure
4030 * this out as well. */
4031 if (hw->mac_type == e1000_80003es2lan)
4032 hw->phy_type = e1000_phy_gg82563;
4033
Linus Torvalds1da177e2005-04-16 15:20:36 -07004034 /* Read the PHY ID Registers to identify which PHY is onboard. */
4035 ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
Auke Kokcd94dd02006-06-27 09:08:22 -07004036 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004037 return ret_val;
4038
Joe Perchese982f172008-07-11 15:17:18 -07004039 hw->phy_id = (u32)(phy_id_high << 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004040 udelay(20);
4041 ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
Auke Kok8fc897b2006-08-28 14:56:16 -07004042 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004043 return ret_val;
4044
Joe Perchese982f172008-07-11 15:17:18 -07004045 hw->phy_id |= (u32)(phy_id_low & PHY_REVISION_MASK);
4046 hw->phy_revision = (u32)phy_id_low & ~PHY_REVISION_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004047
Auke Kok8fc897b2006-08-28 14:56:16 -07004048 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004049 case e1000_82543:
Joe Perchesc3033b02008-03-21 11:06:25 -07004050 if (hw->phy_id == M88E1000_E_PHY_ID) match = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004051 break;
4052 case e1000_82544:
Joe Perchesc3033b02008-03-21 11:06:25 -07004053 if (hw->phy_id == M88E1000_I_PHY_ID) match = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004054 break;
4055 case e1000_82540:
4056 case e1000_82545:
4057 case e1000_82545_rev_3:
4058 case e1000_82546:
4059 case e1000_82546_rev_3:
Joe Perchesc3033b02008-03-21 11:06:25 -07004060 if (hw->phy_id == M88E1011_I_PHY_ID) match = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004061 break;
4062 case e1000_82541:
4063 case e1000_82541_rev_2:
4064 case e1000_82547:
4065 case e1000_82547_rev_2:
Joe Perchesc3033b02008-03-21 11:06:25 -07004066 if (hw->phy_id == IGP01E1000_I_PHY_ID) match = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004067 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004068 case e1000_82573:
Joe Perchesc3033b02008-03-21 11:06:25 -07004069 if (hw->phy_id == M88E1111_I_PHY_ID) match = true;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004070 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004071 case e1000_80003es2lan:
Joe Perchesc3033b02008-03-21 11:06:25 -07004072 if (hw->phy_id == GG82563_E_PHY_ID) match = true;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004073 break;
Auke Kokcd94dd02006-06-27 09:08:22 -07004074 case e1000_ich8lan:
Joe Perchesc3033b02008-03-21 11:06:25 -07004075 if (hw->phy_id == IGP03E1000_E_PHY_ID) match = true;
4076 if (hw->phy_id == IFE_E_PHY_ID) match = true;
4077 if (hw->phy_id == IFE_PLUS_E_PHY_ID) match = true;
4078 if (hw->phy_id == IFE_C_E_PHY_ID) match = true;
Auke Kokcd94dd02006-06-27 09:08:22 -07004079 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004080 default:
4081 DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type);
4082 return -E1000_ERR_CONFIG;
4083 }
4084 phy_init_status = e1000_set_phy_type(hw);
4085
4086 if ((match) && (phy_init_status == E1000_SUCCESS)) {
4087 DEBUGOUT1("PHY ID 0x%X detected\n", hw->phy_id);
4088 return E1000_SUCCESS;
4089 }
4090 DEBUGOUT1("Invalid PHY ID 0x%X\n", hw->phy_id);
4091 return -E1000_ERR_PHY;
4092}
4093
4094/******************************************************************************
4095* Resets the PHY's DSP
4096*
4097* hw - Struct containing variables accessed by shared code
4098******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004099static s32 e1000_phy_reset_dsp(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004100{
Joe Perches406874a2008-04-03 10:06:32 -07004101 s32 ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004102 DEBUGFUNC("e1000_phy_reset_dsp");
4103
4104 do {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004105 if (hw->phy_type != e1000_phy_gg82563) {
4106 ret_val = e1000_write_phy_reg(hw, 29, 0x001d);
Auke Kok8fc897b2006-08-28 14:56:16 -07004107 if (ret_val) break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004108 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004109 ret_val = e1000_write_phy_reg(hw, 30, 0x00c1);
Auke Kok8fc897b2006-08-28 14:56:16 -07004110 if (ret_val) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004111 ret_val = e1000_write_phy_reg(hw, 30, 0x0000);
Auke Kok8fc897b2006-08-28 14:56:16 -07004112 if (ret_val) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004113 ret_val = E1000_SUCCESS;
Auke Kok8fc897b2006-08-28 14:56:16 -07004114 } while (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004115
4116 return ret_val;
4117}
4118
4119/******************************************************************************
4120* Get PHY information from various PHY registers for igp PHY only.
4121*
4122* hw - Struct containing variables accessed by shared code
4123* phy_info - PHY information structure
4124******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004125static s32 e1000_phy_igp_get_info(struct e1000_hw *hw,
4126 struct e1000_phy_info *phy_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004127{
Joe Perches406874a2008-04-03 10:06:32 -07004128 s32 ret_val;
4129 u16 phy_data, min_length, max_length, average;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004130 e1000_rev_polarity polarity;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004131
4132 DEBUGFUNC("e1000_phy_igp_get_info");
4133
4134 /* The downshift status is checked only once, after link is established,
4135 * and it stored in the hw->speed_downgraded parameter. */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004136 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004137
4138 /* IGP01E1000 does not need to support it. */
4139 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
4140
4141 /* IGP01E1000 always correct polarity reversal */
4142 phy_info->polarity_correction = e1000_polarity_reversal_enabled;
4143
4144 /* Check polarity status */
4145 ret_val = e1000_check_polarity(hw, &polarity);
Auke Kok8fc897b2006-08-28 14:56:16 -07004146 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004147 return ret_val;
4148
4149 phy_info->cable_polarity = polarity;
4150
4151 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004152 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004153 return ret_val;
4154
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004155 phy_info->mdix_mode = (e1000_auto_x_mode)((phy_data & IGP01E1000_PSSR_MDIX) >>
4156 IGP01E1000_PSSR_MDIX_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004157
Auke Kok8fc897b2006-08-28 14:56:16 -07004158 if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
Linus Torvalds1da177e2005-04-16 15:20:36 -07004159 IGP01E1000_PSSR_SPEED_1000MBPS) {
4160 /* Local/Remote Receiver Information are only valid at 1000 Mbps */
4161 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004162 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004163 return ret_val;
4164
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004165 phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
4166 SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
4167 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
4168 phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
4169 SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
4170 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004171
4172 /* Get cable length */
4173 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
Auke Kok8fc897b2006-08-28 14:56:16 -07004174 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004175 return ret_val;
4176
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004177 /* Translate to old method */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004178 average = (max_length + min_length) / 2;
4179
Auke Kok8fc897b2006-08-28 14:56:16 -07004180 if (average <= e1000_igp_cable_length_50)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004181 phy_info->cable_length = e1000_cable_length_50;
Auke Kok8fc897b2006-08-28 14:56:16 -07004182 else if (average <= e1000_igp_cable_length_80)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004183 phy_info->cable_length = e1000_cable_length_50_80;
Auke Kok8fc897b2006-08-28 14:56:16 -07004184 else if (average <= e1000_igp_cable_length_110)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004185 phy_info->cable_length = e1000_cable_length_80_110;
Auke Kok8fc897b2006-08-28 14:56:16 -07004186 else if (average <= e1000_igp_cable_length_140)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004187 phy_info->cable_length = e1000_cable_length_110_140;
4188 else
4189 phy_info->cable_length = e1000_cable_length_140;
4190 }
4191
4192 return E1000_SUCCESS;
4193}
4194
4195/******************************************************************************
Auke Kokd37ea5d2006-06-27 09:08:17 -07004196* Get PHY information from various PHY registers for ife PHY only.
4197*
4198* hw - Struct containing variables accessed by shared code
4199* phy_info - PHY information structure
4200******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004201static s32 e1000_phy_ife_get_info(struct e1000_hw *hw,
4202 struct e1000_phy_info *phy_info)
Auke Kokd37ea5d2006-06-27 09:08:17 -07004203{
Joe Perches406874a2008-04-03 10:06:32 -07004204 s32 ret_val;
4205 u16 phy_data;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004206 e1000_rev_polarity polarity;
Auke Kokd37ea5d2006-06-27 09:08:17 -07004207
4208 DEBUGFUNC("e1000_phy_ife_get_info");
4209
4210 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
4211 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
4212
4213 ret_val = e1000_read_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL, &phy_data);
4214 if (ret_val)
4215 return ret_val;
4216 phy_info->polarity_correction =
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004217 ((phy_data & IFE_PSC_AUTO_POLARITY_DISABLE) >>
4218 IFE_PSC_AUTO_POLARITY_DISABLE_SHIFT) ?
4219 e1000_polarity_reversal_disabled : e1000_polarity_reversal_enabled;
Auke Kokd37ea5d2006-06-27 09:08:17 -07004220
4221 if (phy_info->polarity_correction == e1000_polarity_reversal_enabled) {
4222 ret_val = e1000_check_polarity(hw, &polarity);
4223 if (ret_val)
4224 return ret_val;
4225 } else {
4226 /* Polarity is forced. */
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004227 polarity = ((phy_data & IFE_PSC_FORCE_POLARITY) >>
4228 IFE_PSC_FORCE_POLARITY_SHIFT) ?
4229 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
Auke Kokd37ea5d2006-06-27 09:08:17 -07004230 }
4231 phy_info->cable_polarity = polarity;
4232
4233 ret_val = e1000_read_phy_reg(hw, IFE_PHY_MDIX_CONTROL, &phy_data);
4234 if (ret_val)
4235 return ret_val;
4236
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004237 phy_info->mdix_mode = (e1000_auto_x_mode)
4238 ((phy_data & (IFE_PMC_AUTO_MDIX | IFE_PMC_FORCE_MDIX)) >>
4239 IFE_PMC_MDIX_MODE_SHIFT);
Auke Kokd37ea5d2006-06-27 09:08:17 -07004240
4241 return E1000_SUCCESS;
4242}
4243
4244/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07004245* Get PHY information from various PHY registers fot m88 PHY only.
4246*
4247* hw - Struct containing variables accessed by shared code
4248* phy_info - PHY information structure
4249******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004250static s32 e1000_phy_m88_get_info(struct e1000_hw *hw,
4251 struct e1000_phy_info *phy_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004252{
Joe Perches406874a2008-04-03 10:06:32 -07004253 s32 ret_val;
4254 u16 phy_data;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004255 e1000_rev_polarity polarity;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004256
4257 DEBUGFUNC("e1000_phy_m88_get_info");
4258
4259 /* The downshift status is checked only once, after link is established,
4260 * and it stored in the hw->speed_downgraded parameter. */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004261 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004262
4263 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004264 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004265 return ret_val;
4266
4267 phy_info->extended_10bt_distance =
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004268 ((phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >>
4269 M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT) ?
4270 e1000_10bt_ext_dist_enable_lower : e1000_10bt_ext_dist_enable_normal;
4271
Linus Torvalds1da177e2005-04-16 15:20:36 -07004272 phy_info->polarity_correction =
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004273 ((phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >>
4274 M88E1000_PSCR_POLARITY_REVERSAL_SHIFT) ?
4275 e1000_polarity_reversal_disabled : e1000_polarity_reversal_enabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004276
4277 /* Check polarity status */
4278 ret_val = e1000_check_polarity(hw, &polarity);
Auke Kok8fc897b2006-08-28 14:56:16 -07004279 if (ret_val)
Auke Kok76c224b2006-05-23 13:36:06 -07004280 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004281 phy_info->cable_polarity = polarity;
4282
4283 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004284 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004285 return ret_val;
4286
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004287 phy_info->mdix_mode = (e1000_auto_x_mode)((phy_data & M88E1000_PSSR_MDIX) >>
4288 M88E1000_PSSR_MDIX_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004289
4290 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
4291 /* Cable Length Estimation and Local/Remote Receiver Information
4292 * are only valid at 1000 Mbps.
4293 */
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004294 if (hw->phy_type != e1000_phy_gg82563) {
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004295 phy_info->cable_length = (e1000_cable_length)((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004296 M88E1000_PSSR_CABLE_LENGTH_SHIFT);
4297 } else {
4298 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_DSP_DISTANCE,
4299 &phy_data);
4300 if (ret_val)
4301 return ret_val;
4302
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004303 phy_info->cable_length = (e1000_cable_length)(phy_data & GG82563_DSPD_CABLE_LENGTH);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004304 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004305
4306 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004307 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004308 return ret_val;
4309
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004310 phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
4311 SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
4312 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
4313 phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
4314 SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
4315 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004316
Linus Torvalds1da177e2005-04-16 15:20:36 -07004317 }
4318
4319 return E1000_SUCCESS;
4320}
4321
4322/******************************************************************************
4323* Get PHY information from various PHY registers
4324*
4325* hw - Struct containing variables accessed by shared code
4326* phy_info - PHY information structure
4327******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004328s32 e1000_phy_get_info(struct e1000_hw *hw, struct e1000_phy_info *phy_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004329{
Joe Perches406874a2008-04-03 10:06:32 -07004330 s32 ret_val;
4331 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004332
4333 DEBUGFUNC("e1000_phy_get_info");
4334
4335 phy_info->cable_length = e1000_cable_length_undefined;
4336 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined;
4337 phy_info->cable_polarity = e1000_rev_polarity_undefined;
4338 phy_info->downshift = e1000_downshift_undefined;
4339 phy_info->polarity_correction = e1000_polarity_reversal_undefined;
4340 phy_info->mdix_mode = e1000_auto_x_mode_undefined;
4341 phy_info->local_rx = e1000_1000t_rx_status_undefined;
4342 phy_info->remote_rx = e1000_1000t_rx_status_undefined;
4343
Auke Kok8fc897b2006-08-28 14:56:16 -07004344 if (hw->media_type != e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004345 DEBUGOUT("PHY info is only valid for copper media\n");
4346 return -E1000_ERR_CONFIG;
4347 }
4348
4349 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004350 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004351 return ret_val;
4352
4353 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004354 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004355 return ret_val;
4356
Auke Kok8fc897b2006-08-28 14:56:16 -07004357 if ((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004358 DEBUGOUT("PHY info is only valid if link is up\n");
4359 return -E1000_ERR_CONFIG;
4360 }
4361
Auke Kokcd94dd02006-06-27 09:08:22 -07004362 if (hw->phy_type == e1000_phy_igp ||
4363 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004364 hw->phy_type == e1000_phy_igp_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004365 return e1000_phy_igp_get_info(hw, phy_info);
Auke Kokcd94dd02006-06-27 09:08:22 -07004366 else if (hw->phy_type == e1000_phy_ife)
4367 return e1000_phy_ife_get_info(hw, phy_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004368 else
4369 return e1000_phy_m88_get_info(hw, phy_info);
4370}
4371
Joe Perches64798842008-07-11 15:17:02 -07004372s32 e1000_validate_mdi_setting(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004373{
4374 DEBUGFUNC("e1000_validate_mdi_settings");
4375
Auke Kok8fc897b2006-08-28 14:56:16 -07004376 if (!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004377 DEBUGOUT("Invalid MDI setting detected\n");
4378 hw->mdix = 1;
4379 return -E1000_ERR_CONFIG;
4380 }
4381 return E1000_SUCCESS;
4382}
4383
4384
4385/******************************************************************************
4386 * Sets up eeprom variables in the hw struct. Must be called after mac_type
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004387 * is configured. Additionally, if this is ICH8, the flash controller GbE
4388 * registers must be mapped, or this will crash.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004389 *
4390 * hw - Struct containing variables accessed by shared code
4391 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004392s32 e1000_init_eeprom_params(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004393{
4394 struct e1000_eeprom_info *eeprom = &hw->eeprom;
Joe Perches1dc32912008-07-11 15:17:08 -07004395 u32 eecd = er32(EECD);
Joe Perches406874a2008-04-03 10:06:32 -07004396 s32 ret_val = E1000_SUCCESS;
4397 u16 eeprom_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004398
4399 DEBUGFUNC("e1000_init_eeprom_params");
4400
4401 switch (hw->mac_type) {
4402 case e1000_82542_rev2_0:
4403 case e1000_82542_rev2_1:
4404 case e1000_82543:
4405 case e1000_82544:
4406 eeprom->type = e1000_eeprom_microwire;
4407 eeprom->word_size = 64;
4408 eeprom->opcode_bits = 3;
4409 eeprom->address_bits = 6;
4410 eeprom->delay_usec = 50;
Joe Perchesc3033b02008-03-21 11:06:25 -07004411 eeprom->use_eerd = false;
4412 eeprom->use_eewr = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004413 break;
4414 case e1000_82540:
4415 case e1000_82545:
4416 case e1000_82545_rev_3:
4417 case e1000_82546:
4418 case e1000_82546_rev_3:
4419 eeprom->type = e1000_eeprom_microwire;
4420 eeprom->opcode_bits = 3;
4421 eeprom->delay_usec = 50;
Auke Kok8fc897b2006-08-28 14:56:16 -07004422 if (eecd & E1000_EECD_SIZE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004423 eeprom->word_size = 256;
4424 eeprom->address_bits = 8;
4425 } else {
4426 eeprom->word_size = 64;
4427 eeprom->address_bits = 6;
4428 }
Joe Perchesc3033b02008-03-21 11:06:25 -07004429 eeprom->use_eerd = false;
4430 eeprom->use_eewr = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004431 break;
4432 case e1000_82541:
4433 case e1000_82541_rev_2:
4434 case e1000_82547:
4435 case e1000_82547_rev_2:
4436 if (eecd & E1000_EECD_TYPE) {
4437 eeprom->type = e1000_eeprom_spi;
4438 eeprom->opcode_bits = 8;
4439 eeprom->delay_usec = 1;
4440 if (eecd & E1000_EECD_ADDR_BITS) {
4441 eeprom->page_size = 32;
4442 eeprom->address_bits = 16;
4443 } else {
4444 eeprom->page_size = 8;
4445 eeprom->address_bits = 8;
4446 }
4447 } else {
4448 eeprom->type = e1000_eeprom_microwire;
4449 eeprom->opcode_bits = 3;
4450 eeprom->delay_usec = 50;
4451 if (eecd & E1000_EECD_ADDR_BITS) {
4452 eeprom->word_size = 256;
4453 eeprom->address_bits = 8;
4454 } else {
4455 eeprom->word_size = 64;
4456 eeprom->address_bits = 6;
4457 }
4458 }
Joe Perchesc3033b02008-03-21 11:06:25 -07004459 eeprom->use_eerd = false;
4460 eeprom->use_eewr = false;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004461 break;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004462 case e1000_82571:
4463 case e1000_82572:
4464 eeprom->type = e1000_eeprom_spi;
4465 eeprom->opcode_bits = 8;
4466 eeprom->delay_usec = 1;
4467 if (eecd & E1000_EECD_ADDR_BITS) {
4468 eeprom->page_size = 32;
4469 eeprom->address_bits = 16;
4470 } else {
4471 eeprom->page_size = 8;
4472 eeprom->address_bits = 8;
4473 }
Joe Perchesc3033b02008-03-21 11:06:25 -07004474 eeprom->use_eerd = false;
4475 eeprom->use_eewr = false;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004476 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004477 case e1000_82573:
4478 eeprom->type = e1000_eeprom_spi;
4479 eeprom->opcode_bits = 8;
4480 eeprom->delay_usec = 1;
4481 if (eecd & E1000_EECD_ADDR_BITS) {
4482 eeprom->page_size = 32;
4483 eeprom->address_bits = 16;
4484 } else {
4485 eeprom->page_size = 8;
4486 eeprom->address_bits = 8;
4487 }
Joe Perchesc3033b02008-03-21 11:06:25 -07004488 eeprom->use_eerd = true;
4489 eeprom->use_eewr = true;
4490 if (!e1000_is_onboard_nvm_eeprom(hw)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004491 eeprom->type = e1000_eeprom_flash;
4492 eeprom->word_size = 2048;
4493
4494 /* Ensure that the Autonomous FLASH update bit is cleared due to
4495 * Flash update issue on parts which use a FLASH for NVM. */
4496 eecd &= ~E1000_EECD_AUPDEN;
Joe Perches1dc32912008-07-11 15:17:08 -07004497 ew32(EECD, eecd);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004498 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004499 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004500 case e1000_80003es2lan:
4501 eeprom->type = e1000_eeprom_spi;
4502 eeprom->opcode_bits = 8;
4503 eeprom->delay_usec = 1;
4504 if (eecd & E1000_EECD_ADDR_BITS) {
4505 eeprom->page_size = 32;
4506 eeprom->address_bits = 16;
4507 } else {
4508 eeprom->page_size = 8;
4509 eeprom->address_bits = 8;
4510 }
Joe Perchesc3033b02008-03-21 11:06:25 -07004511 eeprom->use_eerd = true;
4512 eeprom->use_eewr = false;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004513 break;
Auke Kokcd94dd02006-06-27 09:08:22 -07004514 case e1000_ich8lan:
Nicholas Nunley35574762006-09-27 12:53:34 -07004515 {
Joe Perches406874a2008-04-03 10:06:32 -07004516 s32 i = 0;
4517 u32 flash_size = E1000_READ_ICH_FLASH_REG(hw, ICH_FLASH_GFPREG);
Auke Kokcd94dd02006-06-27 09:08:22 -07004518
4519 eeprom->type = e1000_eeprom_ich8;
Joe Perchesc3033b02008-03-21 11:06:25 -07004520 eeprom->use_eerd = false;
4521 eeprom->use_eewr = false;
Auke Kokcd94dd02006-06-27 09:08:22 -07004522 eeprom->word_size = E1000_SHADOW_RAM_WORDS;
4523
4524 /* Zero the shadow RAM structure. But don't load it from NVM
4525 * so as to save time for driver init */
4526 if (hw->eeprom_shadow_ram != NULL) {
4527 for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
Joe Perchesc3033b02008-03-21 11:06:25 -07004528 hw->eeprom_shadow_ram[i].modified = false;
Auke Kokcd94dd02006-06-27 09:08:22 -07004529 hw->eeprom_shadow_ram[i].eeprom_word = 0xFFFF;
4530 }
4531 }
4532
Jeff Kirsher2df7d592006-11-01 08:48:02 -08004533 hw->flash_base_addr = (flash_size & ICH_GFPREG_BASE_MASK) *
4534 ICH_FLASH_SECTOR_SIZE;
Auke Kokcd94dd02006-06-27 09:08:22 -07004535
Jeff Kirsher2df7d592006-11-01 08:48:02 -08004536 hw->flash_bank_size = ((flash_size >> 16) & ICH_GFPREG_BASE_MASK) + 1;
4537 hw->flash_bank_size -= (flash_size & ICH_GFPREG_BASE_MASK);
4538
4539 hw->flash_bank_size *= ICH_FLASH_SECTOR_SIZE;
4540
Joe Perches406874a2008-04-03 10:06:32 -07004541 hw->flash_bank_size /= 2 * sizeof(u16);
Auke Kokcd94dd02006-06-27 09:08:22 -07004542
4543 break;
Nicholas Nunley35574762006-09-27 12:53:34 -07004544 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004545 default:
4546 break;
4547 }
4548
4549 if (eeprom->type == e1000_eeprom_spi) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004550 /* eeprom_size will be an enum [0..8] that maps to eeprom sizes 128B to
4551 * 32KB (incremented by powers of 2).
4552 */
Auke Kok8fc897b2006-08-28 14:56:16 -07004553 if (hw->mac_type <= e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004554 /* Set to default value for initial eeprom read. */
4555 eeprom->word_size = 64;
4556 ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size);
Auke Kok8fc897b2006-08-28 14:56:16 -07004557 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004558 return ret_val;
4559 eeprom_size = (eeprom_size & EEPROM_SIZE_MASK) >> EEPROM_SIZE_SHIFT;
4560 /* 256B eeprom size was not supported in earlier hardware, so we
4561 * bump eeprom_size up one to ensure that "1" (which maps to 256B)
4562 * is never the result used in the shifting logic below. */
Auke Kok8fc897b2006-08-28 14:56:16 -07004563 if (eeprom_size)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004564 eeprom_size++;
4565 } else {
Joe Perches406874a2008-04-03 10:06:32 -07004566 eeprom_size = (u16)((eecd & E1000_EECD_SIZE_EX_MASK) >>
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004567 E1000_EECD_SIZE_EX_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004568 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004569
4570 eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004571 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004572 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004573}
4574
4575/******************************************************************************
4576 * Raises the EEPROM's clock input.
4577 *
4578 * hw - Struct containing variables accessed by shared code
4579 * eecd - EECD's current value
4580 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004581static void e1000_raise_ee_clk(struct e1000_hw *hw, u32 *eecd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004582{
4583 /* Raise the clock input to the EEPROM (by setting the SK bit), and then
4584 * wait <delay> microseconds.
4585 */
4586 *eecd = *eecd | E1000_EECD_SK;
Joe Perches1dc32912008-07-11 15:17:08 -07004587 ew32(EECD, *eecd);
4588 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07004589 udelay(hw->eeprom.delay_usec);
4590}
4591
4592/******************************************************************************
4593 * Lowers the EEPROM's clock input.
4594 *
4595 * hw - Struct containing variables accessed by shared code
4596 * eecd - EECD's current value
4597 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004598static void e1000_lower_ee_clk(struct e1000_hw *hw, u32 *eecd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004599{
4600 /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
4601 * wait 50 microseconds.
4602 */
4603 *eecd = *eecd & ~E1000_EECD_SK;
Joe Perches1dc32912008-07-11 15:17:08 -07004604 ew32(EECD, *eecd);
4605 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07004606 udelay(hw->eeprom.delay_usec);
4607}
4608
4609/******************************************************************************
4610 * Shift data bits out to the EEPROM.
4611 *
4612 * hw - Struct containing variables accessed by shared code
4613 * data - data to send to the EEPROM
4614 * count - number of bits to shift out
4615 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004616static void e1000_shift_out_ee_bits(struct e1000_hw *hw, u16 data, u16 count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004617{
4618 struct e1000_eeprom_info *eeprom = &hw->eeprom;
Joe Perches406874a2008-04-03 10:06:32 -07004619 u32 eecd;
4620 u32 mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004621
4622 /* We need to shift "count" bits out to the EEPROM. So, value in the
4623 * "data" parameter will be shifted out to the EEPROM one bit at a time.
4624 * In order to do this, "data" must be broken down into bits.
4625 */
4626 mask = 0x01 << (count - 1);
Joe Perches1dc32912008-07-11 15:17:08 -07004627 eecd = er32(EECD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004628 if (eeprom->type == e1000_eeprom_microwire) {
4629 eecd &= ~E1000_EECD_DO;
4630 } else if (eeprom->type == e1000_eeprom_spi) {
4631 eecd |= E1000_EECD_DO;
4632 }
4633 do {
4634 /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
4635 * and then raising and then lowering the clock (the SK bit controls
4636 * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
4637 * by setting "DI" to "0" and then raising and then lowering the clock.
4638 */
4639 eecd &= ~E1000_EECD_DI;
4640
Auke Kok8fc897b2006-08-28 14:56:16 -07004641 if (data & mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004642 eecd |= E1000_EECD_DI;
4643
Joe Perches1dc32912008-07-11 15:17:08 -07004644 ew32(EECD, eecd);
4645 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07004646
4647 udelay(eeprom->delay_usec);
4648
4649 e1000_raise_ee_clk(hw, &eecd);
4650 e1000_lower_ee_clk(hw, &eecd);
4651
4652 mask = mask >> 1;
4653
Auke Kok8fc897b2006-08-28 14:56:16 -07004654 } while (mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004655
4656 /* We leave the "DI" bit set to "0" when we leave this routine. */
4657 eecd &= ~E1000_EECD_DI;
Joe Perches1dc32912008-07-11 15:17:08 -07004658 ew32(EECD, eecd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004659}
4660
4661/******************************************************************************
4662 * Shift data bits in from the EEPROM
4663 *
4664 * hw - Struct containing variables accessed by shared code
4665 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004666static u16 e1000_shift_in_ee_bits(struct e1000_hw *hw, u16 count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004667{
Joe Perches406874a2008-04-03 10:06:32 -07004668 u32 eecd;
4669 u32 i;
4670 u16 data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004671
4672 /* In order to read a register from the EEPROM, we need to shift 'count'
4673 * bits in from the EEPROM. Bits are "shifted in" by raising the clock
4674 * input to the EEPROM (setting the SK bit), and then reading the value of
4675 * the "DO" bit. During this "shifting in" process the "DI" bit should
4676 * always be clear.
4677 */
4678
Joe Perches1dc32912008-07-11 15:17:08 -07004679 eecd = er32(EECD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004680
4681 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
4682 data = 0;
4683
Auke Kok8fc897b2006-08-28 14:56:16 -07004684 for (i = 0; i < count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004685 data = data << 1;
4686 e1000_raise_ee_clk(hw, &eecd);
4687
Joe Perches1dc32912008-07-11 15:17:08 -07004688 eecd = er32(EECD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004689
4690 eecd &= ~(E1000_EECD_DI);
Auke Kok8fc897b2006-08-28 14:56:16 -07004691 if (eecd & E1000_EECD_DO)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004692 data |= 1;
4693
4694 e1000_lower_ee_clk(hw, &eecd);
4695 }
4696
4697 return data;
4698}
4699
4700/******************************************************************************
4701 * Prepares EEPROM for access
4702 *
4703 * hw - Struct containing variables accessed by shared code
4704 *
4705 * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
4706 * function should be called before issuing a command to the EEPROM.
4707 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004708static s32 e1000_acquire_eeprom(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004709{
4710 struct e1000_eeprom_info *eeprom = &hw->eeprom;
Joe Perches406874a2008-04-03 10:06:32 -07004711 u32 eecd, i=0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004712
4713 DEBUGFUNC("e1000_acquire_eeprom");
4714
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004715 if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
4716 return -E1000_ERR_SWFW_SYNC;
Joe Perches1dc32912008-07-11 15:17:08 -07004717 eecd = er32(EECD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004718
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004719 if (hw->mac_type != e1000_82573) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004720 /* Request EEPROM Access */
Auke Kok8fc897b2006-08-28 14:56:16 -07004721 if (hw->mac_type > e1000_82544) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004722 eecd |= E1000_EECD_REQ;
Joe Perches1dc32912008-07-11 15:17:08 -07004723 ew32(EECD, eecd);
4724 eecd = er32(EECD);
Auke Kok8fc897b2006-08-28 14:56:16 -07004725 while ((!(eecd & E1000_EECD_GNT)) &&
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004726 (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
4727 i++;
4728 udelay(5);
Joe Perches1dc32912008-07-11 15:17:08 -07004729 eecd = er32(EECD);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004730 }
Auke Kok8fc897b2006-08-28 14:56:16 -07004731 if (!(eecd & E1000_EECD_GNT)) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004732 eecd &= ~E1000_EECD_REQ;
Joe Perches1dc32912008-07-11 15:17:08 -07004733 ew32(EECD, eecd);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004734 DEBUGOUT("Could not acquire EEPROM grant\n");
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004735 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004736 return -E1000_ERR_EEPROM;
4737 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004738 }
4739 }
4740
4741 /* Setup EEPROM for Read/Write */
4742
4743 if (eeprom->type == e1000_eeprom_microwire) {
4744 /* Clear SK and DI */
4745 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
Joe Perches1dc32912008-07-11 15:17:08 -07004746 ew32(EECD, eecd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004747
4748 /* Set CS */
4749 eecd |= E1000_EECD_CS;
Joe Perches1dc32912008-07-11 15:17:08 -07004750 ew32(EECD, eecd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004751 } else if (eeprom->type == e1000_eeprom_spi) {
4752 /* Clear SK and CS */
4753 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
Joe Perches1dc32912008-07-11 15:17:08 -07004754 ew32(EECD, eecd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004755 udelay(1);
4756 }
4757
4758 return E1000_SUCCESS;
4759}
4760
4761/******************************************************************************
4762 * Returns EEPROM to a "standby" state
4763 *
4764 * hw - Struct containing variables accessed by shared code
4765 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004766static void e1000_standby_eeprom(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004767{
4768 struct e1000_eeprom_info *eeprom = &hw->eeprom;
Joe Perches406874a2008-04-03 10:06:32 -07004769 u32 eecd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004770
Joe Perches1dc32912008-07-11 15:17:08 -07004771 eecd = er32(EECD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004772
Auke Kok8fc897b2006-08-28 14:56:16 -07004773 if (eeprom->type == e1000_eeprom_microwire) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004774 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
Joe Perches1dc32912008-07-11 15:17:08 -07004775 ew32(EECD, eecd);
4776 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07004777 udelay(eeprom->delay_usec);
4778
4779 /* Clock high */
4780 eecd |= E1000_EECD_SK;
Joe Perches1dc32912008-07-11 15:17:08 -07004781 ew32(EECD, eecd);
4782 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07004783 udelay(eeprom->delay_usec);
4784
4785 /* Select EEPROM */
4786 eecd |= E1000_EECD_CS;
Joe Perches1dc32912008-07-11 15:17:08 -07004787 ew32(EECD, eecd);
4788 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07004789 udelay(eeprom->delay_usec);
4790
4791 /* Clock low */
4792 eecd &= ~E1000_EECD_SK;
Joe Perches1dc32912008-07-11 15:17:08 -07004793 ew32(EECD, eecd);
4794 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07004795 udelay(eeprom->delay_usec);
Auke Kok8fc897b2006-08-28 14:56:16 -07004796 } else if (eeprom->type == e1000_eeprom_spi) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004797 /* Toggle CS to flush commands */
4798 eecd |= E1000_EECD_CS;
Joe Perches1dc32912008-07-11 15:17:08 -07004799 ew32(EECD, eecd);
4800 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07004801 udelay(eeprom->delay_usec);
4802 eecd &= ~E1000_EECD_CS;
Joe Perches1dc32912008-07-11 15:17:08 -07004803 ew32(EECD, eecd);
4804 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07004805 udelay(eeprom->delay_usec);
4806 }
4807}
4808
4809/******************************************************************************
4810 * Terminates a command by inverting the EEPROM's chip select pin
4811 *
4812 * hw - Struct containing variables accessed by shared code
4813 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004814static void e1000_release_eeprom(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004815{
Joe Perches406874a2008-04-03 10:06:32 -07004816 u32 eecd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004817
4818 DEBUGFUNC("e1000_release_eeprom");
4819
Joe Perches1dc32912008-07-11 15:17:08 -07004820 eecd = er32(EECD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004821
4822 if (hw->eeprom.type == e1000_eeprom_spi) {
4823 eecd |= E1000_EECD_CS; /* Pull CS high */
4824 eecd &= ~E1000_EECD_SK; /* Lower SCK */
4825
Joe Perches1dc32912008-07-11 15:17:08 -07004826 ew32(EECD, eecd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004827
4828 udelay(hw->eeprom.delay_usec);
Auke Kok8fc897b2006-08-28 14:56:16 -07004829 } else if (hw->eeprom.type == e1000_eeprom_microwire) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004830 /* cleanup eeprom */
4831
4832 /* CS on Microwire is active-high */
4833 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
4834
Joe Perches1dc32912008-07-11 15:17:08 -07004835 ew32(EECD, eecd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004836
4837 /* Rising edge of clock */
4838 eecd |= E1000_EECD_SK;
Joe Perches1dc32912008-07-11 15:17:08 -07004839 ew32(EECD, eecd);
4840 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07004841 udelay(hw->eeprom.delay_usec);
4842
4843 /* Falling edge of clock */
4844 eecd &= ~E1000_EECD_SK;
Joe Perches1dc32912008-07-11 15:17:08 -07004845 ew32(EECD, eecd);
4846 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07004847 udelay(hw->eeprom.delay_usec);
4848 }
4849
4850 /* Stop requesting EEPROM access */
Auke Kok8fc897b2006-08-28 14:56:16 -07004851 if (hw->mac_type > e1000_82544) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004852 eecd &= ~E1000_EECD_REQ;
Joe Perches1dc32912008-07-11 15:17:08 -07004853 ew32(EECD, eecd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004854 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004855
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004856 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004857}
4858
4859/******************************************************************************
4860 * Reads a 16 bit word from the EEPROM.
4861 *
4862 * hw - Struct containing variables accessed by shared code
4863 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004864static s32 e1000_spi_eeprom_ready(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004865{
Joe Perches406874a2008-04-03 10:06:32 -07004866 u16 retry_count = 0;
4867 u8 spi_stat_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004868
4869 DEBUGFUNC("e1000_spi_eeprom_ready");
4870
4871 /* Read "Status Register" repeatedly until the LSB is cleared. The
4872 * EEPROM will signal that the command has been completed by clearing
4873 * bit 0 of the internal status register. If it's not cleared within
4874 * 5 milliseconds, then error out.
4875 */
4876 retry_count = 0;
4877 do {
4878 e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
4879 hw->eeprom.opcode_bits);
Joe Perches406874a2008-04-03 10:06:32 -07004880 spi_stat_reg = (u8)e1000_shift_in_ee_bits(hw, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004881 if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
4882 break;
4883
4884 udelay(5);
4885 retry_count += 5;
4886
4887 e1000_standby_eeprom(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07004888 } while (retry_count < EEPROM_MAX_RETRY_SPI);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004889
4890 /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
4891 * only 0-5mSec on 5V devices)
4892 */
Auke Kok8fc897b2006-08-28 14:56:16 -07004893 if (retry_count >= EEPROM_MAX_RETRY_SPI) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004894 DEBUGOUT("SPI EEPROM Status error\n");
4895 return -E1000_ERR_EEPROM;
4896 }
4897
4898 return E1000_SUCCESS;
4899}
4900
4901/******************************************************************************
4902 * Reads a 16 bit word from the EEPROM.
4903 *
4904 * hw - Struct containing variables accessed by shared code
4905 * offset - offset of word in the EEPROM to read
4906 * data - word read from the EEPROM
4907 * words - number of words to read
4908 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004909s32 e1000_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004910{
Christopher Li78566fe2008-09-05 14:04:05 -07004911 s32 ret;
4912 spin_lock(&e1000_eeprom_lock);
4913 ret = e1000_do_read_eeprom(hw, offset, words, data);
4914 spin_unlock(&e1000_eeprom_lock);
4915 return ret;
4916}
4917
4918static s32 e1000_do_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
4919{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004920 struct e1000_eeprom_info *eeprom = &hw->eeprom;
Joe Perches406874a2008-04-03 10:06:32 -07004921 u32 i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004922
4923 DEBUGFUNC("e1000_read_eeprom");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004924
Jeff Kirsher2a88c172006-09-27 12:54:05 -07004925 /* If eeprom is not yet detected, do so now */
4926 if (eeprom->word_size == 0)
4927 e1000_init_eeprom_params(hw);
4928
Linus Torvalds1da177e2005-04-16 15:20:36 -07004929 /* A check for invalid values: offset too large, too many words, and not
4930 * enough words.
4931 */
Auke Kok8fc897b2006-08-28 14:56:16 -07004932 if ((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07004933 (words == 0)) {
Jeff Kirsher2a88c172006-09-27 12:54:05 -07004934 DEBUGOUT2("\"words\" parameter out of bounds. Words = %d, size = %d\n", offset, eeprom->word_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004935 return -E1000_ERR_EEPROM;
4936 }
4937
Jeff Kirsher2a88c172006-09-27 12:54:05 -07004938 /* EEPROM's that don't use EERD to read require us to bit-bang the SPI
4939 * directly. In this case, we need to acquire the EEPROM so that
4940 * FW or other port software does not interrupt.
4941 */
Joe Perchesc3033b02008-03-21 11:06:25 -07004942 if (e1000_is_onboard_nvm_eeprom(hw) && !hw->eeprom.use_eerd) {
Jeff Kirsher2a88c172006-09-27 12:54:05 -07004943 /* Prepare the EEPROM for bit-bang reading */
4944 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
4945 return -E1000_ERR_EEPROM;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004946 }
4947
Jeff Kirsher2a88c172006-09-27 12:54:05 -07004948 /* Eerd register EEPROM access requires no eeprom aquire/release */
Joe Perchesc3033b02008-03-21 11:06:25 -07004949 if (eeprom->use_eerd)
Jeff Kirsher2a88c172006-09-27 12:54:05 -07004950 return e1000_read_eeprom_eerd(hw, offset, words, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004951
Jeff Kirsher2a88c172006-09-27 12:54:05 -07004952 /* ICH EEPROM access is done via the ICH flash controller */
Auke Kokcd94dd02006-06-27 09:08:22 -07004953 if (eeprom->type == e1000_eeprom_ich8)
4954 return e1000_read_eeprom_ich8(hw, offset, words, data);
4955
Jeff Kirsher2a88c172006-09-27 12:54:05 -07004956 /* Set up the SPI or Microwire EEPROM for bit-bang reading. We have
4957 * acquired the EEPROM at this point, so any returns should relase it */
Auke Kokcd94dd02006-06-27 09:08:22 -07004958 if (eeprom->type == e1000_eeprom_spi) {
Joe Perches406874a2008-04-03 10:06:32 -07004959 u16 word_in;
4960 u8 read_opcode = EEPROM_READ_OPCODE_SPI;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004961
Auke Kok8fc897b2006-08-28 14:56:16 -07004962 if (e1000_spi_eeprom_ready(hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004963 e1000_release_eeprom(hw);
4964 return -E1000_ERR_EEPROM;
4965 }
4966
4967 e1000_standby_eeprom(hw);
4968
4969 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
Auke Kok8fc897b2006-08-28 14:56:16 -07004970 if ((eeprom->address_bits == 8) && (offset >= 128))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004971 read_opcode |= EEPROM_A8_OPCODE_SPI;
4972
4973 /* Send the READ command (opcode + addr) */
4974 e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
Joe Perches406874a2008-04-03 10:06:32 -07004975 e1000_shift_out_ee_bits(hw, (u16)(offset*2), eeprom->address_bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004976
4977 /* Read the data. The address of the eeprom internally increments with
4978 * each byte (spi) being read, saving on the overhead of eeprom setup
4979 * and tear-down. The address counter will roll over if reading beyond
4980 * the size of the eeprom, thus allowing the entire memory to be read
4981 * starting from any offset. */
4982 for (i = 0; i < words; i++) {
4983 word_in = e1000_shift_in_ee_bits(hw, 16);
4984 data[i] = (word_in >> 8) | (word_in << 8);
4985 }
Auke Kok8fc897b2006-08-28 14:56:16 -07004986 } else if (eeprom->type == e1000_eeprom_microwire) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004987 for (i = 0; i < words; i++) {
4988 /* Send the READ command (opcode + addr) */
4989 e1000_shift_out_ee_bits(hw, EEPROM_READ_OPCODE_MICROWIRE,
4990 eeprom->opcode_bits);
Joe Perches406874a2008-04-03 10:06:32 -07004991 e1000_shift_out_ee_bits(hw, (u16)(offset + i),
Linus Torvalds1da177e2005-04-16 15:20:36 -07004992 eeprom->address_bits);
4993
4994 /* Read the data. For microwire, each word requires the overhead
4995 * of eeprom setup and tear-down. */
4996 data[i] = e1000_shift_in_ee_bits(hw, 16);
4997 e1000_standby_eeprom(hw);
4998 }
4999 }
5000
5001 /* End this read operation */
5002 e1000_release_eeprom(hw);
5003
5004 return E1000_SUCCESS;
5005}
5006
5007/******************************************************************************
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005008 * Reads a 16 bit word from the EEPROM using the EERD register.
5009 *
5010 * hw - Struct containing variables accessed by shared code
5011 * offset - offset of word in the EEPROM to read
5012 * data - word read from the EEPROM
5013 * words - number of words to read
5014 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07005015static s32 e1000_read_eeprom_eerd(struct e1000_hw *hw, u16 offset, u16 words,
5016 u16 *data)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005017{
Joe Perches406874a2008-04-03 10:06:32 -07005018 u32 i, eerd = 0;
5019 s32 error = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005020
5021 for (i = 0; i < words; i++) {
5022 eerd = ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) +
5023 E1000_EEPROM_RW_REG_START;
5024
Joe Perches1dc32912008-07-11 15:17:08 -07005025 ew32(EERD, eerd);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005026 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_READ);
Auke Kok76c224b2006-05-23 13:36:06 -07005027
Auke Kok8fc897b2006-08-28 14:56:16 -07005028 if (error) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005029 break;
5030 }
Joe Perches1dc32912008-07-11 15:17:08 -07005031 data[i] = (er32(EERD) >> E1000_EEPROM_RW_REG_DATA);
Auke Kok76c224b2006-05-23 13:36:06 -07005032
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005033 }
Auke Kok76c224b2006-05-23 13:36:06 -07005034
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005035 return error;
5036}
5037
5038/******************************************************************************
5039 * Writes a 16 bit word from the EEPROM using the EEWR register.
5040 *
5041 * hw - Struct containing variables accessed by shared code
5042 * offset - offset of word in the EEPROM to read
5043 * data - word read from the EEPROM
5044 * words - number of words to read
5045 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07005046static s32 e1000_write_eeprom_eewr(struct e1000_hw *hw, u16 offset, u16 words,
5047 u16 *data)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005048{
Joe Perches406874a2008-04-03 10:06:32 -07005049 u32 register_value = 0;
5050 u32 i = 0;
5051 s32 error = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005052
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08005053 if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
5054 return -E1000_ERR_SWFW_SYNC;
5055
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005056 for (i = 0; i < words; i++) {
Auke Kok76c224b2006-05-23 13:36:06 -07005057 register_value = (data[i] << E1000_EEPROM_RW_REG_DATA) |
5058 ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) |
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005059 E1000_EEPROM_RW_REG_START;
5060
5061 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
Auke Kok8fc897b2006-08-28 14:56:16 -07005062 if (error) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005063 break;
Auke Kok76c224b2006-05-23 13:36:06 -07005064 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005065
Joe Perches1dc32912008-07-11 15:17:08 -07005066 ew32(EEWR, register_value);
Auke Kok76c224b2006-05-23 13:36:06 -07005067
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005068 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
Auke Kok76c224b2006-05-23 13:36:06 -07005069
Auke Kok8fc897b2006-08-28 14:56:16 -07005070 if (error) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005071 break;
Auke Kok76c224b2006-05-23 13:36:06 -07005072 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005073 }
Auke Kok76c224b2006-05-23 13:36:06 -07005074
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08005075 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005076 return error;
5077}
5078
5079/******************************************************************************
5080 * Polls the status bit (bit 1) of the EERD to determine when the read is done.
5081 *
5082 * hw - Struct containing variables accessed by shared code
5083 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07005084static s32 e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005085{
Joe Perches406874a2008-04-03 10:06:32 -07005086 u32 attempts = 100000;
5087 u32 i, reg = 0;
5088 s32 done = E1000_ERR_EEPROM;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005089
Auke Kok8fc897b2006-08-28 14:56:16 -07005090 for (i = 0; i < attempts; i++) {
5091 if (eerd == E1000_EEPROM_POLL_READ)
Joe Perches1dc32912008-07-11 15:17:08 -07005092 reg = er32(EERD);
Auke Kok76c224b2006-05-23 13:36:06 -07005093 else
Joe Perches1dc32912008-07-11 15:17:08 -07005094 reg = er32(EEWR);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005095
Auke Kok8fc897b2006-08-28 14:56:16 -07005096 if (reg & E1000_EEPROM_RW_REG_DONE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005097 done = E1000_SUCCESS;
5098 break;
5099 }
5100 udelay(5);
5101 }
5102
5103 return done;
5104}
5105
5106/***************************************************************************
5107* Description: Determines if the onboard NVM is FLASH or EEPROM.
5108*
5109* hw - Struct containing variables accessed by shared code
5110****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07005111static bool e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005112{
Joe Perches406874a2008-04-03 10:06:32 -07005113 u32 eecd = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005114
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08005115 DEBUGFUNC("e1000_is_onboard_nvm_eeprom");
5116
Auke Kokcd94dd02006-06-27 09:08:22 -07005117 if (hw->mac_type == e1000_ich8lan)
Joe Perchesc3033b02008-03-21 11:06:25 -07005118 return false;
Auke Kokcd94dd02006-06-27 09:08:22 -07005119
5120 if (hw->mac_type == e1000_82573) {
Joe Perches1dc32912008-07-11 15:17:08 -07005121 eecd = er32(EECD);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005122
5123 /* Isolate bits 15 & 16 */
5124 eecd = ((eecd >> 15) & 0x03);
5125
5126 /* If both bits are set, device is Flash type */
Auke Kok8fc897b2006-08-28 14:56:16 -07005127 if (eecd == 0x03) {
Joe Perchesc3033b02008-03-21 11:06:25 -07005128 return false;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005129 }
5130 }
Joe Perchesc3033b02008-03-21 11:06:25 -07005131 return true;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005132}
5133
5134/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07005135 * Verifies that the EEPROM has a valid checksum
5136 *
5137 * hw - Struct containing variables accessed by shared code
5138 *
5139 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
5140 * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
5141 * valid.
5142 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07005143s32 e1000_validate_eeprom_checksum(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005144{
Joe Perches406874a2008-04-03 10:06:32 -07005145 u16 checksum = 0;
5146 u16 i, eeprom_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005147
5148 DEBUGFUNC("e1000_validate_eeprom_checksum");
5149
Joe Perchesc3033b02008-03-21 11:06:25 -07005150 if ((hw->mac_type == e1000_82573) && !e1000_is_onboard_nvm_eeprom(hw)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005151 /* Check bit 4 of word 10h. If it is 0, firmware is done updating
5152 * 10h-12h. Checksum may need to be fixed. */
5153 e1000_read_eeprom(hw, 0x10, 1, &eeprom_data);
5154 if ((eeprom_data & 0x10) == 0) {
5155 /* Read 0x23 and check bit 15. This bit is a 1 when the checksum
5156 * has already been fixed. If the checksum is still wrong and this
5157 * bit is a 1, we need to return bad checksum. Otherwise, we need
5158 * to set this bit to a 1 and update the checksum. */
5159 e1000_read_eeprom(hw, 0x23, 1, &eeprom_data);
5160 if ((eeprom_data & 0x8000) == 0) {
5161 eeprom_data |= 0x8000;
5162 e1000_write_eeprom(hw, 0x23, 1, &eeprom_data);
5163 e1000_update_eeprom_checksum(hw);
5164 }
5165 }
5166 }
5167
Auke Kokcd94dd02006-06-27 09:08:22 -07005168 if (hw->mac_type == e1000_ich8lan) {
5169 /* Drivers must allocate the shadow ram structure for the
5170 * EEPROM checksum to be updated. Otherwise, this bit as well
5171 * as the checksum must both be set correctly for this
5172 * validation to pass.
5173 */
5174 e1000_read_eeprom(hw, 0x19, 1, &eeprom_data);
5175 if ((eeprom_data & 0x40) == 0) {
5176 eeprom_data |= 0x40;
5177 e1000_write_eeprom(hw, 0x19, 1, &eeprom_data);
5178 e1000_update_eeprom_checksum(hw);
5179 }
5180 }
5181
5182 for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
5183 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005184 DEBUGOUT("EEPROM Read Error\n");
5185 return -E1000_ERR_EEPROM;
5186 }
5187 checksum += eeprom_data;
5188 }
5189
Joe Perchese982f172008-07-11 15:17:18 -07005190 if (checksum == (u16)EEPROM_SUM)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005191 return E1000_SUCCESS;
5192 else {
5193 DEBUGOUT("EEPROM Checksum Invalid\n");
5194 return -E1000_ERR_EEPROM;
5195 }
5196}
5197
5198/******************************************************************************
5199 * Calculates the EEPROM checksum and writes it to the EEPROM
5200 *
5201 * hw - Struct containing variables accessed by shared code
5202 *
5203 * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA.
5204 * Writes the difference to word offset 63 of the EEPROM.
5205 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07005206s32 e1000_update_eeprom_checksum(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005207{
Joe Perches406874a2008-04-03 10:06:32 -07005208 u32 ctrl_ext;
5209 u16 checksum = 0;
5210 u16 i, eeprom_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005211
5212 DEBUGFUNC("e1000_update_eeprom_checksum");
5213
Auke Kok8fc897b2006-08-28 14:56:16 -07005214 for (i = 0; i < EEPROM_CHECKSUM_REG; i++) {
5215 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005216 DEBUGOUT("EEPROM Read Error\n");
5217 return -E1000_ERR_EEPROM;
5218 }
5219 checksum += eeprom_data;
5220 }
Joe Perchese982f172008-07-11 15:17:18 -07005221 checksum = (u16)EEPROM_SUM - checksum;
Auke Kok8fc897b2006-08-28 14:56:16 -07005222 if (e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005223 DEBUGOUT("EEPROM Write Error\n");
5224 return -E1000_ERR_EEPROM;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005225 } else if (hw->eeprom.type == e1000_eeprom_flash) {
5226 e1000_commit_shadow_ram(hw);
Auke Kokcd94dd02006-06-27 09:08:22 -07005227 } else if (hw->eeprom.type == e1000_eeprom_ich8) {
5228 e1000_commit_shadow_ram(hw);
5229 /* Reload the EEPROM, or else modifications will not appear
5230 * until after next adapter reset. */
Joe Perches1dc32912008-07-11 15:17:08 -07005231 ctrl_ext = er32(CTRL_EXT);
Auke Kokcd94dd02006-06-27 09:08:22 -07005232 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
Joe Perches1dc32912008-07-11 15:17:08 -07005233 ew32(CTRL_EXT, ctrl_ext);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04005234 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005235 }
5236 return E1000_SUCCESS;
5237}
5238
5239/******************************************************************************
5240 * Parent function for writing words to the different EEPROM types.
5241 *
5242 * hw - Struct containing variables accessed by shared code
5243 * offset - offset within the EEPROM to be written to
5244 * words - number of words to write
5245 * data - 16 bit word to be written to the EEPROM
5246 *
5247 * If e1000_update_eeprom_checksum is not called after this function, the
5248 * EEPROM will most likely contain an invalid checksum.
5249 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07005250s32 e1000_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005251{
Christopher Li78566fe2008-09-05 14:04:05 -07005252 s32 ret;
5253 spin_lock(&e1000_eeprom_lock);
5254 ret = e1000_do_write_eeprom(hw, offset, words, data);
5255 spin_unlock(&e1000_eeprom_lock);
5256 return ret;
5257}
5258
5259
5260static s32 e1000_do_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
5261{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005262 struct e1000_eeprom_info *eeprom = &hw->eeprom;
Joe Perches406874a2008-04-03 10:06:32 -07005263 s32 status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005264
5265 DEBUGFUNC("e1000_write_eeprom");
5266
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005267 /* If eeprom is not yet detected, do so now */
5268 if (eeprom->word_size == 0)
5269 e1000_init_eeprom_params(hw);
5270
Linus Torvalds1da177e2005-04-16 15:20:36 -07005271 /* A check for invalid values: offset too large, too many words, and not
5272 * enough words.
5273 */
Auke Kok8fc897b2006-08-28 14:56:16 -07005274 if ((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07005275 (words == 0)) {
5276 DEBUGOUT("\"words\" parameter out of bounds\n");
5277 return -E1000_ERR_EEPROM;
5278 }
5279
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04005280 /* 82573 writes only through eewr */
Joe Perchesc3033b02008-03-21 11:06:25 -07005281 if (eeprom->use_eewr)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005282 return e1000_write_eeprom_eewr(hw, offset, words, data);
5283
Auke Kokcd94dd02006-06-27 09:08:22 -07005284 if (eeprom->type == e1000_eeprom_ich8)
5285 return e1000_write_eeprom_ich8(hw, offset, words, data);
5286
Linus Torvalds1da177e2005-04-16 15:20:36 -07005287 /* Prepare the EEPROM for writing */
5288 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
5289 return -E1000_ERR_EEPROM;
5290
Auke Kok8fc897b2006-08-28 14:56:16 -07005291 if (eeprom->type == e1000_eeprom_microwire) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005292 status = e1000_write_eeprom_microwire(hw, offset, words, data);
5293 } else {
5294 status = e1000_write_eeprom_spi(hw, offset, words, data);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04005295 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005296 }
5297
5298 /* Done with writing */
5299 e1000_release_eeprom(hw);
5300
5301 return status;
5302}
5303
5304/******************************************************************************
5305 * Writes a 16 bit word to a given offset in an SPI EEPROM.
5306 *
5307 * hw - Struct containing variables accessed by shared code
5308 * offset - offset within the EEPROM to be written to
5309 * words - number of words to write
5310 * data - pointer to array of 8 bit words to be written to the EEPROM
5311 *
5312 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07005313static s32 e1000_write_eeprom_spi(struct e1000_hw *hw, u16 offset, u16 words,
5314 u16 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005315{
5316 struct e1000_eeprom_info *eeprom = &hw->eeprom;
Joe Perches406874a2008-04-03 10:06:32 -07005317 u16 widx = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005318
5319 DEBUGFUNC("e1000_write_eeprom_spi");
5320
5321 while (widx < words) {
Joe Perches406874a2008-04-03 10:06:32 -07005322 u8 write_opcode = EEPROM_WRITE_OPCODE_SPI;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005323
Auke Kok8fc897b2006-08-28 14:56:16 -07005324 if (e1000_spi_eeprom_ready(hw)) return -E1000_ERR_EEPROM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005325
5326 e1000_standby_eeprom(hw);
5327
5328 /* Send the WRITE ENABLE command (8 bit opcode ) */
5329 e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI,
5330 eeprom->opcode_bits);
5331
5332 e1000_standby_eeprom(hw);
5333
5334 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
Auke Kok8fc897b2006-08-28 14:56:16 -07005335 if ((eeprom->address_bits == 8) && (offset >= 128))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005336 write_opcode |= EEPROM_A8_OPCODE_SPI;
5337
5338 /* Send the Write command (8-bit opcode + addr) */
5339 e1000_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits);
5340
Joe Perches406874a2008-04-03 10:06:32 -07005341 e1000_shift_out_ee_bits(hw, (u16)((offset + widx)*2),
Linus Torvalds1da177e2005-04-16 15:20:36 -07005342 eeprom->address_bits);
5343
5344 /* Send the data */
5345
5346 /* Loop to allow for up to whole page write (32 bytes) of eeprom */
5347 while (widx < words) {
Joe Perches406874a2008-04-03 10:06:32 -07005348 u16 word_out = data[widx];
Linus Torvalds1da177e2005-04-16 15:20:36 -07005349 word_out = (word_out >> 8) | (word_out << 8);
5350 e1000_shift_out_ee_bits(hw, word_out, 16);
5351 widx++;
5352
5353 /* Some larger eeprom sizes are capable of a 32-byte PAGE WRITE
5354 * operation, while the smaller eeproms are capable of an 8-byte
5355 * PAGE WRITE operation. Break the inner loop to pass new address
5356 */
Auke Kok8fc897b2006-08-28 14:56:16 -07005357 if ((((offset + widx)*2) % eeprom->page_size) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005358 e1000_standby_eeprom(hw);
5359 break;
5360 }
5361 }
5362 }
5363
5364 return E1000_SUCCESS;
5365}
5366
5367/******************************************************************************
5368 * Writes a 16 bit word to a given offset in a Microwire EEPROM.
5369 *
5370 * hw - Struct containing variables accessed by shared code
5371 * offset - offset within the EEPROM to be written to
5372 * words - number of words to write
5373 * data - pointer to array of 16 bit words to be written to the EEPROM
5374 *
5375 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07005376static s32 e1000_write_eeprom_microwire(struct e1000_hw *hw, u16 offset,
5377 u16 words, u16 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005378{
5379 struct e1000_eeprom_info *eeprom = &hw->eeprom;
Joe Perches406874a2008-04-03 10:06:32 -07005380 u32 eecd;
5381 u16 words_written = 0;
5382 u16 i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005383
5384 DEBUGFUNC("e1000_write_eeprom_microwire");
5385
5386 /* Send the write enable command to the EEPROM (3-bit opcode plus
5387 * 6/8-bit dummy address beginning with 11). It's less work to include
5388 * the 11 of the dummy address as part of the opcode than it is to shift
5389 * it over the correct number of bits for the address. This puts the
5390 * EEPROM into write/erase mode.
5391 */
5392 e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE,
Joe Perches406874a2008-04-03 10:06:32 -07005393 (u16)(eeprom->opcode_bits + 2));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005394
Joe Perches406874a2008-04-03 10:06:32 -07005395 e1000_shift_out_ee_bits(hw, 0, (u16)(eeprom->address_bits - 2));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005396
5397 /* Prepare the EEPROM */
5398 e1000_standby_eeprom(hw);
5399
5400 while (words_written < words) {
5401 /* Send the Write command (3-bit opcode + addr) */
5402 e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE,
5403 eeprom->opcode_bits);
5404
Joe Perches406874a2008-04-03 10:06:32 -07005405 e1000_shift_out_ee_bits(hw, (u16)(offset + words_written),
Linus Torvalds1da177e2005-04-16 15:20:36 -07005406 eeprom->address_bits);
5407
5408 /* Send the data */
5409 e1000_shift_out_ee_bits(hw, data[words_written], 16);
5410
5411 /* Toggle the CS line. This in effect tells the EEPROM to execute
5412 * the previous command.
5413 */
5414 e1000_standby_eeprom(hw);
5415
5416 /* Read DO repeatedly until it is high (equal to '1'). The EEPROM will
5417 * signal that the command has been completed by raising the DO signal.
5418 * If DO does not go high in 10 milliseconds, then error out.
5419 */
Auke Kok8fc897b2006-08-28 14:56:16 -07005420 for (i = 0; i < 200; i++) {
Joe Perches1dc32912008-07-11 15:17:08 -07005421 eecd = er32(EECD);
Auke Kok8fc897b2006-08-28 14:56:16 -07005422 if (eecd & E1000_EECD_DO) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005423 udelay(50);
5424 }
Auke Kok8fc897b2006-08-28 14:56:16 -07005425 if (i == 200) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005426 DEBUGOUT("EEPROM Write did not complete\n");
5427 return -E1000_ERR_EEPROM;
5428 }
5429
5430 /* Recover from write */
5431 e1000_standby_eeprom(hw);
5432
5433 words_written++;
5434 }
5435
5436 /* Send the write disable command to the EEPROM (3-bit opcode plus
5437 * 6/8-bit dummy address beginning with 10). It's less work to include
5438 * the 10 of the dummy address as part of the opcode than it is to shift
5439 * it over the correct number of bits for the address. This takes the
5440 * EEPROM out of write/erase mode.
5441 */
5442 e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE,
Joe Perches406874a2008-04-03 10:06:32 -07005443 (u16)(eeprom->opcode_bits + 2));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005444
Joe Perches406874a2008-04-03 10:06:32 -07005445 e1000_shift_out_ee_bits(hw, 0, (u16)(eeprom->address_bits - 2));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005446
5447 return E1000_SUCCESS;
5448}
5449
5450/******************************************************************************
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005451 * Flushes the cached eeprom to NVM. This is done by saving the modified values
5452 * in the eeprom cache and the non modified values in the currently active bank
5453 * to the new bank.
5454 *
5455 * hw - Struct containing variables accessed by shared code
5456 * offset - offset of word in the EEPROM to read
5457 * data - word read from the EEPROM
5458 * words - number of words to read
5459 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07005460static s32 e1000_commit_shadow_ram(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005461{
Joe Perches406874a2008-04-03 10:06:32 -07005462 u32 attempts = 100000;
5463 u32 eecd = 0;
5464 u32 flop = 0;
5465 u32 i = 0;
5466 s32 error = E1000_SUCCESS;
5467 u32 old_bank_offset = 0;
5468 u32 new_bank_offset = 0;
5469 u8 low_byte = 0;
5470 u8 high_byte = 0;
Joe Perchesc3033b02008-03-21 11:06:25 -07005471 bool sector_write_failed = false;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005472
5473 if (hw->mac_type == e1000_82573) {
Auke Kokcd94dd02006-06-27 09:08:22 -07005474 /* The flop register will be used to determine if flash type is STM */
Joe Perches1dc32912008-07-11 15:17:08 -07005475 flop = er32(FLOP);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005476 for (i=0; i < attempts; i++) {
Joe Perches1dc32912008-07-11 15:17:08 -07005477 eecd = er32(EECD);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005478 if ((eecd & E1000_EECD_FLUPD) == 0) {
5479 break;
5480 }
5481 udelay(5);
5482 }
5483
5484 if (i == attempts) {
5485 return -E1000_ERR_EEPROM;
5486 }
5487
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005488 /* If STM opcode located in bits 15:8 of flop, reset firmware */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005489 if ((flop & 0xFF00) == E1000_STM_OPCODE) {
Joe Perches1dc32912008-07-11 15:17:08 -07005490 ew32(HICR, E1000_HICR_FW_RESET);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005491 }
5492
5493 /* Perform the flash update */
Joe Perches1dc32912008-07-11 15:17:08 -07005494 ew32(EECD, eecd | E1000_EECD_FLUPD);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005495
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005496 for (i=0; i < attempts; i++) {
Joe Perches1dc32912008-07-11 15:17:08 -07005497 eecd = er32(EECD);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005498 if ((eecd & E1000_EECD_FLUPD) == 0) {
5499 break;
5500 }
5501 udelay(5);
5502 }
5503
5504 if (i == attempts) {
5505 return -E1000_ERR_EEPROM;
5506 }
5507 }
5508
Auke Kokcd94dd02006-06-27 09:08:22 -07005509 if (hw->mac_type == e1000_ich8lan && hw->eeprom_shadow_ram != NULL) {
5510 /* We're writing to the opposite bank so if we're on bank 1,
5511 * write to bank 0 etc. We also need to erase the segment that
5512 * is going to be written */
Joe Perches1dc32912008-07-11 15:17:08 -07005513 if (!(er32(EECD) & E1000_EECD_SEC1VAL)) {
Auke Kokcd94dd02006-06-27 09:08:22 -07005514 new_bank_offset = hw->flash_bank_size * 2;
5515 old_bank_offset = 0;
5516 e1000_erase_ich8_4k_segment(hw, 1);
5517 } else {
5518 old_bank_offset = hw->flash_bank_size * 2;
5519 new_bank_offset = 0;
5520 e1000_erase_ich8_4k_segment(hw, 0);
5521 }
5522
Joe Perchesc3033b02008-03-21 11:06:25 -07005523 sector_write_failed = false;
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005524 /* Loop for every byte in the shadow RAM,
5525 * which is in units of words. */
5526 for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
5527 /* Determine whether to write the value stored
5528 * in the other NVM bank or a modified value stored
5529 * in the shadow RAM */
Joe Perchesc3033b02008-03-21 11:06:25 -07005530 if (hw->eeprom_shadow_ram[i].modified) {
Joe Perches406874a2008-04-03 10:06:32 -07005531 low_byte = (u8)hw->eeprom_shadow_ram[i].eeprom_word;
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005532 udelay(100);
5533 error = e1000_verify_write_ich8_byte(hw,
5534 (i << 1) + new_bank_offset, low_byte);
5535
5536 if (error != E1000_SUCCESS)
Joe Perchesc3033b02008-03-21 11:06:25 -07005537 sector_write_failed = true;
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005538 else {
Auke Kokcd94dd02006-06-27 09:08:22 -07005539 high_byte =
Joe Perches406874a2008-04-03 10:06:32 -07005540 (u8)(hw->eeprom_shadow_ram[i].eeprom_word >> 8);
Auke Kokcd94dd02006-06-27 09:08:22 -07005541 udelay(100);
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005542 }
5543 } else {
5544 e1000_read_ich8_byte(hw, (i << 1) + old_bank_offset,
5545 &low_byte);
5546 udelay(100);
5547 error = e1000_verify_write_ich8_byte(hw,
5548 (i << 1) + new_bank_offset, low_byte);
5549
5550 if (error != E1000_SUCCESS)
Joe Perchesc3033b02008-03-21 11:06:25 -07005551 sector_write_failed = true;
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005552 else {
Auke Kokcd94dd02006-06-27 09:08:22 -07005553 e1000_read_ich8_byte(hw, (i << 1) + old_bank_offset + 1,
5554 &high_byte);
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005555 udelay(100);
Auke Kokcd94dd02006-06-27 09:08:22 -07005556 }
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005557 }
Auke Kokcd94dd02006-06-27 09:08:22 -07005558
Joe Perchesc3033b02008-03-21 11:06:25 -07005559 /* If the write of the low byte was successful, go ahead and
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005560 * write the high byte while checking to make sure that if it
5561 * is the signature byte, then it is handled properly */
Joe Perchesc3033b02008-03-21 11:06:25 -07005562 if (!sector_write_failed) {
Auke Kokcd94dd02006-06-27 09:08:22 -07005563 /* If the word is 0x13, then make sure the signature bits
5564 * (15:14) are 11b until the commit has completed.
5565 * This will allow us to write 10b which indicates the
5566 * signature is valid. We want to do this after the write
5567 * has completed so that we don't mark the segment valid
5568 * while the write is still in progress */
Jeff Kirsher2df7d592006-11-01 08:48:02 -08005569 if (i == E1000_ICH_NVM_SIG_WORD)
5570 high_byte = E1000_ICH_NVM_SIG_MASK | high_byte;
Auke Kokcd94dd02006-06-27 09:08:22 -07005571
5572 error = e1000_verify_write_ich8_byte(hw,
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005573 (i << 1) + new_bank_offset + 1, high_byte);
Auke Kokcd94dd02006-06-27 09:08:22 -07005574 if (error != E1000_SUCCESS)
Joe Perchesc3033b02008-03-21 11:06:25 -07005575 sector_write_failed = true;
Auke Kokcd94dd02006-06-27 09:08:22 -07005576
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005577 } else {
5578 /* If the write failed then break from the loop and
5579 * return an error */
5580 break;
5581 }
5582 }
5583
5584 /* Don't bother writing the segment valid bits if sector
5585 * programming failed. */
Joe Perchesc3033b02008-03-21 11:06:25 -07005586 if (!sector_write_failed) {
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005587 /* Finally validate the new segment by setting bit 15:14
5588 * to 10b in word 0x13 , this can be done without an
5589 * erase as well since these bits are 11 to start with
5590 * and we need to change bit 14 to 0b */
5591 e1000_read_ich8_byte(hw,
Jeff Kirsher2df7d592006-11-01 08:48:02 -08005592 E1000_ICH_NVM_SIG_WORD * 2 + 1 + new_bank_offset,
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005593 &high_byte);
5594 high_byte &= 0xBF;
5595 error = e1000_verify_write_ich8_byte(hw,
Jeff Kirsher2df7d592006-11-01 08:48:02 -08005596 E1000_ICH_NVM_SIG_WORD * 2 + 1 + new_bank_offset, high_byte);
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005597 /* And invalidate the previously valid segment by setting
5598 * its signature word (0x13) high_byte to 0b. This can be
5599 * done without an erase because flash erase sets all bits
5600 * to 1's. We can write 1's to 0's without an erase */
5601 if (error == E1000_SUCCESS) {
5602 error = e1000_verify_write_ich8_byte(hw,
Jeff Kirsher2df7d592006-11-01 08:48:02 -08005603 E1000_ICH_NVM_SIG_WORD * 2 + 1 + old_bank_offset, 0);
Auke Kokcd94dd02006-06-27 09:08:22 -07005604 }
5605
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005606 /* Clear the now not used entry in the cache */
5607 for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
Joe Perchesc3033b02008-03-21 11:06:25 -07005608 hw->eeprom_shadow_ram[i].modified = false;
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005609 hw->eeprom_shadow_ram[i].eeprom_word = 0xFFFF;
Auke Kokcd94dd02006-06-27 09:08:22 -07005610 }
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005611 }
Auke Kokcd94dd02006-06-27 09:08:22 -07005612 }
5613
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005614 return error;
5615}
5616
5617/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07005618 * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
5619 * second function of dual function devices
5620 *
5621 * hw - Struct containing variables accessed by shared code
5622 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07005623s32 e1000_read_mac_addr(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005624{
Joe Perches406874a2008-04-03 10:06:32 -07005625 u16 offset;
5626 u16 eeprom_data, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005627
5628 DEBUGFUNC("e1000_read_mac_addr");
5629
Auke Kok8fc897b2006-08-28 14:56:16 -07005630 for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005631 offset = i >> 1;
Auke Kok8fc897b2006-08-28 14:56:16 -07005632 if (e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005633 DEBUGOUT("EEPROM Read Error\n");
5634 return -E1000_ERR_EEPROM;
5635 }
Joe Perchese982f172008-07-11 15:17:18 -07005636 hw->perm_mac_addr[i] = (u8)(eeprom_data & 0x00FF);
5637 hw->perm_mac_addr[i+1] = (u8)(eeprom_data >> 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005638 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005639
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04005640 switch (hw->mac_type) {
5641 default:
5642 break;
5643 case e1000_82546:
5644 case e1000_82546_rev_3:
5645 case e1000_82571:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08005646 case e1000_80003es2lan:
Joe Perches1dc32912008-07-11 15:17:08 -07005647 if (er32(STATUS) & E1000_STATUS_FUNC_1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005648 hw->perm_mac_addr[5] ^= 0x01;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04005649 break;
5650 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005651
Auke Kok8fc897b2006-08-28 14:56:16 -07005652 for (i = 0; i < NODE_ADDRESS_SIZE; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005653 hw->mac_addr[i] = hw->perm_mac_addr[i];
5654 return E1000_SUCCESS;
5655}
5656
5657/******************************************************************************
5658 * Initializes receive address filters.
5659 *
5660 * hw - Struct containing variables accessed by shared code
5661 *
5662 * Places the MAC address in receive address register 0 and clears the rest
5663 * of the receive addresss registers. Clears the multicast table. Assumes
5664 * the receiver is in reset when the routine is called.
5665 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07005666static void e1000_init_rx_addrs(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005667{
Joe Perches406874a2008-04-03 10:06:32 -07005668 u32 i;
5669 u32 rar_num;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005670
5671 DEBUGFUNC("e1000_init_rx_addrs");
5672
5673 /* Setup the receive address. */
5674 DEBUGOUT("Programming MAC Address into RAR[0]\n");
5675
5676 e1000_rar_set(hw, hw->mac_addr, 0);
5677
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005678 rar_num = E1000_RAR_ENTRIES;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04005679
5680 /* Reserve a spot for the Locally Administered Address to work around
5681 * an 82571 issue in which a reset on one port will reload the MAC on
5682 * the other port. */
Joe Perchesc3033b02008-03-21 11:06:25 -07005683 if ((hw->mac_type == e1000_82571) && (hw->laa_is_present))
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04005684 rar_num -= 1;
Auke Kokcd94dd02006-06-27 09:08:22 -07005685 if (hw->mac_type == e1000_ich8lan)
5686 rar_num = E1000_RAR_ENTRIES_ICH8LAN;
5687
Linus Torvalds1da177e2005-04-16 15:20:36 -07005688 /* Zero out the other 15 receive addresses. */
5689 DEBUGOUT("Clearing RAR[1-15]\n");
Auke Kok8fc897b2006-08-28 14:56:16 -07005690 for (i = 1; i < rar_num; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005691 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
Joe Perches1dc32912008-07-11 15:17:08 -07005692 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07005693 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
Joe Perches1dc32912008-07-11 15:17:08 -07005694 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07005695 }
5696}
5697
5698/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07005699 * Hashes an address to determine its location in the multicast table
5700 *
5701 * hw - Struct containing variables accessed by shared code
5702 * mc_addr - the multicast address to hash
5703 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07005704u32 e1000_hash_mc_addr(struct e1000_hw *hw, u8 *mc_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005705{
Joe Perches406874a2008-04-03 10:06:32 -07005706 u32 hash_value = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005707
5708 /* The portion of the address that is used for the hash table is
5709 * determined by the mc_filter_type setting.
5710 */
5711 switch (hw->mc_filter_type) {
5712 /* [0] [1] [2] [3] [4] [5]
5713 * 01 AA 00 12 34 56
5714 * LSB MSB
5715 */
5716 case 0:
Auke Kokcd94dd02006-06-27 09:08:22 -07005717 if (hw->mac_type == e1000_ich8lan) {
5718 /* [47:38] i.e. 0x158 for above example address */
Joe Perchese982f172008-07-11 15:17:18 -07005719 hash_value = ((mc_addr[4] >> 6) | (((u16)mc_addr[5]) << 2));
Auke Kokcd94dd02006-06-27 09:08:22 -07005720 } else {
5721 /* [47:36] i.e. 0x563 for above example address */
Joe Perchese982f172008-07-11 15:17:18 -07005722 hash_value = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4));
Auke Kokcd94dd02006-06-27 09:08:22 -07005723 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005724 break;
5725 case 1:
Auke Kokcd94dd02006-06-27 09:08:22 -07005726 if (hw->mac_type == e1000_ich8lan) {
5727 /* [46:37] i.e. 0x2B1 for above example address */
Joe Perchese982f172008-07-11 15:17:18 -07005728 hash_value = ((mc_addr[4] >> 5) | (((u16)mc_addr[5]) << 3));
Auke Kokcd94dd02006-06-27 09:08:22 -07005729 } else {
5730 /* [46:35] i.e. 0xAC6 for above example address */
Joe Perchese982f172008-07-11 15:17:18 -07005731 hash_value = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5));
Auke Kokcd94dd02006-06-27 09:08:22 -07005732 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005733 break;
5734 case 2:
Auke Kokcd94dd02006-06-27 09:08:22 -07005735 if (hw->mac_type == e1000_ich8lan) {
5736 /*[45:36] i.e. 0x163 for above example address */
Joe Perchese982f172008-07-11 15:17:18 -07005737 hash_value = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4));
Auke Kokcd94dd02006-06-27 09:08:22 -07005738 } else {
5739 /* [45:34] i.e. 0x5D8 for above example address */
Joe Perchese982f172008-07-11 15:17:18 -07005740 hash_value = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6));
Auke Kokcd94dd02006-06-27 09:08:22 -07005741 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005742 break;
5743 case 3:
Auke Kokcd94dd02006-06-27 09:08:22 -07005744 if (hw->mac_type == e1000_ich8lan) {
5745 /* [43:34] i.e. 0x18D for above example address */
Joe Perchese982f172008-07-11 15:17:18 -07005746 hash_value = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6));
Auke Kokcd94dd02006-06-27 09:08:22 -07005747 } else {
5748 /* [43:32] i.e. 0x634 for above example address */
Joe Perchese982f172008-07-11 15:17:18 -07005749 hash_value = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8));
Auke Kokcd94dd02006-06-27 09:08:22 -07005750 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005751 break;
5752 }
5753
5754 hash_value &= 0xFFF;
Auke Kokcd94dd02006-06-27 09:08:22 -07005755 if (hw->mac_type == e1000_ich8lan)
5756 hash_value &= 0x3FF;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005757
Linus Torvalds1da177e2005-04-16 15:20:36 -07005758 return hash_value;
5759}
5760
5761/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07005762 * Puts an ethernet address into a receive address register.
5763 *
5764 * hw - Struct containing variables accessed by shared code
5765 * addr - Address to put into receive address register
5766 * index - Receive address register to write
5767 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07005768void e1000_rar_set(struct e1000_hw *hw, u8 *addr, u32 index)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005769{
Joe Perches406874a2008-04-03 10:06:32 -07005770 u32 rar_low, rar_high;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005771
5772 /* HW expects these in little endian so we reverse the byte order
5773 * from network order (big endian) to little endian
5774 */
Joe Perchese982f172008-07-11 15:17:18 -07005775 rar_low = ((u32)addr[0] | ((u32)addr[1] << 8) |
5776 ((u32)addr[2] << 16) | ((u32)addr[3] << 24));
5777 rar_high = ((u32)addr[4] | ((u32)addr[5] << 8));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005778
Jeff Kirsher8df06e52006-03-02 18:18:32 -08005779 /* Disable Rx and flush all Rx frames before enabling RSS to avoid Rx
5780 * unit hang.
5781 *
5782 * Description:
5783 * If there are any Rx frames queued up or otherwise present in the HW
5784 * before RSS is enabled, and then we enable RSS, the HW Rx unit will
5785 * hang. To work around this issue, we have to disable receives and
5786 * flush out all Rx frames before we enable RSS. To do so, we modify we
5787 * redirect all Rx traffic to manageability and then reset the HW.
5788 * This flushes away Rx frames, and (since the redirections to
5789 * manageability persists across resets) keeps new ones from coming in
5790 * while we work. Then, we clear the Address Valid AV bit for all MAC
5791 * addresses and undo the re-direction to manageability.
5792 * Now, frames are coming in again, but the MAC won't accept them, so
5793 * far so good. We now proceed to initialize RSS (if necessary) and
5794 * configure the Rx unit. Last, we re-enable the AV bits and continue
5795 * on our merry way.
5796 */
5797 switch (hw->mac_type) {
5798 case e1000_82571:
5799 case e1000_82572:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08005800 case e1000_80003es2lan:
Joe Perchesc3033b02008-03-21 11:06:25 -07005801 if (hw->leave_av_bit_off)
Jeff Kirsher8df06e52006-03-02 18:18:32 -08005802 break;
5803 default:
5804 /* Indicate to hardware the Address is Valid. */
5805 rar_high |= E1000_RAH_AV;
5806 break;
5807 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005808
5809 E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
Joe Perches1dc32912008-07-11 15:17:08 -07005810 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07005811 E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
Joe Perches1dc32912008-07-11 15:17:08 -07005812 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07005813}
5814
5815/******************************************************************************
5816 * Writes a value to the specified offset in the VLAN filter table.
5817 *
5818 * hw - Struct containing variables accessed by shared code
5819 * offset - Offset in VLAN filer table to write
5820 * value - Value to write into VLAN filter table
5821 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07005822void e1000_write_vfta(struct e1000_hw *hw, u32 offset, u32 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005823{
Joe Perches406874a2008-04-03 10:06:32 -07005824 u32 temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005825
Auke Kokcd94dd02006-06-27 09:08:22 -07005826 if (hw->mac_type == e1000_ich8lan)
5827 return;
5828
5829 if ((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005830 temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1));
5831 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
Joe Perches1dc32912008-07-11 15:17:08 -07005832 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07005833 E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp);
Joe Perches1dc32912008-07-11 15:17:08 -07005834 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07005835 } else {
5836 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
Joe Perches1dc32912008-07-11 15:17:08 -07005837 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07005838 }
5839}
5840
5841/******************************************************************************
5842 * Clears the VLAN filer table
5843 *
5844 * hw - Struct containing variables accessed by shared code
5845 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07005846static void e1000_clear_vfta(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005847{
Joe Perches406874a2008-04-03 10:06:32 -07005848 u32 offset;
5849 u32 vfta_value = 0;
5850 u32 vfta_offset = 0;
5851 u32 vfta_bit_in_reg = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005852
Auke Kokcd94dd02006-06-27 09:08:22 -07005853 if (hw->mac_type == e1000_ich8lan)
5854 return;
5855
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005856 if (hw->mac_type == e1000_82573) {
5857 if (hw->mng_cookie.vlan_id != 0) {
5858 /* The VFTA is a 4096b bit-field, each identifying a single VLAN
5859 * ID. The following operations determine which 32b entry
5860 * (i.e. offset) into the array we want to set the VLAN ID
5861 * (i.e. bit) of the manageability unit. */
5862 vfta_offset = (hw->mng_cookie.vlan_id >>
5863 E1000_VFTA_ENTRY_SHIFT) &
5864 E1000_VFTA_ENTRY_MASK;
5865 vfta_bit_in_reg = 1 << (hw->mng_cookie.vlan_id &
5866 E1000_VFTA_ENTRY_BIT_SHIFT_MASK);
5867 }
5868 }
5869 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
5870 /* If the offset we want to clear is the same offset of the
5871 * manageability VLAN ID, then clear all bits except that of the
5872 * manageability unit */
5873 vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0;
5874 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, vfta_value);
Joe Perches1dc32912008-07-11 15:17:08 -07005875 E1000_WRITE_FLUSH();
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005876 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005877}
5878
Joe Perches64798842008-07-11 15:17:02 -07005879static s32 e1000_id_led_init(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005880{
Joe Perches406874a2008-04-03 10:06:32 -07005881 u32 ledctl;
5882 const u32 ledctl_mask = 0x000000FF;
5883 const u32 ledctl_on = E1000_LEDCTL_MODE_LED_ON;
5884 const u32 ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
5885 u16 eeprom_data, i, temp;
5886 const u16 led_mask = 0x0F;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005887
5888 DEBUGFUNC("e1000_id_led_init");
5889
Auke Kok8fc897b2006-08-28 14:56:16 -07005890 if (hw->mac_type < e1000_82540) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005891 /* Nothing to do */
5892 return E1000_SUCCESS;
5893 }
5894
Joe Perches1dc32912008-07-11 15:17:08 -07005895 ledctl = er32(LEDCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005896 hw->ledctl_default = ledctl;
5897 hw->ledctl_mode1 = hw->ledctl_default;
5898 hw->ledctl_mode2 = hw->ledctl_default;
5899
Auke Kok8fc897b2006-08-28 14:56:16 -07005900 if (e1000_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, 1, &eeprom_data) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005901 DEBUGOUT("EEPROM Read Error\n");
5902 return -E1000_ERR_EEPROM;
5903 }
Auke Kokcd94dd02006-06-27 09:08:22 -07005904
5905 if ((hw->mac_type == e1000_82573) &&
5906 (eeprom_data == ID_LED_RESERVED_82573))
5907 eeprom_data = ID_LED_DEFAULT_82573;
5908 else if ((eeprom_data == ID_LED_RESERVED_0000) ||
5909 (eeprom_data == ID_LED_RESERVED_FFFF)) {
5910 if (hw->mac_type == e1000_ich8lan)
5911 eeprom_data = ID_LED_DEFAULT_ICH8LAN;
5912 else
5913 eeprom_data = ID_LED_DEFAULT;
5914 }
Auke Kok90fb5132006-11-01 08:47:30 -08005915
Auke Kokcd94dd02006-06-27 09:08:22 -07005916 for (i = 0; i < 4; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005917 temp = (eeprom_data >> (i << 2)) & led_mask;
Auke Kok8fc897b2006-08-28 14:56:16 -07005918 switch (temp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005919 case ID_LED_ON1_DEF2:
5920 case ID_LED_ON1_ON2:
5921 case ID_LED_ON1_OFF2:
5922 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
5923 hw->ledctl_mode1 |= ledctl_on << (i << 3);
5924 break;
5925 case ID_LED_OFF1_DEF2:
5926 case ID_LED_OFF1_ON2:
5927 case ID_LED_OFF1_OFF2:
5928 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
5929 hw->ledctl_mode1 |= ledctl_off << (i << 3);
5930 break;
5931 default:
5932 /* Do nothing */
5933 break;
5934 }
Auke Kok8fc897b2006-08-28 14:56:16 -07005935 switch (temp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005936 case ID_LED_DEF1_ON2:
5937 case ID_LED_ON1_ON2:
5938 case ID_LED_OFF1_ON2:
5939 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
5940 hw->ledctl_mode2 |= ledctl_on << (i << 3);
5941 break;
5942 case ID_LED_DEF1_OFF2:
5943 case ID_LED_ON1_OFF2:
5944 case ID_LED_OFF1_OFF2:
5945 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
5946 hw->ledctl_mode2 |= ledctl_off << (i << 3);
5947 break;
5948 default:
5949 /* Do nothing */
5950 break;
5951 }
5952 }
5953 return E1000_SUCCESS;
5954}
5955
5956/******************************************************************************
5957 * Prepares SW controlable LED for use and saves the current state of the LED.
5958 *
5959 * hw - Struct containing variables accessed by shared code
5960 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07005961s32 e1000_setup_led(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005962{
Joe Perches406874a2008-04-03 10:06:32 -07005963 u32 ledctl;
5964 s32 ret_val = E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005965
5966 DEBUGFUNC("e1000_setup_led");
5967
Auke Kok8fc897b2006-08-28 14:56:16 -07005968 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005969 case e1000_82542_rev2_0:
5970 case e1000_82542_rev2_1:
5971 case e1000_82543:
5972 case e1000_82544:
5973 /* No setup necessary */
5974 break;
5975 case e1000_82541:
5976 case e1000_82547:
5977 case e1000_82541_rev_2:
5978 case e1000_82547_rev_2:
5979 /* Turn off PHY Smart Power Down (if enabled) */
5980 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
5981 &hw->phy_spd_default);
Auke Kok8fc897b2006-08-28 14:56:16 -07005982 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005983 return ret_val;
5984 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
Joe Perches406874a2008-04-03 10:06:32 -07005985 (u16)(hw->phy_spd_default &
Linus Torvalds1da177e2005-04-16 15:20:36 -07005986 ~IGP01E1000_GMII_SPD));
Auke Kok8fc897b2006-08-28 14:56:16 -07005987 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005988 return ret_val;
5989 /* Fall Through */
5990 default:
Auke Kok8fc897b2006-08-28 14:56:16 -07005991 if (hw->media_type == e1000_media_type_fiber) {
Joe Perches1dc32912008-07-11 15:17:08 -07005992 ledctl = er32(LEDCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005993 /* Save current LEDCTL settings */
5994 hw->ledctl_default = ledctl;
5995 /* Turn off LED0 */
5996 ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
5997 E1000_LEDCTL_LED0_BLINK |
5998 E1000_LEDCTL_LED0_MODE_MASK);
5999 ledctl |= (E1000_LEDCTL_MODE_LED_OFF <<
6000 E1000_LEDCTL_LED0_MODE_SHIFT);
Joe Perches1dc32912008-07-11 15:17:08 -07006001 ew32(LEDCTL, ledctl);
Auke Kok8fc897b2006-08-28 14:56:16 -07006002 } else if (hw->media_type == e1000_media_type_copper)
Joe Perches1dc32912008-07-11 15:17:08 -07006003 ew32(LEDCTL, hw->ledctl_mode1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006004 break;
6005 }
6006
6007 return E1000_SUCCESS;
6008}
6009
Auke Kok8fc897b2006-08-28 14:56:16 -07006010
Linus Torvalds1da177e2005-04-16 15:20:36 -07006011/******************************************************************************
Auke Kokf1b3a852006-06-27 09:07:56 -07006012 * Used on 82571 and later Si that has LED blink bits.
6013 * Callers must use their own timer and should have already called
6014 * e1000_id_led_init()
6015 * Call e1000_cleanup led() to stop blinking
6016 *
6017 * hw - Struct containing variables accessed by shared code
6018 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07006019s32 e1000_blink_led_start(struct e1000_hw *hw)
Auke Kokf1b3a852006-06-27 09:07:56 -07006020{
Joe Perches406874a2008-04-03 10:06:32 -07006021 s16 i;
6022 u32 ledctl_blink = 0;
Auke Kokf1b3a852006-06-27 09:07:56 -07006023
6024 DEBUGFUNC("e1000_id_led_blink_on");
6025
6026 if (hw->mac_type < e1000_82571) {
6027 /* Nothing to do */
6028 return E1000_SUCCESS;
6029 }
6030 if (hw->media_type == e1000_media_type_fiber) {
6031 /* always blink LED0 for PCI-E fiber */
6032 ledctl_blink = E1000_LEDCTL_LED0_BLINK |
6033 (E1000_LEDCTL_MODE_LED_ON << E1000_LEDCTL_LED0_MODE_SHIFT);
6034 } else {
6035 /* set the blink bit for each LED that's "on" (0x0E) in ledctl_mode2 */
6036 ledctl_blink = hw->ledctl_mode2;
6037 for (i=0; i < 4; i++)
6038 if (((hw->ledctl_mode2 >> (i * 8)) & 0xFF) ==
6039 E1000_LEDCTL_MODE_LED_ON)
6040 ledctl_blink |= (E1000_LEDCTL_LED0_BLINK << (i * 8));
6041 }
6042
Joe Perches1dc32912008-07-11 15:17:08 -07006043 ew32(LEDCTL, ledctl_blink);
Auke Kokf1b3a852006-06-27 09:07:56 -07006044
6045 return E1000_SUCCESS;
6046}
6047
6048/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07006049 * Restores the saved state of the SW controlable LED.
6050 *
6051 * hw - Struct containing variables accessed by shared code
6052 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07006053s32 e1000_cleanup_led(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006054{
Joe Perches406874a2008-04-03 10:06:32 -07006055 s32 ret_val = E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006056
6057 DEBUGFUNC("e1000_cleanup_led");
6058
Auke Kok8fc897b2006-08-28 14:56:16 -07006059 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006060 case e1000_82542_rev2_0:
6061 case e1000_82542_rev2_1:
6062 case e1000_82543:
6063 case e1000_82544:
6064 /* No cleanup necessary */
6065 break;
6066 case e1000_82541:
6067 case e1000_82547:
6068 case e1000_82541_rev_2:
6069 case e1000_82547_rev_2:
6070 /* Turn on PHY Smart Power Down (if previously enabled) */
6071 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
6072 hw->phy_spd_default);
Auke Kok8fc897b2006-08-28 14:56:16 -07006073 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006074 return ret_val;
6075 /* Fall Through */
6076 default:
Auke Kokcd94dd02006-06-27 09:08:22 -07006077 if (hw->phy_type == e1000_phy_ife) {
6078 e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
6079 break;
6080 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006081 /* Restore LEDCTL settings */
Joe Perches1dc32912008-07-11 15:17:08 -07006082 ew32(LEDCTL, hw->ledctl_default);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006083 break;
6084 }
6085
6086 return E1000_SUCCESS;
6087}
6088
6089/******************************************************************************
6090 * Turns on the software controllable LED
6091 *
6092 * hw - Struct containing variables accessed by shared code
6093 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07006094s32 e1000_led_on(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006095{
Joe Perches1dc32912008-07-11 15:17:08 -07006096 u32 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006097
6098 DEBUGFUNC("e1000_led_on");
6099
Auke Kok8fc897b2006-08-28 14:56:16 -07006100 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006101 case e1000_82542_rev2_0:
6102 case e1000_82542_rev2_1:
6103 case e1000_82543:
6104 /* Set SW Defineable Pin 0 to turn on the LED */
6105 ctrl |= E1000_CTRL_SWDPIN0;
6106 ctrl |= E1000_CTRL_SWDPIO0;
6107 break;
6108 case e1000_82544:
Auke Kok8fc897b2006-08-28 14:56:16 -07006109 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006110 /* Set SW Defineable Pin 0 to turn on the LED */
6111 ctrl |= E1000_CTRL_SWDPIN0;
6112 ctrl |= E1000_CTRL_SWDPIO0;
6113 } else {
6114 /* Clear SW Defineable Pin 0 to turn on the LED */
6115 ctrl &= ~E1000_CTRL_SWDPIN0;
6116 ctrl |= E1000_CTRL_SWDPIO0;
6117 }
6118 break;
6119 default:
Auke Kok8fc897b2006-08-28 14:56:16 -07006120 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006121 /* Clear SW Defineable Pin 0 to turn on the LED */
6122 ctrl &= ~E1000_CTRL_SWDPIN0;
6123 ctrl |= E1000_CTRL_SWDPIO0;
Auke Kokcd94dd02006-06-27 09:08:22 -07006124 } else if (hw->phy_type == e1000_phy_ife) {
6125 e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED,
6126 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_ON));
6127 } else if (hw->media_type == e1000_media_type_copper) {
Joe Perches1dc32912008-07-11 15:17:08 -07006128 ew32(LEDCTL, hw->ledctl_mode2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006129 return E1000_SUCCESS;
6130 }
6131 break;
6132 }
6133
Joe Perches1dc32912008-07-11 15:17:08 -07006134 ew32(CTRL, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006135
6136 return E1000_SUCCESS;
6137}
6138
6139/******************************************************************************
6140 * Turns off the software controllable LED
6141 *
6142 * hw - Struct containing variables accessed by shared code
6143 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07006144s32 e1000_led_off(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006145{
Joe Perches1dc32912008-07-11 15:17:08 -07006146 u32 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006147
6148 DEBUGFUNC("e1000_led_off");
6149
Auke Kok8fc897b2006-08-28 14:56:16 -07006150 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006151 case e1000_82542_rev2_0:
6152 case e1000_82542_rev2_1:
6153 case e1000_82543:
6154 /* Clear SW Defineable Pin 0 to turn off the LED */
6155 ctrl &= ~E1000_CTRL_SWDPIN0;
6156 ctrl |= E1000_CTRL_SWDPIO0;
6157 break;
6158 case e1000_82544:
Auke Kok8fc897b2006-08-28 14:56:16 -07006159 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006160 /* Clear SW Defineable Pin 0 to turn off the LED */
6161 ctrl &= ~E1000_CTRL_SWDPIN0;
6162 ctrl |= E1000_CTRL_SWDPIO0;
6163 } else {
6164 /* Set SW Defineable Pin 0 to turn off the LED */
6165 ctrl |= E1000_CTRL_SWDPIN0;
6166 ctrl |= E1000_CTRL_SWDPIO0;
6167 }
6168 break;
6169 default:
Auke Kok8fc897b2006-08-28 14:56:16 -07006170 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006171 /* Set SW Defineable Pin 0 to turn off the LED */
6172 ctrl |= E1000_CTRL_SWDPIN0;
6173 ctrl |= E1000_CTRL_SWDPIO0;
Auke Kokcd94dd02006-06-27 09:08:22 -07006174 } else if (hw->phy_type == e1000_phy_ife) {
6175 e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED,
6176 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_OFF));
6177 } else if (hw->media_type == e1000_media_type_copper) {
Joe Perches1dc32912008-07-11 15:17:08 -07006178 ew32(LEDCTL, hw->ledctl_mode1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006179 return E1000_SUCCESS;
6180 }
6181 break;
6182 }
6183
Joe Perches1dc32912008-07-11 15:17:08 -07006184 ew32(CTRL, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006185
6186 return E1000_SUCCESS;
6187}
6188
6189/******************************************************************************
6190 * Clears all hardware statistics counters.
6191 *
6192 * hw - Struct containing variables accessed by shared code
6193 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07006194static void e1000_clear_hw_cntrs(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006195{
Joe Perches406874a2008-04-03 10:06:32 -07006196 volatile u32 temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006197
Joe Perches1dc32912008-07-11 15:17:08 -07006198 temp = er32(CRCERRS);
6199 temp = er32(SYMERRS);
6200 temp = er32(MPC);
6201 temp = er32(SCC);
6202 temp = er32(ECOL);
6203 temp = er32(MCC);
6204 temp = er32(LATECOL);
6205 temp = er32(COLC);
6206 temp = er32(DC);
6207 temp = er32(SEC);
6208 temp = er32(RLEC);
6209 temp = er32(XONRXC);
6210 temp = er32(XONTXC);
6211 temp = er32(XOFFRXC);
6212 temp = er32(XOFFTXC);
6213 temp = er32(FCRUC);
Auke Kokcd94dd02006-06-27 09:08:22 -07006214
6215 if (hw->mac_type != e1000_ich8lan) {
Joe Perches1dc32912008-07-11 15:17:08 -07006216 temp = er32(PRC64);
6217 temp = er32(PRC127);
6218 temp = er32(PRC255);
6219 temp = er32(PRC511);
6220 temp = er32(PRC1023);
6221 temp = er32(PRC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07006222 }
6223
Joe Perches1dc32912008-07-11 15:17:08 -07006224 temp = er32(GPRC);
6225 temp = er32(BPRC);
6226 temp = er32(MPRC);
6227 temp = er32(GPTC);
6228 temp = er32(GORCL);
6229 temp = er32(GORCH);
6230 temp = er32(GOTCL);
6231 temp = er32(GOTCH);
6232 temp = er32(RNBC);
6233 temp = er32(RUC);
6234 temp = er32(RFC);
6235 temp = er32(ROC);
6236 temp = er32(RJC);
6237 temp = er32(TORL);
6238 temp = er32(TORH);
6239 temp = er32(TOTL);
6240 temp = er32(TOTH);
6241 temp = er32(TPR);
6242 temp = er32(TPT);
Auke Kokcd94dd02006-06-27 09:08:22 -07006243
6244 if (hw->mac_type != e1000_ich8lan) {
Joe Perches1dc32912008-07-11 15:17:08 -07006245 temp = er32(PTC64);
6246 temp = er32(PTC127);
6247 temp = er32(PTC255);
6248 temp = er32(PTC511);
6249 temp = er32(PTC1023);
6250 temp = er32(PTC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07006251 }
6252
Joe Perches1dc32912008-07-11 15:17:08 -07006253 temp = er32(MPTC);
6254 temp = er32(BPTC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006255
Auke Kok8fc897b2006-08-28 14:56:16 -07006256 if (hw->mac_type < e1000_82543) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006257
Joe Perches1dc32912008-07-11 15:17:08 -07006258 temp = er32(ALGNERRC);
6259 temp = er32(RXERRC);
6260 temp = er32(TNCRS);
6261 temp = er32(CEXTERR);
6262 temp = er32(TSCTC);
6263 temp = er32(TSCTFC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006264
Auke Kok8fc897b2006-08-28 14:56:16 -07006265 if (hw->mac_type <= e1000_82544) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006266
Joe Perches1dc32912008-07-11 15:17:08 -07006267 temp = er32(MGTPRC);
6268 temp = er32(MGTPDC);
6269 temp = er32(MGTPTC);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006270
Auke Kok8fc897b2006-08-28 14:56:16 -07006271 if (hw->mac_type <= e1000_82547_rev_2) return;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006272
Joe Perches1dc32912008-07-11 15:17:08 -07006273 temp = er32(IAC);
6274 temp = er32(ICRXOC);
Auke Kokcd94dd02006-06-27 09:08:22 -07006275
6276 if (hw->mac_type == e1000_ich8lan) return;
6277
Joe Perches1dc32912008-07-11 15:17:08 -07006278 temp = er32(ICRXPTC);
6279 temp = er32(ICRXATC);
6280 temp = er32(ICTXPTC);
6281 temp = er32(ICTXATC);
6282 temp = er32(ICTXQEC);
6283 temp = er32(ICTXQMTC);
6284 temp = er32(ICRXDMTC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006285}
6286
6287/******************************************************************************
6288 * Resets Adaptive IFS to its default state.
6289 *
6290 * hw - Struct containing variables accessed by shared code
6291 *
6292 * Call this after e1000_init_hw. You may override the IFS defaults by setting
Joe Perchesc3033b02008-03-21 11:06:25 -07006293 * hw->ifs_params_forced to true. However, you must initialize hw->
Linus Torvalds1da177e2005-04-16 15:20:36 -07006294 * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio
6295 * before calling this function.
6296 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07006297void e1000_reset_adaptive(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006298{
6299 DEBUGFUNC("e1000_reset_adaptive");
6300
Auke Kok8fc897b2006-08-28 14:56:16 -07006301 if (hw->adaptive_ifs) {
6302 if (!hw->ifs_params_forced) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006303 hw->current_ifs_val = 0;
6304 hw->ifs_min_val = IFS_MIN;
6305 hw->ifs_max_val = IFS_MAX;
6306 hw->ifs_step_size = IFS_STEP;
6307 hw->ifs_ratio = IFS_RATIO;
6308 }
Joe Perchesc3033b02008-03-21 11:06:25 -07006309 hw->in_ifs_mode = false;
Joe Perches1dc32912008-07-11 15:17:08 -07006310 ew32(AIT, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006311 } else {
6312 DEBUGOUT("Not in Adaptive IFS mode!\n");
6313 }
6314}
6315
6316/******************************************************************************
6317 * Called during the callback/watchdog routine to update IFS value based on
6318 * the ratio of transmits to collisions.
6319 *
6320 * hw - Struct containing variables accessed by shared code
6321 * tx_packets - Number of transmits since last callback
6322 * total_collisions - Number of collisions since last callback
6323 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07006324void e1000_update_adaptive(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006325{
6326 DEBUGFUNC("e1000_update_adaptive");
6327
Auke Kok8fc897b2006-08-28 14:56:16 -07006328 if (hw->adaptive_ifs) {
6329 if ((hw->collision_delta * hw->ifs_ratio) > hw->tx_packet_delta) {
6330 if (hw->tx_packet_delta > MIN_NUM_XMITS) {
Joe Perchesc3033b02008-03-21 11:06:25 -07006331 hw->in_ifs_mode = true;
Auke Kok8fc897b2006-08-28 14:56:16 -07006332 if (hw->current_ifs_val < hw->ifs_max_val) {
6333 if (hw->current_ifs_val == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006334 hw->current_ifs_val = hw->ifs_min_val;
6335 else
6336 hw->current_ifs_val += hw->ifs_step_size;
Joe Perches1dc32912008-07-11 15:17:08 -07006337 ew32(AIT, hw->current_ifs_val);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006338 }
6339 }
6340 } else {
Auke Kok8fc897b2006-08-28 14:56:16 -07006341 if (hw->in_ifs_mode && (hw->tx_packet_delta <= MIN_NUM_XMITS)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006342 hw->current_ifs_val = 0;
Joe Perchesc3033b02008-03-21 11:06:25 -07006343 hw->in_ifs_mode = false;
Joe Perches1dc32912008-07-11 15:17:08 -07006344 ew32(AIT, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006345 }
6346 }
6347 } else {
6348 DEBUGOUT("Not in Adaptive IFS mode!\n");
6349 }
6350}
6351
6352/******************************************************************************
6353 * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT
6354 *
6355 * hw - Struct containing variables accessed by shared code
6356 * frame_len - The length of the frame in question
6357 * mac_addr - The Ethernet destination address of the frame in question
6358 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07006359void e1000_tbi_adjust_stats(struct e1000_hw *hw, struct e1000_hw_stats *stats,
6360 u32 frame_len, u8 *mac_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006361{
Joe Perches406874a2008-04-03 10:06:32 -07006362 u64 carry_bit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006363
6364 /* First adjust the frame length. */
6365 frame_len--;
6366 /* We need to adjust the statistics counters, since the hardware
6367 * counters overcount this packet as a CRC error and undercount
6368 * the packet as a good packet
6369 */
6370 /* This packet should not be counted as a CRC error. */
6371 stats->crcerrs--;
6372 /* This packet does count as a Good Packet Received. */
6373 stats->gprc++;
6374
6375 /* Adjust the Good Octets received counters */
6376 carry_bit = 0x80000000 & stats->gorcl;
6377 stats->gorcl += frame_len;
6378 /* If the high bit of Gorcl (the low 32 bits of the Good Octets
6379 * Received Count) was one before the addition,
6380 * AND it is zero after, then we lost the carry out,
6381 * need to add one to Gorch (Good Octets Received Count High).
6382 * This could be simplified if all environments supported
6383 * 64-bit integers.
6384 */
Auke Kok8fc897b2006-08-28 14:56:16 -07006385 if (carry_bit && ((stats->gorcl & 0x80000000) == 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07006386 stats->gorch++;
6387 /* Is this a broadcast or multicast? Check broadcast first,
6388 * since the test for a multicast frame will test positive on
6389 * a broadcast frame.
6390 */
Joe Perchese982f172008-07-11 15:17:18 -07006391 if ((mac_addr[0] == (u8)0xff) && (mac_addr[1] == (u8)0xff))
Linus Torvalds1da177e2005-04-16 15:20:36 -07006392 /* Broadcast packet */
6393 stats->bprc++;
Auke Kok8fc897b2006-08-28 14:56:16 -07006394 else if (*mac_addr & 0x01)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006395 /* Multicast packet */
6396 stats->mprc++;
6397
Auke Kok8fc897b2006-08-28 14:56:16 -07006398 if (frame_len == hw->max_frame_size) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006399 /* In this case, the hardware has overcounted the number of
6400 * oversize frames.
6401 */
Auke Kok8fc897b2006-08-28 14:56:16 -07006402 if (stats->roc > 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006403 stats->roc--;
6404 }
6405
6406 /* Adjust the bin counters when the extra byte put the frame in the
6407 * wrong bin. Remember that the frame_len was adjusted above.
6408 */
Auke Kok8fc897b2006-08-28 14:56:16 -07006409 if (frame_len == 64) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006410 stats->prc64++;
6411 stats->prc127--;
Auke Kok8fc897b2006-08-28 14:56:16 -07006412 } else if (frame_len == 127) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006413 stats->prc127++;
6414 stats->prc255--;
Auke Kok8fc897b2006-08-28 14:56:16 -07006415 } else if (frame_len == 255) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006416 stats->prc255++;
6417 stats->prc511--;
Auke Kok8fc897b2006-08-28 14:56:16 -07006418 } else if (frame_len == 511) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006419 stats->prc511++;
6420 stats->prc1023--;
Auke Kok8fc897b2006-08-28 14:56:16 -07006421 } else if (frame_len == 1023) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006422 stats->prc1023++;
6423 stats->prc1522--;
Auke Kok8fc897b2006-08-28 14:56:16 -07006424 } else if (frame_len == 1522) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006425 stats->prc1522++;
6426 }
6427}
6428
6429/******************************************************************************
6430 * Gets the current PCI bus type, speed, and width of the hardware
6431 *
6432 * hw - Struct containing variables accessed by shared code
6433 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07006434void e1000_get_bus_info(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006435{
Joe Perches406874a2008-04-03 10:06:32 -07006436 s32 ret_val;
6437 u16 pci_ex_link_status;
6438 u32 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006439
6440 switch (hw->mac_type) {
6441 case e1000_82542_rev2_0:
6442 case e1000_82542_rev2_1:
Jeff Kirsherc3813ae2006-12-15 10:37:32 +01006443 hw->bus_type = e1000_bus_type_pci;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006444 hw->bus_speed = e1000_bus_speed_unknown;
6445 hw->bus_width = e1000_bus_width_unknown;
6446 break;
Jeff Kirshercaeccb62006-09-27 12:53:57 -07006447 case e1000_82571:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006448 case e1000_82572:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006449 case e1000_82573:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08006450 case e1000_80003es2lan:
Jeff Kirsherfd803242005-12-13 00:06:22 -05006451 hw->bus_type = e1000_bus_type_pci_express;
6452 hw->bus_speed = e1000_bus_speed_2500;
Jeff Kirshercaeccb62006-09-27 12:53:57 -07006453 ret_val = e1000_read_pcie_cap_reg(hw,
6454 PCI_EX_LINK_STATUS,
6455 &pci_ex_link_status);
6456 if (ret_val)
6457 hw->bus_width = e1000_bus_width_unknown;
6458 else
6459 hw->bus_width = (pci_ex_link_status & PCI_EX_LINK_WIDTH_MASK) >>
6460 PCI_EX_LINK_WIDTH_SHIFT;
6461 break;
6462 case e1000_ich8lan:
6463 hw->bus_type = e1000_bus_type_pci_express;
6464 hw->bus_speed = e1000_bus_speed_2500;
6465 hw->bus_width = e1000_bus_width_pciex_1;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006466 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006467 default:
Joe Perches1dc32912008-07-11 15:17:08 -07006468 status = er32(STATUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006469 hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
6470 e1000_bus_type_pcix : e1000_bus_type_pci;
6471
Auke Kok8fc897b2006-08-28 14:56:16 -07006472 if (hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006473 hw->bus_speed = (hw->bus_type == e1000_bus_type_pci) ?
6474 e1000_bus_speed_66 : e1000_bus_speed_120;
Auke Kok8fc897b2006-08-28 14:56:16 -07006475 } else if (hw->bus_type == e1000_bus_type_pci) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006476 hw->bus_speed = (status & E1000_STATUS_PCI66) ?
6477 e1000_bus_speed_66 : e1000_bus_speed_33;
6478 } else {
6479 switch (status & E1000_STATUS_PCIX_SPEED) {
6480 case E1000_STATUS_PCIX_SPEED_66:
6481 hw->bus_speed = e1000_bus_speed_66;
6482 break;
6483 case E1000_STATUS_PCIX_SPEED_100:
6484 hw->bus_speed = e1000_bus_speed_100;
6485 break;
6486 case E1000_STATUS_PCIX_SPEED_133:
6487 hw->bus_speed = e1000_bus_speed_133;
6488 break;
6489 default:
6490 hw->bus_speed = e1000_bus_speed_reserved;
6491 break;
6492 }
6493 }
6494 hw->bus_width = (status & E1000_STATUS_BUS64) ?
6495 e1000_bus_width_64 : e1000_bus_width_32;
6496 break;
6497 }
6498}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006499
6500/******************************************************************************
6501 * Writes a value to one of the devices registers using port I/O (as opposed to
6502 * memory mapped I/O). Only 82544 and newer devices support port I/O.
6503 *
6504 * hw - Struct containing variables accessed by shared code
6505 * offset - offset to write to
6506 * value - value to write
6507 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07006508static void e1000_write_reg_io(struct e1000_hw *hw, u32 offset, u32 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006509{
6510 unsigned long io_addr = hw->io_base;
6511 unsigned long io_data = hw->io_base + 4;
6512
6513 e1000_io_write(hw, io_addr, offset);
6514 e1000_io_write(hw, io_data, value);
6515}
6516
Linus Torvalds1da177e2005-04-16 15:20:36 -07006517/******************************************************************************
6518 * Estimates the cable length.
6519 *
6520 * hw - Struct containing variables accessed by shared code
6521 * min_length - The estimated minimum length
6522 * max_length - The estimated maximum length
6523 *
6524 * returns: - E1000_ERR_XXX
6525 * E1000_SUCCESS
6526 *
6527 * This function always returns a ranged length (minimum & maximum).
6528 * So for M88 phy's, this function interprets the one value returned from the
6529 * register to the minimum and maximum range.
6530 * For IGP phy's, the function calculates the range by the AGC registers.
6531 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07006532static s32 e1000_get_cable_length(struct e1000_hw *hw, u16 *min_length,
6533 u16 *max_length)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006534{
Joe Perches406874a2008-04-03 10:06:32 -07006535 s32 ret_val;
6536 u16 agc_value = 0;
6537 u16 i, phy_data;
6538 u16 cable_length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006539
6540 DEBUGFUNC("e1000_get_cable_length");
6541
6542 *min_length = *max_length = 0;
6543
6544 /* Use old method for Phy older than IGP */
Auke Kok8fc897b2006-08-28 14:56:16 -07006545 if (hw->phy_type == e1000_phy_m88) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006546
Linus Torvalds1da177e2005-04-16 15:20:36 -07006547 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6548 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006549 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006550 return ret_val;
6551 cable_length = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
6552 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
6553
6554 /* Convert the enum value to ranged values */
6555 switch (cable_length) {
6556 case e1000_cable_length_50:
6557 *min_length = 0;
6558 *max_length = e1000_igp_cable_length_50;
6559 break;
6560 case e1000_cable_length_50_80:
6561 *min_length = e1000_igp_cable_length_50;
6562 *max_length = e1000_igp_cable_length_80;
6563 break;
6564 case e1000_cable_length_80_110:
6565 *min_length = e1000_igp_cable_length_80;
6566 *max_length = e1000_igp_cable_length_110;
6567 break;
6568 case e1000_cable_length_110_140:
6569 *min_length = e1000_igp_cable_length_110;
6570 *max_length = e1000_igp_cable_length_140;
6571 break;
6572 case e1000_cable_length_140:
6573 *min_length = e1000_igp_cable_length_140;
6574 *max_length = e1000_igp_cable_length_170;
6575 break;
6576 default:
6577 return -E1000_ERR_PHY;
6578 break;
6579 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08006580 } else if (hw->phy_type == e1000_phy_gg82563) {
6581 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_DSP_DISTANCE,
6582 &phy_data);
6583 if (ret_val)
6584 return ret_val;
6585 cable_length = phy_data & GG82563_DSPD_CABLE_LENGTH;
6586
6587 switch (cable_length) {
6588 case e1000_gg_cable_length_60:
6589 *min_length = 0;
6590 *max_length = e1000_igp_cable_length_60;
6591 break;
6592 case e1000_gg_cable_length_60_115:
6593 *min_length = e1000_igp_cable_length_60;
6594 *max_length = e1000_igp_cable_length_115;
6595 break;
6596 case e1000_gg_cable_length_115_150:
6597 *min_length = e1000_igp_cable_length_115;
6598 *max_length = e1000_igp_cable_length_150;
6599 break;
6600 case e1000_gg_cable_length_150:
6601 *min_length = e1000_igp_cable_length_150;
6602 *max_length = e1000_igp_cable_length_180;
6603 break;
6604 default:
6605 return -E1000_ERR_PHY;
6606 break;
6607 }
Auke Kok8fc897b2006-08-28 14:56:16 -07006608 } else if (hw->phy_type == e1000_phy_igp) { /* For IGP PHY */
Joe Perches406874a2008-04-03 10:06:32 -07006609 u16 cur_agc_value;
6610 u16 min_agc_value = IGP01E1000_AGC_LENGTH_TABLE_SIZE;
6611 u16 agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
Linus Torvalds1da177e2005-04-16 15:20:36 -07006612 {IGP01E1000_PHY_AGC_A,
6613 IGP01E1000_PHY_AGC_B,
6614 IGP01E1000_PHY_AGC_C,
6615 IGP01E1000_PHY_AGC_D};
6616 /* Read the AGC registers for all channels */
Auke Kok8fc897b2006-08-28 14:56:16 -07006617 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006618
6619 ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006620 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006621 return ret_val;
6622
Auke Kokcd94dd02006-06-27 09:08:22 -07006623 cur_agc_value = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006624
Auke Kokcd94dd02006-06-27 09:08:22 -07006625 /* Value bound check. */
6626 if ((cur_agc_value >= IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1) ||
6627 (cur_agc_value == 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07006628 return -E1000_ERR_PHY;
6629
Auke Kokcd94dd02006-06-27 09:08:22 -07006630 agc_value += cur_agc_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006631
6632 /* Update minimal AGC value. */
Auke Kokcd94dd02006-06-27 09:08:22 -07006633 if (min_agc_value > cur_agc_value)
6634 min_agc_value = cur_agc_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006635 }
6636
6637 /* Remove the minimal AGC result for length < 50m */
Auke Kokcd94dd02006-06-27 09:08:22 -07006638 if (agc_value < IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) {
6639 agc_value -= min_agc_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006640
6641 /* Get the average length of the remaining 3 channels */
6642 agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1);
6643 } else {
6644 /* Get the average length of all the 4 channels. */
6645 agc_value /= IGP01E1000_PHY_CHANNEL_NUM;
6646 }
6647
6648 /* Set the range of the calculated length. */
6649 *min_length = ((e1000_igp_cable_length_table[agc_value] -
6650 IGP01E1000_AGC_RANGE) > 0) ?
6651 (e1000_igp_cable_length_table[agc_value] -
6652 IGP01E1000_AGC_RANGE) : 0;
6653 *max_length = e1000_igp_cable_length_table[agc_value] +
6654 IGP01E1000_AGC_RANGE;
Auke Kokcd94dd02006-06-27 09:08:22 -07006655 } else if (hw->phy_type == e1000_phy_igp_2 ||
6656 hw->phy_type == e1000_phy_igp_3) {
Joe Perches406874a2008-04-03 10:06:32 -07006657 u16 cur_agc_index, max_agc_index = 0;
6658 u16 min_agc_index = IGP02E1000_AGC_LENGTH_TABLE_SIZE - 1;
6659 u16 agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] =
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006660 {IGP02E1000_PHY_AGC_A,
6661 IGP02E1000_PHY_AGC_B,
6662 IGP02E1000_PHY_AGC_C,
6663 IGP02E1000_PHY_AGC_D};
6664 /* Read the AGC registers for all channels */
6665 for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
6666 ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
6667 if (ret_val)
6668 return ret_val;
6669
Auke Kok8fc897b2006-08-28 14:56:16 -07006670 /* Getting bits 15:9, which represent the combination of course and
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006671 * fine gain values. The result is a number that can be put into
6672 * the lookup table to obtain the approximate cable length. */
Auke Kokcd94dd02006-06-27 09:08:22 -07006673 cur_agc_index = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
6674 IGP02E1000_AGC_LENGTH_MASK;
6675
6676 /* Array index bound check. */
6677 if ((cur_agc_index >= IGP02E1000_AGC_LENGTH_TABLE_SIZE) ||
6678 (cur_agc_index == 0))
6679 return -E1000_ERR_PHY;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006680
6681 /* Remove min & max AGC values from calculation. */
Auke Kokcd94dd02006-06-27 09:08:22 -07006682 if (e1000_igp_2_cable_length_table[min_agc_index] >
6683 e1000_igp_2_cable_length_table[cur_agc_index])
6684 min_agc_index = cur_agc_index;
6685 if (e1000_igp_2_cable_length_table[max_agc_index] <
6686 e1000_igp_2_cable_length_table[cur_agc_index])
6687 max_agc_index = cur_agc_index;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006688
Auke Kokcd94dd02006-06-27 09:08:22 -07006689 agc_value += e1000_igp_2_cable_length_table[cur_agc_index];
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006690 }
6691
Auke Kokcd94dd02006-06-27 09:08:22 -07006692 agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] +
6693 e1000_igp_2_cable_length_table[max_agc_index]);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006694 agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
6695
6696 /* Calculate cable length with the error range of +/- 10 meters. */
6697 *min_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
6698 (agc_value - IGP02E1000_AGC_RANGE) : 0;
6699 *max_length = agc_value + IGP02E1000_AGC_RANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006700 }
6701
6702 return E1000_SUCCESS;
6703}
6704
6705/******************************************************************************
6706 * Check the cable polarity
6707 *
6708 * hw - Struct containing variables accessed by shared code
6709 * polarity - output parameter : 0 - Polarity is not reversed
6710 * 1 - Polarity is reversed.
6711 *
6712 * returns: - E1000_ERR_XXX
6713 * E1000_SUCCESS
6714 *
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02006715 * For phy's older than IGP, this function simply reads the polarity bit in the
Linus Torvalds1da177e2005-04-16 15:20:36 -07006716 * Phy Status register. For IGP phy's, this bit is valid only if link speed is
6717 * 10 Mbps. If the link speed is 100 Mbps there is no polarity so this bit will
6718 * return 0. If the link speed is 1000 Mbps the polarity status is in the
6719 * IGP01E1000_PHY_PCS_INIT_REG.
6720 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07006721static s32 e1000_check_polarity(struct e1000_hw *hw,
6722 e1000_rev_polarity *polarity)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006723{
Joe Perches406874a2008-04-03 10:06:32 -07006724 s32 ret_val;
6725 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006726
6727 DEBUGFUNC("e1000_check_polarity");
6728
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08006729 if ((hw->phy_type == e1000_phy_m88) ||
6730 (hw->phy_type == e1000_phy_gg82563)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006731 /* return the Polarity bit in the Status register. */
6732 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6733 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006734 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006735 return ret_val;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07006736 *polarity = ((phy_data & M88E1000_PSSR_REV_POLARITY) >>
6737 M88E1000_PSSR_REV_POLARITY_SHIFT) ?
6738 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
6739
Auke Kokcd94dd02006-06-27 09:08:22 -07006740 } else if (hw->phy_type == e1000_phy_igp ||
6741 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006742 hw->phy_type == e1000_phy_igp_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006743 /* Read the Status register to check the speed */
6744 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
6745 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006746 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006747 return ret_val;
6748
6749 /* If speed is 1000 Mbps, must read the IGP01E1000_PHY_PCS_INIT_REG to
6750 * find the polarity status */
Auke Kok8fc897b2006-08-28 14:56:16 -07006751 if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
Linus Torvalds1da177e2005-04-16 15:20:36 -07006752 IGP01E1000_PSSR_SPEED_1000MBPS) {
6753
6754 /* Read the GIG initialization PCS register (0x00B4) */
6755 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG,
6756 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006757 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006758 return ret_val;
6759
6760 /* Check the polarity bits */
Jeff Kirsher70c6f302006-09-27 12:53:31 -07006761 *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ?
6762 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006763 } else {
6764 /* For 10 Mbps, read the polarity bit in the status register. (for
6765 * 100 Mbps this bit is always 0) */
Jeff Kirsher70c6f302006-09-27 12:53:31 -07006766 *polarity = (phy_data & IGP01E1000_PSSR_POLARITY_REVERSED) ?
6767 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006768 }
Auke Kokcd94dd02006-06-27 09:08:22 -07006769 } else if (hw->phy_type == e1000_phy_ife) {
6770 ret_val = e1000_read_phy_reg(hw, IFE_PHY_EXTENDED_STATUS_CONTROL,
6771 &phy_data);
6772 if (ret_val)
6773 return ret_val;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07006774 *polarity = ((phy_data & IFE_PESC_POLARITY_REVERSED) >>
6775 IFE_PESC_POLARITY_REVERSED_SHIFT) ?
6776 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006777 }
6778 return E1000_SUCCESS;
6779}
6780
6781/******************************************************************************
6782 * Check if Downshift occured
6783 *
6784 * hw - Struct containing variables accessed by shared code
6785 * downshift - output parameter : 0 - No Downshift ocured.
6786 * 1 - Downshift ocured.
6787 *
6788 * returns: - E1000_ERR_XXX
Auke Kok76c224b2006-05-23 13:36:06 -07006789 * E1000_SUCCESS
Linus Torvalds1da177e2005-04-16 15:20:36 -07006790 *
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02006791 * For phy's older than IGP, this function reads the Downshift bit in the Phy
Linus Torvalds1da177e2005-04-16 15:20:36 -07006792 * Specific Status register. For IGP phy's, it reads the Downgrade bit in the
6793 * Link Health register. In IGP this bit is latched high, so the driver must
6794 * read it immediately after link is established.
6795 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07006796static s32 e1000_check_downshift(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006797{
Joe Perches406874a2008-04-03 10:06:32 -07006798 s32 ret_val;
6799 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006800
6801 DEBUGFUNC("e1000_check_downshift");
6802
Auke Kokcd94dd02006-06-27 09:08:22 -07006803 if (hw->phy_type == e1000_phy_igp ||
6804 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006805 hw->phy_type == e1000_phy_igp_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006806 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH,
6807 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006808 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006809 return ret_val;
6810
6811 hw->speed_downgraded = (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08006812 } else if ((hw->phy_type == e1000_phy_m88) ||
6813 (hw->phy_type == e1000_phy_gg82563)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006814 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6815 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006816 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006817 return ret_val;
6818
6819 hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >>
6820 M88E1000_PSSR_DOWNSHIFT_SHIFT;
Auke Kokcd94dd02006-06-27 09:08:22 -07006821 } else if (hw->phy_type == e1000_phy_ife) {
6822 /* e1000_phy_ife supports 10/100 speed only */
Joe Perchesc3033b02008-03-21 11:06:25 -07006823 hw->speed_downgraded = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006824 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006825
Linus Torvalds1da177e2005-04-16 15:20:36 -07006826 return E1000_SUCCESS;
6827}
6828
6829/*****************************************************************************
6830 *
6831 * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a
6832 * gigabit link is achieved to improve link quality.
6833 *
6834 * hw: Struct containing variables accessed by shared code
6835 *
6836 * returns: - E1000_ERR_PHY if fail to read/write the PHY
6837 * E1000_SUCCESS at any other case.
6838 *
6839 ****************************************************************************/
6840
Joe Perches64798842008-07-11 15:17:02 -07006841static s32 e1000_config_dsp_after_link_change(struct e1000_hw *hw, bool link_up)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006842{
Joe Perches406874a2008-04-03 10:06:32 -07006843 s32 ret_val;
6844 u16 phy_data, phy_saved_data, speed, duplex, i;
6845 u16 dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
Linus Torvalds1da177e2005-04-16 15:20:36 -07006846 {IGP01E1000_PHY_AGC_PARAM_A,
6847 IGP01E1000_PHY_AGC_PARAM_B,
6848 IGP01E1000_PHY_AGC_PARAM_C,
6849 IGP01E1000_PHY_AGC_PARAM_D};
Joe Perches406874a2008-04-03 10:06:32 -07006850 u16 min_length, max_length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006851
6852 DEBUGFUNC("e1000_config_dsp_after_link_change");
6853
Auke Kok8fc897b2006-08-28 14:56:16 -07006854 if (hw->phy_type != e1000_phy_igp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006855 return E1000_SUCCESS;
6856
Auke Kok8fc897b2006-08-28 14:56:16 -07006857 if (link_up) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006858 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
Auke Kok8fc897b2006-08-28 14:56:16 -07006859 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006860 DEBUGOUT("Error getting link speed and duplex\n");
6861 return ret_val;
6862 }
6863
Auke Kok8fc897b2006-08-28 14:56:16 -07006864 if (speed == SPEED_1000) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006865
Auke Kokcd94dd02006-06-27 09:08:22 -07006866 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
6867 if (ret_val)
6868 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006869
Auke Kok8fc897b2006-08-28 14:56:16 -07006870 if ((hw->dsp_config_state == e1000_dsp_config_enabled) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07006871 min_length >= e1000_igp_cable_length_50) {
6872
Auke Kok8fc897b2006-08-28 14:56:16 -07006873 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006874 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i],
6875 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006876 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006877 return ret_val;
6878
6879 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
6880
6881 ret_val = e1000_write_phy_reg(hw, dsp_reg_array[i],
6882 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006883 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006884 return ret_val;
6885 }
6886 hw->dsp_config_state = e1000_dsp_config_activated;
6887 }
6888
Auke Kok8fc897b2006-08-28 14:56:16 -07006889 if ((hw->ffe_config_state == e1000_ffe_config_enabled) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07006890 (min_length < e1000_igp_cable_length_50)) {
6891
Joe Perches406874a2008-04-03 10:06:32 -07006892 u16 ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_20;
6893 u32 idle_errs = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006894
6895 /* clear previous idle error counts */
6896 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
6897 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006898 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006899 return ret_val;
6900
Auke Kok8fc897b2006-08-28 14:56:16 -07006901 for (i = 0; i < ffe_idle_err_timeout; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006902 udelay(1000);
6903 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
6904 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006905 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006906 return ret_val;
6907
6908 idle_errs += (phy_data & SR_1000T_IDLE_ERROR_CNT);
Auke Kok8fc897b2006-08-28 14:56:16 -07006909 if (idle_errs > SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006910 hw->ffe_config_state = e1000_ffe_config_active;
6911
6912 ret_val = e1000_write_phy_reg(hw,
6913 IGP01E1000_PHY_DSP_FFE,
6914 IGP01E1000_PHY_DSP_FFE_CM_CP);
Auke Kok8fc897b2006-08-28 14:56:16 -07006915 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006916 return ret_val;
6917 break;
6918 }
6919
Auke Kok8fc897b2006-08-28 14:56:16 -07006920 if (idle_errs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006921 ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_100;
6922 }
6923 }
6924 }
6925 } else {
Auke Kok8fc897b2006-08-28 14:56:16 -07006926 if (hw->dsp_config_state == e1000_dsp_config_activated) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006927 /* Save off the current value of register 0x2F5B to be restored at
6928 * the end of the routines. */
6929 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
6930
Auke Kok8fc897b2006-08-28 14:56:16 -07006931 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006932 return ret_val;
6933
6934 /* Disable the PHY transmitter */
6935 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
6936
Auke Kok8fc897b2006-08-28 14:56:16 -07006937 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006938 return ret_val;
6939
Jeff Garzikf8ec4732006-09-19 15:27:07 -04006940 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006941
6942 ret_val = e1000_write_phy_reg(hw, 0x0000,
6943 IGP01E1000_IEEE_FORCE_GIGA);
Auke Kok8fc897b2006-08-28 14:56:16 -07006944 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006945 return ret_val;
Auke Kok8fc897b2006-08-28 14:56:16 -07006946 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006947 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i], &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006948 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006949 return ret_val;
6950
6951 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
6952 phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS;
6953
6954 ret_val = e1000_write_phy_reg(hw,dsp_reg_array[i], phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006955 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006956 return ret_val;
6957 }
6958
6959 ret_val = e1000_write_phy_reg(hw, 0x0000,
6960 IGP01E1000_IEEE_RESTART_AUTONEG);
Auke Kok8fc897b2006-08-28 14:56:16 -07006961 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006962 return ret_val;
6963
Jeff Garzikf8ec4732006-09-19 15:27:07 -04006964 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006965
6966 /* Now enable the transmitter */
6967 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
6968
Auke Kok8fc897b2006-08-28 14:56:16 -07006969 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006970 return ret_val;
6971
6972 hw->dsp_config_state = e1000_dsp_config_enabled;
6973 }
6974
Auke Kok8fc897b2006-08-28 14:56:16 -07006975 if (hw->ffe_config_state == e1000_ffe_config_active) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006976 /* Save off the current value of register 0x2F5B to be restored at
6977 * the end of the routines. */
6978 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
6979
Auke Kok8fc897b2006-08-28 14:56:16 -07006980 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006981 return ret_val;
6982
6983 /* Disable the PHY transmitter */
6984 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
6985
Auke Kok8fc897b2006-08-28 14:56:16 -07006986 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006987 return ret_val;
6988
Jeff Garzikf8ec4732006-09-19 15:27:07 -04006989 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006990
6991 ret_val = e1000_write_phy_reg(hw, 0x0000,
6992 IGP01E1000_IEEE_FORCE_GIGA);
Auke Kok8fc897b2006-08-28 14:56:16 -07006993 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006994 return ret_val;
6995 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE,
6996 IGP01E1000_PHY_DSP_FFE_DEFAULT);
Auke Kok8fc897b2006-08-28 14:56:16 -07006997 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006998 return ret_val;
6999
7000 ret_val = e1000_write_phy_reg(hw, 0x0000,
7001 IGP01E1000_IEEE_RESTART_AUTONEG);
Auke Kok8fc897b2006-08-28 14:56:16 -07007002 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007003 return ret_val;
7004
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007005 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007006
7007 /* Now enable the transmitter */
7008 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
7009
Auke Kok8fc897b2006-08-28 14:56:16 -07007010 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007011 return ret_val;
7012
7013 hw->ffe_config_state = e1000_ffe_config_enabled;
7014 }
7015 }
7016 return E1000_SUCCESS;
7017}
7018
7019/*****************************************************************************
7020 * Set PHY to class A mode
7021 * Assumes the following operations will follow to enable the new class mode.
7022 * 1. Do a PHY soft reset
7023 * 2. Restart auto-negotiation or force link.
7024 *
7025 * hw - Struct containing variables accessed by shared code
7026 ****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07007027static s32 e1000_set_phy_mode(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007028{
Joe Perches406874a2008-04-03 10:06:32 -07007029 s32 ret_val;
7030 u16 eeprom_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007031
7032 DEBUGFUNC("e1000_set_phy_mode");
7033
Auke Kok8fc897b2006-08-28 14:56:16 -07007034 if ((hw->mac_type == e1000_82545_rev_3) &&
7035 (hw->media_type == e1000_media_type_copper)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007036 ret_val = e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, 1, &eeprom_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007037 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007038 return ret_val;
7039 }
7040
Auke Kok8fc897b2006-08-28 14:56:16 -07007041 if ((eeprom_data != EEPROM_RESERVED_WORD) &&
7042 (eeprom_data & EEPROM_PHY_CLASS_A)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007043 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x000B);
Auke Kok8fc897b2006-08-28 14:56:16 -07007044 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007045 return ret_val;
7046 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x8104);
Auke Kok8fc897b2006-08-28 14:56:16 -07007047 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007048 return ret_val;
7049
Joe Perchesc3033b02008-03-21 11:06:25 -07007050 hw->phy_reset_disable = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007051 }
7052 }
7053
7054 return E1000_SUCCESS;
7055}
7056
7057/*****************************************************************************
7058 *
7059 * This function sets the lplu state according to the active flag. When
7060 * activating lplu this function also disables smart speed and vise versa.
7061 * lplu will not be activated unless the device autonegotiation advertisment
7062 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
7063 * hw: Struct containing variables accessed by shared code
7064 * active - true to enable lplu false to disable lplu.
7065 *
7066 * returns: - E1000_ERR_PHY if fail to read/write the PHY
7067 * E1000_SUCCESS at any other case.
7068 *
7069 ****************************************************************************/
7070
Joe Perches64798842008-07-11 15:17:02 -07007071static s32 e1000_set_d3_lplu_state(struct e1000_hw *hw, bool active)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007072{
Joe Perches406874a2008-04-03 10:06:32 -07007073 u32 phy_ctrl = 0;
7074 s32 ret_val;
7075 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007076 DEBUGFUNC("e1000_set_d3_lplu_state");
7077
Auke Kokcd94dd02006-06-27 09:08:22 -07007078 if (hw->phy_type != e1000_phy_igp && hw->phy_type != e1000_phy_igp_2
7079 && hw->phy_type != e1000_phy_igp_3)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007080 return E1000_SUCCESS;
7081
7082 /* During driver activity LPLU should not be used or it will attain link
7083 * from the lowest speeds starting from 10Mbps. The capability is used for
7084 * Dx transitions and states */
Auke Kokcd94dd02006-06-27 09:08:22 -07007085 if (hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007086 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data);
Auke Kokcd94dd02006-06-27 09:08:22 -07007087 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007088 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007089 } else if (hw->mac_type == e1000_ich8lan) {
7090 /* MAC writes into PHY register based on the state transition
7091 * and start auto-negotiation. SW driver can overwrite the settings
7092 * in CSR PHY power control E1000_PHY_CTRL register. */
Joe Perches1dc32912008-07-11 15:17:08 -07007093 phy_ctrl = er32(PHY_CTRL);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007094 } else {
7095 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007096 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007097 return ret_val;
7098 }
7099
Auke Kok8fc897b2006-08-28 14:56:16 -07007100 if (!active) {
7101 if (hw->mac_type == e1000_82541_rev_2 ||
7102 hw->mac_type == e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007103 phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
7104 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007105 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007106 return ret_val;
7107 } else {
Auke Kokcd94dd02006-06-27 09:08:22 -07007108 if (hw->mac_type == e1000_ich8lan) {
7109 phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
Joe Perches1dc32912008-07-11 15:17:08 -07007110 ew32(PHY_CTRL, phy_ctrl);
Auke Kokcd94dd02006-06-27 09:08:22 -07007111 } else {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007112 phy_data &= ~IGP02E1000_PM_D3_LPLU;
7113 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
7114 phy_data);
7115 if (ret_val)
7116 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007117 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007118 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007119
7120 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
7121 * Dx states where the power conservation is most important. During
7122 * driver activity we should enable SmartSpeed, so performance is
7123 * maintained. */
7124 if (hw->smart_speed == e1000_smart_speed_on) {
7125 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7126 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007127 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007128 return ret_val;
7129
7130 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
7131 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7132 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007133 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007134 return ret_val;
7135 } else if (hw->smart_speed == e1000_smart_speed_off) {
7136 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7137 &phy_data);
Nicholas Nunley35574762006-09-27 12:53:34 -07007138 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007139 return ret_val;
7140
7141 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7142 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7143 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007144 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007145 return ret_val;
7146 }
7147
Auke Kok8fc897b2006-08-28 14:56:16 -07007148 } else if ((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT) ||
7149 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL ) ||
7150 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007151
Auke Kok8fc897b2006-08-28 14:56:16 -07007152 if (hw->mac_type == e1000_82541_rev_2 ||
Auke Kokcd94dd02006-06-27 09:08:22 -07007153 hw->mac_type == e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007154 phy_data |= IGP01E1000_GMII_FLEX_SPD;
7155 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007156 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007157 return ret_val;
7158 } else {
Auke Kokcd94dd02006-06-27 09:08:22 -07007159 if (hw->mac_type == e1000_ich8lan) {
7160 phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
Joe Perches1dc32912008-07-11 15:17:08 -07007161 ew32(PHY_CTRL, phy_ctrl);
Auke Kokcd94dd02006-06-27 09:08:22 -07007162 } else {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007163 phy_data |= IGP02E1000_PM_D3_LPLU;
7164 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
7165 phy_data);
7166 if (ret_val)
7167 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007168 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007169 }
7170
7171 /* When LPLU is enabled we should disable SmartSpeed */
7172 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007173 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007174 return ret_val;
7175
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007176 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7177 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007178 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007179 return ret_val;
7180
7181 }
7182 return E1000_SUCCESS;
7183}
7184
7185/*****************************************************************************
7186 *
7187 * This function sets the lplu d0 state according to the active flag. When
7188 * activating lplu this function also disables smart speed and vise versa.
7189 * lplu will not be activated unless the device autonegotiation advertisment
7190 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
7191 * hw: Struct containing variables accessed by shared code
7192 * active - true to enable lplu false to disable lplu.
7193 *
7194 * returns: - E1000_ERR_PHY if fail to read/write the PHY
7195 * E1000_SUCCESS at any other case.
7196 *
7197 ****************************************************************************/
7198
Joe Perches64798842008-07-11 15:17:02 -07007199static s32 e1000_set_d0_lplu_state(struct e1000_hw *hw, bool active)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007200{
Joe Perches406874a2008-04-03 10:06:32 -07007201 u32 phy_ctrl = 0;
7202 s32 ret_val;
7203 u16 phy_data;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007204 DEBUGFUNC("e1000_set_d0_lplu_state");
7205
Auke Kok8fc897b2006-08-28 14:56:16 -07007206 if (hw->mac_type <= e1000_82547_rev_2)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007207 return E1000_SUCCESS;
7208
Auke Kokcd94dd02006-06-27 09:08:22 -07007209 if (hw->mac_type == e1000_ich8lan) {
Joe Perches1dc32912008-07-11 15:17:08 -07007210 phy_ctrl = er32(PHY_CTRL);
Auke Kokcd94dd02006-06-27 09:08:22 -07007211 } else {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007212 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007213 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007214 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007215 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007216
7217 if (!active) {
Auke Kokcd94dd02006-06-27 09:08:22 -07007218 if (hw->mac_type == e1000_ich8lan) {
7219 phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
Joe Perches1dc32912008-07-11 15:17:08 -07007220 ew32(PHY_CTRL, phy_ctrl);
Auke Kokcd94dd02006-06-27 09:08:22 -07007221 } else {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007222 phy_data &= ~IGP02E1000_PM_D0_LPLU;
7223 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
7224 if (ret_val)
7225 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007226 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007227
7228 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
7229 * Dx states where the power conservation is most important. During
7230 * driver activity we should enable SmartSpeed, so performance is
7231 * maintained. */
7232 if (hw->smart_speed == e1000_smart_speed_on) {
7233 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7234 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007235 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007236 return ret_val;
7237
7238 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
7239 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7240 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007241 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007242 return ret_val;
7243 } else if (hw->smart_speed == e1000_smart_speed_off) {
7244 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7245 &phy_data);
Nicholas Nunley35574762006-09-27 12:53:34 -07007246 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007247 return ret_val;
7248
7249 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7250 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7251 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007252 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007253 return ret_val;
7254 }
7255
7256
7257 } else {
Auke Kok76c224b2006-05-23 13:36:06 -07007258
Auke Kokcd94dd02006-06-27 09:08:22 -07007259 if (hw->mac_type == e1000_ich8lan) {
7260 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
Joe Perches1dc32912008-07-11 15:17:08 -07007261 ew32(PHY_CTRL, phy_ctrl);
Auke Kokcd94dd02006-06-27 09:08:22 -07007262 } else {
Auke Kok76c224b2006-05-23 13:36:06 -07007263 phy_data |= IGP02E1000_PM_D0_LPLU;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007264 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
7265 if (ret_val)
7266 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007267 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007268
Linus Torvalds1da177e2005-04-16 15:20:36 -07007269 /* When LPLU is enabled we should disable SmartSpeed */
7270 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007271 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007272 return ret_val;
7273
7274 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7275 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007276 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007277 return ret_val;
7278
7279 }
7280 return E1000_SUCCESS;
7281}
7282
7283/******************************************************************************
7284 * Change VCO speed register to improve Bit Error Rate performance of SERDES.
7285 *
7286 * hw - Struct containing variables accessed by shared code
7287 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07007288static s32 e1000_set_vco_speed(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007289{
Joe Perches406874a2008-04-03 10:06:32 -07007290 s32 ret_val;
7291 u16 default_page = 0;
7292 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007293
7294 DEBUGFUNC("e1000_set_vco_speed");
7295
Auke Kok8fc897b2006-08-28 14:56:16 -07007296 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007297 case e1000_82545_rev_3:
7298 case e1000_82546_rev_3:
7299 break;
7300 default:
7301 return E1000_SUCCESS;
7302 }
7303
7304 /* Set PHY register 30, page 5, bit 8 to 0 */
7305
7306 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, &default_page);
Auke Kok8fc897b2006-08-28 14:56:16 -07007307 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007308 return ret_val;
7309
7310 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005);
Auke Kok8fc897b2006-08-28 14:56:16 -07007311 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007312 return ret_val;
7313
7314 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007315 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007316 return ret_val;
7317
7318 phy_data &= ~M88E1000_PHY_VCO_REG_BIT8;
7319 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007320 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007321 return ret_val;
7322
7323 /* Set PHY register 30, page 4, bit 11 to 1 */
7324
7325 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004);
Auke Kok8fc897b2006-08-28 14:56:16 -07007326 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007327 return ret_val;
7328
7329 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007330 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007331 return ret_val;
7332
7333 phy_data |= M88E1000_PHY_VCO_REG_BIT11;
7334 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007335 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007336 return ret_val;
7337
7338 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, default_page);
Auke Kok8fc897b2006-08-28 14:56:16 -07007339 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007340 return ret_val;
7341
7342 return E1000_SUCCESS;
7343}
7344
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007345
7346/*****************************************************************************
7347 * This function reads the cookie from ARC ram.
7348 *
7349 * returns: - E1000_SUCCESS .
7350 ****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07007351static s32 e1000_host_if_read_cookie(struct e1000_hw *hw, u8 *buffer)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007352{
Joe Perches406874a2008-04-03 10:06:32 -07007353 u8 i;
7354 u32 offset = E1000_MNG_DHCP_COOKIE_OFFSET;
7355 u8 length = E1000_MNG_DHCP_COOKIE_LENGTH;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007356
7357 length = (length >> 2);
7358 offset = (offset >> 2);
7359
7360 for (i = 0; i < length; i++) {
Joe Perchese982f172008-07-11 15:17:18 -07007361 *((u32 *)buffer + i) =
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007362 E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset + i);
7363 }
7364 return E1000_SUCCESS;
7365}
7366
7367
7368/*****************************************************************************
7369 * This function checks whether the HOST IF is enabled for command operaton
7370 * and also checks whether the previous command is completed.
7371 * It busy waits in case of previous command is not completed.
7372 *
Auke Kok76c224b2006-05-23 13:36:06 -07007373 * returns: - E1000_ERR_HOST_INTERFACE_COMMAND in case if is not ready or
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007374 * timeout
7375 * - E1000_SUCCESS for success.
7376 ****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07007377static s32 e1000_mng_enable_host_if(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007378{
Joe Perches406874a2008-04-03 10:06:32 -07007379 u32 hicr;
7380 u8 i;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007381
7382 /* Check that the host interface is enabled. */
Joe Perches1dc32912008-07-11 15:17:08 -07007383 hicr = er32(HICR);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007384 if ((hicr & E1000_HICR_EN) == 0) {
7385 DEBUGOUT("E1000_HOST_EN bit disabled.\n");
7386 return -E1000_ERR_HOST_INTERFACE_COMMAND;
7387 }
7388 /* check the previous command is completed */
7389 for (i = 0; i < E1000_MNG_DHCP_COMMAND_TIMEOUT; i++) {
Joe Perches1dc32912008-07-11 15:17:08 -07007390 hicr = er32(HICR);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007391 if (!(hicr & E1000_HICR_C))
7392 break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007393 mdelay(1);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007394 }
7395
Auke Kok76c224b2006-05-23 13:36:06 -07007396 if (i == E1000_MNG_DHCP_COMMAND_TIMEOUT) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007397 DEBUGOUT("Previous command timeout failed .\n");
7398 return -E1000_ERR_HOST_INTERFACE_COMMAND;
7399 }
7400 return E1000_SUCCESS;
7401}
7402
7403/*****************************************************************************
7404 * This function writes the buffer content at the offset given on the host if.
7405 * It also does alignment considerations to do the writes in most efficient way.
7406 * Also fills up the sum of the buffer in *buffer parameter.
7407 *
7408 * returns - E1000_SUCCESS for success.
7409 ****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07007410static s32 e1000_mng_host_if_write(struct e1000_hw *hw, u8 *buffer, u16 length,
7411 u16 offset, u8 *sum)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007412{
Joe Perches406874a2008-04-03 10:06:32 -07007413 u8 *tmp;
7414 u8 *bufptr = buffer;
7415 u32 data = 0;
7416 u16 remaining, i, j, prev_bytes;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007417
7418 /* sum = only sum of the data and it is not checksum */
7419
7420 if (length == 0 || offset + length > E1000_HI_MAX_MNG_DATA_LENGTH) {
7421 return -E1000_ERR_PARAM;
7422 }
7423
Joe Perches406874a2008-04-03 10:06:32 -07007424 tmp = (u8 *)&data;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007425 prev_bytes = offset & 0x3;
7426 offset &= 0xFFFC;
7427 offset >>= 2;
7428
7429 if (prev_bytes) {
7430 data = E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset);
Joe Perches406874a2008-04-03 10:06:32 -07007431 for (j = prev_bytes; j < sizeof(u32); j++) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007432 *(tmp + j) = *bufptr++;
7433 *sum += *(tmp + j);
7434 }
7435 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset, data);
7436 length -= j - prev_bytes;
7437 offset++;
7438 }
7439
7440 remaining = length & 0x3;
7441 length -= remaining;
7442
7443 /* Calculate length in DWORDs */
7444 length >>= 2;
7445
7446 /* The device driver writes the relevant command block into the
7447 * ram area. */
7448 for (i = 0; i < length; i++) {
Joe Perches406874a2008-04-03 10:06:32 -07007449 for (j = 0; j < sizeof(u32); j++) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007450 *(tmp + j) = *bufptr++;
7451 *sum += *(tmp + j);
7452 }
7453
7454 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data);
7455 }
7456 if (remaining) {
Joe Perches406874a2008-04-03 10:06:32 -07007457 for (j = 0; j < sizeof(u32); j++) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007458 if (j < remaining)
7459 *(tmp + j) = *bufptr++;
7460 else
7461 *(tmp + j) = 0;
7462
7463 *sum += *(tmp + j);
7464 }
7465 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data);
7466 }
7467
7468 return E1000_SUCCESS;
7469}
7470
7471
7472/*****************************************************************************
7473 * This function writes the command header after does the checksum calculation.
7474 *
7475 * returns - E1000_SUCCESS for success.
7476 ****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07007477static s32 e1000_mng_write_cmd_header(struct e1000_hw *hw,
7478 struct e1000_host_mng_command_header *hdr)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007479{
Joe Perches406874a2008-04-03 10:06:32 -07007480 u16 i;
7481 u8 sum;
7482 u8 *buffer;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007483
7484 /* Write the whole command header structure which includes sum of
7485 * the buffer */
7486
Joe Perches406874a2008-04-03 10:06:32 -07007487 u16 length = sizeof(struct e1000_host_mng_command_header);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007488
7489 sum = hdr->checksum;
7490 hdr->checksum = 0;
7491
Joe Perchese982f172008-07-11 15:17:18 -07007492 buffer = (u8 *)hdr;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007493 i = length;
Auke Kok8fc897b2006-08-28 14:56:16 -07007494 while (i--)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007495 sum += buffer[i];
7496
7497 hdr->checksum = 0 - sum;
7498
7499 length >>= 2;
7500 /* The device driver writes the relevant command block into the ram area. */
Auke Kok4ca213a2006-06-27 09:07:08 -07007501 for (i = 0; i < length; i++) {
Joe Perchese982f172008-07-11 15:17:18 -07007502 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, i, *((u32 *)hdr + i));
Joe Perches1dc32912008-07-11 15:17:08 -07007503 E1000_WRITE_FLUSH();
Auke Kok4ca213a2006-06-27 09:07:08 -07007504 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007505
7506 return E1000_SUCCESS;
7507}
7508
7509
7510/*****************************************************************************
7511 * This function indicates to ARC that a new command is pending which completes
7512 * one write operation by the driver.
7513 *
7514 * returns - E1000_SUCCESS for success.
7515 ****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07007516static s32 e1000_mng_write_commit(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007517{
Joe Perches406874a2008-04-03 10:06:32 -07007518 u32 hicr;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007519
Joe Perches1dc32912008-07-11 15:17:08 -07007520 hicr = er32(HICR);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007521 /* Setting this bit tells the ARC that a new command is pending. */
Joe Perches1dc32912008-07-11 15:17:08 -07007522 ew32(HICR, hicr | E1000_HICR_C);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007523
7524 return E1000_SUCCESS;
7525}
7526
7527
7528/*****************************************************************************
7529 * This function checks the mode of the firmware.
7530 *
Joe Perchesc3033b02008-03-21 11:06:25 -07007531 * returns - true when the mode is IAMT or false.
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007532 ****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07007533bool e1000_check_mng_mode(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007534{
Joe Perches406874a2008-04-03 10:06:32 -07007535 u32 fwsm;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007536
Joe Perches1dc32912008-07-11 15:17:08 -07007537 fwsm = er32(FWSM);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007538
Auke Kokcd94dd02006-06-27 09:08:22 -07007539 if (hw->mac_type == e1000_ich8lan) {
7540 if ((fwsm & E1000_FWSM_MODE_MASK) ==
7541 (E1000_MNG_ICH_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
Joe Perchesc3033b02008-03-21 11:06:25 -07007542 return true;
Auke Kokcd94dd02006-06-27 09:08:22 -07007543 } else if ((fwsm & E1000_FWSM_MODE_MASK) ==
7544 (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
Joe Perchesc3033b02008-03-21 11:06:25 -07007545 return true;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007546
Joe Perchesc3033b02008-03-21 11:06:25 -07007547 return false;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007548}
7549
7550
7551/*****************************************************************************
7552 * This function writes the dhcp info .
7553 ****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07007554s32 e1000_mng_write_dhcp_info(struct e1000_hw *hw, u8 *buffer, u16 length)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007555{
Joe Perches406874a2008-04-03 10:06:32 -07007556 s32 ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007557 struct e1000_host_mng_command_header hdr;
7558
7559 hdr.command_id = E1000_MNG_DHCP_TX_PAYLOAD_CMD;
7560 hdr.command_length = length;
7561 hdr.reserved1 = 0;
7562 hdr.reserved2 = 0;
7563 hdr.checksum = 0;
7564
7565 ret_val = e1000_mng_enable_host_if(hw);
7566 if (ret_val == E1000_SUCCESS) {
7567 ret_val = e1000_mng_host_if_write(hw, buffer, length, sizeof(hdr),
7568 &(hdr.checksum));
7569 if (ret_val == E1000_SUCCESS) {
7570 ret_val = e1000_mng_write_cmd_header(hw, &hdr);
7571 if (ret_val == E1000_SUCCESS)
7572 ret_val = e1000_mng_write_commit(hw);
7573 }
7574 }
7575 return ret_val;
7576}
7577
7578
7579/*****************************************************************************
7580 * This function calculates the checksum.
7581 *
7582 * returns - checksum of buffer contents.
7583 ****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07007584static u8 e1000_calculate_mng_checksum(char *buffer, u32 length)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007585{
Joe Perches406874a2008-04-03 10:06:32 -07007586 u8 sum = 0;
7587 u32 i;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007588
7589 if (!buffer)
7590 return 0;
7591
7592 for (i=0; i < length; i++)
7593 sum += buffer[i];
7594
Joe Perchese982f172008-07-11 15:17:18 -07007595 return (u8)(0 - sum);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007596}
7597
7598/*****************************************************************************
7599 * This function checks whether tx pkt filtering needs to be enabled or not.
7600 *
Joe Perchesc3033b02008-03-21 11:06:25 -07007601 * returns - true for packet filtering or false.
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007602 ****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07007603bool e1000_enable_tx_pkt_filtering(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007604{
7605 /* called in init as well as watchdog timer functions */
7606
Joe Perches406874a2008-04-03 10:06:32 -07007607 s32 ret_val, checksum;
Joe Perchesc3033b02008-03-21 11:06:25 -07007608 bool tx_filter = false;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007609 struct e1000_host_mng_dhcp_cookie *hdr = &(hw->mng_cookie);
Joe Perches406874a2008-04-03 10:06:32 -07007610 u8 *buffer = (u8 *) &(hw->mng_cookie);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007611
7612 if (e1000_check_mng_mode(hw)) {
7613 ret_val = e1000_mng_enable_host_if(hw);
7614 if (ret_val == E1000_SUCCESS) {
7615 ret_val = e1000_host_if_read_cookie(hw, buffer);
7616 if (ret_val == E1000_SUCCESS) {
7617 checksum = hdr->checksum;
7618 hdr->checksum = 0;
7619 if ((hdr->signature == E1000_IAMT_SIGNATURE) &&
7620 checksum == e1000_calculate_mng_checksum((char *)buffer,
7621 E1000_MNG_DHCP_COOKIE_LENGTH)) {
7622 if (hdr->status &
7623 E1000_MNG_DHCP_COOKIE_STATUS_PARSING_SUPPORT)
Joe Perchesc3033b02008-03-21 11:06:25 -07007624 tx_filter = true;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007625 } else
Joe Perchesc3033b02008-03-21 11:06:25 -07007626 tx_filter = true;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007627 } else
Joe Perchesc3033b02008-03-21 11:06:25 -07007628 tx_filter = true;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007629 }
7630 }
7631
7632 hw->tx_pkt_filtering = tx_filter;
7633 return tx_filter;
7634}
7635
7636/******************************************************************************
7637 * Verifies the hardware needs to allow ARPs to be processed by the host
7638 *
7639 * hw - Struct containing variables accessed by shared code
7640 *
Joe Perchesc3033b02008-03-21 11:06:25 -07007641 * returns: - true/false
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007642 *
7643 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07007644u32 e1000_enable_mng_pass_thru(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007645{
Joe Perches406874a2008-04-03 10:06:32 -07007646 u32 manc;
7647 u32 fwsm, factps;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007648
7649 if (hw->asf_firmware_present) {
Joe Perches1dc32912008-07-11 15:17:08 -07007650 manc = er32(MANC);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007651
7652 if (!(manc & E1000_MANC_RCV_TCO_EN) ||
7653 !(manc & E1000_MANC_EN_MAC_ADDR_FILTER))
Joe Perchesc3033b02008-03-21 11:06:25 -07007654 return false;
7655 if (e1000_arc_subsystem_valid(hw)) {
Joe Perches1dc32912008-07-11 15:17:08 -07007656 fwsm = er32(FWSM);
7657 factps = er32(FACTPS);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007658
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05007659 if ((((fwsm & E1000_FWSM_MODE_MASK) >> E1000_FWSM_MODE_SHIFT) ==
7660 e1000_mng_mode_pt) && !(factps & E1000_FACTPS_MNGCG))
Joe Perchesc3033b02008-03-21 11:06:25 -07007661 return true;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007662 } else
7663 if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN))
Joe Perchesc3033b02008-03-21 11:06:25 -07007664 return true;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007665 }
Joe Perchesc3033b02008-03-21 11:06:25 -07007666 return false;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007667}
7668
Joe Perches64798842008-07-11 15:17:02 -07007669static s32 e1000_polarity_reversal_workaround(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007670{
Joe Perches406874a2008-04-03 10:06:32 -07007671 s32 ret_val;
7672 u16 mii_status_reg;
7673 u16 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007674
7675 /* Polarity reversal workaround for forced 10F/10H links. */
7676
7677 /* Disable the transmitter on the PHY */
7678
7679 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
Auke Kok8fc897b2006-08-28 14:56:16 -07007680 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007681 return ret_val;
7682 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF);
Auke Kok8fc897b2006-08-28 14:56:16 -07007683 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007684 return ret_val;
7685
7686 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
Auke Kok8fc897b2006-08-28 14:56:16 -07007687 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007688 return ret_val;
7689
7690 /* This loop will early-out if the NO link condition has been met. */
Auke Kok8fc897b2006-08-28 14:56:16 -07007691 for (i = PHY_FORCE_TIME; i > 0; i--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007692 /* Read the MII Status Register and wait for Link Status bit
7693 * to be clear.
7694 */
7695
7696 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07007697 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007698 return ret_val;
7699
7700 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07007701 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007702 return ret_val;
7703
Auke Kok8fc897b2006-08-28 14:56:16 -07007704 if ((mii_status_reg & ~MII_SR_LINK_STATUS) == 0) break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007705 mdelay(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007706 }
7707
7708 /* Recommended delay time after link has been lost */
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007709 mdelay(1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007710
7711 /* Now we will re-enable th transmitter on the PHY */
7712
7713 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
Auke Kok8fc897b2006-08-28 14:56:16 -07007714 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007715 return ret_val;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007716 mdelay(50);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007717 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0);
Auke Kok8fc897b2006-08-28 14:56:16 -07007718 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007719 return ret_val;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007720 mdelay(50);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007721 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00);
Auke Kok8fc897b2006-08-28 14:56:16 -07007722 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007723 return ret_val;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007724 mdelay(50);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007725 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000);
Auke Kok8fc897b2006-08-28 14:56:16 -07007726 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007727 return ret_val;
7728
7729 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
Auke Kok8fc897b2006-08-28 14:56:16 -07007730 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007731 return ret_val;
7732
7733 /* This loop will early-out if the link condition has been met. */
Auke Kok8fc897b2006-08-28 14:56:16 -07007734 for (i = PHY_FORCE_TIME; i > 0; i--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007735 /* Read the MII Status Register and wait for Link Status bit
7736 * to be set.
7737 */
7738
7739 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07007740 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007741 return ret_val;
7742
7743 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07007744 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007745 return ret_val;
7746
Auke Kok8fc897b2006-08-28 14:56:16 -07007747 if (mii_status_reg & MII_SR_LINK_STATUS) break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007748 mdelay(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007749 }
7750 return E1000_SUCCESS;
7751}
7752
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007753/***************************************************************************
7754 *
7755 * Disables PCI-Express master access.
7756 *
7757 * hw: Struct containing variables accessed by shared code
7758 *
7759 * returns: - none.
7760 *
7761 ***************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07007762static void e1000_set_pci_express_master_disable(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007763{
Joe Perches406874a2008-04-03 10:06:32 -07007764 u32 ctrl;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007765
7766 DEBUGFUNC("e1000_set_pci_express_master_disable");
7767
7768 if (hw->bus_type != e1000_bus_type_pci_express)
7769 return;
7770
Joe Perches1dc32912008-07-11 15:17:08 -07007771 ctrl = er32(CTRL);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007772 ctrl |= E1000_CTRL_GIO_MASTER_DISABLE;
Joe Perches1dc32912008-07-11 15:17:08 -07007773 ew32(CTRL, ctrl);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007774}
7775
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007776/*******************************************************************************
7777 *
7778 * Disables PCI-Express master access and verifies there are no pending requests
7779 *
7780 * hw: Struct containing variables accessed by shared code
7781 *
7782 * returns: - E1000_ERR_MASTER_REQUESTS_PENDING if master disable bit hasn't
7783 * caused the master requests to be disabled.
7784 * E1000_SUCCESS master requests disabled.
7785 *
7786 ******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07007787s32 e1000_disable_pciex_master(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007788{
Joe Perches406874a2008-04-03 10:06:32 -07007789 s32 timeout = MASTER_DISABLE_TIMEOUT; /* 80ms */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007790
7791 DEBUGFUNC("e1000_disable_pciex_master");
7792
7793 if (hw->bus_type != e1000_bus_type_pci_express)
7794 return E1000_SUCCESS;
7795
7796 e1000_set_pci_express_master_disable(hw);
7797
Auke Kok8fc897b2006-08-28 14:56:16 -07007798 while (timeout) {
Joe Perches1dc32912008-07-11 15:17:08 -07007799 if (!(er32(STATUS) & E1000_STATUS_GIO_MASTER_ENABLE))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007800 break;
7801 else
7802 udelay(100);
7803 timeout--;
7804 }
7805
Auke Kok8fc897b2006-08-28 14:56:16 -07007806 if (!timeout) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007807 DEBUGOUT("Master requests are pending.\n");
7808 return -E1000_ERR_MASTER_REQUESTS_PENDING;
7809 }
7810
7811 return E1000_SUCCESS;
7812}
7813
7814/*******************************************************************************
7815 *
7816 * Check for EEPROM Auto Read bit done.
7817 *
7818 * hw: Struct containing variables accessed by shared code
7819 *
7820 * returns: - E1000_ERR_RESET if fail to reset MAC
7821 * E1000_SUCCESS at any other case.
7822 *
7823 ******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07007824static s32 e1000_get_auto_rd_done(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007825{
Joe Perches406874a2008-04-03 10:06:32 -07007826 s32 timeout = AUTO_READ_DONE_TIMEOUT;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007827
7828 DEBUGFUNC("e1000_get_auto_rd_done");
7829
7830 switch (hw->mac_type) {
7831 default:
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007832 msleep(5);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007833 break;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04007834 case e1000_82571:
7835 case e1000_82572:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007836 case e1000_82573:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08007837 case e1000_80003es2lan:
Auke Kokcd94dd02006-06-27 09:08:22 -07007838 case e1000_ich8lan:
7839 while (timeout) {
Joe Perches1dc32912008-07-11 15:17:08 -07007840 if (er32(EECD) & E1000_EECD_AUTO_RD)
Auke Kokcd94dd02006-06-27 09:08:22 -07007841 break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007842 else msleep(1);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007843 timeout--;
7844 }
7845
Auke Kok8fc897b2006-08-28 14:56:16 -07007846 if (!timeout) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007847 DEBUGOUT("Auto read by HW from EEPROM has not completed.\n");
7848 return -E1000_ERR_RESET;
7849 }
7850 break;
7851 }
7852
Jeff Kirsherfd803242005-12-13 00:06:22 -05007853 /* PHY configuration from NVM just starts after EECD_AUTO_RD sets to high.
7854 * Need to wait for PHY configuration completion before accessing NVM
7855 * and PHY. */
7856 if (hw->mac_type == e1000_82573)
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007857 msleep(25);
Jeff Kirsherfd803242005-12-13 00:06:22 -05007858
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007859 return E1000_SUCCESS;
7860}
7861
7862/***************************************************************************
7863 * Checks if the PHY configuration is done
7864 *
7865 * hw: Struct containing variables accessed by shared code
7866 *
7867 * returns: - E1000_ERR_RESET if fail to reset MAC
7868 * E1000_SUCCESS at any other case.
7869 *
7870 ***************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07007871static s32 e1000_get_phy_cfg_done(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007872{
Joe Perches406874a2008-04-03 10:06:32 -07007873 s32 timeout = PHY_CFG_TIMEOUT;
7874 u32 cfg_mask = E1000_EEPROM_CFG_DONE;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04007875
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007876 DEBUGFUNC("e1000_get_phy_cfg_done");
7877
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04007878 switch (hw->mac_type) {
7879 default:
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007880 mdelay(10);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04007881 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08007882 case e1000_80003es2lan:
7883 /* Separate *_CFG_DONE_* bit for each port */
Joe Perches1dc32912008-07-11 15:17:08 -07007884 if (er32(STATUS) & E1000_STATUS_FUNC_1)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08007885 cfg_mask = E1000_EEPROM_CFG_DONE_PORT_1;
7886 /* Fall Through */
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04007887 case e1000_82571:
7888 case e1000_82572:
7889 while (timeout) {
Joe Perches1dc32912008-07-11 15:17:08 -07007890 if (er32(EEMNGCTL) & cfg_mask)
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04007891 break;
7892 else
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007893 msleep(1);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04007894 timeout--;
7895 }
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04007896 if (!timeout) {
7897 DEBUGOUT("MNG configuration cycle has not completed.\n");
7898 return -E1000_ERR_RESET;
7899 }
7900 break;
7901 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007902
7903 return E1000_SUCCESS;
7904}
7905
7906/***************************************************************************
7907 *
7908 * Using the combination of SMBI and SWESMBI semaphore bits when resetting
7909 * adapter or Eeprom access.
7910 *
7911 * hw: Struct containing variables accessed by shared code
7912 *
7913 * returns: - E1000_ERR_EEPROM if fail to access EEPROM.
7914 * E1000_SUCCESS at any other case.
7915 *
7916 ***************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07007917static s32 e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007918{
Joe Perches406874a2008-04-03 10:06:32 -07007919 s32 timeout;
7920 u32 swsm;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007921
7922 DEBUGFUNC("e1000_get_hw_eeprom_semaphore");
7923
Auke Kok8fc897b2006-08-28 14:56:16 -07007924 if (!hw->eeprom_semaphore_present)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007925 return E1000_SUCCESS;
7926
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08007927 if (hw->mac_type == e1000_80003es2lan) {
7928 /* Get the SW semaphore. */
7929 if (e1000_get_software_semaphore(hw) != E1000_SUCCESS)
7930 return -E1000_ERR_EEPROM;
7931 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007932
7933 /* Get the FW semaphore. */
7934 timeout = hw->eeprom.word_size + 1;
Auke Kok8fc897b2006-08-28 14:56:16 -07007935 while (timeout) {
Joe Perches1dc32912008-07-11 15:17:08 -07007936 swsm = er32(SWSM);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007937 swsm |= E1000_SWSM_SWESMBI;
Joe Perches1dc32912008-07-11 15:17:08 -07007938 ew32(SWSM, swsm);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007939 /* if we managed to set the bit we got the semaphore. */
Joe Perches1dc32912008-07-11 15:17:08 -07007940 swsm = er32(SWSM);
Auke Kok8fc897b2006-08-28 14:56:16 -07007941 if (swsm & E1000_SWSM_SWESMBI)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007942 break;
7943
7944 udelay(50);
7945 timeout--;
7946 }
7947
Auke Kok8fc897b2006-08-28 14:56:16 -07007948 if (!timeout) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007949 /* Release semaphores */
7950 e1000_put_hw_eeprom_semaphore(hw);
7951 DEBUGOUT("Driver can't access the Eeprom - SWESMBI bit is set.\n");
7952 return -E1000_ERR_EEPROM;
7953 }
7954
7955 return E1000_SUCCESS;
7956}
7957
7958/***************************************************************************
7959 * This function clears HW semaphore bits.
7960 *
7961 * hw: Struct containing variables accessed by shared code
7962 *
7963 * returns: - None.
7964 *
7965 ***************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07007966static void e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007967{
Joe Perches406874a2008-04-03 10:06:32 -07007968 u32 swsm;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007969
7970 DEBUGFUNC("e1000_put_hw_eeprom_semaphore");
7971
Auke Kok8fc897b2006-08-28 14:56:16 -07007972 if (!hw->eeprom_semaphore_present)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007973 return;
7974
Joe Perches1dc32912008-07-11 15:17:08 -07007975 swsm = er32(SWSM);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08007976 if (hw->mac_type == e1000_80003es2lan) {
7977 /* Release both semaphores. */
7978 swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
7979 } else
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04007980 swsm &= ~(E1000_SWSM_SWESMBI);
Joe Perches1dc32912008-07-11 15:17:08 -07007981 ew32(SWSM, swsm);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007982}
7983
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08007984/***************************************************************************
7985 *
7986 * Obtaining software semaphore bit (SMBI) before resetting PHY.
7987 *
7988 * hw: Struct containing variables accessed by shared code
7989 *
7990 * returns: - E1000_ERR_RESET if fail to obtain semaphore.
7991 * E1000_SUCCESS at any other case.
7992 *
7993 ***************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07007994static s32 e1000_get_software_semaphore(struct e1000_hw *hw)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08007995{
Joe Perches406874a2008-04-03 10:06:32 -07007996 s32 timeout = hw->eeprom.word_size + 1;
7997 u32 swsm;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08007998
7999 DEBUGFUNC("e1000_get_software_semaphore");
8000
Nicholas Nunley35574762006-09-27 12:53:34 -07008001 if (hw->mac_type != e1000_80003es2lan) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008002 return E1000_SUCCESS;
Nicholas Nunley35574762006-09-27 12:53:34 -07008003 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008004
Auke Kok8fc897b2006-08-28 14:56:16 -07008005 while (timeout) {
Joe Perches1dc32912008-07-11 15:17:08 -07008006 swsm = er32(SWSM);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008007 /* If SMBI bit cleared, it is now set and we hold the semaphore */
Auke Kok8fc897b2006-08-28 14:56:16 -07008008 if (!(swsm & E1000_SWSM_SMBI))
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008009 break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008010 mdelay(1);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008011 timeout--;
8012 }
8013
Auke Kok8fc897b2006-08-28 14:56:16 -07008014 if (!timeout) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008015 DEBUGOUT("Driver can't access device - SMBI bit is set.\n");
8016 return -E1000_ERR_RESET;
8017 }
8018
8019 return E1000_SUCCESS;
8020}
8021
8022/***************************************************************************
8023 *
8024 * Release semaphore bit (SMBI).
8025 *
8026 * hw: Struct containing variables accessed by shared code
8027 *
8028 ***************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07008029static void e1000_release_software_semaphore(struct e1000_hw *hw)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008030{
Joe Perches406874a2008-04-03 10:06:32 -07008031 u32 swsm;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008032
8033 DEBUGFUNC("e1000_release_software_semaphore");
8034
Nicholas Nunley35574762006-09-27 12:53:34 -07008035 if (hw->mac_type != e1000_80003es2lan) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008036 return;
Nicholas Nunley35574762006-09-27 12:53:34 -07008037 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008038
Joe Perches1dc32912008-07-11 15:17:08 -07008039 swsm = er32(SWSM);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008040 /* Release the SW semaphores.*/
8041 swsm &= ~E1000_SWSM_SMBI;
Joe Perches1dc32912008-07-11 15:17:08 -07008042 ew32(SWSM, swsm);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008043}
8044
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008045/******************************************************************************
8046 * Checks if PHY reset is blocked due to SOL/IDER session, for example.
8047 * Returning E1000_BLK_PHY_RESET isn't necessarily an error. But it's up to
8048 * the caller to figure out how to deal with it.
8049 *
8050 * hw - Struct containing variables accessed by shared code
8051 *
8052 * returns: - E1000_BLK_PHY_RESET
8053 * E1000_SUCCESS
8054 *
8055 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07008056s32 e1000_check_phy_reset_block(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008057{
Joe Perches406874a2008-04-03 10:06:32 -07008058 u32 manc = 0;
8059 u32 fwsm = 0;
Auke Kokcd94dd02006-06-27 09:08:22 -07008060
8061 if (hw->mac_type == e1000_ich8lan) {
Joe Perches1dc32912008-07-11 15:17:08 -07008062 fwsm = er32(FWSM);
Auke Kokcd94dd02006-06-27 09:08:22 -07008063 return (fwsm & E1000_FWSM_RSPCIPHY) ? E1000_SUCCESS
8064 : E1000_BLK_PHY_RESET;
8065 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08008066
8067 if (hw->mac_type > e1000_82547_rev_2)
Joe Perches1dc32912008-07-11 15:17:08 -07008068 manc = er32(MANC);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008069 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
Nicholas Nunley35574762006-09-27 12:53:34 -07008070 E1000_BLK_PHY_RESET : E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008071}
8072
Joe Perches64798842008-07-11 15:17:02 -07008073static u8 e1000_arc_subsystem_valid(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008074{
Joe Perches406874a2008-04-03 10:06:32 -07008075 u32 fwsm;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008076
8077 /* On 8257x silicon, registers in the range of 0x8800 - 0x8FFC
8078 * may not be provided a DMA clock when no manageability features are
8079 * enabled. We do not want to perform any reads/writes to these registers
8080 * if this is the case. We read FWSM to determine the manageability mode.
8081 */
8082 switch (hw->mac_type) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008083 case e1000_82571:
8084 case e1000_82572:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008085 case e1000_82573:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008086 case e1000_80003es2lan:
Joe Perches1dc32912008-07-11 15:17:08 -07008087 fwsm = er32(FWSM);
Auke Kok8fc897b2006-08-28 14:56:16 -07008088 if ((fwsm & E1000_FWSM_MODE_MASK) != 0)
Joe Perchesc3033b02008-03-21 11:06:25 -07008089 return true;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008090 break;
Auke Kokcd94dd02006-06-27 09:08:22 -07008091 case e1000_ich8lan:
Joe Perchesc3033b02008-03-21 11:06:25 -07008092 return true;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008093 default:
8094 break;
8095 }
Joe Perchesc3033b02008-03-21 11:06:25 -07008096 return false;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008097}
8098
8099
Auke Kokd37ea5d2006-06-27 09:08:17 -07008100/******************************************************************************
8101 * Configure PCI-Ex no-snoop
8102 *
8103 * hw - Struct containing variables accessed by shared code.
8104 * no_snoop - Bitmap of no-snoop events.
8105 *
8106 * returns: E1000_SUCCESS
8107 *
8108 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07008109static s32 e1000_set_pci_ex_no_snoop(struct e1000_hw *hw, u32 no_snoop)
Auke Kokd37ea5d2006-06-27 09:08:17 -07008110{
Joe Perches406874a2008-04-03 10:06:32 -07008111 u32 gcr_reg = 0;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008112
8113 DEBUGFUNC("e1000_set_pci_ex_no_snoop");
8114
8115 if (hw->bus_type == e1000_bus_type_unknown)
8116 e1000_get_bus_info(hw);
8117
8118 if (hw->bus_type != e1000_bus_type_pci_express)
8119 return E1000_SUCCESS;
8120
8121 if (no_snoop) {
Joe Perches1dc32912008-07-11 15:17:08 -07008122 gcr_reg = er32(GCR);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008123 gcr_reg &= ~(PCI_EX_NO_SNOOP_ALL);
8124 gcr_reg |= no_snoop;
Joe Perches1dc32912008-07-11 15:17:08 -07008125 ew32(GCR, gcr_reg);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008126 }
8127 if (hw->mac_type == e1000_ich8lan) {
Joe Perches406874a2008-04-03 10:06:32 -07008128 u32 ctrl_ext;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008129
Joe Perches1dc32912008-07-11 15:17:08 -07008130 ew32(GCR, PCI_EX_82566_SNOOP_ALL);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008131
Joe Perches1dc32912008-07-11 15:17:08 -07008132 ctrl_ext = er32(CTRL_EXT);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008133 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
Joe Perches1dc32912008-07-11 15:17:08 -07008134 ew32(CTRL_EXT, ctrl_ext);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008135 }
8136
8137 return E1000_SUCCESS;
8138}
8139
8140/***************************************************************************
8141 *
8142 * Get software semaphore FLAG bit (SWFLAG).
8143 * SWFLAG is used to synchronize the access to all shared resource between
8144 * SW, FW and HW.
8145 *
8146 * hw: Struct containing variables accessed by shared code
8147 *
8148 ***************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07008149static s32 e1000_get_software_flag(struct e1000_hw *hw)
Auke Kokd37ea5d2006-06-27 09:08:17 -07008150{
Joe Perches406874a2008-04-03 10:06:32 -07008151 s32 timeout = PHY_CFG_TIMEOUT;
8152 u32 extcnf_ctrl;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008153
8154 DEBUGFUNC("e1000_get_software_flag");
8155
8156 if (hw->mac_type == e1000_ich8lan) {
8157 while (timeout) {
Joe Perches1dc32912008-07-11 15:17:08 -07008158 extcnf_ctrl = er32(EXTCNF_CTRL);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008159 extcnf_ctrl |= E1000_EXTCNF_CTRL_SWFLAG;
Joe Perches1dc32912008-07-11 15:17:08 -07008160 ew32(EXTCNF_CTRL, extcnf_ctrl);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008161
Joe Perches1dc32912008-07-11 15:17:08 -07008162 extcnf_ctrl = er32(EXTCNF_CTRL);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008163 if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG)
8164 break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008165 mdelay(1);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008166 timeout--;
8167 }
8168
8169 if (!timeout) {
8170 DEBUGOUT("FW or HW locks the resource too long.\n");
8171 return -E1000_ERR_CONFIG;
8172 }
8173 }
8174
8175 return E1000_SUCCESS;
8176}
8177
8178/***************************************************************************
8179 *
8180 * Release software semaphore FLAG bit (SWFLAG).
8181 * SWFLAG is used to synchronize the access to all shared resource between
8182 * SW, FW and HW.
8183 *
8184 * hw: Struct containing variables accessed by shared code
8185 *
8186 ***************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07008187static void e1000_release_software_flag(struct e1000_hw *hw)
Auke Kokd37ea5d2006-06-27 09:08:17 -07008188{
Joe Perches406874a2008-04-03 10:06:32 -07008189 u32 extcnf_ctrl;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008190
8191 DEBUGFUNC("e1000_release_software_flag");
8192
8193 if (hw->mac_type == e1000_ich8lan) {
Joe Perches1dc32912008-07-11 15:17:08 -07008194 extcnf_ctrl= er32(EXTCNF_CTRL);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008195 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
Joe Perches1dc32912008-07-11 15:17:08 -07008196 ew32(EXTCNF_CTRL, extcnf_ctrl);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008197 }
8198
8199 return;
8200}
8201
Auke Kokd37ea5d2006-06-27 09:08:17 -07008202/******************************************************************************
8203 * Reads a 16 bit word or words from the EEPROM using the ICH8's flash access
8204 * register.
8205 *
8206 * hw - Struct containing variables accessed by shared code
8207 * offset - offset of word in the EEPROM to read
8208 * data - word read from the EEPROM
8209 * words - number of words to read
8210 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07008211static s32 e1000_read_eeprom_ich8(struct e1000_hw *hw, u16 offset, u16 words,
8212 u16 *data)
Auke Kokd37ea5d2006-06-27 09:08:17 -07008213{
Joe Perches406874a2008-04-03 10:06:32 -07008214 s32 error = E1000_SUCCESS;
8215 u32 flash_bank = 0;
8216 u32 act_offset = 0;
8217 u32 bank_offset = 0;
8218 u16 word = 0;
8219 u16 i = 0;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008220
8221 /* We need to know which is the valid flash bank. In the event
8222 * that we didn't allocate eeprom_shadow_ram, we may not be
8223 * managing flash_bank. So it cannot be trusted and needs
8224 * to be updated with each read.
8225 */
8226 /* Value of bit 22 corresponds to the flash bank we're on. */
Joe Perches1dc32912008-07-11 15:17:08 -07008227 flash_bank = (er32(EECD) & E1000_EECD_SEC1VAL) ? 1 : 0;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008228
8229 /* Adjust offset appropriately if we're on bank 1 - adjust for word size */
8230 bank_offset = flash_bank * (hw->flash_bank_size * 2);
8231
8232 error = e1000_get_software_flag(hw);
8233 if (error != E1000_SUCCESS)
8234 return error;
8235
8236 for (i = 0; i < words; i++) {
8237 if (hw->eeprom_shadow_ram != NULL &&
Joe Perchesc3033b02008-03-21 11:06:25 -07008238 hw->eeprom_shadow_ram[offset+i].modified) {
Auke Kokd37ea5d2006-06-27 09:08:17 -07008239 data[i] = hw->eeprom_shadow_ram[offset+i].eeprom_word;
8240 } else {
8241 /* The NVM part needs a byte offset, hence * 2 */
8242 act_offset = bank_offset + ((offset + i) * 2);
8243 error = e1000_read_ich8_word(hw, act_offset, &word);
8244 if (error != E1000_SUCCESS)
8245 break;
8246 data[i] = word;
8247 }
8248 }
8249
8250 e1000_release_software_flag(hw);
8251
8252 return error;
8253}
8254
8255/******************************************************************************
8256 * Writes a 16 bit word or words to the EEPROM using the ICH8's flash access
8257 * register. Actually, writes are written to the shadow ram cache in the hw
8258 * structure hw->e1000_shadow_ram. e1000_commit_shadow_ram flushes this to
8259 * the NVM, which occurs when the NVM checksum is updated.
8260 *
8261 * hw - Struct containing variables accessed by shared code
8262 * offset - offset of word in the EEPROM to write
8263 * words - number of words to write
8264 * data - words to write to the EEPROM
8265 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07008266static s32 e1000_write_eeprom_ich8(struct e1000_hw *hw, u16 offset, u16 words,
8267 u16 *data)
Auke Kokd37ea5d2006-06-27 09:08:17 -07008268{
Joe Perches406874a2008-04-03 10:06:32 -07008269 u32 i = 0;
8270 s32 error = E1000_SUCCESS;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008271
8272 error = e1000_get_software_flag(hw);
8273 if (error != E1000_SUCCESS)
8274 return error;
8275
8276 /* A driver can write to the NVM only if it has eeprom_shadow_ram
8277 * allocated. Subsequent reads to the modified words are read from
8278 * this cached structure as well. Writes will only go into this
8279 * cached structure unless it's followed by a call to
8280 * e1000_update_eeprom_checksum() where it will commit the changes
8281 * and clear the "modified" field.
8282 */
8283 if (hw->eeprom_shadow_ram != NULL) {
8284 for (i = 0; i < words; i++) {
8285 if ((offset + i) < E1000_SHADOW_RAM_WORDS) {
Joe Perchesc3033b02008-03-21 11:06:25 -07008286 hw->eeprom_shadow_ram[offset+i].modified = true;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008287 hw->eeprom_shadow_ram[offset+i].eeprom_word = data[i];
8288 } else {
8289 error = -E1000_ERR_EEPROM;
8290 break;
8291 }
8292 }
8293 } else {
8294 /* Drivers have the option to not allocate eeprom_shadow_ram as long
8295 * as they don't perform any NVM writes. An attempt in doing so
8296 * will result in this error.
8297 */
8298 error = -E1000_ERR_EEPROM;
8299 }
8300
8301 e1000_release_software_flag(hw);
8302
8303 return error;
8304}
8305
8306/******************************************************************************
8307 * This function does initial flash setup so that a new read/write/erase cycle
8308 * can be started.
8309 *
8310 * hw - The pointer to the hw structure
8311 ****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07008312static s32 e1000_ich8_cycle_init(struct e1000_hw *hw)
Auke Kokd37ea5d2006-06-27 09:08:17 -07008313{
8314 union ich8_hws_flash_status hsfsts;
Joe Perches406874a2008-04-03 10:06:32 -07008315 s32 error = E1000_ERR_EEPROM;
8316 s32 i = 0;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008317
8318 DEBUGFUNC("e1000_ich8_cycle_init");
8319
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008320 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008321
8322 /* May be check the Flash Des Valid bit in Hw status */
8323 if (hsfsts.hsf_status.fldesvalid == 0) {
8324 DEBUGOUT("Flash descriptor invalid. SW Sequencing must be used.");
8325 return error;
8326 }
8327
8328 /* Clear FCERR in Hw status by writing 1 */
8329 /* Clear DAEL in Hw status by writing a 1 */
8330 hsfsts.hsf_status.flcerr = 1;
8331 hsfsts.hsf_status.dael = 1;
8332
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008333 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS, hsfsts.regval);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008334
8335 /* Either we should have a hardware SPI cycle in progress bit to check
8336 * against, in order to start a new cycle or FDONE bit should be changed
8337 * in the hardware so that it is 1 after harware reset, which can then be
8338 * used as an indication whether a cycle is in progress or has been
8339 * completed .. we should also have some software semaphore mechanism to
8340 * guard FDONE or the cycle in progress bit so that two threads access to
8341 * those bits can be sequentiallized or a way so that 2 threads dont
8342 * start the cycle at the same time */
8343
8344 if (hsfsts.hsf_status.flcinprog == 0) {
8345 /* There is no cycle running at present, so we can start a cycle */
8346 /* Begin by setting Flash Cycle Done. */
8347 hsfsts.hsf_status.flcdone = 1;
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008348 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS, hsfsts.regval);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008349 error = E1000_SUCCESS;
8350 } else {
8351 /* otherwise poll for sometime so the current cycle has a chance
8352 * to end before giving up. */
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008353 for (i = 0; i < ICH_FLASH_COMMAND_TIMEOUT; i++) {
8354 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008355 if (hsfsts.hsf_status.flcinprog == 0) {
8356 error = E1000_SUCCESS;
8357 break;
8358 }
8359 udelay(1);
8360 }
8361 if (error == E1000_SUCCESS) {
8362 /* Successful in waiting for previous cycle to timeout,
8363 * now set the Flash Cycle Done. */
8364 hsfsts.hsf_status.flcdone = 1;
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008365 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS, hsfsts.regval);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008366 } else {
8367 DEBUGOUT("Flash controller busy, cannot get access");
8368 }
8369 }
8370 return error;
8371}
8372
8373/******************************************************************************
8374 * This function starts a flash cycle and waits for its completion
8375 *
8376 * hw - The pointer to the hw structure
8377 ****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07008378static s32 e1000_ich8_flash_cycle(struct e1000_hw *hw, u32 timeout)
Auke Kokd37ea5d2006-06-27 09:08:17 -07008379{
8380 union ich8_hws_flash_ctrl hsflctl;
8381 union ich8_hws_flash_status hsfsts;
Joe Perches406874a2008-04-03 10:06:32 -07008382 s32 error = E1000_ERR_EEPROM;
8383 u32 i = 0;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008384
8385 /* Start a cycle by writing 1 in Flash Cycle Go in Hw Flash Control */
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008386 hsflctl.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008387 hsflctl.hsf_ctrl.flcgo = 1;
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008388 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008389
8390 /* wait till FDONE bit is set to 1 */
8391 do {
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008392 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008393 if (hsfsts.hsf_status.flcdone == 1)
8394 break;
8395 udelay(1);
8396 i++;
8397 } while (i < timeout);
8398 if (hsfsts.hsf_status.flcdone == 1 && hsfsts.hsf_status.flcerr == 0) {
8399 error = E1000_SUCCESS;
8400 }
8401 return error;
8402}
8403
8404/******************************************************************************
8405 * Reads a byte or word from the NVM using the ICH8 flash access registers.
8406 *
8407 * hw - The pointer to the hw structure
8408 * index - The index of the byte or word to read.
8409 * size - Size of data to read, 1=byte 2=word
8410 * data - Pointer to the word to store the value read.
8411 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07008412static s32 e1000_read_ich8_data(struct e1000_hw *hw, u32 index, u32 size,
8413 u16 *data)
Auke Kokd37ea5d2006-06-27 09:08:17 -07008414{
8415 union ich8_hws_flash_status hsfsts;
8416 union ich8_hws_flash_ctrl hsflctl;
Joe Perches406874a2008-04-03 10:06:32 -07008417 u32 flash_linear_address;
8418 u32 flash_data = 0;
8419 s32 error = -E1000_ERR_EEPROM;
8420 s32 count = 0;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008421
8422 DEBUGFUNC("e1000_read_ich8_data");
8423
Stephen Hemmingerabec42a2007-10-29 10:46:19 -07008424 if (size < 1 || size > 2 || data == NULL ||
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008425 index > ICH_FLASH_LINEAR_ADDR_MASK)
Auke Kokd37ea5d2006-06-27 09:08:17 -07008426 return error;
8427
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008428 flash_linear_address = (ICH_FLASH_LINEAR_ADDR_MASK & index) +
Auke Kokd37ea5d2006-06-27 09:08:17 -07008429 hw->flash_base_addr;
8430
8431 do {
8432 udelay(1);
8433 /* Steps */
8434 error = e1000_ich8_cycle_init(hw);
8435 if (error != E1000_SUCCESS)
8436 break;
8437
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008438 hsflctl.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008439 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
8440 hsflctl.hsf_ctrl.fldbcount = size - 1;
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008441 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_READ;
8442 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008443
8444 /* Write the last 24 bits of index into Flash Linear address field in
8445 * Flash Address */
8446 /* TODO: TBD maybe check the index against the size of flash */
8447
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008448 E1000_WRITE_ICH_FLASH_REG(hw, ICH_FLASH_FADDR, flash_linear_address);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008449
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008450 error = e1000_ich8_flash_cycle(hw, ICH_FLASH_COMMAND_TIMEOUT);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008451
8452 /* Check if FCERR is set to 1, if set to 1, clear it and try the whole
8453 * sequence a few more times, else read in (shift in) the Flash Data0,
8454 * the order is least significant byte first msb to lsb */
8455 if (error == E1000_SUCCESS) {
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008456 flash_data = E1000_READ_ICH_FLASH_REG(hw, ICH_FLASH_FDATA0);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008457 if (size == 1) {
Joe Perches406874a2008-04-03 10:06:32 -07008458 *data = (u8)(flash_data & 0x000000FF);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008459 } else if (size == 2) {
Joe Perches406874a2008-04-03 10:06:32 -07008460 *data = (u16)(flash_data & 0x0000FFFF);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008461 }
8462 break;
8463 } else {
8464 /* If we've gotten here, then things are probably completely hosed,
8465 * but if the error condition is detected, it won't hurt to give
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008466 * it another try...ICH_FLASH_CYCLE_REPEAT_COUNT times.
Auke Kokd37ea5d2006-06-27 09:08:17 -07008467 */
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008468 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008469 if (hsfsts.hsf_status.flcerr == 1) {
8470 /* Repeat for some time before giving up. */
8471 continue;
8472 } else if (hsfsts.hsf_status.flcdone == 0) {
8473 DEBUGOUT("Timeout error - flash cycle did not complete.");
8474 break;
8475 }
8476 }
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008477 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008478
8479 return error;
8480}
8481
8482/******************************************************************************
8483 * Writes One /two bytes to the NVM using the ICH8 flash access registers.
8484 *
8485 * hw - The pointer to the hw structure
8486 * index - The index of the byte/word to read.
8487 * size - Size of data to read, 1=byte 2=word
8488 * data - The byte(s) to write to the NVM.
8489 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07008490static s32 e1000_write_ich8_data(struct e1000_hw *hw, u32 index, u32 size,
8491 u16 data)
Auke Kokd37ea5d2006-06-27 09:08:17 -07008492{
8493 union ich8_hws_flash_status hsfsts;
8494 union ich8_hws_flash_ctrl hsflctl;
Joe Perches406874a2008-04-03 10:06:32 -07008495 u32 flash_linear_address;
8496 u32 flash_data = 0;
8497 s32 error = -E1000_ERR_EEPROM;
8498 s32 count = 0;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008499
8500 DEBUGFUNC("e1000_write_ich8_data");
8501
8502 if (size < 1 || size > 2 || data > size * 0xff ||
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008503 index > ICH_FLASH_LINEAR_ADDR_MASK)
Auke Kokd37ea5d2006-06-27 09:08:17 -07008504 return error;
8505
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008506 flash_linear_address = (ICH_FLASH_LINEAR_ADDR_MASK & index) +
Auke Kokd37ea5d2006-06-27 09:08:17 -07008507 hw->flash_base_addr;
8508
8509 do {
8510 udelay(1);
8511 /* Steps */
8512 error = e1000_ich8_cycle_init(hw);
8513 if (error != E1000_SUCCESS)
8514 break;
8515
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008516 hsflctl.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008517 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
8518 hsflctl.hsf_ctrl.fldbcount = size -1;
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008519 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_WRITE;
8520 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008521
8522 /* Write the last 24 bits of index into Flash Linear address field in
8523 * Flash Address */
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008524 E1000_WRITE_ICH_FLASH_REG(hw, ICH_FLASH_FADDR, flash_linear_address);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008525
8526 if (size == 1)
Joe Perches406874a2008-04-03 10:06:32 -07008527 flash_data = (u32)data & 0x00FF;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008528 else
Joe Perches406874a2008-04-03 10:06:32 -07008529 flash_data = (u32)data;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008530
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008531 E1000_WRITE_ICH_FLASH_REG(hw, ICH_FLASH_FDATA0, flash_data);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008532
8533 /* check if FCERR is set to 1 , if set to 1, clear it and try the whole
8534 * sequence a few more times else done */
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008535 error = e1000_ich8_flash_cycle(hw, ICH_FLASH_COMMAND_TIMEOUT);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008536 if (error == E1000_SUCCESS) {
8537 break;
8538 } else {
8539 /* If we're here, then things are most likely completely hosed,
8540 * but if the error condition is detected, it won't hurt to give
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008541 * it another try...ICH_FLASH_CYCLE_REPEAT_COUNT times.
Auke Kokd37ea5d2006-06-27 09:08:17 -07008542 */
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008543 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008544 if (hsfsts.hsf_status.flcerr == 1) {
8545 /* Repeat for some time before giving up. */
8546 continue;
8547 } else if (hsfsts.hsf_status.flcdone == 0) {
8548 DEBUGOUT("Timeout error - flash cycle did not complete.");
8549 break;
8550 }
8551 }
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008552 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008553
8554 return error;
8555}
8556
8557/******************************************************************************
8558 * Reads a single byte from the NVM using the ICH8 flash access registers.
8559 *
8560 * hw - pointer to e1000_hw structure
8561 * index - The index of the byte to read.
8562 * data - Pointer to a byte to store the value read.
8563 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07008564static s32 e1000_read_ich8_byte(struct e1000_hw *hw, u32 index, u8 *data)
Auke Kokd37ea5d2006-06-27 09:08:17 -07008565{
Joe Perches406874a2008-04-03 10:06:32 -07008566 s32 status = E1000_SUCCESS;
8567 u16 word = 0;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008568
8569 status = e1000_read_ich8_data(hw, index, 1, &word);
8570 if (status == E1000_SUCCESS) {
Joe Perches406874a2008-04-03 10:06:32 -07008571 *data = (u8)word;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008572 }
8573
8574 return status;
8575}
8576
8577/******************************************************************************
8578 * Writes a single byte to the NVM using the ICH8 flash access registers.
8579 * Performs verification by reading back the value and then going through
8580 * a retry algorithm before giving up.
8581 *
8582 * hw - pointer to e1000_hw structure
8583 * index - The index of the byte to write.
8584 * byte - The byte to write to the NVM.
8585 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07008586static s32 e1000_verify_write_ich8_byte(struct e1000_hw *hw, u32 index, u8 byte)
Auke Kokd37ea5d2006-06-27 09:08:17 -07008587{
Joe Perches406874a2008-04-03 10:06:32 -07008588 s32 error = E1000_SUCCESS;
8589 s32 program_retries = 0;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008590
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008591 DEBUGOUT2("Byte := %2.2X Offset := %d\n", byte, index);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008592
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008593 error = e1000_write_ich8_byte(hw, index, byte);
8594
8595 if (error != E1000_SUCCESS) {
8596 for (program_retries = 0; program_retries < 100; program_retries++) {
8597 DEBUGOUT2("Retrying \t Byte := %2.2X Offset := %d\n", byte, index);
8598 error = e1000_write_ich8_byte(hw, index, byte);
8599 udelay(100);
8600 if (error == E1000_SUCCESS)
8601 break;
8602 }
Auke Kokd37ea5d2006-06-27 09:08:17 -07008603 }
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008604
Auke Kokd37ea5d2006-06-27 09:08:17 -07008605 if (program_retries == 100)
8606 error = E1000_ERR_EEPROM;
8607
8608 return error;
8609}
8610
8611/******************************************************************************
8612 * Writes a single byte to the NVM using the ICH8 flash access registers.
8613 *
8614 * hw - pointer to e1000_hw structure
8615 * index - The index of the byte to read.
8616 * data - The byte to write to the NVM.
8617 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07008618static s32 e1000_write_ich8_byte(struct e1000_hw *hw, u32 index, u8 data)
Auke Kokd37ea5d2006-06-27 09:08:17 -07008619{
Joe Perches406874a2008-04-03 10:06:32 -07008620 s32 status = E1000_SUCCESS;
8621 u16 word = (u16)data;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008622
8623 status = e1000_write_ich8_data(hw, index, 1, word);
8624
8625 return status;
8626}
8627
8628/******************************************************************************
8629 * Reads a word from the NVM using the ICH8 flash access registers.
8630 *
8631 * hw - pointer to e1000_hw structure
8632 * index - The starting byte index of the word to read.
8633 * data - Pointer to a word to store the value read.
8634 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07008635static s32 e1000_read_ich8_word(struct e1000_hw *hw, u32 index, u16 *data)
Auke Kokd37ea5d2006-06-27 09:08:17 -07008636{
Joe Perches406874a2008-04-03 10:06:32 -07008637 s32 status = E1000_SUCCESS;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008638 status = e1000_read_ich8_data(hw, index, 2, data);
8639 return status;
8640}
8641
8642/******************************************************************************
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008643 * Erases the bank specified. Each bank may be a 4, 8 or 64k block. Banks are 0
8644 * based.
Auke Kokd37ea5d2006-06-27 09:08:17 -07008645 *
8646 * hw - pointer to e1000_hw structure
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008647 * bank - 0 for first bank, 1 for second bank
8648 *
8649 * Note that this function may actually erase as much as 8 or 64 KBytes. The
8650 * amount of NVM used in each bank is a *minimum* of 4 KBytes, but in fact the
8651 * bank size may be 4, 8 or 64 KBytes
Auke Kokd37ea5d2006-06-27 09:08:17 -07008652 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07008653static s32 e1000_erase_ich8_4k_segment(struct e1000_hw *hw, u32 bank)
Auke Kokd37ea5d2006-06-27 09:08:17 -07008654{
8655 union ich8_hws_flash_status hsfsts;
8656 union ich8_hws_flash_ctrl hsflctl;
Joe Perches406874a2008-04-03 10:06:32 -07008657 u32 flash_linear_address;
8658 s32 count = 0;
8659 s32 error = E1000_ERR_EEPROM;
8660 s32 iteration;
8661 s32 sub_sector_size = 0;
8662 s32 bank_size;
8663 s32 j = 0;
8664 s32 error_flag = 0;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008665
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008666 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008667
8668 /* Determine HW Sector size: Read BERASE bits of Hw flash Status register */
8669 /* 00: The Hw sector is 256 bytes, hence we need to erase 16
8670 * consecutive sectors. The start index for the nth Hw sector can be
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008671 * calculated as bank * 4096 + n * 256
Auke Kokd37ea5d2006-06-27 09:08:17 -07008672 * 01: The Hw sector is 4K bytes, hence we need to erase 1 sector.
8673 * The start index for the nth Hw sector can be calculated
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008674 * as bank * 4096
8675 * 10: The HW sector is 8K bytes
8676 * 11: The Hw sector size is 64K bytes */
Auke Kokd37ea5d2006-06-27 09:08:17 -07008677 if (hsfsts.hsf_status.berasesz == 0x0) {
8678 /* Hw sector size 256 */
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008679 sub_sector_size = ICH_FLASH_SEG_SIZE_256;
8680 bank_size = ICH_FLASH_SECTOR_SIZE;
8681 iteration = ICH_FLASH_SECTOR_SIZE / ICH_FLASH_SEG_SIZE_256;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008682 } else if (hsfsts.hsf_status.berasesz == 0x1) {
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008683 bank_size = ICH_FLASH_SEG_SIZE_4K;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008684 iteration = 1;
8685 } else if (hsfsts.hsf_status.berasesz == 0x3) {
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008686 bank_size = ICH_FLASH_SEG_SIZE_64K;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008687 iteration = 1;
8688 } else {
8689 return error;
8690 }
8691
8692 for (j = 0; j < iteration ; j++) {
8693 do {
8694 count++;
8695 /* Steps */
8696 error = e1000_ich8_cycle_init(hw);
8697 if (error != E1000_SUCCESS) {
8698 error_flag = 1;
8699 break;
8700 }
8701
8702 /* Write a value 11 (block Erase) in Flash Cycle field in Hw flash
8703 * Control */
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008704 hsflctl.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL);
8705 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_ERASE;
8706 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008707
8708 /* Write the last 24 bits of an index within the block into Flash
8709 * Linear address field in Flash Address. This probably needs to
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008710 * be calculated here based off the on-chip erase sector size and
8711 * the software bank size (4, 8 or 64 KBytes) */
8712 flash_linear_address = bank * bank_size + j * sub_sector_size;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008713 flash_linear_address += hw->flash_base_addr;
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008714 flash_linear_address &= ICH_FLASH_LINEAR_ADDR_MASK;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008715
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008716 E1000_WRITE_ICH_FLASH_REG(hw, ICH_FLASH_FADDR, flash_linear_address);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008717
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008718 error = e1000_ich8_flash_cycle(hw, ICH_FLASH_ERASE_TIMEOUT);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008719 /* Check if FCERR is set to 1. If 1, clear it and try the whole
8720 * sequence a few more times else Done */
8721 if (error == E1000_SUCCESS) {
8722 break;
8723 } else {
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008724 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008725 if (hsfsts.hsf_status.flcerr == 1) {
8726 /* repeat for some time before giving up */
8727 continue;
8728 } else if (hsfsts.hsf_status.flcdone == 0) {
8729 error_flag = 1;
8730 break;
8731 }
8732 }
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008733 } while ((count < ICH_FLASH_CYCLE_REPEAT_COUNT) && !error_flag);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008734 if (error_flag == 1)
8735 break;
8736 }
8737 if (error_flag != 1)
8738 error = E1000_SUCCESS;
8739 return error;
8740}
8741
Joe Perches64798842008-07-11 15:17:02 -07008742static s32 e1000_init_lcd_from_nvm_config_region(struct e1000_hw *hw,
8743 u32 cnf_base_addr,
8744 u32 cnf_size)
Auke Kokd37ea5d2006-06-27 09:08:17 -07008745{
Joe Perches406874a2008-04-03 10:06:32 -07008746 u32 ret_val = E1000_SUCCESS;
8747 u16 word_addr, reg_data, reg_addr;
8748 u16 i;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008749
8750 /* cnf_base_addr is in DWORD */
Joe Perches406874a2008-04-03 10:06:32 -07008751 word_addr = (u16)(cnf_base_addr << 1);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008752
8753 /* cnf_size is returned in size of dwords */
8754 for (i = 0; i < cnf_size; i++) {
8755 ret_val = e1000_read_eeprom(hw, (word_addr + i*2), 1, &reg_data);
8756 if (ret_val)
8757 return ret_val;
8758
8759 ret_val = e1000_read_eeprom(hw, (word_addr + i*2 + 1), 1, &reg_addr);
8760 if (ret_val)
8761 return ret_val;
8762
8763 ret_val = e1000_get_software_flag(hw);
8764 if (ret_val != E1000_SUCCESS)
8765 return ret_val;
8766
Joe Perches406874a2008-04-03 10:06:32 -07008767 ret_val = e1000_write_phy_reg_ex(hw, (u32)reg_addr, reg_data);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008768
8769 e1000_release_software_flag(hw);
8770 }
8771
8772 return ret_val;
8773}
8774
8775
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008776/******************************************************************************
8777 * This function initializes the PHY from the NVM on ICH8 platforms. This
8778 * is needed due to an issue where the NVM configuration is not properly
8779 * autoloaded after power transitions. Therefore, after each PHY reset, we
8780 * will load the configuration data out of the NVM manually.
8781 *
8782 * hw: Struct containing variables accessed by shared code
8783 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07008784static s32 e1000_init_lcd_from_nvm(struct e1000_hw *hw)
Auke Kokd37ea5d2006-06-27 09:08:17 -07008785{
Joe Perches406874a2008-04-03 10:06:32 -07008786 u32 reg_data, cnf_base_addr, cnf_size, ret_val, loop;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008787
8788 if (hw->phy_type != e1000_phy_igp_3)
8789 return E1000_SUCCESS;
8790
8791 /* Check if SW needs configure the PHY */
Joe Perches1dc32912008-07-11 15:17:08 -07008792 reg_data = er32(FEXTNVM);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008793 if (!(reg_data & FEXTNVM_SW_CONFIG))
8794 return E1000_SUCCESS;
8795
8796 /* Wait for basic configuration completes before proceeding*/
8797 loop = 0;
8798 do {
Joe Perches1dc32912008-07-11 15:17:08 -07008799 reg_data = er32(STATUS) & E1000_STATUS_LAN_INIT_DONE;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008800 udelay(100);
8801 loop++;
8802 } while ((!reg_data) && (loop < 50));
8803
8804 /* Clear the Init Done bit for the next init event */
Joe Perches1dc32912008-07-11 15:17:08 -07008805 reg_data = er32(STATUS);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008806 reg_data &= ~E1000_STATUS_LAN_INIT_DONE;
Joe Perches1dc32912008-07-11 15:17:08 -07008807 ew32(STATUS, reg_data);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008808
8809 /* Make sure HW does not configure LCD from PHY extended configuration
8810 before SW configuration */
Joe Perches1dc32912008-07-11 15:17:08 -07008811 reg_data = er32(EXTCNF_CTRL);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008812 if ((reg_data & E1000_EXTCNF_CTRL_LCD_WRITE_ENABLE) == 0x0000) {
Joe Perches1dc32912008-07-11 15:17:08 -07008813 reg_data = er32(EXTCNF_SIZE);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008814 cnf_size = reg_data & E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH;
8815 cnf_size >>= 16;
8816 if (cnf_size) {
Joe Perches1dc32912008-07-11 15:17:08 -07008817 reg_data = er32(EXTCNF_CTRL);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008818 cnf_base_addr = reg_data & E1000_EXTCNF_CTRL_EXT_CNF_POINTER;
8819 /* cnf_base_addr is in DWORD */
8820 cnf_base_addr >>= 16;
8821
8822 /* Configure LCD from extended configuration region. */
8823 ret_val = e1000_init_lcd_from_nvm_config_region(hw, cnf_base_addr,
8824 cnf_size);
8825 if (ret_val)
8826 return ret_val;
8827 }
8828 }
8829
8830 return E1000_SUCCESS;
8831}
8832