blob: 8d7d87f128275e2d7ba1baf8f100933acad6feb3 [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);
Joe Perches64798842008-07-11 15:17:02 -070052static s32 e1000_phy_m88_get_info(struct e1000_hw *hw,
53 struct e1000_phy_info *phy_info);
Joe Perches406874a2008-04-03 10:06:32 -070054static s32 e1000_set_d3_lplu_state(struct e1000_hw *hw, bool active);
Joe Perches406874a2008-04-03 10:06:32 -070055static s32 e1000_wait_autoneg(struct e1000_hw *hw);
56static void e1000_write_reg_io(struct e1000_hw *hw, u32 offset, u32 value);
57static s32 e1000_set_phy_type(struct e1000_hw *hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -070058static void e1000_phy_init_script(struct e1000_hw *hw);
Joe Perches406874a2008-04-03 10:06:32 -070059static s32 e1000_setup_copper_link(struct e1000_hw *hw);
60static s32 e1000_setup_fiber_serdes_link(struct e1000_hw *hw);
61static s32 e1000_adjust_serdes_amplitude(struct e1000_hw *hw);
62static s32 e1000_phy_force_speed_duplex(struct e1000_hw *hw);
63static s32 e1000_config_mac_to_phy(struct e1000_hw *hw);
64static void e1000_raise_mdi_clk(struct e1000_hw *hw, u32 *ctrl);
65static void e1000_lower_mdi_clk(struct e1000_hw *hw, u32 *ctrl);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -070066static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, u32 data, u16 count);
Joe Perches406874a2008-04-03 10:06:32 -070067static u16 e1000_shift_in_mdi_bits(struct e1000_hw *hw);
68static s32 e1000_phy_reset_dsp(struct e1000_hw *hw);
69static s32 e1000_write_eeprom_spi(struct e1000_hw *hw, u16 offset,
Jesse Brandeburg120a5d02009-09-25 15:19:46 -070070 u16 words, u16 *data);
Joe Perches64798842008-07-11 15:17:02 -070071static s32 e1000_write_eeprom_microwire(struct e1000_hw *hw, u16 offset,
72 u16 words, u16 *data);
Joe Perches406874a2008-04-03 10:06:32 -070073static s32 e1000_spi_eeprom_ready(struct e1000_hw *hw);
74static void e1000_raise_ee_clk(struct e1000_hw *hw, u32 *eecd);
75static void e1000_lower_ee_clk(struct e1000_hw *hw, u32 *eecd);
Joe Perches64798842008-07-11 15:17:02 -070076static void e1000_shift_out_ee_bits(struct e1000_hw *hw, u16 data, u16 count);
Joe Perches406874a2008-04-03 10:06:32 -070077static s32 e1000_write_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr,
Joe Perches64798842008-07-11 15:17:02 -070078 u16 phy_data);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -070079static s32 e1000_read_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr,
Joe Perches64798842008-07-11 15:17:02 -070080 u16 *phy_data);
Joe Perches406874a2008-04-03 10:06:32 -070081static u16 e1000_shift_in_ee_bits(struct e1000_hw *hw, u16 count);
82static s32 e1000_acquire_eeprom(struct e1000_hw *hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -070083static void e1000_release_eeprom(struct e1000_hw *hw);
84static void e1000_standby_eeprom(struct e1000_hw *hw);
Joe Perches406874a2008-04-03 10:06:32 -070085static s32 e1000_set_vco_speed(struct e1000_hw *hw);
86static s32 e1000_polarity_reversal_workaround(struct e1000_hw *hw);
87static s32 e1000_set_phy_mode(struct e1000_hw *hw);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -070088static s32 e1000_do_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words,
89 u16 *data);
90static s32 e1000_do_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words,
91 u16 *data);
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
93/* IGP cable length table */
94static const
Jesse Brandeburg120a5d02009-09-25 15:19:46 -070095u16 e1000_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] = {
96 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
97 5, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 25, 25, 25,
98 25, 25, 25, 25, 30, 30, 30, 30, 40, 40, 40, 40, 40, 40, 40, 40,
99 40, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60,
100 60, 70, 70, 70, 70, 70, 70, 80, 80, 80, 80, 80, 80, 90, 90, 90,
101 90, 90, 90, 90, 90, 90, 100, 100, 100, 100, 100, 100, 100, 100, 100,
102 100,
103 100, 100, 100, 100, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,
104 110, 110,
105 110, 110, 110, 110, 110, 110, 120, 120, 120, 120, 120, 120, 120, 120,
106 120, 120
107};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
Christopher Li78566fe2008-09-05 14:04:05 -0700109static DEFINE_SPINLOCK(e1000_eeprom_lock);
110
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700111/**
112 * e1000_set_phy_type - Set the phy type member in the hw struct.
113 * @hw: Struct containing variables accessed by shared code
114 */
Joe Perches64798842008-07-11 15:17:02 -0700115static s32 e1000_set_phy_type(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700117 DEBUGFUNC("e1000_set_phy_type");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700119 if (hw->mac_type == e1000_undefined)
120 return -E1000_ERR_PHY_TYPE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700121
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700122 switch (hw->phy_id) {
123 case M88E1000_E_PHY_ID:
124 case M88E1000_I_PHY_ID:
125 case M88E1011_I_PHY_ID:
126 case M88E1111_I_PHY_ID:
127 hw->phy_type = e1000_phy_m88;
128 break;
129 case IGP01E1000_I_PHY_ID:
130 if (hw->mac_type == e1000_82541 ||
131 hw->mac_type == e1000_82541_rev_2 ||
132 hw->mac_type == e1000_82547 ||
133 hw->mac_type == e1000_82547_rev_2) {
134 hw->phy_type = e1000_phy_igp;
135 break;
136 }
137 default:
138 /* Should never have loaded on this device */
139 hw->phy_type = e1000_phy_undefined;
140 return -E1000_ERR_PHY_TYPE;
141 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700143 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144}
145
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700146/**
147 * e1000_phy_init_script - IGP phy init script - initializes the GbE PHY
148 * @hw: Struct containing variables accessed by shared code
149 */
Joe Perches64798842008-07-11 15:17:02 -0700150static void e1000_phy_init_script(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700152 u32 ret_val;
153 u16 phy_saved_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700155 DEBUGFUNC("e1000_phy_init_script");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700157 if (hw->phy_init_script) {
158 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700160 /* Save off the current value of register 0x2F5B to be restored at
161 * the end of this routine. */
162 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700164 /* Disabled the PHY transmitter */
165 e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
166 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700168 e1000_write_phy_reg(hw, 0x0000, 0x0140);
169 msleep(5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700171 switch (hw->mac_type) {
172 case e1000_82541:
173 case e1000_82547:
174 e1000_write_phy_reg(hw, 0x1F95, 0x0001);
175 e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
176 e1000_write_phy_reg(hw, 0x1F79, 0x0018);
177 e1000_write_phy_reg(hw, 0x1F30, 0x1600);
178 e1000_write_phy_reg(hw, 0x1F31, 0x0014);
179 e1000_write_phy_reg(hw, 0x1F32, 0x161C);
180 e1000_write_phy_reg(hw, 0x1F94, 0x0003);
181 e1000_write_phy_reg(hw, 0x1F96, 0x003F);
182 e1000_write_phy_reg(hw, 0x2010, 0x0008);
183 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700185 case e1000_82541_rev_2:
186 case e1000_82547_rev_2:
187 e1000_write_phy_reg(hw, 0x1F73, 0x0099);
188 break;
189 default:
190 break;
191 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700193 e1000_write_phy_reg(hw, 0x0000, 0x3300);
194 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700196 /* Now enable the transmitter */
197 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700199 if (hw->mac_type == e1000_82547) {
200 u16 fused, fine, coarse;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700202 /* Move to analog registers page */
203 e1000_read_phy_reg(hw,
204 IGP01E1000_ANALOG_SPARE_FUSE_STATUS,
205 &fused);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700207 if (!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
208 e1000_read_phy_reg(hw,
209 IGP01E1000_ANALOG_FUSE_STATUS,
210 &fused);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700212 fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
213 coarse =
214 fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700216 if (coarse >
217 IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
218 coarse -=
219 IGP01E1000_ANALOG_FUSE_COARSE_10;
220 fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
221 } else if (coarse ==
222 IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
223 fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700225 fused =
226 (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
227 (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
228 (coarse &
229 IGP01E1000_ANALOG_FUSE_COARSE_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700231 e1000_write_phy_reg(hw,
232 IGP01E1000_ANALOG_FUSE_CONTROL,
233 fused);
234 e1000_write_phy_reg(hw,
235 IGP01E1000_ANALOG_FUSE_BYPASS,
236 IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
237 }
238 }
239 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240}
241
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700242/**
243 * e1000_set_mac_type - Set the mac type member in the hw struct.
244 * @hw: Struct containing variables accessed by shared code
245 */
Joe Perches64798842008-07-11 15:17:02 -0700246s32 e1000_set_mac_type(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247{
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500248 DEBUGFUNC("e1000_set_mac_type");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500250 switch (hw->device_id) {
251 case E1000_DEV_ID_82542:
252 switch (hw->revision_id) {
253 case E1000_82542_2_0_REV_ID:
254 hw->mac_type = e1000_82542_rev2_0;
255 break;
256 case E1000_82542_2_1_REV_ID:
257 hw->mac_type = e1000_82542_rev2_1;
258 break;
259 default:
260 /* Invalid 82542 revision ID */
261 return -E1000_ERR_MAC_TYPE;
262 }
263 break;
264 case E1000_DEV_ID_82543GC_FIBER:
265 case E1000_DEV_ID_82543GC_COPPER:
266 hw->mac_type = e1000_82543;
267 break;
268 case E1000_DEV_ID_82544EI_COPPER:
269 case E1000_DEV_ID_82544EI_FIBER:
270 case E1000_DEV_ID_82544GC_COPPER:
271 case E1000_DEV_ID_82544GC_LOM:
272 hw->mac_type = e1000_82544;
273 break;
274 case E1000_DEV_ID_82540EM:
275 case E1000_DEV_ID_82540EM_LOM:
276 case E1000_DEV_ID_82540EP:
277 case E1000_DEV_ID_82540EP_LOM:
278 case E1000_DEV_ID_82540EP_LP:
279 hw->mac_type = e1000_82540;
280 break;
281 case E1000_DEV_ID_82545EM_COPPER:
282 case E1000_DEV_ID_82545EM_FIBER:
283 hw->mac_type = e1000_82545;
284 break;
285 case E1000_DEV_ID_82545GM_COPPER:
286 case E1000_DEV_ID_82545GM_FIBER:
287 case E1000_DEV_ID_82545GM_SERDES:
288 hw->mac_type = e1000_82545_rev_3;
289 break;
290 case E1000_DEV_ID_82546EB_COPPER:
291 case E1000_DEV_ID_82546EB_FIBER:
292 case E1000_DEV_ID_82546EB_QUAD_COPPER:
293 hw->mac_type = e1000_82546;
294 break;
295 case E1000_DEV_ID_82546GB_COPPER:
296 case E1000_DEV_ID_82546GB_FIBER:
297 case E1000_DEV_ID_82546GB_SERDES:
298 case E1000_DEV_ID_82546GB_PCIE:
299 case E1000_DEV_ID_82546GB_QUAD_COPPER:
300 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
301 hw->mac_type = e1000_82546_rev_3;
302 break;
303 case E1000_DEV_ID_82541EI:
304 case E1000_DEV_ID_82541EI_MOBILE:
305 case E1000_DEV_ID_82541ER_LOM:
306 hw->mac_type = e1000_82541;
307 break;
308 case E1000_DEV_ID_82541ER:
309 case E1000_DEV_ID_82541GI:
310 case E1000_DEV_ID_82541GI_LF:
311 case E1000_DEV_ID_82541GI_MOBILE:
312 hw->mac_type = e1000_82541_rev_2;
313 break;
314 case E1000_DEV_ID_82547EI:
315 case E1000_DEV_ID_82547EI_MOBILE:
316 hw->mac_type = e1000_82547;
317 break;
318 case E1000_DEV_ID_82547GI:
319 hw->mac_type = e1000_82547_rev_2;
320 break;
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500321 default:
322 /* Should never have loaded on this device */
323 return -E1000_ERR_MAC_TYPE;
324 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500326 switch (hw->mac_type) {
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500327 case e1000_82541:
328 case e1000_82547:
329 case e1000_82541_rev_2:
330 case e1000_82547_rev_2:
Joe Perchesc3033b02008-03-21 11:06:25 -0700331 hw->asf_firmware_present = true;
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500332 break;
333 default:
334 break;
335 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336
Jeff Garzik167fb282006-12-15 10:41:15 -0500337 /* The 82543 chip does not count tx_carrier_errors properly in
338 * FD mode
339 */
340 if (hw->mac_type == e1000_82543)
Joe Perchesc3033b02008-03-21 11:06:25 -0700341 hw->bad_tx_carr_stats_fd = true;
Jeff Garzik167fb282006-12-15 10:41:15 -0500342
Jeff Garzik15e376b2006-12-15 11:16:33 -0500343 if (hw->mac_type > e1000_82544)
Joe Perchesc3033b02008-03-21 11:06:25 -0700344 hw->has_smbus = true;
Jeff Garzik15e376b2006-12-15 11:16:33 -0500345
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500346 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347}
348
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700349/**
350 * e1000_set_media_type - Set media type and TBI compatibility.
351 * @hw: Struct containing variables accessed by shared code
352 */
Joe Perches64798842008-07-11 15:17:02 -0700353void e1000_set_media_type(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700355 u32 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700357 DEBUGFUNC("e1000_set_media_type");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700359 if (hw->mac_type != e1000_82543) {
360 /* tbi_compatibility is only valid on 82543 */
361 hw->tbi_compatibility_en = false;
362 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700364 switch (hw->device_id) {
365 case E1000_DEV_ID_82545GM_SERDES:
366 case E1000_DEV_ID_82546GB_SERDES:
367 hw->media_type = e1000_media_type_internal_serdes;
368 break;
369 default:
370 switch (hw->mac_type) {
371 case e1000_82542_rev2_0:
372 case e1000_82542_rev2_1:
373 hw->media_type = e1000_media_type_fiber;
374 break;
375 default:
376 status = er32(STATUS);
377 if (status & E1000_STATUS_TBIMODE) {
378 hw->media_type = e1000_media_type_fiber;
379 /* tbi_compatibility not valid on fiber */
380 hw->tbi_compatibility_en = false;
381 } else {
382 hw->media_type = e1000_media_type_copper;
383 }
384 break;
385 }
386 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387}
388
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700389/**
390 * e1000_reset_hw: reset the hardware completely
391 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 *
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700393 * Reset the transmit and receive units; mask and clear all interrupts.
394 */
Joe Perches64798842008-07-11 15:17:02 -0700395s32 e1000_reset_hw(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700397 u32 ctrl;
398 u32 ctrl_ext;
399 u32 icr;
400 u32 manc;
401 u32 led_ctrl;
402 s32 ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700404 DEBUGFUNC("e1000_reset_hw");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700406 /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
407 if (hw->mac_type == e1000_82542_rev2_0) {
408 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
409 e1000_pci_clear_mwi(hw);
410 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700412 /* Clear interrupt mask to stop board from generating interrupts */
413 DEBUGOUT("Masking off all interrupts\n");
414 ew32(IMC, 0xffffffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700416 /* Disable the Transmit and Receive units. Then delay to allow
417 * any pending transactions to complete before we hit the MAC with
418 * the global reset.
419 */
420 ew32(RCTL, 0);
421 ew32(TCTL, E1000_TCTL_PSP);
422 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700424 /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
425 hw->tbi_compatibility_on = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700427 /* Delay to allow any outstanding PCI transactions to complete before
428 * resetting the device
429 */
430 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700432 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700434 /* Must reset the PHY before resetting the MAC */
435 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
436 ew32(CTRL, (ctrl | E1000_CTRL_PHY_RST));
437 msleep(5);
438 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700440 /* Issue a global reset to the MAC. This will reset the chip's
441 * transmit, receive, DMA, and link units. It will not effect
442 * the current PCI configuration. The global reset bit is self-
443 * clearing, and should clear within a microsecond.
444 */
445 DEBUGOUT("Issuing a global reset to MAC\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700447 switch (hw->mac_type) {
448 case e1000_82544:
449 case e1000_82540:
450 case e1000_82545:
451 case e1000_82546:
452 case e1000_82541:
453 case e1000_82541_rev_2:
454 /* These controllers can't ack the 64-bit write when issuing the
455 * reset, so use IO-mapping as a workaround to issue the reset */
456 E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
457 break;
458 case e1000_82545_rev_3:
459 case e1000_82546_rev_3:
460 /* Reset is performed on a shadow of the control register */
461 ew32(CTRL_DUP, (ctrl | E1000_CTRL_RST));
462 break;
463 default:
464 ew32(CTRL, (ctrl | E1000_CTRL_RST));
465 break;
466 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700468 /* After MAC reset, force reload of EEPROM to restore power-on settings to
469 * device. Later controllers reload the EEPROM automatically, so just wait
470 * for reload to complete.
471 */
472 switch (hw->mac_type) {
473 case e1000_82542_rev2_0:
474 case e1000_82542_rev2_1:
475 case e1000_82543:
476 case e1000_82544:
477 /* Wait for reset to complete */
478 udelay(10);
479 ctrl_ext = er32(CTRL_EXT);
480 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
481 ew32(CTRL_EXT, ctrl_ext);
482 E1000_WRITE_FLUSH();
483 /* Wait for EEPROM reload */
484 msleep(2);
485 break;
486 case e1000_82541:
487 case e1000_82541_rev_2:
488 case e1000_82547:
489 case e1000_82547_rev_2:
490 /* Wait for EEPROM reload */
491 msleep(20);
492 break;
493 default:
494 /* Auto read done will delay 5ms or poll based on mac type */
495 ret_val = e1000_get_auto_rd_done(hw);
496 if (ret_val)
497 return ret_val;
498 break;
499 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700501 /* Disable HW ARPs on ASF enabled adapters */
502 if (hw->mac_type >= e1000_82540) {
503 manc = er32(MANC);
504 manc &= ~(E1000_MANC_ARP_EN);
505 ew32(MANC, manc);
506 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700508 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
509 e1000_phy_init_script(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700511 /* Configure activity LED after PHY reset */
512 led_ctrl = er32(LEDCTL);
513 led_ctrl &= IGP_ACTIVITY_LED_MASK;
514 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
515 ew32(LEDCTL, led_ctrl);
516 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700518 /* Clear interrupt mask to stop board from generating interrupts */
519 DEBUGOUT("Masking off all interrupts\n");
520 ew32(IMC, 0xffffffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700522 /* Clear any pending interrupt events. */
523 icr = er32(ICR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700525 /* If MWI was previously enabled, reenable it. */
526 if (hw->mac_type == e1000_82542_rev2_0) {
527 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
528 e1000_pci_set_mwi(hw);
529 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700531 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532}
533
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700534/**
535 * e1000_init_hw: Performs basic configuration of the adapter.
536 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 *
538 * Assumes that the controller has previously been reset and is in a
539 * post-reset uninitialized state. Initializes the receive address registers,
540 * multicast table, and VLAN filter table. Calls routines to setup link
541 * configuration and flow control settings. Clears all on-chip counters. Leaves
542 * the transmit and receive units disabled and uninitialized.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700543 */
Joe Perches64798842008-07-11 15:17:02 -0700544s32 e1000_init_hw(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700546 u32 ctrl;
547 u32 i;
548 s32 ret_val;
549 u32 mta_size;
550 u32 ctrl_ext;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700551
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700552 DEBUGFUNC("e1000_init_hw");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700554 /* Initialize Identification LED */
555 ret_val = e1000_id_led_init(hw);
556 if (ret_val) {
557 DEBUGOUT("Error Initializing Identification LED\n");
558 return ret_val;
559 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700561 /* Set the media type and TBI compatibility */
562 e1000_set_media_type(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700564 /* Disabling VLAN filtering. */
565 DEBUGOUT("Initializing the IEEE VLAN\n");
566 if (hw->mac_type < e1000_82545_rev_3)
567 ew32(VET, 0);
568 e1000_clear_vfta(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700570 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
571 if (hw->mac_type == e1000_82542_rev2_0) {
572 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
573 e1000_pci_clear_mwi(hw);
574 ew32(RCTL, E1000_RCTL_RST);
575 E1000_WRITE_FLUSH();
576 msleep(5);
577 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700579 /* Setup the receive address. This involves initializing all of the Receive
580 * Address Registers (RARs 0 - 15).
581 */
582 e1000_init_rx_addrs(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700584 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
585 if (hw->mac_type == e1000_82542_rev2_0) {
586 ew32(RCTL, 0);
587 E1000_WRITE_FLUSH();
588 msleep(1);
589 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
590 e1000_pci_set_mwi(hw);
591 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700593 /* Zero out the Multicast HASH table */
594 DEBUGOUT("Zeroing the MTA\n");
595 mta_size = E1000_MC_TBL_SIZE;
596 for (i = 0; i < mta_size; i++) {
597 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
598 /* use write flush to prevent Memory Write Block (MWB) from
599 * occurring when accessing our register space */
600 E1000_WRITE_FLUSH();
601 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700603 /* Set the PCI priority bit correctly in the CTRL register. This
604 * determines if the adapter gives priority to receives, or if it
605 * gives equal priority to transmits and receives. Valid only on
606 * 82542 and 82543 silicon.
607 */
608 if (hw->dma_fairness && hw->mac_type <= e1000_82543) {
609 ctrl = er32(CTRL);
610 ew32(CTRL, ctrl | E1000_CTRL_PRIOR);
611 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700613 switch (hw->mac_type) {
614 case e1000_82545_rev_3:
615 case e1000_82546_rev_3:
616 break;
617 default:
618 /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
619 if (hw->bus_type == e1000_bus_type_pcix
620 && e1000_pcix_get_mmrbc(hw) > 2048)
621 e1000_pcix_set_mmrbc(hw, 2048);
622 break;
623 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700625 /* Call a subroutine to configure the link and setup flow control. */
626 ret_val = e1000_setup_link(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700628 /* Set the transmit descriptor write-back policy */
629 if (hw->mac_type > e1000_82544) {
630 ctrl = er32(TXDCTL);
631 ctrl =
632 (ctrl & ~E1000_TXDCTL_WTHRESH) |
633 E1000_TXDCTL_FULL_TX_DESC_WB;
634 ew32(TXDCTL, ctrl);
635 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700637 /* Clear all of the statistics registers (clear on read). It is
638 * important that we do this after we have tried to establish link
639 * because the symbol error count will increment wildly if there
640 * is no link.
641 */
642 e1000_clear_hw_cntrs(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700644 if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER ||
645 hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) {
646 ctrl_ext = er32(CTRL_EXT);
647 /* Relaxed ordering must be disabled to avoid a parity
648 * error crash in a PCI slot. */
649 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
650 ew32(CTRL_EXT, ctrl_ext);
651 }
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -0800652
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700653 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654}
655
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700656/**
657 * e1000_adjust_serdes_amplitude - Adjust SERDES output amplitude based on EEPROM setting.
658 * @hw: Struct containing variables accessed by shared code.
659 */
Joe Perches64798842008-07-11 15:17:02 -0700660static s32 e1000_adjust_serdes_amplitude(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700662 u16 eeprom_data;
663 s32 ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700665 DEBUGFUNC("e1000_adjust_serdes_amplitude");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700667 if (hw->media_type != e1000_media_type_internal_serdes)
668 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700670 switch (hw->mac_type) {
671 case e1000_82545_rev_3:
672 case e1000_82546_rev_3:
673 break;
674 default:
675 return E1000_SUCCESS;
676 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700678 ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1,
679 &eeprom_data);
680 if (ret_val) {
681 return ret_val;
682 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700684 if (eeprom_data != EEPROM_RESERVED_WORD) {
685 /* Adjust SERDES output amplitude only. */
686 eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK;
687 ret_val =
688 e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data);
689 if (ret_val)
690 return ret_val;
691 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700693 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694}
695
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700696/**
697 * e1000_setup_link - Configures flow control and link settings.
698 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 *
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700700 * Determines which flow control settings to use. Calls the appropriate media-
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 * specific link configuration function. Configures the flow control settings.
702 * Assuming the adapter has a valid link partner, a valid link should be
703 * established. Assumes the hardware has previously been reset and the
704 * transmitter and receiver are not enabled.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700705 */
Joe Perches64798842008-07-11 15:17:02 -0700706s32 e1000_setup_link(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700708 u32 ctrl_ext;
709 s32 ret_val;
710 u16 eeprom_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700712 DEBUGFUNC("e1000_setup_link");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700714 /* Read and store word 0x0F of the EEPROM. This word contains bits
715 * that determine the hardware's default PAUSE (flow control) mode,
716 * a bit that determines whether the HW defaults to enabling or
717 * disabling auto-negotiation, and the direction of the
718 * SW defined pins. If there is no SW over-ride of the flow
719 * control setting, then the variable hw->fc will
720 * be initialized based on a value in the EEPROM.
721 */
722 if (hw->fc == E1000_FC_DEFAULT) {
723 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
724 1, &eeprom_data);
725 if (ret_val) {
726 DEBUGOUT("EEPROM Read Error\n");
727 return -E1000_ERR_EEPROM;
728 }
729 if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
730 hw->fc = E1000_FC_NONE;
731 else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
732 EEPROM_WORD0F_ASM_DIR)
733 hw->fc = E1000_FC_TX_PAUSE;
734 else
735 hw->fc = E1000_FC_FULL;
736 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700738 /* We want to save off the original Flow Control configuration just
739 * in case we get disconnected and then reconnected into a different
740 * hub or switch with different Flow Control capabilities.
741 */
742 if (hw->mac_type == e1000_82542_rev2_0)
743 hw->fc &= (~E1000_FC_TX_PAUSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700745 if ((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
746 hw->fc &= (~E1000_FC_RX_PAUSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700748 hw->original_fc = hw->fc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700750 DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700752 /* Take the 4 bits from EEPROM word 0x0F that determine the initial
753 * polarity value for the SW controlled pins, and setup the
754 * Extended Device Control reg with that info.
755 * This is needed because one of the SW controlled pins is used for
756 * signal detection. So this should be done before e1000_setup_pcs_link()
757 * or e1000_phy_setup() is called.
758 */
759 if (hw->mac_type == e1000_82543) {
760 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
761 1, &eeprom_data);
762 if (ret_val) {
763 DEBUGOUT("EEPROM Read Error\n");
764 return -E1000_ERR_EEPROM;
765 }
766 ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
767 SWDPIO__EXT_SHIFT);
768 ew32(CTRL_EXT, ctrl_ext);
769 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700771 /* Call the necessary subroutine to configure the link. */
772 ret_val = (hw->media_type == e1000_media_type_copper) ?
773 e1000_setup_copper_link(hw) : e1000_setup_fiber_serdes_link(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700775 /* Initialize the flow control address, type, and PAUSE timer
776 * registers to their default values. This is done even if flow
777 * control is disabled, because it does not hurt anything to
778 * initialize these registers.
779 */
780 DEBUGOUT
781 ("Initializing the Flow Control address, type and timer regs\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700783 ew32(FCT, FLOW_CONTROL_TYPE);
784 ew32(FCAH, FLOW_CONTROL_ADDRESS_HIGH);
785 ew32(FCAL, FLOW_CONTROL_ADDRESS_LOW);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700786
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700787 ew32(FCTTV, hw->fc_pause_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700789 /* Set the flow control receive threshold registers. Normally,
790 * these registers will be set to a default threshold that may be
791 * adjusted later by the driver's runtime code. However, if the
792 * ability to transmit pause frames in not enabled, then these
793 * registers will be set to 0.
794 */
795 if (!(hw->fc & E1000_FC_TX_PAUSE)) {
796 ew32(FCRTL, 0);
797 ew32(FCRTH, 0);
798 } else {
799 /* We need to set up the Receive Threshold high and low water marks
800 * as well as (optionally) enabling the transmission of XON frames.
801 */
802 if (hw->fc_send_xon) {
803 ew32(FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE));
804 ew32(FCRTH, hw->fc_high_water);
805 } else {
806 ew32(FCRTL, hw->fc_low_water);
807 ew32(FCRTH, hw->fc_high_water);
808 }
809 }
810 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811}
812
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700813/**
814 * e1000_setup_fiber_serdes_link - prepare fiber or serdes link
815 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 *
817 * Manipulates Physical Coding Sublayer functions in order to configure
818 * link. Assumes the hardware has been previously reset and the transmitter
819 * and receiver are not enabled.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700820 */
Joe Perches64798842008-07-11 15:17:02 -0700821static s32 e1000_setup_fiber_serdes_link(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700823 u32 ctrl;
824 u32 status;
825 u32 txcw = 0;
826 u32 i;
827 u32 signal = 0;
828 s32 ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700830 DEBUGFUNC("e1000_setup_fiber_serdes_link");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700832 /* On adapters with a MAC newer than 82544, SWDP 1 will be
833 * set when the optics detect a signal. On older adapters, it will be
834 * cleared when there is a signal. This applies to fiber media only.
835 * If we're on serdes media, adjust the output amplitude to value
836 * set in the EEPROM.
837 */
838 ctrl = er32(CTRL);
839 if (hw->media_type == e1000_media_type_fiber)
840 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700842 ret_val = e1000_adjust_serdes_amplitude(hw);
843 if (ret_val)
844 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700846 /* Take the link out of reset */
847 ctrl &= ~(E1000_CTRL_LRST);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700849 /* Adjust VCO speed to improve BER performance */
850 ret_val = e1000_set_vco_speed(hw);
851 if (ret_val)
852 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700854 e1000_config_collision_dist(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700856 /* Check for a software override of the flow control settings, and setup
857 * the device accordingly. If auto-negotiation is enabled, then software
858 * will have to set the "PAUSE" bits to the correct value in the Tranmsit
859 * Config Word Register (TXCW) and re-start auto-negotiation. However, if
860 * auto-negotiation is disabled, then software will have to manually
861 * configure the two flow control enable bits in the CTRL register.
862 *
863 * The possible values of the "fc" parameter are:
864 * 0: Flow control is completely disabled
865 * 1: Rx flow control is enabled (we can receive pause frames, but
866 * not send pause frames).
867 * 2: Tx flow control is enabled (we can send pause frames but we do
868 * not support receiving pause frames).
869 * 3: Both Rx and TX flow control (symmetric) are enabled.
870 */
871 switch (hw->fc) {
872 case E1000_FC_NONE:
873 /* Flow control is completely disabled by a software over-ride. */
874 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
875 break;
876 case E1000_FC_RX_PAUSE:
877 /* RX Flow control is enabled and TX Flow control is disabled by a
878 * software over-ride. Since there really isn't a way to advertise
879 * that we are capable of RX Pause ONLY, we will advertise that we
880 * support both symmetric and asymmetric RX PAUSE. Later, we will
881 * disable the adapter's ability to send PAUSE frames.
882 */
883 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
884 break;
885 case E1000_FC_TX_PAUSE:
886 /* TX Flow control is enabled, and RX Flow control is disabled, by a
887 * software over-ride.
888 */
889 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
890 break;
891 case E1000_FC_FULL:
892 /* Flow control (both RX and TX) is enabled by a software over-ride. */
893 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
894 break;
895 default:
896 DEBUGOUT("Flow control param set incorrectly\n");
897 return -E1000_ERR_CONFIG;
898 break;
899 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700901 /* Since auto-negotiation is enabled, take the link out of reset (the link
902 * will be in reset, because we previously reset the chip). This will
903 * restart auto-negotiation. If auto-negotiation is successful then the
904 * link-up status bit will be set and the flow control enable bits (RFCE
905 * and TFCE) will be set according to their negotiated value.
906 */
907 DEBUGOUT("Auto-negotiation enabled\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700909 ew32(TXCW, txcw);
910 ew32(CTRL, ctrl);
911 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700913 hw->txcw = txcw;
914 msleep(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700916 /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
917 * indication in the Device Status Register. Time-out if a link isn't
918 * seen in 500 milliseconds seconds (Auto-negotiation should complete in
919 * less than 500 milliseconds even if the other end is doing it in SW).
920 * For internal serdes, we just assume a signal is present, then poll.
921 */
922 if (hw->media_type == e1000_media_type_internal_serdes ||
923 (er32(CTRL) & E1000_CTRL_SWDPIN1) == signal) {
924 DEBUGOUT("Looking for Link\n");
925 for (i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
926 msleep(10);
927 status = er32(STATUS);
928 if (status & E1000_STATUS_LU)
929 break;
930 }
931 if (i == (LINK_UP_TIMEOUT / 10)) {
932 DEBUGOUT("Never got a valid link from auto-neg!!!\n");
933 hw->autoneg_failed = 1;
934 /* AutoNeg failed to achieve a link, so we'll call
935 * e1000_check_for_link. This routine will force the link up if
936 * we detect a signal. This will allow us to communicate with
937 * non-autonegotiating link partners.
938 */
939 ret_val = e1000_check_for_link(hw);
940 if (ret_val) {
941 DEBUGOUT("Error while checking for link\n");
942 return ret_val;
943 }
944 hw->autoneg_failed = 0;
945 } else {
946 hw->autoneg_failed = 0;
947 DEBUGOUT("Valid Link Found\n");
948 }
949 } else {
950 DEBUGOUT("No Signal Detected\n");
951 }
952 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953}
954
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700955/**
956 * e1000_copper_link_preconfig - early configuration for copper
957 * @hw: Struct containing variables accessed by shared code
958 *
959 * Make sure we have a valid PHY and change PHY mode before link setup.
960 */
Joe Perches64798842008-07-11 15:17:02 -0700961static s32 e1000_copper_link_preconfig(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700963 u32 ctrl;
964 s32 ret_val;
965 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700967 DEBUGFUNC("e1000_copper_link_preconfig");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700969 ctrl = er32(CTRL);
970 /* With 82543, we need to force speed and duplex on the MAC equal to what
971 * the PHY speed and duplex configuration is. In addition, we need to
972 * perform a hardware reset on the PHY to take it out of reset.
973 */
974 if (hw->mac_type > e1000_82543) {
975 ctrl |= E1000_CTRL_SLU;
976 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
977 ew32(CTRL, ctrl);
978 } else {
979 ctrl |=
980 (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
981 ew32(CTRL, ctrl);
982 ret_val = e1000_phy_hw_reset(hw);
983 if (ret_val)
984 return ret_val;
985 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700987 /* Make sure we have a valid PHY */
988 ret_val = e1000_detect_gig_phy(hw);
989 if (ret_val) {
990 DEBUGOUT("Error, did not detect valid phy.\n");
991 return ret_val;
992 }
993 DEBUGOUT1("Phy ID = %x \n", hw->phy_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700995 /* Set PHY to class A mode (if necessary) */
996 ret_val = e1000_set_phy_mode(hw);
997 if (ret_val)
998 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001000 if ((hw->mac_type == e1000_82545_rev_3) ||
1001 (hw->mac_type == e1000_82546_rev_3)) {
1002 ret_val =
1003 e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1004 phy_data |= 0x00000008;
1005 ret_val =
1006 e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1007 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001009 if (hw->mac_type <= e1000_82543 ||
1010 hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
1011 hw->mac_type == e1000_82541_rev_2
1012 || hw->mac_type == e1000_82547_rev_2)
1013 hw->phy_reset_disable = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001015 return E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001016}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001018/**
1019 * e1000_copper_link_igp_setup - Copper link setup for e1000_phy_igp series.
1020 * @hw: Struct containing variables accessed by shared code
1021 */
Joe Perches64798842008-07-11 15:17:02 -07001022static s32 e1000_copper_link_igp_setup(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001023{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001024 u32 led_ctrl;
1025 s32 ret_val;
1026 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001028 DEBUGFUNC("e1000_copper_link_igp_setup");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001030 if (hw->phy_reset_disable)
1031 return E1000_SUCCESS;
Auke Kok76c224b2006-05-23 13:36:06 -07001032
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001033 ret_val = e1000_phy_reset(hw);
1034 if (ret_val) {
1035 DEBUGOUT("Error Resetting the PHY\n");
1036 return ret_val;
1037 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001039 /* Wait 15ms for MAC to configure PHY from eeprom settings */
1040 msleep(15);
1041 /* Configure activity LED after PHY reset */
1042 led_ctrl = er32(LEDCTL);
1043 led_ctrl &= IGP_ACTIVITY_LED_MASK;
1044 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
1045 ew32(LEDCTL, led_ctrl);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001046
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001047 /* The NVM settings will configure LPLU in D3 for IGP2 and IGP3 PHYs */
1048 if (hw->phy_type == e1000_phy_igp) {
1049 /* disable lplu d3 during driver init */
1050 ret_val = e1000_set_d3_lplu_state(hw, false);
1051 if (ret_val) {
1052 DEBUGOUT("Error Disabling LPLU D3\n");
1053 return ret_val;
1054 }
1055 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001056
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001057 /* Configure mdi-mdix settings */
1058 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1059 if (ret_val)
1060 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001061
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001062 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
1063 hw->dsp_config_state = e1000_dsp_config_disabled;
1064 /* Force MDI for earlier revs of the IGP PHY */
1065 phy_data &=
1066 ~(IGP01E1000_PSCR_AUTO_MDIX |
1067 IGP01E1000_PSCR_FORCE_MDI_MDIX);
1068 hw->mdix = 1;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001069
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001070 } else {
1071 hw->dsp_config_state = e1000_dsp_config_enabled;
1072 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001073
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001074 switch (hw->mdix) {
1075 case 1:
1076 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1077 break;
1078 case 2:
1079 phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
1080 break;
1081 case 0:
1082 default:
1083 phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
1084 break;
1085 }
1086 }
1087 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1088 if (ret_val)
1089 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001090
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001091 /* set auto-master slave resolution settings */
1092 if (hw->autoneg) {
1093 e1000_ms_type phy_ms_setting = hw->master_slave;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001094
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001095 if (hw->ffe_config_state == e1000_ffe_config_active)
1096 hw->ffe_config_state = e1000_ffe_config_enabled;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001097
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001098 if (hw->dsp_config_state == e1000_dsp_config_activated)
1099 hw->dsp_config_state = e1000_dsp_config_enabled;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001100
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001101 /* when autonegotiation advertisement is only 1000Mbps then we
1102 * should disable SmartSpeed and enable Auto MasterSlave
1103 * resolution as hardware default. */
1104 if (hw->autoneg_advertised == ADVERTISE_1000_FULL) {
1105 /* Disable SmartSpeed */
1106 ret_val =
1107 e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1108 &phy_data);
1109 if (ret_val)
1110 return ret_val;
1111 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1112 ret_val =
1113 e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1114 phy_data);
1115 if (ret_val)
1116 return ret_val;
1117 /* Set auto Master/Slave resolution process */
1118 ret_val =
1119 e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1120 if (ret_val)
1121 return ret_val;
1122 phy_data &= ~CR_1000T_MS_ENABLE;
1123 ret_val =
1124 e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1125 if (ret_val)
1126 return ret_val;
1127 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001129 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1130 if (ret_val)
1131 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001133 /* load defaults for future use */
1134 hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
1135 ((phy_data & CR_1000T_MS_VALUE) ?
1136 e1000_ms_force_master :
1137 e1000_ms_force_slave) : e1000_ms_auto;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001139 switch (phy_ms_setting) {
1140 case e1000_ms_force_master:
1141 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
1142 break;
1143 case e1000_ms_force_slave:
1144 phy_data |= CR_1000T_MS_ENABLE;
1145 phy_data &= ~(CR_1000T_MS_VALUE);
1146 break;
1147 case e1000_ms_auto:
1148 phy_data &= ~CR_1000T_MS_ENABLE;
1149 default:
1150 break;
1151 }
1152 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1153 if (ret_val)
1154 return ret_val;
1155 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001157 return E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001158}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001160/**
1161 * e1000_copper_link_mgp_setup - Copper link setup for e1000_phy_m88 series.
1162 * @hw: Struct containing variables accessed by shared code
1163 */
Joe Perches64798842008-07-11 15:17:02 -07001164static s32 e1000_copper_link_mgp_setup(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001165{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001166 s32 ret_val;
1167 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001169 DEBUGFUNC("e1000_copper_link_mgp_setup");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001170
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001171 if (hw->phy_reset_disable)
1172 return E1000_SUCCESS;
Auke Kok76c224b2006-05-23 13:36:06 -07001173
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001174 /* Enable CRS on TX. This must be set for half-duplex operation. */
1175 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1176 if (ret_val)
1177 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001178
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001179 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001180
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001181 /* Options:
1182 * MDI/MDI-X = 0 (default)
1183 * 0 - Auto for all speeds
1184 * 1 - MDI mode
1185 * 2 - MDI-X mode
1186 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1187 */
1188 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001189
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001190 switch (hw->mdix) {
1191 case 1:
1192 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
1193 break;
1194 case 2:
1195 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
1196 break;
1197 case 3:
1198 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
1199 break;
1200 case 0:
1201 default:
1202 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
1203 break;
1204 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001205
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001206 /* Options:
1207 * disable_polarity_correction = 0 (default)
1208 * Automatic Correction for Reversed Cable Polarity
1209 * 0 - Disabled
1210 * 1 - Enabled
1211 */
1212 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
1213 if (hw->disable_polarity_correction == 1)
1214 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
1215 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1216 if (ret_val)
1217 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001218
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001219 if (hw->phy_revision < M88E1011_I_REV_4) {
1220 /* Force TX_CLK in the Extended PHY Specific Control Register
1221 * to 25MHz clock.
1222 */
1223 ret_val =
1224 e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
1225 &phy_data);
1226 if (ret_val)
1227 return ret_val;
Auke Kokee040222006-06-27 09:08:03 -07001228
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001229 phy_data |= M88E1000_EPSCR_TX_CLK_25;
Auke Kokee040222006-06-27 09:08:03 -07001230
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001231 if ((hw->phy_revision == E1000_REVISION_2) &&
1232 (hw->phy_id == M88E1111_I_PHY_ID)) {
1233 /* Vidalia Phy, set the downshift counter to 5x */
1234 phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK);
1235 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
1236 ret_val = e1000_write_phy_reg(hw,
1237 M88E1000_EXT_PHY_SPEC_CTRL,
1238 phy_data);
1239 if (ret_val)
1240 return ret_val;
1241 } else {
1242 /* Configure Master and Slave downshift values */
1243 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
1244 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
1245 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
1246 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
1247 ret_val = e1000_write_phy_reg(hw,
1248 M88E1000_EXT_PHY_SPEC_CTRL,
1249 phy_data);
1250 if (ret_val)
1251 return ret_val;
1252 }
1253 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001255 /* SW Reset the PHY so all changes take effect */
1256 ret_val = e1000_phy_reset(hw);
1257 if (ret_val) {
1258 DEBUGOUT("Error Resetting the PHY\n");
1259 return ret_val;
1260 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001261
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001262 return E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001263}
1264
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001265/**
1266 * e1000_copper_link_autoneg - setup auto-neg
1267 * @hw: Struct containing variables accessed by shared code
1268 *
1269 * Setup auto-negotiation and flow control advertisements,
1270 * and then perform auto-negotiation.
1271 */
Joe Perches64798842008-07-11 15:17:02 -07001272static s32 e1000_copper_link_autoneg(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001273{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001274 s32 ret_val;
1275 u16 phy_data;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001276
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001277 DEBUGFUNC("e1000_copper_link_autoneg");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001278
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001279 /* Perform some bounds checking on the hw->autoneg_advertised
1280 * parameter. If this variable is zero, then set it to the default.
1281 */
1282 hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001283
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001284 /* If autoneg_advertised is zero, we assume it was not defaulted
1285 * by the calling code so we set to advertise full capability.
1286 */
1287 if (hw->autoneg_advertised == 0)
1288 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001289
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001290 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
1291 ret_val = e1000_phy_setup_autoneg(hw);
1292 if (ret_val) {
1293 DEBUGOUT("Error Setting up Auto-Negotiation\n");
1294 return ret_val;
1295 }
1296 DEBUGOUT("Restarting Auto-Neg\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001297
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001298 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
1299 * the Auto Neg Restart bit in the PHY control register.
1300 */
1301 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
1302 if (ret_val)
1303 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001304
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001305 phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
1306 ret_val = e1000_write_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 /* Does the user want to wait for Auto-Neg to complete here, or
1311 * check at a later time (for example, callback routine).
1312 */
1313 if (hw->wait_autoneg_complete) {
1314 ret_val = e1000_wait_autoneg(hw);
1315 if (ret_val) {
1316 DEBUGOUT
1317 ("Error while waiting for autoneg to complete\n");
1318 return ret_val;
1319 }
1320 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001322 hw->get_link_status = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001324 return E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001325}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001327/**
1328 * e1000_copper_link_postconfig - post link setup
1329 * @hw: Struct containing variables accessed by shared code
1330 *
1331 * Config the MAC and the PHY after link is up.
1332 * 1) Set up the MAC to the current PHY speed/duplex
1333 * if we are on 82543. If we
1334 * are on newer silicon, we only need to configure
1335 * collision distance in the Transmit Control Register.
1336 * 2) Set up flow control on the MAC to that established with
1337 * the link partner.
1338 * 3) Config DSP to improve Gigabit link quality for some PHY revisions.
1339 */
Joe Perches64798842008-07-11 15:17:02 -07001340static s32 e1000_copper_link_postconfig(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001341{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001342 s32 ret_val;
1343 DEBUGFUNC("e1000_copper_link_postconfig");
Auke Kok76c224b2006-05-23 13:36:06 -07001344
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001345 if (hw->mac_type >= e1000_82544) {
1346 e1000_config_collision_dist(hw);
1347 } else {
1348 ret_val = e1000_config_mac_to_phy(hw);
1349 if (ret_val) {
1350 DEBUGOUT("Error configuring MAC to PHY settings\n");
1351 return ret_val;
1352 }
1353 }
1354 ret_val = e1000_config_fc_after_link_up(hw);
1355 if (ret_val) {
1356 DEBUGOUT("Error Configuring Flow Control\n");
1357 return ret_val;
1358 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001359
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001360 /* Config DSP to improve Giga link quality */
1361 if (hw->phy_type == e1000_phy_igp) {
1362 ret_val = e1000_config_dsp_after_link_change(hw, true);
1363 if (ret_val) {
1364 DEBUGOUT("Error Configuring DSP after link up\n");
1365 return ret_val;
1366 }
1367 }
Auke Kok76c224b2006-05-23 13:36:06 -07001368
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001369 return E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001370}
1371
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001372/**
1373 * e1000_setup_copper_link - phy/speed/duplex setting
1374 * @hw: Struct containing variables accessed by shared code
1375 *
1376 * Detects which PHY is present and sets up the speed and duplex
1377 */
Joe Perches64798842008-07-11 15:17:02 -07001378static s32 e1000_setup_copper_link(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001379{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001380 s32 ret_val;
1381 u16 i;
1382 u16 phy_data;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001383
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001384 DEBUGFUNC("e1000_setup_copper_link");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001385
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001386 /* Check if it is a valid PHY and set PHY mode if necessary. */
1387 ret_val = e1000_copper_link_preconfig(hw);
1388 if (ret_val)
1389 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001390
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001391 if (hw->phy_type == e1000_phy_igp) {
1392 ret_val = e1000_copper_link_igp_setup(hw);
1393 if (ret_val)
1394 return ret_val;
1395 } else if (hw->phy_type == e1000_phy_m88) {
1396 ret_val = e1000_copper_link_mgp_setup(hw);
1397 if (ret_val)
1398 return ret_val;
1399 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001400
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001401 if (hw->autoneg) {
1402 /* Setup autoneg and flow control advertisement
1403 * and perform autonegotiation */
1404 ret_val = e1000_copper_link_autoneg(hw);
1405 if (ret_val)
1406 return ret_val;
1407 } else {
1408 /* PHY will be set to 10H, 10F, 100H,or 100F
1409 * depending on value from forced_speed_duplex. */
1410 DEBUGOUT("Forcing speed and duplex\n");
1411 ret_val = e1000_phy_force_speed_duplex(hw);
1412 if (ret_val) {
1413 DEBUGOUT("Error Forcing Speed and Duplex\n");
1414 return ret_val;
1415 }
1416 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001418 /* Check link status. Wait up to 100 microseconds for link to become
1419 * valid.
1420 */
1421 for (i = 0; i < 10; i++) {
1422 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
1423 if (ret_val)
1424 return ret_val;
1425 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
1426 if (ret_val)
1427 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001429 if (phy_data & MII_SR_LINK_STATUS) {
1430 /* Config the MAC and PHY after link is up */
1431 ret_val = e1000_copper_link_postconfig(hw);
1432 if (ret_val)
1433 return ret_val;
Auke Kok76c224b2006-05-23 13:36:06 -07001434
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001435 DEBUGOUT("Valid link established!!!\n");
1436 return E1000_SUCCESS;
1437 }
1438 udelay(10);
1439 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001441 DEBUGOUT("Unable to establish link!!!\n");
1442 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443}
1444
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001445/**
1446 * e1000_phy_setup_autoneg - phy settings
1447 * @hw: Struct containing variables accessed by shared code
1448 *
1449 * Configures PHY autoneg and flow control advertisement settings
1450 */
Joe Perches64798842008-07-11 15:17:02 -07001451s32 e1000_phy_setup_autoneg(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001453 s32 ret_val;
1454 u16 mii_autoneg_adv_reg;
1455 u16 mii_1000t_ctrl_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001457 DEBUGFUNC("e1000_phy_setup_autoneg");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001459 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
1460 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
1461 if (ret_val)
1462 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001464 /* Read the MII 1000Base-T Control Register (Address 9). */
1465 ret_val =
1466 e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
1467 if (ret_val)
1468 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001470 /* Need to parse both autoneg_advertised and fc and set up
1471 * the appropriate PHY registers. First we will parse for
1472 * autoneg_advertised software override. Since we can advertise
1473 * a plethora of combinations, we need to check each bit
1474 * individually.
1475 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001477 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
1478 * Advertisement Register (Address 4) and the 1000 mb speed bits in
1479 * the 1000Base-T Control Register (Address 9).
1480 */
1481 mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
1482 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001484 DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001486 /* Do we want to advertise 10 Mb Half Duplex? */
1487 if (hw->autoneg_advertised & ADVERTISE_10_HALF) {
1488 DEBUGOUT("Advertise 10mb Half duplex\n");
1489 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
1490 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001492 /* Do we want to advertise 10 Mb Full Duplex? */
1493 if (hw->autoneg_advertised & ADVERTISE_10_FULL) {
1494 DEBUGOUT("Advertise 10mb Full duplex\n");
1495 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
1496 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001498 /* Do we want to advertise 100 Mb Half Duplex? */
1499 if (hw->autoneg_advertised & ADVERTISE_100_HALF) {
1500 DEBUGOUT("Advertise 100mb Half duplex\n");
1501 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
1502 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001504 /* Do we want to advertise 100 Mb Full Duplex? */
1505 if (hw->autoneg_advertised & ADVERTISE_100_FULL) {
1506 DEBUGOUT("Advertise 100mb Full duplex\n");
1507 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
1508 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001510 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
1511 if (hw->autoneg_advertised & ADVERTISE_1000_HALF) {
1512 DEBUGOUT
1513 ("Advertise 1000mb Half duplex requested, request denied!\n");
1514 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001516 /* Do we want to advertise 1000 Mb Full Duplex? */
1517 if (hw->autoneg_advertised & ADVERTISE_1000_FULL) {
1518 DEBUGOUT("Advertise 1000mb Full duplex\n");
1519 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
1520 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001522 /* Check for a software override of the flow control settings, and
1523 * setup the PHY advertisement registers accordingly. If
1524 * auto-negotiation is enabled, then software will have to set the
1525 * "PAUSE" bits to the correct value in the Auto-Negotiation
1526 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
1527 *
1528 * The possible values of the "fc" parameter are:
1529 * 0: Flow control is completely disabled
1530 * 1: Rx flow control is enabled (we can receive pause frames
1531 * but not send pause frames).
1532 * 2: Tx flow control is enabled (we can send pause frames
1533 * but we do not support receiving pause frames).
1534 * 3: Both Rx and TX flow control (symmetric) are enabled.
1535 * other: No software override. The flow control configuration
1536 * in the EEPROM is used.
1537 */
1538 switch (hw->fc) {
1539 case E1000_FC_NONE: /* 0 */
1540 /* Flow control (RX & TX) is completely disabled by a
1541 * software over-ride.
1542 */
1543 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1544 break;
1545 case E1000_FC_RX_PAUSE: /* 1 */
1546 /* RX Flow control is enabled, and TX Flow control is
1547 * disabled, by a software over-ride.
1548 */
1549 /* Since there really isn't a way to advertise that we are
1550 * capable of RX Pause ONLY, we will advertise that we
1551 * support both symmetric and asymmetric RX PAUSE. Later
1552 * (in e1000_config_fc_after_link_up) we will disable the
1553 *hw's ability to send PAUSE frames.
1554 */
1555 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1556 break;
1557 case E1000_FC_TX_PAUSE: /* 2 */
1558 /* TX Flow control is enabled, and RX Flow control is
1559 * disabled, by a software over-ride.
1560 */
1561 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
1562 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
1563 break;
1564 case E1000_FC_FULL: /* 3 */
1565 /* Flow control (both RX and TX) is enabled by a software
1566 * over-ride.
1567 */
1568 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1569 break;
1570 default:
1571 DEBUGOUT("Flow control param set incorrectly\n");
1572 return -E1000_ERR_CONFIG;
1573 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001575 ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
1576 if (ret_val)
1577 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001579 DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001581 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg);
1582 if (ret_val)
1583 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001585 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586}
1587
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001588/**
1589 * e1000_phy_force_speed_duplex - force link settings
1590 * @hw: Struct containing variables accessed by shared code
1591 *
1592 * Force PHY speed and duplex settings to hw->forced_speed_duplex
1593 */
Joe Perches64798842008-07-11 15:17:02 -07001594static s32 e1000_phy_force_speed_duplex(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001596 u32 ctrl;
1597 s32 ret_val;
1598 u16 mii_ctrl_reg;
1599 u16 mii_status_reg;
1600 u16 phy_data;
1601 u16 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001603 DEBUGFUNC("e1000_phy_force_speed_duplex");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001605 /* Turn off Flow control if we are forcing speed and duplex. */
1606 hw->fc = E1000_FC_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001608 DEBUGOUT1("hw->fc = %d\n", hw->fc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001610 /* Read the Device Control Register. */
1611 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001613 /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */
1614 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1615 ctrl &= ~(DEVICE_SPEED_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001617 /* Clear the Auto Speed Detect Enable bit. */
1618 ctrl &= ~E1000_CTRL_ASDE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001620 /* Read the MII Control Register. */
1621 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg);
1622 if (ret_val)
1623 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001625 /* We need to disable autoneg in order to force link and duplex. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001627 mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001629 /* Are we forcing Full or Half Duplex? */
1630 if (hw->forced_speed_duplex == e1000_100_full ||
1631 hw->forced_speed_duplex == e1000_10_full) {
1632 /* We want to force full duplex so we SET the full duplex bits in the
1633 * Device and MII Control Registers.
1634 */
1635 ctrl |= E1000_CTRL_FD;
1636 mii_ctrl_reg |= MII_CR_FULL_DUPLEX;
1637 DEBUGOUT("Full Duplex\n");
1638 } else {
1639 /* We want to force half duplex so we CLEAR the full duplex bits in
1640 * the Device and MII Control Registers.
1641 */
1642 ctrl &= ~E1000_CTRL_FD;
1643 mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX;
1644 DEBUGOUT("Half Duplex\n");
1645 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001647 /* Are we forcing 100Mbps??? */
1648 if (hw->forced_speed_duplex == e1000_100_full ||
1649 hw->forced_speed_duplex == e1000_100_half) {
1650 /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */
1651 ctrl |= E1000_CTRL_SPD_100;
1652 mii_ctrl_reg |= MII_CR_SPEED_100;
1653 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
1654 DEBUGOUT("Forcing 100mb ");
1655 } else {
1656 /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */
1657 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1658 mii_ctrl_reg |= MII_CR_SPEED_10;
1659 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
1660 DEBUGOUT("Forcing 10mb ");
1661 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001663 e1000_config_collision_dist(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001665 /* Write the configured values back to the Device Control Reg. */
1666 ew32(CTRL, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001668 if (hw->phy_type == e1000_phy_m88) {
1669 ret_val =
1670 e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1671 if (ret_val)
1672 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001674 /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
1675 * forced whenever speed are duplex are forced.
1676 */
1677 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1678 ret_val =
1679 e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1680 if (ret_val)
1681 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001683 DEBUGOUT1("M88E1000 PSCR: %x \n", phy_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001685 /* Need to reset the PHY or these changes will be ignored */
1686 mii_ctrl_reg |= MII_CR_RESET;
Auke Kok90fb5132006-11-01 08:47:30 -08001687
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001688 /* Disable MDI-X support for 10/100 */
1689 } else {
1690 /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
1691 * forced whenever speed or duplex are forced.
1692 */
1693 ret_val =
1694 e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1695 if (ret_val)
1696 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001698 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1699 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001701 ret_val =
1702 e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1703 if (ret_val)
1704 return ret_val;
1705 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001707 /* Write back the modified PHY MII control register. */
1708 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg);
1709 if (ret_val)
1710 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001712 udelay(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001714 /* The wait_autoneg_complete flag may be a little misleading here.
1715 * Since we are forcing speed and duplex, Auto-Neg is not enabled.
1716 * But we do want to delay for a period while forcing only so we
1717 * don't generate false No Link messages. So we will wait here
1718 * only if the user has set wait_autoneg_complete to 1, which is
1719 * the default.
1720 */
1721 if (hw->wait_autoneg_complete) {
1722 /* We will wait for autoneg to complete. */
1723 DEBUGOUT("Waiting for forced speed/duplex link.\n");
1724 mii_status_reg = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001726 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
1727 for (i = PHY_FORCE_TIME; i > 0; i--) {
1728 /* Read the MII Status Register and wait for Auto-Neg Complete bit
1729 * to be set.
1730 */
1731 ret_val =
1732 e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1733 if (ret_val)
1734 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001736 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 if (mii_status_reg & MII_SR_LINK_STATUS)
1742 break;
1743 msleep(100);
1744 }
1745 if ((i == 0) && (hw->phy_type == e1000_phy_m88)) {
1746 /* We didn't get link. Reset the DSP and wait again for link. */
1747 ret_val = e1000_phy_reset_dsp(hw);
1748 if (ret_val) {
1749 DEBUGOUT("Error Resetting PHY DSP\n");
1750 return ret_val;
1751 }
1752 }
1753 /* This loop will early-out if the link condition has been met. */
1754 for (i = PHY_FORCE_TIME; i > 0; i--) {
1755 if (mii_status_reg & MII_SR_LINK_STATUS)
1756 break;
1757 msleep(100);
1758 /* Read the MII Status Register and wait for Auto-Neg Complete bit
1759 * to be set.
1760 */
1761 ret_val =
1762 e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1763 if (ret_val)
1764 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001766 ret_val =
1767 e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1768 if (ret_val)
1769 return ret_val;
1770 }
1771 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001773 if (hw->phy_type == e1000_phy_m88) {
1774 /* Because we reset the PHY above, we need to re-force TX_CLK in the
1775 * Extended PHY Specific Control Register to 25MHz clock. This value
1776 * defaults back to a 2.5MHz clock when the PHY is reset.
1777 */
1778 ret_val =
1779 e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
1780 &phy_data);
1781 if (ret_val)
1782 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001784 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1785 ret_val =
1786 e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
1787 phy_data);
1788 if (ret_val)
1789 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001791 /* In addition, because of the s/w reset above, we need to enable CRS on
1792 * TX. This must be set for both full and half duplex operation.
1793 */
1794 ret_val =
1795 e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1796 if (ret_val)
1797 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001799 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1800 ret_val =
1801 e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1802 if (ret_val)
1803 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001805 if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543)
1806 && (!hw->autoneg)
1807 && (hw->forced_speed_duplex == e1000_10_full
1808 || hw->forced_speed_duplex == e1000_10_half)) {
1809 ret_val = e1000_polarity_reversal_workaround(hw);
1810 if (ret_val)
1811 return ret_val;
1812 }
1813 }
1814 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815}
1816
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001817/**
1818 * e1000_config_collision_dist - set collision distance register
1819 * @hw: Struct containing variables accessed by shared code
1820 *
1821 * Sets the collision distance in the Transmit Control register.
1822 * Link should have been established previously. Reads the speed and duplex
1823 * information from the Device Status register.
1824 */
Joe Perches64798842008-07-11 15:17:02 -07001825void e1000_config_collision_dist(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001827 u32 tctl, coll_dist;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001829 DEBUGFUNC("e1000_config_collision_dist");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001831 if (hw->mac_type < e1000_82543)
1832 coll_dist = E1000_COLLISION_DISTANCE_82542;
1833 else
1834 coll_dist = E1000_COLLISION_DISTANCE;
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001835
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001836 tctl = er32(TCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001838 tctl &= ~E1000_TCTL_COLD;
1839 tctl |= coll_dist << E1000_COLD_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001841 ew32(TCTL, tctl);
1842 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843}
1844
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001845/**
1846 * e1000_config_mac_to_phy - sync phy and mac settings
1847 * @hw: Struct containing variables accessed by shared code
1848 * @mii_reg: data to write to the MII control register
1849 *
1850 * Sets MAC speed and duplex settings to reflect the those in the PHY
1851 * The contents of the PHY register containing the needed information need to
1852 * be passed in.
1853 */
Joe Perches64798842008-07-11 15:17:02 -07001854static s32 e1000_config_mac_to_phy(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001856 u32 ctrl;
1857 s32 ret_val;
1858 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001860 DEBUGFUNC("e1000_config_mac_to_phy");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001862 /* 82544 or newer MAC, Auto Speed Detection takes care of
1863 * MAC speed/duplex configuration.*/
1864 if (hw->mac_type >= e1000_82544)
1865 return E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001866
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001867 /* Read the Device Control Register and set the bits to Force Speed
1868 * and Duplex.
1869 */
1870 ctrl = er32(CTRL);
1871 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1872 ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001874 /* Set up duplex in the Device Control and Transmit Control
1875 * registers depending on negotiated values.
1876 */
1877 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
1878 if (ret_val)
1879 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001881 if (phy_data & M88E1000_PSSR_DPLX)
1882 ctrl |= E1000_CTRL_FD;
1883 else
1884 ctrl &= ~E1000_CTRL_FD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001886 e1000_config_collision_dist(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001888 /* Set up speed in the Device Control register depending on
1889 * negotiated values.
1890 */
1891 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
1892 ctrl |= E1000_CTRL_SPD_1000;
1893 else if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
1894 ctrl |= E1000_CTRL_SPD_100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001896 /* Write the configured values back to the Device Control Reg. */
1897 ew32(CTRL, ctrl);
1898 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899}
1900
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001901/**
1902 * e1000_force_mac_fc - force flow control settings
1903 * @hw: Struct containing variables accessed by shared code
1904 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905 * Forces the MAC's flow control settings.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906 * Sets the TFCE and RFCE bits in the device control register to reflect
1907 * the adapter settings. TFCE and RFCE need to be explicitly set by
1908 * software when a Copper PHY is used because autonegotiation is managed
1909 * by the PHY rather than the MAC. Software must also configure these
1910 * bits when link is forced on a fiber connection.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001911 */
Joe Perches64798842008-07-11 15:17:02 -07001912s32 e1000_force_mac_fc(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001914 u32 ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001916 DEBUGFUNC("e1000_force_mac_fc");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001918 /* Get the current configuration of the Device Control Register */
1919 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001921 /* Because we didn't get link via the internal auto-negotiation
1922 * mechanism (we either forced link or we got link via PHY
1923 * auto-neg), we have to manually enable/disable transmit an
1924 * receive flow control.
1925 *
1926 * The "Case" statement below enables/disable flow control
1927 * according to the "hw->fc" parameter.
1928 *
1929 * The possible values of the "fc" parameter are:
1930 * 0: Flow control is completely disabled
1931 * 1: Rx flow control is enabled (we can receive pause
1932 * frames but not send pause frames).
1933 * 2: Tx flow control is enabled (we can send pause frames
1934 * frames but we do not receive pause frames).
1935 * 3: Both Rx and TX flow control (symmetric) is enabled.
1936 * other: No other values should be possible at this point.
1937 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001939 switch (hw->fc) {
1940 case E1000_FC_NONE:
1941 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
1942 break;
1943 case E1000_FC_RX_PAUSE:
1944 ctrl &= (~E1000_CTRL_TFCE);
1945 ctrl |= E1000_CTRL_RFCE;
1946 break;
1947 case E1000_FC_TX_PAUSE:
1948 ctrl &= (~E1000_CTRL_RFCE);
1949 ctrl |= E1000_CTRL_TFCE;
1950 break;
1951 case E1000_FC_FULL:
1952 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
1953 break;
1954 default:
1955 DEBUGOUT("Flow control param set incorrectly\n");
1956 return -E1000_ERR_CONFIG;
1957 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001959 /* Disable TX Flow Control for 82542 (rev 2.0) */
1960 if (hw->mac_type == e1000_82542_rev2_0)
1961 ctrl &= (~E1000_CTRL_TFCE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001963 ew32(CTRL, ctrl);
1964 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001965}
1966
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001967/**
1968 * e1000_config_fc_after_link_up - configure flow control after autoneg
1969 * @hw: Struct containing variables accessed by shared code
1970 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001971 * Configures flow control settings after link is established
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972 * Should be called immediately after a valid link has been established.
1973 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
1974 * and autonegotiation is enabled, the MAC flow control settings will be set
1975 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001976 * and RFCE bits will be automatically set to the negotiated flow control mode.
1977 */
Joe Perches64798842008-07-11 15:17:02 -07001978static s32 e1000_config_fc_after_link_up(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001980 s32 ret_val;
1981 u16 mii_status_reg;
1982 u16 mii_nway_adv_reg;
1983 u16 mii_nway_lp_ability_reg;
1984 u16 speed;
1985 u16 duplex;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001987 DEBUGFUNC("e1000_config_fc_after_link_up");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001989 /* Check for the case where we have fiber media and auto-neg failed
1990 * so we had to force link. In this case, we need to force the
1991 * configuration of the MAC to match the "fc" parameter.
1992 */
1993 if (((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed))
1994 || ((hw->media_type == e1000_media_type_internal_serdes)
1995 && (hw->autoneg_failed))
1996 || ((hw->media_type == e1000_media_type_copper)
1997 && (!hw->autoneg))) {
1998 ret_val = e1000_force_mac_fc(hw);
1999 if (ret_val) {
2000 DEBUGOUT("Error forcing flow control settings\n");
2001 return ret_val;
2002 }
2003 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002005 /* Check for the case where we have copper media and auto-neg is
2006 * enabled. In this case, we need to check and see if Auto-Neg
2007 * has completed, and if so, how the PHY and link partner has
2008 * flow control configured.
2009 */
2010 if ((hw->media_type == e1000_media_type_copper) && hw->autoneg) {
2011 /* Read the MII Status Register and check to see if AutoNeg
2012 * has completed. We read this twice because this reg has
2013 * some "sticky" (latched) bits.
2014 */
2015 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2016 if (ret_val)
2017 return ret_val;
2018 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2019 if (ret_val)
2020 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002022 if (mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
2023 /* The AutoNeg process has completed, so we now need to
2024 * read both the Auto Negotiation Advertisement Register
2025 * (Address 4) and the Auto_Negotiation Base Page Ability
2026 * Register (Address 5) to determine how flow control was
2027 * negotiated.
2028 */
2029 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV,
2030 &mii_nway_adv_reg);
2031 if (ret_val)
2032 return ret_val;
2033 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY,
2034 &mii_nway_lp_ability_reg);
2035 if (ret_val)
2036 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002038 /* Two bits in the Auto Negotiation Advertisement Register
2039 * (Address 4) and two bits in the Auto Negotiation Base
2040 * Page Ability Register (Address 5) determine flow control
2041 * for both the PHY and the link partner. The following
2042 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
2043 * 1999, describes these PAUSE resolution bits and how flow
2044 * control is determined based upon these settings.
2045 * NOTE: DC = Don't Care
2046 *
2047 * LOCAL DEVICE | LINK PARTNER
2048 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
2049 *-------|---------|-------|---------|--------------------
2050 * 0 | 0 | DC | DC | E1000_FC_NONE
2051 * 0 | 1 | 0 | DC | E1000_FC_NONE
2052 * 0 | 1 | 1 | 0 | E1000_FC_NONE
2053 * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
2054 * 1 | 0 | 0 | DC | E1000_FC_NONE
2055 * 1 | DC | 1 | DC | E1000_FC_FULL
2056 * 1 | 1 | 0 | 0 | E1000_FC_NONE
2057 * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
2058 *
2059 */
2060 /* Are both PAUSE bits set to 1? If so, this implies
2061 * Symmetric Flow Control is enabled at both ends. The
2062 * ASM_DIR bits are irrelevant per the spec.
2063 *
2064 * For Symmetric Flow Control:
2065 *
2066 * LOCAL DEVICE | LINK PARTNER
2067 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2068 *-------|---------|-------|---------|--------------------
2069 * 1 | DC | 1 | DC | E1000_FC_FULL
2070 *
2071 */
2072 if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2073 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
2074 /* Now we need to check if the user selected RX ONLY
2075 * of pause frames. In this case, we had to advertise
2076 * FULL flow control because we could not advertise RX
2077 * ONLY. Hence, we must now check to see if we need to
2078 * turn OFF the TRANSMISSION of PAUSE frames.
2079 */
2080 if (hw->original_fc == E1000_FC_FULL) {
2081 hw->fc = E1000_FC_FULL;
2082 DEBUGOUT("Flow Control = FULL.\n");
2083 } else {
2084 hw->fc = E1000_FC_RX_PAUSE;
2085 DEBUGOUT
2086 ("Flow Control = RX PAUSE frames only.\n");
2087 }
2088 }
2089 /* For receiving PAUSE frames ONLY.
2090 *
2091 * LOCAL DEVICE | LINK PARTNER
2092 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2093 *-------|---------|-------|---------|--------------------
2094 * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
2095 *
2096 */
2097 else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2098 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2099 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2100 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR))
2101 {
2102 hw->fc = E1000_FC_TX_PAUSE;
2103 DEBUGOUT
2104 ("Flow Control = TX PAUSE frames only.\n");
2105 }
2106 /* For transmitting PAUSE frames ONLY.
2107 *
2108 * LOCAL DEVICE | LINK PARTNER
2109 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2110 *-------|---------|-------|---------|--------------------
2111 * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
2112 *
2113 */
2114 else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2115 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2116 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2117 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR))
2118 {
2119 hw->fc = E1000_FC_RX_PAUSE;
2120 DEBUGOUT
2121 ("Flow Control = RX PAUSE frames only.\n");
2122 }
2123 /* Per the IEEE spec, at this point flow control should be
2124 * disabled. However, we want to consider that we could
2125 * be connected to a legacy switch that doesn't advertise
2126 * desired flow control, but can be forced on the link
2127 * partner. So if we advertised no flow control, that is
2128 * what we will resolve to. If we advertised some kind of
2129 * receive capability (Rx Pause Only or Full Flow Control)
2130 * and the link partner advertised none, we will configure
2131 * ourselves to enable Rx Flow Control only. We can do
2132 * this safely for two reasons: If the link partner really
2133 * didn't want flow control enabled, and we enable Rx, no
2134 * harm done since we won't be receiving any PAUSE frames
2135 * anyway. If the intent on the link partner was to have
2136 * flow control enabled, then by us enabling RX only, we
2137 * can at least receive pause frames and process them.
2138 * This is a good idea because in most cases, since we are
2139 * predominantly a server NIC, more times than not we will
2140 * be asked to delay transmission of packets than asking
2141 * our link partner to pause transmission of frames.
2142 */
2143 else if ((hw->original_fc == E1000_FC_NONE ||
2144 hw->original_fc == E1000_FC_TX_PAUSE) ||
2145 hw->fc_strict_ieee) {
2146 hw->fc = E1000_FC_NONE;
2147 DEBUGOUT("Flow Control = NONE.\n");
2148 } else {
2149 hw->fc = E1000_FC_RX_PAUSE;
2150 DEBUGOUT
2151 ("Flow Control = RX PAUSE frames only.\n");
2152 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002154 /* Now we need to do one last check... If we auto-
2155 * negotiated to HALF DUPLEX, flow control should not be
2156 * enabled per IEEE 802.3 spec.
2157 */
2158 ret_val =
2159 e1000_get_speed_and_duplex(hw, &speed, &duplex);
2160 if (ret_val) {
2161 DEBUGOUT
2162 ("Error getting link speed and duplex\n");
2163 return ret_val;
2164 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002166 if (duplex == HALF_DUPLEX)
2167 hw->fc = E1000_FC_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002169 /* Now we call a subroutine to actually force the MAC
2170 * controller to use the correct flow control settings.
2171 */
2172 ret_val = e1000_force_mac_fc(hw);
2173 if (ret_val) {
2174 DEBUGOUT
2175 ("Error forcing flow control settings\n");
2176 return ret_val;
2177 }
2178 } else {
2179 DEBUGOUT
2180 ("Copper PHY and Auto Neg has not completed.\n");
2181 }
2182 }
2183 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184}
2185
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002186/**
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002187 * e1000_check_for_serdes_link_generic - Check for link (Serdes)
2188 * @hw: pointer to the HW structure
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002189 *
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002190 * Checks for link up on the hardware. If link is not up and we have
2191 * a signal, then we need to force link up.
2192 */
Jesse Brandeburg11b7f7b2009-09-25 12:20:33 +00002193static s32 e1000_check_for_serdes_link_generic(struct e1000_hw *hw)
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002194{
2195 u32 rxcw;
2196 u32 ctrl;
2197 u32 status;
2198 s32 ret_val = E1000_SUCCESS;
2199
2200 DEBUGFUNC("e1000_check_for_serdes_link_generic");
2201
2202 ctrl = er32(CTRL);
2203 status = er32(STATUS);
2204 rxcw = er32(RXCW);
2205
2206 /*
2207 * If we don't have link (auto-negotiation failed or link partner
2208 * cannot auto-negotiate), and our link partner is not trying to
2209 * auto-negotiate with us (we are receiving idles or data),
2210 * we need to force link up. We also need to give auto-negotiation
2211 * time to complete.
2212 */
2213 /* (ctrl & E1000_CTRL_SWDPIN1) == 1 == have signal */
2214 if ((!(status & E1000_STATUS_LU)) && (!(rxcw & E1000_RXCW_C))) {
2215 if (hw->autoneg_failed == 0) {
2216 hw->autoneg_failed = 1;
2217 goto out;
2218 }
2219 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\n");
2220
2221 /* Disable auto-negotiation in the TXCW register */
2222 ew32(TXCW, (hw->txcw & ~E1000_TXCW_ANE));
2223
2224 /* Force link-up and also force full-duplex. */
2225 ctrl = er32(CTRL);
2226 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
2227 ew32(CTRL, ctrl);
2228
2229 /* Configure Flow Control after forcing link up. */
2230 ret_val = e1000_config_fc_after_link_up(hw);
2231 if (ret_val) {
2232 DEBUGOUT("Error configuring flow control\n");
2233 goto out;
2234 }
2235 } else if ((ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
2236 /*
2237 * If we are forcing link and we are receiving /C/ ordered
2238 * sets, re-enable auto-negotiation in the TXCW register
2239 * and disable forced link in the Device Control register
2240 * in an attempt to auto-negotiate with our link partner.
2241 */
2242 DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\n");
2243 ew32(TXCW, hw->txcw);
2244 ew32(CTRL, (ctrl & ~E1000_CTRL_SLU));
2245
2246 hw->serdes_has_link = true;
2247 } else if (!(E1000_TXCW_ANE & er32(TXCW))) {
2248 /*
2249 * If we force link for non-auto-negotiation switch, check
2250 * link status based on MAC synchronization for internal
2251 * serdes media type.
2252 */
2253 /* SYNCH bit and IV bit are sticky. */
2254 udelay(10);
2255 rxcw = er32(RXCW);
2256 if (rxcw & E1000_RXCW_SYNCH) {
2257 if (!(rxcw & E1000_RXCW_IV)) {
2258 hw->serdes_has_link = true;
2259 DEBUGOUT("SERDES: Link up - forced.\n");
2260 }
2261 } else {
2262 hw->serdes_has_link = false;
2263 DEBUGOUT("SERDES: Link down - force failed.\n");
2264 }
2265 }
2266
2267 if (E1000_TXCW_ANE & er32(TXCW)) {
2268 status = er32(STATUS);
2269 if (status & E1000_STATUS_LU) {
2270 /* SYNCH bit and IV bit are sticky, so reread rxcw. */
2271 udelay(10);
2272 rxcw = er32(RXCW);
2273 if (rxcw & E1000_RXCW_SYNCH) {
2274 if (!(rxcw & E1000_RXCW_IV)) {
2275 hw->serdes_has_link = true;
2276 DEBUGOUT("SERDES: Link up - autoneg "
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002277 "completed successfully.\n");
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002278 } else {
2279 hw->serdes_has_link = false;
2280 DEBUGOUT("SERDES: Link down - invalid"
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002281 "codewords detected in autoneg.\n");
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002282 }
2283 } else {
2284 hw->serdes_has_link = false;
2285 DEBUGOUT("SERDES: Link down - no sync.\n");
2286 }
2287 } else {
2288 hw->serdes_has_link = false;
2289 DEBUGOUT("SERDES: Link down - autoneg failed\n");
2290 }
2291 }
2292
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002293 out:
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002294 return ret_val;
2295}
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002296
2297/**
2298 * e1000_check_for_link
2299 * @hw: Struct containing variables accessed by shared code
2300 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301 * Checks to see if the link status of the hardware has changed.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302 * Called by any function that needs to check the link status of the adapter.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002303 */
Joe Perches64798842008-07-11 15:17:02 -07002304s32 e1000_check_for_link(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002306 u32 rxcw = 0;
2307 u32 ctrl;
2308 u32 status;
2309 u32 rctl;
2310 u32 icr;
2311 u32 signal = 0;
2312 s32 ret_val;
2313 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002315 DEBUGFUNC("e1000_check_for_link");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002317 ctrl = er32(CTRL);
2318 status = er32(STATUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002320 /* On adapters with a MAC newer than 82544, SW Definable pin 1 will be
2321 * set when the optics detect a signal. On older adapters, it will be
2322 * cleared when there is a signal. This applies to fiber media only.
2323 */
2324 if ((hw->media_type == e1000_media_type_fiber) ||
2325 (hw->media_type == e1000_media_type_internal_serdes)) {
2326 rxcw = er32(RXCW);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002328 if (hw->media_type == e1000_media_type_fiber) {
2329 signal =
2330 (hw->mac_type >
2331 e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
2332 if (status & E1000_STATUS_LU)
2333 hw->get_link_status = false;
2334 }
2335 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002337 /* If we have a copper PHY then we only want to go out to the PHY
2338 * registers to see if Auto-Neg has completed and/or if our link
2339 * status has changed. The get_link_status flag will be set if we
2340 * receive a Link Status Change interrupt or we have Rx Sequence
2341 * Errors.
2342 */
2343 if ((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
2344 /* First we want to see if the MII Status Register reports
2345 * link. If so, then we want to get the current speed/duplex
2346 * of the PHY.
2347 * Read the register twice since the link bit is sticky.
2348 */
2349 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2350 if (ret_val)
2351 return ret_val;
2352 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2353 if (ret_val)
2354 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002356 if (phy_data & MII_SR_LINK_STATUS) {
2357 hw->get_link_status = false;
2358 /* Check if there was DownShift, must be checked immediately after
2359 * link-up */
2360 e1000_check_downshift(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002362 /* If we are on 82544 or 82543 silicon and speed/duplex
2363 * are forced to 10H or 10F, then we will implement the polarity
2364 * reversal workaround. We disable interrupts first, and upon
2365 * returning, place the devices interrupt state to its previous
2366 * value except for the link status change interrupt which will
2367 * happen due to the execution of this workaround.
2368 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002369
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002370 if ((hw->mac_type == e1000_82544
2371 || hw->mac_type == e1000_82543) && (!hw->autoneg)
2372 && (hw->forced_speed_duplex == e1000_10_full
2373 || hw->forced_speed_duplex == e1000_10_half)) {
2374 ew32(IMC, 0xffffffff);
2375 ret_val =
2376 e1000_polarity_reversal_workaround(hw);
2377 icr = er32(ICR);
2378 ew32(ICS, (icr & ~E1000_ICS_LSC));
2379 ew32(IMS, IMS_ENABLE_MASK);
2380 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002382 } else {
2383 /* No link detected */
2384 e1000_config_dsp_after_link_change(hw, false);
2385 return 0;
2386 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002388 /* If we are forcing speed/duplex, then we simply return since
2389 * we have already determined whether we have link or not.
2390 */
2391 if (!hw->autoneg)
2392 return -E1000_ERR_CONFIG;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002394 /* optimize the dsp settings for the igp phy */
2395 e1000_config_dsp_after_link_change(hw, true);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002397 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
2398 * have Si on board that is 82544 or newer, Auto
2399 * Speed Detection takes care of MAC speed/duplex
2400 * configuration. So we only need to configure Collision
2401 * Distance in the MAC. Otherwise, we need to force
2402 * speed/duplex on the MAC to the current PHY speed/duplex
2403 * settings.
2404 */
2405 if (hw->mac_type >= e1000_82544)
2406 e1000_config_collision_dist(hw);
2407 else {
2408 ret_val = e1000_config_mac_to_phy(hw);
2409 if (ret_val) {
2410 DEBUGOUT
2411 ("Error configuring MAC to PHY settings\n");
2412 return ret_val;
2413 }
2414 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002416 /* Configure Flow Control now that Auto-Neg has completed. First, we
2417 * need to restore the desired flow control settings because we may
2418 * have had to re-autoneg with a different link partner.
2419 */
2420 ret_val = e1000_config_fc_after_link_up(hw);
2421 if (ret_val) {
2422 DEBUGOUT("Error configuring flow control\n");
2423 return ret_val;
2424 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002426 /* At this point we know that we are on copper and we have
2427 * auto-negotiated link. These are conditions for checking the link
2428 * partner capability register. We use the link speed to determine if
2429 * TBI compatibility needs to be turned on or off. If the link is not
2430 * at gigabit speed, then TBI compatibility is not needed. If we are
2431 * at gigabit speed, we turn on TBI compatibility.
2432 */
2433 if (hw->tbi_compatibility_en) {
2434 u16 speed, duplex;
2435 ret_val =
2436 e1000_get_speed_and_duplex(hw, &speed, &duplex);
2437 if (ret_val) {
2438 DEBUGOUT
2439 ("Error getting link speed and duplex\n");
2440 return ret_val;
2441 }
2442 if (speed != SPEED_1000) {
2443 /* If link speed is not set to gigabit speed, we do not need
2444 * to enable TBI compatibility.
2445 */
2446 if (hw->tbi_compatibility_on) {
2447 /* If we previously were in the mode, turn it off. */
2448 rctl = er32(RCTL);
2449 rctl &= ~E1000_RCTL_SBP;
2450 ew32(RCTL, rctl);
2451 hw->tbi_compatibility_on = false;
2452 }
2453 } else {
2454 /* If TBI compatibility is was previously off, turn it on. For
2455 * compatibility with a TBI link partner, we will store bad
2456 * packets. Some frames have an additional byte on the end and
2457 * will look like CRC errors to to the hardware.
2458 */
2459 if (!hw->tbi_compatibility_on) {
2460 hw->tbi_compatibility_on = true;
2461 rctl = er32(RCTL);
2462 rctl |= E1000_RCTL_SBP;
2463 ew32(RCTL, rctl);
2464 }
2465 }
2466 }
2467 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002469 if ((hw->media_type == e1000_media_type_fiber) ||
2470 (hw->media_type == e1000_media_type_internal_serdes))
2471 e1000_check_for_serdes_link_generic(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002473 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474}
2475
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002476/**
2477 * e1000_get_speed_and_duplex
2478 * @hw: Struct containing variables accessed by shared code
2479 * @speed: Speed of the connection
2480 * @duplex: Duplex setting of the connection
2481
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482 * Detects the current speed and duplex settings of the hardware.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002483 */
Joe Perches64798842008-07-11 15:17:02 -07002484s32 e1000_get_speed_and_duplex(struct e1000_hw *hw, u16 *speed, u16 *duplex)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002486 u32 status;
2487 s32 ret_val;
2488 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002490 DEBUGFUNC("e1000_get_speed_and_duplex");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002492 if (hw->mac_type >= e1000_82543) {
2493 status = er32(STATUS);
2494 if (status & E1000_STATUS_SPEED_1000) {
2495 *speed = SPEED_1000;
2496 DEBUGOUT("1000 Mbs, ");
2497 } else if (status & E1000_STATUS_SPEED_100) {
2498 *speed = SPEED_100;
2499 DEBUGOUT("100 Mbs, ");
2500 } else {
2501 *speed = SPEED_10;
2502 DEBUGOUT("10 Mbs, ");
2503 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002505 if (status & E1000_STATUS_FD) {
2506 *duplex = FULL_DUPLEX;
2507 DEBUGOUT("Full Duplex\n");
2508 } else {
2509 *duplex = HALF_DUPLEX;
2510 DEBUGOUT(" Half Duplex\n");
2511 }
2512 } else {
2513 DEBUGOUT("1000 Mbs, Full Duplex\n");
2514 *speed = SPEED_1000;
2515 *duplex = FULL_DUPLEX;
2516 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002518 /* IGP01 PHY may advertise full duplex operation after speed downgrade even
2519 * if it is operating at half duplex. Here we set the duplex settings to
2520 * match the duplex in the link partner's capabilities.
2521 */
2522 if (hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
2523 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
2524 if (ret_val)
2525 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002527 if (!(phy_data & NWAY_ER_LP_NWAY_CAPS))
2528 *duplex = HALF_DUPLEX;
2529 else {
2530 ret_val =
2531 e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data);
2532 if (ret_val)
2533 return ret_val;
2534 if ((*speed == SPEED_100
2535 && !(phy_data & NWAY_LPAR_100TX_FD_CAPS))
2536 || (*speed == SPEED_10
2537 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
2538 *duplex = HALF_DUPLEX;
2539 }
2540 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002541
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002542 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543}
2544
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002545/**
2546 * e1000_wait_autoneg
2547 * @hw: Struct containing variables accessed by shared code
2548 *
2549 * Blocks until autoneg completes or times out (~4.5 seconds)
2550 */
Joe Perches64798842008-07-11 15:17:02 -07002551static s32 e1000_wait_autoneg(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002552{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002553 s32 ret_val;
2554 u16 i;
2555 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002557 DEBUGFUNC("e1000_wait_autoneg");
2558 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002560 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
2561 for (i = PHY_AUTO_NEG_TIME; i > 0; i--) {
2562 /* Read the MII Status Register and wait for Auto-Neg
2563 * Complete bit to be set.
2564 */
2565 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2566 if (ret_val)
2567 return ret_val;
2568 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2569 if (ret_val)
2570 return ret_val;
2571 if (phy_data & MII_SR_AUTONEG_COMPLETE) {
2572 return E1000_SUCCESS;
2573 }
2574 msleep(100);
2575 }
2576 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577}
2578
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002579/**
2580 * e1000_raise_mdi_clk - Raises the Management Data Clock
2581 * @hw: Struct containing variables accessed by shared code
2582 * @ctrl: Device control register's current value
2583 */
Joe Perches64798842008-07-11 15:17:02 -07002584static void e1000_raise_mdi_clk(struct e1000_hw *hw, u32 *ctrl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002586 /* Raise the clock input to the Management Data Clock (by setting the MDC
2587 * bit), and then delay 10 microseconds.
2588 */
2589 ew32(CTRL, (*ctrl | E1000_CTRL_MDC));
2590 E1000_WRITE_FLUSH();
2591 udelay(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592}
2593
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002594/**
2595 * e1000_lower_mdi_clk - Lowers the Management Data Clock
2596 * @hw: Struct containing variables accessed by shared code
2597 * @ctrl: Device control register's current value
2598 */
Joe Perches64798842008-07-11 15:17:02 -07002599static void e1000_lower_mdi_clk(struct e1000_hw *hw, u32 *ctrl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002601 /* Lower the clock input to the Management Data Clock (by clearing the MDC
2602 * bit), and then delay 10 microseconds.
2603 */
2604 ew32(CTRL, (*ctrl & ~E1000_CTRL_MDC));
2605 E1000_WRITE_FLUSH();
2606 udelay(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607}
2608
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002609/**
2610 * e1000_shift_out_mdi_bits - Shifts data bits out to the PHY
2611 * @hw: Struct containing variables accessed by shared code
2612 * @data: Data to send out to the PHY
2613 * @count: Number of bits to shift out
2614 *
2615 * Bits are shifted out in MSB to LSB order.
2616 */
Joe Perches64798842008-07-11 15:17:02 -07002617static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, u32 data, u16 count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002619 u32 ctrl;
2620 u32 mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002622 /* We need to shift "count" number of bits out to the PHY. So, the value
2623 * in the "data" parameter will be shifted out to the PHY one bit at a
2624 * time. In order to do this, "data" must be broken down into bits.
2625 */
2626 mask = 0x01;
2627 mask <<= (count - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002629 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002631 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
2632 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002633
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002634 while (mask) {
2635 /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
2636 * then raising and lowering the Management Data Clock. A "0" is
2637 * shifted out to the PHY by setting the MDIO bit to "0" and then
2638 * raising and lowering the clock.
2639 */
2640 if (data & mask)
2641 ctrl |= E1000_CTRL_MDIO;
2642 else
2643 ctrl &= ~E1000_CTRL_MDIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002645 ew32(CTRL, ctrl);
2646 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002648 udelay(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002650 e1000_raise_mdi_clk(hw, &ctrl);
2651 e1000_lower_mdi_clk(hw, &ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002652
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002653 mask = mask >> 1;
2654 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002655}
2656
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002657/**
2658 * e1000_shift_in_mdi_bits - Shifts data bits in from the PHY
2659 * @hw: Struct containing variables accessed by shared code
2660 *
2661 * Bits are shifted in in MSB to LSB order.
2662 */
Joe Perches64798842008-07-11 15:17:02 -07002663static u16 e1000_shift_in_mdi_bits(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002665 u32 ctrl;
2666 u16 data = 0;
2667 u8 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002668
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002669 /* In order to read a register from the PHY, we need to shift in a total
2670 * of 18 bits from the PHY. The first two bit (turnaround) times are used
2671 * to avoid contention on the MDIO pin when a read operation is performed.
2672 * These two bits are ignored by us and thrown away. Bits are "shifted in"
2673 * by raising the input to the Management Data Clock (setting the MDC bit),
2674 * and then reading the value of the MDIO bit.
2675 */
2676 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002677
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002678 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
2679 ctrl &= ~E1000_CTRL_MDIO_DIR;
2680 ctrl &= ~E1000_CTRL_MDIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002681
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002682 ew32(CTRL, ctrl);
2683 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002684
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002685 /* Raise and Lower the clock before reading in the data. This accounts for
2686 * the turnaround bits. The first clock occurred when we clocked out the
2687 * last bit of the Register Address.
2688 */
2689 e1000_raise_mdi_clk(hw, &ctrl);
2690 e1000_lower_mdi_clk(hw, &ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002691
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002692 for (data = 0, i = 0; i < 16; i++) {
2693 data = data << 1;
2694 e1000_raise_mdi_clk(hw, &ctrl);
2695 ctrl = er32(CTRL);
2696 /* Check to see if we shifted in a "1". */
2697 if (ctrl & E1000_CTRL_MDIO)
2698 data |= 1;
2699 e1000_lower_mdi_clk(hw, &ctrl);
2700 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002701
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002702 e1000_raise_mdi_clk(hw, &ctrl);
2703 e1000_lower_mdi_clk(hw, &ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002704
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002705 return data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002706}
2707
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002708
2709/**
2710 * e1000_read_phy_reg - read a phy register
2711 * @hw: Struct containing variables accessed by shared code
2712 * @reg_addr: address of the PHY register to read
2713 *
2714 * Reads the value from a PHY register, if the value is on a specific non zero
2715 * page, sets the page first.
2716 */
Joe Perches64798842008-07-11 15:17:02 -07002717s32 e1000_read_phy_reg(struct e1000_hw *hw, u32 reg_addr, u16 *phy_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002718{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002719 u32 ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002720
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002721 DEBUGFUNC("e1000_read_phy_reg");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002723 if ((hw->phy_type == e1000_phy_igp) &&
2724 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
2725 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
2726 (u16) reg_addr);
2727 if (ret_val)
2728 return ret_val;
2729 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002731 ret_val = e1000_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
2732 phy_data);
2733
2734 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002735}
2736
Joe Perches64798842008-07-11 15:17:02 -07002737static s32 e1000_read_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr,
2738 u16 *phy_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002739{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002740 u32 i;
2741 u32 mdic = 0;
2742 const u32 phy_addr = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002744 DEBUGFUNC("e1000_read_phy_reg_ex");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002746 if (reg_addr > MAX_PHY_REG_ADDRESS) {
2747 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
2748 return -E1000_ERR_PARAM;
2749 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002750
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002751 if (hw->mac_type > e1000_82543) {
2752 /* Set up Op-code, Phy Address, and register address in the MDI
2753 * Control register. The MAC will take care of interfacing with the
2754 * PHY to retrieve the desired data.
2755 */
2756 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
2757 (phy_addr << E1000_MDIC_PHY_SHIFT) |
2758 (E1000_MDIC_OP_READ));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002759
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002760 ew32(MDIC, mdic);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002761
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002762 /* Poll the ready bit to see if the MDI read completed */
2763 for (i = 0; i < 64; i++) {
2764 udelay(50);
2765 mdic = er32(MDIC);
2766 if (mdic & E1000_MDIC_READY)
2767 break;
2768 }
2769 if (!(mdic & E1000_MDIC_READY)) {
2770 DEBUGOUT("MDI Read did not complete\n");
2771 return -E1000_ERR_PHY;
2772 }
2773 if (mdic & E1000_MDIC_ERROR) {
2774 DEBUGOUT("MDI Error\n");
2775 return -E1000_ERR_PHY;
2776 }
2777 *phy_data = (u16) mdic;
2778 } else {
2779 /* We must first send a preamble through the MDIO pin to signal the
2780 * beginning of an MII instruction. This is done by sending 32
2781 * consecutive "1" bits.
2782 */
2783 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002784
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002785 /* Now combine the next few fields that are required for a read
2786 * operation. We use this method instead of calling the
2787 * e1000_shift_out_mdi_bits routine five different times. The format of
2788 * a MII read instruction consists of a shift out of 14 bits and is
2789 * defined as follows:
2790 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
2791 * followed by a shift in of 18 bits. This first two bits shifted in
2792 * are TurnAround bits used to avoid contention on the MDIO pin when a
2793 * READ operation is performed. These two bits are thrown away
2794 * followed by a shift in of 16 bits which contains the desired data.
2795 */
2796 mdic = ((reg_addr) | (phy_addr << 5) |
2797 (PHY_OP_READ << 10) | (PHY_SOF << 12));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002798
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002799 e1000_shift_out_mdi_bits(hw, mdic, 14);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002800
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002801 /* Now that we've shifted out the read command to the MII, we need to
2802 * "shift in" the 16-bit value (18 total bits) of the requested PHY
2803 * register address.
2804 */
2805 *phy_data = e1000_shift_in_mdi_bits(hw);
2806 }
2807 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002808}
2809
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002810/**
2811 * e1000_write_phy_reg - write a phy register
2812 *
2813 * @hw: Struct containing variables accessed by shared code
2814 * @reg_addr: address of the PHY register to write
2815 * @data: data to write to the PHY
2816
2817 * Writes a value to a PHY register
2818 */
Joe Perches64798842008-07-11 15:17:02 -07002819s32 e1000_write_phy_reg(struct e1000_hw *hw, u32 reg_addr, u16 phy_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002820{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002821 u32 ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002822
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002823 DEBUGFUNC("e1000_write_phy_reg");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002824
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002825 if ((hw->phy_type == e1000_phy_igp) &&
2826 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
2827 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
2828 (u16) reg_addr);
2829 if (ret_val)
2830 return ret_val;
2831 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002832
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002833 ret_val = e1000_write_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
2834 phy_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002835
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002836 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002837}
2838
Joe Perches64798842008-07-11 15:17:02 -07002839static s32 e1000_write_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr,
2840 u16 phy_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002841{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002842 u32 i;
2843 u32 mdic = 0;
2844 const u32 phy_addr = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002845
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002846 DEBUGFUNC("e1000_write_phy_reg_ex");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002847
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002848 if (reg_addr > MAX_PHY_REG_ADDRESS) {
2849 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
2850 return -E1000_ERR_PARAM;
2851 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002852
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002853 if (hw->mac_type > e1000_82543) {
2854 /* Set up Op-code, Phy Address, register address, and data intended
2855 * for the PHY register in the MDI Control register. The MAC will take
2856 * care of interfacing with the PHY to send the desired data.
2857 */
2858 mdic = (((u32) phy_data) |
2859 (reg_addr << E1000_MDIC_REG_SHIFT) |
2860 (phy_addr << E1000_MDIC_PHY_SHIFT) |
2861 (E1000_MDIC_OP_WRITE));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002862
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002863 ew32(MDIC, mdic);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002864
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002865 /* Poll the ready bit to see if the MDI read completed */
2866 for (i = 0; i < 641; i++) {
2867 udelay(5);
2868 mdic = er32(MDIC);
2869 if (mdic & E1000_MDIC_READY)
2870 break;
2871 }
2872 if (!(mdic & E1000_MDIC_READY)) {
2873 DEBUGOUT("MDI Write did not complete\n");
2874 return -E1000_ERR_PHY;
2875 }
2876 } else {
2877 /* We'll need to use the SW defined pins to shift the write command
2878 * out to the PHY. We first send a preamble to the PHY to signal the
2879 * beginning of the MII instruction. This is done by sending 32
2880 * consecutive "1" bits.
2881 */
2882 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002883
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002884 /* Now combine the remaining required fields that will indicate a
2885 * write operation. We use this method instead of calling the
2886 * e1000_shift_out_mdi_bits routine for each field in the command. The
2887 * format of a MII write instruction is as follows:
2888 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
2889 */
2890 mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
2891 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
2892 mdic <<= 16;
2893 mdic |= (u32) phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002894
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002895 e1000_shift_out_mdi_bits(hw, mdic, 32);
2896 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002897
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002898 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002899}
2900
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002901/**
2902 * e1000_phy_hw_reset - reset the phy, hardware style
2903 * @hw: Struct containing variables accessed by shared code
2904 *
2905 * Returns the PHY to the power-on reset state
2906 */
Joe Perches64798842008-07-11 15:17:02 -07002907s32 e1000_phy_hw_reset(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002908{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002909 u32 ctrl, ctrl_ext;
2910 u32 led_ctrl;
2911 s32 ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002912
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002913 DEBUGFUNC("e1000_phy_hw_reset");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002914
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002915 DEBUGOUT("Resetting Phy...\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002916
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002917 if (hw->mac_type > e1000_82543) {
2918 /* Read the device control register and assert the E1000_CTRL_PHY_RST
2919 * bit. Then, take it out of reset.
2920 * For e1000 hardware, we delay for 10ms between the assert
2921 * and deassert.
2922 */
2923 ctrl = er32(CTRL);
2924 ew32(CTRL, ctrl | E1000_CTRL_PHY_RST);
2925 E1000_WRITE_FLUSH();
Auke Kok76c224b2006-05-23 13:36:06 -07002926
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002927 msleep(10);
Auke Kok76c224b2006-05-23 13:36:06 -07002928
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002929 ew32(CTRL, ctrl);
2930 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002931
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002932 } else {
2933 /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
2934 * bit to put the PHY into reset. Then, take it out of reset.
2935 */
2936 ctrl_ext = er32(CTRL_EXT);
2937 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
2938 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
2939 ew32(CTRL_EXT, ctrl_ext);
2940 E1000_WRITE_FLUSH();
2941 msleep(10);
2942 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
2943 ew32(CTRL_EXT, ctrl_ext);
2944 E1000_WRITE_FLUSH();
2945 }
2946 udelay(150);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002947
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002948 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
2949 /* Configure activity LED after PHY reset */
2950 led_ctrl = er32(LEDCTL);
2951 led_ctrl &= IGP_ACTIVITY_LED_MASK;
2952 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
2953 ew32(LEDCTL, led_ctrl);
2954 }
Auke Kok8fc897b2006-08-28 14:56:16 -07002955
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002956 /* Wait for FW to finish PHY configuration. */
2957 ret_val = e1000_get_phy_cfg_done(hw);
2958 if (ret_val != E1000_SUCCESS)
2959 return ret_val;
2960
2961 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002962}
2963
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002964/**
2965 * e1000_phy_reset - reset the phy to commit settings
2966 * @hw: Struct containing variables accessed by shared code
2967 *
2968 * Resets the PHY
2969 * Sets bit 15 of the MII Control register
2970 */
Joe Perches64798842008-07-11 15:17:02 -07002971s32 e1000_phy_reset(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002972{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002973 s32 ret_val;
2974 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002975
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002976 DEBUGFUNC("e1000_phy_reset");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002977
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002978 switch (hw->phy_type) {
2979 case e1000_phy_igp:
2980 ret_val = e1000_phy_hw_reset(hw);
2981 if (ret_val)
2982 return ret_val;
2983 break;
2984 default:
2985 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
2986 if (ret_val)
2987 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002988
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002989 phy_data |= MII_CR_RESET;
2990 ret_val = e1000_write_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 udelay(1);
2995 break;
2996 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002997
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002998 if (hw->phy_type == e1000_phy_igp)
2999 e1000_phy_init_script(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003000
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003001 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003002}
3003
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003004/**
3005 * e1000_detect_gig_phy - check the phy type
3006 * @hw: Struct containing variables accessed by shared code
3007 *
3008 * Probes the expected PHY address for known PHY IDs
3009 */
Joe Perches64798842008-07-11 15:17:02 -07003010static s32 e1000_detect_gig_phy(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003011{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003012 s32 phy_init_status, ret_val;
3013 u16 phy_id_high, phy_id_low;
3014 bool match = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003015
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003016 DEBUGFUNC("e1000_detect_gig_phy");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003017
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003018 if (hw->phy_id != 0)
3019 return E1000_SUCCESS;
Jeff Kirsher2a88c172006-09-27 12:54:05 -07003020
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003021 /* Read the PHY ID Registers to identify which PHY is onboard. */
3022 ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
3023 if (ret_val)
3024 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003025
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003026 hw->phy_id = (u32) (phy_id_high << 16);
3027 udelay(20);
3028 ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
3029 if (ret_val)
3030 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003031
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003032 hw->phy_id |= (u32) (phy_id_low & PHY_REVISION_MASK);
3033 hw->phy_revision = (u32) phy_id_low & ~PHY_REVISION_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003034
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003035 switch (hw->mac_type) {
3036 case e1000_82543:
3037 if (hw->phy_id == M88E1000_E_PHY_ID)
3038 match = true;
3039 break;
3040 case e1000_82544:
3041 if (hw->phy_id == M88E1000_I_PHY_ID)
3042 match = true;
3043 break;
3044 case e1000_82540:
3045 case e1000_82545:
3046 case e1000_82545_rev_3:
3047 case e1000_82546:
3048 case e1000_82546_rev_3:
3049 if (hw->phy_id == M88E1011_I_PHY_ID)
3050 match = true;
3051 break;
3052 case e1000_82541:
3053 case e1000_82541_rev_2:
3054 case e1000_82547:
3055 case e1000_82547_rev_2:
3056 if (hw->phy_id == IGP01E1000_I_PHY_ID)
3057 match = true;
3058 break;
3059 default:
3060 DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type);
3061 return -E1000_ERR_CONFIG;
3062 }
3063 phy_init_status = e1000_set_phy_type(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003064
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003065 if ((match) && (phy_init_status == E1000_SUCCESS)) {
3066 DEBUGOUT1("PHY ID 0x%X detected\n", hw->phy_id);
3067 return E1000_SUCCESS;
3068 }
3069 DEBUGOUT1("Invalid PHY ID 0x%X\n", hw->phy_id);
3070 return -E1000_ERR_PHY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003071}
3072
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003073/**
3074 * e1000_phy_reset_dsp - reset DSP
3075 * @hw: Struct containing variables accessed by shared code
3076 *
3077 * Resets the PHY's DSP
3078 */
Joe Perches64798842008-07-11 15:17:02 -07003079static s32 e1000_phy_reset_dsp(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003080{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003081 s32 ret_val;
3082 DEBUGFUNC("e1000_phy_reset_dsp");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003083
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003084 do {
3085 ret_val = e1000_write_phy_reg(hw, 29, 0x001d);
3086 if (ret_val)
3087 break;
3088 ret_val = e1000_write_phy_reg(hw, 30, 0x00c1);
3089 if (ret_val)
3090 break;
3091 ret_val = e1000_write_phy_reg(hw, 30, 0x0000);
3092 if (ret_val)
3093 break;
3094 ret_val = E1000_SUCCESS;
3095 } while (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003096
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003097 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003098}
3099
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003100/**
3101 * e1000_phy_igp_get_info - get igp specific registers
3102 * @hw: Struct containing variables accessed by shared code
3103 * @phy_info: PHY information structure
3104 *
3105 * Get PHY information from various PHY registers for igp PHY only.
3106 */
Joe Perches64798842008-07-11 15:17:02 -07003107static s32 e1000_phy_igp_get_info(struct e1000_hw *hw,
3108 struct e1000_phy_info *phy_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003109{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003110 s32 ret_val;
3111 u16 phy_data, min_length, max_length, average;
3112 e1000_rev_polarity polarity;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003113
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003114 DEBUGFUNC("e1000_phy_igp_get_info");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003115
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003116 /* The downshift status is checked only once, after link is established,
3117 * and it stored in the hw->speed_downgraded parameter. */
3118 phy_info->downshift = (e1000_downshift) hw->speed_downgraded;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003119
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003120 /* IGP01E1000 does not need to support it. */
3121 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003122
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003123 /* IGP01E1000 always correct polarity reversal */
3124 phy_info->polarity_correction = e1000_polarity_reversal_enabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003125
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003126 /* Check polarity status */
3127 ret_val = e1000_check_polarity(hw, &polarity);
3128 if (ret_val)
3129 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003130
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003131 phy_info->cable_polarity = polarity;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003132
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003133 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, &phy_data);
3134 if (ret_val)
3135 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003136
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003137 phy_info->mdix_mode =
3138 (e1000_auto_x_mode) ((phy_data & IGP01E1000_PSSR_MDIX) >>
3139 IGP01E1000_PSSR_MDIX_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003140
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003141 if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
3142 IGP01E1000_PSSR_SPEED_1000MBPS) {
3143 /* Local/Remote Receiver Information are only valid at 1000 Mbps */
3144 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
3145 if (ret_val)
3146 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003147
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003148 phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
3149 SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
3150 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
3151 phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
3152 SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
3153 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003154
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003155 /* Get cable length */
3156 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
3157 if (ret_val)
3158 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003159
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003160 /* Translate to old method */
3161 average = (max_length + min_length) / 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003162
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003163 if (average <= e1000_igp_cable_length_50)
3164 phy_info->cable_length = e1000_cable_length_50;
3165 else if (average <= e1000_igp_cable_length_80)
3166 phy_info->cable_length = e1000_cable_length_50_80;
3167 else if (average <= e1000_igp_cable_length_110)
3168 phy_info->cable_length = e1000_cable_length_80_110;
3169 else if (average <= e1000_igp_cable_length_140)
3170 phy_info->cable_length = e1000_cable_length_110_140;
3171 else
3172 phy_info->cable_length = e1000_cable_length_140;
3173 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003174
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003175 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003176}
3177
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003178/**
3179 * e1000_phy_m88_get_info - get m88 specific registers
3180 * @hw: Struct containing variables accessed by shared code
3181 * @phy_info: PHY information structure
3182 *
3183 * Get PHY information from various PHY registers for m88 PHY only.
3184 */
Joe Perches64798842008-07-11 15:17:02 -07003185static s32 e1000_phy_m88_get_info(struct e1000_hw *hw,
3186 struct e1000_phy_info *phy_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003187{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003188 s32 ret_val;
3189 u16 phy_data;
3190 e1000_rev_polarity polarity;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003191
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003192 DEBUGFUNC("e1000_phy_m88_get_info");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003193
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003194 /* The downshift status is checked only once, after link is established,
3195 * and it stored in the hw->speed_downgraded parameter. */
3196 phy_info->downshift = (e1000_downshift) hw->speed_downgraded;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003197
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003198 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
3199 if (ret_val)
3200 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003201
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003202 phy_info->extended_10bt_distance =
3203 ((phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >>
3204 M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT) ?
3205 e1000_10bt_ext_dist_enable_lower :
3206 e1000_10bt_ext_dist_enable_normal;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07003207
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003208 phy_info->polarity_correction =
3209 ((phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >>
3210 M88E1000_PSCR_POLARITY_REVERSAL_SHIFT) ?
3211 e1000_polarity_reversal_disabled : e1000_polarity_reversal_enabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003212
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003213 /* Check polarity status */
3214 ret_val = e1000_check_polarity(hw, &polarity);
3215 if (ret_val)
3216 return ret_val;
3217 phy_info->cable_polarity = polarity;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003218
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003219 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
3220 if (ret_val)
3221 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003222
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003223 phy_info->mdix_mode =
3224 (e1000_auto_x_mode) ((phy_data & M88E1000_PSSR_MDIX) >>
3225 M88E1000_PSSR_MDIX_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003226
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003227 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
3228 /* Cable Length Estimation and Local/Remote Receiver Information
3229 * are only valid at 1000 Mbps.
3230 */
3231 phy_info->cable_length =
3232 (e1000_cable_length) ((phy_data &
3233 M88E1000_PSSR_CABLE_LENGTH) >>
3234 M88E1000_PSSR_CABLE_LENGTH_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003235
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003236 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
3237 if (ret_val)
3238 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003239
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003240 phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
3241 SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
3242 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
3243 phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
3244 SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
3245 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003246
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003247 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003248
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003249 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003250}
3251
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003252/**
3253 * e1000_phy_get_info - request phy info
3254 * @hw: Struct containing variables accessed by shared code
3255 * @phy_info: PHY information structure
3256 *
3257 * Get PHY information from various PHY registers
3258 */
Joe Perches64798842008-07-11 15:17:02 -07003259s32 e1000_phy_get_info(struct e1000_hw *hw, struct e1000_phy_info *phy_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003260{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003261 s32 ret_val;
3262 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003263
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003264 DEBUGFUNC("e1000_phy_get_info");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003265
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003266 phy_info->cable_length = e1000_cable_length_undefined;
3267 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined;
3268 phy_info->cable_polarity = e1000_rev_polarity_undefined;
3269 phy_info->downshift = e1000_downshift_undefined;
3270 phy_info->polarity_correction = e1000_polarity_reversal_undefined;
3271 phy_info->mdix_mode = e1000_auto_x_mode_undefined;
3272 phy_info->local_rx = e1000_1000t_rx_status_undefined;
3273 phy_info->remote_rx = e1000_1000t_rx_status_undefined;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003274
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003275 if (hw->media_type != e1000_media_type_copper) {
3276 DEBUGOUT("PHY info is only valid for copper media\n");
3277 return -E1000_ERR_CONFIG;
3278 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003279
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003280 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3281 if (ret_val)
3282 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003283
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003284 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3285 if (ret_val)
3286 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003287
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003288 if ((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) {
3289 DEBUGOUT("PHY info is only valid if link is up\n");
3290 return -E1000_ERR_CONFIG;
3291 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003292
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003293 if (hw->phy_type == e1000_phy_igp)
3294 return e1000_phy_igp_get_info(hw, phy_info);
3295 else
3296 return e1000_phy_m88_get_info(hw, phy_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003297}
3298
Joe Perches64798842008-07-11 15:17:02 -07003299s32 e1000_validate_mdi_setting(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003300{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003301 DEBUGFUNC("e1000_validate_mdi_settings");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003302
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003303 if (!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) {
3304 DEBUGOUT("Invalid MDI setting detected\n");
3305 hw->mdix = 1;
3306 return -E1000_ERR_CONFIG;
3307 }
3308 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003309}
3310
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003311/**
3312 * e1000_init_eeprom_params - initialize sw eeprom vars
3313 * @hw: Struct containing variables accessed by shared code
3314 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07003315 * Sets up eeprom variables in the hw struct. Must be called after mac_type
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00003316 * is configured.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003317 */
Joe Perches64798842008-07-11 15:17:02 -07003318s32 e1000_init_eeprom_params(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003319{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003320 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3321 u32 eecd = er32(EECD);
3322 s32 ret_val = E1000_SUCCESS;
3323 u16 eeprom_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003324
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003325 DEBUGFUNC("e1000_init_eeprom_params");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003326
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003327 switch (hw->mac_type) {
3328 case e1000_82542_rev2_0:
3329 case e1000_82542_rev2_1:
3330 case e1000_82543:
3331 case e1000_82544:
3332 eeprom->type = e1000_eeprom_microwire;
3333 eeprom->word_size = 64;
3334 eeprom->opcode_bits = 3;
3335 eeprom->address_bits = 6;
3336 eeprom->delay_usec = 50;
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003337 break;
3338 case e1000_82540:
3339 case e1000_82545:
3340 case e1000_82545_rev_3:
3341 case e1000_82546:
3342 case e1000_82546_rev_3:
3343 eeprom->type = e1000_eeprom_microwire;
3344 eeprom->opcode_bits = 3;
3345 eeprom->delay_usec = 50;
3346 if (eecd & E1000_EECD_SIZE) {
3347 eeprom->word_size = 256;
3348 eeprom->address_bits = 8;
3349 } else {
3350 eeprom->word_size = 64;
3351 eeprom->address_bits = 6;
3352 }
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003353 break;
3354 case e1000_82541:
3355 case e1000_82541_rev_2:
3356 case e1000_82547:
3357 case e1000_82547_rev_2:
3358 if (eecd & E1000_EECD_TYPE) {
3359 eeprom->type = e1000_eeprom_spi;
3360 eeprom->opcode_bits = 8;
3361 eeprom->delay_usec = 1;
3362 if (eecd & E1000_EECD_ADDR_BITS) {
3363 eeprom->page_size = 32;
3364 eeprom->address_bits = 16;
3365 } else {
3366 eeprom->page_size = 8;
3367 eeprom->address_bits = 8;
3368 }
3369 } else {
3370 eeprom->type = e1000_eeprom_microwire;
3371 eeprom->opcode_bits = 3;
3372 eeprom->delay_usec = 50;
3373 if (eecd & E1000_EECD_ADDR_BITS) {
3374 eeprom->word_size = 256;
3375 eeprom->address_bits = 8;
3376 } else {
3377 eeprom->word_size = 64;
3378 eeprom->address_bits = 6;
3379 }
3380 }
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003381 break;
3382 default:
3383 break;
3384 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003385
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003386 if (eeprom->type == e1000_eeprom_spi) {
3387 /* eeprom_size will be an enum [0..8] that maps to eeprom sizes 128B to
3388 * 32KB (incremented by powers of 2).
3389 */
3390 /* Set to default value for initial eeprom read. */
3391 eeprom->word_size = 64;
3392 ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size);
3393 if (ret_val)
3394 return ret_val;
3395 eeprom_size =
3396 (eeprom_size & EEPROM_SIZE_MASK) >> EEPROM_SIZE_SHIFT;
3397 /* 256B eeprom size was not supported in earlier hardware, so we
3398 * bump eeprom_size up one to ensure that "1" (which maps to 256B)
3399 * is never the result used in the shifting logic below. */
3400 if (eeprom_size)
3401 eeprom_size++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003402
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003403 eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT);
3404 }
3405 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003406}
3407
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003408/**
3409 * e1000_raise_ee_clk - Raises the EEPROM's clock input.
3410 * @hw: Struct containing variables accessed by shared code
3411 * @eecd: EECD's current value
3412 */
Joe Perches64798842008-07-11 15:17:02 -07003413static void e1000_raise_ee_clk(struct e1000_hw *hw, u32 *eecd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003414{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003415 /* Raise the clock input to the EEPROM (by setting the SK bit), and then
3416 * wait <delay> microseconds.
3417 */
3418 *eecd = *eecd | E1000_EECD_SK;
3419 ew32(EECD, *eecd);
3420 E1000_WRITE_FLUSH();
3421 udelay(hw->eeprom.delay_usec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003422}
3423
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003424/**
3425 * e1000_lower_ee_clk - Lowers the EEPROM's clock input.
3426 * @hw: Struct containing variables accessed by shared code
3427 * @eecd: EECD's current value
3428 */
Joe Perches64798842008-07-11 15:17:02 -07003429static void e1000_lower_ee_clk(struct e1000_hw *hw, u32 *eecd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003430{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003431 /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
3432 * wait 50 microseconds.
3433 */
3434 *eecd = *eecd & ~E1000_EECD_SK;
3435 ew32(EECD, *eecd);
3436 E1000_WRITE_FLUSH();
3437 udelay(hw->eeprom.delay_usec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003438}
3439
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003440/**
3441 * e1000_shift_out_ee_bits - Shift data bits out to the EEPROM.
3442 * @hw: Struct containing variables accessed by shared code
3443 * @data: data to send to the EEPROM
3444 * @count: number of bits to shift out
3445 */
Joe Perches64798842008-07-11 15:17:02 -07003446static void e1000_shift_out_ee_bits(struct e1000_hw *hw, u16 data, u16 count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003447{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003448 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3449 u32 eecd;
3450 u32 mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003451
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003452 /* We need to shift "count" bits out to the EEPROM. So, value in the
3453 * "data" parameter will be shifted out to the EEPROM one bit at a time.
3454 * In order to do this, "data" must be broken down into bits.
3455 */
3456 mask = 0x01 << (count - 1);
3457 eecd = er32(EECD);
3458 if (eeprom->type == e1000_eeprom_microwire) {
3459 eecd &= ~E1000_EECD_DO;
3460 } else if (eeprom->type == e1000_eeprom_spi) {
3461 eecd |= E1000_EECD_DO;
3462 }
3463 do {
3464 /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
3465 * and then raising and then lowering the clock (the SK bit controls
3466 * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
3467 * by setting "DI" to "0" and then raising and then lowering the clock.
3468 */
3469 eecd &= ~E1000_EECD_DI;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003470
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003471 if (data & mask)
3472 eecd |= E1000_EECD_DI;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003473
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003474 ew32(EECD, eecd);
3475 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003476
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003477 udelay(eeprom->delay_usec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003478
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003479 e1000_raise_ee_clk(hw, &eecd);
3480 e1000_lower_ee_clk(hw, &eecd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003481
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003482 mask = mask >> 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003483
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003484 } while (mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003485
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003486 /* We leave the "DI" bit set to "0" when we leave this routine. */
3487 eecd &= ~E1000_EECD_DI;
3488 ew32(EECD, eecd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003489}
3490
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003491/**
3492 * e1000_shift_in_ee_bits - Shift data bits in from the EEPROM
3493 * @hw: Struct containing variables accessed by shared code
3494 * @count: number of bits to shift in
3495 */
Joe Perches64798842008-07-11 15:17:02 -07003496static u16 e1000_shift_in_ee_bits(struct e1000_hw *hw, u16 count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003497{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003498 u32 eecd;
3499 u32 i;
3500 u16 data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003501
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003502 /* In order to read a register from the EEPROM, we need to shift 'count'
3503 * bits in from the EEPROM. Bits are "shifted in" by raising the clock
3504 * input to the EEPROM (setting the SK bit), and then reading the value of
3505 * the "DO" bit. During this "shifting in" process the "DI" bit should
3506 * always be clear.
3507 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003508
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003509 eecd = er32(EECD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003510
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003511 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
3512 data = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003513
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003514 for (i = 0; i < count; i++) {
3515 data = data << 1;
3516 e1000_raise_ee_clk(hw, &eecd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003517
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003518 eecd = er32(EECD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003519
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003520 eecd &= ~(E1000_EECD_DI);
3521 if (eecd & E1000_EECD_DO)
3522 data |= 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003523
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003524 e1000_lower_ee_clk(hw, &eecd);
3525 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003526
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003527 return data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003528}
3529
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003530/**
3531 * e1000_acquire_eeprom - Prepares EEPROM for access
3532 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -07003533 *
3534 * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
3535 * function should be called before issuing a command to the EEPROM.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003536 */
Joe Perches64798842008-07-11 15:17:02 -07003537static s32 e1000_acquire_eeprom(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003538{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003539 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3540 u32 eecd, i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003541
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003542 DEBUGFUNC("e1000_acquire_eeprom");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003543
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003544 eecd = er32(EECD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003545
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003546 /* Request EEPROM Access */
3547 if (hw->mac_type > e1000_82544) {
3548 eecd |= E1000_EECD_REQ;
3549 ew32(EECD, eecd);
3550 eecd = er32(EECD);
3551 while ((!(eecd & E1000_EECD_GNT)) &&
3552 (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
3553 i++;
3554 udelay(5);
3555 eecd = er32(EECD);
3556 }
3557 if (!(eecd & E1000_EECD_GNT)) {
3558 eecd &= ~E1000_EECD_REQ;
3559 ew32(EECD, eecd);
3560 DEBUGOUT("Could not acquire EEPROM grant\n");
3561 return -E1000_ERR_EEPROM;
3562 }
3563 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003564
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003565 /* Setup EEPROM for Read/Write */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003566
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003567 if (eeprom->type == e1000_eeprom_microwire) {
3568 /* Clear SK and DI */
3569 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
3570 ew32(EECD, eecd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003571
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003572 /* Set CS */
3573 eecd |= E1000_EECD_CS;
3574 ew32(EECD, eecd);
3575 } else if (eeprom->type == e1000_eeprom_spi) {
3576 /* Clear SK and CS */
3577 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
3578 ew32(EECD, eecd);
3579 udelay(1);
3580 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003581
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003582 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003583}
3584
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003585/**
3586 * e1000_standby_eeprom - Returns EEPROM to a "standby" state
3587 * @hw: Struct containing variables accessed by shared code
3588 */
Joe Perches64798842008-07-11 15:17:02 -07003589static void e1000_standby_eeprom(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003590{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003591 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3592 u32 eecd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003593
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003594 eecd = er32(EECD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003595
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003596 if (eeprom->type == e1000_eeprom_microwire) {
3597 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
3598 ew32(EECD, eecd);
3599 E1000_WRITE_FLUSH();
3600 udelay(eeprom->delay_usec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003601
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003602 /* Clock high */
3603 eecd |= E1000_EECD_SK;
3604 ew32(EECD, eecd);
3605 E1000_WRITE_FLUSH();
3606 udelay(eeprom->delay_usec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003607
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003608 /* Select EEPROM */
3609 eecd |= E1000_EECD_CS;
3610 ew32(EECD, eecd);
3611 E1000_WRITE_FLUSH();
3612 udelay(eeprom->delay_usec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003613
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003614 /* Clock low */
3615 eecd &= ~E1000_EECD_SK;
3616 ew32(EECD, eecd);
3617 E1000_WRITE_FLUSH();
3618 udelay(eeprom->delay_usec);
3619 } else if (eeprom->type == e1000_eeprom_spi) {
3620 /* Toggle CS to flush commands */
3621 eecd |= E1000_EECD_CS;
3622 ew32(EECD, eecd);
3623 E1000_WRITE_FLUSH();
3624 udelay(eeprom->delay_usec);
3625 eecd &= ~E1000_EECD_CS;
3626 ew32(EECD, eecd);
3627 E1000_WRITE_FLUSH();
3628 udelay(eeprom->delay_usec);
3629 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003630}
3631
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003632/**
3633 * e1000_release_eeprom - drop chip select
3634 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -07003635 *
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003636 * Terminates a command by inverting the EEPROM's chip select pin
3637 */
Joe Perches64798842008-07-11 15:17:02 -07003638static void e1000_release_eeprom(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003639{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003640 u32 eecd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003641
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003642 DEBUGFUNC("e1000_release_eeprom");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003643
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003644 eecd = er32(EECD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003645
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003646 if (hw->eeprom.type == e1000_eeprom_spi) {
3647 eecd |= E1000_EECD_CS; /* Pull CS high */
3648 eecd &= ~E1000_EECD_SK; /* Lower SCK */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003649
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003650 ew32(EECD, eecd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003651
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003652 udelay(hw->eeprom.delay_usec);
3653 } else if (hw->eeprom.type == e1000_eeprom_microwire) {
3654 /* cleanup eeprom */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003655
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003656 /* CS on Microwire is active-high */
3657 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003658
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003659 ew32(EECD, eecd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003660
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003661 /* Rising edge of clock */
3662 eecd |= E1000_EECD_SK;
3663 ew32(EECD, eecd);
3664 E1000_WRITE_FLUSH();
3665 udelay(hw->eeprom.delay_usec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003666
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003667 /* Falling edge of clock */
3668 eecd &= ~E1000_EECD_SK;
3669 ew32(EECD, eecd);
3670 E1000_WRITE_FLUSH();
3671 udelay(hw->eeprom.delay_usec);
3672 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003673
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003674 /* Stop requesting EEPROM access */
3675 if (hw->mac_type > e1000_82544) {
3676 eecd &= ~E1000_EECD_REQ;
3677 ew32(EECD, eecd);
3678 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003679}
3680
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003681/**
3682 * e1000_spi_eeprom_ready - Reads a 16 bit word from the EEPROM.
3683 * @hw: Struct containing variables accessed by shared code
3684 */
Joe Perches64798842008-07-11 15:17:02 -07003685static s32 e1000_spi_eeprom_ready(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003686{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003687 u16 retry_count = 0;
3688 u8 spi_stat_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003689
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003690 DEBUGFUNC("e1000_spi_eeprom_ready");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003691
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003692 /* Read "Status Register" repeatedly until the LSB is cleared. The
3693 * EEPROM will signal that the command has been completed by clearing
3694 * bit 0 of the internal status register. If it's not cleared within
3695 * 5 milliseconds, then error out.
3696 */
3697 retry_count = 0;
3698 do {
3699 e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
3700 hw->eeprom.opcode_bits);
3701 spi_stat_reg = (u8) e1000_shift_in_ee_bits(hw, 8);
3702 if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
3703 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003704
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003705 udelay(5);
3706 retry_count += 5;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003707
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003708 e1000_standby_eeprom(hw);
3709 } while (retry_count < EEPROM_MAX_RETRY_SPI);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003710
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003711 /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
3712 * only 0-5mSec on 5V devices)
3713 */
3714 if (retry_count >= EEPROM_MAX_RETRY_SPI) {
3715 DEBUGOUT("SPI EEPROM Status error\n");
3716 return -E1000_ERR_EEPROM;
3717 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003718
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003719 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003720}
3721
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003722/**
3723 * e1000_read_eeprom - Reads a 16 bit word from the EEPROM.
3724 * @hw: Struct containing variables accessed by shared code
3725 * @offset: offset of word in the EEPROM to read
3726 * @data: word read from the EEPROM
3727 * @words: number of words to read
3728 */
Joe Perches64798842008-07-11 15:17:02 -07003729s32 e1000_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003730{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003731 s32 ret;
3732 spin_lock(&e1000_eeprom_lock);
3733 ret = e1000_do_read_eeprom(hw, offset, words, data);
3734 spin_unlock(&e1000_eeprom_lock);
3735 return ret;
Christopher Li78566fe2008-09-05 14:04:05 -07003736}
3737
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003738static s32 e1000_do_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words,
3739 u16 *data)
Christopher Li78566fe2008-09-05 14:04:05 -07003740{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003741 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3742 u32 i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003743
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003744 DEBUGFUNC("e1000_read_eeprom");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003745
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003746 /* If eeprom is not yet detected, do so now */
3747 if (eeprom->word_size == 0)
3748 e1000_init_eeprom_params(hw);
Jeff Kirsher2a88c172006-09-27 12:54:05 -07003749
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003750 /* A check for invalid values: offset too large, too many words, and not
3751 * enough words.
3752 */
3753 if ((offset >= eeprom->word_size)
3754 || (words > eeprom->word_size - offset) || (words == 0)) {
3755 DEBUGOUT2
3756 ("\"words\" parameter out of bounds. Words = %d, size = %d\n",
3757 offset, eeprom->word_size);
3758 return -E1000_ERR_EEPROM;
3759 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003760
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003761 /* EEPROM's that don't use EERD to read require us to bit-bang the SPI
3762 * directly. In this case, we need to acquire the EEPROM so that
3763 * FW or other port software does not interrupt.
3764 */
Jesse Brandeburg8f601b22009-09-25 12:20:11 +00003765 /* Prepare the EEPROM for bit-bang reading */
3766 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
3767 return -E1000_ERR_EEPROM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003768
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003769 /* Set up the SPI or Microwire EEPROM for bit-bang reading. We have
3770 * acquired the EEPROM at this point, so any returns should release it */
3771 if (eeprom->type == e1000_eeprom_spi) {
3772 u16 word_in;
3773 u8 read_opcode = EEPROM_READ_OPCODE_SPI;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003774
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003775 if (e1000_spi_eeprom_ready(hw)) {
3776 e1000_release_eeprom(hw);
3777 return -E1000_ERR_EEPROM;
3778 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003779
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003780 e1000_standby_eeprom(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003781
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003782 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
3783 if ((eeprom->address_bits == 8) && (offset >= 128))
3784 read_opcode |= EEPROM_A8_OPCODE_SPI;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003785
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003786 /* Send the READ command (opcode + addr) */
3787 e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
3788 e1000_shift_out_ee_bits(hw, (u16) (offset * 2),
3789 eeprom->address_bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003790
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003791 /* Read the data. The address of the eeprom internally increments with
3792 * each byte (spi) being read, saving on the overhead of eeprom setup
3793 * and tear-down. The address counter will roll over if reading beyond
3794 * the size of the eeprom, thus allowing the entire memory to be read
3795 * starting from any offset. */
3796 for (i = 0; i < words; i++) {
3797 word_in = e1000_shift_in_ee_bits(hw, 16);
3798 data[i] = (word_in >> 8) | (word_in << 8);
3799 }
3800 } else if (eeprom->type == e1000_eeprom_microwire) {
3801 for (i = 0; i < words; i++) {
3802 /* Send the READ command (opcode + addr) */
3803 e1000_shift_out_ee_bits(hw,
3804 EEPROM_READ_OPCODE_MICROWIRE,
3805 eeprom->opcode_bits);
3806 e1000_shift_out_ee_bits(hw, (u16) (offset + i),
3807 eeprom->address_bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003808
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003809 /* Read the data. For microwire, each word requires the overhead
3810 * of eeprom setup and tear-down. */
3811 data[i] = e1000_shift_in_ee_bits(hw, 16);
3812 e1000_standby_eeprom(hw);
3813 }
3814 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003815
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003816 /* End this read operation */
3817 e1000_release_eeprom(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003818
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003819 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003820}
3821
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003822/**
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003823 * e1000_validate_eeprom_checksum - Verifies that the EEPROM has a valid checksum
3824 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -07003825 *
3826 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
3827 * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
3828 * valid.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003829 */
Joe Perches64798842008-07-11 15:17:02 -07003830s32 e1000_validate_eeprom_checksum(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003831{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003832 u16 checksum = 0;
3833 u16 i, eeprom_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003834
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003835 DEBUGFUNC("e1000_validate_eeprom_checksum");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003836
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003837 for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
3838 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
3839 DEBUGOUT("EEPROM Read Error\n");
3840 return -E1000_ERR_EEPROM;
3841 }
3842 checksum += eeprom_data;
3843 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003844
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003845 if (checksum == (u16) EEPROM_SUM)
3846 return E1000_SUCCESS;
3847 else {
3848 DEBUGOUT("EEPROM Checksum Invalid\n");
3849 return -E1000_ERR_EEPROM;
3850 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003851}
3852
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003853/**
3854 * e1000_update_eeprom_checksum - Calculates/writes the EEPROM checksum
3855 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -07003856 *
3857 * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA.
3858 * Writes the difference to word offset 63 of the EEPROM.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003859 */
Joe Perches64798842008-07-11 15:17:02 -07003860s32 e1000_update_eeprom_checksum(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003861{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003862 u16 checksum = 0;
3863 u16 i, eeprom_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003864
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003865 DEBUGFUNC("e1000_update_eeprom_checksum");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003866
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003867 for (i = 0; i < EEPROM_CHECKSUM_REG; i++) {
3868 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
3869 DEBUGOUT("EEPROM Read Error\n");
3870 return -E1000_ERR_EEPROM;
3871 }
3872 checksum += eeprom_data;
3873 }
3874 checksum = (u16) EEPROM_SUM - checksum;
3875 if (e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) {
3876 DEBUGOUT("EEPROM Write Error\n");
3877 return -E1000_ERR_EEPROM;
3878 }
3879 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003880}
3881
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003882/**
3883 * e1000_write_eeprom - write words to the different EEPROM types.
3884 * @hw: Struct containing variables accessed by shared code
3885 * @offset: offset within the EEPROM to be written to
3886 * @words: number of words to write
3887 * @data: 16 bit word to be written to the EEPROM
Linus Torvalds1da177e2005-04-16 15:20:36 -07003888 *
3889 * If e1000_update_eeprom_checksum is not called after this function, the
3890 * EEPROM will most likely contain an invalid checksum.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003891 */
Joe Perches64798842008-07-11 15:17:02 -07003892s32 e1000_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003893{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003894 s32 ret;
3895 spin_lock(&e1000_eeprom_lock);
3896 ret = e1000_do_write_eeprom(hw, offset, words, data);
3897 spin_unlock(&e1000_eeprom_lock);
3898 return ret;
Christopher Li78566fe2008-09-05 14:04:05 -07003899}
3900
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003901static s32 e1000_do_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words,
3902 u16 *data)
Christopher Li78566fe2008-09-05 14:04:05 -07003903{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003904 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3905 s32 status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003906
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003907 DEBUGFUNC("e1000_write_eeprom");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003908
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003909 /* If eeprom is not yet detected, do so now */
3910 if (eeprom->word_size == 0)
3911 e1000_init_eeprom_params(hw);
Jeff Kirsher2a88c172006-09-27 12:54:05 -07003912
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003913 /* A check for invalid values: offset too large, too many words, and not
3914 * enough words.
3915 */
3916 if ((offset >= eeprom->word_size)
3917 || (words > eeprom->word_size - offset) || (words == 0)) {
3918 DEBUGOUT("\"words\" parameter out of bounds\n");
3919 return -E1000_ERR_EEPROM;
3920 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003921
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003922 /* Prepare the EEPROM for writing */
3923 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
3924 return -E1000_ERR_EEPROM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003925
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003926 if (eeprom->type == e1000_eeprom_microwire) {
3927 status = e1000_write_eeprom_microwire(hw, offset, words, data);
3928 } else {
3929 status = e1000_write_eeprom_spi(hw, offset, words, data);
3930 msleep(10);
3931 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003932
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003933 /* Done with writing */
3934 e1000_release_eeprom(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003935
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003936 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003937}
3938
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003939/**
3940 * e1000_write_eeprom_spi - Writes a 16 bit word to a given offset in an SPI EEPROM.
3941 * @hw: Struct containing variables accessed by shared code
3942 * @offset: offset within the EEPROM to be written to
3943 * @words: number of words to write
3944 * @data: pointer to array of 8 bit words to be written to the EEPROM
3945 */
Joe Perches64798842008-07-11 15:17:02 -07003946static s32 e1000_write_eeprom_spi(struct e1000_hw *hw, u16 offset, u16 words,
3947 u16 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003948{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003949 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3950 u16 widx = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003951
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003952 DEBUGFUNC("e1000_write_eeprom_spi");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003953
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003954 while (widx < words) {
3955 u8 write_opcode = EEPROM_WRITE_OPCODE_SPI;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003956
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003957 if (e1000_spi_eeprom_ready(hw))
3958 return -E1000_ERR_EEPROM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003959
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003960 e1000_standby_eeprom(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003961
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003962 /* Send the WRITE ENABLE command (8 bit opcode ) */
3963 e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI,
3964 eeprom->opcode_bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003965
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003966 e1000_standby_eeprom(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003967
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003968 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
3969 if ((eeprom->address_bits == 8) && (offset >= 128))
3970 write_opcode |= EEPROM_A8_OPCODE_SPI;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003971
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003972 /* Send the Write command (8-bit opcode + addr) */
3973 e1000_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003974
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003975 e1000_shift_out_ee_bits(hw, (u16) ((offset + widx) * 2),
3976 eeprom->address_bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003977
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003978 /* Send the data */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003979
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003980 /* Loop to allow for up to whole page write (32 bytes) of eeprom */
3981 while (widx < words) {
3982 u16 word_out = data[widx];
3983 word_out = (word_out >> 8) | (word_out << 8);
3984 e1000_shift_out_ee_bits(hw, word_out, 16);
3985 widx++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003986
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003987 /* Some larger eeprom sizes are capable of a 32-byte PAGE WRITE
3988 * operation, while the smaller eeproms are capable of an 8-byte
3989 * PAGE WRITE operation. Break the inner loop to pass new address
3990 */
3991 if ((((offset + widx) * 2) % eeprom->page_size) == 0) {
3992 e1000_standby_eeprom(hw);
3993 break;
3994 }
3995 }
3996 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003997
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003998 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003999}
4000
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004001/**
4002 * e1000_write_eeprom_microwire - Writes a 16 bit word to a given offset in a Microwire EEPROM.
4003 * @hw: Struct containing variables accessed by shared code
4004 * @offset: offset within the EEPROM to be written to
4005 * @words: number of words to write
4006 * @data: pointer to array of 8 bit words to be written to the EEPROM
4007 */
Joe Perches64798842008-07-11 15:17:02 -07004008static s32 e1000_write_eeprom_microwire(struct e1000_hw *hw, u16 offset,
4009 u16 words, u16 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004010{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004011 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4012 u32 eecd;
4013 u16 words_written = 0;
4014 u16 i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004015
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004016 DEBUGFUNC("e1000_write_eeprom_microwire");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004017
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004018 /* Send the write enable command to the EEPROM (3-bit opcode plus
4019 * 6/8-bit dummy address beginning with 11). It's less work to include
4020 * the 11 of the dummy address as part of the opcode than it is to shift
4021 * it over the correct number of bits for the address. This puts the
4022 * EEPROM into write/erase mode.
4023 */
4024 e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE,
4025 (u16) (eeprom->opcode_bits + 2));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004026
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004027 e1000_shift_out_ee_bits(hw, 0, (u16) (eeprom->address_bits - 2));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004028
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004029 /* Prepare the EEPROM */
4030 e1000_standby_eeprom(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004031
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004032 while (words_written < words) {
4033 /* Send the Write command (3-bit opcode + addr) */
4034 e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE,
4035 eeprom->opcode_bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004036
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004037 e1000_shift_out_ee_bits(hw, (u16) (offset + words_written),
4038 eeprom->address_bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004039
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004040 /* Send the data */
4041 e1000_shift_out_ee_bits(hw, data[words_written], 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004042
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004043 /* Toggle the CS line. This in effect tells the EEPROM to execute
4044 * the previous command.
4045 */
4046 e1000_standby_eeprom(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004047
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004048 /* Read DO repeatedly until it is high (equal to '1'). The EEPROM will
4049 * signal that the command has been completed by raising the DO signal.
4050 * If DO does not go high in 10 milliseconds, then error out.
4051 */
4052 for (i = 0; i < 200; i++) {
4053 eecd = er32(EECD);
4054 if (eecd & E1000_EECD_DO)
4055 break;
4056 udelay(50);
4057 }
4058 if (i == 200) {
4059 DEBUGOUT("EEPROM Write did not complete\n");
4060 return -E1000_ERR_EEPROM;
4061 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004062
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004063 /* Recover from write */
4064 e1000_standby_eeprom(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004065
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004066 words_written++;
4067 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004068
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004069 /* Send the write disable command to the EEPROM (3-bit opcode plus
4070 * 6/8-bit dummy address beginning with 10). It's less work to include
4071 * the 10 of the dummy address as part of the opcode than it is to shift
4072 * it over the correct number of bits for the address. This takes the
4073 * EEPROM out of write/erase mode.
4074 */
4075 e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE,
4076 (u16) (eeprom->opcode_bits + 2));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004077
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004078 e1000_shift_out_ee_bits(hw, 0, (u16) (eeprom->address_bits - 2));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004079
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004080 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004081}
4082
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004083/**
4084 * e1000_read_mac_addr - read the adapters MAC from eeprom
4085 * @hw: Struct containing variables accessed by shared code
4086 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07004087 * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
4088 * second function of dual function devices
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004089 */
Joe Perches64798842008-07-11 15:17:02 -07004090s32 e1000_read_mac_addr(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004091{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004092 u16 offset;
4093 u16 eeprom_data, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004094
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004095 DEBUGFUNC("e1000_read_mac_addr");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004096
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004097 for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
4098 offset = i >> 1;
4099 if (e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
4100 DEBUGOUT("EEPROM Read Error\n");
4101 return -E1000_ERR_EEPROM;
4102 }
4103 hw->perm_mac_addr[i] = (u8) (eeprom_data & 0x00FF);
4104 hw->perm_mac_addr[i + 1] = (u8) (eeprom_data >> 8);
4105 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004106
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004107 switch (hw->mac_type) {
4108 default:
4109 break;
4110 case e1000_82546:
4111 case e1000_82546_rev_3:
4112 if (er32(STATUS) & E1000_STATUS_FUNC_1)
4113 hw->perm_mac_addr[5] ^= 0x01;
4114 break;
4115 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004116
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004117 for (i = 0; i < NODE_ADDRESS_SIZE; i++)
4118 hw->mac_addr[i] = hw->perm_mac_addr[i];
4119 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004120}
4121
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004122/**
4123 * e1000_init_rx_addrs - Initializes receive address filters.
4124 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -07004125 *
4126 * Places the MAC address in receive address register 0 and clears the rest
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004127 * of the receive address registers. Clears the multicast table. Assumes
Linus Torvalds1da177e2005-04-16 15:20:36 -07004128 * the receiver is in reset when the routine is called.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004129 */
Joe Perches64798842008-07-11 15:17:02 -07004130static void e1000_init_rx_addrs(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004131{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004132 u32 i;
4133 u32 rar_num;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004134
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004135 DEBUGFUNC("e1000_init_rx_addrs");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004136
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004137 /* Setup the receive address. */
4138 DEBUGOUT("Programming MAC Address into RAR[0]\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004139
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004140 e1000_rar_set(hw, hw->mac_addr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004141
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004142 rar_num = E1000_RAR_ENTRIES;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004143
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004144 /* Zero out the other 15 receive addresses. */
4145 DEBUGOUT("Clearing RAR[1-15]\n");
4146 for (i = 1; i < rar_num; i++) {
4147 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
4148 E1000_WRITE_FLUSH();
4149 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
4150 E1000_WRITE_FLUSH();
4151 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004152}
4153
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004154/**
4155 * e1000_hash_mc_addr - Hashes an address to determine its location in the multicast table
4156 * @hw: Struct containing variables accessed by shared code
4157 * @mc_addr: the multicast address to hash
4158 */
Joe Perches64798842008-07-11 15:17:02 -07004159u32 e1000_hash_mc_addr(struct e1000_hw *hw, u8 *mc_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004160{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004161 u32 hash_value = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004162
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004163 /* The portion of the address that is used for the hash table is
4164 * determined by the mc_filter_type setting.
4165 */
4166 switch (hw->mc_filter_type) {
4167 /* [0] [1] [2] [3] [4] [5]
4168 * 01 AA 00 12 34 56
4169 * LSB MSB
4170 */
4171 case 0:
4172 /* [47:36] i.e. 0x563 for above example address */
4173 hash_value = ((mc_addr[4] >> 4) | (((u16) mc_addr[5]) << 4));
4174 break;
4175 case 1:
4176 /* [46:35] i.e. 0xAC6 for above example address */
4177 hash_value = ((mc_addr[4] >> 3) | (((u16) mc_addr[5]) << 5));
4178 break;
4179 case 2:
4180 /* [45:34] i.e. 0x5D8 for above example address */
4181 hash_value = ((mc_addr[4] >> 2) | (((u16) mc_addr[5]) << 6));
4182 break;
4183 case 3:
4184 /* [43:32] i.e. 0x634 for above example address */
4185 hash_value = ((mc_addr[4]) | (((u16) mc_addr[5]) << 8));
4186 break;
4187 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004188
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004189 hash_value &= 0xFFF;
4190 return hash_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004191}
4192
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004193/**
4194 * e1000_rar_set - Puts an ethernet address into a receive address register.
4195 * @hw: Struct containing variables accessed by shared code
4196 * @addr: Address to put into receive address register
4197 * @index: Receive address register to write
4198 */
Joe Perches64798842008-07-11 15:17:02 -07004199void e1000_rar_set(struct e1000_hw *hw, u8 *addr, u32 index)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004200{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004201 u32 rar_low, rar_high;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004202
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004203 /* HW expects these in little endian so we reverse the byte order
4204 * from network order (big endian) to little endian
4205 */
4206 rar_low = ((u32) addr[0] | ((u32) addr[1] << 8) |
4207 ((u32) addr[2] << 16) | ((u32) addr[3] << 24));
4208 rar_high = ((u32) addr[4] | ((u32) addr[5] << 8));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004209
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004210 /* Disable Rx and flush all Rx frames before enabling RSS to avoid Rx
4211 * unit hang.
4212 *
4213 * Description:
4214 * If there are any Rx frames queued up or otherwise present in the HW
4215 * before RSS is enabled, and then we enable RSS, the HW Rx unit will
4216 * hang. To work around this issue, we have to disable receives and
4217 * flush out all Rx frames before we enable RSS. To do so, we modify we
4218 * redirect all Rx traffic to manageability and then reset the HW.
4219 * This flushes away Rx frames, and (since the redirections to
4220 * manageability persists across resets) keeps new ones from coming in
4221 * while we work. Then, we clear the Address Valid AV bit for all MAC
4222 * addresses and undo the re-direction to manageability.
4223 * Now, frames are coming in again, but the MAC won't accept them, so
4224 * far so good. We now proceed to initialize RSS (if necessary) and
4225 * configure the Rx unit. Last, we re-enable the AV bits and continue
4226 * on our merry way.
4227 */
4228 switch (hw->mac_type) {
4229 default:
4230 /* Indicate to hardware the Address is Valid. */
4231 rar_high |= E1000_RAH_AV;
4232 break;
4233 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004234
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004235 E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
4236 E1000_WRITE_FLUSH();
4237 E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
4238 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07004239}
4240
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004241/**
4242 * e1000_write_vfta - Writes a value to the specified offset in the VLAN filter table.
4243 * @hw: Struct containing variables accessed by shared code
4244 * @offset: Offset in VLAN filer table to write
4245 * @value: Value to write into VLAN filter table
4246 */
Joe Perches64798842008-07-11 15:17:02 -07004247void e1000_write_vfta(struct e1000_hw *hw, u32 offset, u32 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004248{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004249 u32 temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004250
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004251 if ((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) {
4252 temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1));
4253 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
4254 E1000_WRITE_FLUSH();
4255 E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp);
4256 E1000_WRITE_FLUSH();
4257 } else {
4258 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
4259 E1000_WRITE_FLUSH();
4260 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004261}
4262
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004263/**
4264 * e1000_clear_vfta - Clears the VLAN filer table
4265 * @hw: Struct containing variables accessed by shared code
4266 */
Joe Perches64798842008-07-11 15:17:02 -07004267static void e1000_clear_vfta(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004268{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004269 u32 offset;
4270 u32 vfta_value = 0;
4271 u32 vfta_offset = 0;
4272 u32 vfta_bit_in_reg = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004273
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004274 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
4275 /* If the offset we want to clear is the same offset of the
4276 * manageability VLAN ID, then clear all bits except that of the
4277 * manageability unit */
4278 vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0;
4279 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, vfta_value);
4280 E1000_WRITE_FLUSH();
4281 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004282}
4283
Joe Perches64798842008-07-11 15:17:02 -07004284static s32 e1000_id_led_init(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004285{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004286 u32 ledctl;
4287 const u32 ledctl_mask = 0x000000FF;
4288 const u32 ledctl_on = E1000_LEDCTL_MODE_LED_ON;
4289 const u32 ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
4290 u16 eeprom_data, i, temp;
4291 const u16 led_mask = 0x0F;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004292
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004293 DEBUGFUNC("e1000_id_led_init");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004294
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004295 if (hw->mac_type < e1000_82540) {
4296 /* Nothing to do */
4297 return E1000_SUCCESS;
4298 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004299
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004300 ledctl = er32(LEDCTL);
4301 hw->ledctl_default = ledctl;
4302 hw->ledctl_mode1 = hw->ledctl_default;
4303 hw->ledctl_mode2 = hw->ledctl_default;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004304
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004305 if (e1000_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, 1, &eeprom_data) < 0) {
4306 DEBUGOUT("EEPROM Read Error\n");
4307 return -E1000_ERR_EEPROM;
4308 }
Auke Kokcd94dd02006-06-27 09:08:22 -07004309
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004310 if ((eeprom_data == ID_LED_RESERVED_0000) ||
4311 (eeprom_data == ID_LED_RESERVED_FFFF)) {
4312 eeprom_data = ID_LED_DEFAULT;
4313 }
Auke Kok90fb5132006-11-01 08:47:30 -08004314
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004315 for (i = 0; i < 4; i++) {
4316 temp = (eeprom_data >> (i << 2)) & led_mask;
4317 switch (temp) {
4318 case ID_LED_ON1_DEF2:
4319 case ID_LED_ON1_ON2:
4320 case ID_LED_ON1_OFF2:
4321 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
4322 hw->ledctl_mode1 |= ledctl_on << (i << 3);
4323 break;
4324 case ID_LED_OFF1_DEF2:
4325 case ID_LED_OFF1_ON2:
4326 case ID_LED_OFF1_OFF2:
4327 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
4328 hw->ledctl_mode1 |= ledctl_off << (i << 3);
4329 break;
4330 default:
4331 /* Do nothing */
4332 break;
4333 }
4334 switch (temp) {
4335 case ID_LED_DEF1_ON2:
4336 case ID_LED_ON1_ON2:
4337 case ID_LED_OFF1_ON2:
4338 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
4339 hw->ledctl_mode2 |= ledctl_on << (i << 3);
4340 break;
4341 case ID_LED_DEF1_OFF2:
4342 case ID_LED_ON1_OFF2:
4343 case ID_LED_OFF1_OFF2:
4344 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
4345 hw->ledctl_mode2 |= ledctl_off << (i << 3);
4346 break;
4347 default:
4348 /* Do nothing */
4349 break;
4350 }
4351 }
4352 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004353}
4354
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004355/**
4356 * e1000_setup_led
4357 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -07004358 *
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004359 * Prepares SW controlable LED for use and saves the current state of the LED.
4360 */
Joe Perches64798842008-07-11 15:17:02 -07004361s32 e1000_setup_led(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004362{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004363 u32 ledctl;
4364 s32 ret_val = E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004365
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004366 DEBUGFUNC("e1000_setup_led");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004367
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004368 switch (hw->mac_type) {
4369 case e1000_82542_rev2_0:
4370 case e1000_82542_rev2_1:
4371 case e1000_82543:
4372 case e1000_82544:
4373 /* No setup necessary */
4374 break;
4375 case e1000_82541:
4376 case e1000_82547:
4377 case e1000_82541_rev_2:
4378 case e1000_82547_rev_2:
4379 /* Turn off PHY Smart Power Down (if enabled) */
4380 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
4381 &hw->phy_spd_default);
4382 if (ret_val)
4383 return ret_val;
4384 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
4385 (u16) (hw->phy_spd_default &
4386 ~IGP01E1000_GMII_SPD));
4387 if (ret_val)
4388 return ret_val;
4389 /* Fall Through */
4390 default:
4391 if (hw->media_type == e1000_media_type_fiber) {
4392 ledctl = er32(LEDCTL);
4393 /* Save current LEDCTL settings */
4394 hw->ledctl_default = ledctl;
4395 /* Turn off LED0 */
4396 ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
4397 E1000_LEDCTL_LED0_BLINK |
4398 E1000_LEDCTL_LED0_MODE_MASK);
4399 ledctl |= (E1000_LEDCTL_MODE_LED_OFF <<
4400 E1000_LEDCTL_LED0_MODE_SHIFT);
4401 ew32(LEDCTL, ledctl);
4402 } else if (hw->media_type == e1000_media_type_copper)
4403 ew32(LEDCTL, hw->ledctl_mode1);
4404 break;
4405 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004406
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004407 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004408}
4409
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004410/**
4411 * e1000_cleanup_led - Restores the saved state of the SW controlable LED.
4412 * @hw: Struct containing variables accessed by shared code
4413 */
Joe Perches64798842008-07-11 15:17:02 -07004414s32 e1000_cleanup_led(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004415{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004416 s32 ret_val = E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004417
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004418 DEBUGFUNC("e1000_cleanup_led");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004419
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004420 switch (hw->mac_type) {
4421 case e1000_82542_rev2_0:
4422 case e1000_82542_rev2_1:
4423 case e1000_82543:
4424 case e1000_82544:
4425 /* No cleanup necessary */
4426 break;
4427 case e1000_82541:
4428 case e1000_82547:
4429 case e1000_82541_rev_2:
4430 case e1000_82547_rev_2:
4431 /* Turn on PHY Smart Power Down (if previously enabled) */
4432 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
4433 hw->phy_spd_default);
4434 if (ret_val)
4435 return ret_val;
4436 /* Fall Through */
4437 default:
4438 /* Restore LEDCTL settings */
4439 ew32(LEDCTL, hw->ledctl_default);
4440 break;
4441 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004442
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004443 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004444}
4445
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004446/**
4447 * e1000_led_on - Turns on the software controllable LED
4448 * @hw: Struct containing variables accessed by shared code
4449 */
Joe Perches64798842008-07-11 15:17:02 -07004450s32 e1000_led_on(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004451{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004452 u32 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004453
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004454 DEBUGFUNC("e1000_led_on");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004455
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004456 switch (hw->mac_type) {
4457 case e1000_82542_rev2_0:
4458 case e1000_82542_rev2_1:
4459 case e1000_82543:
4460 /* Set SW Defineable Pin 0 to turn on the LED */
4461 ctrl |= E1000_CTRL_SWDPIN0;
4462 ctrl |= E1000_CTRL_SWDPIO0;
4463 break;
4464 case e1000_82544:
4465 if (hw->media_type == e1000_media_type_fiber) {
4466 /* Set SW Defineable Pin 0 to turn on the LED */
4467 ctrl |= E1000_CTRL_SWDPIN0;
4468 ctrl |= E1000_CTRL_SWDPIO0;
4469 } else {
4470 /* Clear SW Defineable Pin 0 to turn on the LED */
4471 ctrl &= ~E1000_CTRL_SWDPIN0;
4472 ctrl |= E1000_CTRL_SWDPIO0;
4473 }
4474 break;
4475 default:
4476 if (hw->media_type == e1000_media_type_fiber) {
4477 /* Clear SW Defineable Pin 0 to turn on the LED */
4478 ctrl &= ~E1000_CTRL_SWDPIN0;
4479 ctrl |= E1000_CTRL_SWDPIO0;
4480 } else if (hw->media_type == e1000_media_type_copper) {
4481 ew32(LEDCTL, hw->ledctl_mode2);
4482 return E1000_SUCCESS;
4483 }
4484 break;
4485 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004486
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004487 ew32(CTRL, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004488
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004489 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004490}
4491
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004492/**
4493 * e1000_led_off - Turns off the software controllable LED
4494 * @hw: Struct containing variables accessed by shared code
4495 */
Joe Perches64798842008-07-11 15:17:02 -07004496s32 e1000_led_off(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004497{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004498 u32 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004499
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004500 DEBUGFUNC("e1000_led_off");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004501
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004502 switch (hw->mac_type) {
4503 case e1000_82542_rev2_0:
4504 case e1000_82542_rev2_1:
4505 case e1000_82543:
4506 /* Clear SW Defineable Pin 0 to turn off the LED */
4507 ctrl &= ~E1000_CTRL_SWDPIN0;
4508 ctrl |= E1000_CTRL_SWDPIO0;
4509 break;
4510 case e1000_82544:
4511 if (hw->media_type == e1000_media_type_fiber) {
4512 /* Clear SW Defineable Pin 0 to turn off the LED */
4513 ctrl &= ~E1000_CTRL_SWDPIN0;
4514 ctrl |= E1000_CTRL_SWDPIO0;
4515 } else {
4516 /* Set SW Defineable Pin 0 to turn off the LED */
4517 ctrl |= E1000_CTRL_SWDPIN0;
4518 ctrl |= E1000_CTRL_SWDPIO0;
4519 }
4520 break;
4521 default:
4522 if (hw->media_type == e1000_media_type_fiber) {
4523 /* Set SW Defineable Pin 0 to turn off the LED */
4524 ctrl |= E1000_CTRL_SWDPIN0;
4525 ctrl |= E1000_CTRL_SWDPIO0;
4526 } else if (hw->media_type == e1000_media_type_copper) {
4527 ew32(LEDCTL, hw->ledctl_mode1);
4528 return E1000_SUCCESS;
4529 }
4530 break;
4531 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004532
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004533 ew32(CTRL, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004534
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004535 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004536}
4537
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004538/**
4539 * e1000_clear_hw_cntrs - Clears all hardware statistics counters.
4540 * @hw: Struct containing variables accessed by shared code
4541 */
Joe Perches64798842008-07-11 15:17:02 -07004542static void e1000_clear_hw_cntrs(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004543{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004544 volatile u32 temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004545
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004546 temp = er32(CRCERRS);
4547 temp = er32(SYMERRS);
4548 temp = er32(MPC);
4549 temp = er32(SCC);
4550 temp = er32(ECOL);
4551 temp = er32(MCC);
4552 temp = er32(LATECOL);
4553 temp = er32(COLC);
4554 temp = er32(DC);
4555 temp = er32(SEC);
4556 temp = er32(RLEC);
4557 temp = er32(XONRXC);
4558 temp = er32(XONTXC);
4559 temp = er32(XOFFRXC);
4560 temp = er32(XOFFTXC);
4561 temp = er32(FCRUC);
Auke Kokcd94dd02006-06-27 09:08:22 -07004562
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004563 temp = er32(PRC64);
4564 temp = er32(PRC127);
4565 temp = er32(PRC255);
4566 temp = er32(PRC511);
4567 temp = er32(PRC1023);
4568 temp = er32(PRC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07004569
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004570 temp = er32(GPRC);
4571 temp = er32(BPRC);
4572 temp = er32(MPRC);
4573 temp = er32(GPTC);
4574 temp = er32(GORCL);
4575 temp = er32(GORCH);
4576 temp = er32(GOTCL);
4577 temp = er32(GOTCH);
4578 temp = er32(RNBC);
4579 temp = er32(RUC);
4580 temp = er32(RFC);
4581 temp = er32(ROC);
4582 temp = er32(RJC);
4583 temp = er32(TORL);
4584 temp = er32(TORH);
4585 temp = er32(TOTL);
4586 temp = er32(TOTH);
4587 temp = er32(TPR);
4588 temp = er32(TPT);
Auke Kokcd94dd02006-06-27 09:08:22 -07004589
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004590 temp = er32(PTC64);
4591 temp = er32(PTC127);
4592 temp = er32(PTC255);
4593 temp = er32(PTC511);
4594 temp = er32(PTC1023);
4595 temp = er32(PTC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07004596
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004597 temp = er32(MPTC);
4598 temp = er32(BPTC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004599
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004600 if (hw->mac_type < e1000_82543)
4601 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004602
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004603 temp = er32(ALGNERRC);
4604 temp = er32(RXERRC);
4605 temp = er32(TNCRS);
4606 temp = er32(CEXTERR);
4607 temp = er32(TSCTC);
4608 temp = er32(TSCTFC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004609
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004610 if (hw->mac_type <= e1000_82544)
4611 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004612
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004613 temp = er32(MGTPRC);
4614 temp = er32(MGTPDC);
4615 temp = er32(MGTPTC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004616}
4617
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004618/**
4619 * e1000_reset_adaptive - Resets Adaptive IFS to its default state.
4620 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -07004621 *
4622 * Call this after e1000_init_hw. You may override the IFS defaults by setting
Joe Perchesc3033b02008-03-21 11:06:25 -07004623 * hw->ifs_params_forced to true. However, you must initialize hw->
Linus Torvalds1da177e2005-04-16 15:20:36 -07004624 * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio
4625 * before calling this function.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004626 */
Joe Perches64798842008-07-11 15:17:02 -07004627void e1000_reset_adaptive(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004628{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004629 DEBUGFUNC("e1000_reset_adaptive");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004630
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004631 if (hw->adaptive_ifs) {
4632 if (!hw->ifs_params_forced) {
4633 hw->current_ifs_val = 0;
4634 hw->ifs_min_val = IFS_MIN;
4635 hw->ifs_max_val = IFS_MAX;
4636 hw->ifs_step_size = IFS_STEP;
4637 hw->ifs_ratio = IFS_RATIO;
4638 }
4639 hw->in_ifs_mode = false;
4640 ew32(AIT, 0);
4641 } else {
4642 DEBUGOUT("Not in Adaptive IFS mode!\n");
4643 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004644}
4645
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004646/**
4647 * e1000_update_adaptive - update adaptive IFS
4648 * @hw: Struct containing variables accessed by shared code
4649 * @tx_packets: Number of transmits since last callback
4650 * @total_collisions: Number of collisions since last callback
4651 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07004652 * Called during the callback/watchdog routine to update IFS value based on
4653 * the ratio of transmits to collisions.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004654 */
Joe Perches64798842008-07-11 15:17:02 -07004655void e1000_update_adaptive(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004656{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004657 DEBUGFUNC("e1000_update_adaptive");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004658
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004659 if (hw->adaptive_ifs) {
4660 if ((hw->collision_delta *hw->ifs_ratio) > hw->tx_packet_delta) {
4661 if (hw->tx_packet_delta > MIN_NUM_XMITS) {
4662 hw->in_ifs_mode = true;
4663 if (hw->current_ifs_val < hw->ifs_max_val) {
4664 if (hw->current_ifs_val == 0)
4665 hw->current_ifs_val =
4666 hw->ifs_min_val;
4667 else
4668 hw->current_ifs_val +=
4669 hw->ifs_step_size;
4670 ew32(AIT, hw->current_ifs_val);
4671 }
4672 }
4673 } else {
4674 if (hw->in_ifs_mode
4675 && (hw->tx_packet_delta <= MIN_NUM_XMITS)) {
4676 hw->current_ifs_val = 0;
4677 hw->in_ifs_mode = false;
4678 ew32(AIT, 0);
4679 }
4680 }
4681 } else {
4682 DEBUGOUT("Not in Adaptive IFS mode!\n");
4683 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004684}
4685
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004686/**
4687 * e1000_tbi_adjust_stats
4688 * @hw: Struct containing variables accessed by shared code
4689 * @frame_len: The length of the frame in question
4690 * @mac_addr: The Ethernet destination address of the frame in question
Linus Torvalds1da177e2005-04-16 15:20:36 -07004691 *
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004692 * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT
4693 */
Joe Perches64798842008-07-11 15:17:02 -07004694void e1000_tbi_adjust_stats(struct e1000_hw *hw, struct e1000_hw_stats *stats,
4695 u32 frame_len, u8 *mac_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004696{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004697 u64 carry_bit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004698
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004699 /* First adjust the frame length. */
4700 frame_len--;
4701 /* We need to adjust the statistics counters, since the hardware
4702 * counters overcount this packet as a CRC error and undercount
4703 * the packet as a good packet
4704 */
4705 /* This packet should not be counted as a CRC error. */
4706 stats->crcerrs--;
4707 /* This packet does count as a Good Packet Received. */
4708 stats->gprc++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004709
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004710 /* Adjust the Good Octets received counters */
4711 carry_bit = 0x80000000 & stats->gorcl;
4712 stats->gorcl += frame_len;
4713 /* If the high bit of Gorcl (the low 32 bits of the Good Octets
4714 * Received Count) was one before the addition,
4715 * AND it is zero after, then we lost the carry out,
4716 * need to add one to Gorch (Good Octets Received Count High).
4717 * This could be simplified if all environments supported
4718 * 64-bit integers.
4719 */
4720 if (carry_bit && ((stats->gorcl & 0x80000000) == 0))
4721 stats->gorch++;
4722 /* Is this a broadcast or multicast? Check broadcast first,
4723 * since the test for a multicast frame will test positive on
4724 * a broadcast frame.
4725 */
4726 if ((mac_addr[0] == (u8) 0xff) && (mac_addr[1] == (u8) 0xff))
4727 /* Broadcast packet */
4728 stats->bprc++;
4729 else if (*mac_addr & 0x01)
4730 /* Multicast packet */
4731 stats->mprc++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004732
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004733 if (frame_len == hw->max_frame_size) {
4734 /* In this case, the hardware has overcounted the number of
4735 * oversize frames.
4736 */
4737 if (stats->roc > 0)
4738 stats->roc--;
4739 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004740
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004741 /* Adjust the bin counters when the extra byte put the frame in the
4742 * wrong bin. Remember that the frame_len was adjusted above.
4743 */
4744 if (frame_len == 64) {
4745 stats->prc64++;
4746 stats->prc127--;
4747 } else if (frame_len == 127) {
4748 stats->prc127++;
4749 stats->prc255--;
4750 } else if (frame_len == 255) {
4751 stats->prc255++;
4752 stats->prc511--;
4753 } else if (frame_len == 511) {
4754 stats->prc511++;
4755 stats->prc1023--;
4756 } else if (frame_len == 1023) {
4757 stats->prc1023++;
4758 stats->prc1522--;
4759 } else if (frame_len == 1522) {
4760 stats->prc1522++;
4761 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004762}
4763
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004764/**
4765 * e1000_get_bus_info
4766 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -07004767 *
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004768 * Gets the current PCI bus type, speed, and width of the hardware
4769 */
Joe Perches64798842008-07-11 15:17:02 -07004770void e1000_get_bus_info(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004771{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004772 u32 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004773
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004774 switch (hw->mac_type) {
4775 case e1000_82542_rev2_0:
4776 case e1000_82542_rev2_1:
4777 hw->bus_type = e1000_bus_type_pci;
4778 hw->bus_speed = e1000_bus_speed_unknown;
4779 hw->bus_width = e1000_bus_width_unknown;
4780 break;
4781 default:
4782 status = er32(STATUS);
4783 hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
4784 e1000_bus_type_pcix : e1000_bus_type_pci;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004785
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004786 if (hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) {
4787 hw->bus_speed = (hw->bus_type == e1000_bus_type_pci) ?
4788 e1000_bus_speed_66 : e1000_bus_speed_120;
4789 } else if (hw->bus_type == e1000_bus_type_pci) {
4790 hw->bus_speed = (status & E1000_STATUS_PCI66) ?
4791 e1000_bus_speed_66 : e1000_bus_speed_33;
4792 } else {
4793 switch (status & E1000_STATUS_PCIX_SPEED) {
4794 case E1000_STATUS_PCIX_SPEED_66:
4795 hw->bus_speed = e1000_bus_speed_66;
4796 break;
4797 case E1000_STATUS_PCIX_SPEED_100:
4798 hw->bus_speed = e1000_bus_speed_100;
4799 break;
4800 case E1000_STATUS_PCIX_SPEED_133:
4801 hw->bus_speed = e1000_bus_speed_133;
4802 break;
4803 default:
4804 hw->bus_speed = e1000_bus_speed_reserved;
4805 break;
4806 }
4807 }
4808 hw->bus_width = (status & E1000_STATUS_BUS64) ?
4809 e1000_bus_width_64 : e1000_bus_width_32;
4810 break;
4811 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004812}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004813
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004814/**
4815 * e1000_write_reg_io
4816 * @hw: Struct containing variables accessed by shared code
4817 * @offset: offset to write to
4818 * @value: value to write
4819 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07004820 * Writes a value to one of the devices registers using port I/O (as opposed to
4821 * memory mapped I/O). Only 82544 and newer devices support port I/O.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004822 */
Joe Perches64798842008-07-11 15:17:02 -07004823static void e1000_write_reg_io(struct e1000_hw *hw, u32 offset, u32 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004824{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004825 unsigned long io_addr = hw->io_base;
4826 unsigned long io_data = hw->io_base + 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004827
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004828 e1000_io_write(hw, io_addr, offset);
4829 e1000_io_write(hw, io_data, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004830}
4831
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004832/**
4833 * e1000_get_cable_length - Estimates the cable length.
4834 * @hw: Struct containing variables accessed by shared code
4835 * @min_length: The estimated minimum length
4836 * @max_length: The estimated maximum length
Linus Torvalds1da177e2005-04-16 15:20:36 -07004837 *
4838 * returns: - E1000_ERR_XXX
4839 * E1000_SUCCESS
4840 *
4841 * This function always returns a ranged length (minimum & maximum).
4842 * So for M88 phy's, this function interprets the one value returned from the
4843 * register to the minimum and maximum range.
4844 * For IGP phy's, the function calculates the range by the AGC registers.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004845 */
Joe Perches64798842008-07-11 15:17:02 -07004846static s32 e1000_get_cable_length(struct e1000_hw *hw, u16 *min_length,
4847 u16 *max_length)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004848{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004849 s32 ret_val;
4850 u16 agc_value = 0;
4851 u16 i, phy_data;
4852 u16 cable_length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004853
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004854 DEBUGFUNC("e1000_get_cable_length");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004855
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004856 *min_length = *max_length = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004857
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004858 /* Use old method for Phy older than IGP */
4859 if (hw->phy_type == e1000_phy_m88) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004860
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004861 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
4862 &phy_data);
4863 if (ret_val)
4864 return ret_val;
4865 cable_length = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
4866 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004867
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004868 /* Convert the enum value to ranged values */
4869 switch (cable_length) {
4870 case e1000_cable_length_50:
4871 *min_length = 0;
4872 *max_length = e1000_igp_cable_length_50;
4873 break;
4874 case e1000_cable_length_50_80:
4875 *min_length = e1000_igp_cable_length_50;
4876 *max_length = e1000_igp_cable_length_80;
4877 break;
4878 case e1000_cable_length_80_110:
4879 *min_length = e1000_igp_cable_length_80;
4880 *max_length = e1000_igp_cable_length_110;
4881 break;
4882 case e1000_cable_length_110_140:
4883 *min_length = e1000_igp_cable_length_110;
4884 *max_length = e1000_igp_cable_length_140;
4885 break;
4886 case e1000_cable_length_140:
4887 *min_length = e1000_igp_cable_length_140;
4888 *max_length = e1000_igp_cable_length_170;
4889 break;
4890 default:
4891 return -E1000_ERR_PHY;
4892 break;
4893 }
4894 } else if (hw->phy_type == e1000_phy_igp) { /* For IGP PHY */
4895 u16 cur_agc_value;
4896 u16 min_agc_value = IGP01E1000_AGC_LENGTH_TABLE_SIZE;
4897 u16 agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
4898 { IGP01E1000_PHY_AGC_A,
4899 IGP01E1000_PHY_AGC_B,
4900 IGP01E1000_PHY_AGC_C,
4901 IGP01E1000_PHY_AGC_D
4902 };
4903 /* Read the AGC registers for all channels */
4904 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004905
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004906 ret_val =
4907 e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
4908 if (ret_val)
4909 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004910
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004911 cur_agc_value = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004912
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004913 /* Value bound check. */
4914 if ((cur_agc_value >=
4915 IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1)
4916 || (cur_agc_value == 0))
4917 return -E1000_ERR_PHY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004918
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004919 agc_value += cur_agc_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004920
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004921 /* Update minimal AGC value. */
4922 if (min_agc_value > cur_agc_value)
4923 min_agc_value = cur_agc_value;
4924 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004925
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004926 /* Remove the minimal AGC result for length < 50m */
4927 if (agc_value <
4928 IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) {
4929 agc_value -= min_agc_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004930
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004931 /* Get the average length of the remaining 3 channels */
4932 agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1);
4933 } else {
4934 /* Get the average length of all the 4 channels. */
4935 agc_value /= IGP01E1000_PHY_CHANNEL_NUM;
4936 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004937
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004938 /* Set the range of the calculated length. */
4939 *min_length = ((e1000_igp_cable_length_table[agc_value] -
4940 IGP01E1000_AGC_RANGE) > 0) ?
4941 (e1000_igp_cable_length_table[agc_value] -
4942 IGP01E1000_AGC_RANGE) : 0;
4943 *max_length = e1000_igp_cable_length_table[agc_value] +
4944 IGP01E1000_AGC_RANGE;
4945 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004946
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004947 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004948}
4949
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004950/**
4951 * e1000_check_polarity - Check the cable polarity
4952 * @hw: Struct containing variables accessed by shared code
4953 * @polarity: output parameter : 0 - Polarity is not reversed
Linus Torvalds1da177e2005-04-16 15:20:36 -07004954 * 1 - Polarity is reversed.
4955 *
4956 * returns: - E1000_ERR_XXX
4957 * E1000_SUCCESS
4958 *
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02004959 * For phy's older than IGP, this function simply reads the polarity bit in the
Linus Torvalds1da177e2005-04-16 15:20:36 -07004960 * Phy Status register. For IGP phy's, this bit is valid only if link speed is
4961 * 10 Mbps. If the link speed is 100 Mbps there is no polarity so this bit will
4962 * return 0. If the link speed is 1000 Mbps the polarity status is in the
4963 * IGP01E1000_PHY_PCS_INIT_REG.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004964 */
Joe Perches64798842008-07-11 15:17:02 -07004965static s32 e1000_check_polarity(struct e1000_hw *hw,
4966 e1000_rev_polarity *polarity)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004967{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004968 s32 ret_val;
4969 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004970
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004971 DEBUGFUNC("e1000_check_polarity");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004972
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004973 if (hw->phy_type == e1000_phy_m88) {
4974 /* return the Polarity bit in the Status register. */
4975 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
4976 &phy_data);
4977 if (ret_val)
4978 return ret_val;
4979 *polarity = ((phy_data & M88E1000_PSSR_REV_POLARITY) >>
4980 M88E1000_PSSR_REV_POLARITY_SHIFT) ?
4981 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004982
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004983 } else if (hw->phy_type == e1000_phy_igp) {
4984 /* Read the Status register to check the speed */
4985 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
4986 &phy_data);
4987 if (ret_val)
4988 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004989
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004990 /* If speed is 1000 Mbps, must read the IGP01E1000_PHY_PCS_INIT_REG to
4991 * find the polarity status */
4992 if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
4993 IGP01E1000_PSSR_SPEED_1000MBPS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004994
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004995 /* Read the GIG initialization PCS register (0x00B4) */
4996 ret_val =
4997 e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG,
4998 &phy_data);
4999 if (ret_val)
5000 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005001
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005002 /* Check the polarity bits */
5003 *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ?
5004 e1000_rev_polarity_reversed :
5005 e1000_rev_polarity_normal;
5006 } else {
5007 /* For 10 Mbps, read the polarity bit in the status register. (for
5008 * 100 Mbps this bit is always 0) */
5009 *polarity =
5010 (phy_data & IGP01E1000_PSSR_POLARITY_REVERSED) ?
5011 e1000_rev_polarity_reversed :
5012 e1000_rev_polarity_normal;
5013 }
5014 }
5015 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005016}
5017
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005018/**
5019 * e1000_check_downshift - Check if Downshift occurred
5020 * @hw: Struct containing variables accessed by shared code
5021 * @downshift: output parameter : 0 - No Downshift occurred.
5022 * 1 - Downshift occurred.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005023 *
5024 * returns: - E1000_ERR_XXX
Auke Kok76c224b2006-05-23 13:36:06 -07005025 * E1000_SUCCESS
Linus Torvalds1da177e2005-04-16 15:20:36 -07005026 *
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02005027 * For phy's older than IGP, this function reads the Downshift bit in the Phy
Linus Torvalds1da177e2005-04-16 15:20:36 -07005028 * Specific Status register. For IGP phy's, it reads the Downgrade bit in the
5029 * Link Health register. In IGP this bit is latched high, so the driver must
5030 * read it immediately after link is established.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005031 */
Joe Perches64798842008-07-11 15:17:02 -07005032static s32 e1000_check_downshift(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005033{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005034 s32 ret_val;
5035 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005036
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005037 DEBUGFUNC("e1000_check_downshift");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005038
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005039 if (hw->phy_type == e1000_phy_igp) {
5040 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH,
5041 &phy_data);
5042 if (ret_val)
5043 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005044
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005045 hw->speed_downgraded =
5046 (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0;
5047 } else if (hw->phy_type == e1000_phy_m88) {
5048 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
5049 &phy_data);
5050 if (ret_val)
5051 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005052
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005053 hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >>
5054 M88E1000_PSSR_DOWNSHIFT_SHIFT;
5055 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005056
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005057 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005058}
5059
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005060/**
5061 * e1000_config_dsp_after_link_change
5062 * @hw: Struct containing variables accessed by shared code
5063 * @link_up: was link up at the time this was called
5064 *
5065 * returns: - E1000_ERR_PHY if fail to read/write the PHY
5066 * E1000_SUCCESS at any other case.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005067 *
5068 * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a
5069 * gigabit link is achieved to improve link quality.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005070 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005071
Joe Perches64798842008-07-11 15:17:02 -07005072static s32 e1000_config_dsp_after_link_change(struct e1000_hw *hw, bool link_up)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005073{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005074 s32 ret_val;
5075 u16 phy_data, phy_saved_data, speed, duplex, i;
5076 u16 dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
5077 { IGP01E1000_PHY_AGC_PARAM_A,
5078 IGP01E1000_PHY_AGC_PARAM_B,
5079 IGP01E1000_PHY_AGC_PARAM_C,
5080 IGP01E1000_PHY_AGC_PARAM_D
5081 };
5082 u16 min_length, max_length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005083
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005084 DEBUGFUNC("e1000_config_dsp_after_link_change");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005085
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005086 if (hw->phy_type != e1000_phy_igp)
5087 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005088
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005089 if (link_up) {
5090 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
5091 if (ret_val) {
5092 DEBUGOUT("Error getting link speed and duplex\n");
5093 return ret_val;
5094 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005095
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005096 if (speed == SPEED_1000) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005097
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005098 ret_val =
5099 e1000_get_cable_length(hw, &min_length,
5100 &max_length);
5101 if (ret_val)
5102 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005103
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005104 if ((hw->dsp_config_state == e1000_dsp_config_enabled)
5105 && min_length >= e1000_igp_cable_length_50) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005106
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005107 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
5108 ret_val =
5109 e1000_read_phy_reg(hw,
5110 dsp_reg_array[i],
5111 &phy_data);
5112 if (ret_val)
5113 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005114
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005115 phy_data &=
5116 ~IGP01E1000_PHY_EDAC_MU_INDEX;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005117
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005118 ret_val =
5119 e1000_write_phy_reg(hw,
5120 dsp_reg_array
5121 [i], phy_data);
5122 if (ret_val)
5123 return ret_val;
5124 }
5125 hw->dsp_config_state =
5126 e1000_dsp_config_activated;
5127 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005128
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005129 if ((hw->ffe_config_state == e1000_ffe_config_enabled)
5130 && (min_length < e1000_igp_cable_length_50)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005131
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005132 u16 ffe_idle_err_timeout =
5133 FFE_IDLE_ERR_COUNT_TIMEOUT_20;
5134 u32 idle_errs = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005135
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005136 /* clear previous idle error counts */
5137 ret_val =
5138 e1000_read_phy_reg(hw, PHY_1000T_STATUS,
5139 &phy_data);
5140 if (ret_val)
5141 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005142
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005143 for (i = 0; i < ffe_idle_err_timeout; i++) {
5144 udelay(1000);
5145 ret_val =
5146 e1000_read_phy_reg(hw,
5147 PHY_1000T_STATUS,
5148 &phy_data);
5149 if (ret_val)
5150 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005151
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005152 idle_errs +=
5153 (phy_data &
5154 SR_1000T_IDLE_ERROR_CNT);
5155 if (idle_errs >
5156 SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT)
5157 {
5158 hw->ffe_config_state =
5159 e1000_ffe_config_active;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005160
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005161 ret_val =
5162 e1000_write_phy_reg(hw,
5163 IGP01E1000_PHY_DSP_FFE,
5164 IGP01E1000_PHY_DSP_FFE_CM_CP);
5165 if (ret_val)
5166 return ret_val;
5167 break;
5168 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005169
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005170 if (idle_errs)
5171 ffe_idle_err_timeout =
5172 FFE_IDLE_ERR_COUNT_TIMEOUT_100;
5173 }
5174 }
5175 }
5176 } else {
5177 if (hw->dsp_config_state == e1000_dsp_config_activated) {
5178 /* Save off the current value of register 0x2F5B to be restored at
5179 * the end of the routines. */
5180 ret_val =
5181 e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005182
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005183 if (ret_val)
5184 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005185
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005186 /* Disable the PHY transmitter */
5187 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005188
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005189 if (ret_val)
5190 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005191
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005192 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005193
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005194 ret_val = e1000_write_phy_reg(hw, 0x0000,
5195 IGP01E1000_IEEE_FORCE_GIGA);
5196 if (ret_val)
5197 return ret_val;
5198 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
5199 ret_val =
5200 e1000_read_phy_reg(hw, dsp_reg_array[i],
5201 &phy_data);
5202 if (ret_val)
5203 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005204
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005205 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
5206 phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005207
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005208 ret_val =
5209 e1000_write_phy_reg(hw, dsp_reg_array[i],
5210 phy_data);
5211 if (ret_val)
5212 return ret_val;
5213 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005214
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005215 ret_val = e1000_write_phy_reg(hw, 0x0000,
5216 IGP01E1000_IEEE_RESTART_AUTONEG);
5217 if (ret_val)
5218 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005219
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005220 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005221
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005222 /* Now enable the transmitter */
5223 ret_val =
5224 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005225
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005226 if (ret_val)
5227 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005228
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005229 hw->dsp_config_state = e1000_dsp_config_enabled;
5230 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005231
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005232 if (hw->ffe_config_state == e1000_ffe_config_active) {
5233 /* Save off the current value of register 0x2F5B to be restored at
5234 * the end of the routines. */
5235 ret_val =
5236 e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005237
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005238 if (ret_val)
5239 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005240
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005241 /* Disable the PHY transmitter */
5242 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005243
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005244 if (ret_val)
5245 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005246
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005247 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005248
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005249 ret_val = e1000_write_phy_reg(hw, 0x0000,
5250 IGP01E1000_IEEE_FORCE_GIGA);
5251 if (ret_val)
5252 return ret_val;
5253 ret_val =
5254 e1000_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE,
5255 IGP01E1000_PHY_DSP_FFE_DEFAULT);
5256 if (ret_val)
5257 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005258
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005259 ret_val = e1000_write_phy_reg(hw, 0x0000,
5260 IGP01E1000_IEEE_RESTART_AUTONEG);
5261 if (ret_val)
5262 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005263
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005264 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005265
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005266 /* Now enable the transmitter */
5267 ret_val =
5268 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005269
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005270 if (ret_val)
5271 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005272
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005273 hw->ffe_config_state = e1000_ffe_config_enabled;
5274 }
5275 }
5276 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005277}
5278
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005279/**
5280 * e1000_set_phy_mode - Set PHY to class A mode
5281 * @hw: Struct containing variables accessed by shared code
5282 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07005283 * Assumes the following operations will follow to enable the new class mode.
5284 * 1. Do a PHY soft reset
5285 * 2. Restart auto-negotiation or force link.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005286 */
Joe Perches64798842008-07-11 15:17:02 -07005287static s32 e1000_set_phy_mode(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005288{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005289 s32 ret_val;
5290 u16 eeprom_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005291
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005292 DEBUGFUNC("e1000_set_phy_mode");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005293
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005294 if ((hw->mac_type == e1000_82545_rev_3) &&
5295 (hw->media_type == e1000_media_type_copper)) {
5296 ret_val =
5297 e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, 1,
5298 &eeprom_data);
5299 if (ret_val) {
5300 return ret_val;
5301 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005302
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005303 if ((eeprom_data != EEPROM_RESERVED_WORD) &&
5304 (eeprom_data & EEPROM_PHY_CLASS_A)) {
5305 ret_val =
5306 e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT,
5307 0x000B);
5308 if (ret_val)
5309 return ret_val;
5310 ret_val =
5311 e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL,
5312 0x8104);
5313 if (ret_val)
5314 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005315
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005316 hw->phy_reset_disable = false;
5317 }
5318 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005319
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005320 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005321}
5322
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005323/**
5324 * e1000_set_d3_lplu_state - set d3 link power state
5325 * @hw: Struct containing variables accessed by shared code
5326 * @active: true to enable lplu false to disable lplu.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005327 *
5328 * This function sets the lplu state according to the active flag. When
5329 * activating lplu this function also disables smart speed and vise versa.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005330 * lplu will not be activated unless the device autonegotiation advertisement
Linus Torvalds1da177e2005-04-16 15:20:36 -07005331 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005332 *
5333 * returns: - E1000_ERR_PHY if fail to read/write the PHY
5334 * E1000_SUCCESS at any other case.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005335 */
Joe Perches64798842008-07-11 15:17:02 -07005336static s32 e1000_set_d3_lplu_state(struct e1000_hw *hw, bool active)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005337{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005338 s32 ret_val;
5339 u16 phy_data;
5340 DEBUGFUNC("e1000_set_d3_lplu_state");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005341
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005342 if (hw->phy_type != e1000_phy_igp)
5343 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005344
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005345 /* During driver activity LPLU should not be used or it will attain link
5346 * from the lowest speeds starting from 10Mbps. The capability is used for
5347 * Dx transitions and states */
5348 if (hw->mac_type == e1000_82541_rev_2
5349 || hw->mac_type == e1000_82547_rev_2) {
5350 ret_val =
5351 e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data);
5352 if (ret_val)
5353 return ret_val;
5354 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005355
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005356 if (!active) {
5357 if (hw->mac_type == e1000_82541_rev_2 ||
5358 hw->mac_type == e1000_82547_rev_2) {
5359 phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
5360 ret_val =
5361 e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
5362 phy_data);
5363 if (ret_val)
5364 return ret_val;
5365 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005366
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005367 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
5368 * Dx states where the power conservation is most important. During
5369 * driver activity we should enable SmartSpeed, so performance is
5370 * maintained. */
5371 if (hw->smart_speed == e1000_smart_speed_on) {
5372 ret_val =
5373 e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5374 &phy_data);
5375 if (ret_val)
5376 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005377
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005378 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
5379 ret_val =
5380 e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5381 phy_data);
5382 if (ret_val)
5383 return ret_val;
5384 } else if (hw->smart_speed == e1000_smart_speed_off) {
5385 ret_val =
5386 e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5387 &phy_data);
5388 if (ret_val)
5389 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005390
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005391 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
5392 ret_val =
5393 e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5394 phy_data);
5395 if (ret_val)
5396 return ret_val;
5397 }
5398 } else if ((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT)
5399 || (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL)
5400 || (hw->autoneg_advertised ==
5401 AUTONEG_ADVERTISE_10_100_ALL)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005402
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005403 if (hw->mac_type == e1000_82541_rev_2 ||
5404 hw->mac_type == e1000_82547_rev_2) {
5405 phy_data |= IGP01E1000_GMII_FLEX_SPD;
5406 ret_val =
5407 e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
5408 phy_data);
5409 if (ret_val)
5410 return ret_val;
5411 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005412
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005413 /* When LPLU is enabled we should disable SmartSpeed */
5414 ret_val =
5415 e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5416 &phy_data);
5417 if (ret_val)
5418 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005419
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005420 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
5421 ret_val =
5422 e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5423 phy_data);
5424 if (ret_val)
5425 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005426
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005427 }
5428 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005429}
5430
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005431/**
5432 * e1000_set_vco_speed
5433 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -07005434 *
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005435 * Change VCO speed register to improve Bit Error Rate performance of SERDES.
5436 */
Joe Perches64798842008-07-11 15:17:02 -07005437static s32 e1000_set_vco_speed(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005438{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005439 s32 ret_val;
5440 u16 default_page = 0;
5441 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005442
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005443 DEBUGFUNC("e1000_set_vco_speed");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005444
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005445 switch (hw->mac_type) {
5446 case e1000_82545_rev_3:
5447 case e1000_82546_rev_3:
5448 break;
5449 default:
5450 return E1000_SUCCESS;
5451 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005452
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005453 /* Set PHY register 30, page 5, bit 8 to 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005454
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005455 ret_val =
5456 e1000_read_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, &default_page);
5457 if (ret_val)
5458 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005459
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005460 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005);
5461 if (ret_val)
5462 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005463
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005464 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
5465 if (ret_val)
5466 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005467
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005468 phy_data &= ~M88E1000_PHY_VCO_REG_BIT8;
5469 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
5470 if (ret_val)
5471 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005472
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005473 /* Set PHY register 30, page 4, bit 11 to 1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005474
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005475 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004);
5476 if (ret_val)
5477 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005478
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005479 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
5480 if (ret_val)
5481 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005482
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005483 phy_data |= M88E1000_PHY_VCO_REG_BIT11;
5484 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
5485 if (ret_val)
5486 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005487
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005488 ret_val =
5489 e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, default_page);
5490 if (ret_val)
5491 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005492
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005493 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005494}
5495
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005496
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005497/**
5498 * e1000_enable_mng_pass_thru - check for bmc pass through
5499 * @hw: Struct containing variables accessed by shared code
5500 *
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005501 * Verifies the hardware needs to allow ARPs to be processed by the host
Joe Perchesc3033b02008-03-21 11:06:25 -07005502 * returns: - true/false
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005503 */
Joe Perches64798842008-07-11 15:17:02 -07005504u32 e1000_enable_mng_pass_thru(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005505{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005506 u32 manc;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005507
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005508 if (hw->asf_firmware_present) {
5509 manc = er32(MANC);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005510
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005511 if (!(manc & E1000_MANC_RCV_TCO_EN) ||
5512 !(manc & E1000_MANC_EN_MAC_ADDR_FILTER))
5513 return false;
5514 if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN))
5515 return true;
5516 }
5517 return false;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005518}
5519
Joe Perches64798842008-07-11 15:17:02 -07005520static s32 e1000_polarity_reversal_workaround(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005521{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005522 s32 ret_val;
5523 u16 mii_status_reg;
5524 u16 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005525
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005526 /* Polarity reversal workaround for forced 10F/10H links. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005527
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005528 /* Disable the transmitter on the PHY */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005529
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005530 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
5531 if (ret_val)
5532 return ret_val;
5533 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF);
5534 if (ret_val)
5535 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005536
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005537 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
5538 if (ret_val)
5539 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005540
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005541 /* This loop will early-out if the NO link condition has been met. */
5542 for (i = PHY_FORCE_TIME; i > 0; i--) {
5543 /* Read the MII Status Register and wait for Link Status bit
5544 * to be clear.
5545 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005546
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005547 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
5548 if (ret_val)
5549 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005550
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005551 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
5552 if (ret_val)
5553 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005554
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005555 if ((mii_status_reg & ~MII_SR_LINK_STATUS) == 0)
5556 break;
5557 mdelay(100);
5558 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005559
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005560 /* Recommended delay time after link has been lost */
5561 mdelay(1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005562
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005563 /* Now we will re-enable th transmitter on the PHY */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005564
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005565 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
5566 if (ret_val)
5567 return ret_val;
5568 mdelay(50);
5569 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0);
5570 if (ret_val)
5571 return ret_val;
5572 mdelay(50);
5573 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00);
5574 if (ret_val)
5575 return ret_val;
5576 mdelay(50);
5577 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000);
5578 if (ret_val)
5579 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005580
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005581 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
5582 if (ret_val)
5583 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005584
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005585 /* This loop will early-out if the link condition has been met. */
5586 for (i = PHY_FORCE_TIME; i > 0; i--) {
5587 /* Read the MII Status Register and wait for Link Status bit
5588 * to be set.
5589 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005590
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005591 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
5592 if (ret_val)
5593 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005594
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005595 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
5596 if (ret_val)
5597 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005598
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005599 if (mii_status_reg & MII_SR_LINK_STATUS)
5600 break;
5601 mdelay(100);
5602 }
5603 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005604}
5605
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005606/**
5607 * e1000_get_auto_rd_done
5608 * @hw: Struct containing variables accessed by shared code
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005609 *
5610 * Check for EEPROM Auto Read bit done.
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005611 * returns: - E1000_ERR_RESET if fail to reset MAC
5612 * E1000_SUCCESS at any other case.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005613 */
Joe Perches64798842008-07-11 15:17:02 -07005614static s32 e1000_get_auto_rd_done(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005615{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005616 DEBUGFUNC("e1000_get_auto_rd_done");
5617 msleep(5);
5618 return E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005619}
5620
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005621/**
5622 * e1000_get_phy_cfg_done
5623 * @hw: Struct containing variables accessed by shared code
5624 *
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005625 * Checks if the PHY configuration is done
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005626 * returns: - E1000_ERR_RESET if fail to reset MAC
5627 * E1000_SUCCESS at any other case.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005628 */
Joe Perches64798842008-07-11 15:17:02 -07005629static s32 e1000_get_phy_cfg_done(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005630{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005631 DEBUGFUNC("e1000_get_phy_cfg_done");
5632 mdelay(10);
5633 return E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005634}