blob: 6e7e923d57bf47d078481ffd5185fcc82c6e5aa3 [file] [log] [blame]
Jeff Kirsherae06c702018-03-22 10:08:48 -07001// SPDX-License-Identifier: GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*******************************************************************************
Janusz Wolak13a87c12015-09-28 23:40:19 +02003*
Auke Kok0abb6eb2006-09-27 12:53:14 -07004 Intel PRO/1000 Linux driver
5 Copyright(c) 1999 - 2006 Intel Corporation.
6
7 This program is free software; you can redistribute it and/or modify it
8 under the terms and conditions of the GNU General Public License,
9 version 2, as published by the Free Software Foundation.
10
11 This program is distributed in the hope it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
Linus Torvalds1da177e2005-04-16 15:20:36 -070014 more details.
Auke Kok0abb6eb2006-09-27 12:53:14 -070015
Linus Torvalds1da177e2005-04-16 15:20:36 -070016 You should have received a copy of the GNU General Public License along with
Auke Kok0abb6eb2006-09-27 12:53:14 -070017 this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19
20 The full GNU General Public License is included in this distribution in
21 the file called "COPYING".
22
Linus Torvalds1da177e2005-04-16 15:20:36 -070023 Contact Information:
24 Linux NICS <linux.nics@intel.com>
Auke Kok3d41e302006-04-14 19:05:31 -070025 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27
Jesse Brandeburg120a5d02009-09-25 15:19:46 -070028 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
30/* e1000_hw.c
31 * Shared functions for accessing and configuring the MAC
32 */
33
Emil Tantilov675ad472010-04-27 14:02:58 +000034#include "e1000.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
Joe Perches406874a2008-04-03 10:06:32 -070036static s32 e1000_check_downshift(struct e1000_hw *hw);
Joe Perches64798842008-07-11 15:17:02 -070037static s32 e1000_check_polarity(struct e1000_hw *hw,
38 e1000_rev_polarity *polarity);
Nicholas Nunley35574762006-09-27 12:53:34 -070039static void e1000_clear_hw_cntrs(struct e1000_hw *hw);
40static void e1000_clear_vfta(struct e1000_hw *hw);
Joe Perches406874a2008-04-03 10:06:32 -070041static s32 e1000_config_dsp_after_link_change(struct e1000_hw *hw,
Joe Perches64798842008-07-11 15:17:02 -070042 bool link_up);
Joe Perches406874a2008-04-03 10:06:32 -070043static s32 e1000_config_fc_after_link_up(struct e1000_hw *hw);
44static s32 e1000_detect_gig_phy(struct e1000_hw *hw);
Joe Perches406874a2008-04-03 10:06:32 -070045static s32 e1000_get_auto_rd_done(struct e1000_hw *hw);
Joe Perches64798842008-07-11 15:17:02 -070046static s32 e1000_get_cable_length(struct e1000_hw *hw, u16 *min_length,
47 u16 *max_length);
Joe Perches406874a2008-04-03 10:06:32 -070048static s32 e1000_get_phy_cfg_done(struct e1000_hw *hw);
Joe Perches406874a2008-04-03 10:06:32 -070049static s32 e1000_id_led_init(struct e1000_hw *hw);
Nicholas Nunley35574762006-09-27 12:53:34 -070050static void e1000_init_rx_addrs(struct e1000_hw *hw);
Joe Perches64798842008-07-11 15:17:02 -070051static s32 e1000_phy_igp_get_info(struct e1000_hw *hw,
52 struct e1000_phy_info *phy_info);
Joe Perches64798842008-07-11 15:17:02 -070053static s32 e1000_phy_m88_get_info(struct e1000_hw *hw,
54 struct e1000_phy_info *phy_info);
Joe Perches406874a2008-04-03 10:06:32 -070055static s32 e1000_set_d3_lplu_state(struct e1000_hw *hw, bool active);
Joe Perches406874a2008-04-03 10:06:32 -070056static s32 e1000_wait_autoneg(struct e1000_hw *hw);
57static void e1000_write_reg_io(struct e1000_hw *hw, u32 offset, u32 value);
58static s32 e1000_set_phy_type(struct e1000_hw *hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -070059static void e1000_phy_init_script(struct e1000_hw *hw);
Joe Perches406874a2008-04-03 10:06:32 -070060static s32 e1000_setup_copper_link(struct e1000_hw *hw);
61static s32 e1000_setup_fiber_serdes_link(struct e1000_hw *hw);
62static s32 e1000_adjust_serdes_amplitude(struct e1000_hw *hw);
63static s32 e1000_phy_force_speed_duplex(struct e1000_hw *hw);
64static s32 e1000_config_mac_to_phy(struct e1000_hw *hw);
65static void e1000_raise_mdi_clk(struct e1000_hw *hw, u32 *ctrl);
66static void e1000_lower_mdi_clk(struct e1000_hw *hw, u32 *ctrl);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -070067static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, u32 data, u16 count);
Joe Perches406874a2008-04-03 10:06:32 -070068static u16 e1000_shift_in_mdi_bits(struct e1000_hw *hw);
69static s32 e1000_phy_reset_dsp(struct e1000_hw *hw);
70static s32 e1000_write_eeprom_spi(struct e1000_hw *hw, u16 offset,
Jesse Brandeburg120a5d02009-09-25 15:19:46 -070071 u16 words, u16 *data);
Joe Perches64798842008-07-11 15:17:02 -070072static s32 e1000_write_eeprom_microwire(struct e1000_hw *hw, u16 offset,
73 u16 words, u16 *data);
Joe Perches406874a2008-04-03 10:06:32 -070074static s32 e1000_spi_eeprom_ready(struct e1000_hw *hw);
75static void e1000_raise_ee_clk(struct e1000_hw *hw, u32 *eecd);
76static void e1000_lower_ee_clk(struct e1000_hw *hw, u32 *eecd);
Joe Perches64798842008-07-11 15:17:02 -070077static void e1000_shift_out_ee_bits(struct e1000_hw *hw, u16 data, u16 count);
Joe Perches406874a2008-04-03 10:06:32 -070078static s32 e1000_write_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr,
Joe Perches64798842008-07-11 15:17:02 -070079 u16 phy_data);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -070080static s32 e1000_read_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr,
Joe Perches64798842008-07-11 15:17:02 -070081 u16 *phy_data);
Joe Perches406874a2008-04-03 10:06:32 -070082static u16 e1000_shift_in_ee_bits(struct e1000_hw *hw, u16 count);
83static s32 e1000_acquire_eeprom(struct e1000_hw *hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084static void e1000_release_eeprom(struct e1000_hw *hw);
85static void e1000_standby_eeprom(struct e1000_hw *hw);
Joe Perches406874a2008-04-03 10:06:32 -070086static s32 e1000_set_vco_speed(struct e1000_hw *hw);
87static s32 e1000_polarity_reversal_workaround(struct e1000_hw *hw);
88static s32 e1000_set_phy_mode(struct e1000_hw *hw);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -070089static s32 e1000_do_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words,
90 u16 *data);
91static s32 e1000_do_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words,
92 u16 *data);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
94/* IGP cable length table */
95static const
Jesse Brandeburg120a5d02009-09-25 15:19:46 -070096u16 e1000_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] = {
97 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
98 5, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 25, 25, 25,
99 25, 25, 25, 25, 30, 30, 30, 30, 40, 40, 40, 40, 40, 40, 40, 40,
100 40, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60,
101 60, 70, 70, 70, 70, 70, 70, 80, 80, 80, 80, 80, 80, 90, 90, 90,
102 90, 90, 90, 90, 90, 90, 100, 100, 100, 100, 100, 100, 100, 100, 100,
103 100,
104 100, 100, 100, 100, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,
105 110, 110,
106 110, 110, 110, 110, 110, 110, 120, 120, 120, 120, 120, 120, 120, 120,
107 120, 120
108};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
Joern Engele09b8902015-07-23 14:54:34 -0700110static DEFINE_MUTEX(e1000_eeprom_lock);
Maxime Bizonac565582012-10-20 14:53:40 +0000111static DEFINE_SPINLOCK(e1000_phy_lock);
Christopher Li78566fe2008-09-05 14:04:05 -0700112
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700113/**
114 * e1000_set_phy_type - Set the phy type member in the hw struct.
115 * @hw: Struct containing variables accessed by shared code
116 */
Joe Perches64798842008-07-11 15:17:02 -0700117static s32 e1000_set_phy_type(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700119 if (hw->mac_type == e1000_undefined)
120 return -E1000_ERR_PHY_TYPE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700121
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700122 switch (hw->phy_id) {
123 case M88E1000_E_PHY_ID:
124 case M88E1000_I_PHY_ID:
125 case M88E1011_I_PHY_ID:
126 case M88E1111_I_PHY_ID:
Florian Fainellicf8e09b2011-01-24 14:48:03 +0000127 case M88E1118_E_PHY_ID:
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700128 hw->phy_type = e1000_phy_m88;
129 break;
130 case IGP01E1000_I_PHY_ID:
131 if (hw->mac_type == e1000_82541 ||
132 hw->mac_type == e1000_82541_rev_2 ||
133 hw->mac_type == e1000_82547 ||
Dirk Brandewie5377a412011-01-06 14:29:54 +0000134 hw->mac_type == e1000_82547_rev_2)
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700135 hw->phy_type = e1000_phy_igp;
Dirk Brandewie5377a412011-01-06 14:29:54 +0000136 break;
137 case RTL8211B_PHY_ID:
138 hw->phy_type = e1000_phy_8211;
139 break;
140 case RTL8201N_PHY_ID:
141 hw->phy_type = e1000_phy_8201;
142 break;
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700143 default:
144 /* Should never have loaded on this device */
145 hw->phy_type = e1000_phy_undefined;
146 return -E1000_ERR_PHY_TYPE;
147 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700149 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150}
151
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700152/**
153 * e1000_phy_init_script - IGP phy init script - initializes the GbE PHY
154 * @hw: Struct containing variables accessed by shared code
155 */
Joe Perches64798842008-07-11 15:17:02 -0700156static void e1000_phy_init_script(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700158 u32 ret_val;
159 u16 phy_saved_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700161 if (hw->phy_init_script) {
162 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000164 /* Save off the current value of register 0x2F5B to be restored
165 * at the end of this routine.
166 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700167 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700169 /* Disabled the PHY transmitter */
170 e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
171 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700173 e1000_write_phy_reg(hw, 0x0000, 0x0140);
174 msleep(5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700176 switch (hw->mac_type) {
177 case e1000_82541:
178 case e1000_82547:
179 e1000_write_phy_reg(hw, 0x1F95, 0x0001);
180 e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
181 e1000_write_phy_reg(hw, 0x1F79, 0x0018);
182 e1000_write_phy_reg(hw, 0x1F30, 0x1600);
183 e1000_write_phy_reg(hw, 0x1F31, 0x0014);
184 e1000_write_phy_reg(hw, 0x1F32, 0x161C);
185 e1000_write_phy_reg(hw, 0x1F94, 0x0003);
186 e1000_write_phy_reg(hw, 0x1F96, 0x003F);
187 e1000_write_phy_reg(hw, 0x2010, 0x0008);
188 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700190 case e1000_82541_rev_2:
191 case e1000_82547_rev_2:
192 e1000_write_phy_reg(hw, 0x1F73, 0x0099);
193 break;
194 default:
195 break;
196 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700198 e1000_write_phy_reg(hw, 0x0000, 0x3300);
199 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700201 /* Now enable the transmitter */
202 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700204 if (hw->mac_type == e1000_82547) {
205 u16 fused, fine, coarse;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700207 /* Move to analog registers page */
208 e1000_read_phy_reg(hw,
209 IGP01E1000_ANALOG_SPARE_FUSE_STATUS,
210 &fused);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700212 if (!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
213 e1000_read_phy_reg(hw,
214 IGP01E1000_ANALOG_FUSE_STATUS,
215 &fused);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700217 fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
218 coarse =
219 fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700221 if (coarse >
222 IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
223 coarse -=
224 IGP01E1000_ANALOG_FUSE_COARSE_10;
225 fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
226 } else if (coarse ==
227 IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
228 fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700230 fused =
231 (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
232 (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
233 (coarse &
234 IGP01E1000_ANALOG_FUSE_COARSE_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700236 e1000_write_phy_reg(hw,
237 IGP01E1000_ANALOG_FUSE_CONTROL,
238 fused);
239 e1000_write_phy_reg(hw,
240 IGP01E1000_ANALOG_FUSE_BYPASS,
241 IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
242 }
243 }
244 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245}
246
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700247/**
248 * e1000_set_mac_type - Set the mac type member in the hw struct.
249 * @hw: Struct containing variables accessed by shared code
250 */
Joe Perches64798842008-07-11 15:17:02 -0700251s32 e1000_set_mac_type(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252{
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500253 switch (hw->device_id) {
254 case E1000_DEV_ID_82542:
255 switch (hw->revision_id) {
256 case E1000_82542_2_0_REV_ID:
257 hw->mac_type = e1000_82542_rev2_0;
258 break;
259 case E1000_82542_2_1_REV_ID:
260 hw->mac_type = e1000_82542_rev2_1;
261 break;
262 default:
263 /* Invalid 82542 revision ID */
264 return -E1000_ERR_MAC_TYPE;
265 }
266 break;
267 case E1000_DEV_ID_82543GC_FIBER:
268 case E1000_DEV_ID_82543GC_COPPER:
269 hw->mac_type = e1000_82543;
270 break;
271 case E1000_DEV_ID_82544EI_COPPER:
272 case E1000_DEV_ID_82544EI_FIBER:
273 case E1000_DEV_ID_82544GC_COPPER:
274 case E1000_DEV_ID_82544GC_LOM:
275 hw->mac_type = e1000_82544;
276 break;
277 case E1000_DEV_ID_82540EM:
278 case E1000_DEV_ID_82540EM_LOM:
279 case E1000_DEV_ID_82540EP:
280 case E1000_DEV_ID_82540EP_LOM:
281 case E1000_DEV_ID_82540EP_LP:
282 hw->mac_type = e1000_82540;
283 break;
284 case E1000_DEV_ID_82545EM_COPPER:
285 case E1000_DEV_ID_82545EM_FIBER:
286 hw->mac_type = e1000_82545;
287 break;
288 case E1000_DEV_ID_82545GM_COPPER:
289 case E1000_DEV_ID_82545GM_FIBER:
290 case E1000_DEV_ID_82545GM_SERDES:
291 hw->mac_type = e1000_82545_rev_3;
292 break;
293 case E1000_DEV_ID_82546EB_COPPER:
294 case E1000_DEV_ID_82546EB_FIBER:
295 case E1000_DEV_ID_82546EB_QUAD_COPPER:
296 hw->mac_type = e1000_82546;
297 break;
298 case E1000_DEV_ID_82546GB_COPPER:
299 case E1000_DEV_ID_82546GB_FIBER:
300 case E1000_DEV_ID_82546GB_SERDES:
301 case E1000_DEV_ID_82546GB_PCIE:
302 case E1000_DEV_ID_82546GB_QUAD_COPPER:
303 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
304 hw->mac_type = e1000_82546_rev_3;
305 break;
306 case E1000_DEV_ID_82541EI:
307 case E1000_DEV_ID_82541EI_MOBILE:
308 case E1000_DEV_ID_82541ER_LOM:
309 hw->mac_type = e1000_82541;
310 break;
311 case E1000_DEV_ID_82541ER:
312 case E1000_DEV_ID_82541GI:
313 case E1000_DEV_ID_82541GI_LF:
314 case E1000_DEV_ID_82541GI_MOBILE:
315 hw->mac_type = e1000_82541_rev_2;
316 break;
317 case E1000_DEV_ID_82547EI:
318 case E1000_DEV_ID_82547EI_MOBILE:
319 hw->mac_type = e1000_82547;
320 break;
321 case E1000_DEV_ID_82547GI:
322 hw->mac_type = e1000_82547_rev_2;
323 break;
Dirk Brandewie5377a412011-01-06 14:29:54 +0000324 case E1000_DEV_ID_INTEL_CE4100_GBE:
325 hw->mac_type = e1000_ce4100;
326 break;
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500327 default:
328 /* Should never have loaded on this device */
329 return -E1000_ERR_MAC_TYPE;
330 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500332 switch (hw->mac_type) {
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500333 case e1000_82541:
334 case e1000_82547:
335 case e1000_82541_rev_2:
336 case e1000_82547_rev_2:
Joe Perchesc3033b02008-03-21 11:06:25 -0700337 hw->asf_firmware_present = true;
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500338 break;
339 default:
340 break;
341 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
Jeff Garzik167fb282006-12-15 10:41:15 -0500343 /* The 82543 chip does not count tx_carrier_errors properly in
344 * FD mode
345 */
346 if (hw->mac_type == e1000_82543)
Joe Perchesc3033b02008-03-21 11:06:25 -0700347 hw->bad_tx_carr_stats_fd = true;
Jeff Garzik167fb282006-12-15 10:41:15 -0500348
Jeff Garzik15e376b2006-12-15 11:16:33 -0500349 if (hw->mac_type > e1000_82544)
Joe Perchesc3033b02008-03-21 11:06:25 -0700350 hw->has_smbus = true;
Jeff Garzik15e376b2006-12-15 11:16:33 -0500351
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500352 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353}
354
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700355/**
356 * e1000_set_media_type - Set media type and TBI compatibility.
357 * @hw: Struct containing variables accessed by shared code
358 */
Joe Perches64798842008-07-11 15:17:02 -0700359void e1000_set_media_type(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700361 u32 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700363 if (hw->mac_type != e1000_82543) {
364 /* tbi_compatibility is only valid on 82543 */
365 hw->tbi_compatibility_en = false;
366 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700368 switch (hw->device_id) {
369 case E1000_DEV_ID_82545GM_SERDES:
370 case E1000_DEV_ID_82546GB_SERDES:
371 hw->media_type = e1000_media_type_internal_serdes;
372 break;
373 default:
374 switch (hw->mac_type) {
375 case e1000_82542_rev2_0:
376 case e1000_82542_rev2_1:
377 hw->media_type = e1000_media_type_fiber;
378 break;
Dirk Brandewie5377a412011-01-06 14:29:54 +0000379 case e1000_ce4100:
380 hw->media_type = e1000_media_type_copper;
381 break;
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700382 default:
383 status = er32(STATUS);
384 if (status & E1000_STATUS_TBIMODE) {
385 hw->media_type = e1000_media_type_fiber;
386 /* tbi_compatibility not valid on fiber */
387 hw->tbi_compatibility_en = false;
388 } else {
389 hw->media_type = e1000_media_type_copper;
390 }
391 break;
392 }
393 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394}
395
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700396/**
Ben Hutchings49ce9c22012-07-10 10:56:00 +0000397 * e1000_reset_hw - reset the hardware completely
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700398 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 *
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700400 * Reset the transmit and receive units; mask and clear all interrupts.
401 */
Joe Perches64798842008-07-11 15:17:02 -0700402s32 e1000_reset_hw(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700404 u32 ctrl;
405 u32 ctrl_ext;
406 u32 icr;
407 u32 manc;
408 u32 led_ctrl;
409 s32 ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700411 /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
412 if (hw->mac_type == e1000_82542_rev2_0) {
Emil Tantilov675ad472010-04-27 14:02:58 +0000413 e_dbg("Disabling MWI on 82542 rev 2.0\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700414 e1000_pci_clear_mwi(hw);
415 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700417 /* Clear interrupt mask to stop board from generating interrupts */
Emil Tantilov675ad472010-04-27 14:02:58 +0000418 e_dbg("Masking off all interrupts\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700419 ew32(IMC, 0xffffffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700421 /* Disable the Transmit and Receive units. Then delay to allow
422 * any pending transactions to complete before we hit the MAC with
423 * the global reset.
424 */
425 ew32(RCTL, 0);
426 ew32(TCTL, E1000_TCTL_PSP);
427 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700429 /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
430 hw->tbi_compatibility_on = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700432 /* Delay to allow any outstanding PCI transactions to complete before
433 * resetting the device
434 */
435 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700437 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700439 /* Must reset the PHY before resetting the MAC */
440 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
441 ew32(CTRL, (ctrl | E1000_CTRL_PHY_RST));
Jesse Brandeburg945a5152011-07-20 00:56:21 +0000442 E1000_WRITE_FLUSH();
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700443 msleep(5);
444 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700446 /* Issue a global reset to the MAC. This will reset the chip's
447 * transmit, receive, DMA, and link units. It will not effect
448 * the current PCI configuration. The global reset bit is self-
449 * clearing, and should clear within a microsecond.
450 */
Emil Tantilov675ad472010-04-27 14:02:58 +0000451 e_dbg("Issuing a global reset to MAC\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700453 switch (hw->mac_type) {
454 case e1000_82544:
455 case e1000_82540:
456 case e1000_82545:
457 case e1000_82546:
458 case e1000_82541:
459 case e1000_82541_rev_2:
460 /* These controllers can't ack the 64-bit write when issuing the
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000461 * reset, so use IO-mapping as a workaround to issue the reset
462 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700463 E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
464 break;
465 case e1000_82545_rev_3:
466 case e1000_82546_rev_3:
467 /* Reset is performed on a shadow of the control register */
468 ew32(CTRL_DUP, (ctrl | E1000_CTRL_RST));
469 break;
Dirk Brandewie5377a412011-01-06 14:29:54 +0000470 case e1000_ce4100:
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700471 default:
472 ew32(CTRL, (ctrl | E1000_CTRL_RST));
473 break;
474 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000476 /* After MAC reset, force reload of EEPROM to restore power-on settings
477 * to device. Later controllers reload the EEPROM automatically, so
478 * just wait for reload to complete.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700479 */
480 switch (hw->mac_type) {
481 case e1000_82542_rev2_0:
482 case e1000_82542_rev2_1:
483 case e1000_82543:
484 case e1000_82544:
485 /* Wait for reset to complete */
486 udelay(10);
487 ctrl_ext = er32(CTRL_EXT);
488 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
489 ew32(CTRL_EXT, ctrl_ext);
490 E1000_WRITE_FLUSH();
491 /* Wait for EEPROM reload */
492 msleep(2);
493 break;
494 case e1000_82541:
495 case e1000_82541_rev_2:
496 case e1000_82547:
497 case e1000_82547_rev_2:
498 /* Wait for EEPROM reload */
499 msleep(20);
500 break;
501 default:
502 /* Auto read done will delay 5ms or poll based on mac type */
503 ret_val = e1000_get_auto_rd_done(hw);
504 if (ret_val)
505 return ret_val;
506 break;
507 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700509 /* Disable HW ARPs on ASF enabled adapters */
510 if (hw->mac_type >= e1000_82540) {
511 manc = er32(MANC);
512 manc &= ~(E1000_MANC_ARP_EN);
513 ew32(MANC, manc);
514 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700516 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
517 e1000_phy_init_script(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700519 /* Configure activity LED after PHY reset */
520 led_ctrl = er32(LEDCTL);
521 led_ctrl &= IGP_ACTIVITY_LED_MASK;
522 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
523 ew32(LEDCTL, led_ctrl);
524 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700526 /* Clear interrupt mask to stop board from generating interrupts */
Emil Tantilov675ad472010-04-27 14:02:58 +0000527 e_dbg("Masking off all interrupts\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700528 ew32(IMC, 0xffffffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700530 /* Clear any pending interrupt events. */
531 icr = er32(ICR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700533 /* If MWI was previously enabled, reenable it. */
534 if (hw->mac_type == e1000_82542_rev2_0) {
535 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
536 e1000_pci_set_mwi(hw);
537 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700539 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540}
541
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700542/**
Ben Hutchings49ce9c22012-07-10 10:56:00 +0000543 * e1000_init_hw - Performs basic configuration of the adapter.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700544 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 *
546 * Assumes that the controller has previously been reset and is in a
547 * post-reset uninitialized state. Initializes the receive address registers,
548 * multicast table, and VLAN filter table. Calls routines to setup link
549 * configuration and flow control settings. Clears all on-chip counters. Leaves
550 * the transmit and receive units disabled and uninitialized.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700551 */
Joe Perches64798842008-07-11 15:17:02 -0700552s32 e1000_init_hw(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700554 u32 ctrl;
555 u32 i;
556 s32 ret_val;
557 u32 mta_size;
558 u32 ctrl_ext;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700559
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700560 /* Initialize Identification LED */
561 ret_val = e1000_id_led_init(hw);
562 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +0000563 e_dbg("Error Initializing Identification LED\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700564 return ret_val;
565 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700567 /* Set the media type and TBI compatibility */
568 e1000_set_media_type(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700570 /* Disabling VLAN filtering. */
Emil Tantilov675ad472010-04-27 14:02:58 +0000571 e_dbg("Initializing the IEEE VLAN\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700572 if (hw->mac_type < e1000_82545_rev_3)
573 ew32(VET, 0);
574 e1000_clear_vfta(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700576 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
577 if (hw->mac_type == e1000_82542_rev2_0) {
Emil Tantilov675ad472010-04-27 14:02:58 +0000578 e_dbg("Disabling MWI on 82542 rev 2.0\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700579 e1000_pci_clear_mwi(hw);
580 ew32(RCTL, E1000_RCTL_RST);
581 E1000_WRITE_FLUSH();
582 msleep(5);
583 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000585 /* Setup the receive address. This involves initializing all of the
586 * Receive Address Registers (RARs 0 - 15).
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700587 */
588 e1000_init_rx_addrs(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700590 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
591 if (hw->mac_type == e1000_82542_rev2_0) {
592 ew32(RCTL, 0);
593 E1000_WRITE_FLUSH();
594 msleep(1);
595 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
596 e1000_pci_set_mwi(hw);
597 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700599 /* Zero out the Multicast HASH table */
Emil Tantilov675ad472010-04-27 14:02:58 +0000600 e_dbg("Zeroing the MTA\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700601 mta_size = E1000_MC_TBL_SIZE;
602 for (i = 0; i < mta_size; i++) {
603 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
604 /* use write flush to prevent Memory Write Block (MWB) from
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000605 * occurring when accessing our register space
606 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700607 E1000_WRITE_FLUSH();
608 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700610 /* Set the PCI priority bit correctly in the CTRL register. This
611 * determines if the adapter gives priority to receives, or if it
612 * gives equal priority to transmits and receives. Valid only on
613 * 82542 and 82543 silicon.
614 */
615 if (hw->dma_fairness && hw->mac_type <= e1000_82543) {
616 ctrl = er32(CTRL);
617 ew32(CTRL, ctrl | E1000_CTRL_PRIOR);
618 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700620 switch (hw->mac_type) {
621 case e1000_82545_rev_3:
622 case e1000_82546_rev_3:
623 break;
624 default:
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000625 /* Workaround for PCI-X problem when BIOS sets MMRBC
626 * incorrectly.
627 */
Janusz Wolak13a87c12015-09-28 23:40:19 +0200628 if (hw->bus_type == e1000_bus_type_pcix &&
629 e1000_pcix_get_mmrbc(hw) > 2048)
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700630 e1000_pcix_set_mmrbc(hw, 2048);
631 break;
632 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700634 /* Call a subroutine to configure the link and setup flow control. */
635 ret_val = e1000_setup_link(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700637 /* Set the transmit descriptor write-back policy */
638 if (hw->mac_type > e1000_82544) {
639 ctrl = er32(TXDCTL);
640 ctrl =
641 (ctrl & ~E1000_TXDCTL_WTHRESH) |
642 E1000_TXDCTL_FULL_TX_DESC_WB;
643 ew32(TXDCTL, ctrl);
644 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700646 /* Clear all of the statistics registers (clear on read). It is
647 * important that we do this after we have tried to establish link
648 * because the symbol error count will increment wildly if there
649 * is no link.
650 */
651 e1000_clear_hw_cntrs(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700653 if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER ||
654 hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) {
655 ctrl_ext = er32(CTRL_EXT);
656 /* Relaxed ordering must be disabled to avoid a parity
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000657 * error crash in a PCI slot.
658 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700659 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
660 ew32(CTRL_EXT, ctrl_ext);
661 }
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -0800662
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700663 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664}
665
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700666/**
667 * e1000_adjust_serdes_amplitude - Adjust SERDES output amplitude based on EEPROM setting.
668 * @hw: Struct containing variables accessed by shared code.
669 */
Joe Perches64798842008-07-11 15:17:02 -0700670static s32 e1000_adjust_serdes_amplitude(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700672 u16 eeprom_data;
673 s32 ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700675 if (hw->media_type != e1000_media_type_internal_serdes)
676 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700678 switch (hw->mac_type) {
679 case e1000_82545_rev_3:
680 case e1000_82546_rev_3:
681 break;
682 default:
683 return E1000_SUCCESS;
684 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700686 ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1,
Janusz Wolaka48954c2015-09-17 23:34:29 +0200687 &eeprom_data);
Janusz Wolak13a87c12015-09-28 23:40:19 +0200688 if (ret_val)
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700689 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700691 if (eeprom_data != EEPROM_RESERVED_WORD) {
692 /* Adjust SERDES output amplitude only. */
693 eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK;
694 ret_val =
695 e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data);
696 if (ret_val)
697 return ret_val;
698 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700700 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701}
702
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700703/**
704 * e1000_setup_link - Configures flow control and link settings.
705 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 *
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700707 * Determines which flow control settings to use. Calls the appropriate media-
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 * specific link configuration function. Configures the flow control settings.
709 * Assuming the adapter has a valid link partner, a valid link should be
710 * established. Assumes the hardware has previously been reset and the
711 * transmitter and receiver are not enabled.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700712 */
Joe Perches64798842008-07-11 15:17:02 -0700713s32 e1000_setup_link(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700715 u32 ctrl_ext;
716 s32 ret_val;
717 u16 eeprom_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700719 /* Read and store word 0x0F of the EEPROM. This word contains bits
720 * that determine the hardware's default PAUSE (flow control) mode,
721 * a bit that determines whether the HW defaults to enabling or
722 * disabling auto-negotiation, and the direction of the
723 * SW defined pins. If there is no SW over-ride of the flow
724 * control setting, then the variable hw->fc will
725 * be initialized based on a value in the EEPROM.
726 */
727 if (hw->fc == E1000_FC_DEFAULT) {
728 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
729 1, &eeprom_data);
730 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +0000731 e_dbg("EEPROM Read Error\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700732 return -E1000_ERR_EEPROM;
733 }
734 if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
735 hw->fc = E1000_FC_NONE;
736 else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
737 EEPROM_WORD0F_ASM_DIR)
738 hw->fc = E1000_FC_TX_PAUSE;
739 else
740 hw->fc = E1000_FC_FULL;
741 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700743 /* We want to save off the original Flow Control configuration just
744 * in case we get disconnected and then reconnected into a different
745 * hub or switch with different Flow Control capabilities.
746 */
747 if (hw->mac_type == e1000_82542_rev2_0)
748 hw->fc &= (~E1000_FC_TX_PAUSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700750 if ((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
751 hw->fc &= (~E1000_FC_RX_PAUSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700753 hw->original_fc = hw->fc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754
Emil Tantilov675ad472010-04-27 14:02:58 +0000755 e_dbg("After fix-ups FlowControl is now = %x\n", hw->fc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700757 /* Take the 4 bits from EEPROM word 0x0F that determine the initial
758 * polarity value for the SW controlled pins, and setup the
759 * Extended Device Control reg with that info.
760 * This is needed because one of the SW controlled pins is used for
761 * signal detection. So this should be done before e1000_setup_pcs_link()
762 * or e1000_phy_setup() is called.
763 */
764 if (hw->mac_type == e1000_82543) {
765 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
766 1, &eeprom_data);
767 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +0000768 e_dbg("EEPROM Read Error\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700769 return -E1000_ERR_EEPROM;
770 }
771 ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
772 SWDPIO__EXT_SHIFT);
773 ew32(CTRL_EXT, ctrl_ext);
774 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700776 /* Call the necessary subroutine to configure the link. */
777 ret_val = (hw->media_type == e1000_media_type_copper) ?
778 e1000_setup_copper_link(hw) : e1000_setup_fiber_serdes_link(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700780 /* Initialize the flow control address, type, and PAUSE timer
781 * registers to their default values. This is done even if flow
782 * control is disabled, because it does not hurt anything to
783 * initialize these registers.
784 */
Emil Tantilov675ad472010-04-27 14:02:58 +0000785 e_dbg("Initializing the Flow Control address, type and timer regs\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700787 ew32(FCT, FLOW_CONTROL_TYPE);
788 ew32(FCAH, FLOW_CONTROL_ADDRESS_HIGH);
789 ew32(FCAL, FLOW_CONTROL_ADDRESS_LOW);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700790
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700791 ew32(FCTTV, hw->fc_pause_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700793 /* Set the flow control receive threshold registers. Normally,
794 * these registers will be set to a default threshold that may be
795 * adjusted later by the driver's runtime code. However, if the
796 * ability to transmit pause frames in not enabled, then these
797 * registers will be set to 0.
798 */
799 if (!(hw->fc & E1000_FC_TX_PAUSE)) {
800 ew32(FCRTL, 0);
801 ew32(FCRTH, 0);
802 } else {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000803 /* We need to set up the Receive Threshold high and low water
804 * marks as well as (optionally) enabling the transmission of
805 * XON frames.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700806 */
807 if (hw->fc_send_xon) {
808 ew32(FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE));
809 ew32(FCRTH, hw->fc_high_water);
810 } else {
811 ew32(FCRTL, hw->fc_low_water);
812 ew32(FCRTH, hw->fc_high_water);
813 }
814 }
815 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816}
817
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700818/**
819 * e1000_setup_fiber_serdes_link - prepare fiber or serdes link
820 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 *
822 * Manipulates Physical Coding Sublayer functions in order to configure
823 * link. Assumes the hardware has been previously reset and the transmitter
824 * and receiver are not enabled.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700825 */
Joe Perches64798842008-07-11 15:17:02 -0700826static s32 e1000_setup_fiber_serdes_link(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700828 u32 ctrl;
829 u32 status;
830 u32 txcw = 0;
831 u32 i;
832 u32 signal = 0;
833 s32 ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700835 /* On adapters with a MAC newer than 82544, SWDP 1 will be
836 * set when the optics detect a signal. On older adapters, it will be
837 * cleared when there is a signal. This applies to fiber media only.
838 * If we're on serdes media, adjust the output amplitude to value
839 * set in the EEPROM.
840 */
841 ctrl = er32(CTRL);
842 if (hw->media_type == e1000_media_type_fiber)
843 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700845 ret_val = e1000_adjust_serdes_amplitude(hw);
846 if (ret_val)
847 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700849 /* Take the link out of reset */
850 ctrl &= ~(E1000_CTRL_LRST);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700852 /* Adjust VCO speed to improve BER performance */
853 ret_val = e1000_set_vco_speed(hw);
854 if (ret_val)
855 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700857 e1000_config_collision_dist(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700859 /* Check for a software override of the flow control settings, and setup
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000860 * the device accordingly. If auto-negotiation is enabled, then
861 * software will have to set the "PAUSE" bits to the correct value in
862 * the Tranmsit Config Word Register (TXCW) and re-start
863 * auto-negotiation. However, if auto-negotiation is disabled, then
864 * software will have to manually configure the two flow control enable
865 * bits in the CTRL register.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700866 *
867 * The possible values of the "fc" parameter are:
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000868 * 0: Flow control is completely disabled
869 * 1: Rx flow control is enabled (we can receive pause frames, but
870 * not send pause frames).
871 * 2: Tx flow control is enabled (we can send pause frames but we do
872 * not support receiving pause frames).
873 * 3: Both Rx and TX flow control (symmetric) are enabled.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700874 */
875 switch (hw->fc) {
876 case E1000_FC_NONE:
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000877 /* Flow ctrl is completely disabled by a software over-ride */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700878 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
879 break;
880 case E1000_FC_RX_PAUSE:
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000881 /* Rx Flow control is enabled and Tx Flow control is disabled by
882 * a software over-ride. Since there really isn't a way to
883 * advertise that we are capable of Rx Pause ONLY, we will
884 * advertise that we support both symmetric and asymmetric Rx
885 * PAUSE. Later, we will disable the adapter's ability to send
886 * PAUSE frames.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700887 */
888 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
889 break;
890 case E1000_FC_TX_PAUSE:
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000891 /* Tx Flow control is enabled, and Rx Flow control is disabled,
892 * by a software over-ride.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700893 */
894 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
895 break;
896 case E1000_FC_FULL:
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000897 /* Flow control (both Rx and Tx) is enabled by a software
898 * over-ride.
899 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700900 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
901 break;
902 default:
Emil Tantilov675ad472010-04-27 14:02:58 +0000903 e_dbg("Flow control param set incorrectly\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700904 return -E1000_ERR_CONFIG;
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700905 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000907 /* Since auto-negotiation is enabled, take the link out of reset (the
908 * link will be in reset, because we previously reset the chip). This
909 * will restart auto-negotiation. If auto-negotiation is successful
910 * then the link-up status bit will be set and the flow control enable
911 * bits (RFCE and TFCE) will be set according to their negotiated value.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700912 */
Emil Tantilov675ad472010-04-27 14:02:58 +0000913 e_dbg("Auto-negotiation enabled\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700915 ew32(TXCW, txcw);
916 ew32(CTRL, ctrl);
917 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700919 hw->txcw = txcw;
920 msleep(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000922 /* If we have a signal (the cable is plugged in) then poll for a
923 * "Link-Up" indication in the Device Status Register. Time-out if a
924 * link isn't seen in 500 milliseconds seconds (Auto-negotiation should
925 * complete in less than 500 milliseconds even if the other end is doing
926 * it in SW). For internal serdes, we just assume a signal is present,
927 * then poll.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700928 */
929 if (hw->media_type == e1000_media_type_internal_serdes ||
930 (er32(CTRL) & E1000_CTRL_SWDPIN1) == signal) {
Emil Tantilov675ad472010-04-27 14:02:58 +0000931 e_dbg("Looking for Link\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700932 for (i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
933 msleep(10);
934 status = er32(STATUS);
935 if (status & E1000_STATUS_LU)
936 break;
937 }
938 if (i == (LINK_UP_TIMEOUT / 10)) {
Emil Tantilov675ad472010-04-27 14:02:58 +0000939 e_dbg("Never got a valid link from auto-neg!!!\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700940 hw->autoneg_failed = 1;
941 /* AutoNeg failed to achieve a link, so we'll call
Jeff Kirsher6cfbd972013-02-09 12:49:21 +0000942 * e1000_check_for_link. This routine will force the
943 * link up if we detect a signal. This will allow us to
944 * communicate with non-autonegotiating link partners.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700945 */
946 ret_val = e1000_check_for_link(hw);
947 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +0000948 e_dbg("Error while checking for link\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700949 return ret_val;
950 }
951 hw->autoneg_failed = 0;
952 } else {
953 hw->autoneg_failed = 0;
Emil Tantilov675ad472010-04-27 14:02:58 +0000954 e_dbg("Valid Link Found\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700955 }
956 } else {
Emil Tantilov675ad472010-04-27 14:02:58 +0000957 e_dbg("No Signal Detected\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700958 }
959 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960}
961
Jesse Brandeburg120a5d02009-09-25 15:19:46 -0700962/**
Dirk Brandewie5377a412011-01-06 14:29:54 +0000963 * e1000_copper_link_rtl_setup - Copper link setup for e1000_phy_rtl series.
964 * @hw: Struct containing variables accessed by shared code
965 *
966 * Commits changes to PHY configuration by calling e1000_phy_reset().
967 */
968static s32 e1000_copper_link_rtl_setup(struct e1000_hw *hw)
969{
970 s32 ret_val;
971
972 /* SW reset the PHY so all changes take effect */
973 ret_val = e1000_phy_reset(hw);
974 if (ret_val) {
975 e_dbg("Error Resetting the PHY\n");
976 return ret_val;
977 }
978
979 return E1000_SUCCESS;
980}
981
982static s32 gbe_dhg_phy_setup(struct e1000_hw *hw)
983{
984 s32 ret_val;
985 u32 ctrl_aux;
986
987 switch (hw->phy_type) {
988 case e1000_phy_8211:
989 ret_val = e1000_copper_link_rtl_setup(hw);
990 if (ret_val) {
991 e_dbg("e1000_copper_link_rtl_setup failed!\n");
992 return ret_val;
993 }
994 break;
995 case e1000_phy_8201:
996 /* Set RMII mode */
997 ctrl_aux = er32(CTL_AUX);
998 ctrl_aux |= E1000_CTL_AUX_RMII;
999 ew32(CTL_AUX, ctrl_aux);
1000 E1000_WRITE_FLUSH();
1001
1002 /* Disable the J/K bits required for receive */
1003 ctrl_aux = er32(CTL_AUX);
1004 ctrl_aux |= 0x4;
1005 ctrl_aux &= ~0x2;
1006 ew32(CTL_AUX, ctrl_aux);
1007 E1000_WRITE_FLUSH();
1008 ret_val = e1000_copper_link_rtl_setup(hw);
1009
1010 if (ret_val) {
1011 e_dbg("e1000_copper_link_rtl_setup failed!\n");
1012 return ret_val;
1013 }
1014 break;
1015 default:
1016 e_dbg("Error Resetting the PHY\n");
1017 return E1000_ERR_PHY_TYPE;
1018 }
1019
1020 return E1000_SUCCESS;
1021}
1022
1023/**
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001024 * e1000_copper_link_preconfig - early configuration for copper
1025 * @hw: Struct containing variables accessed by shared code
1026 *
1027 * Make sure we have a valid PHY and change PHY mode before link setup.
1028 */
Joe Perches64798842008-07-11 15:17:02 -07001029static s32 e1000_copper_link_preconfig(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001031 u32 ctrl;
1032 s32 ret_val;
1033 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001035 ctrl = er32(CTRL);
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001036 /* With 82543, we need to force speed and duplex on the MAC equal to
1037 * what the PHY speed and duplex configuration is. In addition, we need
1038 * to perform a hardware reset on the PHY to take it out of reset.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001039 */
1040 if (hw->mac_type > e1000_82543) {
1041 ctrl |= E1000_CTRL_SLU;
1042 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1043 ew32(CTRL, ctrl);
1044 } else {
1045 ctrl |=
1046 (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
1047 ew32(CTRL, ctrl);
1048 ret_val = e1000_phy_hw_reset(hw);
1049 if (ret_val)
1050 return ret_val;
1051 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001053 /* Make sure we have a valid PHY */
1054 ret_val = e1000_detect_gig_phy(hw);
1055 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00001056 e_dbg("Error, did not detect valid phy.\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001057 return ret_val;
1058 }
Emil Tantilov675ad472010-04-27 14:02:58 +00001059 e_dbg("Phy ID = %x\n", hw->phy_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001061 /* Set PHY to class A mode (if necessary) */
1062 ret_val = e1000_set_phy_mode(hw);
1063 if (ret_val)
1064 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001066 if ((hw->mac_type == e1000_82545_rev_3) ||
1067 (hw->mac_type == e1000_82546_rev_3)) {
1068 ret_val =
1069 e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1070 phy_data |= 0x00000008;
1071 ret_val =
1072 e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1073 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001075 if (hw->mac_type <= e1000_82543 ||
1076 hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
Janusz Wolak13a87c12015-09-28 23:40:19 +02001077 hw->mac_type == e1000_82541_rev_2 ||
1078 hw->mac_type == e1000_82547_rev_2)
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001079 hw->phy_reset_disable = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001081 return E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001082}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001084/**
1085 * e1000_copper_link_igp_setup - Copper link setup for e1000_phy_igp series.
1086 * @hw: Struct containing variables accessed by shared code
1087 */
Joe Perches64798842008-07-11 15:17:02 -07001088static s32 e1000_copper_link_igp_setup(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001089{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001090 u32 led_ctrl;
1091 s32 ret_val;
1092 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001094 if (hw->phy_reset_disable)
1095 return E1000_SUCCESS;
Auke Kok76c224b2006-05-23 13:36:06 -07001096
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001097 ret_val = e1000_phy_reset(hw);
1098 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00001099 e_dbg("Error Resetting the PHY\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001100 return ret_val;
1101 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001103 /* Wait 15ms for MAC to configure PHY from eeprom settings */
1104 msleep(15);
1105 /* Configure activity LED after PHY reset */
1106 led_ctrl = er32(LEDCTL);
1107 led_ctrl &= IGP_ACTIVITY_LED_MASK;
1108 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
1109 ew32(LEDCTL, led_ctrl);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001110
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001111 /* The NVM settings will configure LPLU in D3 for IGP2 and IGP3 PHYs */
1112 if (hw->phy_type == e1000_phy_igp) {
1113 /* disable lplu d3 during driver init */
1114 ret_val = e1000_set_d3_lplu_state(hw, false);
1115 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00001116 e_dbg("Error Disabling LPLU D3\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001117 return ret_val;
1118 }
1119 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001120
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001121 /* Configure mdi-mdix settings */
1122 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1123 if (ret_val)
1124 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001125
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001126 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
1127 hw->dsp_config_state = e1000_dsp_config_disabled;
1128 /* Force MDI for earlier revs of the IGP PHY */
1129 phy_data &=
1130 ~(IGP01E1000_PSCR_AUTO_MDIX |
1131 IGP01E1000_PSCR_FORCE_MDI_MDIX);
1132 hw->mdix = 1;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001133
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001134 } else {
1135 hw->dsp_config_state = e1000_dsp_config_enabled;
1136 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001137
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001138 switch (hw->mdix) {
1139 case 1:
1140 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1141 break;
1142 case 2:
1143 phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
1144 break;
1145 case 0:
1146 default:
1147 phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
1148 break;
1149 }
1150 }
1151 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1152 if (ret_val)
1153 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001154
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001155 /* set auto-master slave resolution settings */
1156 if (hw->autoneg) {
1157 e1000_ms_type phy_ms_setting = hw->master_slave;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001158
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001159 if (hw->ffe_config_state == e1000_ffe_config_active)
1160 hw->ffe_config_state = e1000_ffe_config_enabled;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001161
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001162 if (hw->dsp_config_state == e1000_dsp_config_activated)
1163 hw->dsp_config_state = e1000_dsp_config_enabled;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001164
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001165 /* when autonegotiation advertisement is only 1000Mbps then we
1166 * should disable SmartSpeed and enable Auto MasterSlave
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001167 * resolution as hardware default.
1168 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001169 if (hw->autoneg_advertised == ADVERTISE_1000_FULL) {
1170 /* Disable SmartSpeed */
1171 ret_val =
1172 e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1173 &phy_data);
1174 if (ret_val)
1175 return ret_val;
1176 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1177 ret_val =
1178 e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1179 phy_data);
1180 if (ret_val)
1181 return ret_val;
1182 /* Set auto Master/Slave resolution process */
1183 ret_val =
1184 e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1185 if (ret_val)
1186 return ret_val;
1187 phy_data &= ~CR_1000T_MS_ENABLE;
1188 ret_val =
1189 e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1190 if (ret_val)
1191 return ret_val;
1192 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001194 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1195 if (ret_val)
1196 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001198 /* load defaults for future use */
1199 hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
1200 ((phy_data & CR_1000T_MS_VALUE) ?
1201 e1000_ms_force_master :
1202 e1000_ms_force_slave) : e1000_ms_auto;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001204 switch (phy_ms_setting) {
1205 case e1000_ms_force_master:
1206 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
1207 break;
1208 case e1000_ms_force_slave:
1209 phy_data |= CR_1000T_MS_ENABLE;
1210 phy_data &= ~(CR_1000T_MS_VALUE);
1211 break;
1212 case e1000_ms_auto:
1213 phy_data &= ~CR_1000T_MS_ENABLE;
1214 default:
1215 break;
1216 }
1217 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1218 if (ret_val)
1219 return ret_val;
1220 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001222 return E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001223}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001225/**
1226 * e1000_copper_link_mgp_setup - Copper link setup for e1000_phy_m88 series.
1227 * @hw: Struct containing variables accessed by shared code
1228 */
Joe Perches64798842008-07-11 15:17:02 -07001229static s32 e1000_copper_link_mgp_setup(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001230{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001231 s32 ret_val;
1232 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001234 if (hw->phy_reset_disable)
1235 return E1000_SUCCESS;
Auke Kok76c224b2006-05-23 13:36:06 -07001236
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001237 /* Enable CRS on TX. This must be set for half-duplex operation. */
1238 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1239 if (ret_val)
1240 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001241
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001242 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001243
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001244 /* Options:
1245 * MDI/MDI-X = 0 (default)
1246 * 0 - Auto for all speeds
1247 * 1 - MDI mode
1248 * 2 - MDI-X mode
1249 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1250 */
1251 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001252
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001253 switch (hw->mdix) {
1254 case 1:
1255 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
1256 break;
1257 case 2:
1258 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
1259 break;
1260 case 3:
1261 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
1262 break;
1263 case 0:
1264 default:
1265 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
1266 break;
1267 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001268
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001269 /* Options:
1270 * disable_polarity_correction = 0 (default)
1271 * Automatic Correction for Reversed Cable Polarity
1272 * 0 - Disabled
1273 * 1 - Enabled
1274 */
1275 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
1276 if (hw->disable_polarity_correction == 1)
1277 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
1278 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1279 if (ret_val)
1280 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001281
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001282 if (hw->phy_revision < M88E1011_I_REV_4) {
1283 /* Force TX_CLK in the Extended PHY Specific Control Register
1284 * to 25MHz clock.
1285 */
1286 ret_val =
1287 e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
1288 &phy_data);
1289 if (ret_val)
1290 return ret_val;
Auke Kokee040222006-06-27 09:08:03 -07001291
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001292 phy_data |= M88E1000_EPSCR_TX_CLK_25;
Auke Kokee040222006-06-27 09:08:03 -07001293
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001294 if ((hw->phy_revision == E1000_REVISION_2) &&
1295 (hw->phy_id == M88E1111_I_PHY_ID)) {
1296 /* Vidalia Phy, set the downshift counter to 5x */
1297 phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK);
1298 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
1299 ret_val = e1000_write_phy_reg(hw,
1300 M88E1000_EXT_PHY_SPEC_CTRL,
1301 phy_data);
1302 if (ret_val)
1303 return ret_val;
1304 } else {
1305 /* Configure Master and Slave downshift values */
1306 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
1307 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
1308 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
1309 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
1310 ret_val = e1000_write_phy_reg(hw,
1311 M88E1000_EXT_PHY_SPEC_CTRL,
1312 phy_data);
1313 if (ret_val)
1314 return ret_val;
1315 }
1316 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001318 /* SW Reset the PHY so all changes take effect */
1319 ret_val = e1000_phy_reset(hw);
1320 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00001321 e_dbg("Error Resetting the PHY\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001322 return ret_val;
1323 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001324
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001325 return E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001326}
1327
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001328/**
1329 * e1000_copper_link_autoneg - setup auto-neg
1330 * @hw: Struct containing variables accessed by shared code
1331 *
1332 * Setup auto-negotiation and flow control advertisements,
1333 * and then perform auto-negotiation.
1334 */
Joe Perches64798842008-07-11 15:17:02 -07001335static s32 e1000_copper_link_autoneg(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001336{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001337 s32 ret_val;
1338 u16 phy_data;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001339
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001340 /* Perform some bounds checking on the hw->autoneg_advertised
1341 * parameter. If this variable is zero, then set it to the default.
1342 */
1343 hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001344
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001345 /* If autoneg_advertised is zero, we assume it was not defaulted
1346 * by the calling code so we set to advertise full capability.
1347 */
1348 if (hw->autoneg_advertised == 0)
1349 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001350
Dirk Brandewie5377a412011-01-06 14:29:54 +00001351 /* IFE/RTL8201N PHY only supports 10/100 */
1352 if (hw->phy_type == e1000_phy_8201)
1353 hw->autoneg_advertised &= AUTONEG_ADVERTISE_10_100_ALL;
1354
Emil Tantilov675ad472010-04-27 14:02:58 +00001355 e_dbg("Reconfiguring auto-neg advertisement params\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001356 ret_val = e1000_phy_setup_autoneg(hw);
1357 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00001358 e_dbg("Error Setting up Auto-Negotiation\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001359 return ret_val;
1360 }
Emil Tantilov675ad472010-04-27 14:02:58 +00001361 e_dbg("Restarting Auto-Neg\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001362
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001363 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
1364 * the Auto Neg Restart bit in the PHY control register.
1365 */
1366 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
1367 if (ret_val)
1368 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001369
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001370 phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
1371 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
1372 if (ret_val)
1373 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001374
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001375 /* Does the user want to wait for Auto-Neg to complete here, or
1376 * check at a later time (for example, callback routine).
1377 */
1378 if (hw->wait_autoneg_complete) {
1379 ret_val = e1000_wait_autoneg(hw);
1380 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00001381 e_dbg
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001382 ("Error while waiting for autoneg to complete\n");
1383 return ret_val;
1384 }
1385 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001387 hw->get_link_status = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001389 return E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001390}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001392/**
1393 * e1000_copper_link_postconfig - post link setup
1394 * @hw: Struct containing variables accessed by shared code
1395 *
1396 * Config the MAC and the PHY after link is up.
1397 * 1) Set up the MAC to the current PHY speed/duplex
1398 * if we are on 82543. If we
1399 * are on newer silicon, we only need to configure
1400 * collision distance in the Transmit Control Register.
1401 * 2) Set up flow control on the MAC to that established with
1402 * the link partner.
1403 * 3) Config DSP to improve Gigabit link quality for some PHY revisions.
1404 */
Joe Perches64798842008-07-11 15:17:02 -07001405static s32 e1000_copper_link_postconfig(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001406{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001407 s32 ret_val;
Auke Kok76c224b2006-05-23 13:36:06 -07001408
Dirk Brandewie5377a412011-01-06 14:29:54 +00001409 if ((hw->mac_type >= e1000_82544) && (hw->mac_type != e1000_ce4100)) {
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001410 e1000_config_collision_dist(hw);
1411 } else {
1412 ret_val = e1000_config_mac_to_phy(hw);
1413 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00001414 e_dbg("Error configuring MAC to PHY settings\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001415 return ret_val;
1416 }
1417 }
1418 ret_val = e1000_config_fc_after_link_up(hw);
1419 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00001420 e_dbg("Error Configuring Flow Control\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001421 return ret_val;
1422 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001423
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001424 /* Config DSP to improve Giga link quality */
1425 if (hw->phy_type == e1000_phy_igp) {
1426 ret_val = e1000_config_dsp_after_link_change(hw, true);
1427 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00001428 e_dbg("Error Configuring DSP after link up\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001429 return ret_val;
1430 }
1431 }
Auke Kok76c224b2006-05-23 13:36:06 -07001432
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001433 return E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001434}
1435
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001436/**
1437 * e1000_setup_copper_link - phy/speed/duplex setting
1438 * @hw: Struct containing variables accessed by shared code
1439 *
1440 * Detects which PHY is present and sets up the speed and duplex
1441 */
Joe Perches64798842008-07-11 15:17:02 -07001442static s32 e1000_setup_copper_link(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001443{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001444 s32 ret_val;
1445 u16 i;
1446 u16 phy_data;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001447
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001448 /* Check if it is a valid PHY and set PHY mode if necessary. */
1449 ret_val = e1000_copper_link_preconfig(hw);
1450 if (ret_val)
1451 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001452
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001453 if (hw->phy_type == e1000_phy_igp) {
1454 ret_val = e1000_copper_link_igp_setup(hw);
1455 if (ret_val)
1456 return ret_val;
1457 } else if (hw->phy_type == e1000_phy_m88) {
1458 ret_val = e1000_copper_link_mgp_setup(hw);
1459 if (ret_val)
1460 return ret_val;
Dirk Brandewie5377a412011-01-06 14:29:54 +00001461 } else {
1462 ret_val = gbe_dhg_phy_setup(hw);
1463 if (ret_val) {
1464 e_dbg("gbe_dhg_phy_setup failed!\n");
1465 return ret_val;
1466 }
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001467 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001468
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001469 if (hw->autoneg) {
1470 /* Setup autoneg and flow control advertisement
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001471 * and perform autonegotiation
1472 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001473 ret_val = e1000_copper_link_autoneg(hw);
1474 if (ret_val)
1475 return ret_val;
1476 } else {
1477 /* PHY will be set to 10H, 10F, 100H,or 100F
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001478 * depending on value from forced_speed_duplex.
1479 */
Emil Tantilov675ad472010-04-27 14:02:58 +00001480 e_dbg("Forcing speed and duplex\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001481 ret_val = e1000_phy_force_speed_duplex(hw);
1482 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00001483 e_dbg("Error Forcing Speed and Duplex\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001484 return ret_val;
1485 }
1486 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001488 /* Check link status. Wait up to 100 microseconds for link to become
1489 * valid.
1490 */
1491 for (i = 0; i < 10; i++) {
1492 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
1493 if (ret_val)
1494 return ret_val;
1495 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
1496 if (ret_val)
1497 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001499 if (phy_data & MII_SR_LINK_STATUS) {
1500 /* Config the MAC and PHY after link is up */
1501 ret_val = e1000_copper_link_postconfig(hw);
1502 if (ret_val)
1503 return ret_val;
Auke Kok76c224b2006-05-23 13:36:06 -07001504
Emil Tantilov675ad472010-04-27 14:02:58 +00001505 e_dbg("Valid link established!!!\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001506 return E1000_SUCCESS;
1507 }
1508 udelay(10);
1509 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510
Emil Tantilov675ad472010-04-27 14:02:58 +00001511 e_dbg("Unable to establish link!!!\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001512 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513}
1514
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001515/**
1516 * e1000_phy_setup_autoneg - phy settings
1517 * @hw: Struct containing variables accessed by shared code
1518 *
1519 * Configures PHY autoneg and flow control advertisement settings
1520 */
Joe Perches64798842008-07-11 15:17:02 -07001521s32 e1000_phy_setup_autoneg(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001523 s32 ret_val;
1524 u16 mii_autoneg_adv_reg;
1525 u16 mii_1000t_ctrl_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001527 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
1528 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
1529 if (ret_val)
1530 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001532 /* Read the MII 1000Base-T Control Register (Address 9). */
Dirk Brandewie5377a412011-01-06 14:29:54 +00001533 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001534 if (ret_val)
1535 return ret_val;
Dirk Brandewie5377a412011-01-06 14:29:54 +00001536 else if (hw->phy_type == e1000_phy_8201)
1537 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001539 /* Need to parse both autoneg_advertised and fc and set up
1540 * the appropriate PHY registers. First we will parse for
1541 * autoneg_advertised software override. Since we can advertise
1542 * a plethora of combinations, we need to check each bit
1543 * individually.
1544 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001546 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
1547 * Advertisement Register (Address 4) and the 1000 mb speed bits in
1548 * the 1000Base-T Control Register (Address 9).
1549 */
1550 mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
1551 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552
Emil Tantilov675ad472010-04-27 14:02:58 +00001553 e_dbg("autoneg_advertised %x\n", hw->autoneg_advertised);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001555 /* Do we want to advertise 10 Mb Half Duplex? */
1556 if (hw->autoneg_advertised & ADVERTISE_10_HALF) {
Emil Tantilov675ad472010-04-27 14:02:58 +00001557 e_dbg("Advertise 10mb Half duplex\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001558 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
1559 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001561 /* Do we want to advertise 10 Mb Full Duplex? */
1562 if (hw->autoneg_advertised & ADVERTISE_10_FULL) {
Emil Tantilov675ad472010-04-27 14:02:58 +00001563 e_dbg("Advertise 10mb Full duplex\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001564 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
1565 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001567 /* Do we want to advertise 100 Mb Half Duplex? */
1568 if (hw->autoneg_advertised & ADVERTISE_100_HALF) {
Emil Tantilov675ad472010-04-27 14:02:58 +00001569 e_dbg("Advertise 100mb Half duplex\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001570 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
1571 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001573 /* Do we want to advertise 100 Mb Full Duplex? */
1574 if (hw->autoneg_advertised & ADVERTISE_100_FULL) {
Emil Tantilov675ad472010-04-27 14:02:58 +00001575 e_dbg("Advertise 100mb Full duplex\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001576 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
1577 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001579 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
1580 if (hw->autoneg_advertised & ADVERTISE_1000_HALF) {
Emil Tantilov675ad472010-04-27 14:02:58 +00001581 e_dbg
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001582 ("Advertise 1000mb Half duplex requested, request denied!\n");
1583 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001585 /* Do we want to advertise 1000 Mb Full Duplex? */
1586 if (hw->autoneg_advertised & ADVERTISE_1000_FULL) {
Emil Tantilov675ad472010-04-27 14:02:58 +00001587 e_dbg("Advertise 1000mb Full duplex\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001588 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
1589 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001591 /* Check for a software override of the flow control settings, and
1592 * setup the PHY advertisement registers accordingly. If
1593 * auto-negotiation is enabled, then software will have to set the
1594 * "PAUSE" bits to the correct value in the Auto-Negotiation
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001595 * Advertisement Register (PHY_AUTONEG_ADV) and re-start
1596 * auto-negotiation.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001597 *
1598 * The possible values of the "fc" parameter are:
1599 * 0: Flow control is completely disabled
1600 * 1: Rx flow control is enabled (we can receive pause frames
1601 * but not send pause frames).
1602 * 2: Tx flow control is enabled (we can send pause frames
1603 * but we do not support receiving pause frames).
1604 * 3: Both Rx and TX flow control (symmetric) are enabled.
1605 * other: No software override. The flow control configuration
1606 * in the EEPROM is used.
1607 */
1608 switch (hw->fc) {
1609 case E1000_FC_NONE: /* 0 */
1610 /* Flow control (RX & TX) is completely disabled by a
1611 * software over-ride.
1612 */
1613 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1614 break;
1615 case E1000_FC_RX_PAUSE: /* 1 */
1616 /* RX Flow control is enabled, and TX Flow control is
1617 * disabled, by a software over-ride.
1618 */
1619 /* Since there really isn't a way to advertise that we are
1620 * capable of RX Pause ONLY, we will advertise that we
1621 * support both symmetric and asymmetric RX PAUSE. Later
1622 * (in e1000_config_fc_after_link_up) we will disable the
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001623 * hw's ability to send PAUSE frames.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001624 */
1625 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1626 break;
1627 case E1000_FC_TX_PAUSE: /* 2 */
1628 /* TX Flow control is enabled, and RX Flow control is
1629 * disabled, by a software over-ride.
1630 */
1631 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
1632 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
1633 break;
1634 case E1000_FC_FULL: /* 3 */
1635 /* Flow control (both RX and TX) is enabled by a software
1636 * over-ride.
1637 */
1638 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1639 break;
1640 default:
Emil Tantilov675ad472010-04-27 14:02:58 +00001641 e_dbg("Flow control param set incorrectly\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001642 return -E1000_ERR_CONFIG;
1643 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001645 ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
1646 if (ret_val)
1647 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648
Emil Tantilov675ad472010-04-27 14:02:58 +00001649 e_dbg("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650
Dirk Brandewie5377a412011-01-06 14:29:54 +00001651 if (hw->phy_type == e1000_phy_8201) {
1652 mii_1000t_ctrl_reg = 0;
1653 } else {
1654 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL,
Janusz Wolaka48954c2015-09-17 23:34:29 +02001655 mii_1000t_ctrl_reg);
Dirk Brandewie5377a412011-01-06 14:29:54 +00001656 if (ret_val)
1657 return ret_val;
1658 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001660 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661}
1662
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001663/**
1664 * e1000_phy_force_speed_duplex - force link settings
1665 * @hw: Struct containing variables accessed by shared code
1666 *
1667 * Force PHY speed and duplex settings to hw->forced_speed_duplex
1668 */
Joe Perches64798842008-07-11 15:17:02 -07001669static s32 e1000_phy_force_speed_duplex(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001671 u32 ctrl;
1672 s32 ret_val;
1673 u16 mii_ctrl_reg;
1674 u16 mii_status_reg;
1675 u16 phy_data;
1676 u16 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001678 /* Turn off Flow control if we are forcing speed and duplex. */
1679 hw->fc = E1000_FC_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680
Emil Tantilov675ad472010-04-27 14:02:58 +00001681 e_dbg("hw->fc = %d\n", hw->fc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001683 /* Read the Device Control Register. */
1684 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001686 /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */
1687 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1688 ctrl &= ~(DEVICE_SPEED_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001690 /* Clear the Auto Speed Detect Enable bit. */
1691 ctrl &= ~E1000_CTRL_ASDE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001693 /* Read the MII Control Register. */
1694 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg);
1695 if (ret_val)
1696 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001698 /* We need to disable autoneg in order to force link and duplex. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001700 mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001702 /* Are we forcing Full or Half Duplex? */
1703 if (hw->forced_speed_duplex == e1000_100_full ||
1704 hw->forced_speed_duplex == e1000_10_full) {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001705 /* We want to force full duplex so we SET the full duplex bits
1706 * in the Device and MII Control Registers.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001707 */
1708 ctrl |= E1000_CTRL_FD;
1709 mii_ctrl_reg |= MII_CR_FULL_DUPLEX;
Emil Tantilov675ad472010-04-27 14:02:58 +00001710 e_dbg("Full Duplex\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001711 } else {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001712 /* We want to force half duplex so we CLEAR the full duplex bits
1713 * in the Device and MII Control Registers.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001714 */
1715 ctrl &= ~E1000_CTRL_FD;
1716 mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX;
Emil Tantilov675ad472010-04-27 14:02:58 +00001717 e_dbg("Half Duplex\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001718 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001720 /* Are we forcing 100Mbps??? */
1721 if (hw->forced_speed_duplex == e1000_100_full ||
1722 hw->forced_speed_duplex == e1000_100_half) {
1723 /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */
1724 ctrl |= E1000_CTRL_SPD_100;
1725 mii_ctrl_reg |= MII_CR_SPEED_100;
1726 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
Emil Tantilov675ad472010-04-27 14:02:58 +00001727 e_dbg("Forcing 100mb ");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001728 } else {
1729 /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */
1730 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1731 mii_ctrl_reg |= MII_CR_SPEED_10;
1732 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
Emil Tantilov675ad472010-04-27 14:02:58 +00001733 e_dbg("Forcing 10mb ");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001734 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001736 e1000_config_collision_dist(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001738 /* Write the configured values back to the Device Control Reg. */
1739 ew32(CTRL, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001741 if (hw->phy_type == e1000_phy_m88) {
1742 ret_val =
1743 e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1744 if (ret_val)
1745 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001747 /* Clear Auto-Crossover to force MDI manually. M88E1000 requires
1748 * MDI forced whenever speed are duplex are forced.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001749 */
1750 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1751 ret_val =
1752 e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1753 if (ret_val)
1754 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755
Emil Tantilov675ad472010-04-27 14:02:58 +00001756 e_dbg("M88E1000 PSCR: %x\n", phy_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001758 /* Need to reset the PHY or these changes will be ignored */
1759 mii_ctrl_reg |= MII_CR_RESET;
Auke Kok90fb5132006-11-01 08:47:30 -08001760
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001761 /* Disable MDI-X support for 10/100 */
1762 } else {
1763 /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
1764 * forced whenever speed or duplex are forced.
1765 */
1766 ret_val =
1767 e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1768 if (ret_val)
1769 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001771 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1772 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001774 ret_val =
1775 e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1776 if (ret_val)
1777 return ret_val;
1778 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001780 /* Write back the modified PHY MII control register. */
1781 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg);
1782 if (ret_val)
1783 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001785 udelay(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001787 /* The wait_autoneg_complete flag may be a little misleading here.
1788 * Since we are forcing speed and duplex, Auto-Neg is not enabled.
1789 * But we do want to delay for a period while forcing only so we
1790 * don't generate false No Link messages. So we will wait here
1791 * only if the user has set wait_autoneg_complete to 1, which is
1792 * the default.
1793 */
1794 if (hw->wait_autoneg_complete) {
1795 /* We will wait for autoneg to complete. */
Emil Tantilov675ad472010-04-27 14:02:58 +00001796 e_dbg("Waiting for forced speed/duplex link.\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001797 mii_status_reg = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001799 /* Wait for autoneg to complete or 4.5 seconds to expire */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001800 for (i = PHY_FORCE_TIME; i > 0; i--) {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001801 /* Read the MII Status Register and wait for Auto-Neg
1802 * Complete bit to be set.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001803 */
1804 ret_val =
1805 e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1806 if (ret_val)
1807 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001809 ret_val =
1810 e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1811 if (ret_val)
1812 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001814 if (mii_status_reg & MII_SR_LINK_STATUS)
1815 break;
1816 msleep(100);
1817 }
1818 if ((i == 0) && (hw->phy_type == e1000_phy_m88)) {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001819 /* We didn't get link. Reset the DSP and wait again
1820 * for link.
1821 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001822 ret_val = e1000_phy_reset_dsp(hw);
1823 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00001824 e_dbg("Error Resetting PHY DSP\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001825 return ret_val;
1826 }
1827 }
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001828 /* This loop will early-out if the link condition has been
1829 * met
1830 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001831 for (i = PHY_FORCE_TIME; i > 0; i--) {
1832 if (mii_status_reg & MII_SR_LINK_STATUS)
1833 break;
1834 msleep(100);
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001835 /* Read the MII Status Register and wait for Auto-Neg
1836 * Complete bit to be set.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001837 */
1838 ret_val =
1839 e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1840 if (ret_val)
1841 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001843 ret_val =
1844 e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1845 if (ret_val)
1846 return ret_val;
1847 }
1848 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001850 if (hw->phy_type == e1000_phy_m88) {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001851 /* Because we reset the PHY above, we need to re-force TX_CLK in
1852 * the Extended PHY Specific Control Register to 25MHz clock.
1853 * This value defaults back to a 2.5MHz clock when the PHY is
1854 * reset.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001855 */
1856 ret_val =
1857 e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
1858 &phy_data);
1859 if (ret_val)
1860 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001862 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1863 ret_val =
1864 e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
1865 phy_data);
1866 if (ret_val)
1867 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001869 /* In addition, because of the s/w reset above, we need to
1870 * enable CRS on Tx. This must be set for both full and half
1871 * duplex operation.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001872 */
1873 ret_val =
1874 e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1875 if (ret_val)
1876 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001878 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1879 ret_val =
1880 e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1881 if (ret_val)
1882 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883
Janusz Wolak13a87c12015-09-28 23:40:19 +02001884 if ((hw->mac_type == e1000_82544 ||
1885 hw->mac_type == e1000_82543) &&
1886 (!hw->autoneg) &&
1887 (hw->forced_speed_duplex == e1000_10_full ||
1888 hw->forced_speed_duplex == e1000_10_half)) {
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001889 ret_val = e1000_polarity_reversal_workaround(hw);
1890 if (ret_val)
1891 return ret_val;
1892 }
1893 }
1894 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895}
1896
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001897/**
1898 * e1000_config_collision_dist - set collision distance register
1899 * @hw: Struct containing variables accessed by shared code
1900 *
1901 * Sets the collision distance in the Transmit Control register.
1902 * Link should have been established previously. Reads the speed and duplex
1903 * information from the Device Status register.
1904 */
Joe Perches64798842008-07-11 15:17:02 -07001905void e1000_config_collision_dist(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001907 u32 tctl, coll_dist;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001909 if (hw->mac_type < e1000_82543)
1910 coll_dist = E1000_COLLISION_DISTANCE_82542;
1911 else
1912 coll_dist = E1000_COLLISION_DISTANCE;
Jeff Kirsher0fadb052006-01-12 16:51:05 -08001913
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001914 tctl = er32(TCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001916 tctl &= ~E1000_TCTL_COLD;
1917 tctl |= coll_dist << E1000_COLD_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001918
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001919 ew32(TCTL, tctl);
1920 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921}
1922
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001923/**
1924 * e1000_config_mac_to_phy - sync phy and mac settings
1925 * @hw: Struct containing variables accessed by shared code
1926 * @mii_reg: data to write to the MII control register
1927 *
1928 * Sets MAC speed and duplex settings to reflect the those in the PHY
1929 * The contents of the PHY register containing the needed information need to
1930 * be passed in.
1931 */
Joe Perches64798842008-07-11 15:17:02 -07001932static s32 e1000_config_mac_to_phy(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001934 u32 ctrl;
1935 s32 ret_val;
1936 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001937
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001938 /* 82544 or newer MAC, Auto Speed Detection takes care of
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001939 * MAC speed/duplex configuration.
1940 */
Dirk Brandewie5377a412011-01-06 14:29:54 +00001941 if ((hw->mac_type >= e1000_82544) && (hw->mac_type != e1000_ce4100))
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001942 return E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001943
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001944 /* Read the Device Control Register and set the bits to Force Speed
1945 * and Duplex.
1946 */
1947 ctrl = er32(CTRL);
1948 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1949 ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950
Dirk Brandewie5377a412011-01-06 14:29:54 +00001951 switch (hw->phy_type) {
1952 case e1000_phy_8201:
1953 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
1954 if (ret_val)
1955 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956
Dirk Brandewie5377a412011-01-06 14:29:54 +00001957 if (phy_data & RTL_PHY_CTRL_FD)
1958 ctrl |= E1000_CTRL_FD;
1959 else
1960 ctrl &= ~E1000_CTRL_FD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961
Dirk Brandewie5377a412011-01-06 14:29:54 +00001962 if (phy_data & RTL_PHY_CTRL_SPD_100)
1963 ctrl |= E1000_CTRL_SPD_100;
1964 else
1965 ctrl |= E1000_CTRL_SPD_10;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001966
Dirk Brandewie5377a412011-01-06 14:29:54 +00001967 e1000_config_collision_dist(hw);
1968 break;
1969 default:
1970 /* Set up duplex in the Device Control and Transmit Control
1971 * registers depending on negotiated values.
1972 */
1973 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001974 &phy_data);
Dirk Brandewie5377a412011-01-06 14:29:54 +00001975 if (ret_val)
1976 return ret_val;
1977
1978 if (phy_data & M88E1000_PSSR_DPLX)
1979 ctrl |= E1000_CTRL_FD;
1980 else
1981 ctrl &= ~E1000_CTRL_FD;
1982
1983 e1000_config_collision_dist(hw);
1984
1985 /* Set up speed in the Device Control register depending on
1986 * negotiated values.
1987 */
1988 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
1989 ctrl |= E1000_CTRL_SPD_1000;
1990 else if ((phy_data & M88E1000_PSSR_SPEED) ==
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00001991 M88E1000_PSSR_100MBS)
Dirk Brandewie5377a412011-01-06 14:29:54 +00001992 ctrl |= E1000_CTRL_SPD_100;
1993 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07001995 /* Write the configured values back to the Device Control Reg. */
1996 ew32(CTRL, ctrl);
1997 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998}
1999
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002000/**
2001 * e1000_force_mac_fc - force flow control settings
2002 * @hw: Struct containing variables accessed by shared code
2003 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004 * Forces the MAC's flow control settings.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005 * Sets the TFCE and RFCE bits in the device control register to reflect
2006 * the adapter settings. TFCE and RFCE need to be explicitly set by
2007 * software when a Copper PHY is used because autonegotiation is managed
2008 * by the PHY rather than the MAC. Software must also configure these
2009 * bits when link is forced on a fiber connection.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002010 */
Joe Perches64798842008-07-11 15:17:02 -07002011s32 e1000_force_mac_fc(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002013 u32 ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002014
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002015 /* Get the current configuration of the Device Control Register */
2016 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002018 /* Because we didn't get link via the internal auto-negotiation
2019 * mechanism (we either forced link or we got link via PHY
2020 * auto-neg), we have to manually enable/disable transmit an
2021 * receive flow control.
2022 *
2023 * The "Case" statement below enables/disable flow control
2024 * according to the "hw->fc" parameter.
2025 *
2026 * The possible values of the "fc" parameter are:
2027 * 0: Flow control is completely disabled
2028 * 1: Rx flow control is enabled (we can receive pause
2029 * frames but not send pause frames).
2030 * 2: Tx flow control is enabled (we can send pause frames
2031 * frames but we do not receive pause frames).
2032 * 3: Both Rx and TX flow control (symmetric) is enabled.
2033 * other: No other values should be possible at this point.
2034 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002036 switch (hw->fc) {
2037 case E1000_FC_NONE:
2038 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
2039 break;
2040 case E1000_FC_RX_PAUSE:
2041 ctrl &= (~E1000_CTRL_TFCE);
2042 ctrl |= E1000_CTRL_RFCE;
2043 break;
2044 case E1000_FC_TX_PAUSE:
2045 ctrl &= (~E1000_CTRL_RFCE);
2046 ctrl |= E1000_CTRL_TFCE;
2047 break;
2048 case E1000_FC_FULL:
2049 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
2050 break;
2051 default:
Emil Tantilov675ad472010-04-27 14:02:58 +00002052 e_dbg("Flow control param set incorrectly\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002053 return -E1000_ERR_CONFIG;
2054 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002056 /* Disable TX Flow Control for 82542 (rev 2.0) */
2057 if (hw->mac_type == e1000_82542_rev2_0)
2058 ctrl &= (~E1000_CTRL_TFCE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002060 ew32(CTRL, ctrl);
2061 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062}
2063
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002064/**
2065 * e1000_config_fc_after_link_up - configure flow control after autoneg
2066 * @hw: Struct containing variables accessed by shared code
2067 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068 * Configures flow control settings after link is established
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069 * Should be called immediately after a valid link has been established.
2070 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
2071 * and autonegotiation is enabled, the MAC flow control settings will be set
2072 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002073 * and RFCE bits will be automatically set to the negotiated flow control mode.
2074 */
Joe Perches64798842008-07-11 15:17:02 -07002075static s32 e1000_config_fc_after_link_up(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002077 s32 ret_val;
2078 u16 mii_status_reg;
2079 u16 mii_nway_adv_reg;
2080 u16 mii_nway_lp_ability_reg;
2081 u16 speed;
2082 u16 duplex;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002084 /* Check for the case where we have fiber media and auto-neg failed
2085 * so we had to force link. In this case, we need to force the
2086 * configuration of the MAC to match the "fc" parameter.
2087 */
Janusz Wolak13a87c12015-09-28 23:40:19 +02002088 if (((hw->media_type == e1000_media_type_fiber) &&
2089 (hw->autoneg_failed)) ||
2090 ((hw->media_type == e1000_media_type_internal_serdes) &&
2091 (hw->autoneg_failed)) ||
2092 ((hw->media_type == e1000_media_type_copper) &&
2093 (!hw->autoneg))) {
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002094 ret_val = e1000_force_mac_fc(hw);
2095 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00002096 e_dbg("Error forcing flow control settings\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002097 return ret_val;
2098 }
2099 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002101 /* Check for the case where we have copper media and auto-neg is
2102 * enabled. In this case, we need to check and see if Auto-Neg
2103 * has completed, and if so, how the PHY and link partner has
2104 * flow control configured.
2105 */
2106 if ((hw->media_type == e1000_media_type_copper) && hw->autoneg) {
2107 /* Read the MII Status Register and check to see if AutoNeg
2108 * has completed. We read this twice because this reg has
2109 * some "sticky" (latched) bits.
2110 */
2111 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2112 if (ret_val)
2113 return ret_val;
2114 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2115 if (ret_val)
2116 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002118 if (mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
2119 /* The AutoNeg process has completed, so we now need to
2120 * read both the Auto Negotiation Advertisement Register
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002121 * (Address 4) and the Auto_Negotiation Base Page
2122 * Ability Register (Address 5) to determine how flow
2123 * control was negotiated.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002124 */
2125 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV,
2126 &mii_nway_adv_reg);
2127 if (ret_val)
2128 return ret_val;
2129 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY,
2130 &mii_nway_lp_ability_reg);
2131 if (ret_val)
2132 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002134 /* Two bits in the Auto Negotiation Advertisement
2135 * Register (Address 4) and two bits in the Auto
2136 * Negotiation Base Page Ability Register (Address 5)
2137 * determine flow control for both the PHY and the link
2138 * partner. The following table, taken out of the IEEE
2139 * 802.3ab/D6.0 dated March 25, 1999, describes these
2140 * PAUSE resolution bits and how flow control is
2141 * determined based upon these settings.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002142 * NOTE: DC = Don't Care
2143 *
2144 * LOCAL DEVICE | LINK PARTNER
2145 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002146 *-------|---------|-------|---------|------------------
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002147 * 0 | 0 | DC | DC | E1000_FC_NONE
2148 * 0 | 1 | 0 | DC | E1000_FC_NONE
2149 * 0 | 1 | 1 | 0 | E1000_FC_NONE
2150 * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
2151 * 1 | 0 | 0 | DC | E1000_FC_NONE
2152 * 1 | DC | 1 | DC | E1000_FC_FULL
2153 * 1 | 1 | 0 | 0 | E1000_FC_NONE
2154 * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
2155 *
2156 */
2157 /* Are both PAUSE bits set to 1? If so, this implies
2158 * Symmetric Flow Control is enabled at both ends. The
2159 * ASM_DIR bits are irrelevant per the spec.
2160 *
2161 * For Symmetric Flow Control:
2162 *
2163 * LOCAL DEVICE | LINK PARTNER
2164 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002165 *-------|---------|-------|---------|------------------
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002166 * 1 | DC | 1 | DC | E1000_FC_FULL
2167 *
2168 */
2169 if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2170 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002171 /* Now we need to check if the user selected Rx
2172 * ONLY of pause frames. In this case, we had
2173 * to advertise FULL flow control because we
2174 * could not advertise Rx ONLY. Hence, we must
2175 * now check to see if we need to turn OFF the
2176 * TRANSMISSION of PAUSE frames.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002177 */
2178 if (hw->original_fc == E1000_FC_FULL) {
2179 hw->fc = E1000_FC_FULL;
Emil Tantilov675ad472010-04-27 14:02:58 +00002180 e_dbg("Flow Control = FULL.\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002181 } else {
2182 hw->fc = E1000_FC_RX_PAUSE;
Emil Tantilov675ad472010-04-27 14:02:58 +00002183 e_dbg
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002184 ("Flow Control = RX PAUSE frames only.\n");
2185 }
2186 }
2187 /* For receiving PAUSE frames ONLY.
2188 *
2189 * LOCAL DEVICE | LINK PARTNER
2190 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002191 *-------|---------|-------|---------|------------------
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002192 * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
2193 *
2194 */
2195 else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2196 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2197 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
Janusz Wolaka48954c2015-09-17 23:34:29 +02002198 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002199 hw->fc = E1000_FC_TX_PAUSE;
Emil Tantilov675ad472010-04-27 14:02:58 +00002200 e_dbg
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002201 ("Flow Control = TX PAUSE frames only.\n");
2202 }
2203 /* For transmitting PAUSE frames ONLY.
2204 *
2205 * LOCAL DEVICE | LINK PARTNER
2206 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002207 *-------|---------|-------|---------|------------------
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002208 * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
2209 *
2210 */
2211 else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2212 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2213 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
Janusz Wolaka48954c2015-09-17 23:34:29 +02002214 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002215 hw->fc = E1000_FC_RX_PAUSE;
Emil Tantilov675ad472010-04-27 14:02:58 +00002216 e_dbg
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002217 ("Flow Control = RX PAUSE frames only.\n");
2218 }
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002219 /* Per the IEEE spec, at this point flow control should
2220 * be disabled. However, we want to consider that we
2221 * could be connected to a legacy switch that doesn't
2222 * advertise desired flow control, but can be forced on
2223 * the link partner. So if we advertised no flow
2224 * control, that is what we will resolve to. If we
2225 * advertised some kind of receive capability (Rx Pause
2226 * Only or Full Flow Control) and the link partner
2227 * advertised none, we will configure ourselves to
2228 * enable Rx Flow Control only. We can do this safely
2229 * for two reasons: If the link partner really
2230 * didn't want flow control enabled, and we enable Rx,
2231 * no harm done since we won't be receiving any PAUSE
2232 * frames anyway. If the intent on the link partner was
2233 * to have flow control enabled, then by us enabling Rx
2234 * only, we can at least receive pause frames and
2235 * process them. This is a good idea because in most
2236 * cases, since we are predominantly a server NIC, more
2237 * times than not we will be asked to delay transmission
2238 * of packets than asking our link partner to pause
2239 * transmission of frames.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002240 */
2241 else if ((hw->original_fc == E1000_FC_NONE ||
2242 hw->original_fc == E1000_FC_TX_PAUSE) ||
2243 hw->fc_strict_ieee) {
2244 hw->fc = E1000_FC_NONE;
Emil Tantilov675ad472010-04-27 14:02:58 +00002245 e_dbg("Flow Control = NONE.\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002246 } else {
2247 hw->fc = E1000_FC_RX_PAUSE;
Emil Tantilov675ad472010-04-27 14:02:58 +00002248 e_dbg
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002249 ("Flow Control = RX PAUSE frames only.\n");
2250 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002252 /* Now we need to do one last check... If we auto-
2253 * negotiated to HALF DUPLEX, flow control should not be
2254 * enabled per IEEE 802.3 spec.
2255 */
2256 ret_val =
2257 e1000_get_speed_and_duplex(hw, &speed, &duplex);
2258 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00002259 e_dbg
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002260 ("Error getting link speed and duplex\n");
2261 return ret_val;
2262 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002264 if (duplex == HALF_DUPLEX)
2265 hw->fc = E1000_FC_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002267 /* Now we call a subroutine to actually force the MAC
2268 * controller to use the correct flow control settings.
2269 */
2270 ret_val = e1000_force_mac_fc(hw);
2271 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00002272 e_dbg
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002273 ("Error forcing flow control settings\n");
2274 return ret_val;
2275 }
2276 } else {
Emil Tantilov675ad472010-04-27 14:02:58 +00002277 e_dbg
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002278 ("Copper PHY and Auto Neg has not completed.\n");
2279 }
2280 }
2281 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282}
2283
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002284/**
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002285 * e1000_check_for_serdes_link_generic - Check for link (Serdes)
2286 * @hw: pointer to the HW structure
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002287 *
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002288 * Checks for link up on the hardware. If link is not up and we have
2289 * a signal, then we need to force link up.
2290 */
Jesse Brandeburg11b7f7b2009-09-25 12:20:33 +00002291static s32 e1000_check_for_serdes_link_generic(struct e1000_hw *hw)
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002292{
2293 u32 rxcw;
2294 u32 ctrl;
2295 u32 status;
2296 s32 ret_val = E1000_SUCCESS;
2297
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002298 ctrl = er32(CTRL);
2299 status = er32(STATUS);
2300 rxcw = er32(RXCW);
2301
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002302 /* If we don't have link (auto-negotiation failed or link partner
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002303 * cannot auto-negotiate), and our link partner is not trying to
2304 * auto-negotiate with us (we are receiving idles or data),
2305 * we need to force link up. We also need to give auto-negotiation
2306 * time to complete.
2307 */
2308 /* (ctrl & E1000_CTRL_SWDPIN1) == 1 == have signal */
2309 if ((!(status & E1000_STATUS_LU)) && (!(rxcw & E1000_RXCW_C))) {
2310 if (hw->autoneg_failed == 0) {
2311 hw->autoneg_failed = 1;
2312 goto out;
2313 }
Emil Tantilov675ad472010-04-27 14:02:58 +00002314 e_dbg("NOT RXing /C/, disable AutoNeg and force link.\n");
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002315
2316 /* Disable auto-negotiation in the TXCW register */
2317 ew32(TXCW, (hw->txcw & ~E1000_TXCW_ANE));
2318
2319 /* Force link-up and also force full-duplex. */
2320 ctrl = er32(CTRL);
2321 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
2322 ew32(CTRL, ctrl);
2323
2324 /* Configure Flow Control after forcing link up. */
2325 ret_val = e1000_config_fc_after_link_up(hw);
2326 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00002327 e_dbg("Error configuring flow control\n");
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002328 goto out;
2329 }
2330 } else if ((ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002331 /* If we are forcing link and we are receiving /C/ ordered
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002332 * sets, re-enable auto-negotiation in the TXCW register
2333 * and disable forced link in the Device Control register
2334 * in an attempt to auto-negotiate with our link partner.
2335 */
Emil Tantilov675ad472010-04-27 14:02:58 +00002336 e_dbg("RXing /C/, enable AutoNeg and stop forcing link.\n");
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002337 ew32(TXCW, hw->txcw);
2338 ew32(CTRL, (ctrl & ~E1000_CTRL_SLU));
2339
2340 hw->serdes_has_link = true;
2341 } else if (!(E1000_TXCW_ANE & er32(TXCW))) {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002342 /* If we force link for non-auto-negotiation switch, check
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002343 * link status based on MAC synchronization for internal
2344 * serdes media type.
2345 */
2346 /* SYNCH bit and IV bit are sticky. */
2347 udelay(10);
2348 rxcw = er32(RXCW);
2349 if (rxcw & E1000_RXCW_SYNCH) {
2350 if (!(rxcw & E1000_RXCW_IV)) {
2351 hw->serdes_has_link = true;
Emil Tantilov675ad472010-04-27 14:02:58 +00002352 e_dbg("SERDES: Link up - forced.\n");
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002353 }
2354 } else {
2355 hw->serdes_has_link = false;
Emil Tantilov675ad472010-04-27 14:02:58 +00002356 e_dbg("SERDES: Link down - force failed.\n");
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002357 }
2358 }
2359
2360 if (E1000_TXCW_ANE & er32(TXCW)) {
2361 status = er32(STATUS);
2362 if (status & E1000_STATUS_LU) {
2363 /* SYNCH bit and IV bit are sticky, so reread rxcw. */
2364 udelay(10);
2365 rxcw = er32(RXCW);
2366 if (rxcw & E1000_RXCW_SYNCH) {
2367 if (!(rxcw & E1000_RXCW_IV)) {
2368 hw->serdes_has_link = true;
Emil Tantilov675ad472010-04-27 14:02:58 +00002369 e_dbg("SERDES: Link up - autoneg "
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002370 "completed successfully.\n");
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002371 } else {
2372 hw->serdes_has_link = false;
Emil Tantilov675ad472010-04-27 14:02:58 +00002373 e_dbg("SERDES: Link down - invalid"
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002374 "codewords detected in autoneg.\n");
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002375 }
2376 } else {
2377 hw->serdes_has_link = false;
Emil Tantilov675ad472010-04-27 14:02:58 +00002378 e_dbg("SERDES: Link down - no sync.\n");
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002379 }
2380 } else {
2381 hw->serdes_has_link = false;
Emil Tantilov675ad472010-04-27 14:02:58 +00002382 e_dbg("SERDES: Link down - autoneg failed\n");
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002383 }
2384 }
2385
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002386 out:
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00002387 return ret_val;
2388}
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002389
2390/**
2391 * e1000_check_for_link
2392 * @hw: Struct containing variables accessed by shared code
2393 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394 * Checks to see if the link status of the hardware has changed.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395 * Called by any function that needs to check the link status of the adapter.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002396 */
Joe Perches64798842008-07-11 15:17:02 -07002397s32 e1000_check_for_link(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002399 u32 rxcw = 0;
2400 u32 ctrl;
2401 u32 status;
2402 u32 rctl;
2403 u32 icr;
2404 u32 signal = 0;
2405 s32 ret_val;
2406 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002408 ctrl = er32(CTRL);
2409 status = er32(STATUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002411 /* On adapters with a MAC newer than 82544, SW Definable pin 1 will be
2412 * set when the optics detect a signal. On older adapters, it will be
2413 * cleared when there is a signal. This applies to fiber media only.
2414 */
2415 if ((hw->media_type == e1000_media_type_fiber) ||
2416 (hw->media_type == e1000_media_type_internal_serdes)) {
2417 rxcw = er32(RXCW);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002419 if (hw->media_type == e1000_media_type_fiber) {
2420 signal =
2421 (hw->mac_type >
2422 e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
2423 if (status & E1000_STATUS_LU)
2424 hw->get_link_status = false;
2425 }
2426 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002428 /* If we have a copper PHY then we only want to go out to the PHY
2429 * registers to see if Auto-Neg has completed and/or if our link
2430 * status has changed. The get_link_status flag will be set if we
2431 * receive a Link Status Change interrupt or we have Rx Sequence
2432 * Errors.
2433 */
2434 if ((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
2435 /* First we want to see if the MII Status Register reports
2436 * link. If so, then we want to get the current speed/duplex
2437 * of the PHY.
2438 * Read the register twice since the link bit is sticky.
2439 */
2440 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2441 if (ret_val)
2442 return ret_val;
2443 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2444 if (ret_val)
2445 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002447 if (phy_data & MII_SR_LINK_STATUS) {
2448 hw->get_link_status = false;
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002449 /* Check if there was DownShift, must be checked
2450 * immediately after link-up
2451 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002452 e1000_check_downshift(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002454 /* If we are on 82544 or 82543 silicon and speed/duplex
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002455 * are forced to 10H or 10F, then we will implement the
2456 * polarity reversal workaround. We disable interrupts
2457 * first, and upon returning, place the devices
2458 * interrupt state to its previous value except for the
2459 * link status change interrupt which will
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002460 * happen due to the execution of this workaround.
2461 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462
Janusz Wolak13a87c12015-09-28 23:40:19 +02002463 if ((hw->mac_type == e1000_82544 ||
2464 hw->mac_type == e1000_82543) &&
2465 (!hw->autoneg) &&
2466 (hw->forced_speed_duplex == e1000_10_full ||
2467 hw->forced_speed_duplex == e1000_10_half)) {
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002468 ew32(IMC, 0xffffffff);
2469 ret_val =
2470 e1000_polarity_reversal_workaround(hw);
2471 icr = er32(ICR);
2472 ew32(ICS, (icr & ~E1000_ICS_LSC));
2473 ew32(IMS, IMS_ENABLE_MASK);
2474 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002476 } else {
2477 /* No link detected */
2478 e1000_config_dsp_after_link_change(hw, false);
2479 return 0;
2480 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002482 /* If we are forcing speed/duplex, then we simply return since
2483 * we have already determined whether we have link or not.
2484 */
2485 if (!hw->autoneg)
2486 return -E1000_ERR_CONFIG;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002488 /* optimize the dsp settings for the igp phy */
2489 e1000_config_dsp_after_link_change(hw, true);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002491 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
2492 * have Si on board that is 82544 or newer, Auto
2493 * Speed Detection takes care of MAC speed/duplex
2494 * configuration. So we only need to configure Collision
2495 * Distance in the MAC. Otherwise, we need to force
2496 * speed/duplex on the MAC to the current PHY speed/duplex
2497 * settings.
2498 */
Dirk Brandewie5377a412011-01-06 14:29:54 +00002499 if ((hw->mac_type >= e1000_82544) &&
2500 (hw->mac_type != e1000_ce4100))
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002501 e1000_config_collision_dist(hw);
2502 else {
2503 ret_val = e1000_config_mac_to_phy(hw);
2504 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00002505 e_dbg
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002506 ("Error configuring MAC to PHY settings\n");
2507 return ret_val;
2508 }
2509 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002511 /* Configure Flow Control now that Auto-Neg has completed.
2512 * First, we need to restore the desired flow control settings
2513 * because we may have had to re-autoneg with a different link
2514 * partner.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002515 */
2516 ret_val = e1000_config_fc_after_link_up(hw);
2517 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00002518 e_dbg("Error configuring flow control\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002519 return ret_val;
2520 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002522 /* At this point we know that we are on copper and we have
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002523 * auto-negotiated link. These are conditions for checking the
2524 * link partner capability register. We use the link speed to
2525 * determine if TBI compatibility needs to be turned on or off.
2526 * If the link is not at gigabit speed, then TBI compatibility
2527 * is not needed. If we are at gigabit speed, we turn on TBI
2528 * compatibility.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002529 */
2530 if (hw->tbi_compatibility_en) {
2531 u16 speed, duplex;
Janusz Wolak13a87c12015-09-28 23:40:19 +02002532
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002533 ret_val =
2534 e1000_get_speed_and_duplex(hw, &speed, &duplex);
Janusz Wolak13a87c12015-09-28 23:40:19 +02002535
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002536 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00002537 e_dbg
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002538 ("Error getting link speed and duplex\n");
2539 return ret_val;
2540 }
2541 if (speed != SPEED_1000) {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002542 /* If link speed is not set to gigabit speed, we
2543 * do not need to enable TBI compatibility.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002544 */
2545 if (hw->tbi_compatibility_on) {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002546 /* If we previously were in the mode,
2547 * turn it off.
2548 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002549 rctl = er32(RCTL);
2550 rctl &= ~E1000_RCTL_SBP;
2551 ew32(RCTL, rctl);
2552 hw->tbi_compatibility_on = false;
2553 }
2554 } else {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002555 /* If TBI compatibility is was previously off,
2556 * turn it on. For compatibility with a TBI link
2557 * partner, we will store bad packets. Some
2558 * frames have an additional byte on the end and
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002559 * will look like CRC errors to to the hardware.
2560 */
2561 if (!hw->tbi_compatibility_on) {
2562 hw->tbi_compatibility_on = true;
2563 rctl = er32(RCTL);
2564 rctl |= E1000_RCTL_SBP;
2565 ew32(RCTL, rctl);
2566 }
2567 }
2568 }
2569 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002571 if ((hw->media_type == e1000_media_type_fiber) ||
2572 (hw->media_type == e1000_media_type_internal_serdes))
2573 e1000_check_for_serdes_link_generic(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002575 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576}
2577
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002578/**
2579 * e1000_get_speed_and_duplex
2580 * @hw: Struct containing variables accessed by shared code
2581 * @speed: Speed of the connection
2582 * @duplex: Duplex setting of the connection
Ben Hutchings49ce9c22012-07-10 10:56:00 +00002583 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584 * Detects the current speed and duplex settings of the hardware.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002585 */
Joe Perches64798842008-07-11 15:17:02 -07002586s32 e1000_get_speed_and_duplex(struct e1000_hw *hw, u16 *speed, u16 *duplex)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002588 u32 status;
2589 s32 ret_val;
2590 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002592 if (hw->mac_type >= e1000_82543) {
2593 status = er32(STATUS);
2594 if (status & E1000_STATUS_SPEED_1000) {
2595 *speed = SPEED_1000;
Emil Tantilov675ad472010-04-27 14:02:58 +00002596 e_dbg("1000 Mbs, ");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002597 } else if (status & E1000_STATUS_SPEED_100) {
2598 *speed = SPEED_100;
Emil Tantilov675ad472010-04-27 14:02:58 +00002599 e_dbg("100 Mbs, ");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002600 } else {
2601 *speed = SPEED_10;
Emil Tantilov675ad472010-04-27 14:02:58 +00002602 e_dbg("10 Mbs, ");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002603 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002605 if (status & E1000_STATUS_FD) {
2606 *duplex = FULL_DUPLEX;
Emil Tantilov675ad472010-04-27 14:02:58 +00002607 e_dbg("Full Duplex\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002608 } else {
2609 *duplex = HALF_DUPLEX;
Emil Tantilov675ad472010-04-27 14:02:58 +00002610 e_dbg(" Half Duplex\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002611 }
2612 } else {
Emil Tantilov675ad472010-04-27 14:02:58 +00002613 e_dbg("1000 Mbs, Full Duplex\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002614 *speed = SPEED_1000;
2615 *duplex = FULL_DUPLEX;
2616 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002618 /* IGP01 PHY may advertise full duplex operation after speed downgrade
2619 * even if it is operating at half duplex. Here we set the duplex
2620 * settings to match the duplex in the link partner's capabilities.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002621 */
2622 if (hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
2623 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
2624 if (ret_val)
2625 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002627 if (!(phy_data & NWAY_ER_LP_NWAY_CAPS))
2628 *duplex = HALF_DUPLEX;
2629 else {
2630 ret_val =
2631 e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data);
2632 if (ret_val)
2633 return ret_val;
Janusz Wolak13a87c12015-09-28 23:40:19 +02002634 if ((*speed == SPEED_100 &&
2635 !(phy_data & NWAY_LPAR_100TX_FD_CAPS)) ||
2636 (*speed == SPEED_10 &&
2637 !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002638 *duplex = HALF_DUPLEX;
2639 }
2640 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002642 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643}
2644
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002645/**
2646 * e1000_wait_autoneg
2647 * @hw: Struct containing variables accessed by shared code
2648 *
2649 * Blocks until autoneg completes or times out (~4.5 seconds)
2650 */
Joe Perches64798842008-07-11 15:17:02 -07002651static s32 e1000_wait_autoneg(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002652{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002653 s32 ret_val;
2654 u16 i;
2655 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002656
Emil Tantilov675ad472010-04-27 14:02:58 +00002657 e_dbg("Waiting for Auto-Neg to complete.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002659 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
2660 for (i = PHY_AUTO_NEG_TIME; i > 0; i--) {
2661 /* Read the MII Status Register and wait for Auto-Neg
2662 * Complete bit to be set.
2663 */
2664 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2665 if (ret_val)
2666 return ret_val;
2667 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2668 if (ret_val)
2669 return ret_val;
Janusz Wolak13a87c12015-09-28 23:40:19 +02002670 if (phy_data & MII_SR_AUTONEG_COMPLETE)
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002671 return E1000_SUCCESS;
Janusz Wolak13a87c12015-09-28 23:40:19 +02002672
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002673 msleep(100);
2674 }
2675 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002676}
2677
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002678/**
2679 * e1000_raise_mdi_clk - Raises the Management Data Clock
2680 * @hw: Struct containing variables accessed by shared code
2681 * @ctrl: Device control register's current value
2682 */
Joe Perches64798842008-07-11 15:17:02 -07002683static void e1000_raise_mdi_clk(struct e1000_hw *hw, u32 *ctrl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002684{
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002685 /* Raise the clock input to the Management Data Clock (by setting the
2686 * MDC bit), and then delay 10 microseconds.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002687 */
2688 ew32(CTRL, (*ctrl | E1000_CTRL_MDC));
2689 E1000_WRITE_FLUSH();
2690 udelay(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002691}
2692
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002693/**
2694 * e1000_lower_mdi_clk - Lowers the Management Data Clock
2695 * @hw: Struct containing variables accessed by shared code
2696 * @ctrl: Device control register's current value
2697 */
Joe Perches64798842008-07-11 15:17:02 -07002698static void e1000_lower_mdi_clk(struct e1000_hw *hw, u32 *ctrl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002699{
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002700 /* Lower the clock input to the Management Data Clock (by clearing the
2701 * MDC bit), and then delay 10 microseconds.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002702 */
2703 ew32(CTRL, (*ctrl & ~E1000_CTRL_MDC));
2704 E1000_WRITE_FLUSH();
2705 udelay(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002706}
2707
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002708/**
2709 * e1000_shift_out_mdi_bits - Shifts data bits out to the PHY
2710 * @hw: Struct containing variables accessed by shared code
2711 * @data: Data to send out to the PHY
2712 * @count: Number of bits to shift out
2713 *
2714 * Bits are shifted out in MSB to LSB order.
2715 */
Joe Perches64798842008-07-11 15:17:02 -07002716static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, u32 data, u16 count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002718 u32 ctrl;
2719 u32 mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002720
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002721 /* We need to shift "count" number of bits out to the PHY. So, the value
2722 * in the "data" parameter will be shifted out to the PHY one bit at a
2723 * time. In order to do this, "data" must be broken down into bits.
2724 */
2725 mask = 0x01;
2726 mask <<= (count - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002727
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002728 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002729
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002730 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
2731 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002733 while (mask) {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002734 /* A "1" is shifted out to the PHY by setting the MDIO bit to
2735 * "1" and then raising and lowering the Management Data Clock.
2736 * A "0" is shifted out to the PHY by setting the MDIO bit to
2737 * "0" and then raising and lowering the clock.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002738 */
2739 if (data & mask)
2740 ctrl |= E1000_CTRL_MDIO;
2741 else
2742 ctrl &= ~E1000_CTRL_MDIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002744 ew32(CTRL, ctrl);
2745 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002746
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002747 udelay(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002748
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002749 e1000_raise_mdi_clk(hw, &ctrl);
2750 e1000_lower_mdi_clk(hw, &ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002751
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002752 mask = mask >> 1;
2753 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002754}
2755
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002756/**
2757 * e1000_shift_in_mdi_bits - Shifts data bits in from the PHY
2758 * @hw: Struct containing variables accessed by shared code
2759 *
2760 * Bits are shifted in in MSB to LSB order.
2761 */
Joe Perches64798842008-07-11 15:17:02 -07002762static u16 e1000_shift_in_mdi_bits(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002763{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002764 u32 ctrl;
2765 u16 data = 0;
2766 u8 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002768 /* In order to read a register from the PHY, we need to shift in a total
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002769 * of 18 bits from the PHY. The first two bit (turnaround) times are
2770 * used to avoid contention on the MDIO pin when a read operation is
2771 * performed. These two bits are ignored by us and thrown away. Bits are
2772 * "shifted in" by raising the input to the Management Data Clock
2773 * (setting the MDC bit), and then reading the value of the MDIO bit.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002774 */
2775 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002776
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002777 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as
2778 * input.
2779 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002780 ctrl &= ~E1000_CTRL_MDIO_DIR;
2781 ctrl &= ~E1000_CTRL_MDIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002782
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002783 ew32(CTRL, ctrl);
2784 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002785
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002786 /* Raise and Lower the clock before reading in the data. This accounts
2787 * for the turnaround bits. The first clock occurred when we clocked out
2788 * the last bit of the Register Address.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002789 */
2790 e1000_raise_mdi_clk(hw, &ctrl);
2791 e1000_lower_mdi_clk(hw, &ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002792
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002793 for (data = 0, i = 0; i < 16; i++) {
2794 data = data << 1;
2795 e1000_raise_mdi_clk(hw, &ctrl);
2796 ctrl = er32(CTRL);
2797 /* Check to see if we shifted in a "1". */
2798 if (ctrl & E1000_CTRL_MDIO)
2799 data |= 1;
2800 e1000_lower_mdi_clk(hw, &ctrl);
2801 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002802
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002803 e1000_raise_mdi_clk(hw, &ctrl);
2804 e1000_lower_mdi_clk(hw, &ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002805
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002806 return data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002807}
2808
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002809/**
2810 * e1000_read_phy_reg - read a phy register
2811 * @hw: Struct containing variables accessed by shared code
2812 * @reg_addr: address of the PHY register to read
Jean Sacrenf03fed62015-09-19 05:08:46 -06002813 * @phy_data: pointer to the value on the PHY register
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002814 *
2815 * Reads the value from a PHY register, if the value is on a specific non zero
2816 * page, sets the page first.
2817 */
Joe Perches64798842008-07-11 15:17:02 -07002818s32 e1000_read_phy_reg(struct e1000_hw *hw, u32 reg_addr, u16 *phy_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002819{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002820 u32 ret_val;
Maxime Bizonac565582012-10-20 14:53:40 +00002821 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002822
Maxime Bizonac565582012-10-20 14:53:40 +00002823 spin_lock_irqsave(&e1000_phy_lock, flags);
2824
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002825 if ((hw->phy_type == e1000_phy_igp) &&
2826 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
2827 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
2828 (u16) reg_addr);
Jean Sacrenc6195812015-09-19 05:08:47 -06002829 if (ret_val)
2830 goto out;
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002831 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002832
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002833 ret_val = e1000_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
2834 phy_data);
Jean Sacrenc6195812015-09-19 05:08:47 -06002835out:
Maxime Bizonac565582012-10-20 14:53:40 +00002836 spin_unlock_irqrestore(&e1000_phy_lock, flags);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002837
2838 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002839}
2840
Joe Perches64798842008-07-11 15:17:02 -07002841static s32 e1000_read_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr,
2842 u16 *phy_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002843{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002844 u32 i;
2845 u32 mdic = 0;
Dirk Brandewie5377a412011-01-06 14:29:54 +00002846 const u32 phy_addr = (hw->mac_type == e1000_ce4100) ? hw->phy_addr : 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002847
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002848 if (reg_addr > MAX_PHY_REG_ADDRESS) {
Emil Tantilov675ad472010-04-27 14:02:58 +00002849 e_dbg("PHY Address %d is out of range\n", reg_addr);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002850 return -E1000_ERR_PARAM;
2851 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002852
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002853 if (hw->mac_type > e1000_82543) {
2854 /* Set up Op-code, Phy Address, and register address in the MDI
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002855 * Control register. The MAC will take care of interfacing with
2856 * the PHY to retrieve the desired data.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002857 */
Dirk Brandewie5377a412011-01-06 14:29:54 +00002858 if (hw->mac_type == e1000_ce4100) {
2859 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
2860 (phy_addr << E1000_MDIC_PHY_SHIFT) |
2861 (INTEL_CE_GBE_MDIC_OP_READ) |
2862 (INTEL_CE_GBE_MDIC_GO));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002863
Dirk Brandewie5377a412011-01-06 14:29:54 +00002864 writel(mdic, E1000_MDIO_CMD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002865
Dirk Brandewie5377a412011-01-06 14:29:54 +00002866 /* Poll the ready bit to see if the MDI read
2867 * completed
2868 */
2869 for (i = 0; i < 64; i++) {
2870 udelay(50);
2871 mdic = readl(E1000_MDIO_CMD);
2872 if (!(mdic & INTEL_CE_GBE_MDIC_GO))
2873 break;
2874 }
2875
2876 if (mdic & INTEL_CE_GBE_MDIC_GO) {
2877 e_dbg("MDI Read did not complete\n");
2878 return -E1000_ERR_PHY;
2879 }
2880
2881 mdic = readl(E1000_MDIO_STS);
2882 if (mdic & INTEL_CE_GBE_MDIC_READ_ERROR) {
2883 e_dbg("MDI Read Error\n");
2884 return -E1000_ERR_PHY;
2885 }
Janusz Wolak13a87c12015-09-28 23:40:19 +02002886 *phy_data = (u16)mdic;
Dirk Brandewie5377a412011-01-06 14:29:54 +00002887 } else {
2888 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
2889 (phy_addr << E1000_MDIC_PHY_SHIFT) |
2890 (E1000_MDIC_OP_READ));
2891
2892 ew32(MDIC, mdic);
2893
2894 /* Poll the ready bit to see if the MDI read
2895 * completed
2896 */
2897 for (i = 0; i < 64; i++) {
2898 udelay(50);
2899 mdic = er32(MDIC);
2900 if (mdic & E1000_MDIC_READY)
2901 break;
2902 }
2903 if (!(mdic & E1000_MDIC_READY)) {
2904 e_dbg("MDI Read did not complete\n");
2905 return -E1000_ERR_PHY;
2906 }
2907 if (mdic & E1000_MDIC_ERROR) {
2908 e_dbg("MDI Error\n");
2909 return -E1000_ERR_PHY;
2910 }
Janusz Wolak13a87c12015-09-28 23:40:19 +02002911 *phy_data = (u16)mdic;
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002912 }
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002913 } else {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002914 /* We must first send a preamble through the MDIO pin to signal
2915 * the beginning of an MII instruction. This is done by sending
2916 * 32 consecutive "1" bits.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002917 */
2918 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002920 /* Now combine the next few fields that are required for a read
2921 * operation. We use this method instead of calling the
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002922 * e1000_shift_out_mdi_bits routine five different times. The
2923 * format of a MII read instruction consists of a shift out of
2924 * 14 bits and is defined as follows:
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002925 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002926 * followed by a shift in of 18 bits. This first two bits
2927 * shifted in are TurnAround bits used to avoid contention on
2928 * the MDIO pin when a READ operation is performed. These two
2929 * bits are thrown away followed by a shift in of 16 bits which
2930 * contains the desired data.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002931 */
2932 mdic = ((reg_addr) | (phy_addr << 5) |
2933 (PHY_OP_READ << 10) | (PHY_SOF << 12));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002934
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002935 e1000_shift_out_mdi_bits(hw, mdic, 14);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002936
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00002937 /* Now that we've shifted out the read command to the MII, we
2938 * need to "shift in" the 16-bit value (18 total bits) of the
2939 * requested PHY register address.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002940 */
2941 *phy_data = e1000_shift_in_mdi_bits(hw);
2942 }
2943 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002944}
2945
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002946/**
2947 * e1000_write_phy_reg - write a phy register
2948 *
2949 * @hw: Struct containing variables accessed by shared code
2950 * @reg_addr: address of the PHY register to write
2951 * @data: data to write to the PHY
Ben Hutchings49ce9c22012-07-10 10:56:00 +00002952 *
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002953 * Writes a value to a PHY register
2954 */
Joe Perches64798842008-07-11 15:17:02 -07002955s32 e1000_write_phy_reg(struct e1000_hw *hw, u32 reg_addr, u16 phy_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002956{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002957 u32 ret_val;
Maxime Bizonac565582012-10-20 14:53:40 +00002958 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002959
Maxime Bizonac565582012-10-20 14:53:40 +00002960 spin_lock_irqsave(&e1000_phy_lock, flags);
2961
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002962 if ((hw->phy_type == e1000_phy_igp) &&
2963 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
2964 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
Janusz Wolak13a87c12015-09-28 23:40:19 +02002965 (u16)reg_addr);
Maxime Bizonac565582012-10-20 14:53:40 +00002966 if (ret_val) {
2967 spin_unlock_irqrestore(&e1000_phy_lock, flags);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002968 return ret_val;
Maxime Bizonac565582012-10-20 14:53:40 +00002969 }
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002970 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002971
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002972 ret_val = e1000_write_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
2973 phy_data);
Maxime Bizonac565582012-10-20 14:53:40 +00002974 spin_unlock_irqrestore(&e1000_phy_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002975
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002976 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002977}
2978
Joe Perches64798842008-07-11 15:17:02 -07002979static s32 e1000_write_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr,
2980 u16 phy_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002981{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002982 u32 i;
2983 u32 mdic = 0;
Dirk Brandewie5377a412011-01-06 14:29:54 +00002984 const u32 phy_addr = (hw->mac_type == e1000_ce4100) ? hw->phy_addr : 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002985
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002986 if (reg_addr > MAX_PHY_REG_ADDRESS) {
Emil Tantilov675ad472010-04-27 14:02:58 +00002987 e_dbg("PHY Address %d is out of range\n", reg_addr);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002988 return -E1000_ERR_PARAM;
2989 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002990
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002991 if (hw->mac_type > e1000_82543) {
Dirk Brandewie5377a412011-01-06 14:29:54 +00002992 /* Set up Op-code, Phy Address, register address, and data
2993 * intended for the PHY register in the MDI Control register.
2994 * The MAC will take care of interfacing with the PHY to send
2995 * the desired data.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07002996 */
Dirk Brandewie5377a412011-01-06 14:29:54 +00002997 if (hw->mac_type == e1000_ce4100) {
Janusz Wolak13a87c12015-09-28 23:40:19 +02002998 mdic = (((u32)phy_data) |
Dirk Brandewie5377a412011-01-06 14:29:54 +00002999 (reg_addr << E1000_MDIC_REG_SHIFT) |
3000 (phy_addr << E1000_MDIC_PHY_SHIFT) |
3001 (INTEL_CE_GBE_MDIC_OP_WRITE) |
3002 (INTEL_CE_GBE_MDIC_GO));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003003
Dirk Brandewie5377a412011-01-06 14:29:54 +00003004 writel(mdic, E1000_MDIO_CMD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003005
Dirk Brandewie5377a412011-01-06 14:29:54 +00003006 /* Poll the ready bit to see if the MDI read
3007 * completed
3008 */
3009 for (i = 0; i < 640; i++) {
3010 udelay(5);
3011 mdic = readl(E1000_MDIO_CMD);
3012 if (!(mdic & INTEL_CE_GBE_MDIC_GO))
3013 break;
3014 }
3015 if (mdic & INTEL_CE_GBE_MDIC_GO) {
3016 e_dbg("MDI Write did not complete\n");
3017 return -E1000_ERR_PHY;
3018 }
3019 } else {
Janusz Wolak13a87c12015-09-28 23:40:19 +02003020 mdic = (((u32)phy_data) |
Dirk Brandewie5377a412011-01-06 14:29:54 +00003021 (reg_addr << E1000_MDIC_REG_SHIFT) |
3022 (phy_addr << E1000_MDIC_PHY_SHIFT) |
3023 (E1000_MDIC_OP_WRITE));
3024
3025 ew32(MDIC, mdic);
3026
3027 /* Poll the ready bit to see if the MDI read
3028 * completed
3029 */
3030 for (i = 0; i < 641; i++) {
3031 udelay(5);
3032 mdic = er32(MDIC);
3033 if (mdic & E1000_MDIC_READY)
3034 break;
3035 }
3036 if (!(mdic & E1000_MDIC_READY)) {
3037 e_dbg("MDI Write did not complete\n");
3038 return -E1000_ERR_PHY;
3039 }
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003040 }
3041 } else {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003042 /* We'll need to use the SW defined pins to shift the write
3043 * command out to the PHY. We first send a preamble to the PHY
3044 * to signal the beginning of the MII instruction. This is done
3045 * by sending 32 consecutive "1" bits.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003046 */
3047 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003048
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003049 /* Now combine the remaining required fields that will indicate
3050 * a write operation. We use this method instead of calling the
3051 * e1000_shift_out_mdi_bits routine for each field in the
3052 * command. The format of a MII write instruction is as follows:
3053 * <Preamble><SOF><OpCode><PhyAddr><RegAddr><Turnaround><Data>.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003054 */
3055 mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
3056 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
3057 mdic <<= 16;
Janusz Wolak13a87c12015-09-28 23:40:19 +02003058 mdic |= (u32)phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003059
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003060 e1000_shift_out_mdi_bits(hw, mdic, 32);
3061 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003062
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003063 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003064}
3065
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003066/**
3067 * e1000_phy_hw_reset - reset the phy, hardware style
3068 * @hw: Struct containing variables accessed by shared code
3069 *
3070 * Returns the PHY to the power-on reset state
3071 */
Joe Perches64798842008-07-11 15:17:02 -07003072s32 e1000_phy_hw_reset(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003073{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003074 u32 ctrl, ctrl_ext;
3075 u32 led_ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003076
Emil Tantilov675ad472010-04-27 14:02:58 +00003077 e_dbg("Resetting Phy...\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003078
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003079 if (hw->mac_type > e1000_82543) {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003080 /* Read the device control register and assert the
3081 * E1000_CTRL_PHY_RST bit. Then, take it out of reset.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003082 * For e1000 hardware, we delay for 10ms between the assert
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003083 * and de-assert.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003084 */
3085 ctrl = er32(CTRL);
3086 ew32(CTRL, ctrl | E1000_CTRL_PHY_RST);
3087 E1000_WRITE_FLUSH();
Auke Kok76c224b2006-05-23 13:36:06 -07003088
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003089 msleep(10);
Auke Kok76c224b2006-05-23 13:36:06 -07003090
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003091 ew32(CTRL, ctrl);
3092 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003093
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003094 } else {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003095 /* Read the Extended Device Control Register, assert the
3096 * PHY_RESET_DIR bit to put the PHY into reset. Then, take it
3097 * out of reset.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003098 */
3099 ctrl_ext = er32(CTRL_EXT);
3100 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
3101 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
3102 ew32(CTRL_EXT, ctrl_ext);
3103 E1000_WRITE_FLUSH();
3104 msleep(10);
3105 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
3106 ew32(CTRL_EXT, ctrl_ext);
3107 E1000_WRITE_FLUSH();
3108 }
3109 udelay(150);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003110
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003111 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
3112 /* Configure activity LED after PHY reset */
3113 led_ctrl = er32(LEDCTL);
3114 led_ctrl &= IGP_ACTIVITY_LED_MASK;
3115 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
3116 ew32(LEDCTL, led_ctrl);
3117 }
Auke Kok8fc897b2006-08-28 14:56:16 -07003118
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003119 /* Wait for FW to finish PHY configuration. */
Greg Dietschec4dc4d12011-06-16 07:09:30 +00003120 return e1000_get_phy_cfg_done(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003121}
3122
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003123/**
3124 * e1000_phy_reset - reset the phy to commit settings
3125 * @hw: Struct containing variables accessed by shared code
3126 *
3127 * Resets the PHY
3128 * Sets bit 15 of the MII Control register
3129 */
Joe Perches64798842008-07-11 15:17:02 -07003130s32 e1000_phy_reset(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003131{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003132 s32 ret_val;
3133 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003134
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003135 switch (hw->phy_type) {
3136 case e1000_phy_igp:
3137 ret_val = e1000_phy_hw_reset(hw);
3138 if (ret_val)
3139 return ret_val;
3140 break;
3141 default:
3142 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
3143 if (ret_val)
3144 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003145
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003146 phy_data |= MII_CR_RESET;
3147 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
3148 if (ret_val)
3149 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003150
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003151 udelay(1);
3152 break;
3153 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003154
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003155 if (hw->phy_type == e1000_phy_igp)
3156 e1000_phy_init_script(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003157
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003158 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003159}
3160
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003161/**
3162 * e1000_detect_gig_phy - check the phy type
3163 * @hw: Struct containing variables accessed by shared code
3164 *
3165 * Probes the expected PHY address for known PHY IDs
3166 */
Joe Perches64798842008-07-11 15:17:02 -07003167static s32 e1000_detect_gig_phy(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003168{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003169 s32 phy_init_status, ret_val;
3170 u16 phy_id_high, phy_id_low;
3171 bool match = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003172
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003173 if (hw->phy_id != 0)
3174 return E1000_SUCCESS;
Jeff Kirsher2a88c172006-09-27 12:54:05 -07003175
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003176 /* Read the PHY ID Registers to identify which PHY is onboard. */
3177 ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
3178 if (ret_val)
3179 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003180
Janusz Wolak13a87c12015-09-28 23:40:19 +02003181 hw->phy_id = (u32)(phy_id_high << 16);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003182 udelay(20);
3183 ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
3184 if (ret_val)
3185 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003186
Janusz Wolak13a87c12015-09-28 23:40:19 +02003187 hw->phy_id |= (u32)(phy_id_low & PHY_REVISION_MASK);
3188 hw->phy_revision = (u32)phy_id_low & ~PHY_REVISION_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003189
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003190 switch (hw->mac_type) {
3191 case e1000_82543:
3192 if (hw->phy_id == M88E1000_E_PHY_ID)
3193 match = true;
3194 break;
3195 case e1000_82544:
3196 if (hw->phy_id == M88E1000_I_PHY_ID)
3197 match = true;
3198 break;
3199 case e1000_82540:
3200 case e1000_82545:
3201 case e1000_82545_rev_3:
3202 case e1000_82546:
3203 case e1000_82546_rev_3:
3204 if (hw->phy_id == M88E1011_I_PHY_ID)
3205 match = true;
3206 break;
Dirk Brandewie5377a412011-01-06 14:29:54 +00003207 case e1000_ce4100:
3208 if ((hw->phy_id == RTL8211B_PHY_ID) ||
Florian Fainellicf8e09b2011-01-24 14:48:03 +00003209 (hw->phy_id == RTL8201N_PHY_ID) ||
3210 (hw->phy_id == M88E1118_E_PHY_ID))
Dirk Brandewie5377a412011-01-06 14:29:54 +00003211 match = true;
3212 break;
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003213 case e1000_82541:
3214 case e1000_82541_rev_2:
3215 case e1000_82547:
3216 case e1000_82547_rev_2:
3217 if (hw->phy_id == IGP01E1000_I_PHY_ID)
3218 match = true;
3219 break;
3220 default:
Emil Tantilov675ad472010-04-27 14:02:58 +00003221 e_dbg("Invalid MAC type %d\n", hw->mac_type);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003222 return -E1000_ERR_CONFIG;
3223 }
3224 phy_init_status = e1000_set_phy_type(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003225
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003226 if ((match) && (phy_init_status == E1000_SUCCESS)) {
Emil Tantilov675ad472010-04-27 14:02:58 +00003227 e_dbg("PHY ID 0x%X detected\n", hw->phy_id);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003228 return E1000_SUCCESS;
3229 }
Emil Tantilov675ad472010-04-27 14:02:58 +00003230 e_dbg("Invalid PHY ID 0x%X\n", hw->phy_id);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003231 return -E1000_ERR_PHY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003232}
3233
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003234/**
3235 * e1000_phy_reset_dsp - reset DSP
3236 * @hw: Struct containing variables accessed by shared code
3237 *
3238 * Resets the PHY's DSP
3239 */
Joe Perches64798842008-07-11 15:17:02 -07003240static s32 e1000_phy_reset_dsp(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003241{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003242 s32 ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003243
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003244 do {
3245 ret_val = e1000_write_phy_reg(hw, 29, 0x001d);
3246 if (ret_val)
3247 break;
3248 ret_val = e1000_write_phy_reg(hw, 30, 0x00c1);
3249 if (ret_val)
3250 break;
3251 ret_val = e1000_write_phy_reg(hw, 30, 0x0000);
3252 if (ret_val)
3253 break;
3254 ret_val = E1000_SUCCESS;
3255 } while (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003256
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003257 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003258}
3259
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003260/**
3261 * e1000_phy_igp_get_info - get igp specific registers
3262 * @hw: Struct containing variables accessed by shared code
3263 * @phy_info: PHY information structure
3264 *
3265 * Get PHY information from various PHY registers for igp PHY only.
3266 */
Joe Perches64798842008-07-11 15:17:02 -07003267static s32 e1000_phy_igp_get_info(struct e1000_hw *hw,
3268 struct e1000_phy_info *phy_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003269{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003270 s32 ret_val;
3271 u16 phy_data, min_length, max_length, average;
3272 e1000_rev_polarity polarity;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003273
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003274 /* The downshift status is checked only once, after link is established,
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003275 * and it stored in the hw->speed_downgraded parameter.
3276 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003277 phy_info->downshift = (e1000_downshift) hw->speed_downgraded;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003278
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003279 /* IGP01E1000 does not need to support it. */
3280 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003281
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003282 /* IGP01E1000 always correct polarity reversal */
3283 phy_info->polarity_correction = e1000_polarity_reversal_enabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003284
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003285 /* Check polarity status */
3286 ret_val = e1000_check_polarity(hw, &polarity);
3287 if (ret_val)
3288 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003289
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003290 phy_info->cable_polarity = polarity;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003291
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003292 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, &phy_data);
3293 if (ret_val)
3294 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003295
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003296 phy_info->mdix_mode =
3297 (e1000_auto_x_mode) ((phy_data & IGP01E1000_PSSR_MDIX) >>
3298 IGP01E1000_PSSR_MDIX_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003299
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003300 if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
3301 IGP01E1000_PSSR_SPEED_1000MBPS) {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003302 /* Local/Remote Receiver Information are only valid @ 1000
3303 * Mbps
3304 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003305 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
3306 if (ret_val)
3307 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003308
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003309 phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
3310 SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
3311 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
3312 phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
3313 SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
3314 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003315
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003316 /* Get cable length */
3317 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
3318 if (ret_val)
3319 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003320
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003321 /* Translate to old method */
3322 average = (max_length + min_length) / 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003323
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003324 if (average <= e1000_igp_cable_length_50)
3325 phy_info->cable_length = e1000_cable_length_50;
3326 else if (average <= e1000_igp_cable_length_80)
3327 phy_info->cable_length = e1000_cable_length_50_80;
3328 else if (average <= e1000_igp_cable_length_110)
3329 phy_info->cable_length = e1000_cable_length_80_110;
3330 else if (average <= e1000_igp_cable_length_140)
3331 phy_info->cable_length = e1000_cable_length_110_140;
3332 else
3333 phy_info->cable_length = e1000_cable_length_140;
3334 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003335
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003336 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003337}
3338
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003339/**
3340 * e1000_phy_m88_get_info - get m88 specific registers
3341 * @hw: Struct containing variables accessed by shared code
3342 * @phy_info: PHY information structure
3343 *
3344 * Get PHY information from various PHY registers for m88 PHY only.
3345 */
Joe Perches64798842008-07-11 15:17:02 -07003346static s32 e1000_phy_m88_get_info(struct e1000_hw *hw,
3347 struct e1000_phy_info *phy_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003348{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003349 s32 ret_val;
3350 u16 phy_data;
3351 e1000_rev_polarity polarity;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003352
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003353 /* The downshift status is checked only once, after link is established,
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003354 * and it stored in the hw->speed_downgraded parameter.
3355 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003356 phy_info->downshift = (e1000_downshift) hw->speed_downgraded;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003357
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003358 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
3359 if (ret_val)
3360 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003361
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003362 phy_info->extended_10bt_distance =
3363 ((phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >>
3364 M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT) ?
3365 e1000_10bt_ext_dist_enable_lower :
3366 e1000_10bt_ext_dist_enable_normal;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07003367
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003368 phy_info->polarity_correction =
3369 ((phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >>
3370 M88E1000_PSCR_POLARITY_REVERSAL_SHIFT) ?
3371 e1000_polarity_reversal_disabled : e1000_polarity_reversal_enabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003372
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003373 /* Check polarity status */
3374 ret_val = e1000_check_polarity(hw, &polarity);
3375 if (ret_val)
3376 return ret_val;
3377 phy_info->cable_polarity = polarity;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003378
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003379 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
3380 if (ret_val)
3381 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003382
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003383 phy_info->mdix_mode =
3384 (e1000_auto_x_mode) ((phy_data & M88E1000_PSSR_MDIX) >>
3385 M88E1000_PSSR_MDIX_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003386
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003387 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
3388 /* Cable Length Estimation and Local/Remote Receiver Information
3389 * are only valid at 1000 Mbps.
3390 */
3391 phy_info->cable_length =
3392 (e1000_cable_length) ((phy_data &
3393 M88E1000_PSSR_CABLE_LENGTH) >>
3394 M88E1000_PSSR_CABLE_LENGTH_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003395
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003396 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
3397 if (ret_val)
3398 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003399
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003400 phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
3401 SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
3402 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
3403 phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
3404 SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
3405 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003406 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003407
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003408 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003409}
3410
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003411/**
3412 * e1000_phy_get_info - request phy info
3413 * @hw: Struct containing variables accessed by shared code
3414 * @phy_info: PHY information structure
3415 *
3416 * Get PHY information from various PHY registers
3417 */
Joe Perches64798842008-07-11 15:17:02 -07003418s32 e1000_phy_get_info(struct e1000_hw *hw, struct e1000_phy_info *phy_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003419{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003420 s32 ret_val;
3421 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003422
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003423 phy_info->cable_length = e1000_cable_length_undefined;
3424 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined;
3425 phy_info->cable_polarity = e1000_rev_polarity_undefined;
3426 phy_info->downshift = e1000_downshift_undefined;
3427 phy_info->polarity_correction = e1000_polarity_reversal_undefined;
3428 phy_info->mdix_mode = e1000_auto_x_mode_undefined;
3429 phy_info->local_rx = e1000_1000t_rx_status_undefined;
3430 phy_info->remote_rx = e1000_1000t_rx_status_undefined;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003431
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003432 if (hw->media_type != e1000_media_type_copper) {
Emil Tantilov675ad472010-04-27 14:02:58 +00003433 e_dbg("PHY info is only valid for copper media\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003434 return -E1000_ERR_CONFIG;
3435 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003436
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003437 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3438 if (ret_val)
3439 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003440
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003441 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3442 if (ret_val)
3443 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003444
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003445 if ((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) {
Emil Tantilov675ad472010-04-27 14:02:58 +00003446 e_dbg("PHY info is only valid if link is up\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003447 return -E1000_ERR_CONFIG;
3448 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003449
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003450 if (hw->phy_type == e1000_phy_igp)
3451 return e1000_phy_igp_get_info(hw, phy_info);
Dirk Brandewie5377a412011-01-06 14:29:54 +00003452 else if ((hw->phy_type == e1000_phy_8211) ||
Janusz Wolaka48954c2015-09-17 23:34:29 +02003453 (hw->phy_type == e1000_phy_8201))
Dirk Brandewie5377a412011-01-06 14:29:54 +00003454 return E1000_SUCCESS;
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003455 else
3456 return e1000_phy_m88_get_info(hw, phy_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003457}
3458
Joe Perches64798842008-07-11 15:17:02 -07003459s32 e1000_validate_mdi_setting(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003460{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003461 if (!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) {
Emil Tantilov675ad472010-04-27 14:02:58 +00003462 e_dbg("Invalid MDI setting detected\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003463 hw->mdix = 1;
3464 return -E1000_ERR_CONFIG;
3465 }
3466 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003467}
3468
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003469/**
3470 * e1000_init_eeprom_params - initialize sw eeprom vars
3471 * @hw: Struct containing variables accessed by shared code
3472 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07003473 * Sets up eeprom variables in the hw struct. Must be called after mac_type
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00003474 * is configured.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003475 */
Joe Perches64798842008-07-11 15:17:02 -07003476s32 e1000_init_eeprom_params(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003477{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003478 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3479 u32 eecd = er32(EECD);
3480 s32 ret_val = E1000_SUCCESS;
3481 u16 eeprom_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003482
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003483 switch (hw->mac_type) {
3484 case e1000_82542_rev2_0:
3485 case e1000_82542_rev2_1:
3486 case e1000_82543:
3487 case e1000_82544:
3488 eeprom->type = e1000_eeprom_microwire;
3489 eeprom->word_size = 64;
3490 eeprom->opcode_bits = 3;
3491 eeprom->address_bits = 6;
3492 eeprom->delay_usec = 50;
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003493 break;
3494 case e1000_82540:
3495 case e1000_82545:
3496 case e1000_82545_rev_3:
3497 case e1000_82546:
3498 case e1000_82546_rev_3:
3499 eeprom->type = e1000_eeprom_microwire;
3500 eeprom->opcode_bits = 3;
3501 eeprom->delay_usec = 50;
3502 if (eecd & E1000_EECD_SIZE) {
3503 eeprom->word_size = 256;
3504 eeprom->address_bits = 8;
3505 } else {
3506 eeprom->word_size = 64;
3507 eeprom->address_bits = 6;
3508 }
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003509 break;
3510 case e1000_82541:
3511 case e1000_82541_rev_2:
3512 case e1000_82547:
3513 case e1000_82547_rev_2:
3514 if (eecd & E1000_EECD_TYPE) {
3515 eeprom->type = e1000_eeprom_spi;
3516 eeprom->opcode_bits = 8;
3517 eeprom->delay_usec = 1;
3518 if (eecd & E1000_EECD_ADDR_BITS) {
3519 eeprom->page_size = 32;
3520 eeprom->address_bits = 16;
3521 } else {
3522 eeprom->page_size = 8;
3523 eeprom->address_bits = 8;
3524 }
3525 } else {
3526 eeprom->type = e1000_eeprom_microwire;
3527 eeprom->opcode_bits = 3;
3528 eeprom->delay_usec = 50;
3529 if (eecd & E1000_EECD_ADDR_BITS) {
3530 eeprom->word_size = 256;
3531 eeprom->address_bits = 8;
3532 } else {
3533 eeprom->word_size = 64;
3534 eeprom->address_bits = 6;
3535 }
3536 }
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003537 break;
3538 default:
3539 break;
3540 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003541
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003542 if (eeprom->type == e1000_eeprom_spi) {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003543 /* eeprom_size will be an enum [0..8] that maps to eeprom sizes
3544 * 128B to 32KB (incremented by powers of 2).
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003545 */
3546 /* Set to default value for initial eeprom read. */
3547 eeprom->word_size = 64;
3548 ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size);
3549 if (ret_val)
3550 return ret_val;
3551 eeprom_size =
3552 (eeprom_size & EEPROM_SIZE_MASK) >> EEPROM_SIZE_SHIFT;
3553 /* 256B eeprom size was not supported in earlier hardware, so we
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003554 * bump eeprom_size up one to ensure that "1" (which maps to
3555 * 256B) is never the result used in the shifting logic below.
3556 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003557 if (eeprom_size)
3558 eeprom_size++;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003559
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003560 eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT);
3561 }
3562 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003563}
3564
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003565/**
3566 * e1000_raise_ee_clk - Raises the EEPROM's clock input.
3567 * @hw: Struct containing variables accessed by shared code
3568 * @eecd: EECD's current value
3569 */
Joe Perches64798842008-07-11 15:17:02 -07003570static void e1000_raise_ee_clk(struct e1000_hw *hw, u32 *eecd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003571{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003572 /* Raise the clock input to the EEPROM (by setting the SK bit), and then
3573 * wait <delay> microseconds.
3574 */
3575 *eecd = *eecd | E1000_EECD_SK;
3576 ew32(EECD, *eecd);
3577 E1000_WRITE_FLUSH();
3578 udelay(hw->eeprom.delay_usec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003579}
3580
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003581/**
3582 * e1000_lower_ee_clk - Lowers the EEPROM's clock input.
3583 * @hw: Struct containing variables accessed by shared code
3584 * @eecd: EECD's current value
3585 */
Joe Perches64798842008-07-11 15:17:02 -07003586static void e1000_lower_ee_clk(struct e1000_hw *hw, u32 *eecd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003587{
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003588 /* Lower the clock input to the EEPROM (by clearing the SK bit), and
3589 * then wait 50 microseconds.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003590 */
3591 *eecd = *eecd & ~E1000_EECD_SK;
3592 ew32(EECD, *eecd);
3593 E1000_WRITE_FLUSH();
3594 udelay(hw->eeprom.delay_usec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003595}
3596
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003597/**
3598 * e1000_shift_out_ee_bits - Shift data bits out to the EEPROM.
3599 * @hw: Struct containing variables accessed by shared code
3600 * @data: data to send to the EEPROM
3601 * @count: number of bits to shift out
3602 */
Joe Perches64798842008-07-11 15:17:02 -07003603static void e1000_shift_out_ee_bits(struct e1000_hw *hw, u16 data, u16 count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003604{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003605 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3606 u32 eecd;
3607 u32 mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003608
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003609 /* We need to shift "count" bits out to the EEPROM. So, value in the
3610 * "data" parameter will be shifted out to the EEPROM one bit at a time.
3611 * In order to do this, "data" must be broken down into bits.
3612 */
3613 mask = 0x01 << (count - 1);
3614 eecd = er32(EECD);
Janusz Wolak13a87c12015-09-28 23:40:19 +02003615 if (eeprom->type == e1000_eeprom_microwire)
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003616 eecd &= ~E1000_EECD_DO;
Janusz Wolak13a87c12015-09-28 23:40:19 +02003617 else if (eeprom->type == e1000_eeprom_spi)
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003618 eecd |= E1000_EECD_DO;
Janusz Wolak13a87c12015-09-28 23:40:19 +02003619
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003620 do {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003621 /* A "1" is shifted out to the EEPROM by setting bit "DI" to a
3622 * "1", and then raising and then lowering the clock (the SK bit
3623 * controls the clock input to the EEPROM). A "0" is shifted
3624 * out to the EEPROM by setting "DI" to "0" and then raising and
3625 * then lowering the clock.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003626 */
3627 eecd &= ~E1000_EECD_DI;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003628
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003629 if (data & mask)
3630 eecd |= E1000_EECD_DI;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003631
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003632 ew32(EECD, eecd);
3633 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003634
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003635 udelay(eeprom->delay_usec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003636
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003637 e1000_raise_ee_clk(hw, &eecd);
3638 e1000_lower_ee_clk(hw, &eecd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003639
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003640 mask = mask >> 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003641
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003642 } while (mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003643
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003644 /* We leave the "DI" bit set to "0" when we leave this routine. */
3645 eecd &= ~E1000_EECD_DI;
3646 ew32(EECD, eecd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003647}
3648
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003649/**
3650 * e1000_shift_in_ee_bits - Shift data bits in from the EEPROM
3651 * @hw: Struct containing variables accessed by shared code
3652 * @count: number of bits to shift in
3653 */
Joe Perches64798842008-07-11 15:17:02 -07003654static u16 e1000_shift_in_ee_bits(struct e1000_hw *hw, u16 count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003655{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003656 u32 eecd;
3657 u32 i;
3658 u16 data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003659
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003660 /* In order to read a register from the EEPROM, we need to shift 'count'
3661 * bits in from the EEPROM. Bits are "shifted in" by raising the clock
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003662 * input to the EEPROM (setting the SK bit), and then reading the value
3663 * of the "DO" bit. During this "shifting in" process the "DI" bit
3664 * should always be clear.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003665 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003666
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003667 eecd = er32(EECD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003668
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003669 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
3670 data = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003671
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003672 for (i = 0; i < count; i++) {
3673 data = data << 1;
3674 e1000_raise_ee_clk(hw, &eecd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003675
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003676 eecd = er32(EECD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003677
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003678 eecd &= ~(E1000_EECD_DI);
3679 if (eecd & E1000_EECD_DO)
3680 data |= 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003681
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003682 e1000_lower_ee_clk(hw, &eecd);
3683 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003684
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003685 return data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003686}
3687
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003688/**
3689 * e1000_acquire_eeprom - Prepares EEPROM for access
3690 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -07003691 *
3692 * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
3693 * function should be called before issuing a command to the EEPROM.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003694 */
Joe Perches64798842008-07-11 15:17:02 -07003695static s32 e1000_acquire_eeprom(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003696{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003697 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3698 u32 eecd, i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003699
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003700 eecd = er32(EECD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003701
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003702 /* Request EEPROM Access */
3703 if (hw->mac_type > e1000_82544) {
3704 eecd |= E1000_EECD_REQ;
3705 ew32(EECD, eecd);
3706 eecd = er32(EECD);
3707 while ((!(eecd & E1000_EECD_GNT)) &&
3708 (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
3709 i++;
3710 udelay(5);
3711 eecd = er32(EECD);
3712 }
3713 if (!(eecd & E1000_EECD_GNT)) {
3714 eecd &= ~E1000_EECD_REQ;
3715 ew32(EECD, eecd);
Emil Tantilov675ad472010-04-27 14:02:58 +00003716 e_dbg("Could not acquire EEPROM grant\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003717 return -E1000_ERR_EEPROM;
3718 }
3719 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003720
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003721 /* Setup EEPROM for Read/Write */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003722
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003723 if (eeprom->type == e1000_eeprom_microwire) {
3724 /* Clear SK and DI */
3725 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
3726 ew32(EECD, eecd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003727
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003728 /* Set CS */
3729 eecd |= E1000_EECD_CS;
3730 ew32(EECD, eecd);
3731 } else if (eeprom->type == e1000_eeprom_spi) {
3732 /* Clear SK and CS */
3733 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
3734 ew32(EECD, eecd);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00003735 E1000_WRITE_FLUSH();
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003736 udelay(1);
3737 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003738
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003739 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003740}
3741
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003742/**
3743 * e1000_standby_eeprom - Returns EEPROM to a "standby" state
3744 * @hw: Struct containing variables accessed by shared code
3745 */
Joe Perches64798842008-07-11 15:17:02 -07003746static void e1000_standby_eeprom(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003747{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003748 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3749 u32 eecd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003750
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003751 eecd = er32(EECD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003752
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003753 if (eeprom->type == e1000_eeprom_microwire) {
3754 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
3755 ew32(EECD, eecd);
3756 E1000_WRITE_FLUSH();
3757 udelay(eeprom->delay_usec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003758
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003759 /* Clock high */
3760 eecd |= E1000_EECD_SK;
3761 ew32(EECD, eecd);
3762 E1000_WRITE_FLUSH();
3763 udelay(eeprom->delay_usec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003764
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003765 /* Select EEPROM */
3766 eecd |= E1000_EECD_CS;
3767 ew32(EECD, eecd);
3768 E1000_WRITE_FLUSH();
3769 udelay(eeprom->delay_usec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003770
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003771 /* Clock low */
3772 eecd &= ~E1000_EECD_SK;
3773 ew32(EECD, eecd);
3774 E1000_WRITE_FLUSH();
3775 udelay(eeprom->delay_usec);
3776 } else if (eeprom->type == e1000_eeprom_spi) {
3777 /* Toggle CS to flush commands */
3778 eecd |= E1000_EECD_CS;
3779 ew32(EECD, eecd);
3780 E1000_WRITE_FLUSH();
3781 udelay(eeprom->delay_usec);
3782 eecd &= ~E1000_EECD_CS;
3783 ew32(EECD, eecd);
3784 E1000_WRITE_FLUSH();
3785 udelay(eeprom->delay_usec);
3786 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003787}
3788
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003789/**
3790 * e1000_release_eeprom - drop chip select
3791 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -07003792 *
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003793 * Terminates a command by inverting the EEPROM's chip select pin
3794 */
Joe Perches64798842008-07-11 15:17:02 -07003795static void e1000_release_eeprom(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003796{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003797 u32 eecd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003798
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003799 eecd = er32(EECD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003800
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003801 if (hw->eeprom.type == e1000_eeprom_spi) {
3802 eecd |= E1000_EECD_CS; /* Pull CS high */
3803 eecd &= ~E1000_EECD_SK; /* Lower SCK */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003804
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003805 ew32(EECD, eecd);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00003806 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003807
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003808 udelay(hw->eeprom.delay_usec);
3809 } else if (hw->eeprom.type == e1000_eeprom_microwire) {
3810 /* cleanup eeprom */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003811
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003812 /* CS on Microwire is active-high */
3813 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003814
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003815 ew32(EECD, eecd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003816
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003817 /* Rising edge of clock */
3818 eecd |= E1000_EECD_SK;
3819 ew32(EECD, eecd);
3820 E1000_WRITE_FLUSH();
3821 udelay(hw->eeprom.delay_usec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003822
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003823 /* Falling edge of clock */
3824 eecd &= ~E1000_EECD_SK;
3825 ew32(EECD, eecd);
3826 E1000_WRITE_FLUSH();
3827 udelay(hw->eeprom.delay_usec);
3828 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003829
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003830 /* Stop requesting EEPROM access */
3831 if (hw->mac_type > e1000_82544) {
3832 eecd &= ~E1000_EECD_REQ;
3833 ew32(EECD, eecd);
3834 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003835}
3836
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003837/**
3838 * e1000_spi_eeprom_ready - Reads a 16 bit word from the EEPROM.
3839 * @hw: Struct containing variables accessed by shared code
3840 */
Joe Perches64798842008-07-11 15:17:02 -07003841static s32 e1000_spi_eeprom_ready(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003842{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003843 u16 retry_count = 0;
3844 u8 spi_stat_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003845
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003846 /* Read "Status Register" repeatedly until the LSB is cleared. The
3847 * EEPROM will signal that the command has been completed by clearing
3848 * bit 0 of the internal status register. If it's not cleared within
3849 * 5 milliseconds, then error out.
3850 */
3851 retry_count = 0;
3852 do {
3853 e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
3854 hw->eeprom.opcode_bits);
Janusz Wolak13a87c12015-09-28 23:40:19 +02003855 spi_stat_reg = (u8)e1000_shift_in_ee_bits(hw, 8);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003856 if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
3857 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003858
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003859 udelay(5);
3860 retry_count += 5;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003861
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003862 e1000_standby_eeprom(hw);
3863 } while (retry_count < EEPROM_MAX_RETRY_SPI);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003864
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003865 /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
3866 * only 0-5mSec on 5V devices)
3867 */
3868 if (retry_count >= EEPROM_MAX_RETRY_SPI) {
Emil Tantilov675ad472010-04-27 14:02:58 +00003869 e_dbg("SPI EEPROM Status error\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003870 return -E1000_ERR_EEPROM;
3871 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003872
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003873 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003874}
3875
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003876/**
3877 * e1000_read_eeprom - Reads a 16 bit word from the EEPROM.
3878 * @hw: Struct containing variables accessed by shared code
3879 * @offset: offset of word in the EEPROM to read
3880 * @data: word read from the EEPROM
3881 * @words: number of words to read
3882 */
Joe Perches64798842008-07-11 15:17:02 -07003883s32 e1000_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003884{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003885 s32 ret;
Janusz Wolak13a87c12015-09-28 23:40:19 +02003886
Joern Engele09b8902015-07-23 14:54:34 -07003887 mutex_lock(&e1000_eeprom_lock);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003888 ret = e1000_do_read_eeprom(hw, offset, words, data);
Joern Engele09b8902015-07-23 14:54:34 -07003889 mutex_unlock(&e1000_eeprom_lock);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003890 return ret;
Christopher Li78566fe2008-09-05 14:04:05 -07003891}
3892
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003893static s32 e1000_do_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words,
3894 u16 *data)
Christopher Li78566fe2008-09-05 14:04:05 -07003895{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003896 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3897 u32 i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003898
Dirk Brandewie5377a412011-01-06 14:29:54 +00003899 if (hw->mac_type == e1000_ce4100) {
3900 GBE_CONFIG_FLASH_READ(GBE_CONFIG_BASE_VIRT, offset, words,
Janusz Wolaka48954c2015-09-17 23:34:29 +02003901 data);
Dirk Brandewie5377a412011-01-06 14:29:54 +00003902 return E1000_SUCCESS;
3903 }
3904
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003905 /* A check for invalid values: offset too large, too many words, and
3906 * not enough words.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003907 */
Janusz Wolak13a87c12015-09-28 23:40:19 +02003908 if ((offset >= eeprom->word_size) ||
3909 (words > eeprom->word_size - offset) ||
3910 (words == 0)) {
Emil Tantilov675ad472010-04-27 14:02:58 +00003911 e_dbg("\"words\" parameter out of bounds. Words = %d,"
3912 "size = %d\n", offset, eeprom->word_size);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003913 return -E1000_ERR_EEPROM;
3914 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003915
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003916 /* EEPROM's that don't use EERD to read require us to bit-bang the SPI
3917 * directly. In this case, we need to acquire the EEPROM so that
3918 * FW or other port software does not interrupt.
3919 */
Jesse Brandeburg8f601b22009-09-25 12:20:11 +00003920 /* Prepare the EEPROM for bit-bang reading */
3921 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
3922 return -E1000_ERR_EEPROM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003923
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003924 /* Set up the SPI or Microwire EEPROM for bit-bang reading. We have
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003925 * acquired the EEPROM at this point, so any returns should release it
3926 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003927 if (eeprom->type == e1000_eeprom_spi) {
3928 u16 word_in;
3929 u8 read_opcode = EEPROM_READ_OPCODE_SPI;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003930
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003931 if (e1000_spi_eeprom_ready(hw)) {
3932 e1000_release_eeprom(hw);
3933 return -E1000_ERR_EEPROM;
3934 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003935
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003936 e1000_standby_eeprom(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003937
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003938 /* Some SPI eeproms use the 8th address bit embedded in the
3939 * opcode
3940 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003941 if ((eeprom->address_bits == 8) && (offset >= 128))
3942 read_opcode |= EEPROM_A8_OPCODE_SPI;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003943
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003944 /* Send the READ command (opcode + addr) */
3945 e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
Janusz Wolak13a87c12015-09-28 23:40:19 +02003946 e1000_shift_out_ee_bits(hw, (u16)(offset * 2),
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003947 eeprom->address_bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003948
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003949 /* Read the data. The address of the eeprom internally
3950 * increments with each byte (spi) being read, saving on the
3951 * overhead of eeprom setup and tear-down. The address counter
3952 * will roll over if reading beyond the size of the eeprom, thus
3953 * allowing the entire memory to be read starting from any
3954 * offset.
3955 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003956 for (i = 0; i < words; i++) {
3957 word_in = e1000_shift_in_ee_bits(hw, 16);
3958 data[i] = (word_in >> 8) | (word_in << 8);
3959 }
3960 } else if (eeprom->type == e1000_eeprom_microwire) {
3961 for (i = 0; i < words; i++) {
3962 /* Send the READ command (opcode + addr) */
3963 e1000_shift_out_ee_bits(hw,
3964 EEPROM_READ_OPCODE_MICROWIRE,
3965 eeprom->opcode_bits);
Janusz Wolak13a87c12015-09-28 23:40:19 +02003966 e1000_shift_out_ee_bits(hw, (u16)(offset + i),
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003967 eeprom->address_bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003968
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00003969 /* Read the data. For microwire, each word requires the
3970 * overhead of eeprom setup and tear-down.
3971 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003972 data[i] = e1000_shift_in_ee_bits(hw, 16);
3973 e1000_standby_eeprom(hw);
Joern Engele09b8902015-07-23 14:54:34 -07003974 cond_resched();
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003975 }
3976 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003977
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003978 /* End this read operation */
3979 e1000_release_eeprom(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003980
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003981 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003982}
3983
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003984/**
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003985 * e1000_validate_eeprom_checksum - Verifies that the EEPROM has a valid checksum
3986 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -07003987 *
3988 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
3989 * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
3990 * valid.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003991 */
Joe Perches64798842008-07-11 15:17:02 -07003992s32 e1000_validate_eeprom_checksum(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003993{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003994 u16 checksum = 0;
3995 u16 i, eeprom_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003996
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07003997 for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
3998 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
Emil Tantilov675ad472010-04-27 14:02:58 +00003999 e_dbg("EEPROM Read Error\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004000 return -E1000_ERR_EEPROM;
4001 }
4002 checksum += eeprom_data;
4003 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004004
Jeff Kirshere2faeec2011-08-30 20:58:56 -04004005#ifdef CONFIG_PARISC
4006 /* This is a signature and not a checksum on HP c8000 */
4007 if ((hw->subsystem_vendor_id == 0x103C) && (eeprom_data == 0x16d6))
4008 return E1000_SUCCESS;
4009
4010#endif
Janusz Wolak13a87c12015-09-28 23:40:19 +02004011 if (checksum == (u16)EEPROM_SUM)
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004012 return E1000_SUCCESS;
4013 else {
Emil Tantilov675ad472010-04-27 14:02:58 +00004014 e_dbg("EEPROM Checksum Invalid\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004015 return -E1000_ERR_EEPROM;
4016 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004017}
4018
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004019/**
4020 * e1000_update_eeprom_checksum - Calculates/writes the EEPROM checksum
4021 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -07004022 *
4023 * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA.
4024 * Writes the difference to word offset 63 of the EEPROM.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004025 */
Joe Perches64798842008-07-11 15:17:02 -07004026s32 e1000_update_eeprom_checksum(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004027{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004028 u16 checksum = 0;
4029 u16 i, eeprom_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004030
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004031 for (i = 0; i < EEPROM_CHECKSUM_REG; i++) {
4032 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
Emil Tantilov675ad472010-04-27 14:02:58 +00004033 e_dbg("EEPROM Read Error\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004034 return -E1000_ERR_EEPROM;
4035 }
4036 checksum += eeprom_data;
4037 }
Janusz Wolak13a87c12015-09-28 23:40:19 +02004038 checksum = (u16)EEPROM_SUM - checksum;
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004039 if (e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) {
Emil Tantilov675ad472010-04-27 14:02:58 +00004040 e_dbg("EEPROM Write Error\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004041 return -E1000_ERR_EEPROM;
4042 }
4043 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004044}
4045
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004046/**
4047 * e1000_write_eeprom - write words to the different EEPROM types.
4048 * @hw: Struct containing variables accessed by shared code
4049 * @offset: offset within the EEPROM to be written to
4050 * @words: number of words to write
4051 * @data: 16 bit word to be written to the EEPROM
Linus Torvalds1da177e2005-04-16 15:20:36 -07004052 *
4053 * If e1000_update_eeprom_checksum is not called after this function, the
4054 * EEPROM will most likely contain an invalid checksum.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004055 */
Joe Perches64798842008-07-11 15:17:02 -07004056s32 e1000_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004057{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004058 s32 ret;
Janusz Wolak13a87c12015-09-28 23:40:19 +02004059
Joern Engele09b8902015-07-23 14:54:34 -07004060 mutex_lock(&e1000_eeprom_lock);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004061 ret = e1000_do_write_eeprom(hw, offset, words, data);
Joern Engele09b8902015-07-23 14:54:34 -07004062 mutex_unlock(&e1000_eeprom_lock);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004063 return ret;
Christopher Li78566fe2008-09-05 14:04:05 -07004064}
4065
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004066static s32 e1000_do_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words,
4067 u16 *data)
Christopher Li78566fe2008-09-05 14:04:05 -07004068{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004069 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4070 s32 status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004071
Dirk Brandewie5377a412011-01-06 14:29:54 +00004072 if (hw->mac_type == e1000_ce4100) {
4073 GBE_CONFIG_FLASH_WRITE(GBE_CONFIG_BASE_VIRT, offset, words,
Janusz Wolaka48954c2015-09-17 23:34:29 +02004074 data);
Dirk Brandewie5377a412011-01-06 14:29:54 +00004075 return E1000_SUCCESS;
4076 }
4077
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00004078 /* A check for invalid values: offset too large, too many words, and
4079 * not enough words.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004080 */
Janusz Wolak13a87c12015-09-28 23:40:19 +02004081 if ((offset >= eeprom->word_size) ||
4082 (words > eeprom->word_size - offset) ||
4083 (words == 0)) {
Emil Tantilov675ad472010-04-27 14:02:58 +00004084 e_dbg("\"words\" parameter out of bounds\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004085 return -E1000_ERR_EEPROM;
4086 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004087
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004088 /* Prepare the EEPROM for writing */
4089 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
4090 return -E1000_ERR_EEPROM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004091
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004092 if (eeprom->type == e1000_eeprom_microwire) {
4093 status = e1000_write_eeprom_microwire(hw, offset, words, data);
4094 } else {
4095 status = e1000_write_eeprom_spi(hw, offset, words, data);
4096 msleep(10);
4097 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004098
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004099 /* Done with writing */
4100 e1000_release_eeprom(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004101
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004102 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004103}
4104
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004105/**
4106 * e1000_write_eeprom_spi - Writes a 16 bit word to a given offset in an SPI EEPROM.
4107 * @hw: Struct containing variables accessed by shared code
4108 * @offset: offset within the EEPROM to be written to
4109 * @words: number of words to write
4110 * @data: pointer to array of 8 bit words to be written to the EEPROM
4111 */
Joe Perches64798842008-07-11 15:17:02 -07004112static s32 e1000_write_eeprom_spi(struct e1000_hw *hw, u16 offset, u16 words,
4113 u16 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004114{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004115 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4116 u16 widx = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004117
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004118 while (widx < words) {
4119 u8 write_opcode = EEPROM_WRITE_OPCODE_SPI;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004120
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004121 if (e1000_spi_eeprom_ready(hw))
4122 return -E1000_ERR_EEPROM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004123
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004124 e1000_standby_eeprom(hw);
Joern Engele09b8902015-07-23 14:54:34 -07004125 cond_resched();
Linus Torvalds1da177e2005-04-16 15:20:36 -07004126
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004127 /* Send the WRITE ENABLE command (8 bit opcode ) */
4128 e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI,
4129 eeprom->opcode_bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004130
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004131 e1000_standby_eeprom(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004132
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00004133 /* Some SPI eeproms use the 8th address bit embedded in the
4134 * opcode
4135 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004136 if ((eeprom->address_bits == 8) && (offset >= 128))
4137 write_opcode |= EEPROM_A8_OPCODE_SPI;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004138
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004139 /* Send the Write command (8-bit opcode + addr) */
4140 e1000_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004141
Janusz Wolak13a87c12015-09-28 23:40:19 +02004142 e1000_shift_out_ee_bits(hw, (u16)((offset + widx) * 2),
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004143 eeprom->address_bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004144
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004145 /* Send the data */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004146
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00004147 /* Loop to allow for up to whole page write (32 bytes) of
4148 * eeprom
4149 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004150 while (widx < words) {
4151 u16 word_out = data[widx];
Janusz Wolak13a87c12015-09-28 23:40:19 +02004152
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004153 word_out = (word_out >> 8) | (word_out << 8);
4154 e1000_shift_out_ee_bits(hw, word_out, 16);
4155 widx++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004156
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00004157 /* Some larger eeprom sizes are capable of a 32-byte
4158 * PAGE WRITE operation, while the smaller eeproms are
4159 * capable of an 8-byte PAGE WRITE operation. Break the
4160 * inner loop to pass new address
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004161 */
4162 if ((((offset + widx) * 2) % eeprom->page_size) == 0) {
4163 e1000_standby_eeprom(hw);
4164 break;
4165 }
4166 }
4167 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004168
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004169 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004170}
4171
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004172/**
4173 * e1000_write_eeprom_microwire - Writes a 16 bit word to a given offset in a Microwire EEPROM.
4174 * @hw: Struct containing variables accessed by shared code
4175 * @offset: offset within the EEPROM to be written to
4176 * @words: number of words to write
4177 * @data: pointer to array of 8 bit words to be written to the EEPROM
4178 */
Joe Perches64798842008-07-11 15:17:02 -07004179static s32 e1000_write_eeprom_microwire(struct e1000_hw *hw, u16 offset,
4180 u16 words, u16 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004181{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004182 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4183 u32 eecd;
4184 u16 words_written = 0;
4185 u16 i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004186
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004187 /* Send the write enable command to the EEPROM (3-bit opcode plus
4188 * 6/8-bit dummy address beginning with 11). It's less work to include
4189 * the 11 of the dummy address as part of the opcode than it is to shift
4190 * it over the correct number of bits for the address. This puts the
4191 * EEPROM into write/erase mode.
4192 */
4193 e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE,
Janusz Wolak13a87c12015-09-28 23:40:19 +02004194 (u16)(eeprom->opcode_bits + 2));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004195
Janusz Wolak13a87c12015-09-28 23:40:19 +02004196 e1000_shift_out_ee_bits(hw, 0, (u16)(eeprom->address_bits - 2));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004197
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004198 /* Prepare the EEPROM */
4199 e1000_standby_eeprom(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004200
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004201 while (words_written < words) {
4202 /* Send the Write command (3-bit opcode + addr) */
4203 e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE,
4204 eeprom->opcode_bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004205
Janusz Wolak13a87c12015-09-28 23:40:19 +02004206 e1000_shift_out_ee_bits(hw, (u16)(offset + words_written),
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004207 eeprom->address_bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004208
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004209 /* Send the data */
4210 e1000_shift_out_ee_bits(hw, data[words_written], 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004211
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00004212 /* Toggle the CS line. This in effect tells the EEPROM to
4213 * execute the previous command.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004214 */
4215 e1000_standby_eeprom(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004216
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00004217 /* Read DO repeatedly until it is high (equal to '1'). The
4218 * EEPROM will signal that the command has been completed by
4219 * raising the DO signal. If DO does not go high in 10
4220 * milliseconds, then error out.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004221 */
4222 for (i = 0; i < 200; i++) {
4223 eecd = er32(EECD);
4224 if (eecd & E1000_EECD_DO)
4225 break;
4226 udelay(50);
4227 }
4228 if (i == 200) {
Emil Tantilov675ad472010-04-27 14:02:58 +00004229 e_dbg("EEPROM Write did not complete\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004230 return -E1000_ERR_EEPROM;
4231 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004232
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004233 /* Recover from write */
4234 e1000_standby_eeprom(hw);
Joern Engele09b8902015-07-23 14:54:34 -07004235 cond_resched();
Linus Torvalds1da177e2005-04-16 15:20:36 -07004236
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004237 words_written++;
4238 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004239
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004240 /* Send the write disable command to the EEPROM (3-bit opcode plus
4241 * 6/8-bit dummy address beginning with 10). It's less work to include
4242 * the 10 of the dummy address as part of the opcode than it is to shift
4243 * it over the correct number of bits for the address. This takes the
4244 * EEPROM out of write/erase mode.
4245 */
4246 e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE,
Janusz Wolak13a87c12015-09-28 23:40:19 +02004247 (u16)(eeprom->opcode_bits + 2));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004248
Janusz Wolak13a87c12015-09-28 23:40:19 +02004249 e1000_shift_out_ee_bits(hw, 0, (u16)(eeprom->address_bits - 2));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004250
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004251 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004252}
4253
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004254/**
4255 * e1000_read_mac_addr - read the adapters MAC from eeprom
4256 * @hw: Struct containing variables accessed by shared code
4257 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07004258 * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
4259 * second function of dual function devices
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004260 */
Joe Perches64798842008-07-11 15:17:02 -07004261s32 e1000_read_mac_addr(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004262{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004263 u16 offset;
4264 u16 eeprom_data, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004265
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004266 for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
4267 offset = i >> 1;
4268 if (e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
Emil Tantilov675ad472010-04-27 14:02:58 +00004269 e_dbg("EEPROM Read Error\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004270 return -E1000_ERR_EEPROM;
4271 }
Janusz Wolak13a87c12015-09-28 23:40:19 +02004272 hw->perm_mac_addr[i] = (u8)(eeprom_data & 0x00FF);
4273 hw->perm_mac_addr[i + 1] = (u8)(eeprom_data >> 8);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004274 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08004275
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004276 switch (hw->mac_type) {
4277 default:
4278 break;
4279 case e1000_82546:
4280 case e1000_82546_rev_3:
4281 if (er32(STATUS) & E1000_STATUS_FUNC_1)
4282 hw->perm_mac_addr[5] ^= 0x01;
4283 break;
4284 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004285
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004286 for (i = 0; i < NODE_ADDRESS_SIZE; i++)
4287 hw->mac_addr[i] = hw->perm_mac_addr[i];
4288 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004289}
4290
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004291/**
4292 * e1000_init_rx_addrs - Initializes receive address filters.
4293 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -07004294 *
4295 * Places the MAC address in receive address register 0 and clears the rest
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004296 * of the receive address registers. Clears the multicast table. Assumes
Linus Torvalds1da177e2005-04-16 15:20:36 -07004297 * the receiver is in reset when the routine is called.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004298 */
Joe Perches64798842008-07-11 15:17:02 -07004299static void e1000_init_rx_addrs(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004300{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004301 u32 i;
4302 u32 rar_num;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004303
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004304 /* Setup the receive address. */
Emil Tantilov675ad472010-04-27 14:02:58 +00004305 e_dbg("Programming MAC Address into RAR[0]\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004306
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004307 e1000_rar_set(hw, hw->mac_addr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004308
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004309 rar_num = E1000_RAR_ENTRIES;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004310
Ahmad Fatoum8abd20b2017-11-18 21:53:58 +01004311 /* Zero out the following 14 receive addresses. RAR[15] is for
4312 * manageability
4313 */
4314 e_dbg("Clearing RAR[1-14]\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004315 for (i = 1; i < rar_num; i++) {
4316 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
4317 E1000_WRITE_FLUSH();
4318 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
4319 E1000_WRITE_FLUSH();
4320 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004321}
4322
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004323/**
4324 * e1000_hash_mc_addr - Hashes an address to determine its location in the multicast table
4325 * @hw: Struct containing variables accessed by shared code
4326 * @mc_addr: the multicast address to hash
4327 */
Joe Perches64798842008-07-11 15:17:02 -07004328u32 e1000_hash_mc_addr(struct e1000_hw *hw, u8 *mc_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004329{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004330 u32 hash_value = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004331
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004332 /* The portion of the address that is used for the hash table is
4333 * determined by the mc_filter_type setting.
4334 */
4335 switch (hw->mc_filter_type) {
4336 /* [0] [1] [2] [3] [4] [5]
4337 * 01 AA 00 12 34 56
4338 * LSB MSB
4339 */
4340 case 0:
4341 /* [47:36] i.e. 0x563 for above example address */
Janusz Wolak13a87c12015-09-28 23:40:19 +02004342 hash_value = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4));
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004343 break;
4344 case 1:
4345 /* [46:35] i.e. 0xAC6 for above example address */
Janusz Wolak13a87c12015-09-28 23:40:19 +02004346 hash_value = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5));
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004347 break;
4348 case 2:
4349 /* [45:34] i.e. 0x5D8 for above example address */
Janusz Wolak13a87c12015-09-28 23:40:19 +02004350 hash_value = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6));
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004351 break;
4352 case 3:
4353 /* [43:32] i.e. 0x634 for above example address */
Janusz Wolak13a87c12015-09-28 23:40:19 +02004354 hash_value = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8));
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004355 break;
4356 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004357
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004358 hash_value &= 0xFFF;
4359 return hash_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004360}
4361
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004362/**
4363 * e1000_rar_set - Puts an ethernet address into a receive address register.
4364 * @hw: Struct containing variables accessed by shared code
4365 * @addr: Address to put into receive address register
4366 * @index: Receive address register to write
4367 */
Joe Perches64798842008-07-11 15:17:02 -07004368void e1000_rar_set(struct e1000_hw *hw, u8 *addr, u32 index)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004369{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004370 u32 rar_low, rar_high;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004371
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004372 /* HW expects these in little endian so we reverse the byte order
4373 * from network order (big endian) to little endian
4374 */
Janusz Wolak13a87c12015-09-28 23:40:19 +02004375 rar_low = ((u32)addr[0] | ((u32)addr[1] << 8) |
4376 ((u32)addr[2] << 16) | ((u32)addr[3] << 24));
4377 rar_high = ((u32)addr[4] | ((u32)addr[5] << 8));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004378
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004379 /* Disable Rx and flush all Rx frames before enabling RSS to avoid Rx
4380 * unit hang.
4381 *
4382 * Description:
4383 * If there are any Rx frames queued up or otherwise present in the HW
4384 * before RSS is enabled, and then we enable RSS, the HW Rx unit will
4385 * hang. To work around this issue, we have to disable receives and
4386 * flush out all Rx frames before we enable RSS. To do so, we modify we
4387 * redirect all Rx traffic to manageability and then reset the HW.
4388 * This flushes away Rx frames, and (since the redirections to
4389 * manageability persists across resets) keeps new ones from coming in
4390 * while we work. Then, we clear the Address Valid AV bit for all MAC
4391 * addresses and undo the re-direction to manageability.
4392 * Now, frames are coming in again, but the MAC won't accept them, so
4393 * far so good. We now proceed to initialize RSS (if necessary) and
4394 * configure the Rx unit. Last, we re-enable the AV bits and continue
4395 * on our merry way.
4396 */
4397 switch (hw->mac_type) {
4398 default:
4399 /* Indicate to hardware the Address is Valid. */
4400 rar_high |= E1000_RAH_AV;
4401 break;
4402 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004403
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004404 E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
4405 E1000_WRITE_FLUSH();
4406 E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
4407 E1000_WRITE_FLUSH();
Linus Torvalds1da177e2005-04-16 15:20:36 -07004408}
4409
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004410/**
4411 * e1000_write_vfta - Writes a value to the specified offset in the VLAN filter table.
4412 * @hw: Struct containing variables accessed by shared code
4413 * @offset: Offset in VLAN filer table to write
4414 * @value: Value to write into VLAN filter table
4415 */
Joe Perches64798842008-07-11 15:17:02 -07004416void e1000_write_vfta(struct e1000_hw *hw, u32 offset, u32 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004417{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004418 u32 temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004419
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004420 if ((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) {
4421 temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1));
4422 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
4423 E1000_WRITE_FLUSH();
4424 E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp);
4425 E1000_WRITE_FLUSH();
4426 } else {
4427 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
4428 E1000_WRITE_FLUSH();
4429 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004430}
4431
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004432/**
4433 * e1000_clear_vfta - Clears the VLAN filer table
4434 * @hw: Struct containing variables accessed by shared code
4435 */
Joe Perches64798842008-07-11 15:17:02 -07004436static void e1000_clear_vfta(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004437{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004438 u32 offset;
4439 u32 vfta_value = 0;
4440 u32 vfta_offset = 0;
4441 u32 vfta_bit_in_reg = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004442
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004443 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
4444 /* If the offset we want to clear is the same offset of the
4445 * manageability VLAN ID, then clear all bits except that of the
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00004446 * manageability unit
4447 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004448 vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0;
4449 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, vfta_value);
4450 E1000_WRITE_FLUSH();
4451 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004452}
4453
Joe Perches64798842008-07-11 15:17:02 -07004454static s32 e1000_id_led_init(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004455{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004456 u32 ledctl;
4457 const u32 ledctl_mask = 0x000000FF;
4458 const u32 ledctl_on = E1000_LEDCTL_MODE_LED_ON;
4459 const u32 ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
4460 u16 eeprom_data, i, temp;
4461 const u16 led_mask = 0x0F;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004462
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004463 if (hw->mac_type < e1000_82540) {
4464 /* Nothing to do */
4465 return E1000_SUCCESS;
4466 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004467
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004468 ledctl = er32(LEDCTL);
4469 hw->ledctl_default = ledctl;
4470 hw->ledctl_mode1 = hw->ledctl_default;
4471 hw->ledctl_mode2 = hw->ledctl_default;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004472
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004473 if (e1000_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, 1, &eeprom_data) < 0) {
Emil Tantilov675ad472010-04-27 14:02:58 +00004474 e_dbg("EEPROM Read Error\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004475 return -E1000_ERR_EEPROM;
4476 }
Auke Kokcd94dd02006-06-27 09:08:22 -07004477
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004478 if ((eeprom_data == ID_LED_RESERVED_0000) ||
4479 (eeprom_data == ID_LED_RESERVED_FFFF)) {
4480 eeprom_data = ID_LED_DEFAULT;
4481 }
Auke Kok90fb5132006-11-01 08:47:30 -08004482
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004483 for (i = 0; i < 4; i++) {
4484 temp = (eeprom_data >> (i << 2)) & led_mask;
4485 switch (temp) {
4486 case ID_LED_ON1_DEF2:
4487 case ID_LED_ON1_ON2:
4488 case ID_LED_ON1_OFF2:
4489 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
4490 hw->ledctl_mode1 |= ledctl_on << (i << 3);
4491 break;
4492 case ID_LED_OFF1_DEF2:
4493 case ID_LED_OFF1_ON2:
4494 case ID_LED_OFF1_OFF2:
4495 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
4496 hw->ledctl_mode1 |= ledctl_off << (i << 3);
4497 break;
4498 default:
4499 /* Do nothing */
4500 break;
4501 }
4502 switch (temp) {
4503 case ID_LED_DEF1_ON2:
4504 case ID_LED_ON1_ON2:
4505 case ID_LED_OFF1_ON2:
4506 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
4507 hw->ledctl_mode2 |= ledctl_on << (i << 3);
4508 break;
4509 case ID_LED_DEF1_OFF2:
4510 case ID_LED_ON1_OFF2:
4511 case ID_LED_OFF1_OFF2:
4512 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
4513 hw->ledctl_mode2 |= ledctl_off << (i << 3);
4514 break;
4515 default:
4516 /* Do nothing */
4517 break;
4518 }
4519 }
4520 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004521}
4522
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004523/**
4524 * e1000_setup_led
4525 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -07004526 *
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004527 * Prepares SW controlable LED for use and saves the current state of the LED.
4528 */
Joe Perches64798842008-07-11 15:17:02 -07004529s32 e1000_setup_led(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004530{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004531 u32 ledctl;
4532 s32 ret_val = E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004533
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004534 switch (hw->mac_type) {
4535 case e1000_82542_rev2_0:
4536 case e1000_82542_rev2_1:
4537 case e1000_82543:
4538 case e1000_82544:
4539 /* No setup necessary */
4540 break;
4541 case e1000_82541:
4542 case e1000_82547:
4543 case e1000_82541_rev_2:
4544 case e1000_82547_rev_2:
4545 /* Turn off PHY Smart Power Down (if enabled) */
4546 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
4547 &hw->phy_spd_default);
4548 if (ret_val)
4549 return ret_val;
4550 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
Janusz Wolak13a87c12015-09-28 23:40:19 +02004551 (u16)(hw->phy_spd_default &
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004552 ~IGP01E1000_GMII_SPD));
4553 if (ret_val)
4554 return ret_val;
4555 /* Fall Through */
4556 default:
4557 if (hw->media_type == e1000_media_type_fiber) {
4558 ledctl = er32(LEDCTL);
4559 /* Save current LEDCTL settings */
4560 hw->ledctl_default = ledctl;
4561 /* Turn off LED0 */
4562 ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
4563 E1000_LEDCTL_LED0_BLINK |
4564 E1000_LEDCTL_LED0_MODE_MASK);
4565 ledctl |= (E1000_LEDCTL_MODE_LED_OFF <<
4566 E1000_LEDCTL_LED0_MODE_SHIFT);
4567 ew32(LEDCTL, ledctl);
4568 } else if (hw->media_type == e1000_media_type_copper)
4569 ew32(LEDCTL, hw->ledctl_mode1);
4570 break;
4571 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004572
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004573 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004574}
4575
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004576/**
4577 * e1000_cleanup_led - Restores the saved state of the SW controlable LED.
4578 * @hw: Struct containing variables accessed by shared code
4579 */
Joe Perches64798842008-07-11 15:17:02 -07004580s32 e1000_cleanup_led(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004581{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004582 s32 ret_val = E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004583
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004584 switch (hw->mac_type) {
4585 case e1000_82542_rev2_0:
4586 case e1000_82542_rev2_1:
4587 case e1000_82543:
4588 case e1000_82544:
4589 /* No cleanup necessary */
4590 break;
4591 case e1000_82541:
4592 case e1000_82547:
4593 case e1000_82541_rev_2:
4594 case e1000_82547_rev_2:
4595 /* Turn on PHY Smart Power Down (if previously enabled) */
4596 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
4597 hw->phy_spd_default);
4598 if (ret_val)
4599 return ret_val;
4600 /* Fall Through */
4601 default:
4602 /* Restore LEDCTL settings */
4603 ew32(LEDCTL, hw->ledctl_default);
4604 break;
4605 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004606
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004607 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004608}
4609
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004610/**
4611 * e1000_led_on - Turns on the software controllable LED
4612 * @hw: Struct containing variables accessed by shared code
4613 */
Joe Perches64798842008-07-11 15:17:02 -07004614s32 e1000_led_on(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004615{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004616 u32 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004617
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004618 switch (hw->mac_type) {
4619 case e1000_82542_rev2_0:
4620 case e1000_82542_rev2_1:
4621 case e1000_82543:
4622 /* Set SW Defineable Pin 0 to turn on the LED */
4623 ctrl |= E1000_CTRL_SWDPIN0;
4624 ctrl |= E1000_CTRL_SWDPIO0;
4625 break;
4626 case e1000_82544:
4627 if (hw->media_type == e1000_media_type_fiber) {
4628 /* Set SW Defineable Pin 0 to turn on the LED */
4629 ctrl |= E1000_CTRL_SWDPIN0;
4630 ctrl |= E1000_CTRL_SWDPIO0;
4631 } else {
4632 /* Clear SW Defineable Pin 0 to turn on the LED */
4633 ctrl &= ~E1000_CTRL_SWDPIN0;
4634 ctrl |= E1000_CTRL_SWDPIO0;
4635 }
4636 break;
4637 default:
4638 if (hw->media_type == e1000_media_type_fiber) {
4639 /* Clear SW Defineable Pin 0 to turn on the LED */
4640 ctrl &= ~E1000_CTRL_SWDPIN0;
4641 ctrl |= E1000_CTRL_SWDPIO0;
4642 } else if (hw->media_type == e1000_media_type_copper) {
4643 ew32(LEDCTL, hw->ledctl_mode2);
4644 return E1000_SUCCESS;
4645 }
4646 break;
4647 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004648
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004649 ew32(CTRL, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004650
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004651 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004652}
4653
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004654/**
4655 * e1000_led_off - Turns off the software controllable LED
4656 * @hw: Struct containing variables accessed by shared code
4657 */
Joe Perches64798842008-07-11 15:17:02 -07004658s32 e1000_led_off(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004659{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004660 u32 ctrl = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004661
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004662 switch (hw->mac_type) {
4663 case e1000_82542_rev2_0:
4664 case e1000_82542_rev2_1:
4665 case e1000_82543:
4666 /* Clear SW Defineable Pin 0 to turn off the LED */
4667 ctrl &= ~E1000_CTRL_SWDPIN0;
4668 ctrl |= E1000_CTRL_SWDPIO0;
4669 break;
4670 case e1000_82544:
4671 if (hw->media_type == e1000_media_type_fiber) {
4672 /* Clear SW Defineable Pin 0 to turn off the LED */
4673 ctrl &= ~E1000_CTRL_SWDPIN0;
4674 ctrl |= E1000_CTRL_SWDPIO0;
4675 } else {
4676 /* Set SW Defineable Pin 0 to turn off the LED */
4677 ctrl |= E1000_CTRL_SWDPIN0;
4678 ctrl |= E1000_CTRL_SWDPIO0;
4679 }
4680 break;
4681 default:
4682 if (hw->media_type == e1000_media_type_fiber) {
4683 /* Set SW Defineable Pin 0 to turn off the LED */
4684 ctrl |= E1000_CTRL_SWDPIN0;
4685 ctrl |= E1000_CTRL_SWDPIO0;
4686 } else if (hw->media_type == e1000_media_type_copper) {
4687 ew32(LEDCTL, hw->ledctl_mode1);
4688 return E1000_SUCCESS;
4689 }
4690 break;
4691 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004692
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004693 ew32(CTRL, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004694
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004695 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004696}
4697
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004698/**
4699 * e1000_clear_hw_cntrs - Clears all hardware statistics counters.
4700 * @hw: Struct containing variables accessed by shared code
4701 */
Joe Perches64798842008-07-11 15:17:02 -07004702static void e1000_clear_hw_cntrs(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004703{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004704 volatile u32 temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004705
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004706 temp = er32(CRCERRS);
4707 temp = er32(SYMERRS);
4708 temp = er32(MPC);
4709 temp = er32(SCC);
4710 temp = er32(ECOL);
4711 temp = er32(MCC);
4712 temp = er32(LATECOL);
4713 temp = er32(COLC);
4714 temp = er32(DC);
4715 temp = er32(SEC);
4716 temp = er32(RLEC);
4717 temp = er32(XONRXC);
4718 temp = er32(XONTXC);
4719 temp = er32(XOFFRXC);
4720 temp = er32(XOFFTXC);
4721 temp = er32(FCRUC);
Auke Kokcd94dd02006-06-27 09:08:22 -07004722
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004723 temp = er32(PRC64);
4724 temp = er32(PRC127);
4725 temp = er32(PRC255);
4726 temp = er32(PRC511);
4727 temp = er32(PRC1023);
4728 temp = er32(PRC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07004729
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004730 temp = er32(GPRC);
4731 temp = er32(BPRC);
4732 temp = er32(MPRC);
4733 temp = er32(GPTC);
4734 temp = er32(GORCL);
4735 temp = er32(GORCH);
4736 temp = er32(GOTCL);
4737 temp = er32(GOTCH);
4738 temp = er32(RNBC);
4739 temp = er32(RUC);
4740 temp = er32(RFC);
4741 temp = er32(ROC);
4742 temp = er32(RJC);
4743 temp = er32(TORL);
4744 temp = er32(TORH);
4745 temp = er32(TOTL);
4746 temp = er32(TOTH);
4747 temp = er32(TPR);
4748 temp = er32(TPT);
Auke Kokcd94dd02006-06-27 09:08:22 -07004749
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004750 temp = er32(PTC64);
4751 temp = er32(PTC127);
4752 temp = er32(PTC255);
4753 temp = er32(PTC511);
4754 temp = er32(PTC1023);
4755 temp = er32(PTC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07004756
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004757 temp = er32(MPTC);
4758 temp = er32(BPTC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004759
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004760 if (hw->mac_type < e1000_82543)
4761 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004762
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004763 temp = er32(ALGNERRC);
4764 temp = er32(RXERRC);
4765 temp = er32(TNCRS);
4766 temp = er32(CEXTERR);
4767 temp = er32(TSCTC);
4768 temp = er32(TSCTFC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004769
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004770 if (hw->mac_type <= e1000_82544)
4771 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004772
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004773 temp = er32(MGTPRC);
4774 temp = er32(MGTPDC);
4775 temp = er32(MGTPTC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004776}
4777
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004778/**
4779 * e1000_reset_adaptive - Resets Adaptive IFS to its default state.
4780 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -07004781 *
4782 * Call this after e1000_init_hw. You may override the IFS defaults by setting
Joe Perchesc3033b02008-03-21 11:06:25 -07004783 * hw->ifs_params_forced to true. However, you must initialize hw->
Linus Torvalds1da177e2005-04-16 15:20:36 -07004784 * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio
4785 * before calling this function.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004786 */
Joe Perches64798842008-07-11 15:17:02 -07004787void e1000_reset_adaptive(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004788{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004789 if (hw->adaptive_ifs) {
4790 if (!hw->ifs_params_forced) {
4791 hw->current_ifs_val = 0;
4792 hw->ifs_min_val = IFS_MIN;
4793 hw->ifs_max_val = IFS_MAX;
4794 hw->ifs_step_size = IFS_STEP;
4795 hw->ifs_ratio = IFS_RATIO;
4796 }
4797 hw->in_ifs_mode = false;
4798 ew32(AIT, 0);
4799 } else {
Emil Tantilov675ad472010-04-27 14:02:58 +00004800 e_dbg("Not in Adaptive IFS mode!\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004801 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004802}
4803
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004804/**
4805 * e1000_update_adaptive - update adaptive IFS
4806 * @hw: Struct containing variables accessed by shared code
4807 * @tx_packets: Number of transmits since last callback
4808 * @total_collisions: Number of collisions since last callback
4809 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07004810 * Called during the callback/watchdog routine to update IFS value based on
4811 * the ratio of transmits to collisions.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004812 */
Joe Perches64798842008-07-11 15:17:02 -07004813void e1000_update_adaptive(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004814{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004815 if (hw->adaptive_ifs) {
Janusz Wolak13a87c12015-09-28 23:40:19 +02004816 if ((hw->collision_delta * hw->ifs_ratio) > hw->tx_packet_delta) {
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004817 if (hw->tx_packet_delta > MIN_NUM_XMITS) {
4818 hw->in_ifs_mode = true;
4819 if (hw->current_ifs_val < hw->ifs_max_val) {
4820 if (hw->current_ifs_val == 0)
4821 hw->current_ifs_val =
4822 hw->ifs_min_val;
4823 else
4824 hw->current_ifs_val +=
4825 hw->ifs_step_size;
4826 ew32(AIT, hw->current_ifs_val);
4827 }
4828 }
4829 } else {
Janusz Wolak13a87c12015-09-28 23:40:19 +02004830 if (hw->in_ifs_mode &&
4831 (hw->tx_packet_delta <= MIN_NUM_XMITS)) {
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004832 hw->current_ifs_val = 0;
4833 hw->in_ifs_mode = false;
4834 ew32(AIT, 0);
4835 }
4836 }
4837 } else {
Emil Tantilov675ad472010-04-27 14:02:58 +00004838 e_dbg("Not in Adaptive IFS mode!\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004839 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004840}
4841
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004842/**
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004843 * e1000_get_bus_info
4844 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -07004845 *
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004846 * Gets the current PCI bus type, speed, and width of the hardware
4847 */
Joe Perches64798842008-07-11 15:17:02 -07004848void e1000_get_bus_info(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004849{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004850 u32 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004851
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004852 switch (hw->mac_type) {
4853 case e1000_82542_rev2_0:
4854 case e1000_82542_rev2_1:
4855 hw->bus_type = e1000_bus_type_pci;
4856 hw->bus_speed = e1000_bus_speed_unknown;
4857 hw->bus_width = e1000_bus_width_unknown;
4858 break;
4859 default:
4860 status = er32(STATUS);
4861 hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
4862 e1000_bus_type_pcix : e1000_bus_type_pci;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004863
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004864 if (hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) {
4865 hw->bus_speed = (hw->bus_type == e1000_bus_type_pci) ?
4866 e1000_bus_speed_66 : e1000_bus_speed_120;
4867 } else if (hw->bus_type == e1000_bus_type_pci) {
4868 hw->bus_speed = (status & E1000_STATUS_PCI66) ?
4869 e1000_bus_speed_66 : e1000_bus_speed_33;
4870 } else {
4871 switch (status & E1000_STATUS_PCIX_SPEED) {
4872 case E1000_STATUS_PCIX_SPEED_66:
4873 hw->bus_speed = e1000_bus_speed_66;
4874 break;
4875 case E1000_STATUS_PCIX_SPEED_100:
4876 hw->bus_speed = e1000_bus_speed_100;
4877 break;
4878 case E1000_STATUS_PCIX_SPEED_133:
4879 hw->bus_speed = e1000_bus_speed_133;
4880 break;
4881 default:
4882 hw->bus_speed = e1000_bus_speed_reserved;
4883 break;
4884 }
4885 }
4886 hw->bus_width = (status & E1000_STATUS_BUS64) ?
4887 e1000_bus_width_64 : e1000_bus_width_32;
4888 break;
4889 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004890}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004891
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004892/**
4893 * e1000_write_reg_io
4894 * @hw: Struct containing variables accessed by shared code
4895 * @offset: offset to write to
4896 * @value: value to write
4897 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07004898 * Writes a value to one of the devices registers using port I/O (as opposed to
4899 * memory mapped I/O). Only 82544 and newer devices support port I/O.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004900 */
Joe Perches64798842008-07-11 15:17:02 -07004901static void e1000_write_reg_io(struct e1000_hw *hw, u32 offset, u32 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004902{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004903 unsigned long io_addr = hw->io_base;
4904 unsigned long io_data = hw->io_base + 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004905
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004906 e1000_io_write(hw, io_addr, offset);
4907 e1000_io_write(hw, io_data, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004908}
4909
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004910/**
4911 * e1000_get_cable_length - Estimates the cable length.
4912 * @hw: Struct containing variables accessed by shared code
4913 * @min_length: The estimated minimum length
4914 * @max_length: The estimated maximum length
Linus Torvalds1da177e2005-04-16 15:20:36 -07004915 *
4916 * returns: - E1000_ERR_XXX
4917 * E1000_SUCCESS
4918 *
4919 * This function always returns a ranged length (minimum & maximum).
4920 * So for M88 phy's, this function interprets the one value returned from the
4921 * register to the minimum and maximum range.
4922 * For IGP phy's, the function calculates the range by the AGC registers.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004923 */
Joe Perches64798842008-07-11 15:17:02 -07004924static s32 e1000_get_cable_length(struct e1000_hw *hw, u16 *min_length,
4925 u16 *max_length)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004926{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004927 s32 ret_val;
4928 u16 agc_value = 0;
4929 u16 i, phy_data;
4930 u16 cable_length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004931
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004932 *min_length = *max_length = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004933
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004934 /* Use old method for Phy older than IGP */
4935 if (hw->phy_type == e1000_phy_m88) {
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004936 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
4937 &phy_data);
4938 if (ret_val)
4939 return ret_val;
4940 cable_length = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
4941 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004942
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004943 /* Convert the enum value to ranged values */
4944 switch (cable_length) {
4945 case e1000_cable_length_50:
4946 *min_length = 0;
4947 *max_length = e1000_igp_cable_length_50;
4948 break;
4949 case e1000_cable_length_50_80:
4950 *min_length = e1000_igp_cable_length_50;
4951 *max_length = e1000_igp_cable_length_80;
4952 break;
4953 case e1000_cable_length_80_110:
4954 *min_length = e1000_igp_cable_length_80;
4955 *max_length = e1000_igp_cable_length_110;
4956 break;
4957 case e1000_cable_length_110_140:
4958 *min_length = e1000_igp_cable_length_110;
4959 *max_length = e1000_igp_cable_length_140;
4960 break;
4961 case e1000_cable_length_140:
4962 *min_length = e1000_igp_cable_length_140;
4963 *max_length = e1000_igp_cable_length_170;
4964 break;
4965 default:
4966 return -E1000_ERR_PHY;
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004967 }
4968 } else if (hw->phy_type == e1000_phy_igp) { /* For IGP PHY */
4969 u16 cur_agc_value;
4970 u16 min_agc_value = IGP01E1000_AGC_LENGTH_TABLE_SIZE;
Jeff Kirsher66744502010-12-01 19:59:50 +00004971 static const u16 agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] = {
4972 IGP01E1000_PHY_AGC_A,
4973 IGP01E1000_PHY_AGC_B,
4974 IGP01E1000_PHY_AGC_C,
4975 IGP01E1000_PHY_AGC_D
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004976 };
4977 /* Read the AGC registers for all channels */
4978 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004979 ret_val =
4980 e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
4981 if (ret_val)
4982 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004983
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004984 cur_agc_value = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004985
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004986 /* Value bound check. */
4987 if ((cur_agc_value >=
Janusz Wolak13a87c12015-09-28 23:40:19 +02004988 IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1) ||
4989 (cur_agc_value == 0))
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004990 return -E1000_ERR_PHY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004991
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004992 agc_value += cur_agc_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004993
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004994 /* Update minimal AGC value. */
4995 if (min_agc_value > cur_agc_value)
4996 min_agc_value = cur_agc_value;
4997 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004998
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07004999 /* Remove the minimal AGC result for length < 50m */
5000 if (agc_value <
5001 IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) {
5002 agc_value -= min_agc_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005003
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005004 /* Get the average length of the remaining 3 channels */
5005 agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1);
5006 } else {
5007 /* Get the average length of all the 4 channels. */
5008 agc_value /= IGP01E1000_PHY_CHANNEL_NUM;
5009 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005010
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005011 /* Set the range of the calculated length. */
5012 *min_length = ((e1000_igp_cable_length_table[agc_value] -
5013 IGP01E1000_AGC_RANGE) > 0) ?
5014 (e1000_igp_cable_length_table[agc_value] -
5015 IGP01E1000_AGC_RANGE) : 0;
5016 *max_length = e1000_igp_cable_length_table[agc_value] +
5017 IGP01E1000_AGC_RANGE;
5018 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005019
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005020 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005021}
5022
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005023/**
5024 * e1000_check_polarity - Check the cable polarity
5025 * @hw: Struct containing variables accessed by shared code
5026 * @polarity: output parameter : 0 - Polarity is not reversed
Linus Torvalds1da177e2005-04-16 15:20:36 -07005027 * 1 - Polarity is reversed.
5028 *
5029 * returns: - E1000_ERR_XXX
5030 * E1000_SUCCESS
5031 *
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02005032 * For phy's older than IGP, this function simply reads the polarity bit in the
Linus Torvalds1da177e2005-04-16 15:20:36 -07005033 * Phy Status register. For IGP phy's, this bit is valid only if link speed is
5034 * 10 Mbps. If the link speed is 100 Mbps there is no polarity so this bit will
5035 * return 0. If the link speed is 1000 Mbps the polarity status is in the
5036 * IGP01E1000_PHY_PCS_INIT_REG.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005037 */
Joe Perches64798842008-07-11 15:17:02 -07005038static s32 e1000_check_polarity(struct e1000_hw *hw,
5039 e1000_rev_polarity *polarity)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005040{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005041 s32 ret_val;
5042 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005043
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005044 if (hw->phy_type == e1000_phy_m88) {
5045 /* return the Polarity bit in the Status register. */
5046 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
5047 &phy_data);
5048 if (ret_val)
5049 return ret_val;
5050 *polarity = ((phy_data & M88E1000_PSSR_REV_POLARITY) >>
5051 M88E1000_PSSR_REV_POLARITY_SHIFT) ?
5052 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07005053
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005054 } else if (hw->phy_type == e1000_phy_igp) {
5055 /* Read the Status register to check the speed */
5056 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
5057 &phy_data);
5058 if (ret_val)
5059 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005060
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00005061 /* If speed is 1000 Mbps, must read the
5062 * IGP01E1000_PHY_PCS_INIT_REG to find the polarity status
5063 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005064 if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
5065 IGP01E1000_PSSR_SPEED_1000MBPS) {
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005066 /* Read the GIG initialization PCS register (0x00B4) */
5067 ret_val =
5068 e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG,
5069 &phy_data);
5070 if (ret_val)
5071 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005072
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005073 /* Check the polarity bits */
5074 *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ?
5075 e1000_rev_polarity_reversed :
5076 e1000_rev_polarity_normal;
5077 } else {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00005078 /* For 10 Mbps, read the polarity bit in the status
5079 * register. (for 100 Mbps this bit is always 0)
5080 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005081 *polarity =
5082 (phy_data & IGP01E1000_PSSR_POLARITY_REVERSED) ?
5083 e1000_rev_polarity_reversed :
5084 e1000_rev_polarity_normal;
5085 }
5086 }
5087 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005088}
5089
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005090/**
5091 * e1000_check_downshift - Check if Downshift occurred
5092 * @hw: Struct containing variables accessed by shared code
5093 * @downshift: output parameter : 0 - No Downshift occurred.
5094 * 1 - Downshift occurred.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005095 *
5096 * returns: - E1000_ERR_XXX
Auke Kok76c224b2006-05-23 13:36:06 -07005097 * E1000_SUCCESS
Linus Torvalds1da177e2005-04-16 15:20:36 -07005098 *
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02005099 * For phy's older than IGP, this function reads the Downshift bit in the Phy
Linus Torvalds1da177e2005-04-16 15:20:36 -07005100 * Specific Status register. For IGP phy's, it reads the Downgrade bit in the
5101 * Link Health register. In IGP this bit is latched high, so the driver must
5102 * read it immediately after link is established.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005103 */
Joe Perches64798842008-07-11 15:17:02 -07005104static s32 e1000_check_downshift(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005105{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005106 s32 ret_val;
5107 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005108
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005109 if (hw->phy_type == e1000_phy_igp) {
5110 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH,
5111 &phy_data);
5112 if (ret_val)
5113 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005114
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005115 hw->speed_downgraded =
5116 (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0;
5117 } else if (hw->phy_type == e1000_phy_m88) {
5118 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
5119 &phy_data);
5120 if (ret_val)
5121 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005122
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005123 hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >>
5124 M88E1000_PSSR_DOWNSHIFT_SHIFT;
5125 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005126
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005127 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005128}
5129
Joe Perches542c3f42012-02-10 12:07:36 +00005130static const u16 dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] = {
5131 IGP01E1000_PHY_AGC_PARAM_A,
5132 IGP01E1000_PHY_AGC_PARAM_B,
5133 IGP01E1000_PHY_AGC_PARAM_C,
5134 IGP01E1000_PHY_AGC_PARAM_D
5135};
5136
5137static s32 e1000_1000Mb_check_cable_length(struct e1000_hw *hw)
5138{
5139 u16 min_length, max_length;
5140 u16 phy_data, i;
5141 s32 ret_val;
5142
5143 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
5144 if (ret_val)
5145 return ret_val;
5146
5147 if (hw->dsp_config_state != e1000_dsp_config_enabled)
5148 return 0;
5149
5150 if (min_length >= e1000_igp_cable_length_50) {
5151 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
5152 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i],
5153 &phy_data);
5154 if (ret_val)
5155 return ret_val;
5156
5157 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
5158
5159 ret_val = e1000_write_phy_reg(hw, dsp_reg_array[i],
5160 phy_data);
5161 if (ret_val)
5162 return ret_val;
5163 }
5164 hw->dsp_config_state = e1000_dsp_config_activated;
5165 } else {
5166 u16 ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_20;
5167 u32 idle_errs = 0;
5168
5169 /* clear previous idle error counts */
5170 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
5171 if (ret_val)
5172 return ret_val;
5173
5174 for (i = 0; i < ffe_idle_err_timeout; i++) {
5175 udelay(1000);
5176 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
5177 &phy_data);
5178 if (ret_val)
5179 return ret_val;
5180
5181 idle_errs += (phy_data & SR_1000T_IDLE_ERROR_CNT);
5182 if (idle_errs > SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT) {
5183 hw->ffe_config_state = e1000_ffe_config_active;
5184
5185 ret_val = e1000_write_phy_reg(hw,
Janusz Wolak13a87c12015-09-28 23:40:19 +02005186 IGP01E1000_PHY_DSP_FFE,
5187 IGP01E1000_PHY_DSP_FFE_CM_CP);
Joe Perches542c3f42012-02-10 12:07:36 +00005188 if (ret_val)
5189 return ret_val;
5190 break;
5191 }
5192
5193 if (idle_errs)
5194 ffe_idle_err_timeout =
5195 FFE_IDLE_ERR_COUNT_TIMEOUT_100;
5196 }
5197 }
5198
5199 return 0;
5200}
5201
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005202/**
5203 * e1000_config_dsp_after_link_change
5204 * @hw: Struct containing variables accessed by shared code
5205 * @link_up: was link up at the time this was called
5206 *
5207 * returns: - E1000_ERR_PHY if fail to read/write the PHY
5208 * E1000_SUCCESS at any other case.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005209 *
5210 * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a
5211 * gigabit link is achieved to improve link quality.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005212 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005213
Joe Perches64798842008-07-11 15:17:02 -07005214static s32 e1000_config_dsp_after_link_change(struct e1000_hw *hw, bool link_up)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005215{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005216 s32 ret_val;
5217 u16 phy_data, phy_saved_data, speed, duplex, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005218
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005219 if (hw->phy_type != e1000_phy_igp)
5220 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005221
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005222 if (link_up) {
5223 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
5224 if (ret_val) {
Emil Tantilov675ad472010-04-27 14:02:58 +00005225 e_dbg("Error getting link speed and duplex\n");
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005226 return ret_val;
5227 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005228
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005229 if (speed == SPEED_1000) {
Joe Perches542c3f42012-02-10 12:07:36 +00005230 ret_val = e1000_1000Mb_check_cable_length(hw);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005231 if (ret_val)
5232 return ret_val;
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005233 }
5234 } else {
5235 if (hw->dsp_config_state == e1000_dsp_config_activated) {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00005236 /* Save off the current value of register 0x2F5B to be
5237 * restored at the end of the routines.
5238 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005239 ret_val =
5240 e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005241
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005242 if (ret_val)
5243 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005244
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005245 /* Disable the PHY transmitter */
5246 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005247
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005248 if (ret_val)
5249 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005250
Jesse Brandeburg4e0d8f7d2011-10-05 07:24:46 +00005251 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005252
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005253 ret_val = e1000_write_phy_reg(hw, 0x0000,
Janusz Wolak13a87c12015-09-28 23:40:19 +02005254 IGP01E1000_IEEE_FORCE_GIGA);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005255 if (ret_val)
5256 return ret_val;
5257 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
5258 ret_val =
5259 e1000_read_phy_reg(hw, dsp_reg_array[i],
5260 &phy_data);
5261 if (ret_val)
5262 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005263
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005264 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
5265 phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005266
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005267 ret_val =
5268 e1000_write_phy_reg(hw, dsp_reg_array[i],
5269 phy_data);
5270 if (ret_val)
5271 return ret_val;
5272 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005273
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005274 ret_val = e1000_write_phy_reg(hw, 0x0000,
Janusz Wolak13a87c12015-09-28 23:40:19 +02005275 IGP01E1000_IEEE_RESTART_AUTONEG);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005276 if (ret_val)
5277 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005278
Jesse Brandeburg4e0d8f7d2011-10-05 07:24:46 +00005279 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005280
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005281 /* Now enable the transmitter */
5282 ret_val =
5283 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005284
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005285 if (ret_val)
5286 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005287
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005288 hw->dsp_config_state = e1000_dsp_config_enabled;
5289 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005290
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005291 if (hw->ffe_config_state == e1000_ffe_config_active) {
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00005292 /* Save off the current value of register 0x2F5B to be
5293 * restored at the end of the routines.
5294 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005295 ret_val =
5296 e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005297
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005298 if (ret_val)
5299 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005300
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005301 /* Disable the PHY transmitter */
5302 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005303
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005304 if (ret_val)
5305 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005306
Jesse Brandeburg4e0d8f7d2011-10-05 07:24:46 +00005307 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005308
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005309 ret_val = e1000_write_phy_reg(hw, 0x0000,
Janusz Wolak13a87c12015-09-28 23:40:19 +02005310 IGP01E1000_IEEE_FORCE_GIGA);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005311 if (ret_val)
5312 return ret_val;
5313 ret_val =
5314 e1000_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE,
5315 IGP01E1000_PHY_DSP_FFE_DEFAULT);
5316 if (ret_val)
5317 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005318
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005319 ret_val = e1000_write_phy_reg(hw, 0x0000,
Janusz Wolak13a87c12015-09-28 23:40:19 +02005320 IGP01E1000_IEEE_RESTART_AUTONEG);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005321 if (ret_val)
5322 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005323
Jesse Brandeburg4e0d8f7d2011-10-05 07:24:46 +00005324 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005325
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005326 /* Now enable the transmitter */
5327 ret_val =
5328 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005329
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005330 if (ret_val)
5331 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005332
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005333 hw->ffe_config_state = e1000_ffe_config_enabled;
5334 }
5335 }
5336 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005337}
5338
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005339/**
5340 * e1000_set_phy_mode - Set PHY to class A mode
5341 * @hw: Struct containing variables accessed by shared code
5342 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07005343 * Assumes the following operations will follow to enable the new class mode.
5344 * 1. Do a PHY soft reset
5345 * 2. Restart auto-negotiation or force link.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005346 */
Joe Perches64798842008-07-11 15:17:02 -07005347static s32 e1000_set_phy_mode(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005348{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005349 s32 ret_val;
5350 u16 eeprom_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005351
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005352 if ((hw->mac_type == e1000_82545_rev_3) &&
5353 (hw->media_type == e1000_media_type_copper)) {
5354 ret_val =
5355 e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, 1,
5356 &eeprom_data);
Janusz Wolak13a87c12015-09-28 23:40:19 +02005357 if (ret_val)
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005358 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005359
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005360 if ((eeprom_data != EEPROM_RESERVED_WORD) &&
5361 (eeprom_data & EEPROM_PHY_CLASS_A)) {
5362 ret_val =
5363 e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT,
5364 0x000B);
5365 if (ret_val)
5366 return ret_val;
5367 ret_val =
5368 e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL,
5369 0x8104);
5370 if (ret_val)
5371 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005372
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005373 hw->phy_reset_disable = false;
5374 }
5375 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005376
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005377 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005378}
5379
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005380/**
5381 * e1000_set_d3_lplu_state - set d3 link power state
5382 * @hw: Struct containing variables accessed by shared code
5383 * @active: true to enable lplu false to disable lplu.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005384 *
5385 * This function sets the lplu state according to the active flag. When
5386 * activating lplu this function also disables smart speed and vise versa.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005387 * lplu will not be activated unless the device autonegotiation advertisement
Linus Torvalds1da177e2005-04-16 15:20:36 -07005388 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005389 *
5390 * returns: - E1000_ERR_PHY if fail to read/write the PHY
5391 * E1000_SUCCESS at any other case.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005392 */
Joe Perches64798842008-07-11 15:17:02 -07005393static s32 e1000_set_d3_lplu_state(struct e1000_hw *hw, bool active)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005394{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005395 s32 ret_val;
5396 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005397
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005398 if (hw->phy_type != e1000_phy_igp)
5399 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005400
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005401 /* During driver activity LPLU should not be used or it will attain link
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00005402 * from the lowest speeds starting from 10Mbps. The capability is used
5403 * for Dx transitions and states
5404 */
Janusz Wolak13a87c12015-09-28 23:40:19 +02005405 if (hw->mac_type == e1000_82541_rev_2 ||
5406 hw->mac_type == e1000_82547_rev_2) {
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005407 ret_val =
5408 e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data);
5409 if (ret_val)
5410 return ret_val;
5411 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005412
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005413 if (!active) {
5414 if (hw->mac_type == e1000_82541_rev_2 ||
5415 hw->mac_type == e1000_82547_rev_2) {
5416 phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
5417 ret_val =
5418 e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
5419 phy_data);
5420 if (ret_val)
5421 return ret_val;
5422 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005423
Jeff Kirsher6cfbd972013-02-09 12:49:21 +00005424 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
5425 * during Dx states where the power conservation is most
5426 * important. During driver activity we should enable
5427 * SmartSpeed, so performance is maintained.
5428 */
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005429 if (hw->smart_speed == e1000_smart_speed_on) {
5430 ret_val =
5431 e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5432 &phy_data);
5433 if (ret_val)
5434 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005435
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005436 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
5437 ret_val =
5438 e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5439 phy_data);
5440 if (ret_val)
5441 return ret_val;
5442 } else if (hw->smart_speed == e1000_smart_speed_off) {
5443 ret_val =
5444 e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5445 &phy_data);
5446 if (ret_val)
5447 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005448
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005449 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
5450 ret_val =
5451 e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5452 phy_data);
5453 if (ret_val)
5454 return ret_val;
5455 }
Janusz Wolak13a87c12015-09-28 23:40:19 +02005456 } else if ((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT) ||
5457 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL) ||
5458 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) {
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005459 if (hw->mac_type == e1000_82541_rev_2 ||
5460 hw->mac_type == e1000_82547_rev_2) {
5461 phy_data |= IGP01E1000_GMII_FLEX_SPD;
5462 ret_val =
5463 e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
5464 phy_data);
5465 if (ret_val)
5466 return ret_val;
5467 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005468
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005469 /* When LPLU is enabled we should disable SmartSpeed */
5470 ret_val =
5471 e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5472 &phy_data);
5473 if (ret_val)
5474 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005475
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005476 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
5477 ret_val =
5478 e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5479 phy_data);
5480 if (ret_val)
5481 return ret_val;
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005482 }
5483 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005484}
5485
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005486/**
5487 * e1000_set_vco_speed
5488 * @hw: Struct containing variables accessed by shared code
Linus Torvalds1da177e2005-04-16 15:20:36 -07005489 *
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005490 * Change VCO speed register to improve Bit Error Rate performance of SERDES.
5491 */
Joe Perches64798842008-07-11 15:17:02 -07005492static s32 e1000_set_vco_speed(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005493{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005494 s32 ret_val;
5495 u16 default_page = 0;
5496 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005497
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005498 switch (hw->mac_type) {
5499 case e1000_82545_rev_3:
5500 case e1000_82546_rev_3:
5501 break;
5502 default:
5503 return E1000_SUCCESS;
5504 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005505
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005506 /* Set PHY register 30, page 5, bit 8 to 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005507
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005508 ret_val =
5509 e1000_read_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, &default_page);
5510 if (ret_val)
5511 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005512
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005513 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005);
5514 if (ret_val)
5515 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005516
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005517 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
5518 if (ret_val)
5519 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005520
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005521 phy_data &= ~M88E1000_PHY_VCO_REG_BIT8;
5522 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
5523 if (ret_val)
5524 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005525
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005526 /* Set PHY register 30, page 4, bit 11 to 1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005527
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005528 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004);
5529 if (ret_val)
5530 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005531
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005532 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
5533 if (ret_val)
5534 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005535
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005536 phy_data |= M88E1000_PHY_VCO_REG_BIT11;
5537 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
5538 if (ret_val)
5539 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005540
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005541 ret_val =
5542 e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, default_page);
5543 if (ret_val)
5544 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005545
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005546 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005547}
5548
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005549/**
5550 * e1000_enable_mng_pass_thru - check for bmc pass through
5551 * @hw: Struct containing variables accessed by shared code
5552 *
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005553 * Verifies the hardware needs to allow ARPs to be processed by the host
Joe Perchesc3033b02008-03-21 11:06:25 -07005554 * returns: - true/false
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005555 */
Joe Perches64798842008-07-11 15:17:02 -07005556u32 e1000_enable_mng_pass_thru(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005557{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005558 u32 manc;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005559
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005560 if (hw->asf_firmware_present) {
5561 manc = er32(MANC);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005562
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005563 if (!(manc & E1000_MANC_RCV_TCO_EN) ||
5564 !(manc & E1000_MANC_EN_MAC_ADDR_FILTER))
5565 return false;
5566 if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN))
5567 return true;
5568 }
5569 return false;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005570}
5571
Joe Perches64798842008-07-11 15:17:02 -07005572static s32 e1000_polarity_reversal_workaround(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005573{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005574 s32 ret_val;
5575 u16 mii_status_reg;
5576 u16 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005577
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005578 /* Polarity reversal workaround for forced 10F/10H links. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005579
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005580 /* Disable the transmitter on the PHY */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005581
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005582 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
5583 if (ret_val)
5584 return ret_val;
5585 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF);
5586 if (ret_val)
5587 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005588
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005589 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
5590 if (ret_val)
5591 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005592
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005593 /* This loop will early-out if the NO link condition has been met. */
5594 for (i = PHY_FORCE_TIME; i > 0; i--) {
5595 /* Read the MII Status Register and wait for Link Status bit
5596 * to be clear.
5597 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005598
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005599 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
5600 if (ret_val)
5601 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005602
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005603 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
5604 if (ret_val)
5605 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005606
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005607 if ((mii_status_reg & ~MII_SR_LINK_STATUS) == 0)
5608 break;
Jesse Brandeburg4e0d8f7d2011-10-05 07:24:46 +00005609 msleep(100);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005610 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005611
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005612 /* Recommended delay time after link has been lost */
Jesse Brandeburg4e0d8f7d2011-10-05 07:24:46 +00005613 msleep(1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005614
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005615 /* Now we will re-enable th transmitter on the PHY */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005616
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005617 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
5618 if (ret_val)
5619 return ret_val;
Jesse Brandeburg4e0d8f7d2011-10-05 07:24:46 +00005620 msleep(50);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005621 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0);
5622 if (ret_val)
5623 return ret_val;
Jesse Brandeburg4e0d8f7d2011-10-05 07:24:46 +00005624 msleep(50);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005625 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00);
5626 if (ret_val)
5627 return ret_val;
Jesse Brandeburg4e0d8f7d2011-10-05 07:24:46 +00005628 msleep(50);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005629 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000);
5630 if (ret_val)
5631 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005632
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005633 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
5634 if (ret_val)
5635 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005636
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005637 /* This loop will early-out if the link condition has been met. */
5638 for (i = PHY_FORCE_TIME; i > 0; i--) {
5639 /* Read the MII Status Register and wait for Link Status bit
5640 * to be set.
5641 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005642
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005643 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
5644 if (ret_val)
5645 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005646
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005647 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
5648 if (ret_val)
5649 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005650
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005651 if (mii_status_reg & MII_SR_LINK_STATUS)
5652 break;
Jesse Brandeburg4e0d8f7d2011-10-05 07:24:46 +00005653 msleep(100);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005654 }
5655 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005656}
5657
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005658/**
5659 * e1000_get_auto_rd_done
5660 * @hw: Struct containing variables accessed by shared code
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005661 *
5662 * Check for EEPROM Auto Read bit done.
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005663 * returns: - E1000_ERR_RESET if fail to reset MAC
5664 * E1000_SUCCESS at any other case.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005665 */
Joe Perches64798842008-07-11 15:17:02 -07005666static s32 e1000_get_auto_rd_done(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005667{
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005668 msleep(5);
5669 return E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005670}
5671
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005672/**
5673 * e1000_get_phy_cfg_done
5674 * @hw: Struct containing variables accessed by shared code
5675 *
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005676 * Checks if the PHY configuration is done
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005677 * returns: - E1000_ERR_RESET if fail to reset MAC
5678 * E1000_SUCCESS at any other case.
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005679 */
Joe Perches64798842008-07-11 15:17:02 -07005680static s32 e1000_get_phy_cfg_done(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005681{
Jesse Brandeburg4e0d8f7d2011-10-05 07:24:46 +00005682 msleep(10);
Jesse Brandeburg120a5d02009-09-25 15:19:46 -07005683 return E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005684}