blob: 2879b9631e150662e164931e326826f82d9a60c8 [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
Christopher Li78566fe2008-09-05 14:04:05 -0700109static DEFINE_SPINLOCK(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{
Emil Tantilov675ad472010-04-27 14:02:58 +0000118 e_dbg("e1000_set_phy_type");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700120 if (hw->mac_type == e1000_undefined)
121 return -E1000_ERR_PHY_TYPE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700122
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700123 switch (hw->phy_id) {
124 case M88E1000_E_PHY_ID:
125 case M88E1000_I_PHY_ID:
126 case M88E1011_I_PHY_ID:
127 case M88E1111_I_PHY_ID:
Florian Fainellicf8e09b2011-01-24 14:48:03 +0000128 case M88E1118_E_PHY_ID:
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700129 hw->phy_type = e1000_phy_m88;
130 break;
131 case IGP01E1000_I_PHY_ID:
132 if (hw->mac_type == e1000_82541 ||
133 hw->mac_type == e1000_82541_rev_2 ||
134 hw->mac_type == e1000_82547 ||
Dirk Brandewie5377a412011-01-06 14:29:54 +0000135 hw->mac_type == e1000_82547_rev_2)
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700136 hw->phy_type = e1000_phy_igp;
Dirk Brandewie5377a412011-01-06 14:29:54 +0000137 break;
138 case RTL8211B_PHY_ID:
139 hw->phy_type = e1000_phy_8211;
140 break;
141 case RTL8201N_PHY_ID:
142 hw->phy_type = e1000_phy_8201;
143 break;
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700144 default:
145 /* Should never have loaded on this device */
146 hw->phy_type = e1000_phy_undefined;
147 return -E1000_ERR_PHY_TYPE;
148 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700150 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151}
152
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700153/**
154 * e1000_phy_init_script - IGP phy init script - initializes the GbE PHY
155 * @hw: Struct containing variables accessed by shared code
156 */
Joe Perches64798842008-07-11 15:17:02 -0700157static void e1000_phy_init_script(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700159 u32 ret_val;
160 u16 phy_saved_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
Emil Tantilov675ad472010-04-27 14:02:58 +0000162 e_dbg("e1000_phy_init_script");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700164 if (hw->phy_init_script) {
165 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000167 /* Save off the current value of register 0x2F5B to be restored
168 * at the end of this routine.
169 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700170 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700172 /* Disabled the PHY transmitter */
173 e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
174 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700176 e1000_write_phy_reg(hw, 0x0000, 0x0140);
177 msleep(5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700179 switch (hw->mac_type) {
180 case e1000_82541:
181 case e1000_82547:
182 e1000_write_phy_reg(hw, 0x1F95, 0x0001);
183 e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
184 e1000_write_phy_reg(hw, 0x1F79, 0x0018);
185 e1000_write_phy_reg(hw, 0x1F30, 0x1600);
186 e1000_write_phy_reg(hw, 0x1F31, 0x0014);
187 e1000_write_phy_reg(hw, 0x1F32, 0x161C);
188 e1000_write_phy_reg(hw, 0x1F94, 0x0003);
189 e1000_write_phy_reg(hw, 0x1F96, 0x003F);
190 e1000_write_phy_reg(hw, 0x2010, 0x0008);
191 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700193 case e1000_82541_rev_2:
194 case e1000_82547_rev_2:
195 e1000_write_phy_reg(hw, 0x1F73, 0x0099);
196 break;
197 default:
198 break;
199 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700201 e1000_write_phy_reg(hw, 0x0000, 0x3300);
202 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700204 /* Now enable the transmitter */
205 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700207 if (hw->mac_type == e1000_82547) {
208 u16 fused, fine, coarse;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700210 /* Move to analog registers page */
211 e1000_read_phy_reg(hw,
212 IGP01E1000_ANALOG_SPARE_FUSE_STATUS,
213 &fused);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700215 if (!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
216 e1000_read_phy_reg(hw,
217 IGP01E1000_ANALOG_FUSE_STATUS,
218 &fused);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700220 fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
221 coarse =
222 fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700224 if (coarse >
225 IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
226 coarse -=
227 IGP01E1000_ANALOG_FUSE_COARSE_10;
228 fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
229 } else if (coarse ==
230 IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
231 fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700233 fused =
234 (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
235 (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
236 (coarse &
237 IGP01E1000_ANALOG_FUSE_COARSE_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700239 e1000_write_phy_reg(hw,
240 IGP01E1000_ANALOG_FUSE_CONTROL,
241 fused);
242 e1000_write_phy_reg(hw,
243 IGP01E1000_ANALOG_FUSE_BYPASS,
244 IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
245 }
246 }
247 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248}
249
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700250/**
251 * e1000_set_mac_type - Set the mac type member in the hw struct.
252 * @hw: Struct containing variables accessed by shared code
253 */
Joe Perches64798842008-07-11 15:17:02 -0700254s32 e1000_set_mac_type(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255{
Emil Tantilov675ad472010-04-27 14:02:58 +0000256 e_dbg("e1000_set_mac_type");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500258 switch (hw->device_id) {
259 case E1000_DEV_ID_82542:
260 switch (hw->revision_id) {
261 case E1000_82542_2_0_REV_ID:
262 hw->mac_type = e1000_82542_rev2_0;
263 break;
264 case E1000_82542_2_1_REV_ID:
265 hw->mac_type = e1000_82542_rev2_1;
266 break;
267 default:
268 /* Invalid 82542 revision ID */
269 return -E1000_ERR_MAC_TYPE;
270 }
271 break;
272 case E1000_DEV_ID_82543GC_FIBER:
273 case E1000_DEV_ID_82543GC_COPPER:
274 hw->mac_type = e1000_82543;
275 break;
276 case E1000_DEV_ID_82544EI_COPPER:
277 case E1000_DEV_ID_82544EI_FIBER:
278 case E1000_DEV_ID_82544GC_COPPER:
279 case E1000_DEV_ID_82544GC_LOM:
280 hw->mac_type = e1000_82544;
281 break;
282 case E1000_DEV_ID_82540EM:
283 case E1000_DEV_ID_82540EM_LOM:
284 case E1000_DEV_ID_82540EP:
285 case E1000_DEV_ID_82540EP_LOM:
286 case E1000_DEV_ID_82540EP_LP:
287 hw->mac_type = e1000_82540;
288 break;
289 case E1000_DEV_ID_82545EM_COPPER:
290 case E1000_DEV_ID_82545EM_FIBER:
291 hw->mac_type = e1000_82545;
292 break;
293 case E1000_DEV_ID_82545GM_COPPER:
294 case E1000_DEV_ID_82545GM_FIBER:
295 case E1000_DEV_ID_82545GM_SERDES:
296 hw->mac_type = e1000_82545_rev_3;
297 break;
298 case E1000_DEV_ID_82546EB_COPPER:
299 case E1000_DEV_ID_82546EB_FIBER:
300 case E1000_DEV_ID_82546EB_QUAD_COPPER:
301 hw->mac_type = e1000_82546;
302 break;
303 case E1000_DEV_ID_82546GB_COPPER:
304 case E1000_DEV_ID_82546GB_FIBER:
305 case E1000_DEV_ID_82546GB_SERDES:
306 case E1000_DEV_ID_82546GB_PCIE:
307 case E1000_DEV_ID_82546GB_QUAD_COPPER:
308 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
309 hw->mac_type = e1000_82546_rev_3;
310 break;
311 case E1000_DEV_ID_82541EI:
312 case E1000_DEV_ID_82541EI_MOBILE:
313 case E1000_DEV_ID_82541ER_LOM:
314 hw->mac_type = e1000_82541;
315 break;
316 case E1000_DEV_ID_82541ER:
317 case E1000_DEV_ID_82541GI:
318 case E1000_DEV_ID_82541GI_LF:
319 case E1000_DEV_ID_82541GI_MOBILE:
320 hw->mac_type = e1000_82541_rev_2;
321 break;
322 case E1000_DEV_ID_82547EI:
323 case E1000_DEV_ID_82547EI_MOBILE:
324 hw->mac_type = e1000_82547;
325 break;
326 case E1000_DEV_ID_82547GI:
327 hw->mac_type = e1000_82547_rev_2;
328 break;
Dirk Brandewie5377a412011-01-06 14:29:54 +0000329 case E1000_DEV_ID_INTEL_CE4100_GBE:
330 hw->mac_type = e1000_ce4100;
331 break;
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500332 default:
333 /* Should never have loaded on this device */
334 return -E1000_ERR_MAC_TYPE;
335 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500337 switch (hw->mac_type) {
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500338 case e1000_82541:
339 case e1000_82547:
340 case e1000_82541_rev_2:
341 case e1000_82547_rev_2:
Joe Perchesc3033b02008-03-21 11:06:25 -0700342 hw->asf_firmware_present = true;
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500343 break;
344 default:
345 break;
346 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347
Jeff Garzik167fb282006-12-15 10:41:15 -0500348 /* The 82543 chip does not count tx_carrier_errors properly in
349 * FD mode
350 */
351 if (hw->mac_type == e1000_82543)
Joe Perchesc3033b02008-03-21 11:06:25 -0700352 hw->bad_tx_carr_stats_fd = true;
Jeff Garzik167fb282006-12-15 10:41:15 -0500353
Jeff Garzik15e376b2006-12-15 11:16:33 -0500354 if (hw->mac_type > e1000_82544)
Joe Perchesc3033b02008-03-21 11:06:25 -0700355 hw->has_smbus = true;
Jeff Garzik15e376b2006-12-15 11:16:33 -0500356
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500357 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358}
359
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700360/**
361 * e1000_set_media_type - Set media type and TBI compatibility.
362 * @hw: Struct containing variables accessed by shared code
363 */
Joe Perches64798842008-07-11 15:17:02 -0700364void e1000_set_media_type(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700366 u32 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367
Emil Tantilov675ad472010-04-27 14:02:58 +0000368 e_dbg("e1000_set_media_type");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700370 if (hw->mac_type != e1000_82543) {
371 /* tbi_compatibility is only valid on 82543 */
372 hw->tbi_compatibility_en = false;
373 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700375 switch (hw->device_id) {
376 case E1000_DEV_ID_82545GM_SERDES:
377 case E1000_DEV_ID_82546GB_SERDES:
378 hw->media_type = e1000_media_type_internal_serdes;
379 break;
380 default:
381 switch (hw->mac_type) {
382 case e1000_82542_rev2_0:
383 case e1000_82542_rev2_1:
384 hw->media_type = e1000_media_type_fiber;
385 break;
Dirk Brandewie5377a412011-01-06 14:29:54 +0000386 case e1000_ce4100:
387 hw->media_type = e1000_media_type_copper;
388 break;
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700389 default:
390 status = er32(STATUS);
391 if (status & E1000_STATUS_TBIMODE) {
392 hw->media_type = e1000_media_type_fiber;
393 /* tbi_compatibility not valid on fiber */
394 hw->tbi_compatibility_en = false;
395 } else {
396 hw->media_type = e1000_media_type_copper;
397 }
398 break;
399 }
400 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401}
402
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700403/**
Ben Hutchings49ce9c22012-07-10 10:56:00 +0000404 * e1000_reset_hw - reset the hardware completely
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700405 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 *
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700407 * Reset the transmit and receive units; mask and clear all interrupts.
408 */
Joe Perches64798842008-07-11 15:17:02 -0700409s32 e1000_reset_hw(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700411 u32 ctrl;
412 u32 ctrl_ext;
413 u32 icr;
414 u32 manc;
415 u32 led_ctrl;
416 s32 ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417
Emil Tantilov675ad472010-04-27 14:02:58 +0000418 e_dbg("e1000_reset_hw");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700420 /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
421 if (hw->mac_type == e1000_82542_rev2_0) {
Emil Tantilov675ad472010-04-27 14:02:58 +0000422 e_dbg("Disabling MWI on 82542 rev 2.0\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700423 e1000_pci_clear_mwi(hw);
424 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700426 /* Clear interrupt mask to stop board from generating interrupts */
Emil Tantilov675ad472010-04-27 14:02:58 +0000427 e_dbg("Masking off all interrupts\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700428 ew32(IMC, 0xffffffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700430 /* Disable the Transmit and Receive units. Then delay to allow
431 * any pending transactions to complete before we hit the MAC with
432 * the global reset.
433 */
434 ew32(RCTL, 0);
435 ew32(TCTL, E1000_TCTL_PSP);
436 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700438 /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
439 hw->tbi_compatibility_on = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700441 /* Delay to allow any outstanding PCI transactions to complete before
442 * resetting the device
443 */
444 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700446 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700448 /* Must reset the PHY before resetting the MAC */
449 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
450 ew32(CTRL, (ctrl | E1000_CTRL_PHY_RST));
Jesse Brandeburg945a5152011-07-20 00:56:21 +0000451 E1000_WRITE_FLUSH();
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700452 msleep(5);
453 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700455 /* Issue a global reset to the MAC. This will reset the chip's
456 * transmit, receive, DMA, and link units. It will not effect
457 * the current PCI configuration. The global reset bit is self-
458 * clearing, and should clear within a microsecond.
459 */
Emil Tantilov675ad472010-04-27 14:02:58 +0000460 e_dbg("Issuing a global reset to MAC\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700462 switch (hw->mac_type) {
463 case e1000_82544:
464 case e1000_82540:
465 case e1000_82545:
466 case e1000_82546:
467 case e1000_82541:
468 case e1000_82541_rev_2:
469 /* These controllers can't ack the 64-bit write when issuing the
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000470 * reset, so use IO-mapping as a workaround to issue the reset
471 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700472 E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
473 break;
474 case e1000_82545_rev_3:
475 case e1000_82546_rev_3:
476 /* Reset is performed on a shadow of the control register */
477 ew32(CTRL_DUP, (ctrl | E1000_CTRL_RST));
478 break;
Dirk Brandewie5377a412011-01-06 14:29:54 +0000479 case e1000_ce4100:
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700480 default:
481 ew32(CTRL, (ctrl | E1000_CTRL_RST));
482 break;
483 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000485 /* After MAC reset, force reload of EEPROM to restore power-on settings
486 * to device. Later controllers reload the EEPROM automatically, so
487 * just wait for reload to complete.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700488 */
489 switch (hw->mac_type) {
490 case e1000_82542_rev2_0:
491 case e1000_82542_rev2_1:
492 case e1000_82543:
493 case e1000_82544:
494 /* Wait for reset to complete */
495 udelay(10);
496 ctrl_ext = er32(CTRL_EXT);
497 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
498 ew32(CTRL_EXT, ctrl_ext);
499 E1000_WRITE_FLUSH();
500 /* Wait for EEPROM reload */
501 msleep(2);
502 break;
503 case e1000_82541:
504 case e1000_82541_rev_2:
505 case e1000_82547:
506 case e1000_82547_rev_2:
507 /* Wait for EEPROM reload */
508 msleep(20);
509 break;
510 default:
511 /* Auto read done will delay 5ms or poll based on mac type */
512 ret_val = e1000_get_auto_rd_done(hw);
513 if (ret_val)
514 return ret_val;
515 break;
516 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700518 /* Disable HW ARPs on ASF enabled adapters */
519 if (hw->mac_type >= e1000_82540) {
520 manc = er32(MANC);
521 manc &= ~(E1000_MANC_ARP_EN);
522 ew32(MANC, manc);
523 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700525 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
526 e1000_phy_init_script(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700528 /* Configure activity LED after PHY reset */
529 led_ctrl = er32(LEDCTL);
530 led_ctrl &= IGP_ACTIVITY_LED_MASK;
531 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
532 ew32(LEDCTL, led_ctrl);
533 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700535 /* Clear interrupt mask to stop board from generating interrupts */
Emil Tantilov675ad472010-04-27 14:02:58 +0000536 e_dbg("Masking off all interrupts\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700537 ew32(IMC, 0xffffffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700539 /* Clear any pending interrupt events. */
540 icr = er32(ICR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700542 /* If MWI was previously enabled, reenable it. */
543 if (hw->mac_type == e1000_82542_rev2_0) {
544 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
545 e1000_pci_set_mwi(hw);
546 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700548 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549}
550
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700551/**
Ben Hutchings49ce9c22012-07-10 10:56:00 +0000552 * e1000_init_hw - Performs basic configuration of the adapter.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700553 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 *
555 * Assumes that the controller has previously been reset and is in a
556 * post-reset uninitialized state. Initializes the receive address registers,
557 * multicast table, and VLAN filter table. Calls routines to setup link
558 * configuration and flow control settings. Clears all on-chip counters. Leaves
559 * the transmit and receive units disabled and uninitialized.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700560 */
Joe Perches64798842008-07-11 15:17:02 -0700561s32 e1000_init_hw(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700563 u32 ctrl;
564 u32 i;
565 s32 ret_val;
566 u32 mta_size;
567 u32 ctrl_ext;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700568
Emil Tantilov675ad472010-04-27 14:02:58 +0000569 e_dbg("e1000_init_hw");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700571 /* Initialize Identification LED */
572 ret_val = e1000_id_led_init(hw);
573 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +0000574 e_dbg("Error Initializing Identification LED\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700575 return ret_val;
576 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700578 /* Set the media type and TBI compatibility */
579 e1000_set_media_type(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700581 /* Disabling VLAN filtering. */
Emil Tantilov675ad472010-04-27 14:02:58 +0000582 e_dbg("Initializing the IEEE VLAN\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700583 if (hw->mac_type < e1000_82545_rev_3)
584 ew32(VET, 0);
585 e1000_clear_vfta(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700587 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
588 if (hw->mac_type == e1000_82542_rev2_0) {
Emil Tantilov675ad472010-04-27 14:02:58 +0000589 e_dbg("Disabling MWI on 82542 rev 2.0\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700590 e1000_pci_clear_mwi(hw);
591 ew32(RCTL, E1000_RCTL_RST);
592 E1000_WRITE_FLUSH();
593 msleep(5);
594 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000596 /* Setup the receive address. This involves initializing all of the
597 * Receive Address Registers (RARs 0 - 15).
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700598 */
599 e1000_init_rx_addrs(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700601 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
602 if (hw->mac_type == e1000_82542_rev2_0) {
603 ew32(RCTL, 0);
604 E1000_WRITE_FLUSH();
605 msleep(1);
606 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
607 e1000_pci_set_mwi(hw);
608 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700610 /* Zero out the Multicast HASH table */
Emil Tantilov675ad472010-04-27 14:02:58 +0000611 e_dbg("Zeroing the MTA\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700612 mta_size = E1000_MC_TBL_SIZE;
613 for (i = 0; i < mta_size; i++) {
614 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
615 /* use write flush to prevent Memory Write Block (MWB) from
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000616 * occurring when accessing our register space
617 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700618 E1000_WRITE_FLUSH();
619 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700621 /* Set the PCI priority bit correctly in the CTRL register. This
622 * determines if the adapter gives priority to receives, or if it
623 * gives equal priority to transmits and receives. Valid only on
624 * 82542 and 82543 silicon.
625 */
626 if (hw->dma_fairness && hw->mac_type <= e1000_82543) {
627 ctrl = er32(CTRL);
628 ew32(CTRL, ctrl | E1000_CTRL_PRIOR);
629 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700631 switch (hw->mac_type) {
632 case e1000_82545_rev_3:
633 case e1000_82546_rev_3:
634 break;
635 default:
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000636 /* Workaround for PCI-X problem when BIOS sets MMRBC
637 * incorrectly.
638 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700639 if (hw->bus_type == e1000_bus_type_pcix
640 && e1000_pcix_get_mmrbc(hw) > 2048)
641 e1000_pcix_set_mmrbc(hw, 2048);
642 break;
643 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700645 /* Call a subroutine to configure the link and setup flow control. */
646 ret_val = e1000_setup_link(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700648 /* Set the transmit descriptor write-back policy */
649 if (hw->mac_type > e1000_82544) {
650 ctrl = er32(TXDCTL);
651 ctrl =
652 (ctrl & ~E1000_TXDCTL_WTHRESH) |
653 E1000_TXDCTL_FULL_TX_DESC_WB;
654 ew32(TXDCTL, ctrl);
655 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700657 /* Clear all of the statistics registers (clear on read). It is
658 * important that we do this after we have tried to establish link
659 * because the symbol error count will increment wildly if there
660 * is no link.
661 */
662 e1000_clear_hw_cntrs(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700664 if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER ||
665 hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) {
666 ctrl_ext = er32(CTRL_EXT);
667 /* Relaxed ordering must be disabled to avoid a parity
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000668 * error crash in a PCI slot.
669 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700670 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
671 ew32(CTRL_EXT, ctrl_ext);
672 }
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -0800673
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700674 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675}
676
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700677/**
678 * e1000_adjust_serdes_amplitude - Adjust SERDES output amplitude based on EEPROM setting.
679 * @hw: Struct containing variables accessed by shared code.
680 */
Joe Perches64798842008-07-11 15:17:02 -0700681static s32 e1000_adjust_serdes_amplitude(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700683 u16 eeprom_data;
684 s32 ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685
Emil Tantilov675ad472010-04-27 14:02:58 +0000686 e_dbg("e1000_adjust_serdes_amplitude");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700688 if (hw->media_type != e1000_media_type_internal_serdes)
689 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700691 switch (hw->mac_type) {
692 case e1000_82545_rev_3:
693 case e1000_82546_rev_3:
694 break;
695 default:
696 return E1000_SUCCESS;
697 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700699 ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1,
700 &eeprom_data);
701 if (ret_val) {
702 return ret_val;
703 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700705 if (eeprom_data != EEPROM_RESERVED_WORD) {
706 /* Adjust SERDES output amplitude only. */
707 eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK;
708 ret_val =
709 e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data);
710 if (ret_val)
711 return ret_val;
712 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700714 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715}
716
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700717/**
718 * e1000_setup_link - Configures flow control and link settings.
719 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 *
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700721 * Determines which flow control settings to use. Calls the appropriate media-
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 * specific link configuration function. Configures the flow control settings.
723 * Assuming the adapter has a valid link partner, a valid link should be
724 * established. Assumes the hardware has previously been reset and the
725 * transmitter and receiver are not enabled.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700726 */
Joe Perches64798842008-07-11 15:17:02 -0700727s32 e1000_setup_link(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700729 u32 ctrl_ext;
730 s32 ret_val;
731 u16 eeprom_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732
Emil Tantilov675ad472010-04-27 14:02:58 +0000733 e_dbg("e1000_setup_link");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700735 /* Read and store word 0x0F of the EEPROM. This word contains bits
736 * that determine the hardware's default PAUSE (flow control) mode,
737 * a bit that determines whether the HW defaults to enabling or
738 * disabling auto-negotiation, and the direction of the
739 * SW defined pins. If there is no SW over-ride of the flow
740 * control setting, then the variable hw->fc will
741 * be initialized based on a value in the EEPROM.
742 */
743 if (hw->fc == E1000_FC_DEFAULT) {
744 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
745 1, &eeprom_data);
746 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +0000747 e_dbg("EEPROM Read Error\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700748 return -E1000_ERR_EEPROM;
749 }
750 if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
751 hw->fc = E1000_FC_NONE;
752 else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
753 EEPROM_WORD0F_ASM_DIR)
754 hw->fc = E1000_FC_TX_PAUSE;
755 else
756 hw->fc = E1000_FC_FULL;
757 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700759 /* We want to save off the original Flow Control configuration just
760 * in case we get disconnected and then reconnected into a different
761 * hub or switch with different Flow Control capabilities.
762 */
763 if (hw->mac_type == e1000_82542_rev2_0)
764 hw->fc &= (~E1000_FC_TX_PAUSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700766 if ((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
767 hw->fc &= (~E1000_FC_RX_PAUSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700769 hw->original_fc = hw->fc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770
Emil Tantilov675ad472010-04-27 14:02:58 +0000771 e_dbg("After fix-ups FlowControl is now = %x\n", hw->fc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700773 /* Take the 4 bits from EEPROM word 0x0F that determine the initial
774 * polarity value for the SW controlled pins, and setup the
775 * Extended Device Control reg with that info.
776 * This is needed because one of the SW controlled pins is used for
777 * signal detection. So this should be done before e1000_setup_pcs_link()
778 * or e1000_phy_setup() is called.
779 */
780 if (hw->mac_type == e1000_82543) {
781 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
782 1, &eeprom_data);
783 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +0000784 e_dbg("EEPROM Read Error\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700785 return -E1000_ERR_EEPROM;
786 }
787 ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
788 SWDPIO__EXT_SHIFT);
789 ew32(CTRL_EXT, ctrl_ext);
790 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700792 /* Call the necessary subroutine to configure the link. */
793 ret_val = (hw->media_type == e1000_media_type_copper) ?
794 e1000_setup_copper_link(hw) : e1000_setup_fiber_serdes_link(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700796 /* Initialize the flow control address, type, and PAUSE timer
797 * registers to their default values. This is done even if flow
798 * control is disabled, because it does not hurt anything to
799 * initialize these registers.
800 */
Emil Tantilov675ad472010-04-27 14:02:58 +0000801 e_dbg("Initializing the Flow Control address, type and timer regs\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700803 ew32(FCT, FLOW_CONTROL_TYPE);
804 ew32(FCAH, FLOW_CONTROL_ADDRESS_HIGH);
805 ew32(FCAL, FLOW_CONTROL_ADDRESS_LOW);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700806
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700807 ew32(FCTTV, hw->fc_pause_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700809 /* Set the flow control receive threshold registers. Normally,
810 * these registers will be set to a default threshold that may be
811 * adjusted later by the driver's runtime code. However, if the
812 * ability to transmit pause frames in not enabled, then these
813 * registers will be set to 0.
814 */
815 if (!(hw->fc & E1000_FC_TX_PAUSE)) {
816 ew32(FCRTL, 0);
817 ew32(FCRTH, 0);
818 } else {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000819 /* We need to set up the Receive Threshold high and low water
820 * marks as well as (optionally) enabling the transmission of
821 * XON frames.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700822 */
823 if (hw->fc_send_xon) {
824 ew32(FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE));
825 ew32(FCRTH, hw->fc_high_water);
826 } else {
827 ew32(FCRTL, hw->fc_low_water);
828 ew32(FCRTH, hw->fc_high_water);
829 }
830 }
831 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832}
833
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700834/**
835 * e1000_setup_fiber_serdes_link - prepare fiber or serdes link
836 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 *
838 * Manipulates Physical Coding Sublayer functions in order to configure
839 * link. Assumes the hardware has been previously reset and the transmitter
840 * and receiver are not enabled.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700841 */
Joe Perches64798842008-07-11 15:17:02 -0700842static s32 e1000_setup_fiber_serdes_link(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700844 u32 ctrl;
845 u32 status;
846 u32 txcw = 0;
847 u32 i;
848 u32 signal = 0;
849 s32 ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850
Emil Tantilov675ad472010-04-27 14:02:58 +0000851 e_dbg("e1000_setup_fiber_serdes_link");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700853 /* On adapters with a MAC newer than 82544, SWDP 1 will be
854 * set when the optics detect a signal. On older adapters, it will be
855 * cleared when there is a signal. This applies to fiber media only.
856 * If we're on serdes media, adjust the output amplitude to value
857 * set in the EEPROM.
858 */
859 ctrl = er32(CTRL);
860 if (hw->media_type == e1000_media_type_fiber)
861 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700863 ret_val = e1000_adjust_serdes_amplitude(hw);
864 if (ret_val)
865 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700867 /* Take the link out of reset */
868 ctrl &= ~(E1000_CTRL_LRST);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700870 /* Adjust VCO speed to improve BER performance */
871 ret_val = e1000_set_vco_speed(hw);
872 if (ret_val)
873 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700875 e1000_config_collision_dist(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700877 /* Check for a software override of the flow control settings, and setup
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000878 * the device accordingly. If auto-negotiation is enabled, then
879 * software will have to set the "PAUSE" bits to the correct value in
880 * the Tranmsit Config Word Register (TXCW) and re-start
881 * auto-negotiation. However, if auto-negotiation is disabled, then
882 * software will have to manually configure the two flow control enable
883 * bits in the CTRL register.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700884 *
885 * The possible values of the "fc" parameter are:
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000886 * 0: Flow control is completely disabled
887 * 1: Rx flow control is enabled (we can receive pause frames, but
888 * not send pause frames).
889 * 2: Tx flow control is enabled (we can send pause frames but we do
890 * not support receiving pause frames).
891 * 3: Both Rx and TX flow control (symmetric) are enabled.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700892 */
893 switch (hw->fc) {
894 case E1000_FC_NONE:
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000895 /* Flow ctrl is completely disabled by a software over-ride */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700896 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
897 break;
898 case E1000_FC_RX_PAUSE:
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000899 /* Rx Flow control is enabled and Tx Flow control is disabled by
900 * a software over-ride. Since there really isn't a way to
901 * advertise that we are capable of Rx Pause ONLY, we will
902 * advertise that we support both symmetric and asymmetric Rx
903 * PAUSE. Later, we will disable the adapter's ability to send
904 * PAUSE frames.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700905 */
906 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
907 break;
908 case E1000_FC_TX_PAUSE:
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000909 /* Tx Flow control is enabled, and Rx Flow control is disabled,
910 * by a software over-ride.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700911 */
912 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
913 break;
914 case E1000_FC_FULL:
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000915 /* Flow control (both Rx and Tx) is enabled by a software
916 * over-ride.
917 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700918 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
919 break;
920 default:
Emil Tantilov675ad472010-04-27 14:02:58 +0000921 e_dbg("Flow control param set incorrectly\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700922 return -E1000_ERR_CONFIG;
923 break;
924 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000926 /* Since auto-negotiation is enabled, take the link out of reset (the
927 * link will be in reset, because we previously reset the chip). This
928 * will restart auto-negotiation. If auto-negotiation is successful
929 * then the link-up status bit will be set and the flow control enable
930 * bits (RFCE and TFCE) will be set according to their negotiated value.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700931 */
Emil Tantilov675ad472010-04-27 14:02:58 +0000932 e_dbg("Auto-negotiation enabled\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700934 ew32(TXCW, txcw);
935 ew32(CTRL, ctrl);
936 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700938 hw->txcw = txcw;
939 msleep(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000941 /* If we have a signal (the cable is plugged in) then poll for a
942 * "Link-Up" indication in the Device Status Register. Time-out if a
943 * link isn't seen in 500 milliseconds seconds (Auto-negotiation should
944 * complete in less than 500 milliseconds even if the other end is doing
945 * it in SW). For internal serdes, we just assume a signal is present,
946 * then poll.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700947 */
948 if (hw->media_type == e1000_media_type_internal_serdes ||
949 (er32(CTRL) & E1000_CTRL_SWDPIN1) == signal) {
Emil Tantilov675ad472010-04-27 14:02:58 +0000950 e_dbg("Looking for Link\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700951 for (i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
952 msleep(10);
953 status = er32(STATUS);
954 if (status & E1000_STATUS_LU)
955 break;
956 }
957 if (i == (LINK_UP_TIMEOUT / 10)) {
Emil Tantilov675ad472010-04-27 14:02:58 +0000958 e_dbg("Never got a valid link from auto-neg!!!\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700959 hw->autoneg_failed = 1;
960 /* AutoNeg failed to achieve a link, so we'll call
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000961 * e1000_check_for_link. This routine will force the
962 * link up if we detect a signal. This will allow us to
963 * communicate with non-autonegotiating link partners.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700964 */
965 ret_val = e1000_check_for_link(hw);
966 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +0000967 e_dbg("Error while checking for link\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700968 return ret_val;
969 }
970 hw->autoneg_failed = 0;
971 } else {
972 hw->autoneg_failed = 0;
Emil Tantilov675ad472010-04-27 14:02:58 +0000973 e_dbg("Valid Link Found\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700974 }
975 } else {
Emil Tantilov675ad472010-04-27 14:02:58 +0000976 e_dbg("No Signal Detected\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700977 }
978 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979}
980
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700981/**
Dirk Brandewie5377a412011-01-06 14:29:54 +0000982 * e1000_copper_link_rtl_setup - Copper link setup for e1000_phy_rtl series.
983 * @hw: Struct containing variables accessed by shared code
984 *
985 * Commits changes to PHY configuration by calling e1000_phy_reset().
986 */
987static s32 e1000_copper_link_rtl_setup(struct e1000_hw *hw)
988{
989 s32 ret_val;
990
991 /* SW reset the PHY so all changes take effect */
992 ret_val = e1000_phy_reset(hw);
993 if (ret_val) {
994 e_dbg("Error Resetting the PHY\n");
995 return ret_val;
996 }
997
998 return E1000_SUCCESS;
999}
1000
1001static s32 gbe_dhg_phy_setup(struct e1000_hw *hw)
1002{
1003 s32 ret_val;
1004 u32 ctrl_aux;
1005
1006 switch (hw->phy_type) {
1007 case e1000_phy_8211:
1008 ret_val = e1000_copper_link_rtl_setup(hw);
1009 if (ret_val) {
1010 e_dbg("e1000_copper_link_rtl_setup failed!\n");
1011 return ret_val;
1012 }
1013 break;
1014 case e1000_phy_8201:
1015 /* Set RMII mode */
1016 ctrl_aux = er32(CTL_AUX);
1017 ctrl_aux |= E1000_CTL_AUX_RMII;
1018 ew32(CTL_AUX, ctrl_aux);
1019 E1000_WRITE_FLUSH();
1020
1021 /* Disable the J/K bits required for receive */
1022 ctrl_aux = er32(CTL_AUX);
1023 ctrl_aux |= 0x4;
1024 ctrl_aux &= ~0x2;
1025 ew32(CTL_AUX, ctrl_aux);
1026 E1000_WRITE_FLUSH();
1027 ret_val = e1000_copper_link_rtl_setup(hw);
1028
1029 if (ret_val) {
1030 e_dbg("e1000_copper_link_rtl_setup failed!\n");
1031 return ret_val;
1032 }
1033 break;
1034 default:
1035 e_dbg("Error Resetting the PHY\n");
1036 return E1000_ERR_PHY_TYPE;
1037 }
1038
1039 return E1000_SUCCESS;
1040}
1041
1042/**
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001043 * e1000_copper_link_preconfig - early configuration for copper
1044 * @hw: Struct containing variables accessed by shared code
1045 *
1046 * Make sure we have a valid PHY and change PHY mode before link setup.
1047 */
Joe Perches64798842008-07-11 15:17:02 -07001048static s32 e1000_copper_link_preconfig(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001050 u32 ctrl;
1051 s32 ret_val;
1052 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053
Emil Tantilov675ad472010-04-27 14:02:58 +00001054 e_dbg("e1000_copper_link_preconfig");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001056 ctrl = er32(CTRL);
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001057 /* With 82543, we need to force speed and duplex on the MAC equal to
1058 * what the PHY speed and duplex configuration is. In addition, we need
1059 * to perform a hardware reset on the PHY to take it out of reset.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001060 */
1061 if (hw->mac_type > e1000_82543) {
1062 ctrl |= E1000_CTRL_SLU;
1063 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1064 ew32(CTRL, ctrl);
1065 } else {
1066 ctrl |=
1067 (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
1068 ew32(CTRL, ctrl);
1069 ret_val = e1000_phy_hw_reset(hw);
1070 if (ret_val)
1071 return ret_val;
1072 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001074 /* Make sure we have a valid PHY */
1075 ret_val = e1000_detect_gig_phy(hw);
1076 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00001077 e_dbg("Error, did not detect valid phy.\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001078 return ret_val;
1079 }
Emil Tantilov675ad472010-04-27 14:02:58 +00001080 e_dbg("Phy ID = %x\n", hw->phy_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001082 /* Set PHY to class A mode (if necessary) */
1083 ret_val = e1000_set_phy_mode(hw);
1084 if (ret_val)
1085 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001087 if ((hw->mac_type == e1000_82545_rev_3) ||
1088 (hw->mac_type == e1000_82546_rev_3)) {
1089 ret_val =
1090 e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1091 phy_data |= 0x00000008;
1092 ret_val =
1093 e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1094 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001096 if (hw->mac_type <= e1000_82543 ||
1097 hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
1098 hw->mac_type == e1000_82541_rev_2
1099 || hw->mac_type == e1000_82547_rev_2)
1100 hw->phy_reset_disable = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001102 return E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001103}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001105/**
1106 * e1000_copper_link_igp_setup - Copper link setup for e1000_phy_igp series.
1107 * @hw: Struct containing variables accessed by shared code
1108 */
Joe Perches64798842008-07-11 15:17:02 -07001109static s32 e1000_copper_link_igp_setup(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001110{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001111 u32 led_ctrl;
1112 s32 ret_val;
1113 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114
Emil Tantilov675ad472010-04-27 14:02:58 +00001115 e_dbg("e1000_copper_link_igp_setup");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001117 if (hw->phy_reset_disable)
1118 return E1000_SUCCESS;
Auke Kok76c224b2006-05-23 13:36:06 -07001119
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001120 ret_val = e1000_phy_reset(hw);
1121 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00001122 e_dbg("Error Resetting the PHY\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001123 return ret_val;
1124 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001126 /* Wait 15ms for MAC to configure PHY from eeprom settings */
1127 msleep(15);
1128 /* Configure activity LED after PHY reset */
1129 led_ctrl = er32(LEDCTL);
1130 led_ctrl &= IGP_ACTIVITY_LED_MASK;
1131 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
1132 ew32(LEDCTL, led_ctrl);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001133
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001134 /* The NVM settings will configure LPLU in D3 for IGP2 and IGP3 PHYs */
1135 if (hw->phy_type == e1000_phy_igp) {
1136 /* disable lplu d3 during driver init */
1137 ret_val = e1000_set_d3_lplu_state(hw, false);
1138 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00001139 e_dbg("Error Disabling LPLU D3\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001140 return ret_val;
1141 }
1142 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001143
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001144 /* Configure mdi-mdix settings */
1145 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1146 if (ret_val)
1147 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001148
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001149 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
1150 hw->dsp_config_state = e1000_dsp_config_disabled;
1151 /* Force MDI for earlier revs of the IGP PHY */
1152 phy_data &=
1153 ~(IGP01E1000_PSCR_AUTO_MDIX |
1154 IGP01E1000_PSCR_FORCE_MDI_MDIX);
1155 hw->mdix = 1;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001156
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001157 } else {
1158 hw->dsp_config_state = e1000_dsp_config_enabled;
1159 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001160
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001161 switch (hw->mdix) {
1162 case 1:
1163 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1164 break;
1165 case 2:
1166 phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
1167 break;
1168 case 0:
1169 default:
1170 phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
1171 break;
1172 }
1173 }
1174 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1175 if (ret_val)
1176 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001177
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001178 /* set auto-master slave resolution settings */
1179 if (hw->autoneg) {
1180 e1000_ms_type phy_ms_setting = hw->master_slave;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001181
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001182 if (hw->ffe_config_state == e1000_ffe_config_active)
1183 hw->ffe_config_state = e1000_ffe_config_enabled;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001184
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001185 if (hw->dsp_config_state == e1000_dsp_config_activated)
1186 hw->dsp_config_state = e1000_dsp_config_enabled;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001187
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001188 /* when autonegotiation advertisement is only 1000Mbps then we
1189 * should disable SmartSpeed and enable Auto MasterSlave
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001190 * resolution as hardware default.
1191 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001192 if (hw->autoneg_advertised == ADVERTISE_1000_FULL) {
1193 /* Disable SmartSpeed */
1194 ret_val =
1195 e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1196 &phy_data);
1197 if (ret_val)
1198 return ret_val;
1199 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1200 ret_val =
1201 e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1202 phy_data);
1203 if (ret_val)
1204 return ret_val;
1205 /* Set auto Master/Slave resolution process */
1206 ret_val =
1207 e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1208 if (ret_val)
1209 return ret_val;
1210 phy_data &= ~CR_1000T_MS_ENABLE;
1211 ret_val =
1212 e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1213 if (ret_val)
1214 return ret_val;
1215 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001217 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1218 if (ret_val)
1219 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001221 /* load defaults for future use */
1222 hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
1223 ((phy_data & CR_1000T_MS_VALUE) ?
1224 e1000_ms_force_master :
1225 e1000_ms_force_slave) : e1000_ms_auto;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001227 switch (phy_ms_setting) {
1228 case e1000_ms_force_master:
1229 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
1230 break;
1231 case e1000_ms_force_slave:
1232 phy_data |= CR_1000T_MS_ENABLE;
1233 phy_data &= ~(CR_1000T_MS_VALUE);
1234 break;
1235 case e1000_ms_auto:
1236 phy_data &= ~CR_1000T_MS_ENABLE;
1237 default:
1238 break;
1239 }
1240 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1241 if (ret_val)
1242 return ret_val;
1243 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001245 return E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001246}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001248/**
1249 * e1000_copper_link_mgp_setup - Copper link setup for e1000_phy_m88 series.
1250 * @hw: Struct containing variables accessed by shared code
1251 */
Joe Perches64798842008-07-11 15:17:02 -07001252static s32 e1000_copper_link_mgp_setup(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001253{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001254 s32 ret_val;
1255 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256
Emil Tantilov675ad472010-04-27 14:02:58 +00001257 e_dbg("e1000_copper_link_mgp_setup");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001258
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001259 if (hw->phy_reset_disable)
1260 return E1000_SUCCESS;
Auke Kok76c224b2006-05-23 13:36:06 -07001261
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001262 /* Enable CRS on TX. This must be set for half-duplex operation. */
1263 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1264 if (ret_val)
1265 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001266
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001267 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001268
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001269 /* Options:
1270 * MDI/MDI-X = 0 (default)
1271 * 0 - Auto for all speeds
1272 * 1 - MDI mode
1273 * 2 - MDI-X mode
1274 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1275 */
1276 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001277
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001278 switch (hw->mdix) {
1279 case 1:
1280 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
1281 break;
1282 case 2:
1283 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
1284 break;
1285 case 3:
1286 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
1287 break;
1288 case 0:
1289 default:
1290 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
1291 break;
1292 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001293
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001294 /* Options:
1295 * disable_polarity_correction = 0 (default)
1296 * Automatic Correction for Reversed Cable Polarity
1297 * 0 - Disabled
1298 * 1 - Enabled
1299 */
1300 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
1301 if (hw->disable_polarity_correction == 1)
1302 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
1303 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1304 if (ret_val)
1305 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001306
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001307 if (hw->phy_revision < M88E1011_I_REV_4) {
1308 /* Force TX_CLK in the Extended PHY Specific Control Register
1309 * to 25MHz clock.
1310 */
1311 ret_val =
1312 e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
1313 &phy_data);
1314 if (ret_val)
1315 return ret_val;
Auke Kokee040222006-06-27 09:08:03 -07001316
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001317 phy_data |= M88E1000_EPSCR_TX_CLK_25;
Auke Kokee040222006-06-27 09:08:03 -07001318
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001319 if ((hw->phy_revision == E1000_REVISION_2) &&
1320 (hw->phy_id == M88E1111_I_PHY_ID)) {
1321 /* Vidalia Phy, set the downshift counter to 5x */
1322 phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK);
1323 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
1324 ret_val = e1000_write_phy_reg(hw,
1325 M88E1000_EXT_PHY_SPEC_CTRL,
1326 phy_data);
1327 if (ret_val)
1328 return ret_val;
1329 } else {
1330 /* Configure Master and Slave downshift values */
1331 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
1332 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
1333 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
1334 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
1335 ret_val = e1000_write_phy_reg(hw,
1336 M88E1000_EXT_PHY_SPEC_CTRL,
1337 phy_data);
1338 if (ret_val)
1339 return ret_val;
1340 }
1341 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001343 /* SW Reset the PHY so all changes take effect */
1344 ret_val = e1000_phy_reset(hw);
1345 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00001346 e_dbg("Error Resetting the PHY\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001347 return ret_val;
1348 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001349
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001350 return E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001351}
1352
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001353/**
1354 * e1000_copper_link_autoneg - setup auto-neg
1355 * @hw: Struct containing variables accessed by shared code
1356 *
1357 * Setup auto-negotiation and flow control advertisements,
1358 * and then perform auto-negotiation.
1359 */
Joe Perches64798842008-07-11 15:17:02 -07001360static s32 e1000_copper_link_autoneg(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001361{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001362 s32 ret_val;
1363 u16 phy_data;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001364
Emil Tantilov675ad472010-04-27 14:02:58 +00001365 e_dbg("e1000_copper_link_autoneg");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001366
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001367 /* Perform some bounds checking on the hw->autoneg_advertised
1368 * parameter. If this variable is zero, then set it to the default.
1369 */
1370 hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001371
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001372 /* If autoneg_advertised is zero, we assume it was not defaulted
1373 * by the calling code so we set to advertise full capability.
1374 */
1375 if (hw->autoneg_advertised == 0)
1376 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001377
Dirk Brandewie5377a412011-01-06 14:29:54 +00001378 /* IFE/RTL8201N PHY only supports 10/100 */
1379 if (hw->phy_type == e1000_phy_8201)
1380 hw->autoneg_advertised &= AUTONEG_ADVERTISE_10_100_ALL;
1381
Emil Tantilov675ad472010-04-27 14:02:58 +00001382 e_dbg("Reconfiguring auto-neg advertisement params\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001383 ret_val = e1000_phy_setup_autoneg(hw);
1384 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00001385 e_dbg("Error Setting up Auto-Negotiation\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001386 return ret_val;
1387 }
Emil Tantilov675ad472010-04-27 14:02:58 +00001388 e_dbg("Restarting Auto-Neg\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001389
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001390 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
1391 * the Auto Neg Restart bit in the PHY control register.
1392 */
1393 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
1394 if (ret_val)
1395 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001396
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001397 phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
1398 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
1399 if (ret_val)
1400 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001401
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001402 /* Does the user want to wait for Auto-Neg to complete here, or
1403 * check at a later time (for example, callback routine).
1404 */
1405 if (hw->wait_autoneg_complete) {
1406 ret_val = e1000_wait_autoneg(hw);
1407 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00001408 e_dbg
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001409 ("Error while waiting for autoneg to complete\n");
1410 return ret_val;
1411 }
1412 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001414 hw->get_link_status = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001416 return E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001417}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001419/**
1420 * e1000_copper_link_postconfig - post link setup
1421 * @hw: Struct containing variables accessed by shared code
1422 *
1423 * Config the MAC and the PHY after link is up.
1424 * 1) Set up the MAC to the current PHY speed/duplex
1425 * if we are on 82543. If we
1426 * are on newer silicon, we only need to configure
1427 * collision distance in the Transmit Control Register.
1428 * 2) Set up flow control on the MAC to that established with
1429 * the link partner.
1430 * 3) Config DSP to improve Gigabit link quality for some PHY revisions.
1431 */
Joe Perches64798842008-07-11 15:17:02 -07001432static s32 e1000_copper_link_postconfig(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001433{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001434 s32 ret_val;
Emil Tantilov675ad472010-04-27 14:02:58 +00001435 e_dbg("e1000_copper_link_postconfig");
Auke Kok76c224b2006-05-23 13:36:06 -07001436
Dirk Brandewie5377a412011-01-06 14:29:54 +00001437 if ((hw->mac_type >= e1000_82544) && (hw->mac_type != e1000_ce4100)) {
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001438 e1000_config_collision_dist(hw);
1439 } else {
1440 ret_val = e1000_config_mac_to_phy(hw);
1441 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00001442 e_dbg("Error configuring MAC to PHY settings\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001443 return ret_val;
1444 }
1445 }
1446 ret_val = e1000_config_fc_after_link_up(hw);
1447 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00001448 e_dbg("Error Configuring Flow Control\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001449 return ret_val;
1450 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001451
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001452 /* Config DSP to improve Giga link quality */
1453 if (hw->phy_type == e1000_phy_igp) {
1454 ret_val = e1000_config_dsp_after_link_change(hw, true);
1455 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00001456 e_dbg("Error Configuring DSP after link up\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001457 return ret_val;
1458 }
1459 }
Auke Kok76c224b2006-05-23 13:36:06 -07001460
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001461 return E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001462}
1463
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001464/**
1465 * e1000_setup_copper_link - phy/speed/duplex setting
1466 * @hw: Struct containing variables accessed by shared code
1467 *
1468 * Detects which PHY is present and sets up the speed and duplex
1469 */
Joe Perches64798842008-07-11 15:17:02 -07001470static s32 e1000_setup_copper_link(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001471{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001472 s32 ret_val;
1473 u16 i;
1474 u16 phy_data;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001475
Emil Tantilov675ad472010-04-27 14:02:58 +00001476 e_dbg("e1000_setup_copper_link");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001477
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001478 /* Check if it is a valid PHY and set PHY mode if necessary. */
1479 ret_val = e1000_copper_link_preconfig(hw);
1480 if (ret_val)
1481 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001482
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001483 if (hw->phy_type == e1000_phy_igp) {
1484 ret_val = e1000_copper_link_igp_setup(hw);
1485 if (ret_val)
1486 return ret_val;
1487 } else if (hw->phy_type == e1000_phy_m88) {
1488 ret_val = e1000_copper_link_mgp_setup(hw);
1489 if (ret_val)
1490 return ret_val;
Dirk Brandewie5377a412011-01-06 14:29:54 +00001491 } else {
1492 ret_val = gbe_dhg_phy_setup(hw);
1493 if (ret_val) {
1494 e_dbg("gbe_dhg_phy_setup failed!\n");
1495 return ret_val;
1496 }
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001497 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001498
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001499 if (hw->autoneg) {
1500 /* Setup autoneg and flow control advertisement
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001501 * and perform autonegotiation
1502 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001503 ret_val = e1000_copper_link_autoneg(hw);
1504 if (ret_val)
1505 return ret_val;
1506 } else {
1507 /* PHY will be set to 10H, 10F, 100H,or 100F
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001508 * depending on value from forced_speed_duplex.
1509 */
Emil Tantilov675ad472010-04-27 14:02:58 +00001510 e_dbg("Forcing speed and duplex\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001511 ret_val = e1000_phy_force_speed_duplex(hw);
1512 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00001513 e_dbg("Error Forcing Speed and Duplex\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001514 return ret_val;
1515 }
1516 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001518 /* Check link status. Wait up to 100 microseconds for link to become
1519 * valid.
1520 */
1521 for (i = 0; i < 10; i++) {
1522 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
1523 if (ret_val)
1524 return ret_val;
1525 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
1526 if (ret_val)
1527 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001529 if (phy_data & MII_SR_LINK_STATUS) {
1530 /* Config the MAC and PHY after link is up */
1531 ret_val = e1000_copper_link_postconfig(hw);
1532 if (ret_val)
1533 return ret_val;
Auke Kok76c224b2006-05-23 13:36:06 -07001534
Emil Tantilov675ad472010-04-27 14:02:58 +00001535 e_dbg("Valid link established!!!\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001536 return E1000_SUCCESS;
1537 }
1538 udelay(10);
1539 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540
Emil Tantilov675ad472010-04-27 14:02:58 +00001541 e_dbg("Unable to establish link!!!\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001542 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543}
1544
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001545/**
1546 * e1000_phy_setup_autoneg - phy settings
1547 * @hw: Struct containing variables accessed by shared code
1548 *
1549 * Configures PHY autoneg and flow control advertisement settings
1550 */
Joe Perches64798842008-07-11 15:17:02 -07001551s32 e1000_phy_setup_autoneg(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001553 s32 ret_val;
1554 u16 mii_autoneg_adv_reg;
1555 u16 mii_1000t_ctrl_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556
Emil Tantilov675ad472010-04-27 14:02:58 +00001557 e_dbg("e1000_phy_setup_autoneg");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001559 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
1560 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
1561 if (ret_val)
1562 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001564 /* Read the MII 1000Base-T Control Register (Address 9). */
Dirk Brandewie5377a412011-01-06 14:29:54 +00001565 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001566 if (ret_val)
1567 return ret_val;
Dirk Brandewie5377a412011-01-06 14:29:54 +00001568 else if (hw->phy_type == e1000_phy_8201)
1569 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001571 /* Need to parse both autoneg_advertised and fc and set up
1572 * the appropriate PHY registers. First we will parse for
1573 * autoneg_advertised software override. Since we can advertise
1574 * a plethora of combinations, we need to check each bit
1575 * individually.
1576 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001578 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
1579 * Advertisement Register (Address 4) and the 1000 mb speed bits in
1580 * the 1000Base-T Control Register (Address 9).
1581 */
1582 mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
1583 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584
Emil Tantilov675ad472010-04-27 14:02:58 +00001585 e_dbg("autoneg_advertised %x\n", hw->autoneg_advertised);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001587 /* Do we want to advertise 10 Mb Half Duplex? */
1588 if (hw->autoneg_advertised & ADVERTISE_10_HALF) {
Emil Tantilov675ad472010-04-27 14:02:58 +00001589 e_dbg("Advertise 10mb Half duplex\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001590 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
1591 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001593 /* Do we want to advertise 10 Mb Full Duplex? */
1594 if (hw->autoneg_advertised & ADVERTISE_10_FULL) {
Emil Tantilov675ad472010-04-27 14:02:58 +00001595 e_dbg("Advertise 10mb Full duplex\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001596 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
1597 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001599 /* Do we want to advertise 100 Mb Half Duplex? */
1600 if (hw->autoneg_advertised & ADVERTISE_100_HALF) {
Emil Tantilov675ad472010-04-27 14:02:58 +00001601 e_dbg("Advertise 100mb Half duplex\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001602 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
1603 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001605 /* Do we want to advertise 100 Mb Full Duplex? */
1606 if (hw->autoneg_advertised & ADVERTISE_100_FULL) {
Emil Tantilov675ad472010-04-27 14:02:58 +00001607 e_dbg("Advertise 100mb Full duplex\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001608 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
1609 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001611 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
1612 if (hw->autoneg_advertised & ADVERTISE_1000_HALF) {
Emil Tantilov675ad472010-04-27 14:02:58 +00001613 e_dbg
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001614 ("Advertise 1000mb Half duplex requested, request denied!\n");
1615 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001617 /* Do we want to advertise 1000 Mb Full Duplex? */
1618 if (hw->autoneg_advertised & ADVERTISE_1000_FULL) {
Emil Tantilov675ad472010-04-27 14:02:58 +00001619 e_dbg("Advertise 1000mb Full duplex\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001620 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
1621 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001623 /* Check for a software override of the flow control settings, and
1624 * setup the PHY advertisement registers accordingly. If
1625 * auto-negotiation is enabled, then software will have to set the
1626 * "PAUSE" bits to the correct value in the Auto-Negotiation
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001627 * Advertisement Register (PHY_AUTONEG_ADV) and re-start
1628 * auto-negotiation.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001629 *
1630 * The possible values of the "fc" parameter are:
1631 * 0: Flow control is completely disabled
1632 * 1: Rx flow control is enabled (we can receive pause frames
1633 * but not send pause frames).
1634 * 2: Tx flow control is enabled (we can send pause frames
1635 * but we do not support receiving pause frames).
1636 * 3: Both Rx and TX flow control (symmetric) are enabled.
1637 * other: No software override. The flow control configuration
1638 * in the EEPROM is used.
1639 */
1640 switch (hw->fc) {
1641 case E1000_FC_NONE: /* 0 */
1642 /* Flow control (RX & TX) is completely disabled by a
1643 * software over-ride.
1644 */
1645 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1646 break;
1647 case E1000_FC_RX_PAUSE: /* 1 */
1648 /* RX Flow control is enabled, and TX Flow control is
1649 * disabled, by a software over-ride.
1650 */
1651 /* Since there really isn't a way to advertise that we are
1652 * capable of RX Pause ONLY, we will advertise that we
1653 * support both symmetric and asymmetric RX PAUSE. Later
1654 * (in e1000_config_fc_after_link_up) we will disable the
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001655 * hw's ability to send PAUSE frames.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001656 */
1657 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1658 break;
1659 case E1000_FC_TX_PAUSE: /* 2 */
1660 /* TX Flow control is enabled, and RX Flow control is
1661 * disabled, by a software over-ride.
1662 */
1663 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
1664 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
1665 break;
1666 case E1000_FC_FULL: /* 3 */
1667 /* Flow control (both RX and TX) is enabled by a software
1668 * over-ride.
1669 */
1670 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1671 break;
1672 default:
Emil Tantilov675ad472010-04-27 14:02:58 +00001673 e_dbg("Flow control param set incorrectly\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001674 return -E1000_ERR_CONFIG;
1675 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001677 ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
1678 if (ret_val)
1679 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680
Emil Tantilov675ad472010-04-27 14:02:58 +00001681 e_dbg("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682
Dirk Brandewie5377a412011-01-06 14:29:54 +00001683 if (hw->phy_type == e1000_phy_8201) {
1684 mii_1000t_ctrl_reg = 0;
1685 } else {
1686 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL,
1687 mii_1000t_ctrl_reg);
1688 if (ret_val)
1689 return ret_val;
1690 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001692 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693}
1694
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001695/**
1696 * e1000_phy_force_speed_duplex - force link settings
1697 * @hw: Struct containing variables accessed by shared code
1698 *
1699 * Force PHY speed and duplex settings to hw->forced_speed_duplex
1700 */
Joe Perches64798842008-07-11 15:17:02 -07001701static s32 e1000_phy_force_speed_duplex(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001703 u32 ctrl;
1704 s32 ret_val;
1705 u16 mii_ctrl_reg;
1706 u16 mii_status_reg;
1707 u16 phy_data;
1708 u16 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709
Emil Tantilov675ad472010-04-27 14:02:58 +00001710 e_dbg("e1000_phy_force_speed_duplex");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001712 /* Turn off Flow control if we are forcing speed and duplex. */
1713 hw->fc = E1000_FC_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714
Emil Tantilov675ad472010-04-27 14:02:58 +00001715 e_dbg("hw->fc = %d\n", hw->fc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001717 /* Read the Device Control Register. */
1718 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001720 /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */
1721 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1722 ctrl &= ~(DEVICE_SPEED_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001724 /* Clear the Auto Speed Detect Enable bit. */
1725 ctrl &= ~E1000_CTRL_ASDE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001727 /* Read the MII Control Register. */
1728 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg);
1729 if (ret_val)
1730 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001732 /* We need to disable autoneg in order to force link and duplex. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001734 mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001736 /* Are we forcing Full or Half Duplex? */
1737 if (hw->forced_speed_duplex == e1000_100_full ||
1738 hw->forced_speed_duplex == e1000_10_full) {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001739 /* We want to force full duplex so we SET the full duplex bits
1740 * in the Device and MII Control Registers.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001741 */
1742 ctrl |= E1000_CTRL_FD;
1743 mii_ctrl_reg |= MII_CR_FULL_DUPLEX;
Emil Tantilov675ad472010-04-27 14:02:58 +00001744 e_dbg("Full Duplex\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001745 } else {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001746 /* We want to force half duplex so we CLEAR the full duplex bits
1747 * in the Device and MII Control Registers.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001748 */
1749 ctrl &= ~E1000_CTRL_FD;
1750 mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX;
Emil Tantilov675ad472010-04-27 14:02:58 +00001751 e_dbg("Half Duplex\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001752 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001754 /* Are we forcing 100Mbps??? */
1755 if (hw->forced_speed_duplex == e1000_100_full ||
1756 hw->forced_speed_duplex == e1000_100_half) {
1757 /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */
1758 ctrl |= E1000_CTRL_SPD_100;
1759 mii_ctrl_reg |= MII_CR_SPEED_100;
1760 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
Emil Tantilov675ad472010-04-27 14:02:58 +00001761 e_dbg("Forcing 100mb ");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001762 } else {
1763 /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */
1764 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1765 mii_ctrl_reg |= MII_CR_SPEED_10;
1766 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
Emil Tantilov675ad472010-04-27 14:02:58 +00001767 e_dbg("Forcing 10mb ");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001768 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001770 e1000_config_collision_dist(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001772 /* Write the configured values back to the Device Control Reg. */
1773 ew32(CTRL, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001775 if (hw->phy_type == e1000_phy_m88) {
1776 ret_val =
1777 e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1778 if (ret_val)
1779 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001781 /* Clear Auto-Crossover to force MDI manually. M88E1000 requires
1782 * MDI forced whenever speed are duplex are forced.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001783 */
1784 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1785 ret_val =
1786 e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1787 if (ret_val)
1788 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789
Emil Tantilov675ad472010-04-27 14:02:58 +00001790 e_dbg("M88E1000 PSCR: %x\n", phy_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001792 /* Need to reset the PHY or these changes will be ignored */
1793 mii_ctrl_reg |= MII_CR_RESET;
Auke Kok90fb5132006-11-01 08:47:30 -08001794
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001795 /* Disable MDI-X support for 10/100 */
1796 } else {
1797 /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
1798 * forced whenever speed or duplex are forced.
1799 */
1800 ret_val =
1801 e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1802 if (ret_val)
1803 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001805 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1806 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001808 ret_val =
1809 e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1810 if (ret_val)
1811 return ret_val;
1812 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001814 /* Write back the modified PHY MII control register. */
1815 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg);
1816 if (ret_val)
1817 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001819 udelay(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001821 /* The wait_autoneg_complete flag may be a little misleading here.
1822 * Since we are forcing speed and duplex, Auto-Neg is not enabled.
1823 * But we do want to delay for a period while forcing only so we
1824 * don't generate false No Link messages. So we will wait here
1825 * only if the user has set wait_autoneg_complete to 1, which is
1826 * the default.
1827 */
1828 if (hw->wait_autoneg_complete) {
1829 /* We will wait for autoneg to complete. */
Emil Tantilov675ad472010-04-27 14:02:58 +00001830 e_dbg("Waiting for forced speed/duplex link.\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001831 mii_status_reg = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001833 /* Wait for autoneg to complete or 4.5 seconds to expire */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001834 for (i = PHY_FORCE_TIME; i > 0; i--) {
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;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001848 if (mii_status_reg & MII_SR_LINK_STATUS)
1849 break;
1850 msleep(100);
1851 }
1852 if ((i == 0) && (hw->phy_type == e1000_phy_m88)) {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001853 /* We didn't get link. Reset the DSP and wait again
1854 * for link.
1855 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001856 ret_val = e1000_phy_reset_dsp(hw);
1857 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00001858 e_dbg("Error Resetting PHY DSP\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001859 return ret_val;
1860 }
1861 }
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001862 /* This loop will early-out if the link condition has been
1863 * met
1864 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001865 for (i = PHY_FORCE_TIME; i > 0; i--) {
1866 if (mii_status_reg & MII_SR_LINK_STATUS)
1867 break;
1868 msleep(100);
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001869 /* Read the MII Status Register and wait for Auto-Neg
1870 * Complete bit to be set.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001871 */
1872 ret_val =
1873 e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1874 if (ret_val)
1875 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001877 ret_val =
1878 e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1879 if (ret_val)
1880 return ret_val;
1881 }
1882 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001884 if (hw->phy_type == e1000_phy_m88) {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001885 /* Because we reset the PHY above, we need to re-force TX_CLK in
1886 * the Extended PHY Specific Control Register to 25MHz clock.
1887 * This value defaults back to a 2.5MHz clock when the PHY is
1888 * reset.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001889 */
1890 ret_val =
1891 e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
1892 &phy_data);
1893 if (ret_val)
1894 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001896 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1897 ret_val =
1898 e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
1899 phy_data);
1900 if (ret_val)
1901 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001903 /* In addition, because of the s/w reset above, we need to
1904 * enable CRS on Tx. This must be set for both full and half
1905 * duplex operation.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001906 */
1907 ret_val =
1908 e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1909 if (ret_val)
1910 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001912 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1913 ret_val =
1914 e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1915 if (ret_val)
1916 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001918 if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543)
1919 && (!hw->autoneg)
1920 && (hw->forced_speed_duplex == e1000_10_full
1921 || hw->forced_speed_duplex == e1000_10_half)) {
1922 ret_val = e1000_polarity_reversal_workaround(hw);
1923 if (ret_val)
1924 return ret_val;
1925 }
1926 }
1927 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928}
1929
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001930/**
1931 * e1000_config_collision_dist - set collision distance register
1932 * @hw: Struct containing variables accessed by shared code
1933 *
1934 * Sets the collision distance in the Transmit Control register.
1935 * Link should have been established previously. Reads the speed and duplex
1936 * information from the Device Status register.
1937 */
Joe Perches64798842008-07-11 15:17:02 -07001938void e1000_config_collision_dist(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001940 u32 tctl, coll_dist;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941
Emil Tantilov675ad472010-04-27 14:02:58 +00001942 e_dbg("e1000_config_collision_dist");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001944 if (hw->mac_type < e1000_82543)
1945 coll_dist = E1000_COLLISION_DISTANCE_82542;
1946 else
1947 coll_dist = E1000_COLLISION_DISTANCE;
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001948
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001949 tctl = er32(TCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001951 tctl &= ~E1000_TCTL_COLD;
1952 tctl |= coll_dist << E1000_COLD_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001953
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001954 ew32(TCTL, tctl);
1955 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956}
1957
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001958/**
1959 * e1000_config_mac_to_phy - sync phy and mac settings
1960 * @hw: Struct containing variables accessed by shared code
1961 * @mii_reg: data to write to the MII control register
1962 *
1963 * Sets MAC speed and duplex settings to reflect the those in the PHY
1964 * The contents of the PHY register containing the needed information need to
1965 * be passed in.
1966 */
Joe Perches64798842008-07-11 15:17:02 -07001967static s32 e1000_config_mac_to_phy(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001969 u32 ctrl;
1970 s32 ret_val;
1971 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972
Emil Tantilov675ad472010-04-27 14:02:58 +00001973 e_dbg("e1000_config_mac_to_phy");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001974
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001975 /* 82544 or newer MAC, Auto Speed Detection takes care of
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001976 * MAC speed/duplex configuration.
1977 */
Dirk Brandewie5377a412011-01-06 14:29:54 +00001978 if ((hw->mac_type >= e1000_82544) && (hw->mac_type != e1000_ce4100))
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001979 return E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001980
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001981 /* Read the Device Control Register and set the bits to Force Speed
1982 * and Duplex.
1983 */
1984 ctrl = er32(CTRL);
1985 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1986 ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001987
Dirk Brandewie5377a412011-01-06 14:29:54 +00001988 switch (hw->phy_type) {
1989 case e1000_phy_8201:
1990 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
1991 if (ret_val)
1992 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001993
Dirk Brandewie5377a412011-01-06 14:29:54 +00001994 if (phy_data & RTL_PHY_CTRL_FD)
1995 ctrl |= E1000_CTRL_FD;
1996 else
1997 ctrl &= ~E1000_CTRL_FD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998
Dirk Brandewie5377a412011-01-06 14:29:54 +00001999 if (phy_data & RTL_PHY_CTRL_SPD_100)
2000 ctrl |= E1000_CTRL_SPD_100;
2001 else
2002 ctrl |= E1000_CTRL_SPD_10;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003
Dirk Brandewie5377a412011-01-06 14:29:54 +00002004 e1000_config_collision_dist(hw);
2005 break;
2006 default:
2007 /* Set up duplex in the Device Control and Transmit Control
2008 * registers depending on negotiated values.
2009 */
2010 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002011 &phy_data);
Dirk Brandewie5377a412011-01-06 14:29:54 +00002012 if (ret_val)
2013 return ret_val;
2014
2015 if (phy_data & M88E1000_PSSR_DPLX)
2016 ctrl |= E1000_CTRL_FD;
2017 else
2018 ctrl &= ~E1000_CTRL_FD;
2019
2020 e1000_config_collision_dist(hw);
2021
2022 /* Set up speed in the Device Control register depending on
2023 * negotiated values.
2024 */
2025 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
2026 ctrl |= E1000_CTRL_SPD_1000;
2027 else if ((phy_data & M88E1000_PSSR_SPEED) ==
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002028 M88E1000_PSSR_100MBS)
Dirk Brandewie5377a412011-01-06 14:29:54 +00002029 ctrl |= E1000_CTRL_SPD_100;
2030 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002032 /* Write the configured values back to the Device Control Reg. */
2033 ew32(CTRL, ctrl);
2034 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035}
2036
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002037/**
2038 * e1000_force_mac_fc - force flow control settings
2039 * @hw: Struct containing variables accessed by shared code
2040 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041 * Forces the MAC's flow control settings.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042 * Sets the TFCE and RFCE bits in the device control register to reflect
2043 * the adapter settings. TFCE and RFCE need to be explicitly set by
2044 * software when a Copper PHY is used because autonegotiation is managed
2045 * by the PHY rather than the MAC. Software must also configure these
2046 * bits when link is forced on a fiber connection.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002047 */
Joe Perches64798842008-07-11 15:17:02 -07002048s32 e1000_force_mac_fc(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002050 u32 ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051
Emil Tantilov675ad472010-04-27 14:02:58 +00002052 e_dbg("e1000_force_mac_fc");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002054 /* Get the current configuration of the Device Control Register */
2055 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002057 /* Because we didn't get link via the internal auto-negotiation
2058 * mechanism (we either forced link or we got link via PHY
2059 * auto-neg), we have to manually enable/disable transmit an
2060 * receive flow control.
2061 *
2062 * The "Case" statement below enables/disable flow control
2063 * according to the "hw->fc" parameter.
2064 *
2065 * The possible values of the "fc" parameter are:
2066 * 0: Flow control is completely disabled
2067 * 1: Rx flow control is enabled (we can receive pause
2068 * frames but not send pause frames).
2069 * 2: Tx flow control is enabled (we can send pause frames
2070 * frames but we do not receive pause frames).
2071 * 3: Both Rx and TX flow control (symmetric) is enabled.
2072 * other: No other values should be possible at this point.
2073 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002075 switch (hw->fc) {
2076 case E1000_FC_NONE:
2077 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
2078 break;
2079 case E1000_FC_RX_PAUSE:
2080 ctrl &= (~E1000_CTRL_TFCE);
2081 ctrl |= E1000_CTRL_RFCE;
2082 break;
2083 case E1000_FC_TX_PAUSE:
2084 ctrl &= (~E1000_CTRL_RFCE);
2085 ctrl |= E1000_CTRL_TFCE;
2086 break;
2087 case E1000_FC_FULL:
2088 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
2089 break;
2090 default:
Emil Tantilov675ad472010-04-27 14:02:58 +00002091 e_dbg("Flow control param set incorrectly\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002092 return -E1000_ERR_CONFIG;
2093 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002095 /* Disable TX Flow Control for 82542 (rev 2.0) */
2096 if (hw->mac_type == e1000_82542_rev2_0)
2097 ctrl &= (~E1000_CTRL_TFCE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002099 ew32(CTRL, ctrl);
2100 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101}
2102
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002103/**
2104 * e1000_config_fc_after_link_up - configure flow control after autoneg
2105 * @hw: Struct containing variables accessed by shared code
2106 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107 * Configures flow control settings after link is established
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108 * Should be called immediately after a valid link has been established.
2109 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
2110 * and autonegotiation is enabled, the MAC flow control settings will be set
2111 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002112 * and RFCE bits will be automatically set to the negotiated flow control mode.
2113 */
Joe Perches64798842008-07-11 15:17:02 -07002114static s32 e1000_config_fc_after_link_up(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002116 s32 ret_val;
2117 u16 mii_status_reg;
2118 u16 mii_nway_adv_reg;
2119 u16 mii_nway_lp_ability_reg;
2120 u16 speed;
2121 u16 duplex;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122
Emil Tantilov675ad472010-04-27 14:02:58 +00002123 e_dbg("e1000_config_fc_after_link_up");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002125 /* Check for the case where we have fiber media and auto-neg failed
2126 * so we had to force link. In this case, we need to force the
2127 * configuration of the MAC to match the "fc" parameter.
2128 */
2129 if (((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed))
2130 || ((hw->media_type == e1000_media_type_internal_serdes)
2131 && (hw->autoneg_failed))
2132 || ((hw->media_type == e1000_media_type_copper)
2133 && (!hw->autoneg))) {
2134 ret_val = e1000_force_mac_fc(hw);
2135 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00002136 e_dbg("Error forcing flow control settings\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002137 return ret_val;
2138 }
2139 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002141 /* Check for the case where we have copper media and auto-neg is
2142 * enabled. In this case, we need to check and see if Auto-Neg
2143 * has completed, and if so, how the PHY and link partner has
2144 * flow control configured.
2145 */
2146 if ((hw->media_type == e1000_media_type_copper) && hw->autoneg) {
2147 /* Read the MII Status Register and check to see if AutoNeg
2148 * has completed. We read this twice because this reg has
2149 * some "sticky" (latched) bits.
2150 */
2151 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2152 if (ret_val)
2153 return ret_val;
2154 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2155 if (ret_val)
2156 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002158 if (mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
2159 /* The AutoNeg process has completed, so we now need to
2160 * read both the Auto Negotiation Advertisement Register
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002161 * (Address 4) and the Auto_Negotiation Base Page
2162 * Ability Register (Address 5) to determine how flow
2163 * control was negotiated.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002164 */
2165 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV,
2166 &mii_nway_adv_reg);
2167 if (ret_val)
2168 return ret_val;
2169 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY,
2170 &mii_nway_lp_ability_reg);
2171 if (ret_val)
2172 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002174 /* Two bits in the Auto Negotiation Advertisement
2175 * Register (Address 4) and two bits in the Auto
2176 * Negotiation Base Page Ability Register (Address 5)
2177 * determine flow control for both the PHY and the link
2178 * partner. The following table, taken out of the IEEE
2179 * 802.3ab/D6.0 dated March 25, 1999, describes these
2180 * PAUSE resolution bits and how flow control is
2181 * determined based upon these settings.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002182 * NOTE: DC = Don't Care
2183 *
2184 * LOCAL DEVICE | LINK PARTNER
2185 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002186 *-------|---------|-------|---------|------------------
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002187 * 0 | 0 | DC | DC | E1000_FC_NONE
2188 * 0 | 1 | 0 | DC | E1000_FC_NONE
2189 * 0 | 1 | 1 | 0 | E1000_FC_NONE
2190 * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
2191 * 1 | 0 | 0 | DC | E1000_FC_NONE
2192 * 1 | DC | 1 | DC | E1000_FC_FULL
2193 * 1 | 1 | 0 | 0 | E1000_FC_NONE
2194 * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
2195 *
2196 */
2197 /* Are both PAUSE bits set to 1? If so, this implies
2198 * Symmetric Flow Control is enabled at both ends. The
2199 * ASM_DIR bits are irrelevant per the spec.
2200 *
2201 * For Symmetric Flow Control:
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 | DC | 1 | DC | E1000_FC_FULL
2207 *
2208 */
2209 if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2210 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002211 /* Now we need to check if the user selected Rx
2212 * ONLY of pause frames. In this case, we had
2213 * to advertise FULL flow control because we
2214 * could not advertise Rx ONLY. Hence, we must
2215 * now check to see if we need to turn OFF the
2216 * TRANSMISSION of PAUSE frames.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002217 */
2218 if (hw->original_fc == E1000_FC_FULL) {
2219 hw->fc = E1000_FC_FULL;
Emil Tantilov675ad472010-04-27 14:02:58 +00002220 e_dbg("Flow Control = FULL.\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002221 } else {
2222 hw->fc = E1000_FC_RX_PAUSE;
Emil Tantilov675ad472010-04-27 14:02:58 +00002223 e_dbg
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002224 ("Flow Control = RX PAUSE frames only.\n");
2225 }
2226 }
2227 /* For receiving PAUSE frames ONLY.
2228 *
2229 * LOCAL DEVICE | LINK PARTNER
2230 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002231 *-------|---------|-------|---------|------------------
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002232 * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
2233 *
2234 */
2235 else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2236 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2237 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2238 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR))
2239 {
2240 hw->fc = E1000_FC_TX_PAUSE;
Emil Tantilov675ad472010-04-27 14:02:58 +00002241 e_dbg
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002242 ("Flow Control = TX PAUSE frames only.\n");
2243 }
2244 /* For transmitting PAUSE frames ONLY.
2245 *
2246 * LOCAL DEVICE | LINK PARTNER
2247 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002248 *-------|---------|-------|---------|------------------
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002249 * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
2250 *
2251 */
2252 else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2253 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2254 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2255 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR))
2256 {
2257 hw->fc = E1000_FC_RX_PAUSE;
Emil Tantilov675ad472010-04-27 14:02:58 +00002258 e_dbg
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002259 ("Flow Control = RX PAUSE frames only.\n");
2260 }
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002261 /* Per the IEEE spec, at this point flow control should
2262 * be disabled. However, we want to consider that we
2263 * could be connected to a legacy switch that doesn't
2264 * advertise desired flow control, but can be forced on
2265 * the link partner. So if we advertised no flow
2266 * control, that is what we will resolve to. If we
2267 * advertised some kind of receive capability (Rx Pause
2268 * Only or Full Flow Control) and the link partner
2269 * advertised none, we will configure ourselves to
2270 * enable Rx Flow Control only. We can do this safely
2271 * for two reasons: If the link partner really
2272 * didn't want flow control enabled, and we enable Rx,
2273 * no harm done since we won't be receiving any PAUSE
2274 * frames anyway. If the intent on the link partner was
2275 * to have flow control enabled, then by us enabling Rx
2276 * only, we can at least receive pause frames and
2277 * process them. This is a good idea because in most
2278 * cases, since we are predominantly a server NIC, more
2279 * times than not we will be asked to delay transmission
2280 * of packets than asking our link partner to pause
2281 * transmission of frames.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002282 */
2283 else if ((hw->original_fc == E1000_FC_NONE ||
2284 hw->original_fc == E1000_FC_TX_PAUSE) ||
2285 hw->fc_strict_ieee) {
2286 hw->fc = E1000_FC_NONE;
Emil Tantilov675ad472010-04-27 14:02:58 +00002287 e_dbg("Flow Control = NONE.\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002288 } else {
2289 hw->fc = E1000_FC_RX_PAUSE;
Emil Tantilov675ad472010-04-27 14:02:58 +00002290 e_dbg
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002291 ("Flow Control = RX PAUSE frames only.\n");
2292 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002294 /* Now we need to do one last check... If we auto-
2295 * negotiated to HALF DUPLEX, flow control should not be
2296 * enabled per IEEE 802.3 spec.
2297 */
2298 ret_val =
2299 e1000_get_speed_and_duplex(hw, &speed, &duplex);
2300 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00002301 e_dbg
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002302 ("Error getting link speed and duplex\n");
2303 return ret_val;
2304 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002306 if (duplex == HALF_DUPLEX)
2307 hw->fc = E1000_FC_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002309 /* Now we call a subroutine to actually force the MAC
2310 * controller to use the correct flow control settings.
2311 */
2312 ret_val = e1000_force_mac_fc(hw);
2313 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00002314 e_dbg
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002315 ("Error forcing flow control settings\n");
2316 return ret_val;
2317 }
2318 } else {
Emil Tantilov675ad472010-04-27 14:02:58 +00002319 e_dbg
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002320 ("Copper PHY and Auto Neg has not completed.\n");
2321 }
2322 }
2323 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324}
2325
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002326/**
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002327 * e1000_check_for_serdes_link_generic - Check for link (Serdes)
2328 * @hw: pointer to the HW structure
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002329 *
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002330 * Checks for link up on the hardware. If link is not up and we have
2331 * a signal, then we need to force link up.
2332 */
Jesse Brandeburg11b7f7b2009-09-25 12:20:33 +00002333static s32 e1000_check_for_serdes_link_generic(struct e1000_hw *hw)
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002334{
2335 u32 rxcw;
2336 u32 ctrl;
2337 u32 status;
2338 s32 ret_val = E1000_SUCCESS;
2339
Emil Tantilov675ad472010-04-27 14:02:58 +00002340 e_dbg("e1000_check_for_serdes_link_generic");
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002341
2342 ctrl = er32(CTRL);
2343 status = er32(STATUS);
2344 rxcw = er32(RXCW);
2345
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002346 /* If we don't have link (auto-negotiation failed or link partner
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002347 * cannot auto-negotiate), and our link partner is not trying to
2348 * auto-negotiate with us (we are receiving idles or data),
2349 * we need to force link up. We also need to give auto-negotiation
2350 * time to complete.
2351 */
2352 /* (ctrl & E1000_CTRL_SWDPIN1) == 1 == have signal */
2353 if ((!(status & E1000_STATUS_LU)) && (!(rxcw & E1000_RXCW_C))) {
2354 if (hw->autoneg_failed == 0) {
2355 hw->autoneg_failed = 1;
2356 goto out;
2357 }
Emil Tantilov675ad472010-04-27 14:02:58 +00002358 e_dbg("NOT RXing /C/, disable AutoNeg and force link.\n");
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002359
2360 /* Disable auto-negotiation in the TXCW register */
2361 ew32(TXCW, (hw->txcw & ~E1000_TXCW_ANE));
2362
2363 /* Force link-up and also force full-duplex. */
2364 ctrl = er32(CTRL);
2365 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
2366 ew32(CTRL, ctrl);
2367
2368 /* Configure Flow Control after forcing link up. */
2369 ret_val = e1000_config_fc_after_link_up(hw);
2370 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00002371 e_dbg("Error configuring flow control\n");
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002372 goto out;
2373 }
2374 } else if ((ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002375 /* If we are forcing link and we are receiving /C/ ordered
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002376 * sets, re-enable auto-negotiation in the TXCW register
2377 * and disable forced link in the Device Control register
2378 * in an attempt to auto-negotiate with our link partner.
2379 */
Emil Tantilov675ad472010-04-27 14:02:58 +00002380 e_dbg("RXing /C/, enable AutoNeg and stop forcing link.\n");
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002381 ew32(TXCW, hw->txcw);
2382 ew32(CTRL, (ctrl & ~E1000_CTRL_SLU));
2383
2384 hw->serdes_has_link = true;
2385 } else if (!(E1000_TXCW_ANE & er32(TXCW))) {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002386 /* If we force link for non-auto-negotiation switch, check
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002387 * link status based on MAC synchronization for internal
2388 * serdes media type.
2389 */
2390 /* SYNCH bit and IV bit are sticky. */
2391 udelay(10);
2392 rxcw = er32(RXCW);
2393 if (rxcw & E1000_RXCW_SYNCH) {
2394 if (!(rxcw & E1000_RXCW_IV)) {
2395 hw->serdes_has_link = true;
Emil Tantilov675ad472010-04-27 14:02:58 +00002396 e_dbg("SERDES: Link up - forced.\n");
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002397 }
2398 } else {
2399 hw->serdes_has_link = false;
Emil Tantilov675ad472010-04-27 14:02:58 +00002400 e_dbg("SERDES: Link down - force failed.\n");
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002401 }
2402 }
2403
2404 if (E1000_TXCW_ANE & er32(TXCW)) {
2405 status = er32(STATUS);
2406 if (status & E1000_STATUS_LU) {
2407 /* SYNCH bit and IV bit are sticky, so reread rxcw. */
2408 udelay(10);
2409 rxcw = er32(RXCW);
2410 if (rxcw & E1000_RXCW_SYNCH) {
2411 if (!(rxcw & E1000_RXCW_IV)) {
2412 hw->serdes_has_link = true;
Emil Tantilov675ad472010-04-27 14:02:58 +00002413 e_dbg("SERDES: Link up - autoneg "
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002414 "completed successfully.\n");
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002415 } else {
2416 hw->serdes_has_link = false;
Emil Tantilov675ad472010-04-27 14:02:58 +00002417 e_dbg("SERDES: Link down - invalid"
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002418 "codewords detected in autoneg.\n");
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002419 }
2420 } else {
2421 hw->serdes_has_link = false;
Emil Tantilov675ad472010-04-27 14:02:58 +00002422 e_dbg("SERDES: Link down - no sync.\n");
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002423 }
2424 } else {
2425 hw->serdes_has_link = false;
Emil Tantilov675ad472010-04-27 14:02:58 +00002426 e_dbg("SERDES: Link down - autoneg failed\n");
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002427 }
2428 }
2429
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002430 out:
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002431 return ret_val;
2432}
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002433
2434/**
2435 * e1000_check_for_link
2436 * @hw: Struct containing variables accessed by shared code
2437 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438 * Checks to see if the link status of the hardware has changed.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439 * Called by any function that needs to check the link status of the adapter.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002440 */
Joe Perches64798842008-07-11 15:17:02 -07002441s32 e1000_check_for_link(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002443 u32 rxcw = 0;
2444 u32 ctrl;
2445 u32 status;
2446 u32 rctl;
2447 u32 icr;
2448 u32 signal = 0;
2449 s32 ret_val;
2450 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002451
Emil Tantilov675ad472010-04-27 14:02:58 +00002452 e_dbg("e1000_check_for_link");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002454 ctrl = er32(CTRL);
2455 status = er32(STATUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002457 /* On adapters with a MAC newer than 82544, SW Definable pin 1 will be
2458 * set when the optics detect a signal. On older adapters, it will be
2459 * cleared when there is a signal. This applies to fiber media only.
2460 */
2461 if ((hw->media_type == e1000_media_type_fiber) ||
2462 (hw->media_type == e1000_media_type_internal_serdes)) {
2463 rxcw = er32(RXCW);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002465 if (hw->media_type == e1000_media_type_fiber) {
2466 signal =
2467 (hw->mac_type >
2468 e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
2469 if (status & E1000_STATUS_LU)
2470 hw->get_link_status = false;
2471 }
2472 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002474 /* If we have a copper PHY then we only want to go out to the PHY
2475 * registers to see if Auto-Neg has completed and/or if our link
2476 * status has changed. The get_link_status flag will be set if we
2477 * receive a Link Status Change interrupt or we have Rx Sequence
2478 * Errors.
2479 */
2480 if ((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
2481 /* First we want to see if the MII Status Register reports
2482 * link. If so, then we want to get the current speed/duplex
2483 * of the PHY.
2484 * Read the register twice since the link bit is sticky.
2485 */
2486 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2487 if (ret_val)
2488 return ret_val;
2489 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2490 if (ret_val)
2491 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002493 if (phy_data & MII_SR_LINK_STATUS) {
2494 hw->get_link_status = false;
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002495 /* Check if there was DownShift, must be checked
2496 * immediately after link-up
2497 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002498 e1000_check_downshift(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002499
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002500 /* If we are on 82544 or 82543 silicon and speed/duplex
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002501 * are forced to 10H or 10F, then we will implement the
2502 * polarity reversal workaround. We disable interrupts
2503 * first, and upon returning, place the devices
2504 * interrupt state to its previous value except for the
2505 * link status change interrupt which will
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002506 * happen due to the execution of this workaround.
2507 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002509 if ((hw->mac_type == e1000_82544
2510 || hw->mac_type == e1000_82543) && (!hw->autoneg)
2511 && (hw->forced_speed_duplex == e1000_10_full
2512 || hw->forced_speed_duplex == e1000_10_half)) {
2513 ew32(IMC, 0xffffffff);
2514 ret_val =
2515 e1000_polarity_reversal_workaround(hw);
2516 icr = er32(ICR);
2517 ew32(ICS, (icr & ~E1000_ICS_LSC));
2518 ew32(IMS, IMS_ENABLE_MASK);
2519 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002521 } else {
2522 /* No link detected */
2523 e1000_config_dsp_after_link_change(hw, false);
2524 return 0;
2525 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002527 /* If we are forcing speed/duplex, then we simply return since
2528 * we have already determined whether we have link or not.
2529 */
2530 if (!hw->autoneg)
2531 return -E1000_ERR_CONFIG;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002533 /* optimize the dsp settings for the igp phy */
2534 e1000_config_dsp_after_link_change(hw, true);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002536 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
2537 * have Si on board that is 82544 or newer, Auto
2538 * Speed Detection takes care of MAC speed/duplex
2539 * configuration. So we only need to configure Collision
2540 * Distance in the MAC. Otherwise, we need to force
2541 * speed/duplex on the MAC to the current PHY speed/duplex
2542 * settings.
2543 */
Dirk Brandewie5377a412011-01-06 14:29:54 +00002544 if ((hw->mac_type >= e1000_82544) &&
2545 (hw->mac_type != e1000_ce4100))
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002546 e1000_config_collision_dist(hw);
2547 else {
2548 ret_val = e1000_config_mac_to_phy(hw);
2549 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00002550 e_dbg
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002551 ("Error configuring MAC to PHY settings\n");
2552 return ret_val;
2553 }
2554 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002556 /* Configure Flow Control now that Auto-Neg has completed.
2557 * First, we need to restore the desired flow control settings
2558 * because we may have had to re-autoneg with a different link
2559 * partner.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002560 */
2561 ret_val = e1000_config_fc_after_link_up(hw);
2562 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00002563 e_dbg("Error configuring flow control\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002564 return ret_val;
2565 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002567 /* At this point we know that we are on copper and we have
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002568 * auto-negotiated link. These are conditions for checking the
2569 * link partner capability register. We use the link speed to
2570 * determine if TBI compatibility needs to be turned on or off.
2571 * If the link is not at gigabit speed, then TBI compatibility
2572 * is not needed. If we are at gigabit speed, we turn on TBI
2573 * compatibility.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002574 */
2575 if (hw->tbi_compatibility_en) {
2576 u16 speed, duplex;
2577 ret_val =
2578 e1000_get_speed_and_duplex(hw, &speed, &duplex);
2579 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00002580 e_dbg
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002581 ("Error getting link speed and duplex\n");
2582 return ret_val;
2583 }
2584 if (speed != SPEED_1000) {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002585 /* If link speed is not set to gigabit speed, we
2586 * do not need to enable TBI compatibility.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002587 */
2588 if (hw->tbi_compatibility_on) {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002589 /* If we previously were in the mode,
2590 * turn it off.
2591 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002592 rctl = er32(RCTL);
2593 rctl &= ~E1000_RCTL_SBP;
2594 ew32(RCTL, rctl);
2595 hw->tbi_compatibility_on = false;
2596 }
2597 } else {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002598 /* If TBI compatibility is was previously off,
2599 * turn it on. For compatibility with a TBI link
2600 * partner, we will store bad packets. Some
2601 * frames have an additional byte on the end and
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002602 * will look like CRC errors to to the hardware.
2603 */
2604 if (!hw->tbi_compatibility_on) {
2605 hw->tbi_compatibility_on = true;
2606 rctl = er32(RCTL);
2607 rctl |= E1000_RCTL_SBP;
2608 ew32(RCTL, rctl);
2609 }
2610 }
2611 }
2612 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002614 if ((hw->media_type == e1000_media_type_fiber) ||
2615 (hw->media_type == e1000_media_type_internal_serdes))
2616 e1000_check_for_serdes_link_generic(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002618 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002619}
2620
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002621/**
2622 * e1000_get_speed_and_duplex
2623 * @hw: Struct containing variables accessed by shared code
2624 * @speed: Speed of the connection
2625 * @duplex: Duplex setting of the connection
Ben Hutchings49ce9c22012-07-10 10:56:00 +00002626 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627 * Detects the current speed and duplex settings of the hardware.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002628 */
Joe Perches64798842008-07-11 15:17:02 -07002629s32 e1000_get_speed_and_duplex(struct e1000_hw *hw, u16 *speed, u16 *duplex)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002631 u32 status;
2632 s32 ret_val;
2633 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634
Emil Tantilov675ad472010-04-27 14:02:58 +00002635 e_dbg("e1000_get_speed_and_duplex");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002637 if (hw->mac_type >= e1000_82543) {
2638 status = er32(STATUS);
2639 if (status & E1000_STATUS_SPEED_1000) {
2640 *speed = SPEED_1000;
Emil Tantilov675ad472010-04-27 14:02:58 +00002641 e_dbg("1000 Mbs, ");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002642 } else if (status & E1000_STATUS_SPEED_100) {
2643 *speed = SPEED_100;
Emil Tantilov675ad472010-04-27 14:02:58 +00002644 e_dbg("100 Mbs, ");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002645 } else {
2646 *speed = SPEED_10;
Emil Tantilov675ad472010-04-27 14:02:58 +00002647 e_dbg("10 Mbs, ");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002648 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002650 if (status & E1000_STATUS_FD) {
2651 *duplex = FULL_DUPLEX;
Emil Tantilov675ad472010-04-27 14:02:58 +00002652 e_dbg("Full Duplex\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002653 } else {
2654 *duplex = HALF_DUPLEX;
Emil Tantilov675ad472010-04-27 14:02:58 +00002655 e_dbg(" Half Duplex\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002656 }
2657 } else {
Emil Tantilov675ad472010-04-27 14:02:58 +00002658 e_dbg("1000 Mbs, Full Duplex\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002659 *speed = SPEED_1000;
2660 *duplex = FULL_DUPLEX;
2661 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002663 /* IGP01 PHY may advertise full duplex operation after speed downgrade
2664 * even if it is operating at half duplex. Here we set the duplex
2665 * settings to match the duplex in the link partner's capabilities.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002666 */
2667 if (hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
2668 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
2669 if (ret_val)
2670 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002672 if (!(phy_data & NWAY_ER_LP_NWAY_CAPS))
2673 *duplex = HALF_DUPLEX;
2674 else {
2675 ret_val =
2676 e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data);
2677 if (ret_val)
2678 return ret_val;
2679 if ((*speed == SPEED_100
2680 && !(phy_data & NWAY_LPAR_100TX_FD_CAPS))
2681 || (*speed == SPEED_10
2682 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
2683 *duplex = HALF_DUPLEX;
2684 }
2685 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002686
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002687 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002688}
2689
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002690/**
2691 * e1000_wait_autoneg
2692 * @hw: Struct containing variables accessed by shared code
2693 *
2694 * Blocks until autoneg completes or times out (~4.5 seconds)
2695 */
Joe Perches64798842008-07-11 15:17:02 -07002696static s32 e1000_wait_autoneg(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002697{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002698 s32 ret_val;
2699 u16 i;
2700 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002701
Emil Tantilov675ad472010-04-27 14:02:58 +00002702 e_dbg("e1000_wait_autoneg");
2703 e_dbg("Waiting for Auto-Neg to complete.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002704
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002705 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
2706 for (i = PHY_AUTO_NEG_TIME; i > 0; i--) {
2707 /* Read the MII Status Register and wait for Auto-Neg
2708 * Complete bit to be set.
2709 */
2710 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2711 if (ret_val)
2712 return ret_val;
2713 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2714 if (ret_val)
2715 return ret_val;
2716 if (phy_data & MII_SR_AUTONEG_COMPLETE) {
2717 return E1000_SUCCESS;
2718 }
2719 msleep(100);
2720 }
2721 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722}
2723
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002724/**
2725 * e1000_raise_mdi_clk - Raises the Management Data Clock
2726 * @hw: Struct containing variables accessed by shared code
2727 * @ctrl: Device control register's current value
2728 */
Joe Perches64798842008-07-11 15:17:02 -07002729static void e1000_raise_mdi_clk(struct e1000_hw *hw, u32 *ctrl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730{
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002731 /* Raise the clock input to the Management Data Clock (by setting the
2732 * MDC bit), and then delay 10 microseconds.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002733 */
2734 ew32(CTRL, (*ctrl | E1000_CTRL_MDC));
2735 E1000_WRITE_FLUSH();
2736 udelay(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737}
2738
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002739/**
2740 * e1000_lower_mdi_clk - Lowers the Management Data Clock
2741 * @hw: Struct containing variables accessed by shared code
2742 * @ctrl: Device control register's current value
2743 */
Joe Perches64798842008-07-11 15:17:02 -07002744static void e1000_lower_mdi_clk(struct e1000_hw *hw, u32 *ctrl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745{
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002746 /* Lower the clock input to the Management Data Clock (by clearing the
2747 * MDC bit), and then delay 10 microseconds.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002748 */
2749 ew32(CTRL, (*ctrl & ~E1000_CTRL_MDC));
2750 E1000_WRITE_FLUSH();
2751 udelay(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002752}
2753
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002754/**
2755 * e1000_shift_out_mdi_bits - Shifts data bits out to the PHY
2756 * @hw: Struct containing variables accessed by shared code
2757 * @data: Data to send out to the PHY
2758 * @count: Number of bits to shift out
2759 *
2760 * Bits are shifted out in MSB to LSB order.
2761 */
Joe Perches64798842008-07-11 15:17:02 -07002762static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, u32 data, u16 count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002763{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002764 u32 ctrl;
2765 u32 mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002766
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002767 /* We need to shift "count" number of bits out to the PHY. So, the value
2768 * in the "data" parameter will be shifted out to the PHY one bit at a
2769 * time. In order to do this, "data" must be broken down into bits.
2770 */
2771 mask = 0x01;
2772 mask <<= (count - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002773
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002774 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002775
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002776 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
2777 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002778
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002779 while (mask) {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002780 /* A "1" is shifted out to the PHY by setting the MDIO bit to
2781 * "1" and then raising and lowering the Management Data Clock.
2782 * A "0" is shifted out to the PHY by setting the MDIO bit to
2783 * "0" and then raising and lowering the clock.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002784 */
2785 if (data & mask)
2786 ctrl |= E1000_CTRL_MDIO;
2787 else
2788 ctrl &= ~E1000_CTRL_MDIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002789
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002790 ew32(CTRL, ctrl);
2791 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002792
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002793 udelay(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002794
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002795 e1000_raise_mdi_clk(hw, &ctrl);
2796 e1000_lower_mdi_clk(hw, &ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002797
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002798 mask = mask >> 1;
2799 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002800}
2801
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002802/**
2803 * e1000_shift_in_mdi_bits - Shifts data bits in from the PHY
2804 * @hw: Struct containing variables accessed by shared code
2805 *
2806 * Bits are shifted in in MSB to LSB order.
2807 */
Joe Perches64798842008-07-11 15:17:02 -07002808static u16 e1000_shift_in_mdi_bits(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002809{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002810 u32 ctrl;
2811 u16 data = 0;
2812 u8 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002813
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002814 /* In order to read a register from the PHY, we need to shift in a total
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002815 * of 18 bits from the PHY. The first two bit (turnaround) times are
2816 * used to avoid contention on the MDIO pin when a read operation is
2817 * performed. These two bits are ignored by us and thrown away. Bits are
2818 * "shifted in" by raising the input to the Management Data Clock
2819 * (setting the MDC bit), and then reading the value of the MDIO bit.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002820 */
2821 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002822
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002823 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as
2824 * input.
2825 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002826 ctrl &= ~E1000_CTRL_MDIO_DIR;
2827 ctrl &= ~E1000_CTRL_MDIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002828
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002829 ew32(CTRL, ctrl);
2830 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002831
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002832 /* Raise and Lower the clock before reading in the data. This accounts
2833 * for the turnaround bits. The first clock occurred when we clocked out
2834 * the last bit of the Register Address.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002835 */
2836 e1000_raise_mdi_clk(hw, &ctrl);
2837 e1000_lower_mdi_clk(hw, &ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002838
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002839 for (data = 0, i = 0; i < 16; i++) {
2840 data = data << 1;
2841 e1000_raise_mdi_clk(hw, &ctrl);
2842 ctrl = er32(CTRL);
2843 /* Check to see if we shifted in a "1". */
2844 if (ctrl & E1000_CTRL_MDIO)
2845 data |= 1;
2846 e1000_lower_mdi_clk(hw, &ctrl);
2847 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002848
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002849 e1000_raise_mdi_clk(hw, &ctrl);
2850 e1000_lower_mdi_clk(hw, &ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002851
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002852 return data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002853}
2854
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002855
2856/**
2857 * e1000_read_phy_reg - read a phy register
2858 * @hw: Struct containing variables accessed by shared code
2859 * @reg_addr: address of the PHY register to read
2860 *
2861 * Reads the value from a PHY register, if the value is on a specific non zero
2862 * page, sets the page first.
2863 */
Joe Perches64798842008-07-11 15:17:02 -07002864s32 e1000_read_phy_reg(struct e1000_hw *hw, u32 reg_addr, u16 *phy_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002865{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002866 u32 ret_val;
Maxime Bizonac565582012-10-20 14:53:40 +00002867 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002868
Emil Tantilov675ad472010-04-27 14:02:58 +00002869 e_dbg("e1000_read_phy_reg");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002870
Maxime Bizonac565582012-10-20 14:53:40 +00002871 spin_lock_irqsave(&e1000_phy_lock, flags);
2872
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002873 if ((hw->phy_type == e1000_phy_igp) &&
2874 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
2875 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
2876 (u16) reg_addr);
Maxime Bizonac565582012-10-20 14:53:40 +00002877 if (ret_val) {
2878 spin_unlock_irqrestore(&e1000_phy_lock, flags);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002879 return ret_val;
Maxime Bizonac565582012-10-20 14:53:40 +00002880 }
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002881 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002882
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002883 ret_val = e1000_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
2884 phy_data);
Maxime Bizonac565582012-10-20 14:53:40 +00002885 spin_unlock_irqrestore(&e1000_phy_lock, flags);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002886
2887 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002888}
2889
Joe Perches64798842008-07-11 15:17:02 -07002890static s32 e1000_read_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr,
2891 u16 *phy_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002892{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002893 u32 i;
2894 u32 mdic = 0;
Dirk Brandewie5377a412011-01-06 14:29:54 +00002895 const u32 phy_addr = (hw->mac_type == e1000_ce4100) ? hw->phy_addr : 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002896
Emil Tantilov675ad472010-04-27 14:02:58 +00002897 e_dbg("e1000_read_phy_reg_ex");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002898
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002899 if (reg_addr > MAX_PHY_REG_ADDRESS) {
Emil Tantilov675ad472010-04-27 14:02:58 +00002900 e_dbg("PHY Address %d is out of range\n", reg_addr);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002901 return -E1000_ERR_PARAM;
2902 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002903
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002904 if (hw->mac_type > e1000_82543) {
2905 /* Set up Op-code, Phy Address, and register address in the MDI
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002906 * Control register. The MAC will take care of interfacing with
2907 * the PHY to retrieve the desired data.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002908 */
Dirk Brandewie5377a412011-01-06 14:29:54 +00002909 if (hw->mac_type == e1000_ce4100) {
2910 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
2911 (phy_addr << E1000_MDIC_PHY_SHIFT) |
2912 (INTEL_CE_GBE_MDIC_OP_READ) |
2913 (INTEL_CE_GBE_MDIC_GO));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002914
Dirk Brandewie5377a412011-01-06 14:29:54 +00002915 writel(mdic, E1000_MDIO_CMD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002916
Dirk Brandewie5377a412011-01-06 14:29:54 +00002917 /* Poll the ready bit to see if the MDI read
2918 * completed
2919 */
2920 for (i = 0; i < 64; i++) {
2921 udelay(50);
2922 mdic = readl(E1000_MDIO_CMD);
2923 if (!(mdic & INTEL_CE_GBE_MDIC_GO))
2924 break;
2925 }
2926
2927 if (mdic & INTEL_CE_GBE_MDIC_GO) {
2928 e_dbg("MDI Read did not complete\n");
2929 return -E1000_ERR_PHY;
2930 }
2931
2932 mdic = readl(E1000_MDIO_STS);
2933 if (mdic & INTEL_CE_GBE_MDIC_READ_ERROR) {
2934 e_dbg("MDI Read Error\n");
2935 return -E1000_ERR_PHY;
2936 }
2937 *phy_data = (u16) mdic;
2938 } else {
2939 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
2940 (phy_addr << E1000_MDIC_PHY_SHIFT) |
2941 (E1000_MDIC_OP_READ));
2942
2943 ew32(MDIC, mdic);
2944
2945 /* Poll the ready bit to see if the MDI read
2946 * completed
2947 */
2948 for (i = 0; i < 64; i++) {
2949 udelay(50);
2950 mdic = er32(MDIC);
2951 if (mdic & E1000_MDIC_READY)
2952 break;
2953 }
2954 if (!(mdic & E1000_MDIC_READY)) {
2955 e_dbg("MDI Read did not complete\n");
2956 return -E1000_ERR_PHY;
2957 }
2958 if (mdic & E1000_MDIC_ERROR) {
2959 e_dbg("MDI Error\n");
2960 return -E1000_ERR_PHY;
2961 }
2962 *phy_data = (u16) mdic;
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002963 }
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002964 } else {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002965 /* We must first send a preamble through the MDIO pin to signal
2966 * the beginning of an MII instruction. This is done by sending
2967 * 32 consecutive "1" bits.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002968 */
2969 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002970
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002971 /* Now combine the next few fields that are required for a read
2972 * operation. We use this method instead of calling the
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002973 * e1000_shift_out_mdi_bits routine five different times. The
2974 * format of a MII read instruction consists of a shift out of
2975 * 14 bits and is defined as follows:
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002976 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002977 * followed by a shift in of 18 bits. This first two bits
2978 * shifted in are TurnAround bits used to avoid contention on
2979 * the MDIO pin when a READ operation is performed. These two
2980 * bits are thrown away followed by a shift in of 16 bits which
2981 * contains the desired data.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002982 */
2983 mdic = ((reg_addr) | (phy_addr << 5) |
2984 (PHY_OP_READ << 10) | (PHY_SOF << 12));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002985
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002986 e1000_shift_out_mdi_bits(hw, mdic, 14);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002987
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002988 /* Now that we've shifted out the read command to the MII, we
2989 * need to "shift in" the 16-bit value (18 total bits) of the
2990 * requested PHY register address.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002991 */
2992 *phy_data = e1000_shift_in_mdi_bits(hw);
2993 }
2994 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002995}
2996
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002997/**
2998 * e1000_write_phy_reg - write a phy register
2999 *
3000 * @hw: Struct containing variables accessed by shared code
3001 * @reg_addr: address of the PHY register to write
3002 * @data: data to write to the PHY
Ben Hutchings49ce9c22012-07-10 10:56:00 +00003003 *
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003004 * Writes a value to a PHY register
3005 */
Joe Perches64798842008-07-11 15:17:02 -07003006s32 e1000_write_phy_reg(struct e1000_hw *hw, u32 reg_addr, u16 phy_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003007{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003008 u32 ret_val;
Maxime Bizonac565582012-10-20 14:53:40 +00003009 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003010
Emil Tantilov675ad472010-04-27 14:02:58 +00003011 e_dbg("e1000_write_phy_reg");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003012
Maxime Bizonac565582012-10-20 14:53:40 +00003013 spin_lock_irqsave(&e1000_phy_lock, flags);
3014
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003015 if ((hw->phy_type == e1000_phy_igp) &&
3016 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
3017 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
3018 (u16) reg_addr);
Maxime Bizonac565582012-10-20 14:53:40 +00003019 if (ret_val) {
3020 spin_unlock_irqrestore(&e1000_phy_lock, flags);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003021 return ret_val;
Maxime Bizonac565582012-10-20 14:53:40 +00003022 }
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003023 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003024
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003025 ret_val = e1000_write_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
3026 phy_data);
Maxime Bizonac565582012-10-20 14:53:40 +00003027 spin_unlock_irqrestore(&e1000_phy_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003028
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003029 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003030}
3031
Joe Perches64798842008-07-11 15:17:02 -07003032static s32 e1000_write_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr,
3033 u16 phy_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003034{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003035 u32 i;
3036 u32 mdic = 0;
Dirk Brandewie5377a412011-01-06 14:29:54 +00003037 const u32 phy_addr = (hw->mac_type == e1000_ce4100) ? hw->phy_addr : 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003038
Emil Tantilov675ad472010-04-27 14:02:58 +00003039 e_dbg("e1000_write_phy_reg_ex");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003040
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003041 if (reg_addr > MAX_PHY_REG_ADDRESS) {
Emil Tantilov675ad472010-04-27 14:02:58 +00003042 e_dbg("PHY Address %d is out of range\n", reg_addr);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003043 return -E1000_ERR_PARAM;
3044 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003045
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003046 if (hw->mac_type > e1000_82543) {
Dirk Brandewie5377a412011-01-06 14:29:54 +00003047 /* Set up Op-code, Phy Address, register address, and data
3048 * intended for the PHY register in the MDI Control register.
3049 * The MAC will take care of interfacing with the PHY to send
3050 * the desired data.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003051 */
Dirk Brandewie5377a412011-01-06 14:29:54 +00003052 if (hw->mac_type == e1000_ce4100) {
3053 mdic = (((u32) phy_data) |
3054 (reg_addr << E1000_MDIC_REG_SHIFT) |
3055 (phy_addr << E1000_MDIC_PHY_SHIFT) |
3056 (INTEL_CE_GBE_MDIC_OP_WRITE) |
3057 (INTEL_CE_GBE_MDIC_GO));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003058
Dirk Brandewie5377a412011-01-06 14:29:54 +00003059 writel(mdic, E1000_MDIO_CMD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003060
Dirk Brandewie5377a412011-01-06 14:29:54 +00003061 /* Poll the ready bit to see if the MDI read
3062 * completed
3063 */
3064 for (i = 0; i < 640; i++) {
3065 udelay(5);
3066 mdic = readl(E1000_MDIO_CMD);
3067 if (!(mdic & INTEL_CE_GBE_MDIC_GO))
3068 break;
3069 }
3070 if (mdic & INTEL_CE_GBE_MDIC_GO) {
3071 e_dbg("MDI Write did not complete\n");
3072 return -E1000_ERR_PHY;
3073 }
3074 } else {
3075 mdic = (((u32) phy_data) |
3076 (reg_addr << E1000_MDIC_REG_SHIFT) |
3077 (phy_addr << E1000_MDIC_PHY_SHIFT) |
3078 (E1000_MDIC_OP_WRITE));
3079
3080 ew32(MDIC, mdic);
3081
3082 /* Poll the ready bit to see if the MDI read
3083 * completed
3084 */
3085 for (i = 0; i < 641; i++) {
3086 udelay(5);
3087 mdic = er32(MDIC);
3088 if (mdic & E1000_MDIC_READY)
3089 break;
3090 }
3091 if (!(mdic & E1000_MDIC_READY)) {
3092 e_dbg("MDI Write did not complete\n");
3093 return -E1000_ERR_PHY;
3094 }
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003095 }
3096 } else {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003097 /* We'll need to use the SW defined pins to shift the write
3098 * command out to the PHY. We first send a preamble to the PHY
3099 * to signal the beginning of the MII instruction. This is done
3100 * by sending 32 consecutive "1" bits.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003101 */
3102 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003103
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003104 /* Now combine the remaining required fields that will indicate
3105 * a write operation. We use this method instead of calling the
3106 * e1000_shift_out_mdi_bits routine for each field in the
3107 * command. The format of a MII write instruction is as follows:
3108 * <Preamble><SOF><OpCode><PhyAddr><RegAddr><Turnaround><Data>.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003109 */
3110 mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
3111 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
3112 mdic <<= 16;
3113 mdic |= (u32) phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003114
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003115 e1000_shift_out_mdi_bits(hw, mdic, 32);
3116 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003117
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003118 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003119}
3120
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003121/**
3122 * e1000_phy_hw_reset - reset the phy, hardware style
3123 * @hw: Struct containing variables accessed by shared code
3124 *
3125 * Returns the PHY to the power-on reset state
3126 */
Joe Perches64798842008-07-11 15:17:02 -07003127s32 e1000_phy_hw_reset(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003128{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003129 u32 ctrl, ctrl_ext;
3130 u32 led_ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003131
Emil Tantilov675ad472010-04-27 14:02:58 +00003132 e_dbg("e1000_phy_hw_reset");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003133
Emil Tantilov675ad472010-04-27 14:02:58 +00003134 e_dbg("Resetting Phy...\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003135
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003136 if (hw->mac_type > e1000_82543) {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003137 /* Read the device control register and assert the
3138 * E1000_CTRL_PHY_RST bit. Then, take it out of reset.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003139 * For e1000 hardware, we delay for 10ms between the assert
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003140 * and de-assert.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003141 */
3142 ctrl = er32(CTRL);
3143 ew32(CTRL, ctrl | E1000_CTRL_PHY_RST);
3144 E1000_WRITE_FLUSH();
Auke Kok76c224b2006-05-23 13:36:06 -07003145
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003146 msleep(10);
Auke Kok76c224b2006-05-23 13:36:06 -07003147
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003148 ew32(CTRL, ctrl);
3149 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003150
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003151 } else {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003152 /* Read the Extended Device Control Register, assert the
3153 * PHY_RESET_DIR bit to put the PHY into reset. Then, take it
3154 * out of reset.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003155 */
3156 ctrl_ext = er32(CTRL_EXT);
3157 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
3158 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
3159 ew32(CTRL_EXT, ctrl_ext);
3160 E1000_WRITE_FLUSH();
3161 msleep(10);
3162 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
3163 ew32(CTRL_EXT, ctrl_ext);
3164 E1000_WRITE_FLUSH();
3165 }
3166 udelay(150);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003167
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003168 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
3169 /* Configure activity LED after PHY reset */
3170 led_ctrl = er32(LEDCTL);
3171 led_ctrl &= IGP_ACTIVITY_LED_MASK;
3172 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
3173 ew32(LEDCTL, led_ctrl);
3174 }
Auke Kok8fc897b2006-08-28 14:56:16 -07003175
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003176 /* Wait for FW to finish PHY configuration. */
Greg Dietschec4dc4d12011-06-16 07:09:30 +00003177 return e1000_get_phy_cfg_done(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003178}
3179
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003180/**
3181 * e1000_phy_reset - reset the phy to commit settings
3182 * @hw: Struct containing variables accessed by shared code
3183 *
3184 * Resets the PHY
3185 * Sets bit 15 of the MII Control register
3186 */
Joe Perches64798842008-07-11 15:17:02 -07003187s32 e1000_phy_reset(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003188{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003189 s32 ret_val;
3190 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003191
Emil Tantilov675ad472010-04-27 14:02:58 +00003192 e_dbg("e1000_phy_reset");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003193
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003194 switch (hw->phy_type) {
3195 case e1000_phy_igp:
3196 ret_val = e1000_phy_hw_reset(hw);
3197 if (ret_val)
3198 return ret_val;
3199 break;
3200 default:
3201 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
3202 if (ret_val)
3203 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003204
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003205 phy_data |= MII_CR_RESET;
3206 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
3207 if (ret_val)
3208 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003209
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003210 udelay(1);
3211 break;
3212 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003213
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003214 if (hw->phy_type == e1000_phy_igp)
3215 e1000_phy_init_script(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003216
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003217 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003218}
3219
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003220/**
3221 * e1000_detect_gig_phy - check the phy type
3222 * @hw: Struct containing variables accessed by shared code
3223 *
3224 * Probes the expected PHY address for known PHY IDs
3225 */
Joe Perches64798842008-07-11 15:17:02 -07003226static s32 e1000_detect_gig_phy(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003227{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003228 s32 phy_init_status, ret_val;
3229 u16 phy_id_high, phy_id_low;
3230 bool match = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003231
Emil Tantilov675ad472010-04-27 14:02:58 +00003232 e_dbg("e1000_detect_gig_phy");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003233
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003234 if (hw->phy_id != 0)
3235 return E1000_SUCCESS;
Jeff Kirsher2a88c172006-09-27 12:54:05 -07003236
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003237 /* Read the PHY ID Registers to identify which PHY is onboard. */
3238 ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
3239 if (ret_val)
3240 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003241
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003242 hw->phy_id = (u32) (phy_id_high << 16);
3243 udelay(20);
3244 ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
3245 if (ret_val)
3246 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003247
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003248 hw->phy_id |= (u32) (phy_id_low & PHY_REVISION_MASK);
3249 hw->phy_revision = (u32) phy_id_low & ~PHY_REVISION_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003250
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003251 switch (hw->mac_type) {
3252 case e1000_82543:
3253 if (hw->phy_id == M88E1000_E_PHY_ID)
3254 match = true;
3255 break;
3256 case e1000_82544:
3257 if (hw->phy_id == M88E1000_I_PHY_ID)
3258 match = true;
3259 break;
3260 case e1000_82540:
3261 case e1000_82545:
3262 case e1000_82545_rev_3:
3263 case e1000_82546:
3264 case e1000_82546_rev_3:
3265 if (hw->phy_id == M88E1011_I_PHY_ID)
3266 match = true;
3267 break;
Dirk Brandewie5377a412011-01-06 14:29:54 +00003268 case e1000_ce4100:
3269 if ((hw->phy_id == RTL8211B_PHY_ID) ||
Florian Fainellicf8e09b2011-01-24 14:48:03 +00003270 (hw->phy_id == RTL8201N_PHY_ID) ||
3271 (hw->phy_id == M88E1118_E_PHY_ID))
Dirk Brandewie5377a412011-01-06 14:29:54 +00003272 match = true;
3273 break;
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003274 case e1000_82541:
3275 case e1000_82541_rev_2:
3276 case e1000_82547:
3277 case e1000_82547_rev_2:
3278 if (hw->phy_id == IGP01E1000_I_PHY_ID)
3279 match = true;
3280 break;
3281 default:
Emil Tantilov675ad472010-04-27 14:02:58 +00003282 e_dbg("Invalid MAC type %d\n", hw->mac_type);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003283 return -E1000_ERR_CONFIG;
3284 }
3285 phy_init_status = e1000_set_phy_type(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003286
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003287 if ((match) && (phy_init_status == E1000_SUCCESS)) {
Emil Tantilov675ad472010-04-27 14:02:58 +00003288 e_dbg("PHY ID 0x%X detected\n", hw->phy_id);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003289 return E1000_SUCCESS;
3290 }
Emil Tantilov675ad472010-04-27 14:02:58 +00003291 e_dbg("Invalid PHY ID 0x%X\n", hw->phy_id);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003292 return -E1000_ERR_PHY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003293}
3294
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003295/**
3296 * e1000_phy_reset_dsp - reset DSP
3297 * @hw: Struct containing variables accessed by shared code
3298 *
3299 * Resets the PHY's DSP
3300 */
Joe Perches64798842008-07-11 15:17:02 -07003301static s32 e1000_phy_reset_dsp(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003302{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003303 s32 ret_val;
Emil Tantilov675ad472010-04-27 14:02:58 +00003304 e_dbg("e1000_phy_reset_dsp");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003305
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003306 do {
3307 ret_val = e1000_write_phy_reg(hw, 29, 0x001d);
3308 if (ret_val)
3309 break;
3310 ret_val = e1000_write_phy_reg(hw, 30, 0x00c1);
3311 if (ret_val)
3312 break;
3313 ret_val = e1000_write_phy_reg(hw, 30, 0x0000);
3314 if (ret_val)
3315 break;
3316 ret_val = E1000_SUCCESS;
3317 } while (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003318
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003319 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003320}
3321
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003322/**
3323 * e1000_phy_igp_get_info - get igp specific registers
3324 * @hw: Struct containing variables accessed by shared code
3325 * @phy_info: PHY information structure
3326 *
3327 * Get PHY information from various PHY registers for igp PHY only.
3328 */
Joe Perches64798842008-07-11 15:17:02 -07003329static s32 e1000_phy_igp_get_info(struct e1000_hw *hw,
3330 struct e1000_phy_info *phy_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003331{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003332 s32 ret_val;
3333 u16 phy_data, min_length, max_length, average;
3334 e1000_rev_polarity polarity;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003335
Emil Tantilov675ad472010-04-27 14:02:58 +00003336 e_dbg("e1000_phy_igp_get_info");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003337
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003338 /* The downshift status is checked only once, after link is established,
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003339 * and it stored in the hw->speed_downgraded parameter.
3340 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003341 phy_info->downshift = (e1000_downshift) hw->speed_downgraded;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003342
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003343 /* IGP01E1000 does not need to support it. */
3344 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003345
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003346 /* IGP01E1000 always correct polarity reversal */
3347 phy_info->polarity_correction = e1000_polarity_reversal_enabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003348
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003349 /* Check polarity status */
3350 ret_val = e1000_check_polarity(hw, &polarity);
3351 if (ret_val)
3352 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003353
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003354 phy_info->cable_polarity = polarity;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003355
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003356 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, &phy_data);
3357 if (ret_val)
3358 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003359
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003360 phy_info->mdix_mode =
3361 (e1000_auto_x_mode) ((phy_data & IGP01E1000_PSSR_MDIX) >>
3362 IGP01E1000_PSSR_MDIX_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003363
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003364 if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
3365 IGP01E1000_PSSR_SPEED_1000MBPS) {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003366 /* Local/Remote Receiver Information are only valid @ 1000
3367 * Mbps
3368 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003369 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
3370 if (ret_val)
3371 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003372
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003373 phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
3374 SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
3375 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
3376 phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
3377 SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
3378 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003379
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003380 /* Get cable length */
3381 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
3382 if (ret_val)
3383 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003384
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003385 /* Translate to old method */
3386 average = (max_length + min_length) / 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003387
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003388 if (average <= e1000_igp_cable_length_50)
3389 phy_info->cable_length = e1000_cable_length_50;
3390 else if (average <= e1000_igp_cable_length_80)
3391 phy_info->cable_length = e1000_cable_length_50_80;
3392 else if (average <= e1000_igp_cable_length_110)
3393 phy_info->cable_length = e1000_cable_length_80_110;
3394 else if (average <= e1000_igp_cable_length_140)
3395 phy_info->cable_length = e1000_cable_length_110_140;
3396 else
3397 phy_info->cable_length = e1000_cable_length_140;
3398 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003399
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003400 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003401}
3402
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003403/**
3404 * e1000_phy_m88_get_info - get m88 specific registers
3405 * @hw: Struct containing variables accessed by shared code
3406 * @phy_info: PHY information structure
3407 *
3408 * Get PHY information from various PHY registers for m88 PHY only.
3409 */
Joe Perches64798842008-07-11 15:17:02 -07003410static s32 e1000_phy_m88_get_info(struct e1000_hw *hw,
3411 struct e1000_phy_info *phy_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003412{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003413 s32 ret_val;
3414 u16 phy_data;
3415 e1000_rev_polarity polarity;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003416
Emil Tantilov675ad472010-04-27 14:02:58 +00003417 e_dbg("e1000_phy_m88_get_info");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003418
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003419 /* The downshift status is checked only once, after link is established,
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003420 * and it stored in the hw->speed_downgraded parameter.
3421 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003422 phy_info->downshift = (e1000_downshift) hw->speed_downgraded;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003423
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003424 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
3425 if (ret_val)
3426 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003427
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003428 phy_info->extended_10bt_distance =
3429 ((phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >>
3430 M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT) ?
3431 e1000_10bt_ext_dist_enable_lower :
3432 e1000_10bt_ext_dist_enable_normal;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07003433
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003434 phy_info->polarity_correction =
3435 ((phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >>
3436 M88E1000_PSCR_POLARITY_REVERSAL_SHIFT) ?
3437 e1000_polarity_reversal_disabled : e1000_polarity_reversal_enabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003438
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003439 /* Check polarity status */
3440 ret_val = e1000_check_polarity(hw, &polarity);
3441 if (ret_val)
3442 return ret_val;
3443 phy_info->cable_polarity = polarity;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003444
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003445 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
3446 if (ret_val)
3447 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003448
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003449 phy_info->mdix_mode =
3450 (e1000_auto_x_mode) ((phy_data & M88E1000_PSSR_MDIX) >>
3451 M88E1000_PSSR_MDIX_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003452
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003453 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
3454 /* Cable Length Estimation and Local/Remote Receiver Information
3455 * are only valid at 1000 Mbps.
3456 */
3457 phy_info->cable_length =
3458 (e1000_cable_length) ((phy_data &
3459 M88E1000_PSSR_CABLE_LENGTH) >>
3460 M88E1000_PSSR_CABLE_LENGTH_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003461
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003462 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
3463 if (ret_val)
3464 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003465
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003466 phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
3467 SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
3468 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
3469 phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
3470 SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
3471 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003472
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003473 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003474
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003475 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003476}
3477
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003478/**
3479 * e1000_phy_get_info - request phy info
3480 * @hw: Struct containing variables accessed by shared code
3481 * @phy_info: PHY information structure
3482 *
3483 * Get PHY information from various PHY registers
3484 */
Joe Perches64798842008-07-11 15:17:02 -07003485s32 e1000_phy_get_info(struct e1000_hw *hw, struct e1000_phy_info *phy_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003486{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003487 s32 ret_val;
3488 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003489
Emil Tantilov675ad472010-04-27 14:02:58 +00003490 e_dbg("e1000_phy_get_info");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003491
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003492 phy_info->cable_length = e1000_cable_length_undefined;
3493 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined;
3494 phy_info->cable_polarity = e1000_rev_polarity_undefined;
3495 phy_info->downshift = e1000_downshift_undefined;
3496 phy_info->polarity_correction = e1000_polarity_reversal_undefined;
3497 phy_info->mdix_mode = e1000_auto_x_mode_undefined;
3498 phy_info->local_rx = e1000_1000t_rx_status_undefined;
3499 phy_info->remote_rx = e1000_1000t_rx_status_undefined;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003500
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003501 if (hw->media_type != e1000_media_type_copper) {
Emil Tantilov675ad472010-04-27 14:02:58 +00003502 e_dbg("PHY info is only valid for copper media\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003503 return -E1000_ERR_CONFIG;
3504 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003505
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003506 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3507 if (ret_val)
3508 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003509
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003510 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3511 if (ret_val)
3512 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003513
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003514 if ((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) {
Emil Tantilov675ad472010-04-27 14:02:58 +00003515 e_dbg("PHY info is only valid if link is up\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003516 return -E1000_ERR_CONFIG;
3517 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003518
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003519 if (hw->phy_type == e1000_phy_igp)
3520 return e1000_phy_igp_get_info(hw, phy_info);
Dirk Brandewie5377a412011-01-06 14:29:54 +00003521 else if ((hw->phy_type == e1000_phy_8211) ||
3522 (hw->phy_type == e1000_phy_8201))
3523 return E1000_SUCCESS;
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003524 else
3525 return e1000_phy_m88_get_info(hw, phy_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003526}
3527
Joe Perches64798842008-07-11 15:17:02 -07003528s32 e1000_validate_mdi_setting(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003529{
Emil Tantilov675ad472010-04-27 14:02:58 +00003530 e_dbg("e1000_validate_mdi_settings");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003531
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003532 if (!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) {
Emil Tantilov675ad472010-04-27 14:02:58 +00003533 e_dbg("Invalid MDI setting detected\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003534 hw->mdix = 1;
3535 return -E1000_ERR_CONFIG;
3536 }
3537 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003538}
3539
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003540/**
3541 * e1000_init_eeprom_params - initialize sw eeprom vars
3542 * @hw: Struct containing variables accessed by shared code
3543 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07003544 * Sets up eeprom variables in the hw struct. Must be called after mac_type
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00003545 * is configured.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003546 */
Joe Perches64798842008-07-11 15:17:02 -07003547s32 e1000_init_eeprom_params(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003548{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003549 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3550 u32 eecd = er32(EECD);
3551 s32 ret_val = E1000_SUCCESS;
3552 u16 eeprom_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003553
Emil Tantilov675ad472010-04-27 14:02:58 +00003554 e_dbg("e1000_init_eeprom_params");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003555
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003556 switch (hw->mac_type) {
3557 case e1000_82542_rev2_0:
3558 case e1000_82542_rev2_1:
3559 case e1000_82543:
3560 case e1000_82544:
3561 eeprom->type = e1000_eeprom_microwire;
3562 eeprom->word_size = 64;
3563 eeprom->opcode_bits = 3;
3564 eeprom->address_bits = 6;
3565 eeprom->delay_usec = 50;
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003566 break;
3567 case e1000_82540:
3568 case e1000_82545:
3569 case e1000_82545_rev_3:
3570 case e1000_82546:
3571 case e1000_82546_rev_3:
3572 eeprom->type = e1000_eeprom_microwire;
3573 eeprom->opcode_bits = 3;
3574 eeprom->delay_usec = 50;
3575 if (eecd & E1000_EECD_SIZE) {
3576 eeprom->word_size = 256;
3577 eeprom->address_bits = 8;
3578 } else {
3579 eeprom->word_size = 64;
3580 eeprom->address_bits = 6;
3581 }
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003582 break;
3583 case e1000_82541:
3584 case e1000_82541_rev_2:
3585 case e1000_82547:
3586 case e1000_82547_rev_2:
3587 if (eecd & E1000_EECD_TYPE) {
3588 eeprom->type = e1000_eeprom_spi;
3589 eeprom->opcode_bits = 8;
3590 eeprom->delay_usec = 1;
3591 if (eecd & E1000_EECD_ADDR_BITS) {
3592 eeprom->page_size = 32;
3593 eeprom->address_bits = 16;
3594 } else {
3595 eeprom->page_size = 8;
3596 eeprom->address_bits = 8;
3597 }
3598 } else {
3599 eeprom->type = e1000_eeprom_microwire;
3600 eeprom->opcode_bits = 3;
3601 eeprom->delay_usec = 50;
3602 if (eecd & E1000_EECD_ADDR_BITS) {
3603 eeprom->word_size = 256;
3604 eeprom->address_bits = 8;
3605 } else {
3606 eeprom->word_size = 64;
3607 eeprom->address_bits = 6;
3608 }
3609 }
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003610 break;
3611 default:
3612 break;
3613 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003614
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003615 if (eeprom->type == e1000_eeprom_spi) {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003616 /* eeprom_size will be an enum [0..8] that maps to eeprom sizes
3617 * 128B to 32KB (incremented by powers of 2).
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003618 */
3619 /* Set to default value for initial eeprom read. */
3620 eeprom->word_size = 64;
3621 ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size);
3622 if (ret_val)
3623 return ret_val;
3624 eeprom_size =
3625 (eeprom_size & EEPROM_SIZE_MASK) >> EEPROM_SIZE_SHIFT;
3626 /* 256B eeprom size was not supported in earlier hardware, so we
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003627 * bump eeprom_size up one to ensure that "1" (which maps to
3628 * 256B) is never the result used in the shifting logic below.
3629 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003630 if (eeprom_size)
3631 eeprom_size++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003632
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003633 eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT);
3634 }
3635 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003636}
3637
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003638/**
3639 * e1000_raise_ee_clk - Raises the EEPROM's clock input.
3640 * @hw: Struct containing variables accessed by shared code
3641 * @eecd: EECD's current value
3642 */
Joe Perches64798842008-07-11 15:17:02 -07003643static void e1000_raise_ee_clk(struct e1000_hw *hw, u32 *eecd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003644{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003645 /* Raise the clock input to the EEPROM (by setting the SK bit), and then
3646 * wait <delay> microseconds.
3647 */
3648 *eecd = *eecd | E1000_EECD_SK;
3649 ew32(EECD, *eecd);
3650 E1000_WRITE_FLUSH();
3651 udelay(hw->eeprom.delay_usec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003652}
3653
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003654/**
3655 * e1000_lower_ee_clk - Lowers the EEPROM's clock input.
3656 * @hw: Struct containing variables accessed by shared code
3657 * @eecd: EECD's current value
3658 */
Joe Perches64798842008-07-11 15:17:02 -07003659static void e1000_lower_ee_clk(struct e1000_hw *hw, u32 *eecd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003660{
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003661 /* Lower the clock input to the EEPROM (by clearing the SK bit), and
3662 * then wait 50 microseconds.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003663 */
3664 *eecd = *eecd & ~E1000_EECD_SK;
3665 ew32(EECD, *eecd);
3666 E1000_WRITE_FLUSH();
3667 udelay(hw->eeprom.delay_usec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003668}
3669
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003670/**
3671 * e1000_shift_out_ee_bits - Shift data bits out to the EEPROM.
3672 * @hw: Struct containing variables accessed by shared code
3673 * @data: data to send to the EEPROM
3674 * @count: number of bits to shift out
3675 */
Joe Perches64798842008-07-11 15:17:02 -07003676static void e1000_shift_out_ee_bits(struct e1000_hw *hw, u16 data, u16 count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003677{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003678 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3679 u32 eecd;
3680 u32 mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003681
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003682 /* We need to shift "count" bits out to the EEPROM. So, value in the
3683 * "data" parameter will be shifted out to the EEPROM one bit at a time.
3684 * In order to do this, "data" must be broken down into bits.
3685 */
3686 mask = 0x01 << (count - 1);
3687 eecd = er32(EECD);
3688 if (eeprom->type == e1000_eeprom_microwire) {
3689 eecd &= ~E1000_EECD_DO;
3690 } else if (eeprom->type == e1000_eeprom_spi) {
3691 eecd |= E1000_EECD_DO;
3692 }
3693 do {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003694 /* A "1" is shifted out to the EEPROM by setting bit "DI" to a
3695 * "1", and then raising and then lowering the clock (the SK bit
3696 * controls the clock input to the EEPROM). A "0" is shifted
3697 * out to the EEPROM by setting "DI" to "0" and then raising and
3698 * then lowering the clock.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003699 */
3700 eecd &= ~E1000_EECD_DI;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003701
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003702 if (data & mask)
3703 eecd |= E1000_EECD_DI;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003704
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003705 ew32(EECD, eecd);
3706 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003707
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003708 udelay(eeprom->delay_usec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003709
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003710 e1000_raise_ee_clk(hw, &eecd);
3711 e1000_lower_ee_clk(hw, &eecd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003712
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003713 mask = mask >> 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003714
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003715 } while (mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003716
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003717 /* We leave the "DI" bit set to "0" when we leave this routine. */
3718 eecd &= ~E1000_EECD_DI;
3719 ew32(EECD, eecd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003720}
3721
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003722/**
3723 * e1000_shift_in_ee_bits - Shift data bits in from the EEPROM
3724 * @hw: Struct containing variables accessed by shared code
3725 * @count: number of bits to shift in
3726 */
Joe Perches64798842008-07-11 15:17:02 -07003727static u16 e1000_shift_in_ee_bits(struct e1000_hw *hw, u16 count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003728{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003729 u32 eecd;
3730 u32 i;
3731 u16 data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003732
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003733 /* In order to read a register from the EEPROM, we need to shift 'count'
3734 * bits in from the EEPROM. Bits are "shifted in" by raising the clock
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003735 * input to the EEPROM (setting the SK bit), and then reading the value
3736 * of the "DO" bit. During this "shifting in" process the "DI" bit
3737 * should always be clear.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003738 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003739
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003740 eecd = er32(EECD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003741
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003742 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
3743 data = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003744
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003745 for (i = 0; i < count; i++) {
3746 data = data << 1;
3747 e1000_raise_ee_clk(hw, &eecd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003748
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003749 eecd = er32(EECD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003750
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003751 eecd &= ~(E1000_EECD_DI);
3752 if (eecd & E1000_EECD_DO)
3753 data |= 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003754
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003755 e1000_lower_ee_clk(hw, &eecd);
3756 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003757
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003758 return data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003759}
3760
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003761/**
3762 * e1000_acquire_eeprom - Prepares EEPROM for access
3763 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -07003764 *
3765 * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
3766 * function should be called before issuing a command to the EEPROM.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003767 */
Joe Perches64798842008-07-11 15:17:02 -07003768static s32 e1000_acquire_eeprom(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003769{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003770 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3771 u32 eecd, i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003772
Emil Tantilov675ad472010-04-27 14:02:58 +00003773 e_dbg("e1000_acquire_eeprom");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003774
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003775 eecd = er32(EECD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003776
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003777 /* Request EEPROM Access */
3778 if (hw->mac_type > e1000_82544) {
3779 eecd |= E1000_EECD_REQ;
3780 ew32(EECD, eecd);
3781 eecd = er32(EECD);
3782 while ((!(eecd & E1000_EECD_GNT)) &&
3783 (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
3784 i++;
3785 udelay(5);
3786 eecd = er32(EECD);
3787 }
3788 if (!(eecd & E1000_EECD_GNT)) {
3789 eecd &= ~E1000_EECD_REQ;
3790 ew32(EECD, eecd);
Emil Tantilov675ad472010-04-27 14:02:58 +00003791 e_dbg("Could not acquire EEPROM grant\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003792 return -E1000_ERR_EEPROM;
3793 }
3794 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003795
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003796 /* Setup EEPROM for Read/Write */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003797
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003798 if (eeprom->type == e1000_eeprom_microwire) {
3799 /* Clear SK and DI */
3800 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
3801 ew32(EECD, eecd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003802
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003803 /* Set CS */
3804 eecd |= E1000_EECD_CS;
3805 ew32(EECD, eecd);
3806 } else if (eeprom->type == e1000_eeprom_spi) {
3807 /* Clear SK and CS */
3808 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
3809 ew32(EECD, eecd);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00003810 E1000_WRITE_FLUSH();
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003811 udelay(1);
3812 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003813
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003814 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003815}
3816
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003817/**
3818 * e1000_standby_eeprom - Returns EEPROM to a "standby" state
3819 * @hw: Struct containing variables accessed by shared code
3820 */
Joe Perches64798842008-07-11 15:17:02 -07003821static void e1000_standby_eeprom(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003822{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003823 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3824 u32 eecd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003825
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003826 eecd = er32(EECD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003827
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003828 if (eeprom->type == e1000_eeprom_microwire) {
3829 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
3830 ew32(EECD, eecd);
3831 E1000_WRITE_FLUSH();
3832 udelay(eeprom->delay_usec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003833
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003834 /* Clock high */
3835 eecd |= E1000_EECD_SK;
3836 ew32(EECD, eecd);
3837 E1000_WRITE_FLUSH();
3838 udelay(eeprom->delay_usec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003839
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003840 /* Select EEPROM */
3841 eecd |= E1000_EECD_CS;
3842 ew32(EECD, eecd);
3843 E1000_WRITE_FLUSH();
3844 udelay(eeprom->delay_usec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003845
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003846 /* Clock low */
3847 eecd &= ~E1000_EECD_SK;
3848 ew32(EECD, eecd);
3849 E1000_WRITE_FLUSH();
3850 udelay(eeprom->delay_usec);
3851 } else if (eeprom->type == e1000_eeprom_spi) {
3852 /* Toggle CS to flush commands */
3853 eecd |= E1000_EECD_CS;
3854 ew32(EECD, eecd);
3855 E1000_WRITE_FLUSH();
3856 udelay(eeprom->delay_usec);
3857 eecd &= ~E1000_EECD_CS;
3858 ew32(EECD, eecd);
3859 E1000_WRITE_FLUSH();
3860 udelay(eeprom->delay_usec);
3861 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003862}
3863
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003864/**
3865 * e1000_release_eeprom - drop chip select
3866 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -07003867 *
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003868 * Terminates a command by inverting the EEPROM's chip select pin
3869 */
Joe Perches64798842008-07-11 15:17:02 -07003870static void e1000_release_eeprom(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003871{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003872 u32 eecd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003873
Emil Tantilov675ad472010-04-27 14:02:58 +00003874 e_dbg("e1000_release_eeprom");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003875
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003876 eecd = er32(EECD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003877
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003878 if (hw->eeprom.type == e1000_eeprom_spi) {
3879 eecd |= E1000_EECD_CS; /* Pull CS high */
3880 eecd &= ~E1000_EECD_SK; /* Lower SCK */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003881
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003882 ew32(EECD, eecd);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00003883 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003884
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003885 udelay(hw->eeprom.delay_usec);
3886 } else if (hw->eeprom.type == e1000_eeprom_microwire) {
3887 /* cleanup eeprom */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003888
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003889 /* CS on Microwire is active-high */
3890 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003891
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003892 ew32(EECD, eecd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003893
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003894 /* Rising edge of clock */
3895 eecd |= E1000_EECD_SK;
3896 ew32(EECD, eecd);
3897 E1000_WRITE_FLUSH();
3898 udelay(hw->eeprom.delay_usec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003899
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003900 /* Falling edge of clock */
3901 eecd &= ~E1000_EECD_SK;
3902 ew32(EECD, eecd);
3903 E1000_WRITE_FLUSH();
3904 udelay(hw->eeprom.delay_usec);
3905 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003906
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003907 /* Stop requesting EEPROM access */
3908 if (hw->mac_type > e1000_82544) {
3909 eecd &= ~E1000_EECD_REQ;
3910 ew32(EECD, eecd);
3911 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003912}
3913
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003914/**
3915 * e1000_spi_eeprom_ready - Reads a 16 bit word from the EEPROM.
3916 * @hw: Struct containing variables accessed by shared code
3917 */
Joe Perches64798842008-07-11 15:17:02 -07003918static s32 e1000_spi_eeprom_ready(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003919{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003920 u16 retry_count = 0;
3921 u8 spi_stat_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003922
Emil Tantilov675ad472010-04-27 14:02:58 +00003923 e_dbg("e1000_spi_eeprom_ready");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003924
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003925 /* Read "Status Register" repeatedly until the LSB is cleared. The
3926 * EEPROM will signal that the command has been completed by clearing
3927 * bit 0 of the internal status register. If it's not cleared within
3928 * 5 milliseconds, then error out.
3929 */
3930 retry_count = 0;
3931 do {
3932 e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
3933 hw->eeprom.opcode_bits);
3934 spi_stat_reg = (u8) e1000_shift_in_ee_bits(hw, 8);
3935 if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
3936 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003937
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003938 udelay(5);
3939 retry_count += 5;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003940
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003941 e1000_standby_eeprom(hw);
3942 } while (retry_count < EEPROM_MAX_RETRY_SPI);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003943
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003944 /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
3945 * only 0-5mSec on 5V devices)
3946 */
3947 if (retry_count >= EEPROM_MAX_RETRY_SPI) {
Emil Tantilov675ad472010-04-27 14:02:58 +00003948 e_dbg("SPI EEPROM Status error\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003949 return -E1000_ERR_EEPROM;
3950 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003951
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003952 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003953}
3954
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003955/**
3956 * e1000_read_eeprom - Reads a 16 bit word from the EEPROM.
3957 * @hw: Struct containing variables accessed by shared code
3958 * @offset: offset of word in the EEPROM to read
3959 * @data: word read from the EEPROM
3960 * @words: number of words to read
3961 */
Joe Perches64798842008-07-11 15:17:02 -07003962s32 e1000_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003963{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003964 s32 ret;
3965 spin_lock(&e1000_eeprom_lock);
3966 ret = e1000_do_read_eeprom(hw, offset, words, data);
3967 spin_unlock(&e1000_eeprom_lock);
3968 return ret;
Christopher Li78566fe2008-09-05 14:04:05 -07003969}
3970
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003971static s32 e1000_do_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words,
3972 u16 *data)
Christopher Li78566fe2008-09-05 14:04:05 -07003973{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003974 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3975 u32 i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003976
Emil Tantilov675ad472010-04-27 14:02:58 +00003977 e_dbg("e1000_read_eeprom");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003978
Dirk Brandewie5377a412011-01-06 14:29:54 +00003979 if (hw->mac_type == e1000_ce4100) {
3980 GBE_CONFIG_FLASH_READ(GBE_CONFIG_BASE_VIRT, offset, words,
3981 data);
3982 return E1000_SUCCESS;
3983 }
3984
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003985 /* If eeprom is not yet detected, do so now */
3986 if (eeprom->word_size == 0)
3987 e1000_init_eeprom_params(hw);
Jeff Kirsher2a88c172006-09-27 12:54:05 -07003988
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003989 /* A check for invalid values: offset too large, too many words, and
3990 * not enough words.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003991 */
3992 if ((offset >= eeprom->word_size)
3993 || (words > eeprom->word_size - offset) || (words == 0)) {
Emil Tantilov675ad472010-04-27 14:02:58 +00003994 e_dbg("\"words\" parameter out of bounds. Words = %d,"
3995 "size = %d\n", offset, eeprom->word_size);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003996 return -E1000_ERR_EEPROM;
3997 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003998
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003999 /* EEPROM's that don't use EERD to read require us to bit-bang the SPI
4000 * directly. In this case, we need to acquire the EEPROM so that
4001 * FW or other port software does not interrupt.
4002 */
Jesse Brandeburg8f601b22009-09-25 12:20:11 +00004003 /* Prepare the EEPROM for bit-bang reading */
4004 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
4005 return -E1000_ERR_EEPROM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004006
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004007 /* Set up the SPI or Microwire EEPROM for bit-bang reading. We have
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00004008 * acquired the EEPROM at this point, so any returns should release it
4009 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004010 if (eeprom->type == e1000_eeprom_spi) {
4011 u16 word_in;
4012 u8 read_opcode = EEPROM_READ_OPCODE_SPI;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004013
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004014 if (e1000_spi_eeprom_ready(hw)) {
4015 e1000_release_eeprom(hw);
4016 return -E1000_ERR_EEPROM;
4017 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004018
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004019 e1000_standby_eeprom(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004020
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00004021 /* Some SPI eeproms use the 8th address bit embedded in the
4022 * opcode
4023 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004024 if ((eeprom->address_bits == 8) && (offset >= 128))
4025 read_opcode |= EEPROM_A8_OPCODE_SPI;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004026
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004027 /* Send the READ command (opcode + addr) */
4028 e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
4029 e1000_shift_out_ee_bits(hw, (u16) (offset * 2),
4030 eeprom->address_bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004031
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00004032 /* Read the data. The address of the eeprom internally
4033 * increments with each byte (spi) being read, saving on the
4034 * overhead of eeprom setup and tear-down. The address counter
4035 * will roll over if reading beyond the size of the eeprom, thus
4036 * allowing the entire memory to be read starting from any
4037 * offset.
4038 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004039 for (i = 0; i < words; i++) {
4040 word_in = e1000_shift_in_ee_bits(hw, 16);
4041 data[i] = (word_in >> 8) | (word_in << 8);
4042 }
4043 } else if (eeprom->type == e1000_eeprom_microwire) {
4044 for (i = 0; i < words; i++) {
4045 /* Send the READ command (opcode + addr) */
4046 e1000_shift_out_ee_bits(hw,
4047 EEPROM_READ_OPCODE_MICROWIRE,
4048 eeprom->opcode_bits);
4049 e1000_shift_out_ee_bits(hw, (u16) (offset + i),
4050 eeprom->address_bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004051
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00004052 /* Read the data. For microwire, each word requires the
4053 * overhead of eeprom setup and tear-down.
4054 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004055 data[i] = e1000_shift_in_ee_bits(hw, 16);
4056 e1000_standby_eeprom(hw);
4057 }
4058 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004059
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004060 /* End this read operation */
4061 e1000_release_eeprom(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004062
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004063 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004064}
4065
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004066/**
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004067 * e1000_validate_eeprom_checksum - Verifies that the EEPROM has a valid checksum
4068 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -07004069 *
4070 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
4071 * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
4072 * valid.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004073 */
Joe Perches64798842008-07-11 15:17:02 -07004074s32 e1000_validate_eeprom_checksum(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004075{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004076 u16 checksum = 0;
4077 u16 i, eeprom_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004078
Emil Tantilov675ad472010-04-27 14:02:58 +00004079 e_dbg("e1000_validate_eeprom_checksum");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004080
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004081 for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
4082 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
Emil Tantilov675ad472010-04-27 14:02:58 +00004083 e_dbg("EEPROM Read Error\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004084 return -E1000_ERR_EEPROM;
4085 }
4086 checksum += eeprom_data;
4087 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004088
Jeff Kirshere2faeec2011-08-30 20:58:56 -04004089#ifdef CONFIG_PARISC
4090 /* This is a signature and not a checksum on HP c8000 */
4091 if ((hw->subsystem_vendor_id == 0x103C) && (eeprom_data == 0x16d6))
4092 return E1000_SUCCESS;
4093
4094#endif
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004095 if (checksum == (u16) EEPROM_SUM)
4096 return E1000_SUCCESS;
4097 else {
Emil Tantilov675ad472010-04-27 14:02:58 +00004098 e_dbg("EEPROM Checksum Invalid\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004099 return -E1000_ERR_EEPROM;
4100 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004101}
4102
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004103/**
4104 * e1000_update_eeprom_checksum - Calculates/writes the EEPROM checksum
4105 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -07004106 *
4107 * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA.
4108 * Writes the difference to word offset 63 of the EEPROM.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004109 */
Joe Perches64798842008-07-11 15:17:02 -07004110s32 e1000_update_eeprom_checksum(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004111{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004112 u16 checksum = 0;
4113 u16 i, eeprom_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004114
Emil Tantilov675ad472010-04-27 14:02:58 +00004115 e_dbg("e1000_update_eeprom_checksum");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004116
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004117 for (i = 0; i < EEPROM_CHECKSUM_REG; i++) {
4118 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
Emil Tantilov675ad472010-04-27 14:02:58 +00004119 e_dbg("EEPROM Read Error\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004120 return -E1000_ERR_EEPROM;
4121 }
4122 checksum += eeprom_data;
4123 }
4124 checksum = (u16) EEPROM_SUM - checksum;
4125 if (e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) {
Emil Tantilov675ad472010-04-27 14:02:58 +00004126 e_dbg("EEPROM Write Error\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004127 return -E1000_ERR_EEPROM;
4128 }
4129 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004130}
4131
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004132/**
4133 * e1000_write_eeprom - write words to the different EEPROM types.
4134 * @hw: Struct containing variables accessed by shared code
4135 * @offset: offset within the EEPROM to be written to
4136 * @words: number of words to write
4137 * @data: 16 bit word to be written to the EEPROM
Linus Torvalds1da177e2005-04-16 15:20:36 -07004138 *
4139 * If e1000_update_eeprom_checksum is not called after this function, the
4140 * EEPROM will most likely contain an invalid checksum.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004141 */
Joe Perches64798842008-07-11 15:17:02 -07004142s32 e1000_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004143{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004144 s32 ret;
4145 spin_lock(&e1000_eeprom_lock);
4146 ret = e1000_do_write_eeprom(hw, offset, words, data);
4147 spin_unlock(&e1000_eeprom_lock);
4148 return ret;
Christopher Li78566fe2008-09-05 14:04:05 -07004149}
4150
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004151static s32 e1000_do_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words,
4152 u16 *data)
Christopher Li78566fe2008-09-05 14:04:05 -07004153{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004154 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4155 s32 status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004156
Emil Tantilov675ad472010-04-27 14:02:58 +00004157 e_dbg("e1000_write_eeprom");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004158
Dirk Brandewie5377a412011-01-06 14:29:54 +00004159 if (hw->mac_type == e1000_ce4100) {
4160 GBE_CONFIG_FLASH_WRITE(GBE_CONFIG_BASE_VIRT, offset, words,
4161 data);
4162 return E1000_SUCCESS;
4163 }
4164
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004165 /* If eeprom is not yet detected, do so now */
4166 if (eeprom->word_size == 0)
4167 e1000_init_eeprom_params(hw);
Jeff Kirsher2a88c172006-09-27 12:54:05 -07004168
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00004169 /* A check for invalid values: offset too large, too many words, and
4170 * not enough words.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004171 */
4172 if ((offset >= eeprom->word_size)
4173 || (words > eeprom->word_size - offset) || (words == 0)) {
Emil Tantilov675ad472010-04-27 14:02:58 +00004174 e_dbg("\"words\" parameter out of bounds\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004175 return -E1000_ERR_EEPROM;
4176 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004177
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004178 /* Prepare the EEPROM for writing */
4179 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
4180 return -E1000_ERR_EEPROM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004181
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004182 if (eeprom->type == e1000_eeprom_microwire) {
4183 status = e1000_write_eeprom_microwire(hw, offset, words, data);
4184 } else {
4185 status = e1000_write_eeprom_spi(hw, offset, words, data);
4186 msleep(10);
4187 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004188
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004189 /* Done with writing */
4190 e1000_release_eeprom(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004191
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004192 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004193}
4194
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004195/**
4196 * e1000_write_eeprom_spi - Writes a 16 bit word to a given offset in an SPI EEPROM.
4197 * @hw: Struct containing variables accessed by shared code
4198 * @offset: offset within the EEPROM to be written to
4199 * @words: number of words to write
4200 * @data: pointer to array of 8 bit words to be written to the EEPROM
4201 */
Joe Perches64798842008-07-11 15:17:02 -07004202static s32 e1000_write_eeprom_spi(struct e1000_hw *hw, u16 offset, u16 words,
4203 u16 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004204{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004205 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4206 u16 widx = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004207
Emil Tantilov675ad472010-04-27 14:02:58 +00004208 e_dbg("e1000_write_eeprom_spi");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004209
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004210 while (widx < words) {
4211 u8 write_opcode = EEPROM_WRITE_OPCODE_SPI;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004212
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004213 if (e1000_spi_eeprom_ready(hw))
4214 return -E1000_ERR_EEPROM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004215
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004216 e1000_standby_eeprom(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004217
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004218 /* Send the WRITE ENABLE command (8 bit opcode ) */
4219 e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI,
4220 eeprom->opcode_bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004221
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004222 e1000_standby_eeprom(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004223
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00004224 /* Some SPI eeproms use the 8th address bit embedded in the
4225 * opcode
4226 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004227 if ((eeprom->address_bits == 8) && (offset >= 128))
4228 write_opcode |= EEPROM_A8_OPCODE_SPI;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004229
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004230 /* Send the Write command (8-bit opcode + addr) */
4231 e1000_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004232
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004233 e1000_shift_out_ee_bits(hw, (u16) ((offset + widx) * 2),
4234 eeprom->address_bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004235
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004236 /* Send the data */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004237
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00004238 /* Loop to allow for up to whole page write (32 bytes) of
4239 * eeprom
4240 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004241 while (widx < words) {
4242 u16 word_out = data[widx];
4243 word_out = (word_out >> 8) | (word_out << 8);
4244 e1000_shift_out_ee_bits(hw, word_out, 16);
4245 widx++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004246
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00004247 /* Some larger eeprom sizes are capable of a 32-byte
4248 * PAGE WRITE operation, while the smaller eeproms are
4249 * capable of an 8-byte PAGE WRITE operation. Break the
4250 * inner loop to pass new address
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004251 */
4252 if ((((offset + widx) * 2) % eeprom->page_size) == 0) {
4253 e1000_standby_eeprom(hw);
4254 break;
4255 }
4256 }
4257 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004258
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004259 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004260}
4261
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004262/**
4263 * e1000_write_eeprom_microwire - Writes a 16 bit word to a given offset in a Microwire EEPROM.
4264 * @hw: Struct containing variables accessed by shared code
4265 * @offset: offset within the EEPROM to be written to
4266 * @words: number of words to write
4267 * @data: pointer to array of 8 bit words to be written to the EEPROM
4268 */
Joe Perches64798842008-07-11 15:17:02 -07004269static s32 e1000_write_eeprom_microwire(struct e1000_hw *hw, u16 offset,
4270 u16 words, u16 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004271{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004272 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4273 u32 eecd;
4274 u16 words_written = 0;
4275 u16 i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004276
Emil Tantilov675ad472010-04-27 14:02:58 +00004277 e_dbg("e1000_write_eeprom_microwire");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004278
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004279 /* Send the write enable command to the EEPROM (3-bit opcode plus
4280 * 6/8-bit dummy address beginning with 11). It's less work to include
4281 * the 11 of the dummy address as part of the opcode than it is to shift
4282 * it over the correct number of bits for the address. This puts the
4283 * EEPROM into write/erase mode.
4284 */
4285 e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE,
4286 (u16) (eeprom->opcode_bits + 2));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004287
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004288 e1000_shift_out_ee_bits(hw, 0, (u16) (eeprom->address_bits - 2));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004289
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004290 /* Prepare the EEPROM */
4291 e1000_standby_eeprom(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004292
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004293 while (words_written < words) {
4294 /* Send the Write command (3-bit opcode + addr) */
4295 e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE,
4296 eeprom->opcode_bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004297
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004298 e1000_shift_out_ee_bits(hw, (u16) (offset + words_written),
4299 eeprom->address_bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004300
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004301 /* Send the data */
4302 e1000_shift_out_ee_bits(hw, data[words_written], 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004303
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00004304 /* Toggle the CS line. This in effect tells the EEPROM to
4305 * execute the previous command.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004306 */
4307 e1000_standby_eeprom(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004308
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00004309 /* Read DO repeatedly until it is high (equal to '1'). The
4310 * EEPROM will signal that the command has been completed by
4311 * raising the DO signal. If DO does not go high in 10
4312 * milliseconds, then error out.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004313 */
4314 for (i = 0; i < 200; i++) {
4315 eecd = er32(EECD);
4316 if (eecd & E1000_EECD_DO)
4317 break;
4318 udelay(50);
4319 }
4320 if (i == 200) {
Emil Tantilov675ad472010-04-27 14:02:58 +00004321 e_dbg("EEPROM Write did not complete\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004322 return -E1000_ERR_EEPROM;
4323 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004324
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004325 /* Recover from write */
4326 e1000_standby_eeprom(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004327
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004328 words_written++;
4329 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004330
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004331 /* Send the write disable command to the EEPROM (3-bit opcode plus
4332 * 6/8-bit dummy address beginning with 10). It's less work to include
4333 * the 10 of the dummy address as part of the opcode than it is to shift
4334 * it over the correct number of bits for the address. This takes the
4335 * EEPROM out of write/erase mode.
4336 */
4337 e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE,
4338 (u16) (eeprom->opcode_bits + 2));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004339
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004340 e1000_shift_out_ee_bits(hw, 0, (u16) (eeprom->address_bits - 2));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004341
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004342 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004343}
4344
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004345/**
4346 * e1000_read_mac_addr - read the adapters MAC from eeprom
4347 * @hw: Struct containing variables accessed by shared code
4348 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07004349 * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
4350 * second function of dual function devices
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004351 */
Joe Perches64798842008-07-11 15:17:02 -07004352s32 e1000_read_mac_addr(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004353{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004354 u16 offset;
4355 u16 eeprom_data, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004356
Emil Tantilov675ad472010-04-27 14:02:58 +00004357 e_dbg("e1000_read_mac_addr");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004358
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004359 for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
4360 offset = i >> 1;
4361 if (e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
Emil Tantilov675ad472010-04-27 14:02:58 +00004362 e_dbg("EEPROM Read Error\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004363 return -E1000_ERR_EEPROM;
4364 }
4365 hw->perm_mac_addr[i] = (u8) (eeprom_data & 0x00FF);
4366 hw->perm_mac_addr[i + 1] = (u8) (eeprom_data >> 8);
4367 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004368
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004369 switch (hw->mac_type) {
4370 default:
4371 break;
4372 case e1000_82546:
4373 case e1000_82546_rev_3:
4374 if (er32(STATUS) & E1000_STATUS_FUNC_1)
4375 hw->perm_mac_addr[5] ^= 0x01;
4376 break;
4377 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004378
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004379 for (i = 0; i < NODE_ADDRESS_SIZE; i++)
4380 hw->mac_addr[i] = hw->perm_mac_addr[i];
4381 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004382}
4383
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004384/**
4385 * e1000_init_rx_addrs - Initializes receive address filters.
4386 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -07004387 *
4388 * Places the MAC address in receive address register 0 and clears the rest
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004389 * of the receive address registers. Clears the multicast table. Assumes
Linus Torvalds1da177e2005-04-16 15:20:36 -07004390 * the receiver is in reset when the routine is called.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004391 */
Joe Perches64798842008-07-11 15:17:02 -07004392static void e1000_init_rx_addrs(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004393{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004394 u32 i;
4395 u32 rar_num;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004396
Emil Tantilov675ad472010-04-27 14:02:58 +00004397 e_dbg("e1000_init_rx_addrs");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004398
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004399 /* Setup the receive address. */
Emil Tantilov675ad472010-04-27 14:02:58 +00004400 e_dbg("Programming MAC Address into RAR[0]\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004401
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004402 e1000_rar_set(hw, hw->mac_addr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004403
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004404 rar_num = E1000_RAR_ENTRIES;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004405
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004406 /* Zero out the other 15 receive addresses. */
Emil Tantilov675ad472010-04-27 14:02:58 +00004407 e_dbg("Clearing RAR[1-15]\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004408 for (i = 1; i < rar_num; i++) {
4409 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
4410 E1000_WRITE_FLUSH();
4411 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
4412 E1000_WRITE_FLUSH();
4413 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004414}
4415
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004416/**
4417 * e1000_hash_mc_addr - Hashes an address to determine its location in the multicast table
4418 * @hw: Struct containing variables accessed by shared code
4419 * @mc_addr: the multicast address to hash
4420 */
Joe Perches64798842008-07-11 15:17:02 -07004421u32 e1000_hash_mc_addr(struct e1000_hw *hw, u8 *mc_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004422{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004423 u32 hash_value = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004424
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004425 /* The portion of the address that is used for the hash table is
4426 * determined by the mc_filter_type setting.
4427 */
4428 switch (hw->mc_filter_type) {
4429 /* [0] [1] [2] [3] [4] [5]
4430 * 01 AA 00 12 34 56
4431 * LSB MSB
4432 */
4433 case 0:
4434 /* [47:36] i.e. 0x563 for above example address */
4435 hash_value = ((mc_addr[4] >> 4) | (((u16) mc_addr[5]) << 4));
4436 break;
4437 case 1:
4438 /* [46:35] i.e. 0xAC6 for above example address */
4439 hash_value = ((mc_addr[4] >> 3) | (((u16) mc_addr[5]) << 5));
4440 break;
4441 case 2:
4442 /* [45:34] i.e. 0x5D8 for above example address */
4443 hash_value = ((mc_addr[4] >> 2) | (((u16) mc_addr[5]) << 6));
4444 break;
4445 case 3:
4446 /* [43:32] i.e. 0x634 for above example address */
4447 hash_value = ((mc_addr[4]) | (((u16) mc_addr[5]) << 8));
4448 break;
4449 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004450
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004451 hash_value &= 0xFFF;
4452 return hash_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004453}
4454
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004455/**
4456 * e1000_rar_set - Puts an ethernet address into a receive address register.
4457 * @hw: Struct containing variables accessed by shared code
4458 * @addr: Address to put into receive address register
4459 * @index: Receive address register to write
4460 */
Joe Perches64798842008-07-11 15:17:02 -07004461void e1000_rar_set(struct e1000_hw *hw, u8 *addr, u32 index)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004462{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004463 u32 rar_low, rar_high;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004464
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004465 /* HW expects these in little endian so we reverse the byte order
4466 * from network order (big endian) to little endian
4467 */
4468 rar_low = ((u32) addr[0] | ((u32) addr[1] << 8) |
4469 ((u32) addr[2] << 16) | ((u32) addr[3] << 24));
4470 rar_high = ((u32) addr[4] | ((u32) addr[5] << 8));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004471
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004472 /* Disable Rx and flush all Rx frames before enabling RSS to avoid Rx
4473 * unit hang.
4474 *
4475 * Description:
4476 * If there are any Rx frames queued up or otherwise present in the HW
4477 * before RSS is enabled, and then we enable RSS, the HW Rx unit will
4478 * hang. To work around this issue, we have to disable receives and
4479 * flush out all Rx frames before we enable RSS. To do so, we modify we
4480 * redirect all Rx traffic to manageability and then reset the HW.
4481 * This flushes away Rx frames, and (since the redirections to
4482 * manageability persists across resets) keeps new ones from coming in
4483 * while we work. Then, we clear the Address Valid AV bit for all MAC
4484 * addresses and undo the re-direction to manageability.
4485 * Now, frames are coming in again, but the MAC won't accept them, so
4486 * far so good. We now proceed to initialize RSS (if necessary) and
4487 * configure the Rx unit. Last, we re-enable the AV bits and continue
4488 * on our merry way.
4489 */
4490 switch (hw->mac_type) {
4491 default:
4492 /* Indicate to hardware the Address is Valid. */
4493 rar_high |= E1000_RAH_AV;
4494 break;
4495 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004496
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004497 E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
4498 E1000_WRITE_FLUSH();
4499 E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
4500 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07004501}
4502
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004503/**
4504 * e1000_write_vfta - Writes a value to the specified offset in the VLAN filter table.
4505 * @hw: Struct containing variables accessed by shared code
4506 * @offset: Offset in VLAN filer table to write
4507 * @value: Value to write into VLAN filter table
4508 */
Joe Perches64798842008-07-11 15:17:02 -07004509void e1000_write_vfta(struct e1000_hw *hw, u32 offset, u32 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004510{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004511 u32 temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004512
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004513 if ((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) {
4514 temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1));
4515 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
4516 E1000_WRITE_FLUSH();
4517 E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp);
4518 E1000_WRITE_FLUSH();
4519 } else {
4520 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
4521 E1000_WRITE_FLUSH();
4522 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004523}
4524
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004525/**
4526 * e1000_clear_vfta - Clears the VLAN filer table
4527 * @hw: Struct containing variables accessed by shared code
4528 */
Joe Perches64798842008-07-11 15:17:02 -07004529static void e1000_clear_vfta(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004530{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004531 u32 offset;
4532 u32 vfta_value = 0;
4533 u32 vfta_offset = 0;
4534 u32 vfta_bit_in_reg = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004535
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004536 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
4537 /* If the offset we want to clear is the same offset of the
4538 * manageability VLAN ID, then clear all bits except that of the
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00004539 * manageability unit
4540 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004541 vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0;
4542 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, vfta_value);
4543 E1000_WRITE_FLUSH();
4544 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004545}
4546
Joe Perches64798842008-07-11 15:17:02 -07004547static s32 e1000_id_led_init(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004548{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004549 u32 ledctl;
4550 const u32 ledctl_mask = 0x000000FF;
4551 const u32 ledctl_on = E1000_LEDCTL_MODE_LED_ON;
4552 const u32 ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
4553 u16 eeprom_data, i, temp;
4554 const u16 led_mask = 0x0F;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004555
Emil Tantilov675ad472010-04-27 14:02:58 +00004556 e_dbg("e1000_id_led_init");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004557
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004558 if (hw->mac_type < e1000_82540) {
4559 /* Nothing to do */
4560 return E1000_SUCCESS;
4561 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004562
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004563 ledctl = er32(LEDCTL);
4564 hw->ledctl_default = ledctl;
4565 hw->ledctl_mode1 = hw->ledctl_default;
4566 hw->ledctl_mode2 = hw->ledctl_default;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004567
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004568 if (e1000_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, 1, &eeprom_data) < 0) {
Emil Tantilov675ad472010-04-27 14:02:58 +00004569 e_dbg("EEPROM Read Error\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004570 return -E1000_ERR_EEPROM;
4571 }
Auke Kokcd94dd02006-06-27 09:08:22 -07004572
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004573 if ((eeprom_data == ID_LED_RESERVED_0000) ||
4574 (eeprom_data == ID_LED_RESERVED_FFFF)) {
4575 eeprom_data = ID_LED_DEFAULT;
4576 }
Auke Kok90fb5132006-11-01 08:47:30 -08004577
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004578 for (i = 0; i < 4; i++) {
4579 temp = (eeprom_data >> (i << 2)) & led_mask;
4580 switch (temp) {
4581 case ID_LED_ON1_DEF2:
4582 case ID_LED_ON1_ON2:
4583 case ID_LED_ON1_OFF2:
4584 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
4585 hw->ledctl_mode1 |= ledctl_on << (i << 3);
4586 break;
4587 case ID_LED_OFF1_DEF2:
4588 case ID_LED_OFF1_ON2:
4589 case ID_LED_OFF1_OFF2:
4590 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
4591 hw->ledctl_mode1 |= ledctl_off << (i << 3);
4592 break;
4593 default:
4594 /* Do nothing */
4595 break;
4596 }
4597 switch (temp) {
4598 case ID_LED_DEF1_ON2:
4599 case ID_LED_ON1_ON2:
4600 case ID_LED_OFF1_ON2:
4601 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
4602 hw->ledctl_mode2 |= ledctl_on << (i << 3);
4603 break;
4604 case ID_LED_DEF1_OFF2:
4605 case ID_LED_ON1_OFF2:
4606 case ID_LED_OFF1_OFF2:
4607 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
4608 hw->ledctl_mode2 |= ledctl_off << (i << 3);
4609 break;
4610 default:
4611 /* Do nothing */
4612 break;
4613 }
4614 }
4615 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004616}
4617
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004618/**
4619 * e1000_setup_led
4620 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -07004621 *
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004622 * Prepares SW controlable LED for use and saves the current state of the LED.
4623 */
Joe Perches64798842008-07-11 15:17:02 -07004624s32 e1000_setup_led(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004625{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004626 u32 ledctl;
4627 s32 ret_val = E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004628
Emil Tantilov675ad472010-04-27 14:02:58 +00004629 e_dbg("e1000_setup_led");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004630
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004631 switch (hw->mac_type) {
4632 case e1000_82542_rev2_0:
4633 case e1000_82542_rev2_1:
4634 case e1000_82543:
4635 case e1000_82544:
4636 /* No setup necessary */
4637 break;
4638 case e1000_82541:
4639 case e1000_82547:
4640 case e1000_82541_rev_2:
4641 case e1000_82547_rev_2:
4642 /* Turn off PHY Smart Power Down (if enabled) */
4643 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
4644 &hw->phy_spd_default);
4645 if (ret_val)
4646 return ret_val;
4647 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
4648 (u16) (hw->phy_spd_default &
4649 ~IGP01E1000_GMII_SPD));
4650 if (ret_val)
4651 return ret_val;
4652 /* Fall Through */
4653 default:
4654 if (hw->media_type == e1000_media_type_fiber) {
4655 ledctl = er32(LEDCTL);
4656 /* Save current LEDCTL settings */
4657 hw->ledctl_default = ledctl;
4658 /* Turn off LED0 */
4659 ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
4660 E1000_LEDCTL_LED0_BLINK |
4661 E1000_LEDCTL_LED0_MODE_MASK);
4662 ledctl |= (E1000_LEDCTL_MODE_LED_OFF <<
4663 E1000_LEDCTL_LED0_MODE_SHIFT);
4664 ew32(LEDCTL, ledctl);
4665 } else if (hw->media_type == e1000_media_type_copper)
4666 ew32(LEDCTL, hw->ledctl_mode1);
4667 break;
4668 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004669
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004670 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004671}
4672
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004673/**
4674 * e1000_cleanup_led - Restores the saved state of the SW controlable LED.
4675 * @hw: Struct containing variables accessed by shared code
4676 */
Joe Perches64798842008-07-11 15:17:02 -07004677s32 e1000_cleanup_led(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004678{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004679 s32 ret_val = E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004680
Emil Tantilov675ad472010-04-27 14:02:58 +00004681 e_dbg("e1000_cleanup_led");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004682
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004683 switch (hw->mac_type) {
4684 case e1000_82542_rev2_0:
4685 case e1000_82542_rev2_1:
4686 case e1000_82543:
4687 case e1000_82544:
4688 /* No cleanup necessary */
4689 break;
4690 case e1000_82541:
4691 case e1000_82547:
4692 case e1000_82541_rev_2:
4693 case e1000_82547_rev_2:
4694 /* Turn on PHY Smart Power Down (if previously enabled) */
4695 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
4696 hw->phy_spd_default);
4697 if (ret_val)
4698 return ret_val;
4699 /* Fall Through */
4700 default:
4701 /* Restore LEDCTL settings */
4702 ew32(LEDCTL, hw->ledctl_default);
4703 break;
4704 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004705
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004706 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004707}
4708
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004709/**
4710 * e1000_led_on - Turns on the software controllable LED
4711 * @hw: Struct containing variables accessed by shared code
4712 */
Joe Perches64798842008-07-11 15:17:02 -07004713s32 e1000_led_on(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004714{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004715 u32 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004716
Emil Tantilov675ad472010-04-27 14:02:58 +00004717 e_dbg("e1000_led_on");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004718
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004719 switch (hw->mac_type) {
4720 case e1000_82542_rev2_0:
4721 case e1000_82542_rev2_1:
4722 case e1000_82543:
4723 /* Set SW Defineable Pin 0 to turn on the LED */
4724 ctrl |= E1000_CTRL_SWDPIN0;
4725 ctrl |= E1000_CTRL_SWDPIO0;
4726 break;
4727 case e1000_82544:
4728 if (hw->media_type == e1000_media_type_fiber) {
4729 /* Set SW Defineable Pin 0 to turn on the LED */
4730 ctrl |= E1000_CTRL_SWDPIN0;
4731 ctrl |= E1000_CTRL_SWDPIO0;
4732 } else {
4733 /* Clear SW Defineable Pin 0 to turn on the LED */
4734 ctrl &= ~E1000_CTRL_SWDPIN0;
4735 ctrl |= E1000_CTRL_SWDPIO0;
4736 }
4737 break;
4738 default:
4739 if (hw->media_type == e1000_media_type_fiber) {
4740 /* Clear SW Defineable Pin 0 to turn on the LED */
4741 ctrl &= ~E1000_CTRL_SWDPIN0;
4742 ctrl |= E1000_CTRL_SWDPIO0;
4743 } else if (hw->media_type == e1000_media_type_copper) {
4744 ew32(LEDCTL, hw->ledctl_mode2);
4745 return E1000_SUCCESS;
4746 }
4747 break;
4748 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004749
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004750 ew32(CTRL, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004751
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004752 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004753}
4754
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004755/**
4756 * e1000_led_off - Turns off the software controllable LED
4757 * @hw: Struct containing variables accessed by shared code
4758 */
Joe Perches64798842008-07-11 15:17:02 -07004759s32 e1000_led_off(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004760{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004761 u32 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004762
Emil Tantilov675ad472010-04-27 14:02:58 +00004763 e_dbg("e1000_led_off");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004764
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004765 switch (hw->mac_type) {
4766 case e1000_82542_rev2_0:
4767 case e1000_82542_rev2_1:
4768 case e1000_82543:
4769 /* Clear SW Defineable Pin 0 to turn off the LED */
4770 ctrl &= ~E1000_CTRL_SWDPIN0;
4771 ctrl |= E1000_CTRL_SWDPIO0;
4772 break;
4773 case e1000_82544:
4774 if (hw->media_type == e1000_media_type_fiber) {
4775 /* Clear SW Defineable Pin 0 to turn off the LED */
4776 ctrl &= ~E1000_CTRL_SWDPIN0;
4777 ctrl |= E1000_CTRL_SWDPIO0;
4778 } else {
4779 /* Set SW Defineable Pin 0 to turn off the LED */
4780 ctrl |= E1000_CTRL_SWDPIN0;
4781 ctrl |= E1000_CTRL_SWDPIO0;
4782 }
4783 break;
4784 default:
4785 if (hw->media_type == e1000_media_type_fiber) {
4786 /* Set SW Defineable Pin 0 to turn off the LED */
4787 ctrl |= E1000_CTRL_SWDPIN0;
4788 ctrl |= E1000_CTRL_SWDPIO0;
4789 } else if (hw->media_type == e1000_media_type_copper) {
4790 ew32(LEDCTL, hw->ledctl_mode1);
4791 return E1000_SUCCESS;
4792 }
4793 break;
4794 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004795
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004796 ew32(CTRL, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004797
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004798 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004799}
4800
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004801/**
4802 * e1000_clear_hw_cntrs - Clears all hardware statistics counters.
4803 * @hw: Struct containing variables accessed by shared code
4804 */
Joe Perches64798842008-07-11 15:17:02 -07004805static void e1000_clear_hw_cntrs(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004806{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004807 volatile u32 temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004808
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004809 temp = er32(CRCERRS);
4810 temp = er32(SYMERRS);
4811 temp = er32(MPC);
4812 temp = er32(SCC);
4813 temp = er32(ECOL);
4814 temp = er32(MCC);
4815 temp = er32(LATECOL);
4816 temp = er32(COLC);
4817 temp = er32(DC);
4818 temp = er32(SEC);
4819 temp = er32(RLEC);
4820 temp = er32(XONRXC);
4821 temp = er32(XONTXC);
4822 temp = er32(XOFFRXC);
4823 temp = er32(XOFFTXC);
4824 temp = er32(FCRUC);
Auke Kokcd94dd02006-06-27 09:08:22 -07004825
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004826 temp = er32(PRC64);
4827 temp = er32(PRC127);
4828 temp = er32(PRC255);
4829 temp = er32(PRC511);
4830 temp = er32(PRC1023);
4831 temp = er32(PRC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07004832
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004833 temp = er32(GPRC);
4834 temp = er32(BPRC);
4835 temp = er32(MPRC);
4836 temp = er32(GPTC);
4837 temp = er32(GORCL);
4838 temp = er32(GORCH);
4839 temp = er32(GOTCL);
4840 temp = er32(GOTCH);
4841 temp = er32(RNBC);
4842 temp = er32(RUC);
4843 temp = er32(RFC);
4844 temp = er32(ROC);
4845 temp = er32(RJC);
4846 temp = er32(TORL);
4847 temp = er32(TORH);
4848 temp = er32(TOTL);
4849 temp = er32(TOTH);
4850 temp = er32(TPR);
4851 temp = er32(TPT);
Auke Kokcd94dd02006-06-27 09:08:22 -07004852
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004853 temp = er32(PTC64);
4854 temp = er32(PTC127);
4855 temp = er32(PTC255);
4856 temp = er32(PTC511);
4857 temp = er32(PTC1023);
4858 temp = er32(PTC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07004859
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004860 temp = er32(MPTC);
4861 temp = er32(BPTC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004862
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004863 if (hw->mac_type < e1000_82543)
4864 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004865
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004866 temp = er32(ALGNERRC);
4867 temp = er32(RXERRC);
4868 temp = er32(TNCRS);
4869 temp = er32(CEXTERR);
4870 temp = er32(TSCTC);
4871 temp = er32(TSCTFC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004872
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004873 if (hw->mac_type <= e1000_82544)
4874 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004875
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004876 temp = er32(MGTPRC);
4877 temp = er32(MGTPDC);
4878 temp = er32(MGTPTC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004879}
4880
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004881/**
4882 * e1000_reset_adaptive - Resets Adaptive IFS to its default state.
4883 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -07004884 *
4885 * Call this after e1000_init_hw. You may override the IFS defaults by setting
Joe Perchesc3033b02008-03-21 11:06:25 -07004886 * hw->ifs_params_forced to true. However, you must initialize hw->
Linus Torvalds1da177e2005-04-16 15:20:36 -07004887 * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio
4888 * before calling this function.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004889 */
Joe Perches64798842008-07-11 15:17:02 -07004890void e1000_reset_adaptive(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004891{
Emil Tantilov675ad472010-04-27 14:02:58 +00004892 e_dbg("e1000_reset_adaptive");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004893
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004894 if (hw->adaptive_ifs) {
4895 if (!hw->ifs_params_forced) {
4896 hw->current_ifs_val = 0;
4897 hw->ifs_min_val = IFS_MIN;
4898 hw->ifs_max_val = IFS_MAX;
4899 hw->ifs_step_size = IFS_STEP;
4900 hw->ifs_ratio = IFS_RATIO;
4901 }
4902 hw->in_ifs_mode = false;
4903 ew32(AIT, 0);
4904 } else {
Emil Tantilov675ad472010-04-27 14:02:58 +00004905 e_dbg("Not in Adaptive IFS mode!\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004906 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004907}
4908
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004909/**
4910 * e1000_update_adaptive - update adaptive IFS
4911 * @hw: Struct containing variables accessed by shared code
4912 * @tx_packets: Number of transmits since last callback
4913 * @total_collisions: Number of collisions since last callback
4914 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07004915 * Called during the callback/watchdog routine to update IFS value based on
4916 * the ratio of transmits to collisions.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004917 */
Joe Perches64798842008-07-11 15:17:02 -07004918void e1000_update_adaptive(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004919{
Emil Tantilov675ad472010-04-27 14:02:58 +00004920 e_dbg("e1000_update_adaptive");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004921
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004922 if (hw->adaptive_ifs) {
4923 if ((hw->collision_delta *hw->ifs_ratio) > hw->tx_packet_delta) {
4924 if (hw->tx_packet_delta > MIN_NUM_XMITS) {
4925 hw->in_ifs_mode = true;
4926 if (hw->current_ifs_val < hw->ifs_max_val) {
4927 if (hw->current_ifs_val == 0)
4928 hw->current_ifs_val =
4929 hw->ifs_min_val;
4930 else
4931 hw->current_ifs_val +=
4932 hw->ifs_step_size;
4933 ew32(AIT, hw->current_ifs_val);
4934 }
4935 }
4936 } else {
4937 if (hw->in_ifs_mode
4938 && (hw->tx_packet_delta <= MIN_NUM_XMITS)) {
4939 hw->current_ifs_val = 0;
4940 hw->in_ifs_mode = false;
4941 ew32(AIT, 0);
4942 }
4943 }
4944 } else {
Emil Tantilov675ad472010-04-27 14:02:58 +00004945 e_dbg("Not in Adaptive IFS mode!\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004946 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004947}
4948
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004949/**
4950 * e1000_tbi_adjust_stats
4951 * @hw: Struct containing variables accessed by shared code
4952 * @frame_len: The length of the frame in question
4953 * @mac_addr: The Ethernet destination address of the frame in question
Linus Torvalds1da177e2005-04-16 15:20:36 -07004954 *
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004955 * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT
4956 */
Joe Perches64798842008-07-11 15:17:02 -07004957void e1000_tbi_adjust_stats(struct e1000_hw *hw, struct e1000_hw_stats *stats,
4958 u32 frame_len, u8 *mac_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004959{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004960 u64 carry_bit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004961
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004962 /* First adjust the frame length. */
4963 frame_len--;
4964 /* We need to adjust the statistics counters, since the hardware
4965 * counters overcount this packet as a CRC error and undercount
4966 * the packet as a good packet
4967 */
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00004968 /* This packet should not be counted as a CRC error. */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004969 stats->crcerrs--;
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00004970 /* This packet does count as a Good Packet Received. */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004971 stats->gprc++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004972
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00004973 /* Adjust the Good Octets received counters */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004974 carry_bit = 0x80000000 & stats->gorcl;
4975 stats->gorcl += frame_len;
4976 /* If the high bit of Gorcl (the low 32 bits of the Good Octets
4977 * Received Count) was one before the addition,
4978 * AND it is zero after, then we lost the carry out,
4979 * need to add one to Gorch (Good Octets Received Count High).
4980 * This could be simplified if all environments supported
4981 * 64-bit integers.
4982 */
4983 if (carry_bit && ((stats->gorcl & 0x80000000) == 0))
4984 stats->gorch++;
4985 /* Is this a broadcast or multicast? Check broadcast first,
4986 * since the test for a multicast frame will test positive on
4987 * a broadcast frame.
4988 */
4989 if ((mac_addr[0] == (u8) 0xff) && (mac_addr[1] == (u8) 0xff))
4990 /* Broadcast packet */
4991 stats->bprc++;
4992 else if (*mac_addr & 0x01)
4993 /* Multicast packet */
4994 stats->mprc++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004995
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004996 if (frame_len == hw->max_frame_size) {
4997 /* In this case, the hardware has overcounted the number of
4998 * oversize frames.
4999 */
5000 if (stats->roc > 0)
5001 stats->roc--;
5002 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005003
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005004 /* Adjust the bin counters when the extra byte put the frame in the
5005 * wrong bin. Remember that the frame_len was adjusted above.
5006 */
5007 if (frame_len == 64) {
5008 stats->prc64++;
5009 stats->prc127--;
5010 } else if (frame_len == 127) {
5011 stats->prc127++;
5012 stats->prc255--;
5013 } else if (frame_len == 255) {
5014 stats->prc255++;
5015 stats->prc511--;
5016 } else if (frame_len == 511) {
5017 stats->prc511++;
5018 stats->prc1023--;
5019 } else if (frame_len == 1023) {
5020 stats->prc1023++;
5021 stats->prc1522--;
5022 } else if (frame_len == 1522) {
5023 stats->prc1522++;
5024 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005025}
5026
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005027/**
5028 * e1000_get_bus_info
5029 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -07005030 *
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005031 * Gets the current PCI bus type, speed, and width of the hardware
5032 */
Joe Perches64798842008-07-11 15:17:02 -07005033void e1000_get_bus_info(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005034{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005035 u32 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005036
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005037 switch (hw->mac_type) {
5038 case e1000_82542_rev2_0:
5039 case e1000_82542_rev2_1:
5040 hw->bus_type = e1000_bus_type_pci;
5041 hw->bus_speed = e1000_bus_speed_unknown;
5042 hw->bus_width = e1000_bus_width_unknown;
5043 break;
5044 default:
5045 status = er32(STATUS);
5046 hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
5047 e1000_bus_type_pcix : e1000_bus_type_pci;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005048
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005049 if (hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) {
5050 hw->bus_speed = (hw->bus_type == e1000_bus_type_pci) ?
5051 e1000_bus_speed_66 : e1000_bus_speed_120;
5052 } else if (hw->bus_type == e1000_bus_type_pci) {
5053 hw->bus_speed = (status & E1000_STATUS_PCI66) ?
5054 e1000_bus_speed_66 : e1000_bus_speed_33;
5055 } else {
5056 switch (status & E1000_STATUS_PCIX_SPEED) {
5057 case E1000_STATUS_PCIX_SPEED_66:
5058 hw->bus_speed = e1000_bus_speed_66;
5059 break;
5060 case E1000_STATUS_PCIX_SPEED_100:
5061 hw->bus_speed = e1000_bus_speed_100;
5062 break;
5063 case E1000_STATUS_PCIX_SPEED_133:
5064 hw->bus_speed = e1000_bus_speed_133;
5065 break;
5066 default:
5067 hw->bus_speed = e1000_bus_speed_reserved;
5068 break;
5069 }
5070 }
5071 hw->bus_width = (status & E1000_STATUS_BUS64) ?
5072 e1000_bus_width_64 : e1000_bus_width_32;
5073 break;
5074 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005075}
Linus Torvalds1da177e2005-04-16 15:20:36 -07005076
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005077/**
5078 * e1000_write_reg_io
5079 * @hw: Struct containing variables accessed by shared code
5080 * @offset: offset to write to
5081 * @value: value to write
5082 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07005083 * Writes a value to one of the devices registers using port I/O (as opposed to
5084 * memory mapped I/O). Only 82544 and newer devices support port I/O.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005085 */
Joe Perches64798842008-07-11 15:17:02 -07005086static void e1000_write_reg_io(struct e1000_hw *hw, u32 offset, u32 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005087{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005088 unsigned long io_addr = hw->io_base;
5089 unsigned long io_data = hw->io_base + 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005090
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005091 e1000_io_write(hw, io_addr, offset);
5092 e1000_io_write(hw, io_data, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005093}
5094
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005095/**
5096 * e1000_get_cable_length - Estimates the cable length.
5097 * @hw: Struct containing variables accessed by shared code
5098 * @min_length: The estimated minimum length
5099 * @max_length: The estimated maximum length
Linus Torvalds1da177e2005-04-16 15:20:36 -07005100 *
5101 * returns: - E1000_ERR_XXX
5102 * E1000_SUCCESS
5103 *
5104 * This function always returns a ranged length (minimum & maximum).
5105 * So for M88 phy's, this function interprets the one value returned from the
5106 * register to the minimum and maximum range.
5107 * For IGP phy's, the function calculates the range by the AGC registers.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005108 */
Joe Perches64798842008-07-11 15:17:02 -07005109static s32 e1000_get_cable_length(struct e1000_hw *hw, u16 *min_length,
5110 u16 *max_length)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005111{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005112 s32 ret_val;
5113 u16 agc_value = 0;
5114 u16 i, phy_data;
5115 u16 cable_length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005116
Emil Tantilov675ad472010-04-27 14:02:58 +00005117 e_dbg("e1000_get_cable_length");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005118
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005119 *min_length = *max_length = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005120
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005121 /* Use old method for Phy older than IGP */
5122 if (hw->phy_type == e1000_phy_m88) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005123
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005124 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
5125 &phy_data);
5126 if (ret_val)
5127 return ret_val;
5128 cable_length = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
5129 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005130
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005131 /* Convert the enum value to ranged values */
5132 switch (cable_length) {
5133 case e1000_cable_length_50:
5134 *min_length = 0;
5135 *max_length = e1000_igp_cable_length_50;
5136 break;
5137 case e1000_cable_length_50_80:
5138 *min_length = e1000_igp_cable_length_50;
5139 *max_length = e1000_igp_cable_length_80;
5140 break;
5141 case e1000_cable_length_80_110:
5142 *min_length = e1000_igp_cable_length_80;
5143 *max_length = e1000_igp_cable_length_110;
5144 break;
5145 case e1000_cable_length_110_140:
5146 *min_length = e1000_igp_cable_length_110;
5147 *max_length = e1000_igp_cable_length_140;
5148 break;
5149 case e1000_cable_length_140:
5150 *min_length = e1000_igp_cable_length_140;
5151 *max_length = e1000_igp_cable_length_170;
5152 break;
5153 default:
5154 return -E1000_ERR_PHY;
5155 break;
5156 }
5157 } else if (hw->phy_type == e1000_phy_igp) { /* For IGP PHY */
5158 u16 cur_agc_value;
5159 u16 min_agc_value = IGP01E1000_AGC_LENGTH_TABLE_SIZE;
Jeff Kirsher66744502010-12-01 19:59:50 +00005160 static const u16 agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] = {
5161 IGP01E1000_PHY_AGC_A,
5162 IGP01E1000_PHY_AGC_B,
5163 IGP01E1000_PHY_AGC_C,
5164 IGP01E1000_PHY_AGC_D
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005165 };
5166 /* Read the AGC registers for all channels */
5167 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005168
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005169 ret_val =
5170 e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
5171 if (ret_val)
5172 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005173
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005174 cur_agc_value = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005175
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005176 /* Value bound check. */
5177 if ((cur_agc_value >=
5178 IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1)
5179 || (cur_agc_value == 0))
5180 return -E1000_ERR_PHY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005181
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005182 agc_value += cur_agc_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005183
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005184 /* Update minimal AGC value. */
5185 if (min_agc_value > cur_agc_value)
5186 min_agc_value = cur_agc_value;
5187 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005188
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005189 /* Remove the minimal AGC result for length < 50m */
5190 if (agc_value <
5191 IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) {
5192 agc_value -= min_agc_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005193
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005194 /* Get the average length of the remaining 3 channels */
5195 agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1);
5196 } else {
5197 /* Get the average length of all the 4 channels. */
5198 agc_value /= IGP01E1000_PHY_CHANNEL_NUM;
5199 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005200
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005201 /* Set the range of the calculated length. */
5202 *min_length = ((e1000_igp_cable_length_table[agc_value] -
5203 IGP01E1000_AGC_RANGE) > 0) ?
5204 (e1000_igp_cable_length_table[agc_value] -
5205 IGP01E1000_AGC_RANGE) : 0;
5206 *max_length = e1000_igp_cable_length_table[agc_value] +
5207 IGP01E1000_AGC_RANGE;
5208 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005209
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005210 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005211}
5212
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005213/**
5214 * e1000_check_polarity - Check the cable polarity
5215 * @hw: Struct containing variables accessed by shared code
5216 * @polarity: output parameter : 0 - Polarity is not reversed
Linus Torvalds1da177e2005-04-16 15:20:36 -07005217 * 1 - Polarity is reversed.
5218 *
5219 * returns: - E1000_ERR_XXX
5220 * E1000_SUCCESS
5221 *
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02005222 * For phy's older than IGP, this function simply reads the polarity bit in the
Linus Torvalds1da177e2005-04-16 15:20:36 -07005223 * Phy Status register. For IGP phy's, this bit is valid only if link speed is
5224 * 10 Mbps. If the link speed is 100 Mbps there is no polarity so this bit will
5225 * return 0. If the link speed is 1000 Mbps the polarity status is in the
5226 * IGP01E1000_PHY_PCS_INIT_REG.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005227 */
Joe Perches64798842008-07-11 15:17:02 -07005228static s32 e1000_check_polarity(struct e1000_hw *hw,
5229 e1000_rev_polarity *polarity)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005230{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005231 s32 ret_val;
5232 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005233
Emil Tantilov675ad472010-04-27 14:02:58 +00005234 e_dbg("e1000_check_polarity");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005235
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005236 if (hw->phy_type == e1000_phy_m88) {
5237 /* return the Polarity bit in the Status register. */
5238 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
5239 &phy_data);
5240 if (ret_val)
5241 return ret_val;
5242 *polarity = ((phy_data & M88E1000_PSSR_REV_POLARITY) >>
5243 M88E1000_PSSR_REV_POLARITY_SHIFT) ?
5244 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07005245
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005246 } else if (hw->phy_type == e1000_phy_igp) {
5247 /* Read the Status register to check the speed */
5248 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
5249 &phy_data);
5250 if (ret_val)
5251 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005252
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00005253 /* If speed is 1000 Mbps, must read the
5254 * IGP01E1000_PHY_PCS_INIT_REG to find the polarity status
5255 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005256 if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
5257 IGP01E1000_PSSR_SPEED_1000MBPS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005258
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005259 /* Read the GIG initialization PCS register (0x00B4) */
5260 ret_val =
5261 e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG,
5262 &phy_data);
5263 if (ret_val)
5264 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005265
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005266 /* Check the polarity bits */
5267 *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ?
5268 e1000_rev_polarity_reversed :
5269 e1000_rev_polarity_normal;
5270 } else {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00005271 /* For 10 Mbps, read the polarity bit in the status
5272 * register. (for 100 Mbps this bit is always 0)
5273 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005274 *polarity =
5275 (phy_data & IGP01E1000_PSSR_POLARITY_REVERSED) ?
5276 e1000_rev_polarity_reversed :
5277 e1000_rev_polarity_normal;
5278 }
5279 }
5280 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005281}
5282
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005283/**
5284 * e1000_check_downshift - Check if Downshift occurred
5285 * @hw: Struct containing variables accessed by shared code
5286 * @downshift: output parameter : 0 - No Downshift occurred.
5287 * 1 - Downshift occurred.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005288 *
5289 * returns: - E1000_ERR_XXX
Auke Kok76c224b2006-05-23 13:36:06 -07005290 * E1000_SUCCESS
Linus Torvalds1da177e2005-04-16 15:20:36 -07005291 *
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02005292 * For phy's older than IGP, this function reads the Downshift bit in the Phy
Linus Torvalds1da177e2005-04-16 15:20:36 -07005293 * Specific Status register. For IGP phy's, it reads the Downgrade bit in the
5294 * Link Health register. In IGP this bit is latched high, so the driver must
5295 * read it immediately after link is established.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005296 */
Joe Perches64798842008-07-11 15:17:02 -07005297static s32 e1000_check_downshift(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005298{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005299 s32 ret_val;
5300 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005301
Emil Tantilov675ad472010-04-27 14:02:58 +00005302 e_dbg("e1000_check_downshift");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005303
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005304 if (hw->phy_type == e1000_phy_igp) {
5305 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH,
5306 &phy_data);
5307 if (ret_val)
5308 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005309
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005310 hw->speed_downgraded =
5311 (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0;
5312 } else if (hw->phy_type == e1000_phy_m88) {
5313 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
5314 &phy_data);
5315 if (ret_val)
5316 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005317
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005318 hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >>
5319 M88E1000_PSSR_DOWNSHIFT_SHIFT;
5320 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005321
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005322 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005323}
5324
Joe Perches542c3f42012-02-10 12:07:36 +00005325static const u16 dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] = {
5326 IGP01E1000_PHY_AGC_PARAM_A,
5327 IGP01E1000_PHY_AGC_PARAM_B,
5328 IGP01E1000_PHY_AGC_PARAM_C,
5329 IGP01E1000_PHY_AGC_PARAM_D
5330};
5331
5332static s32 e1000_1000Mb_check_cable_length(struct e1000_hw *hw)
5333{
5334 u16 min_length, max_length;
5335 u16 phy_data, i;
5336 s32 ret_val;
5337
5338 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
5339 if (ret_val)
5340 return ret_val;
5341
5342 if (hw->dsp_config_state != e1000_dsp_config_enabled)
5343 return 0;
5344
5345 if (min_length >= e1000_igp_cable_length_50) {
5346 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
5347 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i],
5348 &phy_data);
5349 if (ret_val)
5350 return ret_val;
5351
5352 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
5353
5354 ret_val = e1000_write_phy_reg(hw, dsp_reg_array[i],
5355 phy_data);
5356 if (ret_val)
5357 return ret_val;
5358 }
5359 hw->dsp_config_state = e1000_dsp_config_activated;
5360 } else {
5361 u16 ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_20;
5362 u32 idle_errs = 0;
5363
5364 /* clear previous idle error counts */
5365 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
5366 if (ret_val)
5367 return ret_val;
5368
5369 for (i = 0; i < ffe_idle_err_timeout; i++) {
5370 udelay(1000);
5371 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
5372 &phy_data);
5373 if (ret_val)
5374 return ret_val;
5375
5376 idle_errs += (phy_data & SR_1000T_IDLE_ERROR_CNT);
5377 if (idle_errs > SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT) {
5378 hw->ffe_config_state = e1000_ffe_config_active;
5379
5380 ret_val = e1000_write_phy_reg(hw,
5381 IGP01E1000_PHY_DSP_FFE,
5382 IGP01E1000_PHY_DSP_FFE_CM_CP);
5383 if (ret_val)
5384 return ret_val;
5385 break;
5386 }
5387
5388 if (idle_errs)
5389 ffe_idle_err_timeout =
5390 FFE_IDLE_ERR_COUNT_TIMEOUT_100;
5391 }
5392 }
5393
5394 return 0;
5395}
5396
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005397/**
5398 * e1000_config_dsp_after_link_change
5399 * @hw: Struct containing variables accessed by shared code
5400 * @link_up: was link up at the time this was called
5401 *
5402 * returns: - E1000_ERR_PHY if fail to read/write the PHY
5403 * E1000_SUCCESS at any other case.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005404 *
5405 * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a
5406 * gigabit link is achieved to improve link quality.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005407 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005408
Joe Perches64798842008-07-11 15:17:02 -07005409static s32 e1000_config_dsp_after_link_change(struct e1000_hw *hw, bool link_up)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005410{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005411 s32 ret_val;
5412 u16 phy_data, phy_saved_data, speed, duplex, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005413
Emil Tantilov675ad472010-04-27 14:02:58 +00005414 e_dbg("e1000_config_dsp_after_link_change");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005415
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005416 if (hw->phy_type != e1000_phy_igp)
5417 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005418
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005419 if (link_up) {
5420 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
5421 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00005422 e_dbg("Error getting link speed and duplex\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005423 return ret_val;
5424 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005425
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005426 if (speed == SPEED_1000) {
Joe Perches542c3f42012-02-10 12:07:36 +00005427 ret_val = e1000_1000Mb_check_cable_length(hw);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005428 if (ret_val)
5429 return ret_val;
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005430 }
5431 } else {
5432 if (hw->dsp_config_state == e1000_dsp_config_activated) {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00005433 /* Save off the current value of register 0x2F5B to be
5434 * restored at the end of the routines.
5435 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005436 ret_val =
5437 e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005438
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005439 if (ret_val)
5440 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005441
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005442 /* Disable the PHY transmitter */
5443 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005444
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005445 if (ret_val)
5446 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005447
Jesse Brandeburg4e0d8f7d2011-10-05 07:24:46 +00005448 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005449
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005450 ret_val = e1000_write_phy_reg(hw, 0x0000,
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00005451 IGP01E1000_IEEE_FORCE_GIGA);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005452 if (ret_val)
5453 return ret_val;
5454 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
5455 ret_val =
5456 e1000_read_phy_reg(hw, dsp_reg_array[i],
5457 &phy_data);
5458 if (ret_val)
5459 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005460
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005461 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
5462 phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005463
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005464 ret_val =
5465 e1000_write_phy_reg(hw, dsp_reg_array[i],
5466 phy_data);
5467 if (ret_val)
5468 return ret_val;
5469 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005470
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005471 ret_val = e1000_write_phy_reg(hw, 0x0000,
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00005472 IGP01E1000_IEEE_RESTART_AUTONEG);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005473 if (ret_val)
5474 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005475
Jesse Brandeburg4e0d8f7d2011-10-05 07:24:46 +00005476 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005477
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005478 /* Now enable the transmitter */
5479 ret_val =
5480 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005481
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005482 if (ret_val)
5483 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005484
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005485 hw->dsp_config_state = e1000_dsp_config_enabled;
5486 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005487
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005488 if (hw->ffe_config_state == e1000_ffe_config_active) {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00005489 /* Save off the current value of register 0x2F5B to be
5490 * restored at the end of the routines.
5491 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005492 ret_val =
5493 e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005494
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005495 if (ret_val)
5496 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005497
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005498 /* Disable the PHY transmitter */
5499 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005500
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005501 if (ret_val)
5502 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005503
Jesse Brandeburg4e0d8f7d2011-10-05 07:24:46 +00005504 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005505
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005506 ret_val = e1000_write_phy_reg(hw, 0x0000,
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00005507 IGP01E1000_IEEE_FORCE_GIGA);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005508 if (ret_val)
5509 return ret_val;
5510 ret_val =
5511 e1000_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE,
5512 IGP01E1000_PHY_DSP_FFE_DEFAULT);
5513 if (ret_val)
5514 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005515
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005516 ret_val = e1000_write_phy_reg(hw, 0x0000,
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00005517 IGP01E1000_IEEE_RESTART_AUTONEG);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005518 if (ret_val)
5519 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005520
Jesse Brandeburg4e0d8f7d2011-10-05 07:24:46 +00005521 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005522
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005523 /* Now enable the transmitter */
5524 ret_val =
5525 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005526
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005527 if (ret_val)
5528 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005529
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005530 hw->ffe_config_state = e1000_ffe_config_enabled;
5531 }
5532 }
5533 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005534}
5535
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005536/**
5537 * e1000_set_phy_mode - Set PHY to class A mode
5538 * @hw: Struct containing variables accessed by shared code
5539 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07005540 * Assumes the following operations will follow to enable the new class mode.
5541 * 1. Do a PHY soft reset
5542 * 2. Restart auto-negotiation or force link.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005543 */
Joe Perches64798842008-07-11 15:17:02 -07005544static s32 e1000_set_phy_mode(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005545{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005546 s32 ret_val;
5547 u16 eeprom_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005548
Emil Tantilov675ad472010-04-27 14:02:58 +00005549 e_dbg("e1000_set_phy_mode");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005550
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005551 if ((hw->mac_type == e1000_82545_rev_3) &&
5552 (hw->media_type == e1000_media_type_copper)) {
5553 ret_val =
5554 e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, 1,
5555 &eeprom_data);
5556 if (ret_val) {
5557 return ret_val;
5558 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005559
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005560 if ((eeprom_data != EEPROM_RESERVED_WORD) &&
5561 (eeprom_data & EEPROM_PHY_CLASS_A)) {
5562 ret_val =
5563 e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT,
5564 0x000B);
5565 if (ret_val)
5566 return ret_val;
5567 ret_val =
5568 e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL,
5569 0x8104);
5570 if (ret_val)
5571 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005572
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005573 hw->phy_reset_disable = false;
5574 }
5575 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005576
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005577 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005578}
5579
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005580/**
5581 * e1000_set_d3_lplu_state - set d3 link power state
5582 * @hw: Struct containing variables accessed by shared code
5583 * @active: true to enable lplu false to disable lplu.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005584 *
5585 * This function sets the lplu state according to the active flag. When
5586 * activating lplu this function also disables smart speed and vise versa.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005587 * lplu will not be activated unless the device autonegotiation advertisement
Linus Torvalds1da177e2005-04-16 15:20:36 -07005588 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005589 *
5590 * returns: - E1000_ERR_PHY if fail to read/write the PHY
5591 * E1000_SUCCESS at any other case.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005592 */
Joe Perches64798842008-07-11 15:17:02 -07005593static s32 e1000_set_d3_lplu_state(struct e1000_hw *hw, bool active)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005594{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005595 s32 ret_val;
5596 u16 phy_data;
Emil Tantilov675ad472010-04-27 14:02:58 +00005597 e_dbg("e1000_set_d3_lplu_state");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005598
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005599 if (hw->phy_type != e1000_phy_igp)
5600 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005601
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005602 /* During driver activity LPLU should not be used or it will attain link
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00005603 * from the lowest speeds starting from 10Mbps. The capability is used
5604 * for Dx transitions and states
5605 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005606 if (hw->mac_type == e1000_82541_rev_2
5607 || hw->mac_type == e1000_82547_rev_2) {
5608 ret_val =
5609 e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data);
5610 if (ret_val)
5611 return ret_val;
5612 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005613
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005614 if (!active) {
5615 if (hw->mac_type == e1000_82541_rev_2 ||
5616 hw->mac_type == e1000_82547_rev_2) {
5617 phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
5618 ret_val =
5619 e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
5620 phy_data);
5621 if (ret_val)
5622 return ret_val;
5623 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005624
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00005625 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
5626 * during Dx states where the power conservation is most
5627 * important. During driver activity we should enable
5628 * SmartSpeed, so performance is maintained.
5629 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005630 if (hw->smart_speed == e1000_smart_speed_on) {
5631 ret_val =
5632 e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5633 &phy_data);
5634 if (ret_val)
5635 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005636
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005637 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
5638 ret_val =
5639 e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5640 phy_data);
5641 if (ret_val)
5642 return ret_val;
5643 } else if (hw->smart_speed == e1000_smart_speed_off) {
5644 ret_val =
5645 e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5646 &phy_data);
5647 if (ret_val)
5648 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005649
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005650 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
5651 ret_val =
5652 e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5653 phy_data);
5654 if (ret_val)
5655 return ret_val;
5656 }
5657 } else if ((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT)
5658 || (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL)
5659 || (hw->autoneg_advertised ==
5660 AUTONEG_ADVERTISE_10_100_ALL)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005661
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005662 if (hw->mac_type == e1000_82541_rev_2 ||
5663 hw->mac_type == e1000_82547_rev_2) {
5664 phy_data |= IGP01E1000_GMII_FLEX_SPD;
5665 ret_val =
5666 e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
5667 phy_data);
5668 if (ret_val)
5669 return ret_val;
5670 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005671
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005672 /* When LPLU is enabled we should disable SmartSpeed */
5673 ret_val =
5674 e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5675 &phy_data);
5676 if (ret_val)
5677 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005678
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005679 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
5680 ret_val =
5681 e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5682 phy_data);
5683 if (ret_val)
5684 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005685
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005686 }
5687 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005688}
5689
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005690/**
5691 * e1000_set_vco_speed
5692 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -07005693 *
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005694 * Change VCO speed register to improve Bit Error Rate performance of SERDES.
5695 */
Joe Perches64798842008-07-11 15:17:02 -07005696static s32 e1000_set_vco_speed(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005697{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005698 s32 ret_val;
5699 u16 default_page = 0;
5700 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005701
Emil Tantilov675ad472010-04-27 14:02:58 +00005702 e_dbg("e1000_set_vco_speed");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005703
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005704 switch (hw->mac_type) {
5705 case e1000_82545_rev_3:
5706 case e1000_82546_rev_3:
5707 break;
5708 default:
5709 return E1000_SUCCESS;
5710 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005711
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005712 /* Set PHY register 30, page 5, bit 8 to 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005713
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005714 ret_val =
5715 e1000_read_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, &default_page);
5716 if (ret_val)
5717 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005718
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005719 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005);
5720 if (ret_val)
5721 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005722
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005723 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
5724 if (ret_val)
5725 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005726
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005727 phy_data &= ~M88E1000_PHY_VCO_REG_BIT8;
5728 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
5729 if (ret_val)
5730 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005731
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005732 /* Set PHY register 30, page 4, bit 11 to 1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005733
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005734 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004);
5735 if (ret_val)
5736 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005737
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005738 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
5739 if (ret_val)
5740 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005741
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005742 phy_data |= M88E1000_PHY_VCO_REG_BIT11;
5743 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
5744 if (ret_val)
5745 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005746
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005747 ret_val =
5748 e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, default_page);
5749 if (ret_val)
5750 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005751
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005752 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005753}
5754
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005755
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005756/**
5757 * e1000_enable_mng_pass_thru - check for bmc pass through
5758 * @hw: Struct containing variables accessed by shared code
5759 *
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005760 * Verifies the hardware needs to allow ARPs to be processed by the host
Joe Perchesc3033b02008-03-21 11:06:25 -07005761 * returns: - true/false
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005762 */
Joe Perches64798842008-07-11 15:17:02 -07005763u32 e1000_enable_mng_pass_thru(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005764{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005765 u32 manc;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005766
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005767 if (hw->asf_firmware_present) {
5768 manc = er32(MANC);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005769
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005770 if (!(manc & E1000_MANC_RCV_TCO_EN) ||
5771 !(manc & E1000_MANC_EN_MAC_ADDR_FILTER))
5772 return false;
5773 if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN))
5774 return true;
5775 }
5776 return false;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005777}
5778
Joe Perches64798842008-07-11 15:17:02 -07005779static s32 e1000_polarity_reversal_workaround(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005780{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005781 s32 ret_val;
5782 u16 mii_status_reg;
5783 u16 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005784
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005785 /* Polarity reversal workaround for forced 10F/10H links. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005786
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005787 /* Disable the transmitter on the PHY */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005788
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005789 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
5790 if (ret_val)
5791 return ret_val;
5792 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF);
5793 if (ret_val)
5794 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005795
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005796 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
5797 if (ret_val)
5798 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005799
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005800 /* This loop will early-out if the NO link condition has been met. */
5801 for (i = PHY_FORCE_TIME; i > 0; i--) {
5802 /* Read the MII Status Register and wait for Link Status bit
5803 * to be clear.
5804 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005805
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005806 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
5807 if (ret_val)
5808 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005809
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005810 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
5811 if (ret_val)
5812 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005813
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005814 if ((mii_status_reg & ~MII_SR_LINK_STATUS) == 0)
5815 break;
Jesse Brandeburg4e0d8f7d2011-10-05 07:24:46 +00005816 msleep(100);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005817 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005818
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005819 /* Recommended delay time after link has been lost */
Jesse Brandeburg4e0d8f7d2011-10-05 07:24:46 +00005820 msleep(1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005821
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005822 /* Now we will re-enable th transmitter on the PHY */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005823
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005824 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
5825 if (ret_val)
5826 return ret_val;
Jesse Brandeburg4e0d8f7d2011-10-05 07:24:46 +00005827 msleep(50);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005828 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0);
5829 if (ret_val)
5830 return ret_val;
Jesse Brandeburg4e0d8f7d2011-10-05 07:24:46 +00005831 msleep(50);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005832 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00);
5833 if (ret_val)
5834 return ret_val;
Jesse Brandeburg4e0d8f7d2011-10-05 07:24:46 +00005835 msleep(50);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005836 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000);
5837 if (ret_val)
5838 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005839
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005840 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
5841 if (ret_val)
5842 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005843
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005844 /* This loop will early-out if the link condition has been met. */
5845 for (i = PHY_FORCE_TIME; i > 0; i--) {
5846 /* Read the MII Status Register and wait for Link Status bit
5847 * to be set.
5848 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005849
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005850 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
5851 if (ret_val)
5852 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005853
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005854 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
5855 if (ret_val)
5856 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005857
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005858 if (mii_status_reg & MII_SR_LINK_STATUS)
5859 break;
Jesse Brandeburg4e0d8f7d2011-10-05 07:24:46 +00005860 msleep(100);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005861 }
5862 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005863}
5864
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005865/**
5866 * e1000_get_auto_rd_done
5867 * @hw: Struct containing variables accessed by shared code
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005868 *
5869 * Check for EEPROM Auto Read bit done.
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005870 * returns: - E1000_ERR_RESET if fail to reset MAC
5871 * E1000_SUCCESS at any other case.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005872 */
Joe Perches64798842008-07-11 15:17:02 -07005873static s32 e1000_get_auto_rd_done(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005874{
Emil Tantilov675ad472010-04-27 14:02:58 +00005875 e_dbg("e1000_get_auto_rd_done");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005876 msleep(5);
5877 return E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005878}
5879
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005880/**
5881 * e1000_get_phy_cfg_done
5882 * @hw: Struct containing variables accessed by shared code
5883 *
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005884 * Checks if the PHY configuration is done
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005885 * returns: - E1000_ERR_RESET if fail to reset MAC
5886 * E1000_SUCCESS at any other case.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005887 */
Joe Perches64798842008-07-11 15:17:02 -07005888static s32 e1000_get_phy_cfg_done(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005889{
Emil Tantilov675ad472010-04-27 14:02:58 +00005890 e_dbg("e1000_get_phy_cfg_done");
Jesse Brandeburg4e0d8f7d2011-10-05 07:24:46 +00005891 msleep(10);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005892 return E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005893}