blob: fe76004aca4e7a8464811629d9cfec18dac2f8b2 [file] [log] [blame]
Auke Kok9d5c8242008-01-24 02:22:38 -08001/*******************************************************************************
2
3 Intel(R) Gigabit Ethernet Linux driver
Carolyn Wyborny6e861322012-01-18 22:13:27 +00004 Copyright(c) 2007-2012 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);
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +000038static s32 igb_set_master_slave_mode(struct e1000_hw *hw);
Auke Kok9d5c8242008-01-24 02:22:38 -080039
40/* Cable length tables */
41static const u16 e1000_m88_cable_length_table[] =
42 { 0, 50, 80, 110, 140, 140, E1000_CABLE_LENGTH_UNDEFINED };
Alexander Duyck2553bb22009-10-05 06:35:42 +000043#define M88E1000_CABLE_LENGTH_TABLE_SIZE \
44 (sizeof(e1000_m88_cable_length_table) / \
45 sizeof(e1000_m88_cable_length_table[0]))
Auke Kok9d5c8242008-01-24 02:22:38 -080046
47static const u16 e1000_igp_2_cable_length_table[] =
48 { 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21,
49 0, 0, 0, 3, 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41,
50 6, 10, 14, 18, 22, 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61,
51 21, 26, 31, 35, 40, 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82,
52 40, 45, 51, 56, 61, 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104,
53 60, 66, 72, 77, 82, 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121,
54 83, 89, 95, 100, 105, 109, 113, 116, 119, 122, 124,
55 104, 109, 114, 118, 121, 124};
56#define IGP02E1000_CABLE_LENGTH_TABLE_SIZE \
57 (sizeof(e1000_igp_2_cable_length_table) / \
58 sizeof(e1000_igp_2_cable_length_table[0]))
59
60/**
Jeff Kirsher733596b2008-06-27 10:59:59 -070061 * igb_check_reset_block - Check if PHY reset is blocked
Auke Kok9d5c8242008-01-24 02:22:38 -080062 * @hw: pointer to the HW structure
63 *
64 * Read the PHY management control register and check whether a PHY reset
65 * is blocked. If a reset is not blocked return 0, otherwise
66 * return E1000_BLK_PHY_RESET (12).
67 **/
68s32 igb_check_reset_block(struct e1000_hw *hw)
69{
70 u32 manc;
71
72 manc = rd32(E1000_MANC);
73
74 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
75 E1000_BLK_PHY_RESET : 0;
76}
77
78/**
Jeff Kirsher733596b2008-06-27 10:59:59 -070079 * igb_get_phy_id - Retrieve the PHY ID and revision
Auke Kok9d5c8242008-01-24 02:22:38 -080080 * @hw: pointer to the HW structure
81 *
82 * Reads the PHY registers and stores the PHY ID and possibly the PHY
83 * revision in the hardware structure.
84 **/
85s32 igb_get_phy_id(struct e1000_hw *hw)
86{
87 struct e1000_phy_info *phy = &hw->phy;
88 s32 ret_val = 0;
89 u16 phy_id;
90
Alexander Duycka8d2a0c2009-02-06 23:17:26 +000091 ret_val = phy->ops.read_reg(hw, PHY_ID1, &phy_id);
Auke Kok9d5c8242008-01-24 02:22:38 -080092 if (ret_val)
93 goto out;
94
95 phy->id = (u32)(phy_id << 16);
96 udelay(20);
Alexander Duycka8d2a0c2009-02-06 23:17:26 +000097 ret_val = phy->ops.read_reg(hw, PHY_ID2, &phy_id);
Auke Kok9d5c8242008-01-24 02:22:38 -080098 if (ret_val)
99 goto out;
100
101 phy->id |= (u32)(phy_id & PHY_REVISION_MASK);
102 phy->revision = (u32)(phy_id & ~PHY_REVISION_MASK);
103
104out:
105 return ret_val;
106}
107
108/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700109 * igb_phy_reset_dsp - Reset PHY DSP
Auke Kok9d5c8242008-01-24 02:22:38 -0800110 * @hw: pointer to the HW structure
111 *
112 * Reset the digital signal processor.
113 **/
114static s32 igb_phy_reset_dsp(struct e1000_hw *hw)
115{
Alexander Duyck2553bb22009-10-05 06:35:42 +0000116 s32 ret_val = 0;
117
118 if (!(hw->phy.ops.write_reg))
119 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800120
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000121 ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xC1);
Auke Kok9d5c8242008-01-24 02:22:38 -0800122 if (ret_val)
123 goto out;
124
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000125 ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0);
Auke Kok9d5c8242008-01-24 02:22:38 -0800126
127out:
128 return ret_val;
129}
130
131/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700132 * igb_read_phy_reg_mdic - Read MDI control register
Auke Kok9d5c8242008-01-24 02:22:38 -0800133 * @hw: pointer to the HW structure
134 * @offset: register offset to be read
135 * @data: pointer to the read data
136 *
137 * Reads the MDI control regsiter in the PHY at offset and stores the
138 * information read to data.
139 **/
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000140s32 igb_read_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 *data)
Auke Kok9d5c8242008-01-24 02:22:38 -0800141{
142 struct e1000_phy_info *phy = &hw->phy;
143 u32 i, mdic = 0;
144 s32 ret_val = 0;
145
146 if (offset > MAX_PHY_REG_ADDRESS) {
Auke Kok652fff32008-06-27 11:00:18 -0700147 hw_dbg("PHY Address %d is out of range\n", offset);
Auke Kok9d5c8242008-01-24 02:22:38 -0800148 ret_val = -E1000_ERR_PARAM;
149 goto out;
150 }
151
152 /*
153 * Set up Op-code, Phy Address, and register offset in the MDI
154 * Control register. The MAC will take care of interfacing with the
155 * PHY to retrieve the desired data.
156 */
157 mdic = ((offset << E1000_MDIC_REG_SHIFT) |
158 (phy->addr << E1000_MDIC_PHY_SHIFT) |
159 (E1000_MDIC_OP_READ));
160
161 wr32(E1000_MDIC, mdic);
162
163 /*
164 * Poll the ready bit to see if the MDI read completed
165 * Increasing the time out as testing showed failures with
166 * the lower time out
167 */
168 for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
169 udelay(50);
170 mdic = rd32(E1000_MDIC);
171 if (mdic & E1000_MDIC_READY)
172 break;
173 }
174 if (!(mdic & E1000_MDIC_READY)) {
Auke Kok652fff32008-06-27 11:00:18 -0700175 hw_dbg("MDI Read did not complete\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800176 ret_val = -E1000_ERR_PHY;
177 goto out;
178 }
179 if (mdic & E1000_MDIC_ERROR) {
Auke Kok652fff32008-06-27 11:00:18 -0700180 hw_dbg("MDI Error\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800181 ret_val = -E1000_ERR_PHY;
182 goto out;
183 }
184 *data = (u16) mdic;
185
186out:
187 return ret_val;
188}
189
190/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700191 * igb_write_phy_reg_mdic - Write MDI control register
Auke Kok9d5c8242008-01-24 02:22:38 -0800192 * @hw: pointer to the HW structure
193 * @offset: register offset to write to
194 * @data: data to write to register at offset
195 *
196 * Writes data to MDI control register in the PHY at offset.
197 **/
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000198s32 igb_write_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 data)
Auke Kok9d5c8242008-01-24 02:22:38 -0800199{
200 struct e1000_phy_info *phy = &hw->phy;
201 u32 i, mdic = 0;
202 s32 ret_val = 0;
203
204 if (offset > MAX_PHY_REG_ADDRESS) {
Auke Kok652fff32008-06-27 11:00:18 -0700205 hw_dbg("PHY Address %d is out of range\n", offset);
Auke Kok9d5c8242008-01-24 02:22:38 -0800206 ret_val = -E1000_ERR_PARAM;
207 goto out;
208 }
209
210 /*
211 * Set up Op-code, Phy Address, and register offset in the MDI
212 * Control register. The MAC will take care of interfacing with the
213 * PHY to retrieve the desired data.
214 */
215 mdic = (((u32)data) |
216 (offset << E1000_MDIC_REG_SHIFT) |
217 (phy->addr << E1000_MDIC_PHY_SHIFT) |
218 (E1000_MDIC_OP_WRITE));
219
220 wr32(E1000_MDIC, mdic);
221
222 /*
223 * Poll the ready bit to see if the MDI read completed
224 * Increasing the time out as testing showed failures with
225 * the lower time out
226 */
227 for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
228 udelay(50);
229 mdic = rd32(E1000_MDIC);
230 if (mdic & E1000_MDIC_READY)
231 break;
232 }
233 if (!(mdic & E1000_MDIC_READY)) {
Auke Kok652fff32008-06-27 11:00:18 -0700234 hw_dbg("MDI Write did not complete\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800235 ret_val = -E1000_ERR_PHY;
236 goto out;
237 }
238 if (mdic & E1000_MDIC_ERROR) {
Auke Kok652fff32008-06-27 11:00:18 -0700239 hw_dbg("MDI Error\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800240 ret_val = -E1000_ERR_PHY;
241 goto out;
242 }
243
244out:
245 return ret_val;
246}
247
248/**
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000249 * igb_read_phy_reg_i2c - Read PHY register using i2c
250 * @hw: pointer to the HW structure
251 * @offset: register offset to be read
252 * @data: pointer to the read data
253 *
254 * Reads the PHY register at offset using the i2c interface and stores the
255 * retrieved information in data.
256 **/
257s32 igb_read_phy_reg_i2c(struct e1000_hw *hw, u32 offset, u16 *data)
258{
259 struct e1000_phy_info *phy = &hw->phy;
260 u32 i, i2ccmd = 0;
261
262
263 /*
264 * Set up Op-code, Phy Address, and register address in the I2CCMD
265 * register. The MAC will take care of interfacing with the
266 * PHY to retrieve the desired data.
267 */
268 i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) |
269 (phy->addr << E1000_I2CCMD_PHY_ADDR_SHIFT) |
270 (E1000_I2CCMD_OPCODE_READ));
271
272 wr32(E1000_I2CCMD, i2ccmd);
273
274 /* Poll the ready bit to see if the I2C read completed */
275 for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) {
276 udelay(50);
277 i2ccmd = rd32(E1000_I2CCMD);
278 if (i2ccmd & E1000_I2CCMD_READY)
279 break;
280 }
281 if (!(i2ccmd & E1000_I2CCMD_READY)) {
282 hw_dbg("I2CCMD Read did not complete\n");
283 return -E1000_ERR_PHY;
284 }
285 if (i2ccmd & E1000_I2CCMD_ERROR) {
286 hw_dbg("I2CCMD Error bit set\n");
287 return -E1000_ERR_PHY;
288 }
289
290 /* Need to byte-swap the 16-bit value. */
291 *data = ((i2ccmd >> 8) & 0x00FF) | ((i2ccmd << 8) & 0xFF00);
292
293 return 0;
294}
295
296/**
297 * igb_write_phy_reg_i2c - Write PHY register using i2c
298 * @hw: pointer to the HW structure
299 * @offset: register offset to write to
300 * @data: data to write at register offset
301 *
302 * Writes the data to PHY register at the offset using the i2c interface.
303 **/
304s32 igb_write_phy_reg_i2c(struct e1000_hw *hw, u32 offset, u16 data)
305{
306 struct e1000_phy_info *phy = &hw->phy;
307 u32 i, i2ccmd = 0;
308 u16 phy_data_swapped;
309
Akeem G. Abodunrin76d06522011-09-02 23:11:19 +0000310 /* Prevent overwritting SFP I2C EEPROM which is at A0 address.*/
311 if ((hw->phy.addr == 0) || (hw->phy.addr > 7)) {
312 hw_dbg("PHY I2C Address %d is out of range.\n",
313 hw->phy.addr);
314 return -E1000_ERR_CONFIG;
315 }
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000316
317 /* Swap the data bytes for the I2C interface */
318 phy_data_swapped = ((data >> 8) & 0x00FF) | ((data << 8) & 0xFF00);
319
320 /*
321 * Set up Op-code, Phy Address, and register address in the I2CCMD
322 * register. The MAC will take care of interfacing with the
323 * PHY to retrieve the desired data.
324 */
325 i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) |
326 (phy->addr << E1000_I2CCMD_PHY_ADDR_SHIFT) |
327 E1000_I2CCMD_OPCODE_WRITE |
328 phy_data_swapped);
329
330 wr32(E1000_I2CCMD, i2ccmd);
331
332 /* Poll the ready bit to see if the I2C read completed */
333 for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) {
334 udelay(50);
335 i2ccmd = rd32(E1000_I2CCMD);
336 if (i2ccmd & E1000_I2CCMD_READY)
337 break;
338 }
339 if (!(i2ccmd & E1000_I2CCMD_READY)) {
340 hw_dbg("I2CCMD Write did not complete\n");
341 return -E1000_ERR_PHY;
342 }
343 if (i2ccmd & E1000_I2CCMD_ERROR) {
344 hw_dbg("I2CCMD Error bit set\n");
345 return -E1000_ERR_PHY;
346 }
347
348 return 0;
349}
350
351/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700352 * igb_read_phy_reg_igp - Read igp PHY register
Auke Kok9d5c8242008-01-24 02:22:38 -0800353 * @hw: pointer to the HW structure
354 * @offset: register offset to be read
355 * @data: pointer to the read data
356 *
357 * Acquires semaphore, if necessary, then reads the PHY register at offset
358 * and storing the retrieved information in data. Release any acquired
359 * semaphores before exiting.
360 **/
361s32 igb_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data)
362{
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000363 s32 ret_val = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -0800364
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000365 if (!(hw->phy.ops.acquire))
366 goto out;
367
368 ret_val = hw->phy.ops.acquire(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800369 if (ret_val)
370 goto out;
371
372 if (offset > MAX_PHY_MULTI_PAGE_REG) {
373 ret_val = igb_write_phy_reg_mdic(hw,
374 IGP01E1000_PHY_PAGE_SELECT,
375 (u16)offset);
376 if (ret_val) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000377 hw->phy.ops.release(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800378 goto out;
379 }
380 }
381
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000382 ret_val = igb_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
383 data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800384
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000385 hw->phy.ops.release(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800386
387out:
388 return ret_val;
389}
390
391/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700392 * igb_write_phy_reg_igp - Write igp PHY register
Auke Kok9d5c8242008-01-24 02:22:38 -0800393 * @hw: pointer to the HW structure
394 * @offset: register offset to write to
395 * @data: data to write at register offset
396 *
397 * Acquires semaphore, if necessary, then writes the data to PHY register
398 * at the offset. Release any acquired semaphores before exiting.
399 **/
400s32 igb_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data)
401{
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000402 s32 ret_val = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -0800403
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000404 if (!(hw->phy.ops.acquire))
405 goto out;
406
407 ret_val = hw->phy.ops.acquire(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800408 if (ret_val)
409 goto out;
410
411 if (offset > MAX_PHY_MULTI_PAGE_REG) {
412 ret_val = igb_write_phy_reg_mdic(hw,
413 IGP01E1000_PHY_PAGE_SELECT,
414 (u16)offset);
415 if (ret_val) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000416 hw->phy.ops.release(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800417 goto out;
418 }
419 }
420
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000421 ret_val = igb_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
Auke Kok9d5c8242008-01-24 02:22:38 -0800422 data);
423
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000424 hw->phy.ops.release(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800425
426out:
427 return ret_val;
428}
429
430/**
Alexander Duyck2909c3f2009-11-19 12:41:42 +0000431 * igb_copper_link_setup_82580 - Setup 82580 PHY for copper link
432 * @hw: pointer to the HW structure
433 *
434 * Sets up Carrier-sense on Transmit and downshift values.
435 **/
436s32 igb_copper_link_setup_82580(struct e1000_hw *hw)
437{
438 struct e1000_phy_info *phy = &hw->phy;
439 s32 ret_val;
440 u16 phy_data;
441
442
443 if (phy->reset_disable) {
444 ret_val = 0;
445 goto out;
446 }
447
448 if (phy->type == e1000_phy_82580) {
449 ret_val = hw->phy.ops.reset(hw);
450 if (ret_val) {
451 hw_dbg("Error resetting the PHY.\n");
452 goto out;
453 }
454 }
455
456 /* Enable CRS on TX. This must be set for half-duplex operation. */
457 ret_val = phy->ops.read_reg(hw, I82580_CFG_REG, &phy_data);
458 if (ret_val)
459 goto out;
460
461 phy_data |= I82580_CFG_ASSERT_CRS_ON_TX;
462
463 /* Enable downshift */
464 phy_data |= I82580_CFG_ENABLE_DOWNSHIFT;
465
466 ret_val = phy->ops.write_reg(hw, I82580_CFG_REG, phy_data);
Jesse Brandeburg1b556782012-07-26 02:31:04 +0000467 if (ret_val)
468 goto out;
469
470 /* Set MDI/MDIX mode */
471 ret_val = phy->ops.read_reg(hw, I82580_PHY_CTRL_2, &phy_data);
472 if (ret_val)
473 goto out;
474 phy_data &= ~I82580_PHY_CTRL2_MDIX_CFG_MASK;
475 /*
476 * Options:
477 * 0 - Auto (default)
478 * 1 - MDI mode
479 * 2 - MDI-X mode
480 */
481 switch (hw->phy.mdix) {
482 case 1:
483 break;
484 case 2:
485 phy_data |= I82580_PHY_CTRL2_MANUAL_MDIX;
486 break;
487 case 0:
488 default:
489 phy_data |= I82580_PHY_CTRL2_AUTO_MDI_MDIX;
490 break;
491 }
492 ret_val = hw->phy.ops.write_reg(hw, I82580_PHY_CTRL_2, phy_data);
Alexander Duyck2909c3f2009-11-19 12:41:42 +0000493
494out:
495 return ret_val;
496}
497
498/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700499 * igb_copper_link_setup_m88 - Setup m88 PHY's for copper link
Auke Kok9d5c8242008-01-24 02:22:38 -0800500 * @hw: pointer to the HW structure
501 *
502 * Sets up MDI/MDI-X and polarity for m88 PHY's. If necessary, transmit clock
503 * and downshift values are set also.
504 **/
505s32 igb_copper_link_setup_m88(struct e1000_hw *hw)
506{
507 struct e1000_phy_info *phy = &hw->phy;
508 s32 ret_val;
509 u16 phy_data;
510
511 if (phy->reset_disable) {
512 ret_val = 0;
513 goto out;
514 }
515
516 /* Enable CRS on TX. This must be set for half-duplex operation. */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000517 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800518 if (ret_val)
519 goto out;
520
521 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
522
523 /*
524 * Options:
525 * MDI/MDI-X = 0 (default)
526 * 0 - Auto for all speeds
527 * 1 - MDI mode
528 * 2 - MDI-X mode
529 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
530 */
531 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
532
533 switch (phy->mdix) {
534 case 1:
535 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
536 break;
537 case 2:
538 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
539 break;
540 case 3:
541 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
542 break;
543 case 0:
544 default:
545 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
546 break;
547 }
548
549 /*
550 * Options:
551 * disable_polarity_correction = 0 (default)
552 * Automatic Correction for Reversed Cable Polarity
553 * 0 - Disabled
554 * 1 - Enabled
555 */
556 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
557 if (phy->disable_polarity_correction == 1)
558 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
559
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000560 ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800561 if (ret_val)
562 goto out;
563
564 if (phy->revision < E1000_REVISION_4) {
565 /*
566 * Force TX_CLK in the Extended PHY Specific Control Register
567 * to 25MHz clock.
568 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000569 ret_val = phy->ops.read_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
Auke Kok9d5c8242008-01-24 02:22:38 -0800570 &phy_data);
571 if (ret_val)
572 goto out;
573
574 phy_data |= M88E1000_EPSCR_TX_CLK_25;
575
576 if ((phy->revision == E1000_REVISION_2) &&
577 (phy->id == M88E1111_I_PHY_ID)) {
578 /* 82573L PHY - set the downshift counter to 5x. */
579 phy_data &= ~M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK;
580 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
581 } else {
582 /* Configure Master and Slave downshift values */
583 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
584 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
585 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
586 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
587 }
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000588 ret_val = phy->ops.write_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
Auke Kok9d5c8242008-01-24 02:22:38 -0800589 phy_data);
590 if (ret_val)
591 goto out;
592 }
593
594 /* Commit the changes. */
595 ret_val = igb_phy_sw_reset(hw);
596 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700597 hw_dbg("Error committing the PHY changes\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800598 goto out;
599 }
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000600 if (phy->type == e1000_phy_i210) {
601 ret_val = igb_set_master_slave_mode(hw);
602 if (ret_val)
603 return ret_val;
604 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800605
606out:
607 return ret_val;
608}
609
610/**
Joseph Gasparakis308fb392010-09-22 17:56:44 +0000611 * igb_copper_link_setup_m88_gen2 - Setup m88 PHY's for copper link
612 * @hw: pointer to the HW structure
613 *
614 * Sets up MDI/MDI-X and polarity for i347-AT4, m88e1322 and m88e1112 PHY's.
615 * Also enables and sets the downshift parameters.
616 **/
617s32 igb_copper_link_setup_m88_gen2(struct e1000_hw *hw)
618{
619 struct e1000_phy_info *phy = &hw->phy;
620 s32 ret_val;
621 u16 phy_data;
622
623 if (phy->reset_disable) {
624 ret_val = 0;
625 goto out;
626 }
627
628 /* Enable CRS on Tx. This must be set for half-duplex operation. */
629 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
630 if (ret_val)
631 goto out;
632
633 /*
634 * Options:
635 * MDI/MDI-X = 0 (default)
636 * 0 - Auto for all speeds
637 * 1 - MDI mode
638 * 2 - MDI-X mode
639 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
640 */
641 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
642
643 switch (phy->mdix) {
644 case 1:
645 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
646 break;
647 case 2:
648 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
649 break;
650 case 3:
651 /* M88E1112 does not support this mode) */
652 if (phy->id != M88E1112_E_PHY_ID) {
653 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
654 break;
655 }
656 case 0:
657 default:
658 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
659 break;
660 }
661
662 /*
663 * Options:
664 * disable_polarity_correction = 0 (default)
665 * Automatic Correction for Reversed Cable Polarity
666 * 0 - Disabled
667 * 1 - Enabled
668 */
669 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
670 if (phy->disable_polarity_correction == 1)
671 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
672
673 /* Enable downshift and setting it to X6 */
674 phy_data &= ~I347AT4_PSCR_DOWNSHIFT_MASK;
675 phy_data |= I347AT4_PSCR_DOWNSHIFT_6X;
676 phy_data |= I347AT4_PSCR_DOWNSHIFT_ENABLE;
677
678 ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
679 if (ret_val)
680 goto out;
681
682 /* Commit the changes. */
683 ret_val = igb_phy_sw_reset(hw);
684 if (ret_val) {
685 hw_dbg("Error committing the PHY changes\n");
686 goto out;
687 }
688
689out:
690 return ret_val;
691}
692
693/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700694 * igb_copper_link_setup_igp - Setup igp PHY's for copper link
Auke Kok9d5c8242008-01-24 02:22:38 -0800695 * @hw: pointer to the HW structure
696 *
697 * Sets up LPLU, MDI/MDI-X, polarity, Smartspeed and Master/Slave config for
698 * igp PHY's.
699 **/
700s32 igb_copper_link_setup_igp(struct e1000_hw *hw)
701{
702 struct e1000_phy_info *phy = &hw->phy;
703 s32 ret_val;
704 u16 data;
705
706 if (phy->reset_disable) {
707 ret_val = 0;
708 goto out;
709 }
710
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000711 ret_val = phy->ops.reset(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800712 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700713 hw_dbg("Error resetting the PHY.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800714 goto out;
715 }
716
Alexander Duycka6a60562009-03-31 20:38:38 +0000717 /*
718 * Wait 100ms for MAC to configure PHY from NVM settings, to avoid
719 * timeout issues when LFS is enabled.
720 */
721 msleep(100);
Auke Kok9d5c8242008-01-24 02:22:38 -0800722
723 /*
724 * The NVM settings will configure LPLU in D3 for
725 * non-IGP1 PHYs.
726 */
727 if (phy->type == e1000_phy_igp) {
728 /* disable lplu d3 during driver init */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000729 if (phy->ops.set_d3_lplu_state)
730 ret_val = phy->ops.set_d3_lplu_state(hw, false);
Auke Kok9d5c8242008-01-24 02:22:38 -0800731 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700732 hw_dbg("Error Disabling LPLU D3\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800733 goto out;
734 }
735 }
736
737 /* disable lplu d0 during driver init */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000738 ret_val = phy->ops.set_d0_lplu_state(hw, false);
Auke Kok9d5c8242008-01-24 02:22:38 -0800739 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700740 hw_dbg("Error Disabling LPLU D0\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800741 goto out;
742 }
743 /* Configure mdi-mdix settings */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000744 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CTRL, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800745 if (ret_val)
746 goto out;
747
748 data &= ~IGP01E1000_PSCR_AUTO_MDIX;
749
750 switch (phy->mdix) {
751 case 1:
752 data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
753 break;
754 case 2:
755 data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
756 break;
757 case 0:
758 default:
759 data |= IGP01E1000_PSCR_AUTO_MDIX;
760 break;
761 }
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000762 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CTRL, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800763 if (ret_val)
764 goto out;
765
766 /* set auto-master slave resolution settings */
767 if (hw->mac.autoneg) {
768 /*
769 * when autonegotiation advertisement is only 1000Mbps then we
770 * should disable SmartSpeed and enable Auto MasterSlave
771 * resolution as hardware default.
772 */
773 if (phy->autoneg_advertised == ADVERTISE_1000_FULL) {
774 /* Disable SmartSpeed */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000775 ret_val = phy->ops.read_reg(hw,
776 IGP01E1000_PHY_PORT_CONFIG,
777 &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800778 if (ret_val)
779 goto out;
780
781 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000782 ret_val = phy->ops.write_reg(hw,
Auke Kok9d5c8242008-01-24 02:22:38 -0800783 IGP01E1000_PHY_PORT_CONFIG,
784 data);
785 if (ret_val)
786 goto out;
787
788 /* Set auto Master/Slave resolution process */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000789 ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800790 if (ret_val)
791 goto out;
792
793 data &= ~CR_1000T_MS_ENABLE;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000794 ret_val = phy->ops.write_reg(hw, PHY_1000T_CTRL, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800795 if (ret_val)
796 goto out;
797 }
798
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000799 ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800800 if (ret_val)
801 goto out;
802
803 /* load defaults for future use */
804 phy->original_ms_type = (data & CR_1000T_MS_ENABLE) ?
805 ((data & CR_1000T_MS_VALUE) ?
806 e1000_ms_force_master :
807 e1000_ms_force_slave) :
808 e1000_ms_auto;
809
810 switch (phy->ms_type) {
811 case e1000_ms_force_master:
812 data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
813 break;
814 case e1000_ms_force_slave:
815 data |= CR_1000T_MS_ENABLE;
816 data &= ~(CR_1000T_MS_VALUE);
817 break;
818 case e1000_ms_auto:
819 data &= ~CR_1000T_MS_ENABLE;
820 default:
821 break;
822 }
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000823 ret_val = phy->ops.write_reg(hw, PHY_1000T_CTRL, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800824 if (ret_val)
825 goto out;
826 }
827
828out:
829 return ret_val;
830}
831
832/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700833 * igb_copper_link_autoneg - Setup/Enable autoneg for copper link
Auke Kok9d5c8242008-01-24 02:22:38 -0800834 * @hw: pointer to the HW structure
835 *
836 * Performs initial bounds checking on autoneg advertisement parameter, then
837 * configure to advertise the full capability. Setup the PHY to autoneg
838 * and restart the negotiation process between the link partner. If
839 * autoneg_wait_to_complete, then wait for autoneg to complete before exiting.
840 **/
Alexander Duyck81fadd82009-10-05 06:35:03 +0000841static s32 igb_copper_link_autoneg(struct e1000_hw *hw)
Auke Kok9d5c8242008-01-24 02:22:38 -0800842{
843 struct e1000_phy_info *phy = &hw->phy;
844 s32 ret_val;
845 u16 phy_ctrl;
846
847 /*
848 * Perform some bounds checking on the autoneg advertisement
849 * parameter.
850 */
851 phy->autoneg_advertised &= phy->autoneg_mask;
852
853 /*
854 * If autoneg_advertised is zero, we assume it was not defaulted
855 * by the calling code so we set to advertise full capability.
856 */
857 if (phy->autoneg_advertised == 0)
858 phy->autoneg_advertised = phy->autoneg_mask;
859
Auke Kok652fff32008-06-27 11:00:18 -0700860 hw_dbg("Reconfiguring auto-neg advertisement params\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800861 ret_val = igb_phy_setup_autoneg(hw);
862 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700863 hw_dbg("Error Setting up Auto-Negotiation\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800864 goto out;
865 }
Auke Kok652fff32008-06-27 11:00:18 -0700866 hw_dbg("Restarting Auto-Neg\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800867
868 /*
869 * Restart auto-negotiation by setting the Auto Neg Enable bit and
870 * the Auto Neg Restart bit in the PHY control register.
871 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000872 ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_ctrl);
Auke Kok9d5c8242008-01-24 02:22:38 -0800873 if (ret_val)
874 goto out;
875
876 phy_ctrl |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000877 ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_ctrl);
Auke Kok9d5c8242008-01-24 02:22:38 -0800878 if (ret_val)
879 goto out;
880
881 /*
882 * Does the user want to wait for Auto-Neg to complete here, or
883 * check at a later time (for example, callback routine).
884 */
885 if (phy->autoneg_wait_to_complete) {
886 ret_val = igb_wait_autoneg(hw);
887 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700888 hw_dbg("Error while waiting for "
889 "autoneg to complete\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800890 goto out;
891 }
892 }
893
894 hw->mac.get_link_status = true;
895
896out:
897 return ret_val;
898}
899
900/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700901 * igb_phy_setup_autoneg - Configure PHY for auto-negotiation
Auke Kok9d5c8242008-01-24 02:22:38 -0800902 * @hw: pointer to the HW structure
903 *
904 * Reads the MII auto-neg advertisement register and/or the 1000T control
905 * register and if the PHY is already setup for auto-negotiation, then
906 * return successful. Otherwise, setup advertisement and flow control to
907 * the appropriate values for the wanted auto-negotiation.
908 **/
909static s32 igb_phy_setup_autoneg(struct e1000_hw *hw)
910{
911 struct e1000_phy_info *phy = &hw->phy;
912 s32 ret_val;
913 u16 mii_autoneg_adv_reg;
914 u16 mii_1000t_ctrl_reg = 0;
915
916 phy->autoneg_advertised &= phy->autoneg_mask;
917
918 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000919 ret_val = phy->ops.read_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
Auke Kok9d5c8242008-01-24 02:22:38 -0800920 if (ret_val)
921 goto out;
922
923 if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
924 /* Read the MII 1000Base-T Control Register (Address 9). */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000925 ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL,
Auke Kok9d5c8242008-01-24 02:22:38 -0800926 &mii_1000t_ctrl_reg);
927 if (ret_val)
928 goto out;
929 }
930
931 /*
932 * Need to parse both autoneg_advertised and fc and set up
933 * the appropriate PHY registers. First we will parse for
934 * autoneg_advertised software override. Since we can advertise
935 * a plethora of combinations, we need to check each bit
936 * individually.
937 */
938
939 /*
940 * First we clear all the 10/100 mb speed bits in the Auto-Neg
941 * Advertisement Register (Address 4) and the 1000 mb speed bits in
942 * the 1000Base-T Control Register (Address 9).
943 */
944 mii_autoneg_adv_reg &= ~(NWAY_AR_100TX_FD_CAPS |
945 NWAY_AR_100TX_HD_CAPS |
946 NWAY_AR_10T_FD_CAPS |
947 NWAY_AR_10T_HD_CAPS);
948 mii_1000t_ctrl_reg &= ~(CR_1000T_HD_CAPS | CR_1000T_FD_CAPS);
949
Auke Kok652fff32008-06-27 11:00:18 -0700950 hw_dbg("autoneg_advertised %x\n", phy->autoneg_advertised);
Auke Kok9d5c8242008-01-24 02:22:38 -0800951
952 /* Do we want to advertise 10 Mb Half Duplex? */
953 if (phy->autoneg_advertised & ADVERTISE_10_HALF) {
Auke Kok652fff32008-06-27 11:00:18 -0700954 hw_dbg("Advertise 10mb Half duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800955 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
956 }
957
958 /* Do we want to advertise 10 Mb Full Duplex? */
959 if (phy->autoneg_advertised & ADVERTISE_10_FULL) {
Auke Kok652fff32008-06-27 11:00:18 -0700960 hw_dbg("Advertise 10mb Full duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800961 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
962 }
963
964 /* Do we want to advertise 100 Mb Half Duplex? */
965 if (phy->autoneg_advertised & ADVERTISE_100_HALF) {
Auke Kok652fff32008-06-27 11:00:18 -0700966 hw_dbg("Advertise 100mb Half duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800967 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
968 }
969
970 /* Do we want to advertise 100 Mb Full Duplex? */
971 if (phy->autoneg_advertised & ADVERTISE_100_FULL) {
Auke Kok652fff32008-06-27 11:00:18 -0700972 hw_dbg("Advertise 100mb Full duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800973 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
974 }
975
976 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
977 if (phy->autoneg_advertised & ADVERTISE_1000_HALF)
Auke Kok652fff32008-06-27 11:00:18 -0700978 hw_dbg("Advertise 1000mb Half duplex request denied!\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800979
980 /* Do we want to advertise 1000 Mb Full Duplex? */
981 if (phy->autoneg_advertised & ADVERTISE_1000_FULL) {
Auke Kok652fff32008-06-27 11:00:18 -0700982 hw_dbg("Advertise 1000mb Full duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800983 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
984 }
985
986 /*
987 * Check for a software override of the flow control settings, and
988 * setup the PHY advertisement registers accordingly. If
989 * auto-negotiation is enabled, then software will have to set the
990 * "PAUSE" bits to the correct value in the Auto-Negotiation
991 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-
992 * negotiation.
993 *
994 * The possible values of the "fc" parameter are:
995 * 0: Flow control is completely disabled
996 * 1: Rx flow control is enabled (we can receive pause frames
997 * but not send pause frames).
998 * 2: Tx flow control is enabled (we can send pause frames
999 * but we do not support receiving pause frames).
1000 * 3: Both Rx and TX flow control (symmetric) are enabled.
1001 * other: No software override. The flow control configuration
1002 * in the EEPROM is used.
1003 */
Alexander Duyck0cce1192009-07-23 18:10:24 +00001004 switch (hw->fc.current_mode) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001005 case e1000_fc_none:
1006 /*
1007 * Flow control (RX & TX) is completely disabled by a
1008 * software over-ride.
1009 */
1010 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1011 break;
1012 case e1000_fc_rx_pause:
1013 /*
1014 * RX Flow control is enabled, and TX Flow control is
1015 * disabled, by a software over-ride.
1016 *
1017 * Since there really isn't a way to advertise that we are
1018 * capable of RX Pause ONLY, we will advertise that we
1019 * support both symmetric and asymmetric RX PAUSE. Later
1020 * (in e1000_config_fc_after_link_up) we will disable the
1021 * hw's ability to send PAUSE frames.
1022 */
1023 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1024 break;
1025 case e1000_fc_tx_pause:
1026 /*
1027 * TX Flow control is enabled, and RX Flow control is
1028 * disabled, by a software over-ride.
1029 */
1030 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
1031 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
1032 break;
1033 case e1000_fc_full:
1034 /*
1035 * Flow control (both RX and TX) is enabled by a software
1036 * over-ride.
1037 */
1038 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1039 break;
1040 default:
Auke Kok652fff32008-06-27 11:00:18 -07001041 hw_dbg("Flow control param set incorrectly\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001042 ret_val = -E1000_ERR_CONFIG;
1043 goto out;
1044 }
1045
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001046 ret_val = phy->ops.write_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001047 if (ret_val)
1048 goto out;
1049
Auke Kok652fff32008-06-27 11:00:18 -07001050 hw_dbg("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001051
1052 if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001053 ret_val = phy->ops.write_reg(hw,
1054 PHY_1000T_CTRL,
1055 mii_1000t_ctrl_reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001056 if (ret_val)
1057 goto out;
1058 }
1059
1060out:
1061 return ret_val;
1062}
1063
1064/**
Alexander Duyck81fadd82009-10-05 06:35:03 +00001065 * igb_setup_copper_link - Configure copper link settings
1066 * @hw: pointer to the HW structure
1067 *
1068 * Calls the appropriate function to configure the link for auto-neg or forced
1069 * speed and duplex. Then we check for link, once link is established calls
1070 * to configure collision distance and flow control are called. If link is
1071 * not established, we return -E1000_ERR_PHY (-2).
1072 **/
1073s32 igb_setup_copper_link(struct e1000_hw *hw)
1074{
1075 s32 ret_val;
1076 bool link;
1077
1078
1079 if (hw->mac.autoneg) {
1080 /*
1081 * Setup autoneg and flow control advertisement and perform
1082 * autonegotiation.
1083 */
1084 ret_val = igb_copper_link_autoneg(hw);
1085 if (ret_val)
1086 goto out;
1087 } else {
1088 /*
1089 * PHY will be set to 10H, 10F, 100H or 100F
1090 * depending on user settings.
1091 */
1092 hw_dbg("Forcing Speed and Duplex\n");
1093 ret_val = hw->phy.ops.force_speed_duplex(hw);
1094 if (ret_val) {
1095 hw_dbg("Error Forcing Speed and Duplex\n");
1096 goto out;
1097 }
1098 }
1099
1100 /*
1101 * Check link status. Wait up to 100 microseconds for link to become
1102 * valid.
1103 */
1104 ret_val = igb_phy_has_link(hw,
1105 COPPER_LINK_UP_LIMIT,
1106 10,
1107 &link);
1108 if (ret_val)
1109 goto out;
1110
1111 if (link) {
1112 hw_dbg("Valid link established!!!\n");
1113 igb_config_collision_dist(hw);
1114 ret_val = igb_config_fc_after_link_up(hw);
1115 } else {
1116 hw_dbg("Unable to establish link!!!\n");
1117 }
1118
1119out:
1120 return ret_val;
1121}
1122
1123/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001124 * igb_phy_force_speed_duplex_igp - Force speed/duplex for igp PHY
Auke Kok9d5c8242008-01-24 02:22:38 -08001125 * @hw: pointer to the HW structure
1126 *
1127 * Calls the PHY setup function to force speed and duplex. Clears the
1128 * auto-crossover to force MDI manually. Waits for link and returns
1129 * successful if link up is successful, else -E1000_ERR_PHY (-2).
1130 **/
1131s32 igb_phy_force_speed_duplex_igp(struct e1000_hw *hw)
1132{
1133 struct e1000_phy_info *phy = &hw->phy;
1134 s32 ret_val;
1135 u16 phy_data;
1136 bool link;
1137
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001138 ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001139 if (ret_val)
1140 goto out;
1141
1142 igb_phy_force_speed_duplex_setup(hw, &phy_data);
1143
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001144 ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001145 if (ret_val)
1146 goto out;
1147
1148 /*
1149 * Clear Auto-Crossover to force MDI manually. IGP requires MDI
1150 * forced whenever speed and duplex are forced.
1151 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001152 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001153 if (ret_val)
1154 goto out;
1155
1156 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1157 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1158
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001159 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001160 if (ret_val)
1161 goto out;
1162
Auke Kok652fff32008-06-27 11:00:18 -07001163 hw_dbg("IGP PSCR: %X\n", phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001164
1165 udelay(1);
1166
1167 if (phy->autoneg_wait_to_complete) {
Auke Kok652fff32008-06-27 11:00:18 -07001168 hw_dbg("Waiting for forced speed/duplex link on IGP phy.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001169
1170 ret_val = igb_phy_has_link(hw,
1171 PHY_FORCE_LIMIT,
1172 100000,
1173 &link);
1174 if (ret_val)
1175 goto out;
1176
1177 if (!link)
Auke Kok652fff32008-06-27 11:00:18 -07001178 hw_dbg("Link taking longer than expected.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001179
1180 /* Try once more */
1181 ret_val = igb_phy_has_link(hw,
1182 PHY_FORCE_LIMIT,
1183 100000,
1184 &link);
1185 if (ret_val)
1186 goto out;
1187 }
1188
1189out:
1190 return ret_val;
1191}
1192
1193/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001194 * igb_phy_force_speed_duplex_m88 - Force speed/duplex for m88 PHY
Auke Kok9d5c8242008-01-24 02:22:38 -08001195 * @hw: pointer to the HW structure
1196 *
1197 * Calls the PHY setup function to force speed and duplex. Clears the
1198 * auto-crossover to force MDI manually. Resets the PHY to commit the
1199 * changes. If time expires while waiting for link up, we reset the DSP.
1200 * After reset, TX_CLK and CRS on TX must be set. Return successful upon
1201 * successful completion, else return corresponding error code.
1202 **/
1203s32 igb_phy_force_speed_duplex_m88(struct e1000_hw *hw)
1204{
1205 struct e1000_phy_info *phy = &hw->phy;
1206 s32 ret_val;
1207 u16 phy_data;
1208 bool link;
1209
Matthew Vick9f0b8512012-10-16 07:44:45 +00001210 /* I210 and I211 devices support Auto-Crossover in forced operation. */
1211 if (phy->type != e1000_phy_i210) {
1212 /*
1213 * Clear Auto-Crossover to force MDI manually. M88E1000
1214 * requires MDI forced whenever speed and duplex are forced.
1215 */
1216 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL,
1217 &phy_data);
1218 if (ret_val)
1219 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -08001220
Matthew Vick9f0b8512012-10-16 07:44:45 +00001221 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1222 ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL,
1223 phy_data);
1224 if (ret_val)
1225 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -08001226
Matthew Vick9f0b8512012-10-16 07:44:45 +00001227 hw_dbg("M88E1000 PSCR: %X\n", phy_data);
1228 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001229
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001230 ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001231 if (ret_val)
1232 goto out;
1233
1234 igb_phy_force_speed_duplex_setup(hw, &phy_data);
1235
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001236 ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001237 if (ret_val)
1238 goto out;
1239
Alexander Duyck2553bb22009-10-05 06:35:42 +00001240 /* Reset the phy to commit changes. */
1241 ret_val = igb_phy_sw_reset(hw);
1242 if (ret_val)
1243 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -08001244
1245 if (phy->autoneg_wait_to_complete) {
Auke Kok652fff32008-06-27 11:00:18 -07001246 hw_dbg("Waiting for forced speed/duplex link on M88 phy.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001247
Alexander Duyck2553bb22009-10-05 06:35:42 +00001248 ret_val = igb_phy_has_link(hw, PHY_FORCE_LIMIT, 100000, &link);
Auke Kok9d5c8242008-01-24 02:22:38 -08001249 if (ret_val)
1250 goto out;
1251
1252 if (!link) {
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001253 bool reset_dsp = true;
Joseph Gasparakis308fb392010-09-22 17:56:44 +00001254
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001255 switch (hw->phy.id) {
1256 case I347AT4_E_PHY_ID:
1257 case M88E1112_E_PHY_ID:
1258 case I210_I_PHY_ID:
1259 reset_dsp = false;
1260 break;
1261 default:
1262 if (hw->phy.type != e1000_phy_m88)
1263 reset_dsp = false;
1264 break;
1265 }
1266 if (!reset_dsp)
1267 hw_dbg("Link taking longer than expected.\n");
1268 else {
Joseph Gasparakis308fb392010-09-22 17:56:44 +00001269 /*
1270 * We didn't get link.
1271 * Reset the DSP and cross our fingers.
1272 */
1273 ret_val = phy->ops.write_reg(hw,
1274 M88E1000_PHY_PAGE_SELECT,
1275 0x001d);
1276 if (ret_val)
1277 goto out;
1278 ret_val = igb_phy_reset_dsp(hw);
1279 if (ret_val)
1280 goto out;
1281 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001282 }
1283
1284 /* Try once more */
1285 ret_val = igb_phy_has_link(hw, PHY_FORCE_LIMIT,
Alexander Duyck2553bb22009-10-05 06:35:42 +00001286 100000, &link);
Auke Kok9d5c8242008-01-24 02:22:38 -08001287 if (ret_val)
1288 goto out;
1289 }
1290
Joseph Gasparakis308fb392010-09-22 17:56:44 +00001291 if (hw->phy.type != e1000_phy_m88 ||
1292 hw->phy.id == I347AT4_E_PHY_ID ||
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001293 hw->phy.id == M88E1112_E_PHY_ID ||
1294 hw->phy.id == I210_I_PHY_ID)
Joseph Gasparakis308fb392010-09-22 17:56:44 +00001295 goto out;
1296
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001297 ret_val = phy->ops.read_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001298 if (ret_val)
1299 goto out;
1300
1301 /*
1302 * Resetting the phy means we need to re-force TX_CLK in the
1303 * Extended PHY Specific Control Register to 25MHz clock from
1304 * the reset value of 2.5MHz.
1305 */
1306 phy_data |= M88E1000_EPSCR_TX_CLK_25;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001307 ret_val = phy->ops.write_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001308 if (ret_val)
1309 goto out;
1310
1311 /*
1312 * In addition, we must re-enable CRS on Tx for both half and full
1313 * duplex.
1314 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001315 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001316 if (ret_val)
1317 goto out;
1318
1319 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001320 ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001321
1322out:
1323 return ret_val;
1324}
1325
1326/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001327 * igb_phy_force_speed_duplex_setup - Configure forced PHY speed/duplex
Auke Kok9d5c8242008-01-24 02:22:38 -08001328 * @hw: pointer to the HW structure
1329 * @phy_ctrl: pointer to current value of PHY_CONTROL
1330 *
1331 * Forces speed and duplex on the PHY by doing the following: disable flow
1332 * control, force speed/duplex on the MAC, disable auto speed detection,
1333 * disable auto-negotiation, configure duplex, configure speed, configure
1334 * the collision distance, write configuration to CTRL register. The
1335 * caller must write to the PHY_CONTROL register for these settings to
1336 * take affect.
1337 **/
1338static void igb_phy_force_speed_duplex_setup(struct e1000_hw *hw,
1339 u16 *phy_ctrl)
1340{
1341 struct e1000_mac_info *mac = &hw->mac;
1342 u32 ctrl;
1343
1344 /* Turn off flow control when forcing speed/duplex */
Alexander Duyck0cce1192009-07-23 18:10:24 +00001345 hw->fc.current_mode = e1000_fc_none;
Auke Kok9d5c8242008-01-24 02:22:38 -08001346
1347 /* Force speed/duplex on the mac */
1348 ctrl = rd32(E1000_CTRL);
1349 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1350 ctrl &= ~E1000_CTRL_SPD_SEL;
1351
1352 /* Disable Auto Speed Detection */
1353 ctrl &= ~E1000_CTRL_ASDE;
1354
1355 /* Disable autoneg on the phy */
1356 *phy_ctrl &= ~MII_CR_AUTO_NEG_EN;
1357
1358 /* Forcing Full or Half Duplex? */
1359 if (mac->forced_speed_duplex & E1000_ALL_HALF_DUPLEX) {
1360 ctrl &= ~E1000_CTRL_FD;
1361 *phy_ctrl &= ~MII_CR_FULL_DUPLEX;
Auke Kok652fff32008-06-27 11:00:18 -07001362 hw_dbg("Half Duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001363 } else {
1364 ctrl |= E1000_CTRL_FD;
1365 *phy_ctrl |= MII_CR_FULL_DUPLEX;
Auke Kok652fff32008-06-27 11:00:18 -07001366 hw_dbg("Full Duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001367 }
1368
1369 /* Forcing 10mb or 100mb? */
1370 if (mac->forced_speed_duplex & E1000_ALL_100_SPEED) {
1371 ctrl |= E1000_CTRL_SPD_100;
1372 *phy_ctrl |= MII_CR_SPEED_100;
1373 *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
Auke Kok652fff32008-06-27 11:00:18 -07001374 hw_dbg("Forcing 100mb\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001375 } else {
1376 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1377 *phy_ctrl |= MII_CR_SPEED_10;
1378 *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
Auke Kok652fff32008-06-27 11:00:18 -07001379 hw_dbg("Forcing 10mb\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001380 }
1381
1382 igb_config_collision_dist(hw);
1383
1384 wr32(E1000_CTRL, ctrl);
1385}
1386
1387/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001388 * igb_set_d3_lplu_state - Sets low power link up state for D3
Auke Kok9d5c8242008-01-24 02:22:38 -08001389 * @hw: pointer to the HW structure
1390 * @active: boolean used to enable/disable lplu
1391 *
1392 * Success returns 0, Failure returns 1
1393 *
1394 * The low power link up (lplu) state is set to the power management level D3
1395 * and SmartSpeed is disabled when active is true, else clear lplu for D3
1396 * and enable Smartspeed. LPLU and Smartspeed are mutually exclusive. LPLU
1397 * is used during Dx states where the power conservation is most important.
1398 * During driver activity, SmartSpeed should be enabled so performance is
1399 * maintained.
1400 **/
1401s32 igb_set_d3_lplu_state(struct e1000_hw *hw, bool active)
1402{
1403 struct e1000_phy_info *phy = &hw->phy;
Alexander Duyck2553bb22009-10-05 06:35:42 +00001404 s32 ret_val = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08001405 u16 data;
1406
Alexander Duyck2553bb22009-10-05 06:35:42 +00001407 if (!(hw->phy.ops.read_reg))
1408 goto out;
1409
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001410 ret_val = phy->ops.read_reg(hw, IGP02E1000_PHY_POWER_MGMT, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001411 if (ret_val)
1412 goto out;
1413
1414 if (!active) {
1415 data &= ~IGP02E1000_PM_D3_LPLU;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001416 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
Auke Kok9d5c8242008-01-24 02:22:38 -08001417 data);
1418 if (ret_val)
1419 goto out;
1420 /*
1421 * LPLU and SmartSpeed are mutually exclusive. LPLU is used
1422 * during Dx states where the power conservation is most
1423 * important. During driver activity we should enable
1424 * SmartSpeed, so performance is maintained.
1425 */
1426 if (phy->smart_speed == e1000_smart_speed_on) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001427 ret_val = phy->ops.read_reg(hw,
Auke Kok9d5c8242008-01-24 02:22:38 -08001428 IGP01E1000_PHY_PORT_CONFIG,
1429 &data);
1430 if (ret_val)
1431 goto out;
1432
1433 data |= IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001434 ret_val = phy->ops.write_reg(hw,
Auke Kok9d5c8242008-01-24 02:22:38 -08001435 IGP01E1000_PHY_PORT_CONFIG,
1436 data);
1437 if (ret_val)
1438 goto out;
1439 } else if (phy->smart_speed == e1000_smart_speed_off) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001440 ret_val = phy->ops.read_reg(hw,
Auke Kok9d5c8242008-01-24 02:22:38 -08001441 IGP01E1000_PHY_PORT_CONFIG,
1442 &data);
1443 if (ret_val)
1444 goto out;
1445
1446 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001447 ret_val = phy->ops.write_reg(hw,
Auke Kok9d5c8242008-01-24 02:22:38 -08001448 IGP01E1000_PHY_PORT_CONFIG,
1449 data);
1450 if (ret_val)
1451 goto out;
1452 }
1453 } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
1454 (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
1455 (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
1456 data |= IGP02E1000_PM_D3_LPLU;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001457 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
Auke Kok9d5c8242008-01-24 02:22:38 -08001458 data);
1459 if (ret_val)
1460 goto out;
1461
1462 /* When LPLU is enabled, we should disable SmartSpeed */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001463 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
Auke Kok9d5c8242008-01-24 02:22:38 -08001464 &data);
1465 if (ret_val)
1466 goto out;
1467
1468 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001469 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
Auke Kok9d5c8242008-01-24 02:22:38 -08001470 data);
1471 }
1472
1473out:
1474 return ret_val;
1475}
1476
1477/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001478 * igb_check_downshift - Checks whether a downshift in speed occurred
Auke Kok9d5c8242008-01-24 02:22:38 -08001479 * @hw: pointer to the HW structure
1480 *
1481 * Success returns 0, Failure returns 1
1482 *
1483 * A downshift is detected by querying the PHY link health.
1484 **/
1485s32 igb_check_downshift(struct e1000_hw *hw)
1486{
1487 struct e1000_phy_info *phy = &hw->phy;
1488 s32 ret_val;
1489 u16 phy_data, offset, mask;
1490
1491 switch (phy->type) {
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001492 case e1000_phy_i210:
Auke Kok9d5c8242008-01-24 02:22:38 -08001493 case e1000_phy_m88:
1494 case e1000_phy_gg82563:
1495 offset = M88E1000_PHY_SPEC_STATUS;
1496 mask = M88E1000_PSSR_DOWNSHIFT;
1497 break;
1498 case e1000_phy_igp_2:
1499 case e1000_phy_igp:
1500 case e1000_phy_igp_3:
1501 offset = IGP01E1000_PHY_LINK_HEALTH;
1502 mask = IGP01E1000_PLHR_SS_DOWNGRADE;
1503 break;
1504 default:
1505 /* speed downshift not supported */
1506 phy->speed_downgraded = false;
1507 ret_val = 0;
1508 goto out;
1509 }
1510
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001511 ret_val = phy->ops.read_reg(hw, offset, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001512
1513 if (!ret_val)
1514 phy->speed_downgraded = (phy_data & mask) ? true : false;
1515
1516out:
1517 return ret_val;
1518}
1519
1520/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001521 * igb_check_polarity_m88 - Checks the polarity.
Auke Kok9d5c8242008-01-24 02:22:38 -08001522 * @hw: pointer to the HW structure
1523 *
1524 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1525 *
1526 * Polarity is determined based on the PHY specific status register.
1527 **/
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001528s32 igb_check_polarity_m88(struct e1000_hw *hw)
Auke Kok9d5c8242008-01-24 02:22:38 -08001529{
1530 struct e1000_phy_info *phy = &hw->phy;
1531 s32 ret_val;
1532 u16 data;
1533
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001534 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001535
1536 if (!ret_val)
1537 phy->cable_polarity = (data & M88E1000_PSSR_REV_POLARITY)
1538 ? e1000_rev_polarity_reversed
1539 : e1000_rev_polarity_normal;
1540
1541 return ret_val;
1542}
1543
1544/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001545 * igb_check_polarity_igp - Checks the polarity.
Auke Kok9d5c8242008-01-24 02:22:38 -08001546 * @hw: pointer to the HW structure
1547 *
1548 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1549 *
1550 * Polarity is determined based on the PHY port status register, and the
1551 * current speed (since there is no polarity at 100Mbps).
1552 **/
1553static s32 igb_check_polarity_igp(struct e1000_hw *hw)
1554{
1555 struct e1000_phy_info *phy = &hw->phy;
1556 s32 ret_val;
1557 u16 data, offset, mask;
1558
1559 /*
1560 * Polarity is determined based on the speed of
1561 * our connection.
1562 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001563 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_STATUS, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001564 if (ret_val)
1565 goto out;
1566
1567 if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
1568 IGP01E1000_PSSR_SPEED_1000MBPS) {
1569 offset = IGP01E1000_PHY_PCS_INIT_REG;
1570 mask = IGP01E1000_PHY_POLARITY_MASK;
1571 } else {
1572 /*
1573 * This really only applies to 10Mbps since
1574 * there is no polarity for 100Mbps (always 0).
1575 */
1576 offset = IGP01E1000_PHY_PORT_STATUS;
1577 mask = IGP01E1000_PSSR_POLARITY_REVERSED;
1578 }
1579
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001580 ret_val = phy->ops.read_reg(hw, offset, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001581
1582 if (!ret_val)
1583 phy->cable_polarity = (data & mask)
1584 ? e1000_rev_polarity_reversed
1585 : e1000_rev_polarity_normal;
1586
1587out:
1588 return ret_val;
1589}
1590
1591/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001592 * igb_wait_autoneg - Wait for auto-neg compeletion
Auke Kok9d5c8242008-01-24 02:22:38 -08001593 * @hw: pointer to the HW structure
1594 *
1595 * Waits for auto-negotiation to complete or for the auto-negotiation time
1596 * limit to expire, which ever happens first.
1597 **/
1598static s32 igb_wait_autoneg(struct e1000_hw *hw)
1599{
1600 s32 ret_val = 0;
1601 u16 i, phy_status;
1602
1603 /* Break after autoneg completes or PHY_AUTO_NEG_LIMIT expires. */
1604 for (i = PHY_AUTO_NEG_LIMIT; i > 0; i--) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001605 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
Auke Kok9d5c8242008-01-24 02:22:38 -08001606 if (ret_val)
1607 break;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001608 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
Auke Kok9d5c8242008-01-24 02:22:38 -08001609 if (ret_val)
1610 break;
1611 if (phy_status & MII_SR_AUTONEG_COMPLETE)
1612 break;
1613 msleep(100);
1614 }
1615
1616 /*
1617 * PHY_AUTO_NEG_TIME expiration doesn't guarantee auto-negotiation
1618 * has completed.
1619 */
1620 return ret_val;
1621}
1622
1623/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001624 * igb_phy_has_link - Polls PHY for link
Auke Kok9d5c8242008-01-24 02:22:38 -08001625 * @hw: pointer to the HW structure
1626 * @iterations: number of times to poll for link
1627 * @usec_interval: delay between polling attempts
1628 * @success: pointer to whether polling was successful or not
1629 *
1630 * Polls the PHY status register for link, 'iterations' number of times.
1631 **/
1632s32 igb_phy_has_link(struct e1000_hw *hw, u32 iterations,
1633 u32 usec_interval, bool *success)
1634{
1635 s32 ret_val = 0;
1636 u16 i, phy_status;
1637
1638 for (i = 0; i < iterations; i++) {
1639 /*
1640 * Some PHYs require the PHY_STATUS register to be read
1641 * twice due to the link bit being sticky. No harm doing
1642 * it across the board.
1643 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001644 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
Alexander Duyckab576382009-10-05 06:35:23 +00001645 if (ret_val) {
1646 /*
1647 * If the first read fails, another entity may have
1648 * ownership of the resources, wait and try again to
1649 * see if they have relinquished the resources yet.
1650 */
1651 udelay(usec_interval);
1652 }
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001653 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
Auke Kok9d5c8242008-01-24 02:22:38 -08001654 if (ret_val)
1655 break;
1656 if (phy_status & MII_SR_LINK_STATUS)
1657 break;
1658 if (usec_interval >= 1000)
1659 mdelay(usec_interval/1000);
1660 else
1661 udelay(usec_interval);
1662 }
1663
1664 *success = (i < iterations) ? true : false;
1665
1666 return ret_val;
1667}
1668
1669/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001670 * igb_get_cable_length_m88 - Determine cable length for m88 PHY
Auke Kok9d5c8242008-01-24 02:22:38 -08001671 * @hw: pointer to the HW structure
1672 *
1673 * Reads the PHY specific status register to retrieve the cable length
1674 * information. The cable length is determined by averaging the minimum and
1675 * maximum values to get the "average" cable length. The m88 PHY has four
1676 * possible cable length values, which are:
1677 * Register Value Cable Length
1678 * 0 < 50 meters
1679 * 1 50 - 80 meters
1680 * 2 80 - 110 meters
1681 * 3 110 - 140 meters
1682 * 4 > 140 meters
1683 **/
1684s32 igb_get_cable_length_m88(struct e1000_hw *hw)
1685{
1686 struct e1000_phy_info *phy = &hw->phy;
1687 s32 ret_val;
1688 u16 phy_data, index;
1689
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001690 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001691 if (ret_val)
1692 goto out;
1693
1694 index = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
1695 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
Alexander Duyck2553bb22009-10-05 06:35:42 +00001696 if (index >= M88E1000_CABLE_LENGTH_TABLE_SIZE - 1) {
1697 ret_val = -E1000_ERR_PHY;
1698 goto out;
1699 }
1700
Auke Kok9d5c8242008-01-24 02:22:38 -08001701 phy->min_cable_length = e1000_m88_cable_length_table[index];
Alexander Duyck2553bb22009-10-05 06:35:42 +00001702 phy->max_cable_length = e1000_m88_cable_length_table[index + 1];
Auke Kok9d5c8242008-01-24 02:22:38 -08001703
1704 phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
1705
1706out:
1707 return ret_val;
1708}
1709
Joseph Gasparakis308fb392010-09-22 17:56:44 +00001710s32 igb_get_cable_length_m88_gen2(struct e1000_hw *hw)
1711{
1712 struct e1000_phy_info *phy = &hw->phy;
1713 s32 ret_val;
1714 u16 phy_data, phy_data2, index, default_page, is_cm;
1715
1716 switch (hw->phy.id) {
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001717 case I210_I_PHY_ID:
Carolyn Wyborny59f30102012-10-10 04:42:59 +00001718 /* Get cable length from PHY Cable Diagnostics Control Reg */
1719 ret_val = phy->ops.read_reg(hw, (0x7 << GS40G_PAGE_SHIFT) +
1720 (I347AT4_PCDL + phy->addr),
1721 &phy_data);
1722 if (ret_val)
1723 return ret_val;
1724
1725 /* Check if the unit of cable length is meters or cm */
1726 ret_val = phy->ops.read_reg(hw, (0x7 << GS40G_PAGE_SHIFT) +
1727 I347AT4_PCDC, &phy_data2);
1728 if (ret_val)
1729 return ret_val;
1730
1731 is_cm = !(phy_data2 & I347AT4_PCDC_CABLE_LENGTH_UNIT);
1732
1733 /* Populate the phy structure with cable length in meters */
1734 phy->min_cable_length = phy_data / (is_cm ? 100 : 1);
1735 phy->max_cable_length = phy_data / (is_cm ? 100 : 1);
1736 phy->cable_length = phy_data / (is_cm ? 100 : 1);
1737 break;
Joseph Gasparakis308fb392010-09-22 17:56:44 +00001738 case I347AT4_E_PHY_ID:
1739 /* Remember the original page select and set it to 7 */
1740 ret_val = phy->ops.read_reg(hw, I347AT4_PAGE_SELECT,
1741 &default_page);
1742 if (ret_val)
1743 goto out;
1744
1745 ret_val = phy->ops.write_reg(hw, I347AT4_PAGE_SELECT, 0x07);
1746 if (ret_val)
1747 goto out;
1748
1749 /* Get cable length from PHY Cable Diagnostics Control Reg */
1750 ret_val = phy->ops.read_reg(hw, (I347AT4_PCDL + phy->addr),
1751 &phy_data);
1752 if (ret_val)
1753 goto out;
1754
1755 /* Check if the unit of cable length is meters or cm */
1756 ret_val = phy->ops.read_reg(hw, I347AT4_PCDC, &phy_data2);
1757 if (ret_val)
1758 goto out;
1759
Kantecki, Tomaszd5a0e362011-10-17 22:06:59 +00001760 is_cm = !(phy_data2 & I347AT4_PCDC_CABLE_LENGTH_UNIT);
Joseph Gasparakis308fb392010-09-22 17:56:44 +00001761
1762 /* Populate the phy structure with cable length in meters */
1763 phy->min_cable_length = phy_data / (is_cm ? 100 : 1);
1764 phy->max_cable_length = phy_data / (is_cm ? 100 : 1);
1765 phy->cable_length = phy_data / (is_cm ? 100 : 1);
1766
1767 /* Reset the page selec to its original value */
1768 ret_val = phy->ops.write_reg(hw, I347AT4_PAGE_SELECT,
1769 default_page);
1770 if (ret_val)
1771 goto out;
1772 break;
1773 case M88E1112_E_PHY_ID:
1774 /* Remember the original page select and set it to 5 */
1775 ret_val = phy->ops.read_reg(hw, I347AT4_PAGE_SELECT,
1776 &default_page);
1777 if (ret_val)
1778 goto out;
1779
1780 ret_val = phy->ops.write_reg(hw, I347AT4_PAGE_SELECT, 0x05);
1781 if (ret_val)
1782 goto out;
1783
1784 ret_val = phy->ops.read_reg(hw, M88E1112_VCT_DSP_DISTANCE,
1785 &phy_data);
1786 if (ret_val)
1787 goto out;
1788
1789 index = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
1790 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
1791 if (index >= M88E1000_CABLE_LENGTH_TABLE_SIZE - 1) {
1792 ret_val = -E1000_ERR_PHY;
1793 goto out;
1794 }
1795
1796 phy->min_cable_length = e1000_m88_cable_length_table[index];
1797 phy->max_cable_length = e1000_m88_cable_length_table[index + 1];
1798
1799 phy->cable_length = (phy->min_cable_length +
1800 phy->max_cable_length) / 2;
1801
1802 /* Reset the page select to its original value */
1803 ret_val = phy->ops.write_reg(hw, I347AT4_PAGE_SELECT,
1804 default_page);
1805 if (ret_val)
1806 goto out;
1807
1808 break;
1809 default:
1810 ret_val = -E1000_ERR_PHY;
1811 goto out;
1812 }
1813
1814out:
1815 return ret_val;
1816}
1817
Auke Kok9d5c8242008-01-24 02:22:38 -08001818/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001819 * igb_get_cable_length_igp_2 - Determine cable length for igp2 PHY
Auke Kok9d5c8242008-01-24 02:22:38 -08001820 * @hw: pointer to the HW structure
1821 *
1822 * The automatic gain control (agc) normalizes the amplitude of the
1823 * received signal, adjusting for the attenuation produced by the
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001824 * cable. By reading the AGC registers, which represent the
1825 * combination of coarse and fine gain value, the value can be put
Auke Kok9d5c8242008-01-24 02:22:38 -08001826 * into a lookup table to obtain the approximate cable length
1827 * for each channel.
1828 **/
1829s32 igb_get_cable_length_igp_2(struct e1000_hw *hw)
1830{
1831 struct e1000_phy_info *phy = &hw->phy;
1832 s32 ret_val = 0;
1833 u16 phy_data, i, agc_value = 0;
1834 u16 cur_agc_index, max_agc_index = 0;
1835 u16 min_agc_index = IGP02E1000_CABLE_LENGTH_TABLE_SIZE - 1;
Jeff Kirsher66744502010-12-01 19:59:50 +00001836 static const u16 agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] = {
1837 IGP02E1000_PHY_AGC_A,
1838 IGP02E1000_PHY_AGC_B,
1839 IGP02E1000_PHY_AGC_C,
1840 IGP02E1000_PHY_AGC_D
1841 };
Auke Kok9d5c8242008-01-24 02:22:38 -08001842
1843 /* Read the AGC registers for all channels */
1844 for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001845 ret_val = phy->ops.read_reg(hw, agc_reg_array[i], &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001846 if (ret_val)
1847 goto out;
1848
1849 /*
1850 * Getting bits 15:9, which represent the combination of
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001851 * coarse and fine gain values. The result is a number
Auke Kok9d5c8242008-01-24 02:22:38 -08001852 * that can be put into the lookup table to obtain the
1853 * approximate cable length.
1854 */
1855 cur_agc_index = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
1856 IGP02E1000_AGC_LENGTH_MASK;
1857
1858 /* Array index bound check. */
1859 if ((cur_agc_index >= IGP02E1000_CABLE_LENGTH_TABLE_SIZE) ||
1860 (cur_agc_index == 0)) {
1861 ret_val = -E1000_ERR_PHY;
1862 goto out;
1863 }
1864
1865 /* Remove min & max AGC values from calculation. */
1866 if (e1000_igp_2_cable_length_table[min_agc_index] >
1867 e1000_igp_2_cable_length_table[cur_agc_index])
1868 min_agc_index = cur_agc_index;
1869 if (e1000_igp_2_cable_length_table[max_agc_index] <
1870 e1000_igp_2_cable_length_table[cur_agc_index])
1871 max_agc_index = cur_agc_index;
1872
1873 agc_value += e1000_igp_2_cable_length_table[cur_agc_index];
1874 }
1875
1876 agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] +
1877 e1000_igp_2_cable_length_table[max_agc_index]);
1878 agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
1879
1880 /* Calculate cable length with the error range of +/- 10 meters. */
1881 phy->min_cable_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
1882 (agc_value - IGP02E1000_AGC_RANGE) : 0;
1883 phy->max_cable_length = agc_value + IGP02E1000_AGC_RANGE;
1884
1885 phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
1886
1887out:
1888 return ret_val;
1889}
1890
1891/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001892 * igb_get_phy_info_m88 - Retrieve PHY information
Auke Kok9d5c8242008-01-24 02:22:38 -08001893 * @hw: pointer to the HW structure
1894 *
1895 * Valid for only copper links. Read the PHY status register (sticky read)
1896 * to verify that link is up. Read the PHY special control register to
1897 * determine the polarity and 10base-T extended distance. Read the PHY
1898 * special status register to determine MDI/MDIx and current speed. If
1899 * speed is 1000, then determine cable length, local and remote receiver.
1900 **/
1901s32 igb_get_phy_info_m88(struct e1000_hw *hw)
1902{
1903 struct e1000_phy_info *phy = &hw->phy;
1904 s32 ret_val;
1905 u16 phy_data;
1906 bool link;
1907
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001908 if (phy->media_type != e1000_media_type_copper) {
Auke Kok652fff32008-06-27 11:00:18 -07001909 hw_dbg("Phy info is only valid for copper media\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001910 ret_val = -E1000_ERR_CONFIG;
1911 goto out;
1912 }
1913
1914 ret_val = igb_phy_has_link(hw, 1, 0, &link);
1915 if (ret_val)
1916 goto out;
1917
1918 if (!link) {
Auke Kok652fff32008-06-27 11:00:18 -07001919 hw_dbg("Phy info is only valid if link is up\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001920 ret_val = -E1000_ERR_CONFIG;
1921 goto out;
1922 }
1923
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001924 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001925 if (ret_val)
1926 goto out;
1927
1928 phy->polarity_correction = (phy_data & M88E1000_PSCR_POLARITY_REVERSAL)
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001929 ? true : false;
Auke Kok9d5c8242008-01-24 02:22:38 -08001930
1931 ret_val = igb_check_polarity_m88(hw);
1932 if (ret_val)
1933 goto out;
1934
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001935 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001936 if (ret_val)
1937 goto out;
1938
1939 phy->is_mdix = (phy_data & M88E1000_PSSR_MDIX) ? true : false;
1940
1941 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001942 ret_val = phy->ops.get_cable_length(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001943 if (ret_val)
1944 goto out;
1945
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001946 ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001947 if (ret_val)
1948 goto out;
1949
1950 phy->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS)
1951 ? e1000_1000t_rx_status_ok
1952 : e1000_1000t_rx_status_not_ok;
1953
1954 phy->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS)
1955 ? e1000_1000t_rx_status_ok
1956 : e1000_1000t_rx_status_not_ok;
1957 } else {
1958 /* Set values to "undefined" */
1959 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
1960 phy->local_rx = e1000_1000t_rx_status_undefined;
1961 phy->remote_rx = e1000_1000t_rx_status_undefined;
1962 }
1963
1964out:
1965 return ret_val;
1966}
1967
1968/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001969 * igb_get_phy_info_igp - Retrieve igp PHY information
Auke Kok9d5c8242008-01-24 02:22:38 -08001970 * @hw: pointer to the HW structure
1971 *
1972 * Read PHY status to determine if link is up. If link is up, then
1973 * set/determine 10base-T extended distance and polarity correction. Read
1974 * PHY port status to determine MDI/MDIx and speed. Based on the speed,
1975 * determine on the cable length, local and remote receiver.
1976 **/
1977s32 igb_get_phy_info_igp(struct e1000_hw *hw)
1978{
1979 struct e1000_phy_info *phy = &hw->phy;
1980 s32 ret_val;
1981 u16 data;
1982 bool link;
1983
1984 ret_val = igb_phy_has_link(hw, 1, 0, &link);
1985 if (ret_val)
1986 goto out;
1987
1988 if (!link) {
Auke Kok652fff32008-06-27 11:00:18 -07001989 hw_dbg("Phy info is only valid if link is up\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001990 ret_val = -E1000_ERR_CONFIG;
1991 goto out;
1992 }
1993
1994 phy->polarity_correction = true;
1995
1996 ret_val = igb_check_polarity_igp(hw);
1997 if (ret_val)
1998 goto out;
1999
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002000 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_STATUS, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -08002001 if (ret_val)
2002 goto out;
2003
2004 phy->is_mdix = (data & IGP01E1000_PSSR_MDIX) ? true : false;
2005
2006 if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
2007 IGP01E1000_PSSR_SPEED_1000MBPS) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002008 ret_val = phy->ops.get_cable_length(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08002009 if (ret_val)
2010 goto out;
2011
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002012 ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -08002013 if (ret_val)
2014 goto out;
2015
2016 phy->local_rx = (data & SR_1000T_LOCAL_RX_STATUS)
2017 ? e1000_1000t_rx_status_ok
2018 : e1000_1000t_rx_status_not_ok;
2019
2020 phy->remote_rx = (data & SR_1000T_REMOTE_RX_STATUS)
2021 ? e1000_1000t_rx_status_ok
2022 : e1000_1000t_rx_status_not_ok;
2023 } else {
2024 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
2025 phy->local_rx = e1000_1000t_rx_status_undefined;
2026 phy->remote_rx = e1000_1000t_rx_status_undefined;
2027 }
2028
2029out:
2030 return ret_val;
2031}
2032
2033/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07002034 * igb_phy_sw_reset - PHY software reset
Auke Kok9d5c8242008-01-24 02:22:38 -08002035 * @hw: pointer to the HW structure
2036 *
2037 * Does a software reset of the PHY by reading the PHY control register and
2038 * setting/write the control register reset bit to the PHY.
2039 **/
2040s32 igb_phy_sw_reset(struct e1000_hw *hw)
2041{
Alexander Duyckd3147372009-09-14 08:23:13 +00002042 s32 ret_val = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08002043 u16 phy_ctrl;
2044
Alexander Duyckd3147372009-09-14 08:23:13 +00002045 if (!(hw->phy.ops.read_reg))
2046 goto out;
2047
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002048 ret_val = hw->phy.ops.read_reg(hw, PHY_CONTROL, &phy_ctrl);
Auke Kok9d5c8242008-01-24 02:22:38 -08002049 if (ret_val)
2050 goto out;
2051
2052 phy_ctrl |= MII_CR_RESET;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002053 ret_val = hw->phy.ops.write_reg(hw, PHY_CONTROL, phy_ctrl);
Auke Kok9d5c8242008-01-24 02:22:38 -08002054 if (ret_val)
2055 goto out;
2056
2057 udelay(1);
2058
2059out:
2060 return ret_val;
2061}
2062
2063/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07002064 * igb_phy_hw_reset - PHY hardware reset
Auke Kok9d5c8242008-01-24 02:22:38 -08002065 * @hw: pointer to the HW structure
2066 *
2067 * Verify the reset block is not blocking us from resetting. Acquire
2068 * semaphore (if necessary) and read/set/write the device control reset
2069 * bit in the PHY. Wait the appropriate delay time for the device to
2070 * reset and relase the semaphore (if necessary).
2071 **/
2072s32 igb_phy_hw_reset(struct e1000_hw *hw)
2073{
2074 struct e1000_phy_info *phy = &hw->phy;
2075 s32 ret_val;
2076 u32 ctrl;
2077
2078 ret_val = igb_check_reset_block(hw);
2079 if (ret_val) {
2080 ret_val = 0;
2081 goto out;
2082 }
2083
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002084 ret_val = phy->ops.acquire(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08002085 if (ret_val)
2086 goto out;
2087
2088 ctrl = rd32(E1000_CTRL);
2089 wr32(E1000_CTRL, ctrl | E1000_CTRL_PHY_RST);
2090 wrfl();
2091
2092 udelay(phy->reset_delay_us);
2093
2094 wr32(E1000_CTRL, ctrl);
2095 wrfl();
2096
2097 udelay(150);
2098
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002099 phy->ops.release(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08002100
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002101 ret_val = phy->ops.get_cfg_done(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08002102
2103out:
2104 return ret_val;
2105}
2106
Auke Kok9d5c8242008-01-24 02:22:38 -08002107/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07002108 * igb_phy_init_script_igp3 - Inits the IGP3 PHY
Auke Kok9d5c8242008-01-24 02:22:38 -08002109 * @hw: pointer to the HW structure
2110 *
2111 * Initializes a Intel Gigabit PHY3 when an EEPROM is not present.
2112 **/
2113s32 igb_phy_init_script_igp3(struct e1000_hw *hw)
2114{
Auke Kok652fff32008-06-27 11:00:18 -07002115 hw_dbg("Running IGP 3 PHY init script\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08002116
2117 /* PHY init IGP 3 */
2118 /* Enable rise/fall, 10-mode work in class-A */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002119 hw->phy.ops.write_reg(hw, 0x2F5B, 0x9018);
Auke Kok9d5c8242008-01-24 02:22:38 -08002120 /* Remove all caps from Replica path filter */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002121 hw->phy.ops.write_reg(hw, 0x2F52, 0x0000);
Auke Kok9d5c8242008-01-24 02:22:38 -08002122 /* Bias trimming for ADC, AFE and Driver (Default) */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002123 hw->phy.ops.write_reg(hw, 0x2FB1, 0x8B24);
Auke Kok9d5c8242008-01-24 02:22:38 -08002124 /* Increase Hybrid poly bias */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002125 hw->phy.ops.write_reg(hw, 0x2FB2, 0xF8F0);
Auke Kok9d5c8242008-01-24 02:22:38 -08002126 /* Add 4% to TX amplitude in Giga mode */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002127 hw->phy.ops.write_reg(hw, 0x2010, 0x10B0);
Auke Kok9d5c8242008-01-24 02:22:38 -08002128 /* Disable trimming (TTT) */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002129 hw->phy.ops.write_reg(hw, 0x2011, 0x0000);
Auke Kok9d5c8242008-01-24 02:22:38 -08002130 /* Poly DC correction to 94.6% + 2% for all channels */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002131 hw->phy.ops.write_reg(hw, 0x20DD, 0x249A);
Auke Kok9d5c8242008-01-24 02:22:38 -08002132 /* ABS DC correction to 95.9% */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002133 hw->phy.ops.write_reg(hw, 0x20DE, 0x00D3);
Auke Kok9d5c8242008-01-24 02:22:38 -08002134 /* BG temp curve trim */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002135 hw->phy.ops.write_reg(hw, 0x28B4, 0x04CE);
Auke Kok9d5c8242008-01-24 02:22:38 -08002136 /* Increasing ADC OPAMP stage 1 currents to max */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002137 hw->phy.ops.write_reg(hw, 0x2F70, 0x29E4);
Auke Kok9d5c8242008-01-24 02:22:38 -08002138 /* Force 1000 ( required for enabling PHY regs configuration) */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002139 hw->phy.ops.write_reg(hw, 0x0000, 0x0140);
Auke Kok9d5c8242008-01-24 02:22:38 -08002140 /* Set upd_freq to 6 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002141 hw->phy.ops.write_reg(hw, 0x1F30, 0x1606);
Auke Kok9d5c8242008-01-24 02:22:38 -08002142 /* Disable NPDFE */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002143 hw->phy.ops.write_reg(hw, 0x1F31, 0xB814);
Auke Kok9d5c8242008-01-24 02:22:38 -08002144 /* Disable adaptive fixed FFE (Default) */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002145 hw->phy.ops.write_reg(hw, 0x1F35, 0x002A);
Auke Kok9d5c8242008-01-24 02:22:38 -08002146 /* Enable FFE hysteresis */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002147 hw->phy.ops.write_reg(hw, 0x1F3E, 0x0067);
Auke Kok9d5c8242008-01-24 02:22:38 -08002148 /* Fixed FFE for short cable lengths */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002149 hw->phy.ops.write_reg(hw, 0x1F54, 0x0065);
Auke Kok9d5c8242008-01-24 02:22:38 -08002150 /* Fixed FFE for medium cable lengths */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002151 hw->phy.ops.write_reg(hw, 0x1F55, 0x002A);
Auke Kok9d5c8242008-01-24 02:22:38 -08002152 /* Fixed FFE for long cable lengths */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002153 hw->phy.ops.write_reg(hw, 0x1F56, 0x002A);
Auke Kok9d5c8242008-01-24 02:22:38 -08002154 /* Enable Adaptive Clip Threshold */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002155 hw->phy.ops.write_reg(hw, 0x1F72, 0x3FB0);
Auke Kok9d5c8242008-01-24 02:22:38 -08002156 /* AHT reset limit to 1 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002157 hw->phy.ops.write_reg(hw, 0x1F76, 0xC0FF);
Auke Kok9d5c8242008-01-24 02:22:38 -08002158 /* Set AHT master delay to 127 msec */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002159 hw->phy.ops.write_reg(hw, 0x1F77, 0x1DEC);
Auke Kok9d5c8242008-01-24 02:22:38 -08002160 /* Set scan bits for AHT */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002161 hw->phy.ops.write_reg(hw, 0x1F78, 0xF9EF);
Auke Kok9d5c8242008-01-24 02:22:38 -08002162 /* Set AHT Preset bits */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002163 hw->phy.ops.write_reg(hw, 0x1F79, 0x0210);
Auke Kok9d5c8242008-01-24 02:22:38 -08002164 /* Change integ_factor of channel A to 3 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002165 hw->phy.ops.write_reg(hw, 0x1895, 0x0003);
Auke Kok9d5c8242008-01-24 02:22:38 -08002166 /* Change prop_factor of channels BCD to 8 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002167 hw->phy.ops.write_reg(hw, 0x1796, 0x0008);
Auke Kok9d5c8242008-01-24 02:22:38 -08002168 /* Change cg_icount + enable integbp for channels BCD */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002169 hw->phy.ops.write_reg(hw, 0x1798, 0xD008);
Auke Kok9d5c8242008-01-24 02:22:38 -08002170 /*
2171 * Change cg_icount + enable integbp + change prop_factor_master
2172 * to 8 for channel A
2173 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002174 hw->phy.ops.write_reg(hw, 0x1898, 0xD918);
Auke Kok9d5c8242008-01-24 02:22:38 -08002175 /* Disable AHT in Slave mode on channel A */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002176 hw->phy.ops.write_reg(hw, 0x187A, 0x0800);
Auke Kok9d5c8242008-01-24 02:22:38 -08002177 /*
2178 * Enable LPLU and disable AN to 1000 in non-D0a states,
2179 * Enable SPD+B2B
2180 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002181 hw->phy.ops.write_reg(hw, 0x0019, 0x008D);
Auke Kok9d5c8242008-01-24 02:22:38 -08002182 /* Enable restart AN on an1000_dis change */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002183 hw->phy.ops.write_reg(hw, 0x001B, 0x2080);
Auke Kok9d5c8242008-01-24 02:22:38 -08002184 /* Enable wh_fifo read clock in 10/100 modes */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002185 hw->phy.ops.write_reg(hw, 0x0014, 0x0045);
Auke Kok9d5c8242008-01-24 02:22:38 -08002186 /* Restart AN, Speed selection is 1000 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002187 hw->phy.ops.write_reg(hw, 0x0000, 0x1340);
Auke Kok9d5c8242008-01-24 02:22:38 -08002188
2189 return 0;
2190}
2191
Alexander Duyck2909c3f2009-11-19 12:41:42 +00002192/**
Nick Nunley88a268c2010-02-17 01:01:59 +00002193 * igb_power_up_phy_copper - Restore copper link in case of PHY power down
2194 * @hw: pointer to the HW structure
2195 *
2196 * In the case of a PHY power down to save power, or to turn off link during a
2197 * driver unload, restore the link to previous settings.
2198 **/
2199void igb_power_up_phy_copper(struct e1000_hw *hw)
2200{
2201 u16 mii_reg = 0;
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00002202 u16 power_reg = 0;
Nick Nunley88a268c2010-02-17 01:01:59 +00002203
2204 /* The PHY will retain its settings across a power down/up cycle */
2205 hw->phy.ops.read_reg(hw, PHY_CONTROL, &mii_reg);
2206 mii_reg &= ~MII_CR_POWER_DOWN;
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00002207 if (hw->phy.type == e1000_phy_i210) {
2208 hw->phy.ops.read_reg(hw, GS40G_COPPER_SPEC, &power_reg);
2209 power_reg &= ~GS40G_CS_POWER_DOWN;
2210 hw->phy.ops.write_reg(hw, GS40G_COPPER_SPEC, power_reg);
2211 }
Nick Nunley88a268c2010-02-17 01:01:59 +00002212 hw->phy.ops.write_reg(hw, PHY_CONTROL, mii_reg);
2213}
2214
2215/**
2216 * igb_power_down_phy_copper - Power down copper PHY
2217 * @hw: pointer to the HW structure
2218 *
2219 * Power down PHY to save power when interface is down and wake on lan
2220 * is not enabled.
2221 **/
2222void igb_power_down_phy_copper(struct e1000_hw *hw)
2223{
2224 u16 mii_reg = 0;
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00002225 u16 power_reg = 0;
Nick Nunley88a268c2010-02-17 01:01:59 +00002226
2227 /* The PHY will retain its settings across a power down/up cycle */
2228 hw->phy.ops.read_reg(hw, PHY_CONTROL, &mii_reg);
2229 mii_reg |= MII_CR_POWER_DOWN;
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00002230
2231 /* i210 Phy requires an additional bit for power up/down */
2232 if (hw->phy.type == e1000_phy_i210) {
2233 hw->phy.ops.read_reg(hw, GS40G_COPPER_SPEC, &power_reg);
2234 power_reg |= GS40G_CS_POWER_DOWN;
2235 hw->phy.ops.write_reg(hw, GS40G_COPPER_SPEC, power_reg);
2236 }
Nick Nunley88a268c2010-02-17 01:01:59 +00002237 hw->phy.ops.write_reg(hw, PHY_CONTROL, mii_reg);
2238 msleep(1);
2239}
2240
2241/**
Alexander Duyck2909c3f2009-11-19 12:41:42 +00002242 * igb_check_polarity_82580 - Checks the polarity.
2243 * @hw: pointer to the HW structure
2244 *
2245 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
2246 *
2247 * Polarity is determined based on the PHY specific status register.
2248 **/
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002249static s32 igb_check_polarity_82580(struct e1000_hw *hw)
Alexander Duyck2909c3f2009-11-19 12:41:42 +00002250{
2251 struct e1000_phy_info *phy = &hw->phy;
2252 s32 ret_val;
2253 u16 data;
2254
2255
2256 ret_val = phy->ops.read_reg(hw, I82580_PHY_STATUS_2, &data);
2257
2258 if (!ret_val)
2259 phy->cable_polarity = (data & I82580_PHY_STATUS2_REV_POLARITY)
2260 ? e1000_rev_polarity_reversed
2261 : e1000_rev_polarity_normal;
2262
2263 return ret_val;
2264}
2265
2266/**
2267 * igb_phy_force_speed_duplex_82580 - Force speed/duplex for I82580 PHY
2268 * @hw: pointer to the HW structure
2269 *
2270 * Calls the PHY setup function to force speed and duplex. Clears the
2271 * auto-crossover to force MDI manually. Waits for link and returns
2272 * successful if link up is successful, else -E1000_ERR_PHY (-2).
2273 **/
2274s32 igb_phy_force_speed_duplex_82580(struct e1000_hw *hw)
2275{
2276 struct e1000_phy_info *phy = &hw->phy;
2277 s32 ret_val;
2278 u16 phy_data;
2279 bool link;
2280
2281
2282 ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data);
2283 if (ret_val)
2284 goto out;
2285
2286 igb_phy_force_speed_duplex_setup(hw, &phy_data);
2287
2288 ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data);
2289 if (ret_val)
2290 goto out;
2291
2292 /*
2293 * Clear Auto-Crossover to force MDI manually. 82580 requires MDI
2294 * forced whenever speed and duplex are forced.
2295 */
2296 ret_val = phy->ops.read_reg(hw, I82580_PHY_CTRL_2, &phy_data);
2297 if (ret_val)
2298 goto out;
2299
Jesse Brandeburg1b556782012-07-26 02:31:04 +00002300 phy_data &= ~I82580_PHY_CTRL2_MDIX_CFG_MASK;
Alexander Duyck2909c3f2009-11-19 12:41:42 +00002301
2302 ret_val = phy->ops.write_reg(hw, I82580_PHY_CTRL_2, phy_data);
2303 if (ret_val)
2304 goto out;
2305
2306 hw_dbg("I82580_PHY_CTRL_2: %X\n", phy_data);
2307
2308 udelay(1);
2309
2310 if (phy->autoneg_wait_to_complete) {
2311 hw_dbg("Waiting for forced speed/duplex link on 82580 phy\n");
2312
2313 ret_val = igb_phy_has_link(hw,
2314 PHY_FORCE_LIMIT,
2315 100000,
2316 &link);
2317 if (ret_val)
2318 goto out;
2319
2320 if (!link)
2321 hw_dbg("Link taking longer than expected.\n");
2322
2323 /* Try once more */
2324 ret_val = igb_phy_has_link(hw,
2325 PHY_FORCE_LIMIT,
2326 100000,
2327 &link);
2328 if (ret_val)
2329 goto out;
2330 }
2331
2332out:
2333 return ret_val;
2334}
2335
2336/**
2337 * igb_get_phy_info_82580 - Retrieve I82580 PHY information
2338 * @hw: pointer to the HW structure
2339 *
2340 * Read PHY status to determine if link is up. If link is up, then
2341 * set/determine 10base-T extended distance and polarity correction. Read
2342 * PHY port status to determine MDI/MDIx and speed. Based on the speed,
2343 * determine on the cable length, local and remote receiver.
2344 **/
2345s32 igb_get_phy_info_82580(struct e1000_hw *hw)
2346{
2347 struct e1000_phy_info *phy = &hw->phy;
2348 s32 ret_val;
2349 u16 data;
2350 bool link;
2351
2352
2353 ret_val = igb_phy_has_link(hw, 1, 0, &link);
2354 if (ret_val)
2355 goto out;
2356
2357 if (!link) {
2358 hw_dbg("Phy info is only valid if link is up\n");
2359 ret_val = -E1000_ERR_CONFIG;
2360 goto out;
2361 }
2362
2363 phy->polarity_correction = true;
2364
2365 ret_val = igb_check_polarity_82580(hw);
2366 if (ret_val)
2367 goto out;
2368
2369 ret_val = phy->ops.read_reg(hw, I82580_PHY_STATUS_2, &data);
2370 if (ret_val)
2371 goto out;
2372
2373 phy->is_mdix = (data & I82580_PHY_STATUS2_MDIX) ? true : false;
2374
2375 if ((data & I82580_PHY_STATUS2_SPEED_MASK) ==
2376 I82580_PHY_STATUS2_SPEED_1000MBPS) {
2377 ret_val = hw->phy.ops.get_cable_length(hw);
2378 if (ret_val)
2379 goto out;
2380
2381 ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &data);
2382 if (ret_val)
2383 goto out;
2384
2385 phy->local_rx = (data & SR_1000T_LOCAL_RX_STATUS)
2386 ? e1000_1000t_rx_status_ok
2387 : e1000_1000t_rx_status_not_ok;
2388
2389 phy->remote_rx = (data & SR_1000T_REMOTE_RX_STATUS)
2390 ? e1000_1000t_rx_status_ok
2391 : e1000_1000t_rx_status_not_ok;
2392 } else {
2393 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
2394 phy->local_rx = e1000_1000t_rx_status_undefined;
2395 phy->remote_rx = e1000_1000t_rx_status_undefined;
2396 }
2397
2398out:
2399 return ret_val;
2400}
2401
2402/**
2403 * igb_get_cable_length_82580 - Determine cable length for 82580 PHY
2404 * @hw: pointer to the HW structure
2405 *
2406 * Reads the diagnostic status register and verifies result is valid before
2407 * placing it in the phy_cable_length field.
2408 **/
2409s32 igb_get_cable_length_82580(struct e1000_hw *hw)
2410{
2411 struct e1000_phy_info *phy = &hw->phy;
2412 s32 ret_val;
2413 u16 phy_data, length;
2414
2415
2416 ret_val = phy->ops.read_reg(hw, I82580_PHY_DIAG_STATUS, &phy_data);
2417 if (ret_val)
2418 goto out;
2419
2420 length = (phy_data & I82580_DSTATUS_CABLE_LENGTH) >>
2421 I82580_DSTATUS_CABLE_LENGTH_SHIFT;
2422
2423 if (length == E1000_CABLE_LENGTH_UNDEFINED)
2424 ret_val = -E1000_ERR_PHY;
2425
2426 phy->cable_length = length;
2427
2428out:
2429 return ret_val;
2430}
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00002431
2432/**
2433 * igb_write_phy_reg_gs40g - Write GS40G PHY register
2434 * @hw: pointer to the HW structure
2435 * @offset: lower half is register offset to write to
2436 * upper half is page to use.
2437 * @data: data to write at register offset
2438 *
2439 * Acquires semaphore, if necessary, then writes the data to PHY register
2440 * at the offset. Release any acquired semaphores before exiting.
2441 **/
2442s32 igb_write_phy_reg_gs40g(struct e1000_hw *hw, u32 offset, u16 data)
2443{
2444 s32 ret_val;
2445 u16 page = offset >> GS40G_PAGE_SHIFT;
2446
2447 offset = offset & GS40G_OFFSET_MASK;
2448 ret_val = hw->phy.ops.acquire(hw);
2449 if (ret_val)
2450 return ret_val;
2451
2452 ret_val = igb_write_phy_reg_mdic(hw, GS40G_PAGE_SELECT, page);
2453 if (ret_val)
2454 goto release;
2455 ret_val = igb_write_phy_reg_mdic(hw, offset, data);
2456
2457release:
2458 hw->phy.ops.release(hw);
2459 return ret_val;
2460}
2461
2462/**
2463 * igb_read_phy_reg_gs40g - Read GS40G PHY register
2464 * @hw: pointer to the HW structure
2465 * @offset: lower half is register offset to read to
2466 * upper half is page to use.
2467 * @data: data to read at register offset
2468 *
2469 * Acquires semaphore, if necessary, then reads the data in the PHY register
2470 * at the offset. Release any acquired semaphores before exiting.
2471 **/
2472s32 igb_read_phy_reg_gs40g(struct e1000_hw *hw, u32 offset, u16 *data)
2473{
2474 s32 ret_val;
2475 u16 page = offset >> GS40G_PAGE_SHIFT;
2476
2477 offset = offset & GS40G_OFFSET_MASK;
2478 ret_val = hw->phy.ops.acquire(hw);
2479 if (ret_val)
2480 return ret_val;
2481
2482 ret_val = igb_write_phy_reg_mdic(hw, GS40G_PAGE_SELECT, page);
2483 if (ret_val)
2484 goto release;
2485 ret_val = igb_read_phy_reg_mdic(hw, offset, data);
2486
2487release:
2488 hw->phy.ops.release(hw);
2489 return ret_val;
2490}
2491
2492/**
2493 * igb_set_master_slave_mode - Setup PHY for Master/slave mode
2494 * @hw: pointer to the HW structure
2495 *
2496 * Sets up Master/slave mode
2497 **/
2498static s32 igb_set_master_slave_mode(struct e1000_hw *hw)
2499{
2500 s32 ret_val;
2501 u16 phy_data;
2502
2503 /* Resolve Master/Slave mode */
2504 ret_val = hw->phy.ops.read_reg(hw, PHY_1000T_CTRL, &phy_data);
2505 if (ret_val)
2506 return ret_val;
2507
2508 /* load defaults for future use */
2509 hw->phy.original_ms_type = (phy_data & CR_1000T_MS_ENABLE) ?
2510 ((phy_data & CR_1000T_MS_VALUE) ?
2511 e1000_ms_force_master :
2512 e1000_ms_force_slave) : e1000_ms_auto;
2513
2514 switch (hw->phy.ms_type) {
2515 case e1000_ms_force_master:
2516 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
2517 break;
2518 case e1000_ms_force_slave:
2519 phy_data |= CR_1000T_MS_ENABLE;
2520 phy_data &= ~(CR_1000T_MS_VALUE);
2521 break;
2522 case e1000_ms_auto:
2523 phy_data &= ~CR_1000T_MS_ENABLE;
2524 /* fall-through */
2525 default:
2526 break;
2527 }
2528
2529 return hw->phy.ops.write_reg(hw, PHY_1000T_CTRL, phy_data);
2530}