blob: 076db19f69f4f5b8ee7ba54a71f352d7b5c2bacc [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
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002139/**
2140 * e1000_check_for_serdes_link_generic - Check for link (Serdes)
2141 * @hw: pointer to the HW structure
2142 *
2143 * Checks for link up on the hardware. If link is not up and we have
2144 * a signal, then we need to force link up.
2145 **/
2146s32 e1000_check_for_serdes_link_generic(struct e1000_hw *hw)
2147{
2148 u32 rxcw;
2149 u32 ctrl;
2150 u32 status;
2151 s32 ret_val = E1000_SUCCESS;
2152
2153 DEBUGFUNC("e1000_check_for_serdes_link_generic");
2154
2155 ctrl = er32(CTRL);
2156 status = er32(STATUS);
2157 rxcw = er32(RXCW);
2158
2159 /*
2160 * If we don't have link (auto-negotiation failed or link partner
2161 * cannot auto-negotiate), and our link partner is not trying to
2162 * auto-negotiate with us (we are receiving idles or data),
2163 * we need to force link up. We also need to give auto-negotiation
2164 * time to complete.
2165 */
2166 /* (ctrl & E1000_CTRL_SWDPIN1) == 1 == have signal */
2167 if ((!(status & E1000_STATUS_LU)) && (!(rxcw & E1000_RXCW_C))) {
2168 if (hw->autoneg_failed == 0) {
2169 hw->autoneg_failed = 1;
2170 goto out;
2171 }
2172 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\n");
2173
2174 /* Disable auto-negotiation in the TXCW register */
2175 ew32(TXCW, (hw->txcw & ~E1000_TXCW_ANE));
2176
2177 /* Force link-up and also force full-duplex. */
2178 ctrl = er32(CTRL);
2179 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
2180 ew32(CTRL, ctrl);
2181
2182 /* Configure Flow Control after forcing link up. */
2183 ret_val = e1000_config_fc_after_link_up(hw);
2184 if (ret_val) {
2185 DEBUGOUT("Error configuring flow control\n");
2186 goto out;
2187 }
2188 } else if ((ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
2189 /*
2190 * If we are forcing link and we are receiving /C/ ordered
2191 * sets, re-enable auto-negotiation in the TXCW register
2192 * and disable forced link in the Device Control register
2193 * in an attempt to auto-negotiate with our link partner.
2194 */
2195 DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\n");
2196 ew32(TXCW, hw->txcw);
2197 ew32(CTRL, (ctrl & ~E1000_CTRL_SLU));
2198
2199 hw->serdes_has_link = true;
2200 } else if (!(E1000_TXCW_ANE & er32(TXCW))) {
2201 /*
2202 * If we force link for non-auto-negotiation switch, check
2203 * link status based on MAC synchronization for internal
2204 * serdes media type.
2205 */
2206 /* SYNCH bit and IV bit are sticky. */
2207 udelay(10);
2208 rxcw = er32(RXCW);
2209 if (rxcw & E1000_RXCW_SYNCH) {
2210 if (!(rxcw & E1000_RXCW_IV)) {
2211 hw->serdes_has_link = true;
2212 DEBUGOUT("SERDES: Link up - forced.\n");
2213 }
2214 } else {
2215 hw->serdes_has_link = false;
2216 DEBUGOUT("SERDES: Link down - force failed.\n");
2217 }
2218 }
2219
2220 if (E1000_TXCW_ANE & er32(TXCW)) {
2221 status = er32(STATUS);
2222 if (status & E1000_STATUS_LU) {
2223 /* SYNCH bit and IV bit are sticky, so reread rxcw. */
2224 udelay(10);
2225 rxcw = er32(RXCW);
2226 if (rxcw & E1000_RXCW_SYNCH) {
2227 if (!(rxcw & E1000_RXCW_IV)) {
2228 hw->serdes_has_link = true;
2229 DEBUGOUT("SERDES: Link up - autoneg "
2230 "completed sucessfully.\n");
2231 } else {
2232 hw->serdes_has_link = false;
2233 DEBUGOUT("SERDES: Link down - invalid"
2234 "codewords detected in autoneg.\n");
2235 }
2236 } else {
2237 hw->serdes_has_link = false;
2238 DEBUGOUT("SERDES: Link down - no sync.\n");
2239 }
2240 } else {
2241 hw->serdes_has_link = false;
2242 DEBUGOUT("SERDES: Link down - autoneg failed\n");
2243 }
2244 }
2245
2246out:
2247 return ret_val;
2248}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249/******************************************************************************
2250 * Checks to see if the link status of the hardware has changed.
2251 *
2252 * hw - Struct containing variables accessed by shared code
2253 *
2254 * Called by any function that needs to check the link status of the adapter.
2255 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07002256s32 e1000_check_for_link(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257{
Joe Perches406874a2008-04-03 10:06:32 -07002258 u32 rxcw = 0;
2259 u32 ctrl;
2260 u32 status;
2261 u32 rctl;
2262 u32 icr;
2263 u32 signal = 0;
2264 s32 ret_val;
2265 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266
2267 DEBUGFUNC("e1000_check_for_link");
2268
Joe Perches1dc32912008-07-11 15:17:08 -07002269 ctrl = er32(CTRL);
2270 status = er32(STATUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271
2272 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
2273 * set when the optics detect a signal. On older adapters, it will be
2274 * cleared when there is a signal. This applies to fiber media only.
2275 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002276 if ((hw->media_type == e1000_media_type_fiber) ||
2277 (hw->media_type == e1000_media_type_internal_serdes)) {
Joe Perches1dc32912008-07-11 15:17:08 -07002278 rxcw = er32(RXCW);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279
Auke Kok8fc897b2006-08-28 14:56:16 -07002280 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
Auke Kok8fc897b2006-08-28 14:56:16 -07002282 if (status & E1000_STATUS_LU)
Joe Perchesc3033b02008-03-21 11:06:25 -07002283 hw->get_link_status = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284 }
2285 }
2286
2287 /* If we have a copper PHY then we only want to go out to the PHY
2288 * registers to see if Auto-Neg has completed and/or if our link
2289 * status has changed. The get_link_status flag will be set if we
2290 * receive a Link Status Change interrupt or we have Rx Sequence
2291 * Errors.
2292 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002293 if ((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294 /* First we want to see if the MII Status Register reports
2295 * link. If so, then we want to get the current speed/duplex
2296 * of the PHY.
2297 * Read the register twice since the link bit is sticky.
2298 */
2299 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002300 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301 return ret_val;
2302 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002303 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304 return ret_val;
2305
Auke Kok8fc897b2006-08-28 14:56:16 -07002306 if (phy_data & MII_SR_LINK_STATUS) {
Joe Perchesc3033b02008-03-21 11:06:25 -07002307 hw->get_link_status = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308 /* Check if there was DownShift, must be checked immediately after
2309 * link-up */
2310 e1000_check_downshift(hw);
2311
2312 /* If we are on 82544 or 82543 silicon and speed/duplex
2313 * are forced to 10H or 10F, then we will implement the polarity
2314 * reversal workaround. We disable interrupts first, and upon
2315 * returning, place the devices interrupt state to its previous
2316 * value except for the link status change interrupt which will
2317 * happen due to the execution of this workaround.
2318 */
2319
Auke Kok8fc897b2006-08-28 14:56:16 -07002320 if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
2321 (!hw->autoneg) &&
2322 (hw->forced_speed_duplex == e1000_10_full ||
2323 hw->forced_speed_duplex == e1000_10_half)) {
Joe Perches1dc32912008-07-11 15:17:08 -07002324 ew32(IMC, 0xffffffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325 ret_val = e1000_polarity_reversal_workaround(hw);
Joe Perches1dc32912008-07-11 15:17:08 -07002326 icr = er32(ICR);
2327 ew32(ICS, (icr & ~E1000_ICS_LSC));
2328 ew32(IMS, IMS_ENABLE_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329 }
2330
2331 } else {
2332 /* No link detected */
Joe Perchesc3033b02008-03-21 11:06:25 -07002333 e1000_config_dsp_after_link_change(hw, false);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334 return 0;
2335 }
2336
2337 /* If we are forcing speed/duplex, then we simply return since
2338 * we have already determined whether we have link or not.
2339 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002340 if (!hw->autoneg) return -E1000_ERR_CONFIG;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341
2342 /* optimize the dsp settings for the igp phy */
Joe Perchesc3033b02008-03-21 11:06:25 -07002343 e1000_config_dsp_after_link_change(hw, true);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344
2345 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
2346 * have Si on board that is 82544 or newer, Auto
2347 * Speed Detection takes care of MAC speed/duplex
2348 * configuration. So we only need to configure Collision
2349 * Distance in the MAC. Otherwise, we need to force
2350 * speed/duplex on the MAC to the current PHY speed/duplex
2351 * settings.
2352 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002353 if (hw->mac_type >= e1000_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354 e1000_config_collision_dist(hw);
2355 else {
2356 ret_val = e1000_config_mac_to_phy(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002357 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358 DEBUGOUT("Error configuring MAC to PHY settings\n");
2359 return ret_val;
2360 }
2361 }
2362
2363 /* Configure Flow Control now that Auto-Neg has completed. First, we
2364 * need to restore the desired flow control settings because we may
2365 * have had to re-autoneg with a different link partner.
2366 */
2367 ret_val = e1000_config_fc_after_link_up(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002368 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002369 DEBUGOUT("Error configuring flow control\n");
2370 return ret_val;
2371 }
2372
2373 /* At this point we know that we are on copper and we have
2374 * auto-negotiated link. These are conditions for checking the link
2375 * partner capability register. We use the link speed to determine if
2376 * TBI compatibility needs to be turned on or off. If the link is not
2377 * at gigabit speed, then TBI compatibility is not needed. If we are
2378 * at gigabit speed, we turn on TBI compatibility.
2379 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002380 if (hw->tbi_compatibility_en) {
Joe Perches406874a2008-04-03 10:06:32 -07002381 u16 speed, duplex;
Auke Kok592600a2006-06-27 09:08:09 -07002382 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
2383 if (ret_val) {
2384 DEBUGOUT("Error getting link speed and duplex\n");
2385 return ret_val;
2386 }
2387 if (speed != SPEED_1000) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388 /* If link speed is not set to gigabit speed, we do not need
2389 * to enable TBI compatibility.
2390 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002391 if (hw->tbi_compatibility_on) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392 /* If we previously were in the mode, turn it off. */
Joe Perches1dc32912008-07-11 15:17:08 -07002393 rctl = er32(RCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394 rctl &= ~E1000_RCTL_SBP;
Joe Perches1dc32912008-07-11 15:17:08 -07002395 ew32(RCTL, rctl);
Joe Perchesc3033b02008-03-21 11:06:25 -07002396 hw->tbi_compatibility_on = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397 }
2398 } else {
2399 /* If TBI compatibility is was previously off, turn it on. For
2400 * compatibility with a TBI link partner, we will store bad
2401 * packets. Some frames have an additional byte on the end and
Anand Gadiyarfd589a82009-07-16 17:13:03 +02002402 * will look like CRC errors to the hardware.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002404 if (!hw->tbi_compatibility_on) {
Joe Perchesc3033b02008-03-21 11:06:25 -07002405 hw->tbi_compatibility_on = true;
Joe Perches1dc32912008-07-11 15:17:08 -07002406 rctl = er32(RCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407 rctl |= E1000_RCTL_SBP;
Joe Perches1dc32912008-07-11 15:17:08 -07002408 ew32(RCTL, rctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409 }
2410 }
2411 }
2412 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002414 if ((hw->media_type == e1000_media_type_fiber) ||
2415 (hw->media_type == e1000_media_type_internal_serdes))
2416 e1000_check_for_serdes_link_generic(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418 return E1000_SUCCESS;
2419}
2420
2421/******************************************************************************
2422 * Detects the current speed and duplex settings of the hardware.
2423 *
2424 * hw - Struct containing variables accessed by shared code
2425 * speed - Speed of the connection
2426 * duplex - Duplex setting of the connection
2427 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07002428s32 e1000_get_speed_and_duplex(struct e1000_hw *hw, u16 *speed, u16 *duplex)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429{
Joe Perches406874a2008-04-03 10:06:32 -07002430 u32 status;
2431 s32 ret_val;
2432 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433
2434 DEBUGFUNC("e1000_get_speed_and_duplex");
2435
Auke Kok8fc897b2006-08-28 14:56:16 -07002436 if (hw->mac_type >= e1000_82543) {
Joe Perches1dc32912008-07-11 15:17:08 -07002437 status = er32(STATUS);
Auke Kok8fc897b2006-08-28 14:56:16 -07002438 if (status & E1000_STATUS_SPEED_1000) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439 *speed = SPEED_1000;
2440 DEBUGOUT("1000 Mbs, ");
Auke Kok8fc897b2006-08-28 14:56:16 -07002441 } else if (status & E1000_STATUS_SPEED_100) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442 *speed = SPEED_100;
2443 DEBUGOUT("100 Mbs, ");
2444 } else {
2445 *speed = SPEED_10;
2446 DEBUGOUT("10 Mbs, ");
2447 }
2448
Auke Kok8fc897b2006-08-28 14:56:16 -07002449 if (status & E1000_STATUS_FD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450 *duplex = FULL_DUPLEX;
Auke Koka42a5072006-05-23 13:36:01 -07002451 DEBUGOUT("Full Duplex\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452 } else {
2453 *duplex = HALF_DUPLEX;
Auke Koka42a5072006-05-23 13:36:01 -07002454 DEBUGOUT(" Half Duplex\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455 }
2456 } else {
Auke Koka42a5072006-05-23 13:36:01 -07002457 DEBUGOUT("1000 Mbs, Full Duplex\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002458 *speed = SPEED_1000;
2459 *duplex = FULL_DUPLEX;
2460 }
2461
2462 /* IGP01 PHY may advertise full duplex operation after speed downgrade even
2463 * if it is operating at half duplex. Here we set the duplex settings to
2464 * match the duplex in the link partner's capabilities.
2465 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002466 if (hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002468 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002469 return ret_val;
2470
Auke Kok8fc897b2006-08-28 14:56:16 -07002471 if (!(phy_data & NWAY_ER_LP_NWAY_CAPS))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472 *duplex = HALF_DUPLEX;
2473 else {
2474 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002475 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002476 return ret_val;
Auke Kok8fc897b2006-08-28 14:56:16 -07002477 if ((*speed == SPEED_100 && !(phy_data & NWAY_LPAR_100TX_FD_CAPS)) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002478 (*speed == SPEED_10 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
2479 *duplex = HALF_DUPLEX;
2480 }
2481 }
2482
2483 return E1000_SUCCESS;
2484}
2485
2486/******************************************************************************
2487* Blocks until autoneg completes or times out (~4.5 seconds)
2488*
2489* hw - Struct containing variables accessed by shared code
2490******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07002491static s32 e1000_wait_autoneg(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492{
Joe Perches406874a2008-04-03 10:06:32 -07002493 s32 ret_val;
2494 u16 i;
2495 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496
2497 DEBUGFUNC("e1000_wait_autoneg");
2498 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
2499
2500 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
Auke Kok8fc897b2006-08-28 14:56:16 -07002501 for (i = PHY_AUTO_NEG_TIME; i > 0; i--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502 /* Read the MII Status Register and wait for Auto-Neg
2503 * Complete bit to be set.
2504 */
2505 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002506 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002507 return ret_val;
2508 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002509 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510 return ret_val;
Auke Kok8fc897b2006-08-28 14:56:16 -07002511 if (phy_data & MII_SR_AUTONEG_COMPLETE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512 return E1000_SUCCESS;
2513 }
Jeff Garzikf8ec4732006-09-19 15:27:07 -04002514 msleep(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515 }
2516 return E1000_SUCCESS;
2517}
2518
2519/******************************************************************************
2520* Raises the Management Data Clock
2521*
2522* hw - Struct containing variables accessed by shared code
2523* ctrl - Device control register's current value
2524******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07002525static void e1000_raise_mdi_clk(struct e1000_hw *hw, u32 *ctrl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526{
2527 /* Raise the clock input to the Management Data Clock (by setting the MDC
2528 * bit), and then delay 10 microseconds.
2529 */
Joe Perches1dc32912008-07-11 15:17:08 -07002530 ew32(CTRL, (*ctrl | E1000_CTRL_MDC));
2531 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532 udelay(10);
2533}
2534
2535/******************************************************************************
2536* Lowers the Management Data Clock
2537*
2538* hw - Struct containing variables accessed by shared code
2539* ctrl - Device control register's current value
2540******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07002541static void e1000_lower_mdi_clk(struct e1000_hw *hw, u32 *ctrl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542{
2543 /* Lower the clock input to the Management Data Clock (by clearing the MDC
2544 * bit), and then delay 10 microseconds.
2545 */
Joe Perches1dc32912008-07-11 15:17:08 -07002546 ew32(CTRL, (*ctrl & ~E1000_CTRL_MDC));
2547 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002548 udelay(10);
2549}
2550
2551/******************************************************************************
2552* Shifts data bits out to the PHY
2553*
2554* hw - Struct containing variables accessed by shared code
2555* data - Data to send out to the PHY
2556* count - Number of bits to shift out
2557*
2558* Bits are shifted out in MSB to LSB order.
2559******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07002560static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, u32 data, u16 count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561{
Joe Perches406874a2008-04-03 10:06:32 -07002562 u32 ctrl;
2563 u32 mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564
2565 /* We need to shift "count" number of bits out to the PHY. So, the value
2566 * in the "data" parameter will be shifted out to the PHY one bit at a
2567 * time. In order to do this, "data" must be broken down into bits.
2568 */
2569 mask = 0x01;
2570 mask <<= (count - 1);
2571
Joe Perches1dc32912008-07-11 15:17:08 -07002572 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573
2574 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
2575 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
2576
Auke Kok8fc897b2006-08-28 14:56:16 -07002577 while (mask) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002578 /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
2579 * then raising and lowering the Management Data Clock. A "0" is
2580 * shifted out to the PHY by setting the MDIO bit to "0" and then
2581 * raising and lowering the clock.
2582 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002583 if (data & mask)
2584 ctrl |= E1000_CTRL_MDIO;
2585 else
2586 ctrl &= ~E1000_CTRL_MDIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587
Joe Perches1dc32912008-07-11 15:17:08 -07002588 ew32(CTRL, ctrl);
2589 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590
2591 udelay(10);
2592
2593 e1000_raise_mdi_clk(hw, &ctrl);
2594 e1000_lower_mdi_clk(hw, &ctrl);
2595
2596 mask = mask >> 1;
2597 }
2598}
2599
2600/******************************************************************************
2601* Shifts data bits in from the PHY
2602*
2603* hw - Struct containing variables accessed by shared code
2604*
2605* Bits are shifted in in MSB to LSB order.
2606******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07002607static u16 e1000_shift_in_mdi_bits(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608{
Joe Perches406874a2008-04-03 10:06:32 -07002609 u32 ctrl;
2610 u16 data = 0;
2611 u8 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612
2613 /* In order to read a register from the PHY, we need to shift in a total
2614 * of 18 bits from the PHY. The first two bit (turnaround) times are used
2615 * to avoid contention on the MDIO pin when a read operation is performed.
2616 * These two bits are ignored by us and thrown away. Bits are "shifted in"
2617 * by raising the input to the Management Data Clock (setting the MDC bit),
2618 * and then reading the value of the MDIO bit.
2619 */
Joe Perches1dc32912008-07-11 15:17:08 -07002620 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621
2622 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
2623 ctrl &= ~E1000_CTRL_MDIO_DIR;
2624 ctrl &= ~E1000_CTRL_MDIO;
2625
Joe Perches1dc32912008-07-11 15:17:08 -07002626 ew32(CTRL, ctrl);
2627 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628
2629 /* Raise and Lower the clock before reading in the data. This accounts for
2630 * the turnaround bits. The first clock occurred when we clocked out the
2631 * last bit of the Register Address.
2632 */
2633 e1000_raise_mdi_clk(hw, &ctrl);
2634 e1000_lower_mdi_clk(hw, &ctrl);
2635
Auke Kok8fc897b2006-08-28 14:56:16 -07002636 for (data = 0, i = 0; i < 16; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002637 data = data << 1;
2638 e1000_raise_mdi_clk(hw, &ctrl);
Joe Perches1dc32912008-07-11 15:17:08 -07002639 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002640 /* Check to see if we shifted in a "1". */
Auke Kok8fc897b2006-08-28 14:56:16 -07002641 if (ctrl & E1000_CTRL_MDIO)
2642 data |= 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643 e1000_lower_mdi_clk(hw, &ctrl);
2644 }
2645
2646 e1000_raise_mdi_clk(hw, &ctrl);
2647 e1000_lower_mdi_clk(hw, &ctrl);
2648
2649 return data;
2650}
2651
2652/*****************************************************************************
2653* Reads the value from a PHY register, if the value is on a specific non zero
2654* page, sets the page first.
2655* hw - Struct containing variables accessed by shared code
2656* reg_addr - address of the PHY register to read
2657******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07002658s32 e1000_read_phy_reg(struct e1000_hw *hw, u32 reg_addr, u16 *phy_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002659{
Joe Perches406874a2008-04-03 10:06:32 -07002660 u32 ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002661
2662 DEBUGFUNC("e1000_read_phy_reg");
2663
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00002664 if ((hw->phy_type == e1000_phy_igp) &&
2665 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002666 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
Joe Perches406874a2008-04-03 10:06:32 -07002667 (u16)reg_addr);
Jesse Brandeburg282b1772009-09-25 12:16:39 +00002668 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002669 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670 }
2671
2672 ret_val = e1000_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
2673 phy_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002674 return ret_val;
2675}
2676
Joe Perches64798842008-07-11 15:17:02 -07002677static s32 e1000_read_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr,
2678 u16 *phy_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002679{
Joe Perches406874a2008-04-03 10:06:32 -07002680 u32 i;
2681 u32 mdic = 0;
2682 const u32 phy_addr = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002683
2684 DEBUGFUNC("e1000_read_phy_reg_ex");
2685
Auke Kok8fc897b2006-08-28 14:56:16 -07002686 if (reg_addr > MAX_PHY_REG_ADDRESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002687 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
2688 return -E1000_ERR_PARAM;
2689 }
2690
Auke Kok8fc897b2006-08-28 14:56:16 -07002691 if (hw->mac_type > e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692 /* Set up Op-code, Phy Address, and register address in the MDI
2693 * Control register. The MAC will take care of interfacing with the
2694 * PHY to retrieve the desired data.
2695 */
2696 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
2697 (phy_addr << E1000_MDIC_PHY_SHIFT) |
2698 (E1000_MDIC_OP_READ));
2699
Joe Perches1dc32912008-07-11 15:17:08 -07002700 ew32(MDIC, mdic);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002701
2702 /* Poll the ready bit to see if the MDI read completed */
Auke Kok8fc897b2006-08-28 14:56:16 -07002703 for (i = 0; i < 64; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002704 udelay(50);
Joe Perches1dc32912008-07-11 15:17:08 -07002705 mdic = er32(MDIC);
Auke Kok8fc897b2006-08-28 14:56:16 -07002706 if (mdic & E1000_MDIC_READY) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002707 }
Auke Kok8fc897b2006-08-28 14:56:16 -07002708 if (!(mdic & E1000_MDIC_READY)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709 DEBUGOUT("MDI Read did not complete\n");
2710 return -E1000_ERR_PHY;
2711 }
Auke Kok8fc897b2006-08-28 14:56:16 -07002712 if (mdic & E1000_MDIC_ERROR) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002713 DEBUGOUT("MDI Error\n");
2714 return -E1000_ERR_PHY;
2715 }
Joe Perchese982f172008-07-11 15:17:18 -07002716 *phy_data = (u16)mdic;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717 } else {
2718 /* We must first send a preamble through the MDIO pin to signal the
2719 * beginning of an MII instruction. This is done by sending 32
2720 * consecutive "1" bits.
2721 */
2722 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
2723
2724 /* Now combine the next few fields that are required for a read
2725 * operation. We use this method instead of calling the
2726 * e1000_shift_out_mdi_bits routine five different times. The format of
2727 * a MII read instruction consists of a shift out of 14 bits and is
2728 * defined as follows:
2729 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
2730 * followed by a shift in of 18 bits. This first two bits shifted in
2731 * are TurnAround bits used to avoid contention on the MDIO pin when a
2732 * READ operation is performed. These two bits are thrown away
2733 * followed by a shift in of 16 bits which contains the desired data.
2734 */
2735 mdic = ((reg_addr) | (phy_addr << 5) |
2736 (PHY_OP_READ << 10) | (PHY_SOF << 12));
2737
2738 e1000_shift_out_mdi_bits(hw, mdic, 14);
2739
2740 /* Now that we've shifted out the read command to the MII, we need to
2741 * "shift in" the 16-bit value (18 total bits) of the requested PHY
2742 * register address.
2743 */
2744 *phy_data = e1000_shift_in_mdi_bits(hw);
2745 }
2746 return E1000_SUCCESS;
2747}
2748
2749/******************************************************************************
2750* Writes a value to a PHY register
2751*
2752* hw - Struct containing variables accessed by shared code
2753* reg_addr - address of the PHY register to write
2754* data - data to write to the PHY
2755******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07002756s32 e1000_write_phy_reg(struct e1000_hw *hw, u32 reg_addr, u16 phy_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002757{
Joe Perches406874a2008-04-03 10:06:32 -07002758 u32 ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002759
2760 DEBUGFUNC("e1000_write_phy_reg");
2761
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00002762 if ((hw->phy_type == e1000_phy_igp) &&
2763 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002764 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
Joe Perches406874a2008-04-03 10:06:32 -07002765 (u16)reg_addr);
Jesse Brandeburg282b1772009-09-25 12:16:39 +00002766 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002768 }
2769
2770 ret_val = e1000_write_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
2771 phy_data);
2772
2773 return ret_val;
2774}
2775
Joe Perches64798842008-07-11 15:17:02 -07002776static s32 e1000_write_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr,
2777 u16 phy_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002778{
Joe Perches406874a2008-04-03 10:06:32 -07002779 u32 i;
2780 u32 mdic = 0;
2781 const u32 phy_addr = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002782
2783 DEBUGFUNC("e1000_write_phy_reg_ex");
2784
Auke Kok8fc897b2006-08-28 14:56:16 -07002785 if (reg_addr > MAX_PHY_REG_ADDRESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002786 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
2787 return -E1000_ERR_PARAM;
2788 }
2789
Auke Kok8fc897b2006-08-28 14:56:16 -07002790 if (hw->mac_type > e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002791 /* Set up Op-code, Phy Address, register address, and data intended
2792 * for the PHY register in the MDI Control register. The MAC will take
2793 * care of interfacing with the PHY to send the desired data.
2794 */
Joe Perchese982f172008-07-11 15:17:18 -07002795 mdic = (((u32)phy_data) |
Linus Torvalds1da177e2005-04-16 15:20:36 -07002796 (reg_addr << E1000_MDIC_REG_SHIFT) |
2797 (phy_addr << E1000_MDIC_PHY_SHIFT) |
2798 (E1000_MDIC_OP_WRITE));
2799
Joe Perches1dc32912008-07-11 15:17:08 -07002800 ew32(MDIC, mdic);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002801
2802 /* Poll the ready bit to see if the MDI read completed */
Auke Kok8fc897b2006-08-28 14:56:16 -07002803 for (i = 0; i < 641; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002804 udelay(5);
Joe Perches1dc32912008-07-11 15:17:08 -07002805 mdic = er32(MDIC);
Auke Kok8fc897b2006-08-28 14:56:16 -07002806 if (mdic & E1000_MDIC_READY) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002807 }
Auke Kok8fc897b2006-08-28 14:56:16 -07002808 if (!(mdic & E1000_MDIC_READY)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002809 DEBUGOUT("MDI Write did not complete\n");
2810 return -E1000_ERR_PHY;
2811 }
2812 } else {
2813 /* We'll need to use the SW defined pins to shift the write command
2814 * out to the PHY. We first send a preamble to the PHY to signal the
2815 * beginning of the MII instruction. This is done by sending 32
2816 * consecutive "1" bits.
2817 */
2818 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
2819
2820 /* Now combine the remaining required fields that will indicate a
2821 * write operation. We use this method instead of calling the
2822 * e1000_shift_out_mdi_bits routine for each field in the command. The
2823 * format of a MII write instruction is as follows:
2824 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
2825 */
2826 mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
2827 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
2828 mdic <<= 16;
Joe Perchese982f172008-07-11 15:17:18 -07002829 mdic |= (u32)phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002830
2831 e1000_shift_out_mdi_bits(hw, mdic, 32);
2832 }
2833
2834 return E1000_SUCCESS;
2835}
2836
2837/******************************************************************************
2838* Returns the PHY to the power-on reset state
2839*
2840* hw - Struct containing variables accessed by shared code
2841******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07002842s32 e1000_phy_hw_reset(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002843{
Joe Perches406874a2008-04-03 10:06:32 -07002844 u32 ctrl, ctrl_ext;
2845 u32 led_ctrl;
2846 s32 ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002847
2848 DEBUGFUNC("e1000_phy_hw_reset");
2849
2850 DEBUGOUT("Resetting Phy...\n");
2851
Auke Kok8fc897b2006-08-28 14:56:16 -07002852 if (hw->mac_type > e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002853 /* Read the device control register and assert the E1000_CTRL_PHY_RST
2854 * bit. Then, take it out of reset.
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00002855 * For e1000 hardware, we delay for 10ms between the assert
2856 * and deassert.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002857 */
Joe Perches1dc32912008-07-11 15:17:08 -07002858 ctrl = er32(CTRL);
2859 ew32(CTRL, ctrl | E1000_CTRL_PHY_RST);
2860 E1000_WRITE_FLUSH();
Auke Kok76c224b2006-05-23 13:36:06 -07002861
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00002862 msleep(10);
Auke Kok76c224b2006-05-23 13:36:06 -07002863
Joe Perches1dc32912008-07-11 15:17:08 -07002864 ew32(CTRL, ctrl);
2865 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002866 } else {
2867 /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
2868 * bit to put the PHY into reset. Then, take it out of reset.
2869 */
Joe Perches1dc32912008-07-11 15:17:08 -07002870 ctrl_ext = er32(CTRL_EXT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002871 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
2872 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
Joe Perches1dc32912008-07-11 15:17:08 -07002873 ew32(CTRL_EXT, ctrl_ext);
2874 E1000_WRITE_FLUSH();
Jeff Garzikf8ec4732006-09-19 15:27:07 -04002875 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002876 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
Joe Perches1dc32912008-07-11 15:17:08 -07002877 ew32(CTRL_EXT, ctrl_ext);
2878 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002879 }
2880 udelay(150);
2881
Auke Kok8fc897b2006-08-28 14:56:16 -07002882 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002883 /* Configure activity LED after PHY reset */
Joe Perches1dc32912008-07-11 15:17:08 -07002884 led_ctrl = er32(LEDCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002885 led_ctrl &= IGP_ACTIVITY_LED_MASK;
2886 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
Joe Perches1dc32912008-07-11 15:17:08 -07002887 ew32(LEDCTL, led_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002888 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002889
2890 /* Wait for FW to finish PHY configuration. */
2891 ret_val = e1000_get_phy_cfg_done(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002892 if (ret_val != E1000_SUCCESS)
2893 return ret_val;
Auke Kok8fc897b2006-08-28 14:56:16 -07002894
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002895 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002896}
2897
2898/******************************************************************************
2899* Resets the PHY
2900*
2901* hw - Struct containing variables accessed by shared code
2902*
Matt LaPlante0779bf22006-11-30 05:24:39 +01002903* Sets bit 15 of the MII Control register
Linus Torvalds1da177e2005-04-16 15:20:36 -07002904******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07002905s32 e1000_phy_reset(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002906{
Joe Perches406874a2008-04-03 10:06:32 -07002907 s32 ret_val;
2908 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002909
2910 DEBUGFUNC("e1000_phy_reset");
2911
Jeff Kirsher2a88c172006-09-27 12:54:05 -07002912 switch (hw->phy_type) {
2913 case e1000_phy_igp:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002914 ret_val = e1000_phy_hw_reset(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002915 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002916 return ret_val;
2917 break;
2918 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002920 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002921 return ret_val;
2922
2923 phy_data |= MII_CR_RESET;
2924 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002925 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002926 return ret_val;
2927
2928 udelay(1);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002929 break;
2930 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002931
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00002932 if (hw->phy_type == e1000_phy_igp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002933 e1000_phy_init_script(hw);
2934
2935 return E1000_SUCCESS;
2936}
2937
2938/******************************************************************************
2939* Probes the expected PHY address for known PHY IDs
2940*
2941* hw - Struct containing variables accessed by shared code
2942******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07002943static s32 e1000_detect_gig_phy(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002944{
Joe Perches406874a2008-04-03 10:06:32 -07002945 s32 phy_init_status, ret_val;
2946 u16 phy_id_high, phy_id_low;
Joe Perchesc3033b02008-03-21 11:06:25 -07002947 bool match = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002948
2949 DEBUGFUNC("e1000_detect_gig_phy");
2950
Jeff Kirsher2a88c172006-09-27 12:54:05 -07002951 if (hw->phy_id != 0)
2952 return E1000_SUCCESS;
2953
Linus Torvalds1da177e2005-04-16 15:20:36 -07002954 /* Read the PHY ID Registers to identify which PHY is onboard. */
2955 ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
Auke Kokcd94dd02006-06-27 09:08:22 -07002956 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002957 return ret_val;
2958
Joe Perchese982f172008-07-11 15:17:18 -07002959 hw->phy_id = (u32)(phy_id_high << 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002960 udelay(20);
2961 ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
Auke Kok8fc897b2006-08-28 14:56:16 -07002962 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002963 return ret_val;
2964
Joe Perchese982f172008-07-11 15:17:18 -07002965 hw->phy_id |= (u32)(phy_id_low & PHY_REVISION_MASK);
2966 hw->phy_revision = (u32)phy_id_low & ~PHY_REVISION_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002967
Auke Kok8fc897b2006-08-28 14:56:16 -07002968 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002969 case e1000_82543:
Joe Perchesc3033b02008-03-21 11:06:25 -07002970 if (hw->phy_id == M88E1000_E_PHY_ID) match = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002971 break;
2972 case e1000_82544:
Joe Perchesc3033b02008-03-21 11:06:25 -07002973 if (hw->phy_id == M88E1000_I_PHY_ID) match = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002974 break;
2975 case e1000_82540:
2976 case e1000_82545:
2977 case e1000_82545_rev_3:
2978 case e1000_82546:
2979 case e1000_82546_rev_3:
Joe Perchesc3033b02008-03-21 11:06:25 -07002980 if (hw->phy_id == M88E1011_I_PHY_ID) match = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002981 break;
2982 case e1000_82541:
2983 case e1000_82541_rev_2:
2984 case e1000_82547:
2985 case e1000_82547_rev_2:
Joe Perchesc3033b02008-03-21 11:06:25 -07002986 if (hw->phy_id == IGP01E1000_I_PHY_ID) match = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002987 break;
2988 default:
2989 DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type);
2990 return -E1000_ERR_CONFIG;
2991 }
2992 phy_init_status = e1000_set_phy_type(hw);
2993
2994 if ((match) && (phy_init_status == E1000_SUCCESS)) {
2995 DEBUGOUT1("PHY ID 0x%X detected\n", hw->phy_id);
2996 return E1000_SUCCESS;
2997 }
2998 DEBUGOUT1("Invalid PHY ID 0x%X\n", hw->phy_id);
2999 return -E1000_ERR_PHY;
3000}
3001
3002/******************************************************************************
3003* Resets the PHY's DSP
3004*
3005* hw - Struct containing variables accessed by shared code
3006******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003007static s32 e1000_phy_reset_dsp(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003008{
Joe Perches406874a2008-04-03 10:06:32 -07003009 s32 ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003010 DEBUGFUNC("e1000_phy_reset_dsp");
3011
3012 do {
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00003013 ret_val = e1000_write_phy_reg(hw, 29, 0x001d);
3014 if (ret_val) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003015 ret_val = e1000_write_phy_reg(hw, 30, 0x00c1);
Auke Kok8fc897b2006-08-28 14:56:16 -07003016 if (ret_val) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003017 ret_val = e1000_write_phy_reg(hw, 30, 0x0000);
Auke Kok8fc897b2006-08-28 14:56:16 -07003018 if (ret_val) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003019 ret_val = E1000_SUCCESS;
Auke Kok8fc897b2006-08-28 14:56:16 -07003020 } while (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003021
3022 return ret_val;
3023}
3024
3025/******************************************************************************
3026* Get PHY information from various PHY registers for igp PHY only.
3027*
3028* hw - Struct containing variables accessed by shared code
3029* phy_info - PHY information structure
3030******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003031static s32 e1000_phy_igp_get_info(struct e1000_hw *hw,
3032 struct e1000_phy_info *phy_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003033{
Joe Perches406874a2008-04-03 10:06:32 -07003034 s32 ret_val;
3035 u16 phy_data, min_length, max_length, average;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07003036 e1000_rev_polarity polarity;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003037
3038 DEBUGFUNC("e1000_phy_igp_get_info");
3039
3040 /* The downshift status is checked only once, after link is established,
3041 * and it stored in the hw->speed_downgraded parameter. */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003042 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003043
3044 /* IGP01E1000 does not need to support it. */
3045 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
3046
3047 /* IGP01E1000 always correct polarity reversal */
3048 phy_info->polarity_correction = e1000_polarity_reversal_enabled;
3049
3050 /* Check polarity status */
3051 ret_val = e1000_check_polarity(hw, &polarity);
Auke Kok8fc897b2006-08-28 14:56:16 -07003052 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003053 return ret_val;
3054
3055 phy_info->cable_polarity = polarity;
3056
3057 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003058 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003059 return ret_val;
3060
Jeff Kirsher70c6f302006-09-27 12:53:31 -07003061 phy_info->mdix_mode = (e1000_auto_x_mode)((phy_data & IGP01E1000_PSSR_MDIX) >>
3062 IGP01E1000_PSSR_MDIX_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003063
Auke Kok8fc897b2006-08-28 14:56:16 -07003064 if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
Linus Torvalds1da177e2005-04-16 15:20:36 -07003065 IGP01E1000_PSSR_SPEED_1000MBPS) {
3066 /* Local/Remote Receiver Information are only valid at 1000 Mbps */
3067 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003068 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003069 return ret_val;
3070
Jeff Kirsher70c6f302006-09-27 12:53:31 -07003071 phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
3072 SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
3073 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
3074 phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
3075 SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
3076 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003077
3078 /* Get cable length */
3079 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
Auke Kok8fc897b2006-08-28 14:56:16 -07003080 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003081 return ret_val;
3082
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003083 /* Translate to old method */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003084 average = (max_length + min_length) / 2;
3085
Auke Kok8fc897b2006-08-28 14:56:16 -07003086 if (average <= e1000_igp_cable_length_50)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003087 phy_info->cable_length = e1000_cable_length_50;
Auke Kok8fc897b2006-08-28 14:56:16 -07003088 else if (average <= e1000_igp_cable_length_80)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003089 phy_info->cable_length = e1000_cable_length_50_80;
Auke Kok8fc897b2006-08-28 14:56:16 -07003090 else if (average <= e1000_igp_cable_length_110)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003091 phy_info->cable_length = e1000_cable_length_80_110;
Auke Kok8fc897b2006-08-28 14:56:16 -07003092 else if (average <= e1000_igp_cable_length_140)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003093 phy_info->cable_length = e1000_cable_length_110_140;
3094 else
3095 phy_info->cable_length = e1000_cable_length_140;
3096 }
3097
3098 return E1000_SUCCESS;
3099}
3100
Auke Kokd37ea5d2006-06-27 09:08:17 -07003101
3102/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07003103* Get PHY information from various PHY registers fot m88 PHY only.
3104*
3105* hw - Struct containing variables accessed by shared code
3106* phy_info - PHY information structure
3107******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003108static s32 e1000_phy_m88_get_info(struct e1000_hw *hw,
3109 struct e1000_phy_info *phy_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003110{
Joe Perches406874a2008-04-03 10:06:32 -07003111 s32 ret_val;
3112 u16 phy_data;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07003113 e1000_rev_polarity polarity;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003114
3115 DEBUGFUNC("e1000_phy_m88_get_info");
3116
3117 /* The downshift status is checked only once, after link is established,
3118 * and it stored in the hw->speed_downgraded parameter. */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003119 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003120
3121 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003122 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003123 return ret_val;
3124
3125 phy_info->extended_10bt_distance =
Jeff Kirsher70c6f302006-09-27 12:53:31 -07003126 ((phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >>
3127 M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT) ?
3128 e1000_10bt_ext_dist_enable_lower : e1000_10bt_ext_dist_enable_normal;
3129
Linus Torvalds1da177e2005-04-16 15:20:36 -07003130 phy_info->polarity_correction =
Jeff Kirsher70c6f302006-09-27 12:53:31 -07003131 ((phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >>
3132 M88E1000_PSCR_POLARITY_REVERSAL_SHIFT) ?
3133 e1000_polarity_reversal_disabled : e1000_polarity_reversal_enabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003134
3135 /* Check polarity status */
3136 ret_val = e1000_check_polarity(hw, &polarity);
Auke Kok8fc897b2006-08-28 14:56:16 -07003137 if (ret_val)
Auke Kok76c224b2006-05-23 13:36:06 -07003138 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003139 phy_info->cable_polarity = polarity;
3140
3141 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003142 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003143 return ret_val;
3144
Jeff Kirsher70c6f302006-09-27 12:53:31 -07003145 phy_info->mdix_mode = (e1000_auto_x_mode)((phy_data & M88E1000_PSSR_MDIX) >>
3146 M88E1000_PSSR_MDIX_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003147
3148 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
3149 /* Cable Length Estimation and Local/Remote Receiver Information
3150 * are only valid at 1000 Mbps.
3151 */
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00003152 phy_info->cable_length = (e1000_cable_length)((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
3153 M88E1000_PSSR_CABLE_LENGTH_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003154
3155 ret_val = e1000_read_phy_reg(hw, PHY_1000T_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
Jeff Kirsher70c6f302006-09-27 12:53:31 -07003159 phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
3160 SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
3161 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
3162 phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
3163 SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
3164 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003165
Linus Torvalds1da177e2005-04-16 15:20:36 -07003166 }
3167
3168 return E1000_SUCCESS;
3169}
3170
3171/******************************************************************************
3172* Get PHY information from various PHY registers
3173*
3174* hw - Struct containing variables accessed by shared code
3175* phy_info - PHY information structure
3176******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003177s32 e1000_phy_get_info(struct e1000_hw *hw, struct e1000_phy_info *phy_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003178{
Joe Perches406874a2008-04-03 10:06:32 -07003179 s32 ret_val;
3180 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003181
3182 DEBUGFUNC("e1000_phy_get_info");
3183
3184 phy_info->cable_length = e1000_cable_length_undefined;
3185 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined;
3186 phy_info->cable_polarity = e1000_rev_polarity_undefined;
3187 phy_info->downshift = e1000_downshift_undefined;
3188 phy_info->polarity_correction = e1000_polarity_reversal_undefined;
3189 phy_info->mdix_mode = e1000_auto_x_mode_undefined;
3190 phy_info->local_rx = e1000_1000t_rx_status_undefined;
3191 phy_info->remote_rx = e1000_1000t_rx_status_undefined;
3192
Auke Kok8fc897b2006-08-28 14:56:16 -07003193 if (hw->media_type != e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003194 DEBUGOUT("PHY info is only valid for copper media\n");
3195 return -E1000_ERR_CONFIG;
3196 }
3197
3198 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003199 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003200 return ret_val;
3201
3202 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003203 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003204 return ret_val;
3205
Auke Kok8fc897b2006-08-28 14:56:16 -07003206 if ((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003207 DEBUGOUT("PHY info is only valid if link is up\n");
3208 return -E1000_ERR_CONFIG;
3209 }
3210
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00003211 if (hw->phy_type == e1000_phy_igp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003212 return e1000_phy_igp_get_info(hw, phy_info);
3213 else
3214 return e1000_phy_m88_get_info(hw, phy_info);
3215}
3216
Joe Perches64798842008-07-11 15:17:02 -07003217s32 e1000_validate_mdi_setting(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003218{
3219 DEBUGFUNC("e1000_validate_mdi_settings");
3220
Auke Kok8fc897b2006-08-28 14:56:16 -07003221 if (!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003222 DEBUGOUT("Invalid MDI setting detected\n");
3223 hw->mdix = 1;
3224 return -E1000_ERR_CONFIG;
3225 }
3226 return E1000_SUCCESS;
3227}
3228
3229
3230/******************************************************************************
3231 * Sets up eeprom variables in the hw struct. Must be called after mac_type
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00003232 * is configured.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003233 *
3234 * hw - Struct containing variables accessed by shared code
3235 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003236s32 e1000_init_eeprom_params(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003237{
3238 struct e1000_eeprom_info *eeprom = &hw->eeprom;
Joe Perches1dc32912008-07-11 15:17:08 -07003239 u32 eecd = er32(EECD);
Joe Perches406874a2008-04-03 10:06:32 -07003240 s32 ret_val = E1000_SUCCESS;
3241 u16 eeprom_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003242
3243 DEBUGFUNC("e1000_init_eeprom_params");
3244
3245 switch (hw->mac_type) {
3246 case e1000_82542_rev2_0:
3247 case e1000_82542_rev2_1:
3248 case e1000_82543:
3249 case e1000_82544:
3250 eeprom->type = e1000_eeprom_microwire;
3251 eeprom->word_size = 64;
3252 eeprom->opcode_bits = 3;
3253 eeprom->address_bits = 6;
3254 eeprom->delay_usec = 50;
Joe Perchesc3033b02008-03-21 11:06:25 -07003255 eeprom->use_eerd = false;
3256 eeprom->use_eewr = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003257 break;
3258 case e1000_82540:
3259 case e1000_82545:
3260 case e1000_82545_rev_3:
3261 case e1000_82546:
3262 case e1000_82546_rev_3:
3263 eeprom->type = e1000_eeprom_microwire;
3264 eeprom->opcode_bits = 3;
3265 eeprom->delay_usec = 50;
Auke Kok8fc897b2006-08-28 14:56:16 -07003266 if (eecd & E1000_EECD_SIZE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003267 eeprom->word_size = 256;
3268 eeprom->address_bits = 8;
3269 } else {
3270 eeprom->word_size = 64;
3271 eeprom->address_bits = 6;
3272 }
Joe Perchesc3033b02008-03-21 11:06:25 -07003273 eeprom->use_eerd = false;
3274 eeprom->use_eewr = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003275 break;
3276 case e1000_82541:
3277 case e1000_82541_rev_2:
3278 case e1000_82547:
3279 case e1000_82547_rev_2:
3280 if (eecd & E1000_EECD_TYPE) {
3281 eeprom->type = e1000_eeprom_spi;
3282 eeprom->opcode_bits = 8;
3283 eeprom->delay_usec = 1;
3284 if (eecd & E1000_EECD_ADDR_BITS) {
3285 eeprom->page_size = 32;
3286 eeprom->address_bits = 16;
3287 } else {
3288 eeprom->page_size = 8;
3289 eeprom->address_bits = 8;
3290 }
3291 } else {
3292 eeprom->type = e1000_eeprom_microwire;
3293 eeprom->opcode_bits = 3;
3294 eeprom->delay_usec = 50;
3295 if (eecd & E1000_EECD_ADDR_BITS) {
3296 eeprom->word_size = 256;
3297 eeprom->address_bits = 8;
3298 } else {
3299 eeprom->word_size = 64;
3300 eeprom->address_bits = 6;
3301 }
3302 }
Joe Perchesc3033b02008-03-21 11:06:25 -07003303 eeprom->use_eerd = false;
3304 eeprom->use_eewr = false;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003305 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003306 default:
3307 break;
3308 }
3309
3310 if (eeprom->type == e1000_eeprom_spi) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003311 /* eeprom_size will be an enum [0..8] that maps to eeprom sizes 128B to
3312 * 32KB (incremented by powers of 2).
3313 */
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00003314 /* Set to default value for initial eeprom read. */
3315 eeprom->word_size = 64;
3316 ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size);
3317 if (ret_val)
3318 return ret_val;
3319 eeprom_size = (eeprom_size & EEPROM_SIZE_MASK) >> EEPROM_SIZE_SHIFT;
3320 /* 256B eeprom size was not supported in earlier hardware, so we
3321 * bump eeprom_size up one to ensure that "1" (which maps to 256B)
3322 * is never the result used in the shifting logic below. */
3323 if (eeprom_size)
3324 eeprom_size++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003325
3326 eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003327 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003328 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003329}
3330
3331/******************************************************************************
3332 * Raises the EEPROM's clock input.
3333 *
3334 * hw - Struct containing variables accessed by shared code
3335 * eecd - EECD's current value
3336 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003337static void e1000_raise_ee_clk(struct e1000_hw *hw, u32 *eecd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003338{
3339 /* Raise the clock input to the EEPROM (by setting the SK bit), and then
3340 * wait <delay> microseconds.
3341 */
3342 *eecd = *eecd | E1000_EECD_SK;
Joe Perches1dc32912008-07-11 15:17:08 -07003343 ew32(EECD, *eecd);
3344 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003345 udelay(hw->eeprom.delay_usec);
3346}
3347
3348/******************************************************************************
3349 * Lowers the EEPROM's clock input.
3350 *
3351 * hw - Struct containing variables accessed by shared code
3352 * eecd - EECD's current value
3353 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003354static void e1000_lower_ee_clk(struct e1000_hw *hw, u32 *eecd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003355{
3356 /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
3357 * wait 50 microseconds.
3358 */
3359 *eecd = *eecd & ~E1000_EECD_SK;
Joe Perches1dc32912008-07-11 15:17:08 -07003360 ew32(EECD, *eecd);
3361 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003362 udelay(hw->eeprom.delay_usec);
3363}
3364
3365/******************************************************************************
3366 * Shift data bits out to the EEPROM.
3367 *
3368 * hw - Struct containing variables accessed by shared code
3369 * data - data to send to the EEPROM
3370 * count - number of bits to shift out
3371 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003372static void e1000_shift_out_ee_bits(struct e1000_hw *hw, u16 data, u16 count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003373{
3374 struct e1000_eeprom_info *eeprom = &hw->eeprom;
Joe Perches406874a2008-04-03 10:06:32 -07003375 u32 eecd;
3376 u32 mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003377
3378 /* We need to shift "count" bits out to the EEPROM. So, value in the
3379 * "data" parameter will be shifted out to the EEPROM one bit at a time.
3380 * In order to do this, "data" must be broken down into bits.
3381 */
3382 mask = 0x01 << (count - 1);
Joe Perches1dc32912008-07-11 15:17:08 -07003383 eecd = er32(EECD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003384 if (eeprom->type == e1000_eeprom_microwire) {
3385 eecd &= ~E1000_EECD_DO;
3386 } else if (eeprom->type == e1000_eeprom_spi) {
3387 eecd |= E1000_EECD_DO;
3388 }
3389 do {
3390 /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
3391 * and then raising and then lowering the clock (the SK bit controls
3392 * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
3393 * by setting "DI" to "0" and then raising and then lowering the clock.
3394 */
3395 eecd &= ~E1000_EECD_DI;
3396
Auke Kok8fc897b2006-08-28 14:56:16 -07003397 if (data & mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003398 eecd |= E1000_EECD_DI;
3399
Joe Perches1dc32912008-07-11 15:17:08 -07003400 ew32(EECD, eecd);
3401 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003402
3403 udelay(eeprom->delay_usec);
3404
3405 e1000_raise_ee_clk(hw, &eecd);
3406 e1000_lower_ee_clk(hw, &eecd);
3407
3408 mask = mask >> 1;
3409
Auke Kok8fc897b2006-08-28 14:56:16 -07003410 } while (mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003411
3412 /* We leave the "DI" bit set to "0" when we leave this routine. */
3413 eecd &= ~E1000_EECD_DI;
Joe Perches1dc32912008-07-11 15:17:08 -07003414 ew32(EECD, eecd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003415}
3416
3417/******************************************************************************
3418 * Shift data bits in from the EEPROM
3419 *
3420 * hw - Struct containing variables accessed by shared code
3421 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003422static u16 e1000_shift_in_ee_bits(struct e1000_hw *hw, u16 count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003423{
Joe Perches406874a2008-04-03 10:06:32 -07003424 u32 eecd;
3425 u32 i;
3426 u16 data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003427
3428 /* In order to read a register from the EEPROM, we need to shift 'count'
3429 * bits in from the EEPROM. Bits are "shifted in" by raising the clock
3430 * input to the EEPROM (setting the SK bit), and then reading the value of
3431 * the "DO" bit. During this "shifting in" process the "DI" bit should
3432 * always be clear.
3433 */
3434
Joe Perches1dc32912008-07-11 15:17:08 -07003435 eecd = er32(EECD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003436
3437 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
3438 data = 0;
3439
Auke Kok8fc897b2006-08-28 14:56:16 -07003440 for (i = 0; i < count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003441 data = data << 1;
3442 e1000_raise_ee_clk(hw, &eecd);
3443
Joe Perches1dc32912008-07-11 15:17:08 -07003444 eecd = er32(EECD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003445
3446 eecd &= ~(E1000_EECD_DI);
Auke Kok8fc897b2006-08-28 14:56:16 -07003447 if (eecd & E1000_EECD_DO)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003448 data |= 1;
3449
3450 e1000_lower_ee_clk(hw, &eecd);
3451 }
3452
3453 return data;
3454}
3455
3456/******************************************************************************
3457 * Prepares EEPROM for access
3458 *
3459 * hw - Struct containing variables accessed by shared code
3460 *
3461 * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
3462 * function should be called before issuing a command to the EEPROM.
3463 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003464static s32 e1000_acquire_eeprom(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003465{
3466 struct e1000_eeprom_info *eeprom = &hw->eeprom;
Joe Perches406874a2008-04-03 10:06:32 -07003467 u32 eecd, i=0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003468
3469 DEBUGFUNC("e1000_acquire_eeprom");
3470
Joe Perches1dc32912008-07-11 15:17:08 -07003471 eecd = er32(EECD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003472
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00003473 /* Request EEPROM Access */
3474 if (hw->mac_type > e1000_82544) {
3475 eecd |= E1000_EECD_REQ;
3476 ew32(EECD, eecd);
3477 eecd = er32(EECD);
3478 while ((!(eecd & E1000_EECD_GNT)) &&
3479 (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
3480 i++;
3481 udelay(5);
Joe Perches1dc32912008-07-11 15:17:08 -07003482 eecd = er32(EECD);
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00003483 }
3484 if (!(eecd & E1000_EECD_GNT)) {
3485 eecd &= ~E1000_EECD_REQ;
3486 ew32(EECD, eecd);
3487 DEBUGOUT("Could not acquire EEPROM grant\n");
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00003488 return -E1000_ERR_EEPROM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003489 }
3490 }
3491
3492 /* Setup EEPROM for Read/Write */
3493
3494 if (eeprom->type == e1000_eeprom_microwire) {
3495 /* Clear SK and DI */
3496 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
Joe Perches1dc32912008-07-11 15:17:08 -07003497 ew32(EECD, eecd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003498
3499 /* Set CS */
3500 eecd |= E1000_EECD_CS;
Joe Perches1dc32912008-07-11 15:17:08 -07003501 ew32(EECD, eecd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003502 } else if (eeprom->type == e1000_eeprom_spi) {
3503 /* Clear SK and CS */
3504 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
Joe Perches1dc32912008-07-11 15:17:08 -07003505 ew32(EECD, eecd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003506 udelay(1);
3507 }
3508
3509 return E1000_SUCCESS;
3510}
3511
3512/******************************************************************************
3513 * Returns EEPROM to a "standby" state
3514 *
3515 * hw - Struct containing variables accessed by shared code
3516 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003517static void e1000_standby_eeprom(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003518{
3519 struct e1000_eeprom_info *eeprom = &hw->eeprom;
Joe Perches406874a2008-04-03 10:06:32 -07003520 u32 eecd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003521
Joe Perches1dc32912008-07-11 15:17:08 -07003522 eecd = er32(EECD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003523
Auke Kok8fc897b2006-08-28 14:56:16 -07003524 if (eeprom->type == e1000_eeprom_microwire) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003525 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
Joe Perches1dc32912008-07-11 15:17:08 -07003526 ew32(EECD, eecd);
3527 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003528 udelay(eeprom->delay_usec);
3529
3530 /* Clock high */
3531 eecd |= E1000_EECD_SK;
Joe Perches1dc32912008-07-11 15:17:08 -07003532 ew32(EECD, eecd);
3533 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003534 udelay(eeprom->delay_usec);
3535
3536 /* Select EEPROM */
3537 eecd |= E1000_EECD_CS;
Joe Perches1dc32912008-07-11 15:17:08 -07003538 ew32(EECD, eecd);
3539 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003540 udelay(eeprom->delay_usec);
3541
3542 /* Clock low */
3543 eecd &= ~E1000_EECD_SK;
Joe Perches1dc32912008-07-11 15:17:08 -07003544 ew32(EECD, eecd);
3545 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003546 udelay(eeprom->delay_usec);
Auke Kok8fc897b2006-08-28 14:56:16 -07003547 } else if (eeprom->type == e1000_eeprom_spi) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003548 /* Toggle CS to flush commands */
3549 eecd |= E1000_EECD_CS;
Joe Perches1dc32912008-07-11 15:17:08 -07003550 ew32(EECD, eecd);
3551 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003552 udelay(eeprom->delay_usec);
3553 eecd &= ~E1000_EECD_CS;
Joe Perches1dc32912008-07-11 15:17:08 -07003554 ew32(EECD, eecd);
3555 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003556 udelay(eeprom->delay_usec);
3557 }
3558}
3559
3560/******************************************************************************
3561 * Terminates a command by inverting the EEPROM's chip select pin
3562 *
3563 * hw - Struct containing variables accessed by shared code
3564 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003565static void e1000_release_eeprom(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003566{
Joe Perches406874a2008-04-03 10:06:32 -07003567 u32 eecd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003568
3569 DEBUGFUNC("e1000_release_eeprom");
3570
Joe Perches1dc32912008-07-11 15:17:08 -07003571 eecd = er32(EECD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003572
3573 if (hw->eeprom.type == e1000_eeprom_spi) {
3574 eecd |= E1000_EECD_CS; /* Pull CS high */
3575 eecd &= ~E1000_EECD_SK; /* Lower SCK */
3576
Joe Perches1dc32912008-07-11 15:17:08 -07003577 ew32(EECD, eecd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003578
3579 udelay(hw->eeprom.delay_usec);
Auke Kok8fc897b2006-08-28 14:56:16 -07003580 } else if (hw->eeprom.type == e1000_eeprom_microwire) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003581 /* cleanup eeprom */
3582
3583 /* CS on Microwire is active-high */
3584 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
3585
Joe Perches1dc32912008-07-11 15:17:08 -07003586 ew32(EECD, eecd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003587
3588 /* Rising edge of clock */
3589 eecd |= E1000_EECD_SK;
Joe Perches1dc32912008-07-11 15:17:08 -07003590 ew32(EECD, eecd);
3591 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003592 udelay(hw->eeprom.delay_usec);
3593
3594 /* Falling edge of clock */
3595 eecd &= ~E1000_EECD_SK;
Joe Perches1dc32912008-07-11 15:17:08 -07003596 ew32(EECD, eecd);
3597 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003598 udelay(hw->eeprom.delay_usec);
3599 }
3600
3601 /* Stop requesting EEPROM access */
Auke Kok8fc897b2006-08-28 14:56:16 -07003602 if (hw->mac_type > e1000_82544) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003603 eecd &= ~E1000_EECD_REQ;
Joe Perches1dc32912008-07-11 15:17:08 -07003604 ew32(EECD, eecd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003605 }
3606}
3607
3608/******************************************************************************
3609 * Reads a 16 bit word from the EEPROM.
3610 *
3611 * hw - Struct containing variables accessed by shared code
3612 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003613static s32 e1000_spi_eeprom_ready(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003614{
Joe Perches406874a2008-04-03 10:06:32 -07003615 u16 retry_count = 0;
3616 u8 spi_stat_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003617
3618 DEBUGFUNC("e1000_spi_eeprom_ready");
3619
3620 /* Read "Status Register" repeatedly until the LSB is cleared. The
3621 * EEPROM will signal that the command has been completed by clearing
3622 * bit 0 of the internal status register. If it's not cleared within
3623 * 5 milliseconds, then error out.
3624 */
3625 retry_count = 0;
3626 do {
3627 e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
3628 hw->eeprom.opcode_bits);
Joe Perches406874a2008-04-03 10:06:32 -07003629 spi_stat_reg = (u8)e1000_shift_in_ee_bits(hw, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003630 if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
3631 break;
3632
3633 udelay(5);
3634 retry_count += 5;
3635
3636 e1000_standby_eeprom(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07003637 } while (retry_count < EEPROM_MAX_RETRY_SPI);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003638
3639 /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
3640 * only 0-5mSec on 5V devices)
3641 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003642 if (retry_count >= EEPROM_MAX_RETRY_SPI) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003643 DEBUGOUT("SPI EEPROM Status error\n");
3644 return -E1000_ERR_EEPROM;
3645 }
3646
3647 return E1000_SUCCESS;
3648}
3649
3650/******************************************************************************
3651 * Reads a 16 bit word from the EEPROM.
3652 *
3653 * hw - Struct containing variables accessed by shared code
3654 * offset - offset of word in the EEPROM to read
3655 * data - word read from the EEPROM
3656 * words - number of words to read
3657 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003658s32 e1000_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003659{
Christopher Li78566fe2008-09-05 14:04:05 -07003660 s32 ret;
3661 spin_lock(&e1000_eeprom_lock);
3662 ret = e1000_do_read_eeprom(hw, offset, words, data);
3663 spin_unlock(&e1000_eeprom_lock);
3664 return ret;
3665}
3666
3667static s32 e1000_do_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
3668{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003669 struct e1000_eeprom_info *eeprom = &hw->eeprom;
Joe Perches406874a2008-04-03 10:06:32 -07003670 u32 i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003671
3672 DEBUGFUNC("e1000_read_eeprom");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003673
Jeff Kirsher2a88c172006-09-27 12:54:05 -07003674 /* If eeprom is not yet detected, do so now */
3675 if (eeprom->word_size == 0)
3676 e1000_init_eeprom_params(hw);
3677
Linus Torvalds1da177e2005-04-16 15:20:36 -07003678 /* A check for invalid values: offset too large, too many words, and not
3679 * enough words.
3680 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003681 if ((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07003682 (words == 0)) {
Jeff Kirsher2a88c172006-09-27 12:54:05 -07003683 DEBUGOUT2("\"words\" parameter out of bounds. Words = %d, size = %d\n", offset, eeprom->word_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003684 return -E1000_ERR_EEPROM;
3685 }
3686
Jeff Kirsher2a88c172006-09-27 12:54:05 -07003687 /* EEPROM's that don't use EERD to read require us to bit-bang the SPI
3688 * directly. In this case, we need to acquire the EEPROM so that
3689 * FW or other port software does not interrupt.
3690 */
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00003691 if (!hw->eeprom.use_eerd) {
Jeff Kirsher2a88c172006-09-27 12:54:05 -07003692 /* Prepare the EEPROM for bit-bang reading */
3693 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
3694 return -E1000_ERR_EEPROM;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003695 }
3696
Jeff Kirsher2a88c172006-09-27 12:54:05 -07003697 /* Eerd register EEPROM access requires no eeprom aquire/release */
Joe Perchesc3033b02008-03-21 11:06:25 -07003698 if (eeprom->use_eerd)
Jeff Kirsher2a88c172006-09-27 12:54:05 -07003699 return e1000_read_eeprom_eerd(hw, offset, words, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003700
Jeff Kirsher2a88c172006-09-27 12:54:05 -07003701 /* Set up the SPI or Microwire EEPROM for bit-bang reading. We have
3702 * acquired the EEPROM at this point, so any returns should relase it */
Auke Kokcd94dd02006-06-27 09:08:22 -07003703 if (eeprom->type == e1000_eeprom_spi) {
Joe Perches406874a2008-04-03 10:06:32 -07003704 u16 word_in;
3705 u8 read_opcode = EEPROM_READ_OPCODE_SPI;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003706
Auke Kok8fc897b2006-08-28 14:56:16 -07003707 if (e1000_spi_eeprom_ready(hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003708 e1000_release_eeprom(hw);
3709 return -E1000_ERR_EEPROM;
3710 }
3711
3712 e1000_standby_eeprom(hw);
3713
3714 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
Auke Kok8fc897b2006-08-28 14:56:16 -07003715 if ((eeprom->address_bits == 8) && (offset >= 128))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003716 read_opcode |= EEPROM_A8_OPCODE_SPI;
3717
3718 /* Send the READ command (opcode + addr) */
3719 e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
Joe Perches406874a2008-04-03 10:06:32 -07003720 e1000_shift_out_ee_bits(hw, (u16)(offset*2), eeprom->address_bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003721
3722 /* Read the data. The address of the eeprom internally increments with
3723 * each byte (spi) being read, saving on the overhead of eeprom setup
3724 * and tear-down. The address counter will roll over if reading beyond
3725 * the size of the eeprom, thus allowing the entire memory to be read
3726 * starting from any offset. */
3727 for (i = 0; i < words; i++) {
3728 word_in = e1000_shift_in_ee_bits(hw, 16);
3729 data[i] = (word_in >> 8) | (word_in << 8);
3730 }
Auke Kok8fc897b2006-08-28 14:56:16 -07003731 } else if (eeprom->type == e1000_eeprom_microwire) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003732 for (i = 0; i < words; i++) {
3733 /* Send the READ command (opcode + addr) */
3734 e1000_shift_out_ee_bits(hw, EEPROM_READ_OPCODE_MICROWIRE,
3735 eeprom->opcode_bits);
Joe Perches406874a2008-04-03 10:06:32 -07003736 e1000_shift_out_ee_bits(hw, (u16)(offset + i),
Linus Torvalds1da177e2005-04-16 15:20:36 -07003737 eeprom->address_bits);
3738
3739 /* Read the data. For microwire, each word requires the overhead
3740 * of eeprom setup and tear-down. */
3741 data[i] = e1000_shift_in_ee_bits(hw, 16);
3742 e1000_standby_eeprom(hw);
3743 }
3744 }
3745
3746 /* End this read operation */
3747 e1000_release_eeprom(hw);
3748
3749 return E1000_SUCCESS;
3750}
3751
3752/******************************************************************************
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003753 * Reads a 16 bit word from the EEPROM using the EERD register.
3754 *
3755 * hw - Struct containing variables accessed by shared code
3756 * offset - offset of word in the EEPROM to read
3757 * data - word read from the EEPROM
3758 * words - number of words to read
3759 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003760static s32 e1000_read_eeprom_eerd(struct e1000_hw *hw, u16 offset, u16 words,
3761 u16 *data)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003762{
Joe Perches406874a2008-04-03 10:06:32 -07003763 u32 i, eerd = 0;
3764 s32 error = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003765
3766 for (i = 0; i < words; i++) {
3767 eerd = ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) +
3768 E1000_EEPROM_RW_REG_START;
3769
Joe Perches1dc32912008-07-11 15:17:08 -07003770 ew32(EERD, eerd);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003771 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_READ);
Auke Kok76c224b2006-05-23 13:36:06 -07003772
Auke Kok8fc897b2006-08-28 14:56:16 -07003773 if (error) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003774 break;
3775 }
Joe Perches1dc32912008-07-11 15:17:08 -07003776 data[i] = (er32(EERD) >> E1000_EEPROM_RW_REG_DATA);
Auke Kok76c224b2006-05-23 13:36:06 -07003777
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003778 }
Auke Kok76c224b2006-05-23 13:36:06 -07003779
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003780 return error;
3781}
3782
3783/******************************************************************************
3784 * Writes a 16 bit word from the EEPROM using the EEWR register.
3785 *
3786 * hw - Struct containing variables accessed by shared code
3787 * offset - offset of word in the EEPROM to read
3788 * data - word read from the EEPROM
3789 * words - number of words to read
3790 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003791static s32 e1000_write_eeprom_eewr(struct e1000_hw *hw, u16 offset, u16 words,
3792 u16 *data)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003793{
Joe Perches406874a2008-04-03 10:06:32 -07003794 u32 register_value = 0;
3795 u32 i = 0;
3796 s32 error = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003797
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003798
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003799 for (i = 0; i < words; i++) {
Auke Kok76c224b2006-05-23 13:36:06 -07003800 register_value = (data[i] << E1000_EEPROM_RW_REG_DATA) |
3801 ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) |
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003802 E1000_EEPROM_RW_REG_START;
3803
3804 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
Auke Kok8fc897b2006-08-28 14:56:16 -07003805 if (error) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003806 break;
Auke Kok76c224b2006-05-23 13:36:06 -07003807 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003808
Joe Perches1dc32912008-07-11 15:17:08 -07003809 ew32(EEWR, register_value);
Auke Kok76c224b2006-05-23 13:36:06 -07003810
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003811 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
Auke Kok76c224b2006-05-23 13:36:06 -07003812
Auke Kok8fc897b2006-08-28 14:56:16 -07003813 if (error) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003814 break;
Auke Kok76c224b2006-05-23 13:36:06 -07003815 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003816 }
Auke Kok76c224b2006-05-23 13:36:06 -07003817
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003818 return error;
3819}
3820
3821/******************************************************************************
3822 * Polls the status bit (bit 1) of the EERD to determine when the read is done.
3823 *
3824 * hw - Struct containing variables accessed by shared code
3825 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003826static s32 e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003827{
Joe Perches406874a2008-04-03 10:06:32 -07003828 u32 attempts = 100000;
3829 u32 i, reg = 0;
3830 s32 done = E1000_ERR_EEPROM;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003831
Auke Kok8fc897b2006-08-28 14:56:16 -07003832 for (i = 0; i < attempts; i++) {
3833 if (eerd == E1000_EEPROM_POLL_READ)
Joe Perches1dc32912008-07-11 15:17:08 -07003834 reg = er32(EERD);
Auke Kok76c224b2006-05-23 13:36:06 -07003835 else
Joe Perches1dc32912008-07-11 15:17:08 -07003836 reg = er32(EEWR);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003837
Auke Kok8fc897b2006-08-28 14:56:16 -07003838 if (reg & E1000_EEPROM_RW_REG_DONE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003839 done = E1000_SUCCESS;
3840 break;
3841 }
3842 udelay(5);
3843 }
3844
3845 return done;
3846}
3847
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003848/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07003849 * Verifies that the EEPROM has a valid checksum
3850 *
3851 * hw - Struct containing variables accessed by shared code
3852 *
3853 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
3854 * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
3855 * valid.
3856 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003857s32 e1000_validate_eeprom_checksum(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003858{
Joe Perches406874a2008-04-03 10:06:32 -07003859 u16 checksum = 0;
3860 u16 i, eeprom_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003861
3862 DEBUGFUNC("e1000_validate_eeprom_checksum");
3863
Auke Kokcd94dd02006-06-27 09:08:22 -07003864 for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
3865 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003866 DEBUGOUT("EEPROM Read Error\n");
3867 return -E1000_ERR_EEPROM;
3868 }
3869 checksum += eeprom_data;
3870 }
3871
Joe Perchese982f172008-07-11 15:17:18 -07003872 if (checksum == (u16)EEPROM_SUM)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003873 return E1000_SUCCESS;
3874 else {
3875 DEBUGOUT("EEPROM Checksum Invalid\n");
3876 return -E1000_ERR_EEPROM;
3877 }
3878}
3879
3880/******************************************************************************
3881 * Calculates the EEPROM checksum and writes it to the EEPROM
3882 *
3883 * hw - Struct containing variables accessed by shared code
3884 *
3885 * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA.
3886 * Writes the difference to word offset 63 of the EEPROM.
3887 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003888s32 e1000_update_eeprom_checksum(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003889{
Joe Perches406874a2008-04-03 10:06:32 -07003890 u16 checksum = 0;
3891 u16 i, eeprom_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003892
3893 DEBUGFUNC("e1000_update_eeprom_checksum");
3894
Auke Kok8fc897b2006-08-28 14:56:16 -07003895 for (i = 0; i < EEPROM_CHECKSUM_REG; i++) {
3896 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003897 DEBUGOUT("EEPROM Read Error\n");
3898 return -E1000_ERR_EEPROM;
3899 }
3900 checksum += eeprom_data;
3901 }
Joe Perchese982f172008-07-11 15:17:18 -07003902 checksum = (u16)EEPROM_SUM - checksum;
Auke Kok8fc897b2006-08-28 14:56:16 -07003903 if (e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003904 DEBUGOUT("EEPROM Write Error\n");
3905 return -E1000_ERR_EEPROM;
3906 }
3907 return E1000_SUCCESS;
3908}
3909
3910/******************************************************************************
3911 * Parent function for writing words to the different EEPROM types.
3912 *
3913 * hw - Struct containing variables accessed by shared code
3914 * offset - offset within the EEPROM to be written to
3915 * words - number of words to write
3916 * data - 16 bit word to be written to the EEPROM
3917 *
3918 * If e1000_update_eeprom_checksum is not called after this function, the
3919 * EEPROM will most likely contain an invalid checksum.
3920 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003921s32 e1000_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003922{
Christopher Li78566fe2008-09-05 14:04:05 -07003923 s32 ret;
3924 spin_lock(&e1000_eeprom_lock);
3925 ret = e1000_do_write_eeprom(hw, offset, words, data);
3926 spin_unlock(&e1000_eeprom_lock);
3927 return ret;
3928}
3929
3930
3931static s32 e1000_do_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
3932{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003933 struct e1000_eeprom_info *eeprom = &hw->eeprom;
Joe Perches406874a2008-04-03 10:06:32 -07003934 s32 status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003935
3936 DEBUGFUNC("e1000_write_eeprom");
3937
Jeff Kirsher2a88c172006-09-27 12:54:05 -07003938 /* If eeprom is not yet detected, do so now */
3939 if (eeprom->word_size == 0)
3940 e1000_init_eeprom_params(hw);
3941
Linus Torvalds1da177e2005-04-16 15:20:36 -07003942 /* A check for invalid values: offset too large, too many words, and not
3943 * enough words.
3944 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003945 if ((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07003946 (words == 0)) {
3947 DEBUGOUT("\"words\" parameter out of bounds\n");
3948 return -E1000_ERR_EEPROM;
3949 }
3950
Joe Perchesc3033b02008-03-21 11:06:25 -07003951 if (eeprom->use_eewr)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003952 return e1000_write_eeprom_eewr(hw, offset, words, data);
3953
Linus Torvalds1da177e2005-04-16 15:20:36 -07003954 /* Prepare the EEPROM for writing */
3955 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
3956 return -E1000_ERR_EEPROM;
3957
Auke Kok8fc897b2006-08-28 14:56:16 -07003958 if (eeprom->type == e1000_eeprom_microwire) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003959 status = e1000_write_eeprom_microwire(hw, offset, words, data);
3960 } else {
3961 status = e1000_write_eeprom_spi(hw, offset, words, data);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04003962 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003963 }
3964
3965 /* Done with writing */
3966 e1000_release_eeprom(hw);
3967
3968 return status;
3969}
3970
3971/******************************************************************************
3972 * Writes a 16 bit word to a given offset in an SPI EEPROM.
3973 *
3974 * hw - Struct containing variables accessed by shared code
3975 * offset - offset within the EEPROM to be written to
3976 * words - number of words to write
3977 * data - pointer to array of 8 bit words to be written to the EEPROM
3978 *
3979 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003980static s32 e1000_write_eeprom_spi(struct e1000_hw *hw, u16 offset, u16 words,
3981 u16 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003982{
3983 struct e1000_eeprom_info *eeprom = &hw->eeprom;
Joe Perches406874a2008-04-03 10:06:32 -07003984 u16 widx = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003985
3986 DEBUGFUNC("e1000_write_eeprom_spi");
3987
3988 while (widx < words) {
Joe Perches406874a2008-04-03 10:06:32 -07003989 u8 write_opcode = EEPROM_WRITE_OPCODE_SPI;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003990
Auke Kok8fc897b2006-08-28 14:56:16 -07003991 if (e1000_spi_eeprom_ready(hw)) return -E1000_ERR_EEPROM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003992
3993 e1000_standby_eeprom(hw);
3994
3995 /* Send the WRITE ENABLE command (8 bit opcode ) */
3996 e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI,
3997 eeprom->opcode_bits);
3998
3999 e1000_standby_eeprom(hw);
4000
4001 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
Auke Kok8fc897b2006-08-28 14:56:16 -07004002 if ((eeprom->address_bits == 8) && (offset >= 128))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004003 write_opcode |= EEPROM_A8_OPCODE_SPI;
4004
4005 /* Send the Write command (8-bit opcode + addr) */
4006 e1000_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits);
4007
Joe Perches406874a2008-04-03 10:06:32 -07004008 e1000_shift_out_ee_bits(hw, (u16)((offset + widx)*2),
Linus Torvalds1da177e2005-04-16 15:20:36 -07004009 eeprom->address_bits);
4010
4011 /* Send the data */
4012
4013 /* Loop to allow for up to whole page write (32 bytes) of eeprom */
4014 while (widx < words) {
Joe Perches406874a2008-04-03 10:06:32 -07004015 u16 word_out = data[widx];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004016 word_out = (word_out >> 8) | (word_out << 8);
4017 e1000_shift_out_ee_bits(hw, word_out, 16);
4018 widx++;
4019
4020 /* Some larger eeprom sizes are capable of a 32-byte PAGE WRITE
4021 * operation, while the smaller eeproms are capable of an 8-byte
4022 * PAGE WRITE operation. Break the inner loop to pass new address
4023 */
Auke Kok8fc897b2006-08-28 14:56:16 -07004024 if ((((offset + widx)*2) % eeprom->page_size) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004025 e1000_standby_eeprom(hw);
4026 break;
4027 }
4028 }
4029 }
4030
4031 return E1000_SUCCESS;
4032}
4033
4034/******************************************************************************
4035 * Writes a 16 bit word to a given offset in a Microwire EEPROM.
4036 *
4037 * hw - Struct containing variables accessed by shared code
4038 * offset - offset within the EEPROM to be written to
4039 * words - number of words to write
4040 * data - pointer to array of 16 bit words to be written to the EEPROM
4041 *
4042 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004043static s32 e1000_write_eeprom_microwire(struct e1000_hw *hw, u16 offset,
4044 u16 words, u16 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004045{
4046 struct e1000_eeprom_info *eeprom = &hw->eeprom;
Joe Perches406874a2008-04-03 10:06:32 -07004047 u32 eecd;
4048 u16 words_written = 0;
4049 u16 i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004050
4051 DEBUGFUNC("e1000_write_eeprom_microwire");
4052
4053 /* Send the write enable command to the EEPROM (3-bit opcode plus
4054 * 6/8-bit dummy address beginning with 11). It's less work to include
4055 * the 11 of the dummy address as part of the opcode than it is to shift
4056 * it over the correct number of bits for the address. This puts the
4057 * EEPROM into write/erase mode.
4058 */
4059 e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE,
Joe Perches406874a2008-04-03 10:06:32 -07004060 (u16)(eeprom->opcode_bits + 2));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004061
Joe Perches406874a2008-04-03 10:06:32 -07004062 e1000_shift_out_ee_bits(hw, 0, (u16)(eeprom->address_bits - 2));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004063
4064 /* Prepare the EEPROM */
4065 e1000_standby_eeprom(hw);
4066
4067 while (words_written < words) {
4068 /* Send the Write command (3-bit opcode + addr) */
4069 e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE,
4070 eeprom->opcode_bits);
4071
Joe Perches406874a2008-04-03 10:06:32 -07004072 e1000_shift_out_ee_bits(hw, (u16)(offset + words_written),
Linus Torvalds1da177e2005-04-16 15:20:36 -07004073 eeprom->address_bits);
4074
4075 /* Send the data */
4076 e1000_shift_out_ee_bits(hw, data[words_written], 16);
4077
4078 /* Toggle the CS line. This in effect tells the EEPROM to execute
4079 * the previous command.
4080 */
4081 e1000_standby_eeprom(hw);
4082
4083 /* Read DO repeatedly until it is high (equal to '1'). The EEPROM will
4084 * signal that the command has been completed by raising the DO signal.
4085 * If DO does not go high in 10 milliseconds, then error out.
4086 */
Auke Kok8fc897b2006-08-28 14:56:16 -07004087 for (i = 0; i < 200; i++) {
Joe Perches1dc32912008-07-11 15:17:08 -07004088 eecd = er32(EECD);
Auke Kok8fc897b2006-08-28 14:56:16 -07004089 if (eecd & E1000_EECD_DO) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004090 udelay(50);
4091 }
Auke Kok8fc897b2006-08-28 14:56:16 -07004092 if (i == 200) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004093 DEBUGOUT("EEPROM Write did not complete\n");
4094 return -E1000_ERR_EEPROM;
4095 }
4096
4097 /* Recover from write */
4098 e1000_standby_eeprom(hw);
4099
4100 words_written++;
4101 }
4102
4103 /* Send the write disable command to the EEPROM (3-bit opcode plus
4104 * 6/8-bit dummy address beginning with 10). It's less work to include
4105 * the 10 of the dummy address as part of the opcode than it is to shift
4106 * it over the correct number of bits for the address. This takes the
4107 * EEPROM out of write/erase mode.
4108 */
4109 e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE,
Joe Perches406874a2008-04-03 10:06:32 -07004110 (u16)(eeprom->opcode_bits + 2));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004111
Joe Perches406874a2008-04-03 10:06:32 -07004112 e1000_shift_out_ee_bits(hw, 0, (u16)(eeprom->address_bits - 2));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004113
4114 return E1000_SUCCESS;
4115}
4116
4117/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07004118 * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
4119 * second function of dual function devices
4120 *
4121 * hw - Struct containing variables accessed by shared code
4122 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004123s32 e1000_read_mac_addr(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004124{
Joe Perches406874a2008-04-03 10:06:32 -07004125 u16 offset;
4126 u16 eeprom_data, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004127
4128 DEBUGFUNC("e1000_read_mac_addr");
4129
Auke Kok8fc897b2006-08-28 14:56:16 -07004130 for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004131 offset = i >> 1;
Auke Kok8fc897b2006-08-28 14:56:16 -07004132 if (e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004133 DEBUGOUT("EEPROM Read Error\n");
4134 return -E1000_ERR_EEPROM;
4135 }
Joe Perchese982f172008-07-11 15:17:18 -07004136 hw->perm_mac_addr[i] = (u8)(eeprom_data & 0x00FF);
4137 hw->perm_mac_addr[i+1] = (u8)(eeprom_data >> 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004138 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004139
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004140 switch (hw->mac_type) {
4141 default:
4142 break;
4143 case e1000_82546:
4144 case e1000_82546_rev_3:
Joe Perches1dc32912008-07-11 15:17:08 -07004145 if (er32(STATUS) & E1000_STATUS_FUNC_1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004146 hw->perm_mac_addr[5] ^= 0x01;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004147 break;
4148 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004149
Auke Kok8fc897b2006-08-28 14:56:16 -07004150 for (i = 0; i < NODE_ADDRESS_SIZE; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004151 hw->mac_addr[i] = hw->perm_mac_addr[i];
4152 return E1000_SUCCESS;
4153}
4154
4155/******************************************************************************
4156 * Initializes receive address filters.
4157 *
4158 * hw - Struct containing variables accessed by shared code
4159 *
4160 * Places the MAC address in receive address register 0 and clears the rest
4161 * of the receive addresss registers. Clears the multicast table. Assumes
4162 * the receiver is in reset when the routine is called.
4163 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004164static void e1000_init_rx_addrs(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004165{
Joe Perches406874a2008-04-03 10:06:32 -07004166 u32 i;
4167 u32 rar_num;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004168
4169 DEBUGFUNC("e1000_init_rx_addrs");
4170
4171 /* Setup the receive address. */
4172 DEBUGOUT("Programming MAC Address into RAR[0]\n");
4173
4174 e1000_rar_set(hw, hw->mac_addr, 0);
4175
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004176 rar_num = E1000_RAR_ENTRIES;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004177
Linus Torvalds1da177e2005-04-16 15:20:36 -07004178 /* Zero out the other 15 receive addresses. */
4179 DEBUGOUT("Clearing RAR[1-15]\n");
Auke Kok8fc897b2006-08-28 14:56:16 -07004180 for (i = 1; i < rar_num; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004181 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
Joe Perches1dc32912008-07-11 15:17:08 -07004182 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07004183 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
Joe Perches1dc32912008-07-11 15:17:08 -07004184 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07004185 }
4186}
4187
4188/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07004189 * Hashes an address to determine its location in the multicast table
4190 *
4191 * hw - Struct containing variables accessed by shared code
4192 * mc_addr - the multicast address to hash
4193 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004194u32 e1000_hash_mc_addr(struct e1000_hw *hw, u8 *mc_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004195{
Joe Perches406874a2008-04-03 10:06:32 -07004196 u32 hash_value = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004197
4198 /* The portion of the address that is used for the hash table is
4199 * determined by the mc_filter_type setting.
4200 */
4201 switch (hw->mc_filter_type) {
4202 /* [0] [1] [2] [3] [4] [5]
4203 * 01 AA 00 12 34 56
4204 * LSB MSB
4205 */
4206 case 0:
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00004207 /* [47:36] i.e. 0x563 for above example address */
4208 hash_value = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004209 break;
4210 case 1:
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00004211 /* [46:35] i.e. 0xAC6 for above example address */
4212 hash_value = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004213 break;
4214 case 2:
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00004215 /* [45:34] i.e. 0x5D8 for above example address */
4216 hash_value = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004217 break;
4218 case 3:
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00004219 /* [43:32] i.e. 0x634 for above example address */
4220 hash_value = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004221 break;
4222 }
4223
4224 hash_value &= 0xFFF;
4225 return hash_value;
4226}
4227
4228/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07004229 * Puts an ethernet address into a receive address register.
4230 *
4231 * hw - Struct containing variables accessed by shared code
4232 * addr - Address to put into receive address register
4233 * index - Receive address register to write
4234 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004235void e1000_rar_set(struct e1000_hw *hw, u8 *addr, u32 index)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004236{
Joe Perches406874a2008-04-03 10:06:32 -07004237 u32 rar_low, rar_high;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004238
4239 /* HW expects these in little endian so we reverse the byte order
4240 * from network order (big endian) to little endian
4241 */
Joe Perchese982f172008-07-11 15:17:18 -07004242 rar_low = ((u32)addr[0] | ((u32)addr[1] << 8) |
4243 ((u32)addr[2] << 16) | ((u32)addr[3] << 24));
4244 rar_high = ((u32)addr[4] | ((u32)addr[5] << 8));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004245
Jeff Kirsher8df06e52006-03-02 18:18:32 -08004246 /* Disable Rx and flush all Rx frames before enabling RSS to avoid Rx
4247 * unit hang.
4248 *
4249 * Description:
4250 * If there are any Rx frames queued up or otherwise present in the HW
4251 * before RSS is enabled, and then we enable RSS, the HW Rx unit will
4252 * hang. To work around this issue, we have to disable receives and
4253 * flush out all Rx frames before we enable RSS. To do so, we modify we
4254 * redirect all Rx traffic to manageability and then reset the HW.
4255 * This flushes away Rx frames, and (since the redirections to
4256 * manageability persists across resets) keeps new ones from coming in
4257 * while we work. Then, we clear the Address Valid AV bit for all MAC
4258 * addresses and undo the re-direction to manageability.
4259 * Now, frames are coming in again, but the MAC won't accept them, so
4260 * far so good. We now proceed to initialize RSS (if necessary) and
4261 * configure the Rx unit. Last, we re-enable the AV bits and continue
4262 * on our merry way.
4263 */
4264 switch (hw->mac_type) {
Jeff Kirsher8df06e52006-03-02 18:18:32 -08004265 default:
4266 /* Indicate to hardware the Address is Valid. */
4267 rar_high |= E1000_RAH_AV;
4268 break;
4269 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004270
4271 E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
Joe Perches1dc32912008-07-11 15:17:08 -07004272 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07004273 E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
Joe Perches1dc32912008-07-11 15:17:08 -07004274 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07004275}
4276
4277/******************************************************************************
4278 * Writes a value to the specified offset in the VLAN filter table.
4279 *
4280 * hw - Struct containing variables accessed by shared code
4281 * offset - Offset in VLAN filer table to write
4282 * value - Value to write into VLAN filter table
4283 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004284void e1000_write_vfta(struct e1000_hw *hw, u32 offset, u32 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004285{
Joe Perches406874a2008-04-03 10:06:32 -07004286 u32 temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004287
Auke Kokcd94dd02006-06-27 09:08:22 -07004288 if ((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004289 temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1));
4290 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
Joe Perches1dc32912008-07-11 15:17:08 -07004291 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07004292 E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp);
Joe Perches1dc32912008-07-11 15:17:08 -07004293 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07004294 } else {
4295 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
Joe Perches1dc32912008-07-11 15:17:08 -07004296 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07004297 }
4298}
4299
4300/******************************************************************************
4301 * Clears the VLAN filer table
4302 *
4303 * hw - Struct containing variables accessed by shared code
4304 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004305static void e1000_clear_vfta(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004306{
Joe Perches406874a2008-04-03 10:06:32 -07004307 u32 offset;
4308 u32 vfta_value = 0;
4309 u32 vfta_offset = 0;
4310 u32 vfta_bit_in_reg = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004311
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004312 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
4313 /* If the offset we want to clear is the same offset of the
4314 * manageability VLAN ID, then clear all bits except that of the
4315 * manageability unit */
4316 vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0;
4317 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, vfta_value);
Joe Perches1dc32912008-07-11 15:17:08 -07004318 E1000_WRITE_FLUSH();
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004319 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004320}
4321
Joe Perches64798842008-07-11 15:17:02 -07004322static s32 e1000_id_led_init(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004323{
Joe Perches406874a2008-04-03 10:06:32 -07004324 u32 ledctl;
4325 const u32 ledctl_mask = 0x000000FF;
4326 const u32 ledctl_on = E1000_LEDCTL_MODE_LED_ON;
4327 const u32 ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
4328 u16 eeprom_data, i, temp;
4329 const u16 led_mask = 0x0F;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004330
4331 DEBUGFUNC("e1000_id_led_init");
4332
Auke Kok8fc897b2006-08-28 14:56:16 -07004333 if (hw->mac_type < e1000_82540) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004334 /* Nothing to do */
4335 return E1000_SUCCESS;
4336 }
4337
Joe Perches1dc32912008-07-11 15:17:08 -07004338 ledctl = er32(LEDCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004339 hw->ledctl_default = ledctl;
4340 hw->ledctl_mode1 = hw->ledctl_default;
4341 hw->ledctl_mode2 = hw->ledctl_default;
4342
Auke Kok8fc897b2006-08-28 14:56:16 -07004343 if (e1000_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, 1, &eeprom_data) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004344 DEBUGOUT("EEPROM Read Error\n");
4345 return -E1000_ERR_EEPROM;
4346 }
Auke Kokcd94dd02006-06-27 09:08:22 -07004347
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00004348 if ((eeprom_data == ID_LED_RESERVED_0000) ||
Auke Kokcd94dd02006-06-27 09:08:22 -07004349 (eeprom_data == ID_LED_RESERVED_FFFF)) {
Auke Kokcd94dd02006-06-27 09:08:22 -07004350 eeprom_data = ID_LED_DEFAULT;
4351 }
Auke Kok90fb5132006-11-01 08:47:30 -08004352
Auke Kokcd94dd02006-06-27 09:08:22 -07004353 for (i = 0; i < 4; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004354 temp = (eeprom_data >> (i << 2)) & led_mask;
Auke Kok8fc897b2006-08-28 14:56:16 -07004355 switch (temp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004356 case ID_LED_ON1_DEF2:
4357 case ID_LED_ON1_ON2:
4358 case ID_LED_ON1_OFF2:
4359 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
4360 hw->ledctl_mode1 |= ledctl_on << (i << 3);
4361 break;
4362 case ID_LED_OFF1_DEF2:
4363 case ID_LED_OFF1_ON2:
4364 case ID_LED_OFF1_OFF2:
4365 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
4366 hw->ledctl_mode1 |= ledctl_off << (i << 3);
4367 break;
4368 default:
4369 /* Do nothing */
4370 break;
4371 }
Auke Kok8fc897b2006-08-28 14:56:16 -07004372 switch (temp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004373 case ID_LED_DEF1_ON2:
4374 case ID_LED_ON1_ON2:
4375 case ID_LED_OFF1_ON2:
4376 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
4377 hw->ledctl_mode2 |= ledctl_on << (i << 3);
4378 break;
4379 case ID_LED_DEF1_OFF2:
4380 case ID_LED_ON1_OFF2:
4381 case ID_LED_OFF1_OFF2:
4382 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
4383 hw->ledctl_mode2 |= ledctl_off << (i << 3);
4384 break;
4385 default:
4386 /* Do nothing */
4387 break;
4388 }
4389 }
4390 return E1000_SUCCESS;
4391}
4392
4393/******************************************************************************
4394 * Prepares SW controlable LED for use and saves the current state of the LED.
4395 *
4396 * hw - Struct containing variables accessed by shared code
4397 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004398s32 e1000_setup_led(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004399{
Joe Perches406874a2008-04-03 10:06:32 -07004400 u32 ledctl;
4401 s32 ret_val = E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004402
4403 DEBUGFUNC("e1000_setup_led");
4404
Auke Kok8fc897b2006-08-28 14:56:16 -07004405 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004406 case e1000_82542_rev2_0:
4407 case e1000_82542_rev2_1:
4408 case e1000_82543:
4409 case e1000_82544:
4410 /* No setup necessary */
4411 break;
4412 case e1000_82541:
4413 case e1000_82547:
4414 case e1000_82541_rev_2:
4415 case e1000_82547_rev_2:
4416 /* Turn off PHY Smart Power Down (if enabled) */
4417 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
4418 &hw->phy_spd_default);
Auke Kok8fc897b2006-08-28 14:56:16 -07004419 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004420 return ret_val;
4421 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
Joe Perches406874a2008-04-03 10:06:32 -07004422 (u16)(hw->phy_spd_default &
Linus Torvalds1da177e2005-04-16 15:20:36 -07004423 ~IGP01E1000_GMII_SPD));
Auke Kok8fc897b2006-08-28 14:56:16 -07004424 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004425 return ret_val;
4426 /* Fall Through */
4427 default:
Auke Kok8fc897b2006-08-28 14:56:16 -07004428 if (hw->media_type == e1000_media_type_fiber) {
Joe Perches1dc32912008-07-11 15:17:08 -07004429 ledctl = er32(LEDCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004430 /* Save current LEDCTL settings */
4431 hw->ledctl_default = ledctl;
4432 /* Turn off LED0 */
4433 ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
4434 E1000_LEDCTL_LED0_BLINK |
4435 E1000_LEDCTL_LED0_MODE_MASK);
4436 ledctl |= (E1000_LEDCTL_MODE_LED_OFF <<
4437 E1000_LEDCTL_LED0_MODE_SHIFT);
Joe Perches1dc32912008-07-11 15:17:08 -07004438 ew32(LEDCTL, ledctl);
Auke Kok8fc897b2006-08-28 14:56:16 -07004439 } else if (hw->media_type == e1000_media_type_copper)
Joe Perches1dc32912008-07-11 15:17:08 -07004440 ew32(LEDCTL, hw->ledctl_mode1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004441 break;
4442 }
4443
4444 return E1000_SUCCESS;
4445}
4446
Auke Kokf1b3a852006-06-27 09:07:56 -07004447/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07004448 * Restores the saved state of the SW controlable LED.
4449 *
4450 * hw - Struct containing variables accessed by shared code
4451 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004452s32 e1000_cleanup_led(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004453{
Joe Perches406874a2008-04-03 10:06:32 -07004454 s32 ret_val = E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004455
4456 DEBUGFUNC("e1000_cleanup_led");
4457
Auke Kok8fc897b2006-08-28 14:56:16 -07004458 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004459 case e1000_82542_rev2_0:
4460 case e1000_82542_rev2_1:
4461 case e1000_82543:
4462 case e1000_82544:
4463 /* No cleanup necessary */
4464 break;
4465 case e1000_82541:
4466 case e1000_82547:
4467 case e1000_82541_rev_2:
4468 case e1000_82547_rev_2:
4469 /* Turn on PHY Smart Power Down (if previously enabled) */
4470 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
4471 hw->phy_spd_default);
Auke Kok8fc897b2006-08-28 14:56:16 -07004472 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004473 return ret_val;
4474 /* Fall Through */
4475 default:
4476 /* Restore LEDCTL settings */
Joe Perches1dc32912008-07-11 15:17:08 -07004477 ew32(LEDCTL, hw->ledctl_default);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004478 break;
4479 }
4480
4481 return E1000_SUCCESS;
4482}
4483
4484/******************************************************************************
4485 * Turns on 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_on(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_on");
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 /* Set SW Defineable Pin 0 to turn on 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 /* Set SW Defineable Pin 0 to turn on the LED */
4506 ctrl |= E1000_CTRL_SWDPIN0;
4507 ctrl |= E1000_CTRL_SWDPIO0;
4508 } else {
4509 /* Clear SW Defineable Pin 0 to turn on 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 /* Clear SW Defineable Pin 0 to turn on 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_mode2);
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 * Turns off the software controllable LED
4533 *
4534 * hw - Struct containing variables accessed by shared code
4535 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004536s32 e1000_led_off(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004537{
Joe Perches1dc32912008-07-11 15:17:08 -07004538 u32 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004539
4540 DEBUGFUNC("e1000_led_off");
4541
Auke Kok8fc897b2006-08-28 14:56:16 -07004542 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004543 case e1000_82542_rev2_0:
4544 case e1000_82542_rev2_1:
4545 case e1000_82543:
4546 /* Clear SW Defineable Pin 0 to turn off the LED */
4547 ctrl &= ~E1000_CTRL_SWDPIN0;
4548 ctrl |= E1000_CTRL_SWDPIO0;
4549 break;
4550 case e1000_82544:
Auke Kok8fc897b2006-08-28 14:56:16 -07004551 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004552 /* Clear SW Defineable Pin 0 to turn off the LED */
4553 ctrl &= ~E1000_CTRL_SWDPIN0;
4554 ctrl |= E1000_CTRL_SWDPIO0;
4555 } else {
4556 /* Set SW Defineable Pin 0 to turn off the LED */
4557 ctrl |= E1000_CTRL_SWDPIN0;
4558 ctrl |= E1000_CTRL_SWDPIO0;
4559 }
4560 break;
4561 default:
Auke Kok8fc897b2006-08-28 14:56:16 -07004562 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004563 /* Set SW Defineable Pin 0 to turn off the LED */
4564 ctrl |= E1000_CTRL_SWDPIN0;
4565 ctrl |= E1000_CTRL_SWDPIO0;
Auke Kokcd94dd02006-06-27 09:08:22 -07004566 } else if (hw->media_type == e1000_media_type_copper) {
Joe Perches1dc32912008-07-11 15:17:08 -07004567 ew32(LEDCTL, hw->ledctl_mode1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004568 return E1000_SUCCESS;
4569 }
4570 break;
4571 }
4572
Joe Perches1dc32912008-07-11 15:17:08 -07004573 ew32(CTRL, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004574
4575 return E1000_SUCCESS;
4576}
4577
4578/******************************************************************************
4579 * Clears all hardware statistics counters.
4580 *
4581 * hw - Struct containing variables accessed by shared code
4582 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004583static void e1000_clear_hw_cntrs(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004584{
Joe Perches406874a2008-04-03 10:06:32 -07004585 volatile u32 temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004586
Joe Perches1dc32912008-07-11 15:17:08 -07004587 temp = er32(CRCERRS);
4588 temp = er32(SYMERRS);
4589 temp = er32(MPC);
4590 temp = er32(SCC);
4591 temp = er32(ECOL);
4592 temp = er32(MCC);
4593 temp = er32(LATECOL);
4594 temp = er32(COLC);
4595 temp = er32(DC);
4596 temp = er32(SEC);
4597 temp = er32(RLEC);
4598 temp = er32(XONRXC);
4599 temp = er32(XONTXC);
4600 temp = er32(XOFFRXC);
4601 temp = er32(XOFFTXC);
4602 temp = er32(FCRUC);
Auke Kokcd94dd02006-06-27 09:08:22 -07004603
Joe Perches1dc32912008-07-11 15:17:08 -07004604 temp = er32(PRC64);
4605 temp = er32(PRC127);
4606 temp = er32(PRC255);
4607 temp = er32(PRC511);
4608 temp = er32(PRC1023);
4609 temp = er32(PRC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07004610
Joe Perches1dc32912008-07-11 15:17:08 -07004611 temp = er32(GPRC);
4612 temp = er32(BPRC);
4613 temp = er32(MPRC);
4614 temp = er32(GPTC);
4615 temp = er32(GORCL);
4616 temp = er32(GORCH);
4617 temp = er32(GOTCL);
4618 temp = er32(GOTCH);
4619 temp = er32(RNBC);
4620 temp = er32(RUC);
4621 temp = er32(RFC);
4622 temp = er32(ROC);
4623 temp = er32(RJC);
4624 temp = er32(TORL);
4625 temp = er32(TORH);
4626 temp = er32(TOTL);
4627 temp = er32(TOTH);
4628 temp = er32(TPR);
4629 temp = er32(TPT);
Auke Kokcd94dd02006-06-27 09:08:22 -07004630
Joe Perches1dc32912008-07-11 15:17:08 -07004631 temp = er32(PTC64);
4632 temp = er32(PTC127);
4633 temp = er32(PTC255);
4634 temp = er32(PTC511);
4635 temp = er32(PTC1023);
4636 temp = er32(PTC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07004637
Joe Perches1dc32912008-07-11 15:17:08 -07004638 temp = er32(MPTC);
4639 temp = er32(BPTC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004640
Auke Kok8fc897b2006-08-28 14:56:16 -07004641 if (hw->mac_type < e1000_82543) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004642
Joe Perches1dc32912008-07-11 15:17:08 -07004643 temp = er32(ALGNERRC);
4644 temp = er32(RXERRC);
4645 temp = er32(TNCRS);
4646 temp = er32(CEXTERR);
4647 temp = er32(TSCTC);
4648 temp = er32(TSCTFC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004649
Auke Kok8fc897b2006-08-28 14:56:16 -07004650 if (hw->mac_type <= e1000_82544) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004651
Joe Perches1dc32912008-07-11 15:17:08 -07004652 temp = er32(MGTPRC);
4653 temp = er32(MGTPDC);
4654 temp = er32(MGTPTC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004655}
4656
4657/******************************************************************************
4658 * Resets Adaptive IFS to its default state.
4659 *
4660 * hw - Struct containing variables accessed by shared code
4661 *
4662 * Call this after e1000_init_hw. You may override the IFS defaults by setting
Joe Perchesc3033b02008-03-21 11:06:25 -07004663 * hw->ifs_params_forced to true. However, you must initialize hw->
Linus Torvalds1da177e2005-04-16 15:20:36 -07004664 * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio
4665 * before calling this function.
4666 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004667void e1000_reset_adaptive(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004668{
4669 DEBUGFUNC("e1000_reset_adaptive");
4670
Auke Kok8fc897b2006-08-28 14:56:16 -07004671 if (hw->adaptive_ifs) {
4672 if (!hw->ifs_params_forced) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004673 hw->current_ifs_val = 0;
4674 hw->ifs_min_val = IFS_MIN;
4675 hw->ifs_max_val = IFS_MAX;
4676 hw->ifs_step_size = IFS_STEP;
4677 hw->ifs_ratio = IFS_RATIO;
4678 }
Joe Perchesc3033b02008-03-21 11:06:25 -07004679 hw->in_ifs_mode = false;
Joe Perches1dc32912008-07-11 15:17:08 -07004680 ew32(AIT, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004681 } else {
4682 DEBUGOUT("Not in Adaptive IFS mode!\n");
4683 }
4684}
4685
4686/******************************************************************************
4687 * Called during the callback/watchdog routine to update IFS value based on
4688 * the ratio of transmits to collisions.
4689 *
4690 * hw - Struct containing variables accessed by shared code
4691 * tx_packets - Number of transmits since last callback
4692 * total_collisions - Number of collisions since last callback
4693 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004694void e1000_update_adaptive(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004695{
4696 DEBUGFUNC("e1000_update_adaptive");
4697
Auke Kok8fc897b2006-08-28 14:56:16 -07004698 if (hw->adaptive_ifs) {
4699 if ((hw->collision_delta * hw->ifs_ratio) > hw->tx_packet_delta) {
4700 if (hw->tx_packet_delta > MIN_NUM_XMITS) {
Joe Perchesc3033b02008-03-21 11:06:25 -07004701 hw->in_ifs_mode = true;
Auke Kok8fc897b2006-08-28 14:56:16 -07004702 if (hw->current_ifs_val < hw->ifs_max_val) {
4703 if (hw->current_ifs_val == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004704 hw->current_ifs_val = hw->ifs_min_val;
4705 else
4706 hw->current_ifs_val += hw->ifs_step_size;
Joe Perches1dc32912008-07-11 15:17:08 -07004707 ew32(AIT, hw->current_ifs_val);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004708 }
4709 }
4710 } else {
Auke Kok8fc897b2006-08-28 14:56:16 -07004711 if (hw->in_ifs_mode && (hw->tx_packet_delta <= MIN_NUM_XMITS)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004712 hw->current_ifs_val = 0;
Joe Perchesc3033b02008-03-21 11:06:25 -07004713 hw->in_ifs_mode = false;
Joe Perches1dc32912008-07-11 15:17:08 -07004714 ew32(AIT, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004715 }
4716 }
4717 } else {
4718 DEBUGOUT("Not in Adaptive IFS mode!\n");
4719 }
4720}
4721
4722/******************************************************************************
4723 * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT
4724 *
4725 * hw - Struct containing variables accessed by shared code
4726 * frame_len - The length of the frame in question
4727 * mac_addr - The Ethernet destination address of the frame in question
4728 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004729void e1000_tbi_adjust_stats(struct e1000_hw *hw, struct e1000_hw_stats *stats,
4730 u32 frame_len, u8 *mac_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004731{
Joe Perches406874a2008-04-03 10:06:32 -07004732 u64 carry_bit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004733
4734 /* First adjust the frame length. */
4735 frame_len--;
4736 /* We need to adjust the statistics counters, since the hardware
4737 * counters overcount this packet as a CRC error and undercount
4738 * the packet as a good packet
4739 */
4740 /* This packet should not be counted as a CRC error. */
4741 stats->crcerrs--;
4742 /* This packet does count as a Good Packet Received. */
4743 stats->gprc++;
4744
4745 /* Adjust the Good Octets received counters */
4746 carry_bit = 0x80000000 & stats->gorcl;
4747 stats->gorcl += frame_len;
4748 /* If the high bit of Gorcl (the low 32 bits of the Good Octets
4749 * Received Count) was one before the addition,
4750 * AND it is zero after, then we lost the carry out,
4751 * need to add one to Gorch (Good Octets Received Count High).
4752 * This could be simplified if all environments supported
4753 * 64-bit integers.
4754 */
Auke Kok8fc897b2006-08-28 14:56:16 -07004755 if (carry_bit && ((stats->gorcl & 0x80000000) == 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004756 stats->gorch++;
4757 /* Is this a broadcast or multicast? Check broadcast first,
4758 * since the test for a multicast frame will test positive on
4759 * a broadcast frame.
4760 */
Joe Perchese982f172008-07-11 15:17:18 -07004761 if ((mac_addr[0] == (u8)0xff) && (mac_addr[1] == (u8)0xff))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004762 /* Broadcast packet */
4763 stats->bprc++;
Auke Kok8fc897b2006-08-28 14:56:16 -07004764 else if (*mac_addr & 0x01)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004765 /* Multicast packet */
4766 stats->mprc++;
4767
Auke Kok8fc897b2006-08-28 14:56:16 -07004768 if (frame_len == hw->max_frame_size) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004769 /* In this case, the hardware has overcounted the number of
4770 * oversize frames.
4771 */
Auke Kok8fc897b2006-08-28 14:56:16 -07004772 if (stats->roc > 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004773 stats->roc--;
4774 }
4775
4776 /* Adjust the bin counters when the extra byte put the frame in the
4777 * wrong bin. Remember that the frame_len was adjusted above.
4778 */
Auke Kok8fc897b2006-08-28 14:56:16 -07004779 if (frame_len == 64) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004780 stats->prc64++;
4781 stats->prc127--;
Auke Kok8fc897b2006-08-28 14:56:16 -07004782 } else if (frame_len == 127) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004783 stats->prc127++;
4784 stats->prc255--;
Auke Kok8fc897b2006-08-28 14:56:16 -07004785 } else if (frame_len == 255) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004786 stats->prc255++;
4787 stats->prc511--;
Auke Kok8fc897b2006-08-28 14:56:16 -07004788 } else if (frame_len == 511) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004789 stats->prc511++;
4790 stats->prc1023--;
Auke Kok8fc897b2006-08-28 14:56:16 -07004791 } else if (frame_len == 1023) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004792 stats->prc1023++;
4793 stats->prc1522--;
Auke Kok8fc897b2006-08-28 14:56:16 -07004794 } else if (frame_len == 1522) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004795 stats->prc1522++;
4796 }
4797}
4798
4799/******************************************************************************
4800 * Gets the current PCI bus type, speed, and width of the hardware
4801 *
4802 * hw - Struct containing variables accessed by shared code
4803 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004804void e1000_get_bus_info(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004805{
Joe Perches406874a2008-04-03 10:06:32 -07004806 u32 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004807
4808 switch (hw->mac_type) {
4809 case e1000_82542_rev2_0:
4810 case e1000_82542_rev2_1:
Jeff Kirsherc3813ae2006-12-15 10:37:32 +01004811 hw->bus_type = e1000_bus_type_pci;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004812 hw->bus_speed = e1000_bus_speed_unknown;
4813 hw->bus_width = e1000_bus_width_unknown;
4814 break;
4815 default:
Joe Perches1dc32912008-07-11 15:17:08 -07004816 status = er32(STATUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004817 hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
4818 e1000_bus_type_pcix : e1000_bus_type_pci;
4819
Auke Kok8fc897b2006-08-28 14:56:16 -07004820 if (hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004821 hw->bus_speed = (hw->bus_type == e1000_bus_type_pci) ?
4822 e1000_bus_speed_66 : e1000_bus_speed_120;
Auke Kok8fc897b2006-08-28 14:56:16 -07004823 } else if (hw->bus_type == e1000_bus_type_pci) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004824 hw->bus_speed = (status & E1000_STATUS_PCI66) ?
4825 e1000_bus_speed_66 : e1000_bus_speed_33;
4826 } else {
4827 switch (status & E1000_STATUS_PCIX_SPEED) {
4828 case E1000_STATUS_PCIX_SPEED_66:
4829 hw->bus_speed = e1000_bus_speed_66;
4830 break;
4831 case E1000_STATUS_PCIX_SPEED_100:
4832 hw->bus_speed = e1000_bus_speed_100;
4833 break;
4834 case E1000_STATUS_PCIX_SPEED_133:
4835 hw->bus_speed = e1000_bus_speed_133;
4836 break;
4837 default:
4838 hw->bus_speed = e1000_bus_speed_reserved;
4839 break;
4840 }
4841 }
4842 hw->bus_width = (status & E1000_STATUS_BUS64) ?
4843 e1000_bus_width_64 : e1000_bus_width_32;
4844 break;
4845 }
4846}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004847
4848/******************************************************************************
4849 * Writes a value to one of the devices registers using port I/O (as opposed to
4850 * memory mapped I/O). Only 82544 and newer devices support port I/O.
4851 *
4852 * hw - Struct containing variables accessed by shared code
4853 * offset - offset to write to
4854 * value - value to write
4855 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004856static void e1000_write_reg_io(struct e1000_hw *hw, u32 offset, u32 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004857{
4858 unsigned long io_addr = hw->io_base;
4859 unsigned long io_data = hw->io_base + 4;
4860
4861 e1000_io_write(hw, io_addr, offset);
4862 e1000_io_write(hw, io_data, value);
4863}
4864
Linus Torvalds1da177e2005-04-16 15:20:36 -07004865/******************************************************************************
4866 * Estimates the cable length.
4867 *
4868 * hw - Struct containing variables accessed by shared code
4869 * min_length - The estimated minimum length
4870 * max_length - The estimated maximum length
4871 *
4872 * returns: - E1000_ERR_XXX
4873 * E1000_SUCCESS
4874 *
4875 * This function always returns a ranged length (minimum & maximum).
4876 * So for M88 phy's, this function interprets the one value returned from the
4877 * register to the minimum and maximum range.
4878 * For IGP phy's, the function calculates the range by the AGC registers.
4879 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004880static s32 e1000_get_cable_length(struct e1000_hw *hw, u16 *min_length,
4881 u16 *max_length)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004882{
Joe Perches406874a2008-04-03 10:06:32 -07004883 s32 ret_val;
4884 u16 agc_value = 0;
4885 u16 i, phy_data;
4886 u16 cable_length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004887
4888 DEBUGFUNC("e1000_get_cable_length");
4889
4890 *min_length = *max_length = 0;
4891
4892 /* Use old method for Phy older than IGP */
Auke Kok8fc897b2006-08-28 14:56:16 -07004893 if (hw->phy_type == e1000_phy_m88) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004894
Linus Torvalds1da177e2005-04-16 15:20:36 -07004895 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
4896 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004897 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004898 return ret_val;
4899 cable_length = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
4900 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
4901
4902 /* Convert the enum value to ranged values */
4903 switch (cable_length) {
4904 case e1000_cable_length_50:
4905 *min_length = 0;
4906 *max_length = e1000_igp_cable_length_50;
4907 break;
4908 case e1000_cable_length_50_80:
4909 *min_length = e1000_igp_cable_length_50;
4910 *max_length = e1000_igp_cable_length_80;
4911 break;
4912 case e1000_cable_length_80_110:
4913 *min_length = e1000_igp_cable_length_80;
4914 *max_length = e1000_igp_cable_length_110;
4915 break;
4916 case e1000_cable_length_110_140:
4917 *min_length = e1000_igp_cable_length_110;
4918 *max_length = e1000_igp_cable_length_140;
4919 break;
4920 case e1000_cable_length_140:
4921 *min_length = e1000_igp_cable_length_140;
4922 *max_length = e1000_igp_cable_length_170;
4923 break;
4924 default:
4925 return -E1000_ERR_PHY;
4926 break;
4927 }
Auke Kok8fc897b2006-08-28 14:56:16 -07004928 } else if (hw->phy_type == e1000_phy_igp) { /* For IGP PHY */
Joe Perches406874a2008-04-03 10:06:32 -07004929 u16 cur_agc_value;
4930 u16 min_agc_value = IGP01E1000_AGC_LENGTH_TABLE_SIZE;
4931 u16 agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
Linus Torvalds1da177e2005-04-16 15:20:36 -07004932 {IGP01E1000_PHY_AGC_A,
4933 IGP01E1000_PHY_AGC_B,
4934 IGP01E1000_PHY_AGC_C,
4935 IGP01E1000_PHY_AGC_D};
4936 /* Read the AGC registers for all channels */
Auke Kok8fc897b2006-08-28 14:56:16 -07004937 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004938
4939 ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004940 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004941 return ret_val;
4942
Auke Kokcd94dd02006-06-27 09:08:22 -07004943 cur_agc_value = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004944
Auke Kokcd94dd02006-06-27 09:08:22 -07004945 /* Value bound check. */
4946 if ((cur_agc_value >= IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1) ||
4947 (cur_agc_value == 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004948 return -E1000_ERR_PHY;
4949
Auke Kokcd94dd02006-06-27 09:08:22 -07004950 agc_value += cur_agc_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004951
4952 /* Update minimal AGC value. */
Auke Kokcd94dd02006-06-27 09:08:22 -07004953 if (min_agc_value > cur_agc_value)
4954 min_agc_value = cur_agc_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004955 }
4956
4957 /* Remove the minimal AGC result for length < 50m */
Auke Kokcd94dd02006-06-27 09:08:22 -07004958 if (agc_value < IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) {
4959 agc_value -= min_agc_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004960
4961 /* Get the average length of the remaining 3 channels */
4962 agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1);
4963 } else {
4964 /* Get the average length of all the 4 channels. */
4965 agc_value /= IGP01E1000_PHY_CHANNEL_NUM;
4966 }
4967
4968 /* Set the range of the calculated length. */
4969 *min_length = ((e1000_igp_cable_length_table[agc_value] -
4970 IGP01E1000_AGC_RANGE) > 0) ?
4971 (e1000_igp_cable_length_table[agc_value] -
4972 IGP01E1000_AGC_RANGE) : 0;
4973 *max_length = e1000_igp_cable_length_table[agc_value] +
4974 IGP01E1000_AGC_RANGE;
4975 }
4976
4977 return E1000_SUCCESS;
4978}
4979
4980/******************************************************************************
4981 * Check the cable polarity
4982 *
4983 * hw - Struct containing variables accessed by shared code
4984 * polarity - output parameter : 0 - Polarity is not reversed
4985 * 1 - Polarity is reversed.
4986 *
4987 * returns: - E1000_ERR_XXX
4988 * E1000_SUCCESS
4989 *
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02004990 * For phy's older than IGP, this function simply reads the polarity bit in the
Linus Torvalds1da177e2005-04-16 15:20:36 -07004991 * Phy Status register. For IGP phy's, this bit is valid only if link speed is
4992 * 10 Mbps. If the link speed is 100 Mbps there is no polarity so this bit will
4993 * return 0. If the link speed is 1000 Mbps the polarity status is in the
4994 * IGP01E1000_PHY_PCS_INIT_REG.
4995 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004996static s32 e1000_check_polarity(struct e1000_hw *hw,
4997 e1000_rev_polarity *polarity)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004998{
Joe Perches406874a2008-04-03 10:06:32 -07004999 s32 ret_val;
5000 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005001
5002 DEBUGFUNC("e1000_check_polarity");
5003
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00005004 if (hw->phy_type == e1000_phy_m88) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005005 /* return the Polarity bit in the Status register. */
5006 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
5007 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005008 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005009 return ret_val;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07005010 *polarity = ((phy_data & M88E1000_PSSR_REV_POLARITY) >>
5011 M88E1000_PSSR_REV_POLARITY_SHIFT) ?
5012 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
5013
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00005014 } else if (hw->phy_type == e1000_phy_igp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005015 /* Read the Status register to check the speed */
5016 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
5017 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005018 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005019 return ret_val;
5020
5021 /* If speed is 1000 Mbps, must read the IGP01E1000_PHY_PCS_INIT_REG to
5022 * find the polarity status */
Auke Kok8fc897b2006-08-28 14:56:16 -07005023 if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
Linus Torvalds1da177e2005-04-16 15:20:36 -07005024 IGP01E1000_PSSR_SPEED_1000MBPS) {
5025
5026 /* Read the GIG initialization PCS register (0x00B4) */
5027 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG,
5028 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005029 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005030 return ret_val;
5031
5032 /* Check the polarity bits */
Jeff Kirsher70c6f302006-09-27 12:53:31 -07005033 *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ?
5034 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005035 } else {
5036 /* For 10 Mbps, read the polarity bit in the status register. (for
5037 * 100 Mbps this bit is always 0) */
Jeff Kirsher70c6f302006-09-27 12:53:31 -07005038 *polarity = (phy_data & IGP01E1000_PSSR_POLARITY_REVERSED) ?
5039 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005040 }
5041 }
5042 return E1000_SUCCESS;
5043}
5044
5045/******************************************************************************
5046 * Check if Downshift occured
5047 *
5048 * hw - Struct containing variables accessed by shared code
5049 * downshift - output parameter : 0 - No Downshift ocured.
5050 * 1 - Downshift ocured.
5051 *
5052 * returns: - E1000_ERR_XXX
Auke Kok76c224b2006-05-23 13:36:06 -07005053 * E1000_SUCCESS
Linus Torvalds1da177e2005-04-16 15:20:36 -07005054 *
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02005055 * For phy's older than IGP, this function reads the Downshift bit in the Phy
Linus Torvalds1da177e2005-04-16 15:20:36 -07005056 * Specific Status register. For IGP phy's, it reads the Downgrade bit in the
5057 * Link Health register. In IGP this bit is latched high, so the driver must
5058 * read it immediately after link is established.
5059 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07005060static s32 e1000_check_downshift(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005061{
Joe Perches406874a2008-04-03 10:06:32 -07005062 s32 ret_val;
5063 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005064
5065 DEBUGFUNC("e1000_check_downshift");
5066
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00005067 if (hw->phy_type == e1000_phy_igp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005068 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH,
5069 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005070 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005071 return ret_val;
5072
5073 hw->speed_downgraded = (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0;
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00005074 } else if (hw->phy_type == e1000_phy_m88) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005075 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
5076 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005077 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005078 return ret_val;
5079
5080 hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >>
5081 M88E1000_PSSR_DOWNSHIFT_SHIFT;
5082 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005083
Linus Torvalds1da177e2005-04-16 15:20:36 -07005084 return E1000_SUCCESS;
5085}
5086
5087/*****************************************************************************
5088 *
5089 * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a
5090 * gigabit link is achieved to improve link quality.
5091 *
5092 * hw: Struct containing variables accessed by shared code
5093 *
5094 * returns: - E1000_ERR_PHY if fail to read/write the PHY
5095 * E1000_SUCCESS at any other case.
5096 *
5097 ****************************************************************************/
5098
Joe Perches64798842008-07-11 15:17:02 -07005099static s32 e1000_config_dsp_after_link_change(struct e1000_hw *hw, bool link_up)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005100{
Joe Perches406874a2008-04-03 10:06:32 -07005101 s32 ret_val;
5102 u16 phy_data, phy_saved_data, speed, duplex, i;
5103 u16 dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
Linus Torvalds1da177e2005-04-16 15:20:36 -07005104 {IGP01E1000_PHY_AGC_PARAM_A,
5105 IGP01E1000_PHY_AGC_PARAM_B,
5106 IGP01E1000_PHY_AGC_PARAM_C,
5107 IGP01E1000_PHY_AGC_PARAM_D};
Joe Perches406874a2008-04-03 10:06:32 -07005108 u16 min_length, max_length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005109
5110 DEBUGFUNC("e1000_config_dsp_after_link_change");
5111
Auke Kok8fc897b2006-08-28 14:56:16 -07005112 if (hw->phy_type != e1000_phy_igp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005113 return E1000_SUCCESS;
5114
Auke Kok8fc897b2006-08-28 14:56:16 -07005115 if (link_up) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005116 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
Auke Kok8fc897b2006-08-28 14:56:16 -07005117 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005118 DEBUGOUT("Error getting link speed and duplex\n");
5119 return ret_val;
5120 }
5121
Auke Kok8fc897b2006-08-28 14:56:16 -07005122 if (speed == SPEED_1000) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005123
Auke Kokcd94dd02006-06-27 09:08:22 -07005124 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
5125 if (ret_val)
5126 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005127
Auke Kok8fc897b2006-08-28 14:56:16 -07005128 if ((hw->dsp_config_state == e1000_dsp_config_enabled) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07005129 min_length >= e1000_igp_cable_length_50) {
5130
Auke Kok8fc897b2006-08-28 14:56:16 -07005131 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005132 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i],
5133 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005134 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005135 return ret_val;
5136
5137 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
5138
5139 ret_val = e1000_write_phy_reg(hw, dsp_reg_array[i],
5140 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005141 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005142 return ret_val;
5143 }
5144 hw->dsp_config_state = e1000_dsp_config_activated;
5145 }
5146
Auke Kok8fc897b2006-08-28 14:56:16 -07005147 if ((hw->ffe_config_state == e1000_ffe_config_enabled) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07005148 (min_length < e1000_igp_cable_length_50)) {
5149
Joe Perches406874a2008-04-03 10:06:32 -07005150 u16 ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_20;
5151 u32 idle_errs = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005152
5153 /* clear previous idle error counts */
5154 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
5155 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005156 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005157 return ret_val;
5158
Auke Kok8fc897b2006-08-28 14:56:16 -07005159 for (i = 0; i < ffe_idle_err_timeout; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005160 udelay(1000);
5161 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
5162 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005163 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005164 return ret_val;
5165
5166 idle_errs += (phy_data & SR_1000T_IDLE_ERROR_CNT);
Auke Kok8fc897b2006-08-28 14:56:16 -07005167 if (idle_errs > SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005168 hw->ffe_config_state = e1000_ffe_config_active;
5169
5170 ret_val = e1000_write_phy_reg(hw,
5171 IGP01E1000_PHY_DSP_FFE,
5172 IGP01E1000_PHY_DSP_FFE_CM_CP);
Auke Kok8fc897b2006-08-28 14:56:16 -07005173 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005174 return ret_val;
5175 break;
5176 }
5177
Auke Kok8fc897b2006-08-28 14:56:16 -07005178 if (idle_errs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005179 ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_100;
5180 }
5181 }
5182 }
5183 } else {
Auke Kok8fc897b2006-08-28 14:56:16 -07005184 if (hw->dsp_config_state == e1000_dsp_config_activated) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005185 /* Save off the current value of register 0x2F5B to be restored at
5186 * the end of the routines. */
5187 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
5188
Auke Kok8fc897b2006-08-28 14:56:16 -07005189 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005190 return ret_val;
5191
5192 /* Disable the PHY transmitter */
5193 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
5194
Auke Kok8fc897b2006-08-28 14:56:16 -07005195 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005196 return ret_val;
5197
Jeff Garzikf8ec4732006-09-19 15:27:07 -04005198 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005199
5200 ret_val = e1000_write_phy_reg(hw, 0x0000,
5201 IGP01E1000_IEEE_FORCE_GIGA);
Auke Kok8fc897b2006-08-28 14:56:16 -07005202 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005203 return ret_val;
Auke Kok8fc897b2006-08-28 14:56:16 -07005204 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005205 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i], &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005206 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005207 return ret_val;
5208
5209 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
5210 phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS;
5211
5212 ret_val = e1000_write_phy_reg(hw,dsp_reg_array[i], phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005213 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005214 return ret_val;
5215 }
5216
5217 ret_val = e1000_write_phy_reg(hw, 0x0000,
5218 IGP01E1000_IEEE_RESTART_AUTONEG);
Auke Kok8fc897b2006-08-28 14:56:16 -07005219 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005220 return ret_val;
5221
Jeff Garzikf8ec4732006-09-19 15:27:07 -04005222 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005223
5224 /* Now enable the transmitter */
5225 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
5226
Auke Kok8fc897b2006-08-28 14:56:16 -07005227 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005228 return ret_val;
5229
5230 hw->dsp_config_state = e1000_dsp_config_enabled;
5231 }
5232
Auke Kok8fc897b2006-08-28 14:56:16 -07005233 if (hw->ffe_config_state == e1000_ffe_config_active) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005234 /* Save off the current value of register 0x2F5B to be restored at
5235 * the end of the routines. */
5236 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
5237
Auke Kok8fc897b2006-08-28 14:56:16 -07005238 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005239 return ret_val;
5240
5241 /* Disable the PHY transmitter */
5242 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
5243
Auke Kok8fc897b2006-08-28 14:56:16 -07005244 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005245 return ret_val;
5246
Jeff Garzikf8ec4732006-09-19 15:27:07 -04005247 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005248
5249 ret_val = e1000_write_phy_reg(hw, 0x0000,
5250 IGP01E1000_IEEE_FORCE_GIGA);
Auke Kok8fc897b2006-08-28 14:56:16 -07005251 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005252 return ret_val;
5253 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE,
5254 IGP01E1000_PHY_DSP_FFE_DEFAULT);
Auke Kok8fc897b2006-08-28 14:56:16 -07005255 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005256 return ret_val;
5257
5258 ret_val = e1000_write_phy_reg(hw, 0x0000,
5259 IGP01E1000_IEEE_RESTART_AUTONEG);
Auke Kok8fc897b2006-08-28 14:56:16 -07005260 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005261 return ret_val;
5262
Jeff Garzikf8ec4732006-09-19 15:27:07 -04005263 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005264
5265 /* Now enable the transmitter */
5266 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
5267
Auke Kok8fc897b2006-08-28 14:56:16 -07005268 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005269 return ret_val;
5270
5271 hw->ffe_config_state = e1000_ffe_config_enabled;
5272 }
5273 }
5274 return E1000_SUCCESS;
5275}
5276
5277/*****************************************************************************
5278 * Set PHY to class A mode
5279 * Assumes the following operations will follow to enable the new class mode.
5280 * 1. Do a PHY soft reset
5281 * 2. Restart auto-negotiation or force link.
5282 *
5283 * hw - Struct containing variables accessed by shared code
5284 ****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07005285static s32 e1000_set_phy_mode(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005286{
Joe Perches406874a2008-04-03 10:06:32 -07005287 s32 ret_val;
5288 u16 eeprom_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005289
5290 DEBUGFUNC("e1000_set_phy_mode");
5291
Auke Kok8fc897b2006-08-28 14:56:16 -07005292 if ((hw->mac_type == e1000_82545_rev_3) &&
5293 (hw->media_type == e1000_media_type_copper)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005294 ret_val = e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, 1, &eeprom_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005295 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005296 return ret_val;
5297 }
5298
Auke Kok8fc897b2006-08-28 14:56:16 -07005299 if ((eeprom_data != EEPROM_RESERVED_WORD) &&
5300 (eeprom_data & EEPROM_PHY_CLASS_A)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005301 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x000B);
Auke Kok8fc897b2006-08-28 14:56:16 -07005302 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005303 return ret_val;
5304 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x8104);
Auke Kok8fc897b2006-08-28 14:56:16 -07005305 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005306 return ret_val;
5307
Joe Perchesc3033b02008-03-21 11:06:25 -07005308 hw->phy_reset_disable = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005309 }
5310 }
5311
5312 return E1000_SUCCESS;
5313}
5314
5315/*****************************************************************************
5316 *
5317 * This function sets the lplu state according to the active flag. When
5318 * activating lplu this function also disables smart speed and vise versa.
5319 * lplu will not be activated unless the device autonegotiation advertisment
5320 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
5321 * hw: Struct containing variables accessed by shared code
5322 * active - true to enable lplu false to disable lplu.
5323 *
5324 * returns: - E1000_ERR_PHY if fail to read/write the PHY
5325 * E1000_SUCCESS at any other case.
5326 *
5327 ****************************************************************************/
5328
Joe Perches64798842008-07-11 15:17:02 -07005329static s32 e1000_set_d3_lplu_state(struct e1000_hw *hw, bool active)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005330{
Joe Perches406874a2008-04-03 10:06:32 -07005331 s32 ret_val;
5332 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005333 DEBUGFUNC("e1000_set_d3_lplu_state");
5334
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00005335 if (hw->phy_type != e1000_phy_igp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005336 return E1000_SUCCESS;
5337
5338 /* During driver activity LPLU should not be used or it will attain link
5339 * from the lowest speeds starting from 10Mbps. The capability is used for
5340 * Dx transitions and states */
Auke Kokcd94dd02006-06-27 09:08:22 -07005341 if (hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005342 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data);
Auke Kokcd94dd02006-06-27 09:08:22 -07005343 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005344 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005345 } else {
5346 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005347 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005348 return ret_val;
5349 }
5350
Auke Kok8fc897b2006-08-28 14:56:16 -07005351 if (!active) {
5352 if (hw->mac_type == e1000_82541_rev_2 ||
5353 hw->mac_type == e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005354 phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
5355 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005356 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005357 return ret_val;
5358 } else {
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00005359 phy_data &= ~IGP02E1000_PM_D3_LPLU;
5360 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
5361 phy_data);
5362 if (ret_val)
5363 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005364 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005365
5366 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
5367 * Dx states where the power conservation is most important. During
5368 * driver activity we should enable SmartSpeed, so performance is
5369 * maintained. */
5370 if (hw->smart_speed == e1000_smart_speed_on) {
5371 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5372 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005373 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005374 return ret_val;
5375
5376 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
5377 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5378 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005379 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005380 return ret_val;
5381 } else if (hw->smart_speed == e1000_smart_speed_off) {
5382 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5383 &phy_data);
Nicholas Nunley35574762006-09-27 12:53:34 -07005384 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005385 return ret_val;
5386
5387 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
5388 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5389 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005390 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005391 return ret_val;
5392 }
5393
Auke Kok8fc897b2006-08-28 14:56:16 -07005394 } else if ((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT) ||
5395 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL ) ||
5396 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005397
Auke Kok8fc897b2006-08-28 14:56:16 -07005398 if (hw->mac_type == e1000_82541_rev_2 ||
Auke Kokcd94dd02006-06-27 09:08:22 -07005399 hw->mac_type == e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005400 phy_data |= IGP01E1000_GMII_FLEX_SPD;
5401 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005402 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005403 return ret_val;
5404 } else {
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00005405 phy_data |= IGP02E1000_PM_D3_LPLU;
5406 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005407 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005408 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005409 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07005410 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005411
Linus Torvalds1da177e2005-04-16 15:20:36 -07005412 /* When LPLU is enabled we should disable SmartSpeed */
5413 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005414 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005415 return ret_val;
5416
5417 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
5418 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005419 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005420 return ret_val;
5421
5422 }
5423 return E1000_SUCCESS;
5424}
5425
5426/******************************************************************************
5427 * Change VCO speed register to improve Bit Error Rate performance of SERDES.
5428 *
5429 * hw - Struct containing variables accessed by shared code
5430 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07005431static s32 e1000_set_vco_speed(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005432{
Joe Perches406874a2008-04-03 10:06:32 -07005433 s32 ret_val;
5434 u16 default_page = 0;
5435 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005436
5437 DEBUGFUNC("e1000_set_vco_speed");
5438
Auke Kok8fc897b2006-08-28 14:56:16 -07005439 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005440 case e1000_82545_rev_3:
5441 case e1000_82546_rev_3:
5442 break;
5443 default:
5444 return E1000_SUCCESS;
5445 }
5446
5447 /* Set PHY register 30, page 5, bit 8 to 0 */
5448
5449 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, &default_page);
Auke Kok8fc897b2006-08-28 14:56:16 -07005450 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005451 return ret_val;
5452
5453 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005);
Auke Kok8fc897b2006-08-28 14:56:16 -07005454 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005455 return ret_val;
5456
5457 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005458 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005459 return ret_val;
5460
5461 phy_data &= ~M88E1000_PHY_VCO_REG_BIT8;
5462 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005463 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005464 return ret_val;
5465
5466 /* Set PHY register 30, page 4, bit 11 to 1 */
5467
5468 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004);
Auke Kok8fc897b2006-08-28 14:56:16 -07005469 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005470 return ret_val;
5471
5472 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005473 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005474 return ret_val;
5475
5476 phy_data |= M88E1000_PHY_VCO_REG_BIT11;
5477 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005478 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005479 return ret_val;
5480
5481 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, default_page);
Auke Kok8fc897b2006-08-28 14:56:16 -07005482 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005483 return ret_val;
5484
5485 return E1000_SUCCESS;
5486}
5487
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005488
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005489/******************************************************************************
5490 * Verifies the hardware needs to allow ARPs to be processed by the host
5491 *
5492 * hw - Struct containing variables accessed by shared code
5493 *
Joe Perchesc3033b02008-03-21 11:06:25 -07005494 * returns: - true/false
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005495 *
5496 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07005497u32 e1000_enable_mng_pass_thru(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005498{
Joe Perches406874a2008-04-03 10:06:32 -07005499 u32 manc;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005500
5501 if (hw->asf_firmware_present) {
Joe Perches1dc32912008-07-11 15:17:08 -07005502 manc = er32(MANC);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005503
5504 if (!(manc & E1000_MANC_RCV_TCO_EN) ||
5505 !(manc & E1000_MANC_EN_MAC_ADDR_FILTER))
Joe Perchesc3033b02008-03-21 11:06:25 -07005506 return false;
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00005507 if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN))
5508 return true;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005509 }
Joe Perchesc3033b02008-03-21 11:06:25 -07005510 return false;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005511}
5512
Joe Perches64798842008-07-11 15:17:02 -07005513static s32 e1000_polarity_reversal_workaround(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005514{
Joe Perches406874a2008-04-03 10:06:32 -07005515 s32 ret_val;
5516 u16 mii_status_reg;
5517 u16 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005518
5519 /* Polarity reversal workaround for forced 10F/10H links. */
5520
5521 /* Disable the transmitter on the PHY */
5522
5523 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
Auke Kok8fc897b2006-08-28 14:56:16 -07005524 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005525 return ret_val;
5526 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF);
Auke Kok8fc897b2006-08-28 14:56:16 -07005527 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005528 return ret_val;
5529
5530 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
Auke Kok8fc897b2006-08-28 14:56:16 -07005531 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005532 return ret_val;
5533
5534 /* This loop will early-out if the NO link condition has been met. */
Auke Kok8fc897b2006-08-28 14:56:16 -07005535 for (i = PHY_FORCE_TIME; i > 0; i--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005536 /* Read the MII Status Register and wait for Link Status bit
5537 * to be clear.
5538 */
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
5544 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07005545 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005546 return ret_val;
5547
Auke Kok8fc897b2006-08-28 14:56:16 -07005548 if ((mii_status_reg & ~MII_SR_LINK_STATUS) == 0) break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04005549 mdelay(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005550 }
5551
5552 /* Recommended delay time after link has been lost */
Jeff Garzikf8ec4732006-09-19 15:27:07 -04005553 mdelay(1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005554
5555 /* Now we will re-enable th transmitter on the PHY */
5556
5557 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
Auke Kok8fc897b2006-08-28 14:56:16 -07005558 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005559 return ret_val;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04005560 mdelay(50);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005561 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0);
Auke Kok8fc897b2006-08-28 14:56:16 -07005562 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005563 return ret_val;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04005564 mdelay(50);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005565 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00);
Auke Kok8fc897b2006-08-28 14:56:16 -07005566 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005567 return ret_val;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04005568 mdelay(50);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005569 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000);
Auke Kok8fc897b2006-08-28 14:56:16 -07005570 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005571 return ret_val;
5572
5573 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
Auke Kok8fc897b2006-08-28 14:56:16 -07005574 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005575 return ret_val;
5576
5577 /* This loop will early-out if the link condition has been met. */
Auke Kok8fc897b2006-08-28 14:56:16 -07005578 for (i = PHY_FORCE_TIME; i > 0; i--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005579 /* Read the MII Status Register and wait for Link Status bit
5580 * to be set.
5581 */
5582
5583 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07005584 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005585 return ret_val;
5586
5587 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07005588 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005589 return ret_val;
5590
Auke Kok8fc897b2006-08-28 14:56:16 -07005591 if (mii_status_reg & MII_SR_LINK_STATUS) break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04005592 mdelay(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005593 }
5594 return E1000_SUCCESS;
5595}
5596
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005597/*******************************************************************************
5598 *
5599 * Check for EEPROM Auto Read bit done.
5600 *
5601 * hw: Struct containing variables accessed by shared code
5602 *
5603 * returns: - E1000_ERR_RESET if fail to reset MAC
5604 * E1000_SUCCESS at any other case.
5605 *
5606 ******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07005607static s32 e1000_get_auto_rd_done(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005608{
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005609 DEBUGFUNC("e1000_get_auto_rd_done");
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00005610 msleep(5);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005611 return E1000_SUCCESS;
5612}
5613
5614/***************************************************************************
5615 * Checks if the PHY configuration is done
5616 *
5617 * hw: Struct containing variables accessed by shared code
5618 *
5619 * returns: - E1000_ERR_RESET if fail to reset MAC
5620 * E1000_SUCCESS at any other case.
5621 *
5622 ***************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07005623static s32 e1000_get_phy_cfg_done(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005624{
5625 DEBUGFUNC("e1000_get_phy_cfg_done");
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00005626 mdelay(10);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005627 return E1000_SUCCESS;
5628}