blob: c0f2a16d16dc2eb4303a2f0b4c6a218071af213a [file] [log] [blame]
Auke Kok9d5c8242008-01-24 02:22:38 -08001/*******************************************************************************
2
3 Intel(R) Gigabit Ethernet Linux driver
Akeem G. Abodunrin4b9ea462013-01-08 18:31:12 +00004 Copyright(c) 2007-2013 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,
Jeff Kirsherb980ac12013-02-23 07:29:56 +000036 u16 *phy_ctrl);
Auke Kok9d5c8242008-01-24 02:22:38 -080037static 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 */
Jeff Kirsherb980ac12013-02-23 07:29:56 +000041static 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 \
Jeff Kirsherb980ac12013-02-23 07:29:56 +000044 (sizeof(e1000_m88_cable_length_table) / \
45 sizeof(e1000_m88_cable_length_table[0]))
Auke Kok9d5c8242008-01-24 02:22:38 -080046
Jeff Kirsherb980ac12013-02-23 07:29:56 +000047static 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};
Auke Kok9d5c8242008-01-24 02:22:38 -080056#define IGP02E1000_CABLE_LENGTH_TABLE_SIZE \
Jeff Kirsherb980ac12013-02-23 07:29:56 +000057 (sizeof(e1000_igp_2_cable_length_table) / \
58 sizeof(e1000_igp_2_cable_length_table[0]))
Auke Kok9d5c8242008-01-24 02:22:38 -080059
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
Jeff Kirsherb980ac12013-02-23 07:29:56 +000074 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ? E1000_BLK_PHY_RESET : 0;
Auke Kok9d5c8242008-01-24 02:22:38 -080075}
76
77/**
Jeff Kirsher733596b2008-06-27 10:59:59 -070078 * igb_get_phy_id - Retrieve the PHY ID and revision
Auke Kok9d5c8242008-01-24 02:22:38 -080079 * @hw: pointer to the HW structure
80 *
81 * Reads the PHY registers and stores the PHY ID and possibly the PHY
82 * revision in the hardware structure.
83 **/
84s32 igb_get_phy_id(struct e1000_hw *hw)
85{
86 struct e1000_phy_info *phy = &hw->phy;
87 s32 ret_val = 0;
88 u16 phy_id;
89
Alexander Duycka8d2a0c2009-02-06 23:17:26 +000090 ret_val = phy->ops.read_reg(hw, PHY_ID1, &phy_id);
Auke Kok9d5c8242008-01-24 02:22:38 -080091 if (ret_val)
92 goto out;
93
94 phy->id = (u32)(phy_id << 16);
95 udelay(20);
Alexander Duycka8d2a0c2009-02-06 23:17:26 +000096 ret_val = phy->ops.read_reg(hw, PHY_ID2, &phy_id);
Auke Kok9d5c8242008-01-24 02:22:38 -080097 if (ret_val)
98 goto out;
99
100 phy->id |= (u32)(phy_id & PHY_REVISION_MASK);
101 phy->revision = (u32)(phy_id & ~PHY_REVISION_MASK);
102
103out:
104 return ret_val;
105}
106
107/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700108 * igb_phy_reset_dsp - Reset PHY DSP
Auke Kok9d5c8242008-01-24 02:22:38 -0800109 * @hw: pointer to the HW structure
110 *
111 * Reset the digital signal processor.
112 **/
113static s32 igb_phy_reset_dsp(struct e1000_hw *hw)
114{
Alexander Duyck2553bb22009-10-05 06:35:42 +0000115 s32 ret_val = 0;
116
117 if (!(hw->phy.ops.write_reg))
118 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800119
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000120 ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xC1);
Auke Kok9d5c8242008-01-24 02:22:38 -0800121 if (ret_val)
122 goto out;
123
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000124 ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0);
Auke Kok9d5c8242008-01-24 02:22:38 -0800125
126out:
127 return ret_val;
128}
129
130/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700131 * igb_read_phy_reg_mdic - Read MDI control register
Auke Kok9d5c8242008-01-24 02:22:38 -0800132 * @hw: pointer to the HW structure
133 * @offset: register offset to be read
134 * @data: pointer to the read data
135 *
136 * Reads the MDI control regsiter in the PHY at offset and stores the
137 * information read to data.
138 **/
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000139s32 igb_read_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 *data)
Auke Kok9d5c8242008-01-24 02:22:38 -0800140{
141 struct e1000_phy_info *phy = &hw->phy;
142 u32 i, mdic = 0;
143 s32 ret_val = 0;
144
145 if (offset > MAX_PHY_REG_ADDRESS) {
Auke Kok652fff32008-06-27 11:00:18 -0700146 hw_dbg("PHY Address %d is out of range\n", offset);
Auke Kok9d5c8242008-01-24 02:22:38 -0800147 ret_val = -E1000_ERR_PARAM;
148 goto out;
149 }
150
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000151 /* Set up Op-code, Phy Address, and register offset in the MDI
Auke Kok9d5c8242008-01-24 02:22:38 -0800152 * Control register. The MAC will take care of interfacing with the
153 * PHY to retrieve the desired data.
154 */
155 mdic = ((offset << E1000_MDIC_REG_SHIFT) |
156 (phy->addr << E1000_MDIC_PHY_SHIFT) |
157 (E1000_MDIC_OP_READ));
158
159 wr32(E1000_MDIC, mdic);
160
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000161 /* Poll the ready bit to see if the MDI read completed
Auke Kok9d5c8242008-01-24 02:22:38 -0800162 * Increasing the time out as testing showed failures with
163 * the lower time out
164 */
165 for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
166 udelay(50);
167 mdic = rd32(E1000_MDIC);
168 if (mdic & E1000_MDIC_READY)
169 break;
170 }
171 if (!(mdic & E1000_MDIC_READY)) {
Auke Kok652fff32008-06-27 11:00:18 -0700172 hw_dbg("MDI Read did not complete\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800173 ret_val = -E1000_ERR_PHY;
174 goto out;
175 }
176 if (mdic & E1000_MDIC_ERROR) {
Auke Kok652fff32008-06-27 11:00:18 -0700177 hw_dbg("MDI Error\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800178 ret_val = -E1000_ERR_PHY;
179 goto out;
180 }
181 *data = (u16) mdic;
182
183out:
184 return ret_val;
185}
186
187/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700188 * igb_write_phy_reg_mdic - Write MDI control register
Auke Kok9d5c8242008-01-24 02:22:38 -0800189 * @hw: pointer to the HW structure
190 * @offset: register offset to write to
191 * @data: data to write to register at offset
192 *
193 * Writes data to MDI control register in the PHY at offset.
194 **/
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000195s32 igb_write_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 data)
Auke Kok9d5c8242008-01-24 02:22:38 -0800196{
197 struct e1000_phy_info *phy = &hw->phy;
198 u32 i, mdic = 0;
199 s32 ret_val = 0;
200
201 if (offset > MAX_PHY_REG_ADDRESS) {
Auke Kok652fff32008-06-27 11:00:18 -0700202 hw_dbg("PHY Address %d is out of range\n", offset);
Auke Kok9d5c8242008-01-24 02:22:38 -0800203 ret_val = -E1000_ERR_PARAM;
204 goto out;
205 }
206
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000207 /* Set up Op-code, Phy Address, and register offset in the MDI
Auke Kok9d5c8242008-01-24 02:22:38 -0800208 * Control register. The MAC will take care of interfacing with the
209 * PHY to retrieve the desired data.
210 */
211 mdic = (((u32)data) |
212 (offset << E1000_MDIC_REG_SHIFT) |
213 (phy->addr << E1000_MDIC_PHY_SHIFT) |
214 (E1000_MDIC_OP_WRITE));
215
216 wr32(E1000_MDIC, mdic);
217
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000218 /* Poll the ready bit to see if the MDI read completed
Auke Kok9d5c8242008-01-24 02:22:38 -0800219 * Increasing the time out as testing showed failures with
220 * the lower time out
221 */
222 for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
223 udelay(50);
224 mdic = rd32(E1000_MDIC);
225 if (mdic & E1000_MDIC_READY)
226 break;
227 }
228 if (!(mdic & E1000_MDIC_READY)) {
Auke Kok652fff32008-06-27 11:00:18 -0700229 hw_dbg("MDI Write did not complete\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800230 ret_val = -E1000_ERR_PHY;
231 goto out;
232 }
233 if (mdic & E1000_MDIC_ERROR) {
Auke Kok652fff32008-06-27 11:00:18 -0700234 hw_dbg("MDI Error\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800235 ret_val = -E1000_ERR_PHY;
236 goto out;
237 }
238
239out:
240 return ret_val;
241}
242
243/**
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000244 * igb_read_phy_reg_i2c - Read PHY register using i2c
245 * @hw: pointer to the HW structure
246 * @offset: register offset to be read
247 * @data: pointer to the read data
248 *
249 * Reads the PHY register at offset using the i2c interface and stores the
250 * retrieved information in data.
251 **/
252s32 igb_read_phy_reg_i2c(struct e1000_hw *hw, u32 offset, u16 *data)
253{
254 struct e1000_phy_info *phy = &hw->phy;
255 u32 i, i2ccmd = 0;
256
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000257 /* Set up Op-code, Phy Address, and register address in the I2CCMD
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000258 * register. The MAC will take care of interfacing with the
259 * PHY to retrieve the desired data.
260 */
261 i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) |
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000262 (phy->addr << E1000_I2CCMD_PHY_ADDR_SHIFT) |
263 (E1000_I2CCMD_OPCODE_READ));
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000264
265 wr32(E1000_I2CCMD, i2ccmd);
266
267 /* Poll the ready bit to see if the I2C read completed */
268 for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) {
269 udelay(50);
270 i2ccmd = rd32(E1000_I2CCMD);
271 if (i2ccmd & E1000_I2CCMD_READY)
272 break;
273 }
274 if (!(i2ccmd & E1000_I2CCMD_READY)) {
275 hw_dbg("I2CCMD Read did not complete\n");
276 return -E1000_ERR_PHY;
277 }
278 if (i2ccmd & E1000_I2CCMD_ERROR) {
279 hw_dbg("I2CCMD Error bit set\n");
280 return -E1000_ERR_PHY;
281 }
282
283 /* Need to byte-swap the 16-bit value. */
284 *data = ((i2ccmd >> 8) & 0x00FF) | ((i2ccmd << 8) & 0xFF00);
285
286 return 0;
287}
288
289/**
290 * igb_write_phy_reg_i2c - Write PHY register using i2c
291 * @hw: pointer to the HW structure
292 * @offset: register offset to write to
293 * @data: data to write at register offset
294 *
295 * Writes the data to PHY register at the offset using the i2c interface.
296 **/
297s32 igb_write_phy_reg_i2c(struct e1000_hw *hw, u32 offset, u16 data)
298{
299 struct e1000_phy_info *phy = &hw->phy;
300 u32 i, i2ccmd = 0;
301 u16 phy_data_swapped;
302
Akeem G. Abodunrin76d06522011-09-02 23:11:19 +0000303 /* Prevent overwritting SFP I2C EEPROM which is at A0 address.*/
304 if ((hw->phy.addr == 0) || (hw->phy.addr > 7)) {
305 hw_dbg("PHY I2C Address %d is out of range.\n",
306 hw->phy.addr);
307 return -E1000_ERR_CONFIG;
308 }
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000309
310 /* Swap the data bytes for the I2C interface */
311 phy_data_swapped = ((data >> 8) & 0x00FF) | ((data << 8) & 0xFF00);
312
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000313 /* Set up Op-code, Phy Address, and register address in the I2CCMD
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000314 * register. The MAC will take care of interfacing with the
315 * PHY to retrieve the desired data.
316 */
317 i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) |
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000318 (phy->addr << E1000_I2CCMD_PHY_ADDR_SHIFT) |
319 E1000_I2CCMD_OPCODE_WRITE |
320 phy_data_swapped);
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000321
322 wr32(E1000_I2CCMD, i2ccmd);
323
324 /* Poll the ready bit to see if the I2C read completed */
325 for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) {
326 udelay(50);
327 i2ccmd = rd32(E1000_I2CCMD);
328 if (i2ccmd & E1000_I2CCMD_READY)
329 break;
330 }
331 if (!(i2ccmd & E1000_I2CCMD_READY)) {
332 hw_dbg("I2CCMD Write did not complete\n");
333 return -E1000_ERR_PHY;
334 }
335 if (i2ccmd & E1000_I2CCMD_ERROR) {
336 hw_dbg("I2CCMD Error bit set\n");
337 return -E1000_ERR_PHY;
338 }
339
340 return 0;
341}
342
343/**
Akeem G. Abodunrin641ac5c2013-04-24 16:54:50 +0000344 * igb_read_sfp_data_byte - Reads SFP module data.
345 * @hw: pointer to the HW structure
346 * @offset: byte location offset to be read
347 * @data: read data buffer pointer
348 *
349 * Reads one byte from SFP module data stored
350 * in SFP resided EEPROM memory or SFP diagnostic area.
351 * Function should be called with
352 * E1000_I2CCMD_SFP_DATA_ADDR(<byte offset>) for SFP module database access
353 * E1000_I2CCMD_SFP_DIAG_ADDR(<byte offset>) for SFP diagnostics parameters
354 * access
355 **/
356s32 igb_read_sfp_data_byte(struct e1000_hw *hw, u16 offset, u8 *data)
357{
358 u32 i = 0;
359 u32 i2ccmd = 0;
360 u32 data_local = 0;
361
362 if (offset > E1000_I2CCMD_SFP_DIAG_ADDR(255)) {
363 hw_dbg("I2CCMD command address exceeds upper limit\n");
364 return -E1000_ERR_PHY;
365 }
366
367 /* Set up Op-code, EEPROM Address,in the I2CCMD
368 * register. The MAC will take care of interfacing with the
369 * EEPROM to retrieve the desired data.
370 */
371 i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) |
372 E1000_I2CCMD_OPCODE_READ);
373
374 wr32(E1000_I2CCMD, i2ccmd);
375
376 /* Poll the ready bit to see if the I2C read completed */
377 for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) {
378 udelay(50);
379 data_local = rd32(E1000_I2CCMD);
380 if (data_local & E1000_I2CCMD_READY)
381 break;
382 }
383 if (!(data_local & E1000_I2CCMD_READY)) {
384 hw_dbg("I2CCMD Read did not complete\n");
385 return -E1000_ERR_PHY;
386 }
387 if (data_local & E1000_I2CCMD_ERROR) {
388 hw_dbg("I2CCMD Error bit set\n");
389 return -E1000_ERR_PHY;
390 }
391 *data = (u8) data_local & 0xFF;
392
393 return 0;
394}
395
396/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700397 * igb_read_phy_reg_igp - Read igp PHY register
Auke Kok9d5c8242008-01-24 02:22:38 -0800398 * @hw: pointer to the HW structure
399 * @offset: register offset to be read
400 * @data: pointer to the read data
401 *
402 * Acquires semaphore, if necessary, then reads the PHY register at offset
403 * and storing the retrieved information in data. Release any acquired
404 * semaphores before exiting.
405 **/
406s32 igb_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data)
407{
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000408 s32 ret_val = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -0800409
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000410 if (!(hw->phy.ops.acquire))
411 goto out;
412
413 ret_val = hw->phy.ops.acquire(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800414 if (ret_val)
415 goto out;
416
417 if (offset > MAX_PHY_MULTI_PAGE_REG) {
418 ret_val = igb_write_phy_reg_mdic(hw,
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000419 IGP01E1000_PHY_PAGE_SELECT,
420 (u16)offset);
Auke Kok9d5c8242008-01-24 02:22:38 -0800421 if (ret_val) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000422 hw->phy.ops.release(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800423 goto out;
424 }
425 }
426
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000427 ret_val = igb_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
428 data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800429
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000430 hw->phy.ops.release(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800431
432out:
433 return ret_val;
434}
435
436/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700437 * igb_write_phy_reg_igp - Write igp PHY register
Auke Kok9d5c8242008-01-24 02:22:38 -0800438 * @hw: pointer to the HW structure
439 * @offset: register offset to write to
440 * @data: data to write at register offset
441 *
442 * Acquires semaphore, if necessary, then writes the data to PHY register
443 * at the offset. Release any acquired semaphores before exiting.
444 **/
445s32 igb_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data)
446{
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000447 s32 ret_val = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -0800448
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000449 if (!(hw->phy.ops.acquire))
450 goto out;
451
452 ret_val = hw->phy.ops.acquire(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800453 if (ret_val)
454 goto out;
455
456 if (offset > MAX_PHY_MULTI_PAGE_REG) {
457 ret_val = igb_write_phy_reg_mdic(hw,
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000458 IGP01E1000_PHY_PAGE_SELECT,
459 (u16)offset);
Auke Kok9d5c8242008-01-24 02:22:38 -0800460 if (ret_val) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000461 hw->phy.ops.release(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800462 goto out;
463 }
464 }
465
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000466 ret_val = igb_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000467 data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800468
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000469 hw->phy.ops.release(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800470
471out:
472 return ret_val;
473}
474
475/**
Alexander Duyck2909c3f2009-11-19 12:41:42 +0000476 * igb_copper_link_setup_82580 - Setup 82580 PHY for copper link
477 * @hw: pointer to the HW structure
478 *
479 * Sets up Carrier-sense on Transmit and downshift values.
480 **/
481s32 igb_copper_link_setup_82580(struct e1000_hw *hw)
482{
483 struct e1000_phy_info *phy = &hw->phy;
484 s32 ret_val;
485 u16 phy_data;
486
Alexander Duyck2909c3f2009-11-19 12:41:42 +0000487 if (phy->reset_disable) {
488 ret_val = 0;
489 goto out;
490 }
491
492 if (phy->type == e1000_phy_82580) {
493 ret_val = hw->phy.ops.reset(hw);
494 if (ret_val) {
495 hw_dbg("Error resetting the PHY.\n");
496 goto out;
497 }
498 }
499
500 /* Enable CRS on TX. This must be set for half-duplex operation. */
501 ret_val = phy->ops.read_reg(hw, I82580_CFG_REG, &phy_data);
502 if (ret_val)
503 goto out;
504
505 phy_data |= I82580_CFG_ASSERT_CRS_ON_TX;
506
507 /* Enable downshift */
508 phy_data |= I82580_CFG_ENABLE_DOWNSHIFT;
509
510 ret_val = phy->ops.write_reg(hw, I82580_CFG_REG, phy_data);
Jesse Brandeburg1b556782012-07-26 02:31:04 +0000511 if (ret_val)
512 goto out;
513
514 /* Set MDI/MDIX mode */
515 ret_val = phy->ops.read_reg(hw, I82580_PHY_CTRL_2, &phy_data);
516 if (ret_val)
517 goto out;
518 phy_data &= ~I82580_PHY_CTRL2_MDIX_CFG_MASK;
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000519 /* Options:
Jesse Brandeburg1b556782012-07-26 02:31:04 +0000520 * 0 - Auto (default)
521 * 1 - MDI mode
522 * 2 - MDI-X mode
523 */
524 switch (hw->phy.mdix) {
525 case 1:
526 break;
527 case 2:
528 phy_data |= I82580_PHY_CTRL2_MANUAL_MDIX;
529 break;
530 case 0:
531 default:
532 phy_data |= I82580_PHY_CTRL2_AUTO_MDI_MDIX;
533 break;
534 }
535 ret_val = hw->phy.ops.write_reg(hw, I82580_PHY_CTRL_2, phy_data);
Alexander Duyck2909c3f2009-11-19 12:41:42 +0000536
537out:
538 return ret_val;
539}
540
541/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700542 * igb_copper_link_setup_m88 - Setup m88 PHY's for copper link
Auke Kok9d5c8242008-01-24 02:22:38 -0800543 * @hw: pointer to the HW structure
544 *
545 * Sets up MDI/MDI-X and polarity for m88 PHY's. If necessary, transmit clock
546 * and downshift values are set also.
547 **/
548s32 igb_copper_link_setup_m88(struct e1000_hw *hw)
549{
550 struct e1000_phy_info *phy = &hw->phy;
551 s32 ret_val;
552 u16 phy_data;
553
554 if (phy->reset_disable) {
555 ret_val = 0;
556 goto out;
557 }
558
559 /* Enable CRS on TX. This must be set for half-duplex operation. */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000560 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800561 if (ret_val)
562 goto out;
563
564 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
565
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000566 /* Options:
Auke Kok9d5c8242008-01-24 02:22:38 -0800567 * MDI/MDI-X = 0 (default)
568 * 0 - Auto for all speeds
569 * 1 - MDI mode
570 * 2 - MDI-X mode
571 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
572 */
573 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
574
575 switch (phy->mdix) {
576 case 1:
577 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
578 break;
579 case 2:
580 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
581 break;
582 case 3:
583 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
584 break;
585 case 0:
586 default:
587 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
588 break;
589 }
590
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000591 /* Options:
Auke Kok9d5c8242008-01-24 02:22:38 -0800592 * disable_polarity_correction = 0 (default)
593 * Automatic Correction for Reversed Cable Polarity
594 * 0 - Disabled
595 * 1 - Enabled
596 */
597 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
598 if (phy->disable_polarity_correction == 1)
599 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
600
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000601 ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800602 if (ret_val)
603 goto out;
604
605 if (phy->revision < E1000_REVISION_4) {
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000606 /* Force TX_CLK in the Extended PHY Specific Control Register
Auke Kok9d5c8242008-01-24 02:22:38 -0800607 * to 25MHz clock.
608 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000609 ret_val = phy->ops.read_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000610 &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800611 if (ret_val)
612 goto out;
613
614 phy_data |= M88E1000_EPSCR_TX_CLK_25;
615
616 if ((phy->revision == E1000_REVISION_2) &&
617 (phy->id == M88E1111_I_PHY_ID)) {
618 /* 82573L PHY - set the downshift counter to 5x. */
619 phy_data &= ~M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK;
620 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
621 } else {
622 /* Configure Master and Slave downshift values */
623 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
624 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
625 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
626 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
627 }
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000628 ret_val = phy->ops.write_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
Auke Kok9d5c8242008-01-24 02:22:38 -0800629 phy_data);
630 if (ret_val)
631 goto out;
632 }
633
634 /* Commit the changes. */
635 ret_val = igb_phy_sw_reset(hw);
636 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700637 hw_dbg("Error committing the PHY changes\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800638 goto out;
639 }
640
641out:
642 return ret_val;
643}
644
645/**
Joseph Gasparakis308fb392010-09-22 17:56:44 +0000646 * igb_copper_link_setup_m88_gen2 - Setup m88 PHY's for copper link
647 * @hw: pointer to the HW structure
648 *
649 * Sets up MDI/MDI-X and polarity for i347-AT4, m88e1322 and m88e1112 PHY's.
650 * Also enables and sets the downshift parameters.
651 **/
652s32 igb_copper_link_setup_m88_gen2(struct e1000_hw *hw)
653{
654 struct e1000_phy_info *phy = &hw->phy;
655 s32 ret_val;
656 u16 phy_data;
657
Akeem G Abodunrindfc70752013-08-28 02:22:48 +0000658 if (phy->reset_disable)
659 return 0;
Joseph Gasparakis308fb392010-09-22 17:56:44 +0000660
661 /* Enable CRS on Tx. This must be set for half-duplex operation. */
662 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
663 if (ret_val)
Akeem G Abodunrindfc70752013-08-28 02:22:48 +0000664 return ret_val;
Joseph Gasparakis308fb392010-09-22 17:56:44 +0000665
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000666 /* Options:
Joseph Gasparakis308fb392010-09-22 17:56:44 +0000667 * MDI/MDI-X = 0 (default)
668 * 0 - Auto for all speeds
669 * 1 - MDI mode
670 * 2 - MDI-X mode
671 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
672 */
673 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
674
675 switch (phy->mdix) {
676 case 1:
677 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
678 break;
679 case 2:
680 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
681 break;
682 case 3:
683 /* M88E1112 does not support this mode) */
684 if (phy->id != M88E1112_E_PHY_ID) {
685 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
686 break;
687 }
688 case 0:
689 default:
690 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
691 break;
692 }
693
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000694 /* Options:
Joseph Gasparakis308fb392010-09-22 17:56:44 +0000695 * disable_polarity_correction = 0 (default)
696 * Automatic Correction for Reversed Cable Polarity
697 * 0 - Disabled
698 * 1 - Enabled
699 */
700 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
701 if (phy->disable_polarity_correction == 1)
702 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
703
704 /* Enable downshift and setting it to X6 */
Akeem G Abodunrindfc70752013-08-28 02:22:48 +0000705 if (phy->id == M88E1543_E_PHY_ID) {
706 phy_data &= ~I347AT4_PSCR_DOWNSHIFT_ENABLE;
707 ret_val =
708 phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
709 if (ret_val)
710 return ret_val;
711
712 ret_val = igb_phy_sw_reset(hw);
713 if (ret_val) {
714 hw_dbg("Error committing the PHY changes\n");
715 return ret_val;
716 }
717 }
718
Joseph Gasparakis308fb392010-09-22 17:56:44 +0000719 phy_data &= ~I347AT4_PSCR_DOWNSHIFT_MASK;
720 phy_data |= I347AT4_PSCR_DOWNSHIFT_6X;
721 phy_data |= I347AT4_PSCR_DOWNSHIFT_ENABLE;
722
723 ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
724 if (ret_val)
Akeem G Abodunrindfc70752013-08-28 02:22:48 +0000725 return ret_val;
Joseph Gasparakis308fb392010-09-22 17:56:44 +0000726
727 /* Commit the changes. */
728 ret_val = igb_phy_sw_reset(hw);
729 if (ret_val) {
730 hw_dbg("Error committing the PHY changes\n");
Akeem G Abodunrindfc70752013-08-28 02:22:48 +0000731 return ret_val;
Joseph Gasparakis308fb392010-09-22 17:56:44 +0000732 }
Carolyn Wybornyd1c17d82013-08-16 00:39:10 +0000733 ret_val = igb_set_master_slave_mode(hw);
734 if (ret_val)
735 return ret_val;
Joseph Gasparakis308fb392010-09-22 17:56:44 +0000736
Akeem G Abodunrindfc70752013-08-28 02:22:48 +0000737 return 0;
Joseph Gasparakis308fb392010-09-22 17:56:44 +0000738}
739
740/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700741 * igb_copper_link_setup_igp - Setup igp PHY's for copper link
Auke Kok9d5c8242008-01-24 02:22:38 -0800742 * @hw: pointer to the HW structure
743 *
744 * Sets up LPLU, MDI/MDI-X, polarity, Smartspeed and Master/Slave config for
745 * igp PHY's.
746 **/
747s32 igb_copper_link_setup_igp(struct e1000_hw *hw)
748{
749 struct e1000_phy_info *phy = &hw->phy;
750 s32 ret_val;
751 u16 data;
752
753 if (phy->reset_disable) {
754 ret_val = 0;
755 goto out;
756 }
757
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000758 ret_val = phy->ops.reset(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800759 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700760 hw_dbg("Error resetting the PHY.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800761 goto out;
762 }
763
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000764 /* Wait 100ms for MAC to configure PHY from NVM settings, to avoid
Alexander Duycka6a60562009-03-31 20:38:38 +0000765 * timeout issues when LFS is enabled.
766 */
767 msleep(100);
Auke Kok9d5c8242008-01-24 02:22:38 -0800768
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000769 /* The NVM settings will configure LPLU in D3 for
Auke Kok9d5c8242008-01-24 02:22:38 -0800770 * non-IGP1 PHYs.
771 */
772 if (phy->type == e1000_phy_igp) {
773 /* disable lplu d3 during driver init */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000774 if (phy->ops.set_d3_lplu_state)
775 ret_val = phy->ops.set_d3_lplu_state(hw, false);
Auke Kok9d5c8242008-01-24 02:22:38 -0800776 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700777 hw_dbg("Error Disabling LPLU D3\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800778 goto out;
779 }
780 }
781
782 /* disable lplu d0 during driver init */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000783 ret_val = phy->ops.set_d0_lplu_state(hw, false);
Auke Kok9d5c8242008-01-24 02:22:38 -0800784 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700785 hw_dbg("Error Disabling LPLU D0\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800786 goto out;
787 }
788 /* Configure mdi-mdix settings */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000789 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CTRL, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800790 if (ret_val)
791 goto out;
792
793 data &= ~IGP01E1000_PSCR_AUTO_MDIX;
794
795 switch (phy->mdix) {
796 case 1:
797 data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
798 break;
799 case 2:
800 data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
801 break;
802 case 0:
803 default:
804 data |= IGP01E1000_PSCR_AUTO_MDIX;
805 break;
806 }
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000807 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CTRL, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800808 if (ret_val)
809 goto out;
810
811 /* set auto-master slave resolution settings */
812 if (hw->mac.autoneg) {
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000813 /* when autonegotiation advertisement is only 1000Mbps then we
Auke Kok9d5c8242008-01-24 02:22:38 -0800814 * should disable SmartSpeed and enable Auto MasterSlave
815 * resolution as hardware default.
816 */
817 if (phy->autoneg_advertised == ADVERTISE_1000_FULL) {
818 /* Disable SmartSpeed */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000819 ret_val = phy->ops.read_reg(hw,
820 IGP01E1000_PHY_PORT_CONFIG,
821 &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800822 if (ret_val)
823 goto out;
824
825 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000826 ret_val = phy->ops.write_reg(hw,
Auke Kok9d5c8242008-01-24 02:22:38 -0800827 IGP01E1000_PHY_PORT_CONFIG,
828 data);
829 if (ret_val)
830 goto out;
831
832 /* Set auto Master/Slave resolution process */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000833 ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800834 if (ret_val)
835 goto out;
836
837 data &= ~CR_1000T_MS_ENABLE;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000838 ret_val = phy->ops.write_reg(hw, PHY_1000T_CTRL, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800839 if (ret_val)
840 goto out;
841 }
842
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000843 ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800844 if (ret_val)
845 goto out;
846
847 /* load defaults for future use */
848 phy->original_ms_type = (data & CR_1000T_MS_ENABLE) ?
849 ((data & CR_1000T_MS_VALUE) ?
850 e1000_ms_force_master :
851 e1000_ms_force_slave) :
852 e1000_ms_auto;
853
854 switch (phy->ms_type) {
855 case e1000_ms_force_master:
856 data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
857 break;
858 case e1000_ms_force_slave:
859 data |= CR_1000T_MS_ENABLE;
860 data &= ~(CR_1000T_MS_VALUE);
861 break;
862 case e1000_ms_auto:
863 data &= ~CR_1000T_MS_ENABLE;
864 default:
865 break;
866 }
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000867 ret_val = phy->ops.write_reg(hw, PHY_1000T_CTRL, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800868 if (ret_val)
869 goto out;
870 }
871
872out:
873 return ret_val;
874}
875
876/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700877 * igb_copper_link_autoneg - Setup/Enable autoneg for copper link
Auke Kok9d5c8242008-01-24 02:22:38 -0800878 * @hw: pointer to the HW structure
879 *
880 * Performs initial bounds checking on autoneg advertisement parameter, then
881 * configure to advertise the full capability. Setup the PHY to autoneg
882 * and restart the negotiation process between the link partner. If
883 * autoneg_wait_to_complete, then wait for autoneg to complete before exiting.
884 **/
Alexander Duyck81fadd82009-10-05 06:35:03 +0000885static s32 igb_copper_link_autoneg(struct e1000_hw *hw)
Auke Kok9d5c8242008-01-24 02:22:38 -0800886{
887 struct e1000_phy_info *phy = &hw->phy;
888 s32 ret_val;
889 u16 phy_ctrl;
890
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000891 /* Perform some bounds checking on the autoneg advertisement
Auke Kok9d5c8242008-01-24 02:22:38 -0800892 * parameter.
893 */
894 phy->autoneg_advertised &= phy->autoneg_mask;
895
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000896 /* If autoneg_advertised is zero, we assume it was not defaulted
Auke Kok9d5c8242008-01-24 02:22:38 -0800897 * by the calling code so we set to advertise full capability.
898 */
899 if (phy->autoneg_advertised == 0)
900 phy->autoneg_advertised = phy->autoneg_mask;
901
Auke Kok652fff32008-06-27 11:00:18 -0700902 hw_dbg("Reconfiguring auto-neg advertisement params\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800903 ret_val = igb_phy_setup_autoneg(hw);
904 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700905 hw_dbg("Error Setting up Auto-Negotiation\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800906 goto out;
907 }
Auke Kok652fff32008-06-27 11:00:18 -0700908 hw_dbg("Restarting Auto-Neg\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800909
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000910 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
Auke Kok9d5c8242008-01-24 02:22:38 -0800911 * the Auto Neg Restart bit in the PHY control register.
912 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000913 ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_ctrl);
Auke Kok9d5c8242008-01-24 02:22:38 -0800914 if (ret_val)
915 goto out;
916
917 phy_ctrl |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000918 ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_ctrl);
Auke Kok9d5c8242008-01-24 02:22:38 -0800919 if (ret_val)
920 goto out;
921
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000922 /* Does the user want to wait for Auto-Neg to complete here, or
Auke Kok9d5c8242008-01-24 02:22:38 -0800923 * check at a later time (for example, callback routine).
924 */
925 if (phy->autoneg_wait_to_complete) {
926 ret_val = igb_wait_autoneg(hw);
927 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700928 hw_dbg("Error while waiting for "
929 "autoneg to complete\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800930 goto out;
931 }
932 }
933
934 hw->mac.get_link_status = true;
935
936out:
937 return ret_val;
938}
939
940/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700941 * igb_phy_setup_autoneg - Configure PHY for auto-negotiation
Auke Kok9d5c8242008-01-24 02:22:38 -0800942 * @hw: pointer to the HW structure
943 *
944 * Reads the MII auto-neg advertisement register and/or the 1000T control
945 * register and if the PHY is already setup for auto-negotiation, then
946 * return successful. Otherwise, setup advertisement and flow control to
947 * the appropriate values for the wanted auto-negotiation.
948 **/
949static s32 igb_phy_setup_autoneg(struct e1000_hw *hw)
950{
951 struct e1000_phy_info *phy = &hw->phy;
952 s32 ret_val;
953 u16 mii_autoneg_adv_reg;
954 u16 mii_1000t_ctrl_reg = 0;
955
956 phy->autoneg_advertised &= phy->autoneg_mask;
957
958 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000959 ret_val = phy->ops.read_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
Auke Kok9d5c8242008-01-24 02:22:38 -0800960 if (ret_val)
961 goto out;
962
963 if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
964 /* Read the MII 1000Base-T Control Register (Address 9). */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000965 ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL,
Auke Kok9d5c8242008-01-24 02:22:38 -0800966 &mii_1000t_ctrl_reg);
967 if (ret_val)
968 goto out;
969 }
970
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000971 /* Need to parse both autoneg_advertised and fc and set up
Auke Kok9d5c8242008-01-24 02:22:38 -0800972 * the appropriate PHY registers. First we will parse for
973 * autoneg_advertised software override. Since we can advertise
974 * a plethora of combinations, we need to check each bit
975 * individually.
976 */
977
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000978 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
Auke Kok9d5c8242008-01-24 02:22:38 -0800979 * Advertisement Register (Address 4) and the 1000 mb speed bits in
980 * the 1000Base-T Control Register (Address 9).
981 */
982 mii_autoneg_adv_reg &= ~(NWAY_AR_100TX_FD_CAPS |
983 NWAY_AR_100TX_HD_CAPS |
984 NWAY_AR_10T_FD_CAPS |
985 NWAY_AR_10T_HD_CAPS);
986 mii_1000t_ctrl_reg &= ~(CR_1000T_HD_CAPS | CR_1000T_FD_CAPS);
987
Auke Kok652fff32008-06-27 11:00:18 -0700988 hw_dbg("autoneg_advertised %x\n", phy->autoneg_advertised);
Auke Kok9d5c8242008-01-24 02:22:38 -0800989
990 /* Do we want to advertise 10 Mb Half Duplex? */
991 if (phy->autoneg_advertised & ADVERTISE_10_HALF) {
Auke Kok652fff32008-06-27 11:00:18 -0700992 hw_dbg("Advertise 10mb Half duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800993 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
994 }
995
996 /* Do we want to advertise 10 Mb Full Duplex? */
997 if (phy->autoneg_advertised & ADVERTISE_10_FULL) {
Auke Kok652fff32008-06-27 11:00:18 -0700998 hw_dbg("Advertise 10mb Full duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800999 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
1000 }
1001
1002 /* Do we want to advertise 100 Mb Half Duplex? */
1003 if (phy->autoneg_advertised & ADVERTISE_100_HALF) {
Auke Kok652fff32008-06-27 11:00:18 -07001004 hw_dbg("Advertise 100mb Half duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001005 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
1006 }
1007
1008 /* Do we want to advertise 100 Mb Full Duplex? */
1009 if (phy->autoneg_advertised & ADVERTISE_100_FULL) {
Auke Kok652fff32008-06-27 11:00:18 -07001010 hw_dbg("Advertise 100mb Full duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001011 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
1012 }
1013
1014 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
1015 if (phy->autoneg_advertised & ADVERTISE_1000_HALF)
Auke Kok652fff32008-06-27 11:00:18 -07001016 hw_dbg("Advertise 1000mb Half duplex request denied!\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001017
1018 /* Do we want to advertise 1000 Mb Full Duplex? */
1019 if (phy->autoneg_advertised & ADVERTISE_1000_FULL) {
Auke Kok652fff32008-06-27 11:00:18 -07001020 hw_dbg("Advertise 1000mb Full duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001021 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
1022 }
1023
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001024 /* Check for a software override of the flow control settings, and
Auke Kok9d5c8242008-01-24 02:22:38 -08001025 * setup the PHY advertisement registers accordingly. If
1026 * auto-negotiation is enabled, then software will have to set the
1027 * "PAUSE" bits to the correct value in the Auto-Negotiation
1028 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-
1029 * negotiation.
1030 *
1031 * The possible values of the "fc" parameter are:
1032 * 0: Flow control is completely disabled
1033 * 1: Rx flow control is enabled (we can receive pause frames
1034 * but not send pause frames).
1035 * 2: Tx flow control is enabled (we can send pause frames
1036 * but we do not support receiving pause frames).
1037 * 3: Both Rx and TX flow control (symmetric) are enabled.
1038 * other: No software override. The flow control configuration
1039 * in the EEPROM is used.
1040 */
Alexander Duyck0cce1192009-07-23 18:10:24 +00001041 switch (hw->fc.current_mode) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001042 case e1000_fc_none:
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001043 /* Flow control (RX & TX) is completely disabled by a
Auke Kok9d5c8242008-01-24 02:22:38 -08001044 * software over-ride.
1045 */
1046 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1047 break;
1048 case e1000_fc_rx_pause:
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001049 /* RX Flow control is enabled, and TX Flow control is
Auke Kok9d5c8242008-01-24 02:22:38 -08001050 * disabled, by a software over-ride.
1051 *
1052 * Since there really isn't a way to advertise that we are
1053 * capable of RX Pause ONLY, we will advertise that we
1054 * support both symmetric and asymmetric RX PAUSE. Later
1055 * (in e1000_config_fc_after_link_up) we will disable the
1056 * hw's ability to send PAUSE frames.
1057 */
1058 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1059 break;
1060 case e1000_fc_tx_pause:
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001061 /* TX Flow control is enabled, and RX Flow control is
Auke Kok9d5c8242008-01-24 02:22:38 -08001062 * disabled, by a software over-ride.
1063 */
1064 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
1065 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
1066 break;
1067 case e1000_fc_full:
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001068 /* Flow control (both RX and TX) is enabled by a software
Auke Kok9d5c8242008-01-24 02:22:38 -08001069 * over-ride.
1070 */
1071 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1072 break;
1073 default:
Auke Kok652fff32008-06-27 11:00:18 -07001074 hw_dbg("Flow control param set incorrectly\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001075 ret_val = -E1000_ERR_CONFIG;
1076 goto out;
1077 }
1078
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001079 ret_val = phy->ops.write_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001080 if (ret_val)
1081 goto out;
1082
Auke Kok652fff32008-06-27 11:00:18 -07001083 hw_dbg("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001084
1085 if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001086 ret_val = phy->ops.write_reg(hw,
1087 PHY_1000T_CTRL,
1088 mii_1000t_ctrl_reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001089 if (ret_val)
1090 goto out;
1091 }
1092
1093out:
1094 return ret_val;
1095}
1096
1097/**
Alexander Duyck81fadd82009-10-05 06:35:03 +00001098 * igb_setup_copper_link - Configure copper link settings
1099 * @hw: pointer to the HW structure
1100 *
1101 * Calls the appropriate function to configure the link for auto-neg or forced
1102 * speed and duplex. Then we check for link, once link is established calls
1103 * to configure collision distance and flow control are called. If link is
1104 * not established, we return -E1000_ERR_PHY (-2).
1105 **/
1106s32 igb_setup_copper_link(struct e1000_hw *hw)
1107{
1108 s32 ret_val;
1109 bool link;
1110
Alexander Duyck81fadd82009-10-05 06:35:03 +00001111 if (hw->mac.autoneg) {
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001112 /* Setup autoneg and flow control advertisement and perform
Alexander Duyck81fadd82009-10-05 06:35:03 +00001113 * autonegotiation.
1114 */
1115 ret_val = igb_copper_link_autoneg(hw);
1116 if (ret_val)
1117 goto out;
1118 } else {
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001119 /* PHY will be set to 10H, 10F, 100H or 100F
Alexander Duyck81fadd82009-10-05 06:35:03 +00001120 * depending on user settings.
1121 */
1122 hw_dbg("Forcing Speed and Duplex\n");
1123 ret_val = hw->phy.ops.force_speed_duplex(hw);
1124 if (ret_val) {
1125 hw_dbg("Error Forcing Speed and Duplex\n");
1126 goto out;
1127 }
1128 }
1129
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001130 /* Check link status. Wait up to 100 microseconds for link to become
Alexander Duyck81fadd82009-10-05 06:35:03 +00001131 * valid.
1132 */
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001133 ret_val = igb_phy_has_link(hw, COPPER_LINK_UP_LIMIT, 10, &link);
Alexander Duyck81fadd82009-10-05 06:35:03 +00001134 if (ret_val)
1135 goto out;
1136
1137 if (link) {
1138 hw_dbg("Valid link established!!!\n");
1139 igb_config_collision_dist(hw);
1140 ret_val = igb_config_fc_after_link_up(hw);
1141 } else {
1142 hw_dbg("Unable to establish link!!!\n");
1143 }
1144
1145out:
1146 return ret_val;
1147}
1148
1149/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001150 * igb_phy_force_speed_duplex_igp - Force speed/duplex for igp PHY
Auke Kok9d5c8242008-01-24 02:22:38 -08001151 * @hw: pointer to the HW structure
1152 *
1153 * Calls the PHY setup function to force speed and duplex. Clears the
1154 * auto-crossover to force MDI manually. Waits for link and returns
1155 * successful if link up is successful, else -E1000_ERR_PHY (-2).
1156 **/
1157s32 igb_phy_force_speed_duplex_igp(struct e1000_hw *hw)
1158{
1159 struct e1000_phy_info *phy = &hw->phy;
1160 s32 ret_val;
1161 u16 phy_data;
1162 bool link;
1163
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001164 ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001165 if (ret_val)
1166 goto out;
1167
1168 igb_phy_force_speed_duplex_setup(hw, &phy_data);
1169
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001170 ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001171 if (ret_val)
1172 goto out;
1173
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001174 /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
Auke Kok9d5c8242008-01-24 02:22:38 -08001175 * forced whenever speed and duplex are forced.
1176 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001177 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001178 if (ret_val)
1179 goto out;
1180
1181 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1182 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1183
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001184 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001185 if (ret_val)
1186 goto out;
1187
Auke Kok652fff32008-06-27 11:00:18 -07001188 hw_dbg("IGP PSCR: %X\n", phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001189
1190 udelay(1);
1191
1192 if (phy->autoneg_wait_to_complete) {
Auke Kok652fff32008-06-27 11:00:18 -07001193 hw_dbg("Waiting for forced speed/duplex link on IGP phy.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001194
Andi Kleendc3d2262013-04-22 07:46:40 +00001195 ret_val = igb_phy_has_link(hw, PHY_FORCE_LIMIT, 10000, &link);
Auke Kok9d5c8242008-01-24 02:22:38 -08001196 if (ret_val)
1197 goto out;
1198
1199 if (!link)
Auke Kok652fff32008-06-27 11:00:18 -07001200 hw_dbg("Link taking longer than expected.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001201
1202 /* Try once more */
Andi Kleendc3d2262013-04-22 07:46:40 +00001203 ret_val = igb_phy_has_link(hw, PHY_FORCE_LIMIT, 10000, &link);
Auke Kok9d5c8242008-01-24 02:22:38 -08001204 if (ret_val)
1205 goto out;
1206 }
1207
1208out:
1209 return ret_val;
1210}
1211
1212/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001213 * igb_phy_force_speed_duplex_m88 - Force speed/duplex for m88 PHY
Auke Kok9d5c8242008-01-24 02:22:38 -08001214 * @hw: pointer to the HW structure
1215 *
1216 * Calls the PHY setup function to force speed and duplex. Clears the
1217 * auto-crossover to force MDI manually. Resets the PHY to commit the
1218 * changes. If time expires while waiting for link up, we reset the DSP.
1219 * After reset, TX_CLK and CRS on TX must be set. Return successful upon
1220 * successful completion, else return corresponding error code.
1221 **/
1222s32 igb_phy_force_speed_duplex_m88(struct e1000_hw *hw)
1223{
1224 struct e1000_phy_info *phy = &hw->phy;
1225 s32 ret_val;
1226 u16 phy_data;
1227 bool link;
1228
Matthew Vick9f0b8512012-10-16 07:44:45 +00001229 /* I210 and I211 devices support Auto-Crossover in forced operation. */
1230 if (phy->type != e1000_phy_i210) {
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001231 /* Clear Auto-Crossover to force MDI manually. M88E1000
Matthew Vick9f0b8512012-10-16 07:44:45 +00001232 * requires MDI forced whenever speed and duplex are forced.
1233 */
1234 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL,
1235 &phy_data);
1236 if (ret_val)
1237 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -08001238
Matthew Vick9f0b8512012-10-16 07:44:45 +00001239 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1240 ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL,
1241 phy_data);
1242 if (ret_val)
1243 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -08001244
Matthew Vick9f0b8512012-10-16 07:44:45 +00001245 hw_dbg("M88E1000 PSCR: %X\n", phy_data);
1246 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001247
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001248 ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001249 if (ret_val)
1250 goto out;
1251
1252 igb_phy_force_speed_duplex_setup(hw, &phy_data);
1253
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001254 ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001255 if (ret_val)
1256 goto out;
1257
Alexander Duyck2553bb22009-10-05 06:35:42 +00001258 /* Reset the phy to commit changes. */
1259 ret_val = igb_phy_sw_reset(hw);
1260 if (ret_val)
1261 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -08001262
1263 if (phy->autoneg_wait_to_complete) {
Auke Kok652fff32008-06-27 11:00:18 -07001264 hw_dbg("Waiting for forced speed/duplex link on M88 phy.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001265
Alexander Duyck2553bb22009-10-05 06:35:42 +00001266 ret_val = igb_phy_has_link(hw, PHY_FORCE_LIMIT, 100000, &link);
Auke Kok9d5c8242008-01-24 02:22:38 -08001267 if (ret_val)
1268 goto out;
1269
1270 if (!link) {
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001271 bool reset_dsp = true;
Joseph Gasparakis308fb392010-09-22 17:56:44 +00001272
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001273 switch (hw->phy.id) {
1274 case I347AT4_E_PHY_ID:
1275 case M88E1112_E_PHY_ID:
1276 case I210_I_PHY_ID:
1277 reset_dsp = false;
1278 break;
1279 default:
1280 if (hw->phy.type != e1000_phy_m88)
1281 reset_dsp = false;
1282 break;
1283 }
1284 if (!reset_dsp)
1285 hw_dbg("Link taking longer than expected.\n");
1286 else {
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001287 /* We didn't get link.
Joseph Gasparakis308fb392010-09-22 17:56:44 +00001288 * Reset the DSP and cross our fingers.
1289 */
1290 ret_val = phy->ops.write_reg(hw,
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001291 M88E1000_PHY_PAGE_SELECT,
1292 0x001d);
Joseph Gasparakis308fb392010-09-22 17:56:44 +00001293 if (ret_val)
1294 goto out;
1295 ret_val = igb_phy_reset_dsp(hw);
1296 if (ret_val)
1297 goto out;
1298 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001299 }
1300
1301 /* Try once more */
1302 ret_val = igb_phy_has_link(hw, PHY_FORCE_LIMIT,
Alexander Duyck2553bb22009-10-05 06:35:42 +00001303 100000, &link);
Auke Kok9d5c8242008-01-24 02:22:38 -08001304 if (ret_val)
1305 goto out;
1306 }
1307
Joseph Gasparakis308fb392010-09-22 17:56:44 +00001308 if (hw->phy.type != e1000_phy_m88 ||
1309 hw->phy.id == I347AT4_E_PHY_ID ||
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001310 hw->phy.id == M88E1112_E_PHY_ID ||
1311 hw->phy.id == I210_I_PHY_ID)
Joseph Gasparakis308fb392010-09-22 17:56:44 +00001312 goto out;
1313
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001314 ret_val = phy->ops.read_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001315 if (ret_val)
1316 goto out;
1317
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001318 /* Resetting the phy means we need to re-force TX_CLK in the
Auke Kok9d5c8242008-01-24 02:22:38 -08001319 * Extended PHY Specific Control Register to 25MHz clock from
1320 * the reset value of 2.5MHz.
1321 */
1322 phy_data |= M88E1000_EPSCR_TX_CLK_25;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001323 ret_val = phy->ops.write_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001324 if (ret_val)
1325 goto out;
1326
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001327 /* In addition, we must re-enable CRS on Tx for both half and full
Auke Kok9d5c8242008-01-24 02:22:38 -08001328 * duplex.
1329 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001330 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001331 if (ret_val)
1332 goto out;
1333
1334 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001335 ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001336
1337out:
1338 return ret_val;
1339}
1340
1341/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001342 * igb_phy_force_speed_duplex_setup - Configure forced PHY speed/duplex
Auke Kok9d5c8242008-01-24 02:22:38 -08001343 * @hw: pointer to the HW structure
1344 * @phy_ctrl: pointer to current value of PHY_CONTROL
1345 *
1346 * Forces speed and duplex on the PHY by doing the following: disable flow
1347 * control, force speed/duplex on the MAC, disable auto speed detection,
1348 * disable auto-negotiation, configure duplex, configure speed, configure
1349 * the collision distance, write configuration to CTRL register. The
1350 * caller must write to the PHY_CONTROL register for these settings to
1351 * take affect.
1352 **/
1353static void igb_phy_force_speed_duplex_setup(struct e1000_hw *hw,
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001354 u16 *phy_ctrl)
Auke Kok9d5c8242008-01-24 02:22:38 -08001355{
1356 struct e1000_mac_info *mac = &hw->mac;
1357 u32 ctrl;
1358
1359 /* Turn off flow control when forcing speed/duplex */
Alexander Duyck0cce1192009-07-23 18:10:24 +00001360 hw->fc.current_mode = e1000_fc_none;
Auke Kok9d5c8242008-01-24 02:22:38 -08001361
1362 /* Force speed/duplex on the mac */
1363 ctrl = rd32(E1000_CTRL);
1364 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1365 ctrl &= ~E1000_CTRL_SPD_SEL;
1366
1367 /* Disable Auto Speed Detection */
1368 ctrl &= ~E1000_CTRL_ASDE;
1369
1370 /* Disable autoneg on the phy */
1371 *phy_ctrl &= ~MII_CR_AUTO_NEG_EN;
1372
1373 /* Forcing Full or Half Duplex? */
1374 if (mac->forced_speed_duplex & E1000_ALL_HALF_DUPLEX) {
1375 ctrl &= ~E1000_CTRL_FD;
1376 *phy_ctrl &= ~MII_CR_FULL_DUPLEX;
Auke Kok652fff32008-06-27 11:00:18 -07001377 hw_dbg("Half Duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001378 } else {
1379 ctrl |= E1000_CTRL_FD;
1380 *phy_ctrl |= MII_CR_FULL_DUPLEX;
Auke Kok652fff32008-06-27 11:00:18 -07001381 hw_dbg("Full Duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001382 }
1383
1384 /* Forcing 10mb or 100mb? */
1385 if (mac->forced_speed_duplex & E1000_ALL_100_SPEED) {
1386 ctrl |= E1000_CTRL_SPD_100;
1387 *phy_ctrl |= MII_CR_SPEED_100;
1388 *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
Auke Kok652fff32008-06-27 11:00:18 -07001389 hw_dbg("Forcing 100mb\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001390 } else {
1391 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1392 *phy_ctrl |= MII_CR_SPEED_10;
1393 *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
Auke Kok652fff32008-06-27 11:00:18 -07001394 hw_dbg("Forcing 10mb\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001395 }
1396
1397 igb_config_collision_dist(hw);
1398
1399 wr32(E1000_CTRL, ctrl);
1400}
1401
1402/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001403 * igb_set_d3_lplu_state - Sets low power link up state for D3
Auke Kok9d5c8242008-01-24 02:22:38 -08001404 * @hw: pointer to the HW structure
1405 * @active: boolean used to enable/disable lplu
1406 *
1407 * Success returns 0, Failure returns 1
1408 *
1409 * The low power link up (lplu) state is set to the power management level D3
1410 * and SmartSpeed is disabled when active is true, else clear lplu for D3
1411 * and enable Smartspeed. LPLU and Smartspeed are mutually exclusive. LPLU
1412 * is used during Dx states where the power conservation is most important.
1413 * During driver activity, SmartSpeed should be enabled so performance is
1414 * maintained.
1415 **/
1416s32 igb_set_d3_lplu_state(struct e1000_hw *hw, bool active)
1417{
1418 struct e1000_phy_info *phy = &hw->phy;
Alexander Duyck2553bb22009-10-05 06:35:42 +00001419 s32 ret_val = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08001420 u16 data;
1421
Alexander Duyck2553bb22009-10-05 06:35:42 +00001422 if (!(hw->phy.ops.read_reg))
1423 goto out;
1424
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001425 ret_val = phy->ops.read_reg(hw, IGP02E1000_PHY_POWER_MGMT, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001426 if (ret_val)
1427 goto out;
1428
1429 if (!active) {
1430 data &= ~IGP02E1000_PM_D3_LPLU;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001431 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
Auke Kok9d5c8242008-01-24 02:22:38 -08001432 data);
1433 if (ret_val)
1434 goto out;
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001435 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
Auke Kok9d5c8242008-01-24 02:22:38 -08001436 * during Dx states where the power conservation is most
1437 * important. During driver activity we should enable
1438 * SmartSpeed, so performance is maintained.
1439 */
1440 if (phy->smart_speed == e1000_smart_speed_on) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001441 ret_val = phy->ops.read_reg(hw,
Auke Kok9d5c8242008-01-24 02:22:38 -08001442 IGP01E1000_PHY_PORT_CONFIG,
1443 &data);
1444 if (ret_val)
1445 goto out;
1446
1447 data |= IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001448 ret_val = phy->ops.write_reg(hw,
Auke Kok9d5c8242008-01-24 02:22:38 -08001449 IGP01E1000_PHY_PORT_CONFIG,
1450 data);
1451 if (ret_val)
1452 goto out;
1453 } else if (phy->smart_speed == e1000_smart_speed_off) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001454 ret_val = phy->ops.read_reg(hw,
Auke Kok9d5c8242008-01-24 02:22:38 -08001455 IGP01E1000_PHY_PORT_CONFIG,
1456 &data);
1457 if (ret_val)
1458 goto out;
1459
1460 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001461 ret_val = phy->ops.write_reg(hw,
Auke Kok9d5c8242008-01-24 02:22:38 -08001462 IGP01E1000_PHY_PORT_CONFIG,
1463 data);
1464 if (ret_val)
1465 goto out;
1466 }
1467 } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
1468 (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
1469 (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
1470 data |= IGP02E1000_PM_D3_LPLU;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001471 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
Auke Kok9d5c8242008-01-24 02:22:38 -08001472 data);
1473 if (ret_val)
1474 goto out;
1475
1476 /* When LPLU is enabled, we should disable SmartSpeed */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001477 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001478 &data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001479 if (ret_val)
1480 goto out;
1481
1482 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001483 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001484 data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001485 }
1486
1487out:
1488 return ret_val;
1489}
1490
1491/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001492 * igb_check_downshift - Checks whether a downshift in speed occurred
Auke Kok9d5c8242008-01-24 02:22:38 -08001493 * @hw: pointer to the HW structure
1494 *
1495 * Success returns 0, Failure returns 1
1496 *
1497 * A downshift is detected by querying the PHY link health.
1498 **/
1499s32 igb_check_downshift(struct e1000_hw *hw)
1500{
1501 struct e1000_phy_info *phy = &hw->phy;
1502 s32 ret_val;
1503 u16 phy_data, offset, mask;
1504
1505 switch (phy->type) {
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001506 case e1000_phy_i210:
Auke Kok9d5c8242008-01-24 02:22:38 -08001507 case e1000_phy_m88:
1508 case e1000_phy_gg82563:
1509 offset = M88E1000_PHY_SPEC_STATUS;
1510 mask = M88E1000_PSSR_DOWNSHIFT;
1511 break;
1512 case e1000_phy_igp_2:
1513 case e1000_phy_igp:
1514 case e1000_phy_igp_3:
1515 offset = IGP01E1000_PHY_LINK_HEALTH;
1516 mask = IGP01E1000_PLHR_SS_DOWNGRADE;
1517 break;
1518 default:
1519 /* speed downshift not supported */
1520 phy->speed_downgraded = false;
1521 ret_val = 0;
1522 goto out;
1523 }
1524
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001525 ret_val = phy->ops.read_reg(hw, offset, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001526
1527 if (!ret_val)
1528 phy->speed_downgraded = (phy_data & mask) ? true : false;
1529
1530out:
1531 return ret_val;
1532}
1533
1534/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001535 * igb_check_polarity_m88 - Checks the polarity.
Auke Kok9d5c8242008-01-24 02:22:38 -08001536 * @hw: pointer to the HW structure
1537 *
1538 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1539 *
1540 * Polarity is determined based on the PHY specific status register.
1541 **/
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001542s32 igb_check_polarity_m88(struct e1000_hw *hw)
Auke Kok9d5c8242008-01-24 02:22:38 -08001543{
1544 struct e1000_phy_info *phy = &hw->phy;
1545 s32 ret_val;
1546 u16 data;
1547
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001548 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001549
1550 if (!ret_val)
1551 phy->cable_polarity = (data & M88E1000_PSSR_REV_POLARITY)
1552 ? e1000_rev_polarity_reversed
1553 : e1000_rev_polarity_normal;
1554
1555 return ret_val;
1556}
1557
1558/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001559 * igb_check_polarity_igp - Checks the polarity.
Auke Kok9d5c8242008-01-24 02:22:38 -08001560 * @hw: pointer to the HW structure
1561 *
1562 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1563 *
1564 * Polarity is determined based on the PHY port status register, and the
1565 * current speed (since there is no polarity at 100Mbps).
1566 **/
1567static s32 igb_check_polarity_igp(struct e1000_hw *hw)
1568{
1569 struct e1000_phy_info *phy = &hw->phy;
1570 s32 ret_val;
1571 u16 data, offset, mask;
1572
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001573 /* Polarity is determined based on the speed of
Auke Kok9d5c8242008-01-24 02:22:38 -08001574 * our connection.
1575 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001576 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_STATUS, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001577 if (ret_val)
1578 goto out;
1579
1580 if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
1581 IGP01E1000_PSSR_SPEED_1000MBPS) {
1582 offset = IGP01E1000_PHY_PCS_INIT_REG;
1583 mask = IGP01E1000_PHY_POLARITY_MASK;
1584 } else {
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001585 /* This really only applies to 10Mbps since
Auke Kok9d5c8242008-01-24 02:22:38 -08001586 * there is no polarity for 100Mbps (always 0).
1587 */
1588 offset = IGP01E1000_PHY_PORT_STATUS;
1589 mask = IGP01E1000_PSSR_POLARITY_REVERSED;
1590 }
1591
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001592 ret_val = phy->ops.read_reg(hw, offset, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001593
1594 if (!ret_val)
1595 phy->cable_polarity = (data & mask)
1596 ? e1000_rev_polarity_reversed
1597 : e1000_rev_polarity_normal;
1598
1599out:
1600 return ret_val;
1601}
1602
1603/**
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001604 * igb_wait_autoneg - Wait for auto-neg completion
Auke Kok9d5c8242008-01-24 02:22:38 -08001605 * @hw: pointer to the HW structure
1606 *
1607 * Waits for auto-negotiation to complete or for the auto-negotiation time
1608 * limit to expire, which ever happens first.
1609 **/
1610static s32 igb_wait_autoneg(struct e1000_hw *hw)
1611{
1612 s32 ret_val = 0;
1613 u16 i, phy_status;
1614
1615 /* Break after autoneg completes or PHY_AUTO_NEG_LIMIT expires. */
1616 for (i = PHY_AUTO_NEG_LIMIT; i > 0; i--) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001617 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
Auke Kok9d5c8242008-01-24 02:22:38 -08001618 if (ret_val)
1619 break;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001620 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
Auke Kok9d5c8242008-01-24 02:22:38 -08001621 if (ret_val)
1622 break;
1623 if (phy_status & MII_SR_AUTONEG_COMPLETE)
1624 break;
1625 msleep(100);
1626 }
1627
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001628 /* PHY_AUTO_NEG_TIME expiration doesn't guarantee auto-negotiation
Auke Kok9d5c8242008-01-24 02:22:38 -08001629 * has completed.
1630 */
1631 return ret_val;
1632}
1633
1634/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001635 * igb_phy_has_link - Polls PHY for link
Auke Kok9d5c8242008-01-24 02:22:38 -08001636 * @hw: pointer to the HW structure
1637 * @iterations: number of times to poll for link
1638 * @usec_interval: delay between polling attempts
1639 * @success: pointer to whether polling was successful or not
1640 *
1641 * Polls the PHY status register for link, 'iterations' number of times.
1642 **/
1643s32 igb_phy_has_link(struct e1000_hw *hw, u32 iterations,
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001644 u32 usec_interval, bool *success)
Auke Kok9d5c8242008-01-24 02:22:38 -08001645{
1646 s32 ret_val = 0;
1647 u16 i, phy_status;
1648
1649 for (i = 0; i < iterations; i++) {
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001650 /* Some PHYs require the PHY_STATUS register to be read
Auke Kok9d5c8242008-01-24 02:22:38 -08001651 * twice due to the link bit being sticky. No harm doing
1652 * it across the board.
1653 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001654 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
Andi Kleendc3d2262013-04-22 07:46:40 +00001655 if (ret_val && usec_interval > 0) {
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001656 /* If the first read fails, another entity may have
Alexander Duyckab576382009-10-05 06:35:23 +00001657 * ownership of the resources, wait and try again to
1658 * see if they have relinquished the resources yet.
1659 */
Carolyn Wybornydf29df92013-12-14 03:26:46 -08001660 if (usec_interval >= 1000)
1661 mdelay(usec_interval/1000);
1662 else
1663 udelay(usec_interval);
Alexander Duyckab576382009-10-05 06:35:23 +00001664 }
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001665 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
Auke Kok9d5c8242008-01-24 02:22:38 -08001666 if (ret_val)
1667 break;
1668 if (phy_status & MII_SR_LINK_STATUS)
1669 break;
1670 if (usec_interval >= 1000)
1671 mdelay(usec_interval/1000);
1672 else
1673 udelay(usec_interval);
1674 }
1675
1676 *success = (i < iterations) ? true : false;
1677
1678 return ret_val;
1679}
1680
1681/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001682 * igb_get_cable_length_m88 - Determine cable length for m88 PHY
Auke Kok9d5c8242008-01-24 02:22:38 -08001683 * @hw: pointer to the HW structure
1684 *
1685 * Reads the PHY specific status register to retrieve the cable length
1686 * information. The cable length is determined by averaging the minimum and
1687 * maximum values to get the "average" cable length. The m88 PHY has four
1688 * possible cable length values, which are:
1689 * Register Value Cable Length
1690 * 0 < 50 meters
1691 * 1 50 - 80 meters
1692 * 2 80 - 110 meters
1693 * 3 110 - 140 meters
1694 * 4 > 140 meters
1695 **/
1696s32 igb_get_cable_length_m88(struct e1000_hw *hw)
1697{
1698 struct e1000_phy_info *phy = &hw->phy;
1699 s32 ret_val;
1700 u16 phy_data, index;
1701
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001702 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001703 if (ret_val)
1704 goto out;
1705
1706 index = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
1707 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
Alexander Duyck2553bb22009-10-05 06:35:42 +00001708 if (index >= M88E1000_CABLE_LENGTH_TABLE_SIZE - 1) {
1709 ret_val = -E1000_ERR_PHY;
1710 goto out;
1711 }
1712
Auke Kok9d5c8242008-01-24 02:22:38 -08001713 phy->min_cable_length = e1000_m88_cable_length_table[index];
Alexander Duyck2553bb22009-10-05 06:35:42 +00001714 phy->max_cable_length = e1000_m88_cable_length_table[index + 1];
Auke Kok9d5c8242008-01-24 02:22:38 -08001715
1716 phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
1717
1718out:
1719 return ret_val;
1720}
1721
Joseph Gasparakis308fb392010-09-22 17:56:44 +00001722s32 igb_get_cable_length_m88_gen2(struct e1000_hw *hw)
1723{
1724 struct e1000_phy_info *phy = &hw->phy;
1725 s32 ret_val;
1726 u16 phy_data, phy_data2, index, default_page, is_cm;
1727
1728 switch (hw->phy.id) {
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001729 case I210_I_PHY_ID:
Carolyn Wyborny59f30102012-10-10 04:42:59 +00001730 /* Get cable length from PHY Cable Diagnostics Control Reg */
1731 ret_val = phy->ops.read_reg(hw, (0x7 << GS40G_PAGE_SHIFT) +
1732 (I347AT4_PCDL + phy->addr),
1733 &phy_data);
1734 if (ret_val)
1735 return ret_val;
1736
1737 /* Check if the unit of cable length is meters or cm */
1738 ret_val = phy->ops.read_reg(hw, (0x7 << GS40G_PAGE_SHIFT) +
1739 I347AT4_PCDC, &phy_data2);
1740 if (ret_val)
1741 return ret_val;
1742
1743 is_cm = !(phy_data2 & I347AT4_PCDC_CABLE_LENGTH_UNIT);
1744
1745 /* Populate the phy structure with cable length in meters */
1746 phy->min_cable_length = phy_data / (is_cm ? 100 : 1);
1747 phy->max_cable_length = phy_data / (is_cm ? 100 : 1);
1748 phy->cable_length = phy_data / (is_cm ? 100 : 1);
1749 break;
Akeem G Abodunrin99af4722013-08-28 02:22:58 +00001750 case M88E1543_E_PHY_ID:
Joseph Gasparakis308fb392010-09-22 17:56:44 +00001751 case I347AT4_E_PHY_ID:
1752 /* Remember the original page select and set it to 7 */
1753 ret_val = phy->ops.read_reg(hw, I347AT4_PAGE_SELECT,
1754 &default_page);
1755 if (ret_val)
1756 goto out;
1757
1758 ret_val = phy->ops.write_reg(hw, I347AT4_PAGE_SELECT, 0x07);
1759 if (ret_val)
1760 goto out;
1761
1762 /* Get cable length from PHY Cable Diagnostics Control Reg */
1763 ret_val = phy->ops.read_reg(hw, (I347AT4_PCDL + phy->addr),
1764 &phy_data);
1765 if (ret_val)
1766 goto out;
1767
1768 /* Check if the unit of cable length is meters or cm */
1769 ret_val = phy->ops.read_reg(hw, I347AT4_PCDC, &phy_data2);
1770 if (ret_val)
1771 goto out;
1772
Kantecki, Tomaszd5a0e362011-10-17 22:06:59 +00001773 is_cm = !(phy_data2 & I347AT4_PCDC_CABLE_LENGTH_UNIT);
Joseph Gasparakis308fb392010-09-22 17:56:44 +00001774
1775 /* Populate the phy structure with cable length in meters */
1776 phy->min_cable_length = phy_data / (is_cm ? 100 : 1);
1777 phy->max_cable_length = phy_data / (is_cm ? 100 : 1);
1778 phy->cable_length = phy_data / (is_cm ? 100 : 1);
1779
1780 /* Reset the page selec to its original value */
1781 ret_val = phy->ops.write_reg(hw, I347AT4_PAGE_SELECT,
1782 default_page);
1783 if (ret_val)
1784 goto out;
1785 break;
1786 case M88E1112_E_PHY_ID:
1787 /* Remember the original page select and set it to 5 */
1788 ret_val = phy->ops.read_reg(hw, I347AT4_PAGE_SELECT,
1789 &default_page);
1790 if (ret_val)
1791 goto out;
1792
1793 ret_val = phy->ops.write_reg(hw, I347AT4_PAGE_SELECT, 0x05);
1794 if (ret_val)
1795 goto out;
1796
1797 ret_val = phy->ops.read_reg(hw, M88E1112_VCT_DSP_DISTANCE,
1798 &phy_data);
1799 if (ret_val)
1800 goto out;
1801
1802 index = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
1803 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
1804 if (index >= M88E1000_CABLE_LENGTH_TABLE_SIZE - 1) {
1805 ret_val = -E1000_ERR_PHY;
1806 goto out;
1807 }
1808
1809 phy->min_cable_length = e1000_m88_cable_length_table[index];
1810 phy->max_cable_length = e1000_m88_cable_length_table[index + 1];
1811
1812 phy->cable_length = (phy->min_cable_length +
1813 phy->max_cable_length) / 2;
1814
1815 /* Reset the page select to its original value */
1816 ret_val = phy->ops.write_reg(hw, I347AT4_PAGE_SELECT,
1817 default_page);
1818 if (ret_val)
1819 goto out;
1820
1821 break;
1822 default:
1823 ret_val = -E1000_ERR_PHY;
1824 goto out;
1825 }
1826
1827out:
1828 return ret_val;
1829}
1830
Auke Kok9d5c8242008-01-24 02:22:38 -08001831/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001832 * igb_get_cable_length_igp_2 - Determine cable length for igp2 PHY
Auke Kok9d5c8242008-01-24 02:22:38 -08001833 * @hw: pointer to the HW structure
1834 *
1835 * The automatic gain control (agc) normalizes the amplitude of the
1836 * received signal, adjusting for the attenuation produced by the
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001837 * cable. By reading the AGC registers, which represent the
1838 * combination of coarse and fine gain value, the value can be put
Auke Kok9d5c8242008-01-24 02:22:38 -08001839 * into a lookup table to obtain the approximate cable length
1840 * for each channel.
1841 **/
1842s32 igb_get_cable_length_igp_2(struct e1000_hw *hw)
1843{
1844 struct e1000_phy_info *phy = &hw->phy;
1845 s32 ret_val = 0;
1846 u16 phy_data, i, agc_value = 0;
1847 u16 cur_agc_index, max_agc_index = 0;
1848 u16 min_agc_index = IGP02E1000_CABLE_LENGTH_TABLE_SIZE - 1;
Jeff Kirsher66744502010-12-01 19:59:50 +00001849 static const u16 agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] = {
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001850 IGP02E1000_PHY_AGC_A,
1851 IGP02E1000_PHY_AGC_B,
1852 IGP02E1000_PHY_AGC_C,
1853 IGP02E1000_PHY_AGC_D
Jeff Kirsher66744502010-12-01 19:59:50 +00001854 };
Auke Kok9d5c8242008-01-24 02:22:38 -08001855
1856 /* Read the AGC registers for all channels */
1857 for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001858 ret_val = phy->ops.read_reg(hw, agc_reg_array[i], &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001859 if (ret_val)
1860 goto out;
1861
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001862 /* Getting bits 15:9, which represent the combination of
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001863 * coarse and fine gain values. The result is a number
Auke Kok9d5c8242008-01-24 02:22:38 -08001864 * that can be put into the lookup table to obtain the
1865 * approximate cable length.
1866 */
1867 cur_agc_index = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
1868 IGP02E1000_AGC_LENGTH_MASK;
1869
1870 /* Array index bound check. */
1871 if ((cur_agc_index >= IGP02E1000_CABLE_LENGTH_TABLE_SIZE) ||
1872 (cur_agc_index == 0)) {
1873 ret_val = -E1000_ERR_PHY;
1874 goto out;
1875 }
1876
1877 /* Remove min & max AGC values from calculation. */
1878 if (e1000_igp_2_cable_length_table[min_agc_index] >
1879 e1000_igp_2_cable_length_table[cur_agc_index])
1880 min_agc_index = cur_agc_index;
1881 if (e1000_igp_2_cable_length_table[max_agc_index] <
1882 e1000_igp_2_cable_length_table[cur_agc_index])
1883 max_agc_index = cur_agc_index;
1884
1885 agc_value += e1000_igp_2_cable_length_table[cur_agc_index];
1886 }
1887
1888 agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] +
1889 e1000_igp_2_cable_length_table[max_agc_index]);
1890 agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
1891
1892 /* Calculate cable length with the error range of +/- 10 meters. */
1893 phy->min_cable_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
1894 (agc_value - IGP02E1000_AGC_RANGE) : 0;
1895 phy->max_cable_length = agc_value + IGP02E1000_AGC_RANGE;
1896
1897 phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
1898
1899out:
1900 return ret_val;
1901}
1902
1903/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001904 * igb_get_phy_info_m88 - Retrieve PHY information
Auke Kok9d5c8242008-01-24 02:22:38 -08001905 * @hw: pointer to the HW structure
1906 *
1907 * Valid for only copper links. Read the PHY status register (sticky read)
1908 * to verify that link is up. Read the PHY special control register to
1909 * determine the polarity and 10base-T extended distance. Read the PHY
1910 * special status register to determine MDI/MDIx and current speed. If
1911 * speed is 1000, then determine cable length, local and remote receiver.
1912 **/
1913s32 igb_get_phy_info_m88(struct e1000_hw *hw)
1914{
1915 struct e1000_phy_info *phy = &hw->phy;
1916 s32 ret_val;
1917 u16 phy_data;
1918 bool link;
1919
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001920 if (phy->media_type != e1000_media_type_copper) {
Auke Kok652fff32008-06-27 11:00:18 -07001921 hw_dbg("Phy info is only valid for copper media\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001922 ret_val = -E1000_ERR_CONFIG;
1923 goto out;
1924 }
1925
1926 ret_val = igb_phy_has_link(hw, 1, 0, &link);
1927 if (ret_val)
1928 goto out;
1929
1930 if (!link) {
Auke Kok652fff32008-06-27 11:00:18 -07001931 hw_dbg("Phy info is only valid if link is up\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001932 ret_val = -E1000_ERR_CONFIG;
1933 goto out;
1934 }
1935
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001936 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001937 if (ret_val)
1938 goto out;
1939
1940 phy->polarity_correction = (phy_data & M88E1000_PSCR_POLARITY_REVERSAL)
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001941 ? true : false;
Auke Kok9d5c8242008-01-24 02:22:38 -08001942
1943 ret_val = igb_check_polarity_m88(hw);
1944 if (ret_val)
1945 goto out;
1946
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001947 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001948 if (ret_val)
1949 goto out;
1950
1951 phy->is_mdix = (phy_data & M88E1000_PSSR_MDIX) ? true : false;
1952
1953 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001954 ret_val = phy->ops.get_cable_length(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001955 if (ret_val)
1956 goto out;
1957
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001958 ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001959 if (ret_val)
1960 goto out;
1961
1962 phy->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS)
1963 ? e1000_1000t_rx_status_ok
1964 : e1000_1000t_rx_status_not_ok;
1965
1966 phy->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS)
1967 ? e1000_1000t_rx_status_ok
1968 : e1000_1000t_rx_status_not_ok;
1969 } else {
1970 /* Set values to "undefined" */
1971 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
1972 phy->local_rx = e1000_1000t_rx_status_undefined;
1973 phy->remote_rx = e1000_1000t_rx_status_undefined;
1974 }
1975
1976out:
1977 return ret_val;
1978}
1979
1980/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001981 * igb_get_phy_info_igp - Retrieve igp PHY information
Auke Kok9d5c8242008-01-24 02:22:38 -08001982 * @hw: pointer to the HW structure
1983 *
1984 * Read PHY status to determine if link is up. If link is up, then
1985 * set/determine 10base-T extended distance and polarity correction. Read
1986 * PHY port status to determine MDI/MDIx and speed. Based on the speed,
1987 * determine on the cable length, local and remote receiver.
1988 **/
1989s32 igb_get_phy_info_igp(struct e1000_hw *hw)
1990{
1991 struct e1000_phy_info *phy = &hw->phy;
1992 s32 ret_val;
1993 u16 data;
1994 bool link;
1995
1996 ret_val = igb_phy_has_link(hw, 1, 0, &link);
1997 if (ret_val)
1998 goto out;
1999
2000 if (!link) {
Auke Kok652fff32008-06-27 11:00:18 -07002001 hw_dbg("Phy info is only valid if link is up\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08002002 ret_val = -E1000_ERR_CONFIG;
2003 goto out;
2004 }
2005
2006 phy->polarity_correction = true;
2007
2008 ret_val = igb_check_polarity_igp(hw);
2009 if (ret_val)
2010 goto out;
2011
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002012 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_STATUS, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -08002013 if (ret_val)
2014 goto out;
2015
2016 phy->is_mdix = (data & IGP01E1000_PSSR_MDIX) ? true : false;
2017
2018 if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
2019 IGP01E1000_PSSR_SPEED_1000MBPS) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002020 ret_val = phy->ops.get_cable_length(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08002021 if (ret_val)
2022 goto out;
2023
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002024 ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -08002025 if (ret_val)
2026 goto out;
2027
2028 phy->local_rx = (data & SR_1000T_LOCAL_RX_STATUS)
2029 ? e1000_1000t_rx_status_ok
2030 : e1000_1000t_rx_status_not_ok;
2031
2032 phy->remote_rx = (data & SR_1000T_REMOTE_RX_STATUS)
2033 ? e1000_1000t_rx_status_ok
2034 : e1000_1000t_rx_status_not_ok;
2035 } else {
2036 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
2037 phy->local_rx = e1000_1000t_rx_status_undefined;
2038 phy->remote_rx = e1000_1000t_rx_status_undefined;
2039 }
2040
2041out:
2042 return ret_val;
2043}
2044
2045/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07002046 * igb_phy_sw_reset - PHY software reset
Auke Kok9d5c8242008-01-24 02:22:38 -08002047 * @hw: pointer to the HW structure
2048 *
2049 * Does a software reset of the PHY by reading the PHY control register and
2050 * setting/write the control register reset bit to the PHY.
2051 **/
2052s32 igb_phy_sw_reset(struct e1000_hw *hw)
2053{
Alexander Duyckd3147372009-09-14 08:23:13 +00002054 s32 ret_val = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08002055 u16 phy_ctrl;
2056
Alexander Duyckd3147372009-09-14 08:23:13 +00002057 if (!(hw->phy.ops.read_reg))
2058 goto out;
2059
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002060 ret_val = hw->phy.ops.read_reg(hw, PHY_CONTROL, &phy_ctrl);
Auke Kok9d5c8242008-01-24 02:22:38 -08002061 if (ret_val)
2062 goto out;
2063
2064 phy_ctrl |= MII_CR_RESET;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002065 ret_val = hw->phy.ops.write_reg(hw, PHY_CONTROL, phy_ctrl);
Auke Kok9d5c8242008-01-24 02:22:38 -08002066 if (ret_val)
2067 goto out;
2068
2069 udelay(1);
2070
2071out:
2072 return ret_val;
2073}
2074
2075/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07002076 * igb_phy_hw_reset - PHY hardware reset
Auke Kok9d5c8242008-01-24 02:22:38 -08002077 * @hw: pointer to the HW structure
2078 *
2079 * Verify the reset block is not blocking us from resetting. Acquire
2080 * semaphore (if necessary) and read/set/write the device control reset
2081 * bit in the PHY. Wait the appropriate delay time for the device to
Geert Uytterhoeven83a35e32013-06-28 11:27:31 +02002082 * reset and release the semaphore (if necessary).
Auke Kok9d5c8242008-01-24 02:22:38 -08002083 **/
2084s32 igb_phy_hw_reset(struct e1000_hw *hw)
2085{
2086 struct e1000_phy_info *phy = &hw->phy;
2087 s32 ret_val;
2088 u32 ctrl;
2089
2090 ret_val = igb_check_reset_block(hw);
2091 if (ret_val) {
2092 ret_val = 0;
2093 goto out;
2094 }
2095
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002096 ret_val = phy->ops.acquire(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08002097 if (ret_val)
2098 goto out;
2099
2100 ctrl = rd32(E1000_CTRL);
2101 wr32(E1000_CTRL, ctrl | E1000_CTRL_PHY_RST);
2102 wrfl();
2103
2104 udelay(phy->reset_delay_us);
2105
2106 wr32(E1000_CTRL, ctrl);
2107 wrfl();
2108
2109 udelay(150);
2110
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002111 phy->ops.release(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08002112
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002113 ret_val = phy->ops.get_cfg_done(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08002114
2115out:
2116 return ret_val;
2117}
2118
Auke Kok9d5c8242008-01-24 02:22:38 -08002119/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07002120 * igb_phy_init_script_igp3 - Inits the IGP3 PHY
Auke Kok9d5c8242008-01-24 02:22:38 -08002121 * @hw: pointer to the HW structure
2122 *
2123 * Initializes a Intel Gigabit PHY3 when an EEPROM is not present.
2124 **/
2125s32 igb_phy_init_script_igp3(struct e1000_hw *hw)
2126{
Auke Kok652fff32008-06-27 11:00:18 -07002127 hw_dbg("Running IGP 3 PHY init script\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08002128
2129 /* PHY init IGP 3 */
2130 /* Enable rise/fall, 10-mode work in class-A */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002131 hw->phy.ops.write_reg(hw, 0x2F5B, 0x9018);
Auke Kok9d5c8242008-01-24 02:22:38 -08002132 /* Remove all caps from Replica path filter */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002133 hw->phy.ops.write_reg(hw, 0x2F52, 0x0000);
Auke Kok9d5c8242008-01-24 02:22:38 -08002134 /* Bias trimming for ADC, AFE and Driver (Default) */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002135 hw->phy.ops.write_reg(hw, 0x2FB1, 0x8B24);
Auke Kok9d5c8242008-01-24 02:22:38 -08002136 /* Increase Hybrid poly bias */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002137 hw->phy.ops.write_reg(hw, 0x2FB2, 0xF8F0);
Auke Kok9d5c8242008-01-24 02:22:38 -08002138 /* Add 4% to TX amplitude in Giga mode */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002139 hw->phy.ops.write_reg(hw, 0x2010, 0x10B0);
Auke Kok9d5c8242008-01-24 02:22:38 -08002140 /* Disable trimming (TTT) */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002141 hw->phy.ops.write_reg(hw, 0x2011, 0x0000);
Auke Kok9d5c8242008-01-24 02:22:38 -08002142 /* Poly DC correction to 94.6% + 2% for all channels */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002143 hw->phy.ops.write_reg(hw, 0x20DD, 0x249A);
Auke Kok9d5c8242008-01-24 02:22:38 -08002144 /* ABS DC correction to 95.9% */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002145 hw->phy.ops.write_reg(hw, 0x20DE, 0x00D3);
Auke Kok9d5c8242008-01-24 02:22:38 -08002146 /* BG temp curve trim */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002147 hw->phy.ops.write_reg(hw, 0x28B4, 0x04CE);
Auke Kok9d5c8242008-01-24 02:22:38 -08002148 /* Increasing ADC OPAMP stage 1 currents to max */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002149 hw->phy.ops.write_reg(hw, 0x2F70, 0x29E4);
Auke Kok9d5c8242008-01-24 02:22:38 -08002150 /* Force 1000 ( required for enabling PHY regs configuration) */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002151 hw->phy.ops.write_reg(hw, 0x0000, 0x0140);
Auke Kok9d5c8242008-01-24 02:22:38 -08002152 /* Set upd_freq to 6 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002153 hw->phy.ops.write_reg(hw, 0x1F30, 0x1606);
Auke Kok9d5c8242008-01-24 02:22:38 -08002154 /* Disable NPDFE */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002155 hw->phy.ops.write_reg(hw, 0x1F31, 0xB814);
Auke Kok9d5c8242008-01-24 02:22:38 -08002156 /* Disable adaptive fixed FFE (Default) */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002157 hw->phy.ops.write_reg(hw, 0x1F35, 0x002A);
Auke Kok9d5c8242008-01-24 02:22:38 -08002158 /* Enable FFE hysteresis */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002159 hw->phy.ops.write_reg(hw, 0x1F3E, 0x0067);
Auke Kok9d5c8242008-01-24 02:22:38 -08002160 /* Fixed FFE for short cable lengths */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002161 hw->phy.ops.write_reg(hw, 0x1F54, 0x0065);
Auke Kok9d5c8242008-01-24 02:22:38 -08002162 /* Fixed FFE for medium cable lengths */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002163 hw->phy.ops.write_reg(hw, 0x1F55, 0x002A);
Auke Kok9d5c8242008-01-24 02:22:38 -08002164 /* Fixed FFE for long cable lengths */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002165 hw->phy.ops.write_reg(hw, 0x1F56, 0x002A);
Auke Kok9d5c8242008-01-24 02:22:38 -08002166 /* Enable Adaptive Clip Threshold */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002167 hw->phy.ops.write_reg(hw, 0x1F72, 0x3FB0);
Auke Kok9d5c8242008-01-24 02:22:38 -08002168 /* AHT reset limit to 1 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002169 hw->phy.ops.write_reg(hw, 0x1F76, 0xC0FF);
Auke Kok9d5c8242008-01-24 02:22:38 -08002170 /* Set AHT master delay to 127 msec */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002171 hw->phy.ops.write_reg(hw, 0x1F77, 0x1DEC);
Auke Kok9d5c8242008-01-24 02:22:38 -08002172 /* Set scan bits for AHT */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002173 hw->phy.ops.write_reg(hw, 0x1F78, 0xF9EF);
Auke Kok9d5c8242008-01-24 02:22:38 -08002174 /* Set AHT Preset bits */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002175 hw->phy.ops.write_reg(hw, 0x1F79, 0x0210);
Auke Kok9d5c8242008-01-24 02:22:38 -08002176 /* Change integ_factor of channel A to 3 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002177 hw->phy.ops.write_reg(hw, 0x1895, 0x0003);
Auke Kok9d5c8242008-01-24 02:22:38 -08002178 /* Change prop_factor of channels BCD to 8 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002179 hw->phy.ops.write_reg(hw, 0x1796, 0x0008);
Auke Kok9d5c8242008-01-24 02:22:38 -08002180 /* Change cg_icount + enable integbp for channels BCD */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002181 hw->phy.ops.write_reg(hw, 0x1798, 0xD008);
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002182 /* Change cg_icount + enable integbp + change prop_factor_master
Auke Kok9d5c8242008-01-24 02:22:38 -08002183 * to 8 for channel A
2184 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002185 hw->phy.ops.write_reg(hw, 0x1898, 0xD918);
Auke Kok9d5c8242008-01-24 02:22:38 -08002186 /* Disable AHT in Slave mode on channel A */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002187 hw->phy.ops.write_reg(hw, 0x187A, 0x0800);
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002188 /* Enable LPLU and disable AN to 1000 in non-D0a states,
Auke Kok9d5c8242008-01-24 02:22:38 -08002189 * Enable SPD+B2B
2190 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002191 hw->phy.ops.write_reg(hw, 0x0019, 0x008D);
Auke Kok9d5c8242008-01-24 02:22:38 -08002192 /* Enable restart AN on an1000_dis change */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002193 hw->phy.ops.write_reg(hw, 0x001B, 0x2080);
Auke Kok9d5c8242008-01-24 02:22:38 -08002194 /* Enable wh_fifo read clock in 10/100 modes */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002195 hw->phy.ops.write_reg(hw, 0x0014, 0x0045);
Auke Kok9d5c8242008-01-24 02:22:38 -08002196 /* Restart AN, Speed selection is 1000 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002197 hw->phy.ops.write_reg(hw, 0x0000, 0x1340);
Auke Kok9d5c8242008-01-24 02:22:38 -08002198
2199 return 0;
2200}
2201
Alexander Duyck2909c3f2009-11-19 12:41:42 +00002202/**
Nick Nunley88a268c2010-02-17 01:01:59 +00002203 * igb_power_up_phy_copper - Restore copper link in case of PHY power down
2204 * @hw: pointer to the HW structure
2205 *
2206 * In the case of a PHY power down to save power, or to turn off link during a
2207 * driver unload, restore the link to previous settings.
2208 **/
2209void igb_power_up_phy_copper(struct e1000_hw *hw)
2210{
2211 u16 mii_reg = 0;
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00002212 u16 power_reg = 0;
Nick Nunley88a268c2010-02-17 01:01:59 +00002213
2214 /* The PHY will retain its settings across a power down/up cycle */
2215 hw->phy.ops.read_reg(hw, PHY_CONTROL, &mii_reg);
2216 mii_reg &= ~MII_CR_POWER_DOWN;
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00002217 if (hw->phy.type == e1000_phy_i210) {
2218 hw->phy.ops.read_reg(hw, GS40G_COPPER_SPEC, &power_reg);
2219 power_reg &= ~GS40G_CS_POWER_DOWN;
2220 hw->phy.ops.write_reg(hw, GS40G_COPPER_SPEC, power_reg);
2221 }
Nick Nunley88a268c2010-02-17 01:01:59 +00002222 hw->phy.ops.write_reg(hw, PHY_CONTROL, mii_reg);
2223}
2224
2225/**
2226 * igb_power_down_phy_copper - Power down copper PHY
2227 * @hw: pointer to the HW structure
2228 *
2229 * Power down PHY to save power when interface is down and wake on lan
2230 * is not enabled.
2231 **/
2232void igb_power_down_phy_copper(struct e1000_hw *hw)
2233{
2234 u16 mii_reg = 0;
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00002235 u16 power_reg = 0;
Nick Nunley88a268c2010-02-17 01:01:59 +00002236
2237 /* The PHY will retain its settings across a power down/up cycle */
2238 hw->phy.ops.read_reg(hw, PHY_CONTROL, &mii_reg);
2239 mii_reg |= MII_CR_POWER_DOWN;
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00002240
2241 /* i210 Phy requires an additional bit for power up/down */
2242 if (hw->phy.type == e1000_phy_i210) {
2243 hw->phy.ops.read_reg(hw, GS40G_COPPER_SPEC, &power_reg);
2244 power_reg |= GS40G_CS_POWER_DOWN;
2245 hw->phy.ops.write_reg(hw, GS40G_COPPER_SPEC, power_reg);
2246 }
Nick Nunley88a268c2010-02-17 01:01:59 +00002247 hw->phy.ops.write_reg(hw, PHY_CONTROL, mii_reg);
2248 msleep(1);
2249}
2250
2251/**
Alexander Duyck2909c3f2009-11-19 12:41:42 +00002252 * igb_check_polarity_82580 - Checks the polarity.
2253 * @hw: pointer to the HW structure
2254 *
2255 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
2256 *
2257 * Polarity is determined based on the PHY specific status register.
2258 **/
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002259static s32 igb_check_polarity_82580(struct e1000_hw *hw)
Alexander Duyck2909c3f2009-11-19 12:41:42 +00002260{
2261 struct e1000_phy_info *phy = &hw->phy;
2262 s32 ret_val;
2263 u16 data;
2264
2265
2266 ret_val = phy->ops.read_reg(hw, I82580_PHY_STATUS_2, &data);
2267
2268 if (!ret_val)
2269 phy->cable_polarity = (data & I82580_PHY_STATUS2_REV_POLARITY)
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002270 ? e1000_rev_polarity_reversed
2271 : e1000_rev_polarity_normal;
Alexander Duyck2909c3f2009-11-19 12:41:42 +00002272
2273 return ret_val;
2274}
2275
2276/**
2277 * igb_phy_force_speed_duplex_82580 - Force speed/duplex for I82580 PHY
2278 * @hw: pointer to the HW structure
2279 *
2280 * Calls the PHY setup function to force speed and duplex. Clears the
2281 * auto-crossover to force MDI manually. Waits for link and returns
2282 * successful if link up is successful, else -E1000_ERR_PHY (-2).
2283 **/
2284s32 igb_phy_force_speed_duplex_82580(struct e1000_hw *hw)
2285{
2286 struct e1000_phy_info *phy = &hw->phy;
2287 s32 ret_val;
2288 u16 phy_data;
2289 bool link;
2290
Alexander Duyck2909c3f2009-11-19 12:41:42 +00002291 ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data);
2292 if (ret_val)
2293 goto out;
2294
2295 igb_phy_force_speed_duplex_setup(hw, &phy_data);
2296
2297 ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data);
2298 if (ret_val)
2299 goto out;
2300
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002301 /* Clear Auto-Crossover to force MDI manually. 82580 requires MDI
Alexander Duyck2909c3f2009-11-19 12:41:42 +00002302 * forced whenever speed and duplex are forced.
2303 */
2304 ret_val = phy->ops.read_reg(hw, I82580_PHY_CTRL_2, &phy_data);
2305 if (ret_val)
2306 goto out;
2307
Jesse Brandeburg1b556782012-07-26 02:31:04 +00002308 phy_data &= ~I82580_PHY_CTRL2_MDIX_CFG_MASK;
Alexander Duyck2909c3f2009-11-19 12:41:42 +00002309
2310 ret_val = phy->ops.write_reg(hw, I82580_PHY_CTRL_2, phy_data);
2311 if (ret_val)
2312 goto out;
2313
2314 hw_dbg("I82580_PHY_CTRL_2: %X\n", phy_data);
2315
2316 udelay(1);
2317
2318 if (phy->autoneg_wait_to_complete) {
2319 hw_dbg("Waiting for forced speed/duplex link on 82580 phy\n");
2320
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002321 ret_val = igb_phy_has_link(hw, PHY_FORCE_LIMIT, 100000, &link);
Alexander Duyck2909c3f2009-11-19 12:41:42 +00002322 if (ret_val)
2323 goto out;
2324
2325 if (!link)
2326 hw_dbg("Link taking longer than expected.\n");
2327
2328 /* Try once more */
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002329 ret_val = igb_phy_has_link(hw, PHY_FORCE_LIMIT, 100000, &link);
Alexander Duyck2909c3f2009-11-19 12:41:42 +00002330 if (ret_val)
2331 goto out;
2332 }
2333
2334out:
2335 return ret_val;
2336}
2337
2338/**
2339 * igb_get_phy_info_82580 - Retrieve I82580 PHY information
2340 * @hw: pointer to the HW structure
2341 *
2342 * Read PHY status to determine if link is up. If link is up, then
2343 * set/determine 10base-T extended distance and polarity correction. Read
2344 * PHY port status to determine MDI/MDIx and speed. Based on the speed,
2345 * determine on the cable length, local and remote receiver.
2346 **/
2347s32 igb_get_phy_info_82580(struct e1000_hw *hw)
2348{
2349 struct e1000_phy_info *phy = &hw->phy;
2350 s32 ret_val;
2351 u16 data;
2352 bool link;
2353
Alexander Duyck2909c3f2009-11-19 12:41:42 +00002354 ret_val = igb_phy_has_link(hw, 1, 0, &link);
2355 if (ret_val)
2356 goto out;
2357
2358 if (!link) {
2359 hw_dbg("Phy info is only valid if link is up\n");
2360 ret_val = -E1000_ERR_CONFIG;
2361 goto out;
2362 }
2363
2364 phy->polarity_correction = true;
2365
2366 ret_val = igb_check_polarity_82580(hw);
2367 if (ret_val)
2368 goto out;
2369
2370 ret_val = phy->ops.read_reg(hw, I82580_PHY_STATUS_2, &data);
2371 if (ret_val)
2372 goto out;
2373
2374 phy->is_mdix = (data & I82580_PHY_STATUS2_MDIX) ? true : false;
2375
2376 if ((data & I82580_PHY_STATUS2_SPEED_MASK) ==
2377 I82580_PHY_STATUS2_SPEED_1000MBPS) {
2378 ret_val = hw->phy.ops.get_cable_length(hw);
2379 if (ret_val)
2380 goto out;
2381
2382 ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &data);
2383 if (ret_val)
2384 goto out;
2385
2386 phy->local_rx = (data & SR_1000T_LOCAL_RX_STATUS)
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002387 ? e1000_1000t_rx_status_ok
2388 : e1000_1000t_rx_status_not_ok;
Alexander Duyck2909c3f2009-11-19 12:41:42 +00002389
2390 phy->remote_rx = (data & SR_1000T_REMOTE_RX_STATUS)
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002391 ? e1000_1000t_rx_status_ok
2392 : e1000_1000t_rx_status_not_ok;
Alexander Duyck2909c3f2009-11-19 12:41:42 +00002393 } else {
2394 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
2395 phy->local_rx = e1000_1000t_rx_status_undefined;
2396 phy->remote_rx = e1000_1000t_rx_status_undefined;
2397 }
2398
2399out:
2400 return ret_val;
2401}
2402
2403/**
2404 * igb_get_cable_length_82580 - Determine cable length for 82580 PHY
2405 * @hw: pointer to the HW structure
2406 *
2407 * Reads the diagnostic status register and verifies result is valid before
2408 * placing it in the phy_cable_length field.
2409 **/
2410s32 igb_get_cable_length_82580(struct e1000_hw *hw)
2411{
2412 struct e1000_phy_info *phy = &hw->phy;
2413 s32 ret_val;
2414 u16 phy_data, length;
2415
Alexander Duyck2909c3f2009-11-19 12:41:42 +00002416 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) >>
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002421 I82580_DSTATUS_CABLE_LENGTH_SHIFT;
Alexander Duyck2909c3f2009-11-19 12:41:42 +00002422
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}