blob: b8fbc8558fe20dc59e28d8860dd7a8f19f26ac9a [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 };
Alexander Duyck2553bb22009-10-05 06:35:42 +000042#define M88E1000_CABLE_LENGTH_TABLE_SIZE \
43 (sizeof(e1000_m88_cable_length_table) / \
44 sizeof(e1000_m88_cable_length_table[0]))
Auke Kok9d5c8242008-01-24 02:22:38 -080045
46static const u16 e1000_igp_2_cable_length_table[] =
47 { 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21,
48 0, 0, 0, 3, 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41,
49 6, 10, 14, 18, 22, 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61,
50 21, 26, 31, 35, 40, 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82,
51 40, 45, 51, 56, 61, 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104,
52 60, 66, 72, 77, 82, 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121,
53 83, 89, 95, 100, 105, 109, 113, 116, 119, 122, 124,
54 104, 109, 114, 118, 121, 124};
55#define IGP02E1000_CABLE_LENGTH_TABLE_SIZE \
56 (sizeof(e1000_igp_2_cable_length_table) / \
57 sizeof(e1000_igp_2_cable_length_table[0]))
58
59/**
Jeff Kirsher733596b2008-06-27 10:59:59 -070060 * igb_check_reset_block - Check if PHY reset is blocked
Auke Kok9d5c8242008-01-24 02:22:38 -080061 * @hw: pointer to the HW structure
62 *
63 * Read the PHY management control register and check whether a PHY reset
64 * is blocked. If a reset is not blocked return 0, otherwise
65 * return E1000_BLK_PHY_RESET (12).
66 **/
67s32 igb_check_reset_block(struct e1000_hw *hw)
68{
69 u32 manc;
70
71 manc = rd32(E1000_MANC);
72
73 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
74 E1000_BLK_PHY_RESET : 0;
75}
76
77/**
Jeff Kirsher733596b2008-06-27 10:59:59 -070078 * igb_get_phy_id - Retrieve the PHY ID and revision
Auke Kok9d5c8242008-01-24 02:22:38 -080079 * @hw: pointer to the HW structure
80 *
81 * Reads the PHY registers and stores the PHY ID and possibly the PHY
82 * revision in the hardware structure.
83 **/
84s32 igb_get_phy_id(struct e1000_hw *hw)
85{
86 struct e1000_phy_info *phy = &hw->phy;
87 s32 ret_val = 0;
88 u16 phy_id;
89
Alexander Duycka8d2a0c2009-02-06 23:17:26 +000090 ret_val = phy->ops.read_reg(hw, PHY_ID1, &phy_id);
Auke Kok9d5c8242008-01-24 02:22:38 -080091 if (ret_val)
92 goto out;
93
94 phy->id = (u32)(phy_id << 16);
95 udelay(20);
Alexander Duycka8d2a0c2009-02-06 23:17:26 +000096 ret_val = phy->ops.read_reg(hw, PHY_ID2, &phy_id);
Auke Kok9d5c8242008-01-24 02:22:38 -080097 if (ret_val)
98 goto out;
99
100 phy->id |= (u32)(phy_id & PHY_REVISION_MASK);
101 phy->revision = (u32)(phy_id & ~PHY_REVISION_MASK);
102
103out:
104 return ret_val;
105}
106
107/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700108 * igb_phy_reset_dsp - Reset PHY DSP
Auke Kok9d5c8242008-01-24 02:22:38 -0800109 * @hw: pointer to the HW structure
110 *
111 * Reset the digital signal processor.
112 **/
113static s32 igb_phy_reset_dsp(struct e1000_hw *hw)
114{
Alexander Duyck2553bb22009-10-05 06:35:42 +0000115 s32 ret_val = 0;
116
117 if (!(hw->phy.ops.write_reg))
118 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800119
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000120 ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xC1);
Auke Kok9d5c8242008-01-24 02:22:38 -0800121 if (ret_val)
122 goto out;
123
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000124 ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0);
Auke Kok9d5c8242008-01-24 02:22:38 -0800125
126out:
127 return ret_val;
128}
129
130/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700131 * igb_read_phy_reg_mdic - Read MDI control register
Auke Kok9d5c8242008-01-24 02:22:38 -0800132 * @hw: pointer to the HW structure
133 * @offset: register offset to be read
134 * @data: pointer to the read data
135 *
136 * Reads the MDI control regsiter in the PHY at offset and stores the
137 * information read to data.
138 **/
139static s32 igb_read_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 *data)
140{
141 struct e1000_phy_info *phy = &hw->phy;
142 u32 i, mdic = 0;
143 s32 ret_val = 0;
144
145 if (offset > MAX_PHY_REG_ADDRESS) {
Auke Kok652fff32008-06-27 11:00:18 -0700146 hw_dbg("PHY Address %d is out of range\n", offset);
Auke Kok9d5c8242008-01-24 02:22:38 -0800147 ret_val = -E1000_ERR_PARAM;
148 goto out;
149 }
150
151 /*
152 * Set up Op-code, Phy Address, and register offset in the MDI
153 * Control register. The MAC will take care of interfacing with the
154 * PHY to retrieve the desired data.
155 */
156 mdic = ((offset << E1000_MDIC_REG_SHIFT) |
157 (phy->addr << E1000_MDIC_PHY_SHIFT) |
158 (E1000_MDIC_OP_READ));
159
160 wr32(E1000_MDIC, mdic);
161
162 /*
163 * Poll the ready bit to see if the MDI read completed
164 * Increasing the time out as testing showed failures with
165 * the lower time out
166 */
167 for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
168 udelay(50);
169 mdic = rd32(E1000_MDIC);
170 if (mdic & E1000_MDIC_READY)
171 break;
172 }
173 if (!(mdic & E1000_MDIC_READY)) {
Auke Kok652fff32008-06-27 11:00:18 -0700174 hw_dbg("MDI Read did not complete\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800175 ret_val = -E1000_ERR_PHY;
176 goto out;
177 }
178 if (mdic & E1000_MDIC_ERROR) {
Auke Kok652fff32008-06-27 11:00:18 -0700179 hw_dbg("MDI Error\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800180 ret_val = -E1000_ERR_PHY;
181 goto out;
182 }
183 *data = (u16) mdic;
184
185out:
186 return ret_val;
187}
188
189/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700190 * igb_write_phy_reg_mdic - Write MDI control register
Auke Kok9d5c8242008-01-24 02:22:38 -0800191 * @hw: pointer to the HW structure
192 * @offset: register offset to write to
193 * @data: data to write to register at offset
194 *
195 * Writes data to MDI control register in the PHY at offset.
196 **/
197static s32 igb_write_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 data)
198{
199 struct e1000_phy_info *phy = &hw->phy;
200 u32 i, mdic = 0;
201 s32 ret_val = 0;
202
203 if (offset > MAX_PHY_REG_ADDRESS) {
Auke Kok652fff32008-06-27 11:00:18 -0700204 hw_dbg("PHY Address %d is out of range\n", offset);
Auke Kok9d5c8242008-01-24 02:22:38 -0800205 ret_val = -E1000_ERR_PARAM;
206 goto out;
207 }
208
209 /*
210 * Set up Op-code, Phy Address, and register offset in the MDI
211 * Control register. The MAC will take care of interfacing with the
212 * PHY to retrieve the desired data.
213 */
214 mdic = (((u32)data) |
215 (offset << E1000_MDIC_REG_SHIFT) |
216 (phy->addr << E1000_MDIC_PHY_SHIFT) |
217 (E1000_MDIC_OP_WRITE));
218
219 wr32(E1000_MDIC, mdic);
220
221 /*
222 * Poll the ready bit to see if the MDI read completed
223 * Increasing the time out as testing showed failures with
224 * the lower time out
225 */
226 for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
227 udelay(50);
228 mdic = rd32(E1000_MDIC);
229 if (mdic & E1000_MDIC_READY)
230 break;
231 }
232 if (!(mdic & E1000_MDIC_READY)) {
Auke Kok652fff32008-06-27 11:00:18 -0700233 hw_dbg("MDI Write did not complete\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800234 ret_val = -E1000_ERR_PHY;
235 goto out;
236 }
237 if (mdic & E1000_MDIC_ERROR) {
Auke Kok652fff32008-06-27 11:00:18 -0700238 hw_dbg("MDI Error\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800239 ret_val = -E1000_ERR_PHY;
240 goto out;
241 }
242
243out:
244 return ret_val;
245}
246
247/**
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000248 * igb_read_phy_reg_i2c - Read PHY register using i2c
249 * @hw: pointer to the HW structure
250 * @offset: register offset to be read
251 * @data: pointer to the read data
252 *
253 * Reads the PHY register at offset using the i2c interface and stores the
254 * retrieved information in data.
255 **/
256s32 igb_read_phy_reg_i2c(struct e1000_hw *hw, u32 offset, u16 *data)
257{
258 struct e1000_phy_info *phy = &hw->phy;
259 u32 i, i2ccmd = 0;
260
261
262 /*
263 * Set up Op-code, Phy Address, and register address in the I2CCMD
264 * register. The MAC will take care of interfacing with the
265 * PHY to retrieve the desired data.
266 */
267 i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) |
268 (phy->addr << E1000_I2CCMD_PHY_ADDR_SHIFT) |
269 (E1000_I2CCMD_OPCODE_READ));
270
271 wr32(E1000_I2CCMD, i2ccmd);
272
273 /* Poll the ready bit to see if the I2C read completed */
274 for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) {
275 udelay(50);
276 i2ccmd = rd32(E1000_I2CCMD);
277 if (i2ccmd & E1000_I2CCMD_READY)
278 break;
279 }
280 if (!(i2ccmd & E1000_I2CCMD_READY)) {
281 hw_dbg("I2CCMD Read did not complete\n");
282 return -E1000_ERR_PHY;
283 }
284 if (i2ccmd & E1000_I2CCMD_ERROR) {
285 hw_dbg("I2CCMD Error bit set\n");
286 return -E1000_ERR_PHY;
287 }
288
289 /* Need to byte-swap the 16-bit value. */
290 *data = ((i2ccmd >> 8) & 0x00FF) | ((i2ccmd << 8) & 0xFF00);
291
292 return 0;
293}
294
295/**
296 * igb_write_phy_reg_i2c - Write PHY register using i2c
297 * @hw: pointer to the HW structure
298 * @offset: register offset to write to
299 * @data: data to write at register offset
300 *
301 * Writes the data to PHY register at the offset using the i2c interface.
302 **/
303s32 igb_write_phy_reg_i2c(struct e1000_hw *hw, u32 offset, u16 data)
304{
305 struct e1000_phy_info *phy = &hw->phy;
306 u32 i, i2ccmd = 0;
307 u16 phy_data_swapped;
308
309
310 /* Swap the data bytes for the I2C interface */
311 phy_data_swapped = ((data >> 8) & 0x00FF) | ((data << 8) & 0xFF00);
312
313 /*
314 * Set up Op-code, Phy Address, and register address in the I2CCMD
315 * register. The MAC will take care of interfacing with the
316 * PHY to retrieve the desired data.
317 */
318 i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) |
319 (phy->addr << E1000_I2CCMD_PHY_ADDR_SHIFT) |
320 E1000_I2CCMD_OPCODE_WRITE |
321 phy_data_swapped);
322
323 wr32(E1000_I2CCMD, i2ccmd);
324
325 /* Poll the ready bit to see if the I2C read completed */
326 for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) {
327 udelay(50);
328 i2ccmd = rd32(E1000_I2CCMD);
329 if (i2ccmd & E1000_I2CCMD_READY)
330 break;
331 }
332 if (!(i2ccmd & E1000_I2CCMD_READY)) {
333 hw_dbg("I2CCMD Write did not complete\n");
334 return -E1000_ERR_PHY;
335 }
336 if (i2ccmd & E1000_I2CCMD_ERROR) {
337 hw_dbg("I2CCMD Error bit set\n");
338 return -E1000_ERR_PHY;
339 }
340
341 return 0;
342}
343
344/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700345 * igb_read_phy_reg_igp - Read igp PHY register
Auke Kok9d5c8242008-01-24 02:22:38 -0800346 * @hw: pointer to the HW structure
347 * @offset: register offset to be read
348 * @data: pointer to the read data
349 *
350 * Acquires semaphore, if necessary, then reads the PHY register at offset
351 * and storing the retrieved information in data. Release any acquired
352 * semaphores before exiting.
353 **/
354s32 igb_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data)
355{
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000356 s32 ret_val = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -0800357
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000358 if (!(hw->phy.ops.acquire))
359 goto out;
360
361 ret_val = hw->phy.ops.acquire(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800362 if (ret_val)
363 goto out;
364
365 if (offset > MAX_PHY_MULTI_PAGE_REG) {
366 ret_val = igb_write_phy_reg_mdic(hw,
367 IGP01E1000_PHY_PAGE_SELECT,
368 (u16)offset);
369 if (ret_val) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000370 hw->phy.ops.release(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800371 goto out;
372 }
373 }
374
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000375 ret_val = igb_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
376 data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800377
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000378 hw->phy.ops.release(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800379
380out:
381 return ret_val;
382}
383
384/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700385 * igb_write_phy_reg_igp - Write igp PHY register
Auke Kok9d5c8242008-01-24 02:22:38 -0800386 * @hw: pointer to the HW structure
387 * @offset: register offset to write to
388 * @data: data to write at register offset
389 *
390 * Acquires semaphore, if necessary, then writes the data to PHY register
391 * at the offset. Release any acquired semaphores before exiting.
392 **/
393s32 igb_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data)
394{
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000395 s32 ret_val = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -0800396
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000397 if (!(hw->phy.ops.acquire))
398 goto out;
399
400 ret_val = hw->phy.ops.acquire(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800401 if (ret_val)
402 goto out;
403
404 if (offset > MAX_PHY_MULTI_PAGE_REG) {
405 ret_val = igb_write_phy_reg_mdic(hw,
406 IGP01E1000_PHY_PAGE_SELECT,
407 (u16)offset);
408 if (ret_val) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000409 hw->phy.ops.release(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800410 goto out;
411 }
412 }
413
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000414 ret_val = igb_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
Auke Kok9d5c8242008-01-24 02:22:38 -0800415 data);
416
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000417 hw->phy.ops.release(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800418
419out:
420 return ret_val;
421}
422
423/**
Alexander Duyck2909c3f2009-11-19 12:41:42 +0000424 * igb_copper_link_setup_82580 - Setup 82580 PHY for copper link
425 * @hw: pointer to the HW structure
426 *
427 * Sets up Carrier-sense on Transmit and downshift values.
428 **/
429s32 igb_copper_link_setup_82580(struct e1000_hw *hw)
430{
431 struct e1000_phy_info *phy = &hw->phy;
432 s32 ret_val;
433 u16 phy_data;
434
435
436 if (phy->reset_disable) {
437 ret_val = 0;
438 goto out;
439 }
440
441 if (phy->type == e1000_phy_82580) {
442 ret_val = hw->phy.ops.reset(hw);
443 if (ret_val) {
444 hw_dbg("Error resetting the PHY.\n");
445 goto out;
446 }
447 }
448
449 /* Enable CRS on TX. This must be set for half-duplex operation. */
450 ret_val = phy->ops.read_reg(hw, I82580_CFG_REG, &phy_data);
451 if (ret_val)
452 goto out;
453
454 phy_data |= I82580_CFG_ASSERT_CRS_ON_TX;
455
456 /* Enable downshift */
457 phy_data |= I82580_CFG_ENABLE_DOWNSHIFT;
458
459 ret_val = phy->ops.write_reg(hw, I82580_CFG_REG, phy_data);
460 if (ret_val)
461 goto out;
462
463 /* Set number of link attempts before downshift */
464 ret_val = phy->ops.read_reg(hw, I82580_CTRL_REG, &phy_data);
465 if (ret_val)
466 goto out;
467 phy_data &= ~I82580_CTRL_DOWNSHIFT_MASK;
468 ret_val = phy->ops.write_reg(hw, I82580_CTRL_REG, phy_data);
469
470out:
471 return ret_val;
472}
473
474/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700475 * igb_copper_link_setup_m88 - Setup m88 PHY's for copper link
Auke Kok9d5c8242008-01-24 02:22:38 -0800476 * @hw: pointer to the HW structure
477 *
478 * Sets up MDI/MDI-X and polarity for m88 PHY's. If necessary, transmit clock
479 * and downshift values are set also.
480 **/
481s32 igb_copper_link_setup_m88(struct e1000_hw *hw)
482{
483 struct e1000_phy_info *phy = &hw->phy;
484 s32 ret_val;
485 u16 phy_data;
486
487 if (phy->reset_disable) {
488 ret_val = 0;
489 goto out;
490 }
491
492 /* Enable CRS on TX. This must be set for half-duplex operation. */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000493 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800494 if (ret_val)
495 goto out;
496
497 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
498
499 /*
500 * Options:
501 * MDI/MDI-X = 0 (default)
502 * 0 - Auto for all speeds
503 * 1 - MDI mode
504 * 2 - MDI-X mode
505 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
506 */
507 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
508
509 switch (phy->mdix) {
510 case 1:
511 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
512 break;
513 case 2:
514 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
515 break;
516 case 3:
517 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
518 break;
519 case 0:
520 default:
521 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
522 break;
523 }
524
525 /*
526 * Options:
527 * disable_polarity_correction = 0 (default)
528 * Automatic Correction for Reversed Cable Polarity
529 * 0 - Disabled
530 * 1 - Enabled
531 */
532 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
533 if (phy->disable_polarity_correction == 1)
534 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
535
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000536 ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800537 if (ret_val)
538 goto out;
539
540 if (phy->revision < E1000_REVISION_4) {
541 /*
542 * Force TX_CLK in the Extended PHY Specific Control Register
543 * to 25MHz clock.
544 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000545 ret_val = phy->ops.read_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
Auke Kok9d5c8242008-01-24 02:22:38 -0800546 &phy_data);
547 if (ret_val)
548 goto out;
549
550 phy_data |= M88E1000_EPSCR_TX_CLK_25;
551
552 if ((phy->revision == E1000_REVISION_2) &&
553 (phy->id == M88E1111_I_PHY_ID)) {
554 /* 82573L PHY - set the downshift counter to 5x. */
555 phy_data &= ~M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK;
556 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
557 } else {
558 /* Configure Master and Slave downshift values */
559 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
560 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
561 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
562 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
563 }
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000564 ret_val = phy->ops.write_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
Auke Kok9d5c8242008-01-24 02:22:38 -0800565 phy_data);
566 if (ret_val)
567 goto out;
568 }
569
570 /* Commit the changes. */
571 ret_val = igb_phy_sw_reset(hw);
572 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700573 hw_dbg("Error committing the PHY changes\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800574 goto out;
575 }
576
577out:
578 return ret_val;
579}
580
581/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700582 * igb_copper_link_setup_igp - Setup igp PHY's for copper link
Auke Kok9d5c8242008-01-24 02:22:38 -0800583 * @hw: pointer to the HW structure
584 *
585 * Sets up LPLU, MDI/MDI-X, polarity, Smartspeed and Master/Slave config for
586 * igp PHY's.
587 **/
588s32 igb_copper_link_setup_igp(struct e1000_hw *hw)
589{
590 struct e1000_phy_info *phy = &hw->phy;
591 s32 ret_val;
592 u16 data;
593
594 if (phy->reset_disable) {
595 ret_val = 0;
596 goto out;
597 }
598
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000599 ret_val = phy->ops.reset(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800600 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700601 hw_dbg("Error resetting the PHY.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800602 goto out;
603 }
604
Alexander Duycka6a60562009-03-31 20:38:38 +0000605 /*
606 * Wait 100ms for MAC to configure PHY from NVM settings, to avoid
607 * timeout issues when LFS is enabled.
608 */
609 msleep(100);
Auke Kok9d5c8242008-01-24 02:22:38 -0800610
611 /*
612 * The NVM settings will configure LPLU in D3 for
613 * non-IGP1 PHYs.
614 */
615 if (phy->type == e1000_phy_igp) {
616 /* disable lplu d3 during driver init */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000617 if (phy->ops.set_d3_lplu_state)
618 ret_val = phy->ops.set_d3_lplu_state(hw, false);
Auke Kok9d5c8242008-01-24 02:22:38 -0800619 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700620 hw_dbg("Error Disabling LPLU D3\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800621 goto out;
622 }
623 }
624
625 /* disable lplu d0 during driver init */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000626 ret_val = phy->ops.set_d0_lplu_state(hw, false);
Auke Kok9d5c8242008-01-24 02:22:38 -0800627 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700628 hw_dbg("Error Disabling LPLU D0\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800629 goto out;
630 }
631 /* Configure mdi-mdix settings */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000632 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CTRL, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800633 if (ret_val)
634 goto out;
635
636 data &= ~IGP01E1000_PSCR_AUTO_MDIX;
637
638 switch (phy->mdix) {
639 case 1:
640 data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
641 break;
642 case 2:
643 data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
644 break;
645 case 0:
646 default:
647 data |= IGP01E1000_PSCR_AUTO_MDIX;
648 break;
649 }
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000650 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CTRL, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800651 if (ret_val)
652 goto out;
653
654 /* set auto-master slave resolution settings */
655 if (hw->mac.autoneg) {
656 /*
657 * when autonegotiation advertisement is only 1000Mbps then we
658 * should disable SmartSpeed and enable Auto MasterSlave
659 * resolution as hardware default.
660 */
661 if (phy->autoneg_advertised == ADVERTISE_1000_FULL) {
662 /* Disable SmartSpeed */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000663 ret_val = phy->ops.read_reg(hw,
664 IGP01E1000_PHY_PORT_CONFIG,
665 &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800666 if (ret_val)
667 goto out;
668
669 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000670 ret_val = phy->ops.write_reg(hw,
Auke Kok9d5c8242008-01-24 02:22:38 -0800671 IGP01E1000_PHY_PORT_CONFIG,
672 data);
673 if (ret_val)
674 goto out;
675
676 /* Set auto Master/Slave resolution process */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000677 ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800678 if (ret_val)
679 goto out;
680
681 data &= ~CR_1000T_MS_ENABLE;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000682 ret_val = phy->ops.write_reg(hw, PHY_1000T_CTRL, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800683 if (ret_val)
684 goto out;
685 }
686
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000687 ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800688 if (ret_val)
689 goto out;
690
691 /* load defaults for future use */
692 phy->original_ms_type = (data & CR_1000T_MS_ENABLE) ?
693 ((data & CR_1000T_MS_VALUE) ?
694 e1000_ms_force_master :
695 e1000_ms_force_slave) :
696 e1000_ms_auto;
697
698 switch (phy->ms_type) {
699 case e1000_ms_force_master:
700 data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
701 break;
702 case e1000_ms_force_slave:
703 data |= CR_1000T_MS_ENABLE;
704 data &= ~(CR_1000T_MS_VALUE);
705 break;
706 case e1000_ms_auto:
707 data &= ~CR_1000T_MS_ENABLE;
708 default:
709 break;
710 }
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000711 ret_val = phy->ops.write_reg(hw, PHY_1000T_CTRL, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800712 if (ret_val)
713 goto out;
714 }
715
716out:
717 return ret_val;
718}
719
720/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700721 * igb_copper_link_autoneg - Setup/Enable autoneg for copper link
Auke Kok9d5c8242008-01-24 02:22:38 -0800722 * @hw: pointer to the HW structure
723 *
724 * Performs initial bounds checking on autoneg advertisement parameter, then
725 * configure to advertise the full capability. Setup the PHY to autoneg
726 * and restart the negotiation process between the link partner. If
727 * autoneg_wait_to_complete, then wait for autoneg to complete before exiting.
728 **/
Alexander Duyck81fadd82009-10-05 06:35:03 +0000729static s32 igb_copper_link_autoneg(struct e1000_hw *hw)
Auke Kok9d5c8242008-01-24 02:22:38 -0800730{
731 struct e1000_phy_info *phy = &hw->phy;
732 s32 ret_val;
733 u16 phy_ctrl;
734
735 /*
736 * Perform some bounds checking on the autoneg advertisement
737 * parameter.
738 */
739 phy->autoneg_advertised &= phy->autoneg_mask;
740
741 /*
742 * If autoneg_advertised is zero, we assume it was not defaulted
743 * by the calling code so we set to advertise full capability.
744 */
745 if (phy->autoneg_advertised == 0)
746 phy->autoneg_advertised = phy->autoneg_mask;
747
Auke Kok652fff32008-06-27 11:00:18 -0700748 hw_dbg("Reconfiguring auto-neg advertisement params\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800749 ret_val = igb_phy_setup_autoneg(hw);
750 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700751 hw_dbg("Error Setting up Auto-Negotiation\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800752 goto out;
753 }
Auke Kok652fff32008-06-27 11:00:18 -0700754 hw_dbg("Restarting Auto-Neg\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800755
756 /*
757 * Restart auto-negotiation by setting the Auto Neg Enable bit and
758 * the Auto Neg Restart bit in the PHY control register.
759 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000760 ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_ctrl);
Auke Kok9d5c8242008-01-24 02:22:38 -0800761 if (ret_val)
762 goto out;
763
764 phy_ctrl |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000765 ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_ctrl);
Auke Kok9d5c8242008-01-24 02:22:38 -0800766 if (ret_val)
767 goto out;
768
769 /*
770 * Does the user want to wait for Auto-Neg to complete here, or
771 * check at a later time (for example, callback routine).
772 */
773 if (phy->autoneg_wait_to_complete) {
774 ret_val = igb_wait_autoneg(hw);
775 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700776 hw_dbg("Error while waiting for "
777 "autoneg to complete\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800778 goto out;
779 }
780 }
781
782 hw->mac.get_link_status = true;
783
784out:
785 return ret_val;
786}
787
788/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700789 * igb_phy_setup_autoneg - Configure PHY for auto-negotiation
Auke Kok9d5c8242008-01-24 02:22:38 -0800790 * @hw: pointer to the HW structure
791 *
792 * Reads the MII auto-neg advertisement register and/or the 1000T control
793 * register and if the PHY is already setup for auto-negotiation, then
794 * return successful. Otherwise, setup advertisement and flow control to
795 * the appropriate values for the wanted auto-negotiation.
796 **/
797static s32 igb_phy_setup_autoneg(struct e1000_hw *hw)
798{
799 struct e1000_phy_info *phy = &hw->phy;
800 s32 ret_val;
801 u16 mii_autoneg_adv_reg;
802 u16 mii_1000t_ctrl_reg = 0;
803
804 phy->autoneg_advertised &= phy->autoneg_mask;
805
806 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000807 ret_val = phy->ops.read_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
Auke Kok9d5c8242008-01-24 02:22:38 -0800808 if (ret_val)
809 goto out;
810
811 if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
812 /* Read the MII 1000Base-T Control Register (Address 9). */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000813 ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL,
Auke Kok9d5c8242008-01-24 02:22:38 -0800814 &mii_1000t_ctrl_reg);
815 if (ret_val)
816 goto out;
817 }
818
819 /*
820 * Need to parse both autoneg_advertised and fc and set up
821 * the appropriate PHY registers. First we will parse for
822 * autoneg_advertised software override. Since we can advertise
823 * a plethora of combinations, we need to check each bit
824 * individually.
825 */
826
827 /*
828 * First we clear all the 10/100 mb speed bits in the Auto-Neg
829 * Advertisement Register (Address 4) and the 1000 mb speed bits in
830 * the 1000Base-T Control Register (Address 9).
831 */
832 mii_autoneg_adv_reg &= ~(NWAY_AR_100TX_FD_CAPS |
833 NWAY_AR_100TX_HD_CAPS |
834 NWAY_AR_10T_FD_CAPS |
835 NWAY_AR_10T_HD_CAPS);
836 mii_1000t_ctrl_reg &= ~(CR_1000T_HD_CAPS | CR_1000T_FD_CAPS);
837
Auke Kok652fff32008-06-27 11:00:18 -0700838 hw_dbg("autoneg_advertised %x\n", phy->autoneg_advertised);
Auke Kok9d5c8242008-01-24 02:22:38 -0800839
840 /* Do we want to advertise 10 Mb Half Duplex? */
841 if (phy->autoneg_advertised & ADVERTISE_10_HALF) {
Auke Kok652fff32008-06-27 11:00:18 -0700842 hw_dbg("Advertise 10mb Half duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800843 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
844 }
845
846 /* Do we want to advertise 10 Mb Full Duplex? */
847 if (phy->autoneg_advertised & ADVERTISE_10_FULL) {
Auke Kok652fff32008-06-27 11:00:18 -0700848 hw_dbg("Advertise 10mb Full duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800849 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
850 }
851
852 /* Do we want to advertise 100 Mb Half Duplex? */
853 if (phy->autoneg_advertised & ADVERTISE_100_HALF) {
Auke Kok652fff32008-06-27 11:00:18 -0700854 hw_dbg("Advertise 100mb Half duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800855 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
856 }
857
858 /* Do we want to advertise 100 Mb Full Duplex? */
859 if (phy->autoneg_advertised & ADVERTISE_100_FULL) {
Auke Kok652fff32008-06-27 11:00:18 -0700860 hw_dbg("Advertise 100mb Full duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800861 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
862 }
863
864 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
865 if (phy->autoneg_advertised & ADVERTISE_1000_HALF)
Auke Kok652fff32008-06-27 11:00:18 -0700866 hw_dbg("Advertise 1000mb Half duplex request denied!\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800867
868 /* Do we want to advertise 1000 Mb Full Duplex? */
869 if (phy->autoneg_advertised & ADVERTISE_1000_FULL) {
Auke Kok652fff32008-06-27 11:00:18 -0700870 hw_dbg("Advertise 1000mb Full duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800871 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
872 }
873
874 /*
875 * Check for a software override of the flow control settings, and
876 * setup the PHY advertisement registers accordingly. If
877 * auto-negotiation is enabled, then software will have to set the
878 * "PAUSE" bits to the correct value in the Auto-Negotiation
879 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-
880 * negotiation.
881 *
882 * The possible values of the "fc" parameter are:
883 * 0: Flow control is completely disabled
884 * 1: Rx flow control is enabled (we can receive pause frames
885 * but not send pause frames).
886 * 2: Tx flow control is enabled (we can send pause frames
887 * but we do not support receiving pause frames).
888 * 3: Both Rx and TX flow control (symmetric) are enabled.
889 * other: No software override. The flow control configuration
890 * in the EEPROM is used.
891 */
Alexander Duyck0cce1192009-07-23 18:10:24 +0000892 switch (hw->fc.current_mode) {
Auke Kok9d5c8242008-01-24 02:22:38 -0800893 case e1000_fc_none:
894 /*
895 * Flow control (RX & TX) is completely disabled by a
896 * software over-ride.
897 */
898 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
899 break;
900 case e1000_fc_rx_pause:
901 /*
902 * RX Flow control is enabled, and TX Flow control is
903 * disabled, by a software over-ride.
904 *
905 * Since there really isn't a way to advertise that we are
906 * capable of RX Pause ONLY, we will advertise that we
907 * support both symmetric and asymmetric RX PAUSE. Later
908 * (in e1000_config_fc_after_link_up) we will disable the
909 * hw's ability to send PAUSE frames.
910 */
911 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
912 break;
913 case e1000_fc_tx_pause:
914 /*
915 * TX Flow control is enabled, and RX Flow control is
916 * disabled, by a software over-ride.
917 */
918 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
919 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
920 break;
921 case e1000_fc_full:
922 /*
923 * Flow control (both RX and TX) is enabled by a software
924 * over-ride.
925 */
926 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
927 break;
928 default:
Auke Kok652fff32008-06-27 11:00:18 -0700929 hw_dbg("Flow control param set incorrectly\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800930 ret_val = -E1000_ERR_CONFIG;
931 goto out;
932 }
933
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000934 ret_val = phy->ops.write_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
Auke Kok9d5c8242008-01-24 02:22:38 -0800935 if (ret_val)
936 goto out;
937
Auke Kok652fff32008-06-27 11:00:18 -0700938 hw_dbg("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
Auke Kok9d5c8242008-01-24 02:22:38 -0800939
940 if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000941 ret_val = phy->ops.write_reg(hw,
942 PHY_1000T_CTRL,
943 mii_1000t_ctrl_reg);
Auke Kok9d5c8242008-01-24 02:22:38 -0800944 if (ret_val)
945 goto out;
946 }
947
948out:
949 return ret_val;
950}
951
952/**
Alexander Duyck81fadd82009-10-05 06:35:03 +0000953 * igb_setup_copper_link - Configure copper link settings
954 * @hw: pointer to the HW structure
955 *
956 * Calls the appropriate function to configure the link for auto-neg or forced
957 * speed and duplex. Then we check for link, once link is established calls
958 * to configure collision distance and flow control are called. If link is
959 * not established, we return -E1000_ERR_PHY (-2).
960 **/
961s32 igb_setup_copper_link(struct e1000_hw *hw)
962{
963 s32 ret_val;
964 bool link;
965
966
967 if (hw->mac.autoneg) {
968 /*
969 * Setup autoneg and flow control advertisement and perform
970 * autonegotiation.
971 */
972 ret_val = igb_copper_link_autoneg(hw);
973 if (ret_val)
974 goto out;
975 } else {
976 /*
977 * PHY will be set to 10H, 10F, 100H or 100F
978 * depending on user settings.
979 */
980 hw_dbg("Forcing Speed and Duplex\n");
981 ret_val = hw->phy.ops.force_speed_duplex(hw);
982 if (ret_val) {
983 hw_dbg("Error Forcing Speed and Duplex\n");
984 goto out;
985 }
986 }
987
988 /*
989 * Check link status. Wait up to 100 microseconds for link to become
990 * valid.
991 */
992 ret_val = igb_phy_has_link(hw,
993 COPPER_LINK_UP_LIMIT,
994 10,
995 &link);
996 if (ret_val)
997 goto out;
998
999 if (link) {
1000 hw_dbg("Valid link established!!!\n");
1001 igb_config_collision_dist(hw);
1002 ret_val = igb_config_fc_after_link_up(hw);
1003 } else {
1004 hw_dbg("Unable to establish link!!!\n");
1005 }
1006
1007out:
1008 return ret_val;
1009}
1010
1011/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001012 * igb_phy_force_speed_duplex_igp - Force speed/duplex for igp PHY
Auke Kok9d5c8242008-01-24 02:22:38 -08001013 * @hw: pointer to the HW structure
1014 *
1015 * Calls the PHY setup function to force speed and duplex. Clears the
1016 * auto-crossover to force MDI manually. Waits for link and returns
1017 * successful if link up is successful, else -E1000_ERR_PHY (-2).
1018 **/
1019s32 igb_phy_force_speed_duplex_igp(struct e1000_hw *hw)
1020{
1021 struct e1000_phy_info *phy = &hw->phy;
1022 s32 ret_val;
1023 u16 phy_data;
1024 bool link;
1025
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001026 ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001027 if (ret_val)
1028 goto out;
1029
1030 igb_phy_force_speed_duplex_setup(hw, &phy_data);
1031
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001032 ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001033 if (ret_val)
1034 goto out;
1035
1036 /*
1037 * Clear Auto-Crossover to force MDI manually. IGP requires MDI
1038 * forced whenever speed and duplex are forced.
1039 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001040 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001041 if (ret_val)
1042 goto out;
1043
1044 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1045 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1046
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001047 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001048 if (ret_val)
1049 goto out;
1050
Auke Kok652fff32008-06-27 11:00:18 -07001051 hw_dbg("IGP PSCR: %X\n", phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001052
1053 udelay(1);
1054
1055 if (phy->autoneg_wait_to_complete) {
Auke Kok652fff32008-06-27 11:00:18 -07001056 hw_dbg("Waiting for forced speed/duplex link on IGP phy.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001057
1058 ret_val = igb_phy_has_link(hw,
1059 PHY_FORCE_LIMIT,
1060 100000,
1061 &link);
1062 if (ret_val)
1063 goto out;
1064
1065 if (!link)
Auke Kok652fff32008-06-27 11:00:18 -07001066 hw_dbg("Link taking longer than expected.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001067
1068 /* Try once more */
1069 ret_val = igb_phy_has_link(hw,
1070 PHY_FORCE_LIMIT,
1071 100000,
1072 &link);
1073 if (ret_val)
1074 goto out;
1075 }
1076
1077out:
1078 return ret_val;
1079}
1080
1081/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001082 * igb_phy_force_speed_duplex_m88 - Force speed/duplex for m88 PHY
Auke Kok9d5c8242008-01-24 02:22:38 -08001083 * @hw: pointer to the HW structure
1084 *
1085 * Calls the PHY setup function to force speed and duplex. Clears the
1086 * auto-crossover to force MDI manually. Resets the PHY to commit the
1087 * changes. If time expires while waiting for link up, we reset the DSP.
1088 * After reset, TX_CLK and CRS on TX must be set. Return successful upon
1089 * successful completion, else return corresponding error code.
1090 **/
1091s32 igb_phy_force_speed_duplex_m88(struct e1000_hw *hw)
1092{
1093 struct e1000_phy_info *phy = &hw->phy;
1094 s32 ret_val;
1095 u16 phy_data;
1096 bool link;
1097
1098 /*
1099 * Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
1100 * forced whenever speed and duplex are forced.
1101 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001102 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001103 if (ret_val)
1104 goto out;
1105
1106 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001107 ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001108 if (ret_val)
1109 goto out;
1110
Auke Kok652fff32008-06-27 11:00:18 -07001111 hw_dbg("M88E1000 PSCR: %X\n", phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001112
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001113 ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001114 if (ret_val)
1115 goto out;
1116
1117 igb_phy_force_speed_duplex_setup(hw, &phy_data);
1118
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001119 ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001120 if (ret_val)
1121 goto out;
1122
Alexander Duyck2553bb22009-10-05 06:35:42 +00001123 /* Reset the phy to commit changes. */
1124 ret_val = igb_phy_sw_reset(hw);
1125 if (ret_val)
1126 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -08001127
1128 if (phy->autoneg_wait_to_complete) {
Auke Kok652fff32008-06-27 11:00:18 -07001129 hw_dbg("Waiting for forced speed/duplex link on M88 phy.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001130
Alexander Duyck2553bb22009-10-05 06:35:42 +00001131 ret_val = igb_phy_has_link(hw, PHY_FORCE_LIMIT, 100000, &link);
Auke Kok9d5c8242008-01-24 02:22:38 -08001132 if (ret_val)
1133 goto out;
1134
1135 if (!link) {
1136 /*
1137 * We didn't get link.
1138 * Reset the DSP and cross our fingers.
1139 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001140 ret_val = phy->ops.write_reg(hw,
Alexander Duyck2553bb22009-10-05 06:35:42 +00001141 M88E1000_PHY_PAGE_SELECT,
1142 0x001d);
Auke Kok9d5c8242008-01-24 02:22:38 -08001143 if (ret_val)
1144 goto out;
1145 ret_val = igb_phy_reset_dsp(hw);
1146 if (ret_val)
1147 goto out;
1148 }
1149
1150 /* Try once more */
1151 ret_val = igb_phy_has_link(hw, PHY_FORCE_LIMIT,
Alexander Duyck2553bb22009-10-05 06:35:42 +00001152 100000, &link);
Auke Kok9d5c8242008-01-24 02:22:38 -08001153 if (ret_val)
1154 goto out;
1155 }
1156
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001157 ret_val = phy->ops.read_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001158 if (ret_val)
1159 goto out;
1160
1161 /*
1162 * Resetting the phy means we need to re-force TX_CLK in the
1163 * Extended PHY Specific Control Register to 25MHz clock from
1164 * the reset value of 2.5MHz.
1165 */
1166 phy_data |= M88E1000_EPSCR_TX_CLK_25;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001167 ret_val = phy->ops.write_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001168 if (ret_val)
1169 goto out;
1170
1171 /*
1172 * In addition, we must re-enable CRS on Tx for both half and full
1173 * duplex.
1174 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001175 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001176 if (ret_val)
1177 goto out;
1178
1179 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001180 ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001181
1182out:
1183 return ret_val;
1184}
1185
1186/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001187 * igb_phy_force_speed_duplex_setup - Configure forced PHY speed/duplex
Auke Kok9d5c8242008-01-24 02:22:38 -08001188 * @hw: pointer to the HW structure
1189 * @phy_ctrl: pointer to current value of PHY_CONTROL
1190 *
1191 * Forces speed and duplex on the PHY by doing the following: disable flow
1192 * control, force speed/duplex on the MAC, disable auto speed detection,
1193 * disable auto-negotiation, configure duplex, configure speed, configure
1194 * the collision distance, write configuration to CTRL register. The
1195 * caller must write to the PHY_CONTROL register for these settings to
1196 * take affect.
1197 **/
1198static void igb_phy_force_speed_duplex_setup(struct e1000_hw *hw,
1199 u16 *phy_ctrl)
1200{
1201 struct e1000_mac_info *mac = &hw->mac;
1202 u32 ctrl;
1203
1204 /* Turn off flow control when forcing speed/duplex */
Alexander Duyck0cce1192009-07-23 18:10:24 +00001205 hw->fc.current_mode = e1000_fc_none;
Auke Kok9d5c8242008-01-24 02:22:38 -08001206
1207 /* Force speed/duplex on the mac */
1208 ctrl = rd32(E1000_CTRL);
1209 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1210 ctrl &= ~E1000_CTRL_SPD_SEL;
1211
1212 /* Disable Auto Speed Detection */
1213 ctrl &= ~E1000_CTRL_ASDE;
1214
1215 /* Disable autoneg on the phy */
1216 *phy_ctrl &= ~MII_CR_AUTO_NEG_EN;
1217
1218 /* Forcing Full or Half Duplex? */
1219 if (mac->forced_speed_duplex & E1000_ALL_HALF_DUPLEX) {
1220 ctrl &= ~E1000_CTRL_FD;
1221 *phy_ctrl &= ~MII_CR_FULL_DUPLEX;
Auke Kok652fff32008-06-27 11:00:18 -07001222 hw_dbg("Half Duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001223 } else {
1224 ctrl |= E1000_CTRL_FD;
1225 *phy_ctrl |= MII_CR_FULL_DUPLEX;
Auke Kok652fff32008-06-27 11:00:18 -07001226 hw_dbg("Full Duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001227 }
1228
1229 /* Forcing 10mb or 100mb? */
1230 if (mac->forced_speed_duplex & E1000_ALL_100_SPEED) {
1231 ctrl |= E1000_CTRL_SPD_100;
1232 *phy_ctrl |= MII_CR_SPEED_100;
1233 *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
Auke Kok652fff32008-06-27 11:00:18 -07001234 hw_dbg("Forcing 100mb\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001235 } else {
1236 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1237 *phy_ctrl |= MII_CR_SPEED_10;
1238 *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
Auke Kok652fff32008-06-27 11:00:18 -07001239 hw_dbg("Forcing 10mb\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001240 }
1241
1242 igb_config_collision_dist(hw);
1243
1244 wr32(E1000_CTRL, ctrl);
1245}
1246
1247/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001248 * igb_set_d3_lplu_state - Sets low power link up state for D3
Auke Kok9d5c8242008-01-24 02:22:38 -08001249 * @hw: pointer to the HW structure
1250 * @active: boolean used to enable/disable lplu
1251 *
1252 * Success returns 0, Failure returns 1
1253 *
1254 * The low power link up (lplu) state is set to the power management level D3
1255 * and SmartSpeed is disabled when active is true, else clear lplu for D3
1256 * and enable Smartspeed. LPLU and Smartspeed are mutually exclusive. LPLU
1257 * is used during Dx states where the power conservation is most important.
1258 * During driver activity, SmartSpeed should be enabled so performance is
1259 * maintained.
1260 **/
1261s32 igb_set_d3_lplu_state(struct e1000_hw *hw, bool active)
1262{
1263 struct e1000_phy_info *phy = &hw->phy;
Alexander Duyck2553bb22009-10-05 06:35:42 +00001264 s32 ret_val = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08001265 u16 data;
1266
Alexander Duyck2553bb22009-10-05 06:35:42 +00001267 if (!(hw->phy.ops.read_reg))
1268 goto out;
1269
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001270 ret_val = phy->ops.read_reg(hw, IGP02E1000_PHY_POWER_MGMT, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001271 if (ret_val)
1272 goto out;
1273
1274 if (!active) {
1275 data &= ~IGP02E1000_PM_D3_LPLU;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001276 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
Auke Kok9d5c8242008-01-24 02:22:38 -08001277 data);
1278 if (ret_val)
1279 goto out;
1280 /*
1281 * LPLU and SmartSpeed are mutually exclusive. LPLU is used
1282 * during Dx states where the power conservation is most
1283 * important. During driver activity we should enable
1284 * SmartSpeed, so performance is maintained.
1285 */
1286 if (phy->smart_speed == e1000_smart_speed_on) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001287 ret_val = phy->ops.read_reg(hw,
Auke Kok9d5c8242008-01-24 02:22:38 -08001288 IGP01E1000_PHY_PORT_CONFIG,
1289 &data);
1290 if (ret_val)
1291 goto out;
1292
1293 data |= IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001294 ret_val = phy->ops.write_reg(hw,
Auke Kok9d5c8242008-01-24 02:22:38 -08001295 IGP01E1000_PHY_PORT_CONFIG,
1296 data);
1297 if (ret_val)
1298 goto out;
1299 } else if (phy->smart_speed == e1000_smart_speed_off) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001300 ret_val = phy->ops.read_reg(hw,
Auke Kok9d5c8242008-01-24 02:22:38 -08001301 IGP01E1000_PHY_PORT_CONFIG,
1302 &data);
1303 if (ret_val)
1304 goto out;
1305
1306 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001307 ret_val = phy->ops.write_reg(hw,
Auke Kok9d5c8242008-01-24 02:22:38 -08001308 IGP01E1000_PHY_PORT_CONFIG,
1309 data);
1310 if (ret_val)
1311 goto out;
1312 }
1313 } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
1314 (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
1315 (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
1316 data |= IGP02E1000_PM_D3_LPLU;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001317 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
Auke Kok9d5c8242008-01-24 02:22:38 -08001318 data);
1319 if (ret_val)
1320 goto out;
1321
1322 /* When LPLU is enabled, we should disable SmartSpeed */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001323 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
Auke Kok9d5c8242008-01-24 02:22:38 -08001324 &data);
1325 if (ret_val)
1326 goto out;
1327
1328 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001329 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
Auke Kok9d5c8242008-01-24 02:22:38 -08001330 data);
1331 }
1332
1333out:
1334 return ret_val;
1335}
1336
1337/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001338 * igb_check_downshift - Checks whether a downshift in speed occured
Auke Kok9d5c8242008-01-24 02:22:38 -08001339 * @hw: pointer to the HW structure
1340 *
1341 * Success returns 0, Failure returns 1
1342 *
1343 * A downshift is detected by querying the PHY link health.
1344 **/
1345s32 igb_check_downshift(struct e1000_hw *hw)
1346{
1347 struct e1000_phy_info *phy = &hw->phy;
1348 s32 ret_val;
1349 u16 phy_data, offset, mask;
1350
1351 switch (phy->type) {
1352 case e1000_phy_m88:
1353 case e1000_phy_gg82563:
1354 offset = M88E1000_PHY_SPEC_STATUS;
1355 mask = M88E1000_PSSR_DOWNSHIFT;
1356 break;
1357 case e1000_phy_igp_2:
1358 case e1000_phy_igp:
1359 case e1000_phy_igp_3:
1360 offset = IGP01E1000_PHY_LINK_HEALTH;
1361 mask = IGP01E1000_PLHR_SS_DOWNGRADE;
1362 break;
1363 default:
1364 /* speed downshift not supported */
1365 phy->speed_downgraded = false;
1366 ret_val = 0;
1367 goto out;
1368 }
1369
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001370 ret_val = phy->ops.read_reg(hw, offset, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001371
1372 if (!ret_val)
1373 phy->speed_downgraded = (phy_data & mask) ? true : false;
1374
1375out:
1376 return ret_val;
1377}
1378
1379/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001380 * igb_check_polarity_m88 - Checks the polarity.
Auke Kok9d5c8242008-01-24 02:22:38 -08001381 * @hw: pointer to the HW structure
1382 *
1383 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1384 *
1385 * Polarity is determined based on the PHY specific status register.
1386 **/
1387static s32 igb_check_polarity_m88(struct e1000_hw *hw)
1388{
1389 struct e1000_phy_info *phy = &hw->phy;
1390 s32 ret_val;
1391 u16 data;
1392
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001393 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001394
1395 if (!ret_val)
1396 phy->cable_polarity = (data & M88E1000_PSSR_REV_POLARITY)
1397 ? e1000_rev_polarity_reversed
1398 : e1000_rev_polarity_normal;
1399
1400 return ret_val;
1401}
1402
1403/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001404 * igb_check_polarity_igp - Checks the polarity.
Auke Kok9d5c8242008-01-24 02:22:38 -08001405 * @hw: pointer to the HW structure
1406 *
1407 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1408 *
1409 * Polarity is determined based on the PHY port status register, and the
1410 * current speed (since there is no polarity at 100Mbps).
1411 **/
1412static s32 igb_check_polarity_igp(struct e1000_hw *hw)
1413{
1414 struct e1000_phy_info *phy = &hw->phy;
1415 s32 ret_val;
1416 u16 data, offset, mask;
1417
1418 /*
1419 * Polarity is determined based on the speed of
1420 * our connection.
1421 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001422 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_STATUS, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001423 if (ret_val)
1424 goto out;
1425
1426 if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
1427 IGP01E1000_PSSR_SPEED_1000MBPS) {
1428 offset = IGP01E1000_PHY_PCS_INIT_REG;
1429 mask = IGP01E1000_PHY_POLARITY_MASK;
1430 } else {
1431 /*
1432 * This really only applies to 10Mbps since
1433 * there is no polarity for 100Mbps (always 0).
1434 */
1435 offset = IGP01E1000_PHY_PORT_STATUS;
1436 mask = IGP01E1000_PSSR_POLARITY_REVERSED;
1437 }
1438
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001439 ret_val = phy->ops.read_reg(hw, offset, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001440
1441 if (!ret_val)
1442 phy->cable_polarity = (data & mask)
1443 ? e1000_rev_polarity_reversed
1444 : e1000_rev_polarity_normal;
1445
1446out:
1447 return ret_val;
1448}
1449
1450/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001451 * igb_wait_autoneg - Wait for auto-neg compeletion
Auke Kok9d5c8242008-01-24 02:22:38 -08001452 * @hw: pointer to the HW structure
1453 *
1454 * Waits for auto-negotiation to complete or for the auto-negotiation time
1455 * limit to expire, which ever happens first.
1456 **/
1457static s32 igb_wait_autoneg(struct e1000_hw *hw)
1458{
1459 s32 ret_val = 0;
1460 u16 i, phy_status;
1461
1462 /* Break after autoneg completes or PHY_AUTO_NEG_LIMIT expires. */
1463 for (i = PHY_AUTO_NEG_LIMIT; i > 0; i--) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001464 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
Auke Kok9d5c8242008-01-24 02:22:38 -08001465 if (ret_val)
1466 break;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001467 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
Auke Kok9d5c8242008-01-24 02:22:38 -08001468 if (ret_val)
1469 break;
1470 if (phy_status & MII_SR_AUTONEG_COMPLETE)
1471 break;
1472 msleep(100);
1473 }
1474
1475 /*
1476 * PHY_AUTO_NEG_TIME expiration doesn't guarantee auto-negotiation
1477 * has completed.
1478 */
1479 return ret_val;
1480}
1481
1482/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001483 * igb_phy_has_link - Polls PHY for link
Auke Kok9d5c8242008-01-24 02:22:38 -08001484 * @hw: pointer to the HW structure
1485 * @iterations: number of times to poll for link
1486 * @usec_interval: delay between polling attempts
1487 * @success: pointer to whether polling was successful or not
1488 *
1489 * Polls the PHY status register for link, 'iterations' number of times.
1490 **/
1491s32 igb_phy_has_link(struct e1000_hw *hw, u32 iterations,
1492 u32 usec_interval, bool *success)
1493{
1494 s32 ret_val = 0;
1495 u16 i, phy_status;
1496
1497 for (i = 0; i < iterations; i++) {
1498 /*
1499 * Some PHYs require the PHY_STATUS register to be read
1500 * twice due to the link bit being sticky. No harm doing
1501 * it across the board.
1502 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001503 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
Alexander Duyckab576382009-10-05 06:35:23 +00001504 if (ret_val) {
1505 /*
1506 * If the first read fails, another entity may have
1507 * ownership of the resources, wait and try again to
1508 * see if they have relinquished the resources yet.
1509 */
1510 udelay(usec_interval);
1511 }
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001512 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
Auke Kok9d5c8242008-01-24 02:22:38 -08001513 if (ret_val)
1514 break;
1515 if (phy_status & MII_SR_LINK_STATUS)
1516 break;
1517 if (usec_interval >= 1000)
1518 mdelay(usec_interval/1000);
1519 else
1520 udelay(usec_interval);
1521 }
1522
1523 *success = (i < iterations) ? true : false;
1524
1525 return ret_val;
1526}
1527
1528/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001529 * igb_get_cable_length_m88 - Determine cable length for m88 PHY
Auke Kok9d5c8242008-01-24 02:22:38 -08001530 * @hw: pointer to the HW structure
1531 *
1532 * Reads the PHY specific status register to retrieve the cable length
1533 * information. The cable length is determined by averaging the minimum and
1534 * maximum values to get the "average" cable length. The m88 PHY has four
1535 * possible cable length values, which are:
1536 * Register Value Cable Length
1537 * 0 < 50 meters
1538 * 1 50 - 80 meters
1539 * 2 80 - 110 meters
1540 * 3 110 - 140 meters
1541 * 4 > 140 meters
1542 **/
1543s32 igb_get_cable_length_m88(struct e1000_hw *hw)
1544{
1545 struct e1000_phy_info *phy = &hw->phy;
1546 s32 ret_val;
1547 u16 phy_data, index;
1548
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001549 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001550 if (ret_val)
1551 goto out;
1552
1553 index = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
1554 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
Alexander Duyck2553bb22009-10-05 06:35:42 +00001555 if (index >= M88E1000_CABLE_LENGTH_TABLE_SIZE - 1) {
1556 ret_val = -E1000_ERR_PHY;
1557 goto out;
1558 }
1559
Auke Kok9d5c8242008-01-24 02:22:38 -08001560 phy->min_cable_length = e1000_m88_cable_length_table[index];
Alexander Duyck2553bb22009-10-05 06:35:42 +00001561 phy->max_cable_length = e1000_m88_cable_length_table[index + 1];
Auke Kok9d5c8242008-01-24 02:22:38 -08001562
1563 phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
1564
1565out:
1566 return ret_val;
1567}
1568
1569/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001570 * igb_get_cable_length_igp_2 - Determine cable length for igp2 PHY
Auke Kok9d5c8242008-01-24 02:22:38 -08001571 * @hw: pointer to the HW structure
1572 *
1573 * The automatic gain control (agc) normalizes the amplitude of the
1574 * received signal, adjusting for the attenuation produced by the
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001575 * cable. By reading the AGC registers, which represent the
1576 * combination of coarse and fine gain value, the value can be put
Auke Kok9d5c8242008-01-24 02:22:38 -08001577 * into a lookup table to obtain the approximate cable length
1578 * for each channel.
1579 **/
1580s32 igb_get_cable_length_igp_2(struct e1000_hw *hw)
1581{
1582 struct e1000_phy_info *phy = &hw->phy;
1583 s32 ret_val = 0;
1584 u16 phy_data, i, agc_value = 0;
1585 u16 cur_agc_index, max_agc_index = 0;
1586 u16 min_agc_index = IGP02E1000_CABLE_LENGTH_TABLE_SIZE - 1;
1587 u16 agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] =
1588 {IGP02E1000_PHY_AGC_A,
1589 IGP02E1000_PHY_AGC_B,
1590 IGP02E1000_PHY_AGC_C,
1591 IGP02E1000_PHY_AGC_D};
1592
1593 /* Read the AGC registers for all channels */
1594 for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001595 ret_val = phy->ops.read_reg(hw, agc_reg_array[i], &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001596 if (ret_val)
1597 goto out;
1598
1599 /*
1600 * Getting bits 15:9, which represent the combination of
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001601 * coarse and fine gain values. The result is a number
Auke Kok9d5c8242008-01-24 02:22:38 -08001602 * that can be put into the lookup table to obtain the
1603 * approximate cable length.
1604 */
1605 cur_agc_index = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
1606 IGP02E1000_AGC_LENGTH_MASK;
1607
1608 /* Array index bound check. */
1609 if ((cur_agc_index >= IGP02E1000_CABLE_LENGTH_TABLE_SIZE) ||
1610 (cur_agc_index == 0)) {
1611 ret_val = -E1000_ERR_PHY;
1612 goto out;
1613 }
1614
1615 /* Remove min & max AGC values from calculation. */
1616 if (e1000_igp_2_cable_length_table[min_agc_index] >
1617 e1000_igp_2_cable_length_table[cur_agc_index])
1618 min_agc_index = cur_agc_index;
1619 if (e1000_igp_2_cable_length_table[max_agc_index] <
1620 e1000_igp_2_cable_length_table[cur_agc_index])
1621 max_agc_index = cur_agc_index;
1622
1623 agc_value += e1000_igp_2_cable_length_table[cur_agc_index];
1624 }
1625
1626 agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] +
1627 e1000_igp_2_cable_length_table[max_agc_index]);
1628 agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
1629
1630 /* Calculate cable length with the error range of +/- 10 meters. */
1631 phy->min_cable_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
1632 (agc_value - IGP02E1000_AGC_RANGE) : 0;
1633 phy->max_cable_length = agc_value + IGP02E1000_AGC_RANGE;
1634
1635 phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
1636
1637out:
1638 return ret_val;
1639}
1640
1641/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001642 * igb_get_phy_info_m88 - Retrieve PHY information
Auke Kok9d5c8242008-01-24 02:22:38 -08001643 * @hw: pointer to the HW structure
1644 *
1645 * Valid for only copper links. Read the PHY status register (sticky read)
1646 * to verify that link is up. Read the PHY special control register to
1647 * determine the polarity and 10base-T extended distance. Read the PHY
1648 * special status register to determine MDI/MDIx and current speed. If
1649 * speed is 1000, then determine cable length, local and remote receiver.
1650 **/
1651s32 igb_get_phy_info_m88(struct e1000_hw *hw)
1652{
1653 struct e1000_phy_info *phy = &hw->phy;
1654 s32 ret_val;
1655 u16 phy_data;
1656 bool link;
1657
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001658 if (phy->media_type != e1000_media_type_copper) {
Auke Kok652fff32008-06-27 11:00:18 -07001659 hw_dbg("Phy info is only valid for copper media\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001660 ret_val = -E1000_ERR_CONFIG;
1661 goto out;
1662 }
1663
1664 ret_val = igb_phy_has_link(hw, 1, 0, &link);
1665 if (ret_val)
1666 goto out;
1667
1668 if (!link) {
Auke Kok652fff32008-06-27 11:00:18 -07001669 hw_dbg("Phy info is only valid if link is up\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001670 ret_val = -E1000_ERR_CONFIG;
1671 goto out;
1672 }
1673
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001674 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001675 if (ret_val)
1676 goto out;
1677
1678 phy->polarity_correction = (phy_data & M88E1000_PSCR_POLARITY_REVERSAL)
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001679 ? true : false;
Auke Kok9d5c8242008-01-24 02:22:38 -08001680
1681 ret_val = igb_check_polarity_m88(hw);
1682 if (ret_val)
1683 goto out;
1684
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001685 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001686 if (ret_val)
1687 goto out;
1688
1689 phy->is_mdix = (phy_data & M88E1000_PSSR_MDIX) ? true : false;
1690
1691 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001692 ret_val = phy->ops.get_cable_length(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001693 if (ret_val)
1694 goto out;
1695
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001696 ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001697 if (ret_val)
1698 goto out;
1699
1700 phy->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS)
1701 ? e1000_1000t_rx_status_ok
1702 : e1000_1000t_rx_status_not_ok;
1703
1704 phy->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS)
1705 ? e1000_1000t_rx_status_ok
1706 : e1000_1000t_rx_status_not_ok;
1707 } else {
1708 /* Set values to "undefined" */
1709 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
1710 phy->local_rx = e1000_1000t_rx_status_undefined;
1711 phy->remote_rx = e1000_1000t_rx_status_undefined;
1712 }
1713
1714out:
1715 return ret_val;
1716}
1717
1718/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001719 * igb_get_phy_info_igp - Retrieve igp PHY information
Auke Kok9d5c8242008-01-24 02:22:38 -08001720 * @hw: pointer to the HW structure
1721 *
1722 * Read PHY status to determine if link is up. If link is up, then
1723 * set/determine 10base-T extended distance and polarity correction. Read
1724 * PHY port status to determine MDI/MDIx and speed. Based on the speed,
1725 * determine on the cable length, local and remote receiver.
1726 **/
1727s32 igb_get_phy_info_igp(struct e1000_hw *hw)
1728{
1729 struct e1000_phy_info *phy = &hw->phy;
1730 s32 ret_val;
1731 u16 data;
1732 bool link;
1733
1734 ret_val = igb_phy_has_link(hw, 1, 0, &link);
1735 if (ret_val)
1736 goto out;
1737
1738 if (!link) {
Auke Kok652fff32008-06-27 11:00:18 -07001739 hw_dbg("Phy info is only valid if link is up\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001740 ret_val = -E1000_ERR_CONFIG;
1741 goto out;
1742 }
1743
1744 phy->polarity_correction = true;
1745
1746 ret_val = igb_check_polarity_igp(hw);
1747 if (ret_val)
1748 goto out;
1749
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001750 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_STATUS, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001751 if (ret_val)
1752 goto out;
1753
1754 phy->is_mdix = (data & IGP01E1000_PSSR_MDIX) ? true : false;
1755
1756 if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
1757 IGP01E1000_PSSR_SPEED_1000MBPS) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001758 ret_val = phy->ops.get_cable_length(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001759 if (ret_val)
1760 goto out;
1761
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001762 ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001763 if (ret_val)
1764 goto out;
1765
1766 phy->local_rx = (data & SR_1000T_LOCAL_RX_STATUS)
1767 ? e1000_1000t_rx_status_ok
1768 : e1000_1000t_rx_status_not_ok;
1769
1770 phy->remote_rx = (data & SR_1000T_REMOTE_RX_STATUS)
1771 ? e1000_1000t_rx_status_ok
1772 : e1000_1000t_rx_status_not_ok;
1773 } else {
1774 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
1775 phy->local_rx = e1000_1000t_rx_status_undefined;
1776 phy->remote_rx = e1000_1000t_rx_status_undefined;
1777 }
1778
1779out:
1780 return ret_val;
1781}
1782
1783/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001784 * igb_phy_sw_reset - PHY software reset
Auke Kok9d5c8242008-01-24 02:22:38 -08001785 * @hw: pointer to the HW structure
1786 *
1787 * Does a software reset of the PHY by reading the PHY control register and
1788 * setting/write the control register reset bit to the PHY.
1789 **/
1790s32 igb_phy_sw_reset(struct e1000_hw *hw)
1791{
Alexander Duyckd3147372009-09-14 08:23:13 +00001792 s32 ret_val = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08001793 u16 phy_ctrl;
1794
Alexander Duyckd3147372009-09-14 08:23:13 +00001795 if (!(hw->phy.ops.read_reg))
1796 goto out;
1797
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001798 ret_val = hw->phy.ops.read_reg(hw, PHY_CONTROL, &phy_ctrl);
Auke Kok9d5c8242008-01-24 02:22:38 -08001799 if (ret_val)
1800 goto out;
1801
1802 phy_ctrl |= MII_CR_RESET;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001803 ret_val = hw->phy.ops.write_reg(hw, PHY_CONTROL, phy_ctrl);
Auke Kok9d5c8242008-01-24 02:22:38 -08001804 if (ret_val)
1805 goto out;
1806
1807 udelay(1);
1808
1809out:
1810 return ret_val;
1811}
1812
1813/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001814 * igb_phy_hw_reset - PHY hardware reset
Auke Kok9d5c8242008-01-24 02:22:38 -08001815 * @hw: pointer to the HW structure
1816 *
1817 * Verify the reset block is not blocking us from resetting. Acquire
1818 * semaphore (if necessary) and read/set/write the device control reset
1819 * bit in the PHY. Wait the appropriate delay time for the device to
1820 * reset and relase the semaphore (if necessary).
1821 **/
1822s32 igb_phy_hw_reset(struct e1000_hw *hw)
1823{
1824 struct e1000_phy_info *phy = &hw->phy;
1825 s32 ret_val;
1826 u32 ctrl;
1827
1828 ret_val = igb_check_reset_block(hw);
1829 if (ret_val) {
1830 ret_val = 0;
1831 goto out;
1832 }
1833
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001834 ret_val = phy->ops.acquire(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001835 if (ret_val)
1836 goto out;
1837
1838 ctrl = rd32(E1000_CTRL);
1839 wr32(E1000_CTRL, ctrl | E1000_CTRL_PHY_RST);
1840 wrfl();
1841
1842 udelay(phy->reset_delay_us);
1843
1844 wr32(E1000_CTRL, ctrl);
1845 wrfl();
1846
1847 udelay(150);
1848
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001849 phy->ops.release(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001850
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001851 ret_val = phy->ops.get_cfg_done(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001852
1853out:
1854 return ret_val;
1855}
1856
Auke Kok9d5c8242008-01-24 02:22:38 -08001857/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001858 * igb_phy_init_script_igp3 - Inits the IGP3 PHY
Auke Kok9d5c8242008-01-24 02:22:38 -08001859 * @hw: pointer to the HW structure
1860 *
1861 * Initializes a Intel Gigabit PHY3 when an EEPROM is not present.
1862 **/
1863s32 igb_phy_init_script_igp3(struct e1000_hw *hw)
1864{
Auke Kok652fff32008-06-27 11:00:18 -07001865 hw_dbg("Running IGP 3 PHY init script\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001866
1867 /* PHY init IGP 3 */
1868 /* Enable rise/fall, 10-mode work in class-A */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001869 hw->phy.ops.write_reg(hw, 0x2F5B, 0x9018);
Auke Kok9d5c8242008-01-24 02:22:38 -08001870 /* Remove all caps from Replica path filter */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001871 hw->phy.ops.write_reg(hw, 0x2F52, 0x0000);
Auke Kok9d5c8242008-01-24 02:22:38 -08001872 /* Bias trimming for ADC, AFE and Driver (Default) */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001873 hw->phy.ops.write_reg(hw, 0x2FB1, 0x8B24);
Auke Kok9d5c8242008-01-24 02:22:38 -08001874 /* Increase Hybrid poly bias */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001875 hw->phy.ops.write_reg(hw, 0x2FB2, 0xF8F0);
Auke Kok9d5c8242008-01-24 02:22:38 -08001876 /* Add 4% to TX amplitude in Giga mode */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001877 hw->phy.ops.write_reg(hw, 0x2010, 0x10B0);
Auke Kok9d5c8242008-01-24 02:22:38 -08001878 /* Disable trimming (TTT) */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001879 hw->phy.ops.write_reg(hw, 0x2011, 0x0000);
Auke Kok9d5c8242008-01-24 02:22:38 -08001880 /* Poly DC correction to 94.6% + 2% for all channels */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001881 hw->phy.ops.write_reg(hw, 0x20DD, 0x249A);
Auke Kok9d5c8242008-01-24 02:22:38 -08001882 /* ABS DC correction to 95.9% */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001883 hw->phy.ops.write_reg(hw, 0x20DE, 0x00D3);
Auke Kok9d5c8242008-01-24 02:22:38 -08001884 /* BG temp curve trim */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001885 hw->phy.ops.write_reg(hw, 0x28B4, 0x04CE);
Auke Kok9d5c8242008-01-24 02:22:38 -08001886 /* Increasing ADC OPAMP stage 1 currents to max */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001887 hw->phy.ops.write_reg(hw, 0x2F70, 0x29E4);
Auke Kok9d5c8242008-01-24 02:22:38 -08001888 /* Force 1000 ( required for enabling PHY regs configuration) */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001889 hw->phy.ops.write_reg(hw, 0x0000, 0x0140);
Auke Kok9d5c8242008-01-24 02:22:38 -08001890 /* Set upd_freq to 6 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001891 hw->phy.ops.write_reg(hw, 0x1F30, 0x1606);
Auke Kok9d5c8242008-01-24 02:22:38 -08001892 /* Disable NPDFE */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001893 hw->phy.ops.write_reg(hw, 0x1F31, 0xB814);
Auke Kok9d5c8242008-01-24 02:22:38 -08001894 /* Disable adaptive fixed FFE (Default) */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001895 hw->phy.ops.write_reg(hw, 0x1F35, 0x002A);
Auke Kok9d5c8242008-01-24 02:22:38 -08001896 /* Enable FFE hysteresis */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001897 hw->phy.ops.write_reg(hw, 0x1F3E, 0x0067);
Auke Kok9d5c8242008-01-24 02:22:38 -08001898 /* Fixed FFE for short cable lengths */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001899 hw->phy.ops.write_reg(hw, 0x1F54, 0x0065);
Auke Kok9d5c8242008-01-24 02:22:38 -08001900 /* Fixed FFE for medium cable lengths */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001901 hw->phy.ops.write_reg(hw, 0x1F55, 0x002A);
Auke Kok9d5c8242008-01-24 02:22:38 -08001902 /* Fixed FFE for long cable lengths */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001903 hw->phy.ops.write_reg(hw, 0x1F56, 0x002A);
Auke Kok9d5c8242008-01-24 02:22:38 -08001904 /* Enable Adaptive Clip Threshold */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001905 hw->phy.ops.write_reg(hw, 0x1F72, 0x3FB0);
Auke Kok9d5c8242008-01-24 02:22:38 -08001906 /* AHT reset limit to 1 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001907 hw->phy.ops.write_reg(hw, 0x1F76, 0xC0FF);
Auke Kok9d5c8242008-01-24 02:22:38 -08001908 /* Set AHT master delay to 127 msec */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001909 hw->phy.ops.write_reg(hw, 0x1F77, 0x1DEC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001910 /* Set scan bits for AHT */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001911 hw->phy.ops.write_reg(hw, 0x1F78, 0xF9EF);
Auke Kok9d5c8242008-01-24 02:22:38 -08001912 /* Set AHT Preset bits */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001913 hw->phy.ops.write_reg(hw, 0x1F79, 0x0210);
Auke Kok9d5c8242008-01-24 02:22:38 -08001914 /* Change integ_factor of channel A to 3 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001915 hw->phy.ops.write_reg(hw, 0x1895, 0x0003);
Auke Kok9d5c8242008-01-24 02:22:38 -08001916 /* Change prop_factor of channels BCD to 8 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001917 hw->phy.ops.write_reg(hw, 0x1796, 0x0008);
Auke Kok9d5c8242008-01-24 02:22:38 -08001918 /* Change cg_icount + enable integbp for channels BCD */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001919 hw->phy.ops.write_reg(hw, 0x1798, 0xD008);
Auke Kok9d5c8242008-01-24 02:22:38 -08001920 /*
1921 * Change cg_icount + enable integbp + change prop_factor_master
1922 * to 8 for channel A
1923 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001924 hw->phy.ops.write_reg(hw, 0x1898, 0xD918);
Auke Kok9d5c8242008-01-24 02:22:38 -08001925 /* Disable AHT in Slave mode on channel A */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001926 hw->phy.ops.write_reg(hw, 0x187A, 0x0800);
Auke Kok9d5c8242008-01-24 02:22:38 -08001927 /*
1928 * Enable LPLU and disable AN to 1000 in non-D0a states,
1929 * Enable SPD+B2B
1930 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001931 hw->phy.ops.write_reg(hw, 0x0019, 0x008D);
Auke Kok9d5c8242008-01-24 02:22:38 -08001932 /* Enable restart AN on an1000_dis change */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001933 hw->phy.ops.write_reg(hw, 0x001B, 0x2080);
Auke Kok9d5c8242008-01-24 02:22:38 -08001934 /* Enable wh_fifo read clock in 10/100 modes */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001935 hw->phy.ops.write_reg(hw, 0x0014, 0x0045);
Auke Kok9d5c8242008-01-24 02:22:38 -08001936 /* Restart AN, Speed selection is 1000 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001937 hw->phy.ops.write_reg(hw, 0x0000, 0x1340);
Auke Kok9d5c8242008-01-24 02:22:38 -08001938
1939 return 0;
1940}
1941
Alexander Duyck2909c3f2009-11-19 12:41:42 +00001942/**
1943 * igb_check_polarity_82580 - Checks the polarity.
1944 * @hw: pointer to the HW structure
1945 *
1946 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1947 *
1948 * Polarity is determined based on the PHY specific status register.
1949 **/
1950s32 igb_check_polarity_82580(struct e1000_hw *hw)
1951{
1952 struct e1000_phy_info *phy = &hw->phy;
1953 s32 ret_val;
1954 u16 data;
1955
1956
1957 ret_val = phy->ops.read_reg(hw, I82580_PHY_STATUS_2, &data);
1958
1959 if (!ret_val)
1960 phy->cable_polarity = (data & I82580_PHY_STATUS2_REV_POLARITY)
1961 ? e1000_rev_polarity_reversed
1962 : e1000_rev_polarity_normal;
1963
1964 return ret_val;
1965}
1966
1967/**
1968 * igb_phy_force_speed_duplex_82580 - Force speed/duplex for I82580 PHY
1969 * @hw: pointer to the HW structure
1970 *
1971 * Calls the PHY setup function to force speed and duplex. Clears the
1972 * auto-crossover to force MDI manually. Waits for link and returns
1973 * successful if link up is successful, else -E1000_ERR_PHY (-2).
1974 **/
1975s32 igb_phy_force_speed_duplex_82580(struct e1000_hw *hw)
1976{
1977 struct e1000_phy_info *phy = &hw->phy;
1978 s32 ret_val;
1979 u16 phy_data;
1980 bool link;
1981
1982
1983 ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data);
1984 if (ret_val)
1985 goto out;
1986
1987 igb_phy_force_speed_duplex_setup(hw, &phy_data);
1988
1989 ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data);
1990 if (ret_val)
1991 goto out;
1992
1993 /*
1994 * Clear Auto-Crossover to force MDI manually. 82580 requires MDI
1995 * forced whenever speed and duplex are forced.
1996 */
1997 ret_val = phy->ops.read_reg(hw, I82580_PHY_CTRL_2, &phy_data);
1998 if (ret_val)
1999 goto out;
2000
2001 phy_data &= ~I82580_PHY_CTRL2_AUTO_MDIX;
2002 phy_data &= ~I82580_PHY_CTRL2_FORCE_MDI_MDIX;
2003
2004 ret_val = phy->ops.write_reg(hw, I82580_PHY_CTRL_2, phy_data);
2005 if (ret_val)
2006 goto out;
2007
2008 hw_dbg("I82580_PHY_CTRL_2: %X\n", phy_data);
2009
2010 udelay(1);
2011
2012 if (phy->autoneg_wait_to_complete) {
2013 hw_dbg("Waiting for forced speed/duplex link on 82580 phy\n");
2014
2015 ret_val = igb_phy_has_link(hw,
2016 PHY_FORCE_LIMIT,
2017 100000,
2018 &link);
2019 if (ret_val)
2020 goto out;
2021
2022 if (!link)
2023 hw_dbg("Link taking longer than expected.\n");
2024
2025 /* Try once more */
2026 ret_val = igb_phy_has_link(hw,
2027 PHY_FORCE_LIMIT,
2028 100000,
2029 &link);
2030 if (ret_val)
2031 goto out;
2032 }
2033
2034out:
2035 return ret_val;
2036}
2037
2038/**
2039 * igb_get_phy_info_82580 - Retrieve I82580 PHY information
2040 * @hw: pointer to the HW structure
2041 *
2042 * Read PHY status to determine if link is up. If link is up, then
2043 * set/determine 10base-T extended distance and polarity correction. Read
2044 * PHY port status to determine MDI/MDIx and speed. Based on the speed,
2045 * determine on the cable length, local and remote receiver.
2046 **/
2047s32 igb_get_phy_info_82580(struct e1000_hw *hw)
2048{
2049 struct e1000_phy_info *phy = &hw->phy;
2050 s32 ret_val;
2051 u16 data;
2052 bool link;
2053
2054
2055 ret_val = igb_phy_has_link(hw, 1, 0, &link);
2056 if (ret_val)
2057 goto out;
2058
2059 if (!link) {
2060 hw_dbg("Phy info is only valid if link is up\n");
2061 ret_val = -E1000_ERR_CONFIG;
2062 goto out;
2063 }
2064
2065 phy->polarity_correction = true;
2066
2067 ret_val = igb_check_polarity_82580(hw);
2068 if (ret_val)
2069 goto out;
2070
2071 ret_val = phy->ops.read_reg(hw, I82580_PHY_STATUS_2, &data);
2072 if (ret_val)
2073 goto out;
2074
2075 phy->is_mdix = (data & I82580_PHY_STATUS2_MDIX) ? true : false;
2076
2077 if ((data & I82580_PHY_STATUS2_SPEED_MASK) ==
2078 I82580_PHY_STATUS2_SPEED_1000MBPS) {
2079 ret_val = hw->phy.ops.get_cable_length(hw);
2080 if (ret_val)
2081 goto out;
2082
2083 ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &data);
2084 if (ret_val)
2085 goto out;
2086
2087 phy->local_rx = (data & SR_1000T_LOCAL_RX_STATUS)
2088 ? e1000_1000t_rx_status_ok
2089 : e1000_1000t_rx_status_not_ok;
2090
2091 phy->remote_rx = (data & SR_1000T_REMOTE_RX_STATUS)
2092 ? e1000_1000t_rx_status_ok
2093 : e1000_1000t_rx_status_not_ok;
2094 } else {
2095 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
2096 phy->local_rx = e1000_1000t_rx_status_undefined;
2097 phy->remote_rx = e1000_1000t_rx_status_undefined;
2098 }
2099
2100out:
2101 return ret_val;
2102}
2103
2104/**
2105 * igb_get_cable_length_82580 - Determine cable length for 82580 PHY
2106 * @hw: pointer to the HW structure
2107 *
2108 * Reads the diagnostic status register and verifies result is valid before
2109 * placing it in the phy_cable_length field.
2110 **/
2111s32 igb_get_cable_length_82580(struct e1000_hw *hw)
2112{
2113 struct e1000_phy_info *phy = &hw->phy;
2114 s32 ret_val;
2115 u16 phy_data, length;
2116
2117
2118 ret_val = phy->ops.read_reg(hw, I82580_PHY_DIAG_STATUS, &phy_data);
2119 if (ret_val)
2120 goto out;
2121
2122 length = (phy_data & I82580_DSTATUS_CABLE_LENGTH) >>
2123 I82580_DSTATUS_CABLE_LENGTH_SHIFT;
2124
2125 if (length == E1000_CABLE_LENGTH_UNDEFINED)
2126 ret_val = -E1000_ERR_PHY;
2127
2128 phy->cable_length = length;
2129
2130out:
2131 return ret_val;
2132}