blob: 74aa59973316eecdb4f53cf6febe025c5af20b30 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*******************************************************************************
2
Auke Kok0abb6eb2006-09-27 12:53:14 -07003 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2006 Intel Corporation.
5
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 more details.
Auke Kok0abb6eb2006-09-27 12:53:14 -070014
Linus Torvalds1da177e2005-04-16 15:20:36 -070015 You should have received a copy of the GNU General Public License along with
Auke Kok0abb6eb2006-09-27 12:53:14 -070016 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 Contact Information:
23 Linux NICS <linux.nics@intel.com>
Auke Kok3d41e302006-04-14 19:05:31 -070024 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26
27*******************************************************************************/
28
29/* e1000_hw.c
30 * Shared functions for accessing and configuring the MAC
31 */
32
Auke Kok8fc897b2006-08-28 14:56:16 -070033
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include "e1000_hw.h"
35
Joe Perches406874a2008-04-03 10:06:32 -070036static s32 e1000_swfw_sync_acquire(struct e1000_hw *hw, u16 mask);
37static void e1000_swfw_sync_release(struct e1000_hw *hw, u16 mask);
Nicholas Nunley35574762006-09-27 12:53:34 -070038
Joe Perches406874a2008-04-03 10:06:32 -070039static s32 e1000_check_downshift(struct e1000_hw *hw);
Joe Perches64798842008-07-11 15:17:02 -070040static s32 e1000_check_polarity(struct e1000_hw *hw,
41 e1000_rev_polarity *polarity);
Nicholas Nunley35574762006-09-27 12:53:34 -070042static void e1000_clear_hw_cntrs(struct e1000_hw *hw);
43static void e1000_clear_vfta(struct e1000_hw *hw);
Joe Perches406874a2008-04-03 10:06:32 -070044static s32 e1000_config_dsp_after_link_change(struct e1000_hw *hw,
Joe Perches64798842008-07-11 15:17:02 -070045 bool link_up);
Joe Perches406874a2008-04-03 10:06:32 -070046static s32 e1000_config_fc_after_link_up(struct e1000_hw *hw);
47static s32 e1000_detect_gig_phy(struct e1000_hw *hw);
Joe Perches406874a2008-04-03 10:06:32 -070048static s32 e1000_get_auto_rd_done(struct e1000_hw *hw);
Joe Perches64798842008-07-11 15:17:02 -070049static s32 e1000_get_cable_length(struct e1000_hw *hw, u16 *min_length,
50 u16 *max_length);
Joe Perches406874a2008-04-03 10:06:32 -070051static s32 e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw);
52static s32 e1000_get_phy_cfg_done(struct e1000_hw *hw);
Joe Perches406874a2008-04-03 10:06:32 -070053static s32 e1000_id_led_init(struct e1000_hw *hw);
Nicholas Nunley35574762006-09-27 12:53:34 -070054static void e1000_init_rx_addrs(struct e1000_hw *hw);
Joe Perches64798842008-07-11 15:17:02 -070055static s32 e1000_phy_igp_get_info(struct e1000_hw *hw,
56 struct e1000_phy_info *phy_info);
57static s32 e1000_read_eeprom_eerd(struct e1000_hw *hw, u16 offset, u16 words,
58 u16 *data);
59static s32 e1000_write_eeprom_eewr(struct e1000_hw *hw, u16 offset, u16 words,
60 u16 *data);
Joe Perches406874a2008-04-03 10:06:32 -070061static s32 e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd);
Joe Perches64798842008-07-11 15:17:02 -070062static s32 e1000_phy_m88_get_info(struct e1000_hw *hw,
63 struct e1000_phy_info *phy_info);
Nicholas Nunley35574762006-09-27 12:53:34 -070064static void e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw);
Joe Perches406874a2008-04-03 10:06:32 -070065static s32 e1000_set_d3_lplu_state(struct e1000_hw *hw, bool active);
Joe Perches406874a2008-04-03 10:06:32 -070066static s32 e1000_wait_autoneg(struct e1000_hw *hw);
67static void e1000_write_reg_io(struct e1000_hw *hw, u32 offset, u32 value);
68static s32 e1000_set_phy_type(struct e1000_hw *hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069static void e1000_phy_init_script(struct e1000_hw *hw);
Joe Perches406874a2008-04-03 10:06:32 -070070static s32 e1000_setup_copper_link(struct e1000_hw *hw);
71static s32 e1000_setup_fiber_serdes_link(struct e1000_hw *hw);
72static s32 e1000_adjust_serdes_amplitude(struct e1000_hw *hw);
73static s32 e1000_phy_force_speed_duplex(struct e1000_hw *hw);
74static s32 e1000_config_mac_to_phy(struct e1000_hw *hw);
75static void e1000_raise_mdi_clk(struct e1000_hw *hw, u32 *ctrl);
76static void e1000_lower_mdi_clk(struct e1000_hw *hw, u32 *ctrl);
77static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, u32 data,
Joe Perches64798842008-07-11 15:17:02 -070078 u16 count);
Joe Perches406874a2008-04-03 10:06:32 -070079static u16 e1000_shift_in_mdi_bits(struct e1000_hw *hw);
80static s32 e1000_phy_reset_dsp(struct e1000_hw *hw);
81static s32 e1000_write_eeprom_spi(struct e1000_hw *hw, u16 offset,
82 u16 words, u16 *data);
Joe Perches64798842008-07-11 15:17:02 -070083static s32 e1000_write_eeprom_microwire(struct e1000_hw *hw, u16 offset,
84 u16 words, u16 *data);
Joe Perches406874a2008-04-03 10:06:32 -070085static s32 e1000_spi_eeprom_ready(struct e1000_hw *hw);
86static void e1000_raise_ee_clk(struct e1000_hw *hw, u32 *eecd);
87static void e1000_lower_ee_clk(struct e1000_hw *hw, u32 *eecd);
Joe Perches64798842008-07-11 15:17:02 -070088static void e1000_shift_out_ee_bits(struct e1000_hw *hw, u16 data, u16 count);
Joe Perches406874a2008-04-03 10:06:32 -070089static s32 e1000_write_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr,
Joe Perches64798842008-07-11 15:17:02 -070090 u16 phy_data);
Joe Perches406874a2008-04-03 10:06:32 -070091static s32 e1000_read_phy_reg_ex(struct e1000_hw *hw,u32 reg_addr,
Joe Perches64798842008-07-11 15:17:02 -070092 u16 *phy_data);
Joe Perches406874a2008-04-03 10:06:32 -070093static u16 e1000_shift_in_ee_bits(struct e1000_hw *hw, u16 count);
94static s32 e1000_acquire_eeprom(struct e1000_hw *hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095static void e1000_release_eeprom(struct e1000_hw *hw);
96static void e1000_standby_eeprom(struct e1000_hw *hw);
Joe Perches406874a2008-04-03 10:06:32 -070097static s32 e1000_set_vco_speed(struct e1000_hw *hw);
98static s32 e1000_polarity_reversal_workaround(struct e1000_hw *hw);
99static s32 e1000_set_phy_mode(struct e1000_hw *hw);
Christopher Li78566fe2008-09-05 14:04:05 -0700100static s32 e1000_do_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data);
101static s32 e1000_do_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
103/* IGP cable length table */
104static const
Joe Perches406874a2008-04-03 10:06:32 -0700105u16 e1000_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
107 5, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 25, 25, 25,
108 25, 25, 25, 25, 30, 30, 30, 30, 40, 40, 40, 40, 40, 40, 40, 40,
109 40, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60,
110 60, 70, 70, 70, 70, 70, 70, 80, 80, 80, 80, 80, 80, 90, 90, 90,
111 90, 90, 90, 90, 90, 90, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
112 100, 100, 100, 100, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,
113 110, 110, 110, 110, 110, 110, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120};
114
Christopher Li78566fe2008-09-05 14:04:05 -0700115static DEFINE_SPINLOCK(e1000_eeprom_lock);
116
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117/******************************************************************************
118 * Set the phy type member in the hw struct.
119 *
120 * hw - Struct containing variables accessed by shared code
121 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -0700122static s32 e1000_set_phy_type(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123{
124 DEBUGFUNC("e1000_set_phy_type");
125
Auke Kok8fc897b2006-08-28 14:56:16 -0700126 if (hw->mac_type == e1000_undefined)
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700127 return -E1000_ERR_PHY_TYPE;
128
Auke Kok8fc897b2006-08-28 14:56:16 -0700129 switch (hw->phy_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 case M88E1000_E_PHY_ID:
131 case M88E1000_I_PHY_ID:
132 case M88E1011_I_PHY_ID:
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700133 case M88E1111_I_PHY_ID:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 hw->phy_type = e1000_phy_m88;
135 break;
136 case IGP01E1000_I_PHY_ID:
Auke Kok8fc897b2006-08-28 14:56:16 -0700137 if (hw->mac_type == e1000_82541 ||
138 hw->mac_type == e1000_82541_rev_2 ||
139 hw->mac_type == e1000_82547 ||
140 hw->mac_type == e1000_82547_rev_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 hw->phy_type = e1000_phy_igp;
142 break;
143 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 default:
145 /* Should never have loaded on this device */
146 hw->phy_type = e1000_phy_undefined;
147 return -E1000_ERR_PHY_TYPE;
148 }
149
150 return E1000_SUCCESS;
151}
152
153/******************************************************************************
154 * IGP phy init script - initializes the GbE PHY
155 *
156 * hw - Struct containing variables accessed by shared code
157 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -0700158static void e1000_phy_init_script(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159{
Joe Perches406874a2008-04-03 10:06:32 -0700160 u32 ret_val;
161 u16 phy_saved_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
163 DEBUGFUNC("e1000_phy_init_script");
164
Auke Kok8fc897b2006-08-28 14:56:16 -0700165 if (hw->phy_init_script) {
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400166 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167
168 /* Save off the current value of register 0x2F5B to be restored at
169 * the end of this routine. */
170 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
171
172 /* Disabled the PHY transmitter */
173 e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
174
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400175 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176
177 e1000_write_phy_reg(hw,0x0000,0x0140);
178
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400179 msleep(5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
Auke Kok8fc897b2006-08-28 14:56:16 -0700181 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 case e1000_82541:
183 case e1000_82547:
184 e1000_write_phy_reg(hw, 0x1F95, 0x0001);
185
186 e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
187
188 e1000_write_phy_reg(hw, 0x1F79, 0x0018);
189
190 e1000_write_phy_reg(hw, 0x1F30, 0x1600);
191
192 e1000_write_phy_reg(hw, 0x1F31, 0x0014);
193
194 e1000_write_phy_reg(hw, 0x1F32, 0x161C);
195
196 e1000_write_phy_reg(hw, 0x1F94, 0x0003);
197
198 e1000_write_phy_reg(hw, 0x1F96, 0x003F);
199
200 e1000_write_phy_reg(hw, 0x2010, 0x0008);
201 break;
202
203 case e1000_82541_rev_2:
204 case e1000_82547_rev_2:
205 e1000_write_phy_reg(hw, 0x1F73, 0x0099);
206 break;
207 default:
208 break;
209 }
210
211 e1000_write_phy_reg(hw, 0x0000, 0x3300);
212
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400213 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214
215 /* Now enable the transmitter */
216 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
217
Auke Kok8fc897b2006-08-28 14:56:16 -0700218 if (hw->mac_type == e1000_82547) {
Joe Perches406874a2008-04-03 10:06:32 -0700219 u16 fused, fine, coarse;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
221 /* Move to analog registers page */
222 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_SPARE_FUSE_STATUS, &fused);
223
Auke Kok8fc897b2006-08-28 14:56:16 -0700224 if (!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_FUSE_STATUS, &fused);
226
227 fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
228 coarse = fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
229
Auke Kok8fc897b2006-08-28 14:56:16 -0700230 if (coarse > IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 coarse -= IGP01E1000_ANALOG_FUSE_COARSE_10;
232 fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
Auke Kok8fc897b2006-08-28 14:56:16 -0700233 } else if (coarse == IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
235
236 fused = (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
237 (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
238 (coarse & IGP01E1000_ANALOG_FUSE_COARSE_MASK);
239
240 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_CONTROL, fused);
241 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_BYPASS,
242 IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
243 }
244 }
245 }
246}
247
248/******************************************************************************
249 * Set the mac type member in the hw struct.
250 *
251 * hw - Struct containing variables accessed by shared code
252 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -0700253s32 e1000_set_mac_type(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254{
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500255 DEBUGFUNC("e1000_set_mac_type");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500257 switch (hw->device_id) {
258 case E1000_DEV_ID_82542:
259 switch (hw->revision_id) {
260 case E1000_82542_2_0_REV_ID:
261 hw->mac_type = e1000_82542_rev2_0;
262 break;
263 case E1000_82542_2_1_REV_ID:
264 hw->mac_type = e1000_82542_rev2_1;
265 break;
266 default:
267 /* Invalid 82542 revision ID */
268 return -E1000_ERR_MAC_TYPE;
269 }
270 break;
271 case E1000_DEV_ID_82543GC_FIBER:
272 case E1000_DEV_ID_82543GC_COPPER:
273 hw->mac_type = e1000_82543;
274 break;
275 case E1000_DEV_ID_82544EI_COPPER:
276 case E1000_DEV_ID_82544EI_FIBER:
277 case E1000_DEV_ID_82544GC_COPPER:
278 case E1000_DEV_ID_82544GC_LOM:
279 hw->mac_type = e1000_82544;
280 break;
281 case E1000_DEV_ID_82540EM:
282 case E1000_DEV_ID_82540EM_LOM:
283 case E1000_DEV_ID_82540EP:
284 case E1000_DEV_ID_82540EP_LOM:
285 case E1000_DEV_ID_82540EP_LP:
286 hw->mac_type = e1000_82540;
287 break;
288 case E1000_DEV_ID_82545EM_COPPER:
289 case E1000_DEV_ID_82545EM_FIBER:
290 hw->mac_type = e1000_82545;
291 break;
292 case E1000_DEV_ID_82545GM_COPPER:
293 case E1000_DEV_ID_82545GM_FIBER:
294 case E1000_DEV_ID_82545GM_SERDES:
295 hw->mac_type = e1000_82545_rev_3;
296 break;
297 case E1000_DEV_ID_82546EB_COPPER:
298 case E1000_DEV_ID_82546EB_FIBER:
299 case E1000_DEV_ID_82546EB_QUAD_COPPER:
300 hw->mac_type = e1000_82546;
301 break;
302 case E1000_DEV_ID_82546GB_COPPER:
303 case E1000_DEV_ID_82546GB_FIBER:
304 case E1000_DEV_ID_82546GB_SERDES:
305 case E1000_DEV_ID_82546GB_PCIE:
306 case E1000_DEV_ID_82546GB_QUAD_COPPER:
307 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
308 hw->mac_type = e1000_82546_rev_3;
309 break;
310 case E1000_DEV_ID_82541EI:
311 case E1000_DEV_ID_82541EI_MOBILE:
312 case E1000_DEV_ID_82541ER_LOM:
313 hw->mac_type = e1000_82541;
314 break;
315 case E1000_DEV_ID_82541ER:
316 case E1000_DEV_ID_82541GI:
317 case E1000_DEV_ID_82541GI_LF:
318 case E1000_DEV_ID_82541GI_MOBILE:
319 hw->mac_type = e1000_82541_rev_2;
320 break;
321 case E1000_DEV_ID_82547EI:
322 case E1000_DEV_ID_82547EI_MOBILE:
323 hw->mac_type = e1000_82547;
324 break;
325 case E1000_DEV_ID_82547GI:
326 hw->mac_type = e1000_82547_rev_2;
327 break;
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500328 default:
329 /* Should never have loaded on this device */
330 return -E1000_ERR_MAC_TYPE;
331 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500333 switch (hw->mac_type) {
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500334 case e1000_82541:
335 case e1000_82547:
336 case e1000_82541_rev_2:
337 case e1000_82547_rev_2:
Joe Perchesc3033b02008-03-21 11:06:25 -0700338 hw->asf_firmware_present = true;
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500339 break;
340 default:
341 break;
342 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343
Jeff Garzik167fb282006-12-15 10:41:15 -0500344 /* The 82543 chip does not count tx_carrier_errors properly in
345 * FD mode
346 */
347 if (hw->mac_type == e1000_82543)
Joe Perchesc3033b02008-03-21 11:06:25 -0700348 hw->bad_tx_carr_stats_fd = true;
Jeff Garzik167fb282006-12-15 10:41:15 -0500349
Jeff Garzik15e376b2006-12-15 11:16:33 -0500350 if (hw->mac_type > e1000_82544)
Joe Perchesc3033b02008-03-21 11:06:25 -0700351 hw->has_smbus = true;
Jeff Garzik15e376b2006-12-15 11:16:33 -0500352
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500353 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354}
355
356/*****************************************************************************
357 * Set media type and TBI compatibility.
358 *
359 * hw - Struct containing variables accessed by shared code
360 * **************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -0700361void e1000_set_media_type(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362{
Joe Perches406874a2008-04-03 10:06:32 -0700363 u32 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364
365 DEBUGFUNC("e1000_set_media_type");
366
Auke Kok8fc897b2006-08-28 14:56:16 -0700367 if (hw->mac_type != e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 /* tbi_compatibility is only valid on 82543 */
Joe Perchesc3033b02008-03-21 11:06:25 -0700369 hw->tbi_compatibility_en = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 }
371
372 switch (hw->device_id) {
373 case E1000_DEV_ID_82545GM_SERDES:
374 case E1000_DEV_ID_82546GB_SERDES:
375 hw->media_type = e1000_media_type_internal_serdes;
376 break;
377 default:
Malli Chilakala3893d542005-06-17 17:44:49 -0700378 switch (hw->mac_type) {
379 case e1000_82542_rev2_0:
380 case e1000_82542_rev2_1:
381 hw->media_type = e1000_media_type_fiber;
382 break;
Malli Chilakala3893d542005-06-17 17:44:49 -0700383 default:
Joe Perches1dc32912008-07-11 15:17:08 -0700384 status = er32(STATUS);
Malli Chilakala3893d542005-06-17 17:44:49 -0700385 if (status & E1000_STATUS_TBIMODE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 hw->media_type = e1000_media_type_fiber;
387 /* tbi_compatibility not valid on fiber */
Joe Perchesc3033b02008-03-21 11:06:25 -0700388 hw->tbi_compatibility_en = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 } else {
390 hw->media_type = e1000_media_type_copper;
391 }
Malli Chilakala3893d542005-06-17 17:44:49 -0700392 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 }
394 }
395}
396
397/******************************************************************************
398 * Reset the transmit and receive units; mask and clear all interrupts.
399 *
400 * hw - Struct containing variables accessed by shared code
401 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -0700402s32 e1000_reset_hw(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403{
Joe Perches406874a2008-04-03 10:06:32 -0700404 u32 ctrl;
405 u32 ctrl_ext;
406 u32 icr;
407 u32 manc;
408 u32 led_ctrl;
Joe Perches406874a2008-04-03 10:06:32 -0700409 s32 ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410
411 DEBUGFUNC("e1000_reset_hw");
412
413 /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
Auke Kok8fc897b2006-08-28 14:56:16 -0700414 if (hw->mac_type == e1000_82542_rev2_0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
416 e1000_pci_clear_mwi(hw);
417 }
418
419 /* Clear interrupt mask to stop board from generating interrupts */
420 DEBUGOUT("Masking off all interrupts\n");
Joe Perches1dc32912008-07-11 15:17:08 -0700421 ew32(IMC, 0xffffffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
423 /* Disable the Transmit and Receive units. Then delay to allow
424 * any pending transactions to complete before we hit the MAC with
425 * the global reset.
426 */
Joe Perches1dc32912008-07-11 15:17:08 -0700427 ew32(RCTL, 0);
428 ew32(TCTL, E1000_TCTL_PSP);
429 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430
431 /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
Joe Perchesc3033b02008-03-21 11:06:25 -0700432 hw->tbi_compatibility_on = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433
434 /* Delay to allow any outstanding PCI transactions to complete before
435 * resetting the device
436 */
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400437 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438
Joe Perches1dc32912008-07-11 15:17:08 -0700439 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440
441 /* Must reset the PHY before resetting the MAC */
Auke Kok8fc897b2006-08-28 14:56:16 -0700442 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
Joe Perches1dc32912008-07-11 15:17:08 -0700443 ew32(CTRL, (ctrl | E1000_CTRL_PHY_RST));
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400444 msleep(5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 }
446
447 /* Issue a global reset to the MAC. This will reset the chip's
448 * transmit, receive, DMA, and link units. It will not effect
449 * the current PCI configuration. The global reset bit is self-
450 * clearing, and should clear within a microsecond.
451 */
452 DEBUGOUT("Issuing a global reset to MAC\n");
453
Auke Kok8fc897b2006-08-28 14:56:16 -0700454 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 case e1000_82544:
456 case e1000_82540:
457 case e1000_82545:
458 case e1000_82546:
459 case e1000_82541:
460 case e1000_82541_rev_2:
461 /* These controllers can't ack the 64-bit write when issuing the
462 * reset, so use IO-mapping as a workaround to issue the reset */
463 E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
464 break;
465 case e1000_82545_rev_3:
466 case e1000_82546_rev_3:
467 /* Reset is performed on a shadow of the control register */
Joe Perches1dc32912008-07-11 15:17:08 -0700468 ew32(CTRL_DUP, (ctrl | E1000_CTRL_RST));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 break;
470 default:
Joe Perches1dc32912008-07-11 15:17:08 -0700471 ew32(CTRL, (ctrl | E1000_CTRL_RST));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 break;
473 }
474
475 /* After MAC reset, force reload of EEPROM to restore power-on settings to
476 * device. Later controllers reload the EEPROM automatically, so just wait
477 * for reload to complete.
478 */
Auke Kok8fc897b2006-08-28 14:56:16 -0700479 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 case e1000_82542_rev2_0:
481 case e1000_82542_rev2_1:
482 case e1000_82543:
483 case e1000_82544:
484 /* Wait for reset to complete */
485 udelay(10);
Joe Perches1dc32912008-07-11 15:17:08 -0700486 ctrl_ext = er32(CTRL_EXT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
Joe Perches1dc32912008-07-11 15:17:08 -0700488 ew32(CTRL_EXT, ctrl_ext);
489 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 /* Wait for EEPROM reload */
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400491 msleep(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 break;
493 case e1000_82541:
494 case e1000_82541_rev_2:
495 case e1000_82547:
496 case e1000_82547_rev_2:
497 /* Wait for EEPROM reload */
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400498 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 break;
Jeff Kirsher2a88c172006-09-27 12:54:05 -0700500 default:
501 /* Auto read done will delay 5ms or poll based on mac type */
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700502 ret_val = e1000_get_auto_rd_done(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -0700503 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700504 return ret_val;
505 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 }
507
508 /* Disable HW ARPs on ASF enabled adapters */
Jesse Brandeburg1532ece2009-09-25 12:16:14 +0000509 if (hw->mac_type >= e1000_82540) {
Joe Perches1dc32912008-07-11 15:17:08 -0700510 manc = er32(MANC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 manc &= ~(E1000_MANC_ARP_EN);
Joe Perches1dc32912008-07-11 15:17:08 -0700512 ew32(MANC, manc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 }
514
Auke Kok8fc897b2006-08-28 14:56:16 -0700515 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 e1000_phy_init_script(hw);
517
518 /* Configure activity LED after PHY reset */
Joe Perches1dc32912008-07-11 15:17:08 -0700519 led_ctrl = er32(LEDCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 led_ctrl &= IGP_ACTIVITY_LED_MASK;
521 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
Joe Perches1dc32912008-07-11 15:17:08 -0700522 ew32(LEDCTL, led_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 }
524
525 /* Clear interrupt mask to stop board from generating interrupts */
526 DEBUGOUT("Masking off all interrupts\n");
Joe Perches1dc32912008-07-11 15:17:08 -0700527 ew32(IMC, 0xffffffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528
529 /* Clear any pending interrupt events. */
Joe Perches1dc32912008-07-11 15:17:08 -0700530 icr = er32(ICR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531
532 /* If MWI was previously enabled, reenable it. */
Auke Kok8fc897b2006-08-28 14:56:16 -0700533 if (hw->mac_type == e1000_82542_rev2_0) {
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400534 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 e1000_pci_set_mwi(hw);
536 }
537
538 return E1000_SUCCESS;
539}
540
541/******************************************************************************
542 * Performs basic configuration of the adapter.
543 *
544 * hw - Struct containing variables accessed by shared code
545 *
546 * Assumes that the controller has previously been reset and is in a
547 * post-reset uninitialized state. Initializes the receive address registers,
548 * multicast table, and VLAN filter table. Calls routines to setup link
549 * configuration and flow control settings. Clears all on-chip counters. Leaves
550 * the transmit and receive units disabled and uninitialized.
551 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -0700552s32 e1000_init_hw(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553{
Joe Perches406874a2008-04-03 10:06:32 -0700554 u32 ctrl;
555 u32 i;
556 s32 ret_val;
557 u32 mta_size;
Joe Perches406874a2008-04-03 10:06:32 -0700558 u32 ctrl_ext;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700559
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 DEBUGFUNC("e1000_init_hw");
561
562 /* Initialize Identification LED */
563 ret_val = e1000_id_led_init(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -0700564 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 DEBUGOUT("Error Initializing Identification LED\n");
566 return ret_val;
567 }
568
569 /* Set the media type and TBI compatibility */
570 e1000_set_media_type(hw);
571
572 /* Disabling VLAN filtering. */
573 DEBUGOUT("Initializing the IEEE VLAN\n");
Jesse Brandeburg1532ece2009-09-25 12:16:14 +0000574 if (hw->mac_type < e1000_82545_rev_3)
575 ew32(VET, 0);
576 e1000_clear_vfta(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577
578 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
Auke Kok8fc897b2006-08-28 14:56:16 -0700579 if (hw->mac_type == e1000_82542_rev2_0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
581 e1000_pci_clear_mwi(hw);
Joe Perches1dc32912008-07-11 15:17:08 -0700582 ew32(RCTL, E1000_RCTL_RST);
583 E1000_WRITE_FLUSH();
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400584 msleep(5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 }
586
587 /* Setup the receive address. This involves initializing all of the Receive
588 * Address Registers (RARs 0 - 15).
589 */
590 e1000_init_rx_addrs(hw);
591
592 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
Auke Kok8fc897b2006-08-28 14:56:16 -0700593 if (hw->mac_type == e1000_82542_rev2_0) {
Joe Perches1dc32912008-07-11 15:17:08 -0700594 ew32(RCTL, 0);
595 E1000_WRITE_FLUSH();
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400596 msleep(1);
597 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 e1000_pci_set_mwi(hw);
599 }
600
601 /* Zero out the Multicast HASH table */
602 DEBUGOUT("Zeroing the MTA\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700603 mta_size = E1000_MC_TBL_SIZE;
Auke Kok8fc897b2006-08-28 14:56:16 -0700604 for (i = 0; i < mta_size; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -0700606 /* use write flush to prevent Memory Write Block (MWB) from
607 * occuring when accessing our register space */
Joe Perches1dc32912008-07-11 15:17:08 -0700608 E1000_WRITE_FLUSH();
Auke Kok4ca213a2006-06-27 09:07:08 -0700609 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610
611 /* Set the PCI priority bit correctly in the CTRL register. This
612 * determines if the adapter gives priority to receives, or if it
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700613 * gives equal priority to transmits and receives. Valid only on
614 * 82542 and 82543 silicon.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 */
Auke Kok8fc897b2006-08-28 14:56:16 -0700616 if (hw->dma_fairness && hw->mac_type <= e1000_82543) {
Joe Perches1dc32912008-07-11 15:17:08 -0700617 ctrl = er32(CTRL);
618 ew32(CTRL, ctrl | E1000_CTRL_PRIOR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 }
620
Auke Kok8fc897b2006-08-28 14:56:16 -0700621 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 case e1000_82545_rev_3:
623 case e1000_82546_rev_3:
624 break;
625 default:
626 /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
Peter Oruba007755e2007-09-28 22:42:06 -0700627 if (hw->bus_type == e1000_bus_type_pcix && e1000_pcix_get_mmrbc(hw) > 2048)
628 e1000_pcix_set_mmrbc(hw, 2048);
629 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 }
631
632 /* Call a subroutine to configure the link and setup flow control. */
633 ret_val = e1000_setup_link(hw);
634
635 /* Set the transmit descriptor write-back policy */
Auke Kok8fc897b2006-08-28 14:56:16 -0700636 if (hw->mac_type > e1000_82544) {
Joe Perches1dc32912008-07-11 15:17:08 -0700637 ctrl = er32(TXDCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
Joe Perches1dc32912008-07-11 15:17:08 -0700639 ew32(TXDCTL, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 }
641
642 /* Clear all of the statistics registers (clear on read). It is
643 * important that we do this after we have tried to establish link
644 * because the symbol error count will increment wildly if there
645 * is no link.
646 */
647 e1000_clear_hw_cntrs(hw);
648
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -0800649 if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER ||
650 hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) {
Joe Perches1dc32912008-07-11 15:17:08 -0700651 ctrl_ext = er32(CTRL_EXT);
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -0800652 /* Relaxed ordering must be disabled to avoid a parity
653 * error crash in a PCI slot. */
654 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
Joe Perches1dc32912008-07-11 15:17:08 -0700655 ew32(CTRL_EXT, ctrl_ext);
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -0800656 }
657
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 return ret_val;
659}
660
661/******************************************************************************
662 * Adjust SERDES output amplitude based on EEPROM setting.
663 *
664 * hw - Struct containing variables accessed by shared code.
665 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -0700666static s32 e1000_adjust_serdes_amplitude(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667{
Joe Perches406874a2008-04-03 10:06:32 -0700668 u16 eeprom_data;
669 s32 ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670
671 DEBUGFUNC("e1000_adjust_serdes_amplitude");
672
Auke Kok8fc897b2006-08-28 14:56:16 -0700673 if (hw->media_type != e1000_media_type_internal_serdes)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 return E1000_SUCCESS;
675
Auke Kok8fc897b2006-08-28 14:56:16 -0700676 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 case e1000_82545_rev_3:
678 case e1000_82546_rev_3:
679 break;
680 default:
681 return E1000_SUCCESS;
682 }
683
684 ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1, &eeprom_data);
685 if (ret_val) {
686 return ret_val;
687 }
688
Auke Kok8fc897b2006-08-28 14:56:16 -0700689 if (eeprom_data != EEPROM_RESERVED_WORD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 /* Adjust SERDES output amplitude only. */
Auke Kok76c224b2006-05-23 13:36:06 -0700691 eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data);
Auke Kok8fc897b2006-08-28 14:56:16 -0700693 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 return ret_val;
695 }
696
697 return E1000_SUCCESS;
698}
699
700/******************************************************************************
701 * Configures flow control and link settings.
702 *
703 * hw - Struct containing variables accessed by shared code
704 *
705 * Determines which flow control settings to use. Calls the apropriate media-
706 * specific link configuration function. Configures the flow control settings.
707 * Assuming the adapter has a valid link partner, a valid link should be
708 * established. Assumes the hardware has previously been reset and the
709 * transmitter and receiver are not enabled.
710 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -0700711s32 e1000_setup_link(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712{
Joe Perches406874a2008-04-03 10:06:32 -0700713 u32 ctrl_ext;
714 s32 ret_val;
715 u16 eeprom_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716
717 DEBUGFUNC("e1000_setup_link");
718
719 /* Read and store word 0x0F of the EEPROM. This word contains bits
720 * that determine the hardware's default PAUSE (flow control) mode,
721 * a bit that determines whether the HW defaults to enabling or
722 * disabling auto-negotiation, and the direction of the
723 * SW defined pins. If there is no SW over-ride of the flow
724 * control setting, then the variable hw->fc will
725 * be initialized based on a value in the EEPROM.
726 */
Jeff Kirsher11241b12006-09-27 12:53:28 -0700727 if (hw->fc == E1000_FC_DEFAULT) {
Jesse Brandeburg1532ece2009-09-25 12:16:14 +0000728 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
729 1, &eeprom_data);
730 if (ret_val) {
731 DEBUGOUT("EEPROM Read Error\n");
732 return -E1000_ERR_EEPROM;
Jeff Kirsherfd803242005-12-13 00:06:22 -0500733 }
Jesse Brandeburg1532ece2009-09-25 12:16:14 +0000734 if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
735 hw->fc = E1000_FC_NONE;
736 else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
737 EEPROM_WORD0F_ASM_DIR)
738 hw->fc = E1000_FC_TX_PAUSE;
739 else
740 hw->fc = E1000_FC_FULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 }
742
743 /* We want to save off the original Flow Control configuration just
744 * in case we get disconnected and then reconnected into a different
745 * hub or switch with different Flow Control capabilities.
746 */
Auke Kok8fc897b2006-08-28 14:56:16 -0700747 if (hw->mac_type == e1000_82542_rev2_0)
Jeff Kirsher11241b12006-09-27 12:53:28 -0700748 hw->fc &= (~E1000_FC_TX_PAUSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749
Auke Kok8fc897b2006-08-28 14:56:16 -0700750 if ((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
Jeff Kirsher11241b12006-09-27 12:53:28 -0700751 hw->fc &= (~E1000_FC_RX_PAUSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752
753 hw->original_fc = hw->fc;
754
755 DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc);
756
757 /* Take the 4 bits from EEPROM word 0x0F that determine the initial
758 * polarity value for the SW controlled pins, and setup the
759 * Extended Device Control reg with that info.
760 * This is needed because one of the SW controlled pins is used for
761 * signal detection. So this should be done before e1000_setup_pcs_link()
762 * or e1000_phy_setup() is called.
763 */
Jeff Kirsher497fce52006-03-02 18:18:20 -0800764 if (hw->mac_type == e1000_82543) {
Auke Kok8fc897b2006-08-28 14:56:16 -0700765 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
766 1, &eeprom_data);
767 if (ret_val) {
768 DEBUGOUT("EEPROM Read Error\n");
769 return -E1000_ERR_EEPROM;
770 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
772 SWDPIO__EXT_SHIFT);
Joe Perches1dc32912008-07-11 15:17:08 -0700773 ew32(CTRL_EXT, ctrl_ext);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 }
775
776 /* Call the necessary subroutine to configure the link. */
777 ret_val = (hw->media_type == e1000_media_type_copper) ?
778 e1000_setup_copper_link(hw) :
779 e1000_setup_fiber_serdes_link(hw);
780
781 /* Initialize the flow control address, type, and PAUSE timer
782 * registers to their default values. This is done even if flow
783 * control is disabled, because it does not hurt anything to
784 * initialize these registers.
785 */
786 DEBUGOUT("Initializing the Flow Control address, type and timer regs\n");
787
Jesse Brandeburg1532ece2009-09-25 12:16:14 +0000788 ew32(FCT, FLOW_CONTROL_TYPE);
789 ew32(FCAH, FLOW_CONTROL_ADDRESS_HIGH);
790 ew32(FCAL, FLOW_CONTROL_ADDRESS_LOW);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700791
Joe Perches1dc32912008-07-11 15:17:08 -0700792 ew32(FCTTV, hw->fc_pause_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793
794 /* Set the flow control receive threshold registers. Normally,
795 * these registers will be set to a default threshold that may be
796 * adjusted later by the driver's runtime code. However, if the
797 * ability to transmit pause frames in not enabled, then these
798 * registers will be set to 0.
799 */
Jeff Kirsher11241b12006-09-27 12:53:28 -0700800 if (!(hw->fc & E1000_FC_TX_PAUSE)) {
Joe Perches1dc32912008-07-11 15:17:08 -0700801 ew32(FCRTL, 0);
802 ew32(FCRTH, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 } else {
804 /* We need to set up the Receive Threshold high and low water marks
805 * as well as (optionally) enabling the transmission of XON frames.
806 */
Auke Kok8fc897b2006-08-28 14:56:16 -0700807 if (hw->fc_send_xon) {
Joe Perches1dc32912008-07-11 15:17:08 -0700808 ew32(FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE));
809 ew32(FCRTH, hw->fc_high_water);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 } else {
Joe Perches1dc32912008-07-11 15:17:08 -0700811 ew32(FCRTL, hw->fc_low_water);
812 ew32(FCRTH, hw->fc_high_water);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 }
814 }
815 return ret_val;
816}
817
818/******************************************************************************
819 * Sets up link for a fiber based or serdes based adapter
820 *
821 * hw - Struct containing variables accessed by shared code
822 *
823 * Manipulates Physical Coding Sublayer functions in order to configure
824 * link. Assumes the hardware has been previously reset and the transmitter
825 * and receiver are not enabled.
826 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -0700827static s32 e1000_setup_fiber_serdes_link(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828{
Joe Perches406874a2008-04-03 10:06:32 -0700829 u32 ctrl;
830 u32 status;
831 u32 txcw = 0;
832 u32 i;
833 u32 signal = 0;
834 s32 ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835
836 DEBUGFUNC("e1000_setup_fiber_serdes_link");
837
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700838 /* On adapters with a MAC newer than 82544, SWDP 1 will be
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 * set when the optics detect a signal. On older adapters, it will be
840 * cleared when there is a signal. This applies to fiber media only.
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700841 * If we're on serdes media, adjust the output amplitude to value
842 * set in the EEPROM.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 */
Joe Perches1dc32912008-07-11 15:17:08 -0700844 ctrl = er32(CTRL);
Auke Kok8fc897b2006-08-28 14:56:16 -0700845 if (hw->media_type == e1000_media_type_fiber)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
847
848 ret_val = e1000_adjust_serdes_amplitude(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -0700849 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850 return ret_val;
851
852 /* Take the link out of reset */
853 ctrl &= ~(E1000_CTRL_LRST);
854
855 /* Adjust VCO speed to improve BER performance */
856 ret_val = e1000_set_vco_speed(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -0700857 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 return ret_val;
859
860 e1000_config_collision_dist(hw);
861
862 /* Check for a software override of the flow control settings, and setup
863 * the device accordingly. If auto-negotiation is enabled, then software
864 * will have to set the "PAUSE" bits to the correct value in the Tranmsit
865 * Config Word Register (TXCW) and re-start auto-negotiation. However, if
866 * auto-negotiation is disabled, then software will have to manually
867 * configure the two flow control enable bits in the CTRL register.
868 *
869 * The possible values of the "fc" parameter are:
870 * 0: Flow control is completely disabled
871 * 1: Rx flow control is enabled (we can receive pause frames, but
872 * not send pause frames).
873 * 2: Tx flow control is enabled (we can send pause frames but we do
874 * not support receiving pause frames).
875 * 3: Both Rx and TX flow control (symmetric) are enabled.
876 */
877 switch (hw->fc) {
Jeff Kirsher11241b12006-09-27 12:53:28 -0700878 case E1000_FC_NONE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 /* Flow control is completely disabled by a software over-ride. */
880 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
881 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -0700882 case E1000_FC_RX_PAUSE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 /* RX Flow control is enabled and TX Flow control is disabled by a
884 * software over-ride. Since there really isn't a way to advertise
885 * that we are capable of RX Pause ONLY, we will advertise that we
886 * support both symmetric and asymmetric RX PAUSE. Later, we will
887 * disable the adapter's ability to send PAUSE frames.
888 */
889 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
890 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -0700891 case E1000_FC_TX_PAUSE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 /* TX Flow control is enabled, and RX Flow control is disabled, by a
893 * software over-ride.
894 */
895 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
896 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -0700897 case E1000_FC_FULL:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 /* Flow control (both RX and TX) is enabled by a software over-ride. */
899 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
900 break;
901 default:
902 DEBUGOUT("Flow control param set incorrectly\n");
903 return -E1000_ERR_CONFIG;
904 break;
905 }
906
907 /* Since auto-negotiation is enabled, take the link out of reset (the link
908 * will be in reset, because we previously reset the chip). This will
909 * restart auto-negotiation. If auto-neogtiation is successful then the
910 * link-up status bit will be set and the flow control enable bits (RFCE
911 * and TFCE) will be set according to their negotiated value.
912 */
913 DEBUGOUT("Auto-negotiation enabled\n");
914
Joe Perches1dc32912008-07-11 15:17:08 -0700915 ew32(TXCW, txcw);
916 ew32(CTRL, ctrl);
917 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918
919 hw->txcw = txcw;
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400920 msleep(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921
922 /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
923 * indication in the Device Status Register. Time-out if a link isn't
924 * seen in 500 milliseconds seconds (Auto-negotiation should complete in
925 * less than 500 milliseconds even if the other end is doing it in SW).
926 * For internal serdes, we just assume a signal is present, then poll.
927 */
Auke Kok8fc897b2006-08-28 14:56:16 -0700928 if (hw->media_type == e1000_media_type_internal_serdes ||
Joe Perches1dc32912008-07-11 15:17:08 -0700929 (er32(CTRL) & E1000_CTRL_SWDPIN1) == signal) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 DEBUGOUT("Looking for Link\n");
Auke Kok8fc897b2006-08-28 14:56:16 -0700931 for (i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400932 msleep(10);
Joe Perches1dc32912008-07-11 15:17:08 -0700933 status = er32(STATUS);
Auke Kok8fc897b2006-08-28 14:56:16 -0700934 if (status & E1000_STATUS_LU) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 }
Auke Kok8fc897b2006-08-28 14:56:16 -0700936 if (i == (LINK_UP_TIMEOUT / 10)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 DEBUGOUT("Never got a valid link from auto-neg!!!\n");
938 hw->autoneg_failed = 1;
939 /* AutoNeg failed to achieve a link, so we'll call
940 * e1000_check_for_link. This routine will force the link up if
941 * we detect a signal. This will allow us to communicate with
942 * non-autonegotiating link partners.
943 */
944 ret_val = e1000_check_for_link(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -0700945 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946 DEBUGOUT("Error while checking for link\n");
947 return ret_val;
948 }
949 hw->autoneg_failed = 0;
950 } else {
951 hw->autoneg_failed = 0;
952 DEBUGOUT("Valid Link Found\n");
953 }
954 } else {
955 DEBUGOUT("No Signal Detected\n");
956 }
957 return E1000_SUCCESS;
958}
959
960/******************************************************************************
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700961* Make sure we have a valid PHY and change PHY mode before link setup.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962*
963* hw - Struct containing variables accessed by shared code
964******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -0700965static s32 e1000_copper_link_preconfig(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966{
Joe Perches406874a2008-04-03 10:06:32 -0700967 u32 ctrl;
968 s32 ret_val;
969 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700971 DEBUGFUNC("e1000_copper_link_preconfig");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972
Joe Perches1dc32912008-07-11 15:17:08 -0700973 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974 /* With 82543, we need to force speed and duplex on the MAC equal to what
975 * the PHY speed and duplex configuration is. In addition, we need to
976 * perform a hardware reset on the PHY to take it out of reset.
977 */
Auke Kok8fc897b2006-08-28 14:56:16 -0700978 if (hw->mac_type > e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 ctrl |= E1000_CTRL_SLU;
980 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
Joe Perches1dc32912008-07-11 15:17:08 -0700981 ew32(CTRL, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 } else {
983 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
Joe Perches1dc32912008-07-11 15:17:08 -0700984 ew32(CTRL, ctrl);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700985 ret_val = e1000_phy_hw_reset(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -0700986 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700987 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 }
989
990 /* Make sure we have a valid PHY */
991 ret_val = e1000_detect_gig_phy(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -0700992 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 DEBUGOUT("Error, did not detect valid phy.\n");
994 return ret_val;
995 }
996 DEBUGOUT1("Phy ID = %x \n", hw->phy_id);
997
998 /* Set PHY to class A mode (if necessary) */
999 ret_val = e1000_set_phy_mode(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001000 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 return ret_val;
1002
Auke Kok8fc897b2006-08-28 14:56:16 -07001003 if ((hw->mac_type == e1000_82545_rev_3) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 (hw->mac_type == e1000_82546_rev_3)) {
1005 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1006 phy_data |= 0x00000008;
1007 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1008 }
1009
Auke Kok8fc897b2006-08-28 14:56:16 -07001010 if (hw->mac_type <= e1000_82543 ||
1011 hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
1012 hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2)
Joe Perchesc3033b02008-03-21 11:06:25 -07001013 hw->phy_reset_disable = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001015 return E1000_SUCCESS;
1016}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001019/********************************************************************
1020* Copper link setup for e1000_phy_igp series.
1021*
1022* hw - Struct containing variables accessed by shared code
1023*********************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07001024static s32 e1000_copper_link_igp_setup(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001025{
Joe Perches406874a2008-04-03 10:06:32 -07001026 u32 led_ctrl;
1027 s32 ret_val;
1028 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001030 DEBUGFUNC("e1000_copper_link_igp_setup");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001032 if (hw->phy_reset_disable)
1033 return E1000_SUCCESS;
Auke Kok76c224b2006-05-23 13:36:06 -07001034
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001035 ret_val = e1000_phy_reset(hw);
1036 if (ret_val) {
1037 DEBUGOUT("Error Resetting the PHY\n");
1038 return ret_val;
1039 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040
Auke Kok8fc897b2006-08-28 14:56:16 -07001041 /* Wait 15ms for MAC to configure PHY from eeprom settings */
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001042 msleep(15);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001043 /* Configure activity LED after PHY reset */
Joe Perches1dc32912008-07-11 15:17:08 -07001044 led_ctrl = er32(LEDCTL);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001045 led_ctrl &= IGP_ACTIVITY_LED_MASK;
1046 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
Joe Perches1dc32912008-07-11 15:17:08 -07001047 ew32(LEDCTL, led_ctrl);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001048
Jeff Kirsherc9c1b832006-08-16 13:38:54 -07001049 /* The NVM settings will configure LPLU in D3 for IGP2 and IGP3 PHYs */
1050 if (hw->phy_type == e1000_phy_igp) {
1051 /* disable lplu d3 during driver init */
Joe Perchesc3033b02008-03-21 11:06:25 -07001052 ret_val = e1000_set_d3_lplu_state(hw, false);
Jeff Kirsherc9c1b832006-08-16 13:38:54 -07001053 if (ret_val) {
1054 DEBUGOUT("Error Disabling LPLU D3\n");
1055 return ret_val;
1056 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001057 }
1058
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001059 /* Configure mdi-mdix settings */
1060 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1061 if (ret_val)
1062 return ret_val;
1063
1064 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
1065 hw->dsp_config_state = e1000_dsp_config_disabled;
1066 /* Force MDI for earlier revs of the IGP PHY */
1067 phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX | IGP01E1000_PSCR_FORCE_MDI_MDIX);
1068 hw->mdix = 1;
1069
1070 } else {
1071 hw->dsp_config_state = e1000_dsp_config_enabled;
1072 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1073
1074 switch (hw->mdix) {
1075 case 1:
1076 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1077 break;
1078 case 2:
1079 phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
1080 break;
1081 case 0:
1082 default:
1083 phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
1084 break;
1085 }
1086 }
1087 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001088 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001089 return ret_val;
1090
1091 /* set auto-master slave resolution settings */
Auke Kok8fc897b2006-08-28 14:56:16 -07001092 if (hw->autoneg) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001093 e1000_ms_type phy_ms_setting = hw->master_slave;
1094
Auke Kok8fc897b2006-08-28 14:56:16 -07001095 if (hw->ffe_config_state == e1000_ffe_config_active)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001096 hw->ffe_config_state = e1000_ffe_config_enabled;
1097
Auke Kok8fc897b2006-08-28 14:56:16 -07001098 if (hw->dsp_config_state == e1000_dsp_config_activated)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001099 hw->dsp_config_state = e1000_dsp_config_enabled;
1100
1101 /* when autonegotiation advertisment is only 1000Mbps then we
1102 * should disable SmartSpeed and enable Auto MasterSlave
1103 * resolution as hardware default. */
Auke Kok8fc897b2006-08-28 14:56:16 -07001104 if (hw->autoneg_advertised == ADVERTISE_1000_FULL) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001105 /* Disable SmartSpeed */
Auke Kok8fc897b2006-08-28 14:56:16 -07001106 ret_val = e1000_read_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 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Auke Kok8fc897b2006-08-28 14:56:16 -07001111 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1112 phy_data);
1113 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001115 /* Set auto Master/Slave resolution process */
1116 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001117 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001118 return ret_val;
1119 phy_data &= ~CR_1000T_MS_ENABLE;
1120 ret_val = e1000_write_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;
1123 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001125 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001126 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001127 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001129 /* load defaults for future use */
1130 hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
1131 ((phy_data & CR_1000T_MS_VALUE) ?
1132 e1000_ms_force_master :
1133 e1000_ms_force_slave) :
1134 e1000_ms_auto;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001136 switch (phy_ms_setting) {
1137 case e1000_ms_force_master:
1138 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
1139 break;
1140 case e1000_ms_force_slave:
1141 phy_data |= CR_1000T_MS_ENABLE;
1142 phy_data &= ~(CR_1000T_MS_VALUE);
1143 break;
1144 case e1000_ms_auto:
1145 phy_data &= ~CR_1000T_MS_ENABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146 default:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001147 break;
1148 }
1149 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001150 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001151 return ret_val;
Malli Chilakala2b028932005-06-17 17:46:06 -07001152 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153
Malli Chilakala2b028932005-06-17 17:46:06 -07001154 return E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001155}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001157/********************************************************************
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001158* Copper link setup for e1000_phy_m88 series.
1159*
1160* hw - Struct containing variables accessed by shared code
1161*********************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07001162static s32 e1000_copper_link_mgp_setup(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001163{
Joe Perches406874a2008-04-03 10:06:32 -07001164 s32 ret_val;
1165 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001167 DEBUGFUNC("e1000_copper_link_mgp_setup");
1168
Auke Kok8fc897b2006-08-28 14:56:16 -07001169 if (hw->phy_reset_disable)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001170 return E1000_SUCCESS;
Auke Kok76c224b2006-05-23 13:36:06 -07001171
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001172 /* Enable CRS on TX. This must be set for half-duplex operation. */
1173 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001174 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001175 return ret_val;
1176
1177 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1178
1179 /* Options:
1180 * MDI/MDI-X = 0 (default)
1181 * 0 - Auto for all speeds
1182 * 1 - MDI mode
1183 * 2 - MDI-X mode
1184 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1185 */
1186 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1187
1188 switch (hw->mdix) {
1189 case 1:
1190 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
1191 break;
1192 case 2:
1193 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
1194 break;
1195 case 3:
1196 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
1197 break;
1198 case 0:
1199 default:
1200 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
1201 break;
1202 }
1203
1204 /* Options:
1205 * disable_polarity_correction = 0 (default)
1206 * Automatic Correction for Reversed Cable Polarity
1207 * 0 - Disabled
1208 * 1 - Enabled
1209 */
1210 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
Auke Kok8fc897b2006-08-28 14:56:16 -07001211 if (hw->disable_polarity_correction == 1)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001212 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
Auke Kokee040222006-06-27 09:08:03 -07001213 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1214 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001215 return ret_val;
1216
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001217 if (hw->phy_revision < M88E1011_I_REV_4) {
Auke Kokee040222006-06-27 09:08:03 -07001218 /* Force TX_CLK in the Extended PHY Specific Control Register
1219 * to 25MHz clock.
1220 */
1221 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1222 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001223 return ret_val;
Auke Kokee040222006-06-27 09:08:03 -07001224
1225 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1226
1227 if ((hw->phy_revision == E1000_REVISION_2) &&
1228 (hw->phy_id == M88E1111_I_PHY_ID)) {
1229 /* Vidalia Phy, set the downshift counter to 5x */
1230 phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK);
1231 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
1232 ret_val = e1000_write_phy_reg(hw,
1233 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1234 if (ret_val)
1235 return ret_val;
1236 } else {
1237 /* Configure Master and Slave downshift values */
1238 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
1239 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
1240 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
1241 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
1242 ret_val = e1000_write_phy_reg(hw,
1243 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1244 if (ret_val)
1245 return ret_val;
1246 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001247 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001249 /* SW Reset the PHY so all changes take effect */
1250 ret_val = e1000_phy_reset(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001251 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001252 DEBUGOUT("Error Resetting the PHY\n");
1253 return ret_val;
1254 }
1255
1256 return E1000_SUCCESS;
1257}
1258
1259/********************************************************************
1260* Setup auto-negotiation and flow control advertisements,
1261* and then perform auto-negotiation.
1262*
1263* hw - Struct containing variables accessed by shared code
1264*********************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07001265static s32 e1000_copper_link_autoneg(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001266{
Joe Perches406874a2008-04-03 10:06:32 -07001267 s32 ret_val;
1268 u16 phy_data;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001269
1270 DEBUGFUNC("e1000_copper_link_autoneg");
1271
1272 /* Perform some bounds checking on the hw->autoneg_advertised
1273 * parameter. If this variable is zero, then set it to the default.
1274 */
1275 hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
1276
1277 /* If autoneg_advertised is zero, we assume it was not defaulted
1278 * by the calling code so we set to advertise full capability.
1279 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001280 if (hw->autoneg_advertised == 0)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001281 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
1282
1283 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
1284 ret_val = e1000_phy_setup_autoneg(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001285 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001286 DEBUGOUT("Error Setting up Auto-Negotiation\n");
1287 return ret_val;
1288 }
1289 DEBUGOUT("Restarting Auto-Neg\n");
1290
1291 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
1292 * the Auto Neg Restart bit in the PHY control register.
1293 */
1294 ret_val = e1000_read_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 phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
1299 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001300 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001301 return ret_val;
1302
1303 /* Does the user want to wait for Auto-Neg to complete here, or
1304 * check at a later time (for example, callback routine).
1305 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001306 if (hw->wait_autoneg_complete) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001307 ret_val = e1000_wait_autoneg(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001308 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001309 DEBUGOUT("Error while waiting for autoneg to complete\n");
1310 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001312 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313
Joe Perchesc3033b02008-03-21 11:06:25 -07001314 hw->get_link_status = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001316 return E1000_SUCCESS;
1317}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001319/******************************************************************************
1320* Config the MAC and the PHY after link is up.
1321* 1) Set up the MAC to the current PHY speed/duplex
1322* if we are on 82543. If we
1323* are on newer silicon, we only need to configure
1324* collision distance in the Transmit Control Register.
1325* 2) Set up flow control on the MAC to that established with
1326* the link partner.
Auke Kok76c224b2006-05-23 13:36:06 -07001327* 3) Config DSP to improve Gigabit link quality for some PHY revisions.
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001328*
1329* hw - Struct containing variables accessed by shared code
1330******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07001331static s32 e1000_copper_link_postconfig(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001332{
Joe Perches406874a2008-04-03 10:06:32 -07001333 s32 ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001334 DEBUGFUNC("e1000_copper_link_postconfig");
Auke Kok76c224b2006-05-23 13:36:06 -07001335
Auke Kok8fc897b2006-08-28 14:56:16 -07001336 if (hw->mac_type >= e1000_82544) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001337 e1000_config_collision_dist(hw);
1338 } else {
1339 ret_val = e1000_config_mac_to_phy(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001340 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001341 DEBUGOUT("Error configuring MAC to PHY settings\n");
1342 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001344 }
1345 ret_val = e1000_config_fc_after_link_up(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001346 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001347 DEBUGOUT("Error Configuring Flow Control\n");
1348 return ret_val;
1349 }
1350
1351 /* Config DSP to improve Giga link quality */
Auke Kok8fc897b2006-08-28 14:56:16 -07001352 if (hw->phy_type == e1000_phy_igp) {
Joe Perchesc3033b02008-03-21 11:06:25 -07001353 ret_val = e1000_config_dsp_after_link_change(hw, true);
Auke Kok8fc897b2006-08-28 14:56:16 -07001354 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001355 DEBUGOUT("Error Configuring DSP after link up\n");
1356 return ret_val;
1357 }
1358 }
Auke Kok76c224b2006-05-23 13:36:06 -07001359
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001360 return E1000_SUCCESS;
1361}
1362
1363/******************************************************************************
1364* Detects which PHY is present and setup the speed and duplex
1365*
1366* hw - Struct containing variables accessed by shared code
1367******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07001368static s32 e1000_setup_copper_link(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001369{
Joe Perches406874a2008-04-03 10:06:32 -07001370 s32 ret_val;
1371 u16 i;
1372 u16 phy_data;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001373
1374 DEBUGFUNC("e1000_setup_copper_link");
1375
1376 /* Check if it is a valid PHY and set PHY mode if necessary. */
1377 ret_val = e1000_copper_link_preconfig(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001378 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001379 return ret_val;
1380
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00001381 if (hw->phy_type == e1000_phy_igp) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001382 ret_val = e1000_copper_link_igp_setup(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001383 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001384 return ret_val;
1385 } else if (hw->phy_type == e1000_phy_m88) {
1386 ret_val = e1000_copper_link_mgp_setup(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001387 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001388 return ret_val;
1389 }
1390
Auke Kok8fc897b2006-08-28 14:56:16 -07001391 if (hw->autoneg) {
Auke Kok76c224b2006-05-23 13:36:06 -07001392 /* Setup autoneg and flow control advertisement
1393 * and perform autonegotiation */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001394 ret_val = e1000_copper_link_autoneg(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001395 if (ret_val)
Auke Kok76c224b2006-05-23 13:36:06 -07001396 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001397 } else {
1398 /* PHY will be set to 10H, 10F, 100H,or 100F
1399 * depending on value from forced_speed_duplex. */
1400 DEBUGOUT("Forcing speed and duplex\n");
1401 ret_val = e1000_phy_force_speed_duplex(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001402 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001403 DEBUGOUT("Error Forcing Speed and Duplex\n");
1404 return ret_val;
1405 }
1406 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407
1408 /* Check link status. Wait up to 100 microseconds for link to become
1409 * valid.
1410 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001411 for (i = 0; i < 10; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001413 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 return ret_val;
1415 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001416 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 return ret_val;
1418
Auke Kok8fc897b2006-08-28 14:56:16 -07001419 if (phy_data & MII_SR_LINK_STATUS) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001420 /* Config the MAC and PHY after link is up */
1421 ret_val = e1000_copper_link_postconfig(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001422 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 return ret_val;
Auke Kok76c224b2006-05-23 13:36:06 -07001424
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425 DEBUGOUT("Valid link established!!!\n");
1426 return E1000_SUCCESS;
1427 }
1428 udelay(10);
1429 }
1430
1431 DEBUGOUT("Unable to establish link!!!\n");
1432 return E1000_SUCCESS;
1433}
1434
1435/******************************************************************************
1436* Configures PHY autoneg and flow control advertisement settings
1437*
1438* hw - Struct containing variables accessed by shared code
1439******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07001440s32 e1000_phy_setup_autoneg(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441{
Joe Perches406874a2008-04-03 10:06:32 -07001442 s32 ret_val;
1443 u16 mii_autoneg_adv_reg;
1444 u16 mii_1000t_ctrl_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445
1446 DEBUGFUNC("e1000_phy_setup_autoneg");
1447
1448 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
1449 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07001450 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451 return ret_val;
1452
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00001453 /* Read the MII 1000Base-T Control Register (Address 9). */
1454 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
1455 if (ret_val)
1456 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457
1458 /* Need to parse both autoneg_advertised and fc and set up
1459 * the appropriate PHY registers. First we will parse for
1460 * autoneg_advertised software override. Since we can advertise
1461 * a plethora of combinations, we need to check each bit
1462 * individually.
1463 */
1464
1465 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
1466 * Advertisement Register (Address 4) and the 1000 mb speed bits in
1467 * the 1000Base-T Control Register (Address 9).
1468 */
1469 mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
1470 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
1471
1472 DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised);
1473
1474 /* Do we want to advertise 10 Mb Half Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07001475 if (hw->autoneg_advertised & ADVERTISE_10_HALF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476 DEBUGOUT("Advertise 10mb Half duplex\n");
1477 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
1478 }
1479
1480 /* Do we want to advertise 10 Mb Full Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07001481 if (hw->autoneg_advertised & ADVERTISE_10_FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 DEBUGOUT("Advertise 10mb Full duplex\n");
1483 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
1484 }
1485
1486 /* Do we want to advertise 100 Mb Half Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07001487 if (hw->autoneg_advertised & ADVERTISE_100_HALF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488 DEBUGOUT("Advertise 100mb Half duplex\n");
1489 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
1490 }
1491
1492 /* Do we want to advertise 100 Mb Full Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07001493 if (hw->autoneg_advertised & ADVERTISE_100_FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 DEBUGOUT("Advertise 100mb Full duplex\n");
1495 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
1496 }
1497
1498 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
Auke Kok8fc897b2006-08-28 14:56:16 -07001499 if (hw->autoneg_advertised & ADVERTISE_1000_HALF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500 DEBUGOUT("Advertise 1000mb Half duplex requested, request denied!\n");
1501 }
1502
1503 /* Do we want to advertise 1000 Mb Full Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07001504 if (hw->autoneg_advertised & ADVERTISE_1000_FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505 DEBUGOUT("Advertise 1000mb Full duplex\n");
1506 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
1507 }
1508
1509 /* Check for a software override of the flow control settings, and
1510 * setup the PHY advertisement registers accordingly. If
1511 * auto-negotiation is enabled, then software will have to set the
1512 * "PAUSE" bits to the correct value in the Auto-Negotiation
1513 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
1514 *
1515 * The possible values of the "fc" parameter are:
1516 * 0: Flow control is completely disabled
1517 * 1: Rx flow control is enabled (we can receive pause frames
1518 * but not send pause frames).
1519 * 2: Tx flow control is enabled (we can send pause frames
1520 * but we do not support receiving pause frames).
1521 * 3: Both Rx and TX flow control (symmetric) are enabled.
1522 * other: No software override. The flow control configuration
1523 * in the EEPROM is used.
1524 */
1525 switch (hw->fc) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07001526 case E1000_FC_NONE: /* 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527 /* Flow control (RX & TX) is completely disabled by a
1528 * software over-ride.
1529 */
1530 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1531 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07001532 case E1000_FC_RX_PAUSE: /* 1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533 /* RX Flow control is enabled, and TX Flow control is
1534 * disabled, by a software over-ride.
1535 */
1536 /* Since there really isn't a way to advertise that we are
1537 * capable of RX Pause ONLY, we will advertise that we
1538 * support both symmetric and asymmetric RX PAUSE. Later
1539 * (in e1000_config_fc_after_link_up) we will disable the
1540 *hw's ability to send PAUSE frames.
1541 */
1542 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1543 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07001544 case E1000_FC_TX_PAUSE: /* 2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545 /* TX Flow control is enabled, and RX Flow control is
1546 * disabled, by a software over-ride.
1547 */
1548 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
1549 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
1550 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07001551 case E1000_FC_FULL: /* 3 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552 /* Flow control (both RX and TX) is enabled by a software
1553 * over-ride.
1554 */
1555 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1556 break;
1557 default:
1558 DEBUGOUT("Flow control param set incorrectly\n");
1559 return -E1000_ERR_CONFIG;
1560 }
1561
1562 ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07001563 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564 return ret_val;
1565
1566 DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
1567
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00001568 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg);
1569 if (ret_val)
1570 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571
1572 return E1000_SUCCESS;
1573}
1574
1575/******************************************************************************
1576* Force PHY speed and duplex settings to hw->forced_speed_duplex
1577*
1578* hw - Struct containing variables accessed by shared code
1579******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07001580static s32 e1000_phy_force_speed_duplex(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581{
Joe Perches406874a2008-04-03 10:06:32 -07001582 u32 ctrl;
1583 s32 ret_val;
1584 u16 mii_ctrl_reg;
1585 u16 mii_status_reg;
1586 u16 phy_data;
1587 u16 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588
1589 DEBUGFUNC("e1000_phy_force_speed_duplex");
1590
1591 /* Turn off Flow control if we are forcing speed and duplex. */
Jeff Kirsher11241b12006-09-27 12:53:28 -07001592 hw->fc = E1000_FC_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593
1594 DEBUGOUT1("hw->fc = %d\n", hw->fc);
1595
1596 /* Read the Device Control Register. */
Joe Perches1dc32912008-07-11 15:17:08 -07001597 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598
1599 /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */
1600 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1601 ctrl &= ~(DEVICE_SPEED_MASK);
1602
1603 /* Clear the Auto Speed Detect Enable bit. */
1604 ctrl &= ~E1000_CTRL_ASDE;
1605
1606 /* Read the MII Control Register. */
1607 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07001608 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609 return ret_val;
1610
1611 /* We need to disable autoneg in order to force link and duplex. */
1612
1613 mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN;
1614
1615 /* Are we forcing Full or Half Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07001616 if (hw->forced_speed_duplex == e1000_100_full ||
1617 hw->forced_speed_duplex == e1000_10_full) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618 /* We want to force full duplex so we SET the full duplex bits in the
1619 * Device and MII Control Registers.
1620 */
1621 ctrl |= E1000_CTRL_FD;
1622 mii_ctrl_reg |= MII_CR_FULL_DUPLEX;
1623 DEBUGOUT("Full Duplex\n");
1624 } else {
1625 /* We want to force half duplex so we CLEAR the full duplex bits in
1626 * the Device and MII Control Registers.
1627 */
1628 ctrl &= ~E1000_CTRL_FD;
1629 mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX;
1630 DEBUGOUT("Half Duplex\n");
1631 }
1632
1633 /* Are we forcing 100Mbps??? */
Auke Kok8fc897b2006-08-28 14:56:16 -07001634 if (hw->forced_speed_duplex == e1000_100_full ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635 hw->forced_speed_duplex == e1000_100_half) {
1636 /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */
1637 ctrl |= E1000_CTRL_SPD_100;
1638 mii_ctrl_reg |= MII_CR_SPEED_100;
1639 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
1640 DEBUGOUT("Forcing 100mb ");
1641 } else {
1642 /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */
1643 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1644 mii_ctrl_reg |= MII_CR_SPEED_10;
1645 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
1646 DEBUGOUT("Forcing 10mb ");
1647 }
1648
1649 e1000_config_collision_dist(hw);
1650
1651 /* Write the configured values back to the Device Control Reg. */
Joe Perches1dc32912008-07-11 15:17:08 -07001652 ew32(CTRL, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00001654 if (hw->phy_type == e1000_phy_m88) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001656 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657 return ret_val;
1658
1659 /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
1660 * forced whenever speed are duplex are forced.
1661 */
1662 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1663 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001664 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665 return ret_val;
1666
1667 DEBUGOUT1("M88E1000 PSCR: %x \n", phy_data);
1668
1669 /* Need to reset the PHY or these changes will be ignored */
1670 mii_ctrl_reg |= MII_CR_RESET;
Auke Kok90fb5132006-11-01 08:47:30 -08001671
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672 } else {
1673 /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
1674 * forced whenever speed or duplex are forced.
1675 */
1676 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001677 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678 return ret_val;
1679
1680 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1681 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1682
1683 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001684 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685 return ret_val;
1686 }
1687
1688 /* Write back the modified PHY MII control register. */
1689 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07001690 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691 return ret_val;
1692
1693 udelay(1);
1694
1695 /* The wait_autoneg_complete flag may be a little misleading here.
1696 * Since we are forcing speed and duplex, Auto-Neg is not enabled.
1697 * But we do want to delay for a period while forcing only so we
1698 * don't generate false No Link messages. So we will wait here
1699 * only if the user has set wait_autoneg_complete to 1, which is
1700 * the default.
1701 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001702 if (hw->wait_autoneg_complete) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703 /* We will wait for autoneg to complete. */
1704 DEBUGOUT("Waiting for forced speed/duplex link.\n");
1705 mii_status_reg = 0;
1706
1707 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
Auke Kok8fc897b2006-08-28 14:56:16 -07001708 for (i = PHY_FORCE_TIME; i > 0; i--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709 /* Read the MII Status Register and wait for Auto-Neg Complete bit
1710 * to be set.
1711 */
1712 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07001713 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714 return ret_val;
1715
1716 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07001717 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718 return ret_val;
1719
Auke Kok8fc897b2006-08-28 14:56:16 -07001720 if (mii_status_reg & MII_SR_LINK_STATUS) break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001721 msleep(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722 }
Auke Kok8fc897b2006-08-28 14:56:16 -07001723 if ((i == 0) &&
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00001724 (hw->phy_type == e1000_phy_m88)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725 /* We didn't get link. Reset the DSP and wait again for link. */
1726 ret_val = e1000_phy_reset_dsp(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001727 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728 DEBUGOUT("Error Resetting PHY DSP\n");
1729 return ret_val;
1730 }
1731 }
1732 /* This loop will early-out if the link condition has been met. */
Auke Kok8fc897b2006-08-28 14:56:16 -07001733 for (i = PHY_FORCE_TIME; i > 0; i--) {
1734 if (mii_status_reg & MII_SR_LINK_STATUS) break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001735 msleep(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736 /* Read the MII Status Register and wait for Auto-Neg Complete bit
1737 * to be set.
1738 */
1739 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07001740 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741 return ret_val;
1742
1743 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07001744 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745 return ret_val;
1746 }
1747 }
1748
1749 if (hw->phy_type == e1000_phy_m88) {
1750 /* Because we reset the PHY above, we need to re-force TX_CLK in the
1751 * Extended PHY Specific Control Register to 25MHz clock. This value
1752 * defaults back to a 2.5MHz clock when the PHY is reset.
1753 */
1754 ret_val = e1000_read_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 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1759 ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001760 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761 return ret_val;
1762
1763 /* In addition, because of the s/w reset above, we need to enable CRS on
1764 * TX. This must be set for both full and half duplex operation.
1765 */
1766 ret_val = e1000_read_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
1770 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1771 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001772 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773 return ret_val;
1774
Auke Kok8fc897b2006-08-28 14:56:16 -07001775 if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
1776 (!hw->autoneg) && (hw->forced_speed_duplex == e1000_10_full ||
1777 hw->forced_speed_duplex == e1000_10_half)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778 ret_val = e1000_polarity_reversal_workaround(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001779 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780 return ret_val;
1781 }
1782 }
1783 return E1000_SUCCESS;
1784}
1785
1786/******************************************************************************
1787* Sets the collision distance in the Transmit Control register
1788*
1789* hw - Struct containing variables accessed by shared code
1790*
1791* Link should have been established previously. Reads the speed and duplex
1792* information from the Device Status register.
1793******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07001794void e1000_config_collision_dist(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795{
Joe Perches406874a2008-04-03 10:06:32 -07001796 u32 tctl, coll_dist;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797
1798 DEBUGFUNC("e1000_config_collision_dist");
1799
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001800 if (hw->mac_type < e1000_82543)
1801 coll_dist = E1000_COLLISION_DISTANCE_82542;
1802 else
1803 coll_dist = E1000_COLLISION_DISTANCE;
1804
Joe Perches1dc32912008-07-11 15:17:08 -07001805 tctl = er32(TCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806
1807 tctl &= ~E1000_TCTL_COLD;
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001808 tctl |= coll_dist << E1000_COLD_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809
Joe Perches1dc32912008-07-11 15:17:08 -07001810 ew32(TCTL, tctl);
1811 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812}
1813
1814/******************************************************************************
1815* Sets MAC speed and duplex settings to reflect the those in the PHY
1816*
1817* hw - Struct containing variables accessed by shared code
1818* mii_reg - data to write to the MII control register
1819*
1820* The contents of the PHY register containing the needed information need to
1821* be passed in.
1822******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07001823static s32 e1000_config_mac_to_phy(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824{
Joe Perches406874a2008-04-03 10:06:32 -07001825 u32 ctrl;
1826 s32 ret_val;
1827 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828
1829 DEBUGFUNC("e1000_config_mac_to_phy");
1830
Auke Kok76c224b2006-05-23 13:36:06 -07001831 /* 82544 or newer MAC, Auto Speed Detection takes care of
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001832 * MAC speed/duplex configuration.*/
1833 if (hw->mac_type >= e1000_82544)
1834 return E1000_SUCCESS;
1835
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836 /* Read the Device Control Register and set the bits to Force Speed
1837 * and Duplex.
1838 */
Joe Perches1dc32912008-07-11 15:17:08 -07001839 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1841 ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
1842
1843 /* Set up duplex in the Device Control and Transmit Control
1844 * registers depending on negotiated values.
1845 */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001846 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001847 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001848 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849
Auke Kok8fc897b2006-08-28 14:56:16 -07001850 if (phy_data & M88E1000_PSSR_DPLX)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001851 ctrl |= E1000_CTRL_FD;
Auke Kok76c224b2006-05-23 13:36:06 -07001852 else
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001853 ctrl &= ~E1000_CTRL_FD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001855 e1000_config_collision_dist(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001857 /* Set up speed in the Device Control register depending on
1858 * negotiated values.
1859 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001860 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001861 ctrl |= E1000_CTRL_SPD_1000;
Auke Kok8fc897b2006-08-28 14:56:16 -07001862 else if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001863 ctrl |= E1000_CTRL_SPD_100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865 /* Write the configured values back to the Device Control Reg. */
Joe Perches1dc32912008-07-11 15:17:08 -07001866 ew32(CTRL, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867 return E1000_SUCCESS;
1868}
1869
1870/******************************************************************************
1871 * Forces the MAC's flow control settings.
1872 *
1873 * hw - Struct containing variables accessed by shared code
1874 *
1875 * Sets the TFCE and RFCE bits in the device control register to reflect
1876 * the adapter settings. TFCE and RFCE need to be explicitly set by
1877 * software when a Copper PHY is used because autonegotiation is managed
1878 * by the PHY rather than the MAC. Software must also configure these
1879 * bits when link is forced on a fiber connection.
1880 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07001881s32 e1000_force_mac_fc(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882{
Joe Perches406874a2008-04-03 10:06:32 -07001883 u32 ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884
1885 DEBUGFUNC("e1000_force_mac_fc");
1886
1887 /* Get the current configuration of the Device Control Register */
Joe Perches1dc32912008-07-11 15:17:08 -07001888 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889
1890 /* Because we didn't get link via the internal auto-negotiation
1891 * mechanism (we either forced link or we got link via PHY
1892 * auto-neg), we have to manually enable/disable transmit an
1893 * receive flow control.
1894 *
1895 * The "Case" statement below enables/disable flow control
1896 * according to the "hw->fc" parameter.
1897 *
1898 * The possible values of the "fc" parameter are:
1899 * 0: Flow control is completely disabled
1900 * 1: Rx flow control is enabled (we can receive pause
1901 * frames but not send pause frames).
1902 * 2: Tx flow control is enabled (we can send pause frames
1903 * frames but we do not receive pause frames).
1904 * 3: Both Rx and TX flow control (symmetric) is enabled.
1905 * other: No other values should be possible at this point.
1906 */
1907
1908 switch (hw->fc) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07001909 case E1000_FC_NONE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
1911 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07001912 case E1000_FC_RX_PAUSE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913 ctrl &= (~E1000_CTRL_TFCE);
1914 ctrl |= E1000_CTRL_RFCE;
1915 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07001916 case E1000_FC_TX_PAUSE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917 ctrl &= (~E1000_CTRL_RFCE);
1918 ctrl |= E1000_CTRL_TFCE;
1919 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07001920 case E1000_FC_FULL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
1922 break;
1923 default:
1924 DEBUGOUT("Flow control param set incorrectly\n");
1925 return -E1000_ERR_CONFIG;
1926 }
1927
1928 /* Disable TX Flow Control for 82542 (rev 2.0) */
Auke Kok8fc897b2006-08-28 14:56:16 -07001929 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930 ctrl &= (~E1000_CTRL_TFCE);
1931
Joe Perches1dc32912008-07-11 15:17:08 -07001932 ew32(CTRL, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933 return E1000_SUCCESS;
1934}
1935
1936/******************************************************************************
1937 * Configures flow control settings after link is established
1938 *
1939 * hw - Struct containing variables accessed by shared code
1940 *
1941 * Should be called immediately after a valid link has been established.
1942 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
1943 * and autonegotiation is enabled, the MAC flow control settings will be set
1944 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
1945 * and RFCE bits will be automaticaly set to the negotiated flow control mode.
1946 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07001947static s32 e1000_config_fc_after_link_up(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948{
Joe Perches406874a2008-04-03 10:06:32 -07001949 s32 ret_val;
1950 u16 mii_status_reg;
1951 u16 mii_nway_adv_reg;
1952 u16 mii_nway_lp_ability_reg;
1953 u16 speed;
1954 u16 duplex;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955
1956 DEBUGFUNC("e1000_config_fc_after_link_up");
1957
1958 /* Check for the case where we have fiber media and auto-neg failed
1959 * so we had to force link. In this case, we need to force the
1960 * configuration of the MAC to match the "fc" parameter.
1961 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001962 if (((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) ||
1963 ((hw->media_type == e1000_media_type_internal_serdes) &&
1964 (hw->autoneg_failed)) ||
1965 ((hw->media_type == e1000_media_type_copper) && (!hw->autoneg))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001966 ret_val = e1000_force_mac_fc(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001967 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968 DEBUGOUT("Error forcing flow control settings\n");
1969 return ret_val;
1970 }
1971 }
1972
1973 /* Check for the case where we have copper media and auto-neg is
1974 * enabled. In this case, we need to check and see if Auto-Neg
1975 * has completed, and if so, how the PHY and link partner has
1976 * flow control configured.
1977 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001978 if ((hw->media_type == e1000_media_type_copper) && hw->autoneg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979 /* Read the MII Status Register and check to see if AutoNeg
1980 * has completed. We read this twice because this reg has
1981 * some "sticky" (latched) bits.
1982 */
1983 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07001984 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001985 return ret_val;
1986 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07001987 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988 return ret_val;
1989
Auke Kok8fc897b2006-08-28 14:56:16 -07001990 if (mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991 /* The AutoNeg process has completed, so we now need to
1992 * read both the Auto Negotiation Advertisement Register
1993 * (Address 4) and the Auto_Negotiation Base Page Ability
1994 * Register (Address 5) to determine how flow control was
1995 * negotiated.
1996 */
1997 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV,
1998 &mii_nway_adv_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07001999 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002000 return ret_val;
2001 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY,
2002 &mii_nway_lp_ability_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002003 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004 return ret_val;
2005
2006 /* Two bits in the Auto Negotiation Advertisement Register
2007 * (Address 4) and two bits in the Auto Negotiation Base
2008 * Page Ability Register (Address 5) determine flow control
2009 * for both the PHY and the link partner. The following
2010 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
2011 * 1999, describes these PAUSE resolution bits and how flow
2012 * control is determined based upon these settings.
2013 * NOTE: DC = Don't Care
2014 *
2015 * LOCAL DEVICE | LINK PARTNER
2016 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
2017 *-------|---------|-------|---------|--------------------
Jeff Kirsher11241b12006-09-27 12:53:28 -07002018 * 0 | 0 | DC | DC | E1000_FC_NONE
2019 * 0 | 1 | 0 | DC | E1000_FC_NONE
2020 * 0 | 1 | 1 | 0 | E1000_FC_NONE
2021 * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
2022 * 1 | 0 | 0 | DC | E1000_FC_NONE
2023 * 1 | DC | 1 | DC | E1000_FC_FULL
2024 * 1 | 1 | 0 | 0 | E1000_FC_NONE
2025 * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026 *
2027 */
2028 /* Are both PAUSE bits set to 1? If so, this implies
2029 * Symmetric Flow Control is enabled at both ends. The
2030 * ASM_DIR bits are irrelevant per the spec.
2031 *
2032 * For Symmetric Flow Control:
2033 *
2034 * LOCAL DEVICE | LINK PARTNER
2035 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2036 *-------|---------|-------|---------|--------------------
Jeff Kirsher11241b12006-09-27 12:53:28 -07002037 * 1 | DC | 1 | DC | E1000_FC_FULL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038 *
2039 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002040 if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2041 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042 /* Now we need to check if the user selected RX ONLY
2043 * of pause frames. In this case, we had to advertise
2044 * FULL flow control because we could not advertise RX
2045 * ONLY. Hence, we must now check to see if we need to
2046 * turn OFF the TRANSMISSION of PAUSE frames.
2047 */
Jeff Kirsher11241b12006-09-27 12:53:28 -07002048 if (hw->original_fc == E1000_FC_FULL) {
2049 hw->fc = E1000_FC_FULL;
Auke Koka42a5072006-05-23 13:36:01 -07002050 DEBUGOUT("Flow Control = FULL.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051 } else {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002052 hw->fc = E1000_FC_RX_PAUSE;
Auke Koka42a5072006-05-23 13:36:01 -07002053 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054 }
2055 }
2056 /* For receiving PAUSE frames ONLY.
2057 *
2058 * LOCAL DEVICE | LINK PARTNER
2059 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2060 *-------|---------|-------|---------|--------------------
Jeff Kirsher11241b12006-09-27 12:53:28 -07002061 * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062 *
2063 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002064 else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2065 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2066 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2067 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002068 hw->fc = E1000_FC_TX_PAUSE;
Auke Koka42a5072006-05-23 13:36:01 -07002069 DEBUGOUT("Flow Control = TX PAUSE frames only.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070 }
2071 /* For transmitting PAUSE frames ONLY.
2072 *
2073 * LOCAL DEVICE | LINK PARTNER
2074 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2075 *-------|---------|-------|---------|--------------------
Jeff Kirsher11241b12006-09-27 12:53:28 -07002076 * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077 *
2078 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002079 else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2080 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2081 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2082 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002083 hw->fc = E1000_FC_RX_PAUSE;
Auke Koka42a5072006-05-23 13:36:01 -07002084 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085 }
2086 /* Per the IEEE spec, at this point flow control should be
2087 * disabled. However, we want to consider that we could
2088 * be connected to a legacy switch that doesn't advertise
2089 * desired flow control, but can be forced on the link
2090 * partner. So if we advertised no flow control, that is
2091 * what we will resolve to. If we advertised some kind of
2092 * receive capability (Rx Pause Only or Full Flow Control)
2093 * and the link partner advertised none, we will configure
2094 * ourselves to enable Rx Flow Control only. We can do
2095 * this safely for two reasons: If the link partner really
2096 * didn't want flow control enabled, and we enable Rx, no
2097 * harm done since we won't be receiving any PAUSE frames
2098 * anyway. If the intent on the link partner was to have
2099 * flow control enabled, then by us enabling RX only, we
2100 * can at least receive pause frames and process them.
2101 * This is a good idea because in most cases, since we are
2102 * predominantly a server NIC, more times than not we will
2103 * be asked to delay transmission of packets than asking
2104 * our link partner to pause transmission of frames.
2105 */
Jeff Kirsher11241b12006-09-27 12:53:28 -07002106 else if ((hw->original_fc == E1000_FC_NONE ||
2107 hw->original_fc == E1000_FC_TX_PAUSE) ||
Auke Kok8fc897b2006-08-28 14:56:16 -07002108 hw->fc_strict_ieee) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002109 hw->fc = E1000_FC_NONE;
Auke Koka42a5072006-05-23 13:36:01 -07002110 DEBUGOUT("Flow Control = NONE.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111 } else {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002112 hw->fc = E1000_FC_RX_PAUSE;
Auke Koka42a5072006-05-23 13:36:01 -07002113 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114 }
2115
2116 /* Now we need to do one last check... If we auto-
2117 * negotiated to HALF DUPLEX, flow control should not be
2118 * enabled per IEEE 802.3 spec.
2119 */
2120 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
Auke Kok8fc897b2006-08-28 14:56:16 -07002121 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122 DEBUGOUT("Error getting link speed and duplex\n");
2123 return ret_val;
2124 }
2125
Auke Kok8fc897b2006-08-28 14:56:16 -07002126 if (duplex == HALF_DUPLEX)
Jeff Kirsher11241b12006-09-27 12:53:28 -07002127 hw->fc = E1000_FC_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128
2129 /* Now we call a subroutine to actually force the MAC
2130 * controller to use the correct flow control settings.
2131 */
2132 ret_val = e1000_force_mac_fc(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002133 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134 DEBUGOUT("Error forcing flow control settings\n");
2135 return ret_val;
2136 }
2137 } else {
Auke Koka42a5072006-05-23 13:36:01 -07002138 DEBUGOUT("Copper PHY and Auto Neg has not completed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139 }
2140 }
2141 return E1000_SUCCESS;
2142}
2143
2144/******************************************************************************
2145 * Checks to see if the link status of the hardware has changed.
2146 *
2147 * hw - Struct containing variables accessed by shared code
2148 *
2149 * Called by any function that needs to check the link status of the adapter.
2150 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07002151s32 e1000_check_for_link(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152{
Joe Perches406874a2008-04-03 10:06:32 -07002153 u32 rxcw = 0;
2154 u32 ctrl;
2155 u32 status;
2156 u32 rctl;
2157 u32 icr;
2158 u32 signal = 0;
2159 s32 ret_val;
2160 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161
2162 DEBUGFUNC("e1000_check_for_link");
2163
Joe Perches1dc32912008-07-11 15:17:08 -07002164 ctrl = er32(CTRL);
2165 status = er32(STATUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166
2167 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
2168 * set when the optics detect a signal. On older adapters, it will be
2169 * cleared when there is a signal. This applies to fiber media only.
2170 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002171 if ((hw->media_type == e1000_media_type_fiber) ||
2172 (hw->media_type == e1000_media_type_internal_serdes)) {
Joe Perches1dc32912008-07-11 15:17:08 -07002173 rxcw = er32(RXCW);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174
Auke Kok8fc897b2006-08-28 14:56:16 -07002175 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
Auke Kok8fc897b2006-08-28 14:56:16 -07002177 if (status & E1000_STATUS_LU)
Joe Perchesc3033b02008-03-21 11:06:25 -07002178 hw->get_link_status = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179 }
2180 }
2181
2182 /* If we have a copper PHY then we only want to go out to the PHY
2183 * registers to see if Auto-Neg has completed and/or if our link
2184 * status has changed. The get_link_status flag will be set if we
2185 * receive a Link Status Change interrupt or we have Rx Sequence
2186 * Errors.
2187 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002188 if ((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189 /* First we want to see if the MII Status Register reports
2190 * link. If so, then we want to get the current speed/duplex
2191 * of the PHY.
2192 * Read the register twice since the link bit is sticky.
2193 */
2194 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002195 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196 return ret_val;
2197 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002198 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199 return ret_val;
2200
Auke Kok8fc897b2006-08-28 14:56:16 -07002201 if (phy_data & MII_SR_LINK_STATUS) {
Joe Perchesc3033b02008-03-21 11:06:25 -07002202 hw->get_link_status = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203 /* Check if there was DownShift, must be checked immediately after
2204 * link-up */
2205 e1000_check_downshift(hw);
2206
2207 /* If we are on 82544 or 82543 silicon and speed/duplex
2208 * are forced to 10H or 10F, then we will implement the polarity
2209 * reversal workaround. We disable interrupts first, and upon
2210 * returning, place the devices interrupt state to its previous
2211 * value except for the link status change interrupt which will
2212 * happen due to the execution of this workaround.
2213 */
2214
Auke Kok8fc897b2006-08-28 14:56:16 -07002215 if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
2216 (!hw->autoneg) &&
2217 (hw->forced_speed_duplex == e1000_10_full ||
2218 hw->forced_speed_duplex == e1000_10_half)) {
Joe Perches1dc32912008-07-11 15:17:08 -07002219 ew32(IMC, 0xffffffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220 ret_val = e1000_polarity_reversal_workaround(hw);
Joe Perches1dc32912008-07-11 15:17:08 -07002221 icr = er32(ICR);
2222 ew32(ICS, (icr & ~E1000_ICS_LSC));
2223 ew32(IMS, IMS_ENABLE_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224 }
2225
2226 } else {
2227 /* No link detected */
Joe Perchesc3033b02008-03-21 11:06:25 -07002228 e1000_config_dsp_after_link_change(hw, false);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229 return 0;
2230 }
2231
2232 /* If we are forcing speed/duplex, then we simply return since
2233 * we have already determined whether we have link or not.
2234 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002235 if (!hw->autoneg) return -E1000_ERR_CONFIG;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236
2237 /* optimize the dsp settings for the igp phy */
Joe Perchesc3033b02008-03-21 11:06:25 -07002238 e1000_config_dsp_after_link_change(hw, true);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239
2240 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
2241 * have Si on board that is 82544 or newer, Auto
2242 * Speed Detection takes care of MAC speed/duplex
2243 * configuration. So we only need to configure Collision
2244 * Distance in the MAC. Otherwise, we need to force
2245 * speed/duplex on the MAC to the current PHY speed/duplex
2246 * settings.
2247 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002248 if (hw->mac_type >= e1000_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249 e1000_config_collision_dist(hw);
2250 else {
2251 ret_val = e1000_config_mac_to_phy(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002252 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253 DEBUGOUT("Error configuring MAC to PHY settings\n");
2254 return ret_val;
2255 }
2256 }
2257
2258 /* Configure Flow Control now that Auto-Neg has completed. First, we
2259 * need to restore the desired flow control settings because we may
2260 * have had to re-autoneg with a different link partner.
2261 */
2262 ret_val = e1000_config_fc_after_link_up(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002263 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264 DEBUGOUT("Error configuring flow control\n");
2265 return ret_val;
2266 }
2267
2268 /* At this point we know that we are on copper and we have
2269 * auto-negotiated link. These are conditions for checking the link
2270 * partner capability register. We use the link speed to determine if
2271 * TBI compatibility needs to be turned on or off. If the link is not
2272 * at gigabit speed, then TBI compatibility is not needed. If we are
2273 * at gigabit speed, we turn on TBI compatibility.
2274 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002275 if (hw->tbi_compatibility_en) {
Joe Perches406874a2008-04-03 10:06:32 -07002276 u16 speed, duplex;
Auke Kok592600a2006-06-27 09:08:09 -07002277 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
2278 if (ret_val) {
2279 DEBUGOUT("Error getting link speed and duplex\n");
2280 return ret_val;
2281 }
2282 if (speed != SPEED_1000) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283 /* If link speed is not set to gigabit speed, we do not need
2284 * to enable TBI compatibility.
2285 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002286 if (hw->tbi_compatibility_on) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287 /* If we previously were in the mode, turn it off. */
Joe Perches1dc32912008-07-11 15:17:08 -07002288 rctl = er32(RCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289 rctl &= ~E1000_RCTL_SBP;
Joe Perches1dc32912008-07-11 15:17:08 -07002290 ew32(RCTL, rctl);
Joe Perchesc3033b02008-03-21 11:06:25 -07002291 hw->tbi_compatibility_on = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292 }
2293 } else {
2294 /* If TBI compatibility is was previously off, turn it on. For
2295 * compatibility with a TBI link partner, we will store bad
2296 * packets. Some frames have an additional byte on the end and
Anand Gadiyarfd589a82009-07-16 17:13:03 +02002297 * will look like CRC errors to the hardware.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002299 if (!hw->tbi_compatibility_on) {
Joe Perchesc3033b02008-03-21 11:06:25 -07002300 hw->tbi_compatibility_on = true;
Joe Perches1dc32912008-07-11 15:17:08 -07002301 rctl = er32(RCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302 rctl |= E1000_RCTL_SBP;
Joe Perches1dc32912008-07-11 15:17:08 -07002303 ew32(RCTL, rctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304 }
2305 }
2306 }
2307 }
2308 /* If we don't have link (auto-negotiation failed or link partner cannot
2309 * auto-negotiate), the cable is plugged in (we have signal), and our
2310 * link partner is not trying to auto-negotiate with us (we are receiving
2311 * idles or data), we need to force link up. We also need to give
2312 * auto-negotiation time to complete, in case the cable was just plugged
2313 * in. The autoneg_failed flag does this.
2314 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002315 else if ((((hw->media_type == e1000_media_type_fiber) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316 ((ctrl & E1000_CTRL_SWDPIN1) == signal)) ||
Auke Kok8fc897b2006-08-28 14:56:16 -07002317 (hw->media_type == e1000_media_type_internal_serdes)) &&
2318 (!(status & E1000_STATUS_LU)) &&
2319 (!(rxcw & E1000_RXCW_C))) {
2320 if (hw->autoneg_failed == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321 hw->autoneg_failed = 1;
2322 return 0;
2323 }
Auke Koka42a5072006-05-23 13:36:01 -07002324 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325
2326 /* Disable auto-negotiation in the TXCW register */
Joe Perches1dc32912008-07-11 15:17:08 -07002327 ew32(TXCW, (hw->txcw & ~E1000_TXCW_ANE));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328
2329 /* Force link-up and also force full-duplex. */
Joe Perches1dc32912008-07-11 15:17:08 -07002330 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
Joe Perches1dc32912008-07-11 15:17:08 -07002332 ew32(CTRL, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333
2334 /* Configure Flow Control after forcing link up. */
2335 ret_val = e1000_config_fc_after_link_up(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002336 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337 DEBUGOUT("Error configuring flow control\n");
2338 return ret_val;
2339 }
2340 }
2341 /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
2342 * auto-negotiation in the TXCW register and disable forced link in the
2343 * Device Control register in an attempt to auto-negotiate with our link
2344 * partner.
2345 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002346 else if (((hw->media_type == e1000_media_type_fiber) ||
2347 (hw->media_type == e1000_media_type_internal_serdes)) &&
2348 (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
Auke Koka42a5072006-05-23 13:36:01 -07002349 DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\n");
Joe Perches1dc32912008-07-11 15:17:08 -07002350 ew32(TXCW, hw->txcw);
2351 ew32(CTRL, (ctrl & ~E1000_CTRL_SLU));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352
Joe Perchesc3033b02008-03-21 11:06:25 -07002353 hw->serdes_link_down = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354 }
2355 /* If we force link for non-auto-negotiation switch, check link status
2356 * based on MAC synchronization for internal serdes media type.
2357 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002358 else if ((hw->media_type == e1000_media_type_internal_serdes) &&
Joe Perches1dc32912008-07-11 15:17:08 -07002359 !(E1000_TXCW_ANE & er32(TXCW))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360 /* SYNCH bit and IV bit are sticky. */
2361 udelay(10);
Joe Perches1dc32912008-07-11 15:17:08 -07002362 if (E1000_RXCW_SYNCH & er32(RXCW)) {
Auke Kok8fc897b2006-08-28 14:56:16 -07002363 if (!(rxcw & E1000_RXCW_IV)) {
Joe Perchesc3033b02008-03-21 11:06:25 -07002364 hw->serdes_link_down = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365 DEBUGOUT("SERDES: Link is up.\n");
2366 }
2367 } else {
Joe Perchesc3033b02008-03-21 11:06:25 -07002368 hw->serdes_link_down = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002369 DEBUGOUT("SERDES: Link is down.\n");
2370 }
2371 }
Auke Kok8fc897b2006-08-28 14:56:16 -07002372 if ((hw->media_type == e1000_media_type_internal_serdes) &&
Joe Perches1dc32912008-07-11 15:17:08 -07002373 (E1000_TXCW_ANE & er32(TXCW))) {
2374 hw->serdes_link_down = !(E1000_STATUS_LU & er32(STATUS));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375 }
2376 return E1000_SUCCESS;
2377}
2378
2379/******************************************************************************
2380 * Detects the current speed and duplex settings of the hardware.
2381 *
2382 * hw - Struct containing variables accessed by shared code
2383 * speed - Speed of the connection
2384 * duplex - Duplex setting of the connection
2385 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07002386s32 e1000_get_speed_and_duplex(struct e1000_hw *hw, u16 *speed, u16 *duplex)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387{
Joe Perches406874a2008-04-03 10:06:32 -07002388 u32 status;
2389 s32 ret_val;
2390 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391
2392 DEBUGFUNC("e1000_get_speed_and_duplex");
2393
Auke Kok8fc897b2006-08-28 14:56:16 -07002394 if (hw->mac_type >= e1000_82543) {
Joe Perches1dc32912008-07-11 15:17:08 -07002395 status = er32(STATUS);
Auke Kok8fc897b2006-08-28 14:56:16 -07002396 if (status & E1000_STATUS_SPEED_1000) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397 *speed = SPEED_1000;
2398 DEBUGOUT("1000 Mbs, ");
Auke Kok8fc897b2006-08-28 14:56:16 -07002399 } else if (status & E1000_STATUS_SPEED_100) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400 *speed = SPEED_100;
2401 DEBUGOUT("100 Mbs, ");
2402 } else {
2403 *speed = SPEED_10;
2404 DEBUGOUT("10 Mbs, ");
2405 }
2406
Auke Kok8fc897b2006-08-28 14:56:16 -07002407 if (status & E1000_STATUS_FD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408 *duplex = FULL_DUPLEX;
Auke Koka42a5072006-05-23 13:36:01 -07002409 DEBUGOUT("Full Duplex\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410 } else {
2411 *duplex = HALF_DUPLEX;
Auke Koka42a5072006-05-23 13:36:01 -07002412 DEBUGOUT(" Half Duplex\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413 }
2414 } else {
Auke Koka42a5072006-05-23 13:36:01 -07002415 DEBUGOUT("1000 Mbs, Full Duplex\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416 *speed = SPEED_1000;
2417 *duplex = FULL_DUPLEX;
2418 }
2419
2420 /* IGP01 PHY may advertise full duplex operation after speed downgrade even
2421 * if it is operating at half duplex. Here we set the duplex settings to
2422 * match the duplex in the link partner's capabilities.
2423 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002424 if (hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002426 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427 return ret_val;
2428
Auke Kok8fc897b2006-08-28 14:56:16 -07002429 if (!(phy_data & NWAY_ER_LP_NWAY_CAPS))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430 *duplex = HALF_DUPLEX;
2431 else {
2432 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002433 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434 return ret_val;
Auke Kok8fc897b2006-08-28 14:56:16 -07002435 if ((*speed == SPEED_100 && !(phy_data & NWAY_LPAR_100TX_FD_CAPS)) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436 (*speed == SPEED_10 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
2437 *duplex = HALF_DUPLEX;
2438 }
2439 }
2440
2441 return E1000_SUCCESS;
2442}
2443
2444/******************************************************************************
2445* Blocks until autoneg completes or times out (~4.5 seconds)
2446*
2447* hw - Struct containing variables accessed by shared code
2448******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07002449static s32 e1000_wait_autoneg(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450{
Joe Perches406874a2008-04-03 10:06:32 -07002451 s32 ret_val;
2452 u16 i;
2453 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002454
2455 DEBUGFUNC("e1000_wait_autoneg");
2456 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
2457
2458 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
Auke Kok8fc897b2006-08-28 14:56:16 -07002459 for (i = PHY_AUTO_NEG_TIME; i > 0; i--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002460 /* Read the MII Status Register and wait for Auto-Neg
2461 * Complete bit to be set.
2462 */
2463 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002464 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002465 return ret_val;
2466 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002467 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468 return ret_val;
Auke Kok8fc897b2006-08-28 14:56:16 -07002469 if (phy_data & MII_SR_AUTONEG_COMPLETE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470 return E1000_SUCCESS;
2471 }
Jeff Garzikf8ec4732006-09-19 15:27:07 -04002472 msleep(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473 }
2474 return E1000_SUCCESS;
2475}
2476
2477/******************************************************************************
2478* Raises the Management Data Clock
2479*
2480* hw - Struct containing variables accessed by shared code
2481* ctrl - Device control register's current value
2482******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07002483static void e1000_raise_mdi_clk(struct e1000_hw *hw, u32 *ctrl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484{
2485 /* Raise the clock input to the Management Data Clock (by setting the MDC
2486 * bit), and then delay 10 microseconds.
2487 */
Joe Perches1dc32912008-07-11 15:17:08 -07002488 ew32(CTRL, (*ctrl | E1000_CTRL_MDC));
2489 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490 udelay(10);
2491}
2492
2493/******************************************************************************
2494* Lowers the Management Data Clock
2495*
2496* hw - Struct containing variables accessed by shared code
2497* ctrl - Device control register's current value
2498******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07002499static void e1000_lower_mdi_clk(struct e1000_hw *hw, u32 *ctrl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500{
2501 /* Lower the clock input to the Management Data Clock (by clearing the MDC
2502 * bit), and then delay 10 microseconds.
2503 */
Joe Perches1dc32912008-07-11 15:17:08 -07002504 ew32(CTRL, (*ctrl & ~E1000_CTRL_MDC));
2505 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506 udelay(10);
2507}
2508
2509/******************************************************************************
2510* Shifts data bits out to the PHY
2511*
2512* hw - Struct containing variables accessed by shared code
2513* data - Data to send out to the PHY
2514* count - Number of bits to shift out
2515*
2516* Bits are shifted out in MSB to LSB order.
2517******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07002518static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, u32 data, u16 count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519{
Joe Perches406874a2008-04-03 10:06:32 -07002520 u32 ctrl;
2521 u32 mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522
2523 /* We need to shift "count" number of bits out to the PHY. So, the value
2524 * in the "data" parameter will be shifted out to the PHY one bit at a
2525 * time. In order to do this, "data" must be broken down into bits.
2526 */
2527 mask = 0x01;
2528 mask <<= (count - 1);
2529
Joe Perches1dc32912008-07-11 15:17:08 -07002530 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531
2532 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
2533 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
2534
Auke Kok8fc897b2006-08-28 14:56:16 -07002535 while (mask) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536 /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
2537 * then raising and lowering the Management Data Clock. A "0" is
2538 * shifted out to the PHY by setting the MDIO bit to "0" and then
2539 * raising and lowering the clock.
2540 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002541 if (data & mask)
2542 ctrl |= E1000_CTRL_MDIO;
2543 else
2544 ctrl &= ~E1000_CTRL_MDIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545
Joe Perches1dc32912008-07-11 15:17:08 -07002546 ew32(CTRL, ctrl);
2547 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002548
2549 udelay(10);
2550
2551 e1000_raise_mdi_clk(hw, &ctrl);
2552 e1000_lower_mdi_clk(hw, &ctrl);
2553
2554 mask = mask >> 1;
2555 }
2556}
2557
2558/******************************************************************************
2559* Shifts data bits in from the PHY
2560*
2561* hw - Struct containing variables accessed by shared code
2562*
2563* Bits are shifted in in MSB to LSB order.
2564******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07002565static u16 e1000_shift_in_mdi_bits(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566{
Joe Perches406874a2008-04-03 10:06:32 -07002567 u32 ctrl;
2568 u16 data = 0;
2569 u8 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570
2571 /* In order to read a register from the PHY, we need to shift in a total
2572 * of 18 bits from the PHY. The first two bit (turnaround) times are used
2573 * to avoid contention on the MDIO pin when a read operation is performed.
2574 * These two bits are ignored by us and thrown away. Bits are "shifted in"
2575 * by raising the input to the Management Data Clock (setting the MDC bit),
2576 * and then reading the value of the MDIO bit.
2577 */
Joe Perches1dc32912008-07-11 15:17:08 -07002578 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002579
2580 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
2581 ctrl &= ~E1000_CTRL_MDIO_DIR;
2582 ctrl &= ~E1000_CTRL_MDIO;
2583
Joe Perches1dc32912008-07-11 15:17:08 -07002584 ew32(CTRL, ctrl);
2585 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586
2587 /* Raise and Lower the clock before reading in the data. This accounts for
2588 * the turnaround bits. The first clock occurred when we clocked out the
2589 * last bit of the Register Address.
2590 */
2591 e1000_raise_mdi_clk(hw, &ctrl);
2592 e1000_lower_mdi_clk(hw, &ctrl);
2593
Auke Kok8fc897b2006-08-28 14:56:16 -07002594 for (data = 0, i = 0; i < 16; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595 data = data << 1;
2596 e1000_raise_mdi_clk(hw, &ctrl);
Joe Perches1dc32912008-07-11 15:17:08 -07002597 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002598 /* Check to see if we shifted in a "1". */
Auke Kok8fc897b2006-08-28 14:56:16 -07002599 if (ctrl & E1000_CTRL_MDIO)
2600 data |= 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601 e1000_lower_mdi_clk(hw, &ctrl);
2602 }
2603
2604 e1000_raise_mdi_clk(hw, &ctrl);
2605 e1000_lower_mdi_clk(hw, &ctrl);
2606
2607 return data;
2608}
2609
Joe Perches64798842008-07-11 15:17:02 -07002610static s32 e1000_swfw_sync_acquire(struct e1000_hw *hw, u16 mask)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002611{
Joe Perches406874a2008-04-03 10:06:32 -07002612 u32 swfw_sync = 0;
2613 u32 swmask = mask;
2614 u32 fwmask = mask << 16;
2615 s32 timeout = 200;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002616
2617 DEBUGFUNC("e1000_swfw_sync_acquire");
2618
2619 if (!hw->swfw_sync_present)
2620 return e1000_get_hw_eeprom_semaphore(hw);
2621
Auke Kok8fc897b2006-08-28 14:56:16 -07002622 while (timeout) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002623 if (e1000_get_hw_eeprom_semaphore(hw))
2624 return -E1000_ERR_SWFW_SYNC;
2625
Joe Perches1dc32912008-07-11 15:17:08 -07002626 swfw_sync = er32(SW_FW_SYNC);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002627 if (!(swfw_sync & (fwmask | swmask))) {
2628 break;
2629 }
2630
2631 /* firmware currently using resource (fwmask) */
2632 /* or other software thread currently using resource (swmask) */
2633 e1000_put_hw_eeprom_semaphore(hw);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04002634 mdelay(5);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002635 timeout--;
2636 }
2637
2638 if (!timeout) {
2639 DEBUGOUT("Driver can't access resource, SW_FW_SYNC timeout.\n");
2640 return -E1000_ERR_SWFW_SYNC;
2641 }
2642
2643 swfw_sync |= swmask;
Joe Perches1dc32912008-07-11 15:17:08 -07002644 ew32(SW_FW_SYNC, swfw_sync);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002645
2646 e1000_put_hw_eeprom_semaphore(hw);
2647 return E1000_SUCCESS;
2648}
2649
Joe Perches64798842008-07-11 15:17:02 -07002650static void e1000_swfw_sync_release(struct e1000_hw *hw, u16 mask)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002651{
Joe Perches406874a2008-04-03 10:06:32 -07002652 u32 swfw_sync;
2653 u32 swmask = mask;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002654
2655 DEBUGFUNC("e1000_swfw_sync_release");
2656
2657 if (!hw->swfw_sync_present) {
2658 e1000_put_hw_eeprom_semaphore(hw);
2659 return;
2660 }
2661
2662 /* if (e1000_get_hw_eeprom_semaphore(hw))
2663 * return -E1000_ERR_SWFW_SYNC; */
2664 while (e1000_get_hw_eeprom_semaphore(hw) != E1000_SUCCESS);
2665 /* empty */
2666
Joe Perches1dc32912008-07-11 15:17:08 -07002667 swfw_sync = er32(SW_FW_SYNC);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002668 swfw_sync &= ~swmask;
Joe Perches1dc32912008-07-11 15:17:08 -07002669 ew32(SW_FW_SYNC, swfw_sync);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002670
2671 e1000_put_hw_eeprom_semaphore(hw);
2672}
2673
Linus Torvalds1da177e2005-04-16 15:20:36 -07002674/*****************************************************************************
2675* Reads the value from a PHY register, if the value is on a specific non zero
2676* page, sets the page first.
2677* hw - Struct containing variables accessed by shared code
2678* reg_addr - address of the PHY register to read
2679******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07002680s32 e1000_read_phy_reg(struct e1000_hw *hw, u32 reg_addr, u16 *phy_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002681{
Joe Perches406874a2008-04-03 10:06:32 -07002682 u32 ret_val;
2683 u16 swfw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002684
2685 DEBUGFUNC("e1000_read_phy_reg");
2686
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00002687 swfw = E1000_SWFW_PHY0_SM;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002688 if (e1000_swfw_sync_acquire(hw, swfw))
2689 return -E1000_ERR_SWFW_SYNC;
2690
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00002691 if ((hw->phy_type == e1000_phy_igp) &&
2692 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002693 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
Joe Perches406874a2008-04-03 10:06:32 -07002694 (u16)reg_addr);
Auke Kok8fc897b2006-08-28 14:56:16 -07002695 if (ret_val) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002696 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002697 return ret_val;
2698 }
2699 }
2700
2701 ret_val = e1000_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
2702 phy_data);
2703
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002704 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002705 return ret_val;
2706}
2707
Joe Perches64798842008-07-11 15:17:02 -07002708static s32 e1000_read_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr,
2709 u16 *phy_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710{
Joe Perches406874a2008-04-03 10:06:32 -07002711 u32 i;
2712 u32 mdic = 0;
2713 const u32 phy_addr = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714
2715 DEBUGFUNC("e1000_read_phy_reg_ex");
2716
Auke Kok8fc897b2006-08-28 14:56:16 -07002717 if (reg_addr > MAX_PHY_REG_ADDRESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002718 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
2719 return -E1000_ERR_PARAM;
2720 }
2721
Auke Kok8fc897b2006-08-28 14:56:16 -07002722 if (hw->mac_type > e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002723 /* Set up Op-code, Phy Address, and register address in the MDI
2724 * Control register. The MAC will take care of interfacing with the
2725 * PHY to retrieve the desired data.
2726 */
2727 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
2728 (phy_addr << E1000_MDIC_PHY_SHIFT) |
2729 (E1000_MDIC_OP_READ));
2730
Joe Perches1dc32912008-07-11 15:17:08 -07002731 ew32(MDIC, mdic);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732
2733 /* Poll the ready bit to see if the MDI read completed */
Auke Kok8fc897b2006-08-28 14:56:16 -07002734 for (i = 0; i < 64; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002735 udelay(50);
Joe Perches1dc32912008-07-11 15:17:08 -07002736 mdic = er32(MDIC);
Auke Kok8fc897b2006-08-28 14:56:16 -07002737 if (mdic & E1000_MDIC_READY) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002738 }
Auke Kok8fc897b2006-08-28 14:56:16 -07002739 if (!(mdic & E1000_MDIC_READY)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002740 DEBUGOUT("MDI Read did not complete\n");
2741 return -E1000_ERR_PHY;
2742 }
Auke Kok8fc897b2006-08-28 14:56:16 -07002743 if (mdic & E1000_MDIC_ERROR) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002744 DEBUGOUT("MDI Error\n");
2745 return -E1000_ERR_PHY;
2746 }
Joe Perchese982f172008-07-11 15:17:18 -07002747 *phy_data = (u16)mdic;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002748 } else {
2749 /* We must first send a preamble through the MDIO pin to signal the
2750 * beginning of an MII instruction. This is done by sending 32
2751 * consecutive "1" bits.
2752 */
2753 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
2754
2755 /* Now combine the next few fields that are required for a read
2756 * operation. We use this method instead of calling the
2757 * e1000_shift_out_mdi_bits routine five different times. The format of
2758 * a MII read instruction consists of a shift out of 14 bits and is
2759 * defined as follows:
2760 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
2761 * followed by a shift in of 18 bits. This first two bits shifted in
2762 * are TurnAround bits used to avoid contention on the MDIO pin when a
2763 * READ operation is performed. These two bits are thrown away
2764 * followed by a shift in of 16 bits which contains the desired data.
2765 */
2766 mdic = ((reg_addr) | (phy_addr << 5) |
2767 (PHY_OP_READ << 10) | (PHY_SOF << 12));
2768
2769 e1000_shift_out_mdi_bits(hw, mdic, 14);
2770
2771 /* Now that we've shifted out the read command to the MII, we need to
2772 * "shift in" the 16-bit value (18 total bits) of the requested PHY
2773 * register address.
2774 */
2775 *phy_data = e1000_shift_in_mdi_bits(hw);
2776 }
2777 return E1000_SUCCESS;
2778}
2779
2780/******************************************************************************
2781* Writes a value to a PHY register
2782*
2783* hw - Struct containing variables accessed by shared code
2784* reg_addr - address of the PHY register to write
2785* data - data to write to the PHY
2786******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07002787s32 e1000_write_phy_reg(struct e1000_hw *hw, u32 reg_addr, u16 phy_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002788{
Joe Perches406874a2008-04-03 10:06:32 -07002789 u32 ret_val;
2790 u16 swfw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002791
2792 DEBUGFUNC("e1000_write_phy_reg");
2793
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00002794 swfw = E1000_SWFW_PHY0_SM;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002795 if (e1000_swfw_sync_acquire(hw, swfw))
2796 return -E1000_ERR_SWFW_SYNC;
2797
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00002798 if ((hw->phy_type == e1000_phy_igp) &&
2799 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002800 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
Joe Perches406874a2008-04-03 10:06:32 -07002801 (u16)reg_addr);
Auke Kok8fc897b2006-08-28 14:56:16 -07002802 if (ret_val) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002803 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002804 return ret_val;
2805 }
2806 }
2807
2808 ret_val = e1000_write_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
2809 phy_data);
2810
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002811 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002812 return ret_val;
2813}
2814
Joe Perches64798842008-07-11 15:17:02 -07002815static s32 e1000_write_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr,
2816 u16 phy_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002817{
Joe Perches406874a2008-04-03 10:06:32 -07002818 u32 i;
2819 u32 mdic = 0;
2820 const u32 phy_addr = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002821
2822 DEBUGFUNC("e1000_write_phy_reg_ex");
2823
Auke Kok8fc897b2006-08-28 14:56:16 -07002824 if (reg_addr > MAX_PHY_REG_ADDRESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002825 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
2826 return -E1000_ERR_PARAM;
2827 }
2828
Auke Kok8fc897b2006-08-28 14:56:16 -07002829 if (hw->mac_type > e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002830 /* Set up Op-code, Phy Address, register address, and data intended
2831 * for the PHY register in the MDI Control register. The MAC will take
2832 * care of interfacing with the PHY to send the desired data.
2833 */
Joe Perchese982f172008-07-11 15:17:18 -07002834 mdic = (((u32)phy_data) |
Linus Torvalds1da177e2005-04-16 15:20:36 -07002835 (reg_addr << E1000_MDIC_REG_SHIFT) |
2836 (phy_addr << E1000_MDIC_PHY_SHIFT) |
2837 (E1000_MDIC_OP_WRITE));
2838
Joe Perches1dc32912008-07-11 15:17:08 -07002839 ew32(MDIC, mdic);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002840
2841 /* Poll the ready bit to see if the MDI read completed */
Auke Kok8fc897b2006-08-28 14:56:16 -07002842 for (i = 0; i < 641; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002843 udelay(5);
Joe Perches1dc32912008-07-11 15:17:08 -07002844 mdic = er32(MDIC);
Auke Kok8fc897b2006-08-28 14:56:16 -07002845 if (mdic & E1000_MDIC_READY) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002846 }
Auke Kok8fc897b2006-08-28 14:56:16 -07002847 if (!(mdic & E1000_MDIC_READY)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002848 DEBUGOUT("MDI Write did not complete\n");
2849 return -E1000_ERR_PHY;
2850 }
2851 } else {
2852 /* We'll need to use the SW defined pins to shift the write command
2853 * out to the PHY. We first send a preamble to the PHY to signal the
2854 * beginning of the MII instruction. This is done by sending 32
2855 * consecutive "1" bits.
2856 */
2857 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
2858
2859 /* Now combine the remaining required fields that will indicate a
2860 * write operation. We use this method instead of calling the
2861 * e1000_shift_out_mdi_bits routine for each field in the command. The
2862 * format of a MII write instruction is as follows:
2863 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
2864 */
2865 mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
2866 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
2867 mdic <<= 16;
Joe Perchese982f172008-07-11 15:17:18 -07002868 mdic |= (u32)phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002869
2870 e1000_shift_out_mdi_bits(hw, mdic, 32);
2871 }
2872
2873 return E1000_SUCCESS;
2874}
2875
2876/******************************************************************************
2877* Returns the PHY to the power-on reset state
2878*
2879* hw - Struct containing variables accessed by shared code
2880******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07002881s32 e1000_phy_hw_reset(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002882{
Joe Perches406874a2008-04-03 10:06:32 -07002883 u32 ctrl, ctrl_ext;
2884 u32 led_ctrl;
2885 s32 ret_val;
2886 u16 swfw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002887
2888 DEBUGFUNC("e1000_phy_hw_reset");
2889
2890 DEBUGOUT("Resetting Phy...\n");
2891
Auke Kok8fc897b2006-08-28 14:56:16 -07002892 if (hw->mac_type > e1000_82543) {
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00002893 swfw = E1000_SWFW_PHY0_SM;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002894 if (e1000_swfw_sync_acquire(hw, swfw)) {
Jeff Kirsher2a88c172006-09-27 12:54:05 -07002895 DEBUGOUT("Unable to acquire swfw sync\n");
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002896 return -E1000_ERR_SWFW_SYNC;
2897 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002898 /* Read the device control register and assert the E1000_CTRL_PHY_RST
2899 * bit. Then, take it out of reset.
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00002900 * For e1000 hardware, we delay for 10ms between the assert
2901 * and deassert.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002902 */
Joe Perches1dc32912008-07-11 15:17:08 -07002903 ctrl = er32(CTRL);
2904 ew32(CTRL, ctrl | E1000_CTRL_PHY_RST);
2905 E1000_WRITE_FLUSH();
Auke Kok76c224b2006-05-23 13:36:06 -07002906
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00002907 msleep(10);
Auke Kok76c224b2006-05-23 13:36:06 -07002908
Joe Perches1dc32912008-07-11 15:17:08 -07002909 ew32(CTRL, ctrl);
2910 E1000_WRITE_FLUSH();
Auke Kok76c224b2006-05-23 13:36:06 -07002911
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002912 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002913 } else {
2914 /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
2915 * bit to put the PHY into reset. Then, take it out of reset.
2916 */
Joe Perches1dc32912008-07-11 15:17:08 -07002917 ctrl_ext = er32(CTRL_EXT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002918 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
2919 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
Joe Perches1dc32912008-07-11 15:17:08 -07002920 ew32(CTRL_EXT, ctrl_ext);
2921 E1000_WRITE_FLUSH();
Jeff Garzikf8ec4732006-09-19 15:27:07 -04002922 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002923 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
Joe Perches1dc32912008-07-11 15:17:08 -07002924 ew32(CTRL_EXT, ctrl_ext);
2925 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002926 }
2927 udelay(150);
2928
Auke Kok8fc897b2006-08-28 14:56:16 -07002929 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002930 /* Configure activity LED after PHY reset */
Joe Perches1dc32912008-07-11 15:17:08 -07002931 led_ctrl = er32(LEDCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002932 led_ctrl &= IGP_ACTIVITY_LED_MASK;
2933 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
Joe Perches1dc32912008-07-11 15:17:08 -07002934 ew32(LEDCTL, led_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002935 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002936
2937 /* Wait for FW to finish PHY configuration. */
2938 ret_val = e1000_get_phy_cfg_done(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002939 if (ret_val != E1000_SUCCESS)
2940 return ret_val;
Auke Kok8fc897b2006-08-28 14:56:16 -07002941
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002942 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002943}
2944
2945/******************************************************************************
2946* Resets the PHY
2947*
2948* hw - Struct containing variables accessed by shared code
2949*
Matt LaPlante0779bf22006-11-30 05:24:39 +01002950* Sets bit 15 of the MII Control register
Linus Torvalds1da177e2005-04-16 15:20:36 -07002951******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07002952s32 e1000_phy_reset(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002953{
Joe Perches406874a2008-04-03 10:06:32 -07002954 s32 ret_val;
2955 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002956
2957 DEBUGFUNC("e1000_phy_reset");
2958
Jeff Kirsher2a88c172006-09-27 12:54:05 -07002959 switch (hw->phy_type) {
2960 case e1000_phy_igp:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002961 ret_val = e1000_phy_hw_reset(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002962 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002963 return ret_val;
2964 break;
2965 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002966 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002967 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002968 return ret_val;
2969
2970 phy_data |= MII_CR_RESET;
2971 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002972 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002973 return ret_val;
2974
2975 udelay(1);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002976 break;
2977 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002978
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00002979 if (hw->phy_type == e1000_phy_igp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002980 e1000_phy_init_script(hw);
2981
2982 return E1000_SUCCESS;
2983}
2984
2985/******************************************************************************
2986* Probes the expected PHY address for known PHY IDs
2987*
2988* hw - Struct containing variables accessed by shared code
2989******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07002990static s32 e1000_detect_gig_phy(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002991{
Joe Perches406874a2008-04-03 10:06:32 -07002992 s32 phy_init_status, ret_val;
2993 u16 phy_id_high, phy_id_low;
Joe Perchesc3033b02008-03-21 11:06:25 -07002994 bool match = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002995
2996 DEBUGFUNC("e1000_detect_gig_phy");
2997
Jeff Kirsher2a88c172006-09-27 12:54:05 -07002998 if (hw->phy_id != 0)
2999 return E1000_SUCCESS;
3000
Linus Torvalds1da177e2005-04-16 15:20:36 -07003001 /* Read the PHY ID Registers to identify which PHY is onboard. */
3002 ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
Auke Kokcd94dd02006-06-27 09:08:22 -07003003 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003004 return ret_val;
3005
Joe Perchese982f172008-07-11 15:17:18 -07003006 hw->phy_id = (u32)(phy_id_high << 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003007 udelay(20);
3008 ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
Auke Kok8fc897b2006-08-28 14:56:16 -07003009 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003010 return ret_val;
3011
Joe Perchese982f172008-07-11 15:17:18 -07003012 hw->phy_id |= (u32)(phy_id_low & PHY_REVISION_MASK);
3013 hw->phy_revision = (u32)phy_id_low & ~PHY_REVISION_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003014
Auke Kok8fc897b2006-08-28 14:56:16 -07003015 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003016 case e1000_82543:
Joe Perchesc3033b02008-03-21 11:06:25 -07003017 if (hw->phy_id == M88E1000_E_PHY_ID) match = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003018 break;
3019 case e1000_82544:
Joe Perchesc3033b02008-03-21 11:06:25 -07003020 if (hw->phy_id == M88E1000_I_PHY_ID) match = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003021 break;
3022 case e1000_82540:
3023 case e1000_82545:
3024 case e1000_82545_rev_3:
3025 case e1000_82546:
3026 case e1000_82546_rev_3:
Joe Perchesc3033b02008-03-21 11:06:25 -07003027 if (hw->phy_id == M88E1011_I_PHY_ID) match = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003028 break;
3029 case e1000_82541:
3030 case e1000_82541_rev_2:
3031 case e1000_82547:
3032 case e1000_82547_rev_2:
Joe Perchesc3033b02008-03-21 11:06:25 -07003033 if (hw->phy_id == IGP01E1000_I_PHY_ID) match = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003034 break;
3035 default:
3036 DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type);
3037 return -E1000_ERR_CONFIG;
3038 }
3039 phy_init_status = e1000_set_phy_type(hw);
3040
3041 if ((match) && (phy_init_status == E1000_SUCCESS)) {
3042 DEBUGOUT1("PHY ID 0x%X detected\n", hw->phy_id);
3043 return E1000_SUCCESS;
3044 }
3045 DEBUGOUT1("Invalid PHY ID 0x%X\n", hw->phy_id);
3046 return -E1000_ERR_PHY;
3047}
3048
3049/******************************************************************************
3050* Resets the PHY's DSP
3051*
3052* hw - Struct containing variables accessed by shared code
3053******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003054static s32 e1000_phy_reset_dsp(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003055{
Joe Perches406874a2008-04-03 10:06:32 -07003056 s32 ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003057 DEBUGFUNC("e1000_phy_reset_dsp");
3058
3059 do {
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00003060 ret_val = e1000_write_phy_reg(hw, 29, 0x001d);
3061 if (ret_val) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003062 ret_val = e1000_write_phy_reg(hw, 30, 0x00c1);
Auke Kok8fc897b2006-08-28 14:56:16 -07003063 if (ret_val) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003064 ret_val = e1000_write_phy_reg(hw, 30, 0x0000);
Auke Kok8fc897b2006-08-28 14:56:16 -07003065 if (ret_val) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003066 ret_val = E1000_SUCCESS;
Auke Kok8fc897b2006-08-28 14:56:16 -07003067 } while (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003068
3069 return ret_val;
3070}
3071
3072/******************************************************************************
3073* Get PHY information from various PHY registers for igp PHY only.
3074*
3075* hw - Struct containing variables accessed by shared code
3076* phy_info - PHY information structure
3077******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003078static s32 e1000_phy_igp_get_info(struct e1000_hw *hw,
3079 struct e1000_phy_info *phy_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003080{
Joe Perches406874a2008-04-03 10:06:32 -07003081 s32 ret_val;
3082 u16 phy_data, min_length, max_length, average;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07003083 e1000_rev_polarity polarity;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003084
3085 DEBUGFUNC("e1000_phy_igp_get_info");
3086
3087 /* The downshift status is checked only once, after link is established,
3088 * and it stored in the hw->speed_downgraded parameter. */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003089 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003090
3091 /* IGP01E1000 does not need to support it. */
3092 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
3093
3094 /* IGP01E1000 always correct polarity reversal */
3095 phy_info->polarity_correction = e1000_polarity_reversal_enabled;
3096
3097 /* Check polarity status */
3098 ret_val = e1000_check_polarity(hw, &polarity);
Auke Kok8fc897b2006-08-28 14:56:16 -07003099 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003100 return ret_val;
3101
3102 phy_info->cable_polarity = polarity;
3103
3104 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003105 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003106 return ret_val;
3107
Jeff Kirsher70c6f302006-09-27 12:53:31 -07003108 phy_info->mdix_mode = (e1000_auto_x_mode)((phy_data & IGP01E1000_PSSR_MDIX) >>
3109 IGP01E1000_PSSR_MDIX_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003110
Auke Kok8fc897b2006-08-28 14:56:16 -07003111 if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
Linus Torvalds1da177e2005-04-16 15:20:36 -07003112 IGP01E1000_PSSR_SPEED_1000MBPS) {
3113 /* Local/Remote Receiver Information are only valid at 1000 Mbps */
3114 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003115 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003116 return ret_val;
3117
Jeff Kirsher70c6f302006-09-27 12:53:31 -07003118 phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
3119 SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
3120 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
3121 phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
3122 SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
3123 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003124
3125 /* Get cable length */
3126 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
Auke Kok8fc897b2006-08-28 14:56:16 -07003127 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003128 return ret_val;
3129
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003130 /* Translate to old method */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003131 average = (max_length + min_length) / 2;
3132
Auke Kok8fc897b2006-08-28 14:56:16 -07003133 if (average <= e1000_igp_cable_length_50)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003134 phy_info->cable_length = e1000_cable_length_50;
Auke Kok8fc897b2006-08-28 14:56:16 -07003135 else if (average <= e1000_igp_cable_length_80)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003136 phy_info->cable_length = e1000_cable_length_50_80;
Auke Kok8fc897b2006-08-28 14:56:16 -07003137 else if (average <= e1000_igp_cable_length_110)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003138 phy_info->cable_length = e1000_cable_length_80_110;
Auke Kok8fc897b2006-08-28 14:56:16 -07003139 else if (average <= e1000_igp_cable_length_140)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003140 phy_info->cable_length = e1000_cable_length_110_140;
3141 else
3142 phy_info->cable_length = e1000_cable_length_140;
3143 }
3144
3145 return E1000_SUCCESS;
3146}
3147
Auke Kokd37ea5d2006-06-27 09:08:17 -07003148
3149/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07003150* Get PHY information from various PHY registers fot m88 PHY only.
3151*
3152* hw - Struct containing variables accessed by shared code
3153* phy_info - PHY information structure
3154******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003155static s32 e1000_phy_m88_get_info(struct e1000_hw *hw,
3156 struct e1000_phy_info *phy_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003157{
Joe Perches406874a2008-04-03 10:06:32 -07003158 s32 ret_val;
3159 u16 phy_data;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07003160 e1000_rev_polarity polarity;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003161
3162 DEBUGFUNC("e1000_phy_m88_get_info");
3163
3164 /* The downshift status is checked only once, after link is established,
3165 * and it stored in the hw->speed_downgraded parameter. */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003166 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003167
3168 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003169 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003170 return ret_val;
3171
3172 phy_info->extended_10bt_distance =
Jeff Kirsher70c6f302006-09-27 12:53:31 -07003173 ((phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >>
3174 M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT) ?
3175 e1000_10bt_ext_dist_enable_lower : e1000_10bt_ext_dist_enable_normal;
3176
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177 phy_info->polarity_correction =
Jeff Kirsher70c6f302006-09-27 12:53:31 -07003178 ((phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >>
3179 M88E1000_PSCR_POLARITY_REVERSAL_SHIFT) ?
3180 e1000_polarity_reversal_disabled : e1000_polarity_reversal_enabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003181
3182 /* Check polarity status */
3183 ret_val = e1000_check_polarity(hw, &polarity);
Auke Kok8fc897b2006-08-28 14:56:16 -07003184 if (ret_val)
Auke Kok76c224b2006-05-23 13:36:06 -07003185 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003186 phy_info->cable_polarity = polarity;
3187
3188 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003189 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003190 return ret_val;
3191
Jeff Kirsher70c6f302006-09-27 12:53:31 -07003192 phy_info->mdix_mode = (e1000_auto_x_mode)((phy_data & M88E1000_PSSR_MDIX) >>
3193 M88E1000_PSSR_MDIX_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003194
3195 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
3196 /* Cable Length Estimation and Local/Remote Receiver Information
3197 * are only valid at 1000 Mbps.
3198 */
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00003199 phy_info->cable_length = (e1000_cable_length)((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
3200 M88E1000_PSSR_CABLE_LENGTH_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003201
3202 ret_val = e1000_read_phy_reg(hw, PHY_1000T_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
Jeff Kirsher70c6f302006-09-27 12:53:31 -07003206 phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
3207 SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
3208 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
3209 phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
3210 SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
3211 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003212
Linus Torvalds1da177e2005-04-16 15:20:36 -07003213 }
3214
3215 return E1000_SUCCESS;
3216}
3217
3218/******************************************************************************
3219* Get PHY information from various PHY registers
3220*
3221* hw - Struct containing variables accessed by shared code
3222* phy_info - PHY information structure
3223******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003224s32 e1000_phy_get_info(struct e1000_hw *hw, struct e1000_phy_info *phy_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003225{
Joe Perches406874a2008-04-03 10:06:32 -07003226 s32 ret_val;
3227 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003228
3229 DEBUGFUNC("e1000_phy_get_info");
3230
3231 phy_info->cable_length = e1000_cable_length_undefined;
3232 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined;
3233 phy_info->cable_polarity = e1000_rev_polarity_undefined;
3234 phy_info->downshift = e1000_downshift_undefined;
3235 phy_info->polarity_correction = e1000_polarity_reversal_undefined;
3236 phy_info->mdix_mode = e1000_auto_x_mode_undefined;
3237 phy_info->local_rx = e1000_1000t_rx_status_undefined;
3238 phy_info->remote_rx = e1000_1000t_rx_status_undefined;
3239
Auke Kok8fc897b2006-08-28 14:56:16 -07003240 if (hw->media_type != e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003241 DEBUGOUT("PHY info is only valid for copper media\n");
3242 return -E1000_ERR_CONFIG;
3243 }
3244
3245 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003246 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003247 return ret_val;
3248
3249 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003250 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003251 return ret_val;
3252
Auke Kok8fc897b2006-08-28 14:56:16 -07003253 if ((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003254 DEBUGOUT("PHY info is only valid if link is up\n");
3255 return -E1000_ERR_CONFIG;
3256 }
3257
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00003258 if (hw->phy_type == e1000_phy_igp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003259 return e1000_phy_igp_get_info(hw, phy_info);
3260 else
3261 return e1000_phy_m88_get_info(hw, phy_info);
3262}
3263
Joe Perches64798842008-07-11 15:17:02 -07003264s32 e1000_validate_mdi_setting(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003265{
3266 DEBUGFUNC("e1000_validate_mdi_settings");
3267
Auke Kok8fc897b2006-08-28 14:56:16 -07003268 if (!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003269 DEBUGOUT("Invalid MDI setting detected\n");
3270 hw->mdix = 1;
3271 return -E1000_ERR_CONFIG;
3272 }
3273 return E1000_SUCCESS;
3274}
3275
3276
3277/******************************************************************************
3278 * Sets up eeprom variables in the hw struct. Must be called after mac_type
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00003279 * is configured.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003280 *
3281 * hw - Struct containing variables accessed by shared code
3282 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003283s32 e1000_init_eeprom_params(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003284{
3285 struct e1000_eeprom_info *eeprom = &hw->eeprom;
Joe Perches1dc32912008-07-11 15:17:08 -07003286 u32 eecd = er32(EECD);
Joe Perches406874a2008-04-03 10:06:32 -07003287 s32 ret_val = E1000_SUCCESS;
3288 u16 eeprom_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003289
3290 DEBUGFUNC("e1000_init_eeprom_params");
3291
3292 switch (hw->mac_type) {
3293 case e1000_82542_rev2_0:
3294 case e1000_82542_rev2_1:
3295 case e1000_82543:
3296 case e1000_82544:
3297 eeprom->type = e1000_eeprom_microwire;
3298 eeprom->word_size = 64;
3299 eeprom->opcode_bits = 3;
3300 eeprom->address_bits = 6;
3301 eeprom->delay_usec = 50;
Joe Perchesc3033b02008-03-21 11:06:25 -07003302 eeprom->use_eerd = false;
3303 eeprom->use_eewr = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003304 break;
3305 case e1000_82540:
3306 case e1000_82545:
3307 case e1000_82545_rev_3:
3308 case e1000_82546:
3309 case e1000_82546_rev_3:
3310 eeprom->type = e1000_eeprom_microwire;
3311 eeprom->opcode_bits = 3;
3312 eeprom->delay_usec = 50;
Auke Kok8fc897b2006-08-28 14:56:16 -07003313 if (eecd & E1000_EECD_SIZE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003314 eeprom->word_size = 256;
3315 eeprom->address_bits = 8;
3316 } else {
3317 eeprom->word_size = 64;
3318 eeprom->address_bits = 6;
3319 }
Joe Perchesc3033b02008-03-21 11:06:25 -07003320 eeprom->use_eerd = false;
3321 eeprom->use_eewr = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003322 break;
3323 case e1000_82541:
3324 case e1000_82541_rev_2:
3325 case e1000_82547:
3326 case e1000_82547_rev_2:
3327 if (eecd & E1000_EECD_TYPE) {
3328 eeprom->type = e1000_eeprom_spi;
3329 eeprom->opcode_bits = 8;
3330 eeprom->delay_usec = 1;
3331 if (eecd & E1000_EECD_ADDR_BITS) {
3332 eeprom->page_size = 32;
3333 eeprom->address_bits = 16;
3334 } else {
3335 eeprom->page_size = 8;
3336 eeprom->address_bits = 8;
3337 }
3338 } else {
3339 eeprom->type = e1000_eeprom_microwire;
3340 eeprom->opcode_bits = 3;
3341 eeprom->delay_usec = 50;
3342 if (eecd & E1000_EECD_ADDR_BITS) {
3343 eeprom->word_size = 256;
3344 eeprom->address_bits = 8;
3345 } else {
3346 eeprom->word_size = 64;
3347 eeprom->address_bits = 6;
3348 }
3349 }
Joe Perchesc3033b02008-03-21 11:06:25 -07003350 eeprom->use_eerd = false;
3351 eeprom->use_eewr = false;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003352 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003353 default:
3354 break;
3355 }
3356
3357 if (eeprom->type == e1000_eeprom_spi) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003358 /* eeprom_size will be an enum [0..8] that maps to eeprom sizes 128B to
3359 * 32KB (incremented by powers of 2).
3360 */
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00003361 /* Set to default value for initial eeprom read. */
3362 eeprom->word_size = 64;
3363 ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size);
3364 if (ret_val)
3365 return ret_val;
3366 eeprom_size = (eeprom_size & EEPROM_SIZE_MASK) >> EEPROM_SIZE_SHIFT;
3367 /* 256B eeprom size was not supported in earlier hardware, so we
3368 * bump eeprom_size up one to ensure that "1" (which maps to 256B)
3369 * is never the result used in the shifting logic below. */
3370 if (eeprom_size)
3371 eeprom_size++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003372
3373 eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003374 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003375 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003376}
3377
3378/******************************************************************************
3379 * Raises the EEPROM's clock input.
3380 *
3381 * hw - Struct containing variables accessed by shared code
3382 * eecd - EECD's current value
3383 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003384static void e1000_raise_ee_clk(struct e1000_hw *hw, u32 *eecd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003385{
3386 /* Raise the clock input to the EEPROM (by setting the SK bit), and then
3387 * wait <delay> microseconds.
3388 */
3389 *eecd = *eecd | E1000_EECD_SK;
Joe Perches1dc32912008-07-11 15:17:08 -07003390 ew32(EECD, *eecd);
3391 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003392 udelay(hw->eeprom.delay_usec);
3393}
3394
3395/******************************************************************************
3396 * Lowers the EEPROM's clock input.
3397 *
3398 * hw - Struct containing variables accessed by shared code
3399 * eecd - EECD's current value
3400 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003401static void e1000_lower_ee_clk(struct e1000_hw *hw, u32 *eecd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003402{
3403 /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
3404 * wait 50 microseconds.
3405 */
3406 *eecd = *eecd & ~E1000_EECD_SK;
Joe Perches1dc32912008-07-11 15:17:08 -07003407 ew32(EECD, *eecd);
3408 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003409 udelay(hw->eeprom.delay_usec);
3410}
3411
3412/******************************************************************************
3413 * Shift data bits out to the EEPROM.
3414 *
3415 * hw - Struct containing variables accessed by shared code
3416 * data - data to send to the EEPROM
3417 * count - number of bits to shift out
3418 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003419static void e1000_shift_out_ee_bits(struct e1000_hw *hw, u16 data, u16 count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003420{
3421 struct e1000_eeprom_info *eeprom = &hw->eeprom;
Joe Perches406874a2008-04-03 10:06:32 -07003422 u32 eecd;
3423 u32 mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003424
3425 /* We need to shift "count" bits out to the EEPROM. So, value in the
3426 * "data" parameter will be shifted out to the EEPROM one bit at a time.
3427 * In order to do this, "data" must be broken down into bits.
3428 */
3429 mask = 0x01 << (count - 1);
Joe Perches1dc32912008-07-11 15:17:08 -07003430 eecd = er32(EECD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003431 if (eeprom->type == e1000_eeprom_microwire) {
3432 eecd &= ~E1000_EECD_DO;
3433 } else if (eeprom->type == e1000_eeprom_spi) {
3434 eecd |= E1000_EECD_DO;
3435 }
3436 do {
3437 /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
3438 * and then raising and then lowering the clock (the SK bit controls
3439 * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
3440 * by setting "DI" to "0" and then raising and then lowering the clock.
3441 */
3442 eecd &= ~E1000_EECD_DI;
3443
Auke Kok8fc897b2006-08-28 14:56:16 -07003444 if (data & mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003445 eecd |= E1000_EECD_DI;
3446
Joe Perches1dc32912008-07-11 15:17:08 -07003447 ew32(EECD, eecd);
3448 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003449
3450 udelay(eeprom->delay_usec);
3451
3452 e1000_raise_ee_clk(hw, &eecd);
3453 e1000_lower_ee_clk(hw, &eecd);
3454
3455 mask = mask >> 1;
3456
Auke Kok8fc897b2006-08-28 14:56:16 -07003457 } while (mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003458
3459 /* We leave the "DI" bit set to "0" when we leave this routine. */
3460 eecd &= ~E1000_EECD_DI;
Joe Perches1dc32912008-07-11 15:17:08 -07003461 ew32(EECD, eecd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003462}
3463
3464/******************************************************************************
3465 * Shift data bits in from the EEPROM
3466 *
3467 * hw - Struct containing variables accessed by shared code
3468 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003469static u16 e1000_shift_in_ee_bits(struct e1000_hw *hw, u16 count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003470{
Joe Perches406874a2008-04-03 10:06:32 -07003471 u32 eecd;
3472 u32 i;
3473 u16 data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003474
3475 /* In order to read a register from the EEPROM, we need to shift 'count'
3476 * bits in from the EEPROM. Bits are "shifted in" by raising the clock
3477 * input to the EEPROM (setting the SK bit), and then reading the value of
3478 * the "DO" bit. During this "shifting in" process the "DI" bit should
3479 * always be clear.
3480 */
3481
Joe Perches1dc32912008-07-11 15:17:08 -07003482 eecd = er32(EECD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003483
3484 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
3485 data = 0;
3486
Auke Kok8fc897b2006-08-28 14:56:16 -07003487 for (i = 0; i < count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003488 data = data << 1;
3489 e1000_raise_ee_clk(hw, &eecd);
3490
Joe Perches1dc32912008-07-11 15:17:08 -07003491 eecd = er32(EECD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003492
3493 eecd &= ~(E1000_EECD_DI);
Auke Kok8fc897b2006-08-28 14:56:16 -07003494 if (eecd & E1000_EECD_DO)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003495 data |= 1;
3496
3497 e1000_lower_ee_clk(hw, &eecd);
3498 }
3499
3500 return data;
3501}
3502
3503/******************************************************************************
3504 * Prepares EEPROM for access
3505 *
3506 * hw - Struct containing variables accessed by shared code
3507 *
3508 * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
3509 * function should be called before issuing a command to the EEPROM.
3510 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003511static s32 e1000_acquire_eeprom(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003512{
3513 struct e1000_eeprom_info *eeprom = &hw->eeprom;
Joe Perches406874a2008-04-03 10:06:32 -07003514 u32 eecd, i=0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003515
3516 DEBUGFUNC("e1000_acquire_eeprom");
3517
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003518 if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
3519 return -E1000_ERR_SWFW_SYNC;
Joe Perches1dc32912008-07-11 15:17:08 -07003520 eecd = er32(EECD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003521
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00003522 /* Request EEPROM Access */
3523 if (hw->mac_type > e1000_82544) {
3524 eecd |= E1000_EECD_REQ;
3525 ew32(EECD, eecd);
3526 eecd = er32(EECD);
3527 while ((!(eecd & E1000_EECD_GNT)) &&
3528 (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
3529 i++;
3530 udelay(5);
Joe Perches1dc32912008-07-11 15:17:08 -07003531 eecd = er32(EECD);
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00003532 }
3533 if (!(eecd & E1000_EECD_GNT)) {
3534 eecd &= ~E1000_EECD_REQ;
3535 ew32(EECD, eecd);
3536 DEBUGOUT("Could not acquire EEPROM grant\n");
3537 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
3538 return -E1000_ERR_EEPROM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003539 }
3540 }
3541
3542 /* Setup EEPROM for Read/Write */
3543
3544 if (eeprom->type == e1000_eeprom_microwire) {
3545 /* Clear SK and DI */
3546 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
Joe Perches1dc32912008-07-11 15:17:08 -07003547 ew32(EECD, eecd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003548
3549 /* Set CS */
3550 eecd |= E1000_EECD_CS;
Joe Perches1dc32912008-07-11 15:17:08 -07003551 ew32(EECD, eecd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003552 } else if (eeprom->type == e1000_eeprom_spi) {
3553 /* Clear SK and CS */
3554 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
Joe Perches1dc32912008-07-11 15:17:08 -07003555 ew32(EECD, eecd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003556 udelay(1);
3557 }
3558
3559 return E1000_SUCCESS;
3560}
3561
3562/******************************************************************************
3563 * Returns EEPROM to a "standby" state
3564 *
3565 * hw - Struct containing variables accessed by shared code
3566 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003567static void e1000_standby_eeprom(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003568{
3569 struct e1000_eeprom_info *eeprom = &hw->eeprom;
Joe Perches406874a2008-04-03 10:06:32 -07003570 u32 eecd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003571
Joe Perches1dc32912008-07-11 15:17:08 -07003572 eecd = er32(EECD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003573
Auke Kok8fc897b2006-08-28 14:56:16 -07003574 if (eeprom->type == e1000_eeprom_microwire) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003575 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
Joe Perches1dc32912008-07-11 15:17:08 -07003576 ew32(EECD, eecd);
3577 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003578 udelay(eeprom->delay_usec);
3579
3580 /* Clock high */
3581 eecd |= E1000_EECD_SK;
Joe Perches1dc32912008-07-11 15:17:08 -07003582 ew32(EECD, eecd);
3583 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003584 udelay(eeprom->delay_usec);
3585
3586 /* Select EEPROM */
3587 eecd |= E1000_EECD_CS;
Joe Perches1dc32912008-07-11 15:17:08 -07003588 ew32(EECD, eecd);
3589 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003590 udelay(eeprom->delay_usec);
3591
3592 /* Clock low */
3593 eecd &= ~E1000_EECD_SK;
Joe Perches1dc32912008-07-11 15:17:08 -07003594 ew32(EECD, eecd);
3595 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003596 udelay(eeprom->delay_usec);
Auke Kok8fc897b2006-08-28 14:56:16 -07003597 } else if (eeprom->type == e1000_eeprom_spi) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003598 /* Toggle CS to flush commands */
3599 eecd |= E1000_EECD_CS;
Joe Perches1dc32912008-07-11 15:17:08 -07003600 ew32(EECD, eecd);
3601 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003602 udelay(eeprom->delay_usec);
3603 eecd &= ~E1000_EECD_CS;
Joe Perches1dc32912008-07-11 15:17:08 -07003604 ew32(EECD, eecd);
3605 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003606 udelay(eeprom->delay_usec);
3607 }
3608}
3609
3610/******************************************************************************
3611 * Terminates a command by inverting the EEPROM's chip select pin
3612 *
3613 * hw - Struct containing variables accessed by shared code
3614 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003615static void e1000_release_eeprom(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003616{
Joe Perches406874a2008-04-03 10:06:32 -07003617 u32 eecd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003618
3619 DEBUGFUNC("e1000_release_eeprom");
3620
Joe Perches1dc32912008-07-11 15:17:08 -07003621 eecd = er32(EECD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003622
3623 if (hw->eeprom.type == e1000_eeprom_spi) {
3624 eecd |= E1000_EECD_CS; /* Pull CS high */
3625 eecd &= ~E1000_EECD_SK; /* Lower SCK */
3626
Joe Perches1dc32912008-07-11 15:17:08 -07003627 ew32(EECD, eecd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003628
3629 udelay(hw->eeprom.delay_usec);
Auke Kok8fc897b2006-08-28 14:56:16 -07003630 } else if (hw->eeprom.type == e1000_eeprom_microwire) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003631 /* cleanup eeprom */
3632
3633 /* CS on Microwire is active-high */
3634 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
3635
Joe Perches1dc32912008-07-11 15:17:08 -07003636 ew32(EECD, eecd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003637
3638 /* Rising edge of clock */
3639 eecd |= E1000_EECD_SK;
Joe Perches1dc32912008-07-11 15:17:08 -07003640 ew32(EECD, eecd);
3641 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003642 udelay(hw->eeprom.delay_usec);
3643
3644 /* Falling edge of clock */
3645 eecd &= ~E1000_EECD_SK;
Joe Perches1dc32912008-07-11 15:17:08 -07003646 ew32(EECD, eecd);
3647 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003648 udelay(hw->eeprom.delay_usec);
3649 }
3650
3651 /* Stop requesting EEPROM access */
Auke Kok8fc897b2006-08-28 14:56:16 -07003652 if (hw->mac_type > e1000_82544) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003653 eecd &= ~E1000_EECD_REQ;
Joe Perches1dc32912008-07-11 15:17:08 -07003654 ew32(EECD, eecd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003655 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003656
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003657 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003658}
3659
3660/******************************************************************************
3661 * Reads a 16 bit word from the EEPROM.
3662 *
3663 * hw - Struct containing variables accessed by shared code
3664 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003665static s32 e1000_spi_eeprom_ready(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003666{
Joe Perches406874a2008-04-03 10:06:32 -07003667 u16 retry_count = 0;
3668 u8 spi_stat_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003669
3670 DEBUGFUNC("e1000_spi_eeprom_ready");
3671
3672 /* Read "Status Register" repeatedly until the LSB is cleared. The
3673 * EEPROM will signal that the command has been completed by clearing
3674 * bit 0 of the internal status register. If it's not cleared within
3675 * 5 milliseconds, then error out.
3676 */
3677 retry_count = 0;
3678 do {
3679 e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
3680 hw->eeprom.opcode_bits);
Joe Perches406874a2008-04-03 10:06:32 -07003681 spi_stat_reg = (u8)e1000_shift_in_ee_bits(hw, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003682 if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
3683 break;
3684
3685 udelay(5);
3686 retry_count += 5;
3687
3688 e1000_standby_eeprom(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07003689 } while (retry_count < EEPROM_MAX_RETRY_SPI);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003690
3691 /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
3692 * only 0-5mSec on 5V devices)
3693 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003694 if (retry_count >= EEPROM_MAX_RETRY_SPI) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003695 DEBUGOUT("SPI EEPROM Status error\n");
3696 return -E1000_ERR_EEPROM;
3697 }
3698
3699 return E1000_SUCCESS;
3700}
3701
3702/******************************************************************************
3703 * Reads a 16 bit word from the EEPROM.
3704 *
3705 * hw - Struct containing variables accessed by shared code
3706 * offset - offset of word in the EEPROM to read
3707 * data - word read from the EEPROM
3708 * words - number of words to read
3709 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003710s32 e1000_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003711{
Christopher Li78566fe2008-09-05 14:04:05 -07003712 s32 ret;
3713 spin_lock(&e1000_eeprom_lock);
3714 ret = e1000_do_read_eeprom(hw, offset, words, data);
3715 spin_unlock(&e1000_eeprom_lock);
3716 return ret;
3717}
3718
3719static s32 e1000_do_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
3720{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003721 struct e1000_eeprom_info *eeprom = &hw->eeprom;
Joe Perches406874a2008-04-03 10:06:32 -07003722 u32 i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003723
3724 DEBUGFUNC("e1000_read_eeprom");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003725
Jeff Kirsher2a88c172006-09-27 12:54:05 -07003726 /* If eeprom is not yet detected, do so now */
3727 if (eeprom->word_size == 0)
3728 e1000_init_eeprom_params(hw);
3729
Linus Torvalds1da177e2005-04-16 15:20:36 -07003730 /* A check for invalid values: offset too large, too many words, and not
3731 * enough words.
3732 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003733 if ((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07003734 (words == 0)) {
Jeff Kirsher2a88c172006-09-27 12:54:05 -07003735 DEBUGOUT2("\"words\" parameter out of bounds. Words = %d, size = %d\n", offset, eeprom->word_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003736 return -E1000_ERR_EEPROM;
3737 }
3738
Jeff Kirsher2a88c172006-09-27 12:54:05 -07003739 /* EEPROM's that don't use EERD to read require us to bit-bang the SPI
3740 * directly. In this case, we need to acquire the EEPROM so that
3741 * FW or other port software does not interrupt.
3742 */
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00003743 if (!hw->eeprom.use_eerd) {
Jeff Kirsher2a88c172006-09-27 12:54:05 -07003744 /* Prepare the EEPROM for bit-bang reading */
3745 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
3746 return -E1000_ERR_EEPROM;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003747 }
3748
Jeff Kirsher2a88c172006-09-27 12:54:05 -07003749 /* Eerd register EEPROM access requires no eeprom aquire/release */
Joe Perchesc3033b02008-03-21 11:06:25 -07003750 if (eeprom->use_eerd)
Jeff Kirsher2a88c172006-09-27 12:54:05 -07003751 return e1000_read_eeprom_eerd(hw, offset, words, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003752
Jeff Kirsher2a88c172006-09-27 12:54:05 -07003753 /* Set up the SPI or Microwire EEPROM for bit-bang reading. We have
3754 * acquired the EEPROM at this point, so any returns should relase it */
Auke Kokcd94dd02006-06-27 09:08:22 -07003755 if (eeprom->type == e1000_eeprom_spi) {
Joe Perches406874a2008-04-03 10:06:32 -07003756 u16 word_in;
3757 u8 read_opcode = EEPROM_READ_OPCODE_SPI;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003758
Auke Kok8fc897b2006-08-28 14:56:16 -07003759 if (e1000_spi_eeprom_ready(hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003760 e1000_release_eeprom(hw);
3761 return -E1000_ERR_EEPROM;
3762 }
3763
3764 e1000_standby_eeprom(hw);
3765
3766 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
Auke Kok8fc897b2006-08-28 14:56:16 -07003767 if ((eeprom->address_bits == 8) && (offset >= 128))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003768 read_opcode |= EEPROM_A8_OPCODE_SPI;
3769
3770 /* Send the READ command (opcode + addr) */
3771 e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
Joe Perches406874a2008-04-03 10:06:32 -07003772 e1000_shift_out_ee_bits(hw, (u16)(offset*2), eeprom->address_bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003773
3774 /* Read the data. The address of the eeprom internally increments with
3775 * each byte (spi) being read, saving on the overhead of eeprom setup
3776 * and tear-down. The address counter will roll over if reading beyond
3777 * the size of the eeprom, thus allowing the entire memory to be read
3778 * starting from any offset. */
3779 for (i = 0; i < words; i++) {
3780 word_in = e1000_shift_in_ee_bits(hw, 16);
3781 data[i] = (word_in >> 8) | (word_in << 8);
3782 }
Auke Kok8fc897b2006-08-28 14:56:16 -07003783 } else if (eeprom->type == e1000_eeprom_microwire) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003784 for (i = 0; i < words; i++) {
3785 /* Send the READ command (opcode + addr) */
3786 e1000_shift_out_ee_bits(hw, EEPROM_READ_OPCODE_MICROWIRE,
3787 eeprom->opcode_bits);
Joe Perches406874a2008-04-03 10:06:32 -07003788 e1000_shift_out_ee_bits(hw, (u16)(offset + i),
Linus Torvalds1da177e2005-04-16 15:20:36 -07003789 eeprom->address_bits);
3790
3791 /* Read the data. For microwire, each word requires the overhead
3792 * of eeprom setup and tear-down. */
3793 data[i] = e1000_shift_in_ee_bits(hw, 16);
3794 e1000_standby_eeprom(hw);
3795 }
3796 }
3797
3798 /* End this read operation */
3799 e1000_release_eeprom(hw);
3800
3801 return E1000_SUCCESS;
3802}
3803
3804/******************************************************************************
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003805 * Reads a 16 bit word from the EEPROM using the EERD register.
3806 *
3807 * hw - Struct containing variables accessed by shared code
3808 * offset - offset of word in the EEPROM to read
3809 * data - word read from the EEPROM
3810 * words - number of words to read
3811 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003812static s32 e1000_read_eeprom_eerd(struct e1000_hw *hw, u16 offset, u16 words,
3813 u16 *data)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003814{
Joe Perches406874a2008-04-03 10:06:32 -07003815 u32 i, eerd = 0;
3816 s32 error = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003817
3818 for (i = 0; i < words; i++) {
3819 eerd = ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) +
3820 E1000_EEPROM_RW_REG_START;
3821
Joe Perches1dc32912008-07-11 15:17:08 -07003822 ew32(EERD, eerd);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003823 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_READ);
Auke Kok76c224b2006-05-23 13:36:06 -07003824
Auke Kok8fc897b2006-08-28 14:56:16 -07003825 if (error) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003826 break;
3827 }
Joe Perches1dc32912008-07-11 15:17:08 -07003828 data[i] = (er32(EERD) >> E1000_EEPROM_RW_REG_DATA);
Auke Kok76c224b2006-05-23 13:36:06 -07003829
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003830 }
Auke Kok76c224b2006-05-23 13:36:06 -07003831
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003832 return error;
3833}
3834
3835/******************************************************************************
3836 * Writes a 16 bit word from the EEPROM using the EEWR register.
3837 *
3838 * hw - Struct containing variables accessed by shared code
3839 * offset - offset of word in the EEPROM to read
3840 * data - word read from the EEPROM
3841 * words - number of words to read
3842 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003843static s32 e1000_write_eeprom_eewr(struct e1000_hw *hw, u16 offset, u16 words,
3844 u16 *data)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003845{
Joe Perches406874a2008-04-03 10:06:32 -07003846 u32 register_value = 0;
3847 u32 i = 0;
3848 s32 error = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003849
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003850 if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
3851 return -E1000_ERR_SWFW_SYNC;
3852
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003853 for (i = 0; i < words; i++) {
Auke Kok76c224b2006-05-23 13:36:06 -07003854 register_value = (data[i] << E1000_EEPROM_RW_REG_DATA) |
3855 ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) |
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003856 E1000_EEPROM_RW_REG_START;
3857
3858 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
Auke Kok8fc897b2006-08-28 14:56:16 -07003859 if (error) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003860 break;
Auke Kok76c224b2006-05-23 13:36:06 -07003861 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003862
Joe Perches1dc32912008-07-11 15:17:08 -07003863 ew32(EEWR, register_value);
Auke Kok76c224b2006-05-23 13:36:06 -07003864
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003865 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
Auke Kok76c224b2006-05-23 13:36:06 -07003866
Auke Kok8fc897b2006-08-28 14:56:16 -07003867 if (error) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003868 break;
Auke Kok76c224b2006-05-23 13:36:06 -07003869 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003870 }
Auke Kok76c224b2006-05-23 13:36:06 -07003871
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003872 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003873 return error;
3874}
3875
3876/******************************************************************************
3877 * Polls the status bit (bit 1) of the EERD to determine when the read is done.
3878 *
3879 * hw - Struct containing variables accessed by shared code
3880 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003881static s32 e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003882{
Joe Perches406874a2008-04-03 10:06:32 -07003883 u32 attempts = 100000;
3884 u32 i, reg = 0;
3885 s32 done = E1000_ERR_EEPROM;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003886
Auke Kok8fc897b2006-08-28 14:56:16 -07003887 for (i = 0; i < attempts; i++) {
3888 if (eerd == E1000_EEPROM_POLL_READ)
Joe Perches1dc32912008-07-11 15:17:08 -07003889 reg = er32(EERD);
Auke Kok76c224b2006-05-23 13:36:06 -07003890 else
Joe Perches1dc32912008-07-11 15:17:08 -07003891 reg = er32(EEWR);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003892
Auke Kok8fc897b2006-08-28 14:56:16 -07003893 if (reg & E1000_EEPROM_RW_REG_DONE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003894 done = E1000_SUCCESS;
3895 break;
3896 }
3897 udelay(5);
3898 }
3899
3900 return done;
3901}
3902
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003903/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07003904 * Verifies that the EEPROM has a valid checksum
3905 *
3906 * hw - Struct containing variables accessed by shared code
3907 *
3908 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
3909 * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
3910 * valid.
3911 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003912s32 e1000_validate_eeprom_checksum(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003913{
Joe Perches406874a2008-04-03 10:06:32 -07003914 u16 checksum = 0;
3915 u16 i, eeprom_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003916
3917 DEBUGFUNC("e1000_validate_eeprom_checksum");
3918
Auke Kokcd94dd02006-06-27 09:08:22 -07003919 for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
3920 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003921 DEBUGOUT("EEPROM Read Error\n");
3922 return -E1000_ERR_EEPROM;
3923 }
3924 checksum += eeprom_data;
3925 }
3926
Joe Perchese982f172008-07-11 15:17:18 -07003927 if (checksum == (u16)EEPROM_SUM)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003928 return E1000_SUCCESS;
3929 else {
3930 DEBUGOUT("EEPROM Checksum Invalid\n");
3931 return -E1000_ERR_EEPROM;
3932 }
3933}
3934
3935/******************************************************************************
3936 * Calculates the EEPROM checksum and writes it to the EEPROM
3937 *
3938 * hw - Struct containing variables accessed by shared code
3939 *
3940 * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA.
3941 * Writes the difference to word offset 63 of the EEPROM.
3942 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003943s32 e1000_update_eeprom_checksum(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003944{
Joe Perches406874a2008-04-03 10:06:32 -07003945 u16 checksum = 0;
3946 u16 i, eeprom_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003947
3948 DEBUGFUNC("e1000_update_eeprom_checksum");
3949
Auke Kok8fc897b2006-08-28 14:56:16 -07003950 for (i = 0; i < EEPROM_CHECKSUM_REG; i++) {
3951 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003952 DEBUGOUT("EEPROM Read Error\n");
3953 return -E1000_ERR_EEPROM;
3954 }
3955 checksum += eeprom_data;
3956 }
Joe Perchese982f172008-07-11 15:17:18 -07003957 checksum = (u16)EEPROM_SUM - checksum;
Auke Kok8fc897b2006-08-28 14:56:16 -07003958 if (e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003959 DEBUGOUT("EEPROM Write Error\n");
3960 return -E1000_ERR_EEPROM;
3961 }
3962 return E1000_SUCCESS;
3963}
3964
3965/******************************************************************************
3966 * Parent function for writing words to the different EEPROM types.
3967 *
3968 * hw - Struct containing variables accessed by shared code
3969 * offset - offset within the EEPROM to be written to
3970 * words - number of words to write
3971 * data - 16 bit word to be written to the EEPROM
3972 *
3973 * If e1000_update_eeprom_checksum is not called after this function, the
3974 * EEPROM will most likely contain an invalid checksum.
3975 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07003976s32 e1000_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003977{
Christopher Li78566fe2008-09-05 14:04:05 -07003978 s32 ret;
3979 spin_lock(&e1000_eeprom_lock);
3980 ret = e1000_do_write_eeprom(hw, offset, words, data);
3981 spin_unlock(&e1000_eeprom_lock);
3982 return ret;
3983}
3984
3985
3986static s32 e1000_do_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
3987{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003988 struct e1000_eeprom_info *eeprom = &hw->eeprom;
Joe Perches406874a2008-04-03 10:06:32 -07003989 s32 status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003990
3991 DEBUGFUNC("e1000_write_eeprom");
3992
Jeff Kirsher2a88c172006-09-27 12:54:05 -07003993 /* If eeprom is not yet detected, do so now */
3994 if (eeprom->word_size == 0)
3995 e1000_init_eeprom_params(hw);
3996
Linus Torvalds1da177e2005-04-16 15:20:36 -07003997 /* A check for invalid values: offset too large, too many words, and not
3998 * enough words.
3999 */
Auke Kok8fc897b2006-08-28 14:56:16 -07004000 if ((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07004001 (words == 0)) {
4002 DEBUGOUT("\"words\" parameter out of bounds\n");
4003 return -E1000_ERR_EEPROM;
4004 }
4005
Joe Perchesc3033b02008-03-21 11:06:25 -07004006 if (eeprom->use_eewr)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004007 return e1000_write_eeprom_eewr(hw, offset, words, data);
4008
Linus Torvalds1da177e2005-04-16 15:20:36 -07004009 /* Prepare the EEPROM for writing */
4010 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
4011 return -E1000_ERR_EEPROM;
4012
Auke Kok8fc897b2006-08-28 14:56:16 -07004013 if (eeprom->type == e1000_eeprom_microwire) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004014 status = e1000_write_eeprom_microwire(hw, offset, words, data);
4015 } else {
4016 status = e1000_write_eeprom_spi(hw, offset, words, data);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04004017 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004018 }
4019
4020 /* Done with writing */
4021 e1000_release_eeprom(hw);
4022
4023 return status;
4024}
4025
4026/******************************************************************************
4027 * Writes a 16 bit word to a given offset in an SPI EEPROM.
4028 *
4029 * hw - Struct containing variables accessed by shared code
4030 * offset - offset within the EEPROM to be written to
4031 * words - number of words to write
4032 * data - pointer to array of 8 bit words to be written to the EEPROM
4033 *
4034 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004035static s32 e1000_write_eeprom_spi(struct e1000_hw *hw, u16 offset, u16 words,
4036 u16 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004037{
4038 struct e1000_eeprom_info *eeprom = &hw->eeprom;
Joe Perches406874a2008-04-03 10:06:32 -07004039 u16 widx = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004040
4041 DEBUGFUNC("e1000_write_eeprom_spi");
4042
4043 while (widx < words) {
Joe Perches406874a2008-04-03 10:06:32 -07004044 u8 write_opcode = EEPROM_WRITE_OPCODE_SPI;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004045
Auke Kok8fc897b2006-08-28 14:56:16 -07004046 if (e1000_spi_eeprom_ready(hw)) return -E1000_ERR_EEPROM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004047
4048 e1000_standby_eeprom(hw);
4049
4050 /* Send the WRITE ENABLE command (8 bit opcode ) */
4051 e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI,
4052 eeprom->opcode_bits);
4053
4054 e1000_standby_eeprom(hw);
4055
4056 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
Auke Kok8fc897b2006-08-28 14:56:16 -07004057 if ((eeprom->address_bits == 8) && (offset >= 128))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004058 write_opcode |= EEPROM_A8_OPCODE_SPI;
4059
4060 /* Send the Write command (8-bit opcode + addr) */
4061 e1000_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits);
4062
Joe Perches406874a2008-04-03 10:06:32 -07004063 e1000_shift_out_ee_bits(hw, (u16)((offset + widx)*2),
Linus Torvalds1da177e2005-04-16 15:20:36 -07004064 eeprom->address_bits);
4065
4066 /* Send the data */
4067
4068 /* Loop to allow for up to whole page write (32 bytes) of eeprom */
4069 while (widx < words) {
Joe Perches406874a2008-04-03 10:06:32 -07004070 u16 word_out = data[widx];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004071 word_out = (word_out >> 8) | (word_out << 8);
4072 e1000_shift_out_ee_bits(hw, word_out, 16);
4073 widx++;
4074
4075 /* Some larger eeprom sizes are capable of a 32-byte PAGE WRITE
4076 * operation, while the smaller eeproms are capable of an 8-byte
4077 * PAGE WRITE operation. Break the inner loop to pass new address
4078 */
Auke Kok8fc897b2006-08-28 14:56:16 -07004079 if ((((offset + widx)*2) % eeprom->page_size) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004080 e1000_standby_eeprom(hw);
4081 break;
4082 }
4083 }
4084 }
4085
4086 return E1000_SUCCESS;
4087}
4088
4089/******************************************************************************
4090 * Writes a 16 bit word to a given offset in a Microwire EEPROM.
4091 *
4092 * hw - Struct containing variables accessed by shared code
4093 * offset - offset within the EEPROM to be written to
4094 * words - number of words to write
4095 * data - pointer to array of 16 bit words to be written to the EEPROM
4096 *
4097 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004098static s32 e1000_write_eeprom_microwire(struct e1000_hw *hw, u16 offset,
4099 u16 words, u16 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004100{
4101 struct e1000_eeprom_info *eeprom = &hw->eeprom;
Joe Perches406874a2008-04-03 10:06:32 -07004102 u32 eecd;
4103 u16 words_written = 0;
4104 u16 i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004105
4106 DEBUGFUNC("e1000_write_eeprom_microwire");
4107
4108 /* Send the write enable command to the EEPROM (3-bit opcode plus
4109 * 6/8-bit dummy address beginning with 11). It's less work to include
4110 * the 11 of the dummy address as part of the opcode than it is to shift
4111 * it over the correct number of bits for the address. This puts the
4112 * EEPROM into write/erase mode.
4113 */
4114 e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE,
Joe Perches406874a2008-04-03 10:06:32 -07004115 (u16)(eeprom->opcode_bits + 2));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004116
Joe Perches406874a2008-04-03 10:06:32 -07004117 e1000_shift_out_ee_bits(hw, 0, (u16)(eeprom->address_bits - 2));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004118
4119 /* Prepare the EEPROM */
4120 e1000_standby_eeprom(hw);
4121
4122 while (words_written < words) {
4123 /* Send the Write command (3-bit opcode + addr) */
4124 e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE,
4125 eeprom->opcode_bits);
4126
Joe Perches406874a2008-04-03 10:06:32 -07004127 e1000_shift_out_ee_bits(hw, (u16)(offset + words_written),
Linus Torvalds1da177e2005-04-16 15:20:36 -07004128 eeprom->address_bits);
4129
4130 /* Send the data */
4131 e1000_shift_out_ee_bits(hw, data[words_written], 16);
4132
4133 /* Toggle the CS line. This in effect tells the EEPROM to execute
4134 * the previous command.
4135 */
4136 e1000_standby_eeprom(hw);
4137
4138 /* Read DO repeatedly until it is high (equal to '1'). The EEPROM will
4139 * signal that the command has been completed by raising the DO signal.
4140 * If DO does not go high in 10 milliseconds, then error out.
4141 */
Auke Kok8fc897b2006-08-28 14:56:16 -07004142 for (i = 0; i < 200; i++) {
Joe Perches1dc32912008-07-11 15:17:08 -07004143 eecd = er32(EECD);
Auke Kok8fc897b2006-08-28 14:56:16 -07004144 if (eecd & E1000_EECD_DO) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004145 udelay(50);
4146 }
Auke Kok8fc897b2006-08-28 14:56:16 -07004147 if (i == 200) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004148 DEBUGOUT("EEPROM Write did not complete\n");
4149 return -E1000_ERR_EEPROM;
4150 }
4151
4152 /* Recover from write */
4153 e1000_standby_eeprom(hw);
4154
4155 words_written++;
4156 }
4157
4158 /* Send the write disable command to the EEPROM (3-bit opcode plus
4159 * 6/8-bit dummy address beginning with 10). It's less work to include
4160 * the 10 of the dummy address as part of the opcode than it is to shift
4161 * it over the correct number of bits for the address. This takes the
4162 * EEPROM out of write/erase mode.
4163 */
4164 e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE,
Joe Perches406874a2008-04-03 10:06:32 -07004165 (u16)(eeprom->opcode_bits + 2));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004166
Joe Perches406874a2008-04-03 10:06:32 -07004167 e1000_shift_out_ee_bits(hw, 0, (u16)(eeprom->address_bits - 2));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004168
4169 return E1000_SUCCESS;
4170}
4171
4172/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07004173 * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
4174 * second function of dual function devices
4175 *
4176 * hw - Struct containing variables accessed by shared code
4177 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004178s32 e1000_read_mac_addr(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004179{
Joe Perches406874a2008-04-03 10:06:32 -07004180 u16 offset;
4181 u16 eeprom_data, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004182
4183 DEBUGFUNC("e1000_read_mac_addr");
4184
Auke Kok8fc897b2006-08-28 14:56:16 -07004185 for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004186 offset = i >> 1;
Auke Kok8fc897b2006-08-28 14:56:16 -07004187 if (e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004188 DEBUGOUT("EEPROM Read Error\n");
4189 return -E1000_ERR_EEPROM;
4190 }
Joe Perchese982f172008-07-11 15:17:18 -07004191 hw->perm_mac_addr[i] = (u8)(eeprom_data & 0x00FF);
4192 hw->perm_mac_addr[i+1] = (u8)(eeprom_data >> 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004193 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004194
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004195 switch (hw->mac_type) {
4196 default:
4197 break;
4198 case e1000_82546:
4199 case e1000_82546_rev_3:
Joe Perches1dc32912008-07-11 15:17:08 -07004200 if (er32(STATUS) & E1000_STATUS_FUNC_1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004201 hw->perm_mac_addr[5] ^= 0x01;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004202 break;
4203 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004204
Auke Kok8fc897b2006-08-28 14:56:16 -07004205 for (i = 0; i < NODE_ADDRESS_SIZE; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004206 hw->mac_addr[i] = hw->perm_mac_addr[i];
4207 return E1000_SUCCESS;
4208}
4209
4210/******************************************************************************
4211 * Initializes receive address filters.
4212 *
4213 * hw - Struct containing variables accessed by shared code
4214 *
4215 * Places the MAC address in receive address register 0 and clears the rest
4216 * of the receive addresss registers. Clears the multicast table. Assumes
4217 * the receiver is in reset when the routine is called.
4218 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004219static void e1000_init_rx_addrs(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004220{
Joe Perches406874a2008-04-03 10:06:32 -07004221 u32 i;
4222 u32 rar_num;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004223
4224 DEBUGFUNC("e1000_init_rx_addrs");
4225
4226 /* Setup the receive address. */
4227 DEBUGOUT("Programming MAC Address into RAR[0]\n");
4228
4229 e1000_rar_set(hw, hw->mac_addr, 0);
4230
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004231 rar_num = E1000_RAR_ENTRIES;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004232
Linus Torvalds1da177e2005-04-16 15:20:36 -07004233 /* Zero out the other 15 receive addresses. */
4234 DEBUGOUT("Clearing RAR[1-15]\n");
Auke Kok8fc897b2006-08-28 14:56:16 -07004235 for (i = 1; i < rar_num; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004236 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
Joe Perches1dc32912008-07-11 15:17:08 -07004237 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07004238 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
Joe Perches1dc32912008-07-11 15:17:08 -07004239 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07004240 }
4241}
4242
4243/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07004244 * Hashes an address to determine its location in the multicast table
4245 *
4246 * hw - Struct containing variables accessed by shared code
4247 * mc_addr - the multicast address to hash
4248 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004249u32 e1000_hash_mc_addr(struct e1000_hw *hw, u8 *mc_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004250{
Joe Perches406874a2008-04-03 10:06:32 -07004251 u32 hash_value = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004252
4253 /* The portion of the address that is used for the hash table is
4254 * determined by the mc_filter_type setting.
4255 */
4256 switch (hw->mc_filter_type) {
4257 /* [0] [1] [2] [3] [4] [5]
4258 * 01 AA 00 12 34 56
4259 * LSB MSB
4260 */
4261 case 0:
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00004262 /* [47:36] i.e. 0x563 for above example address */
4263 hash_value = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004264 break;
4265 case 1:
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00004266 /* [46:35] i.e. 0xAC6 for above example address */
4267 hash_value = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004268 break;
4269 case 2:
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00004270 /* [45:34] i.e. 0x5D8 for above example address */
4271 hash_value = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004272 break;
4273 case 3:
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00004274 /* [43:32] i.e. 0x634 for above example address */
4275 hash_value = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004276 break;
4277 }
4278
4279 hash_value &= 0xFFF;
4280 return hash_value;
4281}
4282
4283/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07004284 * Puts an ethernet address into a receive address register.
4285 *
4286 * hw - Struct containing variables accessed by shared code
4287 * addr - Address to put into receive address register
4288 * index - Receive address register to write
4289 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004290void e1000_rar_set(struct e1000_hw *hw, u8 *addr, u32 index)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004291{
Joe Perches406874a2008-04-03 10:06:32 -07004292 u32 rar_low, rar_high;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004293
4294 /* HW expects these in little endian so we reverse the byte order
4295 * from network order (big endian) to little endian
4296 */
Joe Perchese982f172008-07-11 15:17:18 -07004297 rar_low = ((u32)addr[0] | ((u32)addr[1] << 8) |
4298 ((u32)addr[2] << 16) | ((u32)addr[3] << 24));
4299 rar_high = ((u32)addr[4] | ((u32)addr[5] << 8));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004300
Jeff Kirsher8df06e52006-03-02 18:18:32 -08004301 /* Disable Rx and flush all Rx frames before enabling RSS to avoid Rx
4302 * unit hang.
4303 *
4304 * Description:
4305 * If there are any Rx frames queued up or otherwise present in the HW
4306 * before RSS is enabled, and then we enable RSS, the HW Rx unit will
4307 * hang. To work around this issue, we have to disable receives and
4308 * flush out all Rx frames before we enable RSS. To do so, we modify we
4309 * redirect all Rx traffic to manageability and then reset the HW.
4310 * This flushes away Rx frames, and (since the redirections to
4311 * manageability persists across resets) keeps new ones from coming in
4312 * while we work. Then, we clear the Address Valid AV bit for all MAC
4313 * addresses and undo the re-direction to manageability.
4314 * Now, frames are coming in again, but the MAC won't accept them, so
4315 * far so good. We now proceed to initialize RSS (if necessary) and
4316 * configure the Rx unit. Last, we re-enable the AV bits and continue
4317 * on our merry way.
4318 */
4319 switch (hw->mac_type) {
Jeff Kirsher8df06e52006-03-02 18:18:32 -08004320 default:
4321 /* Indicate to hardware the Address is Valid. */
4322 rar_high |= E1000_RAH_AV;
4323 break;
4324 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004325
4326 E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
Joe Perches1dc32912008-07-11 15:17:08 -07004327 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07004328 E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
Joe Perches1dc32912008-07-11 15:17:08 -07004329 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07004330}
4331
4332/******************************************************************************
4333 * Writes a value to the specified offset in the VLAN filter table.
4334 *
4335 * hw - Struct containing variables accessed by shared code
4336 * offset - Offset in VLAN filer table to write
4337 * value - Value to write into VLAN filter table
4338 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004339void e1000_write_vfta(struct e1000_hw *hw, u32 offset, u32 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004340{
Joe Perches406874a2008-04-03 10:06:32 -07004341 u32 temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004342
Auke Kokcd94dd02006-06-27 09:08:22 -07004343 if ((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004344 temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1));
4345 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
Joe Perches1dc32912008-07-11 15:17:08 -07004346 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07004347 E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp);
Joe Perches1dc32912008-07-11 15:17:08 -07004348 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07004349 } else {
4350 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
Joe Perches1dc32912008-07-11 15:17:08 -07004351 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07004352 }
4353}
4354
4355/******************************************************************************
4356 * Clears the VLAN filer table
4357 *
4358 * hw - Struct containing variables accessed by shared code
4359 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004360static void e1000_clear_vfta(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004361{
Joe Perches406874a2008-04-03 10:06:32 -07004362 u32 offset;
4363 u32 vfta_value = 0;
4364 u32 vfta_offset = 0;
4365 u32 vfta_bit_in_reg = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004366
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004367 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
4368 /* If the offset we want to clear is the same offset of the
4369 * manageability VLAN ID, then clear all bits except that of the
4370 * manageability unit */
4371 vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0;
4372 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, vfta_value);
Joe Perches1dc32912008-07-11 15:17:08 -07004373 E1000_WRITE_FLUSH();
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004374 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004375}
4376
Joe Perches64798842008-07-11 15:17:02 -07004377static s32 e1000_id_led_init(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004378{
Joe Perches406874a2008-04-03 10:06:32 -07004379 u32 ledctl;
4380 const u32 ledctl_mask = 0x000000FF;
4381 const u32 ledctl_on = E1000_LEDCTL_MODE_LED_ON;
4382 const u32 ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
4383 u16 eeprom_data, i, temp;
4384 const u16 led_mask = 0x0F;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004385
4386 DEBUGFUNC("e1000_id_led_init");
4387
Auke Kok8fc897b2006-08-28 14:56:16 -07004388 if (hw->mac_type < e1000_82540) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004389 /* Nothing to do */
4390 return E1000_SUCCESS;
4391 }
4392
Joe Perches1dc32912008-07-11 15:17:08 -07004393 ledctl = er32(LEDCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004394 hw->ledctl_default = ledctl;
4395 hw->ledctl_mode1 = hw->ledctl_default;
4396 hw->ledctl_mode2 = hw->ledctl_default;
4397
Auke Kok8fc897b2006-08-28 14:56:16 -07004398 if (e1000_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, 1, &eeprom_data) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004399 DEBUGOUT("EEPROM Read Error\n");
4400 return -E1000_ERR_EEPROM;
4401 }
Auke Kokcd94dd02006-06-27 09:08:22 -07004402
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00004403 if ((eeprom_data == ID_LED_RESERVED_0000) ||
Auke Kokcd94dd02006-06-27 09:08:22 -07004404 (eeprom_data == ID_LED_RESERVED_FFFF)) {
Auke Kokcd94dd02006-06-27 09:08:22 -07004405 eeprom_data = ID_LED_DEFAULT;
4406 }
Auke Kok90fb5132006-11-01 08:47:30 -08004407
Auke Kokcd94dd02006-06-27 09:08:22 -07004408 for (i = 0; i < 4; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004409 temp = (eeprom_data >> (i << 2)) & led_mask;
Auke Kok8fc897b2006-08-28 14:56:16 -07004410 switch (temp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004411 case ID_LED_ON1_DEF2:
4412 case ID_LED_ON1_ON2:
4413 case ID_LED_ON1_OFF2:
4414 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
4415 hw->ledctl_mode1 |= ledctl_on << (i << 3);
4416 break;
4417 case ID_LED_OFF1_DEF2:
4418 case ID_LED_OFF1_ON2:
4419 case ID_LED_OFF1_OFF2:
4420 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
4421 hw->ledctl_mode1 |= ledctl_off << (i << 3);
4422 break;
4423 default:
4424 /* Do nothing */
4425 break;
4426 }
Auke Kok8fc897b2006-08-28 14:56:16 -07004427 switch (temp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004428 case ID_LED_DEF1_ON2:
4429 case ID_LED_ON1_ON2:
4430 case ID_LED_OFF1_ON2:
4431 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
4432 hw->ledctl_mode2 |= ledctl_on << (i << 3);
4433 break;
4434 case ID_LED_DEF1_OFF2:
4435 case ID_LED_ON1_OFF2:
4436 case ID_LED_OFF1_OFF2:
4437 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
4438 hw->ledctl_mode2 |= ledctl_off << (i << 3);
4439 break;
4440 default:
4441 /* Do nothing */
4442 break;
4443 }
4444 }
4445 return E1000_SUCCESS;
4446}
4447
4448/******************************************************************************
4449 * Prepares SW controlable LED for use and saves the current state of the LED.
4450 *
4451 * hw - Struct containing variables accessed by shared code
4452 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004453s32 e1000_setup_led(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004454{
Joe Perches406874a2008-04-03 10:06:32 -07004455 u32 ledctl;
4456 s32 ret_val = E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004457
4458 DEBUGFUNC("e1000_setup_led");
4459
Auke Kok8fc897b2006-08-28 14:56:16 -07004460 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004461 case e1000_82542_rev2_0:
4462 case e1000_82542_rev2_1:
4463 case e1000_82543:
4464 case e1000_82544:
4465 /* No setup necessary */
4466 break;
4467 case e1000_82541:
4468 case e1000_82547:
4469 case e1000_82541_rev_2:
4470 case e1000_82547_rev_2:
4471 /* Turn off PHY Smart Power Down (if enabled) */
4472 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
4473 &hw->phy_spd_default);
Auke Kok8fc897b2006-08-28 14:56:16 -07004474 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004475 return ret_val;
4476 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
Joe Perches406874a2008-04-03 10:06:32 -07004477 (u16)(hw->phy_spd_default &
Linus Torvalds1da177e2005-04-16 15:20:36 -07004478 ~IGP01E1000_GMII_SPD));
Auke Kok8fc897b2006-08-28 14:56:16 -07004479 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004480 return ret_val;
4481 /* Fall Through */
4482 default:
Auke Kok8fc897b2006-08-28 14:56:16 -07004483 if (hw->media_type == e1000_media_type_fiber) {
Joe Perches1dc32912008-07-11 15:17:08 -07004484 ledctl = er32(LEDCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004485 /* Save current LEDCTL settings */
4486 hw->ledctl_default = ledctl;
4487 /* Turn off LED0 */
4488 ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
4489 E1000_LEDCTL_LED0_BLINK |
4490 E1000_LEDCTL_LED0_MODE_MASK);
4491 ledctl |= (E1000_LEDCTL_MODE_LED_OFF <<
4492 E1000_LEDCTL_LED0_MODE_SHIFT);
Joe Perches1dc32912008-07-11 15:17:08 -07004493 ew32(LEDCTL, ledctl);
Auke Kok8fc897b2006-08-28 14:56:16 -07004494 } else if (hw->media_type == e1000_media_type_copper)
Joe Perches1dc32912008-07-11 15:17:08 -07004495 ew32(LEDCTL, hw->ledctl_mode1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004496 break;
4497 }
4498
4499 return E1000_SUCCESS;
4500}
4501
Auke Kokf1b3a852006-06-27 09:07:56 -07004502/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07004503 * Restores the saved state of the SW controlable LED.
4504 *
4505 * hw - Struct containing variables accessed by shared code
4506 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004507s32 e1000_cleanup_led(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004508{
Joe Perches406874a2008-04-03 10:06:32 -07004509 s32 ret_val = E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004510
4511 DEBUGFUNC("e1000_cleanup_led");
4512
Auke Kok8fc897b2006-08-28 14:56:16 -07004513 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004514 case e1000_82542_rev2_0:
4515 case e1000_82542_rev2_1:
4516 case e1000_82543:
4517 case e1000_82544:
4518 /* No cleanup necessary */
4519 break;
4520 case e1000_82541:
4521 case e1000_82547:
4522 case e1000_82541_rev_2:
4523 case e1000_82547_rev_2:
4524 /* Turn on PHY Smart Power Down (if previously enabled) */
4525 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
4526 hw->phy_spd_default);
Auke Kok8fc897b2006-08-28 14:56:16 -07004527 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004528 return ret_val;
4529 /* Fall Through */
4530 default:
4531 /* Restore LEDCTL settings */
Joe Perches1dc32912008-07-11 15:17:08 -07004532 ew32(LEDCTL, hw->ledctl_default);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004533 break;
4534 }
4535
4536 return E1000_SUCCESS;
4537}
4538
4539/******************************************************************************
4540 * Turns on the software controllable LED
4541 *
4542 * hw - Struct containing variables accessed by shared code
4543 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004544s32 e1000_led_on(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004545{
Joe Perches1dc32912008-07-11 15:17:08 -07004546 u32 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004547
4548 DEBUGFUNC("e1000_led_on");
4549
Auke Kok8fc897b2006-08-28 14:56:16 -07004550 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004551 case e1000_82542_rev2_0:
4552 case e1000_82542_rev2_1:
4553 case e1000_82543:
4554 /* Set SW Defineable Pin 0 to turn on the LED */
4555 ctrl |= E1000_CTRL_SWDPIN0;
4556 ctrl |= E1000_CTRL_SWDPIO0;
4557 break;
4558 case e1000_82544:
Auke Kok8fc897b2006-08-28 14:56:16 -07004559 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004560 /* Set SW Defineable Pin 0 to turn on the LED */
4561 ctrl |= E1000_CTRL_SWDPIN0;
4562 ctrl |= E1000_CTRL_SWDPIO0;
4563 } else {
4564 /* Clear SW Defineable Pin 0 to turn on the LED */
4565 ctrl &= ~E1000_CTRL_SWDPIN0;
4566 ctrl |= E1000_CTRL_SWDPIO0;
4567 }
4568 break;
4569 default:
Auke Kok8fc897b2006-08-28 14:56:16 -07004570 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004571 /* Clear SW Defineable Pin 0 to turn on the LED */
4572 ctrl &= ~E1000_CTRL_SWDPIN0;
4573 ctrl |= E1000_CTRL_SWDPIO0;
Auke Kokcd94dd02006-06-27 09:08:22 -07004574 } else if (hw->media_type == e1000_media_type_copper) {
Joe Perches1dc32912008-07-11 15:17:08 -07004575 ew32(LEDCTL, hw->ledctl_mode2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004576 return E1000_SUCCESS;
4577 }
4578 break;
4579 }
4580
Joe Perches1dc32912008-07-11 15:17:08 -07004581 ew32(CTRL, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004582
4583 return E1000_SUCCESS;
4584}
4585
4586/******************************************************************************
4587 * Turns off the software controllable LED
4588 *
4589 * hw - Struct containing variables accessed by shared code
4590 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004591s32 e1000_led_off(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004592{
Joe Perches1dc32912008-07-11 15:17:08 -07004593 u32 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004594
4595 DEBUGFUNC("e1000_led_off");
4596
Auke Kok8fc897b2006-08-28 14:56:16 -07004597 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004598 case e1000_82542_rev2_0:
4599 case e1000_82542_rev2_1:
4600 case e1000_82543:
4601 /* Clear SW Defineable Pin 0 to turn off the LED */
4602 ctrl &= ~E1000_CTRL_SWDPIN0;
4603 ctrl |= E1000_CTRL_SWDPIO0;
4604 break;
4605 case e1000_82544:
Auke Kok8fc897b2006-08-28 14:56:16 -07004606 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004607 /* Clear SW Defineable Pin 0 to turn off the LED */
4608 ctrl &= ~E1000_CTRL_SWDPIN0;
4609 ctrl |= E1000_CTRL_SWDPIO0;
4610 } else {
4611 /* Set SW Defineable Pin 0 to turn off the LED */
4612 ctrl |= E1000_CTRL_SWDPIN0;
4613 ctrl |= E1000_CTRL_SWDPIO0;
4614 }
4615 break;
4616 default:
Auke Kok8fc897b2006-08-28 14:56:16 -07004617 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004618 /* Set SW Defineable Pin 0 to turn off the LED */
4619 ctrl |= E1000_CTRL_SWDPIN0;
4620 ctrl |= E1000_CTRL_SWDPIO0;
Auke Kokcd94dd02006-06-27 09:08:22 -07004621 } else if (hw->media_type == e1000_media_type_copper) {
Joe Perches1dc32912008-07-11 15:17:08 -07004622 ew32(LEDCTL, hw->ledctl_mode1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004623 return E1000_SUCCESS;
4624 }
4625 break;
4626 }
4627
Joe Perches1dc32912008-07-11 15:17:08 -07004628 ew32(CTRL, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004629
4630 return E1000_SUCCESS;
4631}
4632
4633/******************************************************************************
4634 * Clears all hardware statistics counters.
4635 *
4636 * hw - Struct containing variables accessed by shared code
4637 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004638static void e1000_clear_hw_cntrs(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004639{
Joe Perches406874a2008-04-03 10:06:32 -07004640 volatile u32 temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004641
Joe Perches1dc32912008-07-11 15:17:08 -07004642 temp = er32(CRCERRS);
4643 temp = er32(SYMERRS);
4644 temp = er32(MPC);
4645 temp = er32(SCC);
4646 temp = er32(ECOL);
4647 temp = er32(MCC);
4648 temp = er32(LATECOL);
4649 temp = er32(COLC);
4650 temp = er32(DC);
4651 temp = er32(SEC);
4652 temp = er32(RLEC);
4653 temp = er32(XONRXC);
4654 temp = er32(XONTXC);
4655 temp = er32(XOFFRXC);
4656 temp = er32(XOFFTXC);
4657 temp = er32(FCRUC);
Auke Kokcd94dd02006-06-27 09:08:22 -07004658
Joe Perches1dc32912008-07-11 15:17:08 -07004659 temp = er32(PRC64);
4660 temp = er32(PRC127);
4661 temp = er32(PRC255);
4662 temp = er32(PRC511);
4663 temp = er32(PRC1023);
4664 temp = er32(PRC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07004665
Joe Perches1dc32912008-07-11 15:17:08 -07004666 temp = er32(GPRC);
4667 temp = er32(BPRC);
4668 temp = er32(MPRC);
4669 temp = er32(GPTC);
4670 temp = er32(GORCL);
4671 temp = er32(GORCH);
4672 temp = er32(GOTCL);
4673 temp = er32(GOTCH);
4674 temp = er32(RNBC);
4675 temp = er32(RUC);
4676 temp = er32(RFC);
4677 temp = er32(ROC);
4678 temp = er32(RJC);
4679 temp = er32(TORL);
4680 temp = er32(TORH);
4681 temp = er32(TOTL);
4682 temp = er32(TOTH);
4683 temp = er32(TPR);
4684 temp = er32(TPT);
Auke Kokcd94dd02006-06-27 09:08:22 -07004685
Joe Perches1dc32912008-07-11 15:17:08 -07004686 temp = er32(PTC64);
4687 temp = er32(PTC127);
4688 temp = er32(PTC255);
4689 temp = er32(PTC511);
4690 temp = er32(PTC1023);
4691 temp = er32(PTC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07004692
Joe Perches1dc32912008-07-11 15:17:08 -07004693 temp = er32(MPTC);
4694 temp = er32(BPTC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004695
Auke Kok8fc897b2006-08-28 14:56:16 -07004696 if (hw->mac_type < e1000_82543) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004697
Joe Perches1dc32912008-07-11 15:17:08 -07004698 temp = er32(ALGNERRC);
4699 temp = er32(RXERRC);
4700 temp = er32(TNCRS);
4701 temp = er32(CEXTERR);
4702 temp = er32(TSCTC);
4703 temp = er32(TSCTFC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004704
Auke Kok8fc897b2006-08-28 14:56:16 -07004705 if (hw->mac_type <= e1000_82544) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004706
Joe Perches1dc32912008-07-11 15:17:08 -07004707 temp = er32(MGTPRC);
4708 temp = er32(MGTPDC);
4709 temp = er32(MGTPTC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004710}
4711
4712/******************************************************************************
4713 * Resets Adaptive IFS to its default state.
4714 *
4715 * hw - Struct containing variables accessed by shared code
4716 *
4717 * Call this after e1000_init_hw. You may override the IFS defaults by setting
Joe Perchesc3033b02008-03-21 11:06:25 -07004718 * hw->ifs_params_forced to true. However, you must initialize hw->
Linus Torvalds1da177e2005-04-16 15:20:36 -07004719 * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio
4720 * before calling this function.
4721 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004722void e1000_reset_adaptive(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004723{
4724 DEBUGFUNC("e1000_reset_adaptive");
4725
Auke Kok8fc897b2006-08-28 14:56:16 -07004726 if (hw->adaptive_ifs) {
4727 if (!hw->ifs_params_forced) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004728 hw->current_ifs_val = 0;
4729 hw->ifs_min_val = IFS_MIN;
4730 hw->ifs_max_val = IFS_MAX;
4731 hw->ifs_step_size = IFS_STEP;
4732 hw->ifs_ratio = IFS_RATIO;
4733 }
Joe Perchesc3033b02008-03-21 11:06:25 -07004734 hw->in_ifs_mode = false;
Joe Perches1dc32912008-07-11 15:17:08 -07004735 ew32(AIT, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004736 } else {
4737 DEBUGOUT("Not in Adaptive IFS mode!\n");
4738 }
4739}
4740
4741/******************************************************************************
4742 * Called during the callback/watchdog routine to update IFS value based on
4743 * the ratio of transmits to collisions.
4744 *
4745 * hw - Struct containing variables accessed by shared code
4746 * tx_packets - Number of transmits since last callback
4747 * total_collisions - Number of collisions since last callback
4748 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004749void e1000_update_adaptive(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004750{
4751 DEBUGFUNC("e1000_update_adaptive");
4752
Auke Kok8fc897b2006-08-28 14:56:16 -07004753 if (hw->adaptive_ifs) {
4754 if ((hw->collision_delta * hw->ifs_ratio) > hw->tx_packet_delta) {
4755 if (hw->tx_packet_delta > MIN_NUM_XMITS) {
Joe Perchesc3033b02008-03-21 11:06:25 -07004756 hw->in_ifs_mode = true;
Auke Kok8fc897b2006-08-28 14:56:16 -07004757 if (hw->current_ifs_val < hw->ifs_max_val) {
4758 if (hw->current_ifs_val == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004759 hw->current_ifs_val = hw->ifs_min_val;
4760 else
4761 hw->current_ifs_val += hw->ifs_step_size;
Joe Perches1dc32912008-07-11 15:17:08 -07004762 ew32(AIT, hw->current_ifs_val);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004763 }
4764 }
4765 } else {
Auke Kok8fc897b2006-08-28 14:56:16 -07004766 if (hw->in_ifs_mode && (hw->tx_packet_delta <= MIN_NUM_XMITS)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004767 hw->current_ifs_val = 0;
Joe Perchesc3033b02008-03-21 11:06:25 -07004768 hw->in_ifs_mode = false;
Joe Perches1dc32912008-07-11 15:17:08 -07004769 ew32(AIT, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004770 }
4771 }
4772 } else {
4773 DEBUGOUT("Not in Adaptive IFS mode!\n");
4774 }
4775}
4776
4777/******************************************************************************
4778 * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT
4779 *
4780 * hw - Struct containing variables accessed by shared code
4781 * frame_len - The length of the frame in question
4782 * mac_addr - The Ethernet destination address of the frame in question
4783 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004784void e1000_tbi_adjust_stats(struct e1000_hw *hw, struct e1000_hw_stats *stats,
4785 u32 frame_len, u8 *mac_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004786{
Joe Perches406874a2008-04-03 10:06:32 -07004787 u64 carry_bit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004788
4789 /* First adjust the frame length. */
4790 frame_len--;
4791 /* We need to adjust the statistics counters, since the hardware
4792 * counters overcount this packet as a CRC error and undercount
4793 * the packet as a good packet
4794 */
4795 /* This packet should not be counted as a CRC error. */
4796 stats->crcerrs--;
4797 /* This packet does count as a Good Packet Received. */
4798 stats->gprc++;
4799
4800 /* Adjust the Good Octets received counters */
4801 carry_bit = 0x80000000 & stats->gorcl;
4802 stats->gorcl += frame_len;
4803 /* If the high bit of Gorcl (the low 32 bits of the Good Octets
4804 * Received Count) was one before the addition,
4805 * AND it is zero after, then we lost the carry out,
4806 * need to add one to Gorch (Good Octets Received Count High).
4807 * This could be simplified if all environments supported
4808 * 64-bit integers.
4809 */
Auke Kok8fc897b2006-08-28 14:56:16 -07004810 if (carry_bit && ((stats->gorcl & 0x80000000) == 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004811 stats->gorch++;
4812 /* Is this a broadcast or multicast? Check broadcast first,
4813 * since the test for a multicast frame will test positive on
4814 * a broadcast frame.
4815 */
Joe Perchese982f172008-07-11 15:17:18 -07004816 if ((mac_addr[0] == (u8)0xff) && (mac_addr[1] == (u8)0xff))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004817 /* Broadcast packet */
4818 stats->bprc++;
Auke Kok8fc897b2006-08-28 14:56:16 -07004819 else if (*mac_addr & 0x01)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004820 /* Multicast packet */
4821 stats->mprc++;
4822
Auke Kok8fc897b2006-08-28 14:56:16 -07004823 if (frame_len == hw->max_frame_size) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004824 /* In this case, the hardware has overcounted the number of
4825 * oversize frames.
4826 */
Auke Kok8fc897b2006-08-28 14:56:16 -07004827 if (stats->roc > 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004828 stats->roc--;
4829 }
4830
4831 /* Adjust the bin counters when the extra byte put the frame in the
4832 * wrong bin. Remember that the frame_len was adjusted above.
4833 */
Auke Kok8fc897b2006-08-28 14:56:16 -07004834 if (frame_len == 64) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004835 stats->prc64++;
4836 stats->prc127--;
Auke Kok8fc897b2006-08-28 14:56:16 -07004837 } else if (frame_len == 127) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004838 stats->prc127++;
4839 stats->prc255--;
Auke Kok8fc897b2006-08-28 14:56:16 -07004840 } else if (frame_len == 255) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004841 stats->prc255++;
4842 stats->prc511--;
Auke Kok8fc897b2006-08-28 14:56:16 -07004843 } else if (frame_len == 511) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004844 stats->prc511++;
4845 stats->prc1023--;
Auke Kok8fc897b2006-08-28 14:56:16 -07004846 } else if (frame_len == 1023) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004847 stats->prc1023++;
4848 stats->prc1522--;
Auke Kok8fc897b2006-08-28 14:56:16 -07004849 } else if (frame_len == 1522) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004850 stats->prc1522++;
4851 }
4852}
4853
4854/******************************************************************************
4855 * Gets the current PCI bus type, speed, and width of the hardware
4856 *
4857 * hw - Struct containing variables accessed by shared code
4858 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004859void e1000_get_bus_info(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004860{
Joe Perches406874a2008-04-03 10:06:32 -07004861 u32 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004862
4863 switch (hw->mac_type) {
4864 case e1000_82542_rev2_0:
4865 case e1000_82542_rev2_1:
Jeff Kirsherc3813ae2006-12-15 10:37:32 +01004866 hw->bus_type = e1000_bus_type_pci;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004867 hw->bus_speed = e1000_bus_speed_unknown;
4868 hw->bus_width = e1000_bus_width_unknown;
4869 break;
4870 default:
Joe Perches1dc32912008-07-11 15:17:08 -07004871 status = er32(STATUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004872 hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
4873 e1000_bus_type_pcix : e1000_bus_type_pci;
4874
Auke Kok8fc897b2006-08-28 14:56:16 -07004875 if (hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004876 hw->bus_speed = (hw->bus_type == e1000_bus_type_pci) ?
4877 e1000_bus_speed_66 : e1000_bus_speed_120;
Auke Kok8fc897b2006-08-28 14:56:16 -07004878 } else if (hw->bus_type == e1000_bus_type_pci) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004879 hw->bus_speed = (status & E1000_STATUS_PCI66) ?
4880 e1000_bus_speed_66 : e1000_bus_speed_33;
4881 } else {
4882 switch (status & E1000_STATUS_PCIX_SPEED) {
4883 case E1000_STATUS_PCIX_SPEED_66:
4884 hw->bus_speed = e1000_bus_speed_66;
4885 break;
4886 case E1000_STATUS_PCIX_SPEED_100:
4887 hw->bus_speed = e1000_bus_speed_100;
4888 break;
4889 case E1000_STATUS_PCIX_SPEED_133:
4890 hw->bus_speed = e1000_bus_speed_133;
4891 break;
4892 default:
4893 hw->bus_speed = e1000_bus_speed_reserved;
4894 break;
4895 }
4896 }
4897 hw->bus_width = (status & E1000_STATUS_BUS64) ?
4898 e1000_bus_width_64 : e1000_bus_width_32;
4899 break;
4900 }
4901}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004902
4903/******************************************************************************
4904 * Writes a value to one of the devices registers using port I/O (as opposed to
4905 * memory mapped I/O). Only 82544 and newer devices support port I/O.
4906 *
4907 * hw - Struct containing variables accessed by shared code
4908 * offset - offset to write to
4909 * value - value to write
4910 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004911static void e1000_write_reg_io(struct e1000_hw *hw, u32 offset, u32 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004912{
4913 unsigned long io_addr = hw->io_base;
4914 unsigned long io_data = hw->io_base + 4;
4915
4916 e1000_io_write(hw, io_addr, offset);
4917 e1000_io_write(hw, io_data, value);
4918}
4919
Linus Torvalds1da177e2005-04-16 15:20:36 -07004920/******************************************************************************
4921 * Estimates the cable length.
4922 *
4923 * hw - Struct containing variables accessed by shared code
4924 * min_length - The estimated minimum length
4925 * max_length - The estimated maximum length
4926 *
4927 * returns: - E1000_ERR_XXX
4928 * E1000_SUCCESS
4929 *
4930 * This function always returns a ranged length (minimum & maximum).
4931 * So for M88 phy's, this function interprets the one value returned from the
4932 * register to the minimum and maximum range.
4933 * For IGP phy's, the function calculates the range by the AGC registers.
4934 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07004935static s32 e1000_get_cable_length(struct e1000_hw *hw, u16 *min_length,
4936 u16 *max_length)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004937{
Joe Perches406874a2008-04-03 10:06:32 -07004938 s32 ret_val;
4939 u16 agc_value = 0;
4940 u16 i, phy_data;
4941 u16 cable_length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004942
4943 DEBUGFUNC("e1000_get_cable_length");
4944
4945 *min_length = *max_length = 0;
4946
4947 /* Use old method for Phy older than IGP */
Auke Kok8fc897b2006-08-28 14:56:16 -07004948 if (hw->phy_type == e1000_phy_m88) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004949
Linus Torvalds1da177e2005-04-16 15:20:36 -07004950 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
4951 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004952 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004953 return ret_val;
4954 cable_length = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
4955 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
4956
4957 /* Convert the enum value to ranged values */
4958 switch (cable_length) {
4959 case e1000_cable_length_50:
4960 *min_length = 0;
4961 *max_length = e1000_igp_cable_length_50;
4962 break;
4963 case e1000_cable_length_50_80:
4964 *min_length = e1000_igp_cable_length_50;
4965 *max_length = e1000_igp_cable_length_80;
4966 break;
4967 case e1000_cable_length_80_110:
4968 *min_length = e1000_igp_cable_length_80;
4969 *max_length = e1000_igp_cable_length_110;
4970 break;
4971 case e1000_cable_length_110_140:
4972 *min_length = e1000_igp_cable_length_110;
4973 *max_length = e1000_igp_cable_length_140;
4974 break;
4975 case e1000_cable_length_140:
4976 *min_length = e1000_igp_cable_length_140;
4977 *max_length = e1000_igp_cable_length_170;
4978 break;
4979 default:
4980 return -E1000_ERR_PHY;
4981 break;
4982 }
Auke Kok8fc897b2006-08-28 14:56:16 -07004983 } else if (hw->phy_type == e1000_phy_igp) { /* For IGP PHY */
Joe Perches406874a2008-04-03 10:06:32 -07004984 u16 cur_agc_value;
4985 u16 min_agc_value = IGP01E1000_AGC_LENGTH_TABLE_SIZE;
4986 u16 agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
Linus Torvalds1da177e2005-04-16 15:20:36 -07004987 {IGP01E1000_PHY_AGC_A,
4988 IGP01E1000_PHY_AGC_B,
4989 IGP01E1000_PHY_AGC_C,
4990 IGP01E1000_PHY_AGC_D};
4991 /* Read the AGC registers for all channels */
Auke Kok8fc897b2006-08-28 14:56:16 -07004992 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004993
4994 ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004995 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004996 return ret_val;
4997
Auke Kokcd94dd02006-06-27 09:08:22 -07004998 cur_agc_value = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004999
Auke Kokcd94dd02006-06-27 09:08:22 -07005000 /* Value bound check. */
5001 if ((cur_agc_value >= IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1) ||
5002 (cur_agc_value == 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005003 return -E1000_ERR_PHY;
5004
Auke Kokcd94dd02006-06-27 09:08:22 -07005005 agc_value += cur_agc_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005006
5007 /* Update minimal AGC value. */
Auke Kokcd94dd02006-06-27 09:08:22 -07005008 if (min_agc_value > cur_agc_value)
5009 min_agc_value = cur_agc_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005010 }
5011
5012 /* Remove the minimal AGC result for length < 50m */
Auke Kokcd94dd02006-06-27 09:08:22 -07005013 if (agc_value < IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) {
5014 agc_value -= min_agc_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005015
5016 /* Get the average length of the remaining 3 channels */
5017 agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1);
5018 } else {
5019 /* Get the average length of all the 4 channels. */
5020 agc_value /= IGP01E1000_PHY_CHANNEL_NUM;
5021 }
5022
5023 /* Set the range of the calculated length. */
5024 *min_length = ((e1000_igp_cable_length_table[agc_value] -
5025 IGP01E1000_AGC_RANGE) > 0) ?
5026 (e1000_igp_cable_length_table[agc_value] -
5027 IGP01E1000_AGC_RANGE) : 0;
5028 *max_length = e1000_igp_cable_length_table[agc_value] +
5029 IGP01E1000_AGC_RANGE;
5030 }
5031
5032 return E1000_SUCCESS;
5033}
5034
5035/******************************************************************************
5036 * Check the cable polarity
5037 *
5038 * hw - Struct containing variables accessed by shared code
5039 * polarity - output parameter : 0 - Polarity is not reversed
5040 * 1 - Polarity is reversed.
5041 *
5042 * returns: - E1000_ERR_XXX
5043 * E1000_SUCCESS
5044 *
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02005045 * For phy's older than IGP, this function simply reads the polarity bit in the
Linus Torvalds1da177e2005-04-16 15:20:36 -07005046 * Phy Status register. For IGP phy's, this bit is valid only if link speed is
5047 * 10 Mbps. If the link speed is 100 Mbps there is no polarity so this bit will
5048 * return 0. If the link speed is 1000 Mbps the polarity status is in the
5049 * IGP01E1000_PHY_PCS_INIT_REG.
5050 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07005051static s32 e1000_check_polarity(struct e1000_hw *hw,
5052 e1000_rev_polarity *polarity)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005053{
Joe Perches406874a2008-04-03 10:06:32 -07005054 s32 ret_val;
5055 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005056
5057 DEBUGFUNC("e1000_check_polarity");
5058
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00005059 if (hw->phy_type == e1000_phy_m88) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005060 /* return the Polarity bit in the Status register. */
5061 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
5062 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005063 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005064 return ret_val;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07005065 *polarity = ((phy_data & M88E1000_PSSR_REV_POLARITY) >>
5066 M88E1000_PSSR_REV_POLARITY_SHIFT) ?
5067 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
5068
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00005069 } else if (hw->phy_type == e1000_phy_igp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005070 /* Read the Status register to check the speed */
5071 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
5072 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005073 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005074 return ret_val;
5075
5076 /* If speed is 1000 Mbps, must read the IGP01E1000_PHY_PCS_INIT_REG to
5077 * find the polarity status */
Auke Kok8fc897b2006-08-28 14:56:16 -07005078 if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
Linus Torvalds1da177e2005-04-16 15:20:36 -07005079 IGP01E1000_PSSR_SPEED_1000MBPS) {
5080
5081 /* Read the GIG initialization PCS register (0x00B4) */
5082 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG,
5083 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005084 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005085 return ret_val;
5086
5087 /* Check the polarity bits */
Jeff Kirsher70c6f302006-09-27 12:53:31 -07005088 *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ?
5089 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005090 } else {
5091 /* For 10 Mbps, read the polarity bit in the status register. (for
5092 * 100 Mbps this bit is always 0) */
Jeff Kirsher70c6f302006-09-27 12:53:31 -07005093 *polarity = (phy_data & IGP01E1000_PSSR_POLARITY_REVERSED) ?
5094 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005095 }
5096 }
5097 return E1000_SUCCESS;
5098}
5099
5100/******************************************************************************
5101 * Check if Downshift occured
5102 *
5103 * hw - Struct containing variables accessed by shared code
5104 * downshift - output parameter : 0 - No Downshift ocured.
5105 * 1 - Downshift ocured.
5106 *
5107 * returns: - E1000_ERR_XXX
Auke Kok76c224b2006-05-23 13:36:06 -07005108 * E1000_SUCCESS
Linus Torvalds1da177e2005-04-16 15:20:36 -07005109 *
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02005110 * For phy's older than IGP, this function reads the Downshift bit in the Phy
Linus Torvalds1da177e2005-04-16 15:20:36 -07005111 * Specific Status register. For IGP phy's, it reads the Downgrade bit in the
5112 * Link Health register. In IGP this bit is latched high, so the driver must
5113 * read it immediately after link is established.
5114 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07005115static s32 e1000_check_downshift(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005116{
Joe Perches406874a2008-04-03 10:06:32 -07005117 s32 ret_val;
5118 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005119
5120 DEBUGFUNC("e1000_check_downshift");
5121
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00005122 if (hw->phy_type == e1000_phy_igp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005123 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH,
5124 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005125 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005126 return ret_val;
5127
5128 hw->speed_downgraded = (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0;
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00005129 } else if (hw->phy_type == e1000_phy_m88) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005130 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
5131 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005132 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005133 return ret_val;
5134
5135 hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >>
5136 M88E1000_PSSR_DOWNSHIFT_SHIFT;
5137 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005138
Linus Torvalds1da177e2005-04-16 15:20:36 -07005139 return E1000_SUCCESS;
5140}
5141
5142/*****************************************************************************
5143 *
5144 * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a
5145 * gigabit link is achieved to improve link quality.
5146 *
5147 * hw: Struct containing variables accessed by shared code
5148 *
5149 * returns: - E1000_ERR_PHY if fail to read/write the PHY
5150 * E1000_SUCCESS at any other case.
5151 *
5152 ****************************************************************************/
5153
Joe Perches64798842008-07-11 15:17:02 -07005154static s32 e1000_config_dsp_after_link_change(struct e1000_hw *hw, bool link_up)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005155{
Joe Perches406874a2008-04-03 10:06:32 -07005156 s32 ret_val;
5157 u16 phy_data, phy_saved_data, speed, duplex, i;
5158 u16 dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
Linus Torvalds1da177e2005-04-16 15:20:36 -07005159 {IGP01E1000_PHY_AGC_PARAM_A,
5160 IGP01E1000_PHY_AGC_PARAM_B,
5161 IGP01E1000_PHY_AGC_PARAM_C,
5162 IGP01E1000_PHY_AGC_PARAM_D};
Joe Perches406874a2008-04-03 10:06:32 -07005163 u16 min_length, max_length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005164
5165 DEBUGFUNC("e1000_config_dsp_after_link_change");
5166
Auke Kok8fc897b2006-08-28 14:56:16 -07005167 if (hw->phy_type != e1000_phy_igp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005168 return E1000_SUCCESS;
5169
Auke Kok8fc897b2006-08-28 14:56:16 -07005170 if (link_up) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005171 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
Auke Kok8fc897b2006-08-28 14:56:16 -07005172 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005173 DEBUGOUT("Error getting link speed and duplex\n");
5174 return ret_val;
5175 }
5176
Auke Kok8fc897b2006-08-28 14:56:16 -07005177 if (speed == SPEED_1000) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005178
Auke Kokcd94dd02006-06-27 09:08:22 -07005179 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
5180 if (ret_val)
5181 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005182
Auke Kok8fc897b2006-08-28 14:56:16 -07005183 if ((hw->dsp_config_state == e1000_dsp_config_enabled) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07005184 min_length >= e1000_igp_cable_length_50) {
5185
Auke Kok8fc897b2006-08-28 14:56:16 -07005186 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005187 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i],
5188 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005189 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005190 return ret_val;
5191
5192 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
5193
5194 ret_val = e1000_write_phy_reg(hw, dsp_reg_array[i],
5195 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005196 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005197 return ret_val;
5198 }
5199 hw->dsp_config_state = e1000_dsp_config_activated;
5200 }
5201
Auke Kok8fc897b2006-08-28 14:56:16 -07005202 if ((hw->ffe_config_state == e1000_ffe_config_enabled) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07005203 (min_length < e1000_igp_cable_length_50)) {
5204
Joe Perches406874a2008-04-03 10:06:32 -07005205 u16 ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_20;
5206 u32 idle_errs = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005207
5208 /* clear previous idle error counts */
5209 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
5210 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005211 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005212 return ret_val;
5213
Auke Kok8fc897b2006-08-28 14:56:16 -07005214 for (i = 0; i < ffe_idle_err_timeout; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005215 udelay(1000);
5216 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
5217 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005218 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005219 return ret_val;
5220
5221 idle_errs += (phy_data & SR_1000T_IDLE_ERROR_CNT);
Auke Kok8fc897b2006-08-28 14:56:16 -07005222 if (idle_errs > SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005223 hw->ffe_config_state = e1000_ffe_config_active;
5224
5225 ret_val = e1000_write_phy_reg(hw,
5226 IGP01E1000_PHY_DSP_FFE,
5227 IGP01E1000_PHY_DSP_FFE_CM_CP);
Auke Kok8fc897b2006-08-28 14:56:16 -07005228 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005229 return ret_val;
5230 break;
5231 }
5232
Auke Kok8fc897b2006-08-28 14:56:16 -07005233 if (idle_errs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005234 ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_100;
5235 }
5236 }
5237 }
5238 } else {
Auke Kok8fc897b2006-08-28 14:56:16 -07005239 if (hw->dsp_config_state == e1000_dsp_config_activated) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005240 /* Save off the current value of register 0x2F5B to be restored at
5241 * the end of the routines. */
5242 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
5243
Auke Kok8fc897b2006-08-28 14:56:16 -07005244 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005245 return ret_val;
5246
5247 /* Disable the PHY transmitter */
5248 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
5249
Auke Kok8fc897b2006-08-28 14:56:16 -07005250 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005251 return ret_val;
5252
Jeff Garzikf8ec4732006-09-19 15:27:07 -04005253 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005254
5255 ret_val = e1000_write_phy_reg(hw, 0x0000,
5256 IGP01E1000_IEEE_FORCE_GIGA);
Auke Kok8fc897b2006-08-28 14:56:16 -07005257 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005258 return ret_val;
Auke Kok8fc897b2006-08-28 14:56:16 -07005259 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005260 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i], &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005261 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005262 return ret_val;
5263
5264 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
5265 phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS;
5266
5267 ret_val = e1000_write_phy_reg(hw,dsp_reg_array[i], phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005268 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005269 return ret_val;
5270 }
5271
5272 ret_val = e1000_write_phy_reg(hw, 0x0000,
5273 IGP01E1000_IEEE_RESTART_AUTONEG);
Auke Kok8fc897b2006-08-28 14:56:16 -07005274 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005275 return ret_val;
5276
Jeff Garzikf8ec4732006-09-19 15:27:07 -04005277 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005278
5279 /* Now enable the transmitter */
5280 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
5281
Auke Kok8fc897b2006-08-28 14:56:16 -07005282 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005283 return ret_val;
5284
5285 hw->dsp_config_state = e1000_dsp_config_enabled;
5286 }
5287
Auke Kok8fc897b2006-08-28 14:56:16 -07005288 if (hw->ffe_config_state == e1000_ffe_config_active) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005289 /* Save off the current value of register 0x2F5B to be restored at
5290 * the end of the routines. */
5291 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
5292
Auke Kok8fc897b2006-08-28 14:56:16 -07005293 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005294 return ret_val;
5295
5296 /* Disable the PHY transmitter */
5297 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
5298
Auke Kok8fc897b2006-08-28 14:56:16 -07005299 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005300 return ret_val;
5301
Jeff Garzikf8ec4732006-09-19 15:27:07 -04005302 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005303
5304 ret_val = e1000_write_phy_reg(hw, 0x0000,
5305 IGP01E1000_IEEE_FORCE_GIGA);
Auke Kok8fc897b2006-08-28 14:56:16 -07005306 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005307 return ret_val;
5308 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE,
5309 IGP01E1000_PHY_DSP_FFE_DEFAULT);
Auke Kok8fc897b2006-08-28 14:56:16 -07005310 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005311 return ret_val;
5312
5313 ret_val = e1000_write_phy_reg(hw, 0x0000,
5314 IGP01E1000_IEEE_RESTART_AUTONEG);
Auke Kok8fc897b2006-08-28 14:56:16 -07005315 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005316 return ret_val;
5317
Jeff Garzikf8ec4732006-09-19 15:27:07 -04005318 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005319
5320 /* Now enable the transmitter */
5321 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
5322
Auke Kok8fc897b2006-08-28 14:56:16 -07005323 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005324 return ret_val;
5325
5326 hw->ffe_config_state = e1000_ffe_config_enabled;
5327 }
5328 }
5329 return E1000_SUCCESS;
5330}
5331
5332/*****************************************************************************
5333 * Set PHY to class A mode
5334 * Assumes the following operations will follow to enable the new class mode.
5335 * 1. Do a PHY soft reset
5336 * 2. Restart auto-negotiation or force link.
5337 *
5338 * hw - Struct containing variables accessed by shared code
5339 ****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07005340static s32 e1000_set_phy_mode(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005341{
Joe Perches406874a2008-04-03 10:06:32 -07005342 s32 ret_val;
5343 u16 eeprom_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005344
5345 DEBUGFUNC("e1000_set_phy_mode");
5346
Auke Kok8fc897b2006-08-28 14:56:16 -07005347 if ((hw->mac_type == e1000_82545_rev_3) &&
5348 (hw->media_type == e1000_media_type_copper)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005349 ret_val = e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, 1, &eeprom_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005350 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005351 return ret_val;
5352 }
5353
Auke Kok8fc897b2006-08-28 14:56:16 -07005354 if ((eeprom_data != EEPROM_RESERVED_WORD) &&
5355 (eeprom_data & EEPROM_PHY_CLASS_A)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005356 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x000B);
Auke Kok8fc897b2006-08-28 14:56:16 -07005357 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005358 return ret_val;
5359 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x8104);
Auke Kok8fc897b2006-08-28 14:56:16 -07005360 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005361 return ret_val;
5362
Joe Perchesc3033b02008-03-21 11:06:25 -07005363 hw->phy_reset_disable = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005364 }
5365 }
5366
5367 return E1000_SUCCESS;
5368}
5369
5370/*****************************************************************************
5371 *
5372 * This function sets the lplu state according to the active flag. When
5373 * activating lplu this function also disables smart speed and vise versa.
5374 * lplu will not be activated unless the device autonegotiation advertisment
5375 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
5376 * hw: Struct containing variables accessed by shared code
5377 * active - true to enable lplu false to disable lplu.
5378 *
5379 * returns: - E1000_ERR_PHY if fail to read/write the PHY
5380 * E1000_SUCCESS at any other case.
5381 *
5382 ****************************************************************************/
5383
Joe Perches64798842008-07-11 15:17:02 -07005384static s32 e1000_set_d3_lplu_state(struct e1000_hw *hw, bool active)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005385{
Joe Perches406874a2008-04-03 10:06:32 -07005386 s32 ret_val;
5387 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005388 DEBUGFUNC("e1000_set_d3_lplu_state");
5389
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00005390 if (hw->phy_type != e1000_phy_igp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005391 return E1000_SUCCESS;
5392
5393 /* During driver activity LPLU should not be used or it will attain link
5394 * from the lowest speeds starting from 10Mbps. The capability is used for
5395 * Dx transitions and states */
Auke Kokcd94dd02006-06-27 09:08:22 -07005396 if (hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005397 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data);
Auke Kokcd94dd02006-06-27 09:08:22 -07005398 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005399 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005400 } else {
5401 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &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 }
5405
Auke Kok8fc897b2006-08-28 14:56:16 -07005406 if (!active) {
5407 if (hw->mac_type == e1000_82541_rev_2 ||
5408 hw->mac_type == e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005409 phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
5410 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005411 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005412 return ret_val;
5413 } else {
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00005414 phy_data &= ~IGP02E1000_PM_D3_LPLU;
5415 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
5416 phy_data);
5417 if (ret_val)
5418 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005419 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005420
5421 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
5422 * Dx states where the power conservation is most important. During
5423 * driver activity we should enable SmartSpeed, so performance is
5424 * maintained. */
5425 if (hw->smart_speed == e1000_smart_speed_on) {
5426 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5427 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005428 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005429 return ret_val;
5430
5431 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
5432 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5433 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005434 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005435 return ret_val;
5436 } else if (hw->smart_speed == e1000_smart_speed_off) {
5437 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5438 &phy_data);
Nicholas Nunley35574762006-09-27 12:53:34 -07005439 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005440 return ret_val;
5441
5442 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
5443 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5444 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005445 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005446 return ret_val;
5447 }
5448
Auke Kok8fc897b2006-08-28 14:56:16 -07005449 } else if ((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT) ||
5450 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL ) ||
5451 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005452
Auke Kok8fc897b2006-08-28 14:56:16 -07005453 if (hw->mac_type == e1000_82541_rev_2 ||
Auke Kokcd94dd02006-06-27 09:08:22 -07005454 hw->mac_type == e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005455 phy_data |= IGP01E1000_GMII_FLEX_SPD;
5456 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005457 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005458 return ret_val;
5459 } else {
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00005460 phy_data |= IGP02E1000_PM_D3_LPLU;
5461 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005462 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005463 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005464 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07005465 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005466
Linus Torvalds1da177e2005-04-16 15:20:36 -07005467 /* When LPLU is enabled we should disable SmartSpeed */
5468 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005469 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005470 return ret_val;
5471
5472 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
5473 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005474 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005475 return ret_val;
5476
5477 }
5478 return E1000_SUCCESS;
5479}
5480
5481/******************************************************************************
5482 * Change VCO speed register to improve Bit Error Rate performance of SERDES.
5483 *
5484 * hw - Struct containing variables accessed by shared code
5485 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07005486static s32 e1000_set_vco_speed(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005487{
Joe Perches406874a2008-04-03 10:06:32 -07005488 s32 ret_val;
5489 u16 default_page = 0;
5490 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005491
5492 DEBUGFUNC("e1000_set_vco_speed");
5493
Auke Kok8fc897b2006-08-28 14:56:16 -07005494 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005495 case e1000_82545_rev_3:
5496 case e1000_82546_rev_3:
5497 break;
5498 default:
5499 return E1000_SUCCESS;
5500 }
5501
5502 /* Set PHY register 30, page 5, bit 8 to 0 */
5503
5504 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, &default_page);
Auke Kok8fc897b2006-08-28 14:56:16 -07005505 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005506 return ret_val;
5507
5508 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005);
Auke Kok8fc897b2006-08-28 14:56:16 -07005509 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005510 return ret_val;
5511
5512 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005513 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005514 return ret_val;
5515
5516 phy_data &= ~M88E1000_PHY_VCO_REG_BIT8;
5517 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005518 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005519 return ret_val;
5520
5521 /* Set PHY register 30, page 4, bit 11 to 1 */
5522
5523 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004);
Auke Kok8fc897b2006-08-28 14:56:16 -07005524 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005525 return ret_val;
5526
5527 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005528 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005529 return ret_val;
5530
5531 phy_data |= M88E1000_PHY_VCO_REG_BIT11;
5532 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07005533 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005534 return ret_val;
5535
5536 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, default_page);
Auke Kok8fc897b2006-08-28 14:56:16 -07005537 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005538 return ret_val;
5539
5540 return E1000_SUCCESS;
5541}
5542
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005543
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005544/******************************************************************************
5545 * Verifies the hardware needs to allow ARPs to be processed by the host
5546 *
5547 * hw - Struct containing variables accessed by shared code
5548 *
Joe Perchesc3033b02008-03-21 11:06:25 -07005549 * returns: - true/false
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005550 *
5551 *****************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07005552u32 e1000_enable_mng_pass_thru(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005553{
Joe Perches406874a2008-04-03 10:06:32 -07005554 u32 manc;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005555
5556 if (hw->asf_firmware_present) {
Joe Perches1dc32912008-07-11 15:17:08 -07005557 manc = er32(MANC);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005558
5559 if (!(manc & E1000_MANC_RCV_TCO_EN) ||
5560 !(manc & E1000_MANC_EN_MAC_ADDR_FILTER))
Joe Perchesc3033b02008-03-21 11:06:25 -07005561 return false;
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00005562 if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN))
5563 return true;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005564 }
Joe Perchesc3033b02008-03-21 11:06:25 -07005565 return false;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005566}
5567
Joe Perches64798842008-07-11 15:17:02 -07005568static s32 e1000_polarity_reversal_workaround(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005569{
Joe Perches406874a2008-04-03 10:06:32 -07005570 s32 ret_val;
5571 u16 mii_status_reg;
5572 u16 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005573
5574 /* Polarity reversal workaround for forced 10F/10H links. */
5575
5576 /* Disable the transmitter on the PHY */
5577
5578 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
Auke Kok8fc897b2006-08-28 14:56:16 -07005579 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005580 return ret_val;
5581 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF);
Auke Kok8fc897b2006-08-28 14:56:16 -07005582 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005583 return ret_val;
5584
5585 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
Auke Kok8fc897b2006-08-28 14:56:16 -07005586 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005587 return ret_val;
5588
5589 /* This loop will early-out if the NO link condition has been met. */
Auke Kok8fc897b2006-08-28 14:56:16 -07005590 for (i = PHY_FORCE_TIME; i > 0; i--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005591 /* Read the MII Status Register and wait for Link Status bit
5592 * to be clear.
5593 */
5594
5595 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07005596 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005597 return ret_val;
5598
5599 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07005600 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005601 return ret_val;
5602
Auke Kok8fc897b2006-08-28 14:56:16 -07005603 if ((mii_status_reg & ~MII_SR_LINK_STATUS) == 0) break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04005604 mdelay(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005605 }
5606
5607 /* Recommended delay time after link has been lost */
Jeff Garzikf8ec4732006-09-19 15:27:07 -04005608 mdelay(1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005609
5610 /* Now we will re-enable th transmitter on the PHY */
5611
5612 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
Auke Kok8fc897b2006-08-28 14:56:16 -07005613 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005614 return ret_val;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04005615 mdelay(50);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005616 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0);
Auke Kok8fc897b2006-08-28 14:56:16 -07005617 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005618 return ret_val;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04005619 mdelay(50);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005620 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00);
Auke Kok8fc897b2006-08-28 14:56:16 -07005621 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005622 return ret_val;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04005623 mdelay(50);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005624 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000);
Auke Kok8fc897b2006-08-28 14:56:16 -07005625 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005626 return ret_val;
5627
5628 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
Auke Kok8fc897b2006-08-28 14:56:16 -07005629 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005630 return ret_val;
5631
5632 /* This loop will early-out if the link condition has been met. */
Auke Kok8fc897b2006-08-28 14:56:16 -07005633 for (i = PHY_FORCE_TIME; i > 0; i--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005634 /* Read the MII Status Register and wait for Link Status bit
5635 * to be set.
5636 */
5637
5638 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07005639 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005640 return ret_val;
5641
5642 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07005643 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005644 return ret_val;
5645
Auke Kok8fc897b2006-08-28 14:56:16 -07005646 if (mii_status_reg & MII_SR_LINK_STATUS) break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04005647 mdelay(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005648 }
5649 return E1000_SUCCESS;
5650}
5651
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005652/*******************************************************************************
5653 *
5654 * Check for EEPROM Auto Read bit done.
5655 *
5656 * hw: Struct containing variables accessed by shared code
5657 *
5658 * returns: - E1000_ERR_RESET if fail to reset MAC
5659 * E1000_SUCCESS at any other case.
5660 *
5661 ******************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07005662static s32 e1000_get_auto_rd_done(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005663{
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005664 DEBUGFUNC("e1000_get_auto_rd_done");
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00005665 msleep(5);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005666 return E1000_SUCCESS;
5667}
5668
5669/***************************************************************************
5670 * Checks if the PHY configuration is done
5671 *
5672 * hw: Struct containing variables accessed by shared code
5673 *
5674 * returns: - E1000_ERR_RESET if fail to reset MAC
5675 * E1000_SUCCESS at any other case.
5676 *
5677 ***************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07005678static s32 e1000_get_phy_cfg_done(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005679{
5680 DEBUGFUNC("e1000_get_phy_cfg_done");
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00005681 mdelay(10);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005682 return E1000_SUCCESS;
5683}
5684
5685/***************************************************************************
5686 *
5687 * Using the combination of SMBI and SWESMBI semaphore bits when resetting
5688 * adapter or Eeprom access.
5689 *
5690 * hw: Struct containing variables accessed by shared code
5691 *
5692 * returns: - E1000_ERR_EEPROM if fail to access EEPROM.
5693 * E1000_SUCCESS at any other case.
5694 *
5695 ***************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07005696static s32 e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005697{
Joe Perches406874a2008-04-03 10:06:32 -07005698 s32 timeout;
5699 u32 swsm;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005700
5701 DEBUGFUNC("e1000_get_hw_eeprom_semaphore");
5702
Auke Kok8fc897b2006-08-28 14:56:16 -07005703 if (!hw->eeprom_semaphore_present)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005704 return E1000_SUCCESS;
5705
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005706 /* Get the FW semaphore. */
5707 timeout = hw->eeprom.word_size + 1;
Auke Kok8fc897b2006-08-28 14:56:16 -07005708 while (timeout) {
Joe Perches1dc32912008-07-11 15:17:08 -07005709 swsm = er32(SWSM);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005710 swsm |= E1000_SWSM_SWESMBI;
Joe Perches1dc32912008-07-11 15:17:08 -07005711 ew32(SWSM, swsm);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005712 /* if we managed to set the bit we got the semaphore. */
Joe Perches1dc32912008-07-11 15:17:08 -07005713 swsm = er32(SWSM);
Auke Kok8fc897b2006-08-28 14:56:16 -07005714 if (swsm & E1000_SWSM_SWESMBI)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005715 break;
5716
5717 udelay(50);
5718 timeout--;
5719 }
5720
Auke Kok8fc897b2006-08-28 14:56:16 -07005721 if (!timeout) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005722 /* Release semaphores */
5723 e1000_put_hw_eeprom_semaphore(hw);
5724 DEBUGOUT("Driver can't access the Eeprom - SWESMBI bit is set.\n");
5725 return -E1000_ERR_EEPROM;
5726 }
5727
5728 return E1000_SUCCESS;
5729}
5730
5731/***************************************************************************
5732 * This function clears HW semaphore bits.
5733 *
5734 * hw: Struct containing variables accessed by shared code
5735 *
5736 * returns: - None.
5737 *
5738 ***************************************************************************/
Joe Perches64798842008-07-11 15:17:02 -07005739static void e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005740{
Joe Perches406874a2008-04-03 10:06:32 -07005741 u32 swsm;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005742
5743 DEBUGFUNC("e1000_put_hw_eeprom_semaphore");
5744
Auke Kok8fc897b2006-08-28 14:56:16 -07005745 if (!hw->eeprom_semaphore_present)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005746 return;
5747
Joe Perches1dc32912008-07-11 15:17:08 -07005748 swsm = er32(SWSM);
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00005749 swsm &= ~(E1000_SWSM_SWESMBI);
Joe Perches1dc32912008-07-11 15:17:08 -07005750 ew32(SWSM, swsm);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005751}