blob: d4c928ccb2946c53b58854dadbf706c3248b0b29 [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/**
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000242 * igb_read_phy_reg_i2c - Read PHY register using i2c
243 * @hw: pointer to the HW structure
244 * @offset: register offset to be read
245 * @data: pointer to the read data
246 *
247 * Reads the PHY register at offset using the i2c interface and stores the
248 * retrieved information in data.
249 **/
250s32 igb_read_phy_reg_i2c(struct e1000_hw *hw, u32 offset, u16 *data)
251{
252 struct e1000_phy_info *phy = &hw->phy;
253 u32 i, i2ccmd = 0;
254
255
256 /*
257 * Set up Op-code, Phy Address, and register address in the I2CCMD
258 * register. The MAC will take care of interfacing with the
259 * PHY to retrieve the desired data.
260 */
261 i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) |
262 (phy->addr << E1000_I2CCMD_PHY_ADDR_SHIFT) |
263 (E1000_I2CCMD_OPCODE_READ));
264
265 wr32(E1000_I2CCMD, i2ccmd);
266
267 /* Poll the ready bit to see if the I2C read completed */
268 for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) {
269 udelay(50);
270 i2ccmd = rd32(E1000_I2CCMD);
271 if (i2ccmd & E1000_I2CCMD_READY)
272 break;
273 }
274 if (!(i2ccmd & E1000_I2CCMD_READY)) {
275 hw_dbg("I2CCMD Read did not complete\n");
276 return -E1000_ERR_PHY;
277 }
278 if (i2ccmd & E1000_I2CCMD_ERROR) {
279 hw_dbg("I2CCMD Error bit set\n");
280 return -E1000_ERR_PHY;
281 }
282
283 /* Need to byte-swap the 16-bit value. */
284 *data = ((i2ccmd >> 8) & 0x00FF) | ((i2ccmd << 8) & 0xFF00);
285
286 return 0;
287}
288
289/**
290 * igb_write_phy_reg_i2c - Write PHY register using i2c
291 * @hw: pointer to the HW structure
292 * @offset: register offset to write to
293 * @data: data to write at register offset
294 *
295 * Writes the data to PHY register at the offset using the i2c interface.
296 **/
297s32 igb_write_phy_reg_i2c(struct e1000_hw *hw, u32 offset, u16 data)
298{
299 struct e1000_phy_info *phy = &hw->phy;
300 u32 i, i2ccmd = 0;
301 u16 phy_data_swapped;
302
303
304 /* Swap the data bytes for the I2C interface */
305 phy_data_swapped = ((data >> 8) & 0x00FF) | ((data << 8) & 0xFF00);
306
307 /*
308 * Set up Op-code, Phy Address, and register address in the I2CCMD
309 * register. The MAC will take care of interfacing with the
310 * PHY to retrieve the desired data.
311 */
312 i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) |
313 (phy->addr << E1000_I2CCMD_PHY_ADDR_SHIFT) |
314 E1000_I2CCMD_OPCODE_WRITE |
315 phy_data_swapped);
316
317 wr32(E1000_I2CCMD, i2ccmd);
318
319 /* Poll the ready bit to see if the I2C read completed */
320 for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) {
321 udelay(50);
322 i2ccmd = rd32(E1000_I2CCMD);
323 if (i2ccmd & E1000_I2CCMD_READY)
324 break;
325 }
326 if (!(i2ccmd & E1000_I2CCMD_READY)) {
327 hw_dbg("I2CCMD Write did not complete\n");
328 return -E1000_ERR_PHY;
329 }
330 if (i2ccmd & E1000_I2CCMD_ERROR) {
331 hw_dbg("I2CCMD Error bit set\n");
332 return -E1000_ERR_PHY;
333 }
334
335 return 0;
336}
337
338/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700339 * igb_read_phy_reg_igp - Read igp PHY register
Auke Kok9d5c8242008-01-24 02:22:38 -0800340 * @hw: pointer to the HW structure
341 * @offset: register offset to be read
342 * @data: pointer to the read data
343 *
344 * Acquires semaphore, if necessary, then reads the PHY register at offset
345 * and storing the retrieved information in data. Release any acquired
346 * semaphores before exiting.
347 **/
348s32 igb_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data)
349{
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000350 s32 ret_val = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -0800351
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000352 if (!(hw->phy.ops.acquire))
353 goto out;
354
355 ret_val = hw->phy.ops.acquire(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800356 if (ret_val)
357 goto out;
358
359 if (offset > MAX_PHY_MULTI_PAGE_REG) {
360 ret_val = igb_write_phy_reg_mdic(hw,
361 IGP01E1000_PHY_PAGE_SELECT,
362 (u16)offset);
363 if (ret_val) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000364 hw->phy.ops.release(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800365 goto out;
366 }
367 }
368
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000369 ret_val = igb_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
370 data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800371
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000372 hw->phy.ops.release(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800373
374out:
375 return ret_val;
376}
377
378/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700379 * igb_write_phy_reg_igp - Write igp PHY register
Auke Kok9d5c8242008-01-24 02:22:38 -0800380 * @hw: pointer to the HW structure
381 * @offset: register offset to write to
382 * @data: data to write at register offset
383 *
384 * Acquires semaphore, if necessary, then writes the data to PHY register
385 * at the offset. Release any acquired semaphores before exiting.
386 **/
387s32 igb_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data)
388{
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000389 s32 ret_val = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -0800390
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000391 if (!(hw->phy.ops.acquire))
392 goto out;
393
394 ret_val = hw->phy.ops.acquire(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800395 if (ret_val)
396 goto out;
397
398 if (offset > MAX_PHY_MULTI_PAGE_REG) {
399 ret_val = igb_write_phy_reg_mdic(hw,
400 IGP01E1000_PHY_PAGE_SELECT,
401 (u16)offset);
402 if (ret_val) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000403 hw->phy.ops.release(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800404 goto out;
405 }
406 }
407
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000408 ret_val = igb_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
Auke Kok9d5c8242008-01-24 02:22:38 -0800409 data);
410
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000411 hw->phy.ops.release(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800412
413out:
414 return ret_val;
415}
416
417/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700418 * igb_copper_link_setup_m88 - Setup m88 PHY's for copper link
Auke Kok9d5c8242008-01-24 02:22:38 -0800419 * @hw: pointer to the HW structure
420 *
421 * Sets up MDI/MDI-X and polarity for m88 PHY's. If necessary, transmit clock
422 * and downshift values are set also.
423 **/
424s32 igb_copper_link_setup_m88(struct e1000_hw *hw)
425{
426 struct e1000_phy_info *phy = &hw->phy;
427 s32 ret_val;
428 u16 phy_data;
429
430 if (phy->reset_disable) {
431 ret_val = 0;
432 goto out;
433 }
434
435 /* Enable CRS on TX. This must be set for half-duplex operation. */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000436 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800437 if (ret_val)
438 goto out;
439
440 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
441
442 /*
443 * Options:
444 * MDI/MDI-X = 0 (default)
445 * 0 - Auto for all speeds
446 * 1 - MDI mode
447 * 2 - MDI-X mode
448 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
449 */
450 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
451
452 switch (phy->mdix) {
453 case 1:
454 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
455 break;
456 case 2:
457 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
458 break;
459 case 3:
460 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
461 break;
462 case 0:
463 default:
464 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
465 break;
466 }
467
468 /*
469 * Options:
470 * disable_polarity_correction = 0 (default)
471 * Automatic Correction for Reversed Cable Polarity
472 * 0 - Disabled
473 * 1 - Enabled
474 */
475 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
476 if (phy->disable_polarity_correction == 1)
477 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
478
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000479 ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800480 if (ret_val)
481 goto out;
482
483 if (phy->revision < E1000_REVISION_4) {
484 /*
485 * Force TX_CLK in the Extended PHY Specific Control Register
486 * to 25MHz clock.
487 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000488 ret_val = phy->ops.read_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
Auke Kok9d5c8242008-01-24 02:22:38 -0800489 &phy_data);
490 if (ret_val)
491 goto out;
492
493 phy_data |= M88E1000_EPSCR_TX_CLK_25;
494
495 if ((phy->revision == E1000_REVISION_2) &&
496 (phy->id == M88E1111_I_PHY_ID)) {
497 /* 82573L PHY - set the downshift counter to 5x. */
498 phy_data &= ~M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK;
499 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
500 } else {
501 /* Configure Master and Slave downshift values */
502 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
503 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
504 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
505 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
506 }
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000507 ret_val = phy->ops.write_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
Auke Kok9d5c8242008-01-24 02:22:38 -0800508 phy_data);
509 if (ret_val)
510 goto out;
511 }
512
513 /* Commit the changes. */
514 ret_val = igb_phy_sw_reset(hw);
515 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700516 hw_dbg("Error committing the PHY changes\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800517 goto out;
518 }
519
520out:
521 return ret_val;
522}
523
524/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700525 * igb_copper_link_setup_igp - Setup igp PHY's for copper link
Auke Kok9d5c8242008-01-24 02:22:38 -0800526 * @hw: pointer to the HW structure
527 *
528 * Sets up LPLU, MDI/MDI-X, polarity, Smartspeed and Master/Slave config for
529 * igp PHY's.
530 **/
531s32 igb_copper_link_setup_igp(struct e1000_hw *hw)
532{
533 struct e1000_phy_info *phy = &hw->phy;
534 s32 ret_val;
535 u16 data;
536
537 if (phy->reset_disable) {
538 ret_val = 0;
539 goto out;
540 }
541
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000542 ret_val = phy->ops.reset(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800543 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700544 hw_dbg("Error resetting the PHY.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800545 goto out;
546 }
547
Alexander Duycka6a60562009-03-31 20:38:38 +0000548 /*
549 * Wait 100ms for MAC to configure PHY from NVM settings, to avoid
550 * timeout issues when LFS is enabled.
551 */
552 msleep(100);
Auke Kok9d5c8242008-01-24 02:22:38 -0800553
554 /*
555 * The NVM settings will configure LPLU in D3 for
556 * non-IGP1 PHYs.
557 */
558 if (phy->type == e1000_phy_igp) {
559 /* disable lplu d3 during driver init */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000560 if (phy->ops.set_d3_lplu_state)
561 ret_val = phy->ops.set_d3_lplu_state(hw, false);
Auke Kok9d5c8242008-01-24 02:22:38 -0800562 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700563 hw_dbg("Error Disabling LPLU D3\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800564 goto out;
565 }
566 }
567
568 /* disable lplu d0 during driver init */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000569 ret_val = phy->ops.set_d0_lplu_state(hw, false);
Auke Kok9d5c8242008-01-24 02:22:38 -0800570 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700571 hw_dbg("Error Disabling LPLU D0\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800572 goto out;
573 }
574 /* Configure mdi-mdix settings */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000575 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CTRL, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800576 if (ret_val)
577 goto out;
578
579 data &= ~IGP01E1000_PSCR_AUTO_MDIX;
580
581 switch (phy->mdix) {
582 case 1:
583 data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
584 break;
585 case 2:
586 data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
587 break;
588 case 0:
589 default:
590 data |= IGP01E1000_PSCR_AUTO_MDIX;
591 break;
592 }
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000593 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CTRL, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800594 if (ret_val)
595 goto out;
596
597 /* set auto-master slave resolution settings */
598 if (hw->mac.autoneg) {
599 /*
600 * when autonegotiation advertisement is only 1000Mbps then we
601 * should disable SmartSpeed and enable Auto MasterSlave
602 * resolution as hardware default.
603 */
604 if (phy->autoneg_advertised == ADVERTISE_1000_FULL) {
605 /* Disable SmartSpeed */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000606 ret_val = phy->ops.read_reg(hw,
607 IGP01E1000_PHY_PORT_CONFIG,
608 &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800609 if (ret_val)
610 goto out;
611
612 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000613 ret_val = phy->ops.write_reg(hw,
Auke Kok9d5c8242008-01-24 02:22:38 -0800614 IGP01E1000_PHY_PORT_CONFIG,
615 data);
616 if (ret_val)
617 goto out;
618
619 /* Set auto Master/Slave resolution process */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000620 ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800621 if (ret_val)
622 goto out;
623
624 data &= ~CR_1000T_MS_ENABLE;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000625 ret_val = phy->ops.write_reg(hw, PHY_1000T_CTRL, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800626 if (ret_val)
627 goto out;
628 }
629
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000630 ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800631 if (ret_val)
632 goto out;
633
634 /* load defaults for future use */
635 phy->original_ms_type = (data & CR_1000T_MS_ENABLE) ?
636 ((data & CR_1000T_MS_VALUE) ?
637 e1000_ms_force_master :
638 e1000_ms_force_slave) :
639 e1000_ms_auto;
640
641 switch (phy->ms_type) {
642 case e1000_ms_force_master:
643 data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
644 break;
645 case e1000_ms_force_slave:
646 data |= CR_1000T_MS_ENABLE;
647 data &= ~(CR_1000T_MS_VALUE);
648 break;
649 case e1000_ms_auto:
650 data &= ~CR_1000T_MS_ENABLE;
651 default:
652 break;
653 }
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000654 ret_val = phy->ops.write_reg(hw, PHY_1000T_CTRL, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800655 if (ret_val)
656 goto out;
657 }
658
659out:
660 return ret_val;
661}
662
663/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700664 * igb_copper_link_autoneg - Setup/Enable autoneg for copper link
Auke Kok9d5c8242008-01-24 02:22:38 -0800665 * @hw: pointer to the HW structure
666 *
667 * Performs initial bounds checking on autoneg advertisement parameter, then
668 * configure to advertise the full capability. Setup the PHY to autoneg
669 * and restart the negotiation process between the link partner. If
670 * autoneg_wait_to_complete, then wait for autoneg to complete before exiting.
671 **/
672s32 igb_copper_link_autoneg(struct e1000_hw *hw)
673{
674 struct e1000_phy_info *phy = &hw->phy;
675 s32 ret_val;
676 u16 phy_ctrl;
677
678 /*
679 * Perform some bounds checking on the autoneg advertisement
680 * parameter.
681 */
682 phy->autoneg_advertised &= phy->autoneg_mask;
683
684 /*
685 * If autoneg_advertised is zero, we assume it was not defaulted
686 * by the calling code so we set to advertise full capability.
687 */
688 if (phy->autoneg_advertised == 0)
689 phy->autoneg_advertised = phy->autoneg_mask;
690
Auke Kok652fff32008-06-27 11:00:18 -0700691 hw_dbg("Reconfiguring auto-neg advertisement params\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800692 ret_val = igb_phy_setup_autoneg(hw);
693 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700694 hw_dbg("Error Setting up Auto-Negotiation\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800695 goto out;
696 }
Auke Kok652fff32008-06-27 11:00:18 -0700697 hw_dbg("Restarting Auto-Neg\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800698
699 /*
700 * Restart auto-negotiation by setting the Auto Neg Enable bit and
701 * the Auto Neg Restart bit in the PHY control register.
702 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000703 ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_ctrl);
Auke Kok9d5c8242008-01-24 02:22:38 -0800704 if (ret_val)
705 goto out;
706
707 phy_ctrl |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000708 ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_ctrl);
Auke Kok9d5c8242008-01-24 02:22:38 -0800709 if (ret_val)
710 goto out;
711
712 /*
713 * Does the user want to wait for Auto-Neg to complete here, or
714 * check at a later time (for example, callback routine).
715 */
716 if (phy->autoneg_wait_to_complete) {
717 ret_val = igb_wait_autoneg(hw);
718 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700719 hw_dbg("Error while waiting for "
720 "autoneg to complete\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800721 goto out;
722 }
723 }
724
725 hw->mac.get_link_status = true;
726
727out:
728 return ret_val;
729}
730
731/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700732 * igb_phy_setup_autoneg - Configure PHY for auto-negotiation
Auke Kok9d5c8242008-01-24 02:22:38 -0800733 * @hw: pointer to the HW structure
734 *
735 * Reads the MII auto-neg advertisement register and/or the 1000T control
736 * register and if the PHY is already setup for auto-negotiation, then
737 * return successful. Otherwise, setup advertisement and flow control to
738 * the appropriate values for the wanted auto-negotiation.
739 **/
740static s32 igb_phy_setup_autoneg(struct e1000_hw *hw)
741{
742 struct e1000_phy_info *phy = &hw->phy;
743 s32 ret_val;
744 u16 mii_autoneg_adv_reg;
745 u16 mii_1000t_ctrl_reg = 0;
746
747 phy->autoneg_advertised &= phy->autoneg_mask;
748
749 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000750 ret_val = phy->ops.read_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
Auke Kok9d5c8242008-01-24 02:22:38 -0800751 if (ret_val)
752 goto out;
753
754 if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
755 /* Read the MII 1000Base-T Control Register (Address 9). */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000756 ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL,
Auke Kok9d5c8242008-01-24 02:22:38 -0800757 &mii_1000t_ctrl_reg);
758 if (ret_val)
759 goto out;
760 }
761
762 /*
763 * Need to parse both autoneg_advertised and fc and set up
764 * the appropriate PHY registers. First we will parse for
765 * autoneg_advertised software override. Since we can advertise
766 * a plethora of combinations, we need to check each bit
767 * individually.
768 */
769
770 /*
771 * First we clear all the 10/100 mb speed bits in the Auto-Neg
772 * Advertisement Register (Address 4) and the 1000 mb speed bits in
773 * the 1000Base-T Control Register (Address 9).
774 */
775 mii_autoneg_adv_reg &= ~(NWAY_AR_100TX_FD_CAPS |
776 NWAY_AR_100TX_HD_CAPS |
777 NWAY_AR_10T_FD_CAPS |
778 NWAY_AR_10T_HD_CAPS);
779 mii_1000t_ctrl_reg &= ~(CR_1000T_HD_CAPS | CR_1000T_FD_CAPS);
780
Auke Kok652fff32008-06-27 11:00:18 -0700781 hw_dbg("autoneg_advertised %x\n", phy->autoneg_advertised);
Auke Kok9d5c8242008-01-24 02:22:38 -0800782
783 /* Do we want to advertise 10 Mb Half Duplex? */
784 if (phy->autoneg_advertised & ADVERTISE_10_HALF) {
Auke Kok652fff32008-06-27 11:00:18 -0700785 hw_dbg("Advertise 10mb Half duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800786 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
787 }
788
789 /* Do we want to advertise 10 Mb Full Duplex? */
790 if (phy->autoneg_advertised & ADVERTISE_10_FULL) {
Auke Kok652fff32008-06-27 11:00:18 -0700791 hw_dbg("Advertise 10mb Full duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800792 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
793 }
794
795 /* Do we want to advertise 100 Mb Half Duplex? */
796 if (phy->autoneg_advertised & ADVERTISE_100_HALF) {
Auke Kok652fff32008-06-27 11:00:18 -0700797 hw_dbg("Advertise 100mb Half duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800798 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
799 }
800
801 /* Do we want to advertise 100 Mb Full Duplex? */
802 if (phy->autoneg_advertised & ADVERTISE_100_FULL) {
Auke Kok652fff32008-06-27 11:00:18 -0700803 hw_dbg("Advertise 100mb Full duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800804 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
805 }
806
807 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
808 if (phy->autoneg_advertised & ADVERTISE_1000_HALF)
Auke Kok652fff32008-06-27 11:00:18 -0700809 hw_dbg("Advertise 1000mb Half duplex request denied!\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800810
811 /* Do we want to advertise 1000 Mb Full Duplex? */
812 if (phy->autoneg_advertised & ADVERTISE_1000_FULL) {
Auke Kok652fff32008-06-27 11:00:18 -0700813 hw_dbg("Advertise 1000mb Full duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800814 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
815 }
816
817 /*
818 * Check for a software override of the flow control settings, and
819 * setup the PHY advertisement registers accordingly. If
820 * auto-negotiation is enabled, then software will have to set the
821 * "PAUSE" bits to the correct value in the Auto-Negotiation
822 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-
823 * negotiation.
824 *
825 * The possible values of the "fc" parameter are:
826 * 0: Flow control is completely disabled
827 * 1: Rx flow control is enabled (we can receive pause frames
828 * but not send pause frames).
829 * 2: Tx flow control is enabled (we can send pause frames
830 * but we do not support receiving pause frames).
831 * 3: Both Rx and TX flow control (symmetric) are enabled.
832 * other: No software override. The flow control configuration
833 * in the EEPROM is used.
834 */
Alexander Duyck0cce1192009-07-23 18:10:24 +0000835 switch (hw->fc.current_mode) {
Auke Kok9d5c8242008-01-24 02:22:38 -0800836 case e1000_fc_none:
837 /*
838 * Flow control (RX & TX) is completely disabled by a
839 * software over-ride.
840 */
841 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
842 break;
843 case e1000_fc_rx_pause:
844 /*
845 * RX Flow control is enabled, and TX Flow control is
846 * disabled, by a software over-ride.
847 *
848 * Since there really isn't a way to advertise that we are
849 * capable of RX Pause ONLY, we will advertise that we
850 * support both symmetric and asymmetric RX PAUSE. Later
851 * (in e1000_config_fc_after_link_up) we will disable the
852 * hw's ability to send PAUSE frames.
853 */
854 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
855 break;
856 case e1000_fc_tx_pause:
857 /*
858 * TX Flow control is enabled, and RX Flow control is
859 * disabled, by a software over-ride.
860 */
861 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
862 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
863 break;
864 case e1000_fc_full:
865 /*
866 * Flow control (both RX and TX) is enabled by a software
867 * over-ride.
868 */
869 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
870 break;
871 default:
Auke Kok652fff32008-06-27 11:00:18 -0700872 hw_dbg("Flow control param set incorrectly\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800873 ret_val = -E1000_ERR_CONFIG;
874 goto out;
875 }
876
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000877 ret_val = phy->ops.write_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
Auke Kok9d5c8242008-01-24 02:22:38 -0800878 if (ret_val)
879 goto out;
880
Auke Kok652fff32008-06-27 11:00:18 -0700881 hw_dbg("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
Auke Kok9d5c8242008-01-24 02:22:38 -0800882
883 if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000884 ret_val = phy->ops.write_reg(hw,
885 PHY_1000T_CTRL,
886 mii_1000t_ctrl_reg);
Auke Kok9d5c8242008-01-24 02:22:38 -0800887 if (ret_val)
888 goto out;
889 }
890
891out:
892 return ret_val;
893}
894
895/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700896 * igb_phy_force_speed_duplex_igp - Force speed/duplex for igp PHY
Auke Kok9d5c8242008-01-24 02:22:38 -0800897 * @hw: pointer to the HW structure
898 *
899 * Calls the PHY setup function to force speed and duplex. Clears the
900 * auto-crossover to force MDI manually. Waits for link and returns
901 * successful if link up is successful, else -E1000_ERR_PHY (-2).
902 **/
903s32 igb_phy_force_speed_duplex_igp(struct e1000_hw *hw)
904{
905 struct e1000_phy_info *phy = &hw->phy;
906 s32 ret_val;
907 u16 phy_data;
908 bool link;
909
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000910 ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800911 if (ret_val)
912 goto out;
913
914 igb_phy_force_speed_duplex_setup(hw, &phy_data);
915
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000916 ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800917 if (ret_val)
918 goto out;
919
920 /*
921 * Clear Auto-Crossover to force MDI manually. IGP requires MDI
922 * forced whenever speed and duplex are forced.
923 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000924 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800925 if (ret_val)
926 goto out;
927
928 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
929 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
930
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000931 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800932 if (ret_val)
933 goto out;
934
Auke Kok652fff32008-06-27 11:00:18 -0700935 hw_dbg("IGP PSCR: %X\n", phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800936
937 udelay(1);
938
939 if (phy->autoneg_wait_to_complete) {
Auke Kok652fff32008-06-27 11:00:18 -0700940 hw_dbg("Waiting for forced speed/duplex link on IGP phy.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800941
942 ret_val = igb_phy_has_link(hw,
943 PHY_FORCE_LIMIT,
944 100000,
945 &link);
946 if (ret_val)
947 goto out;
948
949 if (!link)
Auke Kok652fff32008-06-27 11:00:18 -0700950 hw_dbg("Link taking longer than expected.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800951
952 /* Try once more */
953 ret_val = igb_phy_has_link(hw,
954 PHY_FORCE_LIMIT,
955 100000,
956 &link);
957 if (ret_val)
958 goto out;
959 }
960
961out:
962 return ret_val;
963}
964
965/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700966 * igb_phy_force_speed_duplex_m88 - Force speed/duplex for m88 PHY
Auke Kok9d5c8242008-01-24 02:22:38 -0800967 * @hw: pointer to the HW structure
968 *
969 * Calls the PHY setup function to force speed and duplex. Clears the
970 * auto-crossover to force MDI manually. Resets the PHY to commit the
971 * changes. If time expires while waiting for link up, we reset the DSP.
972 * After reset, TX_CLK and CRS on TX must be set. Return successful upon
973 * successful completion, else return corresponding error code.
974 **/
975s32 igb_phy_force_speed_duplex_m88(struct e1000_hw *hw)
976{
977 struct e1000_phy_info *phy = &hw->phy;
978 s32 ret_val;
979 u16 phy_data;
980 bool link;
981
982 /*
983 * Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
984 * forced whenever speed and duplex are forced.
985 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000986 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800987 if (ret_val)
988 goto out;
989
990 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000991 ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800992 if (ret_val)
993 goto out;
994
Auke Kok652fff32008-06-27 11:00:18 -0700995 hw_dbg("M88E1000 PSCR: %X\n", phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800996
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000997 ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800998 if (ret_val)
999 goto out;
1000
1001 igb_phy_force_speed_duplex_setup(hw, &phy_data);
1002
1003 /* Reset the phy to commit changes. */
1004 phy_data |= MII_CR_RESET;
1005
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001006 ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001007 if (ret_val)
1008 goto out;
1009
1010 udelay(1);
1011
1012 if (phy->autoneg_wait_to_complete) {
Auke Kok652fff32008-06-27 11:00:18 -07001013 hw_dbg("Waiting for forced speed/duplex link on M88 phy.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001014
1015 ret_val = igb_phy_has_link(hw,
1016 PHY_FORCE_LIMIT,
1017 100000,
1018 &link);
1019 if (ret_val)
1020 goto out;
1021
1022 if (!link) {
1023 /*
1024 * We didn't get link.
1025 * Reset the DSP and cross our fingers.
1026 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001027 ret_val = phy->ops.write_reg(hw,
Auke Kok9d5c8242008-01-24 02:22:38 -08001028 M88E1000_PHY_PAGE_SELECT,
1029 0x001d);
1030 if (ret_val)
1031 goto out;
1032 ret_val = igb_phy_reset_dsp(hw);
1033 if (ret_val)
1034 goto out;
1035 }
1036
1037 /* Try once more */
1038 ret_val = igb_phy_has_link(hw, PHY_FORCE_LIMIT,
1039 100000, &link);
1040 if (ret_val)
1041 goto out;
1042 }
1043
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001044 ret_val = phy->ops.read_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001045 if (ret_val)
1046 goto out;
1047
1048 /*
1049 * Resetting the phy means we need to re-force TX_CLK in the
1050 * Extended PHY Specific Control Register to 25MHz clock from
1051 * the reset value of 2.5MHz.
1052 */
1053 phy_data |= M88E1000_EPSCR_TX_CLK_25;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001054 ret_val = phy->ops.write_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001055 if (ret_val)
1056 goto out;
1057
1058 /*
1059 * In addition, we must re-enable CRS on Tx for both half and full
1060 * duplex.
1061 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001062 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001063 if (ret_val)
1064 goto out;
1065
1066 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001067 ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001068
1069out:
1070 return ret_val;
1071}
1072
1073/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001074 * igb_phy_force_speed_duplex_setup - Configure forced PHY speed/duplex
Auke Kok9d5c8242008-01-24 02:22:38 -08001075 * @hw: pointer to the HW structure
1076 * @phy_ctrl: pointer to current value of PHY_CONTROL
1077 *
1078 * Forces speed and duplex on the PHY by doing the following: disable flow
1079 * control, force speed/duplex on the MAC, disable auto speed detection,
1080 * disable auto-negotiation, configure duplex, configure speed, configure
1081 * the collision distance, write configuration to CTRL register. The
1082 * caller must write to the PHY_CONTROL register for these settings to
1083 * take affect.
1084 **/
1085static void igb_phy_force_speed_duplex_setup(struct e1000_hw *hw,
1086 u16 *phy_ctrl)
1087{
1088 struct e1000_mac_info *mac = &hw->mac;
1089 u32 ctrl;
1090
1091 /* Turn off flow control when forcing speed/duplex */
Alexander Duyck0cce1192009-07-23 18:10:24 +00001092 hw->fc.current_mode = e1000_fc_none;
Auke Kok9d5c8242008-01-24 02:22:38 -08001093
1094 /* Force speed/duplex on the mac */
1095 ctrl = rd32(E1000_CTRL);
1096 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1097 ctrl &= ~E1000_CTRL_SPD_SEL;
1098
1099 /* Disable Auto Speed Detection */
1100 ctrl &= ~E1000_CTRL_ASDE;
1101
1102 /* Disable autoneg on the phy */
1103 *phy_ctrl &= ~MII_CR_AUTO_NEG_EN;
1104
1105 /* Forcing Full or Half Duplex? */
1106 if (mac->forced_speed_duplex & E1000_ALL_HALF_DUPLEX) {
1107 ctrl &= ~E1000_CTRL_FD;
1108 *phy_ctrl &= ~MII_CR_FULL_DUPLEX;
Auke Kok652fff32008-06-27 11:00:18 -07001109 hw_dbg("Half Duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001110 } else {
1111 ctrl |= E1000_CTRL_FD;
1112 *phy_ctrl |= MII_CR_FULL_DUPLEX;
Auke Kok652fff32008-06-27 11:00:18 -07001113 hw_dbg("Full Duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001114 }
1115
1116 /* Forcing 10mb or 100mb? */
1117 if (mac->forced_speed_duplex & E1000_ALL_100_SPEED) {
1118 ctrl |= E1000_CTRL_SPD_100;
1119 *phy_ctrl |= MII_CR_SPEED_100;
1120 *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
Auke Kok652fff32008-06-27 11:00:18 -07001121 hw_dbg("Forcing 100mb\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001122 } else {
1123 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1124 *phy_ctrl |= MII_CR_SPEED_10;
1125 *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
Auke Kok652fff32008-06-27 11:00:18 -07001126 hw_dbg("Forcing 10mb\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001127 }
1128
1129 igb_config_collision_dist(hw);
1130
1131 wr32(E1000_CTRL, ctrl);
1132}
1133
1134/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001135 * igb_set_d3_lplu_state - Sets low power link up state for D3
Auke Kok9d5c8242008-01-24 02:22:38 -08001136 * @hw: pointer to the HW structure
1137 * @active: boolean used to enable/disable lplu
1138 *
1139 * Success returns 0, Failure returns 1
1140 *
1141 * The low power link up (lplu) state is set to the power management level D3
1142 * and SmartSpeed is disabled when active is true, else clear lplu for D3
1143 * and enable Smartspeed. LPLU and Smartspeed are mutually exclusive. LPLU
1144 * is used during Dx states where the power conservation is most important.
1145 * During driver activity, SmartSpeed should be enabled so performance is
1146 * maintained.
1147 **/
1148s32 igb_set_d3_lplu_state(struct e1000_hw *hw, bool active)
1149{
1150 struct e1000_phy_info *phy = &hw->phy;
1151 s32 ret_val;
1152 u16 data;
1153
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001154 ret_val = phy->ops.read_reg(hw, IGP02E1000_PHY_POWER_MGMT, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001155 if (ret_val)
1156 goto out;
1157
1158 if (!active) {
1159 data &= ~IGP02E1000_PM_D3_LPLU;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001160 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
Auke Kok9d5c8242008-01-24 02:22:38 -08001161 data);
1162 if (ret_val)
1163 goto out;
1164 /*
1165 * LPLU and SmartSpeed are mutually exclusive. LPLU is used
1166 * during Dx states where the power conservation is most
1167 * important. During driver activity we should enable
1168 * SmartSpeed, so performance is maintained.
1169 */
1170 if (phy->smart_speed == e1000_smart_speed_on) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001171 ret_val = phy->ops.read_reg(hw,
Auke Kok9d5c8242008-01-24 02:22:38 -08001172 IGP01E1000_PHY_PORT_CONFIG,
1173 &data);
1174 if (ret_val)
1175 goto out;
1176
1177 data |= IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001178 ret_val = phy->ops.write_reg(hw,
Auke Kok9d5c8242008-01-24 02:22:38 -08001179 IGP01E1000_PHY_PORT_CONFIG,
1180 data);
1181 if (ret_val)
1182 goto out;
1183 } else if (phy->smart_speed == e1000_smart_speed_off) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001184 ret_val = phy->ops.read_reg(hw,
Auke Kok9d5c8242008-01-24 02:22:38 -08001185 IGP01E1000_PHY_PORT_CONFIG,
1186 &data);
1187 if (ret_val)
1188 goto out;
1189
1190 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001191 ret_val = phy->ops.write_reg(hw,
Auke Kok9d5c8242008-01-24 02:22:38 -08001192 IGP01E1000_PHY_PORT_CONFIG,
1193 data);
1194 if (ret_val)
1195 goto out;
1196 }
1197 } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
1198 (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
1199 (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
1200 data |= IGP02E1000_PM_D3_LPLU;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001201 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
Auke Kok9d5c8242008-01-24 02:22:38 -08001202 data);
1203 if (ret_val)
1204 goto out;
1205
1206 /* When LPLU is enabled, we should disable SmartSpeed */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001207 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
Auke Kok9d5c8242008-01-24 02:22:38 -08001208 &data);
1209 if (ret_val)
1210 goto out;
1211
1212 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001213 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
Auke Kok9d5c8242008-01-24 02:22:38 -08001214 data);
1215 }
1216
1217out:
1218 return ret_val;
1219}
1220
1221/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001222 * igb_check_downshift - Checks whether a downshift in speed occured
Auke Kok9d5c8242008-01-24 02:22:38 -08001223 * @hw: pointer to the HW structure
1224 *
1225 * Success returns 0, Failure returns 1
1226 *
1227 * A downshift is detected by querying the PHY link health.
1228 **/
1229s32 igb_check_downshift(struct e1000_hw *hw)
1230{
1231 struct e1000_phy_info *phy = &hw->phy;
1232 s32 ret_val;
1233 u16 phy_data, offset, mask;
1234
1235 switch (phy->type) {
1236 case e1000_phy_m88:
1237 case e1000_phy_gg82563:
1238 offset = M88E1000_PHY_SPEC_STATUS;
1239 mask = M88E1000_PSSR_DOWNSHIFT;
1240 break;
1241 case e1000_phy_igp_2:
1242 case e1000_phy_igp:
1243 case e1000_phy_igp_3:
1244 offset = IGP01E1000_PHY_LINK_HEALTH;
1245 mask = IGP01E1000_PLHR_SS_DOWNGRADE;
1246 break;
1247 default:
1248 /* speed downshift not supported */
1249 phy->speed_downgraded = false;
1250 ret_val = 0;
1251 goto out;
1252 }
1253
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001254 ret_val = phy->ops.read_reg(hw, offset, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001255
1256 if (!ret_val)
1257 phy->speed_downgraded = (phy_data & mask) ? true : false;
1258
1259out:
1260 return ret_val;
1261}
1262
1263/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001264 * igb_check_polarity_m88 - Checks the polarity.
Auke Kok9d5c8242008-01-24 02:22:38 -08001265 * @hw: pointer to the HW structure
1266 *
1267 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1268 *
1269 * Polarity is determined based on the PHY specific status register.
1270 **/
1271static s32 igb_check_polarity_m88(struct e1000_hw *hw)
1272{
1273 struct e1000_phy_info *phy = &hw->phy;
1274 s32 ret_val;
1275 u16 data;
1276
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001277 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001278
1279 if (!ret_val)
1280 phy->cable_polarity = (data & M88E1000_PSSR_REV_POLARITY)
1281 ? e1000_rev_polarity_reversed
1282 : e1000_rev_polarity_normal;
1283
1284 return ret_val;
1285}
1286
1287/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001288 * igb_check_polarity_igp - Checks the polarity.
Auke Kok9d5c8242008-01-24 02:22:38 -08001289 * @hw: pointer to the HW structure
1290 *
1291 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1292 *
1293 * Polarity is determined based on the PHY port status register, and the
1294 * current speed (since there is no polarity at 100Mbps).
1295 **/
1296static s32 igb_check_polarity_igp(struct e1000_hw *hw)
1297{
1298 struct e1000_phy_info *phy = &hw->phy;
1299 s32 ret_val;
1300 u16 data, offset, mask;
1301
1302 /*
1303 * Polarity is determined based on the speed of
1304 * our connection.
1305 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001306 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_STATUS, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001307 if (ret_val)
1308 goto out;
1309
1310 if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
1311 IGP01E1000_PSSR_SPEED_1000MBPS) {
1312 offset = IGP01E1000_PHY_PCS_INIT_REG;
1313 mask = IGP01E1000_PHY_POLARITY_MASK;
1314 } else {
1315 /*
1316 * This really only applies to 10Mbps since
1317 * there is no polarity for 100Mbps (always 0).
1318 */
1319 offset = IGP01E1000_PHY_PORT_STATUS;
1320 mask = IGP01E1000_PSSR_POLARITY_REVERSED;
1321 }
1322
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001323 ret_val = phy->ops.read_reg(hw, offset, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001324
1325 if (!ret_val)
1326 phy->cable_polarity = (data & mask)
1327 ? e1000_rev_polarity_reversed
1328 : e1000_rev_polarity_normal;
1329
1330out:
1331 return ret_val;
1332}
1333
1334/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001335 * igb_wait_autoneg - Wait for auto-neg compeletion
Auke Kok9d5c8242008-01-24 02:22:38 -08001336 * @hw: pointer to the HW structure
1337 *
1338 * Waits for auto-negotiation to complete or for the auto-negotiation time
1339 * limit to expire, which ever happens first.
1340 **/
1341static s32 igb_wait_autoneg(struct e1000_hw *hw)
1342{
1343 s32 ret_val = 0;
1344 u16 i, phy_status;
1345
1346 /* Break after autoneg completes or PHY_AUTO_NEG_LIMIT expires. */
1347 for (i = PHY_AUTO_NEG_LIMIT; i > 0; i--) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001348 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
Auke Kok9d5c8242008-01-24 02:22:38 -08001349 if (ret_val)
1350 break;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001351 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
Auke Kok9d5c8242008-01-24 02:22:38 -08001352 if (ret_val)
1353 break;
1354 if (phy_status & MII_SR_AUTONEG_COMPLETE)
1355 break;
1356 msleep(100);
1357 }
1358
1359 /*
1360 * PHY_AUTO_NEG_TIME expiration doesn't guarantee auto-negotiation
1361 * has completed.
1362 */
1363 return ret_val;
1364}
1365
1366/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001367 * igb_phy_has_link - Polls PHY for link
Auke Kok9d5c8242008-01-24 02:22:38 -08001368 * @hw: pointer to the HW structure
1369 * @iterations: number of times to poll for link
1370 * @usec_interval: delay between polling attempts
1371 * @success: pointer to whether polling was successful or not
1372 *
1373 * Polls the PHY status register for link, 'iterations' number of times.
1374 **/
1375s32 igb_phy_has_link(struct e1000_hw *hw, u32 iterations,
1376 u32 usec_interval, bool *success)
1377{
1378 s32 ret_val = 0;
1379 u16 i, phy_status;
1380
1381 for (i = 0; i < iterations; i++) {
1382 /*
1383 * Some PHYs require the PHY_STATUS register to be read
1384 * twice due to the link bit being sticky. No harm doing
1385 * it across the board.
1386 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001387 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
Auke Kok9d5c8242008-01-24 02:22:38 -08001388 if (ret_val)
1389 break;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001390 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
Auke Kok9d5c8242008-01-24 02:22:38 -08001391 if (ret_val)
1392 break;
1393 if (phy_status & MII_SR_LINK_STATUS)
1394 break;
1395 if (usec_interval >= 1000)
1396 mdelay(usec_interval/1000);
1397 else
1398 udelay(usec_interval);
1399 }
1400
1401 *success = (i < iterations) ? true : false;
1402
1403 return ret_val;
1404}
1405
1406/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001407 * igb_get_cable_length_m88 - Determine cable length for m88 PHY
Auke Kok9d5c8242008-01-24 02:22:38 -08001408 * @hw: pointer to the HW structure
1409 *
1410 * Reads the PHY specific status register to retrieve the cable length
1411 * information. The cable length is determined by averaging the minimum and
1412 * maximum values to get the "average" cable length. The m88 PHY has four
1413 * possible cable length values, which are:
1414 * Register Value Cable Length
1415 * 0 < 50 meters
1416 * 1 50 - 80 meters
1417 * 2 80 - 110 meters
1418 * 3 110 - 140 meters
1419 * 4 > 140 meters
1420 **/
1421s32 igb_get_cable_length_m88(struct e1000_hw *hw)
1422{
1423 struct e1000_phy_info *phy = &hw->phy;
1424 s32 ret_val;
1425 u16 phy_data, index;
1426
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001427 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001428 if (ret_val)
1429 goto out;
1430
1431 index = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
1432 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
1433 phy->min_cable_length = e1000_m88_cable_length_table[index];
1434 phy->max_cable_length = e1000_m88_cable_length_table[index+1];
1435
1436 phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
1437
1438out:
1439 return ret_val;
1440}
1441
1442/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001443 * igb_get_cable_length_igp_2 - Determine cable length for igp2 PHY
Auke Kok9d5c8242008-01-24 02:22:38 -08001444 * @hw: pointer to the HW structure
1445 *
1446 * The automatic gain control (agc) normalizes the amplitude of the
1447 * received signal, adjusting for the attenuation produced by the
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001448 * cable. By reading the AGC registers, which represent the
1449 * combination of coarse and fine gain value, the value can be put
Auke Kok9d5c8242008-01-24 02:22:38 -08001450 * into a lookup table to obtain the approximate cable length
1451 * for each channel.
1452 **/
1453s32 igb_get_cable_length_igp_2(struct e1000_hw *hw)
1454{
1455 struct e1000_phy_info *phy = &hw->phy;
1456 s32 ret_val = 0;
1457 u16 phy_data, i, agc_value = 0;
1458 u16 cur_agc_index, max_agc_index = 0;
1459 u16 min_agc_index = IGP02E1000_CABLE_LENGTH_TABLE_SIZE - 1;
1460 u16 agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] =
1461 {IGP02E1000_PHY_AGC_A,
1462 IGP02E1000_PHY_AGC_B,
1463 IGP02E1000_PHY_AGC_C,
1464 IGP02E1000_PHY_AGC_D};
1465
1466 /* Read the AGC registers for all channels */
1467 for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001468 ret_val = phy->ops.read_reg(hw, agc_reg_array[i], &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001469 if (ret_val)
1470 goto out;
1471
1472 /*
1473 * Getting bits 15:9, which represent the combination of
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001474 * coarse and fine gain values. The result is a number
Auke Kok9d5c8242008-01-24 02:22:38 -08001475 * that can be put into the lookup table to obtain the
1476 * approximate cable length.
1477 */
1478 cur_agc_index = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
1479 IGP02E1000_AGC_LENGTH_MASK;
1480
1481 /* Array index bound check. */
1482 if ((cur_agc_index >= IGP02E1000_CABLE_LENGTH_TABLE_SIZE) ||
1483 (cur_agc_index == 0)) {
1484 ret_val = -E1000_ERR_PHY;
1485 goto out;
1486 }
1487
1488 /* Remove min & max AGC values from calculation. */
1489 if (e1000_igp_2_cable_length_table[min_agc_index] >
1490 e1000_igp_2_cable_length_table[cur_agc_index])
1491 min_agc_index = cur_agc_index;
1492 if (e1000_igp_2_cable_length_table[max_agc_index] <
1493 e1000_igp_2_cable_length_table[cur_agc_index])
1494 max_agc_index = cur_agc_index;
1495
1496 agc_value += e1000_igp_2_cable_length_table[cur_agc_index];
1497 }
1498
1499 agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] +
1500 e1000_igp_2_cable_length_table[max_agc_index]);
1501 agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
1502
1503 /* Calculate cable length with the error range of +/- 10 meters. */
1504 phy->min_cable_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
1505 (agc_value - IGP02E1000_AGC_RANGE) : 0;
1506 phy->max_cable_length = agc_value + IGP02E1000_AGC_RANGE;
1507
1508 phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
1509
1510out:
1511 return ret_val;
1512}
1513
1514/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001515 * igb_get_phy_info_m88 - Retrieve PHY information
Auke Kok9d5c8242008-01-24 02:22:38 -08001516 * @hw: pointer to the HW structure
1517 *
1518 * Valid for only copper links. Read the PHY status register (sticky read)
1519 * to verify that link is up. Read the PHY special control register to
1520 * determine the polarity and 10base-T extended distance. Read the PHY
1521 * special status register to determine MDI/MDIx and current speed. If
1522 * speed is 1000, then determine cable length, local and remote receiver.
1523 **/
1524s32 igb_get_phy_info_m88(struct e1000_hw *hw)
1525{
1526 struct e1000_phy_info *phy = &hw->phy;
1527 s32 ret_val;
1528 u16 phy_data;
1529 bool link;
1530
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001531 if (phy->media_type != e1000_media_type_copper) {
Auke Kok652fff32008-06-27 11:00:18 -07001532 hw_dbg("Phy info is only valid for copper media\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001533 ret_val = -E1000_ERR_CONFIG;
1534 goto out;
1535 }
1536
1537 ret_val = igb_phy_has_link(hw, 1, 0, &link);
1538 if (ret_val)
1539 goto out;
1540
1541 if (!link) {
Auke Kok652fff32008-06-27 11:00:18 -07001542 hw_dbg("Phy info is only valid if link is up\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001543 ret_val = -E1000_ERR_CONFIG;
1544 goto out;
1545 }
1546
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001547 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001548 if (ret_val)
1549 goto out;
1550
1551 phy->polarity_correction = (phy_data & M88E1000_PSCR_POLARITY_REVERSAL)
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001552 ? true : false;
Auke Kok9d5c8242008-01-24 02:22:38 -08001553
1554 ret_val = igb_check_polarity_m88(hw);
1555 if (ret_val)
1556 goto out;
1557
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001558 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001559 if (ret_val)
1560 goto out;
1561
1562 phy->is_mdix = (phy_data & M88E1000_PSSR_MDIX) ? true : false;
1563
1564 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001565 ret_val = phy->ops.get_cable_length(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001566 if (ret_val)
1567 goto out;
1568
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001569 ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001570 if (ret_val)
1571 goto out;
1572
1573 phy->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS)
1574 ? e1000_1000t_rx_status_ok
1575 : e1000_1000t_rx_status_not_ok;
1576
1577 phy->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS)
1578 ? e1000_1000t_rx_status_ok
1579 : e1000_1000t_rx_status_not_ok;
1580 } else {
1581 /* Set values to "undefined" */
1582 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
1583 phy->local_rx = e1000_1000t_rx_status_undefined;
1584 phy->remote_rx = e1000_1000t_rx_status_undefined;
1585 }
1586
1587out:
1588 return ret_val;
1589}
1590
1591/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001592 * igb_get_phy_info_igp - Retrieve igp PHY information
Auke Kok9d5c8242008-01-24 02:22:38 -08001593 * @hw: pointer to the HW structure
1594 *
1595 * Read PHY status to determine if link is up. If link is up, then
1596 * set/determine 10base-T extended distance and polarity correction. Read
1597 * PHY port status to determine MDI/MDIx and speed. Based on the speed,
1598 * determine on the cable length, local and remote receiver.
1599 **/
1600s32 igb_get_phy_info_igp(struct e1000_hw *hw)
1601{
1602 struct e1000_phy_info *phy = &hw->phy;
1603 s32 ret_val;
1604 u16 data;
1605 bool link;
1606
1607 ret_val = igb_phy_has_link(hw, 1, 0, &link);
1608 if (ret_val)
1609 goto out;
1610
1611 if (!link) {
Auke Kok652fff32008-06-27 11:00:18 -07001612 hw_dbg("Phy info is only valid if link is up\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001613 ret_val = -E1000_ERR_CONFIG;
1614 goto out;
1615 }
1616
1617 phy->polarity_correction = true;
1618
1619 ret_val = igb_check_polarity_igp(hw);
1620 if (ret_val)
1621 goto out;
1622
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001623 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_STATUS, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001624 if (ret_val)
1625 goto out;
1626
1627 phy->is_mdix = (data & IGP01E1000_PSSR_MDIX) ? true : false;
1628
1629 if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
1630 IGP01E1000_PSSR_SPEED_1000MBPS) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001631 ret_val = phy->ops.get_cable_length(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001632 if (ret_val)
1633 goto out;
1634
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001635 ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001636 if (ret_val)
1637 goto out;
1638
1639 phy->local_rx = (data & SR_1000T_LOCAL_RX_STATUS)
1640 ? e1000_1000t_rx_status_ok
1641 : e1000_1000t_rx_status_not_ok;
1642
1643 phy->remote_rx = (data & SR_1000T_REMOTE_RX_STATUS)
1644 ? e1000_1000t_rx_status_ok
1645 : e1000_1000t_rx_status_not_ok;
1646 } else {
1647 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
1648 phy->local_rx = e1000_1000t_rx_status_undefined;
1649 phy->remote_rx = e1000_1000t_rx_status_undefined;
1650 }
1651
1652out:
1653 return ret_val;
1654}
1655
1656/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001657 * igb_phy_sw_reset - PHY software reset
Auke Kok9d5c8242008-01-24 02:22:38 -08001658 * @hw: pointer to the HW structure
1659 *
1660 * Does a software reset of the PHY by reading the PHY control register and
1661 * setting/write the control register reset bit to the PHY.
1662 **/
1663s32 igb_phy_sw_reset(struct e1000_hw *hw)
1664{
Alexander Duyckd3147372009-09-14 08:23:13 +00001665 s32 ret_val = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08001666 u16 phy_ctrl;
1667
Alexander Duyckd3147372009-09-14 08:23:13 +00001668 if (!(hw->phy.ops.read_reg))
1669 goto out;
1670
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001671 ret_val = hw->phy.ops.read_reg(hw, PHY_CONTROL, &phy_ctrl);
Auke Kok9d5c8242008-01-24 02:22:38 -08001672 if (ret_val)
1673 goto out;
1674
1675 phy_ctrl |= MII_CR_RESET;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001676 ret_val = hw->phy.ops.write_reg(hw, PHY_CONTROL, phy_ctrl);
Auke Kok9d5c8242008-01-24 02:22:38 -08001677 if (ret_val)
1678 goto out;
1679
1680 udelay(1);
1681
1682out:
1683 return ret_val;
1684}
1685
1686/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001687 * igb_phy_hw_reset - PHY hardware reset
Auke Kok9d5c8242008-01-24 02:22:38 -08001688 * @hw: pointer to the HW structure
1689 *
1690 * Verify the reset block is not blocking us from resetting. Acquire
1691 * semaphore (if necessary) and read/set/write the device control reset
1692 * bit in the PHY. Wait the appropriate delay time for the device to
1693 * reset and relase the semaphore (if necessary).
1694 **/
1695s32 igb_phy_hw_reset(struct e1000_hw *hw)
1696{
1697 struct e1000_phy_info *phy = &hw->phy;
1698 s32 ret_val;
1699 u32 ctrl;
1700
1701 ret_val = igb_check_reset_block(hw);
1702 if (ret_val) {
1703 ret_val = 0;
1704 goto out;
1705 }
1706
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001707 ret_val = phy->ops.acquire(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001708 if (ret_val)
1709 goto out;
1710
1711 ctrl = rd32(E1000_CTRL);
1712 wr32(E1000_CTRL, ctrl | E1000_CTRL_PHY_RST);
1713 wrfl();
1714
1715 udelay(phy->reset_delay_us);
1716
1717 wr32(E1000_CTRL, ctrl);
1718 wrfl();
1719
1720 udelay(150);
1721
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001722 phy->ops.release(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001723
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001724 ret_val = phy->ops.get_cfg_done(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001725
1726out:
1727 return ret_val;
1728}
1729
Auke Kok9d5c8242008-01-24 02:22:38 -08001730/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001731 * igb_phy_init_script_igp3 - Inits the IGP3 PHY
Auke Kok9d5c8242008-01-24 02:22:38 -08001732 * @hw: pointer to the HW structure
1733 *
1734 * Initializes a Intel Gigabit PHY3 when an EEPROM is not present.
1735 **/
1736s32 igb_phy_init_script_igp3(struct e1000_hw *hw)
1737{
Auke Kok652fff32008-06-27 11:00:18 -07001738 hw_dbg("Running IGP 3 PHY init script\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001739
1740 /* PHY init IGP 3 */
1741 /* Enable rise/fall, 10-mode work in class-A */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001742 hw->phy.ops.write_reg(hw, 0x2F5B, 0x9018);
Auke Kok9d5c8242008-01-24 02:22:38 -08001743 /* Remove all caps from Replica path filter */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001744 hw->phy.ops.write_reg(hw, 0x2F52, 0x0000);
Auke Kok9d5c8242008-01-24 02:22:38 -08001745 /* Bias trimming for ADC, AFE and Driver (Default) */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001746 hw->phy.ops.write_reg(hw, 0x2FB1, 0x8B24);
Auke Kok9d5c8242008-01-24 02:22:38 -08001747 /* Increase Hybrid poly bias */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001748 hw->phy.ops.write_reg(hw, 0x2FB2, 0xF8F0);
Auke Kok9d5c8242008-01-24 02:22:38 -08001749 /* Add 4% to TX amplitude in Giga mode */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001750 hw->phy.ops.write_reg(hw, 0x2010, 0x10B0);
Auke Kok9d5c8242008-01-24 02:22:38 -08001751 /* Disable trimming (TTT) */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001752 hw->phy.ops.write_reg(hw, 0x2011, 0x0000);
Auke Kok9d5c8242008-01-24 02:22:38 -08001753 /* Poly DC correction to 94.6% + 2% for all channels */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001754 hw->phy.ops.write_reg(hw, 0x20DD, 0x249A);
Auke Kok9d5c8242008-01-24 02:22:38 -08001755 /* ABS DC correction to 95.9% */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001756 hw->phy.ops.write_reg(hw, 0x20DE, 0x00D3);
Auke Kok9d5c8242008-01-24 02:22:38 -08001757 /* BG temp curve trim */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001758 hw->phy.ops.write_reg(hw, 0x28B4, 0x04CE);
Auke Kok9d5c8242008-01-24 02:22:38 -08001759 /* Increasing ADC OPAMP stage 1 currents to max */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001760 hw->phy.ops.write_reg(hw, 0x2F70, 0x29E4);
Auke Kok9d5c8242008-01-24 02:22:38 -08001761 /* Force 1000 ( required for enabling PHY regs configuration) */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001762 hw->phy.ops.write_reg(hw, 0x0000, 0x0140);
Auke Kok9d5c8242008-01-24 02:22:38 -08001763 /* Set upd_freq to 6 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001764 hw->phy.ops.write_reg(hw, 0x1F30, 0x1606);
Auke Kok9d5c8242008-01-24 02:22:38 -08001765 /* Disable NPDFE */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001766 hw->phy.ops.write_reg(hw, 0x1F31, 0xB814);
Auke Kok9d5c8242008-01-24 02:22:38 -08001767 /* Disable adaptive fixed FFE (Default) */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001768 hw->phy.ops.write_reg(hw, 0x1F35, 0x002A);
Auke Kok9d5c8242008-01-24 02:22:38 -08001769 /* Enable FFE hysteresis */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001770 hw->phy.ops.write_reg(hw, 0x1F3E, 0x0067);
Auke Kok9d5c8242008-01-24 02:22:38 -08001771 /* Fixed FFE for short cable lengths */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001772 hw->phy.ops.write_reg(hw, 0x1F54, 0x0065);
Auke Kok9d5c8242008-01-24 02:22:38 -08001773 /* Fixed FFE for medium cable lengths */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001774 hw->phy.ops.write_reg(hw, 0x1F55, 0x002A);
Auke Kok9d5c8242008-01-24 02:22:38 -08001775 /* Fixed FFE for long cable lengths */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001776 hw->phy.ops.write_reg(hw, 0x1F56, 0x002A);
Auke Kok9d5c8242008-01-24 02:22:38 -08001777 /* Enable Adaptive Clip Threshold */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001778 hw->phy.ops.write_reg(hw, 0x1F72, 0x3FB0);
Auke Kok9d5c8242008-01-24 02:22:38 -08001779 /* AHT reset limit to 1 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001780 hw->phy.ops.write_reg(hw, 0x1F76, 0xC0FF);
Auke Kok9d5c8242008-01-24 02:22:38 -08001781 /* Set AHT master delay to 127 msec */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001782 hw->phy.ops.write_reg(hw, 0x1F77, 0x1DEC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001783 /* Set scan bits for AHT */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001784 hw->phy.ops.write_reg(hw, 0x1F78, 0xF9EF);
Auke Kok9d5c8242008-01-24 02:22:38 -08001785 /* Set AHT Preset bits */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001786 hw->phy.ops.write_reg(hw, 0x1F79, 0x0210);
Auke Kok9d5c8242008-01-24 02:22:38 -08001787 /* Change integ_factor of channel A to 3 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001788 hw->phy.ops.write_reg(hw, 0x1895, 0x0003);
Auke Kok9d5c8242008-01-24 02:22:38 -08001789 /* Change prop_factor of channels BCD to 8 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001790 hw->phy.ops.write_reg(hw, 0x1796, 0x0008);
Auke Kok9d5c8242008-01-24 02:22:38 -08001791 /* Change cg_icount + enable integbp for channels BCD */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001792 hw->phy.ops.write_reg(hw, 0x1798, 0xD008);
Auke Kok9d5c8242008-01-24 02:22:38 -08001793 /*
1794 * Change cg_icount + enable integbp + change prop_factor_master
1795 * to 8 for channel A
1796 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001797 hw->phy.ops.write_reg(hw, 0x1898, 0xD918);
Auke Kok9d5c8242008-01-24 02:22:38 -08001798 /* Disable AHT in Slave mode on channel A */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001799 hw->phy.ops.write_reg(hw, 0x187A, 0x0800);
Auke Kok9d5c8242008-01-24 02:22:38 -08001800 /*
1801 * Enable LPLU and disable AN to 1000 in non-D0a states,
1802 * Enable SPD+B2B
1803 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001804 hw->phy.ops.write_reg(hw, 0x0019, 0x008D);
Auke Kok9d5c8242008-01-24 02:22:38 -08001805 /* Enable restart AN on an1000_dis change */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001806 hw->phy.ops.write_reg(hw, 0x001B, 0x2080);
Auke Kok9d5c8242008-01-24 02:22:38 -08001807 /* Enable wh_fifo read clock in 10/100 modes */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001808 hw->phy.ops.write_reg(hw, 0x0014, 0x0045);
Auke Kok9d5c8242008-01-24 02:22:38 -08001809 /* Restart AN, Speed selection is 1000 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001810 hw->phy.ops.write_reg(hw, 0x0000, 0x1340);
Auke Kok9d5c8242008-01-24 02:22:38 -08001811
1812 return 0;
1813}
1814