blob: de2d48624683d03388039a15aff3bc4b22d9dbc9 [file] [log] [blame]
Auke Kok9d5c8242008-01-24 02:22:38 -08001/*******************************************************************************
2
3 Intel(R) Gigabit Ethernet Linux driver
Alexander Duyck86d5d382009-02-06 23:23:12 +00004 Copyright(c) 2007-2009 Intel Corporation.
Auke Kok9d5c8242008-01-24 02:22:38 -08005
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
14
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Contact Information:
23 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25
26*******************************************************************************/
27
28#include <linux/if_ether.h>
29#include <linux/delay.h>
30
31#include "e1000_mac.h"
32#include "e1000_phy.h"
33
Auke Kok9d5c8242008-01-24 02:22:38 -080034static s32 igb_phy_setup_autoneg(struct e1000_hw *hw);
35static void igb_phy_force_speed_duplex_setup(struct e1000_hw *hw,
36 u16 *phy_ctrl);
37static s32 igb_wait_autoneg(struct e1000_hw *hw);
38
39/* Cable length tables */
40static const u16 e1000_m88_cable_length_table[] =
41 { 0, 50, 80, 110, 140, 140, E1000_CABLE_LENGTH_UNDEFINED };
Auke Kok9d5c8242008-01-24 02:22:38 -080042
43static const u16 e1000_igp_2_cable_length_table[] =
44 { 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21,
45 0, 0, 0, 3, 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41,
46 6, 10, 14, 18, 22, 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61,
47 21, 26, 31, 35, 40, 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82,
48 40, 45, 51, 56, 61, 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104,
49 60, 66, 72, 77, 82, 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121,
50 83, 89, 95, 100, 105, 109, 113, 116, 119, 122, 124,
51 104, 109, 114, 118, 121, 124};
52#define IGP02E1000_CABLE_LENGTH_TABLE_SIZE \
53 (sizeof(e1000_igp_2_cable_length_table) / \
54 sizeof(e1000_igp_2_cable_length_table[0]))
55
56/**
Jeff Kirsher733596b2008-06-27 10:59:59 -070057 * igb_check_reset_block - Check if PHY reset is blocked
Auke Kok9d5c8242008-01-24 02:22:38 -080058 * @hw: pointer to the HW structure
59 *
60 * Read the PHY management control register and check whether a PHY reset
61 * is blocked. If a reset is not blocked return 0, otherwise
62 * return E1000_BLK_PHY_RESET (12).
63 **/
64s32 igb_check_reset_block(struct e1000_hw *hw)
65{
66 u32 manc;
67
68 manc = rd32(E1000_MANC);
69
70 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
71 E1000_BLK_PHY_RESET : 0;
72}
73
74/**
Jeff Kirsher733596b2008-06-27 10:59:59 -070075 * igb_get_phy_id - Retrieve the PHY ID and revision
Auke Kok9d5c8242008-01-24 02:22:38 -080076 * @hw: pointer to the HW structure
77 *
78 * Reads the PHY registers and stores the PHY ID and possibly the PHY
79 * revision in the hardware structure.
80 **/
81s32 igb_get_phy_id(struct e1000_hw *hw)
82{
83 struct e1000_phy_info *phy = &hw->phy;
84 s32 ret_val = 0;
85 u16 phy_id;
86
Alexander Duycka8d2a0c2009-02-06 23:17:26 +000087 ret_val = phy->ops.read_reg(hw, PHY_ID1, &phy_id);
Auke Kok9d5c8242008-01-24 02:22:38 -080088 if (ret_val)
89 goto out;
90
91 phy->id = (u32)(phy_id << 16);
92 udelay(20);
Alexander Duycka8d2a0c2009-02-06 23:17:26 +000093 ret_val = phy->ops.read_reg(hw, PHY_ID2, &phy_id);
Auke Kok9d5c8242008-01-24 02:22:38 -080094 if (ret_val)
95 goto out;
96
97 phy->id |= (u32)(phy_id & PHY_REVISION_MASK);
98 phy->revision = (u32)(phy_id & ~PHY_REVISION_MASK);
99
100out:
101 return ret_val;
102}
103
104/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700105 * igb_phy_reset_dsp - Reset PHY DSP
Auke Kok9d5c8242008-01-24 02:22:38 -0800106 * @hw: pointer to the HW structure
107 *
108 * Reset the digital signal processor.
109 **/
110static s32 igb_phy_reset_dsp(struct e1000_hw *hw)
111{
112 s32 ret_val;
113
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000114 ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xC1);
Auke Kok9d5c8242008-01-24 02:22:38 -0800115 if (ret_val)
116 goto out;
117
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000118 ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0);
Auke Kok9d5c8242008-01-24 02:22:38 -0800119
120out:
121 return ret_val;
122}
123
124/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700125 * igb_read_phy_reg_mdic - Read MDI control register
Auke Kok9d5c8242008-01-24 02:22:38 -0800126 * @hw: pointer to the HW structure
127 * @offset: register offset to be read
128 * @data: pointer to the read data
129 *
130 * Reads the MDI control regsiter in the PHY at offset and stores the
131 * information read to data.
132 **/
133static s32 igb_read_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 *data)
134{
135 struct e1000_phy_info *phy = &hw->phy;
136 u32 i, mdic = 0;
137 s32 ret_val = 0;
138
139 if (offset > MAX_PHY_REG_ADDRESS) {
Auke Kok652fff32008-06-27 11:00:18 -0700140 hw_dbg("PHY Address %d is out of range\n", offset);
Auke Kok9d5c8242008-01-24 02:22:38 -0800141 ret_val = -E1000_ERR_PARAM;
142 goto out;
143 }
144
145 /*
146 * Set up Op-code, Phy Address, and register offset in the MDI
147 * Control register. The MAC will take care of interfacing with the
148 * PHY to retrieve the desired data.
149 */
150 mdic = ((offset << E1000_MDIC_REG_SHIFT) |
151 (phy->addr << E1000_MDIC_PHY_SHIFT) |
152 (E1000_MDIC_OP_READ));
153
154 wr32(E1000_MDIC, mdic);
155
156 /*
157 * Poll the ready bit to see if the MDI read completed
158 * Increasing the time out as testing showed failures with
159 * the lower time out
160 */
161 for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
162 udelay(50);
163 mdic = rd32(E1000_MDIC);
164 if (mdic & E1000_MDIC_READY)
165 break;
166 }
167 if (!(mdic & E1000_MDIC_READY)) {
Auke Kok652fff32008-06-27 11:00:18 -0700168 hw_dbg("MDI Read did not complete\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800169 ret_val = -E1000_ERR_PHY;
170 goto out;
171 }
172 if (mdic & E1000_MDIC_ERROR) {
Auke Kok652fff32008-06-27 11:00:18 -0700173 hw_dbg("MDI Error\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800174 ret_val = -E1000_ERR_PHY;
175 goto out;
176 }
177 *data = (u16) mdic;
178
179out:
180 return ret_val;
181}
182
183/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700184 * igb_write_phy_reg_mdic - Write MDI control register
Auke Kok9d5c8242008-01-24 02:22:38 -0800185 * @hw: pointer to the HW structure
186 * @offset: register offset to write to
187 * @data: data to write to register at offset
188 *
189 * Writes data to MDI control register in the PHY at offset.
190 **/
191static s32 igb_write_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 data)
192{
193 struct e1000_phy_info *phy = &hw->phy;
194 u32 i, mdic = 0;
195 s32 ret_val = 0;
196
197 if (offset > MAX_PHY_REG_ADDRESS) {
Auke Kok652fff32008-06-27 11:00:18 -0700198 hw_dbg("PHY Address %d is out of range\n", offset);
Auke Kok9d5c8242008-01-24 02:22:38 -0800199 ret_val = -E1000_ERR_PARAM;
200 goto out;
201 }
202
203 /*
204 * Set up Op-code, Phy Address, and register offset in the MDI
205 * Control register. The MAC will take care of interfacing with the
206 * PHY to retrieve the desired data.
207 */
208 mdic = (((u32)data) |
209 (offset << E1000_MDIC_REG_SHIFT) |
210 (phy->addr << E1000_MDIC_PHY_SHIFT) |
211 (E1000_MDIC_OP_WRITE));
212
213 wr32(E1000_MDIC, mdic);
214
215 /*
216 * Poll the ready bit to see if the MDI read completed
217 * Increasing the time out as testing showed failures with
218 * the lower time out
219 */
220 for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
221 udelay(50);
222 mdic = rd32(E1000_MDIC);
223 if (mdic & E1000_MDIC_READY)
224 break;
225 }
226 if (!(mdic & E1000_MDIC_READY)) {
Auke Kok652fff32008-06-27 11:00:18 -0700227 hw_dbg("MDI Write did not complete\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800228 ret_val = -E1000_ERR_PHY;
229 goto out;
230 }
231 if (mdic & E1000_MDIC_ERROR) {
Auke Kok652fff32008-06-27 11:00:18 -0700232 hw_dbg("MDI Error\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800233 ret_val = -E1000_ERR_PHY;
234 goto out;
235 }
236
237out:
238 return ret_val;
239}
240
241/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700242 * igb_read_phy_reg_igp - Read igp PHY register
Auke Kok9d5c8242008-01-24 02:22:38 -0800243 * @hw: pointer to the HW structure
244 * @offset: register offset to be read
245 * @data: pointer to the read data
246 *
247 * Acquires semaphore, if necessary, then reads the PHY register at offset
248 * and storing the retrieved information in data. Release any acquired
249 * semaphores before exiting.
250 **/
251s32 igb_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data)
252{
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000253 s32 ret_val = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -0800254
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000255 if (!(hw->phy.ops.acquire))
256 goto out;
257
258 ret_val = hw->phy.ops.acquire(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800259 if (ret_val)
260 goto out;
261
262 if (offset > MAX_PHY_MULTI_PAGE_REG) {
263 ret_val = igb_write_phy_reg_mdic(hw,
264 IGP01E1000_PHY_PAGE_SELECT,
265 (u16)offset);
266 if (ret_val) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000267 hw->phy.ops.release(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800268 goto out;
269 }
270 }
271
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000272 ret_val = igb_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
273 data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800274
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000275 hw->phy.ops.release(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800276
277out:
278 return ret_val;
279}
280
281/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700282 * igb_write_phy_reg_igp - Write igp PHY register
Auke Kok9d5c8242008-01-24 02:22:38 -0800283 * @hw: pointer to the HW structure
284 * @offset: register offset to write to
285 * @data: data to write at register offset
286 *
287 * Acquires semaphore, if necessary, then writes the data to PHY register
288 * at the offset. Release any acquired semaphores before exiting.
289 **/
290s32 igb_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data)
291{
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000292 s32 ret_val = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -0800293
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000294 if (!(hw->phy.ops.acquire))
295 goto out;
296
297 ret_val = hw->phy.ops.acquire(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800298 if (ret_val)
299 goto out;
300
301 if (offset > MAX_PHY_MULTI_PAGE_REG) {
302 ret_val = igb_write_phy_reg_mdic(hw,
303 IGP01E1000_PHY_PAGE_SELECT,
304 (u16)offset);
305 if (ret_val) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000306 hw->phy.ops.release(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800307 goto out;
308 }
309 }
310
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000311 ret_val = igb_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
Auke Kok9d5c8242008-01-24 02:22:38 -0800312 data);
313
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000314 hw->phy.ops.release(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800315
316out:
317 return ret_val;
318}
319
320/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700321 * igb_copper_link_setup_m88 - Setup m88 PHY's for copper link
Auke Kok9d5c8242008-01-24 02:22:38 -0800322 * @hw: pointer to the HW structure
323 *
324 * Sets up MDI/MDI-X and polarity for m88 PHY's. If necessary, transmit clock
325 * and downshift values are set also.
326 **/
327s32 igb_copper_link_setup_m88(struct e1000_hw *hw)
328{
329 struct e1000_phy_info *phy = &hw->phy;
330 s32 ret_val;
331 u16 phy_data;
332
333 if (phy->reset_disable) {
334 ret_val = 0;
335 goto out;
336 }
337
338 /* Enable CRS on TX. This must be set for half-duplex operation. */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000339 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800340 if (ret_val)
341 goto out;
342
343 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
344
345 /*
346 * Options:
347 * MDI/MDI-X = 0 (default)
348 * 0 - Auto for all speeds
349 * 1 - MDI mode
350 * 2 - MDI-X mode
351 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
352 */
353 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
354
355 switch (phy->mdix) {
356 case 1:
357 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
358 break;
359 case 2:
360 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
361 break;
362 case 3:
363 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
364 break;
365 case 0:
366 default:
367 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
368 break;
369 }
370
371 /*
372 * Options:
373 * disable_polarity_correction = 0 (default)
374 * Automatic Correction for Reversed Cable Polarity
375 * 0 - Disabled
376 * 1 - Enabled
377 */
378 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
379 if (phy->disable_polarity_correction == 1)
380 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
381
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000382 ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800383 if (ret_val)
384 goto out;
385
386 if (phy->revision < E1000_REVISION_4) {
387 /*
388 * Force TX_CLK in the Extended PHY Specific Control Register
389 * to 25MHz clock.
390 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000391 ret_val = phy->ops.read_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
Auke Kok9d5c8242008-01-24 02:22:38 -0800392 &phy_data);
393 if (ret_val)
394 goto out;
395
396 phy_data |= M88E1000_EPSCR_TX_CLK_25;
397
398 if ((phy->revision == E1000_REVISION_2) &&
399 (phy->id == M88E1111_I_PHY_ID)) {
400 /* 82573L PHY - set the downshift counter to 5x. */
401 phy_data &= ~M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK;
402 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
403 } else {
404 /* Configure Master and Slave downshift values */
405 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
406 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
407 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
408 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
409 }
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000410 ret_val = phy->ops.write_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
Auke Kok9d5c8242008-01-24 02:22:38 -0800411 phy_data);
412 if (ret_val)
413 goto out;
414 }
415
416 /* Commit the changes. */
417 ret_val = igb_phy_sw_reset(hw);
418 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700419 hw_dbg("Error committing the PHY changes\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800420 goto out;
421 }
422
423out:
424 return ret_val;
425}
426
427/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700428 * igb_copper_link_setup_igp - Setup igp PHY's for copper link
Auke Kok9d5c8242008-01-24 02:22:38 -0800429 * @hw: pointer to the HW structure
430 *
431 * Sets up LPLU, MDI/MDI-X, polarity, Smartspeed and Master/Slave config for
432 * igp PHY's.
433 **/
434s32 igb_copper_link_setup_igp(struct e1000_hw *hw)
435{
436 struct e1000_phy_info *phy = &hw->phy;
437 s32 ret_val;
438 u16 data;
439
440 if (phy->reset_disable) {
441 ret_val = 0;
442 goto out;
443 }
444
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000445 ret_val = phy->ops.reset(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800446 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700447 hw_dbg("Error resetting the PHY.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800448 goto out;
449 }
450
451 /* Wait 15ms for MAC to configure PHY from NVM settings. */
452 msleep(15);
453
454 /*
455 * The NVM settings will configure LPLU in D3 for
456 * non-IGP1 PHYs.
457 */
458 if (phy->type == e1000_phy_igp) {
459 /* disable lplu d3 during driver init */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000460 if (phy->ops.set_d3_lplu_state)
461 ret_val = phy->ops.set_d3_lplu_state(hw, false);
Auke Kok9d5c8242008-01-24 02:22:38 -0800462 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700463 hw_dbg("Error Disabling LPLU D3\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800464 goto out;
465 }
466 }
467
468 /* disable lplu d0 during driver init */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000469 ret_val = phy->ops.set_d0_lplu_state(hw, false);
Auke Kok9d5c8242008-01-24 02:22:38 -0800470 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700471 hw_dbg("Error Disabling LPLU D0\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800472 goto out;
473 }
474 /* Configure mdi-mdix settings */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000475 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CTRL, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800476 if (ret_val)
477 goto out;
478
479 data &= ~IGP01E1000_PSCR_AUTO_MDIX;
480
481 switch (phy->mdix) {
482 case 1:
483 data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
484 break;
485 case 2:
486 data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
487 break;
488 case 0:
489 default:
490 data |= IGP01E1000_PSCR_AUTO_MDIX;
491 break;
492 }
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000493 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CTRL, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800494 if (ret_val)
495 goto out;
496
497 /* set auto-master slave resolution settings */
498 if (hw->mac.autoneg) {
499 /*
500 * when autonegotiation advertisement is only 1000Mbps then we
501 * should disable SmartSpeed and enable Auto MasterSlave
502 * resolution as hardware default.
503 */
504 if (phy->autoneg_advertised == ADVERTISE_1000_FULL) {
505 /* Disable SmartSpeed */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000506 ret_val = phy->ops.read_reg(hw,
507 IGP01E1000_PHY_PORT_CONFIG,
508 &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800509 if (ret_val)
510 goto out;
511
512 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000513 ret_val = phy->ops.write_reg(hw,
Auke Kok9d5c8242008-01-24 02:22:38 -0800514 IGP01E1000_PHY_PORT_CONFIG,
515 data);
516 if (ret_val)
517 goto out;
518
519 /* Set auto Master/Slave resolution process */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000520 ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800521 if (ret_val)
522 goto out;
523
524 data &= ~CR_1000T_MS_ENABLE;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000525 ret_val = phy->ops.write_reg(hw, PHY_1000T_CTRL, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800526 if (ret_val)
527 goto out;
528 }
529
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000530 ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800531 if (ret_val)
532 goto out;
533
534 /* load defaults for future use */
535 phy->original_ms_type = (data & CR_1000T_MS_ENABLE) ?
536 ((data & CR_1000T_MS_VALUE) ?
537 e1000_ms_force_master :
538 e1000_ms_force_slave) :
539 e1000_ms_auto;
540
541 switch (phy->ms_type) {
542 case e1000_ms_force_master:
543 data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
544 break;
545 case e1000_ms_force_slave:
546 data |= CR_1000T_MS_ENABLE;
547 data &= ~(CR_1000T_MS_VALUE);
548 break;
549 case e1000_ms_auto:
550 data &= ~CR_1000T_MS_ENABLE;
551 default:
552 break;
553 }
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000554 ret_val = phy->ops.write_reg(hw, PHY_1000T_CTRL, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800555 if (ret_val)
556 goto out;
557 }
558
559out:
560 return ret_val;
561}
562
563/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700564 * igb_copper_link_autoneg - Setup/Enable autoneg for copper link
Auke Kok9d5c8242008-01-24 02:22:38 -0800565 * @hw: pointer to the HW structure
566 *
567 * Performs initial bounds checking on autoneg advertisement parameter, then
568 * configure to advertise the full capability. Setup the PHY to autoneg
569 * and restart the negotiation process between the link partner. If
570 * autoneg_wait_to_complete, then wait for autoneg to complete before exiting.
571 **/
572s32 igb_copper_link_autoneg(struct e1000_hw *hw)
573{
574 struct e1000_phy_info *phy = &hw->phy;
575 s32 ret_val;
576 u16 phy_ctrl;
577
578 /*
579 * Perform some bounds checking on the autoneg advertisement
580 * parameter.
581 */
582 phy->autoneg_advertised &= phy->autoneg_mask;
583
584 /*
585 * If autoneg_advertised is zero, we assume it was not defaulted
586 * by the calling code so we set to advertise full capability.
587 */
588 if (phy->autoneg_advertised == 0)
589 phy->autoneg_advertised = phy->autoneg_mask;
590
Auke Kok652fff32008-06-27 11:00:18 -0700591 hw_dbg("Reconfiguring auto-neg advertisement params\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800592 ret_val = igb_phy_setup_autoneg(hw);
593 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700594 hw_dbg("Error Setting up Auto-Negotiation\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800595 goto out;
596 }
Auke Kok652fff32008-06-27 11:00:18 -0700597 hw_dbg("Restarting Auto-Neg\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800598
599 /*
600 * Restart auto-negotiation by setting the Auto Neg Enable bit and
601 * the Auto Neg Restart bit in the PHY control register.
602 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000603 ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_ctrl);
Auke Kok9d5c8242008-01-24 02:22:38 -0800604 if (ret_val)
605 goto out;
606
607 phy_ctrl |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000608 ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_ctrl);
Auke Kok9d5c8242008-01-24 02:22:38 -0800609 if (ret_val)
610 goto out;
611
612 /*
613 * Does the user want to wait for Auto-Neg to complete here, or
614 * check at a later time (for example, callback routine).
615 */
616 if (phy->autoneg_wait_to_complete) {
617 ret_val = igb_wait_autoneg(hw);
618 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700619 hw_dbg("Error while waiting for "
620 "autoneg to complete\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800621 goto out;
622 }
623 }
624
625 hw->mac.get_link_status = true;
626
627out:
628 return ret_val;
629}
630
631/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700632 * igb_phy_setup_autoneg - Configure PHY for auto-negotiation
Auke Kok9d5c8242008-01-24 02:22:38 -0800633 * @hw: pointer to the HW structure
634 *
635 * Reads the MII auto-neg advertisement register and/or the 1000T control
636 * register and if the PHY is already setup for auto-negotiation, then
637 * return successful. Otherwise, setup advertisement and flow control to
638 * the appropriate values for the wanted auto-negotiation.
639 **/
640static s32 igb_phy_setup_autoneg(struct e1000_hw *hw)
641{
642 struct e1000_phy_info *phy = &hw->phy;
643 s32 ret_val;
644 u16 mii_autoneg_adv_reg;
645 u16 mii_1000t_ctrl_reg = 0;
646
647 phy->autoneg_advertised &= phy->autoneg_mask;
648
649 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000650 ret_val = phy->ops.read_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
Auke Kok9d5c8242008-01-24 02:22:38 -0800651 if (ret_val)
652 goto out;
653
654 if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
655 /* Read the MII 1000Base-T Control Register (Address 9). */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000656 ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL,
Auke Kok9d5c8242008-01-24 02:22:38 -0800657 &mii_1000t_ctrl_reg);
658 if (ret_val)
659 goto out;
660 }
661
662 /*
663 * Need to parse both autoneg_advertised and fc and set up
664 * the appropriate PHY registers. First we will parse for
665 * autoneg_advertised software override. Since we can advertise
666 * a plethora of combinations, we need to check each bit
667 * individually.
668 */
669
670 /*
671 * First we clear all the 10/100 mb speed bits in the Auto-Neg
672 * Advertisement Register (Address 4) and the 1000 mb speed bits in
673 * the 1000Base-T Control Register (Address 9).
674 */
675 mii_autoneg_adv_reg &= ~(NWAY_AR_100TX_FD_CAPS |
676 NWAY_AR_100TX_HD_CAPS |
677 NWAY_AR_10T_FD_CAPS |
678 NWAY_AR_10T_HD_CAPS);
679 mii_1000t_ctrl_reg &= ~(CR_1000T_HD_CAPS | CR_1000T_FD_CAPS);
680
Auke Kok652fff32008-06-27 11:00:18 -0700681 hw_dbg("autoneg_advertised %x\n", phy->autoneg_advertised);
Auke Kok9d5c8242008-01-24 02:22:38 -0800682
683 /* Do we want to advertise 10 Mb Half Duplex? */
684 if (phy->autoneg_advertised & ADVERTISE_10_HALF) {
Auke Kok652fff32008-06-27 11:00:18 -0700685 hw_dbg("Advertise 10mb Half duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800686 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
687 }
688
689 /* Do we want to advertise 10 Mb Full Duplex? */
690 if (phy->autoneg_advertised & ADVERTISE_10_FULL) {
Auke Kok652fff32008-06-27 11:00:18 -0700691 hw_dbg("Advertise 10mb Full duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800692 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
693 }
694
695 /* Do we want to advertise 100 Mb Half Duplex? */
696 if (phy->autoneg_advertised & ADVERTISE_100_HALF) {
Auke Kok652fff32008-06-27 11:00:18 -0700697 hw_dbg("Advertise 100mb Half duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800698 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
699 }
700
701 /* Do we want to advertise 100 Mb Full Duplex? */
702 if (phy->autoneg_advertised & ADVERTISE_100_FULL) {
Auke Kok652fff32008-06-27 11:00:18 -0700703 hw_dbg("Advertise 100mb Full duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800704 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
705 }
706
707 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
708 if (phy->autoneg_advertised & ADVERTISE_1000_HALF)
Auke Kok652fff32008-06-27 11:00:18 -0700709 hw_dbg("Advertise 1000mb Half duplex request denied!\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800710
711 /* Do we want to advertise 1000 Mb Full Duplex? */
712 if (phy->autoneg_advertised & ADVERTISE_1000_FULL) {
Auke Kok652fff32008-06-27 11:00:18 -0700713 hw_dbg("Advertise 1000mb Full duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800714 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
715 }
716
717 /*
718 * Check for a software override of the flow control settings, and
719 * setup the PHY advertisement registers accordingly. If
720 * auto-negotiation is enabled, then software will have to set the
721 * "PAUSE" bits to the correct value in the Auto-Negotiation
722 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-
723 * negotiation.
724 *
725 * The possible values of the "fc" parameter are:
726 * 0: Flow control is completely disabled
727 * 1: Rx flow control is enabled (we can receive pause frames
728 * but not send pause frames).
729 * 2: Tx flow control is enabled (we can send pause frames
730 * but we do not support receiving pause frames).
731 * 3: Both Rx and TX flow control (symmetric) are enabled.
732 * other: No software override. The flow control configuration
733 * in the EEPROM is used.
734 */
735 switch (hw->fc.type) {
736 case e1000_fc_none:
737 /*
738 * Flow control (RX & TX) is completely disabled by a
739 * software over-ride.
740 */
741 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
742 break;
743 case e1000_fc_rx_pause:
744 /*
745 * RX Flow control is enabled, and TX Flow control is
746 * disabled, by a software over-ride.
747 *
748 * Since there really isn't a way to advertise that we are
749 * capable of RX Pause ONLY, we will advertise that we
750 * support both symmetric and asymmetric RX PAUSE. Later
751 * (in e1000_config_fc_after_link_up) we will disable the
752 * hw's ability to send PAUSE frames.
753 */
754 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
755 break;
756 case e1000_fc_tx_pause:
757 /*
758 * TX Flow control is enabled, and RX Flow control is
759 * disabled, by a software over-ride.
760 */
761 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
762 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
763 break;
764 case e1000_fc_full:
765 /*
766 * Flow control (both RX and TX) is enabled by a software
767 * over-ride.
768 */
769 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
770 break;
771 default:
Auke Kok652fff32008-06-27 11:00:18 -0700772 hw_dbg("Flow control param set incorrectly\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800773 ret_val = -E1000_ERR_CONFIG;
774 goto out;
775 }
776
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000777 ret_val = phy->ops.write_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
Auke Kok9d5c8242008-01-24 02:22:38 -0800778 if (ret_val)
779 goto out;
780
Auke Kok652fff32008-06-27 11:00:18 -0700781 hw_dbg("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
Auke Kok9d5c8242008-01-24 02:22:38 -0800782
783 if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000784 ret_val = phy->ops.write_reg(hw,
785 PHY_1000T_CTRL,
786 mii_1000t_ctrl_reg);
Auke Kok9d5c8242008-01-24 02:22:38 -0800787 if (ret_val)
788 goto out;
789 }
790
791out:
792 return ret_val;
793}
794
795/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700796 * igb_phy_force_speed_duplex_igp - Force speed/duplex for igp PHY
Auke Kok9d5c8242008-01-24 02:22:38 -0800797 * @hw: pointer to the HW structure
798 *
799 * Calls the PHY setup function to force speed and duplex. Clears the
800 * auto-crossover to force MDI manually. Waits for link and returns
801 * successful if link up is successful, else -E1000_ERR_PHY (-2).
802 **/
803s32 igb_phy_force_speed_duplex_igp(struct e1000_hw *hw)
804{
805 struct e1000_phy_info *phy = &hw->phy;
806 s32 ret_val;
807 u16 phy_data;
808 bool link;
809
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000810 ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800811 if (ret_val)
812 goto out;
813
814 igb_phy_force_speed_duplex_setup(hw, &phy_data);
815
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000816 ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800817 if (ret_val)
818 goto out;
819
820 /*
821 * Clear Auto-Crossover to force MDI manually. IGP requires MDI
822 * forced whenever speed and duplex are forced.
823 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000824 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800825 if (ret_val)
826 goto out;
827
828 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
829 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
830
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000831 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800832 if (ret_val)
833 goto out;
834
Auke Kok652fff32008-06-27 11:00:18 -0700835 hw_dbg("IGP PSCR: %X\n", phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800836
837 udelay(1);
838
839 if (phy->autoneg_wait_to_complete) {
Auke Kok652fff32008-06-27 11:00:18 -0700840 hw_dbg("Waiting for forced speed/duplex link on IGP phy.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800841
842 ret_val = igb_phy_has_link(hw,
843 PHY_FORCE_LIMIT,
844 100000,
845 &link);
846 if (ret_val)
847 goto out;
848
849 if (!link)
Auke Kok652fff32008-06-27 11:00:18 -0700850 hw_dbg("Link taking longer than expected.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800851
852 /* Try once more */
853 ret_val = igb_phy_has_link(hw,
854 PHY_FORCE_LIMIT,
855 100000,
856 &link);
857 if (ret_val)
858 goto out;
859 }
860
861out:
862 return ret_val;
863}
864
865/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700866 * igb_phy_force_speed_duplex_m88 - Force speed/duplex for m88 PHY
Auke Kok9d5c8242008-01-24 02:22:38 -0800867 * @hw: pointer to the HW structure
868 *
869 * Calls the PHY setup function to force speed and duplex. Clears the
870 * auto-crossover to force MDI manually. Resets the PHY to commit the
871 * changes. If time expires while waiting for link up, we reset the DSP.
872 * After reset, TX_CLK and CRS on TX must be set. Return successful upon
873 * successful completion, else return corresponding error code.
874 **/
875s32 igb_phy_force_speed_duplex_m88(struct e1000_hw *hw)
876{
877 struct e1000_phy_info *phy = &hw->phy;
878 s32 ret_val;
879 u16 phy_data;
880 bool link;
881
882 /*
883 * Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
884 * forced whenever speed and duplex are forced.
885 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000886 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800887 if (ret_val)
888 goto out;
889
890 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000891 ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800892 if (ret_val)
893 goto out;
894
Auke Kok652fff32008-06-27 11:00:18 -0700895 hw_dbg("M88E1000 PSCR: %X\n", phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800896
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000897 ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800898 if (ret_val)
899 goto out;
900
901 igb_phy_force_speed_duplex_setup(hw, &phy_data);
902
903 /* Reset the phy to commit changes. */
904 phy_data |= MII_CR_RESET;
905
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000906 ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800907 if (ret_val)
908 goto out;
909
910 udelay(1);
911
912 if (phy->autoneg_wait_to_complete) {
Auke Kok652fff32008-06-27 11:00:18 -0700913 hw_dbg("Waiting for forced speed/duplex link on M88 phy.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800914
915 ret_val = igb_phy_has_link(hw,
916 PHY_FORCE_LIMIT,
917 100000,
918 &link);
919 if (ret_val)
920 goto out;
921
922 if (!link) {
923 /*
924 * We didn't get link.
925 * Reset the DSP and cross our fingers.
926 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000927 ret_val = phy->ops.write_reg(hw,
Auke Kok9d5c8242008-01-24 02:22:38 -0800928 M88E1000_PHY_PAGE_SELECT,
929 0x001d);
930 if (ret_val)
931 goto out;
932 ret_val = igb_phy_reset_dsp(hw);
933 if (ret_val)
934 goto out;
935 }
936
937 /* Try once more */
938 ret_val = igb_phy_has_link(hw, PHY_FORCE_LIMIT,
939 100000, &link);
940 if (ret_val)
941 goto out;
942 }
943
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000944 ret_val = phy->ops.read_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800945 if (ret_val)
946 goto out;
947
948 /*
949 * Resetting the phy means we need to re-force TX_CLK in the
950 * Extended PHY Specific Control Register to 25MHz clock from
951 * the reset value of 2.5MHz.
952 */
953 phy_data |= M88E1000_EPSCR_TX_CLK_25;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000954 ret_val = phy->ops.write_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800955 if (ret_val)
956 goto out;
957
958 /*
959 * In addition, we must re-enable CRS on Tx for both half and full
960 * duplex.
961 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000962 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800963 if (ret_val)
964 goto out;
965
966 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000967 ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800968
969out:
970 return ret_val;
971}
972
973/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700974 * igb_phy_force_speed_duplex_setup - Configure forced PHY speed/duplex
Auke Kok9d5c8242008-01-24 02:22:38 -0800975 * @hw: pointer to the HW structure
976 * @phy_ctrl: pointer to current value of PHY_CONTROL
977 *
978 * Forces speed and duplex on the PHY by doing the following: disable flow
979 * control, force speed/duplex on the MAC, disable auto speed detection,
980 * disable auto-negotiation, configure duplex, configure speed, configure
981 * the collision distance, write configuration to CTRL register. The
982 * caller must write to the PHY_CONTROL register for these settings to
983 * take affect.
984 **/
985static void igb_phy_force_speed_duplex_setup(struct e1000_hw *hw,
986 u16 *phy_ctrl)
987{
988 struct e1000_mac_info *mac = &hw->mac;
989 u32 ctrl;
990
991 /* Turn off flow control when forcing speed/duplex */
992 hw->fc.type = e1000_fc_none;
993
994 /* Force speed/duplex on the mac */
995 ctrl = rd32(E1000_CTRL);
996 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
997 ctrl &= ~E1000_CTRL_SPD_SEL;
998
999 /* Disable Auto Speed Detection */
1000 ctrl &= ~E1000_CTRL_ASDE;
1001
1002 /* Disable autoneg on the phy */
1003 *phy_ctrl &= ~MII_CR_AUTO_NEG_EN;
1004
1005 /* Forcing Full or Half Duplex? */
1006 if (mac->forced_speed_duplex & E1000_ALL_HALF_DUPLEX) {
1007 ctrl &= ~E1000_CTRL_FD;
1008 *phy_ctrl &= ~MII_CR_FULL_DUPLEX;
Auke Kok652fff32008-06-27 11:00:18 -07001009 hw_dbg("Half Duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001010 } else {
1011 ctrl |= E1000_CTRL_FD;
1012 *phy_ctrl |= MII_CR_FULL_DUPLEX;
Auke Kok652fff32008-06-27 11:00:18 -07001013 hw_dbg("Full Duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001014 }
1015
1016 /* Forcing 10mb or 100mb? */
1017 if (mac->forced_speed_duplex & E1000_ALL_100_SPEED) {
1018 ctrl |= E1000_CTRL_SPD_100;
1019 *phy_ctrl |= MII_CR_SPEED_100;
1020 *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
Auke Kok652fff32008-06-27 11:00:18 -07001021 hw_dbg("Forcing 100mb\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001022 } else {
1023 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1024 *phy_ctrl |= MII_CR_SPEED_10;
1025 *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
Auke Kok652fff32008-06-27 11:00:18 -07001026 hw_dbg("Forcing 10mb\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001027 }
1028
1029 igb_config_collision_dist(hw);
1030
1031 wr32(E1000_CTRL, ctrl);
1032}
1033
1034/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001035 * igb_set_d3_lplu_state - Sets low power link up state for D3
Auke Kok9d5c8242008-01-24 02:22:38 -08001036 * @hw: pointer to the HW structure
1037 * @active: boolean used to enable/disable lplu
1038 *
1039 * Success returns 0, Failure returns 1
1040 *
1041 * The low power link up (lplu) state is set to the power management level D3
1042 * and SmartSpeed is disabled when active is true, else clear lplu for D3
1043 * and enable Smartspeed. LPLU and Smartspeed are mutually exclusive. LPLU
1044 * is used during Dx states where the power conservation is most important.
1045 * During driver activity, SmartSpeed should be enabled so performance is
1046 * maintained.
1047 **/
1048s32 igb_set_d3_lplu_state(struct e1000_hw *hw, bool active)
1049{
1050 struct e1000_phy_info *phy = &hw->phy;
1051 s32 ret_val;
1052 u16 data;
1053
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001054 ret_val = phy->ops.read_reg(hw, IGP02E1000_PHY_POWER_MGMT, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001055 if (ret_val)
1056 goto out;
1057
1058 if (!active) {
1059 data &= ~IGP02E1000_PM_D3_LPLU;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001060 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
Auke Kok9d5c8242008-01-24 02:22:38 -08001061 data);
1062 if (ret_val)
1063 goto out;
1064 /*
1065 * LPLU and SmartSpeed are mutually exclusive. LPLU is used
1066 * during Dx states where the power conservation is most
1067 * important. During driver activity we should enable
1068 * SmartSpeed, so performance is maintained.
1069 */
1070 if (phy->smart_speed == e1000_smart_speed_on) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001071 ret_val = phy->ops.read_reg(hw,
Auke Kok9d5c8242008-01-24 02:22:38 -08001072 IGP01E1000_PHY_PORT_CONFIG,
1073 &data);
1074 if (ret_val)
1075 goto out;
1076
1077 data |= IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001078 ret_val = phy->ops.write_reg(hw,
Auke Kok9d5c8242008-01-24 02:22:38 -08001079 IGP01E1000_PHY_PORT_CONFIG,
1080 data);
1081 if (ret_val)
1082 goto out;
1083 } else if (phy->smart_speed == e1000_smart_speed_off) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001084 ret_val = phy->ops.read_reg(hw,
Auke Kok9d5c8242008-01-24 02:22:38 -08001085 IGP01E1000_PHY_PORT_CONFIG,
1086 &data);
1087 if (ret_val)
1088 goto out;
1089
1090 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001091 ret_val = phy->ops.write_reg(hw,
Auke Kok9d5c8242008-01-24 02:22:38 -08001092 IGP01E1000_PHY_PORT_CONFIG,
1093 data);
1094 if (ret_val)
1095 goto out;
1096 }
1097 } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
1098 (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
1099 (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
1100 data |= IGP02E1000_PM_D3_LPLU;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001101 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
Auke Kok9d5c8242008-01-24 02:22:38 -08001102 data);
1103 if (ret_val)
1104 goto out;
1105
1106 /* When LPLU is enabled, we should disable SmartSpeed */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001107 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
Auke Kok9d5c8242008-01-24 02:22:38 -08001108 &data);
1109 if (ret_val)
1110 goto out;
1111
1112 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001113 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
Auke Kok9d5c8242008-01-24 02:22:38 -08001114 data);
1115 }
1116
1117out:
1118 return ret_val;
1119}
1120
1121/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001122 * igb_check_downshift - Checks whether a downshift in speed occured
Auke Kok9d5c8242008-01-24 02:22:38 -08001123 * @hw: pointer to the HW structure
1124 *
1125 * Success returns 0, Failure returns 1
1126 *
1127 * A downshift is detected by querying the PHY link health.
1128 **/
1129s32 igb_check_downshift(struct e1000_hw *hw)
1130{
1131 struct e1000_phy_info *phy = &hw->phy;
1132 s32 ret_val;
1133 u16 phy_data, offset, mask;
1134
1135 switch (phy->type) {
1136 case e1000_phy_m88:
1137 case e1000_phy_gg82563:
1138 offset = M88E1000_PHY_SPEC_STATUS;
1139 mask = M88E1000_PSSR_DOWNSHIFT;
1140 break;
1141 case e1000_phy_igp_2:
1142 case e1000_phy_igp:
1143 case e1000_phy_igp_3:
1144 offset = IGP01E1000_PHY_LINK_HEALTH;
1145 mask = IGP01E1000_PLHR_SS_DOWNGRADE;
1146 break;
1147 default:
1148 /* speed downshift not supported */
1149 phy->speed_downgraded = false;
1150 ret_val = 0;
1151 goto out;
1152 }
1153
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001154 ret_val = phy->ops.read_reg(hw, offset, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001155
1156 if (!ret_val)
1157 phy->speed_downgraded = (phy_data & mask) ? true : false;
1158
1159out:
1160 return ret_val;
1161}
1162
1163/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001164 * igb_check_polarity_m88 - Checks the polarity.
Auke Kok9d5c8242008-01-24 02:22:38 -08001165 * @hw: pointer to the HW structure
1166 *
1167 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1168 *
1169 * Polarity is determined based on the PHY specific status register.
1170 **/
1171static s32 igb_check_polarity_m88(struct e1000_hw *hw)
1172{
1173 struct e1000_phy_info *phy = &hw->phy;
1174 s32 ret_val;
1175 u16 data;
1176
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001177 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001178
1179 if (!ret_val)
1180 phy->cable_polarity = (data & M88E1000_PSSR_REV_POLARITY)
1181 ? e1000_rev_polarity_reversed
1182 : e1000_rev_polarity_normal;
1183
1184 return ret_val;
1185}
1186
1187/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001188 * igb_check_polarity_igp - Checks the polarity.
Auke Kok9d5c8242008-01-24 02:22:38 -08001189 * @hw: pointer to the HW structure
1190 *
1191 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1192 *
1193 * Polarity is determined based on the PHY port status register, and the
1194 * current speed (since there is no polarity at 100Mbps).
1195 **/
1196static s32 igb_check_polarity_igp(struct e1000_hw *hw)
1197{
1198 struct e1000_phy_info *phy = &hw->phy;
1199 s32 ret_val;
1200 u16 data, offset, mask;
1201
1202 /*
1203 * Polarity is determined based on the speed of
1204 * our connection.
1205 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001206 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_STATUS, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001207 if (ret_val)
1208 goto out;
1209
1210 if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
1211 IGP01E1000_PSSR_SPEED_1000MBPS) {
1212 offset = IGP01E1000_PHY_PCS_INIT_REG;
1213 mask = IGP01E1000_PHY_POLARITY_MASK;
1214 } else {
1215 /*
1216 * This really only applies to 10Mbps since
1217 * there is no polarity for 100Mbps (always 0).
1218 */
1219 offset = IGP01E1000_PHY_PORT_STATUS;
1220 mask = IGP01E1000_PSSR_POLARITY_REVERSED;
1221 }
1222
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001223 ret_val = phy->ops.read_reg(hw, offset, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001224
1225 if (!ret_val)
1226 phy->cable_polarity = (data & mask)
1227 ? e1000_rev_polarity_reversed
1228 : e1000_rev_polarity_normal;
1229
1230out:
1231 return ret_val;
1232}
1233
1234/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001235 * igb_wait_autoneg - Wait for auto-neg compeletion
Auke Kok9d5c8242008-01-24 02:22:38 -08001236 * @hw: pointer to the HW structure
1237 *
1238 * Waits for auto-negotiation to complete or for the auto-negotiation time
1239 * limit to expire, which ever happens first.
1240 **/
1241static s32 igb_wait_autoneg(struct e1000_hw *hw)
1242{
1243 s32 ret_val = 0;
1244 u16 i, phy_status;
1245
1246 /* Break after autoneg completes or PHY_AUTO_NEG_LIMIT expires. */
1247 for (i = PHY_AUTO_NEG_LIMIT; i > 0; i--) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001248 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
Auke Kok9d5c8242008-01-24 02:22:38 -08001249 if (ret_val)
1250 break;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001251 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
Auke Kok9d5c8242008-01-24 02:22:38 -08001252 if (ret_val)
1253 break;
1254 if (phy_status & MII_SR_AUTONEG_COMPLETE)
1255 break;
1256 msleep(100);
1257 }
1258
1259 /*
1260 * PHY_AUTO_NEG_TIME expiration doesn't guarantee auto-negotiation
1261 * has completed.
1262 */
1263 return ret_val;
1264}
1265
1266/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001267 * igb_phy_has_link - Polls PHY for link
Auke Kok9d5c8242008-01-24 02:22:38 -08001268 * @hw: pointer to the HW structure
1269 * @iterations: number of times to poll for link
1270 * @usec_interval: delay between polling attempts
1271 * @success: pointer to whether polling was successful or not
1272 *
1273 * Polls the PHY status register for link, 'iterations' number of times.
1274 **/
1275s32 igb_phy_has_link(struct e1000_hw *hw, u32 iterations,
1276 u32 usec_interval, bool *success)
1277{
1278 s32 ret_val = 0;
1279 u16 i, phy_status;
1280
1281 for (i = 0; i < iterations; i++) {
1282 /*
1283 * Some PHYs require the PHY_STATUS register to be read
1284 * twice due to the link bit being sticky. No harm doing
1285 * it across the board.
1286 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001287 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
Auke Kok9d5c8242008-01-24 02:22:38 -08001288 if (ret_val)
1289 break;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001290 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
Auke Kok9d5c8242008-01-24 02:22:38 -08001291 if (ret_val)
1292 break;
1293 if (phy_status & MII_SR_LINK_STATUS)
1294 break;
1295 if (usec_interval >= 1000)
1296 mdelay(usec_interval/1000);
1297 else
1298 udelay(usec_interval);
1299 }
1300
1301 *success = (i < iterations) ? true : false;
1302
1303 return ret_val;
1304}
1305
1306/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001307 * igb_get_cable_length_m88 - Determine cable length for m88 PHY
Auke Kok9d5c8242008-01-24 02:22:38 -08001308 * @hw: pointer to the HW structure
1309 *
1310 * Reads the PHY specific status register to retrieve the cable length
1311 * information. The cable length is determined by averaging the minimum and
1312 * maximum values to get the "average" cable length. The m88 PHY has four
1313 * possible cable length values, which are:
1314 * Register Value Cable Length
1315 * 0 < 50 meters
1316 * 1 50 - 80 meters
1317 * 2 80 - 110 meters
1318 * 3 110 - 140 meters
1319 * 4 > 140 meters
1320 **/
1321s32 igb_get_cable_length_m88(struct e1000_hw *hw)
1322{
1323 struct e1000_phy_info *phy = &hw->phy;
1324 s32 ret_val;
1325 u16 phy_data, index;
1326
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001327 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001328 if (ret_val)
1329 goto out;
1330
1331 index = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
1332 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
1333 phy->min_cable_length = e1000_m88_cable_length_table[index];
1334 phy->max_cable_length = e1000_m88_cable_length_table[index+1];
1335
1336 phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
1337
1338out:
1339 return ret_val;
1340}
1341
1342/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001343 * igb_get_cable_length_igp_2 - Determine cable length for igp2 PHY
Auke Kok9d5c8242008-01-24 02:22:38 -08001344 * @hw: pointer to the HW structure
1345 *
1346 * The automatic gain control (agc) normalizes the amplitude of the
1347 * received signal, adjusting for the attenuation produced by the
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001348 * cable. By reading the AGC registers, which represent the
1349 * combination of coarse and fine gain value, the value can be put
Auke Kok9d5c8242008-01-24 02:22:38 -08001350 * into a lookup table to obtain the approximate cable length
1351 * for each channel.
1352 **/
1353s32 igb_get_cable_length_igp_2(struct e1000_hw *hw)
1354{
1355 struct e1000_phy_info *phy = &hw->phy;
1356 s32 ret_val = 0;
1357 u16 phy_data, i, agc_value = 0;
1358 u16 cur_agc_index, max_agc_index = 0;
1359 u16 min_agc_index = IGP02E1000_CABLE_LENGTH_TABLE_SIZE - 1;
1360 u16 agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] =
1361 {IGP02E1000_PHY_AGC_A,
1362 IGP02E1000_PHY_AGC_B,
1363 IGP02E1000_PHY_AGC_C,
1364 IGP02E1000_PHY_AGC_D};
1365
1366 /* Read the AGC registers for all channels */
1367 for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001368 ret_val = phy->ops.read_reg(hw, agc_reg_array[i], &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001369 if (ret_val)
1370 goto out;
1371
1372 /*
1373 * Getting bits 15:9, which represent the combination of
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001374 * coarse and fine gain values. The result is a number
Auke Kok9d5c8242008-01-24 02:22:38 -08001375 * that can be put into the lookup table to obtain the
1376 * approximate cable length.
1377 */
1378 cur_agc_index = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
1379 IGP02E1000_AGC_LENGTH_MASK;
1380
1381 /* Array index bound check. */
1382 if ((cur_agc_index >= IGP02E1000_CABLE_LENGTH_TABLE_SIZE) ||
1383 (cur_agc_index == 0)) {
1384 ret_val = -E1000_ERR_PHY;
1385 goto out;
1386 }
1387
1388 /* Remove min & max AGC values from calculation. */
1389 if (e1000_igp_2_cable_length_table[min_agc_index] >
1390 e1000_igp_2_cable_length_table[cur_agc_index])
1391 min_agc_index = cur_agc_index;
1392 if (e1000_igp_2_cable_length_table[max_agc_index] <
1393 e1000_igp_2_cable_length_table[cur_agc_index])
1394 max_agc_index = cur_agc_index;
1395
1396 agc_value += e1000_igp_2_cable_length_table[cur_agc_index];
1397 }
1398
1399 agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] +
1400 e1000_igp_2_cable_length_table[max_agc_index]);
1401 agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
1402
1403 /* Calculate cable length with the error range of +/- 10 meters. */
1404 phy->min_cable_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
1405 (agc_value - IGP02E1000_AGC_RANGE) : 0;
1406 phy->max_cable_length = agc_value + IGP02E1000_AGC_RANGE;
1407
1408 phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
1409
1410out:
1411 return ret_val;
1412}
1413
1414/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001415 * igb_get_phy_info_m88 - Retrieve PHY information
Auke Kok9d5c8242008-01-24 02:22:38 -08001416 * @hw: pointer to the HW structure
1417 *
1418 * Valid for only copper links. Read the PHY status register (sticky read)
1419 * to verify that link is up. Read the PHY special control register to
1420 * determine the polarity and 10base-T extended distance. Read the PHY
1421 * special status register to determine MDI/MDIx and current speed. If
1422 * speed is 1000, then determine cable length, local and remote receiver.
1423 **/
1424s32 igb_get_phy_info_m88(struct e1000_hw *hw)
1425{
1426 struct e1000_phy_info *phy = &hw->phy;
1427 s32 ret_val;
1428 u16 phy_data;
1429 bool link;
1430
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001431 if (phy->media_type != e1000_media_type_copper) {
Auke Kok652fff32008-06-27 11:00:18 -07001432 hw_dbg("Phy info is only valid for copper media\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001433 ret_val = -E1000_ERR_CONFIG;
1434 goto out;
1435 }
1436
1437 ret_val = igb_phy_has_link(hw, 1, 0, &link);
1438 if (ret_val)
1439 goto out;
1440
1441 if (!link) {
Auke Kok652fff32008-06-27 11:00:18 -07001442 hw_dbg("Phy info is only valid if link is up\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001443 ret_val = -E1000_ERR_CONFIG;
1444 goto out;
1445 }
1446
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001447 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001448 if (ret_val)
1449 goto out;
1450
1451 phy->polarity_correction = (phy_data & M88E1000_PSCR_POLARITY_REVERSAL)
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001452 ? true : false;
Auke Kok9d5c8242008-01-24 02:22:38 -08001453
1454 ret_val = igb_check_polarity_m88(hw);
1455 if (ret_val)
1456 goto out;
1457
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001458 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001459 if (ret_val)
1460 goto out;
1461
1462 phy->is_mdix = (phy_data & M88E1000_PSSR_MDIX) ? true : false;
1463
1464 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001465 ret_val = phy->ops.get_cable_length(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001466 if (ret_val)
1467 goto out;
1468
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001469 ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001470 if (ret_val)
1471 goto out;
1472
1473 phy->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS)
1474 ? e1000_1000t_rx_status_ok
1475 : e1000_1000t_rx_status_not_ok;
1476
1477 phy->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS)
1478 ? e1000_1000t_rx_status_ok
1479 : e1000_1000t_rx_status_not_ok;
1480 } else {
1481 /* Set values to "undefined" */
1482 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
1483 phy->local_rx = e1000_1000t_rx_status_undefined;
1484 phy->remote_rx = e1000_1000t_rx_status_undefined;
1485 }
1486
1487out:
1488 return ret_val;
1489}
1490
1491/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001492 * igb_get_phy_info_igp - Retrieve igp PHY information
Auke Kok9d5c8242008-01-24 02:22:38 -08001493 * @hw: pointer to the HW structure
1494 *
1495 * Read PHY status to determine if link is up. If link is up, then
1496 * set/determine 10base-T extended distance and polarity correction. Read
1497 * PHY port status to determine MDI/MDIx and speed. Based on the speed,
1498 * determine on the cable length, local and remote receiver.
1499 **/
1500s32 igb_get_phy_info_igp(struct e1000_hw *hw)
1501{
1502 struct e1000_phy_info *phy = &hw->phy;
1503 s32 ret_val;
1504 u16 data;
1505 bool link;
1506
1507 ret_val = igb_phy_has_link(hw, 1, 0, &link);
1508 if (ret_val)
1509 goto out;
1510
1511 if (!link) {
Auke Kok652fff32008-06-27 11:00:18 -07001512 hw_dbg("Phy info is only valid if link is up\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001513 ret_val = -E1000_ERR_CONFIG;
1514 goto out;
1515 }
1516
1517 phy->polarity_correction = true;
1518
1519 ret_val = igb_check_polarity_igp(hw);
1520 if (ret_val)
1521 goto out;
1522
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001523 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_STATUS, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001524 if (ret_val)
1525 goto out;
1526
1527 phy->is_mdix = (data & IGP01E1000_PSSR_MDIX) ? true : false;
1528
1529 if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
1530 IGP01E1000_PSSR_SPEED_1000MBPS) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001531 ret_val = phy->ops.get_cable_length(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001532 if (ret_val)
1533 goto out;
1534
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001535 ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001536 if (ret_val)
1537 goto out;
1538
1539 phy->local_rx = (data & SR_1000T_LOCAL_RX_STATUS)
1540 ? e1000_1000t_rx_status_ok
1541 : e1000_1000t_rx_status_not_ok;
1542
1543 phy->remote_rx = (data & SR_1000T_REMOTE_RX_STATUS)
1544 ? e1000_1000t_rx_status_ok
1545 : e1000_1000t_rx_status_not_ok;
1546 } else {
1547 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
1548 phy->local_rx = e1000_1000t_rx_status_undefined;
1549 phy->remote_rx = e1000_1000t_rx_status_undefined;
1550 }
1551
1552out:
1553 return ret_val;
1554}
1555
1556/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001557 * igb_phy_sw_reset - PHY software reset
Auke Kok9d5c8242008-01-24 02:22:38 -08001558 * @hw: pointer to the HW structure
1559 *
1560 * Does a software reset of the PHY by reading the PHY control register and
1561 * setting/write the control register reset bit to the PHY.
1562 **/
1563s32 igb_phy_sw_reset(struct e1000_hw *hw)
1564{
1565 s32 ret_val;
1566 u16 phy_ctrl;
1567
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001568 ret_val = hw->phy.ops.read_reg(hw, PHY_CONTROL, &phy_ctrl);
Auke Kok9d5c8242008-01-24 02:22:38 -08001569 if (ret_val)
1570 goto out;
1571
1572 phy_ctrl |= MII_CR_RESET;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001573 ret_val = hw->phy.ops.write_reg(hw, PHY_CONTROL, phy_ctrl);
Auke Kok9d5c8242008-01-24 02:22:38 -08001574 if (ret_val)
1575 goto out;
1576
1577 udelay(1);
1578
1579out:
1580 return ret_val;
1581}
1582
1583/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001584 * igb_phy_hw_reset - PHY hardware reset
Auke Kok9d5c8242008-01-24 02:22:38 -08001585 * @hw: pointer to the HW structure
1586 *
1587 * Verify the reset block is not blocking us from resetting. Acquire
1588 * semaphore (if necessary) and read/set/write the device control reset
1589 * bit in the PHY. Wait the appropriate delay time for the device to
1590 * reset and relase the semaphore (if necessary).
1591 **/
1592s32 igb_phy_hw_reset(struct e1000_hw *hw)
1593{
1594 struct e1000_phy_info *phy = &hw->phy;
1595 s32 ret_val;
1596 u32 ctrl;
1597
1598 ret_val = igb_check_reset_block(hw);
1599 if (ret_val) {
1600 ret_val = 0;
1601 goto out;
1602 }
1603
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001604 ret_val = phy->ops.acquire(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001605 if (ret_val)
1606 goto out;
1607
1608 ctrl = rd32(E1000_CTRL);
1609 wr32(E1000_CTRL, ctrl | E1000_CTRL_PHY_RST);
1610 wrfl();
1611
1612 udelay(phy->reset_delay_us);
1613
1614 wr32(E1000_CTRL, ctrl);
1615 wrfl();
1616
1617 udelay(150);
1618
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001619 phy->ops.release(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001620
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001621 ret_val = phy->ops.get_cfg_done(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001622
1623out:
1624 return ret_val;
1625}
1626
Auke Kok9d5c8242008-01-24 02:22:38 -08001627/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001628 * igb_phy_init_script_igp3 - Inits the IGP3 PHY
Auke Kok9d5c8242008-01-24 02:22:38 -08001629 * @hw: pointer to the HW structure
1630 *
1631 * Initializes a Intel Gigabit PHY3 when an EEPROM is not present.
1632 **/
1633s32 igb_phy_init_script_igp3(struct e1000_hw *hw)
1634{
Auke Kok652fff32008-06-27 11:00:18 -07001635 hw_dbg("Running IGP 3 PHY init script\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001636
1637 /* PHY init IGP 3 */
1638 /* Enable rise/fall, 10-mode work in class-A */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001639 hw->phy.ops.write_reg(hw, 0x2F5B, 0x9018);
Auke Kok9d5c8242008-01-24 02:22:38 -08001640 /* Remove all caps from Replica path filter */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001641 hw->phy.ops.write_reg(hw, 0x2F52, 0x0000);
Auke Kok9d5c8242008-01-24 02:22:38 -08001642 /* Bias trimming for ADC, AFE and Driver (Default) */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001643 hw->phy.ops.write_reg(hw, 0x2FB1, 0x8B24);
Auke Kok9d5c8242008-01-24 02:22:38 -08001644 /* Increase Hybrid poly bias */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001645 hw->phy.ops.write_reg(hw, 0x2FB2, 0xF8F0);
Auke Kok9d5c8242008-01-24 02:22:38 -08001646 /* Add 4% to TX amplitude in Giga mode */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001647 hw->phy.ops.write_reg(hw, 0x2010, 0x10B0);
Auke Kok9d5c8242008-01-24 02:22:38 -08001648 /* Disable trimming (TTT) */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001649 hw->phy.ops.write_reg(hw, 0x2011, 0x0000);
Auke Kok9d5c8242008-01-24 02:22:38 -08001650 /* Poly DC correction to 94.6% + 2% for all channels */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001651 hw->phy.ops.write_reg(hw, 0x20DD, 0x249A);
Auke Kok9d5c8242008-01-24 02:22:38 -08001652 /* ABS DC correction to 95.9% */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001653 hw->phy.ops.write_reg(hw, 0x20DE, 0x00D3);
Auke Kok9d5c8242008-01-24 02:22:38 -08001654 /* BG temp curve trim */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001655 hw->phy.ops.write_reg(hw, 0x28B4, 0x04CE);
Auke Kok9d5c8242008-01-24 02:22:38 -08001656 /* Increasing ADC OPAMP stage 1 currents to max */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001657 hw->phy.ops.write_reg(hw, 0x2F70, 0x29E4);
Auke Kok9d5c8242008-01-24 02:22:38 -08001658 /* Force 1000 ( required for enabling PHY regs configuration) */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001659 hw->phy.ops.write_reg(hw, 0x0000, 0x0140);
Auke Kok9d5c8242008-01-24 02:22:38 -08001660 /* Set upd_freq to 6 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001661 hw->phy.ops.write_reg(hw, 0x1F30, 0x1606);
Auke Kok9d5c8242008-01-24 02:22:38 -08001662 /* Disable NPDFE */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001663 hw->phy.ops.write_reg(hw, 0x1F31, 0xB814);
Auke Kok9d5c8242008-01-24 02:22:38 -08001664 /* Disable adaptive fixed FFE (Default) */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001665 hw->phy.ops.write_reg(hw, 0x1F35, 0x002A);
Auke Kok9d5c8242008-01-24 02:22:38 -08001666 /* Enable FFE hysteresis */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001667 hw->phy.ops.write_reg(hw, 0x1F3E, 0x0067);
Auke Kok9d5c8242008-01-24 02:22:38 -08001668 /* Fixed FFE for short cable lengths */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001669 hw->phy.ops.write_reg(hw, 0x1F54, 0x0065);
Auke Kok9d5c8242008-01-24 02:22:38 -08001670 /* Fixed FFE for medium cable lengths */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001671 hw->phy.ops.write_reg(hw, 0x1F55, 0x002A);
Auke Kok9d5c8242008-01-24 02:22:38 -08001672 /* Fixed FFE for long cable lengths */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001673 hw->phy.ops.write_reg(hw, 0x1F56, 0x002A);
Auke Kok9d5c8242008-01-24 02:22:38 -08001674 /* Enable Adaptive Clip Threshold */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001675 hw->phy.ops.write_reg(hw, 0x1F72, 0x3FB0);
Auke Kok9d5c8242008-01-24 02:22:38 -08001676 /* AHT reset limit to 1 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001677 hw->phy.ops.write_reg(hw, 0x1F76, 0xC0FF);
Auke Kok9d5c8242008-01-24 02:22:38 -08001678 /* Set AHT master delay to 127 msec */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001679 hw->phy.ops.write_reg(hw, 0x1F77, 0x1DEC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001680 /* Set scan bits for AHT */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001681 hw->phy.ops.write_reg(hw, 0x1F78, 0xF9EF);
Auke Kok9d5c8242008-01-24 02:22:38 -08001682 /* Set AHT Preset bits */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001683 hw->phy.ops.write_reg(hw, 0x1F79, 0x0210);
Auke Kok9d5c8242008-01-24 02:22:38 -08001684 /* Change integ_factor of channel A to 3 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001685 hw->phy.ops.write_reg(hw, 0x1895, 0x0003);
Auke Kok9d5c8242008-01-24 02:22:38 -08001686 /* Change prop_factor of channels BCD to 8 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001687 hw->phy.ops.write_reg(hw, 0x1796, 0x0008);
Auke Kok9d5c8242008-01-24 02:22:38 -08001688 /* Change cg_icount + enable integbp for channels BCD */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001689 hw->phy.ops.write_reg(hw, 0x1798, 0xD008);
Auke Kok9d5c8242008-01-24 02:22:38 -08001690 /*
1691 * Change cg_icount + enable integbp + change prop_factor_master
1692 * to 8 for channel A
1693 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001694 hw->phy.ops.write_reg(hw, 0x1898, 0xD918);
Auke Kok9d5c8242008-01-24 02:22:38 -08001695 /* Disable AHT in Slave mode on channel A */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001696 hw->phy.ops.write_reg(hw, 0x187A, 0x0800);
Auke Kok9d5c8242008-01-24 02:22:38 -08001697 /*
1698 * Enable LPLU and disable AN to 1000 in non-D0a states,
1699 * Enable SPD+B2B
1700 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001701 hw->phy.ops.write_reg(hw, 0x0019, 0x008D);
Auke Kok9d5c8242008-01-24 02:22:38 -08001702 /* Enable restart AN on an1000_dis change */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001703 hw->phy.ops.write_reg(hw, 0x001B, 0x2080);
Auke Kok9d5c8242008-01-24 02:22:38 -08001704 /* Enable wh_fifo read clock in 10/100 modes */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001705 hw->phy.ops.write_reg(hw, 0x0014, 0x0045);
Auke Kok9d5c8242008-01-24 02:22:38 -08001706 /* Restart AN, Speed selection is 1000 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001707 hw->phy.ops.write_reg(hw, 0x0000, 0x1340);
Auke Kok9d5c8242008-01-24 02:22:38 -08001708
1709 return 0;
1710}
1711