blob: 765fd71ad5f24d101205fb0edb5e71eda38a5c0b [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_check_downshift(struct e1000_hw *hw);
Joe Perches64798842008-07-11 15:17:02 -070037static s32 e1000_check_polarity(struct e1000_hw *hw,
38 e1000_rev_polarity *polarity);
Nicholas Nunley35574762006-09-27 12:53:34 -070039static void e1000_clear_hw_cntrs(struct e1000_hw *hw);
40static void e1000_clear_vfta(struct e1000_hw *hw);
Joe Perches406874a2008-04-03 10:06:32 -070041static s32 e1000_config_dsp_after_link_change(struct e1000_hw *hw,
Joe Perches64798842008-07-11 15:17:02 -070042 bool link_up);
Joe Perches406874a2008-04-03 10:06:32 -070043static s32 e1000_config_fc_after_link_up(struct e1000_hw *hw);
44static s32 e1000_detect_gig_phy(struct e1000_hw *hw);
Joe Perches406874a2008-04-03 10:06:32 -070045static s32 e1000_get_auto_rd_done(struct e1000_hw *hw);
Joe Perches64798842008-07-11 15:17:02 -070046static s32 e1000_get_cable_length(struct e1000_hw *hw, u16 *min_length,
47 u16 *max_length);
Joe Perches406874a2008-04-03 10:06:32 -070048static s32 e1000_get_phy_cfg_done(struct e1000_hw *hw);
Joe Perches406874a2008-04-03 10:06:32 -070049static s32 e1000_id_led_init(struct e1000_hw *hw);
Nicholas Nunley35574762006-09-27 12:53:34 -070050static void e1000_init_rx_addrs(struct e1000_hw *hw);
Joe Perches64798842008-07-11 15:17:02 -070051static s32 e1000_phy_igp_get_info(struct e1000_hw *hw,
52 struct e1000_phy_info *phy_info);
53static s32 e1000_read_eeprom_eerd(struct e1000_hw *hw, u16 offset, u16 words,
54 u16 *data);
55static s32 e1000_write_eeprom_eewr(struct e1000_hw *hw, u16 offset, u16 words,
56 u16 *data);
Joe Perches406874a2008-04-03 10:06:32 -070057static s32 e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd);
Joe Perches64798842008-07-11 15:17:02 -070058static s32 e1000_phy_m88_get_info(struct e1000_hw *hw,
59 struct e1000_phy_info *phy_info);
Joe Perches406874a2008-04-03 10:06:32 -070060static s32 e1000_set_d3_lplu_state(struct e1000_hw *hw, bool active);
Joe Perches406874a2008-04-03 10:06:32 -070061static s32 e1000_wait_autoneg(struct e1000_hw *hw);
62static void e1000_write_reg_io(struct e1000_hw *hw, u32 offset, u32 value);
63static s32 e1000_set_phy_type(struct e1000_hw *hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064static void e1000_phy_init_script(struct e1000_hw *hw);
Joe Perches406874a2008-04-03 10:06:32 -070065static s32 e1000_setup_copper_link(struct e1000_hw *hw);
66static s32 e1000_setup_fiber_serdes_link(struct e1000_hw *hw);
67static s32 e1000_adjust_serdes_amplitude(struct e1000_hw *hw);
68static s32 e1000_phy_force_speed_duplex(struct e1000_hw *hw);
69static s32 e1000_config_mac_to_phy(struct e1000_hw *hw);
70static void e1000_raise_mdi_clk(struct e1000_hw *hw, u32 *ctrl);
71static void e1000_lower_mdi_clk(struct e1000_hw *hw, u32 *ctrl);
72static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, u32 data,
Joe Perches64798842008-07-11 15:17:02 -070073 u16 count);
Joe Perches406874a2008-04-03 10:06:32 -070074static u16 e1000_shift_in_mdi_bits(struct e1000_hw *hw);
75static s32 e1000_phy_reset_dsp(struct e1000_hw *hw);
76static s32 e1000_write_eeprom_spi(struct e1000_hw *hw, u16 offset,
77 u16 words, u16 *data);
Joe Perches64798842008-07-11 15:17:02 -070078static s32 e1000_write_eeprom_microwire(struct e1000_hw *hw, u16 offset,
79 u16 words, u16 *data);
Joe Perches406874a2008-04-03 10:06:32 -070080static s32 e1000_spi_eeprom_ready(struct e1000_hw *hw);
81static void e1000_raise_ee_clk(struct e1000_hw *hw, u32 *eecd);
82static void e1000_lower_ee_clk(struct e1000_hw *hw, u32 *eecd);
Joe Perches64798842008-07-11 15:17:02 -070083static void e1000_shift_out_ee_bits(struct e1000_hw *hw, u16 data, u16 count);
Joe Perches406874a2008-04-03 10:06:32 -070084static s32 e1000_write_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr,
Joe Perches64798842008-07-11 15:17:02 -070085 u16 phy_data);
Joe Perches406874a2008-04-03 10:06:32 -070086static s32 e1000_read_phy_reg_ex(struct e1000_hw *hw,u32 reg_addr,
Joe Perches64798842008-07-11 15:17:02 -070087 u16 *phy_data);
Joe Perches406874a2008-04-03 10:06:32 -070088static u16 e1000_shift_in_ee_bits(struct e1000_hw *hw, u16 count);
89static s32 e1000_acquire_eeprom(struct e1000_hw *hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090static void e1000_release_eeprom(struct e1000_hw *hw);
91static void e1000_standby_eeprom(struct e1000_hw *hw);
Joe Perches406874a2008-04-03 10:06:32 -070092static s32 e1000_set_vco_speed(struct e1000_hw *hw);
93static s32 e1000_polarity_reversal_workaround(struct e1000_hw *hw);
94static s32 e1000_set_phy_mode(struct e1000_hw *hw);
Christopher Li78566fe2008-09-05 14:04:05 -070095static s32 e1000_do_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data);
96static s32 e1000_do_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
98/* IGP cable length table */
99static const
Joe Perches406874a2008-04-03 10:06:32 -0700100u16 e1000_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
102 5, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 25, 25, 25,
103 25, 25, 25, 25, 30, 30, 30, 30, 40, 40, 40, 40, 40, 40, 40, 40,
104 40, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60,
105 60, 70, 70, 70, 70, 70, 70, 80, 80, 80, 80, 80, 80, 90, 90, 90,
106 90, 90, 90, 90, 90, 90, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
107 100, 100, 100, 100, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,
108 110, 110, 110, 110, 110, 110, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120};
109
Christopher Li78566fe2008-09-05 14:04:05 -0700110static DEFINE_SPINLOCK(e1000_eeprom_lock);
111
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112/******************************************************************************
113 * Set the phy type member in the hw struct.
114 *
115 * hw - Struct containing variables accessed by shared code
116 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -0700117static s32 e1000_set_phy_type(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118{
119 DEBUGFUNC("e1000_set_phy_type");
120
Auke Kok8fc897b2006-08-28 14:56:16 -0700121 if (hw->mac_type == e1000_undefined)
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700122 return -E1000_ERR_PHY_TYPE;
123
Auke Kok8fc897b2006-08-28 14:56:16 -0700124 switch (hw->phy_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 case M88E1000_E_PHY_ID:
126 case M88E1000_I_PHY_ID:
127 case M88E1011_I_PHY_ID:
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700128 case M88E1111_I_PHY_ID:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 hw->phy_type = e1000_phy_m88;
130 break;
131 case IGP01E1000_I_PHY_ID:
Auke Kok8fc897b2006-08-28 14:56:16 -0700132 if (hw->mac_type == e1000_82541 ||
133 hw->mac_type == e1000_82541_rev_2 ||
134 hw->mac_type == e1000_82547 ||
135 hw->mac_type == e1000_82547_rev_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 hw->phy_type = e1000_phy_igp;
137 break;
138 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 default:
140 /* Should never have loaded on this device */
141 hw->phy_type = e1000_phy_undefined;
142 return -E1000_ERR_PHY_TYPE;
143 }
144
145 return E1000_SUCCESS;
146}
147
148/******************************************************************************
149 * IGP phy init script - initializes the GbE PHY
150 *
151 * hw - Struct containing variables accessed by shared code
152 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -0700153static void e1000_phy_init_script(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154{
Joe Perches406874a2008-04-03 10:06:32 -0700155 u32 ret_val;
156 u16 phy_saved_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
158 DEBUGFUNC("e1000_phy_init_script");
159
Auke Kok8fc897b2006-08-28 14:56:16 -0700160 if (hw->phy_init_script) {
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400161 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
163 /* Save off the current value of register 0x2F5B to be restored at
164 * the end of this routine. */
165 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
166
167 /* Disabled the PHY transmitter */
168 e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
169
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400170 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
172 e1000_write_phy_reg(hw,0x0000,0x0140);
173
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400174 msleep(5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175
Auke Kok8fc897b2006-08-28 14:56:16 -0700176 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 case e1000_82541:
178 case e1000_82547:
179 e1000_write_phy_reg(hw, 0x1F95, 0x0001);
180
181 e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
182
183 e1000_write_phy_reg(hw, 0x1F79, 0x0018);
184
185 e1000_write_phy_reg(hw, 0x1F30, 0x1600);
186
187 e1000_write_phy_reg(hw, 0x1F31, 0x0014);
188
189 e1000_write_phy_reg(hw, 0x1F32, 0x161C);
190
191 e1000_write_phy_reg(hw, 0x1F94, 0x0003);
192
193 e1000_write_phy_reg(hw, 0x1F96, 0x003F);
194
195 e1000_write_phy_reg(hw, 0x2010, 0x0008);
196 break;
197
198 case e1000_82541_rev_2:
199 case e1000_82547_rev_2:
200 e1000_write_phy_reg(hw, 0x1F73, 0x0099);
201 break;
202 default:
203 break;
204 }
205
206 e1000_write_phy_reg(hw, 0x0000, 0x3300);
207
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400208 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
210 /* Now enable the transmitter */
211 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
212
Auke Kok8fc897b2006-08-28 14:56:16 -0700213 if (hw->mac_type == e1000_82547) {
Joe Perches406874a2008-04-03 10:06:32 -0700214 u16 fused, fine, coarse;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
216 /* Move to analog registers page */
217 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_SPARE_FUSE_STATUS, &fused);
218
Auke Kok8fc897b2006-08-28 14:56:16 -0700219 if (!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_FUSE_STATUS, &fused);
221
222 fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
223 coarse = fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
224
Auke Kok8fc897b2006-08-28 14:56:16 -0700225 if (coarse > IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 coarse -= IGP01E1000_ANALOG_FUSE_COARSE_10;
227 fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
Auke Kok8fc897b2006-08-28 14:56:16 -0700228 } else if (coarse == IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
230
231 fused = (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
232 (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
233 (coarse & IGP01E1000_ANALOG_FUSE_COARSE_MASK);
234
235 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_CONTROL, fused);
236 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_BYPASS,
237 IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
238 }
239 }
240 }
241}
242
243/******************************************************************************
244 * Set the mac type member in the hw struct.
245 *
246 * hw - Struct containing variables accessed by shared code
247 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -0700248s32 e1000_set_mac_type(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249{
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500250 DEBUGFUNC("e1000_set_mac_type");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500252 switch (hw->device_id) {
253 case E1000_DEV_ID_82542:
254 switch (hw->revision_id) {
255 case E1000_82542_2_0_REV_ID:
256 hw->mac_type = e1000_82542_rev2_0;
257 break;
258 case E1000_82542_2_1_REV_ID:
259 hw->mac_type = e1000_82542_rev2_1;
260 break;
261 default:
262 /* Invalid 82542 revision ID */
263 return -E1000_ERR_MAC_TYPE;
264 }
265 break;
266 case E1000_DEV_ID_82543GC_FIBER:
267 case E1000_DEV_ID_82543GC_COPPER:
268 hw->mac_type = e1000_82543;
269 break;
270 case E1000_DEV_ID_82544EI_COPPER:
271 case E1000_DEV_ID_82544EI_FIBER:
272 case E1000_DEV_ID_82544GC_COPPER:
273 case E1000_DEV_ID_82544GC_LOM:
274 hw->mac_type = e1000_82544;
275 break;
276 case E1000_DEV_ID_82540EM:
277 case E1000_DEV_ID_82540EM_LOM:
278 case E1000_DEV_ID_82540EP:
279 case E1000_DEV_ID_82540EP_LOM:
280 case E1000_DEV_ID_82540EP_LP:
281 hw->mac_type = e1000_82540;
282 break;
283 case E1000_DEV_ID_82545EM_COPPER:
284 case E1000_DEV_ID_82545EM_FIBER:
285 hw->mac_type = e1000_82545;
286 break;
287 case E1000_DEV_ID_82545GM_COPPER:
288 case E1000_DEV_ID_82545GM_FIBER:
289 case E1000_DEV_ID_82545GM_SERDES:
290 hw->mac_type = e1000_82545_rev_3;
291 break;
292 case E1000_DEV_ID_82546EB_COPPER:
293 case E1000_DEV_ID_82546EB_FIBER:
294 case E1000_DEV_ID_82546EB_QUAD_COPPER:
295 hw->mac_type = e1000_82546;
296 break;
297 case E1000_DEV_ID_82546GB_COPPER:
298 case E1000_DEV_ID_82546GB_FIBER:
299 case E1000_DEV_ID_82546GB_SERDES:
300 case E1000_DEV_ID_82546GB_PCIE:
301 case E1000_DEV_ID_82546GB_QUAD_COPPER:
302 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
303 hw->mac_type = e1000_82546_rev_3;
304 break;
305 case E1000_DEV_ID_82541EI:
306 case E1000_DEV_ID_82541EI_MOBILE:
307 case E1000_DEV_ID_82541ER_LOM:
308 hw->mac_type = e1000_82541;
309 break;
310 case E1000_DEV_ID_82541ER:
311 case E1000_DEV_ID_82541GI:
312 case E1000_DEV_ID_82541GI_LF:
313 case E1000_DEV_ID_82541GI_MOBILE:
314 hw->mac_type = e1000_82541_rev_2;
315 break;
316 case E1000_DEV_ID_82547EI:
317 case E1000_DEV_ID_82547EI_MOBILE:
318 hw->mac_type = e1000_82547;
319 break;
320 case E1000_DEV_ID_82547GI:
321 hw->mac_type = e1000_82547_rev_2;
322 break;
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500323 default:
324 /* Should never have loaded on this device */
325 return -E1000_ERR_MAC_TYPE;
326 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500328 switch (hw->mac_type) {
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500329 case e1000_82541:
330 case e1000_82547:
331 case e1000_82541_rev_2:
332 case e1000_82547_rev_2:
Joe Perchesc3033b02008-03-21 11:06:25 -0700333 hw->asf_firmware_present = true;
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500334 break;
335 default:
336 break;
337 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338
Jeff Garzik167fb282006-12-15 10:41:15 -0500339 /* The 82543 chip does not count tx_carrier_errors properly in
340 * FD mode
341 */
342 if (hw->mac_type == e1000_82543)
Joe Perchesc3033b02008-03-21 11:06:25 -0700343 hw->bad_tx_carr_stats_fd = true;
Jeff Garzik167fb282006-12-15 10:41:15 -0500344
Jeff Garzik15e376b2006-12-15 11:16:33 -0500345 if (hw->mac_type > e1000_82544)
Joe Perchesc3033b02008-03-21 11:06:25 -0700346 hw->has_smbus = true;
Jeff Garzik15e376b2006-12-15 11:16:33 -0500347
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500348 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349}
350
351/*****************************************************************************
352 * Set media type and TBI compatibility.
353 *
354 * hw - Struct containing variables accessed by shared code
355 * **************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -0700356void e1000_set_media_type(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357{
Joe Perches406874a2008-04-03 10:06:32 -0700358 u32 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
360 DEBUGFUNC("e1000_set_media_type");
361
Auke Kok8fc897b2006-08-28 14:56:16 -0700362 if (hw->mac_type != e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 /* tbi_compatibility is only valid on 82543 */
Joe Perchesc3033b02008-03-21 11:06:25 -0700364 hw->tbi_compatibility_en = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 }
366
367 switch (hw->device_id) {
368 case E1000_DEV_ID_82545GM_SERDES:
369 case E1000_DEV_ID_82546GB_SERDES:
370 hw->media_type = e1000_media_type_internal_serdes;
371 break;
372 default:
Malli Chilakala3893d542005-06-17 17:44:49 -0700373 switch (hw->mac_type) {
374 case e1000_82542_rev2_0:
375 case e1000_82542_rev2_1:
376 hw->media_type = e1000_media_type_fiber;
377 break;
Malli Chilakala3893d542005-06-17 17:44:49 -0700378 default:
Joe Perches1dc32912008-07-11 15:17:08 -0700379 status = er32(STATUS);
Malli Chilakala3893d542005-06-17 17:44:49 -0700380 if (status & E1000_STATUS_TBIMODE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 hw->media_type = e1000_media_type_fiber;
382 /* tbi_compatibility not valid on fiber */
Joe Perchesc3033b02008-03-21 11:06:25 -0700383 hw->tbi_compatibility_en = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 } else {
385 hw->media_type = e1000_media_type_copper;
386 }
Malli Chilakala3893d542005-06-17 17:44:49 -0700387 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 }
389 }
390}
391
392/******************************************************************************
393 * Reset the transmit and receive units; mask and clear all interrupts.
394 *
395 * hw - Struct containing variables accessed by shared code
396 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -0700397s32 e1000_reset_hw(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398{
Joe Perches406874a2008-04-03 10:06:32 -0700399 u32 ctrl;
400 u32 ctrl_ext;
401 u32 icr;
402 u32 manc;
403 u32 led_ctrl;
Joe Perches406874a2008-04-03 10:06:32 -0700404 s32 ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
406 DEBUGFUNC("e1000_reset_hw");
407
408 /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
Auke Kok8fc897b2006-08-28 14:56:16 -0700409 if (hw->mac_type == e1000_82542_rev2_0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
411 e1000_pci_clear_mwi(hw);
412 }
413
414 /* Clear interrupt mask to stop board from generating interrupts */
415 DEBUGOUT("Masking off all interrupts\n");
Joe Perches1dc32912008-07-11 15:17:08 -0700416 ew32(IMC, 0xffffffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417
418 /* Disable the Transmit and Receive units. Then delay to allow
419 * any pending transactions to complete before we hit the MAC with
420 * the global reset.
421 */
Joe Perches1dc32912008-07-11 15:17:08 -0700422 ew32(RCTL, 0);
423 ew32(TCTL, E1000_TCTL_PSP);
424 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425
426 /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
Joe Perchesc3033b02008-03-21 11:06:25 -0700427 hw->tbi_compatibility_on = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428
429 /* Delay to allow any outstanding PCI transactions to complete before
430 * resetting the device
431 */
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400432 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433
Joe Perches1dc32912008-07-11 15:17:08 -0700434 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435
436 /* Must reset the PHY before resetting the MAC */
Auke Kok8fc897b2006-08-28 14:56:16 -0700437 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
Joe Perches1dc32912008-07-11 15:17:08 -0700438 ew32(CTRL, (ctrl | E1000_CTRL_PHY_RST));
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400439 msleep(5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 }
441
442 /* Issue a global reset to the MAC. This will reset the chip's
443 * transmit, receive, DMA, and link units. It will not effect
444 * the current PCI configuration. The global reset bit is self-
445 * clearing, and should clear within a microsecond.
446 */
447 DEBUGOUT("Issuing a global reset to MAC\n");
448
Auke Kok8fc897b2006-08-28 14:56:16 -0700449 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 case e1000_82544:
451 case e1000_82540:
452 case e1000_82545:
453 case e1000_82546:
454 case e1000_82541:
455 case e1000_82541_rev_2:
456 /* These controllers can't ack the 64-bit write when issuing the
457 * reset, so use IO-mapping as a workaround to issue the reset */
458 E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
459 break;
460 case e1000_82545_rev_3:
461 case e1000_82546_rev_3:
462 /* Reset is performed on a shadow of the control register */
Joe Perches1dc32912008-07-11 15:17:08 -0700463 ew32(CTRL_DUP, (ctrl | E1000_CTRL_RST));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 break;
465 default:
Joe Perches1dc32912008-07-11 15:17:08 -0700466 ew32(CTRL, (ctrl | E1000_CTRL_RST));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 break;
468 }
469
470 /* After MAC reset, force reload of EEPROM to restore power-on settings to
471 * device. Later controllers reload the EEPROM automatically, so just wait
472 * for reload to complete.
473 */
Auke Kok8fc897b2006-08-28 14:56:16 -0700474 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 case e1000_82542_rev2_0:
476 case e1000_82542_rev2_1:
477 case e1000_82543:
478 case e1000_82544:
479 /* Wait for reset to complete */
480 udelay(10);
Joe Perches1dc32912008-07-11 15:17:08 -0700481 ctrl_ext = er32(CTRL_EXT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
Joe Perches1dc32912008-07-11 15:17:08 -0700483 ew32(CTRL_EXT, ctrl_ext);
484 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 /* Wait for EEPROM reload */
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400486 msleep(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 break;
488 case e1000_82541:
489 case e1000_82541_rev_2:
490 case e1000_82547:
491 case e1000_82547_rev_2:
492 /* Wait for EEPROM reload */
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400493 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 break;
Jeff Kirsher2a88c172006-09-27 12:54:05 -0700495 default:
496 /* Auto read done will delay 5ms or poll based on mac type */
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700497 ret_val = e1000_get_auto_rd_done(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -0700498 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700499 return ret_val;
500 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 }
502
503 /* Disable HW ARPs on ASF enabled adapters */
Jesse Brandeburg1532ece2009-09-25 12:16:14 +0000504 if (hw->mac_type >= e1000_82540) {
Joe Perches1dc32912008-07-11 15:17:08 -0700505 manc = er32(MANC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 manc &= ~(E1000_MANC_ARP_EN);
Joe Perches1dc32912008-07-11 15:17:08 -0700507 ew32(MANC, manc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 }
509
Auke Kok8fc897b2006-08-28 14:56:16 -0700510 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 e1000_phy_init_script(hw);
512
513 /* Configure activity LED after PHY reset */
Joe Perches1dc32912008-07-11 15:17:08 -0700514 led_ctrl = er32(LEDCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 led_ctrl &= IGP_ACTIVITY_LED_MASK;
516 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
Joe Perches1dc32912008-07-11 15:17:08 -0700517 ew32(LEDCTL, led_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 }
519
520 /* Clear interrupt mask to stop board from generating interrupts */
521 DEBUGOUT("Masking off all interrupts\n");
Joe Perches1dc32912008-07-11 15:17:08 -0700522 ew32(IMC, 0xffffffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523
524 /* Clear any pending interrupt events. */
Joe Perches1dc32912008-07-11 15:17:08 -0700525 icr = er32(ICR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526
527 /* If MWI was previously enabled, reenable it. */
Auke Kok8fc897b2006-08-28 14:56:16 -0700528 if (hw->mac_type == e1000_82542_rev2_0) {
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400529 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 e1000_pci_set_mwi(hw);
531 }
532
533 return E1000_SUCCESS;
534}
535
536/******************************************************************************
537 * Performs basic configuration of the adapter.
538 *
539 * hw - Struct containing variables accessed by shared code
540 *
541 * Assumes that the controller has previously been reset and is in a
542 * post-reset uninitialized state. Initializes the receive address registers,
543 * multicast table, and VLAN filter table. Calls routines to setup link
544 * configuration and flow control settings. Clears all on-chip counters. Leaves
545 * the transmit and receive units disabled and uninitialized.
546 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -0700547s32 e1000_init_hw(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548{
Joe Perches406874a2008-04-03 10:06:32 -0700549 u32 ctrl;
550 u32 i;
551 s32 ret_val;
552 u32 mta_size;
Joe Perches406874a2008-04-03 10:06:32 -0700553 u32 ctrl_ext;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700554
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 DEBUGFUNC("e1000_init_hw");
556
557 /* Initialize Identification LED */
558 ret_val = e1000_id_led_init(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -0700559 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 DEBUGOUT("Error Initializing Identification LED\n");
561 return ret_val;
562 }
563
564 /* Set the media type and TBI compatibility */
565 e1000_set_media_type(hw);
566
567 /* Disabling VLAN filtering. */
568 DEBUGOUT("Initializing the IEEE VLAN\n");
Jesse Brandeburg1532ece2009-09-25 12:16:14 +0000569 if (hw->mac_type < e1000_82545_rev_3)
570 ew32(VET, 0);
571 e1000_clear_vfta(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572
573 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
Auke Kok8fc897b2006-08-28 14:56:16 -0700574 if (hw->mac_type == e1000_82542_rev2_0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
576 e1000_pci_clear_mwi(hw);
Joe Perches1dc32912008-07-11 15:17:08 -0700577 ew32(RCTL, E1000_RCTL_RST);
578 E1000_WRITE_FLUSH();
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400579 msleep(5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 }
581
582 /* Setup the receive address. This involves initializing all of the Receive
583 * Address Registers (RARs 0 - 15).
584 */
585 e1000_init_rx_addrs(hw);
586
587 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
Auke Kok8fc897b2006-08-28 14:56:16 -0700588 if (hw->mac_type == e1000_82542_rev2_0) {
Joe Perches1dc32912008-07-11 15:17:08 -0700589 ew32(RCTL, 0);
590 E1000_WRITE_FLUSH();
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400591 msleep(1);
592 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 e1000_pci_set_mwi(hw);
594 }
595
596 /* Zero out the Multicast HASH table */
597 DEBUGOUT("Zeroing the MTA\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700598 mta_size = E1000_MC_TBL_SIZE;
Auke Kok8fc897b2006-08-28 14:56:16 -0700599 for (i = 0; i < mta_size; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -0700601 /* use write flush to prevent Memory Write Block (MWB) from
602 * occuring when accessing our register space */
Joe Perches1dc32912008-07-11 15:17:08 -0700603 E1000_WRITE_FLUSH();
Auke Kok4ca213a2006-06-27 09:07:08 -0700604 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605
606 /* Set the PCI priority bit correctly in the CTRL register. This
607 * determines if the adapter gives priority to receives, or if it
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700608 * gives equal priority to transmits and receives. Valid only on
609 * 82542 and 82543 silicon.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 */
Auke Kok8fc897b2006-08-28 14:56:16 -0700611 if (hw->dma_fairness && hw->mac_type <= e1000_82543) {
Joe Perches1dc32912008-07-11 15:17:08 -0700612 ctrl = er32(CTRL);
613 ew32(CTRL, ctrl | E1000_CTRL_PRIOR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 }
615
Auke Kok8fc897b2006-08-28 14:56:16 -0700616 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 case e1000_82545_rev_3:
618 case e1000_82546_rev_3:
619 break;
620 default:
621 /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
Peter Oruba007755e2007-09-28 22:42:06 -0700622 if (hw->bus_type == e1000_bus_type_pcix && e1000_pcix_get_mmrbc(hw) > 2048)
623 e1000_pcix_set_mmrbc(hw, 2048);
624 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 }
626
627 /* Call a subroutine to configure the link and setup flow control. */
628 ret_val = e1000_setup_link(hw);
629
630 /* Set the transmit descriptor write-back policy */
Auke Kok8fc897b2006-08-28 14:56:16 -0700631 if (hw->mac_type > e1000_82544) {
Joe Perches1dc32912008-07-11 15:17:08 -0700632 ctrl = er32(TXDCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
Joe Perches1dc32912008-07-11 15:17:08 -0700634 ew32(TXDCTL, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 }
636
637 /* Clear all of the statistics registers (clear on read). It is
638 * important that we do this after we have tried to establish link
639 * because the symbol error count will increment wildly if there
640 * is no link.
641 */
642 e1000_clear_hw_cntrs(hw);
643
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -0800644 if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER ||
645 hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) {
Joe Perches1dc32912008-07-11 15:17:08 -0700646 ctrl_ext = er32(CTRL_EXT);
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -0800647 /* Relaxed ordering must be disabled to avoid a parity
648 * error crash in a PCI slot. */
649 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
Joe Perches1dc32912008-07-11 15:17:08 -0700650 ew32(CTRL_EXT, ctrl_ext);
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -0800651 }
652
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 return ret_val;
654}
655
656/******************************************************************************
657 * Adjust SERDES output amplitude based on EEPROM setting.
658 *
659 * hw - Struct containing variables accessed by shared code.
660 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -0700661static s32 e1000_adjust_serdes_amplitude(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662{
Joe Perches406874a2008-04-03 10:06:32 -0700663 u16 eeprom_data;
664 s32 ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665
666 DEBUGFUNC("e1000_adjust_serdes_amplitude");
667
Auke Kok8fc897b2006-08-28 14:56:16 -0700668 if (hw->media_type != e1000_media_type_internal_serdes)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 return E1000_SUCCESS;
670
Auke Kok8fc897b2006-08-28 14:56:16 -0700671 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 case e1000_82545_rev_3:
673 case e1000_82546_rev_3:
674 break;
675 default:
676 return E1000_SUCCESS;
677 }
678
679 ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1, &eeprom_data);
680 if (ret_val) {
681 return ret_val;
682 }
683
Auke Kok8fc897b2006-08-28 14:56:16 -0700684 if (eeprom_data != EEPROM_RESERVED_WORD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 /* Adjust SERDES output amplitude only. */
Auke Kok76c224b2006-05-23 13:36:06 -0700686 eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data);
Auke Kok8fc897b2006-08-28 14:56:16 -0700688 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 return ret_val;
690 }
691
692 return E1000_SUCCESS;
693}
694
695/******************************************************************************
696 * Configures flow control and link settings.
697 *
698 * hw - Struct containing variables accessed by shared code
699 *
700 * Determines which flow control settings to use. Calls the apropriate media-
701 * specific link configuration function. Configures the flow control settings.
702 * Assuming the adapter has a valid link partner, a valid link should be
703 * established. Assumes the hardware has previously been reset and the
704 * transmitter and receiver are not enabled.
705 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -0700706s32 e1000_setup_link(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707{
Joe Perches406874a2008-04-03 10:06:32 -0700708 u32 ctrl_ext;
709 s32 ret_val;
710 u16 eeprom_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711
712 DEBUGFUNC("e1000_setup_link");
713
714 /* Read and store word 0x0F of the EEPROM. This word contains bits
715 * that determine the hardware's default PAUSE (flow control) mode,
716 * a bit that determines whether the HW defaults to enabling or
717 * disabling auto-negotiation, and the direction of the
718 * SW defined pins. If there is no SW over-ride of the flow
719 * control setting, then the variable hw->fc will
720 * be initialized based on a value in the EEPROM.
721 */
Jeff Kirsher11241b12006-09-27 12:53:28 -0700722 if (hw->fc == E1000_FC_DEFAULT) {
Jesse Brandeburg1532ece2009-09-25 12:16:14 +0000723 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
724 1, &eeprom_data);
725 if (ret_val) {
726 DEBUGOUT("EEPROM Read Error\n");
727 return -E1000_ERR_EEPROM;
Jeff Kirsherfd803242005-12-13 00:06:22 -0500728 }
Jesse Brandeburg1532ece2009-09-25 12:16:14 +0000729 if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
730 hw->fc = E1000_FC_NONE;
731 else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
732 EEPROM_WORD0F_ASM_DIR)
733 hw->fc = E1000_FC_TX_PAUSE;
734 else
735 hw->fc = E1000_FC_FULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 }
737
738 /* We want to save off the original Flow Control configuration just
739 * in case we get disconnected and then reconnected into a different
740 * hub or switch with different Flow Control capabilities.
741 */
Auke Kok8fc897b2006-08-28 14:56:16 -0700742 if (hw->mac_type == e1000_82542_rev2_0)
Jeff Kirsher11241b12006-09-27 12:53:28 -0700743 hw->fc &= (~E1000_FC_TX_PAUSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744
Auke Kok8fc897b2006-08-28 14:56:16 -0700745 if ((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
Jeff Kirsher11241b12006-09-27 12:53:28 -0700746 hw->fc &= (~E1000_FC_RX_PAUSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747
748 hw->original_fc = hw->fc;
749
750 DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc);
751
752 /* Take the 4 bits from EEPROM word 0x0F that determine the initial
753 * polarity value for the SW controlled pins, and setup the
754 * Extended Device Control reg with that info.
755 * This is needed because one of the SW controlled pins is used for
756 * signal detection. So this should be done before e1000_setup_pcs_link()
757 * or e1000_phy_setup() is called.
758 */
Jeff Kirsher497fce52006-03-02 18:18:20 -0800759 if (hw->mac_type == e1000_82543) {
Auke Kok8fc897b2006-08-28 14:56:16 -0700760 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
761 1, &eeprom_data);
762 if (ret_val) {
763 DEBUGOUT("EEPROM Read Error\n");
764 return -E1000_ERR_EEPROM;
765 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
767 SWDPIO__EXT_SHIFT);
Joe Perches1dc32912008-07-11 15:17:08 -0700768 ew32(CTRL_EXT, ctrl_ext);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 }
770
771 /* Call the necessary subroutine to configure the link. */
772 ret_val = (hw->media_type == e1000_media_type_copper) ?
773 e1000_setup_copper_link(hw) :
774 e1000_setup_fiber_serdes_link(hw);
775
776 /* Initialize the flow control address, type, and PAUSE timer
777 * registers to their default values. This is done even if flow
778 * control is disabled, because it does not hurt anything to
779 * initialize these registers.
780 */
781 DEBUGOUT("Initializing the Flow Control address, type and timer regs\n");
782
Jesse Brandeburg1532ece2009-09-25 12:16:14 +0000783 ew32(FCT, FLOW_CONTROL_TYPE);
784 ew32(FCAH, FLOW_CONTROL_ADDRESS_HIGH);
785 ew32(FCAL, FLOW_CONTROL_ADDRESS_LOW);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700786
Joe Perches1dc32912008-07-11 15:17:08 -0700787 ew32(FCTTV, hw->fc_pause_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788
789 /* Set the flow control receive threshold registers. Normally,
790 * these registers will be set to a default threshold that may be
791 * adjusted later by the driver's runtime code. However, if the
792 * ability to transmit pause frames in not enabled, then these
793 * registers will be set to 0.
794 */
Jeff Kirsher11241b12006-09-27 12:53:28 -0700795 if (!(hw->fc & E1000_FC_TX_PAUSE)) {
Joe Perches1dc32912008-07-11 15:17:08 -0700796 ew32(FCRTL, 0);
797 ew32(FCRTH, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 } else {
799 /* We need to set up the Receive Threshold high and low water marks
800 * as well as (optionally) enabling the transmission of XON frames.
801 */
Auke Kok8fc897b2006-08-28 14:56:16 -0700802 if (hw->fc_send_xon) {
Joe Perches1dc32912008-07-11 15:17:08 -0700803 ew32(FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE));
804 ew32(FCRTH, hw->fc_high_water);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 } else {
Joe Perches1dc32912008-07-11 15:17:08 -0700806 ew32(FCRTL, hw->fc_low_water);
807 ew32(FCRTH, hw->fc_high_water);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 }
809 }
810 return ret_val;
811}
812
813/******************************************************************************
814 * Sets up link for a fiber based or serdes based adapter
815 *
816 * hw - Struct containing variables accessed by shared code
817 *
818 * Manipulates Physical Coding Sublayer functions in order to configure
819 * link. Assumes the hardware has been previously reset and the transmitter
820 * and receiver are not enabled.
821 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -0700822static s32 e1000_setup_fiber_serdes_link(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823{
Joe Perches406874a2008-04-03 10:06:32 -0700824 u32 ctrl;
825 u32 status;
826 u32 txcw = 0;
827 u32 i;
828 u32 signal = 0;
829 s32 ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830
831 DEBUGFUNC("e1000_setup_fiber_serdes_link");
832
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700833 /* On adapters with a MAC newer than 82544, SWDP 1 will be
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 * set when the optics detect a signal. On older adapters, it will be
835 * cleared when there is a signal. This applies to fiber media only.
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700836 * If we're on serdes media, adjust the output amplitude to value
837 * set in the EEPROM.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 */
Joe Perches1dc32912008-07-11 15:17:08 -0700839 ctrl = er32(CTRL);
Auke Kok8fc897b2006-08-28 14:56:16 -0700840 if (hw->media_type == e1000_media_type_fiber)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
842
843 ret_val = e1000_adjust_serdes_amplitude(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -0700844 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 return ret_val;
846
847 /* Take the link out of reset */
848 ctrl &= ~(E1000_CTRL_LRST);
849
850 /* Adjust VCO speed to improve BER performance */
851 ret_val = e1000_set_vco_speed(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -0700852 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 return ret_val;
854
855 e1000_config_collision_dist(hw);
856
857 /* Check for a software override of the flow control settings, and setup
858 * the device accordingly. If auto-negotiation is enabled, then software
859 * will have to set the "PAUSE" bits to the correct value in the Tranmsit
860 * Config Word Register (TXCW) and re-start auto-negotiation. However, if
861 * auto-negotiation is disabled, then software will have to manually
862 * configure the two flow control enable bits in the CTRL register.
863 *
864 * The possible values of the "fc" parameter are:
865 * 0: Flow control is completely disabled
866 * 1: Rx flow control is enabled (we can receive pause frames, but
867 * not send pause frames).
868 * 2: Tx flow control is enabled (we can send pause frames but we do
869 * not support receiving pause frames).
870 * 3: Both Rx and TX flow control (symmetric) are enabled.
871 */
872 switch (hw->fc) {
Jeff Kirsher11241b12006-09-27 12:53:28 -0700873 case E1000_FC_NONE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 /* Flow control is completely disabled by a software over-ride. */
875 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
876 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -0700877 case E1000_FC_RX_PAUSE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 /* RX Flow control is enabled and TX Flow control is disabled by a
879 * software over-ride. Since there really isn't a way to advertise
880 * that we are capable of RX Pause ONLY, we will advertise that we
881 * support both symmetric and asymmetric RX PAUSE. Later, we will
882 * disable the adapter's ability to send PAUSE frames.
883 */
884 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
885 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -0700886 case E1000_FC_TX_PAUSE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 /* TX Flow control is enabled, and RX Flow control is disabled, by a
888 * software over-ride.
889 */
890 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
891 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -0700892 case E1000_FC_FULL:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 /* Flow control (both RX and TX) is enabled by a software over-ride. */
894 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
895 break;
896 default:
897 DEBUGOUT("Flow control param set incorrectly\n");
898 return -E1000_ERR_CONFIG;
899 break;
900 }
901
902 /* Since auto-negotiation is enabled, take the link out of reset (the link
903 * will be in reset, because we previously reset the chip). This will
904 * restart auto-negotiation. If auto-neogtiation is successful then the
905 * link-up status bit will be set and the flow control enable bits (RFCE
906 * and TFCE) will be set according to their negotiated value.
907 */
908 DEBUGOUT("Auto-negotiation enabled\n");
909
Joe Perches1dc32912008-07-11 15:17:08 -0700910 ew32(TXCW, txcw);
911 ew32(CTRL, ctrl);
912 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913
914 hw->txcw = txcw;
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400915 msleep(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916
917 /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
918 * indication in the Device Status Register. Time-out if a link isn't
919 * seen in 500 milliseconds seconds (Auto-negotiation should complete in
920 * less than 500 milliseconds even if the other end is doing it in SW).
921 * For internal serdes, we just assume a signal is present, then poll.
922 */
Auke Kok8fc897b2006-08-28 14:56:16 -0700923 if (hw->media_type == e1000_media_type_internal_serdes ||
Joe Perches1dc32912008-07-11 15:17:08 -0700924 (er32(CTRL) & E1000_CTRL_SWDPIN1) == signal) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 DEBUGOUT("Looking for Link\n");
Auke Kok8fc897b2006-08-28 14:56:16 -0700926 for (i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400927 msleep(10);
Joe Perches1dc32912008-07-11 15:17:08 -0700928 status = er32(STATUS);
Auke Kok8fc897b2006-08-28 14:56:16 -0700929 if (status & E1000_STATUS_LU) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 }
Auke Kok8fc897b2006-08-28 14:56:16 -0700931 if (i == (LINK_UP_TIMEOUT / 10)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 DEBUGOUT("Never got a valid link from auto-neg!!!\n");
933 hw->autoneg_failed = 1;
934 /* AutoNeg failed to achieve a link, so we'll call
935 * e1000_check_for_link. This routine will force the link up if
936 * we detect a signal. This will allow us to communicate with
937 * non-autonegotiating link partners.
938 */
939 ret_val = e1000_check_for_link(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -0700940 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 DEBUGOUT("Error while checking for link\n");
942 return ret_val;
943 }
944 hw->autoneg_failed = 0;
945 } else {
946 hw->autoneg_failed = 0;
947 DEBUGOUT("Valid Link Found\n");
948 }
949 } else {
950 DEBUGOUT("No Signal Detected\n");
951 }
952 return E1000_SUCCESS;
953}
954
955/******************************************************************************
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700956* Make sure we have a valid PHY and change PHY mode before link setup.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957*
958* hw - Struct containing variables accessed by shared code
959******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -0700960static s32 e1000_copper_link_preconfig(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961{
Joe Perches406874a2008-04-03 10:06:32 -0700962 u32 ctrl;
963 s32 ret_val;
964 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700966 DEBUGFUNC("e1000_copper_link_preconfig");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967
Joe Perches1dc32912008-07-11 15:17:08 -0700968 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 /* With 82543, we need to force speed and duplex on the MAC equal to what
970 * the PHY speed and duplex configuration is. In addition, we need to
971 * perform a hardware reset on the PHY to take it out of reset.
972 */
Auke Kok8fc897b2006-08-28 14:56:16 -0700973 if (hw->mac_type > e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974 ctrl |= E1000_CTRL_SLU;
975 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
Joe Perches1dc32912008-07-11 15:17:08 -0700976 ew32(CTRL, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 } else {
978 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
Joe Perches1dc32912008-07-11 15:17:08 -0700979 ew32(CTRL, ctrl);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700980 ret_val = e1000_phy_hw_reset(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -0700981 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700982 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 }
984
985 /* Make sure we have a valid PHY */
986 ret_val = e1000_detect_gig_phy(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -0700987 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 DEBUGOUT("Error, did not detect valid phy.\n");
989 return ret_val;
990 }
991 DEBUGOUT1("Phy ID = %x \n", hw->phy_id);
992
993 /* Set PHY to class A mode (if necessary) */
994 ret_val = e1000_set_phy_mode(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -0700995 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 return ret_val;
997
Auke Kok8fc897b2006-08-28 14:56:16 -0700998 if ((hw->mac_type == e1000_82545_rev_3) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 (hw->mac_type == e1000_82546_rev_3)) {
1000 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1001 phy_data |= 0x00000008;
1002 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1003 }
1004
Auke Kok8fc897b2006-08-28 14:56:16 -07001005 if (hw->mac_type <= e1000_82543 ||
1006 hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
1007 hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2)
Joe Perchesc3033b02008-03-21 11:06:25 -07001008 hw->phy_reset_disable = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001010 return E1000_SUCCESS;
1011}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001014/********************************************************************
1015* Copper link setup for e1000_phy_igp series.
1016*
1017* hw - Struct containing variables accessed by shared code
1018*********************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07001019static s32 e1000_copper_link_igp_setup(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001020{
Joe Perches406874a2008-04-03 10:06:32 -07001021 u32 led_ctrl;
1022 s32 ret_val;
1023 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001025 DEBUGFUNC("e1000_copper_link_igp_setup");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001027 if (hw->phy_reset_disable)
1028 return E1000_SUCCESS;
Auke Kok76c224b2006-05-23 13:36:06 -07001029
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001030 ret_val = e1000_phy_reset(hw);
1031 if (ret_val) {
1032 DEBUGOUT("Error Resetting the PHY\n");
1033 return ret_val;
1034 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035
Auke Kok8fc897b2006-08-28 14:56:16 -07001036 /* Wait 15ms for MAC to configure PHY from eeprom settings */
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001037 msleep(15);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001038 /* Configure activity LED after PHY reset */
Joe Perches1dc32912008-07-11 15:17:08 -07001039 led_ctrl = er32(LEDCTL);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001040 led_ctrl &= IGP_ACTIVITY_LED_MASK;
1041 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
Joe Perches1dc32912008-07-11 15:17:08 -07001042 ew32(LEDCTL, led_ctrl);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001043
Jeff Kirsherc9c1b832006-08-16 13:38:54 -07001044 /* The NVM settings will configure LPLU in D3 for IGP2 and IGP3 PHYs */
1045 if (hw->phy_type == e1000_phy_igp) {
1046 /* disable lplu d3 during driver init */
Joe Perchesc3033b02008-03-21 11:06:25 -07001047 ret_val = e1000_set_d3_lplu_state(hw, false);
Jeff Kirsherc9c1b832006-08-16 13:38:54 -07001048 if (ret_val) {
1049 DEBUGOUT("Error Disabling LPLU D3\n");
1050 return ret_val;
1051 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001052 }
1053
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001054 /* Configure mdi-mdix settings */
1055 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1056 if (ret_val)
1057 return ret_val;
1058
1059 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
1060 hw->dsp_config_state = e1000_dsp_config_disabled;
1061 /* Force MDI for earlier revs of the IGP PHY */
1062 phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX | IGP01E1000_PSCR_FORCE_MDI_MDIX);
1063 hw->mdix = 1;
1064
1065 } else {
1066 hw->dsp_config_state = e1000_dsp_config_enabled;
1067 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1068
1069 switch (hw->mdix) {
1070 case 1:
1071 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1072 break;
1073 case 2:
1074 phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
1075 break;
1076 case 0:
1077 default:
1078 phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
1079 break;
1080 }
1081 }
1082 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001083 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001084 return ret_val;
1085
1086 /* set auto-master slave resolution settings */
Auke Kok8fc897b2006-08-28 14:56:16 -07001087 if (hw->autoneg) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001088 e1000_ms_type phy_ms_setting = hw->master_slave;
1089
Auke Kok8fc897b2006-08-28 14:56:16 -07001090 if (hw->ffe_config_state == e1000_ffe_config_active)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001091 hw->ffe_config_state = e1000_ffe_config_enabled;
1092
Auke Kok8fc897b2006-08-28 14:56:16 -07001093 if (hw->dsp_config_state == e1000_dsp_config_activated)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001094 hw->dsp_config_state = e1000_dsp_config_enabled;
1095
1096 /* when autonegotiation advertisment is only 1000Mbps then we
1097 * should disable SmartSpeed and enable Auto MasterSlave
1098 * resolution as hardware default. */
Auke Kok8fc897b2006-08-28 14:56:16 -07001099 if (hw->autoneg_advertised == ADVERTISE_1000_FULL) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001100 /* Disable SmartSpeed */
Auke Kok8fc897b2006-08-28 14:56:16 -07001101 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1102 &phy_data);
1103 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001105 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Auke Kok8fc897b2006-08-28 14:56:16 -07001106 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1107 phy_data);
1108 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001110 /* Set auto Master/Slave resolution process */
1111 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001112 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001113 return ret_val;
1114 phy_data &= ~CR_1000T_MS_ENABLE;
1115 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001116 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001117 return ret_val;
1118 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001120 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001121 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001122 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001124 /* load defaults for future use */
1125 hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
1126 ((phy_data & CR_1000T_MS_VALUE) ?
1127 e1000_ms_force_master :
1128 e1000_ms_force_slave) :
1129 e1000_ms_auto;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001131 switch (phy_ms_setting) {
1132 case e1000_ms_force_master:
1133 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
1134 break;
1135 case e1000_ms_force_slave:
1136 phy_data |= CR_1000T_MS_ENABLE;
1137 phy_data &= ~(CR_1000T_MS_VALUE);
1138 break;
1139 case e1000_ms_auto:
1140 phy_data &= ~CR_1000T_MS_ENABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141 default:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001142 break;
1143 }
1144 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001145 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001146 return ret_val;
Malli Chilakala2b028932005-06-17 17:46:06 -07001147 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148
Malli Chilakala2b028932005-06-17 17:46:06 -07001149 return E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001150}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001152/********************************************************************
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001153* Copper link setup for e1000_phy_m88 series.
1154*
1155* hw - Struct containing variables accessed by shared code
1156*********************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07001157static s32 e1000_copper_link_mgp_setup(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001158{
Joe Perches406874a2008-04-03 10:06:32 -07001159 s32 ret_val;
1160 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001162 DEBUGFUNC("e1000_copper_link_mgp_setup");
1163
Auke Kok8fc897b2006-08-28 14:56:16 -07001164 if (hw->phy_reset_disable)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001165 return E1000_SUCCESS;
Auke Kok76c224b2006-05-23 13:36:06 -07001166
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001167 /* Enable CRS on TX. This must be set for half-duplex operation. */
1168 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001169 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001170 return ret_val;
1171
1172 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1173
1174 /* Options:
1175 * MDI/MDI-X = 0 (default)
1176 * 0 - Auto for all speeds
1177 * 1 - MDI mode
1178 * 2 - MDI-X mode
1179 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1180 */
1181 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1182
1183 switch (hw->mdix) {
1184 case 1:
1185 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
1186 break;
1187 case 2:
1188 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
1189 break;
1190 case 3:
1191 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
1192 break;
1193 case 0:
1194 default:
1195 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
1196 break;
1197 }
1198
1199 /* Options:
1200 * disable_polarity_correction = 0 (default)
1201 * Automatic Correction for Reversed Cable Polarity
1202 * 0 - Disabled
1203 * 1 - Enabled
1204 */
1205 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
Auke Kok8fc897b2006-08-28 14:56:16 -07001206 if (hw->disable_polarity_correction == 1)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001207 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
Auke Kokee040222006-06-27 09:08:03 -07001208 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1209 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001210 return ret_val;
1211
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001212 if (hw->phy_revision < M88E1011_I_REV_4) {
Auke Kokee040222006-06-27 09:08:03 -07001213 /* Force TX_CLK in the Extended PHY Specific Control Register
1214 * to 25MHz clock.
1215 */
1216 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1217 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001218 return ret_val;
Auke Kokee040222006-06-27 09:08:03 -07001219
1220 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1221
1222 if ((hw->phy_revision == E1000_REVISION_2) &&
1223 (hw->phy_id == M88E1111_I_PHY_ID)) {
1224 /* Vidalia Phy, set the downshift counter to 5x */
1225 phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK);
1226 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
1227 ret_val = e1000_write_phy_reg(hw,
1228 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1229 if (ret_val)
1230 return ret_val;
1231 } else {
1232 /* Configure Master and Slave downshift values */
1233 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
1234 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
1235 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
1236 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
1237 ret_val = e1000_write_phy_reg(hw,
1238 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1239 if (ret_val)
1240 return ret_val;
1241 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001242 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001244 /* SW Reset the PHY so all changes take effect */
1245 ret_val = e1000_phy_reset(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001246 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001247 DEBUGOUT("Error Resetting the PHY\n");
1248 return ret_val;
1249 }
1250
1251 return E1000_SUCCESS;
1252}
1253
1254/********************************************************************
1255* Setup auto-negotiation and flow control advertisements,
1256* and then perform auto-negotiation.
1257*
1258* hw - Struct containing variables accessed by shared code
1259*********************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07001260static s32 e1000_copper_link_autoneg(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001261{
Joe Perches406874a2008-04-03 10:06:32 -07001262 s32 ret_val;
1263 u16 phy_data;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001264
1265 DEBUGFUNC("e1000_copper_link_autoneg");
1266
1267 /* Perform some bounds checking on the hw->autoneg_advertised
1268 * parameter. If this variable is zero, then set it to the default.
1269 */
1270 hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
1271
1272 /* If autoneg_advertised is zero, we assume it was not defaulted
1273 * by the calling code so we set to advertise full capability.
1274 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001275 if (hw->autoneg_advertised == 0)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001276 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
1277
1278 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
1279 ret_val = e1000_phy_setup_autoneg(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001280 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001281 DEBUGOUT("Error Setting up Auto-Negotiation\n");
1282 return ret_val;
1283 }
1284 DEBUGOUT("Restarting Auto-Neg\n");
1285
1286 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
1287 * the Auto Neg Restart bit in the PHY control register.
1288 */
1289 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001290 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001291 return ret_val;
1292
1293 phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
1294 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001295 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001296 return ret_val;
1297
1298 /* Does the user want to wait for Auto-Neg to complete here, or
1299 * check at a later time (for example, callback routine).
1300 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001301 if (hw->wait_autoneg_complete) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001302 ret_val = e1000_wait_autoneg(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001303 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001304 DEBUGOUT("Error while waiting for autoneg to complete\n");
1305 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001307 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308
Joe Perchesc3033b02008-03-21 11:06:25 -07001309 hw->get_link_status = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001311 return E1000_SUCCESS;
1312}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001314/******************************************************************************
1315* Config the MAC and the PHY after link is up.
1316* 1) Set up the MAC to the current PHY speed/duplex
1317* if we are on 82543. If we
1318* are on newer silicon, we only need to configure
1319* collision distance in the Transmit Control Register.
1320* 2) Set up flow control on the MAC to that established with
1321* the link partner.
Auke Kok76c224b2006-05-23 13:36:06 -07001322* 3) Config DSP to improve Gigabit link quality for some PHY revisions.
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001323*
1324* hw - Struct containing variables accessed by shared code
1325******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07001326static s32 e1000_copper_link_postconfig(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001327{
Joe Perches406874a2008-04-03 10:06:32 -07001328 s32 ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001329 DEBUGFUNC("e1000_copper_link_postconfig");
Auke Kok76c224b2006-05-23 13:36:06 -07001330
Auke Kok8fc897b2006-08-28 14:56:16 -07001331 if (hw->mac_type >= e1000_82544) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001332 e1000_config_collision_dist(hw);
1333 } else {
1334 ret_val = e1000_config_mac_to_phy(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001335 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001336 DEBUGOUT("Error configuring MAC to PHY settings\n");
1337 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001339 }
1340 ret_val = e1000_config_fc_after_link_up(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001341 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001342 DEBUGOUT("Error Configuring Flow Control\n");
1343 return ret_val;
1344 }
1345
1346 /* Config DSP to improve Giga link quality */
Auke Kok8fc897b2006-08-28 14:56:16 -07001347 if (hw->phy_type == e1000_phy_igp) {
Joe Perchesc3033b02008-03-21 11:06:25 -07001348 ret_val = e1000_config_dsp_after_link_change(hw, true);
Auke Kok8fc897b2006-08-28 14:56:16 -07001349 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001350 DEBUGOUT("Error Configuring DSP after link up\n");
1351 return ret_val;
1352 }
1353 }
Auke Kok76c224b2006-05-23 13:36:06 -07001354
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001355 return E1000_SUCCESS;
1356}
1357
1358/******************************************************************************
1359* Detects which PHY is present and setup the speed and duplex
1360*
1361* hw - Struct containing variables accessed by shared code
1362******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07001363static s32 e1000_setup_copper_link(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001364{
Joe Perches406874a2008-04-03 10:06:32 -07001365 s32 ret_val;
1366 u16 i;
1367 u16 phy_data;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001368
1369 DEBUGFUNC("e1000_setup_copper_link");
1370
1371 /* Check if it is a valid PHY and set PHY mode if necessary. */
1372 ret_val = e1000_copper_link_preconfig(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001373 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001374 return ret_val;
1375
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00001376 if (hw->phy_type == e1000_phy_igp) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001377 ret_val = e1000_copper_link_igp_setup(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001378 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001379 return ret_val;
1380 } else if (hw->phy_type == e1000_phy_m88) {
1381 ret_val = e1000_copper_link_mgp_setup(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001382 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001383 return ret_val;
1384 }
1385
Auke Kok8fc897b2006-08-28 14:56:16 -07001386 if (hw->autoneg) {
Auke Kok76c224b2006-05-23 13:36:06 -07001387 /* Setup autoneg and flow control advertisement
1388 * and perform autonegotiation */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001389 ret_val = e1000_copper_link_autoneg(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001390 if (ret_val)
Auke Kok76c224b2006-05-23 13:36:06 -07001391 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001392 } else {
1393 /* PHY will be set to 10H, 10F, 100H,or 100F
1394 * depending on value from forced_speed_duplex. */
1395 DEBUGOUT("Forcing speed and duplex\n");
1396 ret_val = e1000_phy_force_speed_duplex(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001397 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001398 DEBUGOUT("Error Forcing Speed and Duplex\n");
1399 return ret_val;
1400 }
1401 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402
1403 /* Check link status. Wait up to 100 microseconds for link to become
1404 * valid.
1405 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001406 for (i = 0; i < 10; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001408 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 return ret_val;
1410 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001411 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 return ret_val;
1413
Auke Kok8fc897b2006-08-28 14:56:16 -07001414 if (phy_data & MII_SR_LINK_STATUS) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001415 /* Config the MAC and PHY after link is up */
1416 ret_val = e1000_copper_link_postconfig(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001417 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 return ret_val;
Auke Kok76c224b2006-05-23 13:36:06 -07001419
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 DEBUGOUT("Valid link established!!!\n");
1421 return E1000_SUCCESS;
1422 }
1423 udelay(10);
1424 }
1425
1426 DEBUGOUT("Unable to establish link!!!\n");
1427 return E1000_SUCCESS;
1428}
1429
1430/******************************************************************************
1431* Configures PHY autoneg and flow control advertisement settings
1432*
1433* hw - Struct containing variables accessed by shared code
1434******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07001435s32 e1000_phy_setup_autoneg(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436{
Joe Perches406874a2008-04-03 10:06:32 -07001437 s32 ret_val;
1438 u16 mii_autoneg_adv_reg;
1439 u16 mii_1000t_ctrl_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440
1441 DEBUGFUNC("e1000_phy_setup_autoneg");
1442
1443 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
1444 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07001445 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446 return ret_val;
1447
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00001448 /* Read the MII 1000Base-T Control Register (Address 9). */
1449 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
1450 if (ret_val)
1451 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452
1453 /* Need to parse both autoneg_advertised and fc and set up
1454 * the appropriate PHY registers. First we will parse for
1455 * autoneg_advertised software override. Since we can advertise
1456 * a plethora of combinations, we need to check each bit
1457 * individually.
1458 */
1459
1460 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
1461 * Advertisement Register (Address 4) and the 1000 mb speed bits in
1462 * the 1000Base-T Control Register (Address 9).
1463 */
1464 mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
1465 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
1466
1467 DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised);
1468
1469 /* Do we want to advertise 10 Mb Half Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07001470 if (hw->autoneg_advertised & ADVERTISE_10_HALF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471 DEBUGOUT("Advertise 10mb Half duplex\n");
1472 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
1473 }
1474
1475 /* Do we want to advertise 10 Mb Full Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07001476 if (hw->autoneg_advertised & ADVERTISE_10_FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477 DEBUGOUT("Advertise 10mb Full duplex\n");
1478 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
1479 }
1480
1481 /* Do we want to advertise 100 Mb Half Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07001482 if (hw->autoneg_advertised & ADVERTISE_100_HALF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483 DEBUGOUT("Advertise 100mb Half duplex\n");
1484 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
1485 }
1486
1487 /* Do we want to advertise 100 Mb Full Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07001488 if (hw->autoneg_advertised & ADVERTISE_100_FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489 DEBUGOUT("Advertise 100mb Full duplex\n");
1490 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
1491 }
1492
1493 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
Auke Kok8fc897b2006-08-28 14:56:16 -07001494 if (hw->autoneg_advertised & ADVERTISE_1000_HALF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495 DEBUGOUT("Advertise 1000mb Half duplex requested, request denied!\n");
1496 }
1497
1498 /* Do we want to advertise 1000 Mb Full Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07001499 if (hw->autoneg_advertised & ADVERTISE_1000_FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500 DEBUGOUT("Advertise 1000mb Full duplex\n");
1501 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
1502 }
1503
1504 /* Check for a software override of the flow control settings, and
1505 * setup the PHY advertisement registers accordingly. If
1506 * auto-negotiation is enabled, then software will have to set the
1507 * "PAUSE" bits to the correct value in the Auto-Negotiation
1508 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
1509 *
1510 * The possible values of the "fc" parameter are:
1511 * 0: Flow control is completely disabled
1512 * 1: Rx flow control is enabled (we can receive pause frames
1513 * but not send pause frames).
1514 * 2: Tx flow control is enabled (we can send pause frames
1515 * but we do not support receiving pause frames).
1516 * 3: Both Rx and TX flow control (symmetric) are enabled.
1517 * other: No software override. The flow control configuration
1518 * in the EEPROM is used.
1519 */
1520 switch (hw->fc) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07001521 case E1000_FC_NONE: /* 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522 /* Flow control (RX & TX) is completely disabled by a
1523 * software over-ride.
1524 */
1525 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1526 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07001527 case E1000_FC_RX_PAUSE: /* 1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528 /* RX Flow control is enabled, and TX Flow control is
1529 * disabled, by a software over-ride.
1530 */
1531 /* Since there really isn't a way to advertise that we are
1532 * capable of RX Pause ONLY, we will advertise that we
1533 * support both symmetric and asymmetric RX PAUSE. Later
1534 * (in e1000_config_fc_after_link_up) we will disable the
1535 *hw's ability to send PAUSE frames.
1536 */
1537 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1538 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07001539 case E1000_FC_TX_PAUSE: /* 2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540 /* TX Flow control is enabled, and RX Flow control is
1541 * disabled, by a software over-ride.
1542 */
1543 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
1544 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
1545 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07001546 case E1000_FC_FULL: /* 3 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547 /* Flow control (both RX and TX) is enabled by a software
1548 * over-ride.
1549 */
1550 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1551 break;
1552 default:
1553 DEBUGOUT("Flow control param set incorrectly\n");
1554 return -E1000_ERR_CONFIG;
1555 }
1556
1557 ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07001558 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559 return ret_val;
1560
1561 DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
1562
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00001563 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg);
1564 if (ret_val)
1565 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566
1567 return E1000_SUCCESS;
1568}
1569
1570/******************************************************************************
1571* Force PHY speed and duplex settings to hw->forced_speed_duplex
1572*
1573* hw - Struct containing variables accessed by shared code
1574******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07001575static s32 e1000_phy_force_speed_duplex(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576{
Joe Perches406874a2008-04-03 10:06:32 -07001577 u32 ctrl;
1578 s32 ret_val;
1579 u16 mii_ctrl_reg;
1580 u16 mii_status_reg;
1581 u16 phy_data;
1582 u16 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583
1584 DEBUGFUNC("e1000_phy_force_speed_duplex");
1585
1586 /* Turn off Flow control if we are forcing speed and duplex. */
Jeff Kirsher11241b12006-09-27 12:53:28 -07001587 hw->fc = E1000_FC_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588
1589 DEBUGOUT1("hw->fc = %d\n", hw->fc);
1590
1591 /* Read the Device Control Register. */
Joe Perches1dc32912008-07-11 15:17:08 -07001592 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593
1594 /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */
1595 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1596 ctrl &= ~(DEVICE_SPEED_MASK);
1597
1598 /* Clear the Auto Speed Detect Enable bit. */
1599 ctrl &= ~E1000_CTRL_ASDE;
1600
1601 /* Read the MII Control Register. */
1602 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07001603 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604 return ret_val;
1605
1606 /* We need to disable autoneg in order to force link and duplex. */
1607
1608 mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN;
1609
1610 /* Are we forcing Full or Half Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07001611 if (hw->forced_speed_duplex == e1000_100_full ||
1612 hw->forced_speed_duplex == e1000_10_full) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613 /* We want to force full duplex so we SET the full duplex bits in the
1614 * Device and MII Control Registers.
1615 */
1616 ctrl |= E1000_CTRL_FD;
1617 mii_ctrl_reg |= MII_CR_FULL_DUPLEX;
1618 DEBUGOUT("Full Duplex\n");
1619 } else {
1620 /* We want to force half duplex so we CLEAR the full duplex bits in
1621 * the Device and MII Control Registers.
1622 */
1623 ctrl &= ~E1000_CTRL_FD;
1624 mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX;
1625 DEBUGOUT("Half Duplex\n");
1626 }
1627
1628 /* Are we forcing 100Mbps??? */
Auke Kok8fc897b2006-08-28 14:56:16 -07001629 if (hw->forced_speed_duplex == e1000_100_full ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630 hw->forced_speed_duplex == e1000_100_half) {
1631 /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */
1632 ctrl |= E1000_CTRL_SPD_100;
1633 mii_ctrl_reg |= MII_CR_SPEED_100;
1634 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
1635 DEBUGOUT("Forcing 100mb ");
1636 } else {
1637 /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */
1638 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1639 mii_ctrl_reg |= MII_CR_SPEED_10;
1640 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
1641 DEBUGOUT("Forcing 10mb ");
1642 }
1643
1644 e1000_config_collision_dist(hw);
1645
1646 /* Write the configured values back to the Device Control Reg. */
Joe Perches1dc32912008-07-11 15:17:08 -07001647 ew32(CTRL, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00001649 if (hw->phy_type == e1000_phy_m88) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001651 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652 return ret_val;
1653
1654 /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
1655 * forced whenever speed are duplex are forced.
1656 */
1657 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1658 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001659 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660 return ret_val;
1661
1662 DEBUGOUT1("M88E1000 PSCR: %x \n", phy_data);
1663
1664 /* Need to reset the PHY or these changes will be ignored */
1665 mii_ctrl_reg |= MII_CR_RESET;
Auke Kok90fb5132006-11-01 08:47:30 -08001666
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667 } else {
1668 /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
1669 * forced whenever speed or duplex are forced.
1670 */
1671 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001672 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673 return ret_val;
1674
1675 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1676 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1677
1678 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001679 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680 return ret_val;
1681 }
1682
1683 /* Write back the modified PHY MII control register. */
1684 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07001685 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686 return ret_val;
1687
1688 udelay(1);
1689
1690 /* The wait_autoneg_complete flag may be a little misleading here.
1691 * Since we are forcing speed and duplex, Auto-Neg is not enabled.
1692 * But we do want to delay for a period while forcing only so we
1693 * don't generate false No Link messages. So we will wait here
1694 * only if the user has set wait_autoneg_complete to 1, which is
1695 * the default.
1696 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001697 if (hw->wait_autoneg_complete) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698 /* We will wait for autoneg to complete. */
1699 DEBUGOUT("Waiting for forced speed/duplex link.\n");
1700 mii_status_reg = 0;
1701
1702 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
Auke Kok8fc897b2006-08-28 14:56:16 -07001703 for (i = PHY_FORCE_TIME; i > 0; i--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704 /* Read the MII Status Register and wait for Auto-Neg Complete bit
1705 * to be set.
1706 */
1707 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07001708 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709 return ret_val;
1710
1711 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07001712 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713 return ret_val;
1714
Auke Kok8fc897b2006-08-28 14:56:16 -07001715 if (mii_status_reg & MII_SR_LINK_STATUS) break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001716 msleep(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717 }
Auke Kok8fc897b2006-08-28 14:56:16 -07001718 if ((i == 0) &&
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00001719 (hw->phy_type == e1000_phy_m88)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720 /* We didn't get link. Reset the DSP and wait again for link. */
1721 ret_val = e1000_phy_reset_dsp(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001722 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723 DEBUGOUT("Error Resetting PHY DSP\n");
1724 return ret_val;
1725 }
1726 }
1727 /* This loop will early-out if the link condition has been met. */
Auke Kok8fc897b2006-08-28 14:56:16 -07001728 for (i = PHY_FORCE_TIME; i > 0; i--) {
1729 if (mii_status_reg & MII_SR_LINK_STATUS) break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001730 msleep(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731 /* Read the MII Status Register and wait for Auto-Neg Complete bit
1732 * to be set.
1733 */
1734 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07001735 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736 return ret_val;
1737
1738 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07001739 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740 return ret_val;
1741 }
1742 }
1743
1744 if (hw->phy_type == e1000_phy_m88) {
1745 /* Because we reset the PHY above, we need to re-force TX_CLK in the
1746 * Extended PHY Specific Control Register to 25MHz clock. This value
1747 * defaults back to a 2.5MHz clock when the PHY is reset.
1748 */
1749 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001750 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751 return ret_val;
1752
1753 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1754 ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001755 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756 return ret_val;
1757
1758 /* In addition, because of the s/w reset above, we need to enable CRS on
1759 * TX. This must be set for both full and half duplex operation.
1760 */
1761 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001762 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763 return ret_val;
1764
1765 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1766 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001767 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768 return ret_val;
1769
Auke Kok8fc897b2006-08-28 14:56:16 -07001770 if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
1771 (!hw->autoneg) && (hw->forced_speed_duplex == e1000_10_full ||
1772 hw->forced_speed_duplex == e1000_10_half)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773 ret_val = e1000_polarity_reversal_workaround(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001774 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775 return ret_val;
1776 }
1777 }
1778 return E1000_SUCCESS;
1779}
1780
1781/******************************************************************************
1782* Sets the collision distance in the Transmit Control register
1783*
1784* hw - Struct containing variables accessed by shared code
1785*
1786* Link should have been established previously. Reads the speed and duplex
1787* information from the Device Status register.
1788******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07001789void e1000_config_collision_dist(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790{
Joe Perches406874a2008-04-03 10:06:32 -07001791 u32 tctl, coll_dist;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792
1793 DEBUGFUNC("e1000_config_collision_dist");
1794
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001795 if (hw->mac_type < e1000_82543)
1796 coll_dist = E1000_COLLISION_DISTANCE_82542;
1797 else
1798 coll_dist = E1000_COLLISION_DISTANCE;
1799
Joe Perches1dc32912008-07-11 15:17:08 -07001800 tctl = er32(TCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801
1802 tctl &= ~E1000_TCTL_COLD;
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001803 tctl |= coll_dist << E1000_COLD_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804
Joe Perches1dc32912008-07-11 15:17:08 -07001805 ew32(TCTL, tctl);
1806 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807}
1808
1809/******************************************************************************
1810* Sets MAC speed and duplex settings to reflect the those in the PHY
1811*
1812* hw - Struct containing variables accessed by shared code
1813* mii_reg - data to write to the MII control register
1814*
1815* The contents of the PHY register containing the needed information need to
1816* be passed in.
1817******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07001818static s32 e1000_config_mac_to_phy(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819{
Joe Perches406874a2008-04-03 10:06:32 -07001820 u32 ctrl;
1821 s32 ret_val;
1822 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823
1824 DEBUGFUNC("e1000_config_mac_to_phy");
1825
Auke Kok76c224b2006-05-23 13:36:06 -07001826 /* 82544 or newer MAC, Auto Speed Detection takes care of
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001827 * MAC speed/duplex configuration.*/
1828 if (hw->mac_type >= e1000_82544)
1829 return E1000_SUCCESS;
1830
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831 /* Read the Device Control Register and set the bits to Force Speed
1832 * and Duplex.
1833 */
Joe Perches1dc32912008-07-11 15:17:08 -07001834 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1836 ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
1837
1838 /* Set up duplex in the Device Control and Transmit Control
1839 * registers depending on negotiated values.
1840 */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001841 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001842 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001843 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844
Auke Kok8fc897b2006-08-28 14:56:16 -07001845 if (phy_data & M88E1000_PSSR_DPLX)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001846 ctrl |= E1000_CTRL_FD;
Auke Kok76c224b2006-05-23 13:36:06 -07001847 else
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001848 ctrl &= ~E1000_CTRL_FD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001850 e1000_config_collision_dist(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001852 /* Set up speed in the Device Control register depending on
1853 * negotiated values.
1854 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001855 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001856 ctrl |= E1000_CTRL_SPD_1000;
Auke Kok8fc897b2006-08-28 14:56:16 -07001857 else if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001858 ctrl |= E1000_CTRL_SPD_100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860 /* Write the configured values back to the Device Control Reg. */
Joe Perches1dc32912008-07-11 15:17:08 -07001861 ew32(CTRL, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862 return E1000_SUCCESS;
1863}
1864
1865/******************************************************************************
1866 * Forces the MAC's flow control settings.
1867 *
1868 * hw - Struct containing variables accessed by shared code
1869 *
1870 * Sets the TFCE and RFCE bits in the device control register to reflect
1871 * the adapter settings. TFCE and RFCE need to be explicitly set by
1872 * software when a Copper PHY is used because autonegotiation is managed
1873 * by the PHY rather than the MAC. Software must also configure these
1874 * bits when link is forced on a fiber connection.
1875 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07001876s32 e1000_force_mac_fc(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877{
Joe Perches406874a2008-04-03 10:06:32 -07001878 u32 ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879
1880 DEBUGFUNC("e1000_force_mac_fc");
1881
1882 /* Get the current configuration of the Device Control Register */
Joe Perches1dc32912008-07-11 15:17:08 -07001883 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884
1885 /* Because we didn't get link via the internal auto-negotiation
1886 * mechanism (we either forced link or we got link via PHY
1887 * auto-neg), we have to manually enable/disable transmit an
1888 * receive flow control.
1889 *
1890 * The "Case" statement below enables/disable flow control
1891 * according to the "hw->fc" parameter.
1892 *
1893 * The possible values of the "fc" parameter are:
1894 * 0: Flow control is completely disabled
1895 * 1: Rx flow control is enabled (we can receive pause
1896 * frames but not send pause frames).
1897 * 2: Tx flow control is enabled (we can send pause frames
1898 * frames but we do not receive pause frames).
1899 * 3: Both Rx and TX flow control (symmetric) is enabled.
1900 * other: No other values should be possible at this point.
1901 */
1902
1903 switch (hw->fc) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07001904 case E1000_FC_NONE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
1906 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07001907 case E1000_FC_RX_PAUSE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908 ctrl &= (~E1000_CTRL_TFCE);
1909 ctrl |= E1000_CTRL_RFCE;
1910 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07001911 case E1000_FC_TX_PAUSE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912 ctrl &= (~E1000_CTRL_RFCE);
1913 ctrl |= E1000_CTRL_TFCE;
1914 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07001915 case E1000_FC_FULL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
1917 break;
1918 default:
1919 DEBUGOUT("Flow control param set incorrectly\n");
1920 return -E1000_ERR_CONFIG;
1921 }
1922
1923 /* Disable TX Flow Control for 82542 (rev 2.0) */
Auke Kok8fc897b2006-08-28 14:56:16 -07001924 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925 ctrl &= (~E1000_CTRL_TFCE);
1926
Joe Perches1dc32912008-07-11 15:17:08 -07001927 ew32(CTRL, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928 return E1000_SUCCESS;
1929}
1930
1931/******************************************************************************
1932 * Configures flow control settings after link is established
1933 *
1934 * hw - Struct containing variables accessed by shared code
1935 *
1936 * Should be called immediately after a valid link has been established.
1937 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
1938 * and autonegotiation is enabled, the MAC flow control settings will be set
1939 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
1940 * and RFCE bits will be automaticaly set to the negotiated flow control mode.
1941 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07001942static s32 e1000_config_fc_after_link_up(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943{
Joe Perches406874a2008-04-03 10:06:32 -07001944 s32 ret_val;
1945 u16 mii_status_reg;
1946 u16 mii_nway_adv_reg;
1947 u16 mii_nway_lp_ability_reg;
1948 u16 speed;
1949 u16 duplex;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950
1951 DEBUGFUNC("e1000_config_fc_after_link_up");
1952
1953 /* Check for the case where we have fiber media and auto-neg failed
1954 * so we had to force link. In this case, we need to force the
1955 * configuration of the MAC to match the "fc" parameter.
1956 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001957 if (((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) ||
1958 ((hw->media_type == e1000_media_type_internal_serdes) &&
1959 (hw->autoneg_failed)) ||
1960 ((hw->media_type == e1000_media_type_copper) && (!hw->autoneg))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961 ret_val = e1000_force_mac_fc(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001962 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963 DEBUGOUT("Error forcing flow control settings\n");
1964 return ret_val;
1965 }
1966 }
1967
1968 /* Check for the case where we have copper media and auto-neg is
1969 * enabled. In this case, we need to check and see if Auto-Neg
1970 * has completed, and if so, how the PHY and link partner has
1971 * flow control configured.
1972 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001973 if ((hw->media_type == e1000_media_type_copper) && hw->autoneg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001974 /* Read the MII Status Register and check to see if AutoNeg
1975 * has completed. We read this twice because this reg has
1976 * some "sticky" (latched) bits.
1977 */
1978 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07001979 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980 return ret_val;
1981 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07001982 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983 return ret_val;
1984
Auke Kok8fc897b2006-08-28 14:56:16 -07001985 if (mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986 /* The AutoNeg process has completed, so we now need to
1987 * read both the Auto Negotiation Advertisement Register
1988 * (Address 4) and the Auto_Negotiation Base Page Ability
1989 * Register (Address 5) to determine how flow control was
1990 * negotiated.
1991 */
1992 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV,
1993 &mii_nway_adv_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07001994 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995 return ret_val;
1996 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY,
1997 &mii_nway_lp_ability_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07001998 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999 return ret_val;
2000
2001 /* Two bits in the Auto Negotiation Advertisement Register
2002 * (Address 4) and two bits in the Auto Negotiation Base
2003 * Page Ability Register (Address 5) determine flow control
2004 * for both the PHY and the link partner. The following
2005 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
2006 * 1999, describes these PAUSE resolution bits and how flow
2007 * control is determined based upon these settings.
2008 * NOTE: DC = Don't Care
2009 *
2010 * LOCAL DEVICE | LINK PARTNER
2011 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
2012 *-------|---------|-------|---------|--------------------
Jeff Kirsher11241b12006-09-27 12:53:28 -07002013 * 0 | 0 | DC | DC | E1000_FC_NONE
2014 * 0 | 1 | 0 | DC | E1000_FC_NONE
2015 * 0 | 1 | 1 | 0 | E1000_FC_NONE
2016 * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
2017 * 1 | 0 | 0 | DC | E1000_FC_NONE
2018 * 1 | DC | 1 | DC | E1000_FC_FULL
2019 * 1 | 1 | 0 | 0 | E1000_FC_NONE
2020 * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021 *
2022 */
2023 /* Are both PAUSE bits set to 1? If so, this implies
2024 * Symmetric Flow Control is enabled at both ends. The
2025 * ASM_DIR bits are irrelevant per the spec.
2026 *
2027 * For Symmetric Flow Control:
2028 *
2029 * LOCAL DEVICE | LINK PARTNER
2030 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2031 *-------|---------|-------|---------|--------------------
Jeff Kirsher11241b12006-09-27 12:53:28 -07002032 * 1 | DC | 1 | DC | E1000_FC_FULL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033 *
2034 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002035 if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2036 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037 /* Now we need to check if the user selected RX ONLY
2038 * of pause frames. In this case, we had to advertise
2039 * FULL flow control because we could not advertise RX
2040 * ONLY. Hence, we must now check to see if we need to
2041 * turn OFF the TRANSMISSION of PAUSE frames.
2042 */
Jeff Kirsher11241b12006-09-27 12:53:28 -07002043 if (hw->original_fc == E1000_FC_FULL) {
2044 hw->fc = E1000_FC_FULL;
Auke Koka42a5072006-05-23 13:36:01 -07002045 DEBUGOUT("Flow Control = FULL.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046 } else {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002047 hw->fc = E1000_FC_RX_PAUSE;
Auke Koka42a5072006-05-23 13:36:01 -07002048 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049 }
2050 }
2051 /* For receiving PAUSE frames ONLY.
2052 *
2053 * LOCAL DEVICE | LINK PARTNER
2054 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2055 *-------|---------|-------|---------|--------------------
Jeff Kirsher11241b12006-09-27 12:53:28 -07002056 * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057 *
2058 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002059 else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2060 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2061 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2062 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002063 hw->fc = E1000_FC_TX_PAUSE;
Auke Koka42a5072006-05-23 13:36:01 -07002064 DEBUGOUT("Flow Control = TX PAUSE frames only.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065 }
2066 /* For transmitting PAUSE frames ONLY.
2067 *
2068 * LOCAL DEVICE | LINK PARTNER
2069 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2070 *-------|---------|-------|---------|--------------------
Jeff Kirsher11241b12006-09-27 12:53:28 -07002071 * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072 *
2073 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002074 else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2075 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2076 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2077 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002078 hw->fc = E1000_FC_RX_PAUSE;
Auke Koka42a5072006-05-23 13:36:01 -07002079 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080 }
2081 /* Per the IEEE spec, at this point flow control should be
2082 * disabled. However, we want to consider that we could
2083 * be connected to a legacy switch that doesn't advertise
2084 * desired flow control, but can be forced on the link
2085 * partner. So if we advertised no flow control, that is
2086 * what we will resolve to. If we advertised some kind of
2087 * receive capability (Rx Pause Only or Full Flow Control)
2088 * and the link partner advertised none, we will configure
2089 * ourselves to enable Rx Flow Control only. We can do
2090 * this safely for two reasons: If the link partner really
2091 * didn't want flow control enabled, and we enable Rx, no
2092 * harm done since we won't be receiving any PAUSE frames
2093 * anyway. If the intent on the link partner was to have
2094 * flow control enabled, then by us enabling RX only, we
2095 * can at least receive pause frames and process them.
2096 * This is a good idea because in most cases, since we are
2097 * predominantly a server NIC, more times than not we will
2098 * be asked to delay transmission of packets than asking
2099 * our link partner to pause transmission of frames.
2100 */
Jeff Kirsher11241b12006-09-27 12:53:28 -07002101 else if ((hw->original_fc == E1000_FC_NONE ||
2102 hw->original_fc == E1000_FC_TX_PAUSE) ||
Auke Kok8fc897b2006-08-28 14:56:16 -07002103 hw->fc_strict_ieee) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002104 hw->fc = E1000_FC_NONE;
Auke Koka42a5072006-05-23 13:36:01 -07002105 DEBUGOUT("Flow Control = NONE.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106 } else {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002107 hw->fc = E1000_FC_RX_PAUSE;
Auke Koka42a5072006-05-23 13:36:01 -07002108 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109 }
2110
2111 /* Now we need to do one last check... If we auto-
2112 * negotiated to HALF DUPLEX, flow control should not be
2113 * enabled per IEEE 802.3 spec.
2114 */
2115 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
Auke Kok8fc897b2006-08-28 14:56:16 -07002116 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117 DEBUGOUT("Error getting link speed and duplex\n");
2118 return ret_val;
2119 }
2120
Auke Kok8fc897b2006-08-28 14:56:16 -07002121 if (duplex == HALF_DUPLEX)
Jeff Kirsher11241b12006-09-27 12:53:28 -07002122 hw->fc = E1000_FC_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123
2124 /* Now we call a subroutine to actually force the MAC
2125 * controller to use the correct flow control settings.
2126 */
2127 ret_val = e1000_force_mac_fc(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002128 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129 DEBUGOUT("Error forcing flow control settings\n");
2130 return ret_val;
2131 }
2132 } else {
Auke Koka42a5072006-05-23 13:36:01 -07002133 DEBUGOUT("Copper PHY and Auto Neg has not completed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134 }
2135 }
2136 return E1000_SUCCESS;
2137}
2138
2139/******************************************************************************
2140 * Checks to see if the link status of the hardware has changed.
2141 *
2142 * hw - Struct containing variables accessed by shared code
2143 *
2144 * Called by any function that needs to check the link status of the adapter.
2145 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07002146s32 e1000_check_for_link(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147{
Joe Perches406874a2008-04-03 10:06:32 -07002148 u32 rxcw = 0;
2149 u32 ctrl;
2150 u32 status;
2151 u32 rctl;
2152 u32 icr;
2153 u32 signal = 0;
2154 s32 ret_val;
2155 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156
2157 DEBUGFUNC("e1000_check_for_link");
2158
Joe Perches1dc32912008-07-11 15:17:08 -07002159 ctrl = er32(CTRL);
2160 status = er32(STATUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161
2162 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
2163 * set when the optics detect a signal. On older adapters, it will be
2164 * cleared when there is a signal. This applies to fiber media only.
2165 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002166 if ((hw->media_type == e1000_media_type_fiber) ||
2167 (hw->media_type == e1000_media_type_internal_serdes)) {
Joe Perches1dc32912008-07-11 15:17:08 -07002168 rxcw = er32(RXCW);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169
Auke Kok8fc897b2006-08-28 14:56:16 -07002170 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
Auke Kok8fc897b2006-08-28 14:56:16 -07002172 if (status & E1000_STATUS_LU)
Joe Perchesc3033b02008-03-21 11:06:25 -07002173 hw->get_link_status = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174 }
2175 }
2176
2177 /* If we have a copper PHY then we only want to go out to the PHY
2178 * registers to see if Auto-Neg has completed and/or if our link
2179 * status has changed. The get_link_status flag will be set if we
2180 * receive a Link Status Change interrupt or we have Rx Sequence
2181 * Errors.
2182 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002183 if ((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184 /* First we want to see if the MII Status Register reports
2185 * link. If so, then we want to get the current speed/duplex
2186 * of the PHY.
2187 * Read the register twice since the link bit is sticky.
2188 */
2189 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002190 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191 return ret_val;
2192 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002193 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194 return ret_val;
2195
Auke Kok8fc897b2006-08-28 14:56:16 -07002196 if (phy_data & MII_SR_LINK_STATUS) {
Joe Perchesc3033b02008-03-21 11:06:25 -07002197 hw->get_link_status = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198 /* Check if there was DownShift, must be checked immediately after
2199 * link-up */
2200 e1000_check_downshift(hw);
2201
2202 /* If we are on 82544 or 82543 silicon and speed/duplex
2203 * are forced to 10H or 10F, then we will implement the polarity
2204 * reversal workaround. We disable interrupts first, and upon
2205 * returning, place the devices interrupt state to its previous
2206 * value except for the link status change interrupt which will
2207 * happen due to the execution of this workaround.
2208 */
2209
Auke Kok8fc897b2006-08-28 14:56:16 -07002210 if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
2211 (!hw->autoneg) &&
2212 (hw->forced_speed_duplex == e1000_10_full ||
2213 hw->forced_speed_duplex == e1000_10_half)) {
Joe Perches1dc32912008-07-11 15:17:08 -07002214 ew32(IMC, 0xffffffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215 ret_val = e1000_polarity_reversal_workaround(hw);
Joe Perches1dc32912008-07-11 15:17:08 -07002216 icr = er32(ICR);
2217 ew32(ICS, (icr & ~E1000_ICS_LSC));
2218 ew32(IMS, IMS_ENABLE_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219 }
2220
2221 } else {
2222 /* No link detected */
Joe Perchesc3033b02008-03-21 11:06:25 -07002223 e1000_config_dsp_after_link_change(hw, false);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224 return 0;
2225 }
2226
2227 /* If we are forcing speed/duplex, then we simply return since
2228 * we have already determined whether we have link or not.
2229 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002230 if (!hw->autoneg) return -E1000_ERR_CONFIG;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231
2232 /* optimize the dsp settings for the igp phy */
Joe Perchesc3033b02008-03-21 11:06:25 -07002233 e1000_config_dsp_after_link_change(hw, true);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234
2235 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
2236 * have Si on board that is 82544 or newer, Auto
2237 * Speed Detection takes care of MAC speed/duplex
2238 * configuration. So we only need to configure Collision
2239 * Distance in the MAC. Otherwise, we need to force
2240 * speed/duplex on the MAC to the current PHY speed/duplex
2241 * settings.
2242 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002243 if (hw->mac_type >= e1000_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002244 e1000_config_collision_dist(hw);
2245 else {
2246 ret_val = e1000_config_mac_to_phy(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002247 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248 DEBUGOUT("Error configuring MAC to PHY settings\n");
2249 return ret_val;
2250 }
2251 }
2252
2253 /* Configure Flow Control now that Auto-Neg has completed. First, we
2254 * need to restore the desired flow control settings because we may
2255 * have had to re-autoneg with a different link partner.
2256 */
2257 ret_val = e1000_config_fc_after_link_up(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002258 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259 DEBUGOUT("Error configuring flow control\n");
2260 return ret_val;
2261 }
2262
2263 /* At this point we know that we are on copper and we have
2264 * auto-negotiated link. These are conditions for checking the link
2265 * partner capability register. We use the link speed to determine if
2266 * TBI compatibility needs to be turned on or off. If the link is not
2267 * at gigabit speed, then TBI compatibility is not needed. If we are
2268 * at gigabit speed, we turn on TBI compatibility.
2269 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002270 if (hw->tbi_compatibility_en) {
Joe Perches406874a2008-04-03 10:06:32 -07002271 u16 speed, duplex;
Auke Kok592600a2006-06-27 09:08:09 -07002272 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
2273 if (ret_val) {
2274 DEBUGOUT("Error getting link speed and duplex\n");
2275 return ret_val;
2276 }
2277 if (speed != SPEED_1000) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278 /* If link speed is not set to gigabit speed, we do not need
2279 * to enable TBI compatibility.
2280 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002281 if (hw->tbi_compatibility_on) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282 /* If we previously were in the mode, turn it off. */
Joe Perches1dc32912008-07-11 15:17:08 -07002283 rctl = er32(RCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284 rctl &= ~E1000_RCTL_SBP;
Joe Perches1dc32912008-07-11 15:17:08 -07002285 ew32(RCTL, rctl);
Joe Perchesc3033b02008-03-21 11:06:25 -07002286 hw->tbi_compatibility_on = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287 }
2288 } else {
2289 /* If TBI compatibility is was previously off, turn it on. For
2290 * compatibility with a TBI link partner, we will store bad
2291 * packets. Some frames have an additional byte on the end and
Anand Gadiyarfd589a82009-07-16 17:13:03 +02002292 * will look like CRC errors to the hardware.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002294 if (!hw->tbi_compatibility_on) {
Joe Perchesc3033b02008-03-21 11:06:25 -07002295 hw->tbi_compatibility_on = true;
Joe Perches1dc32912008-07-11 15:17:08 -07002296 rctl = er32(RCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297 rctl |= E1000_RCTL_SBP;
Joe Perches1dc32912008-07-11 15:17:08 -07002298 ew32(RCTL, rctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299 }
2300 }
2301 }
2302 }
2303 /* If we don't have link (auto-negotiation failed or link partner cannot
2304 * auto-negotiate), the cable is plugged in (we have signal), and our
2305 * link partner is not trying to auto-negotiate with us (we are receiving
2306 * idles or data), we need to force link up. We also need to give
2307 * auto-negotiation time to complete, in case the cable was just plugged
2308 * in. The autoneg_failed flag does this.
2309 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002310 else if ((((hw->media_type == e1000_media_type_fiber) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311 ((ctrl & E1000_CTRL_SWDPIN1) == signal)) ||
Auke Kok8fc897b2006-08-28 14:56:16 -07002312 (hw->media_type == e1000_media_type_internal_serdes)) &&
2313 (!(status & E1000_STATUS_LU)) &&
2314 (!(rxcw & E1000_RXCW_C))) {
2315 if (hw->autoneg_failed == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316 hw->autoneg_failed = 1;
2317 return 0;
2318 }
Auke Koka42a5072006-05-23 13:36:01 -07002319 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320
2321 /* Disable auto-negotiation in the TXCW register */
Joe Perches1dc32912008-07-11 15:17:08 -07002322 ew32(TXCW, (hw->txcw & ~E1000_TXCW_ANE));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323
2324 /* Force link-up and also force full-duplex. */
Joe Perches1dc32912008-07-11 15:17:08 -07002325 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
Joe Perches1dc32912008-07-11 15:17:08 -07002327 ew32(CTRL, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328
2329 /* Configure Flow Control after forcing link up. */
2330 ret_val = e1000_config_fc_after_link_up(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002331 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332 DEBUGOUT("Error configuring flow control\n");
2333 return ret_val;
2334 }
2335 }
2336 /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
2337 * auto-negotiation in the TXCW register and disable forced link in the
2338 * Device Control register in an attempt to auto-negotiate with our link
2339 * partner.
2340 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002341 else if (((hw->media_type == e1000_media_type_fiber) ||
2342 (hw->media_type == e1000_media_type_internal_serdes)) &&
2343 (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
Auke Koka42a5072006-05-23 13:36:01 -07002344 DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\n");
Joe Perches1dc32912008-07-11 15:17:08 -07002345 ew32(TXCW, hw->txcw);
2346 ew32(CTRL, (ctrl & ~E1000_CTRL_SLU));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347
Joe Perchesc3033b02008-03-21 11:06:25 -07002348 hw->serdes_link_down = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349 }
2350 /* If we force link for non-auto-negotiation switch, check link status
2351 * based on MAC synchronization for internal serdes media type.
2352 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002353 else if ((hw->media_type == e1000_media_type_internal_serdes) &&
Joe Perches1dc32912008-07-11 15:17:08 -07002354 !(E1000_TXCW_ANE & er32(TXCW))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355 /* SYNCH bit and IV bit are sticky. */
2356 udelay(10);
Joe Perches1dc32912008-07-11 15:17:08 -07002357 if (E1000_RXCW_SYNCH & er32(RXCW)) {
Auke Kok8fc897b2006-08-28 14:56:16 -07002358 if (!(rxcw & E1000_RXCW_IV)) {
Joe Perchesc3033b02008-03-21 11:06:25 -07002359 hw->serdes_link_down = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360 DEBUGOUT("SERDES: Link is up.\n");
2361 }
2362 } else {
Joe Perchesc3033b02008-03-21 11:06:25 -07002363 hw->serdes_link_down = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364 DEBUGOUT("SERDES: Link is down.\n");
2365 }
2366 }
Auke Kok8fc897b2006-08-28 14:56:16 -07002367 if ((hw->media_type == e1000_media_type_internal_serdes) &&
Joe Perches1dc32912008-07-11 15:17:08 -07002368 (E1000_TXCW_ANE & er32(TXCW))) {
2369 hw->serdes_link_down = !(E1000_STATUS_LU & er32(STATUS));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370 }
2371 return E1000_SUCCESS;
2372}
2373
2374/******************************************************************************
2375 * Detects the current speed and duplex settings of the hardware.
2376 *
2377 * hw - Struct containing variables accessed by shared code
2378 * speed - Speed of the connection
2379 * duplex - Duplex setting of the connection
2380 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07002381s32 e1000_get_speed_and_duplex(struct e1000_hw *hw, u16 *speed, u16 *duplex)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382{
Joe Perches406874a2008-04-03 10:06:32 -07002383 u32 status;
2384 s32 ret_val;
2385 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386
2387 DEBUGFUNC("e1000_get_speed_and_duplex");
2388
Auke Kok8fc897b2006-08-28 14:56:16 -07002389 if (hw->mac_type >= e1000_82543) {
Joe Perches1dc32912008-07-11 15:17:08 -07002390 status = er32(STATUS);
Auke Kok8fc897b2006-08-28 14:56:16 -07002391 if (status & E1000_STATUS_SPEED_1000) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392 *speed = SPEED_1000;
2393 DEBUGOUT("1000 Mbs, ");
Auke Kok8fc897b2006-08-28 14:56:16 -07002394 } else if (status & E1000_STATUS_SPEED_100) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395 *speed = SPEED_100;
2396 DEBUGOUT("100 Mbs, ");
2397 } else {
2398 *speed = SPEED_10;
2399 DEBUGOUT("10 Mbs, ");
2400 }
2401
Auke Kok8fc897b2006-08-28 14:56:16 -07002402 if (status & E1000_STATUS_FD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403 *duplex = FULL_DUPLEX;
Auke Koka42a5072006-05-23 13:36:01 -07002404 DEBUGOUT("Full Duplex\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002405 } else {
2406 *duplex = HALF_DUPLEX;
Auke Koka42a5072006-05-23 13:36:01 -07002407 DEBUGOUT(" Half Duplex\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408 }
2409 } else {
Auke Koka42a5072006-05-23 13:36:01 -07002410 DEBUGOUT("1000 Mbs, Full Duplex\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411 *speed = SPEED_1000;
2412 *duplex = FULL_DUPLEX;
2413 }
2414
2415 /* IGP01 PHY may advertise full duplex operation after speed downgrade even
2416 * if it is operating at half duplex. Here we set the duplex settings to
2417 * match the duplex in the link partner's capabilities.
2418 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002419 if (hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002421 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422 return ret_val;
2423
Auke Kok8fc897b2006-08-28 14:56:16 -07002424 if (!(phy_data & NWAY_ER_LP_NWAY_CAPS))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425 *duplex = HALF_DUPLEX;
2426 else {
2427 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002428 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429 return ret_val;
Auke Kok8fc897b2006-08-28 14:56:16 -07002430 if ((*speed == SPEED_100 && !(phy_data & NWAY_LPAR_100TX_FD_CAPS)) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431 (*speed == SPEED_10 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
2432 *duplex = HALF_DUPLEX;
2433 }
2434 }
2435
2436 return E1000_SUCCESS;
2437}
2438
2439/******************************************************************************
2440* Blocks until autoneg completes or times out (~4.5 seconds)
2441*
2442* hw - Struct containing variables accessed by shared code
2443******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07002444static s32 e1000_wait_autoneg(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445{
Joe Perches406874a2008-04-03 10:06:32 -07002446 s32 ret_val;
2447 u16 i;
2448 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449
2450 DEBUGFUNC("e1000_wait_autoneg");
2451 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
2452
2453 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
Auke Kok8fc897b2006-08-28 14:56:16 -07002454 for (i = PHY_AUTO_NEG_TIME; i > 0; i--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455 /* Read the MII Status Register and wait for Auto-Neg
2456 * Complete bit to be set.
2457 */
2458 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002459 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002460 return ret_val;
2461 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002462 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463 return ret_val;
Auke Kok8fc897b2006-08-28 14:56:16 -07002464 if (phy_data & MII_SR_AUTONEG_COMPLETE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002465 return E1000_SUCCESS;
2466 }
Jeff Garzikf8ec4732006-09-19 15:27:07 -04002467 msleep(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468 }
2469 return E1000_SUCCESS;
2470}
2471
2472/******************************************************************************
2473* Raises the Management Data Clock
2474*
2475* hw - Struct containing variables accessed by shared code
2476* ctrl - Device control register's current value
2477******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07002478static void e1000_raise_mdi_clk(struct e1000_hw *hw, u32 *ctrl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479{
2480 /* Raise the clock input to the Management Data Clock (by setting the MDC
2481 * bit), and then delay 10 microseconds.
2482 */
Joe Perches1dc32912008-07-11 15:17:08 -07002483 ew32(CTRL, (*ctrl | E1000_CTRL_MDC));
2484 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485 udelay(10);
2486}
2487
2488/******************************************************************************
2489* Lowers the Management Data Clock
2490*
2491* hw - Struct containing variables accessed by shared code
2492* ctrl - Device control register's current value
2493******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07002494static void e1000_lower_mdi_clk(struct e1000_hw *hw, u32 *ctrl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495{
2496 /* Lower the clock input to the Management Data Clock (by clearing the MDC
2497 * bit), and then delay 10 microseconds.
2498 */
Joe Perches1dc32912008-07-11 15:17:08 -07002499 ew32(CTRL, (*ctrl & ~E1000_CTRL_MDC));
2500 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002501 udelay(10);
2502}
2503
2504/******************************************************************************
2505* Shifts data bits out to the PHY
2506*
2507* hw - Struct containing variables accessed by shared code
2508* data - Data to send out to the PHY
2509* count - Number of bits to shift out
2510*
2511* Bits are shifted out in MSB to LSB order.
2512******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07002513static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, u32 data, u16 count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514{
Joe Perches406874a2008-04-03 10:06:32 -07002515 u32 ctrl;
2516 u32 mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517
2518 /* We need to shift "count" number of bits out to the PHY. So, the value
2519 * in the "data" parameter will be shifted out to the PHY one bit at a
2520 * time. In order to do this, "data" must be broken down into bits.
2521 */
2522 mask = 0x01;
2523 mask <<= (count - 1);
2524
Joe Perches1dc32912008-07-11 15:17:08 -07002525 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526
2527 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
2528 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
2529
Auke Kok8fc897b2006-08-28 14:56:16 -07002530 while (mask) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531 /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
2532 * then raising and lowering the Management Data Clock. A "0" is
2533 * shifted out to the PHY by setting the MDIO bit to "0" and then
2534 * raising and lowering the clock.
2535 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002536 if (data & mask)
2537 ctrl |= E1000_CTRL_MDIO;
2538 else
2539 ctrl &= ~E1000_CTRL_MDIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540
Joe Perches1dc32912008-07-11 15:17:08 -07002541 ew32(CTRL, ctrl);
2542 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543
2544 udelay(10);
2545
2546 e1000_raise_mdi_clk(hw, &ctrl);
2547 e1000_lower_mdi_clk(hw, &ctrl);
2548
2549 mask = mask >> 1;
2550 }
2551}
2552
2553/******************************************************************************
2554* Shifts data bits in from the PHY
2555*
2556* hw - Struct containing variables accessed by shared code
2557*
2558* Bits are shifted in in MSB to LSB order.
2559******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07002560static u16 e1000_shift_in_mdi_bits(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561{
Joe Perches406874a2008-04-03 10:06:32 -07002562 u32 ctrl;
2563 u16 data = 0;
2564 u8 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565
2566 /* In order to read a register from the PHY, we need to shift in a total
2567 * of 18 bits from the PHY. The first two bit (turnaround) times are used
2568 * to avoid contention on the MDIO pin when a read operation is performed.
2569 * These two bits are ignored by us and thrown away. Bits are "shifted in"
2570 * by raising the input to the Management Data Clock (setting the MDC bit),
2571 * and then reading the value of the MDIO bit.
2572 */
Joe Perches1dc32912008-07-11 15:17:08 -07002573 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574
2575 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
2576 ctrl &= ~E1000_CTRL_MDIO_DIR;
2577 ctrl &= ~E1000_CTRL_MDIO;
2578
Joe Perches1dc32912008-07-11 15:17:08 -07002579 ew32(CTRL, ctrl);
2580 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002581
2582 /* Raise and Lower the clock before reading in the data. This accounts for
2583 * the turnaround bits. The first clock occurred when we clocked out the
2584 * last bit of the Register Address.
2585 */
2586 e1000_raise_mdi_clk(hw, &ctrl);
2587 e1000_lower_mdi_clk(hw, &ctrl);
2588
Auke Kok8fc897b2006-08-28 14:56:16 -07002589 for (data = 0, i = 0; i < 16; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590 data = data << 1;
2591 e1000_raise_mdi_clk(hw, &ctrl);
Joe Perches1dc32912008-07-11 15:17:08 -07002592 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002593 /* Check to see if we shifted in a "1". */
Auke Kok8fc897b2006-08-28 14:56:16 -07002594 if (ctrl & E1000_CTRL_MDIO)
2595 data |= 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596 e1000_lower_mdi_clk(hw, &ctrl);
2597 }
2598
2599 e1000_raise_mdi_clk(hw, &ctrl);
2600 e1000_lower_mdi_clk(hw, &ctrl);
2601
2602 return data;
2603}
2604
2605/*****************************************************************************
2606* Reads the value from a PHY register, if the value is on a specific non zero
2607* page, sets the page first.
2608* hw - Struct containing variables accessed by shared code
2609* reg_addr - address of the PHY register to read
2610******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07002611s32 e1000_read_phy_reg(struct e1000_hw *hw, u32 reg_addr, u16 *phy_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612{
Joe Perches406874a2008-04-03 10:06:32 -07002613 u32 ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002614
2615 DEBUGFUNC("e1000_read_phy_reg");
2616
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00002617 if ((hw->phy_type == e1000_phy_igp) &&
2618 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002619 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
Joe Perches406874a2008-04-03 10:06:32 -07002620 (u16)reg_addr);
Jesse Brandeburg282b1772009-09-25 12:16:39 +00002621 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002622 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002623 }
2624
2625 ret_val = e1000_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
2626 phy_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627 return ret_val;
2628}
2629
Joe Perches64798842008-07-11 15:17:02 -07002630static s32 e1000_read_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr,
2631 u16 *phy_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002632{
Joe Perches406874a2008-04-03 10:06:32 -07002633 u32 i;
2634 u32 mdic = 0;
2635 const u32 phy_addr = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636
2637 DEBUGFUNC("e1000_read_phy_reg_ex");
2638
Auke Kok8fc897b2006-08-28 14:56:16 -07002639 if (reg_addr > MAX_PHY_REG_ADDRESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002640 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
2641 return -E1000_ERR_PARAM;
2642 }
2643
Auke Kok8fc897b2006-08-28 14:56:16 -07002644 if (hw->mac_type > e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645 /* Set up Op-code, Phy Address, and register address in the MDI
2646 * Control register. The MAC will take care of interfacing with the
2647 * PHY to retrieve the desired data.
2648 */
2649 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
2650 (phy_addr << E1000_MDIC_PHY_SHIFT) |
2651 (E1000_MDIC_OP_READ));
2652
Joe Perches1dc32912008-07-11 15:17:08 -07002653 ew32(MDIC, mdic);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654
2655 /* Poll the ready bit to see if the MDI read completed */
Auke Kok8fc897b2006-08-28 14:56:16 -07002656 for (i = 0; i < 64; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657 udelay(50);
Joe Perches1dc32912008-07-11 15:17:08 -07002658 mdic = er32(MDIC);
Auke Kok8fc897b2006-08-28 14:56:16 -07002659 if (mdic & E1000_MDIC_READY) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660 }
Auke Kok8fc897b2006-08-28 14:56:16 -07002661 if (!(mdic & E1000_MDIC_READY)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662 DEBUGOUT("MDI Read did not complete\n");
2663 return -E1000_ERR_PHY;
2664 }
Auke Kok8fc897b2006-08-28 14:56:16 -07002665 if (mdic & E1000_MDIC_ERROR) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002666 DEBUGOUT("MDI Error\n");
2667 return -E1000_ERR_PHY;
2668 }
Joe Perchese982f172008-07-11 15:17:18 -07002669 *phy_data = (u16)mdic;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670 } else {
2671 /* We must first send a preamble through the MDIO pin to signal the
2672 * beginning of an MII instruction. This is done by sending 32
2673 * consecutive "1" bits.
2674 */
2675 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
2676
2677 /* Now combine the next few fields that are required for a read
2678 * operation. We use this method instead of calling the
2679 * e1000_shift_out_mdi_bits routine five different times. The format of
2680 * a MII read instruction consists of a shift out of 14 bits and is
2681 * defined as follows:
2682 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
2683 * followed by a shift in of 18 bits. This first two bits shifted in
2684 * are TurnAround bits used to avoid contention on the MDIO pin when a
2685 * READ operation is performed. These two bits are thrown away
2686 * followed by a shift in of 16 bits which contains the desired data.
2687 */
2688 mdic = ((reg_addr) | (phy_addr << 5) |
2689 (PHY_OP_READ << 10) | (PHY_SOF << 12));
2690
2691 e1000_shift_out_mdi_bits(hw, mdic, 14);
2692
2693 /* Now that we've shifted out the read command to the MII, we need to
2694 * "shift in" the 16-bit value (18 total bits) of the requested PHY
2695 * register address.
2696 */
2697 *phy_data = e1000_shift_in_mdi_bits(hw);
2698 }
2699 return E1000_SUCCESS;
2700}
2701
2702/******************************************************************************
2703* Writes a value to a PHY register
2704*
2705* hw - Struct containing variables accessed by shared code
2706* reg_addr - address of the PHY register to write
2707* data - data to write to the PHY
2708******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07002709s32 e1000_write_phy_reg(struct e1000_hw *hw, u32 reg_addr, u16 phy_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710{
Joe Perches406874a2008-04-03 10:06:32 -07002711 u32 ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002712
2713 DEBUGFUNC("e1000_write_phy_reg");
2714
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00002715 if ((hw->phy_type == e1000_phy_igp) &&
2716 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
Joe Perches406874a2008-04-03 10:06:32 -07002718 (u16)reg_addr);
Jesse Brandeburg282b1772009-09-25 12:16:39 +00002719 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002720 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002721 }
2722
2723 ret_val = e1000_write_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
2724 phy_data);
2725
2726 return ret_val;
2727}
2728
Joe Perches64798842008-07-11 15:17:02 -07002729static s32 e1000_write_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr,
2730 u16 phy_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002731{
Joe Perches406874a2008-04-03 10:06:32 -07002732 u32 i;
2733 u32 mdic = 0;
2734 const u32 phy_addr = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002735
2736 DEBUGFUNC("e1000_write_phy_reg_ex");
2737
Auke Kok8fc897b2006-08-28 14:56:16 -07002738 if (reg_addr > MAX_PHY_REG_ADDRESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002739 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
2740 return -E1000_ERR_PARAM;
2741 }
2742
Auke Kok8fc897b2006-08-28 14:56:16 -07002743 if (hw->mac_type > e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002744 /* Set up Op-code, Phy Address, register address, and data intended
2745 * for the PHY register in the MDI Control register. The MAC will take
2746 * care of interfacing with the PHY to send the desired data.
2747 */
Joe Perchese982f172008-07-11 15:17:18 -07002748 mdic = (((u32)phy_data) |
Linus Torvalds1da177e2005-04-16 15:20:36 -07002749 (reg_addr << E1000_MDIC_REG_SHIFT) |
2750 (phy_addr << E1000_MDIC_PHY_SHIFT) |
2751 (E1000_MDIC_OP_WRITE));
2752
Joe Perches1dc32912008-07-11 15:17:08 -07002753 ew32(MDIC, mdic);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002754
2755 /* Poll the ready bit to see if the MDI read completed */
Auke Kok8fc897b2006-08-28 14:56:16 -07002756 for (i = 0; i < 641; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002757 udelay(5);
Joe Perches1dc32912008-07-11 15:17:08 -07002758 mdic = er32(MDIC);
Auke Kok8fc897b2006-08-28 14:56:16 -07002759 if (mdic & E1000_MDIC_READY) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002760 }
Auke Kok8fc897b2006-08-28 14:56:16 -07002761 if (!(mdic & E1000_MDIC_READY)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002762 DEBUGOUT("MDI Write did not complete\n");
2763 return -E1000_ERR_PHY;
2764 }
2765 } else {
2766 /* We'll need to use the SW defined pins to shift the write command
2767 * out to the PHY. We first send a preamble to the PHY to signal the
2768 * beginning of the MII instruction. This is done by sending 32
2769 * consecutive "1" bits.
2770 */
2771 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
2772
2773 /* Now combine the remaining required fields that will indicate a
2774 * write operation. We use this method instead of calling the
2775 * e1000_shift_out_mdi_bits routine for each field in the command. The
2776 * format of a MII write instruction is as follows:
2777 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
2778 */
2779 mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
2780 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
2781 mdic <<= 16;
Joe Perchese982f172008-07-11 15:17:18 -07002782 mdic |= (u32)phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002783
2784 e1000_shift_out_mdi_bits(hw, mdic, 32);
2785 }
2786
2787 return E1000_SUCCESS;
2788}
2789
2790/******************************************************************************
2791* Returns the PHY to the power-on reset state
2792*
2793* hw - Struct containing variables accessed by shared code
2794******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07002795s32 e1000_phy_hw_reset(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002796{
Joe Perches406874a2008-04-03 10:06:32 -07002797 u32 ctrl, ctrl_ext;
2798 u32 led_ctrl;
2799 s32 ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002800
2801 DEBUGFUNC("e1000_phy_hw_reset");
2802
2803 DEBUGOUT("Resetting Phy...\n");
2804
Auke Kok8fc897b2006-08-28 14:56:16 -07002805 if (hw->mac_type > e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002806 /* Read the device control register and assert the E1000_CTRL_PHY_RST
2807 * bit. Then, take it out of reset.
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00002808 * For e1000 hardware, we delay for 10ms between the assert
2809 * and deassert.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002810 */
Joe Perches1dc32912008-07-11 15:17:08 -07002811 ctrl = er32(CTRL);
2812 ew32(CTRL, ctrl | E1000_CTRL_PHY_RST);
2813 E1000_WRITE_FLUSH();
Auke Kok76c224b2006-05-23 13:36:06 -07002814
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00002815 msleep(10);
Auke Kok76c224b2006-05-23 13:36:06 -07002816
Joe Perches1dc32912008-07-11 15:17:08 -07002817 ew32(CTRL, ctrl);
2818 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002819 } else {
2820 /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
2821 * bit to put the PHY into reset. Then, take it out of reset.
2822 */
Joe Perches1dc32912008-07-11 15:17:08 -07002823 ctrl_ext = er32(CTRL_EXT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002824 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
2825 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
Joe Perches1dc32912008-07-11 15:17:08 -07002826 ew32(CTRL_EXT, ctrl_ext);
2827 E1000_WRITE_FLUSH();
Jeff Garzikf8ec4732006-09-19 15:27:07 -04002828 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002829 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
Joe Perches1dc32912008-07-11 15:17:08 -07002830 ew32(CTRL_EXT, ctrl_ext);
2831 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002832 }
2833 udelay(150);
2834
Auke Kok8fc897b2006-08-28 14:56:16 -07002835 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002836 /* Configure activity LED after PHY reset */
Joe Perches1dc32912008-07-11 15:17:08 -07002837 led_ctrl = er32(LEDCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002838 led_ctrl &= IGP_ACTIVITY_LED_MASK;
2839 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
Joe Perches1dc32912008-07-11 15:17:08 -07002840 ew32(LEDCTL, led_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002841 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002842
2843 /* Wait for FW to finish PHY configuration. */
2844 ret_val = e1000_get_phy_cfg_done(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002845 if (ret_val != E1000_SUCCESS)
2846 return ret_val;
Auke Kok8fc897b2006-08-28 14:56:16 -07002847
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002848 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002849}
2850
2851/******************************************************************************
2852* Resets the PHY
2853*
2854* hw - Struct containing variables accessed by shared code
2855*
Matt LaPlante0779bf22006-11-30 05:24:39 +01002856* Sets bit 15 of the MII Control register
Linus Torvalds1da177e2005-04-16 15:20:36 -07002857******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07002858s32 e1000_phy_reset(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002859{
Joe Perches406874a2008-04-03 10:06:32 -07002860 s32 ret_val;
2861 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002862
2863 DEBUGFUNC("e1000_phy_reset");
2864
Jeff Kirsher2a88c172006-09-27 12:54:05 -07002865 switch (hw->phy_type) {
2866 case e1000_phy_igp:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002867 ret_val = e1000_phy_hw_reset(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002868 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002869 return ret_val;
2870 break;
2871 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002872 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002873 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002874 return ret_val;
2875
2876 phy_data |= MII_CR_RESET;
2877 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002878 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002879 return ret_val;
2880
2881 udelay(1);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002882 break;
2883 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002884
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00002885 if (hw->phy_type == e1000_phy_igp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002886 e1000_phy_init_script(hw);
2887
2888 return E1000_SUCCESS;
2889}
2890
2891/******************************************************************************
2892* Probes the expected PHY address for known PHY IDs
2893*
2894* hw - Struct containing variables accessed by shared code
2895******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07002896static s32 e1000_detect_gig_phy(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002897{
Joe Perches406874a2008-04-03 10:06:32 -07002898 s32 phy_init_status, ret_val;
2899 u16 phy_id_high, phy_id_low;
Joe Perchesc3033b02008-03-21 11:06:25 -07002900 bool match = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002901
2902 DEBUGFUNC("e1000_detect_gig_phy");
2903
Jeff Kirsher2a88c172006-09-27 12:54:05 -07002904 if (hw->phy_id != 0)
2905 return E1000_SUCCESS;
2906
Linus Torvalds1da177e2005-04-16 15:20:36 -07002907 /* Read the PHY ID Registers to identify which PHY is onboard. */
2908 ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
Auke Kokcd94dd02006-06-27 09:08:22 -07002909 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002910 return ret_val;
2911
Joe Perchese982f172008-07-11 15:17:18 -07002912 hw->phy_id = (u32)(phy_id_high << 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002913 udelay(20);
2914 ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
Auke Kok8fc897b2006-08-28 14:56:16 -07002915 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002916 return ret_val;
2917
Joe Perchese982f172008-07-11 15:17:18 -07002918 hw->phy_id |= (u32)(phy_id_low & PHY_REVISION_MASK);
2919 hw->phy_revision = (u32)phy_id_low & ~PHY_REVISION_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002920
Auke Kok8fc897b2006-08-28 14:56:16 -07002921 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002922 case e1000_82543:
Joe Perchesc3033b02008-03-21 11:06:25 -07002923 if (hw->phy_id == M88E1000_E_PHY_ID) match = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002924 break;
2925 case e1000_82544:
Joe Perchesc3033b02008-03-21 11:06:25 -07002926 if (hw->phy_id == M88E1000_I_PHY_ID) match = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002927 break;
2928 case e1000_82540:
2929 case e1000_82545:
2930 case e1000_82545_rev_3:
2931 case e1000_82546:
2932 case e1000_82546_rev_3:
Joe Perchesc3033b02008-03-21 11:06:25 -07002933 if (hw->phy_id == M88E1011_I_PHY_ID) match = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002934 break;
2935 case e1000_82541:
2936 case e1000_82541_rev_2:
2937 case e1000_82547:
2938 case e1000_82547_rev_2:
Joe Perchesc3033b02008-03-21 11:06:25 -07002939 if (hw->phy_id == IGP01E1000_I_PHY_ID) match = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002940 break;
2941 default:
2942 DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type);
2943 return -E1000_ERR_CONFIG;
2944 }
2945 phy_init_status = e1000_set_phy_type(hw);
2946
2947 if ((match) && (phy_init_status == E1000_SUCCESS)) {
2948 DEBUGOUT1("PHY ID 0x%X detected\n", hw->phy_id);
2949 return E1000_SUCCESS;
2950 }
2951 DEBUGOUT1("Invalid PHY ID 0x%X\n", hw->phy_id);
2952 return -E1000_ERR_PHY;
2953}
2954
2955/******************************************************************************
2956* Resets the PHY's DSP
2957*
2958* hw - Struct containing variables accessed by shared code
2959******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07002960static s32 e1000_phy_reset_dsp(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002961{
Joe Perches406874a2008-04-03 10:06:32 -07002962 s32 ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002963 DEBUGFUNC("e1000_phy_reset_dsp");
2964
2965 do {
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00002966 ret_val = e1000_write_phy_reg(hw, 29, 0x001d);
2967 if (ret_val) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002968 ret_val = e1000_write_phy_reg(hw, 30, 0x00c1);
Auke Kok8fc897b2006-08-28 14:56:16 -07002969 if (ret_val) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002970 ret_val = e1000_write_phy_reg(hw, 30, 0x0000);
Auke Kok8fc897b2006-08-28 14:56:16 -07002971 if (ret_val) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002972 ret_val = E1000_SUCCESS;
Auke Kok8fc897b2006-08-28 14:56:16 -07002973 } while (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002974
2975 return ret_val;
2976}
2977
2978/******************************************************************************
2979* Get PHY information from various PHY registers for igp PHY only.
2980*
2981* hw - Struct containing variables accessed by shared code
2982* phy_info - PHY information structure
2983******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07002984static s32 e1000_phy_igp_get_info(struct e1000_hw *hw,
2985 struct e1000_phy_info *phy_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002986{
Joe Perches406874a2008-04-03 10:06:32 -07002987 s32 ret_val;
2988 u16 phy_data, min_length, max_length, average;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07002989 e1000_rev_polarity polarity;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002990
2991 DEBUGFUNC("e1000_phy_igp_get_info");
2992
2993 /* The downshift status is checked only once, after link is established,
2994 * and it stored in the hw->speed_downgraded parameter. */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002995 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002996
2997 /* IGP01E1000 does not need to support it. */
2998 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
2999
3000 /* IGP01E1000 always correct polarity reversal */
3001 phy_info->polarity_correction = e1000_polarity_reversal_enabled;
3002
3003 /* Check polarity status */
3004 ret_val = e1000_check_polarity(hw, &polarity);
Auke Kok8fc897b2006-08-28 14:56:16 -07003005 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003006 return ret_val;
3007
3008 phy_info->cable_polarity = polarity;
3009
3010 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003011 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003012 return ret_val;
3013
Jeff Kirsher70c6f302006-09-27 12:53:31 -07003014 phy_info->mdix_mode = (e1000_auto_x_mode)((phy_data & IGP01E1000_PSSR_MDIX) >>
3015 IGP01E1000_PSSR_MDIX_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003016
Auke Kok8fc897b2006-08-28 14:56:16 -07003017 if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
Linus Torvalds1da177e2005-04-16 15:20:36 -07003018 IGP01E1000_PSSR_SPEED_1000MBPS) {
3019 /* Local/Remote Receiver Information are only valid at 1000 Mbps */
3020 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003021 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022 return ret_val;
3023
Jeff Kirsher70c6f302006-09-27 12:53:31 -07003024 phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
3025 SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
3026 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
3027 phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
3028 SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
3029 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003030
3031 /* Get cable length */
3032 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
Auke Kok8fc897b2006-08-28 14:56:16 -07003033 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003034 return ret_val;
3035
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003036 /* Translate to old method */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003037 average = (max_length + min_length) / 2;
3038
Auke Kok8fc897b2006-08-28 14:56:16 -07003039 if (average <= e1000_igp_cable_length_50)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003040 phy_info->cable_length = e1000_cable_length_50;
Auke Kok8fc897b2006-08-28 14:56:16 -07003041 else if (average <= e1000_igp_cable_length_80)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003042 phy_info->cable_length = e1000_cable_length_50_80;
Auke Kok8fc897b2006-08-28 14:56:16 -07003043 else if (average <= e1000_igp_cable_length_110)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003044 phy_info->cable_length = e1000_cable_length_80_110;
Auke Kok8fc897b2006-08-28 14:56:16 -07003045 else if (average <= e1000_igp_cable_length_140)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003046 phy_info->cable_length = e1000_cable_length_110_140;
3047 else
3048 phy_info->cable_length = e1000_cable_length_140;
3049 }
3050
3051 return E1000_SUCCESS;
3052}
3053
Auke Kokd37ea5d2006-06-27 09:08:17 -07003054
3055/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07003056* Get PHY information from various PHY registers fot m88 PHY only.
3057*
3058* hw - Struct containing variables accessed by shared code
3059* phy_info - PHY information structure
3060******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003061static s32 e1000_phy_m88_get_info(struct e1000_hw *hw,
3062 struct e1000_phy_info *phy_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003063{
Joe Perches406874a2008-04-03 10:06:32 -07003064 s32 ret_val;
3065 u16 phy_data;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07003066 e1000_rev_polarity polarity;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003067
3068 DEBUGFUNC("e1000_phy_m88_get_info");
3069
3070 /* The downshift status is checked only once, after link is established,
3071 * and it stored in the hw->speed_downgraded parameter. */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003072 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003073
3074 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003075 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003076 return ret_val;
3077
3078 phy_info->extended_10bt_distance =
Jeff Kirsher70c6f302006-09-27 12:53:31 -07003079 ((phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >>
3080 M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT) ?
3081 e1000_10bt_ext_dist_enable_lower : e1000_10bt_ext_dist_enable_normal;
3082
Linus Torvalds1da177e2005-04-16 15:20:36 -07003083 phy_info->polarity_correction =
Jeff Kirsher70c6f302006-09-27 12:53:31 -07003084 ((phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >>
3085 M88E1000_PSCR_POLARITY_REVERSAL_SHIFT) ?
3086 e1000_polarity_reversal_disabled : e1000_polarity_reversal_enabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003087
3088 /* Check polarity status */
3089 ret_val = e1000_check_polarity(hw, &polarity);
Auke Kok8fc897b2006-08-28 14:56:16 -07003090 if (ret_val)
Auke Kok76c224b2006-05-23 13:36:06 -07003091 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003092 phy_info->cable_polarity = polarity;
3093
3094 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003095 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003096 return ret_val;
3097
Jeff Kirsher70c6f302006-09-27 12:53:31 -07003098 phy_info->mdix_mode = (e1000_auto_x_mode)((phy_data & M88E1000_PSSR_MDIX) >>
3099 M88E1000_PSSR_MDIX_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003100
3101 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
3102 /* Cable Length Estimation and Local/Remote Receiver Information
3103 * are only valid at 1000 Mbps.
3104 */
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00003105 phy_info->cable_length = (e1000_cable_length)((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
3106 M88E1000_PSSR_CABLE_LENGTH_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003107
3108 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003109 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003110 return ret_val;
3111
Jeff Kirsher70c6f302006-09-27 12:53:31 -07003112 phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
3113 SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
3114 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
3115 phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
3116 SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
3117 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003118
Linus Torvalds1da177e2005-04-16 15:20:36 -07003119 }
3120
3121 return E1000_SUCCESS;
3122}
3123
3124/******************************************************************************
3125* Get PHY information from various PHY registers
3126*
3127* hw - Struct containing variables accessed by shared code
3128* phy_info - PHY information structure
3129******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003130s32 e1000_phy_get_info(struct e1000_hw *hw, struct e1000_phy_info *phy_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003131{
Joe Perches406874a2008-04-03 10:06:32 -07003132 s32 ret_val;
3133 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003134
3135 DEBUGFUNC("e1000_phy_get_info");
3136
3137 phy_info->cable_length = e1000_cable_length_undefined;
3138 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined;
3139 phy_info->cable_polarity = e1000_rev_polarity_undefined;
3140 phy_info->downshift = e1000_downshift_undefined;
3141 phy_info->polarity_correction = e1000_polarity_reversal_undefined;
3142 phy_info->mdix_mode = e1000_auto_x_mode_undefined;
3143 phy_info->local_rx = e1000_1000t_rx_status_undefined;
3144 phy_info->remote_rx = e1000_1000t_rx_status_undefined;
3145
Auke Kok8fc897b2006-08-28 14:56:16 -07003146 if (hw->media_type != e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003147 DEBUGOUT("PHY info is only valid for copper media\n");
3148 return -E1000_ERR_CONFIG;
3149 }
3150
3151 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003152 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003153 return ret_val;
3154
3155 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003156 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003157 return ret_val;
3158
Auke Kok8fc897b2006-08-28 14:56:16 -07003159 if ((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003160 DEBUGOUT("PHY info is only valid if link is up\n");
3161 return -E1000_ERR_CONFIG;
3162 }
3163
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00003164 if (hw->phy_type == e1000_phy_igp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003165 return e1000_phy_igp_get_info(hw, phy_info);
3166 else
3167 return e1000_phy_m88_get_info(hw, phy_info);
3168}
3169
Joe Perches64798842008-07-11 15:17:02 -07003170s32 e1000_validate_mdi_setting(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003171{
3172 DEBUGFUNC("e1000_validate_mdi_settings");
3173
Auke Kok8fc897b2006-08-28 14:56:16 -07003174 if (!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003175 DEBUGOUT("Invalid MDI setting detected\n");
3176 hw->mdix = 1;
3177 return -E1000_ERR_CONFIG;
3178 }
3179 return E1000_SUCCESS;
3180}
3181
3182
3183/******************************************************************************
3184 * Sets up eeprom variables in the hw struct. Must be called after mac_type
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00003185 * is configured.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003186 *
3187 * hw - Struct containing variables accessed by shared code
3188 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003189s32 e1000_init_eeprom_params(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003190{
3191 struct e1000_eeprom_info *eeprom = &hw->eeprom;
Joe Perches1dc32912008-07-11 15:17:08 -07003192 u32 eecd = er32(EECD);
Joe Perches406874a2008-04-03 10:06:32 -07003193 s32 ret_val = E1000_SUCCESS;
3194 u16 eeprom_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003195
3196 DEBUGFUNC("e1000_init_eeprom_params");
3197
3198 switch (hw->mac_type) {
3199 case e1000_82542_rev2_0:
3200 case e1000_82542_rev2_1:
3201 case e1000_82543:
3202 case e1000_82544:
3203 eeprom->type = e1000_eeprom_microwire;
3204 eeprom->word_size = 64;
3205 eeprom->opcode_bits = 3;
3206 eeprom->address_bits = 6;
3207 eeprom->delay_usec = 50;
Joe Perchesc3033b02008-03-21 11:06:25 -07003208 eeprom->use_eerd = false;
3209 eeprom->use_eewr = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003210 break;
3211 case e1000_82540:
3212 case e1000_82545:
3213 case e1000_82545_rev_3:
3214 case e1000_82546:
3215 case e1000_82546_rev_3:
3216 eeprom->type = e1000_eeprom_microwire;
3217 eeprom->opcode_bits = 3;
3218 eeprom->delay_usec = 50;
Auke Kok8fc897b2006-08-28 14:56:16 -07003219 if (eecd & E1000_EECD_SIZE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003220 eeprom->word_size = 256;
3221 eeprom->address_bits = 8;
3222 } else {
3223 eeprom->word_size = 64;
3224 eeprom->address_bits = 6;
3225 }
Joe Perchesc3033b02008-03-21 11:06:25 -07003226 eeprom->use_eerd = false;
3227 eeprom->use_eewr = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003228 break;
3229 case e1000_82541:
3230 case e1000_82541_rev_2:
3231 case e1000_82547:
3232 case e1000_82547_rev_2:
3233 if (eecd & E1000_EECD_TYPE) {
3234 eeprom->type = e1000_eeprom_spi;
3235 eeprom->opcode_bits = 8;
3236 eeprom->delay_usec = 1;
3237 if (eecd & E1000_EECD_ADDR_BITS) {
3238 eeprom->page_size = 32;
3239 eeprom->address_bits = 16;
3240 } else {
3241 eeprom->page_size = 8;
3242 eeprom->address_bits = 8;
3243 }
3244 } else {
3245 eeprom->type = e1000_eeprom_microwire;
3246 eeprom->opcode_bits = 3;
3247 eeprom->delay_usec = 50;
3248 if (eecd & E1000_EECD_ADDR_BITS) {
3249 eeprom->word_size = 256;
3250 eeprom->address_bits = 8;
3251 } else {
3252 eeprom->word_size = 64;
3253 eeprom->address_bits = 6;
3254 }
3255 }
Joe Perchesc3033b02008-03-21 11:06:25 -07003256 eeprom->use_eerd = false;
3257 eeprom->use_eewr = false;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003258 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003259 default:
3260 break;
3261 }
3262
3263 if (eeprom->type == e1000_eeprom_spi) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003264 /* eeprom_size will be an enum [0..8] that maps to eeprom sizes 128B to
3265 * 32KB (incremented by powers of 2).
3266 */
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00003267 /* Set to default value for initial eeprom read. */
3268 eeprom->word_size = 64;
3269 ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size);
3270 if (ret_val)
3271 return ret_val;
3272 eeprom_size = (eeprom_size & EEPROM_SIZE_MASK) >> EEPROM_SIZE_SHIFT;
3273 /* 256B eeprom size was not supported in earlier hardware, so we
3274 * bump eeprom_size up one to ensure that "1" (which maps to 256B)
3275 * is never the result used in the shifting logic below. */
3276 if (eeprom_size)
3277 eeprom_size++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003278
3279 eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003280 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003281 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003282}
3283
3284/******************************************************************************
3285 * Raises the EEPROM's clock input.
3286 *
3287 * hw - Struct containing variables accessed by shared code
3288 * eecd - EECD's current value
3289 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003290static void e1000_raise_ee_clk(struct e1000_hw *hw, u32 *eecd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003291{
3292 /* Raise the clock input to the EEPROM (by setting the SK bit), and then
3293 * wait <delay> microseconds.
3294 */
3295 *eecd = *eecd | E1000_EECD_SK;
Joe Perches1dc32912008-07-11 15:17:08 -07003296 ew32(EECD, *eecd);
3297 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003298 udelay(hw->eeprom.delay_usec);
3299}
3300
3301/******************************************************************************
3302 * Lowers the EEPROM's clock input.
3303 *
3304 * hw - Struct containing variables accessed by shared code
3305 * eecd - EECD's current value
3306 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003307static void e1000_lower_ee_clk(struct e1000_hw *hw, u32 *eecd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003308{
3309 /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
3310 * wait 50 microseconds.
3311 */
3312 *eecd = *eecd & ~E1000_EECD_SK;
Joe Perches1dc32912008-07-11 15:17:08 -07003313 ew32(EECD, *eecd);
3314 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003315 udelay(hw->eeprom.delay_usec);
3316}
3317
3318/******************************************************************************
3319 * Shift data bits out to the EEPROM.
3320 *
3321 * hw - Struct containing variables accessed by shared code
3322 * data - data to send to the EEPROM
3323 * count - number of bits to shift out
3324 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003325static void e1000_shift_out_ee_bits(struct e1000_hw *hw, u16 data, u16 count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003326{
3327 struct e1000_eeprom_info *eeprom = &hw->eeprom;
Joe Perches406874a2008-04-03 10:06:32 -07003328 u32 eecd;
3329 u32 mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003330
3331 /* We need to shift "count" bits out to the EEPROM. So, value in the
3332 * "data" parameter will be shifted out to the EEPROM one bit at a time.
3333 * In order to do this, "data" must be broken down into bits.
3334 */
3335 mask = 0x01 << (count - 1);
Joe Perches1dc32912008-07-11 15:17:08 -07003336 eecd = er32(EECD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003337 if (eeprom->type == e1000_eeprom_microwire) {
3338 eecd &= ~E1000_EECD_DO;
3339 } else if (eeprom->type == e1000_eeprom_spi) {
3340 eecd |= E1000_EECD_DO;
3341 }
3342 do {
3343 /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
3344 * and then raising and then lowering the clock (the SK bit controls
3345 * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
3346 * by setting "DI" to "0" and then raising and then lowering the clock.
3347 */
3348 eecd &= ~E1000_EECD_DI;
3349
Auke Kok8fc897b2006-08-28 14:56:16 -07003350 if (data & mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003351 eecd |= E1000_EECD_DI;
3352
Joe Perches1dc32912008-07-11 15:17:08 -07003353 ew32(EECD, eecd);
3354 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003355
3356 udelay(eeprom->delay_usec);
3357
3358 e1000_raise_ee_clk(hw, &eecd);
3359 e1000_lower_ee_clk(hw, &eecd);
3360
3361 mask = mask >> 1;
3362
Auke Kok8fc897b2006-08-28 14:56:16 -07003363 } while (mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003364
3365 /* We leave the "DI" bit set to "0" when we leave this routine. */
3366 eecd &= ~E1000_EECD_DI;
Joe Perches1dc32912008-07-11 15:17:08 -07003367 ew32(EECD, eecd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003368}
3369
3370/******************************************************************************
3371 * Shift data bits in from the EEPROM
3372 *
3373 * hw - Struct containing variables accessed by shared code
3374 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003375static u16 e1000_shift_in_ee_bits(struct e1000_hw *hw, u16 count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003376{
Joe Perches406874a2008-04-03 10:06:32 -07003377 u32 eecd;
3378 u32 i;
3379 u16 data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003380
3381 /* In order to read a register from the EEPROM, we need to shift 'count'
3382 * bits in from the EEPROM. Bits are "shifted in" by raising the clock
3383 * input to the EEPROM (setting the SK bit), and then reading the value of
3384 * the "DO" bit. During this "shifting in" process the "DI" bit should
3385 * always be clear.
3386 */
3387
Joe Perches1dc32912008-07-11 15:17:08 -07003388 eecd = er32(EECD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003389
3390 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
3391 data = 0;
3392
Auke Kok8fc897b2006-08-28 14:56:16 -07003393 for (i = 0; i < count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003394 data = data << 1;
3395 e1000_raise_ee_clk(hw, &eecd);
3396
Joe Perches1dc32912008-07-11 15:17:08 -07003397 eecd = er32(EECD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003398
3399 eecd &= ~(E1000_EECD_DI);
Auke Kok8fc897b2006-08-28 14:56:16 -07003400 if (eecd & E1000_EECD_DO)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003401 data |= 1;
3402
3403 e1000_lower_ee_clk(hw, &eecd);
3404 }
3405
3406 return data;
3407}
3408
3409/******************************************************************************
3410 * Prepares EEPROM for access
3411 *
3412 * hw - Struct containing variables accessed by shared code
3413 *
3414 * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
3415 * function should be called before issuing a command to the EEPROM.
3416 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003417static s32 e1000_acquire_eeprom(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003418{
3419 struct e1000_eeprom_info *eeprom = &hw->eeprom;
Joe Perches406874a2008-04-03 10:06:32 -07003420 u32 eecd, i=0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003421
3422 DEBUGFUNC("e1000_acquire_eeprom");
3423
Joe Perches1dc32912008-07-11 15:17:08 -07003424 eecd = er32(EECD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003425
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00003426 /* Request EEPROM Access */
3427 if (hw->mac_type > e1000_82544) {
3428 eecd |= E1000_EECD_REQ;
3429 ew32(EECD, eecd);
3430 eecd = er32(EECD);
3431 while ((!(eecd & E1000_EECD_GNT)) &&
3432 (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
3433 i++;
3434 udelay(5);
Joe Perches1dc32912008-07-11 15:17:08 -07003435 eecd = er32(EECD);
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00003436 }
3437 if (!(eecd & E1000_EECD_GNT)) {
3438 eecd &= ~E1000_EECD_REQ;
3439 ew32(EECD, eecd);
3440 DEBUGOUT("Could not acquire EEPROM grant\n");
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00003441 return -E1000_ERR_EEPROM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003442 }
3443 }
3444
3445 /* Setup EEPROM for Read/Write */
3446
3447 if (eeprom->type == e1000_eeprom_microwire) {
3448 /* Clear SK and DI */
3449 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
Joe Perches1dc32912008-07-11 15:17:08 -07003450 ew32(EECD, eecd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003451
3452 /* Set CS */
3453 eecd |= E1000_EECD_CS;
Joe Perches1dc32912008-07-11 15:17:08 -07003454 ew32(EECD, eecd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003455 } else if (eeprom->type == e1000_eeprom_spi) {
3456 /* Clear SK and CS */
3457 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
Joe Perches1dc32912008-07-11 15:17:08 -07003458 ew32(EECD, eecd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003459 udelay(1);
3460 }
3461
3462 return E1000_SUCCESS;
3463}
3464
3465/******************************************************************************
3466 * Returns EEPROM to a "standby" state
3467 *
3468 * hw - Struct containing variables accessed by shared code
3469 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003470static void e1000_standby_eeprom(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003471{
3472 struct e1000_eeprom_info *eeprom = &hw->eeprom;
Joe Perches406874a2008-04-03 10:06:32 -07003473 u32 eecd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003474
Joe Perches1dc32912008-07-11 15:17:08 -07003475 eecd = er32(EECD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003476
Auke Kok8fc897b2006-08-28 14:56:16 -07003477 if (eeprom->type == e1000_eeprom_microwire) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003478 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
Joe Perches1dc32912008-07-11 15:17:08 -07003479 ew32(EECD, eecd);
3480 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003481 udelay(eeprom->delay_usec);
3482
3483 /* Clock high */
3484 eecd |= E1000_EECD_SK;
Joe Perches1dc32912008-07-11 15:17:08 -07003485 ew32(EECD, eecd);
3486 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003487 udelay(eeprom->delay_usec);
3488
3489 /* Select EEPROM */
3490 eecd |= E1000_EECD_CS;
Joe Perches1dc32912008-07-11 15:17:08 -07003491 ew32(EECD, eecd);
3492 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003493 udelay(eeprom->delay_usec);
3494
3495 /* Clock low */
3496 eecd &= ~E1000_EECD_SK;
Joe Perches1dc32912008-07-11 15:17:08 -07003497 ew32(EECD, eecd);
3498 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003499 udelay(eeprom->delay_usec);
Auke Kok8fc897b2006-08-28 14:56:16 -07003500 } else if (eeprom->type == e1000_eeprom_spi) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003501 /* Toggle CS to flush commands */
3502 eecd |= E1000_EECD_CS;
Joe Perches1dc32912008-07-11 15:17:08 -07003503 ew32(EECD, eecd);
3504 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003505 udelay(eeprom->delay_usec);
3506 eecd &= ~E1000_EECD_CS;
Joe Perches1dc32912008-07-11 15:17:08 -07003507 ew32(EECD, eecd);
3508 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003509 udelay(eeprom->delay_usec);
3510 }
3511}
3512
3513/******************************************************************************
3514 * Terminates a command by inverting the EEPROM's chip select pin
3515 *
3516 * hw - Struct containing variables accessed by shared code
3517 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003518static void e1000_release_eeprom(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003519{
Joe Perches406874a2008-04-03 10:06:32 -07003520 u32 eecd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003521
3522 DEBUGFUNC("e1000_release_eeprom");
3523
Joe Perches1dc32912008-07-11 15:17:08 -07003524 eecd = er32(EECD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003525
3526 if (hw->eeprom.type == e1000_eeprom_spi) {
3527 eecd |= E1000_EECD_CS; /* Pull CS high */
3528 eecd &= ~E1000_EECD_SK; /* Lower SCK */
3529
Joe Perches1dc32912008-07-11 15:17:08 -07003530 ew32(EECD, eecd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003531
3532 udelay(hw->eeprom.delay_usec);
Auke Kok8fc897b2006-08-28 14:56:16 -07003533 } else if (hw->eeprom.type == e1000_eeprom_microwire) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003534 /* cleanup eeprom */
3535
3536 /* CS on Microwire is active-high */
3537 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
3538
Joe Perches1dc32912008-07-11 15:17:08 -07003539 ew32(EECD, eecd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003540
3541 /* Rising edge of clock */
3542 eecd |= E1000_EECD_SK;
Joe Perches1dc32912008-07-11 15:17:08 -07003543 ew32(EECD, eecd);
3544 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003545 udelay(hw->eeprom.delay_usec);
3546
3547 /* Falling edge of clock */
3548 eecd &= ~E1000_EECD_SK;
Joe Perches1dc32912008-07-11 15:17:08 -07003549 ew32(EECD, eecd);
3550 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003551 udelay(hw->eeprom.delay_usec);
3552 }
3553
3554 /* Stop requesting EEPROM access */
Auke Kok8fc897b2006-08-28 14:56:16 -07003555 if (hw->mac_type > e1000_82544) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003556 eecd &= ~E1000_EECD_REQ;
Joe Perches1dc32912008-07-11 15:17:08 -07003557 ew32(EECD, eecd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003558 }
3559}
3560
3561/******************************************************************************
3562 * Reads a 16 bit word from the EEPROM.
3563 *
3564 * hw - Struct containing variables accessed by shared code
3565 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003566static s32 e1000_spi_eeprom_ready(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003567{
Joe Perches406874a2008-04-03 10:06:32 -07003568 u16 retry_count = 0;
3569 u8 spi_stat_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003570
3571 DEBUGFUNC("e1000_spi_eeprom_ready");
3572
3573 /* Read "Status Register" repeatedly until the LSB is cleared. The
3574 * EEPROM will signal that the command has been completed by clearing
3575 * bit 0 of the internal status register. If it's not cleared within
3576 * 5 milliseconds, then error out.
3577 */
3578 retry_count = 0;
3579 do {
3580 e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
3581 hw->eeprom.opcode_bits);
Joe Perches406874a2008-04-03 10:06:32 -07003582 spi_stat_reg = (u8)e1000_shift_in_ee_bits(hw, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003583 if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
3584 break;
3585
3586 udelay(5);
3587 retry_count += 5;
3588
3589 e1000_standby_eeprom(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07003590 } while (retry_count < EEPROM_MAX_RETRY_SPI);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003591
3592 /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
3593 * only 0-5mSec on 5V devices)
3594 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003595 if (retry_count >= EEPROM_MAX_RETRY_SPI) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003596 DEBUGOUT("SPI EEPROM Status error\n");
3597 return -E1000_ERR_EEPROM;
3598 }
3599
3600 return E1000_SUCCESS;
3601}
3602
3603/******************************************************************************
3604 * Reads a 16 bit word from the EEPROM.
3605 *
3606 * hw - Struct containing variables accessed by shared code
3607 * offset - offset of word in the EEPROM to read
3608 * data - word read from the EEPROM
3609 * words - number of words to read
3610 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003611s32 e1000_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003612{
Christopher Li78566fe2008-09-05 14:04:05 -07003613 s32 ret;
3614 spin_lock(&e1000_eeprom_lock);
3615 ret = e1000_do_read_eeprom(hw, offset, words, data);
3616 spin_unlock(&e1000_eeprom_lock);
3617 return ret;
3618}
3619
3620static s32 e1000_do_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
3621{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003622 struct e1000_eeprom_info *eeprom = &hw->eeprom;
Joe Perches406874a2008-04-03 10:06:32 -07003623 u32 i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003624
3625 DEBUGFUNC("e1000_read_eeprom");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003626
Jeff Kirsher2a88c172006-09-27 12:54:05 -07003627 /* If eeprom is not yet detected, do so now */
3628 if (eeprom->word_size == 0)
3629 e1000_init_eeprom_params(hw);
3630
Linus Torvalds1da177e2005-04-16 15:20:36 -07003631 /* A check for invalid values: offset too large, too many words, and not
3632 * enough words.
3633 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003634 if ((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07003635 (words == 0)) {
Jeff Kirsher2a88c172006-09-27 12:54:05 -07003636 DEBUGOUT2("\"words\" parameter out of bounds. Words = %d, size = %d\n", offset, eeprom->word_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003637 return -E1000_ERR_EEPROM;
3638 }
3639
Jeff Kirsher2a88c172006-09-27 12:54:05 -07003640 /* EEPROM's that don't use EERD to read require us to bit-bang the SPI
3641 * directly. In this case, we need to acquire the EEPROM so that
3642 * FW or other port software does not interrupt.
3643 */
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00003644 if (!hw->eeprom.use_eerd) {
Jeff Kirsher2a88c172006-09-27 12:54:05 -07003645 /* Prepare the EEPROM for bit-bang reading */
3646 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
3647 return -E1000_ERR_EEPROM;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003648 }
3649
Jeff Kirsher2a88c172006-09-27 12:54:05 -07003650 /* Eerd register EEPROM access requires no eeprom aquire/release */
Joe Perchesc3033b02008-03-21 11:06:25 -07003651 if (eeprom->use_eerd)
Jeff Kirsher2a88c172006-09-27 12:54:05 -07003652 return e1000_read_eeprom_eerd(hw, offset, words, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003653
Jeff Kirsher2a88c172006-09-27 12:54:05 -07003654 /* Set up the SPI or Microwire EEPROM for bit-bang reading. We have
3655 * acquired the EEPROM at this point, so any returns should relase it */
Auke Kokcd94dd02006-06-27 09:08:22 -07003656 if (eeprom->type == e1000_eeprom_spi) {
Joe Perches406874a2008-04-03 10:06:32 -07003657 u16 word_in;
3658 u8 read_opcode = EEPROM_READ_OPCODE_SPI;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003659
Auke Kok8fc897b2006-08-28 14:56:16 -07003660 if (e1000_spi_eeprom_ready(hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003661 e1000_release_eeprom(hw);
3662 return -E1000_ERR_EEPROM;
3663 }
3664
3665 e1000_standby_eeprom(hw);
3666
3667 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
Auke Kok8fc897b2006-08-28 14:56:16 -07003668 if ((eeprom->address_bits == 8) && (offset >= 128))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003669 read_opcode |= EEPROM_A8_OPCODE_SPI;
3670
3671 /* Send the READ command (opcode + addr) */
3672 e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
Joe Perches406874a2008-04-03 10:06:32 -07003673 e1000_shift_out_ee_bits(hw, (u16)(offset*2), eeprom->address_bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003674
3675 /* Read the data. The address of the eeprom internally increments with
3676 * each byte (spi) being read, saving on the overhead of eeprom setup
3677 * and tear-down. The address counter will roll over if reading beyond
3678 * the size of the eeprom, thus allowing the entire memory to be read
3679 * starting from any offset. */
3680 for (i = 0; i < words; i++) {
3681 word_in = e1000_shift_in_ee_bits(hw, 16);
3682 data[i] = (word_in >> 8) | (word_in << 8);
3683 }
Auke Kok8fc897b2006-08-28 14:56:16 -07003684 } else if (eeprom->type == e1000_eeprom_microwire) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003685 for (i = 0; i < words; i++) {
3686 /* Send the READ command (opcode + addr) */
3687 e1000_shift_out_ee_bits(hw, EEPROM_READ_OPCODE_MICROWIRE,
3688 eeprom->opcode_bits);
Joe Perches406874a2008-04-03 10:06:32 -07003689 e1000_shift_out_ee_bits(hw, (u16)(offset + i),
Linus Torvalds1da177e2005-04-16 15:20:36 -07003690 eeprom->address_bits);
3691
3692 /* Read the data. For microwire, each word requires the overhead
3693 * of eeprom setup and tear-down. */
3694 data[i] = e1000_shift_in_ee_bits(hw, 16);
3695 e1000_standby_eeprom(hw);
3696 }
3697 }
3698
3699 /* End this read operation */
3700 e1000_release_eeprom(hw);
3701
3702 return E1000_SUCCESS;
3703}
3704
3705/******************************************************************************
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003706 * Reads a 16 bit word from the EEPROM using the EERD register.
3707 *
3708 * hw - Struct containing variables accessed by shared code
3709 * offset - offset of word in the EEPROM to read
3710 * data - word read from the EEPROM
3711 * words - number of words to read
3712 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003713static s32 e1000_read_eeprom_eerd(struct e1000_hw *hw, u16 offset, u16 words,
3714 u16 *data)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003715{
Joe Perches406874a2008-04-03 10:06:32 -07003716 u32 i, eerd = 0;
3717 s32 error = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003718
3719 for (i = 0; i < words; i++) {
3720 eerd = ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) +
3721 E1000_EEPROM_RW_REG_START;
3722
Joe Perches1dc32912008-07-11 15:17:08 -07003723 ew32(EERD, eerd);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003724 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_READ);
Auke Kok76c224b2006-05-23 13:36:06 -07003725
Auke Kok8fc897b2006-08-28 14:56:16 -07003726 if (error) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003727 break;
3728 }
Joe Perches1dc32912008-07-11 15:17:08 -07003729 data[i] = (er32(EERD) >> E1000_EEPROM_RW_REG_DATA);
Auke Kok76c224b2006-05-23 13:36:06 -07003730
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003731 }
Auke Kok76c224b2006-05-23 13:36:06 -07003732
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003733 return error;
3734}
3735
3736/******************************************************************************
3737 * Writes a 16 bit word from the EEPROM using the EEWR register.
3738 *
3739 * hw - Struct containing variables accessed by shared code
3740 * offset - offset of word in the EEPROM to read
3741 * data - word read from the EEPROM
3742 * words - number of words to read
3743 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003744static s32 e1000_write_eeprom_eewr(struct e1000_hw *hw, u16 offset, u16 words,
3745 u16 *data)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003746{
Joe Perches406874a2008-04-03 10:06:32 -07003747 u32 register_value = 0;
3748 u32 i = 0;
3749 s32 error = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003750
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003751
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003752 for (i = 0; i < words; i++) {
Auke Kok76c224b2006-05-23 13:36:06 -07003753 register_value = (data[i] << E1000_EEPROM_RW_REG_DATA) |
3754 ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) |
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003755 E1000_EEPROM_RW_REG_START;
3756
3757 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
Auke Kok8fc897b2006-08-28 14:56:16 -07003758 if (error) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003759 break;
Auke Kok76c224b2006-05-23 13:36:06 -07003760 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003761
Joe Perches1dc32912008-07-11 15:17:08 -07003762 ew32(EEWR, register_value);
Auke Kok76c224b2006-05-23 13:36:06 -07003763
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003764 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
Auke Kok76c224b2006-05-23 13:36:06 -07003765
Auke Kok8fc897b2006-08-28 14:56:16 -07003766 if (error) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003767 break;
Auke Kok76c224b2006-05-23 13:36:06 -07003768 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003769 }
Auke Kok76c224b2006-05-23 13:36:06 -07003770
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003771 return error;
3772}
3773
3774/******************************************************************************
3775 * Polls the status bit (bit 1) of the EERD to determine when the read is done.
3776 *
3777 * hw - Struct containing variables accessed by shared code
3778 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003779static s32 e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003780{
Joe Perches406874a2008-04-03 10:06:32 -07003781 u32 attempts = 100000;
3782 u32 i, reg = 0;
3783 s32 done = E1000_ERR_EEPROM;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003784
Auke Kok8fc897b2006-08-28 14:56:16 -07003785 for (i = 0; i < attempts; i++) {
3786 if (eerd == E1000_EEPROM_POLL_READ)
Joe Perches1dc32912008-07-11 15:17:08 -07003787 reg = er32(EERD);
Auke Kok76c224b2006-05-23 13:36:06 -07003788 else
Joe Perches1dc32912008-07-11 15:17:08 -07003789 reg = er32(EEWR);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003790
Auke Kok8fc897b2006-08-28 14:56:16 -07003791 if (reg & E1000_EEPROM_RW_REG_DONE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003792 done = E1000_SUCCESS;
3793 break;
3794 }
3795 udelay(5);
3796 }
3797
3798 return done;
3799}
3800
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003801/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07003802 * Verifies that the EEPROM has a valid checksum
3803 *
3804 * hw - Struct containing variables accessed by shared code
3805 *
3806 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
3807 * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
3808 * valid.
3809 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003810s32 e1000_validate_eeprom_checksum(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003811{
Joe Perches406874a2008-04-03 10:06:32 -07003812 u16 checksum = 0;
3813 u16 i, eeprom_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003814
3815 DEBUGFUNC("e1000_validate_eeprom_checksum");
3816
Auke Kokcd94dd02006-06-27 09:08:22 -07003817 for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
3818 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003819 DEBUGOUT("EEPROM Read Error\n");
3820 return -E1000_ERR_EEPROM;
3821 }
3822 checksum += eeprom_data;
3823 }
3824
Joe Perchese982f172008-07-11 15:17:18 -07003825 if (checksum == (u16)EEPROM_SUM)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003826 return E1000_SUCCESS;
3827 else {
3828 DEBUGOUT("EEPROM Checksum Invalid\n");
3829 return -E1000_ERR_EEPROM;
3830 }
3831}
3832
3833/******************************************************************************
3834 * Calculates the EEPROM checksum and writes it to the EEPROM
3835 *
3836 * hw - Struct containing variables accessed by shared code
3837 *
3838 * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA.
3839 * Writes the difference to word offset 63 of the EEPROM.
3840 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003841s32 e1000_update_eeprom_checksum(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003842{
Joe Perches406874a2008-04-03 10:06:32 -07003843 u16 checksum = 0;
3844 u16 i, eeprom_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003845
3846 DEBUGFUNC("e1000_update_eeprom_checksum");
3847
Auke Kok8fc897b2006-08-28 14:56:16 -07003848 for (i = 0; i < EEPROM_CHECKSUM_REG; i++) {
3849 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003850 DEBUGOUT("EEPROM Read Error\n");
3851 return -E1000_ERR_EEPROM;
3852 }
3853 checksum += eeprom_data;
3854 }
Joe Perchese982f172008-07-11 15:17:18 -07003855 checksum = (u16)EEPROM_SUM - checksum;
Auke Kok8fc897b2006-08-28 14:56:16 -07003856 if (e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003857 DEBUGOUT("EEPROM Write Error\n");
3858 return -E1000_ERR_EEPROM;
3859 }
3860 return E1000_SUCCESS;
3861}
3862
3863/******************************************************************************
3864 * Parent function for writing words to the different EEPROM types.
3865 *
3866 * hw - Struct containing variables accessed by shared code
3867 * offset - offset within the EEPROM to be written to
3868 * words - number of words to write
3869 * data - 16 bit word to be written to the EEPROM
3870 *
3871 * If e1000_update_eeprom_checksum is not called after this function, the
3872 * EEPROM will most likely contain an invalid checksum.
3873 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003874s32 e1000_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003875{
Christopher Li78566fe2008-09-05 14:04:05 -07003876 s32 ret;
3877 spin_lock(&e1000_eeprom_lock);
3878 ret = e1000_do_write_eeprom(hw, offset, words, data);
3879 spin_unlock(&e1000_eeprom_lock);
3880 return ret;
3881}
3882
3883
3884static s32 e1000_do_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
3885{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003886 struct e1000_eeprom_info *eeprom = &hw->eeprom;
Joe Perches406874a2008-04-03 10:06:32 -07003887 s32 status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003888
3889 DEBUGFUNC("e1000_write_eeprom");
3890
Jeff Kirsher2a88c172006-09-27 12:54:05 -07003891 /* If eeprom is not yet detected, do so now */
3892 if (eeprom->word_size == 0)
3893 e1000_init_eeprom_params(hw);
3894
Linus Torvalds1da177e2005-04-16 15:20:36 -07003895 /* A check for invalid values: offset too large, too many words, and not
3896 * enough words.
3897 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003898 if ((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07003899 (words == 0)) {
3900 DEBUGOUT("\"words\" parameter out of bounds\n");
3901 return -E1000_ERR_EEPROM;
3902 }
3903
Joe Perchesc3033b02008-03-21 11:06:25 -07003904 if (eeprom->use_eewr)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003905 return e1000_write_eeprom_eewr(hw, offset, words, data);
3906
Linus Torvalds1da177e2005-04-16 15:20:36 -07003907 /* Prepare the EEPROM for writing */
3908 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
3909 return -E1000_ERR_EEPROM;
3910
Auke Kok8fc897b2006-08-28 14:56:16 -07003911 if (eeprom->type == e1000_eeprom_microwire) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003912 status = e1000_write_eeprom_microwire(hw, offset, words, data);
3913 } else {
3914 status = e1000_write_eeprom_spi(hw, offset, words, data);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04003915 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003916 }
3917
3918 /* Done with writing */
3919 e1000_release_eeprom(hw);
3920
3921 return status;
3922}
3923
3924/******************************************************************************
3925 * Writes a 16 bit word to a given offset in an SPI EEPROM.
3926 *
3927 * hw - Struct containing variables accessed by shared code
3928 * offset - offset within the EEPROM to be written to
3929 * words - number of words to write
3930 * data - pointer to array of 8 bit words to be written to the EEPROM
3931 *
3932 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003933static s32 e1000_write_eeprom_spi(struct e1000_hw *hw, u16 offset, u16 words,
3934 u16 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003935{
3936 struct e1000_eeprom_info *eeprom = &hw->eeprom;
Joe Perches406874a2008-04-03 10:06:32 -07003937 u16 widx = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003938
3939 DEBUGFUNC("e1000_write_eeprom_spi");
3940
3941 while (widx < words) {
Joe Perches406874a2008-04-03 10:06:32 -07003942 u8 write_opcode = EEPROM_WRITE_OPCODE_SPI;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003943
Auke Kok8fc897b2006-08-28 14:56:16 -07003944 if (e1000_spi_eeprom_ready(hw)) return -E1000_ERR_EEPROM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003945
3946 e1000_standby_eeprom(hw);
3947
3948 /* Send the WRITE ENABLE command (8 bit opcode ) */
3949 e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI,
3950 eeprom->opcode_bits);
3951
3952 e1000_standby_eeprom(hw);
3953
3954 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
Auke Kok8fc897b2006-08-28 14:56:16 -07003955 if ((eeprom->address_bits == 8) && (offset >= 128))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003956 write_opcode |= EEPROM_A8_OPCODE_SPI;
3957
3958 /* Send the Write command (8-bit opcode + addr) */
3959 e1000_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits);
3960
Joe Perches406874a2008-04-03 10:06:32 -07003961 e1000_shift_out_ee_bits(hw, (u16)((offset + widx)*2),
Linus Torvalds1da177e2005-04-16 15:20:36 -07003962 eeprom->address_bits);
3963
3964 /* Send the data */
3965
3966 /* Loop to allow for up to whole page write (32 bytes) of eeprom */
3967 while (widx < words) {
Joe Perches406874a2008-04-03 10:06:32 -07003968 u16 word_out = data[widx];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003969 word_out = (word_out >> 8) | (word_out << 8);
3970 e1000_shift_out_ee_bits(hw, word_out, 16);
3971 widx++;
3972
3973 /* Some larger eeprom sizes are capable of a 32-byte PAGE WRITE
3974 * operation, while the smaller eeproms are capable of an 8-byte
3975 * PAGE WRITE operation. Break the inner loop to pass new address
3976 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003977 if ((((offset + widx)*2) % eeprom->page_size) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003978 e1000_standby_eeprom(hw);
3979 break;
3980 }
3981 }
3982 }
3983
3984 return E1000_SUCCESS;
3985}
3986
3987/******************************************************************************
3988 * Writes a 16 bit word to a given offset in a Microwire EEPROM.
3989 *
3990 * hw - Struct containing variables accessed by shared code
3991 * offset - offset within the EEPROM to be written to
3992 * words - number of words to write
3993 * data - pointer to array of 16 bit words to be written to the EEPROM
3994 *
3995 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003996static s32 e1000_write_eeprom_microwire(struct e1000_hw *hw, u16 offset,
3997 u16 words, u16 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003998{
3999 struct e1000_eeprom_info *eeprom = &hw->eeprom;
Joe Perches406874a2008-04-03 10:06:32 -07004000 u32 eecd;
4001 u16 words_written = 0;
4002 u16 i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004003
4004 DEBUGFUNC("e1000_write_eeprom_microwire");
4005
4006 /* Send the write enable command to the EEPROM (3-bit opcode plus
4007 * 6/8-bit dummy address beginning with 11). It's less work to include
4008 * the 11 of the dummy address as part of the opcode than it is to shift
4009 * it over the correct number of bits for the address. This puts the
4010 * EEPROM into write/erase mode.
4011 */
4012 e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE,
Joe Perches406874a2008-04-03 10:06:32 -07004013 (u16)(eeprom->opcode_bits + 2));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004014
Joe Perches406874a2008-04-03 10:06:32 -07004015 e1000_shift_out_ee_bits(hw, 0, (u16)(eeprom->address_bits - 2));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004016
4017 /* Prepare the EEPROM */
4018 e1000_standby_eeprom(hw);
4019
4020 while (words_written < words) {
4021 /* Send the Write command (3-bit opcode + addr) */
4022 e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE,
4023 eeprom->opcode_bits);
4024
Joe Perches406874a2008-04-03 10:06:32 -07004025 e1000_shift_out_ee_bits(hw, (u16)(offset + words_written),
Linus Torvalds1da177e2005-04-16 15:20:36 -07004026 eeprom->address_bits);
4027
4028 /* Send the data */
4029 e1000_shift_out_ee_bits(hw, data[words_written], 16);
4030
4031 /* Toggle the CS line. This in effect tells the EEPROM to execute
4032 * the previous command.
4033 */
4034 e1000_standby_eeprom(hw);
4035
4036 /* Read DO repeatedly until it is high (equal to '1'). The EEPROM will
4037 * signal that the command has been completed by raising the DO signal.
4038 * If DO does not go high in 10 milliseconds, then error out.
4039 */
Auke Kok8fc897b2006-08-28 14:56:16 -07004040 for (i = 0; i < 200; i++) {
Joe Perches1dc32912008-07-11 15:17:08 -07004041 eecd = er32(EECD);
Auke Kok8fc897b2006-08-28 14:56:16 -07004042 if (eecd & E1000_EECD_DO) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004043 udelay(50);
4044 }
Auke Kok8fc897b2006-08-28 14:56:16 -07004045 if (i == 200) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004046 DEBUGOUT("EEPROM Write did not complete\n");
4047 return -E1000_ERR_EEPROM;
4048 }
4049
4050 /* Recover from write */
4051 e1000_standby_eeprom(hw);
4052
4053 words_written++;
4054 }
4055
4056 /* Send the write disable command to the EEPROM (3-bit opcode plus
4057 * 6/8-bit dummy address beginning with 10). It's less work to include
4058 * the 10 of the dummy address as part of the opcode than it is to shift
4059 * it over the correct number of bits for the address. This takes the
4060 * EEPROM out of write/erase mode.
4061 */
4062 e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE,
Joe Perches406874a2008-04-03 10:06:32 -07004063 (u16)(eeprom->opcode_bits + 2));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004064
Joe Perches406874a2008-04-03 10:06:32 -07004065 e1000_shift_out_ee_bits(hw, 0, (u16)(eeprom->address_bits - 2));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004066
4067 return E1000_SUCCESS;
4068}
4069
4070/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07004071 * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
4072 * second function of dual function devices
4073 *
4074 * hw - Struct containing variables accessed by shared code
4075 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004076s32 e1000_read_mac_addr(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004077{
Joe Perches406874a2008-04-03 10:06:32 -07004078 u16 offset;
4079 u16 eeprom_data, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004080
4081 DEBUGFUNC("e1000_read_mac_addr");
4082
Auke Kok8fc897b2006-08-28 14:56:16 -07004083 for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004084 offset = i >> 1;
Auke Kok8fc897b2006-08-28 14:56:16 -07004085 if (e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004086 DEBUGOUT("EEPROM Read Error\n");
4087 return -E1000_ERR_EEPROM;
4088 }
Joe Perchese982f172008-07-11 15:17:18 -07004089 hw->perm_mac_addr[i] = (u8)(eeprom_data & 0x00FF);
4090 hw->perm_mac_addr[i+1] = (u8)(eeprom_data >> 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004091 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004092
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004093 switch (hw->mac_type) {
4094 default:
4095 break;
4096 case e1000_82546:
4097 case e1000_82546_rev_3:
Joe Perches1dc32912008-07-11 15:17:08 -07004098 if (er32(STATUS) & E1000_STATUS_FUNC_1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004099 hw->perm_mac_addr[5] ^= 0x01;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004100 break;
4101 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004102
Auke Kok8fc897b2006-08-28 14:56:16 -07004103 for (i = 0; i < NODE_ADDRESS_SIZE; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004104 hw->mac_addr[i] = hw->perm_mac_addr[i];
4105 return E1000_SUCCESS;
4106}
4107
4108/******************************************************************************
4109 * Initializes receive address filters.
4110 *
4111 * hw - Struct containing variables accessed by shared code
4112 *
4113 * Places the MAC address in receive address register 0 and clears the rest
4114 * of the receive addresss registers. Clears the multicast table. Assumes
4115 * the receiver is in reset when the routine is called.
4116 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004117static void e1000_init_rx_addrs(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004118{
Joe Perches406874a2008-04-03 10:06:32 -07004119 u32 i;
4120 u32 rar_num;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004121
4122 DEBUGFUNC("e1000_init_rx_addrs");
4123
4124 /* Setup the receive address. */
4125 DEBUGOUT("Programming MAC Address into RAR[0]\n");
4126
4127 e1000_rar_set(hw, hw->mac_addr, 0);
4128
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004129 rar_num = E1000_RAR_ENTRIES;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004130
Linus Torvalds1da177e2005-04-16 15:20:36 -07004131 /* Zero out the other 15 receive addresses. */
4132 DEBUGOUT("Clearing RAR[1-15]\n");
Auke Kok8fc897b2006-08-28 14:56:16 -07004133 for (i = 1; i < rar_num; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004134 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
Joe Perches1dc32912008-07-11 15:17:08 -07004135 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07004136 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
Joe Perches1dc32912008-07-11 15:17:08 -07004137 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07004138 }
4139}
4140
4141/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07004142 * Hashes an address to determine its location in the multicast table
4143 *
4144 * hw - Struct containing variables accessed by shared code
4145 * mc_addr - the multicast address to hash
4146 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004147u32 e1000_hash_mc_addr(struct e1000_hw *hw, u8 *mc_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004148{
Joe Perches406874a2008-04-03 10:06:32 -07004149 u32 hash_value = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004150
4151 /* The portion of the address that is used for the hash table is
4152 * determined by the mc_filter_type setting.
4153 */
4154 switch (hw->mc_filter_type) {
4155 /* [0] [1] [2] [3] [4] [5]
4156 * 01 AA 00 12 34 56
4157 * LSB MSB
4158 */
4159 case 0:
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00004160 /* [47:36] i.e. 0x563 for above example address */
4161 hash_value = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004162 break;
4163 case 1:
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00004164 /* [46:35] i.e. 0xAC6 for above example address */
4165 hash_value = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004166 break;
4167 case 2:
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00004168 /* [45:34] i.e. 0x5D8 for above example address */
4169 hash_value = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004170 break;
4171 case 3:
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00004172 /* [43:32] i.e. 0x634 for above example address */
4173 hash_value = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004174 break;
4175 }
4176
4177 hash_value &= 0xFFF;
4178 return hash_value;
4179}
4180
4181/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07004182 * Puts an ethernet address into a receive address register.
4183 *
4184 * hw - Struct containing variables accessed by shared code
4185 * addr - Address to put into receive address register
4186 * index - Receive address register to write
4187 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004188void e1000_rar_set(struct e1000_hw *hw, u8 *addr, u32 index)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004189{
Joe Perches406874a2008-04-03 10:06:32 -07004190 u32 rar_low, rar_high;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004191
4192 /* HW expects these in little endian so we reverse the byte order
4193 * from network order (big endian) to little endian
4194 */
Joe Perchese982f172008-07-11 15:17:18 -07004195 rar_low = ((u32)addr[0] | ((u32)addr[1] << 8) |
4196 ((u32)addr[2] << 16) | ((u32)addr[3] << 24));
4197 rar_high = ((u32)addr[4] | ((u32)addr[5] << 8));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004198
Jeff Kirsher8df06e52006-03-02 18:18:32 -08004199 /* Disable Rx and flush all Rx frames before enabling RSS to avoid Rx
4200 * unit hang.
4201 *
4202 * Description:
4203 * If there are any Rx frames queued up or otherwise present in the HW
4204 * before RSS is enabled, and then we enable RSS, the HW Rx unit will
4205 * hang. To work around this issue, we have to disable receives and
4206 * flush out all Rx frames before we enable RSS. To do so, we modify we
4207 * redirect all Rx traffic to manageability and then reset the HW.
4208 * This flushes away Rx frames, and (since the redirections to
4209 * manageability persists across resets) keeps new ones from coming in
4210 * while we work. Then, we clear the Address Valid AV bit for all MAC
4211 * addresses and undo the re-direction to manageability.
4212 * Now, frames are coming in again, but the MAC won't accept them, so
4213 * far so good. We now proceed to initialize RSS (if necessary) and
4214 * configure the Rx unit. Last, we re-enable the AV bits and continue
4215 * on our merry way.
4216 */
4217 switch (hw->mac_type) {
Jeff Kirsher8df06e52006-03-02 18:18:32 -08004218 default:
4219 /* Indicate to hardware the Address is Valid. */
4220 rar_high |= E1000_RAH_AV;
4221 break;
4222 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004223
4224 E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
Joe Perches1dc32912008-07-11 15:17:08 -07004225 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07004226 E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
Joe Perches1dc32912008-07-11 15:17:08 -07004227 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07004228}
4229
4230/******************************************************************************
4231 * Writes a value to the specified offset in the VLAN filter table.
4232 *
4233 * hw - Struct containing variables accessed by shared code
4234 * offset - Offset in VLAN filer table to write
4235 * value - Value to write into VLAN filter table
4236 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004237void e1000_write_vfta(struct e1000_hw *hw, u32 offset, u32 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004238{
Joe Perches406874a2008-04-03 10:06:32 -07004239 u32 temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004240
Auke Kokcd94dd02006-06-27 09:08:22 -07004241 if ((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004242 temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1));
4243 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
Joe Perches1dc32912008-07-11 15:17:08 -07004244 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07004245 E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp);
Joe Perches1dc32912008-07-11 15:17:08 -07004246 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07004247 } else {
4248 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
Joe Perches1dc32912008-07-11 15:17:08 -07004249 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07004250 }
4251}
4252
4253/******************************************************************************
4254 * Clears the VLAN filer table
4255 *
4256 * hw - Struct containing variables accessed by shared code
4257 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004258static void e1000_clear_vfta(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004259{
Joe Perches406874a2008-04-03 10:06:32 -07004260 u32 offset;
4261 u32 vfta_value = 0;
4262 u32 vfta_offset = 0;
4263 u32 vfta_bit_in_reg = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004264
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004265 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
4266 /* If the offset we want to clear is the same offset of the
4267 * manageability VLAN ID, then clear all bits except that of the
4268 * manageability unit */
4269 vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0;
4270 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, vfta_value);
Joe Perches1dc32912008-07-11 15:17:08 -07004271 E1000_WRITE_FLUSH();
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004272 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004273}
4274
Joe Perches64798842008-07-11 15:17:02 -07004275static s32 e1000_id_led_init(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004276{
Joe Perches406874a2008-04-03 10:06:32 -07004277 u32 ledctl;
4278 const u32 ledctl_mask = 0x000000FF;
4279 const u32 ledctl_on = E1000_LEDCTL_MODE_LED_ON;
4280 const u32 ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
4281 u16 eeprom_data, i, temp;
4282 const u16 led_mask = 0x0F;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004283
4284 DEBUGFUNC("e1000_id_led_init");
4285
Auke Kok8fc897b2006-08-28 14:56:16 -07004286 if (hw->mac_type < e1000_82540) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004287 /* Nothing to do */
4288 return E1000_SUCCESS;
4289 }
4290
Joe Perches1dc32912008-07-11 15:17:08 -07004291 ledctl = er32(LEDCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004292 hw->ledctl_default = ledctl;
4293 hw->ledctl_mode1 = hw->ledctl_default;
4294 hw->ledctl_mode2 = hw->ledctl_default;
4295
Auke Kok8fc897b2006-08-28 14:56:16 -07004296 if (e1000_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, 1, &eeprom_data) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004297 DEBUGOUT("EEPROM Read Error\n");
4298 return -E1000_ERR_EEPROM;
4299 }
Auke Kokcd94dd02006-06-27 09:08:22 -07004300
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00004301 if ((eeprom_data == ID_LED_RESERVED_0000) ||
Auke Kokcd94dd02006-06-27 09:08:22 -07004302 (eeprom_data == ID_LED_RESERVED_FFFF)) {
Auke Kokcd94dd02006-06-27 09:08:22 -07004303 eeprom_data = ID_LED_DEFAULT;
4304 }
Auke Kok90fb5132006-11-01 08:47:30 -08004305
Auke Kokcd94dd02006-06-27 09:08:22 -07004306 for (i = 0; i < 4; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004307 temp = (eeprom_data >> (i << 2)) & led_mask;
Auke Kok8fc897b2006-08-28 14:56:16 -07004308 switch (temp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004309 case ID_LED_ON1_DEF2:
4310 case ID_LED_ON1_ON2:
4311 case ID_LED_ON1_OFF2:
4312 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
4313 hw->ledctl_mode1 |= ledctl_on << (i << 3);
4314 break;
4315 case ID_LED_OFF1_DEF2:
4316 case ID_LED_OFF1_ON2:
4317 case ID_LED_OFF1_OFF2:
4318 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
4319 hw->ledctl_mode1 |= ledctl_off << (i << 3);
4320 break;
4321 default:
4322 /* Do nothing */
4323 break;
4324 }
Auke Kok8fc897b2006-08-28 14:56:16 -07004325 switch (temp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004326 case ID_LED_DEF1_ON2:
4327 case ID_LED_ON1_ON2:
4328 case ID_LED_OFF1_ON2:
4329 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
4330 hw->ledctl_mode2 |= ledctl_on << (i << 3);
4331 break;
4332 case ID_LED_DEF1_OFF2:
4333 case ID_LED_ON1_OFF2:
4334 case ID_LED_OFF1_OFF2:
4335 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
4336 hw->ledctl_mode2 |= ledctl_off << (i << 3);
4337 break;
4338 default:
4339 /* Do nothing */
4340 break;
4341 }
4342 }
4343 return E1000_SUCCESS;
4344}
4345
4346/******************************************************************************
4347 * Prepares SW controlable LED for use and saves the current state of the LED.
4348 *
4349 * hw - Struct containing variables accessed by shared code
4350 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004351s32 e1000_setup_led(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004352{
Joe Perches406874a2008-04-03 10:06:32 -07004353 u32 ledctl;
4354 s32 ret_val = E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004355
4356 DEBUGFUNC("e1000_setup_led");
4357
Auke Kok8fc897b2006-08-28 14:56:16 -07004358 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004359 case e1000_82542_rev2_0:
4360 case e1000_82542_rev2_1:
4361 case e1000_82543:
4362 case e1000_82544:
4363 /* No setup necessary */
4364 break;
4365 case e1000_82541:
4366 case e1000_82547:
4367 case e1000_82541_rev_2:
4368 case e1000_82547_rev_2:
4369 /* Turn off PHY Smart Power Down (if enabled) */
4370 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
4371 &hw->phy_spd_default);
Auke Kok8fc897b2006-08-28 14:56:16 -07004372 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004373 return ret_val;
4374 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
Joe Perches406874a2008-04-03 10:06:32 -07004375 (u16)(hw->phy_spd_default &
Linus Torvalds1da177e2005-04-16 15:20:36 -07004376 ~IGP01E1000_GMII_SPD));
Auke Kok8fc897b2006-08-28 14:56:16 -07004377 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004378 return ret_val;
4379 /* Fall Through */
4380 default:
Auke Kok8fc897b2006-08-28 14:56:16 -07004381 if (hw->media_type == e1000_media_type_fiber) {
Joe Perches1dc32912008-07-11 15:17:08 -07004382 ledctl = er32(LEDCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004383 /* Save current LEDCTL settings */
4384 hw->ledctl_default = ledctl;
4385 /* Turn off LED0 */
4386 ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
4387 E1000_LEDCTL_LED0_BLINK |
4388 E1000_LEDCTL_LED0_MODE_MASK);
4389 ledctl |= (E1000_LEDCTL_MODE_LED_OFF <<
4390 E1000_LEDCTL_LED0_MODE_SHIFT);
Joe Perches1dc32912008-07-11 15:17:08 -07004391 ew32(LEDCTL, ledctl);
Auke Kok8fc897b2006-08-28 14:56:16 -07004392 } else if (hw->media_type == e1000_media_type_copper)
Joe Perches1dc32912008-07-11 15:17:08 -07004393 ew32(LEDCTL, hw->ledctl_mode1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004394 break;
4395 }
4396
4397 return E1000_SUCCESS;
4398}
4399
Auke Kokf1b3a852006-06-27 09:07:56 -07004400/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07004401 * Restores the saved state of the SW controlable LED.
4402 *
4403 * hw - Struct containing variables accessed by shared code
4404 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004405s32 e1000_cleanup_led(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004406{
Joe Perches406874a2008-04-03 10:06:32 -07004407 s32 ret_val = E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004408
4409 DEBUGFUNC("e1000_cleanup_led");
4410
Auke Kok8fc897b2006-08-28 14:56:16 -07004411 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004412 case e1000_82542_rev2_0:
4413 case e1000_82542_rev2_1:
4414 case e1000_82543:
4415 case e1000_82544:
4416 /* No cleanup necessary */
4417 break;
4418 case e1000_82541:
4419 case e1000_82547:
4420 case e1000_82541_rev_2:
4421 case e1000_82547_rev_2:
4422 /* Turn on PHY Smart Power Down (if previously enabled) */
4423 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
4424 hw->phy_spd_default);
Auke Kok8fc897b2006-08-28 14:56:16 -07004425 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004426 return ret_val;
4427 /* Fall Through */
4428 default:
4429 /* Restore LEDCTL settings */
Joe Perches1dc32912008-07-11 15:17:08 -07004430 ew32(LEDCTL, hw->ledctl_default);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004431 break;
4432 }
4433
4434 return E1000_SUCCESS;
4435}
4436
4437/******************************************************************************
4438 * Turns on the software controllable LED
4439 *
4440 * hw - Struct containing variables accessed by shared code
4441 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004442s32 e1000_led_on(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004443{
Joe Perches1dc32912008-07-11 15:17:08 -07004444 u32 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004445
4446 DEBUGFUNC("e1000_led_on");
4447
Auke Kok8fc897b2006-08-28 14:56:16 -07004448 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004449 case e1000_82542_rev2_0:
4450 case e1000_82542_rev2_1:
4451 case e1000_82543:
4452 /* Set SW Defineable Pin 0 to turn on the LED */
4453 ctrl |= E1000_CTRL_SWDPIN0;
4454 ctrl |= E1000_CTRL_SWDPIO0;
4455 break;
4456 case e1000_82544:
Auke Kok8fc897b2006-08-28 14:56:16 -07004457 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004458 /* Set SW Defineable Pin 0 to turn on the LED */
4459 ctrl |= E1000_CTRL_SWDPIN0;
4460 ctrl |= E1000_CTRL_SWDPIO0;
4461 } else {
4462 /* Clear SW Defineable Pin 0 to turn on the LED */
4463 ctrl &= ~E1000_CTRL_SWDPIN0;
4464 ctrl |= E1000_CTRL_SWDPIO0;
4465 }
4466 break;
4467 default:
Auke Kok8fc897b2006-08-28 14:56:16 -07004468 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004469 /* Clear SW Defineable Pin 0 to turn on the LED */
4470 ctrl &= ~E1000_CTRL_SWDPIN0;
4471 ctrl |= E1000_CTRL_SWDPIO0;
Auke Kokcd94dd02006-06-27 09:08:22 -07004472 } else if (hw->media_type == e1000_media_type_copper) {
Joe Perches1dc32912008-07-11 15:17:08 -07004473 ew32(LEDCTL, hw->ledctl_mode2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004474 return E1000_SUCCESS;
4475 }
4476 break;
4477 }
4478
Joe Perches1dc32912008-07-11 15:17:08 -07004479 ew32(CTRL, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004480
4481 return E1000_SUCCESS;
4482}
4483
4484/******************************************************************************
4485 * Turns off the software controllable LED
4486 *
4487 * hw - Struct containing variables accessed by shared code
4488 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004489s32 e1000_led_off(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004490{
Joe Perches1dc32912008-07-11 15:17:08 -07004491 u32 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004492
4493 DEBUGFUNC("e1000_led_off");
4494
Auke Kok8fc897b2006-08-28 14:56:16 -07004495 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004496 case e1000_82542_rev2_0:
4497 case e1000_82542_rev2_1:
4498 case e1000_82543:
4499 /* Clear SW Defineable Pin 0 to turn off the LED */
4500 ctrl &= ~E1000_CTRL_SWDPIN0;
4501 ctrl |= E1000_CTRL_SWDPIO0;
4502 break;
4503 case e1000_82544:
Auke Kok8fc897b2006-08-28 14:56:16 -07004504 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004505 /* Clear SW Defineable Pin 0 to turn off the LED */
4506 ctrl &= ~E1000_CTRL_SWDPIN0;
4507 ctrl |= E1000_CTRL_SWDPIO0;
4508 } else {
4509 /* Set SW Defineable Pin 0 to turn off the LED */
4510 ctrl |= E1000_CTRL_SWDPIN0;
4511 ctrl |= E1000_CTRL_SWDPIO0;
4512 }
4513 break;
4514 default:
Auke Kok8fc897b2006-08-28 14:56:16 -07004515 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004516 /* Set SW Defineable Pin 0 to turn off the LED */
4517 ctrl |= E1000_CTRL_SWDPIN0;
4518 ctrl |= E1000_CTRL_SWDPIO0;
Auke Kokcd94dd02006-06-27 09:08:22 -07004519 } else if (hw->media_type == e1000_media_type_copper) {
Joe Perches1dc32912008-07-11 15:17:08 -07004520 ew32(LEDCTL, hw->ledctl_mode1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004521 return E1000_SUCCESS;
4522 }
4523 break;
4524 }
4525
Joe Perches1dc32912008-07-11 15:17:08 -07004526 ew32(CTRL, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004527
4528 return E1000_SUCCESS;
4529}
4530
4531/******************************************************************************
4532 * Clears all hardware statistics counters.
4533 *
4534 * hw - Struct containing variables accessed by shared code
4535 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004536static void e1000_clear_hw_cntrs(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004537{
Joe Perches406874a2008-04-03 10:06:32 -07004538 volatile u32 temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004539
Joe Perches1dc32912008-07-11 15:17:08 -07004540 temp = er32(CRCERRS);
4541 temp = er32(SYMERRS);
4542 temp = er32(MPC);
4543 temp = er32(SCC);
4544 temp = er32(ECOL);
4545 temp = er32(MCC);
4546 temp = er32(LATECOL);
4547 temp = er32(COLC);
4548 temp = er32(DC);
4549 temp = er32(SEC);
4550 temp = er32(RLEC);
4551 temp = er32(XONRXC);
4552 temp = er32(XONTXC);
4553 temp = er32(XOFFRXC);
4554 temp = er32(XOFFTXC);
4555 temp = er32(FCRUC);
Auke Kokcd94dd02006-06-27 09:08:22 -07004556
Joe Perches1dc32912008-07-11 15:17:08 -07004557 temp = er32(PRC64);
4558 temp = er32(PRC127);
4559 temp = er32(PRC255);
4560 temp = er32(PRC511);
4561 temp = er32(PRC1023);
4562 temp = er32(PRC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07004563
Joe Perches1dc32912008-07-11 15:17:08 -07004564 temp = er32(GPRC);
4565 temp = er32(BPRC);
4566 temp = er32(MPRC);
4567 temp = er32(GPTC);
4568 temp = er32(GORCL);
4569 temp = er32(GORCH);
4570 temp = er32(GOTCL);
4571 temp = er32(GOTCH);
4572 temp = er32(RNBC);
4573 temp = er32(RUC);
4574 temp = er32(RFC);
4575 temp = er32(ROC);
4576 temp = er32(RJC);
4577 temp = er32(TORL);
4578 temp = er32(TORH);
4579 temp = er32(TOTL);
4580 temp = er32(TOTH);
4581 temp = er32(TPR);
4582 temp = er32(TPT);
Auke Kokcd94dd02006-06-27 09:08:22 -07004583
Joe Perches1dc32912008-07-11 15:17:08 -07004584 temp = er32(PTC64);
4585 temp = er32(PTC127);
4586 temp = er32(PTC255);
4587 temp = er32(PTC511);
4588 temp = er32(PTC1023);
4589 temp = er32(PTC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07004590
Joe Perches1dc32912008-07-11 15:17:08 -07004591 temp = er32(MPTC);
4592 temp = er32(BPTC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004593
Auke Kok8fc897b2006-08-28 14:56:16 -07004594 if (hw->mac_type < e1000_82543) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004595
Joe Perches1dc32912008-07-11 15:17:08 -07004596 temp = er32(ALGNERRC);
4597 temp = er32(RXERRC);
4598 temp = er32(TNCRS);
4599 temp = er32(CEXTERR);
4600 temp = er32(TSCTC);
4601 temp = er32(TSCTFC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004602
Auke Kok8fc897b2006-08-28 14:56:16 -07004603 if (hw->mac_type <= e1000_82544) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004604
Joe Perches1dc32912008-07-11 15:17:08 -07004605 temp = er32(MGTPRC);
4606 temp = er32(MGTPDC);
4607 temp = er32(MGTPTC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004608}
4609
4610/******************************************************************************
4611 * Resets Adaptive IFS to its default state.
4612 *
4613 * hw - Struct containing variables accessed by shared code
4614 *
4615 * Call this after e1000_init_hw. You may override the IFS defaults by setting
Joe Perchesc3033b02008-03-21 11:06:25 -07004616 * hw->ifs_params_forced to true. However, you must initialize hw->
Linus Torvalds1da177e2005-04-16 15:20:36 -07004617 * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio
4618 * before calling this function.
4619 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004620void e1000_reset_adaptive(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004621{
4622 DEBUGFUNC("e1000_reset_adaptive");
4623
Auke Kok8fc897b2006-08-28 14:56:16 -07004624 if (hw->adaptive_ifs) {
4625 if (!hw->ifs_params_forced) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004626 hw->current_ifs_val = 0;
4627 hw->ifs_min_val = IFS_MIN;
4628 hw->ifs_max_val = IFS_MAX;
4629 hw->ifs_step_size = IFS_STEP;
4630 hw->ifs_ratio = IFS_RATIO;
4631 }
Joe Perchesc3033b02008-03-21 11:06:25 -07004632 hw->in_ifs_mode = false;
Joe Perches1dc32912008-07-11 15:17:08 -07004633 ew32(AIT, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004634 } else {
4635 DEBUGOUT("Not in Adaptive IFS mode!\n");
4636 }
4637}
4638
4639/******************************************************************************
4640 * Called during the callback/watchdog routine to update IFS value based on
4641 * the ratio of transmits to collisions.
4642 *
4643 * hw - Struct containing variables accessed by shared code
4644 * tx_packets - Number of transmits since last callback
4645 * total_collisions - Number of collisions since last callback
4646 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004647void e1000_update_adaptive(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004648{
4649 DEBUGFUNC("e1000_update_adaptive");
4650
Auke Kok8fc897b2006-08-28 14:56:16 -07004651 if (hw->adaptive_ifs) {
4652 if ((hw->collision_delta * hw->ifs_ratio) > hw->tx_packet_delta) {
4653 if (hw->tx_packet_delta > MIN_NUM_XMITS) {
Joe Perchesc3033b02008-03-21 11:06:25 -07004654 hw->in_ifs_mode = true;
Auke Kok8fc897b2006-08-28 14:56:16 -07004655 if (hw->current_ifs_val < hw->ifs_max_val) {
4656 if (hw->current_ifs_val == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004657 hw->current_ifs_val = hw->ifs_min_val;
4658 else
4659 hw->current_ifs_val += hw->ifs_step_size;
Joe Perches1dc32912008-07-11 15:17:08 -07004660 ew32(AIT, hw->current_ifs_val);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004661 }
4662 }
4663 } else {
Auke Kok8fc897b2006-08-28 14:56:16 -07004664 if (hw->in_ifs_mode && (hw->tx_packet_delta <= MIN_NUM_XMITS)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004665 hw->current_ifs_val = 0;
Joe Perchesc3033b02008-03-21 11:06:25 -07004666 hw->in_ifs_mode = false;
Joe Perches1dc32912008-07-11 15:17:08 -07004667 ew32(AIT, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004668 }
4669 }
4670 } else {
4671 DEBUGOUT("Not in Adaptive IFS mode!\n");
4672 }
4673}
4674
4675/******************************************************************************
4676 * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT
4677 *
4678 * hw - Struct containing variables accessed by shared code
4679 * frame_len - The length of the frame in question
4680 * mac_addr - The Ethernet destination address of the frame in question
4681 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004682void e1000_tbi_adjust_stats(struct e1000_hw *hw, struct e1000_hw_stats *stats,
4683 u32 frame_len, u8 *mac_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004684{
Joe Perches406874a2008-04-03 10:06:32 -07004685 u64 carry_bit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004686
4687 /* First adjust the frame length. */
4688 frame_len--;
4689 /* We need to adjust the statistics counters, since the hardware
4690 * counters overcount this packet as a CRC error and undercount
4691 * the packet as a good packet
4692 */
4693 /* This packet should not be counted as a CRC error. */
4694 stats->crcerrs--;
4695 /* This packet does count as a Good Packet Received. */
4696 stats->gprc++;
4697
4698 /* Adjust the Good Octets received counters */
4699 carry_bit = 0x80000000 & stats->gorcl;
4700 stats->gorcl += frame_len;
4701 /* If the high bit of Gorcl (the low 32 bits of the Good Octets
4702 * Received Count) was one before the addition,
4703 * AND it is zero after, then we lost the carry out,
4704 * need to add one to Gorch (Good Octets Received Count High).
4705 * This could be simplified if all environments supported
4706 * 64-bit integers.
4707 */
Auke Kok8fc897b2006-08-28 14:56:16 -07004708 if (carry_bit && ((stats->gorcl & 0x80000000) == 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004709 stats->gorch++;
4710 /* Is this a broadcast or multicast? Check broadcast first,
4711 * since the test for a multicast frame will test positive on
4712 * a broadcast frame.
4713 */
Joe Perchese982f172008-07-11 15:17:18 -07004714 if ((mac_addr[0] == (u8)0xff) && (mac_addr[1] == (u8)0xff))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004715 /* Broadcast packet */
4716 stats->bprc++;
Auke Kok8fc897b2006-08-28 14:56:16 -07004717 else if (*mac_addr & 0x01)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004718 /* Multicast packet */
4719 stats->mprc++;
4720
Auke Kok8fc897b2006-08-28 14:56:16 -07004721 if (frame_len == hw->max_frame_size) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004722 /* In this case, the hardware has overcounted the number of
4723 * oversize frames.
4724 */
Auke Kok8fc897b2006-08-28 14:56:16 -07004725 if (stats->roc > 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004726 stats->roc--;
4727 }
4728
4729 /* Adjust the bin counters when the extra byte put the frame in the
4730 * wrong bin. Remember that the frame_len was adjusted above.
4731 */
Auke Kok8fc897b2006-08-28 14:56:16 -07004732 if (frame_len == 64) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004733 stats->prc64++;
4734 stats->prc127--;
Auke Kok8fc897b2006-08-28 14:56:16 -07004735 } else if (frame_len == 127) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004736 stats->prc127++;
4737 stats->prc255--;
Auke Kok8fc897b2006-08-28 14:56:16 -07004738 } else if (frame_len == 255) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004739 stats->prc255++;
4740 stats->prc511--;
Auke Kok8fc897b2006-08-28 14:56:16 -07004741 } else if (frame_len == 511) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004742 stats->prc511++;
4743 stats->prc1023--;
Auke Kok8fc897b2006-08-28 14:56:16 -07004744 } else if (frame_len == 1023) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004745 stats->prc1023++;
4746 stats->prc1522--;
Auke Kok8fc897b2006-08-28 14:56:16 -07004747 } else if (frame_len == 1522) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004748 stats->prc1522++;
4749 }
4750}
4751
4752/******************************************************************************
4753 * Gets the current PCI bus type, speed, and width of the hardware
4754 *
4755 * hw - Struct containing variables accessed by shared code
4756 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004757void e1000_get_bus_info(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004758{
Joe Perches406874a2008-04-03 10:06:32 -07004759 u32 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004760
4761 switch (hw->mac_type) {
4762 case e1000_82542_rev2_0:
4763 case e1000_82542_rev2_1:
Jeff Kirsherc3813ae2006-12-15 10:37:32 +01004764 hw->bus_type = e1000_bus_type_pci;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004765 hw->bus_speed = e1000_bus_speed_unknown;
4766 hw->bus_width = e1000_bus_width_unknown;
4767 break;
4768 default:
Joe Perches1dc32912008-07-11 15:17:08 -07004769 status = er32(STATUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004770 hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
4771 e1000_bus_type_pcix : e1000_bus_type_pci;
4772
Auke Kok8fc897b2006-08-28 14:56:16 -07004773 if (hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004774 hw->bus_speed = (hw->bus_type == e1000_bus_type_pci) ?
4775 e1000_bus_speed_66 : e1000_bus_speed_120;
Auke Kok8fc897b2006-08-28 14:56:16 -07004776 } else if (hw->bus_type == e1000_bus_type_pci) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004777 hw->bus_speed = (status & E1000_STATUS_PCI66) ?
4778 e1000_bus_speed_66 : e1000_bus_speed_33;
4779 } else {
4780 switch (status & E1000_STATUS_PCIX_SPEED) {
4781 case E1000_STATUS_PCIX_SPEED_66:
4782 hw->bus_speed = e1000_bus_speed_66;
4783 break;
4784 case E1000_STATUS_PCIX_SPEED_100:
4785 hw->bus_speed = e1000_bus_speed_100;
4786 break;
4787 case E1000_STATUS_PCIX_SPEED_133:
4788 hw->bus_speed = e1000_bus_speed_133;
4789 break;
4790 default:
4791 hw->bus_speed = e1000_bus_speed_reserved;
4792 break;
4793 }
4794 }
4795 hw->bus_width = (status & E1000_STATUS_BUS64) ?
4796 e1000_bus_width_64 : e1000_bus_width_32;
4797 break;
4798 }
4799}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004800
4801/******************************************************************************
4802 * Writes a value to one of the devices registers using port I/O (as opposed to
4803 * memory mapped I/O). Only 82544 and newer devices support port I/O.
4804 *
4805 * hw - Struct containing variables accessed by shared code
4806 * offset - offset to write to
4807 * value - value to write
4808 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004809static void e1000_write_reg_io(struct e1000_hw *hw, u32 offset, u32 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004810{
4811 unsigned long io_addr = hw->io_base;
4812 unsigned long io_data = hw->io_base + 4;
4813
4814 e1000_io_write(hw, io_addr, offset);
4815 e1000_io_write(hw, io_data, value);
4816}
4817
Linus Torvalds1da177e2005-04-16 15:20:36 -07004818/******************************************************************************
4819 * Estimates the cable length.
4820 *
4821 * hw - Struct containing variables accessed by shared code
4822 * min_length - The estimated minimum length
4823 * max_length - The estimated maximum length
4824 *
4825 * returns: - E1000_ERR_XXX
4826 * E1000_SUCCESS
4827 *
4828 * This function always returns a ranged length (minimum & maximum).
4829 * So for M88 phy's, this function interprets the one value returned from the
4830 * register to the minimum and maximum range.
4831 * For IGP phy's, the function calculates the range by the AGC registers.
4832 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004833static s32 e1000_get_cable_length(struct e1000_hw *hw, u16 *min_length,
4834 u16 *max_length)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004835{
Joe Perches406874a2008-04-03 10:06:32 -07004836 s32 ret_val;
4837 u16 agc_value = 0;
4838 u16 i, phy_data;
4839 u16 cable_length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004840
4841 DEBUGFUNC("e1000_get_cable_length");
4842
4843 *min_length = *max_length = 0;
4844
4845 /* Use old method for Phy older than IGP */
Auke Kok8fc897b2006-08-28 14:56:16 -07004846 if (hw->phy_type == e1000_phy_m88) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004847
Linus Torvalds1da177e2005-04-16 15:20:36 -07004848 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
4849 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004850 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004851 return ret_val;
4852 cable_length = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
4853 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
4854
4855 /* Convert the enum value to ranged values */
4856 switch (cable_length) {
4857 case e1000_cable_length_50:
4858 *min_length = 0;
4859 *max_length = e1000_igp_cable_length_50;
4860 break;
4861 case e1000_cable_length_50_80:
4862 *min_length = e1000_igp_cable_length_50;
4863 *max_length = e1000_igp_cable_length_80;
4864 break;
4865 case e1000_cable_length_80_110:
4866 *min_length = e1000_igp_cable_length_80;
4867 *max_length = e1000_igp_cable_length_110;
4868 break;
4869 case e1000_cable_length_110_140:
4870 *min_length = e1000_igp_cable_length_110;
4871 *max_length = e1000_igp_cable_length_140;
4872 break;
4873 case e1000_cable_length_140:
4874 *min_length = e1000_igp_cable_length_140;
4875 *max_length = e1000_igp_cable_length_170;
4876 break;
4877 default:
4878 return -E1000_ERR_PHY;
4879 break;
4880 }
Auke Kok8fc897b2006-08-28 14:56:16 -07004881 } else if (hw->phy_type == e1000_phy_igp) { /* For IGP PHY */
Joe Perches406874a2008-04-03 10:06:32 -07004882 u16 cur_agc_value;
4883 u16 min_agc_value = IGP01E1000_AGC_LENGTH_TABLE_SIZE;
4884 u16 agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
Linus Torvalds1da177e2005-04-16 15:20:36 -07004885 {IGP01E1000_PHY_AGC_A,
4886 IGP01E1000_PHY_AGC_B,
4887 IGP01E1000_PHY_AGC_C,
4888 IGP01E1000_PHY_AGC_D};
4889 /* Read the AGC registers for all channels */
Auke Kok8fc897b2006-08-28 14:56:16 -07004890 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004891
4892 ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004893 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004894 return ret_val;
4895
Auke Kokcd94dd02006-06-27 09:08:22 -07004896 cur_agc_value = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004897
Auke Kokcd94dd02006-06-27 09:08:22 -07004898 /* Value bound check. */
4899 if ((cur_agc_value >= IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1) ||
4900 (cur_agc_value == 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004901 return -E1000_ERR_PHY;
4902
Auke Kokcd94dd02006-06-27 09:08:22 -07004903 agc_value += cur_agc_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004904
4905 /* Update minimal AGC value. */
Auke Kokcd94dd02006-06-27 09:08:22 -07004906 if (min_agc_value > cur_agc_value)
4907 min_agc_value = cur_agc_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004908 }
4909
4910 /* Remove the minimal AGC result for length < 50m */
Auke Kokcd94dd02006-06-27 09:08:22 -07004911 if (agc_value < IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) {
4912 agc_value -= min_agc_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004913
4914 /* Get the average length of the remaining 3 channels */
4915 agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1);
4916 } else {
4917 /* Get the average length of all the 4 channels. */
4918 agc_value /= IGP01E1000_PHY_CHANNEL_NUM;
4919 }
4920
4921 /* Set the range of the calculated length. */
4922 *min_length = ((e1000_igp_cable_length_table[agc_value] -
4923 IGP01E1000_AGC_RANGE) > 0) ?
4924 (e1000_igp_cable_length_table[agc_value] -
4925 IGP01E1000_AGC_RANGE) : 0;
4926 *max_length = e1000_igp_cable_length_table[agc_value] +
4927 IGP01E1000_AGC_RANGE;
4928 }
4929
4930 return E1000_SUCCESS;
4931}
4932
4933/******************************************************************************
4934 * Check the cable polarity
4935 *
4936 * hw - Struct containing variables accessed by shared code
4937 * polarity - output parameter : 0 - Polarity is not reversed
4938 * 1 - Polarity is reversed.
4939 *
4940 * returns: - E1000_ERR_XXX
4941 * E1000_SUCCESS
4942 *
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02004943 * For phy's older than IGP, this function simply reads the polarity bit in the
Linus Torvalds1da177e2005-04-16 15:20:36 -07004944 * Phy Status register. For IGP phy's, this bit is valid only if link speed is
4945 * 10 Mbps. If the link speed is 100 Mbps there is no polarity so this bit will
4946 * return 0. If the link speed is 1000 Mbps the polarity status is in the
4947 * IGP01E1000_PHY_PCS_INIT_REG.
4948 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004949static s32 e1000_check_polarity(struct e1000_hw *hw,
4950 e1000_rev_polarity *polarity)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004951{
Joe Perches406874a2008-04-03 10:06:32 -07004952 s32 ret_val;
4953 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004954
4955 DEBUGFUNC("e1000_check_polarity");
4956
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00004957 if (hw->phy_type == e1000_phy_m88) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004958 /* return the Polarity bit in the Status register. */
4959 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
4960 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004961 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004962 return ret_val;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004963 *polarity = ((phy_data & M88E1000_PSSR_REV_POLARITY) >>
4964 M88E1000_PSSR_REV_POLARITY_SHIFT) ?
4965 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
4966
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00004967 } else if (hw->phy_type == e1000_phy_igp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004968 /* Read the Status register to check the speed */
4969 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
4970 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004971 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004972 return ret_val;
4973
4974 /* If speed is 1000 Mbps, must read the IGP01E1000_PHY_PCS_INIT_REG to
4975 * find the polarity status */
Auke Kok8fc897b2006-08-28 14:56:16 -07004976 if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
Linus Torvalds1da177e2005-04-16 15:20:36 -07004977 IGP01E1000_PSSR_SPEED_1000MBPS) {
4978
4979 /* Read the GIG initialization PCS register (0x00B4) */
4980 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG,
4981 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004982 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004983 return ret_val;
4984
4985 /* Check the polarity bits */
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004986 *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ?
4987 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004988 } else {
4989 /* For 10 Mbps, read the polarity bit in the status register. (for
4990 * 100 Mbps this bit is always 0) */
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004991 *polarity = (phy_data & IGP01E1000_PSSR_POLARITY_REVERSED) ?
4992 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004993 }
4994 }
4995 return E1000_SUCCESS;
4996}
4997
4998/******************************************************************************
4999 * Check if Downshift occured
5000 *
5001 * hw - Struct containing variables accessed by shared code
5002 * downshift - output parameter : 0 - No Downshift ocured.
5003 * 1 - Downshift ocured.
5004 *
5005 * returns: - E1000_ERR_XXX
Auke Kok76c224b2006-05-23 13:36:06 -07005006 * E1000_SUCCESS
Linus Torvalds1da177e2005-04-16 15:20:36 -07005007 *
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02005008 * For phy's older than IGP, this function reads the Downshift bit in the Phy
Linus Torvalds1da177e2005-04-16 15:20:36 -07005009 * Specific Status register. For IGP phy's, it reads the Downgrade bit in the
5010 * Link Health register. In IGP this bit is latched high, so the driver must
5011 * read it immediately after link is established.
5012 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07005013static s32 e1000_check_downshift(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005014{
Joe Perches406874a2008-04-03 10:06:32 -07005015 s32 ret_val;
5016 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005017
5018 DEBUGFUNC("e1000_check_downshift");
5019
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00005020 if (hw->phy_type == e1000_phy_igp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005021 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH,
5022 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005023 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005024 return ret_val;
5025
5026 hw->speed_downgraded = (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0;
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00005027 } else if (hw->phy_type == e1000_phy_m88) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005028 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
5029 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005030 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005031 return ret_val;
5032
5033 hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >>
5034 M88E1000_PSSR_DOWNSHIFT_SHIFT;
5035 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005036
Linus Torvalds1da177e2005-04-16 15:20:36 -07005037 return E1000_SUCCESS;
5038}
5039
5040/*****************************************************************************
5041 *
5042 * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a
5043 * gigabit link is achieved to improve link quality.
5044 *
5045 * hw: Struct containing variables accessed by shared code
5046 *
5047 * returns: - E1000_ERR_PHY if fail to read/write the PHY
5048 * E1000_SUCCESS at any other case.
5049 *
5050 ****************************************************************************/
5051
Joe Perches64798842008-07-11 15:17:02 -07005052static s32 e1000_config_dsp_after_link_change(struct e1000_hw *hw, bool link_up)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005053{
Joe Perches406874a2008-04-03 10:06:32 -07005054 s32 ret_val;
5055 u16 phy_data, phy_saved_data, speed, duplex, i;
5056 u16 dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
Linus Torvalds1da177e2005-04-16 15:20:36 -07005057 {IGP01E1000_PHY_AGC_PARAM_A,
5058 IGP01E1000_PHY_AGC_PARAM_B,
5059 IGP01E1000_PHY_AGC_PARAM_C,
5060 IGP01E1000_PHY_AGC_PARAM_D};
Joe Perches406874a2008-04-03 10:06:32 -07005061 u16 min_length, max_length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005062
5063 DEBUGFUNC("e1000_config_dsp_after_link_change");
5064
Auke Kok8fc897b2006-08-28 14:56:16 -07005065 if (hw->phy_type != e1000_phy_igp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005066 return E1000_SUCCESS;
5067
Auke Kok8fc897b2006-08-28 14:56:16 -07005068 if (link_up) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005069 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
Auke Kok8fc897b2006-08-28 14:56:16 -07005070 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005071 DEBUGOUT("Error getting link speed and duplex\n");
5072 return ret_val;
5073 }
5074
Auke Kok8fc897b2006-08-28 14:56:16 -07005075 if (speed == SPEED_1000) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005076
Auke Kokcd94dd02006-06-27 09:08:22 -07005077 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
5078 if (ret_val)
5079 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005080
Auke Kok8fc897b2006-08-28 14:56:16 -07005081 if ((hw->dsp_config_state == e1000_dsp_config_enabled) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07005082 min_length >= e1000_igp_cable_length_50) {
5083
Auke Kok8fc897b2006-08-28 14:56:16 -07005084 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005085 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i],
5086 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005087 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005088 return ret_val;
5089
5090 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
5091
5092 ret_val = e1000_write_phy_reg(hw, dsp_reg_array[i],
5093 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005094 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005095 return ret_val;
5096 }
5097 hw->dsp_config_state = e1000_dsp_config_activated;
5098 }
5099
Auke Kok8fc897b2006-08-28 14:56:16 -07005100 if ((hw->ffe_config_state == e1000_ffe_config_enabled) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07005101 (min_length < e1000_igp_cable_length_50)) {
5102
Joe Perches406874a2008-04-03 10:06:32 -07005103 u16 ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_20;
5104 u32 idle_errs = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005105
5106 /* clear previous idle error counts */
5107 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
5108 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005109 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005110 return ret_val;
5111
Auke Kok8fc897b2006-08-28 14:56:16 -07005112 for (i = 0; i < ffe_idle_err_timeout; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005113 udelay(1000);
5114 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
5115 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005116 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005117 return ret_val;
5118
5119 idle_errs += (phy_data & SR_1000T_IDLE_ERROR_CNT);
Auke Kok8fc897b2006-08-28 14:56:16 -07005120 if (idle_errs > SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005121 hw->ffe_config_state = e1000_ffe_config_active;
5122
5123 ret_val = e1000_write_phy_reg(hw,
5124 IGP01E1000_PHY_DSP_FFE,
5125 IGP01E1000_PHY_DSP_FFE_CM_CP);
Auke Kok8fc897b2006-08-28 14:56:16 -07005126 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005127 return ret_val;
5128 break;
5129 }
5130
Auke Kok8fc897b2006-08-28 14:56:16 -07005131 if (idle_errs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005132 ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_100;
5133 }
5134 }
5135 }
5136 } else {
Auke Kok8fc897b2006-08-28 14:56:16 -07005137 if (hw->dsp_config_state == e1000_dsp_config_activated) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005138 /* Save off the current value of register 0x2F5B to be restored at
5139 * the end of the routines. */
5140 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
5141
Auke Kok8fc897b2006-08-28 14:56:16 -07005142 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005143 return ret_val;
5144
5145 /* Disable the PHY transmitter */
5146 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
5147
Auke Kok8fc897b2006-08-28 14:56:16 -07005148 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005149 return ret_val;
5150
Jeff Garzikf8ec4732006-09-19 15:27:07 -04005151 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005152
5153 ret_val = e1000_write_phy_reg(hw, 0x0000,
5154 IGP01E1000_IEEE_FORCE_GIGA);
Auke Kok8fc897b2006-08-28 14:56:16 -07005155 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005156 return ret_val;
Auke Kok8fc897b2006-08-28 14:56:16 -07005157 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005158 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i], &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005159 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005160 return ret_val;
5161
5162 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
5163 phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS;
5164
5165 ret_val = e1000_write_phy_reg(hw,dsp_reg_array[i], phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005166 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005167 return ret_val;
5168 }
5169
5170 ret_val = e1000_write_phy_reg(hw, 0x0000,
5171 IGP01E1000_IEEE_RESTART_AUTONEG);
Auke Kok8fc897b2006-08-28 14:56:16 -07005172 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005173 return ret_val;
5174
Jeff Garzikf8ec4732006-09-19 15:27:07 -04005175 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005176
5177 /* Now enable the transmitter */
5178 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
5179
Auke Kok8fc897b2006-08-28 14:56:16 -07005180 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005181 return ret_val;
5182
5183 hw->dsp_config_state = e1000_dsp_config_enabled;
5184 }
5185
Auke Kok8fc897b2006-08-28 14:56:16 -07005186 if (hw->ffe_config_state == e1000_ffe_config_active) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005187 /* Save off the current value of register 0x2F5B to be restored at
5188 * the end of the routines. */
5189 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
5190
Auke Kok8fc897b2006-08-28 14:56:16 -07005191 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005192 return ret_val;
5193
5194 /* Disable the PHY transmitter */
5195 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
5196
Auke Kok8fc897b2006-08-28 14:56:16 -07005197 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005198 return ret_val;
5199
Jeff Garzikf8ec4732006-09-19 15:27:07 -04005200 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005201
5202 ret_val = e1000_write_phy_reg(hw, 0x0000,
5203 IGP01E1000_IEEE_FORCE_GIGA);
Auke Kok8fc897b2006-08-28 14:56:16 -07005204 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005205 return ret_val;
5206 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE,
5207 IGP01E1000_PHY_DSP_FFE_DEFAULT);
Auke Kok8fc897b2006-08-28 14:56:16 -07005208 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005209 return ret_val;
5210
5211 ret_val = e1000_write_phy_reg(hw, 0x0000,
5212 IGP01E1000_IEEE_RESTART_AUTONEG);
Auke Kok8fc897b2006-08-28 14:56:16 -07005213 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005214 return ret_val;
5215
Jeff Garzikf8ec4732006-09-19 15:27:07 -04005216 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005217
5218 /* Now enable the transmitter */
5219 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
5220
Auke Kok8fc897b2006-08-28 14:56:16 -07005221 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005222 return ret_val;
5223
5224 hw->ffe_config_state = e1000_ffe_config_enabled;
5225 }
5226 }
5227 return E1000_SUCCESS;
5228}
5229
5230/*****************************************************************************
5231 * Set PHY to class A mode
5232 * Assumes the following operations will follow to enable the new class mode.
5233 * 1. Do a PHY soft reset
5234 * 2. Restart auto-negotiation or force link.
5235 *
5236 * hw - Struct containing variables accessed by shared code
5237 ****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07005238static s32 e1000_set_phy_mode(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005239{
Joe Perches406874a2008-04-03 10:06:32 -07005240 s32 ret_val;
5241 u16 eeprom_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005242
5243 DEBUGFUNC("e1000_set_phy_mode");
5244
Auke Kok8fc897b2006-08-28 14:56:16 -07005245 if ((hw->mac_type == e1000_82545_rev_3) &&
5246 (hw->media_type == e1000_media_type_copper)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005247 ret_val = e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, 1, &eeprom_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005248 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005249 return ret_val;
5250 }
5251
Auke Kok8fc897b2006-08-28 14:56:16 -07005252 if ((eeprom_data != EEPROM_RESERVED_WORD) &&
5253 (eeprom_data & EEPROM_PHY_CLASS_A)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005254 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x000B);
Auke Kok8fc897b2006-08-28 14:56:16 -07005255 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005256 return ret_val;
5257 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x8104);
Auke Kok8fc897b2006-08-28 14:56:16 -07005258 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005259 return ret_val;
5260
Joe Perchesc3033b02008-03-21 11:06:25 -07005261 hw->phy_reset_disable = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005262 }
5263 }
5264
5265 return E1000_SUCCESS;
5266}
5267
5268/*****************************************************************************
5269 *
5270 * This function sets the lplu state according to the active flag. When
5271 * activating lplu this function also disables smart speed and vise versa.
5272 * lplu will not be activated unless the device autonegotiation advertisment
5273 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
5274 * hw: Struct containing variables accessed by shared code
5275 * active - true to enable lplu false to disable lplu.
5276 *
5277 * returns: - E1000_ERR_PHY if fail to read/write the PHY
5278 * E1000_SUCCESS at any other case.
5279 *
5280 ****************************************************************************/
5281
Joe Perches64798842008-07-11 15:17:02 -07005282static s32 e1000_set_d3_lplu_state(struct e1000_hw *hw, bool active)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005283{
Joe Perches406874a2008-04-03 10:06:32 -07005284 s32 ret_val;
5285 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005286 DEBUGFUNC("e1000_set_d3_lplu_state");
5287
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00005288 if (hw->phy_type != e1000_phy_igp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005289 return E1000_SUCCESS;
5290
5291 /* During driver activity LPLU should not be used or it will attain link
5292 * from the lowest speeds starting from 10Mbps. The capability is used for
5293 * Dx transitions and states */
Auke Kokcd94dd02006-06-27 09:08:22 -07005294 if (hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005295 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data);
Auke Kokcd94dd02006-06-27 09:08:22 -07005296 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005297 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005298 } else {
5299 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005300 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005301 return ret_val;
5302 }
5303
Auke Kok8fc897b2006-08-28 14:56:16 -07005304 if (!active) {
5305 if (hw->mac_type == e1000_82541_rev_2 ||
5306 hw->mac_type == e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005307 phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
5308 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005309 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005310 return ret_val;
5311 } else {
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00005312 phy_data &= ~IGP02E1000_PM_D3_LPLU;
5313 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
5314 phy_data);
5315 if (ret_val)
5316 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005317 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005318
5319 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
5320 * Dx states where the power conservation is most important. During
5321 * driver activity we should enable SmartSpeed, so performance is
5322 * maintained. */
5323 if (hw->smart_speed == e1000_smart_speed_on) {
5324 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5325 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005326 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005327 return ret_val;
5328
5329 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
5330 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5331 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005332 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005333 return ret_val;
5334 } else if (hw->smart_speed == e1000_smart_speed_off) {
5335 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5336 &phy_data);
Nicholas Nunley35574762006-09-27 12:53:34 -07005337 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005338 return ret_val;
5339
5340 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
5341 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5342 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005343 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005344 return ret_val;
5345 }
5346
Auke Kok8fc897b2006-08-28 14:56:16 -07005347 } else if ((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT) ||
5348 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL ) ||
5349 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005350
Auke Kok8fc897b2006-08-28 14:56:16 -07005351 if (hw->mac_type == e1000_82541_rev_2 ||
Auke Kokcd94dd02006-06-27 09:08:22 -07005352 hw->mac_type == e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005353 phy_data |= IGP01E1000_GMII_FLEX_SPD;
5354 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005355 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005356 return ret_val;
5357 } else {
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00005358 phy_data |= IGP02E1000_PM_D3_LPLU;
5359 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005360 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005361 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005362 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07005363 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005364
Linus Torvalds1da177e2005-04-16 15:20:36 -07005365 /* When LPLU is enabled we should disable SmartSpeed */
5366 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005367 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005368 return ret_val;
5369
5370 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
5371 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005372 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005373 return ret_val;
5374
5375 }
5376 return E1000_SUCCESS;
5377}
5378
5379/******************************************************************************
5380 * Change VCO speed register to improve Bit Error Rate performance of SERDES.
5381 *
5382 * hw - Struct containing variables accessed by shared code
5383 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07005384static s32 e1000_set_vco_speed(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005385{
Joe Perches406874a2008-04-03 10:06:32 -07005386 s32 ret_val;
5387 u16 default_page = 0;
5388 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005389
5390 DEBUGFUNC("e1000_set_vco_speed");
5391
Auke Kok8fc897b2006-08-28 14:56:16 -07005392 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005393 case e1000_82545_rev_3:
5394 case e1000_82546_rev_3:
5395 break;
5396 default:
5397 return E1000_SUCCESS;
5398 }
5399
5400 /* Set PHY register 30, page 5, bit 8 to 0 */
5401
5402 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, &default_page);
Auke Kok8fc897b2006-08-28 14:56:16 -07005403 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005404 return ret_val;
5405
5406 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005);
Auke Kok8fc897b2006-08-28 14:56:16 -07005407 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005408 return ret_val;
5409
5410 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005411 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005412 return ret_val;
5413
5414 phy_data &= ~M88E1000_PHY_VCO_REG_BIT8;
5415 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005416 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005417 return ret_val;
5418
5419 /* Set PHY register 30, page 4, bit 11 to 1 */
5420
5421 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004);
Auke Kok8fc897b2006-08-28 14:56:16 -07005422 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005423 return ret_val;
5424
5425 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005426 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005427 return ret_val;
5428
5429 phy_data |= M88E1000_PHY_VCO_REG_BIT11;
5430 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005431 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005432 return ret_val;
5433
5434 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, default_page);
Auke Kok8fc897b2006-08-28 14:56:16 -07005435 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005436 return ret_val;
5437
5438 return E1000_SUCCESS;
5439}
5440
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005441
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005442/******************************************************************************
5443 * Verifies the hardware needs to allow ARPs to be processed by the host
5444 *
5445 * hw - Struct containing variables accessed by shared code
5446 *
Joe Perchesc3033b02008-03-21 11:06:25 -07005447 * returns: - true/false
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005448 *
5449 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07005450u32 e1000_enable_mng_pass_thru(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005451{
Joe Perches406874a2008-04-03 10:06:32 -07005452 u32 manc;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005453
5454 if (hw->asf_firmware_present) {
Joe Perches1dc32912008-07-11 15:17:08 -07005455 manc = er32(MANC);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005456
5457 if (!(manc & E1000_MANC_RCV_TCO_EN) ||
5458 !(manc & E1000_MANC_EN_MAC_ADDR_FILTER))
Joe Perchesc3033b02008-03-21 11:06:25 -07005459 return false;
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00005460 if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN))
5461 return true;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005462 }
Joe Perchesc3033b02008-03-21 11:06:25 -07005463 return false;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005464}
5465
Joe Perches64798842008-07-11 15:17:02 -07005466static s32 e1000_polarity_reversal_workaround(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005467{
Joe Perches406874a2008-04-03 10:06:32 -07005468 s32 ret_val;
5469 u16 mii_status_reg;
5470 u16 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005471
5472 /* Polarity reversal workaround for forced 10F/10H links. */
5473
5474 /* Disable the transmitter on the PHY */
5475
5476 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
Auke Kok8fc897b2006-08-28 14:56:16 -07005477 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005478 return ret_val;
5479 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF);
Auke Kok8fc897b2006-08-28 14:56:16 -07005480 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005481 return ret_val;
5482
5483 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
Auke Kok8fc897b2006-08-28 14:56:16 -07005484 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005485 return ret_val;
5486
5487 /* This loop will early-out if the NO link condition has been met. */
Auke Kok8fc897b2006-08-28 14:56:16 -07005488 for (i = PHY_FORCE_TIME; i > 0; i--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005489 /* Read the MII Status Register and wait for Link Status bit
5490 * to be clear.
5491 */
5492
5493 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07005494 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005495 return ret_val;
5496
5497 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07005498 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005499 return ret_val;
5500
Auke Kok8fc897b2006-08-28 14:56:16 -07005501 if ((mii_status_reg & ~MII_SR_LINK_STATUS) == 0) break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04005502 mdelay(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005503 }
5504
5505 /* Recommended delay time after link has been lost */
Jeff Garzikf8ec4732006-09-19 15:27:07 -04005506 mdelay(1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005507
5508 /* Now we will re-enable th transmitter on the PHY */
5509
5510 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
Auke Kok8fc897b2006-08-28 14:56:16 -07005511 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005512 return ret_val;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04005513 mdelay(50);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005514 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0);
Auke Kok8fc897b2006-08-28 14:56:16 -07005515 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005516 return ret_val;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04005517 mdelay(50);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005518 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00);
Auke Kok8fc897b2006-08-28 14:56:16 -07005519 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005520 return ret_val;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04005521 mdelay(50);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005522 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000);
Auke Kok8fc897b2006-08-28 14:56:16 -07005523 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005524 return ret_val;
5525
5526 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
Auke Kok8fc897b2006-08-28 14:56:16 -07005527 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005528 return ret_val;
5529
5530 /* This loop will early-out if the link condition has been met. */
Auke Kok8fc897b2006-08-28 14:56:16 -07005531 for (i = PHY_FORCE_TIME; i > 0; i--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005532 /* Read the MII Status Register and wait for Link Status bit
5533 * to be set.
5534 */
5535
5536 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07005537 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005538 return ret_val;
5539
5540 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07005541 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005542 return ret_val;
5543
Auke Kok8fc897b2006-08-28 14:56:16 -07005544 if (mii_status_reg & MII_SR_LINK_STATUS) break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04005545 mdelay(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005546 }
5547 return E1000_SUCCESS;
5548}
5549
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005550/*******************************************************************************
5551 *
5552 * Check for EEPROM Auto Read bit done.
5553 *
5554 * hw: Struct containing variables accessed by shared code
5555 *
5556 * returns: - E1000_ERR_RESET if fail to reset MAC
5557 * E1000_SUCCESS at any other case.
5558 *
5559 ******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07005560static s32 e1000_get_auto_rd_done(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005561{
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005562 DEBUGFUNC("e1000_get_auto_rd_done");
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00005563 msleep(5);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005564 return E1000_SUCCESS;
5565}
5566
5567/***************************************************************************
5568 * Checks if the PHY configuration is done
5569 *
5570 * hw: Struct containing variables accessed by shared code
5571 *
5572 * returns: - E1000_ERR_RESET if fail to reset MAC
5573 * E1000_SUCCESS at any other case.
5574 *
5575 ***************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07005576static s32 e1000_get_phy_cfg_done(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005577{
5578 DEBUGFUNC("e1000_get_phy_cfg_done");
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00005579 mdelay(10);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005580 return E1000_SUCCESS;
5581}