blob: 8015f3b8e579319f3a86e1189890f88ab4564088 [file] [log] [blame]
Carolyn Wybornye52c0f92014-04-11 01:46:06 +00001/* Intel(R) Gigabit Ethernet Linux driver
Todd Fujinaka9fa04522015-06-30 15:16:55 -07002 * Copyright(c) 2007-2015 Intel Corporation.
Carolyn Wybornye52c0f92014-04-11 01:46:06 +00003 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, see <http://www.gnu.org/licenses/>.
15 *
16 * The full GNU General Public License is included in this distribution in
17 * the file called "COPYING".
18 *
19 * Contact Information:
20 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
21 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
22 */
Auke Kok9d5c8242008-01-24 02:22:38 -080023
24#include <linux/if_ether.h>
25#include <linux/delay.h>
26
27#include "e1000_mac.h"
28#include "e1000_phy.h"
29
Auke Kok9d5c8242008-01-24 02:22:38 -080030static s32 igb_phy_setup_autoneg(struct e1000_hw *hw);
31static void igb_phy_force_speed_duplex_setup(struct e1000_hw *hw,
Jeff Kirsherb980ac12013-02-23 07:29:56 +000032 u16 *phy_ctrl);
Auke Kok9d5c8242008-01-24 02:22:38 -080033static s32 igb_wait_autoneg(struct e1000_hw *hw);
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +000034static s32 igb_set_master_slave_mode(struct e1000_hw *hw);
Auke Kok9d5c8242008-01-24 02:22:38 -080035
36/* Cable length tables */
Jeff Kirsherb980ac12013-02-23 07:29:56 +000037static const u16 e1000_m88_cable_length_table[] = {
38 0, 50, 80, 110, 140, 140, E1000_CABLE_LENGTH_UNDEFINED };
Auke Kok9d5c8242008-01-24 02:22:38 -080039
Jeff Kirsherb980ac12013-02-23 07:29:56 +000040static const u16 e1000_igp_2_cable_length_table[] = {
41 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21,
42 0, 0, 0, 3, 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41,
43 6, 10, 14, 18, 22, 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61,
44 21, 26, 31, 35, 40, 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82,
45 40, 45, 51, 56, 61, 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104,
46 60, 66, 72, 77, 82, 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121,
47 83, 89, 95, 100, 105, 109, 113, 116, 119, 122, 124,
48 104, 109, 114, 118, 121, 124};
Auke Kok9d5c8242008-01-24 02:22:38 -080049
50/**
Jeff Kirsher733596b2008-06-27 10:59:59 -070051 * igb_check_reset_block - Check if PHY reset is blocked
Auke Kok9d5c8242008-01-24 02:22:38 -080052 * @hw: pointer to the HW structure
53 *
54 * Read the PHY management control register and check whether a PHY reset
55 * is blocked. If a reset is not blocked return 0, otherwise
56 * return E1000_BLK_PHY_RESET (12).
57 **/
58s32 igb_check_reset_block(struct e1000_hw *hw)
59{
60 u32 manc;
61
62 manc = rd32(E1000_MANC);
63
Jeff Kirsherb980ac12013-02-23 07:29:56 +000064 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ? E1000_BLK_PHY_RESET : 0;
Auke Kok9d5c8242008-01-24 02:22:38 -080065}
66
67/**
Jeff Kirsher733596b2008-06-27 10:59:59 -070068 * igb_get_phy_id - Retrieve the PHY ID and revision
Auke Kok9d5c8242008-01-24 02:22:38 -080069 * @hw: pointer to the HW structure
70 *
71 * Reads the PHY registers and stores the PHY ID and possibly the PHY
72 * revision in the hardware structure.
73 **/
74s32 igb_get_phy_id(struct e1000_hw *hw)
75{
76 struct e1000_phy_info *phy = &hw->phy;
77 s32 ret_val = 0;
78 u16 phy_id;
79
Alexander Duycka8d2a0c2009-02-06 23:17:26 +000080 ret_val = phy->ops.read_reg(hw, PHY_ID1, &phy_id);
Auke Kok9d5c8242008-01-24 02:22:38 -080081 if (ret_val)
82 goto out;
83
84 phy->id = (u32)(phy_id << 16);
85 udelay(20);
Alexander Duycka8d2a0c2009-02-06 23:17:26 +000086 ret_val = phy->ops.read_reg(hw, PHY_ID2, &phy_id);
Auke Kok9d5c8242008-01-24 02:22:38 -080087 if (ret_val)
88 goto out;
89
90 phy->id |= (u32)(phy_id & PHY_REVISION_MASK);
91 phy->revision = (u32)(phy_id & ~PHY_REVISION_MASK);
92
93out:
94 return ret_val;
95}
96
97/**
Jeff Kirsher733596b2008-06-27 10:59:59 -070098 * igb_phy_reset_dsp - Reset PHY DSP
Auke Kok9d5c8242008-01-24 02:22:38 -080099 * @hw: pointer to the HW structure
100 *
101 * Reset the digital signal processor.
102 **/
103static s32 igb_phy_reset_dsp(struct e1000_hw *hw)
104{
Alexander Duyck2553bb22009-10-05 06:35:42 +0000105 s32 ret_val = 0;
106
107 if (!(hw->phy.ops.write_reg))
108 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800109
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000110 ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xC1);
Auke Kok9d5c8242008-01-24 02:22:38 -0800111 if (ret_val)
112 goto out;
113
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000114 ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0);
Auke Kok9d5c8242008-01-24 02:22:38 -0800115
116out:
117 return ret_val;
118}
119
120/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700121 * igb_read_phy_reg_mdic - Read MDI control register
Auke Kok9d5c8242008-01-24 02:22:38 -0800122 * @hw: pointer to the HW structure
123 * @offset: register offset to be read
124 * @data: pointer to the read data
125 *
126 * Reads the MDI control regsiter in the PHY at offset and stores the
127 * information read to data.
128 **/
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000129s32 igb_read_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 *data)
Auke Kok9d5c8242008-01-24 02:22:38 -0800130{
131 struct e1000_phy_info *phy = &hw->phy;
132 u32 i, mdic = 0;
133 s32 ret_val = 0;
134
135 if (offset > MAX_PHY_REG_ADDRESS) {
Auke Kok652fff32008-06-27 11:00:18 -0700136 hw_dbg("PHY Address %d is out of range\n", offset);
Auke Kok9d5c8242008-01-24 02:22:38 -0800137 ret_val = -E1000_ERR_PARAM;
138 goto out;
139 }
140
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000141 /* Set up Op-code, Phy Address, and register offset in the MDI
Auke Kok9d5c8242008-01-24 02:22:38 -0800142 * Control register. The MAC will take care of interfacing with the
143 * PHY to retrieve the desired data.
144 */
145 mdic = ((offset << E1000_MDIC_REG_SHIFT) |
146 (phy->addr << E1000_MDIC_PHY_SHIFT) |
147 (E1000_MDIC_OP_READ));
148
149 wr32(E1000_MDIC, mdic);
150
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000151 /* Poll the ready bit to see if the MDI read completed
Auke Kok9d5c8242008-01-24 02:22:38 -0800152 * Increasing the time out as testing showed failures with
153 * the lower time out
154 */
155 for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
156 udelay(50);
157 mdic = rd32(E1000_MDIC);
158 if (mdic & E1000_MDIC_READY)
159 break;
160 }
161 if (!(mdic & E1000_MDIC_READY)) {
Auke Kok652fff32008-06-27 11:00:18 -0700162 hw_dbg("MDI Read did not complete\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800163 ret_val = -E1000_ERR_PHY;
164 goto out;
165 }
166 if (mdic & E1000_MDIC_ERROR) {
Auke Kok652fff32008-06-27 11:00:18 -0700167 hw_dbg("MDI Error\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800168 ret_val = -E1000_ERR_PHY;
169 goto out;
170 }
171 *data = (u16) mdic;
172
173out:
174 return ret_val;
175}
176
177/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700178 * igb_write_phy_reg_mdic - Write MDI control register
Auke Kok9d5c8242008-01-24 02:22:38 -0800179 * @hw: pointer to the HW structure
180 * @offset: register offset to write to
181 * @data: data to write to register at offset
182 *
183 * Writes data to MDI control register in the PHY at offset.
184 **/
Alexander Duyckbb2ac472009-11-19 12:42:01 +0000185s32 igb_write_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 data)
Auke Kok9d5c8242008-01-24 02:22:38 -0800186{
187 struct e1000_phy_info *phy = &hw->phy;
188 u32 i, mdic = 0;
189 s32 ret_val = 0;
190
191 if (offset > MAX_PHY_REG_ADDRESS) {
Auke Kok652fff32008-06-27 11:00:18 -0700192 hw_dbg("PHY Address %d is out of range\n", offset);
Auke Kok9d5c8242008-01-24 02:22:38 -0800193 ret_val = -E1000_ERR_PARAM;
194 goto out;
195 }
196
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000197 /* Set up Op-code, Phy Address, and register offset in the MDI
Auke Kok9d5c8242008-01-24 02:22:38 -0800198 * Control register. The MAC will take care of interfacing with the
199 * PHY to retrieve the desired data.
200 */
201 mdic = (((u32)data) |
202 (offset << E1000_MDIC_REG_SHIFT) |
203 (phy->addr << E1000_MDIC_PHY_SHIFT) |
204 (E1000_MDIC_OP_WRITE));
205
206 wr32(E1000_MDIC, mdic);
207
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000208 /* Poll the ready bit to see if the MDI read completed
Auke Kok9d5c8242008-01-24 02:22:38 -0800209 * Increasing the time out as testing showed failures with
210 * the lower time out
211 */
212 for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
213 udelay(50);
214 mdic = rd32(E1000_MDIC);
215 if (mdic & E1000_MDIC_READY)
216 break;
217 }
218 if (!(mdic & E1000_MDIC_READY)) {
Auke Kok652fff32008-06-27 11:00:18 -0700219 hw_dbg("MDI Write did not complete\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800220 ret_val = -E1000_ERR_PHY;
221 goto out;
222 }
223 if (mdic & E1000_MDIC_ERROR) {
Auke Kok652fff32008-06-27 11:00:18 -0700224 hw_dbg("MDI Error\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800225 ret_val = -E1000_ERR_PHY;
226 goto out;
227 }
228
229out:
230 return ret_val;
231}
232
233/**
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000234 * igb_read_phy_reg_i2c - Read PHY register using i2c
235 * @hw: pointer to the HW structure
236 * @offset: register offset to be read
237 * @data: pointer to the read data
238 *
239 * Reads the PHY register at offset using the i2c interface and stores the
240 * retrieved information in data.
241 **/
242s32 igb_read_phy_reg_i2c(struct e1000_hw *hw, u32 offset, u16 *data)
243{
244 struct e1000_phy_info *phy = &hw->phy;
245 u32 i, i2ccmd = 0;
246
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000247 /* Set up Op-code, Phy Address, and register address in the I2CCMD
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000248 * register. The MAC will take care of interfacing with the
249 * PHY to retrieve the desired data.
250 */
251 i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) |
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000252 (phy->addr << E1000_I2CCMD_PHY_ADDR_SHIFT) |
253 (E1000_I2CCMD_OPCODE_READ));
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000254
255 wr32(E1000_I2CCMD, i2ccmd);
256
257 /* Poll the ready bit to see if the I2C read completed */
258 for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) {
259 udelay(50);
260 i2ccmd = rd32(E1000_I2CCMD);
261 if (i2ccmd & E1000_I2CCMD_READY)
262 break;
263 }
264 if (!(i2ccmd & E1000_I2CCMD_READY)) {
265 hw_dbg("I2CCMD Read did not complete\n");
266 return -E1000_ERR_PHY;
267 }
268 if (i2ccmd & E1000_I2CCMD_ERROR) {
269 hw_dbg("I2CCMD Error bit set\n");
270 return -E1000_ERR_PHY;
271 }
272
273 /* Need to byte-swap the 16-bit value. */
274 *data = ((i2ccmd >> 8) & 0x00FF) | ((i2ccmd << 8) & 0xFF00);
275
276 return 0;
277}
278
279/**
280 * igb_write_phy_reg_i2c - Write PHY register using i2c
281 * @hw: pointer to the HW structure
282 * @offset: register offset to write to
283 * @data: data to write at register offset
284 *
285 * Writes the data to PHY register at the offset using the i2c interface.
286 **/
287s32 igb_write_phy_reg_i2c(struct e1000_hw *hw, u32 offset, u16 data)
288{
289 struct e1000_phy_info *phy = &hw->phy;
290 u32 i, i2ccmd = 0;
291 u16 phy_data_swapped;
292
Akeem G. Abodunrin76d06522011-09-02 23:11:19 +0000293 /* Prevent overwritting SFP I2C EEPROM which is at A0 address.*/
294 if ((hw->phy.addr == 0) || (hw->phy.addr > 7)) {
295 hw_dbg("PHY I2C Address %d is out of range.\n",
296 hw->phy.addr);
297 return -E1000_ERR_CONFIG;
298 }
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000299
300 /* Swap the data bytes for the I2C interface */
301 phy_data_swapped = ((data >> 8) & 0x00FF) | ((data << 8) & 0xFF00);
302
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000303 /* Set up Op-code, Phy Address, and register address in the I2CCMD
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000304 * register. The MAC will take care of interfacing with the
305 * PHY to retrieve the desired data.
306 */
307 i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) |
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000308 (phy->addr << E1000_I2CCMD_PHY_ADDR_SHIFT) |
309 E1000_I2CCMD_OPCODE_WRITE |
310 phy_data_swapped);
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000311
312 wr32(E1000_I2CCMD, i2ccmd);
313
314 /* Poll the ready bit to see if the I2C read completed */
315 for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) {
316 udelay(50);
317 i2ccmd = rd32(E1000_I2CCMD);
318 if (i2ccmd & E1000_I2CCMD_READY)
319 break;
320 }
321 if (!(i2ccmd & E1000_I2CCMD_READY)) {
322 hw_dbg("I2CCMD Write did not complete\n");
323 return -E1000_ERR_PHY;
324 }
325 if (i2ccmd & E1000_I2CCMD_ERROR) {
326 hw_dbg("I2CCMD Error bit set\n");
327 return -E1000_ERR_PHY;
328 }
329
330 return 0;
331}
332
333/**
Akeem G. Abodunrin641ac5c2013-04-24 16:54:50 +0000334 * igb_read_sfp_data_byte - Reads SFP module data.
335 * @hw: pointer to the HW structure
336 * @offset: byte location offset to be read
337 * @data: read data buffer pointer
338 *
339 * Reads one byte from SFP module data stored
340 * in SFP resided EEPROM memory or SFP diagnostic area.
341 * Function should be called with
342 * E1000_I2CCMD_SFP_DATA_ADDR(<byte offset>) for SFP module database access
343 * E1000_I2CCMD_SFP_DIAG_ADDR(<byte offset>) for SFP diagnostics parameters
344 * access
345 **/
346s32 igb_read_sfp_data_byte(struct e1000_hw *hw, u16 offset, u8 *data)
347{
348 u32 i = 0;
349 u32 i2ccmd = 0;
350 u32 data_local = 0;
351
352 if (offset > E1000_I2CCMD_SFP_DIAG_ADDR(255)) {
353 hw_dbg("I2CCMD command address exceeds upper limit\n");
354 return -E1000_ERR_PHY;
355 }
356
357 /* Set up Op-code, EEPROM Address,in the I2CCMD
358 * register. The MAC will take care of interfacing with the
359 * EEPROM to retrieve the desired data.
360 */
361 i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) |
362 E1000_I2CCMD_OPCODE_READ);
363
364 wr32(E1000_I2CCMD, i2ccmd);
365
366 /* Poll the ready bit to see if the I2C read completed */
367 for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) {
368 udelay(50);
369 data_local = rd32(E1000_I2CCMD);
370 if (data_local & E1000_I2CCMD_READY)
371 break;
372 }
373 if (!(data_local & E1000_I2CCMD_READY)) {
374 hw_dbg("I2CCMD Read did not complete\n");
375 return -E1000_ERR_PHY;
376 }
377 if (data_local & E1000_I2CCMD_ERROR) {
378 hw_dbg("I2CCMD Error bit set\n");
379 return -E1000_ERR_PHY;
380 }
381 *data = (u8) data_local & 0xFF;
382
383 return 0;
384}
385
386/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700387 * igb_read_phy_reg_igp - Read igp PHY register
Auke Kok9d5c8242008-01-24 02:22:38 -0800388 * @hw: pointer to the HW structure
389 * @offset: register offset to be read
390 * @data: pointer to the read data
391 *
392 * Acquires semaphore, if necessary, then reads the PHY register at offset
393 * and storing the retrieved information in data. Release any acquired
394 * semaphores before exiting.
395 **/
396s32 igb_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data)
397{
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000398 s32 ret_val = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -0800399
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000400 if (!(hw->phy.ops.acquire))
401 goto out;
402
403 ret_val = hw->phy.ops.acquire(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800404 if (ret_val)
405 goto out;
406
407 if (offset > MAX_PHY_MULTI_PAGE_REG) {
408 ret_val = igb_write_phy_reg_mdic(hw,
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000409 IGP01E1000_PHY_PAGE_SELECT,
410 (u16)offset);
Auke Kok9d5c8242008-01-24 02:22:38 -0800411 if (ret_val) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000412 hw->phy.ops.release(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800413 goto out;
414 }
415 }
416
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000417 ret_val = igb_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
418 data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800419
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000420 hw->phy.ops.release(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800421
422out:
423 return ret_val;
424}
425
426/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700427 * igb_write_phy_reg_igp - Write igp PHY register
Auke Kok9d5c8242008-01-24 02:22:38 -0800428 * @hw: pointer to the HW structure
429 * @offset: register offset to write to
430 * @data: data to write at register offset
431 *
432 * Acquires semaphore, if necessary, then writes the data to PHY register
433 * at the offset. Release any acquired semaphores before exiting.
434 **/
435s32 igb_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data)
436{
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000437 s32 ret_val = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -0800438
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000439 if (!(hw->phy.ops.acquire))
440 goto out;
441
442 ret_val = hw->phy.ops.acquire(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800443 if (ret_val)
444 goto out;
445
446 if (offset > MAX_PHY_MULTI_PAGE_REG) {
447 ret_val = igb_write_phy_reg_mdic(hw,
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000448 IGP01E1000_PHY_PAGE_SELECT,
449 (u16)offset);
Auke Kok9d5c8242008-01-24 02:22:38 -0800450 if (ret_val) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000451 hw->phy.ops.release(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800452 goto out;
453 }
454 }
455
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000456 ret_val = igb_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000457 data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800458
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000459 hw->phy.ops.release(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800460
461out:
462 return ret_val;
463}
464
465/**
Alexander Duyck2909c3f2009-11-19 12:41:42 +0000466 * igb_copper_link_setup_82580 - Setup 82580 PHY for copper link
467 * @hw: pointer to the HW structure
468 *
469 * Sets up Carrier-sense on Transmit and downshift values.
470 **/
471s32 igb_copper_link_setup_82580(struct e1000_hw *hw)
472{
473 struct e1000_phy_info *phy = &hw->phy;
474 s32 ret_val;
475 u16 phy_data;
476
Alexander Duyck2909c3f2009-11-19 12:41:42 +0000477 if (phy->reset_disable) {
478 ret_val = 0;
479 goto out;
480 }
481
482 if (phy->type == e1000_phy_82580) {
483 ret_val = hw->phy.ops.reset(hw);
484 if (ret_val) {
485 hw_dbg("Error resetting the PHY.\n");
486 goto out;
487 }
488 }
489
490 /* Enable CRS on TX. This must be set for half-duplex operation. */
491 ret_val = phy->ops.read_reg(hw, I82580_CFG_REG, &phy_data);
492 if (ret_val)
493 goto out;
494
495 phy_data |= I82580_CFG_ASSERT_CRS_ON_TX;
496
497 /* Enable downshift */
498 phy_data |= I82580_CFG_ENABLE_DOWNSHIFT;
499
500 ret_val = phy->ops.write_reg(hw, I82580_CFG_REG, phy_data);
Jesse Brandeburg1b556782012-07-26 02:31:04 +0000501 if (ret_val)
502 goto out;
503
504 /* Set MDI/MDIX mode */
505 ret_val = phy->ops.read_reg(hw, I82580_PHY_CTRL_2, &phy_data);
506 if (ret_val)
507 goto out;
508 phy_data &= ~I82580_PHY_CTRL2_MDIX_CFG_MASK;
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000509 /* Options:
Jesse Brandeburg1b556782012-07-26 02:31:04 +0000510 * 0 - Auto (default)
511 * 1 - MDI mode
512 * 2 - MDI-X mode
513 */
514 switch (hw->phy.mdix) {
515 case 1:
516 break;
517 case 2:
518 phy_data |= I82580_PHY_CTRL2_MANUAL_MDIX;
519 break;
520 case 0:
521 default:
522 phy_data |= I82580_PHY_CTRL2_AUTO_MDI_MDIX;
523 break;
524 }
525 ret_val = hw->phy.ops.write_reg(hw, I82580_PHY_CTRL_2, phy_data);
Alexander Duyck2909c3f2009-11-19 12:41:42 +0000526
527out:
528 return ret_val;
529}
530
531/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700532 * igb_copper_link_setup_m88 - Setup m88 PHY's for copper link
Auke Kok9d5c8242008-01-24 02:22:38 -0800533 * @hw: pointer to the HW structure
534 *
535 * Sets up MDI/MDI-X and polarity for m88 PHY's. If necessary, transmit clock
536 * and downshift values are set also.
537 **/
538s32 igb_copper_link_setup_m88(struct e1000_hw *hw)
539{
540 struct e1000_phy_info *phy = &hw->phy;
541 s32 ret_val;
542 u16 phy_data;
543
544 if (phy->reset_disable) {
545 ret_val = 0;
546 goto out;
547 }
548
549 /* Enable CRS on TX. This must be set for half-duplex operation. */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000550 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800551 if (ret_val)
552 goto out;
553
554 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
555
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000556 /* Options:
Auke Kok9d5c8242008-01-24 02:22:38 -0800557 * MDI/MDI-X = 0 (default)
558 * 0 - Auto for all speeds
559 * 1 - MDI mode
560 * 2 - MDI-X mode
561 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
562 */
563 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
564
565 switch (phy->mdix) {
566 case 1:
567 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
568 break;
569 case 2:
570 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
571 break;
572 case 3:
573 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
574 break;
575 case 0:
576 default:
577 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
578 break;
579 }
580
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000581 /* Options:
Auke Kok9d5c8242008-01-24 02:22:38 -0800582 * disable_polarity_correction = 0 (default)
583 * Automatic Correction for Reversed Cable Polarity
584 * 0 - Disabled
585 * 1 - Enabled
586 */
587 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
588 if (phy->disable_polarity_correction == 1)
589 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
590
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000591 ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800592 if (ret_val)
593 goto out;
594
595 if (phy->revision < E1000_REVISION_4) {
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000596 /* Force TX_CLK in the Extended PHY Specific Control Register
Auke Kok9d5c8242008-01-24 02:22:38 -0800597 * to 25MHz clock.
598 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000599 ret_val = phy->ops.read_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000600 &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800601 if (ret_val)
602 goto out;
603
604 phy_data |= M88E1000_EPSCR_TX_CLK_25;
605
606 if ((phy->revision == E1000_REVISION_2) &&
607 (phy->id == M88E1111_I_PHY_ID)) {
608 /* 82573L PHY - set the downshift counter to 5x. */
609 phy_data &= ~M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK;
610 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
611 } else {
612 /* Configure Master and Slave downshift values */
613 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
614 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
615 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
616 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
617 }
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000618 ret_val = phy->ops.write_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
Auke Kok9d5c8242008-01-24 02:22:38 -0800619 phy_data);
620 if (ret_val)
621 goto out;
622 }
623
624 /* Commit the changes. */
625 ret_val = igb_phy_sw_reset(hw);
626 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700627 hw_dbg("Error committing the PHY changes\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800628 goto out;
629 }
630
631out:
632 return ret_val;
633}
634
635/**
Joseph Gasparakis308fb392010-09-22 17:56:44 +0000636 * igb_copper_link_setup_m88_gen2 - Setup m88 PHY's for copper link
637 * @hw: pointer to the HW structure
638 *
639 * Sets up MDI/MDI-X and polarity for i347-AT4, m88e1322 and m88e1112 PHY's.
640 * Also enables and sets the downshift parameters.
641 **/
642s32 igb_copper_link_setup_m88_gen2(struct e1000_hw *hw)
643{
644 struct e1000_phy_info *phy = &hw->phy;
645 s32 ret_val;
646 u16 phy_data;
647
Akeem G Abodunrindfc70752013-08-28 02:22:48 +0000648 if (phy->reset_disable)
649 return 0;
Joseph Gasparakis308fb392010-09-22 17:56:44 +0000650
651 /* Enable CRS on Tx. This must be set for half-duplex operation. */
652 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
653 if (ret_val)
Akeem G Abodunrindfc70752013-08-28 02:22:48 +0000654 return ret_val;
Joseph Gasparakis308fb392010-09-22 17:56:44 +0000655
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000656 /* Options:
Joseph Gasparakis308fb392010-09-22 17:56:44 +0000657 * MDI/MDI-X = 0 (default)
658 * 0 - Auto for all speeds
659 * 1 - MDI mode
660 * 2 - MDI-X mode
661 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
662 */
663 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
664
665 switch (phy->mdix) {
666 case 1:
667 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
668 break;
669 case 2:
670 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
671 break;
672 case 3:
673 /* M88E1112 does not support this mode) */
674 if (phy->id != M88E1112_E_PHY_ID) {
675 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
676 break;
677 }
678 case 0:
679 default:
680 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
681 break;
682 }
683
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000684 /* Options:
Joseph Gasparakis308fb392010-09-22 17:56:44 +0000685 * disable_polarity_correction = 0 (default)
686 * Automatic Correction for Reversed Cable Polarity
687 * 0 - Disabled
688 * 1 - Enabled
689 */
690 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
691 if (phy->disable_polarity_correction == 1)
692 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
693
694 /* Enable downshift and setting it to X6 */
Akeem G Abodunrindfc70752013-08-28 02:22:48 +0000695 if (phy->id == M88E1543_E_PHY_ID) {
696 phy_data &= ~I347AT4_PSCR_DOWNSHIFT_ENABLE;
697 ret_val =
698 phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
699 if (ret_val)
700 return ret_val;
701
702 ret_val = igb_phy_sw_reset(hw);
703 if (ret_val) {
704 hw_dbg("Error committing the PHY changes\n");
705 return ret_val;
706 }
707 }
708
Joseph Gasparakis308fb392010-09-22 17:56:44 +0000709 phy_data &= ~I347AT4_PSCR_DOWNSHIFT_MASK;
710 phy_data |= I347AT4_PSCR_DOWNSHIFT_6X;
711 phy_data |= I347AT4_PSCR_DOWNSHIFT_ENABLE;
712
713 ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
714 if (ret_val)
Akeem G Abodunrindfc70752013-08-28 02:22:48 +0000715 return ret_val;
Joseph Gasparakis308fb392010-09-22 17:56:44 +0000716
717 /* Commit the changes. */
718 ret_val = igb_phy_sw_reset(hw);
719 if (ret_val) {
720 hw_dbg("Error committing the PHY changes\n");
Akeem G Abodunrindfc70752013-08-28 02:22:48 +0000721 return ret_val;
Joseph Gasparakis308fb392010-09-22 17:56:44 +0000722 }
Carolyn Wybornyd1c17d82013-08-16 00:39:10 +0000723 ret_val = igb_set_master_slave_mode(hw);
724 if (ret_val)
725 return ret_val;
Joseph Gasparakis308fb392010-09-22 17:56:44 +0000726
Akeem G Abodunrindfc70752013-08-28 02:22:48 +0000727 return 0;
Joseph Gasparakis308fb392010-09-22 17:56:44 +0000728}
729
730/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700731 * igb_copper_link_setup_igp - Setup igp PHY's for copper link
Auke Kok9d5c8242008-01-24 02:22:38 -0800732 * @hw: pointer to the HW structure
733 *
734 * Sets up LPLU, MDI/MDI-X, polarity, Smartspeed and Master/Slave config for
735 * igp PHY's.
736 **/
737s32 igb_copper_link_setup_igp(struct e1000_hw *hw)
738{
739 struct e1000_phy_info *phy = &hw->phy;
740 s32 ret_val;
741 u16 data;
742
743 if (phy->reset_disable) {
744 ret_val = 0;
745 goto out;
746 }
747
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000748 ret_val = phy->ops.reset(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800749 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700750 hw_dbg("Error resetting the PHY.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800751 goto out;
752 }
753
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000754 /* Wait 100ms for MAC to configure PHY from NVM settings, to avoid
Alexander Duycka6a60562009-03-31 20:38:38 +0000755 * timeout issues when LFS is enabled.
756 */
757 msleep(100);
Auke Kok9d5c8242008-01-24 02:22:38 -0800758
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000759 /* The NVM settings will configure LPLU in D3 for
Auke Kok9d5c8242008-01-24 02:22:38 -0800760 * non-IGP1 PHYs.
761 */
762 if (phy->type == e1000_phy_igp) {
763 /* disable lplu d3 during driver init */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000764 if (phy->ops.set_d3_lplu_state)
765 ret_val = phy->ops.set_d3_lplu_state(hw, false);
Auke Kok9d5c8242008-01-24 02:22:38 -0800766 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700767 hw_dbg("Error Disabling LPLU D3\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800768 goto out;
769 }
770 }
771
772 /* disable lplu d0 during driver init */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000773 ret_val = phy->ops.set_d0_lplu_state(hw, false);
Auke Kok9d5c8242008-01-24 02:22:38 -0800774 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700775 hw_dbg("Error Disabling LPLU D0\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800776 goto out;
777 }
778 /* Configure mdi-mdix settings */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000779 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CTRL, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800780 if (ret_val)
781 goto out;
782
783 data &= ~IGP01E1000_PSCR_AUTO_MDIX;
784
785 switch (phy->mdix) {
786 case 1:
787 data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
788 break;
789 case 2:
790 data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
791 break;
792 case 0:
793 default:
794 data |= IGP01E1000_PSCR_AUTO_MDIX;
795 break;
796 }
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000797 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CTRL, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800798 if (ret_val)
799 goto out;
800
801 /* set auto-master slave resolution settings */
802 if (hw->mac.autoneg) {
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000803 /* when autonegotiation advertisement is only 1000Mbps then we
Auke Kok9d5c8242008-01-24 02:22:38 -0800804 * should disable SmartSpeed and enable Auto MasterSlave
805 * resolution as hardware default.
806 */
807 if (phy->autoneg_advertised == ADVERTISE_1000_FULL) {
808 /* Disable SmartSpeed */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000809 ret_val = phy->ops.read_reg(hw,
810 IGP01E1000_PHY_PORT_CONFIG,
811 &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800812 if (ret_val)
813 goto out;
814
815 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000816 ret_val = phy->ops.write_reg(hw,
Auke Kok9d5c8242008-01-24 02:22:38 -0800817 IGP01E1000_PHY_PORT_CONFIG,
818 data);
819 if (ret_val)
820 goto out;
821
822 /* Set auto Master/Slave resolution process */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000823 ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800824 if (ret_val)
825 goto out;
826
827 data &= ~CR_1000T_MS_ENABLE;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000828 ret_val = phy->ops.write_reg(hw, PHY_1000T_CTRL, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800829 if (ret_val)
830 goto out;
831 }
832
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 /* load defaults for future use */
838 phy->original_ms_type = (data & CR_1000T_MS_ENABLE) ?
839 ((data & CR_1000T_MS_VALUE) ?
840 e1000_ms_force_master :
841 e1000_ms_force_slave) :
842 e1000_ms_auto;
843
844 switch (phy->ms_type) {
845 case e1000_ms_force_master:
846 data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
847 break;
848 case e1000_ms_force_slave:
849 data |= CR_1000T_MS_ENABLE;
850 data &= ~(CR_1000T_MS_VALUE);
851 break;
852 case e1000_ms_auto:
853 data &= ~CR_1000T_MS_ENABLE;
854 default:
855 break;
856 }
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000857 ret_val = phy->ops.write_reg(hw, PHY_1000T_CTRL, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800858 if (ret_val)
859 goto out;
860 }
861
862out:
863 return ret_val;
864}
865
866/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700867 * igb_copper_link_autoneg - Setup/Enable autoneg for copper link
Auke Kok9d5c8242008-01-24 02:22:38 -0800868 * @hw: pointer to the HW structure
869 *
870 * Performs initial bounds checking on autoneg advertisement parameter, then
871 * configure to advertise the full capability. Setup the PHY to autoneg
872 * and restart the negotiation process between the link partner. If
873 * autoneg_wait_to_complete, then wait for autoneg to complete before exiting.
874 **/
Alexander Duyck81fadd82009-10-05 06:35:03 +0000875static s32 igb_copper_link_autoneg(struct e1000_hw *hw)
Auke Kok9d5c8242008-01-24 02:22:38 -0800876{
877 struct e1000_phy_info *phy = &hw->phy;
878 s32 ret_val;
879 u16 phy_ctrl;
880
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000881 /* Perform some bounds checking on the autoneg advertisement
Auke Kok9d5c8242008-01-24 02:22:38 -0800882 * parameter.
883 */
884 phy->autoneg_advertised &= phy->autoneg_mask;
885
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000886 /* If autoneg_advertised is zero, we assume it was not defaulted
Auke Kok9d5c8242008-01-24 02:22:38 -0800887 * by the calling code so we set to advertise full capability.
888 */
889 if (phy->autoneg_advertised == 0)
890 phy->autoneg_advertised = phy->autoneg_mask;
891
Auke Kok652fff32008-06-27 11:00:18 -0700892 hw_dbg("Reconfiguring auto-neg advertisement params\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800893 ret_val = igb_phy_setup_autoneg(hw);
894 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700895 hw_dbg("Error Setting up Auto-Negotiation\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800896 goto out;
897 }
Auke Kok652fff32008-06-27 11:00:18 -0700898 hw_dbg("Restarting Auto-Neg\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800899
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000900 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
Auke Kok9d5c8242008-01-24 02:22:38 -0800901 * the Auto Neg Restart bit in the PHY control register.
902 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000903 ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_ctrl);
Auke Kok9d5c8242008-01-24 02:22:38 -0800904 if (ret_val)
905 goto out;
906
907 phy_ctrl |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000908 ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_ctrl);
Auke Kok9d5c8242008-01-24 02:22:38 -0800909 if (ret_val)
910 goto out;
911
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000912 /* Does the user want to wait for Auto-Neg to complete here, or
Auke Kok9d5c8242008-01-24 02:22:38 -0800913 * check at a later time (for example, callback routine).
914 */
915 if (phy->autoneg_wait_to_complete) {
916 ret_val = igb_wait_autoneg(hw);
917 if (ret_val) {
Carolyn Wybornyc75c4ed2014-04-11 01:45:17 +0000918 hw_dbg("Error while waiting for autoneg to complete\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800919 goto out;
920 }
921 }
922
923 hw->mac.get_link_status = true;
924
925out:
926 return ret_val;
927}
928
929/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700930 * igb_phy_setup_autoneg - Configure PHY for auto-negotiation
Auke Kok9d5c8242008-01-24 02:22:38 -0800931 * @hw: pointer to the HW structure
932 *
933 * Reads the MII auto-neg advertisement register and/or the 1000T control
934 * register and if the PHY is already setup for auto-negotiation, then
935 * return successful. Otherwise, setup advertisement and flow control to
936 * the appropriate values for the wanted auto-negotiation.
937 **/
938static s32 igb_phy_setup_autoneg(struct e1000_hw *hw)
939{
940 struct e1000_phy_info *phy = &hw->phy;
941 s32 ret_val;
942 u16 mii_autoneg_adv_reg;
943 u16 mii_1000t_ctrl_reg = 0;
944
945 phy->autoneg_advertised &= phy->autoneg_mask;
946
947 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000948 ret_val = phy->ops.read_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
Auke Kok9d5c8242008-01-24 02:22:38 -0800949 if (ret_val)
950 goto out;
951
952 if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
953 /* Read the MII 1000Base-T Control Register (Address 9). */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000954 ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL,
Auke Kok9d5c8242008-01-24 02:22:38 -0800955 &mii_1000t_ctrl_reg);
956 if (ret_val)
957 goto out;
958 }
959
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000960 /* Need to parse both autoneg_advertised and fc and set up
Auke Kok9d5c8242008-01-24 02:22:38 -0800961 * the appropriate PHY registers. First we will parse for
962 * autoneg_advertised software override. Since we can advertise
963 * a plethora of combinations, we need to check each bit
964 * individually.
965 */
966
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000967 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
Auke Kok9d5c8242008-01-24 02:22:38 -0800968 * Advertisement Register (Address 4) and the 1000 mb speed bits in
969 * the 1000Base-T Control Register (Address 9).
970 */
971 mii_autoneg_adv_reg &= ~(NWAY_AR_100TX_FD_CAPS |
972 NWAY_AR_100TX_HD_CAPS |
973 NWAY_AR_10T_FD_CAPS |
974 NWAY_AR_10T_HD_CAPS);
975 mii_1000t_ctrl_reg &= ~(CR_1000T_HD_CAPS | CR_1000T_FD_CAPS);
976
Auke Kok652fff32008-06-27 11:00:18 -0700977 hw_dbg("autoneg_advertised %x\n", phy->autoneg_advertised);
Auke Kok9d5c8242008-01-24 02:22:38 -0800978
979 /* Do we want to advertise 10 Mb Half Duplex? */
980 if (phy->autoneg_advertised & ADVERTISE_10_HALF) {
Auke Kok652fff32008-06-27 11:00:18 -0700981 hw_dbg("Advertise 10mb Half duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800982 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
983 }
984
985 /* Do we want to advertise 10 Mb Full Duplex? */
986 if (phy->autoneg_advertised & ADVERTISE_10_FULL) {
Auke Kok652fff32008-06-27 11:00:18 -0700987 hw_dbg("Advertise 10mb Full duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800988 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
989 }
990
991 /* Do we want to advertise 100 Mb Half Duplex? */
992 if (phy->autoneg_advertised & ADVERTISE_100_HALF) {
Auke Kok652fff32008-06-27 11:00:18 -0700993 hw_dbg("Advertise 100mb Half duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800994 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
995 }
996
997 /* Do we want to advertise 100 Mb Full Duplex? */
998 if (phy->autoneg_advertised & ADVERTISE_100_FULL) {
Auke Kok652fff32008-06-27 11:00:18 -0700999 hw_dbg("Advertise 100mb Full duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001000 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
1001 }
1002
1003 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
1004 if (phy->autoneg_advertised & ADVERTISE_1000_HALF)
Auke Kok652fff32008-06-27 11:00:18 -07001005 hw_dbg("Advertise 1000mb Half duplex request denied!\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001006
1007 /* Do we want to advertise 1000 Mb Full Duplex? */
1008 if (phy->autoneg_advertised & ADVERTISE_1000_FULL) {
Auke Kok652fff32008-06-27 11:00:18 -07001009 hw_dbg("Advertise 1000mb Full duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001010 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
1011 }
1012
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001013 /* Check for a software override of the flow control settings, and
Auke Kok9d5c8242008-01-24 02:22:38 -08001014 * setup the PHY advertisement registers accordingly. If
1015 * auto-negotiation is enabled, then software will have to set the
1016 * "PAUSE" bits to the correct value in the Auto-Negotiation
1017 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-
1018 * negotiation.
1019 *
1020 * The possible values of the "fc" parameter are:
1021 * 0: Flow control is completely disabled
1022 * 1: Rx flow control is enabled (we can receive pause frames
1023 * but not send pause frames).
1024 * 2: Tx flow control is enabled (we can send pause frames
1025 * but we do not support receiving pause frames).
1026 * 3: Both Rx and TX flow control (symmetric) are enabled.
1027 * other: No software override. The flow control configuration
1028 * in the EEPROM is used.
1029 */
Alexander Duyck0cce1192009-07-23 18:10:24 +00001030 switch (hw->fc.current_mode) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001031 case e1000_fc_none:
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001032 /* Flow control (RX & TX) is completely disabled by a
Auke Kok9d5c8242008-01-24 02:22:38 -08001033 * software over-ride.
1034 */
1035 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1036 break;
1037 case e1000_fc_rx_pause:
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001038 /* RX Flow control is enabled, and TX Flow control is
Auke Kok9d5c8242008-01-24 02:22:38 -08001039 * disabled, by a software over-ride.
1040 *
1041 * Since there really isn't a way to advertise that we are
1042 * capable of RX Pause ONLY, we will advertise that we
1043 * support both symmetric and asymmetric RX PAUSE. Later
1044 * (in e1000_config_fc_after_link_up) we will disable the
1045 * hw's ability to send PAUSE frames.
1046 */
1047 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1048 break;
1049 case e1000_fc_tx_pause:
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001050 /* TX Flow control is enabled, and RX Flow control is
Auke Kok9d5c8242008-01-24 02:22:38 -08001051 * disabled, by a software over-ride.
1052 */
1053 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
1054 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
1055 break;
1056 case e1000_fc_full:
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001057 /* Flow control (both RX and TX) is enabled by a software
Auke Kok9d5c8242008-01-24 02:22:38 -08001058 * over-ride.
1059 */
1060 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1061 break;
1062 default:
Auke Kok652fff32008-06-27 11:00:18 -07001063 hw_dbg("Flow control param set incorrectly\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001064 ret_val = -E1000_ERR_CONFIG;
1065 goto out;
1066 }
1067
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001068 ret_val = phy->ops.write_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001069 if (ret_val)
1070 goto out;
1071
Auke Kok652fff32008-06-27 11:00:18 -07001072 hw_dbg("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001073
1074 if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001075 ret_val = phy->ops.write_reg(hw,
1076 PHY_1000T_CTRL,
1077 mii_1000t_ctrl_reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001078 if (ret_val)
1079 goto out;
1080 }
1081
1082out:
1083 return ret_val;
1084}
1085
1086/**
Alexander Duyck81fadd82009-10-05 06:35:03 +00001087 * igb_setup_copper_link - Configure copper link settings
1088 * @hw: pointer to the HW structure
1089 *
1090 * Calls the appropriate function to configure the link for auto-neg or forced
1091 * speed and duplex. Then we check for link, once link is established calls
1092 * to configure collision distance and flow control are called. If link is
1093 * not established, we return -E1000_ERR_PHY (-2).
1094 **/
1095s32 igb_setup_copper_link(struct e1000_hw *hw)
1096{
1097 s32 ret_val;
1098 bool link;
1099
Alexander Duyck81fadd82009-10-05 06:35:03 +00001100 if (hw->mac.autoneg) {
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001101 /* Setup autoneg and flow control advertisement and perform
Alexander Duyck81fadd82009-10-05 06:35:03 +00001102 * autonegotiation.
1103 */
1104 ret_val = igb_copper_link_autoneg(hw);
1105 if (ret_val)
1106 goto out;
1107 } else {
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001108 /* PHY will be set to 10H, 10F, 100H or 100F
Alexander Duyck81fadd82009-10-05 06:35:03 +00001109 * depending on user settings.
1110 */
1111 hw_dbg("Forcing Speed and Duplex\n");
1112 ret_val = hw->phy.ops.force_speed_duplex(hw);
1113 if (ret_val) {
1114 hw_dbg("Error Forcing Speed and Duplex\n");
1115 goto out;
1116 }
1117 }
1118
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001119 /* Check link status. Wait up to 100 microseconds for link to become
Alexander Duyck81fadd82009-10-05 06:35:03 +00001120 * valid.
1121 */
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001122 ret_val = igb_phy_has_link(hw, COPPER_LINK_UP_LIMIT, 10, &link);
Alexander Duyck81fadd82009-10-05 06:35:03 +00001123 if (ret_val)
1124 goto out;
1125
1126 if (link) {
1127 hw_dbg("Valid link established!!!\n");
1128 igb_config_collision_dist(hw);
1129 ret_val = igb_config_fc_after_link_up(hw);
1130 } else {
1131 hw_dbg("Unable to establish link!!!\n");
1132 }
1133
1134out:
1135 return ret_val;
1136}
1137
1138/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001139 * igb_phy_force_speed_duplex_igp - Force speed/duplex for igp PHY
Auke Kok9d5c8242008-01-24 02:22:38 -08001140 * @hw: pointer to the HW structure
1141 *
1142 * Calls the PHY setup function to force speed and duplex. Clears the
1143 * auto-crossover to force MDI manually. Waits for link and returns
1144 * successful if link up is successful, else -E1000_ERR_PHY (-2).
1145 **/
1146s32 igb_phy_force_speed_duplex_igp(struct e1000_hw *hw)
1147{
1148 struct e1000_phy_info *phy = &hw->phy;
1149 s32 ret_val;
1150 u16 phy_data;
1151 bool link;
1152
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001153 ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001154 if (ret_val)
1155 goto out;
1156
1157 igb_phy_force_speed_duplex_setup(hw, &phy_data);
1158
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001159 ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001160 if (ret_val)
1161 goto out;
1162
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001163 /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
Auke Kok9d5c8242008-01-24 02:22:38 -08001164 * forced whenever speed and duplex are forced.
1165 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001166 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001167 if (ret_val)
1168 goto out;
1169
1170 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1171 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1172
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001173 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001174 if (ret_val)
1175 goto out;
1176
Auke Kok652fff32008-06-27 11:00:18 -07001177 hw_dbg("IGP PSCR: %X\n", phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001178
1179 udelay(1);
1180
1181 if (phy->autoneg_wait_to_complete) {
Auke Kok652fff32008-06-27 11:00:18 -07001182 hw_dbg("Waiting for forced speed/duplex link on IGP phy.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001183
Andi Kleendc3d2262013-04-22 07:46:40 +00001184 ret_val = igb_phy_has_link(hw, PHY_FORCE_LIMIT, 10000, &link);
Auke Kok9d5c8242008-01-24 02:22:38 -08001185 if (ret_val)
1186 goto out;
1187
1188 if (!link)
Auke Kok652fff32008-06-27 11:00:18 -07001189 hw_dbg("Link taking longer than expected.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001190
1191 /* Try once more */
Andi Kleendc3d2262013-04-22 07:46:40 +00001192 ret_val = igb_phy_has_link(hw, PHY_FORCE_LIMIT, 10000, &link);
Auke Kok9d5c8242008-01-24 02:22:38 -08001193 if (ret_val)
1194 goto out;
1195 }
1196
1197out:
1198 return ret_val;
1199}
1200
1201/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001202 * igb_phy_force_speed_duplex_m88 - Force speed/duplex for m88 PHY
Auke Kok9d5c8242008-01-24 02:22:38 -08001203 * @hw: pointer to the HW structure
1204 *
1205 * Calls the PHY setup function to force speed and duplex. Clears the
1206 * auto-crossover to force MDI manually. Resets the PHY to commit the
1207 * changes. If time expires while waiting for link up, we reset the DSP.
1208 * After reset, TX_CLK and CRS on TX must be set. Return successful upon
1209 * successful completion, else return corresponding error code.
1210 **/
1211s32 igb_phy_force_speed_duplex_m88(struct e1000_hw *hw)
1212{
1213 struct e1000_phy_info *phy = &hw->phy;
1214 s32 ret_val;
1215 u16 phy_data;
1216 bool link;
1217
Matthew Vick9f0b8512012-10-16 07:44:45 +00001218 /* I210 and I211 devices support Auto-Crossover in forced operation. */
1219 if (phy->type != e1000_phy_i210) {
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001220 /* Clear Auto-Crossover to force MDI manually. M88E1000
Matthew Vick9f0b8512012-10-16 07:44:45 +00001221 * requires MDI forced whenever speed and duplex are forced.
1222 */
1223 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL,
1224 &phy_data);
1225 if (ret_val)
1226 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -08001227
Matthew Vick9f0b8512012-10-16 07:44:45 +00001228 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1229 ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL,
1230 phy_data);
1231 if (ret_val)
1232 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -08001233
Matthew Vick9f0b8512012-10-16 07:44:45 +00001234 hw_dbg("M88E1000 PSCR: %X\n", phy_data);
1235 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001236
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001237 ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001238 if (ret_val)
1239 goto out;
1240
1241 igb_phy_force_speed_duplex_setup(hw, &phy_data);
1242
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001243 ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001244 if (ret_val)
1245 goto out;
1246
Alexander Duyck2553bb22009-10-05 06:35:42 +00001247 /* Reset the phy to commit changes. */
1248 ret_val = igb_phy_sw_reset(hw);
1249 if (ret_val)
1250 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -08001251
1252 if (phy->autoneg_wait_to_complete) {
Auke Kok652fff32008-06-27 11:00:18 -07001253 hw_dbg("Waiting for forced speed/duplex link on M88 phy.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001254
Alexander Duyck2553bb22009-10-05 06:35:42 +00001255 ret_val = igb_phy_has_link(hw, PHY_FORCE_LIMIT, 100000, &link);
Auke Kok9d5c8242008-01-24 02:22:38 -08001256 if (ret_val)
1257 goto out;
1258
1259 if (!link) {
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001260 bool reset_dsp = true;
Joseph Gasparakis308fb392010-09-22 17:56:44 +00001261
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001262 switch (hw->phy.id) {
1263 case I347AT4_E_PHY_ID:
1264 case M88E1112_E_PHY_ID:
Todd Fujinaka51045ec2015-07-29 07:32:06 -07001265 case M88E1543_E_PHY_ID:
1266 case M88E1512_E_PHY_ID:
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001267 case I210_I_PHY_ID:
1268 reset_dsp = false;
1269 break;
1270 default:
1271 if (hw->phy.type != e1000_phy_m88)
1272 reset_dsp = false;
1273 break;
1274 }
Todd Fujinaka51045ec2015-07-29 07:32:06 -07001275 if (!reset_dsp) {
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001276 hw_dbg("Link taking longer than expected.\n");
Todd Fujinaka51045ec2015-07-29 07:32:06 -07001277 } else {
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001278 /* We didn't get link.
Joseph Gasparakis308fb392010-09-22 17:56:44 +00001279 * Reset the DSP and cross our fingers.
1280 */
1281 ret_val = phy->ops.write_reg(hw,
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001282 M88E1000_PHY_PAGE_SELECT,
1283 0x001d);
Joseph Gasparakis308fb392010-09-22 17:56:44 +00001284 if (ret_val)
1285 goto out;
1286 ret_val = igb_phy_reset_dsp(hw);
1287 if (ret_val)
1288 goto out;
1289 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001290 }
1291
1292 /* Try once more */
1293 ret_val = igb_phy_has_link(hw, PHY_FORCE_LIMIT,
Alexander Duyck2553bb22009-10-05 06:35:42 +00001294 100000, &link);
Auke Kok9d5c8242008-01-24 02:22:38 -08001295 if (ret_val)
1296 goto out;
1297 }
1298
Joseph Gasparakis308fb392010-09-22 17:56:44 +00001299 if (hw->phy.type != e1000_phy_m88 ||
1300 hw->phy.id == I347AT4_E_PHY_ID ||
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001301 hw->phy.id == M88E1112_E_PHY_ID ||
Todd Fujinaka51045ec2015-07-29 07:32:06 -07001302 hw->phy.id == M88E1543_E_PHY_ID ||
1303 hw->phy.id == M88E1512_E_PHY_ID ||
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001304 hw->phy.id == I210_I_PHY_ID)
Joseph Gasparakis308fb392010-09-22 17:56:44 +00001305 goto out;
1306
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001307 ret_val = phy->ops.read_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001308 if (ret_val)
1309 goto out;
1310
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001311 /* Resetting the phy means we need to re-force TX_CLK in the
Auke Kok9d5c8242008-01-24 02:22:38 -08001312 * Extended PHY Specific Control Register to 25MHz clock from
1313 * the reset value of 2.5MHz.
1314 */
1315 phy_data |= M88E1000_EPSCR_TX_CLK_25;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001316 ret_val = phy->ops.write_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001317 if (ret_val)
1318 goto out;
1319
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001320 /* In addition, we must re-enable CRS on Tx for both half and full
Auke Kok9d5c8242008-01-24 02:22:38 -08001321 * duplex.
1322 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001323 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001324 if (ret_val)
1325 goto out;
1326
1327 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001328 ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001329
1330out:
1331 return ret_val;
1332}
1333
1334/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001335 * igb_phy_force_speed_duplex_setup - Configure forced PHY speed/duplex
Auke Kok9d5c8242008-01-24 02:22:38 -08001336 * @hw: pointer to the HW structure
1337 * @phy_ctrl: pointer to current value of PHY_CONTROL
1338 *
1339 * Forces speed and duplex on the PHY by doing the following: disable flow
1340 * control, force speed/duplex on the MAC, disable auto speed detection,
1341 * disable auto-negotiation, configure duplex, configure speed, configure
1342 * the collision distance, write configuration to CTRL register. The
1343 * caller must write to the PHY_CONTROL register for these settings to
1344 * take affect.
1345 **/
1346static void igb_phy_force_speed_duplex_setup(struct e1000_hw *hw,
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001347 u16 *phy_ctrl)
Auke Kok9d5c8242008-01-24 02:22:38 -08001348{
1349 struct e1000_mac_info *mac = &hw->mac;
1350 u32 ctrl;
1351
1352 /* Turn off flow control when forcing speed/duplex */
Alexander Duyck0cce1192009-07-23 18:10:24 +00001353 hw->fc.current_mode = e1000_fc_none;
Auke Kok9d5c8242008-01-24 02:22:38 -08001354
1355 /* Force speed/duplex on the mac */
1356 ctrl = rd32(E1000_CTRL);
1357 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1358 ctrl &= ~E1000_CTRL_SPD_SEL;
1359
1360 /* Disable Auto Speed Detection */
1361 ctrl &= ~E1000_CTRL_ASDE;
1362
1363 /* Disable autoneg on the phy */
1364 *phy_ctrl &= ~MII_CR_AUTO_NEG_EN;
1365
1366 /* Forcing Full or Half Duplex? */
1367 if (mac->forced_speed_duplex & E1000_ALL_HALF_DUPLEX) {
1368 ctrl &= ~E1000_CTRL_FD;
1369 *phy_ctrl &= ~MII_CR_FULL_DUPLEX;
Auke Kok652fff32008-06-27 11:00:18 -07001370 hw_dbg("Half Duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001371 } else {
1372 ctrl |= E1000_CTRL_FD;
1373 *phy_ctrl |= MII_CR_FULL_DUPLEX;
Auke Kok652fff32008-06-27 11:00:18 -07001374 hw_dbg("Full Duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001375 }
1376
1377 /* Forcing 10mb or 100mb? */
1378 if (mac->forced_speed_duplex & E1000_ALL_100_SPEED) {
1379 ctrl |= E1000_CTRL_SPD_100;
1380 *phy_ctrl |= MII_CR_SPEED_100;
1381 *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
Auke Kok652fff32008-06-27 11:00:18 -07001382 hw_dbg("Forcing 100mb\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001383 } else {
1384 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1385 *phy_ctrl |= MII_CR_SPEED_10;
1386 *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
Auke Kok652fff32008-06-27 11:00:18 -07001387 hw_dbg("Forcing 10mb\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001388 }
1389
1390 igb_config_collision_dist(hw);
1391
1392 wr32(E1000_CTRL, ctrl);
1393}
1394
1395/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001396 * igb_set_d3_lplu_state - Sets low power link up state for D3
Auke Kok9d5c8242008-01-24 02:22:38 -08001397 * @hw: pointer to the HW structure
1398 * @active: boolean used to enable/disable lplu
1399 *
1400 * Success returns 0, Failure returns 1
1401 *
1402 * The low power link up (lplu) state is set to the power management level D3
1403 * and SmartSpeed is disabled when active is true, else clear lplu for D3
1404 * and enable Smartspeed. LPLU and Smartspeed are mutually exclusive. LPLU
1405 * is used during Dx states where the power conservation is most important.
1406 * During driver activity, SmartSpeed should be enabled so performance is
1407 * maintained.
1408 **/
1409s32 igb_set_d3_lplu_state(struct e1000_hw *hw, bool active)
1410{
1411 struct e1000_phy_info *phy = &hw->phy;
Alexander Duyck2553bb22009-10-05 06:35:42 +00001412 s32 ret_val = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08001413 u16 data;
1414
Alexander Duyck2553bb22009-10-05 06:35:42 +00001415 if (!(hw->phy.ops.read_reg))
1416 goto out;
1417
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001418 ret_val = phy->ops.read_reg(hw, IGP02E1000_PHY_POWER_MGMT, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001419 if (ret_val)
1420 goto out;
1421
1422 if (!active) {
1423 data &= ~IGP02E1000_PM_D3_LPLU;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001424 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
Auke Kok9d5c8242008-01-24 02:22:38 -08001425 data);
1426 if (ret_val)
1427 goto out;
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001428 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
Auke Kok9d5c8242008-01-24 02:22:38 -08001429 * during Dx states where the power conservation is most
1430 * important. During driver activity we should enable
1431 * SmartSpeed, so performance is maintained.
1432 */
1433 if (phy->smart_speed == e1000_smart_speed_on) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001434 ret_val = phy->ops.read_reg(hw,
Auke Kok9d5c8242008-01-24 02:22:38 -08001435 IGP01E1000_PHY_PORT_CONFIG,
1436 &data);
1437 if (ret_val)
1438 goto out;
1439
1440 data |= IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001441 ret_val = phy->ops.write_reg(hw,
Auke Kok9d5c8242008-01-24 02:22:38 -08001442 IGP01E1000_PHY_PORT_CONFIG,
1443 data);
1444 if (ret_val)
1445 goto out;
1446 } else if (phy->smart_speed == e1000_smart_speed_off) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001447 ret_val = phy->ops.read_reg(hw,
Auke Kok9d5c8242008-01-24 02:22:38 -08001448 IGP01E1000_PHY_PORT_CONFIG,
1449 &data);
1450 if (ret_val)
1451 goto out;
1452
1453 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001454 ret_val = phy->ops.write_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 } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
1461 (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
1462 (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
1463 data |= IGP02E1000_PM_D3_LPLU;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001464 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
Auke Kok9d5c8242008-01-24 02:22:38 -08001465 data);
1466 if (ret_val)
1467 goto out;
1468
1469 /* When LPLU is enabled, we should disable SmartSpeed */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001470 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001471 &data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001472 if (ret_val)
1473 goto out;
1474
1475 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001476 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001477 data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001478 }
1479
1480out:
1481 return ret_val;
1482}
1483
1484/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001485 * igb_check_downshift - Checks whether a downshift in speed occurred
Auke Kok9d5c8242008-01-24 02:22:38 -08001486 * @hw: pointer to the HW structure
1487 *
1488 * Success returns 0, Failure returns 1
1489 *
1490 * A downshift is detected by querying the PHY link health.
1491 **/
1492s32 igb_check_downshift(struct e1000_hw *hw)
1493{
1494 struct e1000_phy_info *phy = &hw->phy;
1495 s32 ret_val;
1496 u16 phy_data, offset, mask;
1497
1498 switch (phy->type) {
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001499 case e1000_phy_i210:
Auke Kok9d5c8242008-01-24 02:22:38 -08001500 case e1000_phy_m88:
1501 case e1000_phy_gg82563:
1502 offset = M88E1000_PHY_SPEC_STATUS;
1503 mask = M88E1000_PSSR_DOWNSHIFT;
1504 break;
1505 case e1000_phy_igp_2:
1506 case e1000_phy_igp:
1507 case e1000_phy_igp_3:
1508 offset = IGP01E1000_PHY_LINK_HEALTH;
1509 mask = IGP01E1000_PLHR_SS_DOWNGRADE;
1510 break;
1511 default:
1512 /* speed downshift not supported */
1513 phy->speed_downgraded = false;
1514 ret_val = 0;
1515 goto out;
1516 }
1517
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001518 ret_val = phy->ops.read_reg(hw, offset, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001519
1520 if (!ret_val)
1521 phy->speed_downgraded = (phy_data & mask) ? true : false;
1522
1523out:
1524 return ret_val;
1525}
1526
1527/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001528 * igb_check_polarity_m88 - Checks the polarity.
Auke Kok9d5c8242008-01-24 02:22:38 -08001529 * @hw: pointer to the HW structure
1530 *
1531 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1532 *
1533 * Polarity is determined based on the PHY specific status register.
1534 **/
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001535s32 igb_check_polarity_m88(struct e1000_hw *hw)
Auke Kok9d5c8242008-01-24 02:22:38 -08001536{
1537 struct e1000_phy_info *phy = &hw->phy;
1538 s32 ret_val;
1539 u16 data;
1540
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001541 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001542
1543 if (!ret_val)
1544 phy->cable_polarity = (data & M88E1000_PSSR_REV_POLARITY)
1545 ? e1000_rev_polarity_reversed
1546 : e1000_rev_polarity_normal;
1547
1548 return ret_val;
1549}
1550
1551/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001552 * igb_check_polarity_igp - Checks the polarity.
Auke Kok9d5c8242008-01-24 02:22:38 -08001553 * @hw: pointer to the HW structure
1554 *
1555 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1556 *
1557 * Polarity is determined based on the PHY port status register, and the
1558 * current speed (since there is no polarity at 100Mbps).
1559 **/
1560static s32 igb_check_polarity_igp(struct e1000_hw *hw)
1561{
1562 struct e1000_phy_info *phy = &hw->phy;
1563 s32 ret_val;
1564 u16 data, offset, mask;
1565
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001566 /* Polarity is determined based on the speed of
Auke Kok9d5c8242008-01-24 02:22:38 -08001567 * our connection.
1568 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001569 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_STATUS, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001570 if (ret_val)
1571 goto out;
1572
1573 if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
1574 IGP01E1000_PSSR_SPEED_1000MBPS) {
1575 offset = IGP01E1000_PHY_PCS_INIT_REG;
1576 mask = IGP01E1000_PHY_POLARITY_MASK;
1577 } else {
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001578 /* This really only applies to 10Mbps since
Auke Kok9d5c8242008-01-24 02:22:38 -08001579 * there is no polarity for 100Mbps (always 0).
1580 */
1581 offset = IGP01E1000_PHY_PORT_STATUS;
1582 mask = IGP01E1000_PSSR_POLARITY_REVERSED;
1583 }
1584
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001585 ret_val = phy->ops.read_reg(hw, offset, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001586
1587 if (!ret_val)
1588 phy->cable_polarity = (data & mask)
1589 ? e1000_rev_polarity_reversed
1590 : e1000_rev_polarity_normal;
1591
1592out:
1593 return ret_val;
1594}
1595
1596/**
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001597 * igb_wait_autoneg - Wait for auto-neg completion
Auke Kok9d5c8242008-01-24 02:22:38 -08001598 * @hw: pointer to the HW structure
1599 *
1600 * Waits for auto-negotiation to complete or for the auto-negotiation time
1601 * limit to expire, which ever happens first.
1602 **/
1603static s32 igb_wait_autoneg(struct e1000_hw *hw)
1604{
1605 s32 ret_val = 0;
1606 u16 i, phy_status;
1607
1608 /* Break after autoneg completes or PHY_AUTO_NEG_LIMIT expires. */
1609 for (i = PHY_AUTO_NEG_LIMIT; i > 0; i--) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001610 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
Auke Kok9d5c8242008-01-24 02:22:38 -08001611 if (ret_val)
1612 break;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001613 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
Auke Kok9d5c8242008-01-24 02:22:38 -08001614 if (ret_val)
1615 break;
1616 if (phy_status & MII_SR_AUTONEG_COMPLETE)
1617 break;
1618 msleep(100);
1619 }
1620
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001621 /* PHY_AUTO_NEG_TIME expiration doesn't guarantee auto-negotiation
Auke Kok9d5c8242008-01-24 02:22:38 -08001622 * has completed.
1623 */
1624 return ret_val;
1625}
1626
1627/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001628 * igb_phy_has_link - Polls PHY for link
Auke Kok9d5c8242008-01-24 02:22:38 -08001629 * @hw: pointer to the HW structure
1630 * @iterations: number of times to poll for link
1631 * @usec_interval: delay between polling attempts
1632 * @success: pointer to whether polling was successful or not
1633 *
1634 * Polls the PHY status register for link, 'iterations' number of times.
1635 **/
1636s32 igb_phy_has_link(struct e1000_hw *hw, u32 iterations,
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001637 u32 usec_interval, bool *success)
Auke Kok9d5c8242008-01-24 02:22:38 -08001638{
1639 s32 ret_val = 0;
1640 u16 i, phy_status;
1641
1642 for (i = 0; i < iterations; i++) {
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001643 /* Some PHYs require the PHY_STATUS register to be read
Auke Kok9d5c8242008-01-24 02:22:38 -08001644 * twice due to the link bit being sticky. No harm doing
1645 * it across the board.
1646 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001647 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
Andi Kleendc3d2262013-04-22 07:46:40 +00001648 if (ret_val && usec_interval > 0) {
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001649 /* If the first read fails, another entity may have
Alexander Duyckab576382009-10-05 06:35:23 +00001650 * ownership of the resources, wait and try again to
1651 * see if they have relinquished the resources yet.
1652 */
Carolyn Wybornydf29df92013-12-14 03:26:46 -08001653 if (usec_interval >= 1000)
1654 mdelay(usec_interval/1000);
1655 else
1656 udelay(usec_interval);
Alexander Duyckab576382009-10-05 06:35:23 +00001657 }
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001658 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
Auke Kok9d5c8242008-01-24 02:22:38 -08001659 if (ret_val)
1660 break;
1661 if (phy_status & MII_SR_LINK_STATUS)
1662 break;
1663 if (usec_interval >= 1000)
1664 mdelay(usec_interval/1000);
1665 else
1666 udelay(usec_interval);
1667 }
1668
1669 *success = (i < iterations) ? true : false;
1670
1671 return ret_val;
1672}
1673
1674/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001675 * igb_get_cable_length_m88 - Determine cable length for m88 PHY
Auke Kok9d5c8242008-01-24 02:22:38 -08001676 * @hw: pointer to the HW structure
1677 *
1678 * Reads the PHY specific status register to retrieve the cable length
1679 * information. The cable length is determined by averaging the minimum and
1680 * maximum values to get the "average" cable length. The m88 PHY has four
1681 * possible cable length values, which are:
1682 * Register Value Cable Length
1683 * 0 < 50 meters
1684 * 1 50 - 80 meters
1685 * 2 80 - 110 meters
1686 * 3 110 - 140 meters
1687 * 4 > 140 meters
1688 **/
1689s32 igb_get_cable_length_m88(struct e1000_hw *hw)
1690{
1691 struct e1000_phy_info *phy = &hw->phy;
1692 s32 ret_val;
1693 u16 phy_data, index;
1694
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001695 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001696 if (ret_val)
1697 goto out;
1698
1699 index = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
1700 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
Todd Fujinaka9fa04522015-06-30 15:16:55 -07001701 if (index >= ARRAY_SIZE(e1000_m88_cable_length_table) - 1) {
Alexander Duyck2553bb22009-10-05 06:35:42 +00001702 ret_val = -E1000_ERR_PHY;
1703 goto out;
1704 }
1705
Auke Kok9d5c8242008-01-24 02:22:38 -08001706 phy->min_cable_length = e1000_m88_cable_length_table[index];
Alexander Duyck2553bb22009-10-05 06:35:42 +00001707 phy->max_cable_length = e1000_m88_cable_length_table[index + 1];
Auke Kok9d5c8242008-01-24 02:22:38 -08001708
1709 phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
1710
1711out:
1712 return ret_val;
1713}
1714
Joseph Gasparakis308fb392010-09-22 17:56:44 +00001715s32 igb_get_cable_length_m88_gen2(struct e1000_hw *hw)
1716{
1717 struct e1000_phy_info *phy = &hw->phy;
1718 s32 ret_val;
1719 u16 phy_data, phy_data2, index, default_page, is_cm;
1720
1721 switch (hw->phy.id) {
Akeem G Abodunrin99af4722013-08-28 02:22:58 +00001722 case M88E1543_E_PHY_ID:
Todd Fujinaka51045ec2015-07-29 07:32:06 -07001723 case M88E1512_E_PHY_ID:
Joseph Gasparakis308fb392010-09-22 17:56:44 +00001724 case I347AT4_E_PHY_ID:
Aaron Sierra2a3cdea2015-11-03 12:37:09 -06001725 case I210_I_PHY_ID:
Joseph Gasparakis308fb392010-09-22 17:56:44 +00001726 /* Remember the original page select and set it to 7 */
1727 ret_val = phy->ops.read_reg(hw, I347AT4_PAGE_SELECT,
1728 &default_page);
1729 if (ret_val)
1730 goto out;
1731
1732 ret_val = phy->ops.write_reg(hw, I347AT4_PAGE_SELECT, 0x07);
1733 if (ret_val)
1734 goto out;
1735
1736 /* Get cable length from PHY Cable Diagnostics Control Reg */
Aaron Sierra06b0dd62015-11-03 12:37:18 -06001737 ret_val = phy->ops.read_reg(hw, I347AT4_PCDL, &phy_data);
Joseph Gasparakis308fb392010-09-22 17:56:44 +00001738 if (ret_val)
1739 goto out;
1740
1741 /* Check if the unit of cable length is meters or cm */
1742 ret_val = phy->ops.read_reg(hw, I347AT4_PCDC, &phy_data2);
1743 if (ret_val)
1744 goto out;
1745
Kantecki, Tomaszd5a0e362011-10-17 22:06:59 +00001746 is_cm = !(phy_data2 & I347AT4_PCDC_CABLE_LENGTH_UNIT);
Joseph Gasparakis308fb392010-09-22 17:56:44 +00001747
1748 /* Populate the phy structure with cable length in meters */
1749 phy->min_cable_length = phy_data / (is_cm ? 100 : 1);
1750 phy->max_cable_length = phy_data / (is_cm ? 100 : 1);
1751 phy->cable_length = phy_data / (is_cm ? 100 : 1);
1752
1753 /* Reset the page selec to its original value */
1754 ret_val = phy->ops.write_reg(hw, I347AT4_PAGE_SELECT,
1755 default_page);
1756 if (ret_val)
1757 goto out;
1758 break;
1759 case M88E1112_E_PHY_ID:
1760 /* Remember the original page select and set it to 5 */
1761 ret_val = phy->ops.read_reg(hw, I347AT4_PAGE_SELECT,
1762 &default_page);
1763 if (ret_val)
1764 goto out;
1765
1766 ret_val = phy->ops.write_reg(hw, I347AT4_PAGE_SELECT, 0x05);
1767 if (ret_val)
1768 goto out;
1769
1770 ret_val = phy->ops.read_reg(hw, M88E1112_VCT_DSP_DISTANCE,
1771 &phy_data);
1772 if (ret_val)
1773 goto out;
1774
1775 index = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
1776 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
Todd Fujinaka9fa04522015-06-30 15:16:55 -07001777 if (index >= ARRAY_SIZE(e1000_m88_cable_length_table) - 1) {
Joseph Gasparakis308fb392010-09-22 17:56:44 +00001778 ret_val = -E1000_ERR_PHY;
1779 goto out;
1780 }
1781
1782 phy->min_cable_length = e1000_m88_cable_length_table[index];
1783 phy->max_cable_length = e1000_m88_cable_length_table[index + 1];
1784
1785 phy->cable_length = (phy->min_cable_length +
1786 phy->max_cable_length) / 2;
1787
1788 /* Reset the page select to its original value */
1789 ret_val = phy->ops.write_reg(hw, I347AT4_PAGE_SELECT,
1790 default_page);
1791 if (ret_val)
1792 goto out;
1793
1794 break;
1795 default:
1796 ret_val = -E1000_ERR_PHY;
1797 goto out;
1798 }
1799
1800out:
1801 return ret_val;
1802}
1803
Auke Kok9d5c8242008-01-24 02:22:38 -08001804/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001805 * igb_get_cable_length_igp_2 - Determine cable length for igp2 PHY
Auke Kok9d5c8242008-01-24 02:22:38 -08001806 * @hw: pointer to the HW structure
1807 *
1808 * The automatic gain control (agc) normalizes the amplitude of the
1809 * received signal, adjusting for the attenuation produced by the
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001810 * cable. By reading the AGC registers, which represent the
1811 * combination of coarse and fine gain value, the value can be put
Auke Kok9d5c8242008-01-24 02:22:38 -08001812 * into a lookup table to obtain the approximate cable length
1813 * for each channel.
1814 **/
1815s32 igb_get_cable_length_igp_2(struct e1000_hw *hw)
1816{
1817 struct e1000_phy_info *phy = &hw->phy;
1818 s32 ret_val = 0;
1819 u16 phy_data, i, agc_value = 0;
1820 u16 cur_agc_index, max_agc_index = 0;
Todd Fujinaka9fa04522015-06-30 15:16:55 -07001821 u16 min_agc_index = ARRAY_SIZE(e1000_igp_2_cable_length_table) - 1;
Jeff Kirsher66744502010-12-01 19:59:50 +00001822 static const u16 agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] = {
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001823 IGP02E1000_PHY_AGC_A,
1824 IGP02E1000_PHY_AGC_B,
1825 IGP02E1000_PHY_AGC_C,
1826 IGP02E1000_PHY_AGC_D
Jeff Kirsher66744502010-12-01 19:59:50 +00001827 };
Auke Kok9d5c8242008-01-24 02:22:38 -08001828
1829 /* Read the AGC registers for all channels */
1830 for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001831 ret_val = phy->ops.read_reg(hw, agc_reg_array[i], &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001832 if (ret_val)
1833 goto out;
1834
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001835 /* Getting bits 15:9, which represent the combination of
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001836 * coarse and fine gain values. The result is a number
Auke Kok9d5c8242008-01-24 02:22:38 -08001837 * that can be put into the lookup table to obtain the
1838 * approximate cable length.
1839 */
1840 cur_agc_index = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
1841 IGP02E1000_AGC_LENGTH_MASK;
1842
1843 /* Array index bound check. */
Todd Fujinaka9fa04522015-06-30 15:16:55 -07001844 if ((cur_agc_index >= ARRAY_SIZE(e1000_igp_2_cable_length_table)) ||
Auke Kok9d5c8242008-01-24 02:22:38 -08001845 (cur_agc_index == 0)) {
1846 ret_val = -E1000_ERR_PHY;
1847 goto out;
1848 }
1849
1850 /* Remove min & max AGC values from calculation. */
1851 if (e1000_igp_2_cable_length_table[min_agc_index] >
1852 e1000_igp_2_cable_length_table[cur_agc_index])
1853 min_agc_index = cur_agc_index;
1854 if (e1000_igp_2_cable_length_table[max_agc_index] <
1855 e1000_igp_2_cable_length_table[cur_agc_index])
1856 max_agc_index = cur_agc_index;
1857
1858 agc_value += e1000_igp_2_cable_length_table[cur_agc_index];
1859 }
1860
1861 agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] +
1862 e1000_igp_2_cable_length_table[max_agc_index]);
1863 agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
1864
1865 /* Calculate cable length with the error range of +/- 10 meters. */
1866 phy->min_cable_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
1867 (agc_value - IGP02E1000_AGC_RANGE) : 0;
1868 phy->max_cable_length = agc_value + IGP02E1000_AGC_RANGE;
1869
1870 phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
1871
1872out:
1873 return ret_val;
1874}
1875
1876/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001877 * igb_get_phy_info_m88 - Retrieve PHY information
Auke Kok9d5c8242008-01-24 02:22:38 -08001878 * @hw: pointer to the HW structure
1879 *
1880 * Valid for only copper links. Read the PHY status register (sticky read)
1881 * to verify that link is up. Read the PHY special control register to
1882 * determine the polarity and 10base-T extended distance. Read the PHY
1883 * special status register to determine MDI/MDIx and current speed. If
1884 * speed is 1000, then determine cable length, local and remote receiver.
1885 **/
1886s32 igb_get_phy_info_m88(struct e1000_hw *hw)
1887{
1888 struct e1000_phy_info *phy = &hw->phy;
1889 s32 ret_val;
1890 u16 phy_data;
1891 bool link;
1892
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001893 if (phy->media_type != e1000_media_type_copper) {
Auke Kok652fff32008-06-27 11:00:18 -07001894 hw_dbg("Phy info is only valid for copper media\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001895 ret_val = -E1000_ERR_CONFIG;
1896 goto out;
1897 }
1898
1899 ret_val = igb_phy_has_link(hw, 1, 0, &link);
1900 if (ret_val)
1901 goto out;
1902
1903 if (!link) {
Auke Kok652fff32008-06-27 11:00:18 -07001904 hw_dbg("Phy info is only valid if link is up\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001905 ret_val = -E1000_ERR_CONFIG;
1906 goto out;
1907 }
1908
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001909 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001910 if (ret_val)
1911 goto out;
1912
1913 phy->polarity_correction = (phy_data & M88E1000_PSCR_POLARITY_REVERSAL)
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001914 ? true : false;
Auke Kok9d5c8242008-01-24 02:22:38 -08001915
1916 ret_val = igb_check_polarity_m88(hw);
1917 if (ret_val)
1918 goto out;
1919
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001920 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001921 if (ret_val)
1922 goto out;
1923
1924 phy->is_mdix = (phy_data & M88E1000_PSSR_MDIX) ? true : false;
1925
1926 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001927 ret_val = phy->ops.get_cable_length(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001928 if (ret_val)
1929 goto out;
1930
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001931 ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001932 if (ret_val)
1933 goto out;
1934
1935 phy->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS)
1936 ? e1000_1000t_rx_status_ok
1937 : e1000_1000t_rx_status_not_ok;
1938
1939 phy->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS)
1940 ? e1000_1000t_rx_status_ok
1941 : e1000_1000t_rx_status_not_ok;
1942 } else {
1943 /* Set values to "undefined" */
1944 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
1945 phy->local_rx = e1000_1000t_rx_status_undefined;
1946 phy->remote_rx = e1000_1000t_rx_status_undefined;
1947 }
1948
1949out:
1950 return ret_val;
1951}
1952
1953/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001954 * igb_get_phy_info_igp - Retrieve igp PHY information
Auke Kok9d5c8242008-01-24 02:22:38 -08001955 * @hw: pointer to the HW structure
1956 *
1957 * Read PHY status to determine if link is up. If link is up, then
1958 * set/determine 10base-T extended distance and polarity correction. Read
1959 * PHY port status to determine MDI/MDIx and speed. Based on the speed,
1960 * determine on the cable length, local and remote receiver.
1961 **/
1962s32 igb_get_phy_info_igp(struct e1000_hw *hw)
1963{
1964 struct e1000_phy_info *phy = &hw->phy;
1965 s32 ret_val;
1966 u16 data;
1967 bool link;
1968
1969 ret_val = igb_phy_has_link(hw, 1, 0, &link);
1970 if (ret_val)
1971 goto out;
1972
1973 if (!link) {
Auke Kok652fff32008-06-27 11:00:18 -07001974 hw_dbg("Phy info is only valid if link is up\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001975 ret_val = -E1000_ERR_CONFIG;
1976 goto out;
1977 }
1978
1979 phy->polarity_correction = true;
1980
1981 ret_val = igb_check_polarity_igp(hw);
1982 if (ret_val)
1983 goto out;
1984
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001985 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_STATUS, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001986 if (ret_val)
1987 goto out;
1988
1989 phy->is_mdix = (data & IGP01E1000_PSSR_MDIX) ? true : false;
1990
1991 if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
1992 IGP01E1000_PSSR_SPEED_1000MBPS) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001993 ret_val = phy->ops.get_cable_length(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001994 if (ret_val)
1995 goto out;
1996
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001997 ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001998 if (ret_val)
1999 goto out;
2000
2001 phy->local_rx = (data & SR_1000T_LOCAL_RX_STATUS)
2002 ? e1000_1000t_rx_status_ok
2003 : e1000_1000t_rx_status_not_ok;
2004
2005 phy->remote_rx = (data & SR_1000T_REMOTE_RX_STATUS)
2006 ? e1000_1000t_rx_status_ok
2007 : e1000_1000t_rx_status_not_ok;
2008 } else {
2009 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
2010 phy->local_rx = e1000_1000t_rx_status_undefined;
2011 phy->remote_rx = e1000_1000t_rx_status_undefined;
2012 }
2013
2014out:
2015 return ret_val;
2016}
2017
2018/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07002019 * igb_phy_sw_reset - PHY software reset
Auke Kok9d5c8242008-01-24 02:22:38 -08002020 * @hw: pointer to the HW structure
2021 *
2022 * Does a software reset of the PHY by reading the PHY control register and
2023 * setting/write the control register reset bit to the PHY.
2024 **/
2025s32 igb_phy_sw_reset(struct e1000_hw *hw)
2026{
Alexander Duyckd3147372009-09-14 08:23:13 +00002027 s32 ret_val = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08002028 u16 phy_ctrl;
2029
Alexander Duyckd3147372009-09-14 08:23:13 +00002030 if (!(hw->phy.ops.read_reg))
2031 goto out;
2032
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002033 ret_val = hw->phy.ops.read_reg(hw, PHY_CONTROL, &phy_ctrl);
Auke Kok9d5c8242008-01-24 02:22:38 -08002034 if (ret_val)
2035 goto out;
2036
2037 phy_ctrl |= MII_CR_RESET;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002038 ret_val = hw->phy.ops.write_reg(hw, PHY_CONTROL, phy_ctrl);
Auke Kok9d5c8242008-01-24 02:22:38 -08002039 if (ret_val)
2040 goto out;
2041
2042 udelay(1);
2043
2044out:
2045 return ret_val;
2046}
2047
2048/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07002049 * igb_phy_hw_reset - PHY hardware reset
Auke Kok9d5c8242008-01-24 02:22:38 -08002050 * @hw: pointer to the HW structure
2051 *
2052 * Verify the reset block is not blocking us from resetting. Acquire
2053 * semaphore (if necessary) and read/set/write the device control reset
2054 * bit in the PHY. Wait the appropriate delay time for the device to
Geert Uytterhoeven83a35e32013-06-28 11:27:31 +02002055 * reset and release the semaphore (if necessary).
Auke Kok9d5c8242008-01-24 02:22:38 -08002056 **/
2057s32 igb_phy_hw_reset(struct e1000_hw *hw)
2058{
2059 struct e1000_phy_info *phy = &hw->phy;
2060 s32 ret_val;
2061 u32 ctrl;
2062
2063 ret_val = igb_check_reset_block(hw);
2064 if (ret_val) {
2065 ret_val = 0;
2066 goto out;
2067 }
2068
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002069 ret_val = phy->ops.acquire(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08002070 if (ret_val)
2071 goto out;
2072
2073 ctrl = rd32(E1000_CTRL);
2074 wr32(E1000_CTRL, ctrl | E1000_CTRL_PHY_RST);
2075 wrfl();
2076
2077 udelay(phy->reset_delay_us);
2078
2079 wr32(E1000_CTRL, ctrl);
2080 wrfl();
2081
2082 udelay(150);
2083
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002084 phy->ops.release(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08002085
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002086 ret_val = phy->ops.get_cfg_done(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08002087
2088out:
2089 return ret_val;
2090}
2091
Auke Kok9d5c8242008-01-24 02:22:38 -08002092/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07002093 * igb_phy_init_script_igp3 - Inits the IGP3 PHY
Auke Kok9d5c8242008-01-24 02:22:38 -08002094 * @hw: pointer to the HW structure
2095 *
2096 * Initializes a Intel Gigabit PHY3 when an EEPROM is not present.
2097 **/
2098s32 igb_phy_init_script_igp3(struct e1000_hw *hw)
2099{
Auke Kok652fff32008-06-27 11:00:18 -07002100 hw_dbg("Running IGP 3 PHY init script\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08002101
2102 /* PHY init IGP 3 */
2103 /* Enable rise/fall, 10-mode work in class-A */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002104 hw->phy.ops.write_reg(hw, 0x2F5B, 0x9018);
Auke Kok9d5c8242008-01-24 02:22:38 -08002105 /* Remove all caps from Replica path filter */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002106 hw->phy.ops.write_reg(hw, 0x2F52, 0x0000);
Auke Kok9d5c8242008-01-24 02:22:38 -08002107 /* Bias trimming for ADC, AFE and Driver (Default) */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002108 hw->phy.ops.write_reg(hw, 0x2FB1, 0x8B24);
Auke Kok9d5c8242008-01-24 02:22:38 -08002109 /* Increase Hybrid poly bias */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002110 hw->phy.ops.write_reg(hw, 0x2FB2, 0xF8F0);
Auke Kok9d5c8242008-01-24 02:22:38 -08002111 /* Add 4% to TX amplitude in Giga mode */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002112 hw->phy.ops.write_reg(hw, 0x2010, 0x10B0);
Auke Kok9d5c8242008-01-24 02:22:38 -08002113 /* Disable trimming (TTT) */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002114 hw->phy.ops.write_reg(hw, 0x2011, 0x0000);
Auke Kok9d5c8242008-01-24 02:22:38 -08002115 /* Poly DC correction to 94.6% + 2% for all channels */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002116 hw->phy.ops.write_reg(hw, 0x20DD, 0x249A);
Auke Kok9d5c8242008-01-24 02:22:38 -08002117 /* ABS DC correction to 95.9% */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002118 hw->phy.ops.write_reg(hw, 0x20DE, 0x00D3);
Auke Kok9d5c8242008-01-24 02:22:38 -08002119 /* BG temp curve trim */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002120 hw->phy.ops.write_reg(hw, 0x28B4, 0x04CE);
Auke Kok9d5c8242008-01-24 02:22:38 -08002121 /* Increasing ADC OPAMP stage 1 currents to max */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002122 hw->phy.ops.write_reg(hw, 0x2F70, 0x29E4);
Auke Kok9d5c8242008-01-24 02:22:38 -08002123 /* Force 1000 ( required for enabling PHY regs configuration) */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002124 hw->phy.ops.write_reg(hw, 0x0000, 0x0140);
Auke Kok9d5c8242008-01-24 02:22:38 -08002125 /* Set upd_freq to 6 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002126 hw->phy.ops.write_reg(hw, 0x1F30, 0x1606);
Auke Kok9d5c8242008-01-24 02:22:38 -08002127 /* Disable NPDFE */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002128 hw->phy.ops.write_reg(hw, 0x1F31, 0xB814);
Auke Kok9d5c8242008-01-24 02:22:38 -08002129 /* Disable adaptive fixed FFE (Default) */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002130 hw->phy.ops.write_reg(hw, 0x1F35, 0x002A);
Auke Kok9d5c8242008-01-24 02:22:38 -08002131 /* Enable FFE hysteresis */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002132 hw->phy.ops.write_reg(hw, 0x1F3E, 0x0067);
Auke Kok9d5c8242008-01-24 02:22:38 -08002133 /* Fixed FFE for short cable lengths */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002134 hw->phy.ops.write_reg(hw, 0x1F54, 0x0065);
Auke Kok9d5c8242008-01-24 02:22:38 -08002135 /* Fixed FFE for medium cable lengths */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002136 hw->phy.ops.write_reg(hw, 0x1F55, 0x002A);
Auke Kok9d5c8242008-01-24 02:22:38 -08002137 /* Fixed FFE for long cable lengths */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002138 hw->phy.ops.write_reg(hw, 0x1F56, 0x002A);
Auke Kok9d5c8242008-01-24 02:22:38 -08002139 /* Enable Adaptive Clip Threshold */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002140 hw->phy.ops.write_reg(hw, 0x1F72, 0x3FB0);
Auke Kok9d5c8242008-01-24 02:22:38 -08002141 /* AHT reset limit to 1 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002142 hw->phy.ops.write_reg(hw, 0x1F76, 0xC0FF);
Auke Kok9d5c8242008-01-24 02:22:38 -08002143 /* Set AHT master delay to 127 msec */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002144 hw->phy.ops.write_reg(hw, 0x1F77, 0x1DEC);
Auke Kok9d5c8242008-01-24 02:22:38 -08002145 /* Set scan bits for AHT */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002146 hw->phy.ops.write_reg(hw, 0x1F78, 0xF9EF);
Auke Kok9d5c8242008-01-24 02:22:38 -08002147 /* Set AHT Preset bits */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002148 hw->phy.ops.write_reg(hw, 0x1F79, 0x0210);
Auke Kok9d5c8242008-01-24 02:22:38 -08002149 /* Change integ_factor of channel A to 3 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002150 hw->phy.ops.write_reg(hw, 0x1895, 0x0003);
Auke Kok9d5c8242008-01-24 02:22:38 -08002151 /* Change prop_factor of channels BCD to 8 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002152 hw->phy.ops.write_reg(hw, 0x1796, 0x0008);
Auke Kok9d5c8242008-01-24 02:22:38 -08002153 /* Change cg_icount + enable integbp for channels BCD */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002154 hw->phy.ops.write_reg(hw, 0x1798, 0xD008);
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002155 /* Change cg_icount + enable integbp + change prop_factor_master
Auke Kok9d5c8242008-01-24 02:22:38 -08002156 * to 8 for channel A
2157 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002158 hw->phy.ops.write_reg(hw, 0x1898, 0xD918);
Auke Kok9d5c8242008-01-24 02:22:38 -08002159 /* Disable AHT in Slave mode on channel A */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002160 hw->phy.ops.write_reg(hw, 0x187A, 0x0800);
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002161 /* Enable LPLU and disable AN to 1000 in non-D0a states,
Auke Kok9d5c8242008-01-24 02:22:38 -08002162 * Enable SPD+B2B
2163 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002164 hw->phy.ops.write_reg(hw, 0x0019, 0x008D);
Auke Kok9d5c8242008-01-24 02:22:38 -08002165 /* Enable restart AN on an1000_dis change */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002166 hw->phy.ops.write_reg(hw, 0x001B, 0x2080);
Auke Kok9d5c8242008-01-24 02:22:38 -08002167 /* Enable wh_fifo read clock in 10/100 modes */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002168 hw->phy.ops.write_reg(hw, 0x0014, 0x0045);
Auke Kok9d5c8242008-01-24 02:22:38 -08002169 /* Restart AN, Speed selection is 1000 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00002170 hw->phy.ops.write_reg(hw, 0x0000, 0x1340);
Auke Kok9d5c8242008-01-24 02:22:38 -08002171
2172 return 0;
2173}
2174
Alexander Duyck2909c3f2009-11-19 12:41:42 +00002175/**
Todd Fujinaka51045ec2015-07-29 07:32:06 -07002176 * igb_initialize_M88E1512_phy - Initialize M88E1512 PHY
2177 * @hw: pointer to the HW structure
2178 *
2179 * Initialize Marvel 1512 to work correctly with Avoton.
2180 **/
2181s32 igb_initialize_M88E1512_phy(struct e1000_hw *hw)
2182{
2183 struct e1000_phy_info *phy = &hw->phy;
2184 s32 ret_val = 0;
2185
2186 /* Switch to PHY page 0xFF. */
2187 ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 0x00FF);
2188 if (ret_val)
2189 goto out;
2190
2191 ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_2, 0x214B);
2192 if (ret_val)
2193 goto out;
2194
2195 ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_1, 0x2144);
2196 if (ret_val)
2197 goto out;
2198
2199 ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_2, 0x0C28);
2200 if (ret_val)
2201 goto out;
2202
2203 ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_1, 0x2146);
2204 if (ret_val)
2205 goto out;
2206
2207 ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_2, 0xB233);
2208 if (ret_val)
2209 goto out;
2210
2211 ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_1, 0x214D);
2212 if (ret_val)
2213 goto out;
2214
2215 ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_2, 0xCC0C);
2216 if (ret_val)
2217 goto out;
2218
2219 ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_1, 0x2159);
2220 if (ret_val)
2221 goto out;
2222
2223 /* Switch to PHY page 0xFB. */
2224 ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 0x00FB);
2225 if (ret_val)
2226 goto out;
2227
2228 ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_3, 0x000D);
2229 if (ret_val)
2230 goto out;
2231
2232 /* Switch to PHY page 0x12. */
2233 ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 0x12);
2234 if (ret_val)
2235 goto out;
2236
2237 /* Change mode to SGMII-to-Copper */
2238 ret_val = phy->ops.write_reg(hw, E1000_M88E1512_MODE, 0x8001);
2239 if (ret_val)
2240 goto out;
2241
2242 /* Return the PHY to page 0. */
2243 ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 0);
2244 if (ret_val)
2245 goto out;
2246
2247 ret_val = igb_phy_sw_reset(hw);
2248 if (ret_val) {
2249 hw_dbg("Error committing the PHY changes\n");
2250 return ret_val;
2251 }
2252
2253 /* msec_delay(1000); */
2254 usleep_range(1000, 2000);
2255out:
2256 return ret_val;
2257}
2258
2259/**
Todd Fujinaka18f7ce52015-09-02 16:54:20 -07002260 * igb_initialize_M88E1543_phy - Initialize M88E1512 PHY
2261 * @hw: pointer to the HW structure
2262 *
2263 * Initialize Marvell 1543 to work correctly with Avoton.
2264 **/
2265s32 igb_initialize_M88E1543_phy(struct e1000_hw *hw)
2266{
2267 struct e1000_phy_info *phy = &hw->phy;
2268 s32 ret_val = 0;
2269
2270 /* Switch to PHY page 0xFF. */
2271 ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 0x00FF);
2272 if (ret_val)
2273 goto out;
2274
2275 ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_2, 0x214B);
2276 if (ret_val)
2277 goto out;
2278
2279 ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_1, 0x2144);
2280 if (ret_val)
2281 goto out;
2282
2283 ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_2, 0x0C28);
2284 if (ret_val)
2285 goto out;
2286
2287 ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_1, 0x2146);
2288 if (ret_val)
2289 goto out;
2290
2291 ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_2, 0xB233);
2292 if (ret_val)
2293 goto out;
2294
2295 ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_1, 0x214D);
2296 if (ret_val)
2297 goto out;
2298
2299 ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_2, 0xDC0C);
2300 if (ret_val)
2301 goto out;
2302
2303 ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_1, 0x2159);
2304 if (ret_val)
2305 goto out;
2306
2307 /* Switch to PHY page 0xFB. */
2308 ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 0x00FB);
2309 if (ret_val)
2310 goto out;
2311
2312 ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_3, 0x0C0D);
2313 if (ret_val)
2314 goto out;
2315
2316 /* Switch to PHY page 0x12. */
2317 ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 0x12);
2318 if (ret_val)
2319 goto out;
2320
2321 /* Change mode to SGMII-to-Copper */
2322 ret_val = phy->ops.write_reg(hw, E1000_M88E1512_MODE, 0x8001);
2323 if (ret_val)
2324 goto out;
2325
2326 /* Switch to PHY page 1. */
2327 ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 0x1);
2328 if (ret_val)
2329 goto out;
2330
2331 /* Change mode to 1000BASE-X/SGMII and autoneg enable */
2332 ret_val = phy->ops.write_reg(hw, E1000_M88E1543_FIBER_CTRL, 0x9140);
2333 if (ret_val)
2334 goto out;
2335
2336 /* Return the PHY to page 0. */
2337 ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 0);
2338 if (ret_val)
2339 goto out;
2340
2341 ret_val = igb_phy_sw_reset(hw);
2342 if (ret_val) {
2343 hw_dbg("Error committing the PHY changes\n");
2344 return ret_val;
2345 }
2346
2347 /* msec_delay(1000); */
2348 usleep_range(1000, 2000);
2349out:
2350 return ret_val;
2351}
2352
2353/**
Nick Nunley88a268c2010-02-17 01:01:59 +00002354 * igb_power_up_phy_copper - Restore copper link in case of PHY power down
2355 * @hw: pointer to the HW structure
2356 *
2357 * In the case of a PHY power down to save power, or to turn off link during a
2358 * driver unload, restore the link to previous settings.
2359 **/
2360void igb_power_up_phy_copper(struct e1000_hw *hw)
2361{
2362 u16 mii_reg = 0;
2363
2364 /* The PHY will retain its settings across a power down/up cycle */
2365 hw->phy.ops.read_reg(hw, PHY_CONTROL, &mii_reg);
2366 mii_reg &= ~MII_CR_POWER_DOWN;
2367 hw->phy.ops.write_reg(hw, PHY_CONTROL, mii_reg);
2368}
2369
2370/**
2371 * igb_power_down_phy_copper - Power down copper PHY
2372 * @hw: pointer to the HW structure
2373 *
2374 * Power down PHY to save power when interface is down and wake on lan
2375 * is not enabled.
2376 **/
2377void igb_power_down_phy_copper(struct e1000_hw *hw)
2378{
2379 u16 mii_reg = 0;
2380
2381 /* The PHY will retain its settings across a power down/up cycle */
2382 hw->phy.ops.read_reg(hw, PHY_CONTROL, &mii_reg);
2383 mii_reg |= MII_CR_POWER_DOWN;
2384 hw->phy.ops.write_reg(hw, PHY_CONTROL, mii_reg);
Carolyn Wyborny0d451e72014-04-11 01:46:40 +00002385 usleep_range(1000, 2000);
Nick Nunley88a268c2010-02-17 01:01:59 +00002386}
2387
2388/**
Alexander Duyck2909c3f2009-11-19 12:41:42 +00002389 * igb_check_polarity_82580 - Checks the polarity.
2390 * @hw: pointer to the HW structure
2391 *
2392 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
2393 *
2394 * Polarity is determined based on the PHY specific status register.
2395 **/
Alexander Duyckbb2ac472009-11-19 12:42:01 +00002396static s32 igb_check_polarity_82580(struct e1000_hw *hw)
Alexander Duyck2909c3f2009-11-19 12:41:42 +00002397{
2398 struct e1000_phy_info *phy = &hw->phy;
2399 s32 ret_val;
2400 u16 data;
2401
2402
2403 ret_val = phy->ops.read_reg(hw, I82580_PHY_STATUS_2, &data);
2404
2405 if (!ret_val)
2406 phy->cable_polarity = (data & I82580_PHY_STATUS2_REV_POLARITY)
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002407 ? e1000_rev_polarity_reversed
2408 : e1000_rev_polarity_normal;
Alexander Duyck2909c3f2009-11-19 12:41:42 +00002409
2410 return ret_val;
2411}
2412
2413/**
2414 * igb_phy_force_speed_duplex_82580 - Force speed/duplex for I82580 PHY
2415 * @hw: pointer to the HW structure
2416 *
2417 * Calls the PHY setup function to force speed and duplex. Clears the
2418 * auto-crossover to force MDI manually. Waits for link and returns
2419 * successful if link up is successful, else -E1000_ERR_PHY (-2).
2420 **/
2421s32 igb_phy_force_speed_duplex_82580(struct e1000_hw *hw)
2422{
2423 struct e1000_phy_info *phy = &hw->phy;
2424 s32 ret_val;
2425 u16 phy_data;
2426 bool link;
2427
Alexander Duyck2909c3f2009-11-19 12:41:42 +00002428 ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data);
2429 if (ret_val)
2430 goto out;
2431
2432 igb_phy_force_speed_duplex_setup(hw, &phy_data);
2433
2434 ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data);
2435 if (ret_val)
2436 goto out;
2437
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002438 /* Clear Auto-Crossover to force MDI manually. 82580 requires MDI
Alexander Duyck2909c3f2009-11-19 12:41:42 +00002439 * forced whenever speed and duplex are forced.
2440 */
2441 ret_val = phy->ops.read_reg(hw, I82580_PHY_CTRL_2, &phy_data);
2442 if (ret_val)
2443 goto out;
2444
Jesse Brandeburg1b556782012-07-26 02:31:04 +00002445 phy_data &= ~I82580_PHY_CTRL2_MDIX_CFG_MASK;
Alexander Duyck2909c3f2009-11-19 12:41:42 +00002446
2447 ret_val = phy->ops.write_reg(hw, I82580_PHY_CTRL_2, phy_data);
2448 if (ret_val)
2449 goto out;
2450
2451 hw_dbg("I82580_PHY_CTRL_2: %X\n", phy_data);
2452
2453 udelay(1);
2454
2455 if (phy->autoneg_wait_to_complete) {
2456 hw_dbg("Waiting for forced speed/duplex link on 82580 phy\n");
2457
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002458 ret_val = igb_phy_has_link(hw, PHY_FORCE_LIMIT, 100000, &link);
Alexander Duyck2909c3f2009-11-19 12:41:42 +00002459 if (ret_val)
2460 goto out;
2461
2462 if (!link)
2463 hw_dbg("Link taking longer than expected.\n");
2464
2465 /* Try once more */
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002466 ret_val = igb_phy_has_link(hw, PHY_FORCE_LIMIT, 100000, &link);
Alexander Duyck2909c3f2009-11-19 12:41:42 +00002467 if (ret_val)
2468 goto out;
2469 }
2470
2471out:
2472 return ret_val;
2473}
2474
2475/**
2476 * igb_get_phy_info_82580 - Retrieve I82580 PHY information
2477 * @hw: pointer to the HW structure
2478 *
2479 * Read PHY status to determine if link is up. If link is up, then
2480 * set/determine 10base-T extended distance and polarity correction. Read
2481 * PHY port status to determine MDI/MDIx and speed. Based on the speed,
2482 * determine on the cable length, local and remote receiver.
2483 **/
2484s32 igb_get_phy_info_82580(struct e1000_hw *hw)
2485{
2486 struct e1000_phy_info *phy = &hw->phy;
2487 s32 ret_val;
2488 u16 data;
2489 bool link;
2490
Alexander Duyck2909c3f2009-11-19 12:41:42 +00002491 ret_val = igb_phy_has_link(hw, 1, 0, &link);
2492 if (ret_val)
2493 goto out;
2494
2495 if (!link) {
2496 hw_dbg("Phy info is only valid if link is up\n");
2497 ret_val = -E1000_ERR_CONFIG;
2498 goto out;
2499 }
2500
2501 phy->polarity_correction = true;
2502
2503 ret_val = igb_check_polarity_82580(hw);
2504 if (ret_val)
2505 goto out;
2506
2507 ret_val = phy->ops.read_reg(hw, I82580_PHY_STATUS_2, &data);
2508 if (ret_val)
2509 goto out;
2510
2511 phy->is_mdix = (data & I82580_PHY_STATUS2_MDIX) ? true : false;
2512
2513 if ((data & I82580_PHY_STATUS2_SPEED_MASK) ==
2514 I82580_PHY_STATUS2_SPEED_1000MBPS) {
2515 ret_val = hw->phy.ops.get_cable_length(hw);
2516 if (ret_val)
2517 goto out;
2518
2519 ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &data);
2520 if (ret_val)
2521 goto out;
2522
2523 phy->local_rx = (data & SR_1000T_LOCAL_RX_STATUS)
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002524 ? e1000_1000t_rx_status_ok
2525 : e1000_1000t_rx_status_not_ok;
Alexander Duyck2909c3f2009-11-19 12:41:42 +00002526
2527 phy->remote_rx = (data & SR_1000T_REMOTE_RX_STATUS)
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002528 ? e1000_1000t_rx_status_ok
2529 : e1000_1000t_rx_status_not_ok;
Alexander Duyck2909c3f2009-11-19 12:41:42 +00002530 } else {
2531 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
2532 phy->local_rx = e1000_1000t_rx_status_undefined;
2533 phy->remote_rx = e1000_1000t_rx_status_undefined;
2534 }
2535
2536out:
2537 return ret_val;
2538}
2539
2540/**
2541 * igb_get_cable_length_82580 - Determine cable length for 82580 PHY
2542 * @hw: pointer to the HW structure
2543 *
2544 * Reads the diagnostic status register and verifies result is valid before
2545 * placing it in the phy_cable_length field.
2546 **/
2547s32 igb_get_cable_length_82580(struct e1000_hw *hw)
2548{
2549 struct e1000_phy_info *phy = &hw->phy;
2550 s32 ret_val;
2551 u16 phy_data, length;
2552
Alexander Duyck2909c3f2009-11-19 12:41:42 +00002553 ret_val = phy->ops.read_reg(hw, I82580_PHY_DIAG_STATUS, &phy_data);
2554 if (ret_val)
2555 goto out;
2556
2557 length = (phy_data & I82580_DSTATUS_CABLE_LENGTH) >>
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002558 I82580_DSTATUS_CABLE_LENGTH_SHIFT;
Alexander Duyck2909c3f2009-11-19 12:41:42 +00002559
2560 if (length == E1000_CABLE_LENGTH_UNDEFINED)
2561 ret_val = -E1000_ERR_PHY;
2562
2563 phy->cable_length = length;
2564
2565out:
2566 return ret_val;
2567}
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00002568
2569/**
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00002570 * igb_set_master_slave_mode - Setup PHY for Master/slave mode
2571 * @hw: pointer to the HW structure
2572 *
2573 * Sets up Master/slave mode
2574 **/
2575static s32 igb_set_master_slave_mode(struct e1000_hw *hw)
2576{
2577 s32 ret_val;
2578 u16 phy_data;
2579
2580 /* Resolve Master/Slave mode */
2581 ret_val = hw->phy.ops.read_reg(hw, PHY_1000T_CTRL, &phy_data);
2582 if (ret_val)
2583 return ret_val;
2584
2585 /* load defaults for future use */
2586 hw->phy.original_ms_type = (phy_data & CR_1000T_MS_ENABLE) ?
2587 ((phy_data & CR_1000T_MS_VALUE) ?
2588 e1000_ms_force_master :
2589 e1000_ms_force_slave) : e1000_ms_auto;
2590
2591 switch (hw->phy.ms_type) {
2592 case e1000_ms_force_master:
2593 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
2594 break;
2595 case e1000_ms_force_slave:
2596 phy_data |= CR_1000T_MS_ENABLE;
2597 phy_data &= ~(CR_1000T_MS_VALUE);
2598 break;
2599 case e1000_ms_auto:
2600 phy_data &= ~CR_1000T_MS_ENABLE;
2601 /* fall-through */
2602 default:
2603 break;
2604 }
2605
2606 return hw->phy.ops.write_reg(hw, PHY_1000T_CTRL, phy_data);
2607}