blob: 5fe03e114b83a6240d0e0c11ae985365f7004c7f [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 **/
Alexander Duyck81fadd82009-10-05 06:35:03 +0000672static s32 igb_copper_link_autoneg(struct e1000_hw *hw)
Auke Kok9d5c8242008-01-24 02:22:38 -0800673{
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/**
Alexander Duyck81fadd82009-10-05 06:35:03 +0000896 * igb_setup_copper_link - Configure copper link settings
897 * @hw: pointer to the HW structure
898 *
899 * Calls the appropriate function to configure the link for auto-neg or forced
900 * speed and duplex. Then we check for link, once link is established calls
901 * to configure collision distance and flow control are called. If link is
902 * not established, we return -E1000_ERR_PHY (-2).
903 **/
904s32 igb_setup_copper_link(struct e1000_hw *hw)
905{
906 s32 ret_val;
907 bool link;
908
909
910 if (hw->mac.autoneg) {
911 /*
912 * Setup autoneg and flow control advertisement and perform
913 * autonegotiation.
914 */
915 ret_val = igb_copper_link_autoneg(hw);
916 if (ret_val)
917 goto out;
918 } else {
919 /*
920 * PHY will be set to 10H, 10F, 100H or 100F
921 * depending on user settings.
922 */
923 hw_dbg("Forcing Speed and Duplex\n");
924 ret_val = hw->phy.ops.force_speed_duplex(hw);
925 if (ret_val) {
926 hw_dbg("Error Forcing Speed and Duplex\n");
927 goto out;
928 }
929 }
930
931 /*
932 * Check link status. Wait up to 100 microseconds for link to become
933 * valid.
934 */
935 ret_val = igb_phy_has_link(hw,
936 COPPER_LINK_UP_LIMIT,
937 10,
938 &link);
939 if (ret_val)
940 goto out;
941
942 if (link) {
943 hw_dbg("Valid link established!!!\n");
944 igb_config_collision_dist(hw);
945 ret_val = igb_config_fc_after_link_up(hw);
946 } else {
947 hw_dbg("Unable to establish link!!!\n");
948 }
949
950out:
951 return ret_val;
952}
953
954/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700955 * igb_phy_force_speed_duplex_igp - Force speed/duplex for igp PHY
Auke Kok9d5c8242008-01-24 02:22:38 -0800956 * @hw: pointer to the HW structure
957 *
958 * Calls the PHY setup function to force speed and duplex. Clears the
959 * auto-crossover to force MDI manually. Waits for link and returns
960 * successful if link up is successful, else -E1000_ERR_PHY (-2).
961 **/
962s32 igb_phy_force_speed_duplex_igp(struct e1000_hw *hw)
963{
964 struct e1000_phy_info *phy = &hw->phy;
965 s32 ret_val;
966 u16 phy_data;
967 bool link;
968
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000969 ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800970 if (ret_val)
971 goto out;
972
973 igb_phy_force_speed_duplex_setup(hw, &phy_data);
974
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000975 ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800976 if (ret_val)
977 goto out;
978
979 /*
980 * Clear Auto-Crossover to force MDI manually. IGP requires MDI
981 * forced whenever speed and duplex are forced.
982 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000983 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800984 if (ret_val)
985 goto out;
986
987 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
988 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
989
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000990 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800991 if (ret_val)
992 goto out;
993
Auke Kok652fff32008-06-27 11:00:18 -0700994 hw_dbg("IGP PSCR: %X\n", phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800995
996 udelay(1);
997
998 if (phy->autoneg_wait_to_complete) {
Auke Kok652fff32008-06-27 11:00:18 -0700999 hw_dbg("Waiting for forced speed/duplex link on IGP phy.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001000
1001 ret_val = igb_phy_has_link(hw,
1002 PHY_FORCE_LIMIT,
1003 100000,
1004 &link);
1005 if (ret_val)
1006 goto out;
1007
1008 if (!link)
Auke Kok652fff32008-06-27 11:00:18 -07001009 hw_dbg("Link taking longer than expected.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001010
1011 /* Try once more */
1012 ret_val = igb_phy_has_link(hw,
1013 PHY_FORCE_LIMIT,
1014 100000,
1015 &link);
1016 if (ret_val)
1017 goto out;
1018 }
1019
1020out:
1021 return ret_val;
1022}
1023
1024/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001025 * igb_phy_force_speed_duplex_m88 - Force speed/duplex for m88 PHY
Auke Kok9d5c8242008-01-24 02:22:38 -08001026 * @hw: pointer to the HW structure
1027 *
1028 * Calls the PHY setup function to force speed and duplex. Clears the
1029 * auto-crossover to force MDI manually. Resets the PHY to commit the
1030 * changes. If time expires while waiting for link up, we reset the DSP.
1031 * After reset, TX_CLK and CRS on TX must be set. Return successful upon
1032 * successful completion, else return corresponding error code.
1033 **/
1034s32 igb_phy_force_speed_duplex_m88(struct e1000_hw *hw)
1035{
1036 struct e1000_phy_info *phy = &hw->phy;
1037 s32 ret_val;
1038 u16 phy_data;
1039 bool link;
1040
1041 /*
1042 * Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
1043 * forced whenever speed and duplex are forced.
1044 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001045 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001046 if (ret_val)
1047 goto out;
1048
1049 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001050 ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001051 if (ret_val)
1052 goto out;
1053
Auke Kok652fff32008-06-27 11:00:18 -07001054 hw_dbg("M88E1000 PSCR: %X\n", phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001055
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001056 ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001057 if (ret_val)
1058 goto out;
1059
1060 igb_phy_force_speed_duplex_setup(hw, &phy_data);
1061
1062 /* Reset the phy to commit changes. */
1063 phy_data |= MII_CR_RESET;
1064
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001065 ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001066 if (ret_val)
1067 goto out;
1068
1069 udelay(1);
1070
1071 if (phy->autoneg_wait_to_complete) {
Auke Kok652fff32008-06-27 11:00:18 -07001072 hw_dbg("Waiting for forced speed/duplex link on M88 phy.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001073
1074 ret_val = igb_phy_has_link(hw,
1075 PHY_FORCE_LIMIT,
1076 100000,
1077 &link);
1078 if (ret_val)
1079 goto out;
1080
1081 if (!link) {
1082 /*
1083 * We didn't get link.
1084 * Reset the DSP and cross our fingers.
1085 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001086 ret_val = phy->ops.write_reg(hw,
Auke Kok9d5c8242008-01-24 02:22:38 -08001087 M88E1000_PHY_PAGE_SELECT,
1088 0x001d);
1089 if (ret_val)
1090 goto out;
1091 ret_val = igb_phy_reset_dsp(hw);
1092 if (ret_val)
1093 goto out;
1094 }
1095
1096 /* Try once more */
1097 ret_val = igb_phy_has_link(hw, PHY_FORCE_LIMIT,
1098 100000, &link);
1099 if (ret_val)
1100 goto out;
1101 }
1102
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001103 ret_val = phy->ops.read_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001104 if (ret_val)
1105 goto out;
1106
1107 /*
1108 * Resetting the phy means we need to re-force TX_CLK in the
1109 * Extended PHY Specific Control Register to 25MHz clock from
1110 * the reset value of 2.5MHz.
1111 */
1112 phy_data |= M88E1000_EPSCR_TX_CLK_25;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001113 ret_val = phy->ops.write_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001114 if (ret_val)
1115 goto out;
1116
1117 /*
1118 * In addition, we must re-enable CRS on Tx for both half and full
1119 * duplex.
1120 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001121 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001122 if (ret_val)
1123 goto out;
1124
1125 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001126 ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001127
1128out:
1129 return ret_val;
1130}
1131
1132/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001133 * igb_phy_force_speed_duplex_setup - Configure forced PHY speed/duplex
Auke Kok9d5c8242008-01-24 02:22:38 -08001134 * @hw: pointer to the HW structure
1135 * @phy_ctrl: pointer to current value of PHY_CONTROL
1136 *
1137 * Forces speed and duplex on the PHY by doing the following: disable flow
1138 * control, force speed/duplex on the MAC, disable auto speed detection,
1139 * disable auto-negotiation, configure duplex, configure speed, configure
1140 * the collision distance, write configuration to CTRL register. The
1141 * caller must write to the PHY_CONTROL register for these settings to
1142 * take affect.
1143 **/
1144static void igb_phy_force_speed_duplex_setup(struct e1000_hw *hw,
1145 u16 *phy_ctrl)
1146{
1147 struct e1000_mac_info *mac = &hw->mac;
1148 u32 ctrl;
1149
1150 /* Turn off flow control when forcing speed/duplex */
Alexander Duyck0cce1192009-07-23 18:10:24 +00001151 hw->fc.current_mode = e1000_fc_none;
Auke Kok9d5c8242008-01-24 02:22:38 -08001152
1153 /* Force speed/duplex on the mac */
1154 ctrl = rd32(E1000_CTRL);
1155 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1156 ctrl &= ~E1000_CTRL_SPD_SEL;
1157
1158 /* Disable Auto Speed Detection */
1159 ctrl &= ~E1000_CTRL_ASDE;
1160
1161 /* Disable autoneg on the phy */
1162 *phy_ctrl &= ~MII_CR_AUTO_NEG_EN;
1163
1164 /* Forcing Full or Half Duplex? */
1165 if (mac->forced_speed_duplex & E1000_ALL_HALF_DUPLEX) {
1166 ctrl &= ~E1000_CTRL_FD;
1167 *phy_ctrl &= ~MII_CR_FULL_DUPLEX;
Auke Kok652fff32008-06-27 11:00:18 -07001168 hw_dbg("Half Duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001169 } else {
1170 ctrl |= E1000_CTRL_FD;
1171 *phy_ctrl |= MII_CR_FULL_DUPLEX;
Auke Kok652fff32008-06-27 11:00:18 -07001172 hw_dbg("Full Duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001173 }
1174
1175 /* Forcing 10mb or 100mb? */
1176 if (mac->forced_speed_duplex & E1000_ALL_100_SPEED) {
1177 ctrl |= E1000_CTRL_SPD_100;
1178 *phy_ctrl |= MII_CR_SPEED_100;
1179 *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
Auke Kok652fff32008-06-27 11:00:18 -07001180 hw_dbg("Forcing 100mb\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001181 } else {
1182 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1183 *phy_ctrl |= MII_CR_SPEED_10;
1184 *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
Auke Kok652fff32008-06-27 11:00:18 -07001185 hw_dbg("Forcing 10mb\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001186 }
1187
1188 igb_config_collision_dist(hw);
1189
1190 wr32(E1000_CTRL, ctrl);
1191}
1192
1193/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001194 * igb_set_d3_lplu_state - Sets low power link up state for D3
Auke Kok9d5c8242008-01-24 02:22:38 -08001195 * @hw: pointer to the HW structure
1196 * @active: boolean used to enable/disable lplu
1197 *
1198 * Success returns 0, Failure returns 1
1199 *
1200 * The low power link up (lplu) state is set to the power management level D3
1201 * and SmartSpeed is disabled when active is true, else clear lplu for D3
1202 * and enable Smartspeed. LPLU and Smartspeed are mutually exclusive. LPLU
1203 * is used during Dx states where the power conservation is most important.
1204 * During driver activity, SmartSpeed should be enabled so performance is
1205 * maintained.
1206 **/
1207s32 igb_set_d3_lplu_state(struct e1000_hw *hw, bool active)
1208{
1209 struct e1000_phy_info *phy = &hw->phy;
1210 s32 ret_val;
1211 u16 data;
1212
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001213 ret_val = phy->ops.read_reg(hw, IGP02E1000_PHY_POWER_MGMT, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001214 if (ret_val)
1215 goto out;
1216
1217 if (!active) {
1218 data &= ~IGP02E1000_PM_D3_LPLU;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001219 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
Auke Kok9d5c8242008-01-24 02:22:38 -08001220 data);
1221 if (ret_val)
1222 goto out;
1223 /*
1224 * LPLU and SmartSpeed are mutually exclusive. LPLU is used
1225 * during Dx states where the power conservation is most
1226 * important. During driver activity we should enable
1227 * SmartSpeed, so performance is maintained.
1228 */
1229 if (phy->smart_speed == e1000_smart_speed_on) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001230 ret_val = phy->ops.read_reg(hw,
Auke Kok9d5c8242008-01-24 02:22:38 -08001231 IGP01E1000_PHY_PORT_CONFIG,
1232 &data);
1233 if (ret_val)
1234 goto out;
1235
1236 data |= IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001237 ret_val = phy->ops.write_reg(hw,
Auke Kok9d5c8242008-01-24 02:22:38 -08001238 IGP01E1000_PHY_PORT_CONFIG,
1239 data);
1240 if (ret_val)
1241 goto out;
1242 } else if (phy->smart_speed == e1000_smart_speed_off) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001243 ret_val = phy->ops.read_reg(hw,
Auke Kok9d5c8242008-01-24 02:22:38 -08001244 IGP01E1000_PHY_PORT_CONFIG,
1245 &data);
1246 if (ret_val)
1247 goto out;
1248
1249 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001250 ret_val = phy->ops.write_reg(hw,
Auke Kok9d5c8242008-01-24 02:22:38 -08001251 IGP01E1000_PHY_PORT_CONFIG,
1252 data);
1253 if (ret_val)
1254 goto out;
1255 }
1256 } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
1257 (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
1258 (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
1259 data |= IGP02E1000_PM_D3_LPLU;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001260 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
Auke Kok9d5c8242008-01-24 02:22:38 -08001261 data);
1262 if (ret_val)
1263 goto out;
1264
1265 /* When LPLU is enabled, we should disable SmartSpeed */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001266 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
Auke Kok9d5c8242008-01-24 02:22:38 -08001267 &data);
1268 if (ret_val)
1269 goto out;
1270
1271 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001272 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
Auke Kok9d5c8242008-01-24 02:22:38 -08001273 data);
1274 }
1275
1276out:
1277 return ret_val;
1278}
1279
1280/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001281 * igb_check_downshift - Checks whether a downshift in speed occured
Auke Kok9d5c8242008-01-24 02:22:38 -08001282 * @hw: pointer to the HW structure
1283 *
1284 * Success returns 0, Failure returns 1
1285 *
1286 * A downshift is detected by querying the PHY link health.
1287 **/
1288s32 igb_check_downshift(struct e1000_hw *hw)
1289{
1290 struct e1000_phy_info *phy = &hw->phy;
1291 s32 ret_val;
1292 u16 phy_data, offset, mask;
1293
1294 switch (phy->type) {
1295 case e1000_phy_m88:
1296 case e1000_phy_gg82563:
1297 offset = M88E1000_PHY_SPEC_STATUS;
1298 mask = M88E1000_PSSR_DOWNSHIFT;
1299 break;
1300 case e1000_phy_igp_2:
1301 case e1000_phy_igp:
1302 case e1000_phy_igp_3:
1303 offset = IGP01E1000_PHY_LINK_HEALTH;
1304 mask = IGP01E1000_PLHR_SS_DOWNGRADE;
1305 break;
1306 default:
1307 /* speed downshift not supported */
1308 phy->speed_downgraded = false;
1309 ret_val = 0;
1310 goto out;
1311 }
1312
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001313 ret_val = phy->ops.read_reg(hw, offset, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001314
1315 if (!ret_val)
1316 phy->speed_downgraded = (phy_data & mask) ? true : false;
1317
1318out:
1319 return ret_val;
1320}
1321
1322/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001323 * igb_check_polarity_m88 - Checks the polarity.
Auke Kok9d5c8242008-01-24 02:22:38 -08001324 * @hw: pointer to the HW structure
1325 *
1326 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1327 *
1328 * Polarity is determined based on the PHY specific status register.
1329 **/
1330static s32 igb_check_polarity_m88(struct e1000_hw *hw)
1331{
1332 struct e1000_phy_info *phy = &hw->phy;
1333 s32 ret_val;
1334 u16 data;
1335
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001336 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001337
1338 if (!ret_val)
1339 phy->cable_polarity = (data & M88E1000_PSSR_REV_POLARITY)
1340 ? e1000_rev_polarity_reversed
1341 : e1000_rev_polarity_normal;
1342
1343 return ret_val;
1344}
1345
1346/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001347 * igb_check_polarity_igp - Checks the polarity.
Auke Kok9d5c8242008-01-24 02:22:38 -08001348 * @hw: pointer to the HW structure
1349 *
1350 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1351 *
1352 * Polarity is determined based on the PHY port status register, and the
1353 * current speed (since there is no polarity at 100Mbps).
1354 **/
1355static s32 igb_check_polarity_igp(struct e1000_hw *hw)
1356{
1357 struct e1000_phy_info *phy = &hw->phy;
1358 s32 ret_val;
1359 u16 data, offset, mask;
1360
1361 /*
1362 * Polarity is determined based on the speed of
1363 * our connection.
1364 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001365 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_STATUS, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001366 if (ret_val)
1367 goto out;
1368
1369 if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
1370 IGP01E1000_PSSR_SPEED_1000MBPS) {
1371 offset = IGP01E1000_PHY_PCS_INIT_REG;
1372 mask = IGP01E1000_PHY_POLARITY_MASK;
1373 } else {
1374 /*
1375 * This really only applies to 10Mbps since
1376 * there is no polarity for 100Mbps (always 0).
1377 */
1378 offset = IGP01E1000_PHY_PORT_STATUS;
1379 mask = IGP01E1000_PSSR_POLARITY_REVERSED;
1380 }
1381
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001382 ret_val = phy->ops.read_reg(hw, offset, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001383
1384 if (!ret_val)
1385 phy->cable_polarity = (data & mask)
1386 ? e1000_rev_polarity_reversed
1387 : e1000_rev_polarity_normal;
1388
1389out:
1390 return ret_val;
1391}
1392
1393/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001394 * igb_wait_autoneg - Wait for auto-neg compeletion
Auke Kok9d5c8242008-01-24 02:22:38 -08001395 * @hw: pointer to the HW structure
1396 *
1397 * Waits for auto-negotiation to complete or for the auto-negotiation time
1398 * limit to expire, which ever happens first.
1399 **/
1400static s32 igb_wait_autoneg(struct e1000_hw *hw)
1401{
1402 s32 ret_val = 0;
1403 u16 i, phy_status;
1404
1405 /* Break after autoneg completes or PHY_AUTO_NEG_LIMIT expires. */
1406 for (i = PHY_AUTO_NEG_LIMIT; i > 0; i--) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001407 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
Auke Kok9d5c8242008-01-24 02:22:38 -08001408 if (ret_val)
1409 break;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001410 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
Auke Kok9d5c8242008-01-24 02:22:38 -08001411 if (ret_val)
1412 break;
1413 if (phy_status & MII_SR_AUTONEG_COMPLETE)
1414 break;
1415 msleep(100);
1416 }
1417
1418 /*
1419 * PHY_AUTO_NEG_TIME expiration doesn't guarantee auto-negotiation
1420 * has completed.
1421 */
1422 return ret_val;
1423}
1424
1425/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001426 * igb_phy_has_link - Polls PHY for link
Auke Kok9d5c8242008-01-24 02:22:38 -08001427 * @hw: pointer to the HW structure
1428 * @iterations: number of times to poll for link
1429 * @usec_interval: delay between polling attempts
1430 * @success: pointer to whether polling was successful or not
1431 *
1432 * Polls the PHY status register for link, 'iterations' number of times.
1433 **/
1434s32 igb_phy_has_link(struct e1000_hw *hw, u32 iterations,
1435 u32 usec_interval, bool *success)
1436{
1437 s32 ret_val = 0;
1438 u16 i, phy_status;
1439
1440 for (i = 0; i < iterations; i++) {
1441 /*
1442 * Some PHYs require the PHY_STATUS register to be read
1443 * twice due to the link bit being sticky. No harm doing
1444 * it across the board.
1445 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001446 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
Alexander Duyckab576382009-10-05 06:35:23 +00001447 if (ret_val) {
1448 /*
1449 * If the first read fails, another entity may have
1450 * ownership of the resources, wait and try again to
1451 * see if they have relinquished the resources yet.
1452 */
1453 udelay(usec_interval);
1454 }
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001455 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
Auke Kok9d5c8242008-01-24 02:22:38 -08001456 if (ret_val)
1457 break;
1458 if (phy_status & MII_SR_LINK_STATUS)
1459 break;
1460 if (usec_interval >= 1000)
1461 mdelay(usec_interval/1000);
1462 else
1463 udelay(usec_interval);
1464 }
1465
1466 *success = (i < iterations) ? true : false;
1467
1468 return ret_val;
1469}
1470
1471/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001472 * igb_get_cable_length_m88 - Determine cable length for m88 PHY
Auke Kok9d5c8242008-01-24 02:22:38 -08001473 * @hw: pointer to the HW structure
1474 *
1475 * Reads the PHY specific status register to retrieve the cable length
1476 * information. The cable length is determined by averaging the minimum and
1477 * maximum values to get the "average" cable length. The m88 PHY has four
1478 * possible cable length values, which are:
1479 * Register Value Cable Length
1480 * 0 < 50 meters
1481 * 1 50 - 80 meters
1482 * 2 80 - 110 meters
1483 * 3 110 - 140 meters
1484 * 4 > 140 meters
1485 **/
1486s32 igb_get_cable_length_m88(struct e1000_hw *hw)
1487{
1488 struct e1000_phy_info *phy = &hw->phy;
1489 s32 ret_val;
1490 u16 phy_data, index;
1491
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001492 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001493 if (ret_val)
1494 goto out;
1495
1496 index = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
1497 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
1498 phy->min_cable_length = e1000_m88_cable_length_table[index];
1499 phy->max_cable_length = e1000_m88_cable_length_table[index+1];
1500
1501 phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
1502
1503out:
1504 return ret_val;
1505}
1506
1507/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001508 * igb_get_cable_length_igp_2 - Determine cable length for igp2 PHY
Auke Kok9d5c8242008-01-24 02:22:38 -08001509 * @hw: pointer to the HW structure
1510 *
1511 * The automatic gain control (agc) normalizes the amplitude of the
1512 * received signal, adjusting for the attenuation produced by the
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001513 * cable. By reading the AGC registers, which represent the
1514 * combination of coarse and fine gain value, the value can be put
Auke Kok9d5c8242008-01-24 02:22:38 -08001515 * into a lookup table to obtain the approximate cable length
1516 * for each channel.
1517 **/
1518s32 igb_get_cable_length_igp_2(struct e1000_hw *hw)
1519{
1520 struct e1000_phy_info *phy = &hw->phy;
1521 s32 ret_val = 0;
1522 u16 phy_data, i, agc_value = 0;
1523 u16 cur_agc_index, max_agc_index = 0;
1524 u16 min_agc_index = IGP02E1000_CABLE_LENGTH_TABLE_SIZE - 1;
1525 u16 agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] =
1526 {IGP02E1000_PHY_AGC_A,
1527 IGP02E1000_PHY_AGC_B,
1528 IGP02E1000_PHY_AGC_C,
1529 IGP02E1000_PHY_AGC_D};
1530
1531 /* Read the AGC registers for all channels */
1532 for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001533 ret_val = phy->ops.read_reg(hw, agc_reg_array[i], &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001534 if (ret_val)
1535 goto out;
1536
1537 /*
1538 * Getting bits 15:9, which represent the combination of
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001539 * coarse and fine gain values. The result is a number
Auke Kok9d5c8242008-01-24 02:22:38 -08001540 * that can be put into the lookup table to obtain the
1541 * approximate cable length.
1542 */
1543 cur_agc_index = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
1544 IGP02E1000_AGC_LENGTH_MASK;
1545
1546 /* Array index bound check. */
1547 if ((cur_agc_index >= IGP02E1000_CABLE_LENGTH_TABLE_SIZE) ||
1548 (cur_agc_index == 0)) {
1549 ret_val = -E1000_ERR_PHY;
1550 goto out;
1551 }
1552
1553 /* Remove min & max AGC values from calculation. */
1554 if (e1000_igp_2_cable_length_table[min_agc_index] >
1555 e1000_igp_2_cable_length_table[cur_agc_index])
1556 min_agc_index = cur_agc_index;
1557 if (e1000_igp_2_cable_length_table[max_agc_index] <
1558 e1000_igp_2_cable_length_table[cur_agc_index])
1559 max_agc_index = cur_agc_index;
1560
1561 agc_value += e1000_igp_2_cable_length_table[cur_agc_index];
1562 }
1563
1564 agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] +
1565 e1000_igp_2_cable_length_table[max_agc_index]);
1566 agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
1567
1568 /* Calculate cable length with the error range of +/- 10 meters. */
1569 phy->min_cable_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
1570 (agc_value - IGP02E1000_AGC_RANGE) : 0;
1571 phy->max_cable_length = agc_value + IGP02E1000_AGC_RANGE;
1572
1573 phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
1574
1575out:
1576 return ret_val;
1577}
1578
1579/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001580 * igb_get_phy_info_m88 - Retrieve PHY information
Auke Kok9d5c8242008-01-24 02:22:38 -08001581 * @hw: pointer to the HW structure
1582 *
1583 * Valid for only copper links. Read the PHY status register (sticky read)
1584 * to verify that link is up. Read the PHY special control register to
1585 * determine the polarity and 10base-T extended distance. Read the PHY
1586 * special status register to determine MDI/MDIx and current speed. If
1587 * speed is 1000, then determine cable length, local and remote receiver.
1588 **/
1589s32 igb_get_phy_info_m88(struct e1000_hw *hw)
1590{
1591 struct e1000_phy_info *phy = &hw->phy;
1592 s32 ret_val;
1593 u16 phy_data;
1594 bool link;
1595
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001596 if (phy->media_type != e1000_media_type_copper) {
Auke Kok652fff32008-06-27 11:00:18 -07001597 hw_dbg("Phy info is only valid for copper media\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001598 ret_val = -E1000_ERR_CONFIG;
1599 goto out;
1600 }
1601
1602 ret_val = igb_phy_has_link(hw, 1, 0, &link);
1603 if (ret_val)
1604 goto out;
1605
1606 if (!link) {
Auke Kok652fff32008-06-27 11:00:18 -07001607 hw_dbg("Phy info is only valid if link is up\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001608 ret_val = -E1000_ERR_CONFIG;
1609 goto out;
1610 }
1611
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001612 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001613 if (ret_val)
1614 goto out;
1615
1616 phy->polarity_correction = (phy_data & M88E1000_PSCR_POLARITY_REVERSAL)
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001617 ? true : false;
Auke Kok9d5c8242008-01-24 02:22:38 -08001618
1619 ret_val = igb_check_polarity_m88(hw);
1620 if (ret_val)
1621 goto out;
1622
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001623 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001624 if (ret_val)
1625 goto out;
1626
1627 phy->is_mdix = (phy_data & M88E1000_PSSR_MDIX) ? true : false;
1628
1629 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001630 ret_val = phy->ops.get_cable_length(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001631 if (ret_val)
1632 goto out;
1633
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001634 ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001635 if (ret_val)
1636 goto out;
1637
1638 phy->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS)
1639 ? e1000_1000t_rx_status_ok
1640 : e1000_1000t_rx_status_not_ok;
1641
1642 phy->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS)
1643 ? e1000_1000t_rx_status_ok
1644 : e1000_1000t_rx_status_not_ok;
1645 } else {
1646 /* Set values to "undefined" */
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_get_phy_info_igp - Retrieve igp PHY information
Auke Kok9d5c8242008-01-24 02:22:38 -08001658 * @hw: pointer to the HW structure
1659 *
1660 * Read PHY status to determine if link is up. If link is up, then
1661 * set/determine 10base-T extended distance and polarity correction. Read
1662 * PHY port status to determine MDI/MDIx and speed. Based on the speed,
1663 * determine on the cable length, local and remote receiver.
1664 **/
1665s32 igb_get_phy_info_igp(struct e1000_hw *hw)
1666{
1667 struct e1000_phy_info *phy = &hw->phy;
1668 s32 ret_val;
1669 u16 data;
1670 bool link;
1671
1672 ret_val = igb_phy_has_link(hw, 1, 0, &link);
1673 if (ret_val)
1674 goto out;
1675
1676 if (!link) {
Auke Kok652fff32008-06-27 11:00:18 -07001677 hw_dbg("Phy info is only valid if link is up\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001678 ret_val = -E1000_ERR_CONFIG;
1679 goto out;
1680 }
1681
1682 phy->polarity_correction = true;
1683
1684 ret_val = igb_check_polarity_igp(hw);
1685 if (ret_val)
1686 goto out;
1687
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001688 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_STATUS, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001689 if (ret_val)
1690 goto out;
1691
1692 phy->is_mdix = (data & IGP01E1000_PSSR_MDIX) ? true : false;
1693
1694 if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
1695 IGP01E1000_PSSR_SPEED_1000MBPS) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001696 ret_val = phy->ops.get_cable_length(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001697 if (ret_val)
1698 goto out;
1699
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001700 ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001701 if (ret_val)
1702 goto out;
1703
1704 phy->local_rx = (data & SR_1000T_LOCAL_RX_STATUS)
1705 ? e1000_1000t_rx_status_ok
1706 : e1000_1000t_rx_status_not_ok;
1707
1708 phy->remote_rx = (data & SR_1000T_REMOTE_RX_STATUS)
1709 ? e1000_1000t_rx_status_ok
1710 : e1000_1000t_rx_status_not_ok;
1711 } else {
1712 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
1713 phy->local_rx = e1000_1000t_rx_status_undefined;
1714 phy->remote_rx = e1000_1000t_rx_status_undefined;
1715 }
1716
1717out:
1718 return ret_val;
1719}
1720
1721/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001722 * igb_phy_sw_reset - PHY software reset
Auke Kok9d5c8242008-01-24 02:22:38 -08001723 * @hw: pointer to the HW structure
1724 *
1725 * Does a software reset of the PHY by reading the PHY control register and
1726 * setting/write the control register reset bit to the PHY.
1727 **/
1728s32 igb_phy_sw_reset(struct e1000_hw *hw)
1729{
Alexander Duyckd3147372009-09-14 08:23:13 +00001730 s32 ret_val = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08001731 u16 phy_ctrl;
1732
Alexander Duyckd3147372009-09-14 08:23:13 +00001733 if (!(hw->phy.ops.read_reg))
1734 goto out;
1735
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001736 ret_val = hw->phy.ops.read_reg(hw, PHY_CONTROL, &phy_ctrl);
Auke Kok9d5c8242008-01-24 02:22:38 -08001737 if (ret_val)
1738 goto out;
1739
1740 phy_ctrl |= MII_CR_RESET;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001741 ret_val = hw->phy.ops.write_reg(hw, PHY_CONTROL, phy_ctrl);
Auke Kok9d5c8242008-01-24 02:22:38 -08001742 if (ret_val)
1743 goto out;
1744
1745 udelay(1);
1746
1747out:
1748 return ret_val;
1749}
1750
1751/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001752 * igb_phy_hw_reset - PHY hardware reset
Auke Kok9d5c8242008-01-24 02:22:38 -08001753 * @hw: pointer to the HW structure
1754 *
1755 * Verify the reset block is not blocking us from resetting. Acquire
1756 * semaphore (if necessary) and read/set/write the device control reset
1757 * bit in the PHY. Wait the appropriate delay time for the device to
1758 * reset and relase the semaphore (if necessary).
1759 **/
1760s32 igb_phy_hw_reset(struct e1000_hw *hw)
1761{
1762 struct e1000_phy_info *phy = &hw->phy;
1763 s32 ret_val;
1764 u32 ctrl;
1765
1766 ret_val = igb_check_reset_block(hw);
1767 if (ret_val) {
1768 ret_val = 0;
1769 goto out;
1770 }
1771
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001772 ret_val = phy->ops.acquire(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001773 if (ret_val)
1774 goto out;
1775
1776 ctrl = rd32(E1000_CTRL);
1777 wr32(E1000_CTRL, ctrl | E1000_CTRL_PHY_RST);
1778 wrfl();
1779
1780 udelay(phy->reset_delay_us);
1781
1782 wr32(E1000_CTRL, ctrl);
1783 wrfl();
1784
1785 udelay(150);
1786
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001787 phy->ops.release(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001788
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001789 ret_val = phy->ops.get_cfg_done(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001790
1791out:
1792 return ret_val;
1793}
1794
Auke Kok9d5c8242008-01-24 02:22:38 -08001795/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001796 * igb_phy_init_script_igp3 - Inits the IGP3 PHY
Auke Kok9d5c8242008-01-24 02:22:38 -08001797 * @hw: pointer to the HW structure
1798 *
1799 * Initializes a Intel Gigabit PHY3 when an EEPROM is not present.
1800 **/
1801s32 igb_phy_init_script_igp3(struct e1000_hw *hw)
1802{
Auke Kok652fff32008-06-27 11:00:18 -07001803 hw_dbg("Running IGP 3 PHY init script\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001804
1805 /* PHY init IGP 3 */
1806 /* Enable rise/fall, 10-mode work in class-A */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001807 hw->phy.ops.write_reg(hw, 0x2F5B, 0x9018);
Auke Kok9d5c8242008-01-24 02:22:38 -08001808 /* Remove all caps from Replica path filter */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001809 hw->phy.ops.write_reg(hw, 0x2F52, 0x0000);
Auke Kok9d5c8242008-01-24 02:22:38 -08001810 /* Bias trimming for ADC, AFE and Driver (Default) */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001811 hw->phy.ops.write_reg(hw, 0x2FB1, 0x8B24);
Auke Kok9d5c8242008-01-24 02:22:38 -08001812 /* Increase Hybrid poly bias */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001813 hw->phy.ops.write_reg(hw, 0x2FB2, 0xF8F0);
Auke Kok9d5c8242008-01-24 02:22:38 -08001814 /* Add 4% to TX amplitude in Giga mode */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001815 hw->phy.ops.write_reg(hw, 0x2010, 0x10B0);
Auke Kok9d5c8242008-01-24 02:22:38 -08001816 /* Disable trimming (TTT) */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001817 hw->phy.ops.write_reg(hw, 0x2011, 0x0000);
Auke Kok9d5c8242008-01-24 02:22:38 -08001818 /* Poly DC correction to 94.6% + 2% for all channels */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001819 hw->phy.ops.write_reg(hw, 0x20DD, 0x249A);
Auke Kok9d5c8242008-01-24 02:22:38 -08001820 /* ABS DC correction to 95.9% */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001821 hw->phy.ops.write_reg(hw, 0x20DE, 0x00D3);
Auke Kok9d5c8242008-01-24 02:22:38 -08001822 /* BG temp curve trim */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001823 hw->phy.ops.write_reg(hw, 0x28B4, 0x04CE);
Auke Kok9d5c8242008-01-24 02:22:38 -08001824 /* Increasing ADC OPAMP stage 1 currents to max */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001825 hw->phy.ops.write_reg(hw, 0x2F70, 0x29E4);
Auke Kok9d5c8242008-01-24 02:22:38 -08001826 /* Force 1000 ( required for enabling PHY regs configuration) */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001827 hw->phy.ops.write_reg(hw, 0x0000, 0x0140);
Auke Kok9d5c8242008-01-24 02:22:38 -08001828 /* Set upd_freq to 6 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001829 hw->phy.ops.write_reg(hw, 0x1F30, 0x1606);
Auke Kok9d5c8242008-01-24 02:22:38 -08001830 /* Disable NPDFE */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001831 hw->phy.ops.write_reg(hw, 0x1F31, 0xB814);
Auke Kok9d5c8242008-01-24 02:22:38 -08001832 /* Disable adaptive fixed FFE (Default) */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001833 hw->phy.ops.write_reg(hw, 0x1F35, 0x002A);
Auke Kok9d5c8242008-01-24 02:22:38 -08001834 /* Enable FFE hysteresis */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001835 hw->phy.ops.write_reg(hw, 0x1F3E, 0x0067);
Auke Kok9d5c8242008-01-24 02:22:38 -08001836 /* Fixed FFE for short cable lengths */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001837 hw->phy.ops.write_reg(hw, 0x1F54, 0x0065);
Auke Kok9d5c8242008-01-24 02:22:38 -08001838 /* Fixed FFE for medium cable lengths */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001839 hw->phy.ops.write_reg(hw, 0x1F55, 0x002A);
Auke Kok9d5c8242008-01-24 02:22:38 -08001840 /* Fixed FFE for long cable lengths */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001841 hw->phy.ops.write_reg(hw, 0x1F56, 0x002A);
Auke Kok9d5c8242008-01-24 02:22:38 -08001842 /* Enable Adaptive Clip Threshold */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001843 hw->phy.ops.write_reg(hw, 0x1F72, 0x3FB0);
Auke Kok9d5c8242008-01-24 02:22:38 -08001844 /* AHT reset limit to 1 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001845 hw->phy.ops.write_reg(hw, 0x1F76, 0xC0FF);
Auke Kok9d5c8242008-01-24 02:22:38 -08001846 /* Set AHT master delay to 127 msec */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001847 hw->phy.ops.write_reg(hw, 0x1F77, 0x1DEC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001848 /* Set scan bits for AHT */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001849 hw->phy.ops.write_reg(hw, 0x1F78, 0xF9EF);
Auke Kok9d5c8242008-01-24 02:22:38 -08001850 /* Set AHT Preset bits */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001851 hw->phy.ops.write_reg(hw, 0x1F79, 0x0210);
Auke Kok9d5c8242008-01-24 02:22:38 -08001852 /* Change integ_factor of channel A to 3 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001853 hw->phy.ops.write_reg(hw, 0x1895, 0x0003);
Auke Kok9d5c8242008-01-24 02:22:38 -08001854 /* Change prop_factor of channels BCD to 8 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001855 hw->phy.ops.write_reg(hw, 0x1796, 0x0008);
Auke Kok9d5c8242008-01-24 02:22:38 -08001856 /* Change cg_icount + enable integbp for channels BCD */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001857 hw->phy.ops.write_reg(hw, 0x1798, 0xD008);
Auke Kok9d5c8242008-01-24 02:22:38 -08001858 /*
1859 * Change cg_icount + enable integbp + change prop_factor_master
1860 * to 8 for channel A
1861 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001862 hw->phy.ops.write_reg(hw, 0x1898, 0xD918);
Auke Kok9d5c8242008-01-24 02:22:38 -08001863 /* Disable AHT in Slave mode on channel A */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001864 hw->phy.ops.write_reg(hw, 0x187A, 0x0800);
Auke Kok9d5c8242008-01-24 02:22:38 -08001865 /*
1866 * Enable LPLU and disable AN to 1000 in non-D0a states,
1867 * Enable SPD+B2B
1868 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001869 hw->phy.ops.write_reg(hw, 0x0019, 0x008D);
Auke Kok9d5c8242008-01-24 02:22:38 -08001870 /* Enable restart AN on an1000_dis change */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001871 hw->phy.ops.write_reg(hw, 0x001B, 0x2080);
Auke Kok9d5c8242008-01-24 02:22:38 -08001872 /* Enable wh_fifo read clock in 10/100 modes */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001873 hw->phy.ops.write_reg(hw, 0x0014, 0x0045);
Auke Kok9d5c8242008-01-24 02:22:38 -08001874 /* Restart AN, Speed selection is 1000 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001875 hw->phy.ops.write_reg(hw, 0x0000, 0x1340);
Auke Kok9d5c8242008-01-24 02:22:38 -08001876
1877 return 0;
1878}
1879