blob: 6aba88304407d571acafa7e11e8a4ae6bfb75bad [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
Jesse Brandeburg120a5d02009-09-25 15:19:46 -070027 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
29/* e1000_hw.c
30 * Shared functions for accessing and configuring the MAC
31 */
32
33#include "e1000_hw.h"
34
Joe Perches406874a2008-04-03 10:06:32 -070035static s32 e1000_check_downshift(struct e1000_hw *hw);
Joe Perches64798842008-07-11 15:17:02 -070036static s32 e1000_check_polarity(struct e1000_hw *hw,
37 e1000_rev_polarity *polarity);
Nicholas Nunley35574762006-09-27 12:53:34 -070038static void e1000_clear_hw_cntrs(struct e1000_hw *hw);
39static void e1000_clear_vfta(struct e1000_hw *hw);
Joe Perches406874a2008-04-03 10:06:32 -070040static s32 e1000_config_dsp_after_link_change(struct e1000_hw *hw,
Joe Perches64798842008-07-11 15:17:02 -070041 bool link_up);
Joe Perches406874a2008-04-03 10:06:32 -070042static s32 e1000_config_fc_after_link_up(struct e1000_hw *hw);
43static s32 e1000_detect_gig_phy(struct e1000_hw *hw);
Joe Perches406874a2008-04-03 10:06:32 -070044static s32 e1000_get_auto_rd_done(struct e1000_hw *hw);
Joe Perches64798842008-07-11 15:17:02 -070045static s32 e1000_get_cable_length(struct e1000_hw *hw, u16 *min_length,
46 u16 *max_length);
Joe Perches406874a2008-04-03 10:06:32 -070047static s32 e1000_get_phy_cfg_done(struct e1000_hw *hw);
Joe Perches406874a2008-04-03 10:06:32 -070048static s32 e1000_id_led_init(struct e1000_hw *hw);
Nicholas Nunley35574762006-09-27 12:53:34 -070049static void e1000_init_rx_addrs(struct e1000_hw *hw);
Joe Perches64798842008-07-11 15:17:02 -070050static s32 e1000_phy_igp_get_info(struct e1000_hw *hw,
51 struct e1000_phy_info *phy_info);
52static s32 e1000_read_eeprom_eerd(struct e1000_hw *hw, u16 offset, u16 words,
53 u16 *data);
54static s32 e1000_write_eeprom_eewr(struct e1000_hw *hw, u16 offset, u16 words,
55 u16 *data);
Joe Perches406874a2008-04-03 10:06:32 -070056static s32 e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd);
Joe Perches64798842008-07-11 15:17:02 -070057static s32 e1000_phy_m88_get_info(struct e1000_hw *hw,
58 struct e1000_phy_info *phy_info);
Joe Perches406874a2008-04-03 10:06:32 -070059static s32 e1000_set_d3_lplu_state(struct e1000_hw *hw, bool active);
Joe Perches406874a2008-04-03 10:06:32 -070060static s32 e1000_wait_autoneg(struct e1000_hw *hw);
61static void e1000_write_reg_io(struct e1000_hw *hw, u32 offset, u32 value);
62static s32 e1000_set_phy_type(struct e1000_hw *hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063static void e1000_phy_init_script(struct e1000_hw *hw);
Joe Perches406874a2008-04-03 10:06:32 -070064static s32 e1000_setup_copper_link(struct e1000_hw *hw);
65static s32 e1000_setup_fiber_serdes_link(struct e1000_hw *hw);
66static s32 e1000_adjust_serdes_amplitude(struct e1000_hw *hw);
67static s32 e1000_phy_force_speed_duplex(struct e1000_hw *hw);
68static s32 e1000_config_mac_to_phy(struct e1000_hw *hw);
69static void e1000_raise_mdi_clk(struct e1000_hw *hw, u32 *ctrl);
70static void e1000_lower_mdi_clk(struct e1000_hw *hw, u32 *ctrl);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -070071static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, u32 data, u16 count);
Joe Perches406874a2008-04-03 10:06:32 -070072static u16 e1000_shift_in_mdi_bits(struct e1000_hw *hw);
73static s32 e1000_phy_reset_dsp(struct e1000_hw *hw);
74static s32 e1000_write_eeprom_spi(struct e1000_hw *hw, u16 offset,
Jesse Brandeburg120a5d02009-09-25 15:19:46 -070075 u16 words, u16 *data);
Joe Perches64798842008-07-11 15:17:02 -070076static s32 e1000_write_eeprom_microwire(struct e1000_hw *hw, u16 offset,
77 u16 words, u16 *data);
Joe Perches406874a2008-04-03 10:06:32 -070078static s32 e1000_spi_eeprom_ready(struct e1000_hw *hw);
79static void e1000_raise_ee_clk(struct e1000_hw *hw, u32 *eecd);
80static void e1000_lower_ee_clk(struct e1000_hw *hw, u32 *eecd);
Joe Perches64798842008-07-11 15:17:02 -070081static void e1000_shift_out_ee_bits(struct e1000_hw *hw, u16 data, u16 count);
Joe Perches406874a2008-04-03 10:06:32 -070082static s32 e1000_write_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr,
Joe Perches64798842008-07-11 15:17:02 -070083 u16 phy_data);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -070084static s32 e1000_read_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr,
Joe Perches64798842008-07-11 15:17:02 -070085 u16 *phy_data);
Joe Perches406874a2008-04-03 10:06:32 -070086static u16 e1000_shift_in_ee_bits(struct e1000_hw *hw, u16 count);
87static s32 e1000_acquire_eeprom(struct e1000_hw *hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088static void e1000_release_eeprom(struct e1000_hw *hw);
89static void e1000_standby_eeprom(struct e1000_hw *hw);
Joe Perches406874a2008-04-03 10:06:32 -070090static s32 e1000_set_vco_speed(struct e1000_hw *hw);
91static s32 e1000_polarity_reversal_workaround(struct e1000_hw *hw);
92static s32 e1000_set_phy_mode(struct e1000_hw *hw);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -070093static s32 e1000_do_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words,
94 u16 *data);
95static s32 e1000_do_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words,
96 u16 *data);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
98/* IGP cable length table */
99static const
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700100u16 e1000_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] = {
101 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
102 5, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 25, 25, 25,
103 25, 25, 25, 25, 30, 30, 30, 30, 40, 40, 40, 40, 40, 40, 40, 40,
104 40, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60,
105 60, 70, 70, 70, 70, 70, 70, 80, 80, 80, 80, 80, 80, 90, 90, 90,
106 90, 90, 90, 90, 90, 90, 100, 100, 100, 100, 100, 100, 100, 100, 100,
107 100,
108 100, 100, 100, 100, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,
109 110, 110,
110 110, 110, 110, 110, 110, 110, 120, 120, 120, 120, 120, 120, 120, 120,
111 120, 120
112};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
Christopher Li78566fe2008-09-05 14:04:05 -0700114static DEFINE_SPINLOCK(e1000_eeprom_lock);
115
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700116/**
117 * e1000_set_phy_type - Set the phy type member in the hw struct.
118 * @hw: Struct containing variables accessed by shared code
119 */
Joe Perches64798842008-07-11 15:17:02 -0700120static s32 e1000_set_phy_type(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700122 DEBUGFUNC("e1000_set_phy_type");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700124 if (hw->mac_type == e1000_undefined)
125 return -E1000_ERR_PHY_TYPE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700126
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700127 switch (hw->phy_id) {
128 case M88E1000_E_PHY_ID:
129 case M88E1000_I_PHY_ID:
130 case M88E1011_I_PHY_ID:
131 case M88E1111_I_PHY_ID:
132 hw->phy_type = e1000_phy_m88;
133 break;
134 case IGP01E1000_I_PHY_ID:
135 if (hw->mac_type == e1000_82541 ||
136 hw->mac_type == e1000_82541_rev_2 ||
137 hw->mac_type == e1000_82547 ||
138 hw->mac_type == e1000_82547_rev_2) {
139 hw->phy_type = e1000_phy_igp;
140 break;
141 }
142 default:
143 /* Should never have loaded on this device */
144 hw->phy_type = e1000_phy_undefined;
145 return -E1000_ERR_PHY_TYPE;
146 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700148 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149}
150
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700151/**
152 * e1000_phy_init_script - IGP phy init script - initializes the GbE PHY
153 * @hw: Struct containing variables accessed by shared code
154 */
Joe Perches64798842008-07-11 15:17:02 -0700155static void e1000_phy_init_script(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700157 u32 ret_val;
158 u16 phy_saved_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700160 DEBUGFUNC("e1000_phy_init_script");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700162 if (hw->phy_init_script) {
163 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700165 /* Save off the current value of register 0x2F5B to be restored at
166 * the end of this routine. */
167 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700169 /* Disabled the PHY transmitter */
170 e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
171 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700173 e1000_write_phy_reg(hw, 0x0000, 0x0140);
174 msleep(5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700176 switch (hw->mac_type) {
177 case e1000_82541:
178 case e1000_82547:
179 e1000_write_phy_reg(hw, 0x1F95, 0x0001);
180 e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
181 e1000_write_phy_reg(hw, 0x1F79, 0x0018);
182 e1000_write_phy_reg(hw, 0x1F30, 0x1600);
183 e1000_write_phy_reg(hw, 0x1F31, 0x0014);
184 e1000_write_phy_reg(hw, 0x1F32, 0x161C);
185 e1000_write_phy_reg(hw, 0x1F94, 0x0003);
186 e1000_write_phy_reg(hw, 0x1F96, 0x003F);
187 e1000_write_phy_reg(hw, 0x2010, 0x0008);
188 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700190 case e1000_82541_rev_2:
191 case e1000_82547_rev_2:
192 e1000_write_phy_reg(hw, 0x1F73, 0x0099);
193 break;
194 default:
195 break;
196 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700198 e1000_write_phy_reg(hw, 0x0000, 0x3300);
199 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700201 /* Now enable the transmitter */
202 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700204 if (hw->mac_type == e1000_82547) {
205 u16 fused, fine, coarse;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700207 /* Move to analog registers page */
208 e1000_read_phy_reg(hw,
209 IGP01E1000_ANALOG_SPARE_FUSE_STATUS,
210 &fused);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700212 if (!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
213 e1000_read_phy_reg(hw,
214 IGP01E1000_ANALOG_FUSE_STATUS,
215 &fused);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700217 fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
218 coarse =
219 fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700221 if (coarse >
222 IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
223 coarse -=
224 IGP01E1000_ANALOG_FUSE_COARSE_10;
225 fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
226 } else if (coarse ==
227 IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
228 fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700230 fused =
231 (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
232 (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
233 (coarse &
234 IGP01E1000_ANALOG_FUSE_COARSE_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700236 e1000_write_phy_reg(hw,
237 IGP01E1000_ANALOG_FUSE_CONTROL,
238 fused);
239 e1000_write_phy_reg(hw,
240 IGP01E1000_ANALOG_FUSE_BYPASS,
241 IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
242 }
243 }
244 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245}
246
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700247/**
248 * e1000_set_mac_type - Set the mac type member in the hw struct.
249 * @hw: Struct containing variables accessed by shared code
250 */
Joe Perches64798842008-07-11 15:17:02 -0700251s32 e1000_set_mac_type(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252{
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500253 DEBUGFUNC("e1000_set_mac_type");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500255 switch (hw->device_id) {
256 case E1000_DEV_ID_82542:
257 switch (hw->revision_id) {
258 case E1000_82542_2_0_REV_ID:
259 hw->mac_type = e1000_82542_rev2_0;
260 break;
261 case E1000_82542_2_1_REV_ID:
262 hw->mac_type = e1000_82542_rev2_1;
263 break;
264 default:
265 /* Invalid 82542 revision ID */
266 return -E1000_ERR_MAC_TYPE;
267 }
268 break;
269 case E1000_DEV_ID_82543GC_FIBER:
270 case E1000_DEV_ID_82543GC_COPPER:
271 hw->mac_type = e1000_82543;
272 break;
273 case E1000_DEV_ID_82544EI_COPPER:
274 case E1000_DEV_ID_82544EI_FIBER:
275 case E1000_DEV_ID_82544GC_COPPER:
276 case E1000_DEV_ID_82544GC_LOM:
277 hw->mac_type = e1000_82544;
278 break;
279 case E1000_DEV_ID_82540EM:
280 case E1000_DEV_ID_82540EM_LOM:
281 case E1000_DEV_ID_82540EP:
282 case E1000_DEV_ID_82540EP_LOM:
283 case E1000_DEV_ID_82540EP_LP:
284 hw->mac_type = e1000_82540;
285 break;
286 case E1000_DEV_ID_82545EM_COPPER:
287 case E1000_DEV_ID_82545EM_FIBER:
288 hw->mac_type = e1000_82545;
289 break;
290 case E1000_DEV_ID_82545GM_COPPER:
291 case E1000_DEV_ID_82545GM_FIBER:
292 case E1000_DEV_ID_82545GM_SERDES:
293 hw->mac_type = e1000_82545_rev_3;
294 break;
295 case E1000_DEV_ID_82546EB_COPPER:
296 case E1000_DEV_ID_82546EB_FIBER:
297 case E1000_DEV_ID_82546EB_QUAD_COPPER:
298 hw->mac_type = e1000_82546;
299 break;
300 case E1000_DEV_ID_82546GB_COPPER:
301 case E1000_DEV_ID_82546GB_FIBER:
302 case E1000_DEV_ID_82546GB_SERDES:
303 case E1000_DEV_ID_82546GB_PCIE:
304 case E1000_DEV_ID_82546GB_QUAD_COPPER:
305 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
306 hw->mac_type = e1000_82546_rev_3;
307 break;
308 case E1000_DEV_ID_82541EI:
309 case E1000_DEV_ID_82541EI_MOBILE:
310 case E1000_DEV_ID_82541ER_LOM:
311 hw->mac_type = e1000_82541;
312 break;
313 case E1000_DEV_ID_82541ER:
314 case E1000_DEV_ID_82541GI:
315 case E1000_DEV_ID_82541GI_LF:
316 case E1000_DEV_ID_82541GI_MOBILE:
317 hw->mac_type = e1000_82541_rev_2;
318 break;
319 case E1000_DEV_ID_82547EI:
320 case E1000_DEV_ID_82547EI_MOBILE:
321 hw->mac_type = e1000_82547;
322 break;
323 case E1000_DEV_ID_82547GI:
324 hw->mac_type = e1000_82547_rev_2;
325 break;
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500326 default:
327 /* Should never have loaded on this device */
328 return -E1000_ERR_MAC_TYPE;
329 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500331 switch (hw->mac_type) {
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500332 case e1000_82541:
333 case e1000_82547:
334 case e1000_82541_rev_2:
335 case e1000_82547_rev_2:
Joe Perchesc3033b02008-03-21 11:06:25 -0700336 hw->asf_firmware_present = true;
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500337 break;
338 default:
339 break;
340 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341
Jeff Garzik167fb282006-12-15 10:41:15 -0500342 /* The 82543 chip does not count tx_carrier_errors properly in
343 * FD mode
344 */
345 if (hw->mac_type == e1000_82543)
Joe Perchesc3033b02008-03-21 11:06:25 -0700346 hw->bad_tx_carr_stats_fd = true;
Jeff Garzik167fb282006-12-15 10:41:15 -0500347
Jeff Garzik15e376b2006-12-15 11:16:33 -0500348 if (hw->mac_type > e1000_82544)
Joe Perchesc3033b02008-03-21 11:06:25 -0700349 hw->has_smbus = true;
Jeff Garzik15e376b2006-12-15 11:16:33 -0500350
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500351 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352}
353
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700354/**
355 * e1000_set_media_type - Set media type and TBI compatibility.
356 * @hw: Struct containing variables accessed by shared code
357 */
Joe Perches64798842008-07-11 15:17:02 -0700358void e1000_set_media_type(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700360 u32 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700362 DEBUGFUNC("e1000_set_media_type");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700364 if (hw->mac_type != e1000_82543) {
365 /* tbi_compatibility is only valid on 82543 */
366 hw->tbi_compatibility_en = false;
367 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700369 switch (hw->device_id) {
370 case E1000_DEV_ID_82545GM_SERDES:
371 case E1000_DEV_ID_82546GB_SERDES:
372 hw->media_type = e1000_media_type_internal_serdes;
373 break;
374 default:
375 switch (hw->mac_type) {
376 case e1000_82542_rev2_0:
377 case e1000_82542_rev2_1:
378 hw->media_type = e1000_media_type_fiber;
379 break;
380 default:
381 status = er32(STATUS);
382 if (status & E1000_STATUS_TBIMODE) {
383 hw->media_type = e1000_media_type_fiber;
384 /* tbi_compatibility not valid on fiber */
385 hw->tbi_compatibility_en = false;
386 } else {
387 hw->media_type = e1000_media_type_copper;
388 }
389 break;
390 }
391 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392}
393
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700394/**
395 * e1000_reset_hw: reset the hardware completely
396 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 *
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700398 * Reset the transmit and receive units; mask and clear all interrupts.
399 */
Joe Perches64798842008-07-11 15:17:02 -0700400s32 e1000_reset_hw(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700402 u32 ctrl;
403 u32 ctrl_ext;
404 u32 icr;
405 u32 manc;
406 u32 led_ctrl;
407 s32 ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700409 DEBUGFUNC("e1000_reset_hw");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700411 /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
412 if (hw->mac_type == e1000_82542_rev2_0) {
413 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
414 e1000_pci_clear_mwi(hw);
415 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700417 /* Clear interrupt mask to stop board from generating interrupts */
418 DEBUGOUT("Masking off all interrupts\n");
419 ew32(IMC, 0xffffffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700421 /* Disable the Transmit and Receive units. Then delay to allow
422 * any pending transactions to complete before we hit the MAC with
423 * the global reset.
424 */
425 ew32(RCTL, 0);
426 ew32(TCTL, E1000_TCTL_PSP);
427 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700429 /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
430 hw->tbi_compatibility_on = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700432 /* Delay to allow any outstanding PCI transactions to complete before
433 * resetting the device
434 */
435 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700437 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700439 /* Must reset the PHY before resetting the MAC */
440 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
441 ew32(CTRL, (ctrl | E1000_CTRL_PHY_RST));
442 msleep(5);
443 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700445 /* Issue a global reset to the MAC. This will reset the chip's
446 * transmit, receive, DMA, and link units. It will not effect
447 * the current PCI configuration. The global reset bit is self-
448 * clearing, and should clear within a microsecond.
449 */
450 DEBUGOUT("Issuing a global reset to MAC\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700452 switch (hw->mac_type) {
453 case e1000_82544:
454 case e1000_82540:
455 case e1000_82545:
456 case e1000_82546:
457 case e1000_82541:
458 case e1000_82541_rev_2:
459 /* These controllers can't ack the 64-bit write when issuing the
460 * reset, so use IO-mapping as a workaround to issue the reset */
461 E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
462 break;
463 case e1000_82545_rev_3:
464 case e1000_82546_rev_3:
465 /* Reset is performed on a shadow of the control register */
466 ew32(CTRL_DUP, (ctrl | E1000_CTRL_RST));
467 break;
468 default:
469 ew32(CTRL, (ctrl | E1000_CTRL_RST));
470 break;
471 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700473 /* After MAC reset, force reload of EEPROM to restore power-on settings to
474 * device. Later controllers reload the EEPROM automatically, so just wait
475 * for reload to complete.
476 */
477 switch (hw->mac_type) {
478 case e1000_82542_rev2_0:
479 case e1000_82542_rev2_1:
480 case e1000_82543:
481 case e1000_82544:
482 /* Wait for reset to complete */
483 udelay(10);
484 ctrl_ext = er32(CTRL_EXT);
485 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
486 ew32(CTRL_EXT, ctrl_ext);
487 E1000_WRITE_FLUSH();
488 /* Wait for EEPROM reload */
489 msleep(2);
490 break;
491 case e1000_82541:
492 case e1000_82541_rev_2:
493 case e1000_82547:
494 case e1000_82547_rev_2:
495 /* Wait for EEPROM reload */
496 msleep(20);
497 break;
498 default:
499 /* Auto read done will delay 5ms or poll based on mac type */
500 ret_val = e1000_get_auto_rd_done(hw);
501 if (ret_val)
502 return ret_val;
503 break;
504 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700506 /* Disable HW ARPs on ASF enabled adapters */
507 if (hw->mac_type >= e1000_82540) {
508 manc = er32(MANC);
509 manc &= ~(E1000_MANC_ARP_EN);
510 ew32(MANC, manc);
511 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700513 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
514 e1000_phy_init_script(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700516 /* Configure activity LED after PHY reset */
517 led_ctrl = er32(LEDCTL);
518 led_ctrl &= IGP_ACTIVITY_LED_MASK;
519 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
520 ew32(LEDCTL, led_ctrl);
521 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700523 /* Clear interrupt mask to stop board from generating interrupts */
524 DEBUGOUT("Masking off all interrupts\n");
525 ew32(IMC, 0xffffffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700527 /* Clear any pending interrupt events. */
528 icr = er32(ICR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700530 /* If MWI was previously enabled, reenable it. */
531 if (hw->mac_type == e1000_82542_rev2_0) {
532 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
533 e1000_pci_set_mwi(hw);
534 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700536 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537}
538
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700539/**
540 * e1000_init_hw: Performs basic configuration of the adapter.
541 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 *
543 * Assumes that the controller has previously been reset and is in a
544 * post-reset uninitialized state. Initializes the receive address registers,
545 * multicast table, and VLAN filter table. Calls routines to setup link
546 * configuration and flow control settings. Clears all on-chip counters. Leaves
547 * the transmit and receive units disabled and uninitialized.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700548 */
Joe Perches64798842008-07-11 15:17:02 -0700549s32 e1000_init_hw(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700551 u32 ctrl;
552 u32 i;
553 s32 ret_val;
554 u32 mta_size;
555 u32 ctrl_ext;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700556
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700557 DEBUGFUNC("e1000_init_hw");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700559 /* Initialize Identification LED */
560 ret_val = e1000_id_led_init(hw);
561 if (ret_val) {
562 DEBUGOUT("Error Initializing Identification LED\n");
563 return ret_val;
564 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700566 /* Set the media type and TBI compatibility */
567 e1000_set_media_type(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700569 /* Disabling VLAN filtering. */
570 DEBUGOUT("Initializing the IEEE VLAN\n");
571 if (hw->mac_type < e1000_82545_rev_3)
572 ew32(VET, 0);
573 e1000_clear_vfta(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700575 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
576 if (hw->mac_type == e1000_82542_rev2_0) {
577 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
578 e1000_pci_clear_mwi(hw);
579 ew32(RCTL, E1000_RCTL_RST);
580 E1000_WRITE_FLUSH();
581 msleep(5);
582 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700584 /* Setup the receive address. This involves initializing all of the Receive
585 * Address Registers (RARs 0 - 15).
586 */
587 e1000_init_rx_addrs(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700589 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
590 if (hw->mac_type == e1000_82542_rev2_0) {
591 ew32(RCTL, 0);
592 E1000_WRITE_FLUSH();
593 msleep(1);
594 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
595 e1000_pci_set_mwi(hw);
596 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700598 /* Zero out the Multicast HASH table */
599 DEBUGOUT("Zeroing the MTA\n");
600 mta_size = E1000_MC_TBL_SIZE;
601 for (i = 0; i < mta_size; i++) {
602 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
603 /* use write flush to prevent Memory Write Block (MWB) from
604 * occurring when accessing our register space */
605 E1000_WRITE_FLUSH();
606 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700608 /* Set the PCI priority bit correctly in the CTRL register. This
609 * determines if the adapter gives priority to receives, or if it
610 * gives equal priority to transmits and receives. Valid only on
611 * 82542 and 82543 silicon.
612 */
613 if (hw->dma_fairness && hw->mac_type <= e1000_82543) {
614 ctrl = er32(CTRL);
615 ew32(CTRL, ctrl | E1000_CTRL_PRIOR);
616 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700618 switch (hw->mac_type) {
619 case e1000_82545_rev_3:
620 case e1000_82546_rev_3:
621 break;
622 default:
623 /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
624 if (hw->bus_type == e1000_bus_type_pcix
625 && e1000_pcix_get_mmrbc(hw) > 2048)
626 e1000_pcix_set_mmrbc(hw, 2048);
627 break;
628 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700630 /* Call a subroutine to configure the link and setup flow control. */
631 ret_val = e1000_setup_link(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700633 /* Set the transmit descriptor write-back policy */
634 if (hw->mac_type > e1000_82544) {
635 ctrl = er32(TXDCTL);
636 ctrl =
637 (ctrl & ~E1000_TXDCTL_WTHRESH) |
638 E1000_TXDCTL_FULL_TX_DESC_WB;
639 ew32(TXDCTL, ctrl);
640 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700642 /* 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700649 if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER ||
650 hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) {
651 ctrl_ext = er32(CTRL_EXT);
652 /* Relaxed ordering must be disabled to avoid a parity
653 * error crash in a PCI slot. */
654 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
655 ew32(CTRL_EXT, ctrl_ext);
656 }
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -0800657
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700658 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659}
660
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700661/**
662 * e1000_adjust_serdes_amplitude - Adjust SERDES output amplitude based on EEPROM setting.
663 * @hw: Struct containing variables accessed by shared code.
664 */
Joe Perches64798842008-07-11 15:17:02 -0700665static s32 e1000_adjust_serdes_amplitude(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700667 u16 eeprom_data;
668 s32 ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700670 DEBUGFUNC("e1000_adjust_serdes_amplitude");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700672 if (hw->media_type != e1000_media_type_internal_serdes)
673 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700675 switch (hw->mac_type) {
676 case e1000_82545_rev_3:
677 case e1000_82546_rev_3:
678 break;
679 default:
680 return E1000_SUCCESS;
681 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700683 ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1,
684 &eeprom_data);
685 if (ret_val) {
686 return ret_val;
687 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700689 if (eeprom_data != EEPROM_RESERVED_WORD) {
690 /* Adjust SERDES output amplitude only. */
691 eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK;
692 ret_val =
693 e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data);
694 if (ret_val)
695 return ret_val;
696 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700698 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699}
700
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700701/**
702 * e1000_setup_link - Configures flow control and link settings.
703 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 *
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700705 * Determines which flow control settings to use. Calls the appropriate media-
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 * 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.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700710 */
Joe Perches64798842008-07-11 15:17:02 -0700711s32 e1000_setup_link(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700713 u32 ctrl_ext;
714 s32 ret_val;
715 u16 eeprom_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700717 DEBUGFUNC("e1000_setup_link");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700719 /* 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 */
727 if (hw->fc == E1000_FC_DEFAULT) {
728 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;
733 }
734 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;
741 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700743 /* 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 */
747 if (hw->mac_type == e1000_82542_rev2_0)
748 hw->fc &= (~E1000_FC_TX_PAUSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700750 if ((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
751 hw->fc &= (~E1000_FC_RX_PAUSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700753 hw->original_fc = hw->fc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700755 DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700757 /* 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 */
764 if (hw->mac_type == e1000_82543) {
765 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 }
771 ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
772 SWDPIO__EXT_SHIFT);
773 ew32(CTRL_EXT, ctrl_ext);
774 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700776 /* Call the necessary subroutine to configure the link. */
777 ret_val = (hw->media_type == e1000_media_type_copper) ?
778 e1000_setup_copper_link(hw) : e1000_setup_fiber_serdes_link(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700780 /* Initialize the flow control address, type, and PAUSE timer
781 * registers to their default values. This is done even if flow
782 * control is disabled, because it does not hurt anything to
783 * initialize these registers.
784 */
785 DEBUGOUT
786 ("Initializing the Flow Control address, type and timer regs\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700788 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
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700792 ew32(FCTTV, hw->fc_pause_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700794 /* 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 */
800 if (!(hw->fc & E1000_FC_TX_PAUSE)) {
801 ew32(FCRTL, 0);
802 ew32(FCRTH, 0);
803 } 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 */
807 if (hw->fc_send_xon) {
808 ew32(FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE));
809 ew32(FCRTH, hw->fc_high_water);
810 } else {
811 ew32(FCRTL, hw->fc_low_water);
812 ew32(FCRTH, hw->fc_high_water);
813 }
814 }
815 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816}
817
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700818/**
819 * e1000_setup_fiber_serdes_link - prepare fiber or serdes link
820 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 *
822 * Manipulates Physical Coding Sublayer functions in order to configure
823 * link. Assumes the hardware has been previously reset and the transmitter
824 * and receiver are not enabled.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700825 */
Joe Perches64798842008-07-11 15:17:02 -0700826static s32 e1000_setup_fiber_serdes_link(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700828 u32 ctrl;
829 u32 status;
830 u32 txcw = 0;
831 u32 i;
832 u32 signal = 0;
833 s32 ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700835 DEBUGFUNC("e1000_setup_fiber_serdes_link");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700837 /* On adapters with a MAC newer than 82544, SWDP 1 will be
838 * set when the optics detect a signal. On older adapters, it will be
839 * cleared when there is a signal. This applies to fiber media only.
840 * If we're on serdes media, adjust the output amplitude to value
841 * set in the EEPROM.
842 */
843 ctrl = er32(CTRL);
844 if (hw->media_type == e1000_media_type_fiber)
845 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700847 ret_val = e1000_adjust_serdes_amplitude(hw);
848 if (ret_val)
849 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700851 /* Take the link out of reset */
852 ctrl &= ~(E1000_CTRL_LRST);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700854 /* Adjust VCO speed to improve BER performance */
855 ret_val = e1000_set_vco_speed(hw);
856 if (ret_val)
857 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700859 e1000_config_collision_dist(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700861 /* Check for a software override of the flow control settings, and setup
862 * the device accordingly. If auto-negotiation is enabled, then software
863 * will have to set the "PAUSE" bits to the correct value in the Tranmsit
864 * Config Word Register (TXCW) and re-start auto-negotiation. However, if
865 * auto-negotiation is disabled, then software will have to manually
866 * configure the two flow control enable bits in the CTRL register.
867 *
868 * The possible values of the "fc" parameter are:
869 * 0: Flow control is completely disabled
870 * 1: Rx flow control is enabled (we can receive pause frames, but
871 * not send pause frames).
872 * 2: Tx flow control is enabled (we can send pause frames but we do
873 * not support receiving pause frames).
874 * 3: Both Rx and TX flow control (symmetric) are enabled.
875 */
876 switch (hw->fc) {
877 case E1000_FC_NONE:
878 /* Flow control is completely disabled by a software over-ride. */
879 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
880 break;
881 case E1000_FC_RX_PAUSE:
882 /* RX Flow control is enabled and TX Flow control is disabled by a
883 * software over-ride. Since there really isn't a way to advertise
884 * that we are capable of RX Pause ONLY, we will advertise that we
885 * support both symmetric and asymmetric RX PAUSE. Later, we will
886 * disable the adapter's ability to send PAUSE frames.
887 */
888 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
889 break;
890 case E1000_FC_TX_PAUSE:
891 /* TX Flow control is enabled, and RX Flow control is disabled, by a
892 * software over-ride.
893 */
894 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
895 break;
896 case E1000_FC_FULL:
897 /* Flow control (both RX and TX) is enabled by a software over-ride. */
898 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
899 break;
900 default:
901 DEBUGOUT("Flow control param set incorrectly\n");
902 return -E1000_ERR_CONFIG;
903 break;
904 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700906 /* Since auto-negotiation is enabled, take the link out of reset (the link
907 * will be in reset, because we previously reset the chip). This will
908 * restart auto-negotiation. If auto-negotiation is successful then the
909 * link-up status bit will be set and the flow control enable bits (RFCE
910 * and TFCE) will be set according to their negotiated value.
911 */
912 DEBUGOUT("Auto-negotiation enabled\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700914 ew32(TXCW, txcw);
915 ew32(CTRL, ctrl);
916 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700918 hw->txcw = txcw;
919 msleep(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700921 /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
922 * indication in the Device Status Register. Time-out if a link isn't
923 * seen in 500 milliseconds seconds (Auto-negotiation should complete in
924 * less than 500 milliseconds even if the other end is doing it in SW).
925 * For internal serdes, we just assume a signal is present, then poll.
926 */
927 if (hw->media_type == e1000_media_type_internal_serdes ||
928 (er32(CTRL) & E1000_CTRL_SWDPIN1) == signal) {
929 DEBUGOUT("Looking for Link\n");
930 for (i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
931 msleep(10);
932 status = er32(STATUS);
933 if (status & E1000_STATUS_LU)
934 break;
935 }
936 if (i == (LINK_UP_TIMEOUT / 10)) {
937 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);
945 if (ret_val) {
946 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958}
959
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700960/**
961 * e1000_copper_link_preconfig - early configuration for copper
962 * @hw: Struct containing variables accessed by shared code
963 *
964 * Make sure we have a valid PHY and change PHY mode before link setup.
965 */
Joe Perches64798842008-07-11 15:17:02 -0700966static s32 e1000_copper_link_preconfig(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700968 u32 ctrl;
969 s32 ret_val;
970 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700972 DEBUGFUNC("e1000_copper_link_preconfig");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700974 ctrl = er32(CTRL);
975 /* With 82543, we need to force speed and duplex on the MAC equal to what
976 * the PHY speed and duplex configuration is. In addition, we need to
977 * perform a hardware reset on the PHY to take it out of reset.
978 */
979 if (hw->mac_type > e1000_82543) {
980 ctrl |= E1000_CTRL_SLU;
981 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
982 ew32(CTRL, ctrl);
983 } else {
984 ctrl |=
985 (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
986 ew32(CTRL, ctrl);
987 ret_val = e1000_phy_hw_reset(hw);
988 if (ret_val)
989 return ret_val;
990 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700992 /* Make sure we have a valid PHY */
993 ret_val = e1000_detect_gig_phy(hw);
994 if (ret_val) {
995 DEBUGOUT("Error, did not detect valid phy.\n");
996 return ret_val;
997 }
998 DEBUGOUT1("Phy ID = %x \n", hw->phy_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001000 /* Set PHY to class A mode (if necessary) */
1001 ret_val = e1000_set_phy_mode(hw);
1002 if (ret_val)
1003 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001005 if ((hw->mac_type == e1000_82545_rev_3) ||
1006 (hw->mac_type == e1000_82546_rev_3)) {
1007 ret_val =
1008 e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1009 phy_data |= 0x00000008;
1010 ret_val =
1011 e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1012 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001014 if (hw->mac_type <= e1000_82543 ||
1015 hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
1016 hw->mac_type == e1000_82541_rev_2
1017 || hw->mac_type == e1000_82547_rev_2)
1018 hw->phy_reset_disable = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001020 return E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001021}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001023/**
1024 * e1000_copper_link_igp_setup - Copper link setup for e1000_phy_igp series.
1025 * @hw: Struct containing variables accessed by shared code
1026 */
Joe Perches64798842008-07-11 15:17:02 -07001027static s32 e1000_copper_link_igp_setup(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001028{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001029 u32 led_ctrl;
1030 s32 ret_val;
1031 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001033 DEBUGFUNC("e1000_copper_link_igp_setup");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001035 if (hw->phy_reset_disable)
1036 return E1000_SUCCESS;
Auke Kok76c224b2006-05-23 13:36:06 -07001037
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001038 ret_val = e1000_phy_reset(hw);
1039 if (ret_val) {
1040 DEBUGOUT("Error Resetting the PHY\n");
1041 return ret_val;
1042 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001044 /* Wait 15ms for MAC to configure PHY from eeprom settings */
1045 msleep(15);
1046 /* Configure activity LED after PHY reset */
1047 led_ctrl = er32(LEDCTL);
1048 led_ctrl &= IGP_ACTIVITY_LED_MASK;
1049 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
1050 ew32(LEDCTL, led_ctrl);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001051
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001052 /* The NVM settings will configure LPLU in D3 for IGP2 and IGP3 PHYs */
1053 if (hw->phy_type == e1000_phy_igp) {
1054 /* disable lplu d3 during driver init */
1055 ret_val = e1000_set_d3_lplu_state(hw, false);
1056 if (ret_val) {
1057 DEBUGOUT("Error Disabling LPLU D3\n");
1058 return ret_val;
1059 }
1060 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001061
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001062 /* Configure mdi-mdix settings */
1063 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1064 if (ret_val)
1065 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001066
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001067 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
1068 hw->dsp_config_state = e1000_dsp_config_disabled;
1069 /* Force MDI for earlier revs of the IGP PHY */
1070 phy_data &=
1071 ~(IGP01E1000_PSCR_AUTO_MDIX |
1072 IGP01E1000_PSCR_FORCE_MDI_MDIX);
1073 hw->mdix = 1;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001074
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001075 } else {
1076 hw->dsp_config_state = e1000_dsp_config_enabled;
1077 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001078
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001079 switch (hw->mdix) {
1080 case 1:
1081 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1082 break;
1083 case 2:
1084 phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
1085 break;
1086 case 0:
1087 default:
1088 phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
1089 break;
1090 }
1091 }
1092 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1093 if (ret_val)
1094 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001095
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001096 /* set auto-master slave resolution settings */
1097 if (hw->autoneg) {
1098 e1000_ms_type phy_ms_setting = hw->master_slave;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001099
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001100 if (hw->ffe_config_state == e1000_ffe_config_active)
1101 hw->ffe_config_state = e1000_ffe_config_enabled;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001102
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001103 if (hw->dsp_config_state == e1000_dsp_config_activated)
1104 hw->dsp_config_state = e1000_dsp_config_enabled;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001105
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001106 /* when autonegotiation advertisement is only 1000Mbps then we
1107 * should disable SmartSpeed and enable Auto MasterSlave
1108 * resolution as hardware default. */
1109 if (hw->autoneg_advertised == ADVERTISE_1000_FULL) {
1110 /* Disable SmartSpeed */
1111 ret_val =
1112 e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1113 &phy_data);
1114 if (ret_val)
1115 return ret_val;
1116 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1117 ret_val =
1118 e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1119 phy_data);
1120 if (ret_val)
1121 return ret_val;
1122 /* Set auto Master/Slave resolution process */
1123 ret_val =
1124 e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1125 if (ret_val)
1126 return ret_val;
1127 phy_data &= ~CR_1000T_MS_ENABLE;
1128 ret_val =
1129 e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1130 if (ret_val)
1131 return ret_val;
1132 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001134 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1135 if (ret_val)
1136 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001138 /* load defaults for future use */
1139 hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
1140 ((phy_data & CR_1000T_MS_VALUE) ?
1141 e1000_ms_force_master :
1142 e1000_ms_force_slave) : e1000_ms_auto;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001144 switch (phy_ms_setting) {
1145 case e1000_ms_force_master:
1146 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
1147 break;
1148 case e1000_ms_force_slave:
1149 phy_data |= CR_1000T_MS_ENABLE;
1150 phy_data &= ~(CR_1000T_MS_VALUE);
1151 break;
1152 case e1000_ms_auto:
1153 phy_data &= ~CR_1000T_MS_ENABLE;
1154 default:
1155 break;
1156 }
1157 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1158 if (ret_val)
1159 return ret_val;
1160 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001162 return E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001163}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001165/**
1166 * e1000_copper_link_mgp_setup - Copper link setup for e1000_phy_m88 series.
1167 * @hw: Struct containing variables accessed by shared code
1168 */
Joe Perches64798842008-07-11 15:17:02 -07001169static s32 e1000_copper_link_mgp_setup(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001170{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001171 s32 ret_val;
1172 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001174 DEBUGFUNC("e1000_copper_link_mgp_setup");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001175
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001176 if (hw->phy_reset_disable)
1177 return E1000_SUCCESS;
Auke Kok76c224b2006-05-23 13:36:06 -07001178
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001179 /* Enable CRS on TX. This must be set for half-duplex operation. */
1180 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1181 if (ret_val)
1182 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001183
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001184 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001185
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001186 /* Options:
1187 * MDI/MDI-X = 0 (default)
1188 * 0 - Auto for all speeds
1189 * 1 - MDI mode
1190 * 2 - MDI-X mode
1191 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1192 */
1193 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001194
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001195 switch (hw->mdix) {
1196 case 1:
1197 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
1198 break;
1199 case 2:
1200 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
1201 break;
1202 case 3:
1203 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
1204 break;
1205 case 0:
1206 default:
1207 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
1208 break;
1209 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001210
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001211 /* Options:
1212 * disable_polarity_correction = 0 (default)
1213 * Automatic Correction for Reversed Cable Polarity
1214 * 0 - Disabled
1215 * 1 - Enabled
1216 */
1217 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
1218 if (hw->disable_polarity_correction == 1)
1219 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
1220 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1221 if (ret_val)
1222 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001223
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001224 if (hw->phy_revision < M88E1011_I_REV_4) {
1225 /* Force TX_CLK in the Extended PHY Specific Control Register
1226 * to 25MHz clock.
1227 */
1228 ret_val =
1229 e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
1230 &phy_data);
1231 if (ret_val)
1232 return ret_val;
Auke Kokee040222006-06-27 09:08:03 -07001233
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001234 phy_data |= M88E1000_EPSCR_TX_CLK_25;
Auke Kokee040222006-06-27 09:08:03 -07001235
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001236 if ((hw->phy_revision == E1000_REVISION_2) &&
1237 (hw->phy_id == M88E1111_I_PHY_ID)) {
1238 /* Vidalia Phy, set the downshift counter to 5x */
1239 phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK);
1240 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
1241 ret_val = e1000_write_phy_reg(hw,
1242 M88E1000_EXT_PHY_SPEC_CTRL,
1243 phy_data);
1244 if (ret_val)
1245 return ret_val;
1246 } else {
1247 /* Configure Master and Slave downshift values */
1248 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
1249 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
1250 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
1251 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
1252 ret_val = e1000_write_phy_reg(hw,
1253 M88E1000_EXT_PHY_SPEC_CTRL,
1254 phy_data);
1255 if (ret_val)
1256 return ret_val;
1257 }
1258 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001260 /* SW Reset the PHY so all changes take effect */
1261 ret_val = e1000_phy_reset(hw);
1262 if (ret_val) {
1263 DEBUGOUT("Error Resetting the PHY\n");
1264 return ret_val;
1265 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001266
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001267 return E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001268}
1269
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001270/**
1271 * e1000_copper_link_autoneg - setup auto-neg
1272 * @hw: Struct containing variables accessed by shared code
1273 *
1274 * Setup auto-negotiation and flow control advertisements,
1275 * and then perform auto-negotiation.
1276 */
Joe Perches64798842008-07-11 15:17:02 -07001277static s32 e1000_copper_link_autoneg(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001278{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001279 s32 ret_val;
1280 u16 phy_data;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001281
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001282 DEBUGFUNC("e1000_copper_link_autoneg");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001283
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001284 /* Perform some bounds checking on the hw->autoneg_advertised
1285 * parameter. If this variable is zero, then set it to the default.
1286 */
1287 hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001288
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001289 /* If autoneg_advertised is zero, we assume it was not defaulted
1290 * by the calling code so we set to advertise full capability.
1291 */
1292 if (hw->autoneg_advertised == 0)
1293 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001294
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001295 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
1296 ret_val = e1000_phy_setup_autoneg(hw);
1297 if (ret_val) {
1298 DEBUGOUT("Error Setting up Auto-Negotiation\n");
1299 return ret_val;
1300 }
1301 DEBUGOUT("Restarting Auto-Neg\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001302
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001303 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
1304 * the Auto Neg Restart bit in the PHY control register.
1305 */
1306 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
1307 if (ret_val)
1308 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001309
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001310 phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
1311 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
1312 if (ret_val)
1313 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001314
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001315 /* Does the user want to wait for Auto-Neg to complete here, or
1316 * check at a later time (for example, callback routine).
1317 */
1318 if (hw->wait_autoneg_complete) {
1319 ret_val = e1000_wait_autoneg(hw);
1320 if (ret_val) {
1321 DEBUGOUT
1322 ("Error while waiting for autoneg to complete\n");
1323 return ret_val;
1324 }
1325 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001327 hw->get_link_status = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001329 return E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001330}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001332/**
1333 * e1000_copper_link_postconfig - post link setup
1334 * @hw: Struct containing variables accessed by shared code
1335 *
1336 * Config the MAC and the PHY after link is up.
1337 * 1) Set up the MAC to the current PHY speed/duplex
1338 * if we are on 82543. If we
1339 * are on newer silicon, we only need to configure
1340 * collision distance in the Transmit Control Register.
1341 * 2) Set up flow control on the MAC to that established with
1342 * the link partner.
1343 * 3) Config DSP to improve Gigabit link quality for some PHY revisions.
1344 */
Joe Perches64798842008-07-11 15:17:02 -07001345static s32 e1000_copper_link_postconfig(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001346{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001347 s32 ret_val;
1348 DEBUGFUNC("e1000_copper_link_postconfig");
Auke Kok76c224b2006-05-23 13:36:06 -07001349
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001350 if (hw->mac_type >= e1000_82544) {
1351 e1000_config_collision_dist(hw);
1352 } else {
1353 ret_val = e1000_config_mac_to_phy(hw);
1354 if (ret_val) {
1355 DEBUGOUT("Error configuring MAC to PHY settings\n");
1356 return ret_val;
1357 }
1358 }
1359 ret_val = e1000_config_fc_after_link_up(hw);
1360 if (ret_val) {
1361 DEBUGOUT("Error Configuring Flow Control\n");
1362 return ret_val;
1363 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001364
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001365 /* Config DSP to improve Giga link quality */
1366 if (hw->phy_type == e1000_phy_igp) {
1367 ret_val = e1000_config_dsp_after_link_change(hw, true);
1368 if (ret_val) {
1369 DEBUGOUT("Error Configuring DSP after link up\n");
1370 return ret_val;
1371 }
1372 }
Auke Kok76c224b2006-05-23 13:36:06 -07001373
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001374 return E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001375}
1376
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001377/**
1378 * e1000_setup_copper_link - phy/speed/duplex setting
1379 * @hw: Struct containing variables accessed by shared code
1380 *
1381 * Detects which PHY is present and sets up the speed and duplex
1382 */
Joe Perches64798842008-07-11 15:17:02 -07001383static s32 e1000_setup_copper_link(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001384{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001385 s32 ret_val;
1386 u16 i;
1387 u16 phy_data;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001388
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001389 DEBUGFUNC("e1000_setup_copper_link");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001390
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001391 /* Check if it is a valid PHY and set PHY mode if necessary. */
1392 ret_val = e1000_copper_link_preconfig(hw);
1393 if (ret_val)
1394 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001395
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001396 if (hw->phy_type == e1000_phy_igp) {
1397 ret_val = e1000_copper_link_igp_setup(hw);
1398 if (ret_val)
1399 return ret_val;
1400 } else if (hw->phy_type == e1000_phy_m88) {
1401 ret_val = e1000_copper_link_mgp_setup(hw);
1402 if (ret_val)
1403 return ret_val;
1404 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001405
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001406 if (hw->autoneg) {
1407 /* Setup autoneg and flow control advertisement
1408 * and perform autonegotiation */
1409 ret_val = e1000_copper_link_autoneg(hw);
1410 if (ret_val)
1411 return ret_val;
1412 } else {
1413 /* PHY will be set to 10H, 10F, 100H,or 100F
1414 * depending on value from forced_speed_duplex. */
1415 DEBUGOUT("Forcing speed and duplex\n");
1416 ret_val = e1000_phy_force_speed_duplex(hw);
1417 if (ret_val) {
1418 DEBUGOUT("Error Forcing Speed and Duplex\n");
1419 return ret_val;
1420 }
1421 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001423 /* Check link status. Wait up to 100 microseconds for link to become
1424 * valid.
1425 */
1426 for (i = 0; i < 10; i++) {
1427 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
1428 if (ret_val)
1429 return ret_val;
1430 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
1431 if (ret_val)
1432 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001434 if (phy_data & MII_SR_LINK_STATUS) {
1435 /* Config the MAC and PHY after link is up */
1436 ret_val = e1000_copper_link_postconfig(hw);
1437 if (ret_val)
1438 return ret_val;
Auke Kok76c224b2006-05-23 13:36:06 -07001439
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001440 DEBUGOUT("Valid link established!!!\n");
1441 return E1000_SUCCESS;
1442 }
1443 udelay(10);
1444 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001446 DEBUGOUT("Unable to establish link!!!\n");
1447 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448}
1449
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001450/**
1451 * e1000_phy_setup_autoneg - phy settings
1452 * @hw: Struct containing variables accessed by shared code
1453 *
1454 * Configures PHY autoneg and flow control advertisement settings
1455 */
Joe Perches64798842008-07-11 15:17:02 -07001456s32 e1000_phy_setup_autoneg(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001458 s32 ret_val;
1459 u16 mii_autoneg_adv_reg;
1460 u16 mii_1000t_ctrl_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001462 DEBUGFUNC("e1000_phy_setup_autoneg");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001464 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
1465 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
1466 if (ret_val)
1467 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001469 /* Read the MII 1000Base-T Control Register (Address 9). */
1470 ret_val =
1471 e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
1472 if (ret_val)
1473 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001475 /* Need to parse both autoneg_advertised and fc and set up
1476 * the appropriate PHY registers. First we will parse for
1477 * autoneg_advertised software override. Since we can advertise
1478 * a plethora of combinations, we need to check each bit
1479 * individually.
1480 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001482 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
1483 * Advertisement Register (Address 4) and the 1000 mb speed bits in
1484 * the 1000Base-T Control Register (Address 9).
1485 */
1486 mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
1487 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001489 DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001491 /* Do we want to advertise 10 Mb Half Duplex? */
1492 if (hw->autoneg_advertised & ADVERTISE_10_HALF) {
1493 DEBUGOUT("Advertise 10mb Half duplex\n");
1494 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
1495 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001497 /* Do we want to advertise 10 Mb Full Duplex? */
1498 if (hw->autoneg_advertised & ADVERTISE_10_FULL) {
1499 DEBUGOUT("Advertise 10mb Full duplex\n");
1500 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
1501 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001503 /* Do we want to advertise 100 Mb Half Duplex? */
1504 if (hw->autoneg_advertised & ADVERTISE_100_HALF) {
1505 DEBUGOUT("Advertise 100mb Half duplex\n");
1506 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
1507 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001509 /* Do we want to advertise 100 Mb Full Duplex? */
1510 if (hw->autoneg_advertised & ADVERTISE_100_FULL) {
1511 DEBUGOUT("Advertise 100mb Full duplex\n");
1512 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
1513 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001515 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
1516 if (hw->autoneg_advertised & ADVERTISE_1000_HALF) {
1517 DEBUGOUT
1518 ("Advertise 1000mb Half duplex requested, request denied!\n");
1519 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001521 /* Do we want to advertise 1000 Mb Full Duplex? */
1522 if (hw->autoneg_advertised & ADVERTISE_1000_FULL) {
1523 DEBUGOUT("Advertise 1000mb Full duplex\n");
1524 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
1525 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001527 /* Check for a software override of the flow control settings, and
1528 * setup the PHY advertisement registers accordingly. If
1529 * auto-negotiation is enabled, then software will have to set the
1530 * "PAUSE" bits to the correct value in the Auto-Negotiation
1531 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
1532 *
1533 * The possible values of the "fc" parameter are:
1534 * 0: Flow control is completely disabled
1535 * 1: Rx flow control is enabled (we can receive pause frames
1536 * but not send pause frames).
1537 * 2: Tx flow control is enabled (we can send pause frames
1538 * but we do not support receiving pause frames).
1539 * 3: Both Rx and TX flow control (symmetric) are enabled.
1540 * other: No software override. The flow control configuration
1541 * in the EEPROM is used.
1542 */
1543 switch (hw->fc) {
1544 case E1000_FC_NONE: /* 0 */
1545 /* Flow control (RX & TX) is completely disabled by a
1546 * software over-ride.
1547 */
1548 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1549 break;
1550 case E1000_FC_RX_PAUSE: /* 1 */
1551 /* RX Flow control is enabled, and TX Flow control is
1552 * disabled, by a software over-ride.
1553 */
1554 /* Since there really isn't a way to advertise that we are
1555 * capable of RX Pause ONLY, we will advertise that we
1556 * support both symmetric and asymmetric RX PAUSE. Later
1557 * (in e1000_config_fc_after_link_up) we will disable the
1558 *hw's ability to send PAUSE frames.
1559 */
1560 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1561 break;
1562 case E1000_FC_TX_PAUSE: /* 2 */
1563 /* TX Flow control is enabled, and RX Flow control is
1564 * disabled, by a software over-ride.
1565 */
1566 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
1567 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
1568 break;
1569 case E1000_FC_FULL: /* 3 */
1570 /* Flow control (both RX and TX) is enabled by a software
1571 * over-ride.
1572 */
1573 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1574 break;
1575 default:
1576 DEBUGOUT("Flow control param set incorrectly\n");
1577 return -E1000_ERR_CONFIG;
1578 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001580 ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
1581 if (ret_val)
1582 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001584 DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001586 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg);
1587 if (ret_val)
1588 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001590 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591}
1592
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001593/**
1594 * e1000_phy_force_speed_duplex - force link settings
1595 * @hw: Struct containing variables accessed by shared code
1596 *
1597 * Force PHY speed and duplex settings to hw->forced_speed_duplex
1598 */
Joe Perches64798842008-07-11 15:17:02 -07001599static s32 e1000_phy_force_speed_duplex(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001601 u32 ctrl;
1602 s32 ret_val;
1603 u16 mii_ctrl_reg;
1604 u16 mii_status_reg;
1605 u16 phy_data;
1606 u16 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001608 DEBUGFUNC("e1000_phy_force_speed_duplex");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001610 /* Turn off Flow control if we are forcing speed and duplex. */
1611 hw->fc = E1000_FC_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001613 DEBUGOUT1("hw->fc = %d\n", hw->fc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001615 /* Read the Device Control Register. */
1616 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001618 /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */
1619 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1620 ctrl &= ~(DEVICE_SPEED_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001622 /* Clear the Auto Speed Detect Enable bit. */
1623 ctrl &= ~E1000_CTRL_ASDE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001625 /* Read the MII Control Register. */
1626 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg);
1627 if (ret_val)
1628 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001630 /* We need to disable autoneg in order to force link and duplex. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001632 mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001634 /* Are we forcing Full or Half Duplex? */
1635 if (hw->forced_speed_duplex == e1000_100_full ||
1636 hw->forced_speed_duplex == e1000_10_full) {
1637 /* We want to force full duplex so we SET the full duplex bits in the
1638 * Device and MII Control Registers.
1639 */
1640 ctrl |= E1000_CTRL_FD;
1641 mii_ctrl_reg |= MII_CR_FULL_DUPLEX;
1642 DEBUGOUT("Full Duplex\n");
1643 } else {
1644 /* We want to force half duplex so we CLEAR the full duplex bits in
1645 * the Device and MII Control Registers.
1646 */
1647 ctrl &= ~E1000_CTRL_FD;
1648 mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX;
1649 DEBUGOUT("Half Duplex\n");
1650 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001652 /* Are we forcing 100Mbps??? */
1653 if (hw->forced_speed_duplex == e1000_100_full ||
1654 hw->forced_speed_duplex == e1000_100_half) {
1655 /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */
1656 ctrl |= E1000_CTRL_SPD_100;
1657 mii_ctrl_reg |= MII_CR_SPEED_100;
1658 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
1659 DEBUGOUT("Forcing 100mb ");
1660 } else {
1661 /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */
1662 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1663 mii_ctrl_reg |= MII_CR_SPEED_10;
1664 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
1665 DEBUGOUT("Forcing 10mb ");
1666 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001668 e1000_config_collision_dist(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001670 /* Write the configured values back to the Device Control Reg. */
1671 ew32(CTRL, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001673 if (hw->phy_type == e1000_phy_m88) {
1674 ret_val =
1675 e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1676 if (ret_val)
1677 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001679 /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
1680 * forced whenever speed are duplex are forced.
1681 */
1682 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1683 ret_val =
1684 e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1685 if (ret_val)
1686 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001688 DEBUGOUT1("M88E1000 PSCR: %x \n", phy_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001690 /* Need to reset the PHY or these changes will be ignored */
1691 mii_ctrl_reg |= MII_CR_RESET;
Auke Kok90fb5132006-11-01 08:47:30 -08001692
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001693 /* Disable MDI-X support for 10/100 */
1694 } else {
1695 /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
1696 * forced whenever speed or duplex are forced.
1697 */
1698 ret_val =
1699 e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1700 if (ret_val)
1701 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001703 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1704 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001706 ret_val =
1707 e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1708 if (ret_val)
1709 return ret_val;
1710 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001712 /* Write back the modified PHY MII control register. */
1713 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg);
1714 if (ret_val)
1715 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001717 udelay(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001719 /* The wait_autoneg_complete flag may be a little misleading here.
1720 * Since we are forcing speed and duplex, Auto-Neg is not enabled.
1721 * But we do want to delay for a period while forcing only so we
1722 * don't generate false No Link messages. So we will wait here
1723 * only if the user has set wait_autoneg_complete to 1, which is
1724 * the default.
1725 */
1726 if (hw->wait_autoneg_complete) {
1727 /* We will wait for autoneg to complete. */
1728 DEBUGOUT("Waiting for forced speed/duplex link.\n");
1729 mii_status_reg = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001731 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
1732 for (i = PHY_FORCE_TIME; i > 0; i--) {
1733 /* Read the MII Status Register and wait for Auto-Neg Complete bit
1734 * to be set.
1735 */
1736 ret_val =
1737 e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1738 if (ret_val)
1739 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001741 ret_val =
1742 e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1743 if (ret_val)
1744 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001746 if (mii_status_reg & MII_SR_LINK_STATUS)
1747 break;
1748 msleep(100);
1749 }
1750 if ((i == 0) && (hw->phy_type == e1000_phy_m88)) {
1751 /* We didn't get link. Reset the DSP and wait again for link. */
1752 ret_val = e1000_phy_reset_dsp(hw);
1753 if (ret_val) {
1754 DEBUGOUT("Error Resetting PHY DSP\n");
1755 return ret_val;
1756 }
1757 }
1758 /* This loop will early-out if the link condition has been met. */
1759 for (i = PHY_FORCE_TIME; i > 0; i--) {
1760 if (mii_status_reg & MII_SR_LINK_STATUS)
1761 break;
1762 msleep(100);
1763 /* Read the MII Status Register and wait for Auto-Neg Complete bit
1764 * to be set.
1765 */
1766 ret_val =
1767 e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1768 if (ret_val)
1769 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001771 ret_val =
1772 e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1773 if (ret_val)
1774 return ret_val;
1775 }
1776 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001778 if (hw->phy_type == e1000_phy_m88) {
1779 /* Because we reset the PHY above, we need to re-force TX_CLK in the
1780 * Extended PHY Specific Control Register to 25MHz clock. This value
1781 * defaults back to a 2.5MHz clock when the PHY is reset.
1782 */
1783 ret_val =
1784 e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
1785 &phy_data);
1786 if (ret_val)
1787 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001789 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1790 ret_val =
1791 e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
1792 phy_data);
1793 if (ret_val)
1794 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001796 /* In addition, because of the s/w reset above, we need to enable CRS on
1797 * TX. This must be set for both full and half duplex operation.
1798 */
1799 ret_val =
1800 e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1801 if (ret_val)
1802 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001804 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1805 ret_val =
1806 e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1807 if (ret_val)
1808 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001810 if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543)
1811 && (!hw->autoneg)
1812 && (hw->forced_speed_duplex == e1000_10_full
1813 || hw->forced_speed_duplex == e1000_10_half)) {
1814 ret_val = e1000_polarity_reversal_workaround(hw);
1815 if (ret_val)
1816 return ret_val;
1817 }
1818 }
1819 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820}
1821
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001822/**
1823 * e1000_config_collision_dist - set collision distance register
1824 * @hw: Struct containing variables accessed by shared code
1825 *
1826 * Sets the collision distance in the Transmit Control register.
1827 * Link should have been established previously. Reads the speed and duplex
1828 * information from the Device Status register.
1829 */
Joe Perches64798842008-07-11 15:17:02 -07001830void e1000_config_collision_dist(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001832 u32 tctl, coll_dist;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001834 DEBUGFUNC("e1000_config_collision_dist");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001836 if (hw->mac_type < e1000_82543)
1837 coll_dist = E1000_COLLISION_DISTANCE_82542;
1838 else
1839 coll_dist = E1000_COLLISION_DISTANCE;
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001840
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001841 tctl = er32(TCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001843 tctl &= ~E1000_TCTL_COLD;
1844 tctl |= coll_dist << E1000_COLD_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001846 ew32(TCTL, tctl);
1847 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848}
1849
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001850/**
1851 * e1000_config_mac_to_phy - sync phy and mac settings
1852 * @hw: Struct containing variables accessed by shared code
1853 * @mii_reg: data to write to the MII control register
1854 *
1855 * Sets MAC speed and duplex settings to reflect the those in the PHY
1856 * The contents of the PHY register containing the needed information need to
1857 * be passed in.
1858 */
Joe Perches64798842008-07-11 15:17:02 -07001859static s32 e1000_config_mac_to_phy(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001861 u32 ctrl;
1862 s32 ret_val;
1863 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001865 DEBUGFUNC("e1000_config_mac_to_phy");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001867 /* 82544 or newer MAC, Auto Speed Detection takes care of
1868 * MAC speed/duplex configuration.*/
1869 if (hw->mac_type >= e1000_82544)
1870 return E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001871
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001872 /* Read the Device Control Register and set the bits to Force Speed
1873 * and Duplex.
1874 */
1875 ctrl = er32(CTRL);
1876 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1877 ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001879 /* Set up duplex in the Device Control and Transmit Control
1880 * registers depending on negotiated values.
1881 */
1882 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
1883 if (ret_val)
1884 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001886 if (phy_data & M88E1000_PSSR_DPLX)
1887 ctrl |= E1000_CTRL_FD;
1888 else
1889 ctrl &= ~E1000_CTRL_FD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001891 e1000_config_collision_dist(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001893 /* Set up speed in the Device Control register depending on
1894 * negotiated values.
1895 */
1896 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
1897 ctrl |= E1000_CTRL_SPD_1000;
1898 else if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
1899 ctrl |= E1000_CTRL_SPD_100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001901 /* Write the configured values back to the Device Control Reg. */
1902 ew32(CTRL, ctrl);
1903 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904}
1905
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001906/**
1907 * e1000_force_mac_fc - force flow control settings
1908 * @hw: Struct containing variables accessed by shared code
1909 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910 * Forces the MAC's flow control settings.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911 * Sets the TFCE and RFCE bits in the device control register to reflect
1912 * the adapter settings. TFCE and RFCE need to be explicitly set by
1913 * software when a Copper PHY is used because autonegotiation is managed
1914 * by the PHY rather than the MAC. Software must also configure these
1915 * bits when link is forced on a fiber connection.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001916 */
Joe Perches64798842008-07-11 15:17:02 -07001917s32 e1000_force_mac_fc(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001918{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001919 u32 ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001921 DEBUGFUNC("e1000_force_mac_fc");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001922
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001923 /* Get the current configuration of the Device Control Register */
1924 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001926 /* Because we didn't get link via the internal auto-negotiation
1927 * mechanism (we either forced link or we got link via PHY
1928 * auto-neg), we have to manually enable/disable transmit an
1929 * receive flow control.
1930 *
1931 * The "Case" statement below enables/disable flow control
1932 * according to the "hw->fc" parameter.
1933 *
1934 * The possible values of the "fc" parameter are:
1935 * 0: Flow control is completely disabled
1936 * 1: Rx flow control is enabled (we can receive pause
1937 * frames but not send pause frames).
1938 * 2: Tx flow control is enabled (we can send pause frames
1939 * frames but we do not receive pause frames).
1940 * 3: Both Rx and TX flow control (symmetric) is enabled.
1941 * other: No other values should be possible at this point.
1942 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001944 switch (hw->fc) {
1945 case E1000_FC_NONE:
1946 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
1947 break;
1948 case E1000_FC_RX_PAUSE:
1949 ctrl &= (~E1000_CTRL_TFCE);
1950 ctrl |= E1000_CTRL_RFCE;
1951 break;
1952 case E1000_FC_TX_PAUSE:
1953 ctrl &= (~E1000_CTRL_RFCE);
1954 ctrl |= E1000_CTRL_TFCE;
1955 break;
1956 case E1000_FC_FULL:
1957 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
1958 break;
1959 default:
1960 DEBUGOUT("Flow control param set incorrectly\n");
1961 return -E1000_ERR_CONFIG;
1962 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001964 /* Disable TX Flow Control for 82542 (rev 2.0) */
1965 if (hw->mac_type == e1000_82542_rev2_0)
1966 ctrl &= (~E1000_CTRL_TFCE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001968 ew32(CTRL, ctrl);
1969 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001970}
1971
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001972/**
1973 * e1000_config_fc_after_link_up - configure flow control after autoneg
1974 * @hw: Struct containing variables accessed by shared code
1975 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001976 * Configures flow control settings after link is established
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977 * Should be called immediately after a valid link has been established.
1978 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
1979 * and autonegotiation is enabled, the MAC flow control settings will be set
1980 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001981 * and RFCE bits will be automatically set to the negotiated flow control mode.
1982 */
Joe Perches64798842008-07-11 15:17:02 -07001983static s32 e1000_config_fc_after_link_up(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001985 s32 ret_val;
1986 u16 mii_status_reg;
1987 u16 mii_nway_adv_reg;
1988 u16 mii_nway_lp_ability_reg;
1989 u16 speed;
1990 u16 duplex;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001992 DEBUGFUNC("e1000_config_fc_after_link_up");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001993
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001994 /* Check for the case where we have fiber media and auto-neg failed
1995 * so we had to force link. In this case, we need to force the
1996 * configuration of the MAC to match the "fc" parameter.
1997 */
1998 if (((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed))
1999 || ((hw->media_type == e1000_media_type_internal_serdes)
2000 && (hw->autoneg_failed))
2001 || ((hw->media_type == e1000_media_type_copper)
2002 && (!hw->autoneg))) {
2003 ret_val = e1000_force_mac_fc(hw);
2004 if (ret_val) {
2005 DEBUGOUT("Error forcing flow control settings\n");
2006 return ret_val;
2007 }
2008 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002010 /* Check for the case where we have copper media and auto-neg is
2011 * enabled. In this case, we need to check and see if Auto-Neg
2012 * has completed, and if so, how the PHY and link partner has
2013 * flow control configured.
2014 */
2015 if ((hw->media_type == e1000_media_type_copper) && hw->autoneg) {
2016 /* Read the MII Status Register and check to see if AutoNeg
2017 * has completed. We read this twice because this reg has
2018 * some "sticky" (latched) bits.
2019 */
2020 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2021 if (ret_val)
2022 return ret_val;
2023 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2024 if (ret_val)
2025 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002027 if (mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
2028 /* The AutoNeg process has completed, so we now need to
2029 * read both the Auto Negotiation Advertisement Register
2030 * (Address 4) and the Auto_Negotiation Base Page Ability
2031 * Register (Address 5) to determine how flow control was
2032 * negotiated.
2033 */
2034 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV,
2035 &mii_nway_adv_reg);
2036 if (ret_val)
2037 return ret_val;
2038 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY,
2039 &mii_nway_lp_ability_reg);
2040 if (ret_val)
2041 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002043 /* Two bits in the Auto Negotiation Advertisement Register
2044 * (Address 4) and two bits in the Auto Negotiation Base
2045 * Page Ability Register (Address 5) determine flow control
2046 * for both the PHY and the link partner. The following
2047 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
2048 * 1999, describes these PAUSE resolution bits and how flow
2049 * control is determined based upon these settings.
2050 * NOTE: DC = Don't Care
2051 *
2052 * LOCAL DEVICE | LINK PARTNER
2053 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
2054 *-------|---------|-------|---------|--------------------
2055 * 0 | 0 | DC | DC | E1000_FC_NONE
2056 * 0 | 1 | 0 | DC | E1000_FC_NONE
2057 * 0 | 1 | 1 | 0 | E1000_FC_NONE
2058 * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
2059 * 1 | 0 | 0 | DC | E1000_FC_NONE
2060 * 1 | DC | 1 | DC | E1000_FC_FULL
2061 * 1 | 1 | 0 | 0 | E1000_FC_NONE
2062 * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
2063 *
2064 */
2065 /* Are both PAUSE bits set to 1? If so, this implies
2066 * Symmetric Flow Control is enabled at both ends. The
2067 * ASM_DIR bits are irrelevant per the spec.
2068 *
2069 * For Symmetric Flow Control:
2070 *
2071 * LOCAL DEVICE | LINK PARTNER
2072 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2073 *-------|---------|-------|---------|--------------------
2074 * 1 | DC | 1 | DC | E1000_FC_FULL
2075 *
2076 */
2077 if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2078 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
2079 /* Now we need to check if the user selected RX ONLY
2080 * of pause frames. In this case, we had to advertise
2081 * FULL flow control because we could not advertise RX
2082 * ONLY. Hence, we must now check to see if we need to
2083 * turn OFF the TRANSMISSION of PAUSE frames.
2084 */
2085 if (hw->original_fc == E1000_FC_FULL) {
2086 hw->fc = E1000_FC_FULL;
2087 DEBUGOUT("Flow Control = FULL.\n");
2088 } else {
2089 hw->fc = E1000_FC_RX_PAUSE;
2090 DEBUGOUT
2091 ("Flow Control = RX PAUSE frames only.\n");
2092 }
2093 }
2094 /* For receiving PAUSE frames ONLY.
2095 *
2096 * LOCAL DEVICE | LINK PARTNER
2097 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2098 *-------|---------|-------|---------|--------------------
2099 * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
2100 *
2101 */
2102 else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2103 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2104 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2105 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR))
2106 {
2107 hw->fc = E1000_FC_TX_PAUSE;
2108 DEBUGOUT
2109 ("Flow Control = TX PAUSE frames only.\n");
2110 }
2111 /* For transmitting PAUSE frames ONLY.
2112 *
2113 * LOCAL DEVICE | LINK PARTNER
2114 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2115 *-------|---------|-------|---------|--------------------
2116 * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
2117 *
2118 */
2119 else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2120 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2121 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2122 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR))
2123 {
2124 hw->fc = E1000_FC_RX_PAUSE;
2125 DEBUGOUT
2126 ("Flow Control = RX PAUSE frames only.\n");
2127 }
2128 /* Per the IEEE spec, at this point flow control should be
2129 * disabled. However, we want to consider that we could
2130 * be connected to a legacy switch that doesn't advertise
2131 * desired flow control, but can be forced on the link
2132 * partner. So if we advertised no flow control, that is
2133 * what we will resolve to. If we advertised some kind of
2134 * receive capability (Rx Pause Only or Full Flow Control)
2135 * and the link partner advertised none, we will configure
2136 * ourselves to enable Rx Flow Control only. We can do
2137 * this safely for two reasons: If the link partner really
2138 * didn't want flow control enabled, and we enable Rx, no
2139 * harm done since we won't be receiving any PAUSE frames
2140 * anyway. If the intent on the link partner was to have
2141 * flow control enabled, then by us enabling RX only, we
2142 * can at least receive pause frames and process them.
2143 * This is a good idea because in most cases, since we are
2144 * predominantly a server NIC, more times than not we will
2145 * be asked to delay transmission of packets than asking
2146 * our link partner to pause transmission of frames.
2147 */
2148 else if ((hw->original_fc == E1000_FC_NONE ||
2149 hw->original_fc == E1000_FC_TX_PAUSE) ||
2150 hw->fc_strict_ieee) {
2151 hw->fc = E1000_FC_NONE;
2152 DEBUGOUT("Flow Control = NONE.\n");
2153 } else {
2154 hw->fc = E1000_FC_RX_PAUSE;
2155 DEBUGOUT
2156 ("Flow Control = RX PAUSE frames only.\n");
2157 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002159 /* Now we need to do one last check... If we auto-
2160 * negotiated to HALF DUPLEX, flow control should not be
2161 * enabled per IEEE 802.3 spec.
2162 */
2163 ret_val =
2164 e1000_get_speed_and_duplex(hw, &speed, &duplex);
2165 if (ret_val) {
2166 DEBUGOUT
2167 ("Error getting link speed and duplex\n");
2168 return ret_val;
2169 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002171 if (duplex == HALF_DUPLEX)
2172 hw->fc = E1000_FC_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002174 /* Now we call a subroutine to actually force the MAC
2175 * controller to use the correct flow control settings.
2176 */
2177 ret_val = e1000_force_mac_fc(hw);
2178 if (ret_val) {
2179 DEBUGOUT
2180 ("Error forcing flow control settings\n");
2181 return ret_val;
2182 }
2183 } else {
2184 DEBUGOUT
2185 ("Copper PHY and Auto Neg has not completed.\n");
2186 }
2187 }
2188 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189}
2190
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002191/**
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002192 * e1000_check_for_serdes_link_generic - Check for link (Serdes)
2193 * @hw: pointer to the HW structure
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002194 *
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002195 * Checks for link up on the hardware. If link is not up and we have
2196 * a signal, then we need to force link up.
2197 */
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002198s32 e1000_check_for_serdes_link_generic(struct e1000_hw *hw)
2199{
2200 u32 rxcw;
2201 u32 ctrl;
2202 u32 status;
2203 s32 ret_val = E1000_SUCCESS;
2204
2205 DEBUGFUNC("e1000_check_for_serdes_link_generic");
2206
2207 ctrl = er32(CTRL);
2208 status = er32(STATUS);
2209 rxcw = er32(RXCW);
2210
2211 /*
2212 * If we don't have link (auto-negotiation failed or link partner
2213 * cannot auto-negotiate), and our link partner is not trying to
2214 * auto-negotiate with us (we are receiving idles or data),
2215 * we need to force link up. We also need to give auto-negotiation
2216 * time to complete.
2217 */
2218 /* (ctrl & E1000_CTRL_SWDPIN1) == 1 == have signal */
2219 if ((!(status & E1000_STATUS_LU)) && (!(rxcw & E1000_RXCW_C))) {
2220 if (hw->autoneg_failed == 0) {
2221 hw->autoneg_failed = 1;
2222 goto out;
2223 }
2224 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\n");
2225
2226 /* Disable auto-negotiation in the TXCW register */
2227 ew32(TXCW, (hw->txcw & ~E1000_TXCW_ANE));
2228
2229 /* Force link-up and also force full-duplex. */
2230 ctrl = er32(CTRL);
2231 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
2232 ew32(CTRL, ctrl);
2233
2234 /* Configure Flow Control after forcing link up. */
2235 ret_val = e1000_config_fc_after_link_up(hw);
2236 if (ret_val) {
2237 DEBUGOUT("Error configuring flow control\n");
2238 goto out;
2239 }
2240 } else if ((ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
2241 /*
2242 * If we are forcing link and we are receiving /C/ ordered
2243 * sets, re-enable auto-negotiation in the TXCW register
2244 * and disable forced link in the Device Control register
2245 * in an attempt to auto-negotiate with our link partner.
2246 */
2247 DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\n");
2248 ew32(TXCW, hw->txcw);
2249 ew32(CTRL, (ctrl & ~E1000_CTRL_SLU));
2250
2251 hw->serdes_has_link = true;
2252 } else if (!(E1000_TXCW_ANE & er32(TXCW))) {
2253 /*
2254 * If we force link for non-auto-negotiation switch, check
2255 * link status based on MAC synchronization for internal
2256 * serdes media type.
2257 */
2258 /* SYNCH bit and IV bit are sticky. */
2259 udelay(10);
2260 rxcw = er32(RXCW);
2261 if (rxcw & E1000_RXCW_SYNCH) {
2262 if (!(rxcw & E1000_RXCW_IV)) {
2263 hw->serdes_has_link = true;
2264 DEBUGOUT("SERDES: Link up - forced.\n");
2265 }
2266 } else {
2267 hw->serdes_has_link = false;
2268 DEBUGOUT("SERDES: Link down - force failed.\n");
2269 }
2270 }
2271
2272 if (E1000_TXCW_ANE & er32(TXCW)) {
2273 status = er32(STATUS);
2274 if (status & E1000_STATUS_LU) {
2275 /* SYNCH bit and IV bit are sticky, so reread rxcw. */
2276 udelay(10);
2277 rxcw = er32(RXCW);
2278 if (rxcw & E1000_RXCW_SYNCH) {
2279 if (!(rxcw & E1000_RXCW_IV)) {
2280 hw->serdes_has_link = true;
2281 DEBUGOUT("SERDES: Link up - autoneg "
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002282 "completed successfully.\n");
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002283 } else {
2284 hw->serdes_has_link = false;
2285 DEBUGOUT("SERDES: Link down - invalid"
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002286 "codewords detected in autoneg.\n");
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002287 }
2288 } else {
2289 hw->serdes_has_link = false;
2290 DEBUGOUT("SERDES: Link down - no sync.\n");
2291 }
2292 } else {
2293 hw->serdes_has_link = false;
2294 DEBUGOUT("SERDES: Link down - autoneg failed\n");
2295 }
2296 }
2297
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002298 out:
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002299 return ret_val;
2300}
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002301
2302/**
2303 * e1000_check_for_link
2304 * @hw: Struct containing variables accessed by shared code
2305 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306 * Checks to see if the link status of the hardware has changed.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307 * Called by any function that needs to check the link status of the adapter.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002308 */
Joe Perches64798842008-07-11 15:17:02 -07002309s32 e1000_check_for_link(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002311 u32 rxcw = 0;
2312 u32 ctrl;
2313 u32 status;
2314 u32 rctl;
2315 u32 icr;
2316 u32 signal = 0;
2317 s32 ret_val;
2318 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002320 DEBUGFUNC("e1000_check_for_link");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002322 ctrl = er32(CTRL);
2323 status = er32(STATUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002325 /* On adapters with a MAC newer than 82544, SW Definable pin 1 will be
2326 * set when the optics detect a signal. On older adapters, it will be
2327 * cleared when there is a signal. This applies to fiber media only.
2328 */
2329 if ((hw->media_type == e1000_media_type_fiber) ||
2330 (hw->media_type == e1000_media_type_internal_serdes)) {
2331 rxcw = er32(RXCW);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002333 if (hw->media_type == e1000_media_type_fiber) {
2334 signal =
2335 (hw->mac_type >
2336 e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
2337 if (status & E1000_STATUS_LU)
2338 hw->get_link_status = false;
2339 }
2340 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002342 /* If we have a copper PHY then we only want to go out to the PHY
2343 * registers to see if Auto-Neg has completed and/or if our link
2344 * status has changed. The get_link_status flag will be set if we
2345 * receive a Link Status Change interrupt or we have Rx Sequence
2346 * Errors.
2347 */
2348 if ((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
2349 /* First we want to see if the MII Status Register reports
2350 * link. If so, then we want to get the current speed/duplex
2351 * of the PHY.
2352 * Read the register twice since the link bit is sticky.
2353 */
2354 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2355 if (ret_val)
2356 return ret_val;
2357 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2358 if (ret_val)
2359 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002361 if (phy_data & MII_SR_LINK_STATUS) {
2362 hw->get_link_status = false;
2363 /* Check if there was DownShift, must be checked immediately after
2364 * link-up */
2365 e1000_check_downshift(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002367 /* If we are on 82544 or 82543 silicon and speed/duplex
2368 * are forced to 10H or 10F, then we will implement the polarity
2369 * reversal workaround. We disable interrupts first, and upon
2370 * returning, place the devices interrupt state to its previous
2371 * value except for the link status change interrupt which will
2372 * happen due to the execution of this workaround.
2373 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002375 if ((hw->mac_type == e1000_82544
2376 || hw->mac_type == e1000_82543) && (!hw->autoneg)
2377 && (hw->forced_speed_duplex == e1000_10_full
2378 || hw->forced_speed_duplex == e1000_10_half)) {
2379 ew32(IMC, 0xffffffff);
2380 ret_val =
2381 e1000_polarity_reversal_workaround(hw);
2382 icr = er32(ICR);
2383 ew32(ICS, (icr & ~E1000_ICS_LSC));
2384 ew32(IMS, IMS_ENABLE_MASK);
2385 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002387 } else {
2388 /* No link detected */
2389 e1000_config_dsp_after_link_change(hw, false);
2390 return 0;
2391 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002393 /* If we are forcing speed/duplex, then we simply return since
2394 * we have already determined whether we have link or not.
2395 */
2396 if (!hw->autoneg)
2397 return -E1000_ERR_CONFIG;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002399 /* optimize the dsp settings for the igp phy */
2400 e1000_config_dsp_after_link_change(hw, true);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002402 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
2403 * have Si on board that is 82544 or newer, Auto
2404 * Speed Detection takes care of MAC speed/duplex
2405 * configuration. So we only need to configure Collision
2406 * Distance in the MAC. Otherwise, we need to force
2407 * speed/duplex on the MAC to the current PHY speed/duplex
2408 * settings.
2409 */
2410 if (hw->mac_type >= e1000_82544)
2411 e1000_config_collision_dist(hw);
2412 else {
2413 ret_val = e1000_config_mac_to_phy(hw);
2414 if (ret_val) {
2415 DEBUGOUT
2416 ("Error configuring MAC to PHY settings\n");
2417 return ret_val;
2418 }
2419 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002421 /* Configure Flow Control now that Auto-Neg has completed. First, we
2422 * need to restore the desired flow control settings because we may
2423 * have had to re-autoneg with a different link partner.
2424 */
2425 ret_val = e1000_config_fc_after_link_up(hw);
2426 if (ret_val) {
2427 DEBUGOUT("Error configuring flow control\n");
2428 return ret_val;
2429 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002431 /* At this point we know that we are on copper and we have
2432 * auto-negotiated link. These are conditions for checking the link
2433 * partner capability register. We use the link speed to determine if
2434 * TBI compatibility needs to be turned on or off. If the link is not
2435 * at gigabit speed, then TBI compatibility is not needed. If we are
2436 * at gigabit speed, we turn on TBI compatibility.
2437 */
2438 if (hw->tbi_compatibility_en) {
2439 u16 speed, duplex;
2440 ret_val =
2441 e1000_get_speed_and_duplex(hw, &speed, &duplex);
2442 if (ret_val) {
2443 DEBUGOUT
2444 ("Error getting link speed and duplex\n");
2445 return ret_val;
2446 }
2447 if (speed != SPEED_1000) {
2448 /* If link speed is not set to gigabit speed, we do not need
2449 * to enable TBI compatibility.
2450 */
2451 if (hw->tbi_compatibility_on) {
2452 /* If we previously were in the mode, turn it off. */
2453 rctl = er32(RCTL);
2454 rctl &= ~E1000_RCTL_SBP;
2455 ew32(RCTL, rctl);
2456 hw->tbi_compatibility_on = false;
2457 }
2458 } else {
2459 /* If TBI compatibility is was previously off, turn it on. For
2460 * compatibility with a TBI link partner, we will store bad
2461 * packets. Some frames have an additional byte on the end and
2462 * will look like CRC errors to to the hardware.
2463 */
2464 if (!hw->tbi_compatibility_on) {
2465 hw->tbi_compatibility_on = true;
2466 rctl = er32(RCTL);
2467 rctl |= E1000_RCTL_SBP;
2468 ew32(RCTL, rctl);
2469 }
2470 }
2471 }
2472 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002474 if ((hw->media_type == e1000_media_type_fiber) ||
2475 (hw->media_type == e1000_media_type_internal_serdes))
2476 e1000_check_for_serdes_link_generic(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002478 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479}
2480
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002481/**
2482 * e1000_get_speed_and_duplex
2483 * @hw: Struct containing variables accessed by shared code
2484 * @speed: Speed of the connection
2485 * @duplex: Duplex setting of the connection
2486
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487 * Detects the current speed and duplex settings of the hardware.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002488 */
Joe Perches64798842008-07-11 15:17:02 -07002489s32 e1000_get_speed_and_duplex(struct e1000_hw *hw, u16 *speed, u16 *duplex)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002491 u32 status;
2492 s32 ret_val;
2493 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002495 DEBUGFUNC("e1000_get_speed_and_duplex");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002497 if (hw->mac_type >= e1000_82543) {
2498 status = er32(STATUS);
2499 if (status & E1000_STATUS_SPEED_1000) {
2500 *speed = SPEED_1000;
2501 DEBUGOUT("1000 Mbs, ");
2502 } else if (status & E1000_STATUS_SPEED_100) {
2503 *speed = SPEED_100;
2504 DEBUGOUT("100 Mbs, ");
2505 } else {
2506 *speed = SPEED_10;
2507 DEBUGOUT("10 Mbs, ");
2508 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002509
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002510 if (status & E1000_STATUS_FD) {
2511 *duplex = FULL_DUPLEX;
2512 DEBUGOUT("Full Duplex\n");
2513 } else {
2514 *duplex = HALF_DUPLEX;
2515 DEBUGOUT(" Half Duplex\n");
2516 }
2517 } else {
2518 DEBUGOUT("1000 Mbs, Full Duplex\n");
2519 *speed = SPEED_1000;
2520 *duplex = FULL_DUPLEX;
2521 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002523 /* IGP01 PHY may advertise full duplex operation after speed downgrade even
2524 * if it is operating at half duplex. Here we set the duplex settings to
2525 * match the duplex in the link partner's capabilities.
2526 */
2527 if (hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
2528 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
2529 if (ret_val)
2530 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002532 if (!(phy_data & NWAY_ER_LP_NWAY_CAPS))
2533 *duplex = HALF_DUPLEX;
2534 else {
2535 ret_val =
2536 e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data);
2537 if (ret_val)
2538 return ret_val;
2539 if ((*speed == SPEED_100
2540 && !(phy_data & NWAY_LPAR_100TX_FD_CAPS))
2541 || (*speed == SPEED_10
2542 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
2543 *duplex = HALF_DUPLEX;
2544 }
2545 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002547 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002548}
2549
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002550/**
2551 * e1000_wait_autoneg
2552 * @hw: Struct containing variables accessed by shared code
2553 *
2554 * Blocks until autoneg completes or times out (~4.5 seconds)
2555 */
Joe Perches64798842008-07-11 15:17:02 -07002556static s32 e1000_wait_autoneg(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002558 s32 ret_val;
2559 u16 i;
2560 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002562 DEBUGFUNC("e1000_wait_autoneg");
2563 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002565 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
2566 for (i = PHY_AUTO_NEG_TIME; i > 0; i--) {
2567 /* Read the MII Status Register and wait for Auto-Neg
2568 * Complete bit to be set.
2569 */
2570 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2571 if (ret_val)
2572 return ret_val;
2573 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2574 if (ret_val)
2575 return ret_val;
2576 if (phy_data & MII_SR_AUTONEG_COMPLETE) {
2577 return E1000_SUCCESS;
2578 }
2579 msleep(100);
2580 }
2581 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582}
2583
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002584/**
2585 * e1000_raise_mdi_clk - Raises the Management Data Clock
2586 * @hw: Struct containing variables accessed by shared code
2587 * @ctrl: Device control register's current value
2588 */
Joe Perches64798842008-07-11 15:17:02 -07002589static void e1000_raise_mdi_clk(struct e1000_hw *hw, u32 *ctrl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002591 /* Raise the clock input to the Management Data Clock (by setting the MDC
2592 * bit), and then delay 10 microseconds.
2593 */
2594 ew32(CTRL, (*ctrl | E1000_CTRL_MDC));
2595 E1000_WRITE_FLUSH();
2596 udelay(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597}
2598
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002599/**
2600 * e1000_lower_mdi_clk - Lowers the Management Data Clock
2601 * @hw: Struct containing variables accessed by shared code
2602 * @ctrl: Device control register's current value
2603 */
Joe Perches64798842008-07-11 15:17:02 -07002604static void e1000_lower_mdi_clk(struct e1000_hw *hw, u32 *ctrl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002606 /* Lower the clock input to the Management Data Clock (by clearing the MDC
2607 * bit), and then delay 10 microseconds.
2608 */
2609 ew32(CTRL, (*ctrl & ~E1000_CTRL_MDC));
2610 E1000_WRITE_FLUSH();
2611 udelay(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612}
2613
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002614/**
2615 * e1000_shift_out_mdi_bits - Shifts data bits out to the PHY
2616 * @hw: Struct containing variables accessed by shared code
2617 * @data: Data to send out to the PHY
2618 * @count: Number of bits to shift out
2619 *
2620 * Bits are shifted out in MSB to LSB order.
2621 */
Joe Perches64798842008-07-11 15:17:02 -07002622static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, u32 data, u16 count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002623{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002624 u32 ctrl;
2625 u32 mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002627 /* We need to shift "count" number of bits out to the PHY. So, the value
2628 * in the "data" parameter will be shifted out to the PHY one bit at a
2629 * time. In order to do this, "data" must be broken down into bits.
2630 */
2631 mask = 0x01;
2632 mask <<= (count - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002633
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002634 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002636 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
2637 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002639 while (mask) {
2640 /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
2641 * then raising and lowering the Management Data Clock. A "0" is
2642 * shifted out to the PHY by setting the MDIO bit to "0" and then
2643 * raising and lowering the clock.
2644 */
2645 if (data & mask)
2646 ctrl |= E1000_CTRL_MDIO;
2647 else
2648 ctrl &= ~E1000_CTRL_MDIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002650 ew32(CTRL, ctrl);
2651 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002652
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002653 udelay(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002655 e1000_raise_mdi_clk(hw, &ctrl);
2656 e1000_lower_mdi_clk(hw, &ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002658 mask = mask >> 1;
2659 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660}
2661
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002662/**
2663 * e1000_shift_in_mdi_bits - Shifts data bits in from the PHY
2664 * @hw: Struct containing variables accessed by shared code
2665 *
2666 * Bits are shifted in in MSB to LSB order.
2667 */
Joe Perches64798842008-07-11 15:17:02 -07002668static u16 e1000_shift_in_mdi_bits(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002669{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002670 u32 ctrl;
2671 u16 data = 0;
2672 u8 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002673
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002674 /* In order to read a register from the PHY, we need to shift in a total
2675 * of 18 bits from the PHY. The first two bit (turnaround) times are used
2676 * to avoid contention on the MDIO pin when a read operation is performed.
2677 * These two bits are ignored by us and thrown away. Bits are "shifted in"
2678 * by raising the input to the Management Data Clock (setting the MDC bit),
2679 * and then reading the value of the MDIO bit.
2680 */
2681 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002683 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
2684 ctrl &= ~E1000_CTRL_MDIO_DIR;
2685 ctrl &= ~E1000_CTRL_MDIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002686
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002687 ew32(CTRL, ctrl);
2688 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002689
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002690 /* Raise and Lower the clock before reading in the data. This accounts for
2691 * the turnaround bits. The first clock occurred when we clocked out the
2692 * last bit of the Register Address.
2693 */
2694 e1000_raise_mdi_clk(hw, &ctrl);
2695 e1000_lower_mdi_clk(hw, &ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002696
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002697 for (data = 0, i = 0; i < 16; i++) {
2698 data = data << 1;
2699 e1000_raise_mdi_clk(hw, &ctrl);
2700 ctrl = er32(CTRL);
2701 /* Check to see if we shifted in a "1". */
2702 if (ctrl & E1000_CTRL_MDIO)
2703 data |= 1;
2704 e1000_lower_mdi_clk(hw, &ctrl);
2705 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002706
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002707 e1000_raise_mdi_clk(hw, &ctrl);
2708 e1000_lower_mdi_clk(hw, &ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002710 return data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002711}
2712
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002713
2714/**
2715 * e1000_read_phy_reg - read a phy register
2716 * @hw: Struct containing variables accessed by shared code
2717 * @reg_addr: address of the PHY register to read
2718 *
2719 * Reads the value from a PHY register, if the value is on a specific non zero
2720 * page, sets the page first.
2721 */
Joe Perches64798842008-07-11 15:17:02 -07002722s32 e1000_read_phy_reg(struct e1000_hw *hw, u32 reg_addr, u16 *phy_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002723{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002724 u32 ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002725
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002726 DEBUGFUNC("e1000_read_phy_reg");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002727
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002728 if ((hw->phy_type == e1000_phy_igp) &&
2729 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
2730 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
2731 (u16) reg_addr);
2732 if (ret_val)
2733 return ret_val;
2734 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002735
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002736 ret_val = e1000_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
2737 phy_data);
2738
2739 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002740}
2741
Joe Perches64798842008-07-11 15:17:02 -07002742static s32 e1000_read_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr,
2743 u16 *phy_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002744{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002745 u32 i;
2746 u32 mdic = 0;
2747 const u32 phy_addr = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002748
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002749 DEBUGFUNC("e1000_read_phy_reg_ex");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002750
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002751 if (reg_addr > MAX_PHY_REG_ADDRESS) {
2752 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
2753 return -E1000_ERR_PARAM;
2754 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002755
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002756 if (hw->mac_type > e1000_82543) {
2757 /* Set up Op-code, Phy Address, and register address in the MDI
2758 * Control register. The MAC will take care of interfacing with the
2759 * PHY to retrieve the desired data.
2760 */
2761 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
2762 (phy_addr << E1000_MDIC_PHY_SHIFT) |
2763 (E1000_MDIC_OP_READ));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002764
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002765 ew32(MDIC, mdic);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002766
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002767 /* Poll the ready bit to see if the MDI read completed */
2768 for (i = 0; i < 64; i++) {
2769 udelay(50);
2770 mdic = er32(MDIC);
2771 if (mdic & E1000_MDIC_READY)
2772 break;
2773 }
2774 if (!(mdic & E1000_MDIC_READY)) {
2775 DEBUGOUT("MDI Read did not complete\n");
2776 return -E1000_ERR_PHY;
2777 }
2778 if (mdic & E1000_MDIC_ERROR) {
2779 DEBUGOUT("MDI Error\n");
2780 return -E1000_ERR_PHY;
2781 }
2782 *phy_data = (u16) mdic;
2783 } else {
2784 /* We must first send a preamble through the MDIO pin to signal the
2785 * beginning of an MII instruction. This is done by sending 32
2786 * consecutive "1" bits.
2787 */
2788 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002789
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002790 /* Now combine the next few fields that are required for a read
2791 * operation. We use this method instead of calling the
2792 * e1000_shift_out_mdi_bits routine five different times. The format of
2793 * a MII read instruction consists of a shift out of 14 bits and is
2794 * defined as follows:
2795 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
2796 * followed by a shift in of 18 bits. This first two bits shifted in
2797 * are TurnAround bits used to avoid contention on the MDIO pin when a
2798 * READ operation is performed. These two bits are thrown away
2799 * followed by a shift in of 16 bits which contains the desired data.
2800 */
2801 mdic = ((reg_addr) | (phy_addr << 5) |
2802 (PHY_OP_READ << 10) | (PHY_SOF << 12));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002804 e1000_shift_out_mdi_bits(hw, mdic, 14);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002805
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002806 /* Now that we've shifted out the read command to the MII, we need to
2807 * "shift in" the 16-bit value (18 total bits) of the requested PHY
2808 * register address.
2809 */
2810 *phy_data = e1000_shift_in_mdi_bits(hw);
2811 }
2812 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002813}
2814
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002815/**
2816 * e1000_write_phy_reg - write a phy register
2817 *
2818 * @hw: Struct containing variables accessed by shared code
2819 * @reg_addr: address of the PHY register to write
2820 * @data: data to write to the PHY
2821
2822 * Writes a value to a PHY register
2823 */
Joe Perches64798842008-07-11 15:17:02 -07002824s32 e1000_write_phy_reg(struct e1000_hw *hw, u32 reg_addr, u16 phy_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002825{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002826 u32 ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002827
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002828 DEBUGFUNC("e1000_write_phy_reg");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002829
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002830 if ((hw->phy_type == e1000_phy_igp) &&
2831 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
2832 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
2833 (u16) reg_addr);
2834 if (ret_val)
2835 return ret_val;
2836 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002837
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002838 ret_val = e1000_write_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
2839 phy_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002840
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002841 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002842}
2843
Joe Perches64798842008-07-11 15:17:02 -07002844static s32 e1000_write_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr,
2845 u16 phy_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002846{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002847 u32 i;
2848 u32 mdic = 0;
2849 const u32 phy_addr = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002850
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002851 DEBUGFUNC("e1000_write_phy_reg_ex");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002852
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002853 if (reg_addr > MAX_PHY_REG_ADDRESS) {
2854 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
2855 return -E1000_ERR_PARAM;
2856 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002857
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002858 if (hw->mac_type > e1000_82543) {
2859 /* Set up Op-code, Phy Address, register address, and data intended
2860 * for the PHY register in the MDI Control register. The MAC will take
2861 * care of interfacing with the PHY to send the desired data.
2862 */
2863 mdic = (((u32) phy_data) |
2864 (reg_addr << E1000_MDIC_REG_SHIFT) |
2865 (phy_addr << E1000_MDIC_PHY_SHIFT) |
2866 (E1000_MDIC_OP_WRITE));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002867
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002868 ew32(MDIC, mdic);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002869
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002870 /* Poll the ready bit to see if the MDI read completed */
2871 for (i = 0; i < 641; i++) {
2872 udelay(5);
2873 mdic = er32(MDIC);
2874 if (mdic & E1000_MDIC_READY)
2875 break;
2876 }
2877 if (!(mdic & E1000_MDIC_READY)) {
2878 DEBUGOUT("MDI Write did not complete\n");
2879 return -E1000_ERR_PHY;
2880 }
2881 } else {
2882 /* We'll need to use the SW defined pins to shift the write command
2883 * out to the PHY. We first send a preamble to the PHY to signal the
2884 * beginning of the MII instruction. This is done by sending 32
2885 * consecutive "1" bits.
2886 */
2887 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002888
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002889 /* Now combine the remaining required fields that will indicate a
2890 * write operation. We use this method instead of calling the
2891 * e1000_shift_out_mdi_bits routine for each field in the command. The
2892 * format of a MII write instruction is as follows:
2893 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
2894 */
2895 mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
2896 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
2897 mdic <<= 16;
2898 mdic |= (u32) phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002899
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002900 e1000_shift_out_mdi_bits(hw, mdic, 32);
2901 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002902
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002903 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002904}
2905
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002906/**
2907 * e1000_phy_hw_reset - reset the phy, hardware style
2908 * @hw: Struct containing variables accessed by shared code
2909 *
2910 * Returns the PHY to the power-on reset state
2911 */
Joe Perches64798842008-07-11 15:17:02 -07002912s32 e1000_phy_hw_reset(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002913{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002914 u32 ctrl, ctrl_ext;
2915 u32 led_ctrl;
2916 s32 ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002917
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002918 DEBUGFUNC("e1000_phy_hw_reset");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002920 DEBUGOUT("Resetting Phy...\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002921
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002922 if (hw->mac_type > e1000_82543) {
2923 /* Read the device control register and assert the E1000_CTRL_PHY_RST
2924 * bit. Then, take it out of reset.
2925 * For e1000 hardware, we delay for 10ms between the assert
2926 * and deassert.
2927 */
2928 ctrl = er32(CTRL);
2929 ew32(CTRL, ctrl | E1000_CTRL_PHY_RST);
2930 E1000_WRITE_FLUSH();
Auke Kok76c224b2006-05-23 13:36:06 -07002931
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002932 msleep(10);
Auke Kok76c224b2006-05-23 13:36:06 -07002933
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002934 ew32(CTRL, ctrl);
2935 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002936
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002937 } else {
2938 /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
2939 * bit to put the PHY into reset. Then, take it out of reset.
2940 */
2941 ctrl_ext = er32(CTRL_EXT);
2942 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
2943 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
2944 ew32(CTRL_EXT, ctrl_ext);
2945 E1000_WRITE_FLUSH();
2946 msleep(10);
2947 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
2948 ew32(CTRL_EXT, ctrl_ext);
2949 E1000_WRITE_FLUSH();
2950 }
2951 udelay(150);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002952
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002953 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
2954 /* Configure activity LED after PHY reset */
2955 led_ctrl = er32(LEDCTL);
2956 led_ctrl &= IGP_ACTIVITY_LED_MASK;
2957 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
2958 ew32(LEDCTL, led_ctrl);
2959 }
Auke Kok8fc897b2006-08-28 14:56:16 -07002960
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002961 /* Wait for FW to finish PHY configuration. */
2962 ret_val = e1000_get_phy_cfg_done(hw);
2963 if (ret_val != E1000_SUCCESS)
2964 return ret_val;
2965
2966 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002967}
2968
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002969/**
2970 * e1000_phy_reset - reset the phy to commit settings
2971 * @hw: Struct containing variables accessed by shared code
2972 *
2973 * Resets the PHY
2974 * Sets bit 15 of the MII Control register
2975 */
Joe Perches64798842008-07-11 15:17:02 -07002976s32 e1000_phy_reset(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002977{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002978 s32 ret_val;
2979 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002980
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002981 DEBUGFUNC("e1000_phy_reset");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002982
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002983 switch (hw->phy_type) {
2984 case e1000_phy_igp:
2985 ret_val = e1000_phy_hw_reset(hw);
2986 if (ret_val)
2987 return ret_val;
2988 break;
2989 default:
2990 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
2991 if (ret_val)
2992 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002993
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002994 phy_data |= MII_CR_RESET;
2995 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
2996 if (ret_val)
2997 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002998
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002999 udelay(1);
3000 break;
3001 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003002
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003003 if (hw->phy_type == e1000_phy_igp)
3004 e1000_phy_init_script(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003005
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003006 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003007}
3008
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003009/**
3010 * e1000_detect_gig_phy - check the phy type
3011 * @hw: Struct containing variables accessed by shared code
3012 *
3013 * Probes the expected PHY address for known PHY IDs
3014 */
Joe Perches64798842008-07-11 15:17:02 -07003015static s32 e1000_detect_gig_phy(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003016{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003017 s32 phy_init_status, ret_val;
3018 u16 phy_id_high, phy_id_low;
3019 bool match = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003020
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003021 DEBUGFUNC("e1000_detect_gig_phy");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003023 if (hw->phy_id != 0)
3024 return E1000_SUCCESS;
Jeff Kirsher2a88c172006-09-27 12:54:05 -07003025
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003026 /* Read the PHY ID Registers to identify which PHY is onboard. */
3027 ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
3028 if (ret_val)
3029 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003030
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003031 hw->phy_id = (u32) (phy_id_high << 16);
3032 udelay(20);
3033 ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
3034 if (ret_val)
3035 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003036
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003037 hw->phy_id |= (u32) (phy_id_low & PHY_REVISION_MASK);
3038 hw->phy_revision = (u32) phy_id_low & ~PHY_REVISION_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003039
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003040 switch (hw->mac_type) {
3041 case e1000_82543:
3042 if (hw->phy_id == M88E1000_E_PHY_ID)
3043 match = true;
3044 break;
3045 case e1000_82544:
3046 if (hw->phy_id == M88E1000_I_PHY_ID)
3047 match = true;
3048 break;
3049 case e1000_82540:
3050 case e1000_82545:
3051 case e1000_82545_rev_3:
3052 case e1000_82546:
3053 case e1000_82546_rev_3:
3054 if (hw->phy_id == M88E1011_I_PHY_ID)
3055 match = true;
3056 break;
3057 case e1000_82541:
3058 case e1000_82541_rev_2:
3059 case e1000_82547:
3060 case e1000_82547_rev_2:
3061 if (hw->phy_id == IGP01E1000_I_PHY_ID)
3062 match = true;
3063 break;
3064 default:
3065 DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type);
3066 return -E1000_ERR_CONFIG;
3067 }
3068 phy_init_status = e1000_set_phy_type(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003069
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003070 if ((match) && (phy_init_status == E1000_SUCCESS)) {
3071 DEBUGOUT1("PHY ID 0x%X detected\n", hw->phy_id);
3072 return E1000_SUCCESS;
3073 }
3074 DEBUGOUT1("Invalid PHY ID 0x%X\n", hw->phy_id);
3075 return -E1000_ERR_PHY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003076}
3077
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003078/**
3079 * e1000_phy_reset_dsp - reset DSP
3080 * @hw: Struct containing variables accessed by shared code
3081 *
3082 * Resets the PHY's DSP
3083 */
Joe Perches64798842008-07-11 15:17:02 -07003084static s32 e1000_phy_reset_dsp(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003085{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003086 s32 ret_val;
3087 DEBUGFUNC("e1000_phy_reset_dsp");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003088
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003089 do {
3090 ret_val = e1000_write_phy_reg(hw, 29, 0x001d);
3091 if (ret_val)
3092 break;
3093 ret_val = e1000_write_phy_reg(hw, 30, 0x00c1);
3094 if (ret_val)
3095 break;
3096 ret_val = e1000_write_phy_reg(hw, 30, 0x0000);
3097 if (ret_val)
3098 break;
3099 ret_val = E1000_SUCCESS;
3100 } while (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003101
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003102 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003103}
3104
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003105/**
3106 * e1000_phy_igp_get_info - get igp specific registers
3107 * @hw: Struct containing variables accessed by shared code
3108 * @phy_info: PHY information structure
3109 *
3110 * Get PHY information from various PHY registers for igp PHY only.
3111 */
Joe Perches64798842008-07-11 15:17:02 -07003112static s32 e1000_phy_igp_get_info(struct e1000_hw *hw,
3113 struct e1000_phy_info *phy_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003114{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003115 s32 ret_val;
3116 u16 phy_data, min_length, max_length, average;
3117 e1000_rev_polarity polarity;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003118
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003119 DEBUGFUNC("e1000_phy_igp_get_info");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003120
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003121 /* The downshift status is checked only once, after link is established,
3122 * and it stored in the hw->speed_downgraded parameter. */
3123 phy_info->downshift = (e1000_downshift) hw->speed_downgraded;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003124
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003125 /* IGP01E1000 does not need to support it. */
3126 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003127
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003128 /* IGP01E1000 always correct polarity reversal */
3129 phy_info->polarity_correction = e1000_polarity_reversal_enabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003130
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003131 /* Check polarity status */
3132 ret_val = e1000_check_polarity(hw, &polarity);
3133 if (ret_val)
3134 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003135
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003136 phy_info->cable_polarity = polarity;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003137
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003138 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, &phy_data);
3139 if (ret_val)
3140 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003141
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003142 phy_info->mdix_mode =
3143 (e1000_auto_x_mode) ((phy_data & IGP01E1000_PSSR_MDIX) >>
3144 IGP01E1000_PSSR_MDIX_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003145
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003146 if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
3147 IGP01E1000_PSSR_SPEED_1000MBPS) {
3148 /* Local/Remote Receiver Information are only valid at 1000 Mbps */
3149 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
3150 if (ret_val)
3151 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003152
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003153 phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
3154 SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
3155 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
3156 phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
3157 SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
3158 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003159
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003160 /* Get cable length */
3161 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
3162 if (ret_val)
3163 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003164
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003165 /* Translate to old method */
3166 average = (max_length + min_length) / 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003167
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003168 if (average <= e1000_igp_cable_length_50)
3169 phy_info->cable_length = e1000_cable_length_50;
3170 else if (average <= e1000_igp_cable_length_80)
3171 phy_info->cable_length = e1000_cable_length_50_80;
3172 else if (average <= e1000_igp_cable_length_110)
3173 phy_info->cable_length = e1000_cable_length_80_110;
3174 else if (average <= e1000_igp_cable_length_140)
3175 phy_info->cable_length = e1000_cable_length_110_140;
3176 else
3177 phy_info->cable_length = e1000_cable_length_140;
3178 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003179
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003180 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003181}
3182
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003183/**
3184 * e1000_phy_m88_get_info - get m88 specific registers
3185 * @hw: Struct containing variables accessed by shared code
3186 * @phy_info: PHY information structure
3187 *
3188 * Get PHY information from various PHY registers for m88 PHY only.
3189 */
Joe Perches64798842008-07-11 15:17:02 -07003190static s32 e1000_phy_m88_get_info(struct e1000_hw *hw,
3191 struct e1000_phy_info *phy_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003192{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003193 s32 ret_val;
3194 u16 phy_data;
3195 e1000_rev_polarity polarity;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003196
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003197 DEBUGFUNC("e1000_phy_m88_get_info");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003198
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003199 /* The downshift status is checked only once, after link is established,
3200 * and it stored in the hw->speed_downgraded parameter. */
3201 phy_info->downshift = (e1000_downshift) hw->speed_downgraded;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003202
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003203 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
3204 if (ret_val)
3205 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003206
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003207 phy_info->extended_10bt_distance =
3208 ((phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >>
3209 M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT) ?
3210 e1000_10bt_ext_dist_enable_lower :
3211 e1000_10bt_ext_dist_enable_normal;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07003212
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003213 phy_info->polarity_correction =
3214 ((phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >>
3215 M88E1000_PSCR_POLARITY_REVERSAL_SHIFT) ?
3216 e1000_polarity_reversal_disabled : e1000_polarity_reversal_enabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003217
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003218 /* Check polarity status */
3219 ret_val = e1000_check_polarity(hw, &polarity);
3220 if (ret_val)
3221 return ret_val;
3222 phy_info->cable_polarity = polarity;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003223
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003224 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
3225 if (ret_val)
3226 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003227
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003228 phy_info->mdix_mode =
3229 (e1000_auto_x_mode) ((phy_data & M88E1000_PSSR_MDIX) >>
3230 M88E1000_PSSR_MDIX_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003231
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003232 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
3233 /* Cable Length Estimation and Local/Remote Receiver Information
3234 * are only valid at 1000 Mbps.
3235 */
3236 phy_info->cable_length =
3237 (e1000_cable_length) ((phy_data &
3238 M88E1000_PSSR_CABLE_LENGTH) >>
3239 M88E1000_PSSR_CABLE_LENGTH_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003240
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003241 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
3242 if (ret_val)
3243 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003244
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003245 phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
3246 SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
3247 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
3248 phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
3249 SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
3250 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003251
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003252 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003253
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003254 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003255}
3256
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003257/**
3258 * e1000_phy_get_info - request phy info
3259 * @hw: Struct containing variables accessed by shared code
3260 * @phy_info: PHY information structure
3261 *
3262 * Get PHY information from various PHY registers
3263 */
Joe Perches64798842008-07-11 15:17:02 -07003264s32 e1000_phy_get_info(struct e1000_hw *hw, struct e1000_phy_info *phy_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003265{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003266 s32 ret_val;
3267 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003268
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003269 DEBUGFUNC("e1000_phy_get_info");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003270
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003271 phy_info->cable_length = e1000_cable_length_undefined;
3272 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined;
3273 phy_info->cable_polarity = e1000_rev_polarity_undefined;
3274 phy_info->downshift = e1000_downshift_undefined;
3275 phy_info->polarity_correction = e1000_polarity_reversal_undefined;
3276 phy_info->mdix_mode = e1000_auto_x_mode_undefined;
3277 phy_info->local_rx = e1000_1000t_rx_status_undefined;
3278 phy_info->remote_rx = e1000_1000t_rx_status_undefined;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003279
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003280 if (hw->media_type != e1000_media_type_copper) {
3281 DEBUGOUT("PHY info is only valid for copper media\n");
3282 return -E1000_ERR_CONFIG;
3283 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003284
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003285 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3286 if (ret_val)
3287 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003288
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003289 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3290 if (ret_val)
3291 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003292
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003293 if ((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) {
3294 DEBUGOUT("PHY info is only valid if link is up\n");
3295 return -E1000_ERR_CONFIG;
3296 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003297
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003298 if (hw->phy_type == e1000_phy_igp)
3299 return e1000_phy_igp_get_info(hw, phy_info);
3300 else
3301 return e1000_phy_m88_get_info(hw, phy_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003302}
3303
Joe Perches64798842008-07-11 15:17:02 -07003304s32 e1000_validate_mdi_setting(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003305{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003306 DEBUGFUNC("e1000_validate_mdi_settings");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003307
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003308 if (!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) {
3309 DEBUGOUT("Invalid MDI setting detected\n");
3310 hw->mdix = 1;
3311 return -E1000_ERR_CONFIG;
3312 }
3313 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003314}
3315
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003316/**
3317 * e1000_init_eeprom_params - initialize sw eeprom vars
3318 * @hw: Struct containing variables accessed by shared code
3319 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07003320 * Sets up eeprom variables in the hw struct. Must be called after mac_type
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00003321 * is configured.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003322 */
Joe Perches64798842008-07-11 15:17:02 -07003323s32 e1000_init_eeprom_params(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003324{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003325 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3326 u32 eecd = er32(EECD);
3327 s32 ret_val = E1000_SUCCESS;
3328 u16 eeprom_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003329
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003330 DEBUGFUNC("e1000_init_eeprom_params");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003331
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003332 switch (hw->mac_type) {
3333 case e1000_82542_rev2_0:
3334 case e1000_82542_rev2_1:
3335 case e1000_82543:
3336 case e1000_82544:
3337 eeprom->type = e1000_eeprom_microwire;
3338 eeprom->word_size = 64;
3339 eeprom->opcode_bits = 3;
3340 eeprom->address_bits = 6;
3341 eeprom->delay_usec = 50;
3342 eeprom->use_eerd = false;
3343 eeprom->use_eewr = false;
3344 break;
3345 case e1000_82540:
3346 case e1000_82545:
3347 case e1000_82545_rev_3:
3348 case e1000_82546:
3349 case e1000_82546_rev_3:
3350 eeprom->type = e1000_eeprom_microwire;
3351 eeprom->opcode_bits = 3;
3352 eeprom->delay_usec = 50;
3353 if (eecd & E1000_EECD_SIZE) {
3354 eeprom->word_size = 256;
3355 eeprom->address_bits = 8;
3356 } else {
3357 eeprom->word_size = 64;
3358 eeprom->address_bits = 6;
3359 }
3360 eeprom->use_eerd = false;
3361 eeprom->use_eewr = false;
3362 break;
3363 case e1000_82541:
3364 case e1000_82541_rev_2:
3365 case e1000_82547:
3366 case e1000_82547_rev_2:
3367 if (eecd & E1000_EECD_TYPE) {
3368 eeprom->type = e1000_eeprom_spi;
3369 eeprom->opcode_bits = 8;
3370 eeprom->delay_usec = 1;
3371 if (eecd & E1000_EECD_ADDR_BITS) {
3372 eeprom->page_size = 32;
3373 eeprom->address_bits = 16;
3374 } else {
3375 eeprom->page_size = 8;
3376 eeprom->address_bits = 8;
3377 }
3378 } else {
3379 eeprom->type = e1000_eeprom_microwire;
3380 eeprom->opcode_bits = 3;
3381 eeprom->delay_usec = 50;
3382 if (eecd & E1000_EECD_ADDR_BITS) {
3383 eeprom->word_size = 256;
3384 eeprom->address_bits = 8;
3385 } else {
3386 eeprom->word_size = 64;
3387 eeprom->address_bits = 6;
3388 }
3389 }
3390 eeprom->use_eerd = false;
3391 eeprom->use_eewr = false;
3392 break;
3393 default:
3394 break;
3395 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003396
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003397 if (eeprom->type == e1000_eeprom_spi) {
3398 /* eeprom_size will be an enum [0..8] that maps to eeprom sizes 128B to
3399 * 32KB (incremented by powers of 2).
3400 */
3401 /* Set to default value for initial eeprom read. */
3402 eeprom->word_size = 64;
3403 ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size);
3404 if (ret_val)
3405 return ret_val;
3406 eeprom_size =
3407 (eeprom_size & EEPROM_SIZE_MASK) >> EEPROM_SIZE_SHIFT;
3408 /* 256B eeprom size was not supported in earlier hardware, so we
3409 * bump eeprom_size up one to ensure that "1" (which maps to 256B)
3410 * is never the result used in the shifting logic below. */
3411 if (eeprom_size)
3412 eeprom_size++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003413
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003414 eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT);
3415 }
3416 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003417}
3418
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003419/**
3420 * e1000_raise_ee_clk - Raises the EEPROM's clock input.
3421 * @hw: Struct containing variables accessed by shared code
3422 * @eecd: EECD's current value
3423 */
Joe Perches64798842008-07-11 15:17:02 -07003424static void e1000_raise_ee_clk(struct e1000_hw *hw, u32 *eecd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003425{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003426 /* Raise the clock input to the EEPROM (by setting the SK bit), and then
3427 * wait <delay> microseconds.
3428 */
3429 *eecd = *eecd | E1000_EECD_SK;
3430 ew32(EECD, *eecd);
3431 E1000_WRITE_FLUSH();
3432 udelay(hw->eeprom.delay_usec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003433}
3434
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003435/**
3436 * e1000_lower_ee_clk - Lowers the EEPROM's clock input.
3437 * @hw: Struct containing variables accessed by shared code
3438 * @eecd: EECD's current value
3439 */
Joe Perches64798842008-07-11 15:17:02 -07003440static void e1000_lower_ee_clk(struct e1000_hw *hw, u32 *eecd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003441{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003442 /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
3443 * wait 50 microseconds.
3444 */
3445 *eecd = *eecd & ~E1000_EECD_SK;
3446 ew32(EECD, *eecd);
3447 E1000_WRITE_FLUSH();
3448 udelay(hw->eeprom.delay_usec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003449}
3450
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003451/**
3452 * e1000_shift_out_ee_bits - Shift data bits out to the EEPROM.
3453 * @hw: Struct containing variables accessed by shared code
3454 * @data: data to send to the EEPROM
3455 * @count: number of bits to shift out
3456 */
Joe Perches64798842008-07-11 15:17:02 -07003457static void e1000_shift_out_ee_bits(struct e1000_hw *hw, u16 data, u16 count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003458{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003459 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3460 u32 eecd;
3461 u32 mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003462
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003463 /* We need to shift "count" bits out to the EEPROM. So, value in the
3464 * "data" parameter will be shifted out to the EEPROM one bit at a time.
3465 * In order to do this, "data" must be broken down into bits.
3466 */
3467 mask = 0x01 << (count - 1);
3468 eecd = er32(EECD);
3469 if (eeprom->type == e1000_eeprom_microwire) {
3470 eecd &= ~E1000_EECD_DO;
3471 } else if (eeprom->type == e1000_eeprom_spi) {
3472 eecd |= E1000_EECD_DO;
3473 }
3474 do {
3475 /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
3476 * and then raising and then lowering the clock (the SK bit controls
3477 * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
3478 * by setting "DI" to "0" and then raising and then lowering the clock.
3479 */
3480 eecd &= ~E1000_EECD_DI;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003481
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003482 if (data & mask)
3483 eecd |= E1000_EECD_DI;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003484
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003485 ew32(EECD, eecd);
3486 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003487
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003488 udelay(eeprom->delay_usec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003489
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003490 e1000_raise_ee_clk(hw, &eecd);
3491 e1000_lower_ee_clk(hw, &eecd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003492
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003493 mask = mask >> 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003494
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003495 } while (mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003496
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003497 /* We leave the "DI" bit set to "0" when we leave this routine. */
3498 eecd &= ~E1000_EECD_DI;
3499 ew32(EECD, eecd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003500}
3501
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003502/**
3503 * e1000_shift_in_ee_bits - Shift data bits in from the EEPROM
3504 * @hw: Struct containing variables accessed by shared code
3505 * @count: number of bits to shift in
3506 */
Joe Perches64798842008-07-11 15:17:02 -07003507static u16 e1000_shift_in_ee_bits(struct e1000_hw *hw, u16 count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003508{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003509 u32 eecd;
3510 u32 i;
3511 u16 data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003512
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003513 /* In order to read a register from the EEPROM, we need to shift 'count'
3514 * bits in from the EEPROM. Bits are "shifted in" by raising the clock
3515 * input to the EEPROM (setting the SK bit), and then reading the value of
3516 * the "DO" bit. During this "shifting in" process the "DI" bit should
3517 * always be clear.
3518 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003519
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003520 eecd = er32(EECD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003521
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003522 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
3523 data = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003524
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003525 for (i = 0; i < count; i++) {
3526 data = data << 1;
3527 e1000_raise_ee_clk(hw, &eecd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003528
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003529 eecd = er32(EECD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003530
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003531 eecd &= ~(E1000_EECD_DI);
3532 if (eecd & E1000_EECD_DO)
3533 data |= 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003534
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003535 e1000_lower_ee_clk(hw, &eecd);
3536 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003537
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003538 return data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003539}
3540
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003541/**
3542 * e1000_acquire_eeprom - Prepares EEPROM for access
3543 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -07003544 *
3545 * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
3546 * function should be called before issuing a command to the EEPROM.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003547 */
Joe Perches64798842008-07-11 15:17:02 -07003548static s32 e1000_acquire_eeprom(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003549{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003550 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3551 u32 eecd, i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003552
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003553 DEBUGFUNC("e1000_acquire_eeprom");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003554
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003555 eecd = er32(EECD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003556
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003557 /* Request EEPROM Access */
3558 if (hw->mac_type > e1000_82544) {
3559 eecd |= E1000_EECD_REQ;
3560 ew32(EECD, eecd);
3561 eecd = er32(EECD);
3562 while ((!(eecd & E1000_EECD_GNT)) &&
3563 (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
3564 i++;
3565 udelay(5);
3566 eecd = er32(EECD);
3567 }
3568 if (!(eecd & E1000_EECD_GNT)) {
3569 eecd &= ~E1000_EECD_REQ;
3570 ew32(EECD, eecd);
3571 DEBUGOUT("Could not acquire EEPROM grant\n");
3572 return -E1000_ERR_EEPROM;
3573 }
3574 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003575
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003576 /* Setup EEPROM for Read/Write */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003577
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003578 if (eeprom->type == e1000_eeprom_microwire) {
3579 /* Clear SK and DI */
3580 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
3581 ew32(EECD, eecd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003582
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003583 /* Set CS */
3584 eecd |= E1000_EECD_CS;
3585 ew32(EECD, eecd);
3586 } else if (eeprom->type == e1000_eeprom_spi) {
3587 /* Clear SK and CS */
3588 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
3589 ew32(EECD, eecd);
3590 udelay(1);
3591 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003592
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003593 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003594}
3595
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003596/**
3597 * e1000_standby_eeprom - Returns EEPROM to a "standby" state
3598 * @hw: Struct containing variables accessed by shared code
3599 */
Joe Perches64798842008-07-11 15:17:02 -07003600static void e1000_standby_eeprom(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003601{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003602 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3603 u32 eecd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003604
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003605 eecd = er32(EECD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003606
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003607 if (eeprom->type == e1000_eeprom_microwire) {
3608 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
3609 ew32(EECD, eecd);
3610 E1000_WRITE_FLUSH();
3611 udelay(eeprom->delay_usec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003612
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003613 /* Clock high */
3614 eecd |= E1000_EECD_SK;
3615 ew32(EECD, eecd);
3616 E1000_WRITE_FLUSH();
3617 udelay(eeprom->delay_usec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003618
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003619 /* Select EEPROM */
3620 eecd |= E1000_EECD_CS;
3621 ew32(EECD, eecd);
3622 E1000_WRITE_FLUSH();
3623 udelay(eeprom->delay_usec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003624
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003625 /* Clock low */
3626 eecd &= ~E1000_EECD_SK;
3627 ew32(EECD, eecd);
3628 E1000_WRITE_FLUSH();
3629 udelay(eeprom->delay_usec);
3630 } else if (eeprom->type == e1000_eeprom_spi) {
3631 /* Toggle CS to flush commands */
3632 eecd |= E1000_EECD_CS;
3633 ew32(EECD, eecd);
3634 E1000_WRITE_FLUSH();
3635 udelay(eeprom->delay_usec);
3636 eecd &= ~E1000_EECD_CS;
3637 ew32(EECD, eecd);
3638 E1000_WRITE_FLUSH();
3639 udelay(eeprom->delay_usec);
3640 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003641}
3642
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003643/**
3644 * e1000_release_eeprom - drop chip select
3645 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -07003646 *
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003647 * Terminates a command by inverting the EEPROM's chip select pin
3648 */
Joe Perches64798842008-07-11 15:17:02 -07003649static void e1000_release_eeprom(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003650{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003651 u32 eecd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003652
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003653 DEBUGFUNC("e1000_release_eeprom");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003654
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003655 eecd = er32(EECD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003656
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003657 if (hw->eeprom.type == e1000_eeprom_spi) {
3658 eecd |= E1000_EECD_CS; /* Pull CS high */
3659 eecd &= ~E1000_EECD_SK; /* Lower SCK */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003660
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003661 ew32(EECD, eecd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003662
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003663 udelay(hw->eeprom.delay_usec);
3664 } else if (hw->eeprom.type == e1000_eeprom_microwire) {
3665 /* cleanup eeprom */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003666
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003667 /* CS on Microwire is active-high */
3668 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003669
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003670 ew32(EECD, eecd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003671
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003672 /* Rising edge of clock */
3673 eecd |= E1000_EECD_SK;
3674 ew32(EECD, eecd);
3675 E1000_WRITE_FLUSH();
3676 udelay(hw->eeprom.delay_usec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003677
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003678 /* Falling edge of clock */
3679 eecd &= ~E1000_EECD_SK;
3680 ew32(EECD, eecd);
3681 E1000_WRITE_FLUSH();
3682 udelay(hw->eeprom.delay_usec);
3683 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003684
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003685 /* Stop requesting EEPROM access */
3686 if (hw->mac_type > e1000_82544) {
3687 eecd &= ~E1000_EECD_REQ;
3688 ew32(EECD, eecd);
3689 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003690}
3691
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003692/**
3693 * e1000_spi_eeprom_ready - Reads a 16 bit word from the EEPROM.
3694 * @hw: Struct containing variables accessed by shared code
3695 */
Joe Perches64798842008-07-11 15:17:02 -07003696static s32 e1000_spi_eeprom_ready(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003697{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003698 u16 retry_count = 0;
3699 u8 spi_stat_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003700
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003701 DEBUGFUNC("e1000_spi_eeprom_ready");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003702
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003703 /* Read "Status Register" repeatedly until the LSB is cleared. The
3704 * EEPROM will signal that the command has been completed by clearing
3705 * bit 0 of the internal status register. If it's not cleared within
3706 * 5 milliseconds, then error out.
3707 */
3708 retry_count = 0;
3709 do {
3710 e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
3711 hw->eeprom.opcode_bits);
3712 spi_stat_reg = (u8) e1000_shift_in_ee_bits(hw, 8);
3713 if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
3714 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003715
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003716 udelay(5);
3717 retry_count += 5;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003718
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003719 e1000_standby_eeprom(hw);
3720 } while (retry_count < EEPROM_MAX_RETRY_SPI);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003721
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003722 /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
3723 * only 0-5mSec on 5V devices)
3724 */
3725 if (retry_count >= EEPROM_MAX_RETRY_SPI) {
3726 DEBUGOUT("SPI EEPROM Status error\n");
3727 return -E1000_ERR_EEPROM;
3728 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003729
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003730 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003731}
3732
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003733/**
3734 * e1000_read_eeprom - Reads a 16 bit word from the EEPROM.
3735 * @hw: Struct containing variables accessed by shared code
3736 * @offset: offset of word in the EEPROM to read
3737 * @data: word read from the EEPROM
3738 * @words: number of words to read
3739 */
Joe Perches64798842008-07-11 15:17:02 -07003740s32 e1000_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003741{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003742 s32 ret;
3743 spin_lock(&e1000_eeprom_lock);
3744 ret = e1000_do_read_eeprom(hw, offset, words, data);
3745 spin_unlock(&e1000_eeprom_lock);
3746 return ret;
Christopher Li78566fe2008-09-05 14:04:05 -07003747}
3748
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003749static s32 e1000_do_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words,
3750 u16 *data)
Christopher Li78566fe2008-09-05 14:04:05 -07003751{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003752 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3753 u32 i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003754
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003755 DEBUGFUNC("e1000_read_eeprom");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003756
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003757 /* If eeprom is not yet detected, do so now */
3758 if (eeprom->word_size == 0)
3759 e1000_init_eeprom_params(hw);
Jeff Kirsher2a88c172006-09-27 12:54:05 -07003760
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003761 /* A check for invalid values: offset too large, too many words, and not
3762 * enough words.
3763 */
3764 if ((offset >= eeprom->word_size)
3765 || (words > eeprom->word_size - offset) || (words == 0)) {
3766 DEBUGOUT2
3767 ("\"words\" parameter out of bounds. Words = %d, size = %d\n",
3768 offset, eeprom->word_size);
3769 return -E1000_ERR_EEPROM;
3770 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003771
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003772 /* EEPROM's that don't use EERD to read require us to bit-bang the SPI
3773 * directly. In this case, we need to acquire the EEPROM so that
3774 * FW or other port software does not interrupt.
3775 */
3776 if (!hw->eeprom.use_eerd) {
3777 /* Prepare the EEPROM for bit-bang reading */
3778 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
3779 return -E1000_ERR_EEPROM;
3780 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003781
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003782 /* Eerd register EEPROM access requires no eeprom aquire/release */
3783 if (eeprom->use_eerd)
3784 return e1000_read_eeprom_eerd(hw, offset, words, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003785
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003786 /* Set up the SPI or Microwire EEPROM for bit-bang reading. We have
3787 * acquired the EEPROM at this point, so any returns should release it */
3788 if (eeprom->type == e1000_eeprom_spi) {
3789 u16 word_in;
3790 u8 read_opcode = EEPROM_READ_OPCODE_SPI;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003791
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003792 if (e1000_spi_eeprom_ready(hw)) {
3793 e1000_release_eeprom(hw);
3794 return -E1000_ERR_EEPROM;
3795 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003796
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003797 e1000_standby_eeprom(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003798
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003799 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
3800 if ((eeprom->address_bits == 8) && (offset >= 128))
3801 read_opcode |= EEPROM_A8_OPCODE_SPI;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003802
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003803 /* Send the READ command (opcode + addr) */
3804 e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
3805 e1000_shift_out_ee_bits(hw, (u16) (offset * 2),
3806 eeprom->address_bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003807
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003808 /* Read the data. The address of the eeprom internally increments with
3809 * each byte (spi) being read, saving on the overhead of eeprom setup
3810 * and tear-down. The address counter will roll over if reading beyond
3811 * the size of the eeprom, thus allowing the entire memory to be read
3812 * starting from any offset. */
3813 for (i = 0; i < words; i++) {
3814 word_in = e1000_shift_in_ee_bits(hw, 16);
3815 data[i] = (word_in >> 8) | (word_in << 8);
3816 }
3817 } else if (eeprom->type == e1000_eeprom_microwire) {
3818 for (i = 0; i < words; i++) {
3819 /* Send the READ command (opcode + addr) */
3820 e1000_shift_out_ee_bits(hw,
3821 EEPROM_READ_OPCODE_MICROWIRE,
3822 eeprom->opcode_bits);
3823 e1000_shift_out_ee_bits(hw, (u16) (offset + i),
3824 eeprom->address_bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003825
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003826 /* Read the data. For microwire, each word requires the overhead
3827 * of eeprom setup and tear-down. */
3828 data[i] = e1000_shift_in_ee_bits(hw, 16);
3829 e1000_standby_eeprom(hw);
3830 }
3831 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003832
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003833 /* End this read operation */
3834 e1000_release_eeprom(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003835
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003836 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003837}
3838
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003839/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003840 * Reads a 16 bit word from the EEPROM using the EERD register.
3841 *
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003842 * @hw: Struct containing variables accessed by shared code
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003843 * offset - offset of word in the EEPROM to read
3844 * data - word read from the EEPROM
3845 * words - number of words to read
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003846 */
Joe Perches64798842008-07-11 15:17:02 -07003847static s32 e1000_read_eeprom_eerd(struct e1000_hw *hw, u16 offset, u16 words,
3848 u16 *data)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003849{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003850 u32 i, eerd = 0;
3851 s32 error = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003852
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003853 for (i = 0; i < words; i++) {
3854 eerd = ((offset + i) << E1000_EEPROM_RW_ADDR_SHIFT) +
3855 E1000_EEPROM_RW_REG_START;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003856
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003857 ew32(EERD, eerd);
3858 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_READ);
Auke Kok76c224b2006-05-23 13:36:06 -07003859
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003860 if (error) {
3861 break;
3862 }
3863 data[i] = (er32(EERD) >> E1000_EEPROM_RW_REG_DATA);
Auke Kok76c224b2006-05-23 13:36:06 -07003864
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003865 }
Auke Kok76c224b2006-05-23 13:36:06 -07003866
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003867 return error;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003868}
3869
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003870/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003871 * Writes a 16 bit word from the EEPROM using the EEWR register.
3872 *
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003873 * @hw: Struct containing variables accessed by shared code
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003874 * offset - offset of word in the EEPROM to read
3875 * data - word read from the EEPROM
3876 * words - number of words to read
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003877 */
Joe Perches64798842008-07-11 15:17:02 -07003878static s32 e1000_write_eeprom_eewr(struct e1000_hw *hw, u16 offset, u16 words,
3879 u16 *data)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003880{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003881 u32 register_value = 0;
3882 u32 i = 0;
3883 s32 error = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003884
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003885 for (i = 0; i < words; i++) {
3886 register_value = (data[i] << E1000_EEPROM_RW_REG_DATA) |
3887 ((offset + i) << E1000_EEPROM_RW_ADDR_SHIFT) |
3888 E1000_EEPROM_RW_REG_START;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003889
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003890 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
3891 if (error) {
3892 break;
3893 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003894
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003895 ew32(EEWR, register_value);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003896
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003897 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
Auke Kok76c224b2006-05-23 13:36:06 -07003898
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003899 if (error) {
3900 break;
3901 }
3902 }
Auke Kok76c224b2006-05-23 13:36:06 -07003903
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003904 return error;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003905}
3906
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003907/**
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003908 * Polls the status bit (bit 1) of the EERD to determine when the read is done.
3909 *
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003910 * @hw: Struct containing variables accessed by shared code
3911 */
Joe Perches64798842008-07-11 15:17:02 -07003912static s32 e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003913{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003914 u32 attempts = 100000;
3915 u32 i, reg = 0;
3916 s32 done = E1000_ERR_EEPROM;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003917
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003918 for (i = 0; i < attempts; i++) {
3919 if (eerd == E1000_EEPROM_POLL_READ)
3920 reg = er32(EERD);
3921 else
3922 reg = er32(EEWR);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003923
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003924 if (reg & E1000_EEPROM_RW_REG_DONE) {
3925 done = E1000_SUCCESS;
3926 break;
3927 }
3928 udelay(5);
3929 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003930
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003931 return done;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003932}
3933
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003934/**
3935 * e1000_validate_eeprom_checksum - Verifies that the EEPROM has a valid checksum
3936 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -07003937 *
3938 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
3939 * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
3940 * valid.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003941 */
Joe Perches64798842008-07-11 15:17:02 -07003942s32 e1000_validate_eeprom_checksum(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003943{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003944 u16 checksum = 0;
3945 u16 i, eeprom_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003946
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003947 DEBUGFUNC("e1000_validate_eeprom_checksum");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003948
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003949 for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
3950 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
3951 DEBUGOUT("EEPROM Read Error\n");
3952 return -E1000_ERR_EEPROM;
3953 }
3954 checksum += eeprom_data;
3955 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003956
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003957 if (checksum == (u16) EEPROM_SUM)
3958 return E1000_SUCCESS;
3959 else {
3960 DEBUGOUT("EEPROM Checksum Invalid\n");
3961 return -E1000_ERR_EEPROM;
3962 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003963}
3964
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003965/**
3966 * e1000_update_eeprom_checksum - Calculates/writes the EEPROM checksum
3967 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -07003968 *
3969 * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA.
3970 * Writes the difference to word offset 63 of the EEPROM.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003971 */
Joe Perches64798842008-07-11 15:17:02 -07003972s32 e1000_update_eeprom_checksum(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003973{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003974 u16 checksum = 0;
3975 u16 i, eeprom_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003976
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003977 DEBUGFUNC("e1000_update_eeprom_checksum");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003978
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003979 for (i = 0; i < EEPROM_CHECKSUM_REG; i++) {
3980 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
3981 DEBUGOUT("EEPROM Read Error\n");
3982 return -E1000_ERR_EEPROM;
3983 }
3984 checksum += eeprom_data;
3985 }
3986 checksum = (u16) EEPROM_SUM - checksum;
3987 if (e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) {
3988 DEBUGOUT("EEPROM Write Error\n");
3989 return -E1000_ERR_EEPROM;
3990 }
3991 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003992}
3993
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003994/**
3995 * e1000_write_eeprom - write words to the different EEPROM types.
3996 * @hw: Struct containing variables accessed by shared code
3997 * @offset: offset within the EEPROM to be written to
3998 * @words: number of words to write
3999 * @data: 16 bit word to be written to the EEPROM
Linus Torvalds1da177e2005-04-16 15:20:36 -07004000 *
4001 * If e1000_update_eeprom_checksum is not called after this function, the
4002 * EEPROM will most likely contain an invalid checksum.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004003 */
Joe Perches64798842008-07-11 15:17:02 -07004004s32 e1000_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004005{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004006 s32 ret;
4007 spin_lock(&e1000_eeprom_lock);
4008 ret = e1000_do_write_eeprom(hw, offset, words, data);
4009 spin_unlock(&e1000_eeprom_lock);
4010 return ret;
Christopher Li78566fe2008-09-05 14:04:05 -07004011}
4012
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004013static s32 e1000_do_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words,
4014 u16 *data)
Christopher Li78566fe2008-09-05 14:04:05 -07004015{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004016 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4017 s32 status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004018
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004019 DEBUGFUNC("e1000_write_eeprom");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004020
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004021 /* If eeprom is not yet detected, do so now */
4022 if (eeprom->word_size == 0)
4023 e1000_init_eeprom_params(hw);
Jeff Kirsher2a88c172006-09-27 12:54:05 -07004024
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004025 /* A check for invalid values: offset too large, too many words, and not
4026 * enough words.
4027 */
4028 if ((offset >= eeprom->word_size)
4029 || (words > eeprom->word_size - offset) || (words == 0)) {
4030 DEBUGOUT("\"words\" parameter out of bounds\n");
4031 return -E1000_ERR_EEPROM;
4032 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004033
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004034 if (eeprom->use_eewr)
4035 return e1000_write_eeprom_eewr(hw, offset, words, data);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004036
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004037 /* Prepare the EEPROM for writing */
4038 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
4039 return -E1000_ERR_EEPROM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004040
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004041 if (eeprom->type == e1000_eeprom_microwire) {
4042 status = e1000_write_eeprom_microwire(hw, offset, words, data);
4043 } else {
4044 status = e1000_write_eeprom_spi(hw, offset, words, data);
4045 msleep(10);
4046 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004047
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004048 /* Done with writing */
4049 e1000_release_eeprom(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004050
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004051 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004052}
4053
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004054/**
4055 * e1000_write_eeprom_spi - Writes a 16 bit word to a given offset in an SPI EEPROM.
4056 * @hw: Struct containing variables accessed by shared code
4057 * @offset: offset within the EEPROM to be written to
4058 * @words: number of words to write
4059 * @data: pointer to array of 8 bit words to be written to the EEPROM
4060 */
Joe Perches64798842008-07-11 15:17:02 -07004061static s32 e1000_write_eeprom_spi(struct e1000_hw *hw, u16 offset, u16 words,
4062 u16 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004063{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004064 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4065 u16 widx = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004066
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004067 DEBUGFUNC("e1000_write_eeprom_spi");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004068
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004069 while (widx < words) {
4070 u8 write_opcode = EEPROM_WRITE_OPCODE_SPI;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004071
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004072 if (e1000_spi_eeprom_ready(hw))
4073 return -E1000_ERR_EEPROM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004074
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004075 e1000_standby_eeprom(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004076
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004077 /* Send the WRITE ENABLE command (8 bit opcode ) */
4078 e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI,
4079 eeprom->opcode_bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004080
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004081 e1000_standby_eeprom(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004082
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004083 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
4084 if ((eeprom->address_bits == 8) && (offset >= 128))
4085 write_opcode |= EEPROM_A8_OPCODE_SPI;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004086
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004087 /* Send the Write command (8-bit opcode + addr) */
4088 e1000_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004089
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004090 e1000_shift_out_ee_bits(hw, (u16) ((offset + widx) * 2),
4091 eeprom->address_bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004092
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004093 /* Send the data */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004094
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004095 /* Loop to allow for up to whole page write (32 bytes) of eeprom */
4096 while (widx < words) {
4097 u16 word_out = data[widx];
4098 word_out = (word_out >> 8) | (word_out << 8);
4099 e1000_shift_out_ee_bits(hw, word_out, 16);
4100 widx++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004101
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004102 /* Some larger eeprom sizes are capable of a 32-byte PAGE WRITE
4103 * operation, while the smaller eeproms are capable of an 8-byte
4104 * PAGE WRITE operation. Break the inner loop to pass new address
4105 */
4106 if ((((offset + widx) * 2) % eeprom->page_size) == 0) {
4107 e1000_standby_eeprom(hw);
4108 break;
4109 }
4110 }
4111 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004112
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004113 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004114}
4115
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004116/**
4117 * e1000_write_eeprom_microwire - Writes a 16 bit word to a given offset in a Microwire EEPROM.
4118 * @hw: Struct containing variables accessed by shared code
4119 * @offset: offset within the EEPROM to be written to
4120 * @words: number of words to write
4121 * @data: pointer to array of 8 bit words to be written to the EEPROM
4122 */
Joe Perches64798842008-07-11 15:17:02 -07004123static s32 e1000_write_eeprom_microwire(struct e1000_hw *hw, u16 offset,
4124 u16 words, u16 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004125{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004126 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4127 u32 eecd;
4128 u16 words_written = 0;
4129 u16 i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004130
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004131 DEBUGFUNC("e1000_write_eeprom_microwire");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004132
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004133 /* Send the write enable command to the EEPROM (3-bit opcode plus
4134 * 6/8-bit dummy address beginning with 11). It's less work to include
4135 * the 11 of the dummy address as part of the opcode than it is to shift
4136 * it over the correct number of bits for the address. This puts the
4137 * EEPROM into write/erase mode.
4138 */
4139 e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE,
4140 (u16) (eeprom->opcode_bits + 2));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004141
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004142 e1000_shift_out_ee_bits(hw, 0, (u16) (eeprom->address_bits - 2));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004143
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004144 /* Prepare the EEPROM */
4145 e1000_standby_eeprom(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004146
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004147 while (words_written < words) {
4148 /* Send the Write command (3-bit opcode + addr) */
4149 e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE,
4150 eeprom->opcode_bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004151
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004152 e1000_shift_out_ee_bits(hw, (u16) (offset + words_written),
4153 eeprom->address_bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004154
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004155 /* Send the data */
4156 e1000_shift_out_ee_bits(hw, data[words_written], 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004157
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004158 /* Toggle the CS line. This in effect tells the EEPROM to execute
4159 * the previous command.
4160 */
4161 e1000_standby_eeprom(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004162
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004163 /* Read DO repeatedly until it is high (equal to '1'). The EEPROM will
4164 * signal that the command has been completed by raising the DO signal.
4165 * If DO does not go high in 10 milliseconds, then error out.
4166 */
4167 for (i = 0; i < 200; i++) {
4168 eecd = er32(EECD);
4169 if (eecd & E1000_EECD_DO)
4170 break;
4171 udelay(50);
4172 }
4173 if (i == 200) {
4174 DEBUGOUT("EEPROM Write did not complete\n");
4175 return -E1000_ERR_EEPROM;
4176 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004177
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004178 /* Recover from write */
4179 e1000_standby_eeprom(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004180
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004181 words_written++;
4182 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004183
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004184 /* Send the write disable command to the EEPROM (3-bit opcode plus
4185 * 6/8-bit dummy address beginning with 10). It's less work to include
4186 * the 10 of the dummy address as part of the opcode than it is to shift
4187 * it over the correct number of bits for the address. This takes the
4188 * EEPROM out of write/erase mode.
4189 */
4190 e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE,
4191 (u16) (eeprom->opcode_bits + 2));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004192
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004193 e1000_shift_out_ee_bits(hw, 0, (u16) (eeprom->address_bits - 2));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004194
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004195 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004196}
4197
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004198/**
4199 * e1000_read_mac_addr - read the adapters MAC from eeprom
4200 * @hw: Struct containing variables accessed by shared code
4201 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07004202 * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
4203 * second function of dual function devices
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004204 */
Joe Perches64798842008-07-11 15:17:02 -07004205s32 e1000_read_mac_addr(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004206{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004207 u16 offset;
4208 u16 eeprom_data, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004209
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004210 DEBUGFUNC("e1000_read_mac_addr");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004211
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004212 for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
4213 offset = i >> 1;
4214 if (e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
4215 DEBUGOUT("EEPROM Read Error\n");
4216 return -E1000_ERR_EEPROM;
4217 }
4218 hw->perm_mac_addr[i] = (u8) (eeprom_data & 0x00FF);
4219 hw->perm_mac_addr[i + 1] = (u8) (eeprom_data >> 8);
4220 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004221
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004222 switch (hw->mac_type) {
4223 default:
4224 break;
4225 case e1000_82546:
4226 case e1000_82546_rev_3:
4227 if (er32(STATUS) & E1000_STATUS_FUNC_1)
4228 hw->perm_mac_addr[5] ^= 0x01;
4229 break;
4230 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004231
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004232 for (i = 0; i < NODE_ADDRESS_SIZE; i++)
4233 hw->mac_addr[i] = hw->perm_mac_addr[i];
4234 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004235}
4236
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004237/**
4238 * e1000_init_rx_addrs - Initializes receive address filters.
4239 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -07004240 *
4241 * Places the MAC address in receive address register 0 and clears the rest
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004242 * of the receive address registers. Clears the multicast table. Assumes
Linus Torvalds1da177e2005-04-16 15:20:36 -07004243 * the receiver is in reset when the routine is called.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004244 */
Joe Perches64798842008-07-11 15:17:02 -07004245static void e1000_init_rx_addrs(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004246{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004247 u32 i;
4248 u32 rar_num;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004249
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004250 DEBUGFUNC("e1000_init_rx_addrs");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004251
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004252 /* Setup the receive address. */
4253 DEBUGOUT("Programming MAC Address into RAR[0]\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004254
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004255 e1000_rar_set(hw, hw->mac_addr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004256
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004257 rar_num = E1000_RAR_ENTRIES;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004258
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004259 /* Zero out the other 15 receive addresses. */
4260 DEBUGOUT("Clearing RAR[1-15]\n");
4261 for (i = 1; i < rar_num; i++) {
4262 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
4263 E1000_WRITE_FLUSH();
4264 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
4265 E1000_WRITE_FLUSH();
4266 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004267}
4268
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004269/**
4270 * e1000_hash_mc_addr - Hashes an address to determine its location in the multicast table
4271 * @hw: Struct containing variables accessed by shared code
4272 * @mc_addr: the multicast address to hash
4273 */
Joe Perches64798842008-07-11 15:17:02 -07004274u32 e1000_hash_mc_addr(struct e1000_hw *hw, u8 *mc_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004275{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004276 u32 hash_value = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004277
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004278 /* The portion of the address that is used for the hash table is
4279 * determined by the mc_filter_type setting.
4280 */
4281 switch (hw->mc_filter_type) {
4282 /* [0] [1] [2] [3] [4] [5]
4283 * 01 AA 00 12 34 56
4284 * LSB MSB
4285 */
4286 case 0:
4287 /* [47:36] i.e. 0x563 for above example address */
4288 hash_value = ((mc_addr[4] >> 4) | (((u16) mc_addr[5]) << 4));
4289 break;
4290 case 1:
4291 /* [46:35] i.e. 0xAC6 for above example address */
4292 hash_value = ((mc_addr[4] >> 3) | (((u16) mc_addr[5]) << 5));
4293 break;
4294 case 2:
4295 /* [45:34] i.e. 0x5D8 for above example address */
4296 hash_value = ((mc_addr[4] >> 2) | (((u16) mc_addr[5]) << 6));
4297 break;
4298 case 3:
4299 /* [43:32] i.e. 0x634 for above example address */
4300 hash_value = ((mc_addr[4]) | (((u16) mc_addr[5]) << 8));
4301 break;
4302 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004303
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004304 hash_value &= 0xFFF;
4305 return hash_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004306}
4307
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004308/**
4309 * e1000_rar_set - Puts an ethernet address into a receive address register.
4310 * @hw: Struct containing variables accessed by shared code
4311 * @addr: Address to put into receive address register
4312 * @index: Receive address register to write
4313 */
Joe Perches64798842008-07-11 15:17:02 -07004314void e1000_rar_set(struct e1000_hw *hw, u8 *addr, u32 index)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004315{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004316 u32 rar_low, rar_high;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004317
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004318 /* HW expects these in little endian so we reverse the byte order
4319 * from network order (big endian) to little endian
4320 */
4321 rar_low = ((u32) addr[0] | ((u32) addr[1] << 8) |
4322 ((u32) addr[2] << 16) | ((u32) addr[3] << 24));
4323 rar_high = ((u32) addr[4] | ((u32) addr[5] << 8));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004324
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004325 /* Disable Rx and flush all Rx frames before enabling RSS to avoid Rx
4326 * unit hang.
4327 *
4328 * Description:
4329 * If there are any Rx frames queued up or otherwise present in the HW
4330 * before RSS is enabled, and then we enable RSS, the HW Rx unit will
4331 * hang. To work around this issue, we have to disable receives and
4332 * flush out all Rx frames before we enable RSS. To do so, we modify we
4333 * redirect all Rx traffic to manageability and then reset the HW.
4334 * This flushes away Rx frames, and (since the redirections to
4335 * manageability persists across resets) keeps new ones from coming in
4336 * while we work. Then, we clear the Address Valid AV bit for all MAC
4337 * addresses and undo the re-direction to manageability.
4338 * Now, frames are coming in again, but the MAC won't accept them, so
4339 * far so good. We now proceed to initialize RSS (if necessary) and
4340 * configure the Rx unit. Last, we re-enable the AV bits and continue
4341 * on our merry way.
4342 */
4343 switch (hw->mac_type) {
4344 default:
4345 /* Indicate to hardware the Address is Valid. */
4346 rar_high |= E1000_RAH_AV;
4347 break;
4348 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004349
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004350 E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
4351 E1000_WRITE_FLUSH();
4352 E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
4353 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07004354}
4355
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004356/**
4357 * e1000_write_vfta - Writes a value to the specified offset in the VLAN filter table.
4358 * @hw: Struct containing variables accessed by shared code
4359 * @offset: Offset in VLAN filer table to write
4360 * @value: Value to write into VLAN filter table
4361 */
Joe Perches64798842008-07-11 15:17:02 -07004362void e1000_write_vfta(struct e1000_hw *hw, u32 offset, u32 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004363{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004364 u32 temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004365
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004366 if ((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) {
4367 temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1));
4368 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
4369 E1000_WRITE_FLUSH();
4370 E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp);
4371 E1000_WRITE_FLUSH();
4372 } else {
4373 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
4374 E1000_WRITE_FLUSH();
4375 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004376}
4377
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004378/**
4379 * e1000_clear_vfta - Clears the VLAN filer table
4380 * @hw: Struct containing variables accessed by shared code
4381 */
Joe Perches64798842008-07-11 15:17:02 -07004382static void e1000_clear_vfta(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004383{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004384 u32 offset;
4385 u32 vfta_value = 0;
4386 u32 vfta_offset = 0;
4387 u32 vfta_bit_in_reg = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004388
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004389 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
4390 /* If the offset we want to clear is the same offset of the
4391 * manageability VLAN ID, then clear all bits except that of the
4392 * manageability unit */
4393 vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0;
4394 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, vfta_value);
4395 E1000_WRITE_FLUSH();
4396 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004397}
4398
Joe Perches64798842008-07-11 15:17:02 -07004399static s32 e1000_id_led_init(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004400{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004401 u32 ledctl;
4402 const u32 ledctl_mask = 0x000000FF;
4403 const u32 ledctl_on = E1000_LEDCTL_MODE_LED_ON;
4404 const u32 ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
4405 u16 eeprom_data, i, temp;
4406 const u16 led_mask = 0x0F;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004407
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004408 DEBUGFUNC("e1000_id_led_init");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004409
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004410 if (hw->mac_type < e1000_82540) {
4411 /* Nothing to do */
4412 return E1000_SUCCESS;
4413 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004414
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004415 ledctl = er32(LEDCTL);
4416 hw->ledctl_default = ledctl;
4417 hw->ledctl_mode1 = hw->ledctl_default;
4418 hw->ledctl_mode2 = hw->ledctl_default;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004419
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004420 if (e1000_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, 1, &eeprom_data) < 0) {
4421 DEBUGOUT("EEPROM Read Error\n");
4422 return -E1000_ERR_EEPROM;
4423 }
Auke Kokcd94dd02006-06-27 09:08:22 -07004424
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004425 if ((eeprom_data == ID_LED_RESERVED_0000) ||
4426 (eeprom_data == ID_LED_RESERVED_FFFF)) {
4427 eeprom_data = ID_LED_DEFAULT;
4428 }
Auke Kok90fb5132006-11-01 08:47:30 -08004429
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004430 for (i = 0; i < 4; i++) {
4431 temp = (eeprom_data >> (i << 2)) & led_mask;
4432 switch (temp) {
4433 case ID_LED_ON1_DEF2:
4434 case ID_LED_ON1_ON2:
4435 case ID_LED_ON1_OFF2:
4436 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
4437 hw->ledctl_mode1 |= ledctl_on << (i << 3);
4438 break;
4439 case ID_LED_OFF1_DEF2:
4440 case ID_LED_OFF1_ON2:
4441 case ID_LED_OFF1_OFF2:
4442 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
4443 hw->ledctl_mode1 |= ledctl_off << (i << 3);
4444 break;
4445 default:
4446 /* Do nothing */
4447 break;
4448 }
4449 switch (temp) {
4450 case ID_LED_DEF1_ON2:
4451 case ID_LED_ON1_ON2:
4452 case ID_LED_OFF1_ON2:
4453 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
4454 hw->ledctl_mode2 |= ledctl_on << (i << 3);
4455 break;
4456 case ID_LED_DEF1_OFF2:
4457 case ID_LED_ON1_OFF2:
4458 case ID_LED_OFF1_OFF2:
4459 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
4460 hw->ledctl_mode2 |= ledctl_off << (i << 3);
4461 break;
4462 default:
4463 /* Do nothing */
4464 break;
4465 }
4466 }
4467 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004468}
4469
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004470/**
4471 * e1000_setup_led
4472 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -07004473 *
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004474 * Prepares SW controlable LED for use and saves the current state of the LED.
4475 */
Joe Perches64798842008-07-11 15:17:02 -07004476s32 e1000_setup_led(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004477{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004478 u32 ledctl;
4479 s32 ret_val = E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004480
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004481 DEBUGFUNC("e1000_setup_led");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004482
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004483 switch (hw->mac_type) {
4484 case e1000_82542_rev2_0:
4485 case e1000_82542_rev2_1:
4486 case e1000_82543:
4487 case e1000_82544:
4488 /* No setup necessary */
4489 break;
4490 case e1000_82541:
4491 case e1000_82547:
4492 case e1000_82541_rev_2:
4493 case e1000_82547_rev_2:
4494 /* Turn off PHY Smart Power Down (if enabled) */
4495 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
4496 &hw->phy_spd_default);
4497 if (ret_val)
4498 return ret_val;
4499 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
4500 (u16) (hw->phy_spd_default &
4501 ~IGP01E1000_GMII_SPD));
4502 if (ret_val)
4503 return ret_val;
4504 /* Fall Through */
4505 default:
4506 if (hw->media_type == e1000_media_type_fiber) {
4507 ledctl = er32(LEDCTL);
4508 /* Save current LEDCTL settings */
4509 hw->ledctl_default = ledctl;
4510 /* Turn off LED0 */
4511 ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
4512 E1000_LEDCTL_LED0_BLINK |
4513 E1000_LEDCTL_LED0_MODE_MASK);
4514 ledctl |= (E1000_LEDCTL_MODE_LED_OFF <<
4515 E1000_LEDCTL_LED0_MODE_SHIFT);
4516 ew32(LEDCTL, ledctl);
4517 } else if (hw->media_type == e1000_media_type_copper)
4518 ew32(LEDCTL, hw->ledctl_mode1);
4519 break;
4520 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004521
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004522 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004523}
4524
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004525/**
4526 * e1000_cleanup_led - Restores the saved state of the SW controlable LED.
4527 * @hw: Struct containing variables accessed by shared code
4528 */
Joe Perches64798842008-07-11 15:17:02 -07004529s32 e1000_cleanup_led(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004530{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004531 s32 ret_val = E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004532
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004533 DEBUGFUNC("e1000_cleanup_led");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004534
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004535 switch (hw->mac_type) {
4536 case e1000_82542_rev2_0:
4537 case e1000_82542_rev2_1:
4538 case e1000_82543:
4539 case e1000_82544:
4540 /* No cleanup necessary */
4541 break;
4542 case e1000_82541:
4543 case e1000_82547:
4544 case e1000_82541_rev_2:
4545 case e1000_82547_rev_2:
4546 /* Turn on PHY Smart Power Down (if previously enabled) */
4547 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
4548 hw->phy_spd_default);
4549 if (ret_val)
4550 return ret_val;
4551 /* Fall Through */
4552 default:
4553 /* Restore LEDCTL settings */
4554 ew32(LEDCTL, hw->ledctl_default);
4555 break;
4556 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004557
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004558 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004559}
4560
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004561/**
4562 * e1000_led_on - Turns on the software controllable LED
4563 * @hw: Struct containing variables accessed by shared code
4564 */
Joe Perches64798842008-07-11 15:17:02 -07004565s32 e1000_led_on(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004566{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004567 u32 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004568
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004569 DEBUGFUNC("e1000_led_on");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004570
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004571 switch (hw->mac_type) {
4572 case e1000_82542_rev2_0:
4573 case e1000_82542_rev2_1:
4574 case e1000_82543:
4575 /* Set SW Defineable Pin 0 to turn on the LED */
4576 ctrl |= E1000_CTRL_SWDPIN0;
4577 ctrl |= E1000_CTRL_SWDPIO0;
4578 break;
4579 case e1000_82544:
4580 if (hw->media_type == e1000_media_type_fiber) {
4581 /* Set SW Defineable Pin 0 to turn on the LED */
4582 ctrl |= E1000_CTRL_SWDPIN0;
4583 ctrl |= E1000_CTRL_SWDPIO0;
4584 } else {
4585 /* Clear SW Defineable Pin 0 to turn on the LED */
4586 ctrl &= ~E1000_CTRL_SWDPIN0;
4587 ctrl |= E1000_CTRL_SWDPIO0;
4588 }
4589 break;
4590 default:
4591 if (hw->media_type == e1000_media_type_fiber) {
4592 /* Clear SW Defineable Pin 0 to turn on the LED */
4593 ctrl &= ~E1000_CTRL_SWDPIN0;
4594 ctrl |= E1000_CTRL_SWDPIO0;
4595 } else if (hw->media_type == e1000_media_type_copper) {
4596 ew32(LEDCTL, hw->ledctl_mode2);
4597 return E1000_SUCCESS;
4598 }
4599 break;
4600 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004601
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004602 ew32(CTRL, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004603
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004604 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004605}
4606
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004607/**
4608 * e1000_led_off - Turns off the software controllable LED
4609 * @hw: Struct containing variables accessed by shared code
4610 */
Joe Perches64798842008-07-11 15:17:02 -07004611s32 e1000_led_off(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004612{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004613 u32 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004614
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004615 DEBUGFUNC("e1000_led_off");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004616
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004617 switch (hw->mac_type) {
4618 case e1000_82542_rev2_0:
4619 case e1000_82542_rev2_1:
4620 case e1000_82543:
4621 /* Clear SW Defineable Pin 0 to turn off the LED */
4622 ctrl &= ~E1000_CTRL_SWDPIN0;
4623 ctrl |= E1000_CTRL_SWDPIO0;
4624 break;
4625 case e1000_82544:
4626 if (hw->media_type == e1000_media_type_fiber) {
4627 /* Clear SW Defineable Pin 0 to turn off the LED */
4628 ctrl &= ~E1000_CTRL_SWDPIN0;
4629 ctrl |= E1000_CTRL_SWDPIO0;
4630 } else {
4631 /* Set SW Defineable Pin 0 to turn off the LED */
4632 ctrl |= E1000_CTRL_SWDPIN0;
4633 ctrl |= E1000_CTRL_SWDPIO0;
4634 }
4635 break;
4636 default:
4637 if (hw->media_type == e1000_media_type_fiber) {
4638 /* Set SW Defineable Pin 0 to turn off the LED */
4639 ctrl |= E1000_CTRL_SWDPIN0;
4640 ctrl |= E1000_CTRL_SWDPIO0;
4641 } else if (hw->media_type == e1000_media_type_copper) {
4642 ew32(LEDCTL, hw->ledctl_mode1);
4643 return E1000_SUCCESS;
4644 }
4645 break;
4646 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004647
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004648 ew32(CTRL, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004649
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004650 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004651}
4652
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004653/**
4654 * e1000_clear_hw_cntrs - Clears all hardware statistics counters.
4655 * @hw: Struct containing variables accessed by shared code
4656 */
Joe Perches64798842008-07-11 15:17:02 -07004657static void e1000_clear_hw_cntrs(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004658{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004659 volatile u32 temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004660
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004661 temp = er32(CRCERRS);
4662 temp = er32(SYMERRS);
4663 temp = er32(MPC);
4664 temp = er32(SCC);
4665 temp = er32(ECOL);
4666 temp = er32(MCC);
4667 temp = er32(LATECOL);
4668 temp = er32(COLC);
4669 temp = er32(DC);
4670 temp = er32(SEC);
4671 temp = er32(RLEC);
4672 temp = er32(XONRXC);
4673 temp = er32(XONTXC);
4674 temp = er32(XOFFRXC);
4675 temp = er32(XOFFTXC);
4676 temp = er32(FCRUC);
Auke Kokcd94dd02006-06-27 09:08:22 -07004677
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004678 temp = er32(PRC64);
4679 temp = er32(PRC127);
4680 temp = er32(PRC255);
4681 temp = er32(PRC511);
4682 temp = er32(PRC1023);
4683 temp = er32(PRC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07004684
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004685 temp = er32(GPRC);
4686 temp = er32(BPRC);
4687 temp = er32(MPRC);
4688 temp = er32(GPTC);
4689 temp = er32(GORCL);
4690 temp = er32(GORCH);
4691 temp = er32(GOTCL);
4692 temp = er32(GOTCH);
4693 temp = er32(RNBC);
4694 temp = er32(RUC);
4695 temp = er32(RFC);
4696 temp = er32(ROC);
4697 temp = er32(RJC);
4698 temp = er32(TORL);
4699 temp = er32(TORH);
4700 temp = er32(TOTL);
4701 temp = er32(TOTH);
4702 temp = er32(TPR);
4703 temp = er32(TPT);
Auke Kokcd94dd02006-06-27 09:08:22 -07004704
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004705 temp = er32(PTC64);
4706 temp = er32(PTC127);
4707 temp = er32(PTC255);
4708 temp = er32(PTC511);
4709 temp = er32(PTC1023);
4710 temp = er32(PTC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07004711
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004712 temp = er32(MPTC);
4713 temp = er32(BPTC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004714
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004715 if (hw->mac_type < e1000_82543)
4716 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004717
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004718 temp = er32(ALGNERRC);
4719 temp = er32(RXERRC);
4720 temp = er32(TNCRS);
4721 temp = er32(CEXTERR);
4722 temp = er32(TSCTC);
4723 temp = er32(TSCTFC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004724
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004725 if (hw->mac_type <= e1000_82544)
4726 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004727
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004728 temp = er32(MGTPRC);
4729 temp = er32(MGTPDC);
4730 temp = er32(MGTPTC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004731}
4732
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004733/**
4734 * e1000_reset_adaptive - Resets Adaptive IFS to its default state.
4735 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -07004736 *
4737 * Call this after e1000_init_hw. You may override the IFS defaults by setting
Joe Perchesc3033b02008-03-21 11:06:25 -07004738 * hw->ifs_params_forced to true. However, you must initialize hw->
Linus Torvalds1da177e2005-04-16 15:20:36 -07004739 * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio
4740 * before calling this function.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004741 */
Joe Perches64798842008-07-11 15:17:02 -07004742void e1000_reset_adaptive(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004743{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004744 DEBUGFUNC("e1000_reset_adaptive");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004745
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004746 if (hw->adaptive_ifs) {
4747 if (!hw->ifs_params_forced) {
4748 hw->current_ifs_val = 0;
4749 hw->ifs_min_val = IFS_MIN;
4750 hw->ifs_max_val = IFS_MAX;
4751 hw->ifs_step_size = IFS_STEP;
4752 hw->ifs_ratio = IFS_RATIO;
4753 }
4754 hw->in_ifs_mode = false;
4755 ew32(AIT, 0);
4756 } else {
4757 DEBUGOUT("Not in Adaptive IFS mode!\n");
4758 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004759}
4760
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004761/**
4762 * e1000_update_adaptive - update adaptive IFS
4763 * @hw: Struct containing variables accessed by shared code
4764 * @tx_packets: Number of transmits since last callback
4765 * @total_collisions: Number of collisions since last callback
4766 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07004767 * Called during the callback/watchdog routine to update IFS value based on
4768 * the ratio of transmits to collisions.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004769 */
Joe Perches64798842008-07-11 15:17:02 -07004770void e1000_update_adaptive(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004771{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004772 DEBUGFUNC("e1000_update_adaptive");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004773
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004774 if (hw->adaptive_ifs) {
4775 if ((hw->collision_delta *hw->ifs_ratio) > hw->tx_packet_delta) {
4776 if (hw->tx_packet_delta > MIN_NUM_XMITS) {
4777 hw->in_ifs_mode = true;
4778 if (hw->current_ifs_val < hw->ifs_max_val) {
4779 if (hw->current_ifs_val == 0)
4780 hw->current_ifs_val =
4781 hw->ifs_min_val;
4782 else
4783 hw->current_ifs_val +=
4784 hw->ifs_step_size;
4785 ew32(AIT, hw->current_ifs_val);
4786 }
4787 }
4788 } else {
4789 if (hw->in_ifs_mode
4790 && (hw->tx_packet_delta <= MIN_NUM_XMITS)) {
4791 hw->current_ifs_val = 0;
4792 hw->in_ifs_mode = false;
4793 ew32(AIT, 0);
4794 }
4795 }
4796 } else {
4797 DEBUGOUT("Not in Adaptive IFS mode!\n");
4798 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004799}
4800
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004801/**
4802 * e1000_tbi_adjust_stats
4803 * @hw: Struct containing variables accessed by shared code
4804 * @frame_len: The length of the frame in question
4805 * @mac_addr: The Ethernet destination address of the frame in question
Linus Torvalds1da177e2005-04-16 15:20:36 -07004806 *
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004807 * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT
4808 */
Joe Perches64798842008-07-11 15:17:02 -07004809void e1000_tbi_adjust_stats(struct e1000_hw *hw, struct e1000_hw_stats *stats,
4810 u32 frame_len, u8 *mac_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004811{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004812 u64 carry_bit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004813
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004814 /* First adjust the frame length. */
4815 frame_len--;
4816 /* We need to adjust the statistics counters, since the hardware
4817 * counters overcount this packet as a CRC error and undercount
4818 * the packet as a good packet
4819 */
4820 /* This packet should not be counted as a CRC error. */
4821 stats->crcerrs--;
4822 /* This packet does count as a Good Packet Received. */
4823 stats->gprc++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004824
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004825 /* Adjust the Good Octets received counters */
4826 carry_bit = 0x80000000 & stats->gorcl;
4827 stats->gorcl += frame_len;
4828 /* If the high bit of Gorcl (the low 32 bits of the Good Octets
4829 * Received Count) was one before the addition,
4830 * AND it is zero after, then we lost the carry out,
4831 * need to add one to Gorch (Good Octets Received Count High).
4832 * This could be simplified if all environments supported
4833 * 64-bit integers.
4834 */
4835 if (carry_bit && ((stats->gorcl & 0x80000000) == 0))
4836 stats->gorch++;
4837 /* Is this a broadcast or multicast? Check broadcast first,
4838 * since the test for a multicast frame will test positive on
4839 * a broadcast frame.
4840 */
4841 if ((mac_addr[0] == (u8) 0xff) && (mac_addr[1] == (u8) 0xff))
4842 /* Broadcast packet */
4843 stats->bprc++;
4844 else if (*mac_addr & 0x01)
4845 /* Multicast packet */
4846 stats->mprc++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004847
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004848 if (frame_len == hw->max_frame_size) {
4849 /* In this case, the hardware has overcounted the number of
4850 * oversize frames.
4851 */
4852 if (stats->roc > 0)
4853 stats->roc--;
4854 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004855
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004856 /* Adjust the bin counters when the extra byte put the frame in the
4857 * wrong bin. Remember that the frame_len was adjusted above.
4858 */
4859 if (frame_len == 64) {
4860 stats->prc64++;
4861 stats->prc127--;
4862 } else if (frame_len == 127) {
4863 stats->prc127++;
4864 stats->prc255--;
4865 } else if (frame_len == 255) {
4866 stats->prc255++;
4867 stats->prc511--;
4868 } else if (frame_len == 511) {
4869 stats->prc511++;
4870 stats->prc1023--;
4871 } else if (frame_len == 1023) {
4872 stats->prc1023++;
4873 stats->prc1522--;
4874 } else if (frame_len == 1522) {
4875 stats->prc1522++;
4876 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004877}
4878
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004879/**
4880 * e1000_get_bus_info
4881 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -07004882 *
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004883 * Gets the current PCI bus type, speed, and width of the hardware
4884 */
Joe Perches64798842008-07-11 15:17:02 -07004885void e1000_get_bus_info(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004886{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004887 u32 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004888
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004889 switch (hw->mac_type) {
4890 case e1000_82542_rev2_0:
4891 case e1000_82542_rev2_1:
4892 hw->bus_type = e1000_bus_type_pci;
4893 hw->bus_speed = e1000_bus_speed_unknown;
4894 hw->bus_width = e1000_bus_width_unknown;
4895 break;
4896 default:
4897 status = er32(STATUS);
4898 hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
4899 e1000_bus_type_pcix : e1000_bus_type_pci;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004900
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004901 if (hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) {
4902 hw->bus_speed = (hw->bus_type == e1000_bus_type_pci) ?
4903 e1000_bus_speed_66 : e1000_bus_speed_120;
4904 } else if (hw->bus_type == e1000_bus_type_pci) {
4905 hw->bus_speed = (status & E1000_STATUS_PCI66) ?
4906 e1000_bus_speed_66 : e1000_bus_speed_33;
4907 } else {
4908 switch (status & E1000_STATUS_PCIX_SPEED) {
4909 case E1000_STATUS_PCIX_SPEED_66:
4910 hw->bus_speed = e1000_bus_speed_66;
4911 break;
4912 case E1000_STATUS_PCIX_SPEED_100:
4913 hw->bus_speed = e1000_bus_speed_100;
4914 break;
4915 case E1000_STATUS_PCIX_SPEED_133:
4916 hw->bus_speed = e1000_bus_speed_133;
4917 break;
4918 default:
4919 hw->bus_speed = e1000_bus_speed_reserved;
4920 break;
4921 }
4922 }
4923 hw->bus_width = (status & E1000_STATUS_BUS64) ?
4924 e1000_bus_width_64 : e1000_bus_width_32;
4925 break;
4926 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004927}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004928
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004929/**
4930 * e1000_write_reg_io
4931 * @hw: Struct containing variables accessed by shared code
4932 * @offset: offset to write to
4933 * @value: value to write
4934 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07004935 * Writes a value to one of the devices registers using port I/O (as opposed to
4936 * memory mapped I/O). Only 82544 and newer devices support port I/O.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004937 */
Joe Perches64798842008-07-11 15:17:02 -07004938static void e1000_write_reg_io(struct e1000_hw *hw, u32 offset, u32 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004939{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004940 unsigned long io_addr = hw->io_base;
4941 unsigned long io_data = hw->io_base + 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004942
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004943 e1000_io_write(hw, io_addr, offset);
4944 e1000_io_write(hw, io_data, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004945}
4946
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004947/**
4948 * e1000_get_cable_length - Estimates the cable length.
4949 * @hw: Struct containing variables accessed by shared code
4950 * @min_length: The estimated minimum length
4951 * @max_length: The estimated maximum length
Linus Torvalds1da177e2005-04-16 15:20:36 -07004952 *
4953 * returns: - E1000_ERR_XXX
4954 * E1000_SUCCESS
4955 *
4956 * This function always returns a ranged length (minimum & maximum).
4957 * So for M88 phy's, this function interprets the one value returned from the
4958 * register to the minimum and maximum range.
4959 * For IGP phy's, the function calculates the range by the AGC registers.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004960 */
Joe Perches64798842008-07-11 15:17:02 -07004961static s32 e1000_get_cable_length(struct e1000_hw *hw, u16 *min_length,
4962 u16 *max_length)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004963{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004964 s32 ret_val;
4965 u16 agc_value = 0;
4966 u16 i, phy_data;
4967 u16 cable_length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004968
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004969 DEBUGFUNC("e1000_get_cable_length");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004970
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004971 *min_length = *max_length = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004972
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004973 /* Use old method for Phy older than IGP */
4974 if (hw->phy_type == e1000_phy_m88) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004975
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004976 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
4977 &phy_data);
4978 if (ret_val)
4979 return ret_val;
4980 cable_length = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
4981 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004982
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004983 /* Convert the enum value to ranged values */
4984 switch (cable_length) {
4985 case e1000_cable_length_50:
4986 *min_length = 0;
4987 *max_length = e1000_igp_cable_length_50;
4988 break;
4989 case e1000_cable_length_50_80:
4990 *min_length = e1000_igp_cable_length_50;
4991 *max_length = e1000_igp_cable_length_80;
4992 break;
4993 case e1000_cable_length_80_110:
4994 *min_length = e1000_igp_cable_length_80;
4995 *max_length = e1000_igp_cable_length_110;
4996 break;
4997 case e1000_cable_length_110_140:
4998 *min_length = e1000_igp_cable_length_110;
4999 *max_length = e1000_igp_cable_length_140;
5000 break;
5001 case e1000_cable_length_140:
5002 *min_length = e1000_igp_cable_length_140;
5003 *max_length = e1000_igp_cable_length_170;
5004 break;
5005 default:
5006 return -E1000_ERR_PHY;
5007 break;
5008 }
5009 } else if (hw->phy_type == e1000_phy_igp) { /* For IGP PHY */
5010 u16 cur_agc_value;
5011 u16 min_agc_value = IGP01E1000_AGC_LENGTH_TABLE_SIZE;
5012 u16 agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
5013 { IGP01E1000_PHY_AGC_A,
5014 IGP01E1000_PHY_AGC_B,
5015 IGP01E1000_PHY_AGC_C,
5016 IGP01E1000_PHY_AGC_D
5017 };
5018 /* Read the AGC registers for all channels */
5019 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005020
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005021 ret_val =
5022 e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
5023 if (ret_val)
5024 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005025
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005026 cur_agc_value = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005027
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005028 /* Value bound check. */
5029 if ((cur_agc_value >=
5030 IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1)
5031 || (cur_agc_value == 0))
5032 return -E1000_ERR_PHY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005033
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005034 agc_value += cur_agc_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005035
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005036 /* Update minimal AGC value. */
5037 if (min_agc_value > cur_agc_value)
5038 min_agc_value = cur_agc_value;
5039 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005040
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005041 /* Remove the minimal AGC result for length < 50m */
5042 if (agc_value <
5043 IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) {
5044 agc_value -= min_agc_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005045
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005046 /* Get the average length of the remaining 3 channels */
5047 agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1);
5048 } else {
5049 /* Get the average length of all the 4 channels. */
5050 agc_value /= IGP01E1000_PHY_CHANNEL_NUM;
5051 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005052
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005053 /* Set the range of the calculated length. */
5054 *min_length = ((e1000_igp_cable_length_table[agc_value] -
5055 IGP01E1000_AGC_RANGE) > 0) ?
5056 (e1000_igp_cable_length_table[agc_value] -
5057 IGP01E1000_AGC_RANGE) : 0;
5058 *max_length = e1000_igp_cable_length_table[agc_value] +
5059 IGP01E1000_AGC_RANGE;
5060 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005061
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005062 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005063}
5064
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005065/**
5066 * e1000_check_polarity - Check the cable polarity
5067 * @hw: Struct containing variables accessed by shared code
5068 * @polarity: output parameter : 0 - Polarity is not reversed
Linus Torvalds1da177e2005-04-16 15:20:36 -07005069 * 1 - Polarity is reversed.
5070 *
5071 * returns: - E1000_ERR_XXX
5072 * E1000_SUCCESS
5073 *
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02005074 * For phy's older than IGP, this function simply reads the polarity bit in the
Linus Torvalds1da177e2005-04-16 15:20:36 -07005075 * Phy Status register. For IGP phy's, this bit is valid only if link speed is
5076 * 10 Mbps. If the link speed is 100 Mbps there is no polarity so this bit will
5077 * return 0. If the link speed is 1000 Mbps the polarity status is in the
5078 * IGP01E1000_PHY_PCS_INIT_REG.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005079 */
Joe Perches64798842008-07-11 15:17:02 -07005080static s32 e1000_check_polarity(struct e1000_hw *hw,
5081 e1000_rev_polarity *polarity)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005082{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005083 s32 ret_val;
5084 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005085
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005086 DEBUGFUNC("e1000_check_polarity");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005087
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005088 if (hw->phy_type == e1000_phy_m88) {
5089 /* return the Polarity bit in the Status register. */
5090 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
5091 &phy_data);
5092 if (ret_val)
5093 return ret_val;
5094 *polarity = ((phy_data & M88E1000_PSSR_REV_POLARITY) >>
5095 M88E1000_PSSR_REV_POLARITY_SHIFT) ?
5096 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07005097
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005098 } else if (hw->phy_type == e1000_phy_igp) {
5099 /* Read the Status register to check the speed */
5100 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
5101 &phy_data);
5102 if (ret_val)
5103 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005104
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005105 /* If speed is 1000 Mbps, must read the IGP01E1000_PHY_PCS_INIT_REG to
5106 * find the polarity status */
5107 if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
5108 IGP01E1000_PSSR_SPEED_1000MBPS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005109
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005110 /* Read the GIG initialization PCS register (0x00B4) */
5111 ret_val =
5112 e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG,
5113 &phy_data);
5114 if (ret_val)
5115 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005116
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005117 /* Check the polarity bits */
5118 *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ?
5119 e1000_rev_polarity_reversed :
5120 e1000_rev_polarity_normal;
5121 } else {
5122 /* For 10 Mbps, read the polarity bit in the status register. (for
5123 * 100 Mbps this bit is always 0) */
5124 *polarity =
5125 (phy_data & IGP01E1000_PSSR_POLARITY_REVERSED) ?
5126 e1000_rev_polarity_reversed :
5127 e1000_rev_polarity_normal;
5128 }
5129 }
5130 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005131}
5132
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005133/**
5134 * e1000_check_downshift - Check if Downshift occurred
5135 * @hw: Struct containing variables accessed by shared code
5136 * @downshift: output parameter : 0 - No Downshift occurred.
5137 * 1 - Downshift occurred.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005138 *
5139 * returns: - E1000_ERR_XXX
Auke Kok76c224b2006-05-23 13:36:06 -07005140 * E1000_SUCCESS
Linus Torvalds1da177e2005-04-16 15:20:36 -07005141 *
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02005142 * For phy's older than IGP, this function reads the Downshift bit in the Phy
Linus Torvalds1da177e2005-04-16 15:20:36 -07005143 * Specific Status register. For IGP phy's, it reads the Downgrade bit in the
5144 * Link Health register. In IGP this bit is latched high, so the driver must
5145 * read it immediately after link is established.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005146 */
Joe Perches64798842008-07-11 15:17:02 -07005147static s32 e1000_check_downshift(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005148{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005149 s32 ret_val;
5150 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005151
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005152 DEBUGFUNC("e1000_check_downshift");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005153
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005154 if (hw->phy_type == e1000_phy_igp) {
5155 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH,
5156 &phy_data);
5157 if (ret_val)
5158 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005159
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005160 hw->speed_downgraded =
5161 (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0;
5162 } else if (hw->phy_type == e1000_phy_m88) {
5163 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
5164 &phy_data);
5165 if (ret_val)
5166 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005167
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005168 hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >>
5169 M88E1000_PSSR_DOWNSHIFT_SHIFT;
5170 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005171
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005172 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005173}
5174
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005175/**
5176 * e1000_config_dsp_after_link_change
5177 * @hw: Struct containing variables accessed by shared code
5178 * @link_up: was link up at the time this was called
5179 *
5180 * returns: - E1000_ERR_PHY if fail to read/write the PHY
5181 * E1000_SUCCESS at any other case.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005182 *
5183 * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a
5184 * gigabit link is achieved to improve link quality.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005185 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005186
Joe Perches64798842008-07-11 15:17:02 -07005187static s32 e1000_config_dsp_after_link_change(struct e1000_hw *hw, bool link_up)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005188{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005189 s32 ret_val;
5190 u16 phy_data, phy_saved_data, speed, duplex, i;
5191 u16 dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
5192 { IGP01E1000_PHY_AGC_PARAM_A,
5193 IGP01E1000_PHY_AGC_PARAM_B,
5194 IGP01E1000_PHY_AGC_PARAM_C,
5195 IGP01E1000_PHY_AGC_PARAM_D
5196 };
5197 u16 min_length, max_length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005198
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005199 DEBUGFUNC("e1000_config_dsp_after_link_change");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005200
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005201 if (hw->phy_type != e1000_phy_igp)
5202 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005203
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005204 if (link_up) {
5205 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
5206 if (ret_val) {
5207 DEBUGOUT("Error getting link speed and duplex\n");
5208 return ret_val;
5209 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005210
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005211 if (speed == SPEED_1000) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005212
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005213 ret_val =
5214 e1000_get_cable_length(hw, &min_length,
5215 &max_length);
5216 if (ret_val)
5217 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005218
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005219 if ((hw->dsp_config_state == e1000_dsp_config_enabled)
5220 && min_length >= e1000_igp_cable_length_50) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005221
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005222 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
5223 ret_val =
5224 e1000_read_phy_reg(hw,
5225 dsp_reg_array[i],
5226 &phy_data);
5227 if (ret_val)
5228 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005229
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005230 phy_data &=
5231 ~IGP01E1000_PHY_EDAC_MU_INDEX;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005232
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005233 ret_val =
5234 e1000_write_phy_reg(hw,
5235 dsp_reg_array
5236 [i], phy_data);
5237 if (ret_val)
5238 return ret_val;
5239 }
5240 hw->dsp_config_state =
5241 e1000_dsp_config_activated;
5242 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005243
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005244 if ((hw->ffe_config_state == e1000_ffe_config_enabled)
5245 && (min_length < e1000_igp_cable_length_50)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005246
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005247 u16 ffe_idle_err_timeout =
5248 FFE_IDLE_ERR_COUNT_TIMEOUT_20;
5249 u32 idle_errs = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005250
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005251 /* clear previous idle error counts */
5252 ret_val =
5253 e1000_read_phy_reg(hw, PHY_1000T_STATUS,
5254 &phy_data);
5255 if (ret_val)
5256 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005257
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005258 for (i = 0; i < ffe_idle_err_timeout; i++) {
5259 udelay(1000);
5260 ret_val =
5261 e1000_read_phy_reg(hw,
5262 PHY_1000T_STATUS,
5263 &phy_data);
5264 if (ret_val)
5265 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005266
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005267 idle_errs +=
5268 (phy_data &
5269 SR_1000T_IDLE_ERROR_CNT);
5270 if (idle_errs >
5271 SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT)
5272 {
5273 hw->ffe_config_state =
5274 e1000_ffe_config_active;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005275
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005276 ret_val =
5277 e1000_write_phy_reg(hw,
5278 IGP01E1000_PHY_DSP_FFE,
5279 IGP01E1000_PHY_DSP_FFE_CM_CP);
5280 if (ret_val)
5281 return ret_val;
5282 break;
5283 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005284
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005285 if (idle_errs)
5286 ffe_idle_err_timeout =
5287 FFE_IDLE_ERR_COUNT_TIMEOUT_100;
5288 }
5289 }
5290 }
5291 } else {
5292 if (hw->dsp_config_state == e1000_dsp_config_activated) {
5293 /* Save off the current value of register 0x2F5B to be restored at
5294 * the end of the routines. */
5295 ret_val =
5296 e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005297
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005298 if (ret_val)
5299 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005300
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005301 /* Disable the PHY transmitter */
5302 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005303
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005304 if (ret_val)
5305 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005306
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005307 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005308
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005309 ret_val = e1000_write_phy_reg(hw, 0x0000,
5310 IGP01E1000_IEEE_FORCE_GIGA);
5311 if (ret_val)
5312 return ret_val;
5313 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
5314 ret_val =
5315 e1000_read_phy_reg(hw, dsp_reg_array[i],
5316 &phy_data);
5317 if (ret_val)
5318 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005319
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005320 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
5321 phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005322
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005323 ret_val =
5324 e1000_write_phy_reg(hw, dsp_reg_array[i],
5325 phy_data);
5326 if (ret_val)
5327 return ret_val;
5328 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005329
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005330 ret_val = e1000_write_phy_reg(hw, 0x0000,
5331 IGP01E1000_IEEE_RESTART_AUTONEG);
5332 if (ret_val)
5333 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005334
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005335 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005336
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005337 /* Now enable the transmitter */
5338 ret_val =
5339 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005340
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005341 if (ret_val)
5342 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005343
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005344 hw->dsp_config_state = e1000_dsp_config_enabled;
5345 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005346
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005347 if (hw->ffe_config_state == e1000_ffe_config_active) {
5348 /* Save off the current value of register 0x2F5B to be restored at
5349 * the end of the routines. */
5350 ret_val =
5351 e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005352
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005353 if (ret_val)
5354 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005355
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005356 /* Disable the PHY transmitter */
5357 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005358
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005359 if (ret_val)
5360 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005361
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005362 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005363
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005364 ret_val = e1000_write_phy_reg(hw, 0x0000,
5365 IGP01E1000_IEEE_FORCE_GIGA);
5366 if (ret_val)
5367 return ret_val;
5368 ret_val =
5369 e1000_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE,
5370 IGP01E1000_PHY_DSP_FFE_DEFAULT);
5371 if (ret_val)
5372 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005373
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005374 ret_val = e1000_write_phy_reg(hw, 0x0000,
5375 IGP01E1000_IEEE_RESTART_AUTONEG);
5376 if (ret_val)
5377 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005378
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005379 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005380
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005381 /* Now enable the transmitter */
5382 ret_val =
5383 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005384
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005385 if (ret_val)
5386 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005387
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005388 hw->ffe_config_state = e1000_ffe_config_enabled;
5389 }
5390 }
5391 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005392}
5393
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005394/**
5395 * e1000_set_phy_mode - Set PHY to class A mode
5396 * @hw: Struct containing variables accessed by shared code
5397 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07005398 * Assumes the following operations will follow to enable the new class mode.
5399 * 1. Do a PHY soft reset
5400 * 2. Restart auto-negotiation or force link.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005401 */
Joe Perches64798842008-07-11 15:17:02 -07005402static s32 e1000_set_phy_mode(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005403{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005404 s32 ret_val;
5405 u16 eeprom_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005406
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005407 DEBUGFUNC("e1000_set_phy_mode");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005408
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005409 if ((hw->mac_type == e1000_82545_rev_3) &&
5410 (hw->media_type == e1000_media_type_copper)) {
5411 ret_val =
5412 e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, 1,
5413 &eeprom_data);
5414 if (ret_val) {
5415 return ret_val;
5416 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005417
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005418 if ((eeprom_data != EEPROM_RESERVED_WORD) &&
5419 (eeprom_data & EEPROM_PHY_CLASS_A)) {
5420 ret_val =
5421 e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT,
5422 0x000B);
5423 if (ret_val)
5424 return ret_val;
5425 ret_val =
5426 e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL,
5427 0x8104);
5428 if (ret_val)
5429 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005430
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005431 hw->phy_reset_disable = false;
5432 }
5433 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005434
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005435 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005436}
5437
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005438/**
5439 * e1000_set_d3_lplu_state - set d3 link power state
5440 * @hw: Struct containing variables accessed by shared code
5441 * @active: true to enable lplu false to disable lplu.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005442 *
5443 * This function sets the lplu state according to the active flag. When
5444 * activating lplu this function also disables smart speed and vise versa.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005445 * lplu will not be activated unless the device autonegotiation advertisement
Linus Torvalds1da177e2005-04-16 15:20:36 -07005446 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005447 *
5448 * returns: - E1000_ERR_PHY if fail to read/write the PHY
5449 * E1000_SUCCESS at any other case.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005450 */
Joe Perches64798842008-07-11 15:17:02 -07005451static s32 e1000_set_d3_lplu_state(struct e1000_hw *hw, bool active)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005452{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005453 s32 ret_val;
5454 u16 phy_data;
5455 DEBUGFUNC("e1000_set_d3_lplu_state");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005456
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005457 if (hw->phy_type != e1000_phy_igp)
5458 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005459
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005460 /* During driver activity LPLU should not be used or it will attain link
5461 * from the lowest speeds starting from 10Mbps. The capability is used for
5462 * Dx transitions and states */
5463 if (hw->mac_type == e1000_82541_rev_2
5464 || hw->mac_type == e1000_82547_rev_2) {
5465 ret_val =
5466 e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data);
5467 if (ret_val)
5468 return ret_val;
5469 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005470
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005471 if (!active) {
5472 if (hw->mac_type == e1000_82541_rev_2 ||
5473 hw->mac_type == e1000_82547_rev_2) {
5474 phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
5475 ret_val =
5476 e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
5477 phy_data);
5478 if (ret_val)
5479 return ret_val;
5480 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005481
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005482 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
5483 * Dx states where the power conservation is most important. During
5484 * driver activity we should enable SmartSpeed, so performance is
5485 * maintained. */
5486 if (hw->smart_speed == e1000_smart_speed_on) {
5487 ret_val =
5488 e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5489 &phy_data);
5490 if (ret_val)
5491 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005492
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005493 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
5494 ret_val =
5495 e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5496 phy_data);
5497 if (ret_val)
5498 return ret_val;
5499 } else if (hw->smart_speed == e1000_smart_speed_off) {
5500 ret_val =
5501 e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5502 &phy_data);
5503 if (ret_val)
5504 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005505
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005506 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
5507 ret_val =
5508 e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5509 phy_data);
5510 if (ret_val)
5511 return ret_val;
5512 }
5513 } else if ((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT)
5514 || (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL)
5515 || (hw->autoneg_advertised ==
5516 AUTONEG_ADVERTISE_10_100_ALL)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005517
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005518 if (hw->mac_type == e1000_82541_rev_2 ||
5519 hw->mac_type == e1000_82547_rev_2) {
5520 phy_data |= IGP01E1000_GMII_FLEX_SPD;
5521 ret_val =
5522 e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
5523 phy_data);
5524 if (ret_val)
5525 return ret_val;
5526 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005527
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005528 /* When LPLU is enabled we should disable SmartSpeed */
5529 ret_val =
5530 e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5531 &phy_data);
5532 if (ret_val)
5533 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005534
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005535 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
5536 ret_val =
5537 e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5538 phy_data);
5539 if (ret_val)
5540 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005541
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005542 }
5543 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005544}
5545
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005546/**
5547 * e1000_set_vco_speed
5548 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -07005549 *
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005550 * Change VCO speed register to improve Bit Error Rate performance of SERDES.
5551 */
Joe Perches64798842008-07-11 15:17:02 -07005552static s32 e1000_set_vco_speed(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005553{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005554 s32 ret_val;
5555 u16 default_page = 0;
5556 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005557
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005558 DEBUGFUNC("e1000_set_vco_speed");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005559
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005560 switch (hw->mac_type) {
5561 case e1000_82545_rev_3:
5562 case e1000_82546_rev_3:
5563 break;
5564 default:
5565 return E1000_SUCCESS;
5566 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005567
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005568 /* Set PHY register 30, page 5, bit 8 to 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005569
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005570 ret_val =
5571 e1000_read_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, &default_page);
5572 if (ret_val)
5573 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005574
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005575 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005);
5576 if (ret_val)
5577 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005578
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005579 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
5580 if (ret_val)
5581 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005582
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005583 phy_data &= ~M88E1000_PHY_VCO_REG_BIT8;
5584 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
5585 if (ret_val)
5586 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005587
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005588 /* Set PHY register 30, page 4, bit 11 to 1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005589
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005590 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004);
5591 if (ret_val)
5592 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005593
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005594 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
5595 if (ret_val)
5596 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005597
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005598 phy_data |= M88E1000_PHY_VCO_REG_BIT11;
5599 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
5600 if (ret_val)
5601 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005602
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005603 ret_val =
5604 e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, default_page);
5605 if (ret_val)
5606 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005607
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005608 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005609}
5610
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005611
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005612/**
5613 * e1000_enable_mng_pass_thru - check for bmc pass through
5614 * @hw: Struct containing variables accessed by shared code
5615 *
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005616 * Verifies the hardware needs to allow ARPs to be processed by the host
Joe Perchesc3033b02008-03-21 11:06:25 -07005617 * returns: - true/false
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005618 */
Joe Perches64798842008-07-11 15:17:02 -07005619u32 e1000_enable_mng_pass_thru(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005620{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005621 u32 manc;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005622
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005623 if (hw->asf_firmware_present) {
5624 manc = er32(MANC);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005625
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005626 if (!(manc & E1000_MANC_RCV_TCO_EN) ||
5627 !(manc & E1000_MANC_EN_MAC_ADDR_FILTER))
5628 return false;
5629 if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN))
5630 return true;
5631 }
5632 return false;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005633}
5634
Joe Perches64798842008-07-11 15:17:02 -07005635static s32 e1000_polarity_reversal_workaround(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005636{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005637 s32 ret_val;
5638 u16 mii_status_reg;
5639 u16 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005640
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005641 /* Polarity reversal workaround for forced 10F/10H links. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005642
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005643 /* Disable the transmitter on the PHY */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005644
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005645 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
5646 if (ret_val)
5647 return ret_val;
5648 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF);
5649 if (ret_val)
5650 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005651
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005652 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
5653 if (ret_val)
5654 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005655
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005656 /* This loop will early-out if the NO link condition has been met. */
5657 for (i = PHY_FORCE_TIME; i > 0; i--) {
5658 /* Read the MII Status Register and wait for Link Status bit
5659 * to be clear.
5660 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005661
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005662 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
5663 if (ret_val)
5664 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005665
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005666 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
5667 if (ret_val)
5668 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005669
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005670 if ((mii_status_reg & ~MII_SR_LINK_STATUS) == 0)
5671 break;
5672 mdelay(100);
5673 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005674
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005675 /* Recommended delay time after link has been lost */
5676 mdelay(1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005677
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005678 /* Now we will re-enable th transmitter on the PHY */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005679
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005680 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
5681 if (ret_val)
5682 return ret_val;
5683 mdelay(50);
5684 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0);
5685 if (ret_val)
5686 return ret_val;
5687 mdelay(50);
5688 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00);
5689 if (ret_val)
5690 return ret_val;
5691 mdelay(50);
5692 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000);
5693 if (ret_val)
5694 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005695
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005696 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
5697 if (ret_val)
5698 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005699
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005700 /* This loop will early-out if the link condition has been met. */
5701 for (i = PHY_FORCE_TIME; i > 0; i--) {
5702 /* Read the MII Status Register and wait for Link Status bit
5703 * to be set.
5704 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005705
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005706 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
5707 if (ret_val)
5708 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005709
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005710 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
5711 if (ret_val)
5712 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005713
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005714 if (mii_status_reg & MII_SR_LINK_STATUS)
5715 break;
5716 mdelay(100);
5717 }
5718 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005719}
5720
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005721/**
5722 * e1000_get_auto_rd_done
5723 * @hw: Struct containing variables accessed by shared code
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005724 *
5725 * Check for EEPROM Auto Read bit done.
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005726 * returns: - E1000_ERR_RESET if fail to reset MAC
5727 * E1000_SUCCESS at any other case.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005728 */
Joe Perches64798842008-07-11 15:17:02 -07005729static s32 e1000_get_auto_rd_done(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005730{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005731 DEBUGFUNC("e1000_get_auto_rd_done");
5732 msleep(5);
5733 return E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005734}
5735
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005736/**
5737 * e1000_get_phy_cfg_done
5738 * @hw: Struct containing variables accessed by shared code
5739 *
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005740 * Checks if the PHY configuration is done
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005741 * returns: - E1000_ERR_RESET if fail to reset MAC
5742 * E1000_SUCCESS at any other case.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005743 */
Joe Perches64798842008-07-11 15:17:02 -07005744static s32 e1000_get_phy_cfg_done(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005745{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005746 DEBUGFUNC("e1000_get_phy_cfg_done");
5747 mdelay(10);
5748 return E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005749}