blob: 9c06456759e99af7d61e34f84f4c532daed9155e [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
Emil Tantilov675ad472010-04-27 14:02:58 +000033#include "e1000.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
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
Joern Engele09b8902015-07-23 14:54:34 -0700109static DEFINE_MUTEX(e1000_eeprom_lock);
Maxime Bizonac565582012-10-20 14:53:40 +0000110static DEFINE_SPINLOCK(e1000_phy_lock);
Christopher Li78566fe2008-09-05 14:04:05 -0700111
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700112/**
113 * e1000_set_phy_type - Set the phy type member in the hw struct.
114 * @hw: Struct containing variables accessed by shared code
115 */
Joe Perches64798842008-07-11 15:17:02 -0700116static s32 e1000_set_phy_type(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700118 if (hw->mac_type == e1000_undefined)
119 return -E1000_ERR_PHY_TYPE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700120
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700121 switch (hw->phy_id) {
122 case M88E1000_E_PHY_ID:
123 case M88E1000_I_PHY_ID:
124 case M88E1011_I_PHY_ID:
125 case M88E1111_I_PHY_ID:
Florian Fainellicf8e09b2011-01-24 14:48:03 +0000126 case M88E1118_E_PHY_ID:
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700127 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 ||
Dirk Brandewie5377a412011-01-06 14:29:54 +0000133 hw->mac_type == e1000_82547_rev_2)
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700134 hw->phy_type = e1000_phy_igp;
Dirk Brandewie5377a412011-01-06 14:29:54 +0000135 break;
136 case RTL8211B_PHY_ID:
137 hw->phy_type = e1000_phy_8211;
138 break;
139 case RTL8201N_PHY_ID:
140 hw->phy_type = e1000_phy_8201;
141 break;
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700142 default:
143 /* Should never have loaded on this device */
144 hw->phy_type = e1000_phy_undefined;
145 return -E1000_ERR_PHY_TYPE;
146 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700148 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149}
150
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700151/**
152 * e1000_phy_init_script - IGP phy init script - initializes the GbE PHY
153 * @hw: Struct containing variables accessed by shared code
154 */
Joe Perches64798842008-07-11 15:17:02 -0700155static void e1000_phy_init_script(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700157 u32 ret_val;
158 u16 phy_saved_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700160 if (hw->phy_init_script) {
161 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000163 /* Save off the current value of register 0x2F5B to be restored
164 * at the end of this routine.
165 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700166 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700168 /* Disabled the PHY transmitter */
169 e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
170 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700172 e1000_write_phy_reg(hw, 0x0000, 0x0140);
173 msleep(5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700175 switch (hw->mac_type) {
176 case e1000_82541:
177 case e1000_82547:
178 e1000_write_phy_reg(hw, 0x1F95, 0x0001);
179 e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
180 e1000_write_phy_reg(hw, 0x1F79, 0x0018);
181 e1000_write_phy_reg(hw, 0x1F30, 0x1600);
182 e1000_write_phy_reg(hw, 0x1F31, 0x0014);
183 e1000_write_phy_reg(hw, 0x1F32, 0x161C);
184 e1000_write_phy_reg(hw, 0x1F94, 0x0003);
185 e1000_write_phy_reg(hw, 0x1F96, 0x003F);
186 e1000_write_phy_reg(hw, 0x2010, 0x0008);
187 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700189 case e1000_82541_rev_2:
190 case e1000_82547_rev_2:
191 e1000_write_phy_reg(hw, 0x1F73, 0x0099);
192 break;
193 default:
194 break;
195 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700197 e1000_write_phy_reg(hw, 0x0000, 0x3300);
198 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700200 /* Now enable the transmitter */
201 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700203 if (hw->mac_type == e1000_82547) {
204 u16 fused, fine, coarse;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700206 /* Move to analog registers page */
207 e1000_read_phy_reg(hw,
208 IGP01E1000_ANALOG_SPARE_FUSE_STATUS,
209 &fused);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700211 if (!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
212 e1000_read_phy_reg(hw,
213 IGP01E1000_ANALOG_FUSE_STATUS,
214 &fused);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700216 fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
217 coarse =
218 fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700220 if (coarse >
221 IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
222 coarse -=
223 IGP01E1000_ANALOG_FUSE_COARSE_10;
224 fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
225 } else if (coarse ==
226 IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
227 fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700229 fused =
230 (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
231 (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
232 (coarse &
233 IGP01E1000_ANALOG_FUSE_COARSE_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700235 e1000_write_phy_reg(hw,
236 IGP01E1000_ANALOG_FUSE_CONTROL,
237 fused);
238 e1000_write_phy_reg(hw,
239 IGP01E1000_ANALOG_FUSE_BYPASS,
240 IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
241 }
242 }
243 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244}
245
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700246/**
247 * e1000_set_mac_type - Set the mac type member in the hw struct.
248 * @hw: Struct containing variables accessed by shared code
249 */
Joe Perches64798842008-07-11 15:17:02 -0700250s32 e1000_set_mac_type(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251{
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500252 switch (hw->device_id) {
253 case E1000_DEV_ID_82542:
254 switch (hw->revision_id) {
255 case E1000_82542_2_0_REV_ID:
256 hw->mac_type = e1000_82542_rev2_0;
257 break;
258 case E1000_82542_2_1_REV_ID:
259 hw->mac_type = e1000_82542_rev2_1;
260 break;
261 default:
262 /* Invalid 82542 revision ID */
263 return -E1000_ERR_MAC_TYPE;
264 }
265 break;
266 case E1000_DEV_ID_82543GC_FIBER:
267 case E1000_DEV_ID_82543GC_COPPER:
268 hw->mac_type = e1000_82543;
269 break;
270 case E1000_DEV_ID_82544EI_COPPER:
271 case E1000_DEV_ID_82544EI_FIBER:
272 case E1000_DEV_ID_82544GC_COPPER:
273 case E1000_DEV_ID_82544GC_LOM:
274 hw->mac_type = e1000_82544;
275 break;
276 case E1000_DEV_ID_82540EM:
277 case E1000_DEV_ID_82540EM_LOM:
278 case E1000_DEV_ID_82540EP:
279 case E1000_DEV_ID_82540EP_LOM:
280 case E1000_DEV_ID_82540EP_LP:
281 hw->mac_type = e1000_82540;
282 break;
283 case E1000_DEV_ID_82545EM_COPPER:
284 case E1000_DEV_ID_82545EM_FIBER:
285 hw->mac_type = e1000_82545;
286 break;
287 case E1000_DEV_ID_82545GM_COPPER:
288 case E1000_DEV_ID_82545GM_FIBER:
289 case E1000_DEV_ID_82545GM_SERDES:
290 hw->mac_type = e1000_82545_rev_3;
291 break;
292 case E1000_DEV_ID_82546EB_COPPER:
293 case E1000_DEV_ID_82546EB_FIBER:
294 case E1000_DEV_ID_82546EB_QUAD_COPPER:
295 hw->mac_type = e1000_82546;
296 break;
297 case E1000_DEV_ID_82546GB_COPPER:
298 case E1000_DEV_ID_82546GB_FIBER:
299 case E1000_DEV_ID_82546GB_SERDES:
300 case E1000_DEV_ID_82546GB_PCIE:
301 case E1000_DEV_ID_82546GB_QUAD_COPPER:
302 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
303 hw->mac_type = e1000_82546_rev_3;
304 break;
305 case E1000_DEV_ID_82541EI:
306 case E1000_DEV_ID_82541EI_MOBILE:
307 case E1000_DEV_ID_82541ER_LOM:
308 hw->mac_type = e1000_82541;
309 break;
310 case E1000_DEV_ID_82541ER:
311 case E1000_DEV_ID_82541GI:
312 case E1000_DEV_ID_82541GI_LF:
313 case E1000_DEV_ID_82541GI_MOBILE:
314 hw->mac_type = e1000_82541_rev_2;
315 break;
316 case E1000_DEV_ID_82547EI:
317 case E1000_DEV_ID_82547EI_MOBILE:
318 hw->mac_type = e1000_82547;
319 break;
320 case E1000_DEV_ID_82547GI:
321 hw->mac_type = e1000_82547_rev_2;
322 break;
Dirk Brandewie5377a412011-01-06 14:29:54 +0000323 case E1000_DEV_ID_INTEL_CE4100_GBE:
324 hw->mac_type = e1000_ce4100;
325 break;
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500326 default:
327 /* Should never have loaded on this device */
328 return -E1000_ERR_MAC_TYPE;
329 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500331 switch (hw->mac_type) {
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500332 case e1000_82541:
333 case e1000_82547:
334 case e1000_82541_rev_2:
335 case e1000_82547_rev_2:
Joe Perchesc3033b02008-03-21 11:06:25 -0700336 hw->asf_firmware_present = true;
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500337 break;
338 default:
339 break;
340 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341
Jeff Garzik167fb282006-12-15 10:41:15 -0500342 /* The 82543 chip does not count tx_carrier_errors properly in
343 * FD mode
344 */
345 if (hw->mac_type == e1000_82543)
Joe Perchesc3033b02008-03-21 11:06:25 -0700346 hw->bad_tx_carr_stats_fd = true;
Jeff Garzik167fb282006-12-15 10:41:15 -0500347
Jeff Garzik15e376b2006-12-15 11:16:33 -0500348 if (hw->mac_type > e1000_82544)
Joe Perchesc3033b02008-03-21 11:06:25 -0700349 hw->has_smbus = true;
Jeff Garzik15e376b2006-12-15 11:16:33 -0500350
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500351 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352}
353
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700354/**
355 * e1000_set_media_type - Set media type and TBI compatibility.
356 * @hw: Struct containing variables accessed by shared code
357 */
Joe Perches64798842008-07-11 15:17:02 -0700358void e1000_set_media_type(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700360 u32 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700362 if (hw->mac_type != e1000_82543) {
363 /* tbi_compatibility is only valid on 82543 */
364 hw->tbi_compatibility_en = false;
365 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700367 switch (hw->device_id) {
368 case E1000_DEV_ID_82545GM_SERDES:
369 case E1000_DEV_ID_82546GB_SERDES:
370 hw->media_type = e1000_media_type_internal_serdes;
371 break;
372 default:
373 switch (hw->mac_type) {
374 case e1000_82542_rev2_0:
375 case e1000_82542_rev2_1:
376 hw->media_type = e1000_media_type_fiber;
377 break;
Dirk Brandewie5377a412011-01-06 14:29:54 +0000378 case e1000_ce4100:
379 hw->media_type = e1000_media_type_copper;
380 break;
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700381 default:
382 status = er32(STATUS);
383 if (status & E1000_STATUS_TBIMODE) {
384 hw->media_type = e1000_media_type_fiber;
385 /* tbi_compatibility not valid on fiber */
386 hw->tbi_compatibility_en = false;
387 } else {
388 hw->media_type = e1000_media_type_copper;
389 }
390 break;
391 }
392 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393}
394
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700395/**
Ben Hutchings49ce9c22012-07-10 10:56:00 +0000396 * e1000_reset_hw - reset the hardware completely
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700397 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 *
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700399 * Reset the transmit and receive units; mask and clear all interrupts.
400 */
Joe Perches64798842008-07-11 15:17:02 -0700401s32 e1000_reset_hw(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700403 u32 ctrl;
404 u32 ctrl_ext;
405 u32 icr;
406 u32 manc;
407 u32 led_ctrl;
408 s32 ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700410 /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
411 if (hw->mac_type == e1000_82542_rev2_0) {
Emil Tantilov675ad472010-04-27 14:02:58 +0000412 e_dbg("Disabling MWI on 82542 rev 2.0\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700413 e1000_pci_clear_mwi(hw);
414 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700416 /* Clear interrupt mask to stop board from generating interrupts */
Emil Tantilov675ad472010-04-27 14:02:58 +0000417 e_dbg("Masking off all interrupts\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700418 ew32(IMC, 0xffffffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700420 /* Disable the Transmit and Receive units. Then delay to allow
421 * any pending transactions to complete before we hit the MAC with
422 * the global reset.
423 */
424 ew32(RCTL, 0);
425 ew32(TCTL, E1000_TCTL_PSP);
426 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700428 /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
429 hw->tbi_compatibility_on = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700431 /* Delay to allow any outstanding PCI transactions to complete before
432 * resetting the device
433 */
434 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700436 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700438 /* Must reset the PHY before resetting the MAC */
439 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
440 ew32(CTRL, (ctrl | E1000_CTRL_PHY_RST));
Jesse Brandeburg945a5152011-07-20 00:56:21 +0000441 E1000_WRITE_FLUSH();
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700442 msleep(5);
443 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700445 /* Issue a global reset to the MAC. This will reset the chip's
446 * transmit, receive, DMA, and link units. It will not effect
447 * the current PCI configuration. The global reset bit is self-
448 * clearing, and should clear within a microsecond.
449 */
Emil Tantilov675ad472010-04-27 14:02:58 +0000450 e_dbg("Issuing a global reset to MAC\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700452 switch (hw->mac_type) {
453 case e1000_82544:
454 case e1000_82540:
455 case e1000_82545:
456 case e1000_82546:
457 case e1000_82541:
458 case e1000_82541_rev_2:
459 /* These controllers can't ack the 64-bit write when issuing the
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000460 * reset, so use IO-mapping as a workaround to issue the reset
461 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700462 E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
463 break;
464 case e1000_82545_rev_3:
465 case e1000_82546_rev_3:
466 /* Reset is performed on a shadow of the control register */
467 ew32(CTRL_DUP, (ctrl | E1000_CTRL_RST));
468 break;
Dirk Brandewie5377a412011-01-06 14:29:54 +0000469 case e1000_ce4100:
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700470 default:
471 ew32(CTRL, (ctrl | E1000_CTRL_RST));
472 break;
473 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000475 /* After MAC reset, force reload of EEPROM to restore power-on settings
476 * to device. Later controllers reload the EEPROM automatically, so
477 * just wait for reload to complete.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700478 */
479 switch (hw->mac_type) {
480 case e1000_82542_rev2_0:
481 case e1000_82542_rev2_1:
482 case e1000_82543:
483 case e1000_82544:
484 /* Wait for reset to complete */
485 udelay(10);
486 ctrl_ext = er32(CTRL_EXT);
487 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
488 ew32(CTRL_EXT, ctrl_ext);
489 E1000_WRITE_FLUSH();
490 /* Wait for EEPROM reload */
491 msleep(2);
492 break;
493 case e1000_82541:
494 case e1000_82541_rev_2:
495 case e1000_82547:
496 case e1000_82547_rev_2:
497 /* Wait for EEPROM reload */
498 msleep(20);
499 break;
500 default:
501 /* Auto read done will delay 5ms or poll based on mac type */
502 ret_val = e1000_get_auto_rd_done(hw);
503 if (ret_val)
504 return ret_val;
505 break;
506 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700508 /* Disable HW ARPs on ASF enabled adapters */
509 if (hw->mac_type >= e1000_82540) {
510 manc = er32(MANC);
511 manc &= ~(E1000_MANC_ARP_EN);
512 ew32(MANC, manc);
513 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700515 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
516 e1000_phy_init_script(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700518 /* Configure activity LED after PHY reset */
519 led_ctrl = er32(LEDCTL);
520 led_ctrl &= IGP_ACTIVITY_LED_MASK;
521 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
522 ew32(LEDCTL, led_ctrl);
523 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700525 /* Clear interrupt mask to stop board from generating interrupts */
Emil Tantilov675ad472010-04-27 14:02:58 +0000526 e_dbg("Masking off all interrupts\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700527 ew32(IMC, 0xffffffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700529 /* Clear any pending interrupt events. */
530 icr = er32(ICR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700532 /* If MWI was previously enabled, reenable it. */
533 if (hw->mac_type == e1000_82542_rev2_0) {
534 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
535 e1000_pci_set_mwi(hw);
536 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700538 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539}
540
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700541/**
Ben Hutchings49ce9c22012-07-10 10:56:00 +0000542 * e1000_init_hw - Performs basic configuration of the adapter.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700543 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 *
545 * Assumes that the controller has previously been reset and is in a
546 * post-reset uninitialized state. Initializes the receive address registers,
547 * multicast table, and VLAN filter table. Calls routines to setup link
548 * configuration and flow control settings. Clears all on-chip counters. Leaves
549 * the transmit and receive units disabled and uninitialized.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700550 */
Joe Perches64798842008-07-11 15:17:02 -0700551s32 e1000_init_hw(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700553 u32 ctrl;
554 u32 i;
555 s32 ret_val;
556 u32 mta_size;
557 u32 ctrl_ext;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700558
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700559 /* Initialize Identification LED */
560 ret_val = e1000_id_led_init(hw);
561 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +0000562 e_dbg("Error Initializing Identification LED\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700563 return ret_val;
564 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700566 /* Set the media type and TBI compatibility */
567 e1000_set_media_type(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700569 /* Disabling VLAN filtering. */
Emil Tantilov675ad472010-04-27 14:02:58 +0000570 e_dbg("Initializing the IEEE VLAN\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700571 if (hw->mac_type < e1000_82545_rev_3)
572 ew32(VET, 0);
573 e1000_clear_vfta(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700575 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
576 if (hw->mac_type == e1000_82542_rev2_0) {
Emil Tantilov675ad472010-04-27 14:02:58 +0000577 e_dbg("Disabling MWI on 82542 rev 2.0\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700578 e1000_pci_clear_mwi(hw);
579 ew32(RCTL, E1000_RCTL_RST);
580 E1000_WRITE_FLUSH();
581 msleep(5);
582 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000584 /* Setup the receive address. This involves initializing all of the
585 * Receive Address Registers (RARs 0 - 15).
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700586 */
587 e1000_init_rx_addrs(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700589 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
590 if (hw->mac_type == e1000_82542_rev2_0) {
591 ew32(RCTL, 0);
592 E1000_WRITE_FLUSH();
593 msleep(1);
594 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
595 e1000_pci_set_mwi(hw);
596 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700598 /* Zero out the Multicast HASH table */
Emil Tantilov675ad472010-04-27 14:02:58 +0000599 e_dbg("Zeroing the MTA\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700600 mta_size = E1000_MC_TBL_SIZE;
601 for (i = 0; i < mta_size; i++) {
602 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
603 /* use write flush to prevent Memory Write Block (MWB) from
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000604 * occurring when accessing our register space
605 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700606 E1000_WRITE_FLUSH();
607 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700609 /* Set the PCI priority bit correctly in the CTRL register. This
610 * determines if the adapter gives priority to receives, or if it
611 * gives equal priority to transmits and receives. Valid only on
612 * 82542 and 82543 silicon.
613 */
614 if (hw->dma_fairness && hw->mac_type <= e1000_82543) {
615 ctrl = er32(CTRL);
616 ew32(CTRL, ctrl | E1000_CTRL_PRIOR);
617 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700619 switch (hw->mac_type) {
620 case e1000_82545_rev_3:
621 case e1000_82546_rev_3:
622 break;
623 default:
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000624 /* Workaround for PCI-X problem when BIOS sets MMRBC
625 * incorrectly.
626 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700627 if (hw->bus_type == e1000_bus_type_pcix
628 && e1000_pcix_get_mmrbc(hw) > 2048)
629 e1000_pcix_set_mmrbc(hw, 2048);
630 break;
631 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700633 /* Call a subroutine to configure the link and setup flow control. */
634 ret_val = e1000_setup_link(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700636 /* Set the transmit descriptor write-back policy */
637 if (hw->mac_type > e1000_82544) {
638 ctrl = er32(TXDCTL);
639 ctrl =
640 (ctrl & ~E1000_TXDCTL_WTHRESH) |
641 E1000_TXDCTL_FULL_TX_DESC_WB;
642 ew32(TXDCTL, ctrl);
643 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700645 /* Clear all of the statistics registers (clear on read). It is
646 * important that we do this after we have tried to establish link
647 * because the symbol error count will increment wildly if there
648 * is no link.
649 */
650 e1000_clear_hw_cntrs(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700652 if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER ||
653 hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) {
654 ctrl_ext = er32(CTRL_EXT);
655 /* Relaxed ordering must be disabled to avoid a parity
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000656 * error crash in a PCI slot.
657 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700658 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
659 ew32(CTRL_EXT, ctrl_ext);
660 }
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -0800661
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700662 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663}
664
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700665/**
666 * e1000_adjust_serdes_amplitude - Adjust SERDES output amplitude based on EEPROM setting.
667 * @hw: Struct containing variables accessed by shared code.
668 */
Joe Perches64798842008-07-11 15:17:02 -0700669static s32 e1000_adjust_serdes_amplitude(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700671 u16 eeprom_data;
672 s32 ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700674 if (hw->media_type != e1000_media_type_internal_serdes)
675 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700677 switch (hw->mac_type) {
678 case e1000_82545_rev_3:
679 case e1000_82546_rev_3:
680 break;
681 default:
682 return E1000_SUCCESS;
683 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700685 ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1,
Janusz Wolaka48954c2015-09-17 23:34:29 +0200686 &eeprom_data);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700687 if (ret_val) {
688 return ret_val;
689 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700691 if (eeprom_data != EEPROM_RESERVED_WORD) {
692 /* Adjust SERDES output amplitude only. */
693 eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK;
694 ret_val =
695 e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data);
696 if (ret_val)
697 return ret_val;
698 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700700 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701}
702
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700703/**
704 * e1000_setup_link - Configures flow control and link settings.
705 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 *
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700707 * Determines which flow control settings to use. Calls the appropriate media-
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 * specific link configuration function. Configures the flow control settings.
709 * Assuming the adapter has a valid link partner, a valid link should be
710 * established. Assumes the hardware has previously been reset and the
711 * transmitter and receiver are not enabled.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700712 */
Joe Perches64798842008-07-11 15:17:02 -0700713s32 e1000_setup_link(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700715 u32 ctrl_ext;
716 s32 ret_val;
717 u16 eeprom_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700719 /* Read and store word 0x0F of the EEPROM. This word contains bits
720 * that determine the hardware's default PAUSE (flow control) mode,
721 * a bit that determines whether the HW defaults to enabling or
722 * disabling auto-negotiation, and the direction of the
723 * SW defined pins. If there is no SW over-ride of the flow
724 * control setting, then the variable hw->fc will
725 * be initialized based on a value in the EEPROM.
726 */
727 if (hw->fc == E1000_FC_DEFAULT) {
728 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
729 1, &eeprom_data);
730 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +0000731 e_dbg("EEPROM Read Error\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700732 return -E1000_ERR_EEPROM;
733 }
734 if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
735 hw->fc = E1000_FC_NONE;
736 else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
737 EEPROM_WORD0F_ASM_DIR)
738 hw->fc = E1000_FC_TX_PAUSE;
739 else
740 hw->fc = E1000_FC_FULL;
741 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700743 /* We want to save off the original Flow Control configuration just
744 * in case we get disconnected and then reconnected into a different
745 * hub or switch with different Flow Control capabilities.
746 */
747 if (hw->mac_type == e1000_82542_rev2_0)
748 hw->fc &= (~E1000_FC_TX_PAUSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700750 if ((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
751 hw->fc &= (~E1000_FC_RX_PAUSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700753 hw->original_fc = hw->fc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754
Emil Tantilov675ad472010-04-27 14:02:58 +0000755 e_dbg("After fix-ups FlowControl is now = %x\n", hw->fc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700757 /* Take the 4 bits from EEPROM word 0x0F that determine the initial
758 * polarity value for the SW controlled pins, and setup the
759 * Extended Device Control reg with that info.
760 * This is needed because one of the SW controlled pins is used for
761 * signal detection. So this should be done before e1000_setup_pcs_link()
762 * or e1000_phy_setup() is called.
763 */
764 if (hw->mac_type == e1000_82543) {
765 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
766 1, &eeprom_data);
767 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +0000768 e_dbg("EEPROM Read Error\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700769 return -E1000_ERR_EEPROM;
770 }
771 ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
772 SWDPIO__EXT_SHIFT);
773 ew32(CTRL_EXT, ctrl_ext);
774 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700776 /* Call the necessary subroutine to configure the link. */
777 ret_val = (hw->media_type == e1000_media_type_copper) ?
778 e1000_setup_copper_link(hw) : e1000_setup_fiber_serdes_link(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700780 /* Initialize the flow control address, type, and PAUSE timer
781 * registers to their default values. This is done even if flow
782 * control is disabled, because it does not hurt anything to
783 * initialize these registers.
784 */
Emil Tantilov675ad472010-04-27 14:02:58 +0000785 e_dbg("Initializing the Flow Control address, type and timer regs\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700787 ew32(FCT, FLOW_CONTROL_TYPE);
788 ew32(FCAH, FLOW_CONTROL_ADDRESS_HIGH);
789 ew32(FCAL, FLOW_CONTROL_ADDRESS_LOW);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700790
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700791 ew32(FCTTV, hw->fc_pause_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700793 /* Set the flow control receive threshold registers. Normally,
794 * these registers will be set to a default threshold that may be
795 * adjusted later by the driver's runtime code. However, if the
796 * ability to transmit pause frames in not enabled, then these
797 * registers will be set to 0.
798 */
799 if (!(hw->fc & E1000_FC_TX_PAUSE)) {
800 ew32(FCRTL, 0);
801 ew32(FCRTH, 0);
802 } else {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000803 /* We need to set up the Receive Threshold high and low water
804 * marks as well as (optionally) enabling the transmission of
805 * XON frames.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700806 */
807 if (hw->fc_send_xon) {
808 ew32(FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE));
809 ew32(FCRTH, hw->fc_high_water);
810 } else {
811 ew32(FCRTL, hw->fc_low_water);
812 ew32(FCRTH, hw->fc_high_water);
813 }
814 }
815 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816}
817
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700818/**
819 * e1000_setup_fiber_serdes_link - prepare fiber or serdes link
820 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 *
822 * Manipulates Physical Coding Sublayer functions in order to configure
823 * link. Assumes the hardware has been previously reset and the transmitter
824 * and receiver are not enabled.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700825 */
Joe Perches64798842008-07-11 15:17:02 -0700826static s32 e1000_setup_fiber_serdes_link(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700828 u32 ctrl;
829 u32 status;
830 u32 txcw = 0;
831 u32 i;
832 u32 signal = 0;
833 s32 ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700835 /* On adapters with a MAC newer than 82544, SWDP 1 will be
836 * set when the optics detect a signal. On older adapters, it will be
837 * cleared when there is a signal. This applies to fiber media only.
838 * If we're on serdes media, adjust the output amplitude to value
839 * set in the EEPROM.
840 */
841 ctrl = er32(CTRL);
842 if (hw->media_type == e1000_media_type_fiber)
843 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700845 ret_val = e1000_adjust_serdes_amplitude(hw);
846 if (ret_val)
847 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700849 /* Take the link out of reset */
850 ctrl &= ~(E1000_CTRL_LRST);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700852 /* Adjust VCO speed to improve BER performance */
853 ret_val = e1000_set_vco_speed(hw);
854 if (ret_val)
855 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700857 e1000_config_collision_dist(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700859 /* Check for a software override of the flow control settings, and setup
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000860 * the device accordingly. If auto-negotiation is enabled, then
861 * software will have to set the "PAUSE" bits to the correct value in
862 * the Tranmsit Config Word Register (TXCW) and re-start
863 * auto-negotiation. However, if auto-negotiation is disabled, then
864 * software will have to manually configure the two flow control enable
865 * bits in the CTRL register.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700866 *
867 * The possible values of the "fc" parameter are:
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000868 * 0: Flow control is completely disabled
869 * 1: Rx flow control is enabled (we can receive pause frames, but
870 * not send pause frames).
871 * 2: Tx flow control is enabled (we can send pause frames but we do
872 * not support receiving pause frames).
873 * 3: Both Rx and TX flow control (symmetric) are enabled.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700874 */
875 switch (hw->fc) {
876 case E1000_FC_NONE:
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000877 /* Flow ctrl is completely disabled by a software over-ride */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700878 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
879 break;
880 case E1000_FC_RX_PAUSE:
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000881 /* Rx Flow control is enabled and Tx Flow control is disabled by
882 * a software over-ride. Since there really isn't a way to
883 * advertise that we are capable of Rx Pause ONLY, we will
884 * advertise that we support both symmetric and asymmetric Rx
885 * PAUSE. Later, we will disable the adapter's ability to send
886 * PAUSE frames.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700887 */
888 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
889 break;
890 case E1000_FC_TX_PAUSE:
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000891 /* Tx Flow control is enabled, and Rx Flow control is disabled,
892 * by a software over-ride.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700893 */
894 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
895 break;
896 case E1000_FC_FULL:
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000897 /* Flow control (both Rx and Tx) is enabled by a software
898 * over-ride.
899 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700900 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
901 break;
902 default:
Emil Tantilov675ad472010-04-27 14:02:58 +0000903 e_dbg("Flow control param set incorrectly\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700904 return -E1000_ERR_CONFIG;
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700905 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000907 /* Since auto-negotiation is enabled, take the link out of reset (the
908 * link will be in reset, because we previously reset the chip). This
909 * will restart auto-negotiation. If auto-negotiation is successful
910 * then the link-up status bit will be set and the flow control enable
911 * bits (RFCE and TFCE) will be set according to their negotiated value.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700912 */
Emil Tantilov675ad472010-04-27 14:02:58 +0000913 e_dbg("Auto-negotiation enabled\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700915 ew32(TXCW, txcw);
916 ew32(CTRL, ctrl);
917 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700919 hw->txcw = txcw;
920 msleep(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000922 /* If we have a signal (the cable is plugged in) then poll for a
923 * "Link-Up" indication in the Device Status Register. Time-out if a
924 * link isn't seen in 500 milliseconds seconds (Auto-negotiation should
925 * complete in less than 500 milliseconds even if the other end is doing
926 * it in SW). For internal serdes, we just assume a signal is present,
927 * then poll.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700928 */
929 if (hw->media_type == e1000_media_type_internal_serdes ||
930 (er32(CTRL) & E1000_CTRL_SWDPIN1) == signal) {
Emil Tantilov675ad472010-04-27 14:02:58 +0000931 e_dbg("Looking for Link\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700932 for (i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
933 msleep(10);
934 status = er32(STATUS);
935 if (status & E1000_STATUS_LU)
936 break;
937 }
938 if (i == (LINK_UP_TIMEOUT / 10)) {
Emil Tantilov675ad472010-04-27 14:02:58 +0000939 e_dbg("Never got a valid link from auto-neg!!!\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700940 hw->autoneg_failed = 1;
941 /* AutoNeg failed to achieve a link, so we'll call
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000942 * e1000_check_for_link. This routine will force the
943 * link up if we detect a signal. This will allow us to
944 * communicate with non-autonegotiating link partners.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700945 */
946 ret_val = e1000_check_for_link(hw);
947 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +0000948 e_dbg("Error while checking for link\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700949 return ret_val;
950 }
951 hw->autoneg_failed = 0;
952 } else {
953 hw->autoneg_failed = 0;
Emil Tantilov675ad472010-04-27 14:02:58 +0000954 e_dbg("Valid Link Found\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700955 }
956 } else {
Emil Tantilov675ad472010-04-27 14:02:58 +0000957 e_dbg("No Signal Detected\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700958 }
959 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960}
961
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700962/**
Dirk Brandewie5377a412011-01-06 14:29:54 +0000963 * e1000_copper_link_rtl_setup - Copper link setup for e1000_phy_rtl series.
964 * @hw: Struct containing variables accessed by shared code
965 *
966 * Commits changes to PHY configuration by calling e1000_phy_reset().
967 */
968static s32 e1000_copper_link_rtl_setup(struct e1000_hw *hw)
969{
970 s32 ret_val;
971
972 /* SW reset the PHY so all changes take effect */
973 ret_val = e1000_phy_reset(hw);
974 if (ret_val) {
975 e_dbg("Error Resetting the PHY\n");
976 return ret_val;
977 }
978
979 return E1000_SUCCESS;
980}
981
982static s32 gbe_dhg_phy_setup(struct e1000_hw *hw)
983{
984 s32 ret_val;
985 u32 ctrl_aux;
986
987 switch (hw->phy_type) {
988 case e1000_phy_8211:
989 ret_val = e1000_copper_link_rtl_setup(hw);
990 if (ret_val) {
991 e_dbg("e1000_copper_link_rtl_setup failed!\n");
992 return ret_val;
993 }
994 break;
995 case e1000_phy_8201:
996 /* Set RMII mode */
997 ctrl_aux = er32(CTL_AUX);
998 ctrl_aux |= E1000_CTL_AUX_RMII;
999 ew32(CTL_AUX, ctrl_aux);
1000 E1000_WRITE_FLUSH();
1001
1002 /* Disable the J/K bits required for receive */
1003 ctrl_aux = er32(CTL_AUX);
1004 ctrl_aux |= 0x4;
1005 ctrl_aux &= ~0x2;
1006 ew32(CTL_AUX, ctrl_aux);
1007 E1000_WRITE_FLUSH();
1008 ret_val = e1000_copper_link_rtl_setup(hw);
1009
1010 if (ret_val) {
1011 e_dbg("e1000_copper_link_rtl_setup failed!\n");
1012 return ret_val;
1013 }
1014 break;
1015 default:
1016 e_dbg("Error Resetting the PHY\n");
1017 return E1000_ERR_PHY_TYPE;
1018 }
1019
1020 return E1000_SUCCESS;
1021}
1022
1023/**
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001024 * e1000_copper_link_preconfig - early configuration for copper
1025 * @hw: Struct containing variables accessed by shared code
1026 *
1027 * Make sure we have a valid PHY and change PHY mode before link setup.
1028 */
Joe Perches64798842008-07-11 15:17:02 -07001029static s32 e1000_copper_link_preconfig(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001031 u32 ctrl;
1032 s32 ret_val;
1033 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001035 ctrl = er32(CTRL);
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001036 /* With 82543, we need to force speed and duplex on the MAC equal to
1037 * what the PHY speed and duplex configuration is. In addition, we need
1038 * to perform a hardware reset on the PHY to take it out of reset.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001039 */
1040 if (hw->mac_type > e1000_82543) {
1041 ctrl |= E1000_CTRL_SLU;
1042 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1043 ew32(CTRL, ctrl);
1044 } else {
1045 ctrl |=
1046 (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
1047 ew32(CTRL, ctrl);
1048 ret_val = e1000_phy_hw_reset(hw);
1049 if (ret_val)
1050 return ret_val;
1051 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001053 /* Make sure we have a valid PHY */
1054 ret_val = e1000_detect_gig_phy(hw);
1055 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00001056 e_dbg("Error, did not detect valid phy.\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001057 return ret_val;
1058 }
Emil Tantilov675ad472010-04-27 14:02:58 +00001059 e_dbg("Phy ID = %x\n", hw->phy_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001061 /* Set PHY to class A mode (if necessary) */
1062 ret_val = e1000_set_phy_mode(hw);
1063 if (ret_val)
1064 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001066 if ((hw->mac_type == e1000_82545_rev_3) ||
1067 (hw->mac_type == e1000_82546_rev_3)) {
1068 ret_val =
1069 e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1070 phy_data |= 0x00000008;
1071 ret_val =
1072 e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1073 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001075 if (hw->mac_type <= e1000_82543 ||
1076 hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
1077 hw->mac_type == e1000_82541_rev_2
1078 || hw->mac_type == e1000_82547_rev_2)
1079 hw->phy_reset_disable = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001081 return E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001082}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001084/**
1085 * e1000_copper_link_igp_setup - Copper link setup for e1000_phy_igp series.
1086 * @hw: Struct containing variables accessed by shared code
1087 */
Joe Perches64798842008-07-11 15:17:02 -07001088static s32 e1000_copper_link_igp_setup(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001089{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001090 u32 led_ctrl;
1091 s32 ret_val;
1092 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001094 if (hw->phy_reset_disable)
1095 return E1000_SUCCESS;
Auke Kok76c224b2006-05-23 13:36:06 -07001096
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001097 ret_val = e1000_phy_reset(hw);
1098 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00001099 e_dbg("Error Resetting the PHY\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001100 return ret_val;
1101 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001103 /* Wait 15ms for MAC to configure PHY from eeprom settings */
1104 msleep(15);
1105 /* Configure activity LED after PHY reset */
1106 led_ctrl = er32(LEDCTL);
1107 led_ctrl &= IGP_ACTIVITY_LED_MASK;
1108 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
1109 ew32(LEDCTL, led_ctrl);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001110
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001111 /* The NVM settings will configure LPLU in D3 for IGP2 and IGP3 PHYs */
1112 if (hw->phy_type == e1000_phy_igp) {
1113 /* disable lplu d3 during driver init */
1114 ret_val = e1000_set_d3_lplu_state(hw, false);
1115 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00001116 e_dbg("Error Disabling LPLU D3\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001117 return ret_val;
1118 }
1119 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001120
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001121 /* Configure mdi-mdix settings */
1122 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1123 if (ret_val)
1124 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001125
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001126 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
1127 hw->dsp_config_state = e1000_dsp_config_disabled;
1128 /* Force MDI for earlier revs of the IGP PHY */
1129 phy_data &=
1130 ~(IGP01E1000_PSCR_AUTO_MDIX |
1131 IGP01E1000_PSCR_FORCE_MDI_MDIX);
1132 hw->mdix = 1;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001133
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001134 } else {
1135 hw->dsp_config_state = e1000_dsp_config_enabled;
1136 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001137
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001138 switch (hw->mdix) {
1139 case 1:
1140 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1141 break;
1142 case 2:
1143 phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
1144 break;
1145 case 0:
1146 default:
1147 phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
1148 break;
1149 }
1150 }
1151 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1152 if (ret_val)
1153 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001154
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001155 /* set auto-master slave resolution settings */
1156 if (hw->autoneg) {
1157 e1000_ms_type phy_ms_setting = hw->master_slave;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001158
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001159 if (hw->ffe_config_state == e1000_ffe_config_active)
1160 hw->ffe_config_state = e1000_ffe_config_enabled;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001161
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001162 if (hw->dsp_config_state == e1000_dsp_config_activated)
1163 hw->dsp_config_state = e1000_dsp_config_enabled;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001164
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001165 /* when autonegotiation advertisement is only 1000Mbps then we
1166 * should disable SmartSpeed and enable Auto MasterSlave
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001167 * resolution as hardware default.
1168 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001169 if (hw->autoneg_advertised == ADVERTISE_1000_FULL) {
1170 /* Disable SmartSpeed */
1171 ret_val =
1172 e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1173 &phy_data);
1174 if (ret_val)
1175 return ret_val;
1176 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1177 ret_val =
1178 e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1179 phy_data);
1180 if (ret_val)
1181 return ret_val;
1182 /* Set auto Master/Slave resolution process */
1183 ret_val =
1184 e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1185 if (ret_val)
1186 return ret_val;
1187 phy_data &= ~CR_1000T_MS_ENABLE;
1188 ret_val =
1189 e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1190 if (ret_val)
1191 return ret_val;
1192 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001194 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1195 if (ret_val)
1196 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001198 /* load defaults for future use */
1199 hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
1200 ((phy_data & CR_1000T_MS_VALUE) ?
1201 e1000_ms_force_master :
1202 e1000_ms_force_slave) : e1000_ms_auto;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001204 switch (phy_ms_setting) {
1205 case e1000_ms_force_master:
1206 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
1207 break;
1208 case e1000_ms_force_slave:
1209 phy_data |= CR_1000T_MS_ENABLE;
1210 phy_data &= ~(CR_1000T_MS_VALUE);
1211 break;
1212 case e1000_ms_auto:
1213 phy_data &= ~CR_1000T_MS_ENABLE;
1214 default:
1215 break;
1216 }
1217 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1218 if (ret_val)
1219 return ret_val;
1220 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001222 return E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001223}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001225/**
1226 * e1000_copper_link_mgp_setup - Copper link setup for e1000_phy_m88 series.
1227 * @hw: Struct containing variables accessed by shared code
1228 */
Joe Perches64798842008-07-11 15:17:02 -07001229static s32 e1000_copper_link_mgp_setup(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001230{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001231 s32 ret_val;
1232 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001234 if (hw->phy_reset_disable)
1235 return E1000_SUCCESS;
Auke Kok76c224b2006-05-23 13:36:06 -07001236
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001237 /* Enable CRS on TX. This must be set for half-duplex operation. */
1238 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1239 if (ret_val)
1240 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001241
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001242 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001243
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001244 /* Options:
1245 * MDI/MDI-X = 0 (default)
1246 * 0 - Auto for all speeds
1247 * 1 - MDI mode
1248 * 2 - MDI-X mode
1249 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1250 */
1251 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001252
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001253 switch (hw->mdix) {
1254 case 1:
1255 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
1256 break;
1257 case 2:
1258 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
1259 break;
1260 case 3:
1261 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
1262 break;
1263 case 0:
1264 default:
1265 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
1266 break;
1267 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001268
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001269 /* Options:
1270 * disable_polarity_correction = 0 (default)
1271 * Automatic Correction for Reversed Cable Polarity
1272 * 0 - Disabled
1273 * 1 - Enabled
1274 */
1275 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
1276 if (hw->disable_polarity_correction == 1)
1277 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
1278 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1279 if (ret_val)
1280 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001281
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001282 if (hw->phy_revision < M88E1011_I_REV_4) {
1283 /* Force TX_CLK in the Extended PHY Specific Control Register
1284 * to 25MHz clock.
1285 */
1286 ret_val =
1287 e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
1288 &phy_data);
1289 if (ret_val)
1290 return ret_val;
Auke Kokee040222006-06-27 09:08:03 -07001291
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001292 phy_data |= M88E1000_EPSCR_TX_CLK_25;
Auke Kokee040222006-06-27 09:08:03 -07001293
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001294 if ((hw->phy_revision == E1000_REVISION_2) &&
1295 (hw->phy_id == M88E1111_I_PHY_ID)) {
1296 /* Vidalia Phy, set the downshift counter to 5x */
1297 phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK);
1298 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
1299 ret_val = e1000_write_phy_reg(hw,
1300 M88E1000_EXT_PHY_SPEC_CTRL,
1301 phy_data);
1302 if (ret_val)
1303 return ret_val;
1304 } else {
1305 /* Configure Master and Slave downshift values */
1306 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
1307 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
1308 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
1309 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
1310 ret_val = e1000_write_phy_reg(hw,
1311 M88E1000_EXT_PHY_SPEC_CTRL,
1312 phy_data);
1313 if (ret_val)
1314 return ret_val;
1315 }
1316 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001318 /* SW Reset the PHY so all changes take effect */
1319 ret_val = e1000_phy_reset(hw);
1320 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00001321 e_dbg("Error Resetting the PHY\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001322 return ret_val;
1323 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001324
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001325 return E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001326}
1327
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001328/**
1329 * e1000_copper_link_autoneg - setup auto-neg
1330 * @hw: Struct containing variables accessed by shared code
1331 *
1332 * Setup auto-negotiation and flow control advertisements,
1333 * and then perform auto-negotiation.
1334 */
Joe Perches64798842008-07-11 15:17:02 -07001335static s32 e1000_copper_link_autoneg(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001336{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001337 s32 ret_val;
1338 u16 phy_data;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001339
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001340 /* Perform some bounds checking on the hw->autoneg_advertised
1341 * parameter. If this variable is zero, then set it to the default.
1342 */
1343 hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001344
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001345 /* If autoneg_advertised is zero, we assume it was not defaulted
1346 * by the calling code so we set to advertise full capability.
1347 */
1348 if (hw->autoneg_advertised == 0)
1349 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001350
Dirk Brandewie5377a412011-01-06 14:29:54 +00001351 /* IFE/RTL8201N PHY only supports 10/100 */
1352 if (hw->phy_type == e1000_phy_8201)
1353 hw->autoneg_advertised &= AUTONEG_ADVERTISE_10_100_ALL;
1354
Emil Tantilov675ad472010-04-27 14:02:58 +00001355 e_dbg("Reconfiguring auto-neg advertisement params\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001356 ret_val = e1000_phy_setup_autoneg(hw);
1357 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00001358 e_dbg("Error Setting up Auto-Negotiation\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001359 return ret_val;
1360 }
Emil Tantilov675ad472010-04-27 14:02:58 +00001361 e_dbg("Restarting Auto-Neg\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001362
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001363 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
1364 * the Auto Neg Restart bit in the PHY control register.
1365 */
1366 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
1367 if (ret_val)
1368 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001369
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001370 phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
1371 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
1372 if (ret_val)
1373 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001374
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001375 /* Does the user want to wait for Auto-Neg to complete here, or
1376 * check at a later time (for example, callback routine).
1377 */
1378 if (hw->wait_autoneg_complete) {
1379 ret_val = e1000_wait_autoneg(hw);
1380 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00001381 e_dbg
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001382 ("Error while waiting for autoneg to complete\n");
1383 return ret_val;
1384 }
1385 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001387 hw->get_link_status = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001389 return E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001390}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001392/**
1393 * e1000_copper_link_postconfig - post link setup
1394 * @hw: Struct containing variables accessed by shared code
1395 *
1396 * Config the MAC and the PHY after link is up.
1397 * 1) Set up the MAC to the current PHY speed/duplex
1398 * if we are on 82543. If we
1399 * are on newer silicon, we only need to configure
1400 * collision distance in the Transmit Control Register.
1401 * 2) Set up flow control on the MAC to that established with
1402 * the link partner.
1403 * 3) Config DSP to improve Gigabit link quality for some PHY revisions.
1404 */
Joe Perches64798842008-07-11 15:17:02 -07001405static s32 e1000_copper_link_postconfig(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001406{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001407 s32 ret_val;
Auke Kok76c224b2006-05-23 13:36:06 -07001408
Dirk Brandewie5377a412011-01-06 14:29:54 +00001409 if ((hw->mac_type >= e1000_82544) && (hw->mac_type != e1000_ce4100)) {
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001410 e1000_config_collision_dist(hw);
1411 } else {
1412 ret_val = e1000_config_mac_to_phy(hw);
1413 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00001414 e_dbg("Error configuring MAC to PHY settings\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001415 return ret_val;
1416 }
1417 }
1418 ret_val = e1000_config_fc_after_link_up(hw);
1419 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00001420 e_dbg("Error Configuring Flow Control\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001421 return ret_val;
1422 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001423
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001424 /* Config DSP to improve Giga link quality */
1425 if (hw->phy_type == e1000_phy_igp) {
1426 ret_val = e1000_config_dsp_after_link_change(hw, true);
1427 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00001428 e_dbg("Error Configuring DSP after link up\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001429 return ret_val;
1430 }
1431 }
Auke Kok76c224b2006-05-23 13:36:06 -07001432
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001433 return E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001434}
1435
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001436/**
1437 * e1000_setup_copper_link - phy/speed/duplex setting
1438 * @hw: Struct containing variables accessed by shared code
1439 *
1440 * Detects which PHY is present and sets up the speed and duplex
1441 */
Joe Perches64798842008-07-11 15:17:02 -07001442static s32 e1000_setup_copper_link(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001443{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001444 s32 ret_val;
1445 u16 i;
1446 u16 phy_data;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001447
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001448 /* Check if it is a valid PHY and set PHY mode if necessary. */
1449 ret_val = e1000_copper_link_preconfig(hw);
1450 if (ret_val)
1451 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001452
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001453 if (hw->phy_type == e1000_phy_igp) {
1454 ret_val = e1000_copper_link_igp_setup(hw);
1455 if (ret_val)
1456 return ret_val;
1457 } else if (hw->phy_type == e1000_phy_m88) {
1458 ret_val = e1000_copper_link_mgp_setup(hw);
1459 if (ret_val)
1460 return ret_val;
Dirk Brandewie5377a412011-01-06 14:29:54 +00001461 } else {
1462 ret_val = gbe_dhg_phy_setup(hw);
1463 if (ret_val) {
1464 e_dbg("gbe_dhg_phy_setup failed!\n");
1465 return ret_val;
1466 }
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001467 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001468
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001469 if (hw->autoneg) {
1470 /* Setup autoneg and flow control advertisement
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001471 * and perform autonegotiation
1472 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001473 ret_val = e1000_copper_link_autoneg(hw);
1474 if (ret_val)
1475 return ret_val;
1476 } else {
1477 /* PHY will be set to 10H, 10F, 100H,or 100F
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001478 * depending on value from forced_speed_duplex.
1479 */
Emil Tantilov675ad472010-04-27 14:02:58 +00001480 e_dbg("Forcing speed and duplex\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001481 ret_val = e1000_phy_force_speed_duplex(hw);
1482 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00001483 e_dbg("Error Forcing Speed and Duplex\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001484 return ret_val;
1485 }
1486 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001488 /* Check link status. Wait up to 100 microseconds for link to become
1489 * valid.
1490 */
1491 for (i = 0; i < 10; i++) {
1492 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
1493 if (ret_val)
1494 return ret_val;
1495 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
1496 if (ret_val)
1497 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001499 if (phy_data & MII_SR_LINK_STATUS) {
1500 /* Config the MAC and PHY after link is up */
1501 ret_val = e1000_copper_link_postconfig(hw);
1502 if (ret_val)
1503 return ret_val;
Auke Kok76c224b2006-05-23 13:36:06 -07001504
Emil Tantilov675ad472010-04-27 14:02:58 +00001505 e_dbg("Valid link established!!!\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001506 return E1000_SUCCESS;
1507 }
1508 udelay(10);
1509 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510
Emil Tantilov675ad472010-04-27 14:02:58 +00001511 e_dbg("Unable to establish link!!!\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001512 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513}
1514
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001515/**
1516 * e1000_phy_setup_autoneg - phy settings
1517 * @hw: Struct containing variables accessed by shared code
1518 *
1519 * Configures PHY autoneg and flow control advertisement settings
1520 */
Joe Perches64798842008-07-11 15:17:02 -07001521s32 e1000_phy_setup_autoneg(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001523 s32 ret_val;
1524 u16 mii_autoneg_adv_reg;
1525 u16 mii_1000t_ctrl_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001527 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
1528 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
1529 if (ret_val)
1530 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001532 /* Read the MII 1000Base-T Control Register (Address 9). */
Dirk Brandewie5377a412011-01-06 14:29:54 +00001533 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001534 if (ret_val)
1535 return ret_val;
Dirk Brandewie5377a412011-01-06 14:29:54 +00001536 else if (hw->phy_type == e1000_phy_8201)
1537 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001539 /* Need to parse both autoneg_advertised and fc and set up
1540 * the appropriate PHY registers. First we will parse for
1541 * autoneg_advertised software override. Since we can advertise
1542 * a plethora of combinations, we need to check each bit
1543 * individually.
1544 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001546 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
1547 * Advertisement Register (Address 4) and the 1000 mb speed bits in
1548 * the 1000Base-T Control Register (Address 9).
1549 */
1550 mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
1551 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552
Emil Tantilov675ad472010-04-27 14:02:58 +00001553 e_dbg("autoneg_advertised %x\n", hw->autoneg_advertised);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001555 /* Do we want to advertise 10 Mb Half Duplex? */
1556 if (hw->autoneg_advertised & ADVERTISE_10_HALF) {
Emil Tantilov675ad472010-04-27 14:02:58 +00001557 e_dbg("Advertise 10mb Half duplex\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001558 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
1559 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001561 /* Do we want to advertise 10 Mb Full Duplex? */
1562 if (hw->autoneg_advertised & ADVERTISE_10_FULL) {
Emil Tantilov675ad472010-04-27 14:02:58 +00001563 e_dbg("Advertise 10mb Full duplex\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001564 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
1565 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001567 /* Do we want to advertise 100 Mb Half Duplex? */
1568 if (hw->autoneg_advertised & ADVERTISE_100_HALF) {
Emil Tantilov675ad472010-04-27 14:02:58 +00001569 e_dbg("Advertise 100mb Half duplex\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001570 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
1571 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001573 /* Do we want to advertise 100 Mb Full Duplex? */
1574 if (hw->autoneg_advertised & ADVERTISE_100_FULL) {
Emil Tantilov675ad472010-04-27 14:02:58 +00001575 e_dbg("Advertise 100mb Full duplex\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001576 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
1577 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001579 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
1580 if (hw->autoneg_advertised & ADVERTISE_1000_HALF) {
Emil Tantilov675ad472010-04-27 14:02:58 +00001581 e_dbg
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001582 ("Advertise 1000mb Half duplex requested, request denied!\n");
1583 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001585 /* Do we want to advertise 1000 Mb Full Duplex? */
1586 if (hw->autoneg_advertised & ADVERTISE_1000_FULL) {
Emil Tantilov675ad472010-04-27 14:02:58 +00001587 e_dbg("Advertise 1000mb Full duplex\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001588 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
1589 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001591 /* Check for a software override of the flow control settings, and
1592 * setup the PHY advertisement registers accordingly. If
1593 * auto-negotiation is enabled, then software will have to set the
1594 * "PAUSE" bits to the correct value in the Auto-Negotiation
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001595 * Advertisement Register (PHY_AUTONEG_ADV) and re-start
1596 * auto-negotiation.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001597 *
1598 * The possible values of the "fc" parameter are:
1599 * 0: Flow control is completely disabled
1600 * 1: Rx flow control is enabled (we can receive pause frames
1601 * but not send pause frames).
1602 * 2: Tx flow control is enabled (we can send pause frames
1603 * but we do not support receiving pause frames).
1604 * 3: Both Rx and TX flow control (symmetric) are enabled.
1605 * other: No software override. The flow control configuration
1606 * in the EEPROM is used.
1607 */
1608 switch (hw->fc) {
1609 case E1000_FC_NONE: /* 0 */
1610 /* Flow control (RX & TX) is completely disabled by a
1611 * software over-ride.
1612 */
1613 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1614 break;
1615 case E1000_FC_RX_PAUSE: /* 1 */
1616 /* RX Flow control is enabled, and TX Flow control is
1617 * disabled, by a software over-ride.
1618 */
1619 /* Since there really isn't a way to advertise that we are
1620 * capable of RX Pause ONLY, we will advertise that we
1621 * support both symmetric and asymmetric RX PAUSE. Later
1622 * (in e1000_config_fc_after_link_up) we will disable the
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001623 * hw's ability to send PAUSE frames.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001624 */
1625 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1626 break;
1627 case E1000_FC_TX_PAUSE: /* 2 */
1628 /* TX Flow control is enabled, and RX Flow control is
1629 * disabled, by a software over-ride.
1630 */
1631 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
1632 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
1633 break;
1634 case E1000_FC_FULL: /* 3 */
1635 /* Flow control (both RX and TX) is enabled by a software
1636 * over-ride.
1637 */
1638 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1639 break;
1640 default:
Emil Tantilov675ad472010-04-27 14:02:58 +00001641 e_dbg("Flow control param set incorrectly\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001642 return -E1000_ERR_CONFIG;
1643 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001645 ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
1646 if (ret_val)
1647 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648
Emil Tantilov675ad472010-04-27 14:02:58 +00001649 e_dbg("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650
Dirk Brandewie5377a412011-01-06 14:29:54 +00001651 if (hw->phy_type == e1000_phy_8201) {
1652 mii_1000t_ctrl_reg = 0;
1653 } else {
1654 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL,
Janusz Wolaka48954c2015-09-17 23:34:29 +02001655 mii_1000t_ctrl_reg);
Dirk Brandewie5377a412011-01-06 14:29:54 +00001656 if (ret_val)
1657 return ret_val;
1658 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001660 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661}
1662
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001663/**
1664 * e1000_phy_force_speed_duplex - force link settings
1665 * @hw: Struct containing variables accessed by shared code
1666 *
1667 * Force PHY speed and duplex settings to hw->forced_speed_duplex
1668 */
Joe Perches64798842008-07-11 15:17:02 -07001669static s32 e1000_phy_force_speed_duplex(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001671 u32 ctrl;
1672 s32 ret_val;
1673 u16 mii_ctrl_reg;
1674 u16 mii_status_reg;
1675 u16 phy_data;
1676 u16 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001678 /* Turn off Flow control if we are forcing speed and duplex. */
1679 hw->fc = E1000_FC_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680
Emil Tantilov675ad472010-04-27 14:02:58 +00001681 e_dbg("hw->fc = %d\n", hw->fc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001683 /* Read the Device Control Register. */
1684 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001686 /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */
1687 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1688 ctrl &= ~(DEVICE_SPEED_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001690 /* Clear the Auto Speed Detect Enable bit. */
1691 ctrl &= ~E1000_CTRL_ASDE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001693 /* Read the MII Control Register. */
1694 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg);
1695 if (ret_val)
1696 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001698 /* We need to disable autoneg in order to force link and duplex. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001700 mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001702 /* Are we forcing Full or Half Duplex? */
1703 if (hw->forced_speed_duplex == e1000_100_full ||
1704 hw->forced_speed_duplex == e1000_10_full) {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001705 /* We want to force full duplex so we SET the full duplex bits
1706 * in the Device and MII Control Registers.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001707 */
1708 ctrl |= E1000_CTRL_FD;
1709 mii_ctrl_reg |= MII_CR_FULL_DUPLEX;
Emil Tantilov675ad472010-04-27 14:02:58 +00001710 e_dbg("Full Duplex\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001711 } else {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001712 /* We want to force half duplex so we CLEAR the full duplex bits
1713 * in the Device and MII Control Registers.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001714 */
1715 ctrl &= ~E1000_CTRL_FD;
1716 mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX;
Emil Tantilov675ad472010-04-27 14:02:58 +00001717 e_dbg("Half Duplex\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001718 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001720 /* Are we forcing 100Mbps??? */
1721 if (hw->forced_speed_duplex == e1000_100_full ||
1722 hw->forced_speed_duplex == e1000_100_half) {
1723 /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */
1724 ctrl |= E1000_CTRL_SPD_100;
1725 mii_ctrl_reg |= MII_CR_SPEED_100;
1726 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
Emil Tantilov675ad472010-04-27 14:02:58 +00001727 e_dbg("Forcing 100mb ");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001728 } else {
1729 /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */
1730 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1731 mii_ctrl_reg |= MII_CR_SPEED_10;
1732 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
Emil Tantilov675ad472010-04-27 14:02:58 +00001733 e_dbg("Forcing 10mb ");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001734 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001736 e1000_config_collision_dist(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001738 /* Write the configured values back to the Device Control Reg. */
1739 ew32(CTRL, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001741 if (hw->phy_type == e1000_phy_m88) {
1742 ret_val =
1743 e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1744 if (ret_val)
1745 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001747 /* Clear Auto-Crossover to force MDI manually. M88E1000 requires
1748 * MDI forced whenever speed are duplex are forced.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001749 */
1750 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1751 ret_val =
1752 e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1753 if (ret_val)
1754 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755
Emil Tantilov675ad472010-04-27 14:02:58 +00001756 e_dbg("M88E1000 PSCR: %x\n", phy_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001758 /* Need to reset the PHY or these changes will be ignored */
1759 mii_ctrl_reg |= MII_CR_RESET;
Auke Kok90fb5132006-11-01 08:47:30 -08001760
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001761 /* Disable MDI-X support for 10/100 */
1762 } else {
1763 /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
1764 * forced whenever speed or duplex are forced.
1765 */
1766 ret_val =
1767 e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1768 if (ret_val)
1769 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001771 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1772 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001774 ret_val =
1775 e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1776 if (ret_val)
1777 return ret_val;
1778 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001780 /* Write back the modified PHY MII control register. */
1781 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg);
1782 if (ret_val)
1783 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001785 udelay(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001787 /* The wait_autoneg_complete flag may be a little misleading here.
1788 * Since we are forcing speed and duplex, Auto-Neg is not enabled.
1789 * But we do want to delay for a period while forcing only so we
1790 * don't generate false No Link messages. So we will wait here
1791 * only if the user has set wait_autoneg_complete to 1, which is
1792 * the default.
1793 */
1794 if (hw->wait_autoneg_complete) {
1795 /* We will wait for autoneg to complete. */
Emil Tantilov675ad472010-04-27 14:02:58 +00001796 e_dbg("Waiting for forced speed/duplex link.\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001797 mii_status_reg = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001799 /* Wait for autoneg to complete or 4.5 seconds to expire */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001800 for (i = PHY_FORCE_TIME; i > 0; i--) {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001801 /* Read the MII Status Register and wait for Auto-Neg
1802 * Complete bit to be set.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001803 */
1804 ret_val =
1805 e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1806 if (ret_val)
1807 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001809 ret_val =
1810 e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1811 if (ret_val)
1812 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001814 if (mii_status_reg & MII_SR_LINK_STATUS)
1815 break;
1816 msleep(100);
1817 }
1818 if ((i == 0) && (hw->phy_type == e1000_phy_m88)) {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001819 /* We didn't get link. Reset the DSP and wait again
1820 * for link.
1821 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001822 ret_val = e1000_phy_reset_dsp(hw);
1823 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00001824 e_dbg("Error Resetting PHY DSP\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001825 return ret_val;
1826 }
1827 }
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001828 /* This loop will early-out if the link condition has been
1829 * met
1830 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001831 for (i = PHY_FORCE_TIME; i > 0; i--) {
1832 if (mii_status_reg & MII_SR_LINK_STATUS)
1833 break;
1834 msleep(100);
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001835 /* Read the MII Status Register and wait for Auto-Neg
1836 * Complete bit to be set.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001837 */
1838 ret_val =
1839 e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1840 if (ret_val)
1841 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001843 ret_val =
1844 e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1845 if (ret_val)
1846 return ret_val;
1847 }
1848 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001850 if (hw->phy_type == e1000_phy_m88) {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001851 /* Because we reset the PHY above, we need to re-force TX_CLK in
1852 * the Extended PHY Specific Control Register to 25MHz clock.
1853 * This value defaults back to a 2.5MHz clock when the PHY is
1854 * reset.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001855 */
1856 ret_val =
1857 e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
1858 &phy_data);
1859 if (ret_val)
1860 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001862 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1863 ret_val =
1864 e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
1865 phy_data);
1866 if (ret_val)
1867 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001869 /* In addition, because of the s/w reset above, we need to
1870 * enable CRS on Tx. This must be set for both full and half
1871 * duplex operation.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001872 */
1873 ret_val =
1874 e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1875 if (ret_val)
1876 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001878 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1879 ret_val =
1880 e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1881 if (ret_val)
1882 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001884 if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543)
1885 && (!hw->autoneg)
1886 && (hw->forced_speed_duplex == e1000_10_full
1887 || hw->forced_speed_duplex == e1000_10_half)) {
1888 ret_val = e1000_polarity_reversal_workaround(hw);
1889 if (ret_val)
1890 return ret_val;
1891 }
1892 }
1893 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894}
1895
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001896/**
1897 * e1000_config_collision_dist - set collision distance register
1898 * @hw: Struct containing variables accessed by shared code
1899 *
1900 * Sets the collision distance in the Transmit Control register.
1901 * Link should have been established previously. Reads the speed and duplex
1902 * information from the Device Status register.
1903 */
Joe Perches64798842008-07-11 15:17:02 -07001904void e1000_config_collision_dist(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001906 u32 tctl, coll_dist;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001908 if (hw->mac_type < e1000_82543)
1909 coll_dist = E1000_COLLISION_DISTANCE_82542;
1910 else
1911 coll_dist = E1000_COLLISION_DISTANCE;
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001912
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001913 tctl = er32(TCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001914
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001915 tctl &= ~E1000_TCTL_COLD;
1916 tctl |= coll_dist << E1000_COLD_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001918 ew32(TCTL, tctl);
1919 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920}
1921
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001922/**
1923 * e1000_config_mac_to_phy - sync phy and mac settings
1924 * @hw: Struct containing variables accessed by shared code
1925 * @mii_reg: data to write to the MII control register
1926 *
1927 * Sets MAC speed and duplex settings to reflect the those in the PHY
1928 * The contents of the PHY register containing the needed information need to
1929 * be passed in.
1930 */
Joe Perches64798842008-07-11 15:17:02 -07001931static s32 e1000_config_mac_to_phy(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001933 u32 ctrl;
1934 s32 ret_val;
1935 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001937 /* 82544 or newer MAC, Auto Speed Detection takes care of
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001938 * MAC speed/duplex configuration.
1939 */
Dirk Brandewie5377a412011-01-06 14:29:54 +00001940 if ((hw->mac_type >= e1000_82544) && (hw->mac_type != e1000_ce4100))
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001941 return E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001942
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001943 /* Read the Device Control Register and set the bits to Force Speed
1944 * and Duplex.
1945 */
1946 ctrl = er32(CTRL);
1947 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1948 ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949
Dirk Brandewie5377a412011-01-06 14:29:54 +00001950 switch (hw->phy_type) {
1951 case e1000_phy_8201:
1952 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
1953 if (ret_val)
1954 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955
Dirk Brandewie5377a412011-01-06 14:29:54 +00001956 if (phy_data & RTL_PHY_CTRL_FD)
1957 ctrl |= E1000_CTRL_FD;
1958 else
1959 ctrl &= ~E1000_CTRL_FD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960
Dirk Brandewie5377a412011-01-06 14:29:54 +00001961 if (phy_data & RTL_PHY_CTRL_SPD_100)
1962 ctrl |= E1000_CTRL_SPD_100;
1963 else
1964 ctrl |= E1000_CTRL_SPD_10;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001965
Dirk Brandewie5377a412011-01-06 14:29:54 +00001966 e1000_config_collision_dist(hw);
1967 break;
1968 default:
1969 /* Set up duplex in the Device Control and Transmit Control
1970 * registers depending on negotiated values.
1971 */
1972 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001973 &phy_data);
Dirk Brandewie5377a412011-01-06 14:29:54 +00001974 if (ret_val)
1975 return ret_val;
1976
1977 if (phy_data & M88E1000_PSSR_DPLX)
1978 ctrl |= E1000_CTRL_FD;
1979 else
1980 ctrl &= ~E1000_CTRL_FD;
1981
1982 e1000_config_collision_dist(hw);
1983
1984 /* Set up speed in the Device Control register depending on
1985 * negotiated values.
1986 */
1987 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
1988 ctrl |= E1000_CTRL_SPD_1000;
1989 else if ((phy_data & M88E1000_PSSR_SPEED) ==
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001990 M88E1000_PSSR_100MBS)
Dirk Brandewie5377a412011-01-06 14:29:54 +00001991 ctrl |= E1000_CTRL_SPD_100;
1992 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001993
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001994 /* Write the configured values back to the Device Control Reg. */
1995 ew32(CTRL, ctrl);
1996 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001997}
1998
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001999/**
2000 * e1000_force_mac_fc - force flow control settings
2001 * @hw: Struct containing variables accessed by shared code
2002 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003 * Forces the MAC's flow control settings.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004 * Sets the TFCE and RFCE bits in the device control register to reflect
2005 * the adapter settings. TFCE and RFCE need to be explicitly set by
2006 * software when a Copper PHY is used because autonegotiation is managed
2007 * by the PHY rather than the MAC. Software must also configure these
2008 * bits when link is forced on a fiber connection.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002009 */
Joe Perches64798842008-07-11 15:17:02 -07002010s32 e1000_force_mac_fc(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002012 u32 ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002013
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002014 /* Get the current configuration of the Device Control Register */
2015 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002016
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002017 /* Because we didn't get link via the internal auto-negotiation
2018 * mechanism (we either forced link or we got link via PHY
2019 * auto-neg), we have to manually enable/disable transmit an
2020 * receive flow control.
2021 *
2022 * The "Case" statement below enables/disable flow control
2023 * according to the "hw->fc" parameter.
2024 *
2025 * The possible values of the "fc" parameter are:
2026 * 0: Flow control is completely disabled
2027 * 1: Rx flow control is enabled (we can receive pause
2028 * frames but not send pause frames).
2029 * 2: Tx flow control is enabled (we can send pause frames
2030 * frames but we do not receive pause frames).
2031 * 3: Both Rx and TX flow control (symmetric) is enabled.
2032 * other: No other values should be possible at this point.
2033 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002035 switch (hw->fc) {
2036 case E1000_FC_NONE:
2037 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
2038 break;
2039 case E1000_FC_RX_PAUSE:
2040 ctrl &= (~E1000_CTRL_TFCE);
2041 ctrl |= E1000_CTRL_RFCE;
2042 break;
2043 case E1000_FC_TX_PAUSE:
2044 ctrl &= (~E1000_CTRL_RFCE);
2045 ctrl |= E1000_CTRL_TFCE;
2046 break;
2047 case E1000_FC_FULL:
2048 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
2049 break;
2050 default:
Emil Tantilov675ad472010-04-27 14:02:58 +00002051 e_dbg("Flow control param set incorrectly\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002052 return -E1000_ERR_CONFIG;
2053 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002055 /* Disable TX Flow Control for 82542 (rev 2.0) */
2056 if (hw->mac_type == e1000_82542_rev2_0)
2057 ctrl &= (~E1000_CTRL_TFCE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002059 ew32(CTRL, ctrl);
2060 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061}
2062
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002063/**
2064 * e1000_config_fc_after_link_up - configure flow control after autoneg
2065 * @hw: Struct containing variables accessed by shared code
2066 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067 * Configures flow control settings after link is established
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068 * Should be called immediately after a valid link has been established.
2069 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
2070 * and autonegotiation is enabled, the MAC flow control settings will be set
2071 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002072 * and RFCE bits will be automatically set to the negotiated flow control mode.
2073 */
Joe Perches64798842008-07-11 15:17:02 -07002074static s32 e1000_config_fc_after_link_up(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002076 s32 ret_val;
2077 u16 mii_status_reg;
2078 u16 mii_nway_adv_reg;
2079 u16 mii_nway_lp_ability_reg;
2080 u16 speed;
2081 u16 duplex;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002083 /* Check for the case where we have fiber media and auto-neg failed
2084 * so we had to force link. In this case, we need to force the
2085 * configuration of the MAC to match the "fc" parameter.
2086 */
2087 if (((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed))
2088 || ((hw->media_type == e1000_media_type_internal_serdes)
2089 && (hw->autoneg_failed))
2090 || ((hw->media_type == e1000_media_type_copper)
2091 && (!hw->autoneg))) {
2092 ret_val = e1000_force_mac_fc(hw);
2093 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00002094 e_dbg("Error forcing flow control settings\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002095 return ret_val;
2096 }
2097 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002099 /* Check for the case where we have copper media and auto-neg is
2100 * enabled. In this case, we need to check and see if Auto-Neg
2101 * has completed, and if so, how the PHY and link partner has
2102 * flow control configured.
2103 */
2104 if ((hw->media_type == e1000_media_type_copper) && hw->autoneg) {
2105 /* Read the MII Status Register and check to see if AutoNeg
2106 * has completed. We read this twice because this reg has
2107 * some "sticky" (latched) bits.
2108 */
2109 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2110 if (ret_val)
2111 return ret_val;
2112 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2113 if (ret_val)
2114 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002116 if (mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
2117 /* The AutoNeg process has completed, so we now need to
2118 * read both the Auto Negotiation Advertisement Register
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002119 * (Address 4) and the Auto_Negotiation Base Page
2120 * Ability Register (Address 5) to determine how flow
2121 * control was negotiated.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002122 */
2123 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV,
2124 &mii_nway_adv_reg);
2125 if (ret_val)
2126 return ret_val;
2127 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY,
2128 &mii_nway_lp_ability_reg);
2129 if (ret_val)
2130 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002132 /* Two bits in the Auto Negotiation Advertisement
2133 * Register (Address 4) and two bits in the Auto
2134 * Negotiation Base Page Ability Register (Address 5)
2135 * determine flow control for both the PHY and the link
2136 * partner. The following table, taken out of the IEEE
2137 * 802.3ab/D6.0 dated March 25, 1999, describes these
2138 * PAUSE resolution bits and how flow control is
2139 * determined based upon these settings.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002140 * NOTE: DC = Don't Care
2141 *
2142 * LOCAL DEVICE | LINK PARTNER
2143 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002144 *-------|---------|-------|---------|------------------
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002145 * 0 | 0 | DC | DC | E1000_FC_NONE
2146 * 0 | 1 | 0 | DC | E1000_FC_NONE
2147 * 0 | 1 | 1 | 0 | E1000_FC_NONE
2148 * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
2149 * 1 | 0 | 0 | DC | E1000_FC_NONE
2150 * 1 | DC | 1 | DC | E1000_FC_FULL
2151 * 1 | 1 | 0 | 0 | E1000_FC_NONE
2152 * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
2153 *
2154 */
2155 /* Are both PAUSE bits set to 1? If so, this implies
2156 * Symmetric Flow Control is enabled at both ends. The
2157 * ASM_DIR bits are irrelevant per the spec.
2158 *
2159 * For Symmetric Flow Control:
2160 *
2161 * LOCAL DEVICE | LINK PARTNER
2162 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002163 *-------|---------|-------|---------|------------------
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002164 * 1 | DC | 1 | DC | E1000_FC_FULL
2165 *
2166 */
2167 if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2168 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002169 /* Now we need to check if the user selected Rx
2170 * ONLY of pause frames. In this case, we had
2171 * to advertise FULL flow control because we
2172 * could not advertise Rx ONLY. Hence, we must
2173 * now check to see if we need to turn OFF the
2174 * TRANSMISSION of PAUSE frames.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002175 */
2176 if (hw->original_fc == E1000_FC_FULL) {
2177 hw->fc = E1000_FC_FULL;
Emil Tantilov675ad472010-04-27 14:02:58 +00002178 e_dbg("Flow Control = FULL.\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002179 } else {
2180 hw->fc = E1000_FC_RX_PAUSE;
Emil Tantilov675ad472010-04-27 14:02:58 +00002181 e_dbg
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002182 ("Flow Control = RX PAUSE frames only.\n");
2183 }
2184 }
2185 /* For receiving PAUSE frames ONLY.
2186 *
2187 * LOCAL DEVICE | LINK PARTNER
2188 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002189 *-------|---------|-------|---------|------------------
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002190 * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
2191 *
2192 */
2193 else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2194 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2195 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
Janusz Wolaka48954c2015-09-17 23:34:29 +02002196 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002197 hw->fc = E1000_FC_TX_PAUSE;
Emil Tantilov675ad472010-04-27 14:02:58 +00002198 e_dbg
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002199 ("Flow Control = TX PAUSE frames only.\n");
2200 }
2201 /* For transmitting PAUSE frames ONLY.
2202 *
2203 * LOCAL DEVICE | LINK PARTNER
2204 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002205 *-------|---------|-------|---------|------------------
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002206 * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
2207 *
2208 */
2209 else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2210 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2211 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
Janusz Wolaka48954c2015-09-17 23:34:29 +02002212 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002213 hw->fc = E1000_FC_RX_PAUSE;
Emil Tantilov675ad472010-04-27 14:02:58 +00002214 e_dbg
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002215 ("Flow Control = RX PAUSE frames only.\n");
2216 }
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002217 /* Per the IEEE spec, at this point flow control should
2218 * be disabled. However, we want to consider that we
2219 * could be connected to a legacy switch that doesn't
2220 * advertise desired flow control, but can be forced on
2221 * the link partner. So if we advertised no flow
2222 * control, that is what we will resolve to. If we
2223 * advertised some kind of receive capability (Rx Pause
2224 * Only or Full Flow Control) and the link partner
2225 * advertised none, we will configure ourselves to
2226 * enable Rx Flow Control only. We can do this safely
2227 * for two reasons: If the link partner really
2228 * didn't want flow control enabled, and we enable Rx,
2229 * no harm done since we won't be receiving any PAUSE
2230 * frames anyway. If the intent on the link partner was
2231 * to have flow control enabled, then by us enabling Rx
2232 * only, we can at least receive pause frames and
2233 * process them. This is a good idea because in most
2234 * cases, since we are predominantly a server NIC, more
2235 * times than not we will be asked to delay transmission
2236 * of packets than asking our link partner to pause
2237 * transmission of frames.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002238 */
2239 else if ((hw->original_fc == E1000_FC_NONE ||
2240 hw->original_fc == E1000_FC_TX_PAUSE) ||
2241 hw->fc_strict_ieee) {
2242 hw->fc = E1000_FC_NONE;
Emil Tantilov675ad472010-04-27 14:02:58 +00002243 e_dbg("Flow Control = NONE.\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002244 } else {
2245 hw->fc = E1000_FC_RX_PAUSE;
Emil Tantilov675ad472010-04-27 14:02:58 +00002246 e_dbg
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002247 ("Flow Control = RX PAUSE frames only.\n");
2248 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002250 /* Now we need to do one last check... If we auto-
2251 * negotiated to HALF DUPLEX, flow control should not be
2252 * enabled per IEEE 802.3 spec.
2253 */
2254 ret_val =
2255 e1000_get_speed_and_duplex(hw, &speed, &duplex);
2256 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00002257 e_dbg
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002258 ("Error getting link speed and duplex\n");
2259 return ret_val;
2260 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002262 if (duplex == HALF_DUPLEX)
2263 hw->fc = E1000_FC_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002265 /* Now we call a subroutine to actually force the MAC
2266 * controller to use the correct flow control settings.
2267 */
2268 ret_val = e1000_force_mac_fc(hw);
2269 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00002270 e_dbg
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002271 ("Error forcing flow control settings\n");
2272 return ret_val;
2273 }
2274 } else {
Emil Tantilov675ad472010-04-27 14:02:58 +00002275 e_dbg
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002276 ("Copper PHY and Auto Neg has not completed.\n");
2277 }
2278 }
2279 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280}
2281
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002282/**
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002283 * e1000_check_for_serdes_link_generic - Check for link (Serdes)
2284 * @hw: pointer to the HW structure
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002285 *
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002286 * Checks for link up on the hardware. If link is not up and we have
2287 * a signal, then we need to force link up.
2288 */
Jesse Brandeburg11b7f7b2009-09-25 12:20:33 +00002289static s32 e1000_check_for_serdes_link_generic(struct e1000_hw *hw)
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002290{
2291 u32 rxcw;
2292 u32 ctrl;
2293 u32 status;
2294 s32 ret_val = E1000_SUCCESS;
2295
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002296 ctrl = er32(CTRL);
2297 status = er32(STATUS);
2298 rxcw = er32(RXCW);
2299
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002300 /* If we don't have link (auto-negotiation failed or link partner
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002301 * cannot auto-negotiate), and our link partner is not trying to
2302 * auto-negotiate with us (we are receiving idles or data),
2303 * we need to force link up. We also need to give auto-negotiation
2304 * time to complete.
2305 */
2306 /* (ctrl & E1000_CTRL_SWDPIN1) == 1 == have signal */
2307 if ((!(status & E1000_STATUS_LU)) && (!(rxcw & E1000_RXCW_C))) {
2308 if (hw->autoneg_failed == 0) {
2309 hw->autoneg_failed = 1;
2310 goto out;
2311 }
Emil Tantilov675ad472010-04-27 14:02:58 +00002312 e_dbg("NOT RXing /C/, disable AutoNeg and force link.\n");
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002313
2314 /* Disable auto-negotiation in the TXCW register */
2315 ew32(TXCW, (hw->txcw & ~E1000_TXCW_ANE));
2316
2317 /* Force link-up and also force full-duplex. */
2318 ctrl = er32(CTRL);
2319 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
2320 ew32(CTRL, ctrl);
2321
2322 /* Configure Flow Control after forcing link up. */
2323 ret_val = e1000_config_fc_after_link_up(hw);
2324 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00002325 e_dbg("Error configuring flow control\n");
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002326 goto out;
2327 }
2328 } else if ((ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002329 /* If we are forcing link and we are receiving /C/ ordered
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002330 * sets, re-enable auto-negotiation in the TXCW register
2331 * and disable forced link in the Device Control register
2332 * in an attempt to auto-negotiate with our link partner.
2333 */
Emil Tantilov675ad472010-04-27 14:02:58 +00002334 e_dbg("RXing /C/, enable AutoNeg and stop forcing link.\n");
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002335 ew32(TXCW, hw->txcw);
2336 ew32(CTRL, (ctrl & ~E1000_CTRL_SLU));
2337
2338 hw->serdes_has_link = true;
2339 } else if (!(E1000_TXCW_ANE & er32(TXCW))) {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002340 /* If we force link for non-auto-negotiation switch, check
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002341 * link status based on MAC synchronization for internal
2342 * serdes media type.
2343 */
2344 /* SYNCH bit and IV bit are sticky. */
2345 udelay(10);
2346 rxcw = er32(RXCW);
2347 if (rxcw & E1000_RXCW_SYNCH) {
2348 if (!(rxcw & E1000_RXCW_IV)) {
2349 hw->serdes_has_link = true;
Emil Tantilov675ad472010-04-27 14:02:58 +00002350 e_dbg("SERDES: Link up - forced.\n");
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002351 }
2352 } else {
2353 hw->serdes_has_link = false;
Emil Tantilov675ad472010-04-27 14:02:58 +00002354 e_dbg("SERDES: Link down - force failed.\n");
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002355 }
2356 }
2357
2358 if (E1000_TXCW_ANE & er32(TXCW)) {
2359 status = er32(STATUS);
2360 if (status & E1000_STATUS_LU) {
2361 /* SYNCH bit and IV bit are sticky, so reread rxcw. */
2362 udelay(10);
2363 rxcw = er32(RXCW);
2364 if (rxcw & E1000_RXCW_SYNCH) {
2365 if (!(rxcw & E1000_RXCW_IV)) {
2366 hw->serdes_has_link = true;
Emil Tantilov675ad472010-04-27 14:02:58 +00002367 e_dbg("SERDES: Link up - autoneg "
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002368 "completed successfully.\n");
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002369 } else {
2370 hw->serdes_has_link = false;
Emil Tantilov675ad472010-04-27 14:02:58 +00002371 e_dbg("SERDES: Link down - invalid"
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002372 "codewords detected in autoneg.\n");
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002373 }
2374 } else {
2375 hw->serdes_has_link = false;
Emil Tantilov675ad472010-04-27 14:02:58 +00002376 e_dbg("SERDES: Link down - no sync.\n");
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002377 }
2378 } else {
2379 hw->serdes_has_link = false;
Emil Tantilov675ad472010-04-27 14:02:58 +00002380 e_dbg("SERDES: Link down - autoneg failed\n");
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002381 }
2382 }
2383
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002384 out:
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002385 return ret_val;
2386}
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002387
2388/**
2389 * e1000_check_for_link
2390 * @hw: Struct containing variables accessed by shared code
2391 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392 * Checks to see if the link status of the hardware has changed.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393 * Called by any function that needs to check the link status of the adapter.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002394 */
Joe Perches64798842008-07-11 15:17:02 -07002395s32 e1000_check_for_link(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002397 u32 rxcw = 0;
2398 u32 ctrl;
2399 u32 status;
2400 u32 rctl;
2401 u32 icr;
2402 u32 signal = 0;
2403 s32 ret_val;
2404 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002405
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002406 ctrl = er32(CTRL);
2407 status = er32(STATUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002409 /* On adapters with a MAC newer than 82544, SW Definable pin 1 will be
2410 * set when the optics detect a signal. On older adapters, it will be
2411 * cleared when there is a signal. This applies to fiber media only.
2412 */
2413 if ((hw->media_type == e1000_media_type_fiber) ||
2414 (hw->media_type == e1000_media_type_internal_serdes)) {
2415 rxcw = er32(RXCW);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002417 if (hw->media_type == e1000_media_type_fiber) {
2418 signal =
2419 (hw->mac_type >
2420 e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
2421 if (status & E1000_STATUS_LU)
2422 hw->get_link_status = false;
2423 }
2424 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002426 /* If we have a copper PHY then we only want to go out to the PHY
2427 * registers to see if Auto-Neg has completed and/or if our link
2428 * status has changed. The get_link_status flag will be set if we
2429 * receive a Link Status Change interrupt or we have Rx Sequence
2430 * Errors.
2431 */
2432 if ((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
2433 /* First we want to see if the MII Status Register reports
2434 * link. If so, then we want to get the current speed/duplex
2435 * of the PHY.
2436 * Read the register twice since the link bit is sticky.
2437 */
2438 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2439 if (ret_val)
2440 return ret_val;
2441 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2442 if (ret_val)
2443 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002445 if (phy_data & MII_SR_LINK_STATUS) {
2446 hw->get_link_status = false;
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002447 /* Check if there was DownShift, must be checked
2448 * immediately after link-up
2449 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002450 e1000_check_downshift(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002451
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002452 /* If we are on 82544 or 82543 silicon and speed/duplex
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002453 * are forced to 10H or 10F, then we will implement the
2454 * polarity reversal workaround. We disable interrupts
2455 * first, and upon returning, place the devices
2456 * interrupt state to its previous value except for the
2457 * link status change interrupt which will
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002458 * happen due to the execution of this workaround.
2459 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002460
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002461 if ((hw->mac_type == e1000_82544
2462 || hw->mac_type == e1000_82543) && (!hw->autoneg)
2463 && (hw->forced_speed_duplex == e1000_10_full
2464 || hw->forced_speed_duplex == e1000_10_half)) {
2465 ew32(IMC, 0xffffffff);
2466 ret_val =
2467 e1000_polarity_reversal_workaround(hw);
2468 icr = er32(ICR);
2469 ew32(ICS, (icr & ~E1000_ICS_LSC));
2470 ew32(IMS, IMS_ENABLE_MASK);
2471 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002473 } else {
2474 /* No link detected */
2475 e1000_config_dsp_after_link_change(hw, false);
2476 return 0;
2477 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002478
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002479 /* If we are forcing speed/duplex, then we simply return since
2480 * we have already determined whether we have link or not.
2481 */
2482 if (!hw->autoneg)
2483 return -E1000_ERR_CONFIG;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002485 /* optimize the dsp settings for the igp phy */
2486 e1000_config_dsp_after_link_change(hw, true);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002488 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
2489 * have Si on board that is 82544 or newer, Auto
2490 * Speed Detection takes care of MAC speed/duplex
2491 * configuration. So we only need to configure Collision
2492 * Distance in the MAC. Otherwise, we need to force
2493 * speed/duplex on the MAC to the current PHY speed/duplex
2494 * settings.
2495 */
Dirk Brandewie5377a412011-01-06 14:29:54 +00002496 if ((hw->mac_type >= e1000_82544) &&
2497 (hw->mac_type != e1000_ce4100))
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002498 e1000_config_collision_dist(hw);
2499 else {
2500 ret_val = e1000_config_mac_to_phy(hw);
2501 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00002502 e_dbg
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002503 ("Error configuring MAC to PHY settings\n");
2504 return ret_val;
2505 }
2506 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002507
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002508 /* Configure Flow Control now that Auto-Neg has completed.
2509 * First, we need to restore the desired flow control settings
2510 * because we may have had to re-autoneg with a different link
2511 * partner.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002512 */
2513 ret_val = e1000_config_fc_after_link_up(hw);
2514 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00002515 e_dbg("Error configuring flow control\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002516 return ret_val;
2517 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002519 /* At this point we know that we are on copper and we have
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002520 * auto-negotiated link. These are conditions for checking the
2521 * link partner capability register. We use the link speed to
2522 * determine if TBI compatibility needs to be turned on or off.
2523 * If the link is not at gigabit speed, then TBI compatibility
2524 * is not needed. If we are at gigabit speed, we turn on TBI
2525 * compatibility.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002526 */
2527 if (hw->tbi_compatibility_en) {
2528 u16 speed, duplex;
2529 ret_val =
2530 e1000_get_speed_and_duplex(hw, &speed, &duplex);
2531 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00002532 e_dbg
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002533 ("Error getting link speed and duplex\n");
2534 return ret_val;
2535 }
2536 if (speed != SPEED_1000) {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002537 /* If link speed is not set to gigabit speed, we
2538 * do not need to enable TBI compatibility.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002539 */
2540 if (hw->tbi_compatibility_on) {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002541 /* If we previously were in the mode,
2542 * turn it off.
2543 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002544 rctl = er32(RCTL);
2545 rctl &= ~E1000_RCTL_SBP;
2546 ew32(RCTL, rctl);
2547 hw->tbi_compatibility_on = false;
2548 }
2549 } else {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002550 /* If TBI compatibility is was previously off,
2551 * turn it on. For compatibility with a TBI link
2552 * partner, we will store bad packets. Some
2553 * frames have an additional byte on the end and
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002554 * will look like CRC errors to to the hardware.
2555 */
2556 if (!hw->tbi_compatibility_on) {
2557 hw->tbi_compatibility_on = true;
2558 rctl = er32(RCTL);
2559 rctl |= E1000_RCTL_SBP;
2560 ew32(RCTL, rctl);
2561 }
2562 }
2563 }
2564 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002566 if ((hw->media_type == e1000_media_type_fiber) ||
2567 (hw->media_type == e1000_media_type_internal_serdes))
2568 e1000_check_for_serdes_link_generic(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002569
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002570 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571}
2572
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002573/**
2574 * e1000_get_speed_and_duplex
2575 * @hw: Struct containing variables accessed by shared code
2576 * @speed: Speed of the connection
2577 * @duplex: Duplex setting of the connection
Ben Hutchings49ce9c22012-07-10 10:56:00 +00002578 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002579 * Detects the current speed and duplex settings of the hardware.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002580 */
Joe Perches64798842008-07-11 15:17:02 -07002581s32 e1000_get_speed_and_duplex(struct e1000_hw *hw, u16 *speed, u16 *duplex)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002583 u32 status;
2584 s32 ret_val;
2585 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002587 if (hw->mac_type >= e1000_82543) {
2588 status = er32(STATUS);
2589 if (status & E1000_STATUS_SPEED_1000) {
2590 *speed = SPEED_1000;
Emil Tantilov675ad472010-04-27 14:02:58 +00002591 e_dbg("1000 Mbs, ");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002592 } else if (status & E1000_STATUS_SPEED_100) {
2593 *speed = SPEED_100;
Emil Tantilov675ad472010-04-27 14:02:58 +00002594 e_dbg("100 Mbs, ");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002595 } else {
2596 *speed = SPEED_10;
Emil Tantilov675ad472010-04-27 14:02:58 +00002597 e_dbg("10 Mbs, ");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002598 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002600 if (status & E1000_STATUS_FD) {
2601 *duplex = FULL_DUPLEX;
Emil Tantilov675ad472010-04-27 14:02:58 +00002602 e_dbg("Full Duplex\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002603 } else {
2604 *duplex = HALF_DUPLEX;
Emil Tantilov675ad472010-04-27 14:02:58 +00002605 e_dbg(" Half Duplex\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002606 }
2607 } else {
Emil Tantilov675ad472010-04-27 14:02:58 +00002608 e_dbg("1000 Mbs, Full Duplex\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002609 *speed = SPEED_1000;
2610 *duplex = FULL_DUPLEX;
2611 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002613 /* IGP01 PHY may advertise full duplex operation after speed downgrade
2614 * even if it is operating at half duplex. Here we set the duplex
2615 * settings to match the duplex in the link partner's capabilities.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002616 */
2617 if (hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
2618 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
2619 if (ret_val)
2620 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002622 if (!(phy_data & NWAY_ER_LP_NWAY_CAPS))
2623 *duplex = HALF_DUPLEX;
2624 else {
2625 ret_val =
2626 e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data);
2627 if (ret_val)
2628 return ret_val;
2629 if ((*speed == SPEED_100
2630 && !(phy_data & NWAY_LPAR_100TX_FD_CAPS))
2631 || (*speed == SPEED_10
2632 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
2633 *duplex = HALF_DUPLEX;
2634 }
2635 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002637 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638}
2639
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002640/**
2641 * e1000_wait_autoneg
2642 * @hw: Struct containing variables accessed by shared code
2643 *
2644 * Blocks until autoneg completes or times out (~4.5 seconds)
2645 */
Joe Perches64798842008-07-11 15:17:02 -07002646static s32 e1000_wait_autoneg(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002648 s32 ret_val;
2649 u16 i;
2650 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651
Emil Tantilov675ad472010-04-27 14:02:58 +00002652 e_dbg("Waiting for Auto-Neg to complete.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002653
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002654 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
2655 for (i = PHY_AUTO_NEG_TIME; i > 0; i--) {
2656 /* Read the MII Status Register and wait for Auto-Neg
2657 * Complete bit to be set.
2658 */
2659 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2660 if (ret_val)
2661 return ret_val;
2662 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2663 if (ret_val)
2664 return ret_val;
2665 if (phy_data & MII_SR_AUTONEG_COMPLETE) {
2666 return E1000_SUCCESS;
2667 }
2668 msleep(100);
2669 }
2670 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671}
2672
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002673/**
2674 * e1000_raise_mdi_clk - Raises the Management Data Clock
2675 * @hw: Struct containing variables accessed by shared code
2676 * @ctrl: Device control register's current value
2677 */
Joe Perches64798842008-07-11 15:17:02 -07002678static void e1000_raise_mdi_clk(struct e1000_hw *hw, u32 *ctrl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002679{
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002680 /* Raise the clock input to the Management Data Clock (by setting the
2681 * MDC bit), and then delay 10 microseconds.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002682 */
2683 ew32(CTRL, (*ctrl | E1000_CTRL_MDC));
2684 E1000_WRITE_FLUSH();
2685 udelay(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002686}
2687
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002688/**
2689 * e1000_lower_mdi_clk - Lowers the Management Data Clock
2690 * @hw: Struct containing variables accessed by shared code
2691 * @ctrl: Device control register's current value
2692 */
Joe Perches64798842008-07-11 15:17:02 -07002693static void e1000_lower_mdi_clk(struct e1000_hw *hw, u32 *ctrl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002694{
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002695 /* Lower the clock input to the Management Data Clock (by clearing the
2696 * MDC bit), and then delay 10 microseconds.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002697 */
2698 ew32(CTRL, (*ctrl & ~E1000_CTRL_MDC));
2699 E1000_WRITE_FLUSH();
2700 udelay(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002701}
2702
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002703/**
2704 * e1000_shift_out_mdi_bits - Shifts data bits out to the PHY
2705 * @hw: Struct containing variables accessed by shared code
2706 * @data: Data to send out to the PHY
2707 * @count: Number of bits to shift out
2708 *
2709 * Bits are shifted out in MSB to LSB order.
2710 */
Joe Perches64798842008-07-11 15:17:02 -07002711static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, u32 data, u16 count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002712{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002713 u32 ctrl;
2714 u32 mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002715
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002716 /* We need to shift "count" number of bits out to the PHY. So, the value
2717 * in the "data" parameter will be shifted out to the PHY one bit at a
2718 * time. In order to do this, "data" must be broken down into bits.
2719 */
2720 mask = 0x01;
2721 mask <<= (count - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002723 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002724
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002725 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
2726 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002727
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002728 while (mask) {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002729 /* A "1" is shifted out to the PHY by setting the MDIO bit to
2730 * "1" and then raising and lowering the Management Data Clock.
2731 * A "0" is shifted out to the PHY by setting the MDIO bit to
2732 * "0" and then raising and lowering the clock.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002733 */
2734 if (data & mask)
2735 ctrl |= E1000_CTRL_MDIO;
2736 else
2737 ctrl &= ~E1000_CTRL_MDIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002738
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002739 ew32(CTRL, ctrl);
2740 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002741
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002742 udelay(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002744 e1000_raise_mdi_clk(hw, &ctrl);
2745 e1000_lower_mdi_clk(hw, &ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002746
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002747 mask = mask >> 1;
2748 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002749}
2750
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002751/**
2752 * e1000_shift_in_mdi_bits - Shifts data bits in from the PHY
2753 * @hw: Struct containing variables accessed by shared code
2754 *
2755 * Bits are shifted in in MSB to LSB order.
2756 */
Joe Perches64798842008-07-11 15:17:02 -07002757static u16 e1000_shift_in_mdi_bits(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002758{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002759 u32 ctrl;
2760 u16 data = 0;
2761 u8 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002762
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002763 /* In order to read a register from the PHY, we need to shift in a total
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002764 * of 18 bits from the PHY. The first two bit (turnaround) times are
2765 * used to avoid contention on the MDIO pin when a read operation is
2766 * performed. These two bits are ignored by us and thrown away. Bits are
2767 * "shifted in" by raising the input to the Management Data Clock
2768 * (setting the MDC bit), and then reading the value of the MDIO bit.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002769 */
2770 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002771
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002772 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as
2773 * input.
2774 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002775 ctrl &= ~E1000_CTRL_MDIO_DIR;
2776 ctrl &= ~E1000_CTRL_MDIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002777
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002778 ew32(CTRL, ctrl);
2779 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002780
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002781 /* Raise and Lower the clock before reading in the data. This accounts
2782 * for the turnaround bits. The first clock occurred when we clocked out
2783 * the last bit of the Register Address.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002784 */
2785 e1000_raise_mdi_clk(hw, &ctrl);
2786 e1000_lower_mdi_clk(hw, &ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002787
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002788 for (data = 0, i = 0; i < 16; i++) {
2789 data = data << 1;
2790 e1000_raise_mdi_clk(hw, &ctrl);
2791 ctrl = er32(CTRL);
2792 /* Check to see if we shifted in a "1". */
2793 if (ctrl & E1000_CTRL_MDIO)
2794 data |= 1;
2795 e1000_lower_mdi_clk(hw, &ctrl);
2796 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002797
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002798 e1000_raise_mdi_clk(hw, &ctrl);
2799 e1000_lower_mdi_clk(hw, &ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002800
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002801 return data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002802}
2803
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002804
2805/**
2806 * e1000_read_phy_reg - read a phy register
2807 * @hw: Struct containing variables accessed by shared code
2808 * @reg_addr: address of the PHY register to read
Jean Sacrenf03fed62015-09-19 05:08:46 -06002809 * @phy_data: pointer to the value on the PHY register
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002810 *
2811 * Reads the value from a PHY register, if the value is on a specific non zero
2812 * page, sets the page first.
2813 */
Joe Perches64798842008-07-11 15:17:02 -07002814s32 e1000_read_phy_reg(struct e1000_hw *hw, u32 reg_addr, u16 *phy_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002815{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002816 u32 ret_val;
Maxime Bizonac565582012-10-20 14:53:40 +00002817 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002818
Maxime Bizonac565582012-10-20 14:53:40 +00002819 spin_lock_irqsave(&e1000_phy_lock, flags);
2820
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002821 if ((hw->phy_type == e1000_phy_igp) &&
2822 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
2823 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
2824 (u16) reg_addr);
Jean Sacrenc6195812015-09-19 05:08:47 -06002825 if (ret_val)
2826 goto out;
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002827 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002828
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002829 ret_val = e1000_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
2830 phy_data);
Jean Sacrenc6195812015-09-19 05:08:47 -06002831out:
Maxime Bizonac565582012-10-20 14:53:40 +00002832 spin_unlock_irqrestore(&e1000_phy_lock, flags);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002833
2834 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002835}
2836
Joe Perches64798842008-07-11 15:17:02 -07002837static s32 e1000_read_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr,
2838 u16 *phy_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002839{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002840 u32 i;
2841 u32 mdic = 0;
Dirk Brandewie5377a412011-01-06 14:29:54 +00002842 const u32 phy_addr = (hw->mac_type == e1000_ce4100) ? hw->phy_addr : 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002843
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002844 if (reg_addr > MAX_PHY_REG_ADDRESS) {
Emil Tantilov675ad472010-04-27 14:02:58 +00002845 e_dbg("PHY Address %d is out of range\n", reg_addr);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002846 return -E1000_ERR_PARAM;
2847 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002848
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002849 if (hw->mac_type > e1000_82543) {
2850 /* Set up Op-code, Phy Address, and register address in the MDI
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002851 * Control register. The MAC will take care of interfacing with
2852 * the PHY to retrieve the desired data.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002853 */
Dirk Brandewie5377a412011-01-06 14:29:54 +00002854 if (hw->mac_type == e1000_ce4100) {
2855 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
2856 (phy_addr << E1000_MDIC_PHY_SHIFT) |
2857 (INTEL_CE_GBE_MDIC_OP_READ) |
2858 (INTEL_CE_GBE_MDIC_GO));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002859
Dirk Brandewie5377a412011-01-06 14:29:54 +00002860 writel(mdic, E1000_MDIO_CMD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002861
Dirk Brandewie5377a412011-01-06 14:29:54 +00002862 /* Poll the ready bit to see if the MDI read
2863 * completed
2864 */
2865 for (i = 0; i < 64; i++) {
2866 udelay(50);
2867 mdic = readl(E1000_MDIO_CMD);
2868 if (!(mdic & INTEL_CE_GBE_MDIC_GO))
2869 break;
2870 }
2871
2872 if (mdic & INTEL_CE_GBE_MDIC_GO) {
2873 e_dbg("MDI Read did not complete\n");
2874 return -E1000_ERR_PHY;
2875 }
2876
2877 mdic = readl(E1000_MDIO_STS);
2878 if (mdic & INTEL_CE_GBE_MDIC_READ_ERROR) {
2879 e_dbg("MDI Read Error\n");
2880 return -E1000_ERR_PHY;
2881 }
2882 *phy_data = (u16) mdic;
2883 } else {
2884 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
2885 (phy_addr << E1000_MDIC_PHY_SHIFT) |
2886 (E1000_MDIC_OP_READ));
2887
2888 ew32(MDIC, mdic);
2889
2890 /* Poll the ready bit to see if the MDI read
2891 * completed
2892 */
2893 for (i = 0; i < 64; i++) {
2894 udelay(50);
2895 mdic = er32(MDIC);
2896 if (mdic & E1000_MDIC_READY)
2897 break;
2898 }
2899 if (!(mdic & E1000_MDIC_READY)) {
2900 e_dbg("MDI Read did not complete\n");
2901 return -E1000_ERR_PHY;
2902 }
2903 if (mdic & E1000_MDIC_ERROR) {
2904 e_dbg("MDI Error\n");
2905 return -E1000_ERR_PHY;
2906 }
2907 *phy_data = (u16) mdic;
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002908 }
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002909 } else {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002910 /* We must first send a preamble through the MDIO pin to signal
2911 * the beginning of an MII instruction. This is done by sending
2912 * 32 consecutive "1" bits.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002913 */
2914 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002915
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002916 /* Now combine the next few fields that are required for a read
2917 * operation. We use this method instead of calling the
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002918 * e1000_shift_out_mdi_bits routine five different times. The
2919 * format of a MII read instruction consists of a shift out of
2920 * 14 bits and is defined as follows:
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002921 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002922 * followed by a shift in of 18 bits. This first two bits
2923 * shifted in are TurnAround bits used to avoid contention on
2924 * the MDIO pin when a READ operation is performed. These two
2925 * bits are thrown away followed by a shift in of 16 bits which
2926 * contains the desired data.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002927 */
2928 mdic = ((reg_addr) | (phy_addr << 5) |
2929 (PHY_OP_READ << 10) | (PHY_SOF << 12));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002930
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002931 e1000_shift_out_mdi_bits(hw, mdic, 14);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002932
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002933 /* Now that we've shifted out the read command to the MII, we
2934 * need to "shift in" the 16-bit value (18 total bits) of the
2935 * requested PHY register address.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002936 */
2937 *phy_data = e1000_shift_in_mdi_bits(hw);
2938 }
2939 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002940}
2941
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002942/**
2943 * e1000_write_phy_reg - write a phy register
2944 *
2945 * @hw: Struct containing variables accessed by shared code
2946 * @reg_addr: address of the PHY register to write
2947 * @data: data to write to the PHY
Ben Hutchings49ce9c22012-07-10 10:56:00 +00002948 *
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002949 * Writes a value to a PHY register
2950 */
Joe Perches64798842008-07-11 15:17:02 -07002951s32 e1000_write_phy_reg(struct e1000_hw *hw, u32 reg_addr, u16 phy_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002952{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002953 u32 ret_val;
Maxime Bizonac565582012-10-20 14:53:40 +00002954 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002955
Maxime Bizonac565582012-10-20 14:53:40 +00002956 spin_lock_irqsave(&e1000_phy_lock, flags);
2957
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002958 if ((hw->phy_type == e1000_phy_igp) &&
2959 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
2960 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
2961 (u16) reg_addr);
Maxime Bizonac565582012-10-20 14:53:40 +00002962 if (ret_val) {
2963 spin_unlock_irqrestore(&e1000_phy_lock, flags);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002964 return ret_val;
Maxime Bizonac565582012-10-20 14:53:40 +00002965 }
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002966 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002967
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002968 ret_val = e1000_write_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
2969 phy_data);
Maxime Bizonac565582012-10-20 14:53:40 +00002970 spin_unlock_irqrestore(&e1000_phy_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002971
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002972 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002973}
2974
Joe Perches64798842008-07-11 15:17:02 -07002975static s32 e1000_write_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr,
2976 u16 phy_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002977{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002978 u32 i;
2979 u32 mdic = 0;
Dirk Brandewie5377a412011-01-06 14:29:54 +00002980 const u32 phy_addr = (hw->mac_type == e1000_ce4100) ? hw->phy_addr : 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002981
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002982 if (reg_addr > MAX_PHY_REG_ADDRESS) {
Emil Tantilov675ad472010-04-27 14:02:58 +00002983 e_dbg("PHY Address %d is out of range\n", reg_addr);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002984 return -E1000_ERR_PARAM;
2985 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002986
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002987 if (hw->mac_type > e1000_82543) {
Dirk Brandewie5377a412011-01-06 14:29:54 +00002988 /* Set up Op-code, Phy Address, register address, and data
2989 * intended for the PHY register in the MDI Control register.
2990 * The MAC will take care of interfacing with the PHY to send
2991 * the desired data.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002992 */
Dirk Brandewie5377a412011-01-06 14:29:54 +00002993 if (hw->mac_type == e1000_ce4100) {
2994 mdic = (((u32) phy_data) |
2995 (reg_addr << E1000_MDIC_REG_SHIFT) |
2996 (phy_addr << E1000_MDIC_PHY_SHIFT) |
2997 (INTEL_CE_GBE_MDIC_OP_WRITE) |
2998 (INTEL_CE_GBE_MDIC_GO));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002999
Dirk Brandewie5377a412011-01-06 14:29:54 +00003000 writel(mdic, E1000_MDIO_CMD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003001
Dirk Brandewie5377a412011-01-06 14:29:54 +00003002 /* Poll the ready bit to see if the MDI read
3003 * completed
3004 */
3005 for (i = 0; i < 640; i++) {
3006 udelay(5);
3007 mdic = readl(E1000_MDIO_CMD);
3008 if (!(mdic & INTEL_CE_GBE_MDIC_GO))
3009 break;
3010 }
3011 if (mdic & INTEL_CE_GBE_MDIC_GO) {
3012 e_dbg("MDI Write did not complete\n");
3013 return -E1000_ERR_PHY;
3014 }
3015 } else {
3016 mdic = (((u32) phy_data) |
3017 (reg_addr << E1000_MDIC_REG_SHIFT) |
3018 (phy_addr << E1000_MDIC_PHY_SHIFT) |
3019 (E1000_MDIC_OP_WRITE));
3020
3021 ew32(MDIC, mdic);
3022
3023 /* Poll the ready bit to see if the MDI read
3024 * completed
3025 */
3026 for (i = 0; i < 641; i++) {
3027 udelay(5);
3028 mdic = er32(MDIC);
3029 if (mdic & E1000_MDIC_READY)
3030 break;
3031 }
3032 if (!(mdic & E1000_MDIC_READY)) {
3033 e_dbg("MDI Write did not complete\n");
3034 return -E1000_ERR_PHY;
3035 }
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003036 }
3037 } else {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003038 /* We'll need to use the SW defined pins to shift the write
3039 * command out to the PHY. We first send a preamble to the PHY
3040 * to signal the beginning of the MII instruction. This is done
3041 * by sending 32 consecutive "1" bits.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003042 */
3043 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003044
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003045 /* Now combine the remaining required fields that will indicate
3046 * a write operation. We use this method instead of calling the
3047 * e1000_shift_out_mdi_bits routine for each field in the
3048 * command. The format of a MII write instruction is as follows:
3049 * <Preamble><SOF><OpCode><PhyAddr><RegAddr><Turnaround><Data>.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003050 */
3051 mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
3052 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
3053 mdic <<= 16;
3054 mdic |= (u32) phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003055
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003056 e1000_shift_out_mdi_bits(hw, mdic, 32);
3057 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003058
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003059 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003060}
3061
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003062/**
3063 * e1000_phy_hw_reset - reset the phy, hardware style
3064 * @hw: Struct containing variables accessed by shared code
3065 *
3066 * Returns the PHY to the power-on reset state
3067 */
Joe Perches64798842008-07-11 15:17:02 -07003068s32 e1000_phy_hw_reset(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003069{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003070 u32 ctrl, ctrl_ext;
3071 u32 led_ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003072
Emil Tantilov675ad472010-04-27 14:02:58 +00003073 e_dbg("Resetting Phy...\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003074
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003075 if (hw->mac_type > e1000_82543) {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003076 /* Read the device control register and assert the
3077 * E1000_CTRL_PHY_RST bit. Then, take it out of reset.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003078 * For e1000 hardware, we delay for 10ms between the assert
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003079 * and de-assert.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003080 */
3081 ctrl = er32(CTRL);
3082 ew32(CTRL, ctrl | E1000_CTRL_PHY_RST);
3083 E1000_WRITE_FLUSH();
Auke Kok76c224b2006-05-23 13:36:06 -07003084
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003085 msleep(10);
Auke Kok76c224b2006-05-23 13:36:06 -07003086
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003087 ew32(CTRL, ctrl);
3088 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003089
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003090 } else {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003091 /* Read the Extended Device Control Register, assert the
3092 * PHY_RESET_DIR bit to put the PHY into reset. Then, take it
3093 * out of reset.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003094 */
3095 ctrl_ext = er32(CTRL_EXT);
3096 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
3097 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
3098 ew32(CTRL_EXT, ctrl_ext);
3099 E1000_WRITE_FLUSH();
3100 msleep(10);
3101 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
3102 ew32(CTRL_EXT, ctrl_ext);
3103 E1000_WRITE_FLUSH();
3104 }
3105 udelay(150);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003106
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003107 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
3108 /* Configure activity LED after PHY reset */
3109 led_ctrl = er32(LEDCTL);
3110 led_ctrl &= IGP_ACTIVITY_LED_MASK;
3111 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
3112 ew32(LEDCTL, led_ctrl);
3113 }
Auke Kok8fc897b2006-08-28 14:56:16 -07003114
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003115 /* Wait for FW to finish PHY configuration. */
Greg Dietschec4dc4d12011-06-16 07:09:30 +00003116 return e1000_get_phy_cfg_done(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003117}
3118
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003119/**
3120 * e1000_phy_reset - reset the phy to commit settings
3121 * @hw: Struct containing variables accessed by shared code
3122 *
3123 * Resets the PHY
3124 * Sets bit 15 of the MII Control register
3125 */
Joe Perches64798842008-07-11 15:17:02 -07003126s32 e1000_phy_reset(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003127{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003128 s32 ret_val;
3129 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003130
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003131 switch (hw->phy_type) {
3132 case e1000_phy_igp:
3133 ret_val = e1000_phy_hw_reset(hw);
3134 if (ret_val)
3135 return ret_val;
3136 break;
3137 default:
3138 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
3139 if (ret_val)
3140 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003141
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003142 phy_data |= MII_CR_RESET;
3143 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
3144 if (ret_val)
3145 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003146
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003147 udelay(1);
3148 break;
3149 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003150
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003151 if (hw->phy_type == e1000_phy_igp)
3152 e1000_phy_init_script(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003153
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003154 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003155}
3156
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003157/**
3158 * e1000_detect_gig_phy - check the phy type
3159 * @hw: Struct containing variables accessed by shared code
3160 *
3161 * Probes the expected PHY address for known PHY IDs
3162 */
Joe Perches64798842008-07-11 15:17:02 -07003163static s32 e1000_detect_gig_phy(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003164{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003165 s32 phy_init_status, ret_val;
3166 u16 phy_id_high, phy_id_low;
3167 bool match = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003168
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003169 if (hw->phy_id != 0)
3170 return E1000_SUCCESS;
Jeff Kirsher2a88c172006-09-27 12:54:05 -07003171
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003172 /* Read the PHY ID Registers to identify which PHY is onboard. */
3173 ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
3174 if (ret_val)
3175 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003176
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003177 hw->phy_id = (u32) (phy_id_high << 16);
3178 udelay(20);
3179 ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
3180 if (ret_val)
3181 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003182
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003183 hw->phy_id |= (u32) (phy_id_low & PHY_REVISION_MASK);
3184 hw->phy_revision = (u32) phy_id_low & ~PHY_REVISION_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003185
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003186 switch (hw->mac_type) {
3187 case e1000_82543:
3188 if (hw->phy_id == M88E1000_E_PHY_ID)
3189 match = true;
3190 break;
3191 case e1000_82544:
3192 if (hw->phy_id == M88E1000_I_PHY_ID)
3193 match = true;
3194 break;
3195 case e1000_82540:
3196 case e1000_82545:
3197 case e1000_82545_rev_3:
3198 case e1000_82546:
3199 case e1000_82546_rev_3:
3200 if (hw->phy_id == M88E1011_I_PHY_ID)
3201 match = true;
3202 break;
Dirk Brandewie5377a412011-01-06 14:29:54 +00003203 case e1000_ce4100:
3204 if ((hw->phy_id == RTL8211B_PHY_ID) ||
Florian Fainellicf8e09b2011-01-24 14:48:03 +00003205 (hw->phy_id == RTL8201N_PHY_ID) ||
3206 (hw->phy_id == M88E1118_E_PHY_ID))
Dirk Brandewie5377a412011-01-06 14:29:54 +00003207 match = true;
3208 break;
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003209 case e1000_82541:
3210 case e1000_82541_rev_2:
3211 case e1000_82547:
3212 case e1000_82547_rev_2:
3213 if (hw->phy_id == IGP01E1000_I_PHY_ID)
3214 match = true;
3215 break;
3216 default:
Emil Tantilov675ad472010-04-27 14:02:58 +00003217 e_dbg("Invalid MAC type %d\n", hw->mac_type);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003218 return -E1000_ERR_CONFIG;
3219 }
3220 phy_init_status = e1000_set_phy_type(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003221
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003222 if ((match) && (phy_init_status == E1000_SUCCESS)) {
Emil Tantilov675ad472010-04-27 14:02:58 +00003223 e_dbg("PHY ID 0x%X detected\n", hw->phy_id);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003224 return E1000_SUCCESS;
3225 }
Emil Tantilov675ad472010-04-27 14:02:58 +00003226 e_dbg("Invalid PHY ID 0x%X\n", hw->phy_id);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003227 return -E1000_ERR_PHY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003228}
3229
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003230/**
3231 * e1000_phy_reset_dsp - reset DSP
3232 * @hw: Struct containing variables accessed by shared code
3233 *
3234 * Resets the PHY's DSP
3235 */
Joe Perches64798842008-07-11 15:17:02 -07003236static s32 e1000_phy_reset_dsp(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003237{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003238 s32 ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003239
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003240 do {
3241 ret_val = e1000_write_phy_reg(hw, 29, 0x001d);
3242 if (ret_val)
3243 break;
3244 ret_val = e1000_write_phy_reg(hw, 30, 0x00c1);
3245 if (ret_val)
3246 break;
3247 ret_val = e1000_write_phy_reg(hw, 30, 0x0000);
3248 if (ret_val)
3249 break;
3250 ret_val = E1000_SUCCESS;
3251 } while (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003252
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003253 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003254}
3255
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003256/**
3257 * e1000_phy_igp_get_info - get igp specific registers
3258 * @hw: Struct containing variables accessed by shared code
3259 * @phy_info: PHY information structure
3260 *
3261 * Get PHY information from various PHY registers for igp PHY only.
3262 */
Joe Perches64798842008-07-11 15:17:02 -07003263static s32 e1000_phy_igp_get_info(struct e1000_hw *hw,
3264 struct e1000_phy_info *phy_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003265{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003266 s32 ret_val;
3267 u16 phy_data, min_length, max_length, average;
3268 e1000_rev_polarity polarity;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003269
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003270 /* The downshift status is checked only once, after link is established,
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003271 * and it stored in the hw->speed_downgraded parameter.
3272 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003273 phy_info->downshift = (e1000_downshift) hw->speed_downgraded;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003274
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003275 /* IGP01E1000 does not need to support it. */
3276 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003277
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003278 /* IGP01E1000 always correct polarity reversal */
3279 phy_info->polarity_correction = e1000_polarity_reversal_enabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003280
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003281 /* Check polarity status */
3282 ret_val = e1000_check_polarity(hw, &polarity);
3283 if (ret_val)
3284 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003285
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003286 phy_info->cable_polarity = polarity;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003287
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003288 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, &phy_data);
3289 if (ret_val)
3290 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003291
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003292 phy_info->mdix_mode =
3293 (e1000_auto_x_mode) ((phy_data & IGP01E1000_PSSR_MDIX) >>
3294 IGP01E1000_PSSR_MDIX_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003295
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003296 if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
3297 IGP01E1000_PSSR_SPEED_1000MBPS) {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003298 /* Local/Remote Receiver Information are only valid @ 1000
3299 * Mbps
3300 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003301 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
3302 if (ret_val)
3303 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003304
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003305 phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
3306 SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
3307 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
3308 phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
3309 SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
3310 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003311
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003312 /* Get cable length */
3313 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
3314 if (ret_val)
3315 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003316
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003317 /* Translate to old method */
3318 average = (max_length + min_length) / 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003319
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003320 if (average <= e1000_igp_cable_length_50)
3321 phy_info->cable_length = e1000_cable_length_50;
3322 else if (average <= e1000_igp_cable_length_80)
3323 phy_info->cable_length = e1000_cable_length_50_80;
3324 else if (average <= e1000_igp_cable_length_110)
3325 phy_info->cable_length = e1000_cable_length_80_110;
3326 else if (average <= e1000_igp_cable_length_140)
3327 phy_info->cable_length = e1000_cable_length_110_140;
3328 else
3329 phy_info->cable_length = e1000_cable_length_140;
3330 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003331
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003332 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003333}
3334
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003335/**
3336 * e1000_phy_m88_get_info - get m88 specific registers
3337 * @hw: Struct containing variables accessed by shared code
3338 * @phy_info: PHY information structure
3339 *
3340 * Get PHY information from various PHY registers for m88 PHY only.
3341 */
Joe Perches64798842008-07-11 15:17:02 -07003342static s32 e1000_phy_m88_get_info(struct e1000_hw *hw,
3343 struct e1000_phy_info *phy_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003344{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003345 s32 ret_val;
3346 u16 phy_data;
3347 e1000_rev_polarity polarity;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003348
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003349 /* The downshift status is checked only once, after link is established,
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003350 * and it stored in the hw->speed_downgraded parameter.
3351 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003352 phy_info->downshift = (e1000_downshift) hw->speed_downgraded;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003353
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003354 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
3355 if (ret_val)
3356 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003357
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003358 phy_info->extended_10bt_distance =
3359 ((phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >>
3360 M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT) ?
3361 e1000_10bt_ext_dist_enable_lower :
3362 e1000_10bt_ext_dist_enable_normal;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07003363
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003364 phy_info->polarity_correction =
3365 ((phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >>
3366 M88E1000_PSCR_POLARITY_REVERSAL_SHIFT) ?
3367 e1000_polarity_reversal_disabled : e1000_polarity_reversal_enabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003368
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003369 /* Check polarity status */
3370 ret_val = e1000_check_polarity(hw, &polarity);
3371 if (ret_val)
3372 return ret_val;
3373 phy_info->cable_polarity = polarity;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003374
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003375 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
3376 if (ret_val)
3377 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003378
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003379 phy_info->mdix_mode =
3380 (e1000_auto_x_mode) ((phy_data & M88E1000_PSSR_MDIX) >>
3381 M88E1000_PSSR_MDIX_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003382
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003383 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
3384 /* Cable Length Estimation and Local/Remote Receiver Information
3385 * are only valid at 1000 Mbps.
3386 */
3387 phy_info->cable_length =
3388 (e1000_cable_length) ((phy_data &
3389 M88E1000_PSSR_CABLE_LENGTH) >>
3390 M88E1000_PSSR_CABLE_LENGTH_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003391
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003392 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
3393 if (ret_val)
3394 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003395
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003396 phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
3397 SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
3398 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
3399 phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
3400 SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
3401 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003402
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003403 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003404
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003405 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003406}
3407
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003408/**
3409 * e1000_phy_get_info - request phy info
3410 * @hw: Struct containing variables accessed by shared code
3411 * @phy_info: PHY information structure
3412 *
3413 * Get PHY information from various PHY registers
3414 */
Joe Perches64798842008-07-11 15:17:02 -07003415s32 e1000_phy_get_info(struct e1000_hw *hw, struct e1000_phy_info *phy_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003416{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003417 s32 ret_val;
3418 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003419
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003420 phy_info->cable_length = e1000_cable_length_undefined;
3421 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined;
3422 phy_info->cable_polarity = e1000_rev_polarity_undefined;
3423 phy_info->downshift = e1000_downshift_undefined;
3424 phy_info->polarity_correction = e1000_polarity_reversal_undefined;
3425 phy_info->mdix_mode = e1000_auto_x_mode_undefined;
3426 phy_info->local_rx = e1000_1000t_rx_status_undefined;
3427 phy_info->remote_rx = e1000_1000t_rx_status_undefined;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003428
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003429 if (hw->media_type != e1000_media_type_copper) {
Emil Tantilov675ad472010-04-27 14:02:58 +00003430 e_dbg("PHY info is only valid for copper media\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003431 return -E1000_ERR_CONFIG;
3432 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003433
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003434 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3435 if (ret_val)
3436 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003437
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003438 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3439 if (ret_val)
3440 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003441
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003442 if ((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) {
Emil Tantilov675ad472010-04-27 14:02:58 +00003443 e_dbg("PHY info is only valid if link is up\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003444 return -E1000_ERR_CONFIG;
3445 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003446
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003447 if (hw->phy_type == e1000_phy_igp)
3448 return e1000_phy_igp_get_info(hw, phy_info);
Dirk Brandewie5377a412011-01-06 14:29:54 +00003449 else if ((hw->phy_type == e1000_phy_8211) ||
Janusz Wolaka48954c2015-09-17 23:34:29 +02003450 (hw->phy_type == e1000_phy_8201))
Dirk Brandewie5377a412011-01-06 14:29:54 +00003451 return E1000_SUCCESS;
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003452 else
3453 return e1000_phy_m88_get_info(hw, phy_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003454}
3455
Joe Perches64798842008-07-11 15:17:02 -07003456s32 e1000_validate_mdi_setting(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003457{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003458 if (!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) {
Emil Tantilov675ad472010-04-27 14:02:58 +00003459 e_dbg("Invalid MDI setting detected\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003460 hw->mdix = 1;
3461 return -E1000_ERR_CONFIG;
3462 }
3463 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003464}
3465
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003466/**
3467 * e1000_init_eeprom_params - initialize sw eeprom vars
3468 * @hw: Struct containing variables accessed by shared code
3469 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07003470 * Sets up eeprom variables in the hw struct. Must be called after mac_type
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00003471 * is configured.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003472 */
Joe Perches64798842008-07-11 15:17:02 -07003473s32 e1000_init_eeprom_params(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003474{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003475 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3476 u32 eecd = er32(EECD);
3477 s32 ret_val = E1000_SUCCESS;
3478 u16 eeprom_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003479
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003480 switch (hw->mac_type) {
3481 case e1000_82542_rev2_0:
3482 case e1000_82542_rev2_1:
3483 case e1000_82543:
3484 case e1000_82544:
3485 eeprom->type = e1000_eeprom_microwire;
3486 eeprom->word_size = 64;
3487 eeprom->opcode_bits = 3;
3488 eeprom->address_bits = 6;
3489 eeprom->delay_usec = 50;
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003490 break;
3491 case e1000_82540:
3492 case e1000_82545:
3493 case e1000_82545_rev_3:
3494 case e1000_82546:
3495 case e1000_82546_rev_3:
3496 eeprom->type = e1000_eeprom_microwire;
3497 eeprom->opcode_bits = 3;
3498 eeprom->delay_usec = 50;
3499 if (eecd & E1000_EECD_SIZE) {
3500 eeprom->word_size = 256;
3501 eeprom->address_bits = 8;
3502 } else {
3503 eeprom->word_size = 64;
3504 eeprom->address_bits = 6;
3505 }
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003506 break;
3507 case e1000_82541:
3508 case e1000_82541_rev_2:
3509 case e1000_82547:
3510 case e1000_82547_rev_2:
3511 if (eecd & E1000_EECD_TYPE) {
3512 eeprom->type = e1000_eeprom_spi;
3513 eeprom->opcode_bits = 8;
3514 eeprom->delay_usec = 1;
3515 if (eecd & E1000_EECD_ADDR_BITS) {
3516 eeprom->page_size = 32;
3517 eeprom->address_bits = 16;
3518 } else {
3519 eeprom->page_size = 8;
3520 eeprom->address_bits = 8;
3521 }
3522 } else {
3523 eeprom->type = e1000_eeprom_microwire;
3524 eeprom->opcode_bits = 3;
3525 eeprom->delay_usec = 50;
3526 if (eecd & E1000_EECD_ADDR_BITS) {
3527 eeprom->word_size = 256;
3528 eeprom->address_bits = 8;
3529 } else {
3530 eeprom->word_size = 64;
3531 eeprom->address_bits = 6;
3532 }
3533 }
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003534 break;
3535 default:
3536 break;
3537 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003538
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003539 if (eeprom->type == e1000_eeprom_spi) {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003540 /* eeprom_size will be an enum [0..8] that maps to eeprom sizes
3541 * 128B to 32KB (incremented by powers of 2).
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003542 */
3543 /* Set to default value for initial eeprom read. */
3544 eeprom->word_size = 64;
3545 ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size);
3546 if (ret_val)
3547 return ret_val;
3548 eeprom_size =
3549 (eeprom_size & EEPROM_SIZE_MASK) >> EEPROM_SIZE_SHIFT;
3550 /* 256B eeprom size was not supported in earlier hardware, so we
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003551 * bump eeprom_size up one to ensure that "1" (which maps to
3552 * 256B) is never the result used in the shifting logic below.
3553 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003554 if (eeprom_size)
3555 eeprom_size++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003556
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003557 eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT);
3558 }
3559 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003560}
3561
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003562/**
3563 * e1000_raise_ee_clk - Raises the EEPROM's clock input.
3564 * @hw: Struct containing variables accessed by shared code
3565 * @eecd: EECD's current value
3566 */
Joe Perches64798842008-07-11 15:17:02 -07003567static void e1000_raise_ee_clk(struct e1000_hw *hw, u32 *eecd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003568{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003569 /* Raise the clock input to the EEPROM (by setting the SK bit), and then
3570 * wait <delay> microseconds.
3571 */
3572 *eecd = *eecd | E1000_EECD_SK;
3573 ew32(EECD, *eecd);
3574 E1000_WRITE_FLUSH();
3575 udelay(hw->eeprom.delay_usec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003576}
3577
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003578/**
3579 * e1000_lower_ee_clk - Lowers the EEPROM's clock input.
3580 * @hw: Struct containing variables accessed by shared code
3581 * @eecd: EECD's current value
3582 */
Joe Perches64798842008-07-11 15:17:02 -07003583static void e1000_lower_ee_clk(struct e1000_hw *hw, u32 *eecd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003584{
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003585 /* Lower the clock input to the EEPROM (by clearing the SK bit), and
3586 * then wait 50 microseconds.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003587 */
3588 *eecd = *eecd & ~E1000_EECD_SK;
3589 ew32(EECD, *eecd);
3590 E1000_WRITE_FLUSH();
3591 udelay(hw->eeprom.delay_usec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003592}
3593
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003594/**
3595 * e1000_shift_out_ee_bits - Shift data bits out to the EEPROM.
3596 * @hw: Struct containing variables accessed by shared code
3597 * @data: data to send to the EEPROM
3598 * @count: number of bits to shift out
3599 */
Joe Perches64798842008-07-11 15:17:02 -07003600static void e1000_shift_out_ee_bits(struct e1000_hw *hw, u16 data, u16 count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003601{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003602 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3603 u32 eecd;
3604 u32 mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003605
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003606 /* We need to shift "count" bits out to the EEPROM. So, value in the
3607 * "data" parameter will be shifted out to the EEPROM one bit at a time.
3608 * In order to do this, "data" must be broken down into bits.
3609 */
3610 mask = 0x01 << (count - 1);
3611 eecd = er32(EECD);
3612 if (eeprom->type == e1000_eeprom_microwire) {
3613 eecd &= ~E1000_EECD_DO;
3614 } else if (eeprom->type == e1000_eeprom_spi) {
3615 eecd |= E1000_EECD_DO;
3616 }
3617 do {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003618 /* A "1" is shifted out to the EEPROM by setting bit "DI" to a
3619 * "1", and then raising and then lowering the clock (the SK bit
3620 * controls the clock input to the EEPROM). A "0" is shifted
3621 * out to the EEPROM by setting "DI" to "0" and then raising and
3622 * then lowering the clock.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003623 */
3624 eecd &= ~E1000_EECD_DI;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003625
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003626 if (data & mask)
3627 eecd |= E1000_EECD_DI;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003628
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003629 ew32(EECD, eecd);
3630 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003631
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003632 udelay(eeprom->delay_usec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003633
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003634 e1000_raise_ee_clk(hw, &eecd);
3635 e1000_lower_ee_clk(hw, &eecd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003636
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003637 mask = mask >> 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003638
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003639 } while (mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003640
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003641 /* We leave the "DI" bit set to "0" when we leave this routine. */
3642 eecd &= ~E1000_EECD_DI;
3643 ew32(EECD, eecd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003644}
3645
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003646/**
3647 * e1000_shift_in_ee_bits - Shift data bits in from the EEPROM
3648 * @hw: Struct containing variables accessed by shared code
3649 * @count: number of bits to shift in
3650 */
Joe Perches64798842008-07-11 15:17:02 -07003651static u16 e1000_shift_in_ee_bits(struct e1000_hw *hw, u16 count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003652{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003653 u32 eecd;
3654 u32 i;
3655 u16 data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003656
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003657 /* In order to read a register from the EEPROM, we need to shift 'count'
3658 * bits in from the EEPROM. Bits are "shifted in" by raising the clock
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003659 * input to the EEPROM (setting the SK bit), and then reading the value
3660 * of the "DO" bit. During this "shifting in" process the "DI" bit
3661 * should always be clear.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003662 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003663
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003664 eecd = er32(EECD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003665
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003666 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
3667 data = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003668
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003669 for (i = 0; i < count; i++) {
3670 data = data << 1;
3671 e1000_raise_ee_clk(hw, &eecd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003672
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003673 eecd = er32(EECD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003674
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003675 eecd &= ~(E1000_EECD_DI);
3676 if (eecd & E1000_EECD_DO)
3677 data |= 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003678
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003679 e1000_lower_ee_clk(hw, &eecd);
3680 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003681
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003682 return data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003683}
3684
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003685/**
3686 * e1000_acquire_eeprom - Prepares EEPROM for access
3687 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -07003688 *
3689 * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
3690 * function should be called before issuing a command to the EEPROM.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003691 */
Joe Perches64798842008-07-11 15:17:02 -07003692static s32 e1000_acquire_eeprom(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003693{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003694 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3695 u32 eecd, i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003696
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003697 eecd = er32(EECD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003698
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003699 /* Request EEPROM Access */
3700 if (hw->mac_type > e1000_82544) {
3701 eecd |= E1000_EECD_REQ;
3702 ew32(EECD, eecd);
3703 eecd = er32(EECD);
3704 while ((!(eecd & E1000_EECD_GNT)) &&
3705 (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
3706 i++;
3707 udelay(5);
3708 eecd = er32(EECD);
3709 }
3710 if (!(eecd & E1000_EECD_GNT)) {
3711 eecd &= ~E1000_EECD_REQ;
3712 ew32(EECD, eecd);
Emil Tantilov675ad472010-04-27 14:02:58 +00003713 e_dbg("Could not acquire EEPROM grant\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003714 return -E1000_ERR_EEPROM;
3715 }
3716 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003717
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003718 /* Setup EEPROM for Read/Write */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003719
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003720 if (eeprom->type == e1000_eeprom_microwire) {
3721 /* Clear SK and DI */
3722 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
3723 ew32(EECD, eecd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003724
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003725 /* Set CS */
3726 eecd |= E1000_EECD_CS;
3727 ew32(EECD, eecd);
3728 } else if (eeprom->type == e1000_eeprom_spi) {
3729 /* Clear SK and CS */
3730 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
3731 ew32(EECD, eecd);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00003732 E1000_WRITE_FLUSH();
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003733 udelay(1);
3734 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003735
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003736 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003737}
3738
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003739/**
3740 * e1000_standby_eeprom - Returns EEPROM to a "standby" state
3741 * @hw: Struct containing variables accessed by shared code
3742 */
Joe Perches64798842008-07-11 15:17:02 -07003743static void e1000_standby_eeprom(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003744{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003745 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3746 u32 eecd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003747
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003748 eecd = er32(EECD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003749
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003750 if (eeprom->type == e1000_eeprom_microwire) {
3751 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
3752 ew32(EECD, eecd);
3753 E1000_WRITE_FLUSH();
3754 udelay(eeprom->delay_usec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003755
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003756 /* Clock high */
3757 eecd |= E1000_EECD_SK;
3758 ew32(EECD, eecd);
3759 E1000_WRITE_FLUSH();
3760 udelay(eeprom->delay_usec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003761
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003762 /* Select EEPROM */
3763 eecd |= E1000_EECD_CS;
3764 ew32(EECD, eecd);
3765 E1000_WRITE_FLUSH();
3766 udelay(eeprom->delay_usec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003767
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003768 /* Clock low */
3769 eecd &= ~E1000_EECD_SK;
3770 ew32(EECD, eecd);
3771 E1000_WRITE_FLUSH();
3772 udelay(eeprom->delay_usec);
3773 } else if (eeprom->type == e1000_eeprom_spi) {
3774 /* Toggle CS to flush commands */
3775 eecd |= E1000_EECD_CS;
3776 ew32(EECD, eecd);
3777 E1000_WRITE_FLUSH();
3778 udelay(eeprom->delay_usec);
3779 eecd &= ~E1000_EECD_CS;
3780 ew32(EECD, eecd);
3781 E1000_WRITE_FLUSH();
3782 udelay(eeprom->delay_usec);
3783 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003784}
3785
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003786/**
3787 * e1000_release_eeprom - drop chip select
3788 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -07003789 *
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003790 * Terminates a command by inverting the EEPROM's chip select pin
3791 */
Joe Perches64798842008-07-11 15:17:02 -07003792static void e1000_release_eeprom(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003793{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003794 u32 eecd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003795
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003796 eecd = er32(EECD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003797
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003798 if (hw->eeprom.type == e1000_eeprom_spi) {
3799 eecd |= E1000_EECD_CS; /* Pull CS high */
3800 eecd &= ~E1000_EECD_SK; /* Lower SCK */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003801
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003802 ew32(EECD, eecd);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00003803 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003804
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003805 udelay(hw->eeprom.delay_usec);
3806 } else if (hw->eeprom.type == e1000_eeprom_microwire) {
3807 /* cleanup eeprom */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003808
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003809 /* CS on Microwire is active-high */
3810 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003811
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003812 ew32(EECD, eecd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003813
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003814 /* Rising edge of clock */
3815 eecd |= E1000_EECD_SK;
3816 ew32(EECD, eecd);
3817 E1000_WRITE_FLUSH();
3818 udelay(hw->eeprom.delay_usec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003819
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003820 /* Falling edge of clock */
3821 eecd &= ~E1000_EECD_SK;
3822 ew32(EECD, eecd);
3823 E1000_WRITE_FLUSH();
3824 udelay(hw->eeprom.delay_usec);
3825 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003826
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003827 /* Stop requesting EEPROM access */
3828 if (hw->mac_type > e1000_82544) {
3829 eecd &= ~E1000_EECD_REQ;
3830 ew32(EECD, eecd);
3831 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003832}
3833
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003834/**
3835 * e1000_spi_eeprom_ready - Reads a 16 bit word from the EEPROM.
3836 * @hw: Struct containing variables accessed by shared code
3837 */
Joe Perches64798842008-07-11 15:17:02 -07003838static s32 e1000_spi_eeprom_ready(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003839{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003840 u16 retry_count = 0;
3841 u8 spi_stat_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003842
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003843 /* Read "Status Register" repeatedly until the LSB is cleared. The
3844 * EEPROM will signal that the command has been completed by clearing
3845 * bit 0 of the internal status register. If it's not cleared within
3846 * 5 milliseconds, then error out.
3847 */
3848 retry_count = 0;
3849 do {
3850 e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
3851 hw->eeprom.opcode_bits);
3852 spi_stat_reg = (u8) e1000_shift_in_ee_bits(hw, 8);
3853 if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
3854 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003855
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003856 udelay(5);
3857 retry_count += 5;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003858
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003859 e1000_standby_eeprom(hw);
3860 } while (retry_count < EEPROM_MAX_RETRY_SPI);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003861
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003862 /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
3863 * only 0-5mSec on 5V devices)
3864 */
3865 if (retry_count >= EEPROM_MAX_RETRY_SPI) {
Emil Tantilov675ad472010-04-27 14:02:58 +00003866 e_dbg("SPI EEPROM Status error\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003867 return -E1000_ERR_EEPROM;
3868 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003869
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003870 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003871}
3872
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003873/**
3874 * e1000_read_eeprom - Reads a 16 bit word from the EEPROM.
3875 * @hw: Struct containing variables accessed by shared code
3876 * @offset: offset of word in the EEPROM to read
3877 * @data: word read from the EEPROM
3878 * @words: number of words to read
3879 */
Joe Perches64798842008-07-11 15:17:02 -07003880s32 e1000_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003881{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003882 s32 ret;
Joern Engele09b8902015-07-23 14:54:34 -07003883 mutex_lock(&e1000_eeprom_lock);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003884 ret = e1000_do_read_eeprom(hw, offset, words, data);
Joern Engele09b8902015-07-23 14:54:34 -07003885 mutex_unlock(&e1000_eeprom_lock);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003886 return ret;
Christopher Li78566fe2008-09-05 14:04:05 -07003887}
3888
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003889static s32 e1000_do_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words,
3890 u16 *data)
Christopher Li78566fe2008-09-05 14:04:05 -07003891{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003892 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3893 u32 i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003894
Dirk Brandewie5377a412011-01-06 14:29:54 +00003895 if (hw->mac_type == e1000_ce4100) {
3896 GBE_CONFIG_FLASH_READ(GBE_CONFIG_BASE_VIRT, offset, words,
Janusz Wolaka48954c2015-09-17 23:34:29 +02003897 data);
Dirk Brandewie5377a412011-01-06 14:29:54 +00003898 return E1000_SUCCESS;
3899 }
3900
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003901 /* A check for invalid values: offset too large, too many words, and
3902 * not enough words.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003903 */
3904 if ((offset >= eeprom->word_size)
3905 || (words > eeprom->word_size - offset) || (words == 0)) {
Emil Tantilov675ad472010-04-27 14:02:58 +00003906 e_dbg("\"words\" parameter out of bounds. Words = %d,"
3907 "size = %d\n", offset, eeprom->word_size);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003908 return -E1000_ERR_EEPROM;
3909 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003910
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003911 /* EEPROM's that don't use EERD to read require us to bit-bang the SPI
3912 * directly. In this case, we need to acquire the EEPROM so that
3913 * FW or other port software does not interrupt.
3914 */
Jesse Brandeburg8f601b22009-09-25 12:20:11 +00003915 /* Prepare the EEPROM for bit-bang reading */
3916 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
3917 return -E1000_ERR_EEPROM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003918
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003919 /* Set up the SPI or Microwire EEPROM for bit-bang reading. We have
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003920 * acquired the EEPROM at this point, so any returns should release it
3921 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003922 if (eeprom->type == e1000_eeprom_spi) {
3923 u16 word_in;
3924 u8 read_opcode = EEPROM_READ_OPCODE_SPI;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003925
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003926 if (e1000_spi_eeprom_ready(hw)) {
3927 e1000_release_eeprom(hw);
3928 return -E1000_ERR_EEPROM;
3929 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003930
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003931 e1000_standby_eeprom(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003932
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003933 /* Some SPI eeproms use the 8th address bit embedded in the
3934 * opcode
3935 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003936 if ((eeprom->address_bits == 8) && (offset >= 128))
3937 read_opcode |= EEPROM_A8_OPCODE_SPI;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003938
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003939 /* Send the READ command (opcode + addr) */
3940 e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
3941 e1000_shift_out_ee_bits(hw, (u16) (offset * 2),
3942 eeprom->address_bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003943
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003944 /* Read the data. The address of the eeprom internally
3945 * increments with each byte (spi) being read, saving on the
3946 * overhead of eeprom setup and tear-down. The address counter
3947 * will roll over if reading beyond the size of the eeprom, thus
3948 * allowing the entire memory to be read starting from any
3949 * offset.
3950 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003951 for (i = 0; i < words; i++) {
3952 word_in = e1000_shift_in_ee_bits(hw, 16);
3953 data[i] = (word_in >> 8) | (word_in << 8);
3954 }
3955 } else if (eeprom->type == e1000_eeprom_microwire) {
3956 for (i = 0; i < words; i++) {
3957 /* Send the READ command (opcode + addr) */
3958 e1000_shift_out_ee_bits(hw,
3959 EEPROM_READ_OPCODE_MICROWIRE,
3960 eeprom->opcode_bits);
3961 e1000_shift_out_ee_bits(hw, (u16) (offset + i),
3962 eeprom->address_bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003963
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003964 /* Read the data. For microwire, each word requires the
3965 * overhead of eeprom setup and tear-down.
3966 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003967 data[i] = e1000_shift_in_ee_bits(hw, 16);
3968 e1000_standby_eeprom(hw);
Joern Engele09b8902015-07-23 14:54:34 -07003969 cond_resched();
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003970 }
3971 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003972
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003973 /* End this read operation */
3974 e1000_release_eeprom(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003975
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003976 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003977}
3978
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003979/**
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003980 * e1000_validate_eeprom_checksum - Verifies that the EEPROM has a valid checksum
3981 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -07003982 *
3983 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
3984 * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
3985 * valid.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003986 */
Joe Perches64798842008-07-11 15:17:02 -07003987s32 e1000_validate_eeprom_checksum(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003988{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003989 u16 checksum = 0;
3990 u16 i, eeprom_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003991
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003992 for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
3993 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
Emil Tantilov675ad472010-04-27 14:02:58 +00003994 e_dbg("EEPROM Read Error\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003995 return -E1000_ERR_EEPROM;
3996 }
3997 checksum += eeprom_data;
3998 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003999
Jeff Kirshere2faeec2011-08-30 20:58:56 -04004000#ifdef CONFIG_PARISC
4001 /* This is a signature and not a checksum on HP c8000 */
4002 if ((hw->subsystem_vendor_id == 0x103C) && (eeprom_data == 0x16d6))
4003 return E1000_SUCCESS;
4004
4005#endif
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004006 if (checksum == (u16) EEPROM_SUM)
4007 return E1000_SUCCESS;
4008 else {
Emil Tantilov675ad472010-04-27 14:02:58 +00004009 e_dbg("EEPROM Checksum Invalid\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004010 return -E1000_ERR_EEPROM;
4011 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004012}
4013
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004014/**
4015 * e1000_update_eeprom_checksum - Calculates/writes the EEPROM checksum
4016 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -07004017 *
4018 * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA.
4019 * Writes the difference to word offset 63 of the EEPROM.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004020 */
Joe Perches64798842008-07-11 15:17:02 -07004021s32 e1000_update_eeprom_checksum(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004022{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004023 u16 checksum = 0;
4024 u16 i, eeprom_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004025
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004026 for (i = 0; i < EEPROM_CHECKSUM_REG; i++) {
4027 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
Emil Tantilov675ad472010-04-27 14:02:58 +00004028 e_dbg("EEPROM Read Error\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004029 return -E1000_ERR_EEPROM;
4030 }
4031 checksum += eeprom_data;
4032 }
4033 checksum = (u16) EEPROM_SUM - checksum;
4034 if (e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) {
Emil Tantilov675ad472010-04-27 14:02:58 +00004035 e_dbg("EEPROM Write Error\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004036 return -E1000_ERR_EEPROM;
4037 }
4038 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004039}
4040
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004041/**
4042 * e1000_write_eeprom - write words to the different EEPROM types.
4043 * @hw: Struct containing variables accessed by shared code
4044 * @offset: offset within the EEPROM to be written to
4045 * @words: number of words to write
4046 * @data: 16 bit word to be written to the EEPROM
Linus Torvalds1da177e2005-04-16 15:20:36 -07004047 *
4048 * If e1000_update_eeprom_checksum is not called after this function, the
4049 * EEPROM will most likely contain an invalid checksum.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004050 */
Joe Perches64798842008-07-11 15:17:02 -07004051s32 e1000_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004052{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004053 s32 ret;
Joern Engele09b8902015-07-23 14:54:34 -07004054 mutex_lock(&e1000_eeprom_lock);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004055 ret = e1000_do_write_eeprom(hw, offset, words, data);
Joern Engele09b8902015-07-23 14:54:34 -07004056 mutex_unlock(&e1000_eeprom_lock);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004057 return ret;
Christopher Li78566fe2008-09-05 14:04:05 -07004058}
4059
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004060static s32 e1000_do_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words,
4061 u16 *data)
Christopher Li78566fe2008-09-05 14:04:05 -07004062{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004063 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4064 s32 status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004065
Dirk Brandewie5377a412011-01-06 14:29:54 +00004066 if (hw->mac_type == e1000_ce4100) {
4067 GBE_CONFIG_FLASH_WRITE(GBE_CONFIG_BASE_VIRT, offset, words,
Janusz Wolaka48954c2015-09-17 23:34:29 +02004068 data);
Dirk Brandewie5377a412011-01-06 14:29:54 +00004069 return E1000_SUCCESS;
4070 }
4071
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00004072 /* A check for invalid values: offset too large, too many words, and
4073 * not enough words.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004074 */
4075 if ((offset >= eeprom->word_size)
4076 || (words > eeprom->word_size - offset) || (words == 0)) {
Emil Tantilov675ad472010-04-27 14:02:58 +00004077 e_dbg("\"words\" parameter out of bounds\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004078 return -E1000_ERR_EEPROM;
4079 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004080
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004081 /* Prepare the EEPROM for writing */
4082 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
4083 return -E1000_ERR_EEPROM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004084
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004085 if (eeprom->type == e1000_eeprom_microwire) {
4086 status = e1000_write_eeprom_microwire(hw, offset, words, data);
4087 } else {
4088 status = e1000_write_eeprom_spi(hw, offset, words, data);
4089 msleep(10);
4090 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004091
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004092 /* Done with writing */
4093 e1000_release_eeprom(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004094
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004095 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004096}
4097
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004098/**
4099 * e1000_write_eeprom_spi - Writes a 16 bit word to a given offset in an SPI EEPROM.
4100 * @hw: Struct containing variables accessed by shared code
4101 * @offset: offset within the EEPROM to be written to
4102 * @words: number of words to write
4103 * @data: pointer to array of 8 bit words to be written to the EEPROM
4104 */
Joe Perches64798842008-07-11 15:17:02 -07004105static s32 e1000_write_eeprom_spi(struct e1000_hw *hw, u16 offset, u16 words,
4106 u16 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004107{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004108 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4109 u16 widx = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004110
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004111 while (widx < words) {
4112 u8 write_opcode = EEPROM_WRITE_OPCODE_SPI;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004113
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004114 if (e1000_spi_eeprom_ready(hw))
4115 return -E1000_ERR_EEPROM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004116
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004117 e1000_standby_eeprom(hw);
Joern Engele09b8902015-07-23 14:54:34 -07004118 cond_resched();
Linus Torvalds1da177e2005-04-16 15:20:36 -07004119
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004120 /* Send the WRITE ENABLE command (8 bit opcode ) */
4121 e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI,
4122 eeprom->opcode_bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004123
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004124 e1000_standby_eeprom(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004125
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00004126 /* Some SPI eeproms use the 8th address bit embedded in the
4127 * opcode
4128 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004129 if ((eeprom->address_bits == 8) && (offset >= 128))
4130 write_opcode |= EEPROM_A8_OPCODE_SPI;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004131
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004132 /* Send the Write command (8-bit opcode + addr) */
4133 e1000_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004134
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004135 e1000_shift_out_ee_bits(hw, (u16) ((offset + widx) * 2),
4136 eeprom->address_bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004137
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004138 /* Send the data */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004139
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00004140 /* Loop to allow for up to whole page write (32 bytes) of
4141 * eeprom
4142 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004143 while (widx < words) {
4144 u16 word_out = data[widx];
4145 word_out = (word_out >> 8) | (word_out << 8);
4146 e1000_shift_out_ee_bits(hw, word_out, 16);
4147 widx++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004148
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00004149 /* Some larger eeprom sizes are capable of a 32-byte
4150 * PAGE WRITE operation, while the smaller eeproms are
4151 * capable of an 8-byte PAGE WRITE operation. Break the
4152 * inner loop to pass new address
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004153 */
4154 if ((((offset + widx) * 2) % eeprom->page_size) == 0) {
4155 e1000_standby_eeprom(hw);
4156 break;
4157 }
4158 }
4159 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004160
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004161 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004162}
4163
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004164/**
4165 * e1000_write_eeprom_microwire - Writes a 16 bit word to a given offset in a Microwire EEPROM.
4166 * @hw: Struct containing variables accessed by shared code
4167 * @offset: offset within the EEPROM to be written to
4168 * @words: number of words to write
4169 * @data: pointer to array of 8 bit words to be written to the EEPROM
4170 */
Joe Perches64798842008-07-11 15:17:02 -07004171static s32 e1000_write_eeprom_microwire(struct e1000_hw *hw, u16 offset,
4172 u16 words, u16 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004173{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004174 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4175 u32 eecd;
4176 u16 words_written = 0;
4177 u16 i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004178
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004179 /* Send the write enable command to the EEPROM (3-bit opcode plus
4180 * 6/8-bit dummy address beginning with 11). It's less work to include
4181 * the 11 of the dummy address as part of the opcode than it is to shift
4182 * it over the correct number of bits for the address. This puts the
4183 * EEPROM into write/erase mode.
4184 */
4185 e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE,
4186 (u16) (eeprom->opcode_bits + 2));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004187
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004188 e1000_shift_out_ee_bits(hw, 0, (u16) (eeprom->address_bits - 2));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004189
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004190 /* Prepare the EEPROM */
4191 e1000_standby_eeprom(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004192
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004193 while (words_written < words) {
4194 /* Send the Write command (3-bit opcode + addr) */
4195 e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE,
4196 eeprom->opcode_bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004197
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004198 e1000_shift_out_ee_bits(hw, (u16) (offset + words_written),
4199 eeprom->address_bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004200
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004201 /* Send the data */
4202 e1000_shift_out_ee_bits(hw, data[words_written], 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004203
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00004204 /* Toggle the CS line. This in effect tells the EEPROM to
4205 * execute the previous command.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004206 */
4207 e1000_standby_eeprom(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004208
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00004209 /* Read DO repeatedly until it is high (equal to '1'). The
4210 * EEPROM will signal that the command has been completed by
4211 * raising the DO signal. If DO does not go high in 10
4212 * milliseconds, then error out.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004213 */
4214 for (i = 0; i < 200; i++) {
4215 eecd = er32(EECD);
4216 if (eecd & E1000_EECD_DO)
4217 break;
4218 udelay(50);
4219 }
4220 if (i == 200) {
Emil Tantilov675ad472010-04-27 14:02:58 +00004221 e_dbg("EEPROM Write did not complete\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004222 return -E1000_ERR_EEPROM;
4223 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004224
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004225 /* Recover from write */
4226 e1000_standby_eeprom(hw);
Joern Engele09b8902015-07-23 14:54:34 -07004227 cond_resched();
Linus Torvalds1da177e2005-04-16 15:20:36 -07004228
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004229 words_written++;
4230 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004231
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004232 /* Send the write disable command to the EEPROM (3-bit opcode plus
4233 * 6/8-bit dummy address beginning with 10). It's less work to include
4234 * the 10 of the dummy address as part of the opcode than it is to shift
4235 * it over the correct number of bits for the address. This takes the
4236 * EEPROM out of write/erase mode.
4237 */
4238 e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE,
4239 (u16) (eeprom->opcode_bits + 2));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004240
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004241 e1000_shift_out_ee_bits(hw, 0, (u16) (eeprom->address_bits - 2));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004242
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004243 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004244}
4245
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004246/**
4247 * e1000_read_mac_addr - read the adapters MAC from eeprom
4248 * @hw: Struct containing variables accessed by shared code
4249 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07004250 * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
4251 * second function of dual function devices
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004252 */
Joe Perches64798842008-07-11 15:17:02 -07004253s32 e1000_read_mac_addr(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004254{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004255 u16 offset;
4256 u16 eeprom_data, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004257
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004258 for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
4259 offset = i >> 1;
4260 if (e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
Emil Tantilov675ad472010-04-27 14:02:58 +00004261 e_dbg("EEPROM Read Error\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004262 return -E1000_ERR_EEPROM;
4263 }
4264 hw->perm_mac_addr[i] = (u8) (eeprom_data & 0x00FF);
4265 hw->perm_mac_addr[i + 1] = (u8) (eeprom_data >> 8);
4266 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004267
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004268 switch (hw->mac_type) {
4269 default:
4270 break;
4271 case e1000_82546:
4272 case e1000_82546_rev_3:
4273 if (er32(STATUS) & E1000_STATUS_FUNC_1)
4274 hw->perm_mac_addr[5] ^= 0x01;
4275 break;
4276 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004277
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004278 for (i = 0; i < NODE_ADDRESS_SIZE; i++)
4279 hw->mac_addr[i] = hw->perm_mac_addr[i];
4280 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004281}
4282
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004283/**
4284 * e1000_init_rx_addrs - Initializes receive address filters.
4285 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -07004286 *
4287 * Places the MAC address in receive address register 0 and clears the rest
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004288 * of the receive address registers. Clears the multicast table. Assumes
Linus Torvalds1da177e2005-04-16 15:20:36 -07004289 * the receiver is in reset when the routine is called.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004290 */
Joe Perches64798842008-07-11 15:17:02 -07004291static void e1000_init_rx_addrs(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004292{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004293 u32 i;
4294 u32 rar_num;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004295
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004296 /* Setup the receive address. */
Emil Tantilov675ad472010-04-27 14:02:58 +00004297 e_dbg("Programming MAC Address into RAR[0]\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004298
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004299 e1000_rar_set(hw, hw->mac_addr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004300
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004301 rar_num = E1000_RAR_ENTRIES;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004302
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004303 /* Zero out the other 15 receive addresses. */
Emil Tantilov675ad472010-04-27 14:02:58 +00004304 e_dbg("Clearing RAR[1-15]\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004305 for (i = 1; i < rar_num; i++) {
4306 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
4307 E1000_WRITE_FLUSH();
4308 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
4309 E1000_WRITE_FLUSH();
4310 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004311}
4312
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004313/**
4314 * e1000_hash_mc_addr - Hashes an address to determine its location in the multicast table
4315 * @hw: Struct containing variables accessed by shared code
4316 * @mc_addr: the multicast address to hash
4317 */
Joe Perches64798842008-07-11 15:17:02 -07004318u32 e1000_hash_mc_addr(struct e1000_hw *hw, u8 *mc_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004319{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004320 u32 hash_value = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004321
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004322 /* The portion of the address that is used for the hash table is
4323 * determined by the mc_filter_type setting.
4324 */
4325 switch (hw->mc_filter_type) {
4326 /* [0] [1] [2] [3] [4] [5]
4327 * 01 AA 00 12 34 56
4328 * LSB MSB
4329 */
4330 case 0:
4331 /* [47:36] i.e. 0x563 for above example address */
4332 hash_value = ((mc_addr[4] >> 4) | (((u16) mc_addr[5]) << 4));
4333 break;
4334 case 1:
4335 /* [46:35] i.e. 0xAC6 for above example address */
4336 hash_value = ((mc_addr[4] >> 3) | (((u16) mc_addr[5]) << 5));
4337 break;
4338 case 2:
4339 /* [45:34] i.e. 0x5D8 for above example address */
4340 hash_value = ((mc_addr[4] >> 2) | (((u16) mc_addr[5]) << 6));
4341 break;
4342 case 3:
4343 /* [43:32] i.e. 0x634 for above example address */
4344 hash_value = ((mc_addr[4]) | (((u16) mc_addr[5]) << 8));
4345 break;
4346 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004347
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004348 hash_value &= 0xFFF;
4349 return hash_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004350}
4351
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004352/**
4353 * e1000_rar_set - Puts an ethernet address into a receive address register.
4354 * @hw: Struct containing variables accessed by shared code
4355 * @addr: Address to put into receive address register
4356 * @index: Receive address register to write
4357 */
Joe Perches64798842008-07-11 15:17:02 -07004358void e1000_rar_set(struct e1000_hw *hw, u8 *addr, u32 index)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004359{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004360 u32 rar_low, rar_high;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004361
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004362 /* HW expects these in little endian so we reverse the byte order
4363 * from network order (big endian) to little endian
4364 */
4365 rar_low = ((u32) addr[0] | ((u32) addr[1] << 8) |
4366 ((u32) addr[2] << 16) | ((u32) addr[3] << 24));
4367 rar_high = ((u32) addr[4] | ((u32) addr[5] << 8));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004368
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004369 /* Disable Rx and flush all Rx frames before enabling RSS to avoid Rx
4370 * unit hang.
4371 *
4372 * Description:
4373 * If there are any Rx frames queued up or otherwise present in the HW
4374 * before RSS is enabled, and then we enable RSS, the HW Rx unit will
4375 * hang. To work around this issue, we have to disable receives and
4376 * flush out all Rx frames before we enable RSS. To do so, we modify we
4377 * redirect all Rx traffic to manageability and then reset the HW.
4378 * This flushes away Rx frames, and (since the redirections to
4379 * manageability persists across resets) keeps new ones from coming in
4380 * while we work. Then, we clear the Address Valid AV bit for all MAC
4381 * addresses and undo the re-direction to manageability.
4382 * Now, frames are coming in again, but the MAC won't accept them, so
4383 * far so good. We now proceed to initialize RSS (if necessary) and
4384 * configure the Rx unit. Last, we re-enable the AV bits and continue
4385 * on our merry way.
4386 */
4387 switch (hw->mac_type) {
4388 default:
4389 /* Indicate to hardware the Address is Valid. */
4390 rar_high |= E1000_RAH_AV;
4391 break;
4392 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004393
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004394 E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
4395 E1000_WRITE_FLUSH();
4396 E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
4397 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07004398}
4399
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004400/**
4401 * e1000_write_vfta - Writes a value to the specified offset in the VLAN filter table.
4402 * @hw: Struct containing variables accessed by shared code
4403 * @offset: Offset in VLAN filer table to write
4404 * @value: Value to write into VLAN filter table
4405 */
Joe Perches64798842008-07-11 15:17:02 -07004406void e1000_write_vfta(struct e1000_hw *hw, u32 offset, u32 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004407{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004408 u32 temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004409
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004410 if ((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) {
4411 temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1));
4412 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
4413 E1000_WRITE_FLUSH();
4414 E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp);
4415 E1000_WRITE_FLUSH();
4416 } else {
4417 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
4418 E1000_WRITE_FLUSH();
4419 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004420}
4421
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004422/**
4423 * e1000_clear_vfta - Clears the VLAN filer table
4424 * @hw: Struct containing variables accessed by shared code
4425 */
Joe Perches64798842008-07-11 15:17:02 -07004426static void e1000_clear_vfta(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004427{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004428 u32 offset;
4429 u32 vfta_value = 0;
4430 u32 vfta_offset = 0;
4431 u32 vfta_bit_in_reg = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004432
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004433 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
4434 /* If the offset we want to clear is the same offset of the
4435 * manageability VLAN ID, then clear all bits except that of the
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00004436 * manageability unit
4437 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004438 vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0;
4439 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, vfta_value);
4440 E1000_WRITE_FLUSH();
4441 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004442}
4443
Joe Perches64798842008-07-11 15:17:02 -07004444static s32 e1000_id_led_init(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004445{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004446 u32 ledctl;
4447 const u32 ledctl_mask = 0x000000FF;
4448 const u32 ledctl_on = E1000_LEDCTL_MODE_LED_ON;
4449 const u32 ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
4450 u16 eeprom_data, i, temp;
4451 const u16 led_mask = 0x0F;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004452
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004453 if (hw->mac_type < e1000_82540) {
4454 /* Nothing to do */
4455 return E1000_SUCCESS;
4456 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004457
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004458 ledctl = er32(LEDCTL);
4459 hw->ledctl_default = ledctl;
4460 hw->ledctl_mode1 = hw->ledctl_default;
4461 hw->ledctl_mode2 = hw->ledctl_default;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004462
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004463 if (e1000_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, 1, &eeprom_data) < 0) {
Emil Tantilov675ad472010-04-27 14:02:58 +00004464 e_dbg("EEPROM Read Error\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004465 return -E1000_ERR_EEPROM;
4466 }
Auke Kokcd94dd02006-06-27 09:08:22 -07004467
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004468 if ((eeprom_data == ID_LED_RESERVED_0000) ||
4469 (eeprom_data == ID_LED_RESERVED_FFFF)) {
4470 eeprom_data = ID_LED_DEFAULT;
4471 }
Auke Kok90fb5132006-11-01 08:47:30 -08004472
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004473 for (i = 0; i < 4; i++) {
4474 temp = (eeprom_data >> (i << 2)) & led_mask;
4475 switch (temp) {
4476 case ID_LED_ON1_DEF2:
4477 case ID_LED_ON1_ON2:
4478 case ID_LED_ON1_OFF2:
4479 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
4480 hw->ledctl_mode1 |= ledctl_on << (i << 3);
4481 break;
4482 case ID_LED_OFF1_DEF2:
4483 case ID_LED_OFF1_ON2:
4484 case ID_LED_OFF1_OFF2:
4485 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
4486 hw->ledctl_mode1 |= ledctl_off << (i << 3);
4487 break;
4488 default:
4489 /* Do nothing */
4490 break;
4491 }
4492 switch (temp) {
4493 case ID_LED_DEF1_ON2:
4494 case ID_LED_ON1_ON2:
4495 case ID_LED_OFF1_ON2:
4496 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
4497 hw->ledctl_mode2 |= ledctl_on << (i << 3);
4498 break;
4499 case ID_LED_DEF1_OFF2:
4500 case ID_LED_ON1_OFF2:
4501 case ID_LED_OFF1_OFF2:
4502 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
4503 hw->ledctl_mode2 |= ledctl_off << (i << 3);
4504 break;
4505 default:
4506 /* Do nothing */
4507 break;
4508 }
4509 }
4510 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004511}
4512
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004513/**
4514 * e1000_setup_led
4515 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -07004516 *
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004517 * Prepares SW controlable LED for use and saves the current state of the LED.
4518 */
Joe Perches64798842008-07-11 15:17:02 -07004519s32 e1000_setup_led(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004520{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004521 u32 ledctl;
4522 s32 ret_val = E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004523
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004524 switch (hw->mac_type) {
4525 case e1000_82542_rev2_0:
4526 case e1000_82542_rev2_1:
4527 case e1000_82543:
4528 case e1000_82544:
4529 /* No setup necessary */
4530 break;
4531 case e1000_82541:
4532 case e1000_82547:
4533 case e1000_82541_rev_2:
4534 case e1000_82547_rev_2:
4535 /* Turn off PHY Smart Power Down (if enabled) */
4536 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
4537 &hw->phy_spd_default);
4538 if (ret_val)
4539 return ret_val;
4540 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
4541 (u16) (hw->phy_spd_default &
4542 ~IGP01E1000_GMII_SPD));
4543 if (ret_val)
4544 return ret_val;
4545 /* Fall Through */
4546 default:
4547 if (hw->media_type == e1000_media_type_fiber) {
4548 ledctl = er32(LEDCTL);
4549 /* Save current LEDCTL settings */
4550 hw->ledctl_default = ledctl;
4551 /* Turn off LED0 */
4552 ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
4553 E1000_LEDCTL_LED0_BLINK |
4554 E1000_LEDCTL_LED0_MODE_MASK);
4555 ledctl |= (E1000_LEDCTL_MODE_LED_OFF <<
4556 E1000_LEDCTL_LED0_MODE_SHIFT);
4557 ew32(LEDCTL, ledctl);
4558 } else if (hw->media_type == e1000_media_type_copper)
4559 ew32(LEDCTL, hw->ledctl_mode1);
4560 break;
4561 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004562
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004563 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004564}
4565
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004566/**
4567 * e1000_cleanup_led - Restores the saved state of the SW controlable LED.
4568 * @hw: Struct containing variables accessed by shared code
4569 */
Joe Perches64798842008-07-11 15:17:02 -07004570s32 e1000_cleanup_led(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004571{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004572 s32 ret_val = E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004573
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004574 switch (hw->mac_type) {
4575 case e1000_82542_rev2_0:
4576 case e1000_82542_rev2_1:
4577 case e1000_82543:
4578 case e1000_82544:
4579 /* No cleanup necessary */
4580 break;
4581 case e1000_82541:
4582 case e1000_82547:
4583 case e1000_82541_rev_2:
4584 case e1000_82547_rev_2:
4585 /* Turn on PHY Smart Power Down (if previously enabled) */
4586 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
4587 hw->phy_spd_default);
4588 if (ret_val)
4589 return ret_val;
4590 /* Fall Through */
4591 default:
4592 /* Restore LEDCTL settings */
4593 ew32(LEDCTL, hw->ledctl_default);
4594 break;
4595 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004596
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004597 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004598}
4599
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004600/**
4601 * e1000_led_on - Turns on the software controllable LED
4602 * @hw: Struct containing variables accessed by shared code
4603 */
Joe Perches64798842008-07-11 15:17:02 -07004604s32 e1000_led_on(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004605{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004606 u32 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004607
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004608 switch (hw->mac_type) {
4609 case e1000_82542_rev2_0:
4610 case e1000_82542_rev2_1:
4611 case e1000_82543:
4612 /* Set SW Defineable Pin 0 to turn on the LED */
4613 ctrl |= E1000_CTRL_SWDPIN0;
4614 ctrl |= E1000_CTRL_SWDPIO0;
4615 break;
4616 case e1000_82544:
4617 if (hw->media_type == e1000_media_type_fiber) {
4618 /* Set SW Defineable Pin 0 to turn on the LED */
4619 ctrl |= E1000_CTRL_SWDPIN0;
4620 ctrl |= E1000_CTRL_SWDPIO0;
4621 } else {
4622 /* Clear SW Defineable Pin 0 to turn on the LED */
4623 ctrl &= ~E1000_CTRL_SWDPIN0;
4624 ctrl |= E1000_CTRL_SWDPIO0;
4625 }
4626 break;
4627 default:
4628 if (hw->media_type == e1000_media_type_fiber) {
4629 /* Clear SW Defineable Pin 0 to turn on the LED */
4630 ctrl &= ~E1000_CTRL_SWDPIN0;
4631 ctrl |= E1000_CTRL_SWDPIO0;
4632 } else if (hw->media_type == e1000_media_type_copper) {
4633 ew32(LEDCTL, hw->ledctl_mode2);
4634 return E1000_SUCCESS;
4635 }
4636 break;
4637 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004638
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004639 ew32(CTRL, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004640
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004641 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004642}
4643
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004644/**
4645 * e1000_led_off - Turns off the software controllable LED
4646 * @hw: Struct containing variables accessed by shared code
4647 */
Joe Perches64798842008-07-11 15:17:02 -07004648s32 e1000_led_off(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004649{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004650 u32 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004651
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004652 switch (hw->mac_type) {
4653 case e1000_82542_rev2_0:
4654 case e1000_82542_rev2_1:
4655 case e1000_82543:
4656 /* Clear SW Defineable Pin 0 to turn off the LED */
4657 ctrl &= ~E1000_CTRL_SWDPIN0;
4658 ctrl |= E1000_CTRL_SWDPIO0;
4659 break;
4660 case e1000_82544:
4661 if (hw->media_type == e1000_media_type_fiber) {
4662 /* Clear SW Defineable Pin 0 to turn off the LED */
4663 ctrl &= ~E1000_CTRL_SWDPIN0;
4664 ctrl |= E1000_CTRL_SWDPIO0;
4665 } else {
4666 /* Set SW Defineable Pin 0 to turn off the LED */
4667 ctrl |= E1000_CTRL_SWDPIN0;
4668 ctrl |= E1000_CTRL_SWDPIO0;
4669 }
4670 break;
4671 default:
4672 if (hw->media_type == e1000_media_type_fiber) {
4673 /* Set SW Defineable Pin 0 to turn off the LED */
4674 ctrl |= E1000_CTRL_SWDPIN0;
4675 ctrl |= E1000_CTRL_SWDPIO0;
4676 } else if (hw->media_type == e1000_media_type_copper) {
4677 ew32(LEDCTL, hw->ledctl_mode1);
4678 return E1000_SUCCESS;
4679 }
4680 break;
4681 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004682
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004683 ew32(CTRL, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004684
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004685 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004686}
4687
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004688/**
4689 * e1000_clear_hw_cntrs - Clears all hardware statistics counters.
4690 * @hw: Struct containing variables accessed by shared code
4691 */
Joe Perches64798842008-07-11 15:17:02 -07004692static void e1000_clear_hw_cntrs(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004693{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004694 volatile u32 temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004695
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004696 temp = er32(CRCERRS);
4697 temp = er32(SYMERRS);
4698 temp = er32(MPC);
4699 temp = er32(SCC);
4700 temp = er32(ECOL);
4701 temp = er32(MCC);
4702 temp = er32(LATECOL);
4703 temp = er32(COLC);
4704 temp = er32(DC);
4705 temp = er32(SEC);
4706 temp = er32(RLEC);
4707 temp = er32(XONRXC);
4708 temp = er32(XONTXC);
4709 temp = er32(XOFFRXC);
4710 temp = er32(XOFFTXC);
4711 temp = er32(FCRUC);
Auke Kokcd94dd02006-06-27 09:08:22 -07004712
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004713 temp = er32(PRC64);
4714 temp = er32(PRC127);
4715 temp = er32(PRC255);
4716 temp = er32(PRC511);
4717 temp = er32(PRC1023);
4718 temp = er32(PRC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07004719
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004720 temp = er32(GPRC);
4721 temp = er32(BPRC);
4722 temp = er32(MPRC);
4723 temp = er32(GPTC);
4724 temp = er32(GORCL);
4725 temp = er32(GORCH);
4726 temp = er32(GOTCL);
4727 temp = er32(GOTCH);
4728 temp = er32(RNBC);
4729 temp = er32(RUC);
4730 temp = er32(RFC);
4731 temp = er32(ROC);
4732 temp = er32(RJC);
4733 temp = er32(TORL);
4734 temp = er32(TORH);
4735 temp = er32(TOTL);
4736 temp = er32(TOTH);
4737 temp = er32(TPR);
4738 temp = er32(TPT);
Auke Kokcd94dd02006-06-27 09:08:22 -07004739
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004740 temp = er32(PTC64);
4741 temp = er32(PTC127);
4742 temp = er32(PTC255);
4743 temp = er32(PTC511);
4744 temp = er32(PTC1023);
4745 temp = er32(PTC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07004746
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004747 temp = er32(MPTC);
4748 temp = er32(BPTC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004749
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004750 if (hw->mac_type < e1000_82543)
4751 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004752
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004753 temp = er32(ALGNERRC);
4754 temp = er32(RXERRC);
4755 temp = er32(TNCRS);
4756 temp = er32(CEXTERR);
4757 temp = er32(TSCTC);
4758 temp = er32(TSCTFC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004759
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004760 if (hw->mac_type <= e1000_82544)
4761 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004762
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004763 temp = er32(MGTPRC);
4764 temp = er32(MGTPDC);
4765 temp = er32(MGTPTC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004766}
4767
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004768/**
4769 * e1000_reset_adaptive - Resets Adaptive IFS to its default state.
4770 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -07004771 *
4772 * Call this after e1000_init_hw. You may override the IFS defaults by setting
Joe Perchesc3033b02008-03-21 11:06:25 -07004773 * hw->ifs_params_forced to true. However, you must initialize hw->
Linus Torvalds1da177e2005-04-16 15:20:36 -07004774 * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio
4775 * before calling this function.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004776 */
Joe Perches64798842008-07-11 15:17:02 -07004777void e1000_reset_adaptive(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004778{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004779 if (hw->adaptive_ifs) {
4780 if (!hw->ifs_params_forced) {
4781 hw->current_ifs_val = 0;
4782 hw->ifs_min_val = IFS_MIN;
4783 hw->ifs_max_val = IFS_MAX;
4784 hw->ifs_step_size = IFS_STEP;
4785 hw->ifs_ratio = IFS_RATIO;
4786 }
4787 hw->in_ifs_mode = false;
4788 ew32(AIT, 0);
4789 } else {
Emil Tantilov675ad472010-04-27 14:02:58 +00004790 e_dbg("Not in Adaptive IFS mode!\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004791 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004792}
4793
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004794/**
4795 * e1000_update_adaptive - update adaptive IFS
4796 * @hw: Struct containing variables accessed by shared code
4797 * @tx_packets: Number of transmits since last callback
4798 * @total_collisions: Number of collisions since last callback
4799 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07004800 * Called during the callback/watchdog routine to update IFS value based on
4801 * the ratio of transmits to collisions.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004802 */
Joe Perches64798842008-07-11 15:17:02 -07004803void e1000_update_adaptive(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004804{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004805 if (hw->adaptive_ifs) {
4806 if ((hw->collision_delta *hw->ifs_ratio) > hw->tx_packet_delta) {
4807 if (hw->tx_packet_delta > MIN_NUM_XMITS) {
4808 hw->in_ifs_mode = true;
4809 if (hw->current_ifs_val < hw->ifs_max_val) {
4810 if (hw->current_ifs_val == 0)
4811 hw->current_ifs_val =
4812 hw->ifs_min_val;
4813 else
4814 hw->current_ifs_val +=
4815 hw->ifs_step_size;
4816 ew32(AIT, hw->current_ifs_val);
4817 }
4818 }
4819 } else {
4820 if (hw->in_ifs_mode
4821 && (hw->tx_packet_delta <= MIN_NUM_XMITS)) {
4822 hw->current_ifs_val = 0;
4823 hw->in_ifs_mode = false;
4824 ew32(AIT, 0);
4825 }
4826 }
4827 } else {
Emil Tantilov675ad472010-04-27 14:02:58 +00004828 e_dbg("Not in Adaptive IFS mode!\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004829 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004830}
4831
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004832/**
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004833 * e1000_get_bus_info
4834 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -07004835 *
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004836 * Gets the current PCI bus type, speed, and width of the hardware
4837 */
Joe Perches64798842008-07-11 15:17:02 -07004838void e1000_get_bus_info(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004839{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004840 u32 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004841
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004842 switch (hw->mac_type) {
4843 case e1000_82542_rev2_0:
4844 case e1000_82542_rev2_1:
4845 hw->bus_type = e1000_bus_type_pci;
4846 hw->bus_speed = e1000_bus_speed_unknown;
4847 hw->bus_width = e1000_bus_width_unknown;
4848 break;
4849 default:
4850 status = er32(STATUS);
4851 hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
4852 e1000_bus_type_pcix : e1000_bus_type_pci;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004853
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004854 if (hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) {
4855 hw->bus_speed = (hw->bus_type == e1000_bus_type_pci) ?
4856 e1000_bus_speed_66 : e1000_bus_speed_120;
4857 } else if (hw->bus_type == e1000_bus_type_pci) {
4858 hw->bus_speed = (status & E1000_STATUS_PCI66) ?
4859 e1000_bus_speed_66 : e1000_bus_speed_33;
4860 } else {
4861 switch (status & E1000_STATUS_PCIX_SPEED) {
4862 case E1000_STATUS_PCIX_SPEED_66:
4863 hw->bus_speed = e1000_bus_speed_66;
4864 break;
4865 case E1000_STATUS_PCIX_SPEED_100:
4866 hw->bus_speed = e1000_bus_speed_100;
4867 break;
4868 case E1000_STATUS_PCIX_SPEED_133:
4869 hw->bus_speed = e1000_bus_speed_133;
4870 break;
4871 default:
4872 hw->bus_speed = e1000_bus_speed_reserved;
4873 break;
4874 }
4875 }
4876 hw->bus_width = (status & E1000_STATUS_BUS64) ?
4877 e1000_bus_width_64 : e1000_bus_width_32;
4878 break;
4879 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004880}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004881
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004882/**
4883 * e1000_write_reg_io
4884 * @hw: Struct containing variables accessed by shared code
4885 * @offset: offset to write to
4886 * @value: value to write
4887 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07004888 * Writes a value to one of the devices registers using port I/O (as opposed to
4889 * memory mapped I/O). Only 82544 and newer devices support port I/O.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004890 */
Joe Perches64798842008-07-11 15:17:02 -07004891static void e1000_write_reg_io(struct e1000_hw *hw, u32 offset, u32 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004892{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004893 unsigned long io_addr = hw->io_base;
4894 unsigned long io_data = hw->io_base + 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004895
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004896 e1000_io_write(hw, io_addr, offset);
4897 e1000_io_write(hw, io_data, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004898}
4899
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004900/**
4901 * e1000_get_cable_length - Estimates the cable length.
4902 * @hw: Struct containing variables accessed by shared code
4903 * @min_length: The estimated minimum length
4904 * @max_length: The estimated maximum length
Linus Torvalds1da177e2005-04-16 15:20:36 -07004905 *
4906 * returns: - E1000_ERR_XXX
4907 * E1000_SUCCESS
4908 *
4909 * This function always returns a ranged length (minimum & maximum).
4910 * So for M88 phy's, this function interprets the one value returned from the
4911 * register to the minimum and maximum range.
4912 * For IGP phy's, the function calculates the range by the AGC registers.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004913 */
Joe Perches64798842008-07-11 15:17:02 -07004914static s32 e1000_get_cable_length(struct e1000_hw *hw, u16 *min_length,
4915 u16 *max_length)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004916{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004917 s32 ret_val;
4918 u16 agc_value = 0;
4919 u16 i, phy_data;
4920 u16 cable_length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004921
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004922 *min_length = *max_length = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004923
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004924 /* Use old method for Phy older than IGP */
4925 if (hw->phy_type == e1000_phy_m88) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004926
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004927 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
4928 &phy_data);
4929 if (ret_val)
4930 return ret_val;
4931 cable_length = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
4932 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004933
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004934 /* Convert the enum value to ranged values */
4935 switch (cable_length) {
4936 case e1000_cable_length_50:
4937 *min_length = 0;
4938 *max_length = e1000_igp_cable_length_50;
4939 break;
4940 case e1000_cable_length_50_80:
4941 *min_length = e1000_igp_cable_length_50;
4942 *max_length = e1000_igp_cable_length_80;
4943 break;
4944 case e1000_cable_length_80_110:
4945 *min_length = e1000_igp_cable_length_80;
4946 *max_length = e1000_igp_cable_length_110;
4947 break;
4948 case e1000_cable_length_110_140:
4949 *min_length = e1000_igp_cable_length_110;
4950 *max_length = e1000_igp_cable_length_140;
4951 break;
4952 case e1000_cable_length_140:
4953 *min_length = e1000_igp_cable_length_140;
4954 *max_length = e1000_igp_cable_length_170;
4955 break;
4956 default:
4957 return -E1000_ERR_PHY;
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004958 }
4959 } else if (hw->phy_type == e1000_phy_igp) { /* For IGP PHY */
4960 u16 cur_agc_value;
4961 u16 min_agc_value = IGP01E1000_AGC_LENGTH_TABLE_SIZE;
Jeff Kirsher66744502010-12-01 19:59:50 +00004962 static const u16 agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] = {
4963 IGP01E1000_PHY_AGC_A,
4964 IGP01E1000_PHY_AGC_B,
4965 IGP01E1000_PHY_AGC_C,
4966 IGP01E1000_PHY_AGC_D
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004967 };
4968 /* Read the AGC registers for all channels */
4969 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004970
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004971 ret_val =
4972 e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
4973 if (ret_val)
4974 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004975
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004976 cur_agc_value = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004977
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004978 /* Value bound check. */
4979 if ((cur_agc_value >=
4980 IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1)
4981 || (cur_agc_value == 0))
4982 return -E1000_ERR_PHY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004983
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004984 agc_value += cur_agc_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004985
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004986 /* Update minimal AGC value. */
4987 if (min_agc_value > cur_agc_value)
4988 min_agc_value = cur_agc_value;
4989 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004990
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004991 /* Remove the minimal AGC result for length < 50m */
4992 if (agc_value <
4993 IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) {
4994 agc_value -= min_agc_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004995
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004996 /* Get the average length of the remaining 3 channels */
4997 agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1);
4998 } else {
4999 /* Get the average length of all the 4 channels. */
5000 agc_value /= IGP01E1000_PHY_CHANNEL_NUM;
5001 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005002
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005003 /* Set the range of the calculated length. */
5004 *min_length = ((e1000_igp_cable_length_table[agc_value] -
5005 IGP01E1000_AGC_RANGE) > 0) ?
5006 (e1000_igp_cable_length_table[agc_value] -
5007 IGP01E1000_AGC_RANGE) : 0;
5008 *max_length = e1000_igp_cable_length_table[agc_value] +
5009 IGP01E1000_AGC_RANGE;
5010 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005011
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005012 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005013}
5014
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005015/**
5016 * e1000_check_polarity - Check the cable polarity
5017 * @hw: Struct containing variables accessed by shared code
5018 * @polarity: output parameter : 0 - Polarity is not reversed
Linus Torvalds1da177e2005-04-16 15:20:36 -07005019 * 1 - Polarity is reversed.
5020 *
5021 * returns: - E1000_ERR_XXX
5022 * E1000_SUCCESS
5023 *
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02005024 * For phy's older than IGP, this function simply reads the polarity bit in the
Linus Torvalds1da177e2005-04-16 15:20:36 -07005025 * Phy Status register. For IGP phy's, this bit is valid only if link speed is
5026 * 10 Mbps. If the link speed is 100 Mbps there is no polarity so this bit will
5027 * return 0. If the link speed is 1000 Mbps the polarity status is in the
5028 * IGP01E1000_PHY_PCS_INIT_REG.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005029 */
Joe Perches64798842008-07-11 15:17:02 -07005030static s32 e1000_check_polarity(struct e1000_hw *hw,
5031 e1000_rev_polarity *polarity)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005032{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005033 s32 ret_val;
5034 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005035
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005036 if (hw->phy_type == e1000_phy_m88) {
5037 /* return the Polarity bit in the Status register. */
5038 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
5039 &phy_data);
5040 if (ret_val)
5041 return ret_val;
5042 *polarity = ((phy_data & M88E1000_PSSR_REV_POLARITY) >>
5043 M88E1000_PSSR_REV_POLARITY_SHIFT) ?
5044 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07005045
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005046 } else if (hw->phy_type == e1000_phy_igp) {
5047 /* Read the Status register to check the speed */
5048 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
5049 &phy_data);
5050 if (ret_val)
5051 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005052
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00005053 /* If speed is 1000 Mbps, must read the
5054 * IGP01E1000_PHY_PCS_INIT_REG to find the polarity status
5055 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005056 if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
5057 IGP01E1000_PSSR_SPEED_1000MBPS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005058
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005059 /* Read the GIG initialization PCS register (0x00B4) */
5060 ret_val =
5061 e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG,
5062 &phy_data);
5063 if (ret_val)
5064 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005065
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005066 /* Check the polarity bits */
5067 *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ?
5068 e1000_rev_polarity_reversed :
5069 e1000_rev_polarity_normal;
5070 } else {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00005071 /* For 10 Mbps, read the polarity bit in the status
5072 * register. (for 100 Mbps this bit is always 0)
5073 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005074 *polarity =
5075 (phy_data & IGP01E1000_PSSR_POLARITY_REVERSED) ?
5076 e1000_rev_polarity_reversed :
5077 e1000_rev_polarity_normal;
5078 }
5079 }
5080 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005081}
5082
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005083/**
5084 * e1000_check_downshift - Check if Downshift occurred
5085 * @hw: Struct containing variables accessed by shared code
5086 * @downshift: output parameter : 0 - No Downshift occurred.
5087 * 1 - Downshift occurred.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005088 *
5089 * returns: - E1000_ERR_XXX
Auke Kok76c224b2006-05-23 13:36:06 -07005090 * E1000_SUCCESS
Linus Torvalds1da177e2005-04-16 15:20:36 -07005091 *
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02005092 * For phy's older than IGP, this function reads the Downshift bit in the Phy
Linus Torvalds1da177e2005-04-16 15:20:36 -07005093 * Specific Status register. For IGP phy's, it reads the Downgrade bit in the
5094 * Link Health register. In IGP this bit is latched high, so the driver must
5095 * read it immediately after link is established.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005096 */
Joe Perches64798842008-07-11 15:17:02 -07005097static s32 e1000_check_downshift(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005098{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005099 s32 ret_val;
5100 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005101
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005102 if (hw->phy_type == e1000_phy_igp) {
5103 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH,
5104 &phy_data);
5105 if (ret_val)
5106 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005107
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005108 hw->speed_downgraded =
5109 (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0;
5110 } else if (hw->phy_type == e1000_phy_m88) {
5111 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
5112 &phy_data);
5113 if (ret_val)
5114 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005115
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005116 hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >>
5117 M88E1000_PSSR_DOWNSHIFT_SHIFT;
5118 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005119
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005120 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005121}
5122
Joe Perches542c3f42012-02-10 12:07:36 +00005123static const u16 dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] = {
5124 IGP01E1000_PHY_AGC_PARAM_A,
5125 IGP01E1000_PHY_AGC_PARAM_B,
5126 IGP01E1000_PHY_AGC_PARAM_C,
5127 IGP01E1000_PHY_AGC_PARAM_D
5128};
5129
5130static s32 e1000_1000Mb_check_cable_length(struct e1000_hw *hw)
5131{
5132 u16 min_length, max_length;
5133 u16 phy_data, i;
5134 s32 ret_val;
5135
5136 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
5137 if (ret_val)
5138 return ret_val;
5139
5140 if (hw->dsp_config_state != e1000_dsp_config_enabled)
5141 return 0;
5142
5143 if (min_length >= e1000_igp_cable_length_50) {
5144 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
5145 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i],
5146 &phy_data);
5147 if (ret_val)
5148 return ret_val;
5149
5150 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
5151
5152 ret_val = e1000_write_phy_reg(hw, dsp_reg_array[i],
5153 phy_data);
5154 if (ret_val)
5155 return ret_val;
5156 }
5157 hw->dsp_config_state = e1000_dsp_config_activated;
5158 } else {
5159 u16 ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_20;
5160 u32 idle_errs = 0;
5161
5162 /* clear previous idle error counts */
5163 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
5164 if (ret_val)
5165 return ret_val;
5166
5167 for (i = 0; i < ffe_idle_err_timeout; i++) {
5168 udelay(1000);
5169 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
5170 &phy_data);
5171 if (ret_val)
5172 return ret_val;
5173
5174 idle_errs += (phy_data & SR_1000T_IDLE_ERROR_CNT);
5175 if (idle_errs > SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT) {
5176 hw->ffe_config_state = e1000_ffe_config_active;
5177
5178 ret_val = e1000_write_phy_reg(hw,
5179 IGP01E1000_PHY_DSP_FFE,
5180 IGP01E1000_PHY_DSP_FFE_CM_CP);
5181 if (ret_val)
5182 return ret_val;
5183 break;
5184 }
5185
5186 if (idle_errs)
5187 ffe_idle_err_timeout =
5188 FFE_IDLE_ERR_COUNT_TIMEOUT_100;
5189 }
5190 }
5191
5192 return 0;
5193}
5194
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005195/**
5196 * e1000_config_dsp_after_link_change
5197 * @hw: Struct containing variables accessed by shared code
5198 * @link_up: was link up at the time this was called
5199 *
5200 * returns: - E1000_ERR_PHY if fail to read/write the PHY
5201 * E1000_SUCCESS at any other case.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005202 *
5203 * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a
5204 * gigabit link is achieved to improve link quality.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005205 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005206
Joe Perches64798842008-07-11 15:17:02 -07005207static s32 e1000_config_dsp_after_link_change(struct e1000_hw *hw, bool link_up)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005208{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005209 s32 ret_val;
5210 u16 phy_data, phy_saved_data, speed, duplex, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005211
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005212 if (hw->phy_type != e1000_phy_igp)
5213 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005214
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005215 if (link_up) {
5216 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
5217 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00005218 e_dbg("Error getting link speed and duplex\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005219 return ret_val;
5220 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005221
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005222 if (speed == SPEED_1000) {
Joe Perches542c3f42012-02-10 12:07:36 +00005223 ret_val = e1000_1000Mb_check_cable_length(hw);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005224 if (ret_val)
5225 return ret_val;
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005226 }
5227 } else {
5228 if (hw->dsp_config_state == e1000_dsp_config_activated) {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00005229 /* Save off the current value of register 0x2F5B to be
5230 * restored at the end of the routines.
5231 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005232 ret_val =
5233 e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005234
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005235 if (ret_val)
5236 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005237
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005238 /* Disable the PHY transmitter */
5239 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005240
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005241 if (ret_val)
5242 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005243
Jesse Brandeburg4e0d8f7d2011-10-05 07:24:46 +00005244 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005245
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005246 ret_val = e1000_write_phy_reg(hw, 0x0000,
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00005247 IGP01E1000_IEEE_FORCE_GIGA);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005248 if (ret_val)
5249 return ret_val;
5250 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
5251 ret_val =
5252 e1000_read_phy_reg(hw, dsp_reg_array[i],
5253 &phy_data);
5254 if (ret_val)
5255 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005256
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005257 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
5258 phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005259
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005260 ret_val =
5261 e1000_write_phy_reg(hw, dsp_reg_array[i],
5262 phy_data);
5263 if (ret_val)
5264 return ret_val;
5265 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005266
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005267 ret_val = e1000_write_phy_reg(hw, 0x0000,
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00005268 IGP01E1000_IEEE_RESTART_AUTONEG);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005269 if (ret_val)
5270 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005271
Jesse Brandeburg4e0d8f7d2011-10-05 07:24:46 +00005272 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005273
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005274 /* Now enable the transmitter */
5275 ret_val =
5276 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005277
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005278 if (ret_val)
5279 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005280
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005281 hw->dsp_config_state = e1000_dsp_config_enabled;
5282 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005283
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005284 if (hw->ffe_config_state == e1000_ffe_config_active) {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00005285 /* Save off the current value of register 0x2F5B to be
5286 * restored at the end of the routines.
5287 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005288 ret_val =
5289 e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005290
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005291 if (ret_val)
5292 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005293
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005294 /* Disable the PHY transmitter */
5295 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005296
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005297 if (ret_val)
5298 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005299
Jesse Brandeburg4e0d8f7d2011-10-05 07:24:46 +00005300 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005301
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005302 ret_val = e1000_write_phy_reg(hw, 0x0000,
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00005303 IGP01E1000_IEEE_FORCE_GIGA);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005304 if (ret_val)
5305 return ret_val;
5306 ret_val =
5307 e1000_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE,
5308 IGP01E1000_PHY_DSP_FFE_DEFAULT);
5309 if (ret_val)
5310 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005311
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005312 ret_val = e1000_write_phy_reg(hw, 0x0000,
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00005313 IGP01E1000_IEEE_RESTART_AUTONEG);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005314 if (ret_val)
5315 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005316
Jesse Brandeburg4e0d8f7d2011-10-05 07:24:46 +00005317 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005318
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005319 /* Now enable the transmitter */
5320 ret_val =
5321 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005322
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005323 if (ret_val)
5324 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005325
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005326 hw->ffe_config_state = e1000_ffe_config_enabled;
5327 }
5328 }
5329 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005330}
5331
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005332/**
5333 * e1000_set_phy_mode - Set PHY to class A mode
5334 * @hw: Struct containing variables accessed by shared code
5335 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07005336 * Assumes the following operations will follow to enable the new class mode.
5337 * 1. Do a PHY soft reset
5338 * 2. Restart auto-negotiation or force link.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005339 */
Joe Perches64798842008-07-11 15:17:02 -07005340static s32 e1000_set_phy_mode(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005341{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005342 s32 ret_val;
5343 u16 eeprom_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005344
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005345 if ((hw->mac_type == e1000_82545_rev_3) &&
5346 (hw->media_type == e1000_media_type_copper)) {
5347 ret_val =
5348 e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, 1,
5349 &eeprom_data);
5350 if (ret_val) {
5351 return ret_val;
5352 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005353
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005354 if ((eeprom_data != EEPROM_RESERVED_WORD) &&
5355 (eeprom_data & EEPROM_PHY_CLASS_A)) {
5356 ret_val =
5357 e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT,
5358 0x000B);
5359 if (ret_val)
5360 return ret_val;
5361 ret_val =
5362 e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL,
5363 0x8104);
5364 if (ret_val)
5365 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005366
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005367 hw->phy_reset_disable = false;
5368 }
5369 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005370
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005371 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005372}
5373
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005374/**
5375 * e1000_set_d3_lplu_state - set d3 link power state
5376 * @hw: Struct containing variables accessed by shared code
5377 * @active: true to enable lplu false to disable lplu.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005378 *
5379 * This function sets the lplu state according to the active flag. When
5380 * activating lplu this function also disables smart speed and vise versa.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005381 * lplu will not be activated unless the device autonegotiation advertisement
Linus Torvalds1da177e2005-04-16 15:20:36 -07005382 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005383 *
5384 * returns: - E1000_ERR_PHY if fail to read/write the PHY
5385 * E1000_SUCCESS at any other case.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005386 */
Joe Perches64798842008-07-11 15:17:02 -07005387static s32 e1000_set_d3_lplu_state(struct e1000_hw *hw, bool active)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005388{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005389 s32 ret_val;
5390 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005391
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005392 if (hw->phy_type != e1000_phy_igp)
5393 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005394
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005395 /* During driver activity LPLU should not be used or it will attain link
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00005396 * from the lowest speeds starting from 10Mbps. The capability is used
5397 * for Dx transitions and states
5398 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005399 if (hw->mac_type == e1000_82541_rev_2
5400 || hw->mac_type == e1000_82547_rev_2) {
5401 ret_val =
5402 e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data);
5403 if (ret_val)
5404 return ret_val;
5405 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005406
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005407 if (!active) {
5408 if (hw->mac_type == e1000_82541_rev_2 ||
5409 hw->mac_type == e1000_82547_rev_2) {
5410 phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
5411 ret_val =
5412 e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
5413 phy_data);
5414 if (ret_val)
5415 return ret_val;
5416 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005417
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00005418 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
5419 * during Dx states where the power conservation is most
5420 * important. During driver activity we should enable
5421 * SmartSpeed, so performance is maintained.
5422 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005423 if (hw->smart_speed == e1000_smart_speed_on) {
5424 ret_val =
5425 e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5426 &phy_data);
5427 if (ret_val)
5428 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005429
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005430 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
5431 ret_val =
5432 e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5433 phy_data);
5434 if (ret_val)
5435 return ret_val;
5436 } else if (hw->smart_speed == e1000_smart_speed_off) {
5437 ret_val =
5438 e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5439 &phy_data);
5440 if (ret_val)
5441 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005442
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005443 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
5444 ret_val =
5445 e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5446 phy_data);
5447 if (ret_val)
5448 return ret_val;
5449 }
5450 } else if ((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT)
5451 || (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL)
5452 || (hw->autoneg_advertised ==
5453 AUTONEG_ADVERTISE_10_100_ALL)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005454
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005455 if (hw->mac_type == e1000_82541_rev_2 ||
5456 hw->mac_type == e1000_82547_rev_2) {
5457 phy_data |= IGP01E1000_GMII_FLEX_SPD;
5458 ret_val =
5459 e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
5460 phy_data);
5461 if (ret_val)
5462 return ret_val;
5463 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005464
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005465 /* When LPLU is enabled we should disable SmartSpeed */
5466 ret_val =
5467 e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5468 &phy_data);
5469 if (ret_val)
5470 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005471
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005472 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
5473 ret_val =
5474 e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5475 phy_data);
5476 if (ret_val)
5477 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005478
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005479 }
5480 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005481}
5482
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005483/**
5484 * e1000_set_vco_speed
5485 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -07005486 *
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005487 * Change VCO speed register to improve Bit Error Rate performance of SERDES.
5488 */
Joe Perches64798842008-07-11 15:17:02 -07005489static s32 e1000_set_vco_speed(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005490{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005491 s32 ret_val;
5492 u16 default_page = 0;
5493 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005494
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005495 switch (hw->mac_type) {
5496 case e1000_82545_rev_3:
5497 case e1000_82546_rev_3:
5498 break;
5499 default:
5500 return E1000_SUCCESS;
5501 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005502
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005503 /* Set PHY register 30, page 5, bit 8 to 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005504
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005505 ret_val =
5506 e1000_read_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, &default_page);
5507 if (ret_val)
5508 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005509
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005510 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005);
5511 if (ret_val)
5512 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005513
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005514 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
5515 if (ret_val)
5516 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005517
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005518 phy_data &= ~M88E1000_PHY_VCO_REG_BIT8;
5519 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
5520 if (ret_val)
5521 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005522
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005523 /* Set PHY register 30, page 4, bit 11 to 1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005524
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005525 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004);
5526 if (ret_val)
5527 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005528
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005529 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
5530 if (ret_val)
5531 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005532
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005533 phy_data |= M88E1000_PHY_VCO_REG_BIT11;
5534 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
5535 if (ret_val)
5536 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005537
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005538 ret_val =
5539 e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, default_page);
5540 if (ret_val)
5541 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005542
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005543 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005544}
5545
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005546
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005547/**
5548 * e1000_enable_mng_pass_thru - check for bmc pass through
5549 * @hw: Struct containing variables accessed by shared code
5550 *
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005551 * Verifies the hardware needs to allow ARPs to be processed by the host
Joe Perchesc3033b02008-03-21 11:06:25 -07005552 * returns: - true/false
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005553 */
Joe Perches64798842008-07-11 15:17:02 -07005554u32 e1000_enable_mng_pass_thru(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005555{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005556 u32 manc;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005557
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005558 if (hw->asf_firmware_present) {
5559 manc = er32(MANC);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005560
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005561 if (!(manc & E1000_MANC_RCV_TCO_EN) ||
5562 !(manc & E1000_MANC_EN_MAC_ADDR_FILTER))
5563 return false;
5564 if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN))
5565 return true;
5566 }
5567 return false;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005568}
5569
Joe Perches64798842008-07-11 15:17:02 -07005570static s32 e1000_polarity_reversal_workaround(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005571{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005572 s32 ret_val;
5573 u16 mii_status_reg;
5574 u16 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005575
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005576 /* Polarity reversal workaround for forced 10F/10H links. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005577
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005578 /* Disable the transmitter on the PHY */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005579
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005580 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
5581 if (ret_val)
5582 return ret_val;
5583 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF);
5584 if (ret_val)
5585 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005586
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005587 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
5588 if (ret_val)
5589 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005590
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005591 /* This loop will early-out if the NO link condition has been met. */
5592 for (i = PHY_FORCE_TIME; i > 0; i--) {
5593 /* Read the MII Status Register and wait for Link Status bit
5594 * to be clear.
5595 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005596
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005597 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
5598 if (ret_val)
5599 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005600
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005601 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
5602 if (ret_val)
5603 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005604
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005605 if ((mii_status_reg & ~MII_SR_LINK_STATUS) == 0)
5606 break;
Jesse Brandeburg4e0d8f7d2011-10-05 07:24:46 +00005607 msleep(100);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005608 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005609
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005610 /* Recommended delay time after link has been lost */
Jesse Brandeburg4e0d8f7d2011-10-05 07:24:46 +00005611 msleep(1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005612
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005613 /* Now we will re-enable th transmitter on the PHY */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005614
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005615 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
5616 if (ret_val)
5617 return ret_val;
Jesse Brandeburg4e0d8f7d2011-10-05 07:24:46 +00005618 msleep(50);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005619 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0);
5620 if (ret_val)
5621 return ret_val;
Jesse Brandeburg4e0d8f7d2011-10-05 07:24:46 +00005622 msleep(50);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005623 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00);
5624 if (ret_val)
5625 return ret_val;
Jesse Brandeburg4e0d8f7d2011-10-05 07:24:46 +00005626 msleep(50);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005627 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000);
5628 if (ret_val)
5629 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005630
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005631 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
5632 if (ret_val)
5633 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005634
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005635 /* This loop will early-out if the link condition has been met. */
5636 for (i = PHY_FORCE_TIME; i > 0; i--) {
5637 /* Read the MII Status Register and wait for Link Status bit
5638 * to be set.
5639 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005640
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005641 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
5642 if (ret_val)
5643 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005644
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005645 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
5646 if (ret_val)
5647 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005648
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005649 if (mii_status_reg & MII_SR_LINK_STATUS)
5650 break;
Jesse Brandeburg4e0d8f7d2011-10-05 07:24:46 +00005651 msleep(100);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005652 }
5653 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005654}
5655
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005656/**
5657 * e1000_get_auto_rd_done
5658 * @hw: Struct containing variables accessed by shared code
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005659 *
5660 * Check for EEPROM Auto Read bit done.
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005661 * returns: - E1000_ERR_RESET if fail to reset MAC
5662 * E1000_SUCCESS at any other case.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005663 */
Joe Perches64798842008-07-11 15:17:02 -07005664static s32 e1000_get_auto_rd_done(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005665{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005666 msleep(5);
5667 return E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005668}
5669
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005670/**
5671 * e1000_get_phy_cfg_done
5672 * @hw: Struct containing variables accessed by shared code
5673 *
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005674 * Checks if the PHY configuration is done
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005675 * returns: - E1000_ERR_RESET if fail to reset MAC
5676 * E1000_SUCCESS at any other case.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005677 */
Joe Perches64798842008-07-11 15:17:02 -07005678static s32 e1000_get_phy_cfg_done(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005679{
Jesse Brandeburg4e0d8f7d2011-10-05 07:24:46 +00005680 msleep(10);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005681 return E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005682}