blob: f9d33ab05e97814de596a538a73aa3d975e44763 [file] [log] [blame]
Auke Kokbc7f75f2007-09-17 12:30:59 -07001/*******************************************************************************
2
3 Intel PRO/1000 Linux driver
Bruce Allanad680762008-03-28 09:15:03 -07004 Copyright(c) 1999 - 2008 Intel Corporation.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
14
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Contact Information:
23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26
27*******************************************************************************/
28
29#include <linux/delay.h>
30
31#include "e1000.h"
32
33static s32 e1000_get_phy_cfg_done(struct e1000_hw *hw);
34static s32 e1000_phy_force_speed_duplex(struct e1000_hw *hw);
35static s32 e1000_set_d0_lplu_state(struct e1000_hw *hw, bool active);
36static s32 e1000_wait_autoneg(struct e1000_hw *hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -070037static u32 e1000_get_phy_addr_for_bm_page(u32 page, u32 reg);
38static s32 e1000_access_phy_wakeup_reg_bm(struct e1000_hw *hw, u32 offset,
39 u16 *data, bool read);
Bruce Allana4f58f52009-06-02 11:29:18 +000040static u32 e1000_get_phy_addr_for_hv_page(u32 page);
41static s32 e1000_access_phy_debug_regs_hv(struct e1000_hw *hw, u32 offset,
42 u16 *data, bool read);
Auke Kokbc7f75f2007-09-17 12:30:59 -070043
44/* Cable length tables */
45static const u16 e1000_m88_cable_length_table[] =
46 { 0, 50, 80, 110, 140, 140, E1000_CABLE_LENGTH_UNDEFINED };
47
48static const u16 e1000_igp_2_cable_length_table[] =
49 { 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21, 0, 0, 0, 3,
50 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41, 6, 10, 14, 18, 22,
51 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61, 21, 26, 31, 35, 40,
52 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82, 40, 45, 51, 56, 61,
53 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104, 60, 66, 72, 77, 82,
54 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121, 83, 89, 95,
55 100, 105, 109, 113, 116, 119, 122, 124, 104, 109, 114, 118, 121,
56 124};
57#define IGP02E1000_CABLE_LENGTH_TABLE_SIZE \
Alejandro Martinez Ruizc00acf42007-10-18 10:16:33 +020058 ARRAY_SIZE(e1000_igp_2_cable_length_table)
Auke Kokbc7f75f2007-09-17 12:30:59 -070059
Bruce Allana4f58f52009-06-02 11:29:18 +000060#define BM_PHY_REG_PAGE(offset) \
61 ((u16)(((offset) >> PHY_PAGE_SHIFT) & 0xFFFF))
62#define BM_PHY_REG_NUM(offset) \
63 ((u16)(((offset) & MAX_PHY_REG_ADDRESS) |\
64 (((offset) >> (PHY_UPPER_SHIFT - PHY_PAGE_SHIFT)) &\
65 ~MAX_PHY_REG_ADDRESS)))
66
67#define HV_INTC_FC_PAGE_START 768
68#define I82578_ADDR_REG 29
69#define I82577_ADDR_REG 16
70#define I82577_CFG_REG 22
71#define I82577_CFG_ASSERT_CRS_ON_TX (1 << 15)
72#define I82577_CFG_ENABLE_DOWNSHIFT (3 << 10) /* auto downshift 100/10 */
73#define I82577_CTRL_REG 23
74#define I82577_CTRL_DOWNSHIFT_MASK (7 << 10)
75
76/* 82577 specific PHY registers */
77#define I82577_PHY_CTRL_2 18
78#define I82577_PHY_STATUS_2 26
79#define I82577_PHY_DIAG_STATUS 31
80
81/* I82577 PHY Status 2 */
82#define I82577_PHY_STATUS2_REV_POLARITY 0x0400
83#define I82577_PHY_STATUS2_MDIX 0x0800
84#define I82577_PHY_STATUS2_SPEED_MASK 0x0300
85#define I82577_PHY_STATUS2_SPEED_1000MBPS 0x0200
86
87/* I82577 PHY Control 2 */
88#define I82577_PHY_CTRL2_AUTO_MDIX 0x0400
89#define I82577_PHY_CTRL2_FORCE_MDI_MDIX 0x0200
90
91/* I82577 PHY Diagnostics Status */
92#define I82577_DSTATUS_CABLE_LENGTH 0x03FC
93#define I82577_DSTATUS_CABLE_LENGTH_SHIFT 2
94
95/* BM PHY Copper Specific Control 1 */
96#define BM_CS_CTRL1 16
97
98/* BM PHY Copper Specific Status */
99#define BM_CS_STATUS 17
100#define BM_CS_STATUS_LINK_UP 0x0400
101#define BM_CS_STATUS_RESOLVED 0x0800
102#define BM_CS_STATUS_SPEED_MASK 0xC000
103#define BM_CS_STATUS_SPEED_1000 0x8000
104
105#define HV_MUX_DATA_CTRL PHY_REG(776, 16)
106#define HV_MUX_DATA_CTRL_GEN_TO_MAC 0x0400
107#define HV_MUX_DATA_CTRL_FORCE_SPEED 0x0004
108
Auke Kokbc7f75f2007-09-17 12:30:59 -0700109/**
110 * e1000e_check_reset_block_generic - Check if PHY reset is blocked
111 * @hw: pointer to the HW structure
112 *
113 * Read the PHY management control register and check whether a PHY reset
114 * is blocked. If a reset is not blocked return 0, otherwise
115 * return E1000_BLK_PHY_RESET (12).
116 **/
117s32 e1000e_check_reset_block_generic(struct e1000_hw *hw)
118{
119 u32 manc;
120
121 manc = er32(MANC);
122
123 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
124 E1000_BLK_PHY_RESET : 0;
125}
126
127/**
128 * e1000e_get_phy_id - Retrieve the PHY ID and revision
129 * @hw: pointer to the HW structure
130 *
131 * Reads the PHY registers and stores the PHY ID and possibly the PHY
132 * revision in the hardware structure.
133 **/
134s32 e1000e_get_phy_id(struct e1000_hw *hw)
135{
136 struct e1000_phy_info *phy = &hw->phy;
Bruce Allana4f58f52009-06-02 11:29:18 +0000137 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700138 u16 phy_id;
Bruce Allana4f58f52009-06-02 11:29:18 +0000139 u16 retry_count = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700140
Bruce Allana4f58f52009-06-02 11:29:18 +0000141 if (!(phy->ops.read_phy_reg))
142 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700143
Bruce Allana4f58f52009-06-02 11:29:18 +0000144 while (retry_count < 2) {
145 ret_val = e1e_rphy(hw, PHY_ID1, &phy_id);
146 if (ret_val)
147 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700148
Bruce Allana4f58f52009-06-02 11:29:18 +0000149 phy->id = (u32)(phy_id << 16);
150 udelay(20);
151 ret_val = e1e_rphy(hw, PHY_ID2, &phy_id);
152 if (ret_val)
153 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700154
Bruce Allana4f58f52009-06-02 11:29:18 +0000155 phy->id |= (u32)(phy_id & PHY_REVISION_MASK);
156 phy->revision = (u32)(phy_id & ~PHY_REVISION_MASK);
157
158 if (phy->id != 0 && phy->id != PHY_REVISION_MASK)
159 goto out;
160
161 /*
162 * If the PHY ID is still unknown, we may have an 82577i
163 * without link. We will try again after setting Slow
164 * MDIC mode. No harm in trying again in this case since
165 * the PHY ID is unknown at this point anyway
166 */
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000167 ret_val = phy->ops.acquire_phy(hw);
168 if (ret_val)
169 goto out;
Bruce Allana4f58f52009-06-02 11:29:18 +0000170 ret_val = e1000_set_mdio_slow_mode_hv(hw, true);
171 if (ret_val)
172 goto out;
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000173 phy->ops.release_phy(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +0000174
175 retry_count++;
176 }
177out:
178 /* Revert to MDIO fast mode, if applicable */
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000179 if (retry_count) {
180 ret_val = phy->ops.acquire_phy(hw);
181 if (ret_val)
182 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +0000183 ret_val = e1000_set_mdio_slow_mode_hv(hw, false);
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000184 phy->ops.release_phy(hw);
185 }
Bruce Allana4f58f52009-06-02 11:29:18 +0000186
187 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700188}
189
190/**
191 * e1000e_phy_reset_dsp - Reset PHY DSP
192 * @hw: pointer to the HW structure
193 *
194 * Reset the digital signal processor.
195 **/
196s32 e1000e_phy_reset_dsp(struct e1000_hw *hw)
197{
198 s32 ret_val;
199
200 ret_val = e1e_wphy(hw, M88E1000_PHY_GEN_CONTROL, 0xC1);
201 if (ret_val)
202 return ret_val;
203
204 return e1e_wphy(hw, M88E1000_PHY_GEN_CONTROL, 0);
205}
206
207/**
David Graham2d9498f2008-04-23 11:09:14 -0700208 * e1000e_read_phy_reg_mdic - Read MDI control register
Auke Kokbc7f75f2007-09-17 12:30:59 -0700209 * @hw: pointer to the HW structure
210 * @offset: register offset to be read
211 * @data: pointer to the read data
212 *
Auke Kok489815c2008-02-21 15:11:07 -0800213 * Reads the MDI control register in the PHY at offset and stores the
Auke Kokbc7f75f2007-09-17 12:30:59 -0700214 * information read to data.
215 **/
David Graham2d9498f2008-04-23 11:09:14 -0700216s32 e1000e_read_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 *data)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700217{
218 struct e1000_phy_info *phy = &hw->phy;
219 u32 i, mdic = 0;
220
221 if (offset > MAX_PHY_REG_ADDRESS) {
222 hw_dbg(hw, "PHY Address %d is out of range\n", offset);
223 return -E1000_ERR_PARAM;
224 }
225
Bruce Allanad680762008-03-28 09:15:03 -0700226 /*
227 * Set up Op-code, Phy Address, and register offset in the MDI
Auke Kokbc7f75f2007-09-17 12:30:59 -0700228 * Control register. The MAC will take care of interfacing with the
229 * PHY to retrieve the desired data.
230 */
231 mdic = ((offset << E1000_MDIC_REG_SHIFT) |
232 (phy->addr << E1000_MDIC_PHY_SHIFT) |
233 (E1000_MDIC_OP_READ));
234
235 ew32(MDIC, mdic);
236
Bruce Allanad680762008-03-28 09:15:03 -0700237 /*
238 * Poll the ready bit to see if the MDI read completed
239 * Increasing the time out as testing showed failures with
240 * the lower time out
241 */
David Graham2d9498f2008-04-23 11:09:14 -0700242 for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700243 udelay(50);
244 mdic = er32(MDIC);
245 if (mdic & E1000_MDIC_READY)
246 break;
247 }
248 if (!(mdic & E1000_MDIC_READY)) {
249 hw_dbg(hw, "MDI Read did not complete\n");
250 return -E1000_ERR_PHY;
251 }
252 if (mdic & E1000_MDIC_ERROR) {
253 hw_dbg(hw, "MDI Error\n");
254 return -E1000_ERR_PHY;
255 }
256 *data = (u16) mdic;
257
258 return 0;
259}
260
261/**
David Graham2d9498f2008-04-23 11:09:14 -0700262 * e1000e_write_phy_reg_mdic - Write MDI control register
Auke Kokbc7f75f2007-09-17 12:30:59 -0700263 * @hw: pointer to the HW structure
264 * @offset: register offset to write to
265 * @data: data to write to register at offset
266 *
267 * Writes data to MDI control register in the PHY at offset.
268 **/
David Graham2d9498f2008-04-23 11:09:14 -0700269s32 e1000e_write_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 data)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700270{
271 struct e1000_phy_info *phy = &hw->phy;
272 u32 i, mdic = 0;
273
274 if (offset > MAX_PHY_REG_ADDRESS) {
275 hw_dbg(hw, "PHY Address %d is out of range\n", offset);
276 return -E1000_ERR_PARAM;
277 }
278
Bruce Allanad680762008-03-28 09:15:03 -0700279 /*
280 * Set up Op-code, Phy Address, and register offset in the MDI
Auke Kokbc7f75f2007-09-17 12:30:59 -0700281 * Control register. The MAC will take care of interfacing with the
282 * PHY to retrieve the desired data.
283 */
284 mdic = (((u32)data) |
285 (offset << E1000_MDIC_REG_SHIFT) |
286 (phy->addr << E1000_MDIC_PHY_SHIFT) |
287 (E1000_MDIC_OP_WRITE));
288
289 ew32(MDIC, mdic);
290
David Graham2d9498f2008-04-23 11:09:14 -0700291 /*
292 * Poll the ready bit to see if the MDI read completed
293 * Increasing the time out as testing showed failures with
294 * the lower time out
295 */
296 for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
297 udelay(50);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700298 mdic = er32(MDIC);
299 if (mdic & E1000_MDIC_READY)
300 break;
301 }
302 if (!(mdic & E1000_MDIC_READY)) {
303 hw_dbg(hw, "MDI Write did not complete\n");
304 return -E1000_ERR_PHY;
305 }
David Graham2d9498f2008-04-23 11:09:14 -0700306 if (mdic & E1000_MDIC_ERROR) {
307 hw_dbg(hw, "MDI Error\n");
308 return -E1000_ERR_PHY;
309 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700310
311 return 0;
312}
313
314/**
315 * e1000e_read_phy_reg_m88 - Read m88 PHY register
316 * @hw: pointer to the HW structure
317 * @offset: register offset to be read
318 * @data: pointer to the read data
319 *
320 * Acquires semaphore, if necessary, then reads the PHY register at offset
321 * and storing the retrieved information in data. Release any acquired
322 * semaphores before exiting.
323 **/
324s32 e1000e_read_phy_reg_m88(struct e1000_hw *hw, u32 offset, u16 *data)
325{
326 s32 ret_val;
327
328 ret_val = hw->phy.ops.acquire_phy(hw);
329 if (ret_val)
330 return ret_val;
331
David Graham2d9498f2008-04-23 11:09:14 -0700332 ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
333 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700334
335 hw->phy.ops.release_phy(hw);
336
337 return ret_val;
338}
339
340/**
341 * e1000e_write_phy_reg_m88 - Write m88 PHY register
342 * @hw: pointer to the HW structure
343 * @offset: register offset to write to
344 * @data: data to write at register offset
345 *
346 * Acquires semaphore, if necessary, then writes the data to PHY register
347 * at the offset. Release any acquired semaphores before exiting.
348 **/
349s32 e1000e_write_phy_reg_m88(struct e1000_hw *hw, u32 offset, u16 data)
350{
351 s32 ret_val;
352
353 ret_val = hw->phy.ops.acquire_phy(hw);
354 if (ret_val)
355 return ret_val;
356
David Graham2d9498f2008-04-23 11:09:14 -0700357 ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
358 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700359
360 hw->phy.ops.release_phy(hw);
361
362 return ret_val;
363}
364
365/**
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000366 * __e1000e_read_phy_reg_igp - Read igp PHY register
Auke Kokbc7f75f2007-09-17 12:30:59 -0700367 * @hw: pointer to the HW structure
368 * @offset: register offset to be read
369 * @data: pointer to the read data
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000370 * @locked: semaphore has already been acquired or not
Auke Kokbc7f75f2007-09-17 12:30:59 -0700371 *
372 * Acquires semaphore, if necessary, then reads the PHY register at offset
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000373 * and stores the retrieved information in data. Release any acquired
Auke Kokbc7f75f2007-09-17 12:30:59 -0700374 * semaphores before exiting.
375 **/
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000376static s32 __e1000e_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data,
377 bool locked)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700378{
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000379 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700380
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000381 if (!locked) {
382 if (!(hw->phy.ops.acquire_phy))
383 goto out;
384
385 ret_val = hw->phy.ops.acquire_phy(hw);
386 if (ret_val)
387 goto out;
388 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700389
390 if (offset > MAX_PHY_MULTI_PAGE_REG) {
David Graham2d9498f2008-04-23 11:09:14 -0700391 ret_val = e1000e_write_phy_reg_mdic(hw,
392 IGP01E1000_PHY_PAGE_SELECT,
393 (u16)offset);
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000394 if (ret_val)
395 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700396 }
397
David Graham2d9498f2008-04-23 11:09:14 -0700398 ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000399 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700400
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000401release:
402 if (!locked)
403 hw->phy.ops.release_phy(hw);
404out:
405 return ret_val;
406}
Auke Kokbc7f75f2007-09-17 12:30:59 -0700407
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000408/**
409 * e1000e_read_phy_reg_igp - Read igp PHY register
410 * @hw: pointer to the HW structure
411 * @offset: register offset to be read
412 * @data: pointer to the read data
413 *
414 * Acquires semaphore then reads the PHY register at offset and stores the
415 * retrieved information in data.
416 * Release the acquired semaphore before exiting.
417 **/
418s32 e1000e_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data)
419{
420 return __e1000e_read_phy_reg_igp(hw, offset, data, false);
421}
422
423/**
424 * e1000e_read_phy_reg_igp_locked - Read igp PHY register
425 * @hw: pointer to the HW structure
426 * @offset: register offset to be read
427 * @data: pointer to the read data
428 *
429 * Reads the PHY register at offset and stores the retrieved information
430 * in data. Assumes semaphore already acquired.
431 **/
432s32 e1000e_read_phy_reg_igp_locked(struct e1000_hw *hw, u32 offset, u16 *data)
433{
434 return __e1000e_read_phy_reg_igp(hw, offset, data, true);
435}
436
437/**
438 * e1000e_write_phy_reg_igp - Write igp PHY register
439 * @hw: pointer to the HW structure
440 * @offset: register offset to write to
441 * @data: data to write at register offset
442 * @locked: semaphore has already been acquired or not
443 *
444 * Acquires semaphore, if necessary, then writes the data to PHY register
445 * at the offset. Release any acquired semaphores before exiting.
446 **/
447static s32 __e1000e_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data,
448 bool locked)
449{
450 s32 ret_val = 0;
451
452 if (!locked) {
453 if (!(hw->phy.ops.acquire_phy))
454 goto out;
455
456 ret_val = hw->phy.ops.acquire_phy(hw);
457 if (ret_val)
458 goto out;
459 }
460
461 if (offset > MAX_PHY_MULTI_PAGE_REG) {
462 ret_val = e1000e_write_phy_reg_mdic(hw,
463 IGP01E1000_PHY_PAGE_SELECT,
464 (u16)offset);
465 if (ret_val)
466 goto release;
467 }
468
469 ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
470 data);
471
472release:
473 if (!locked)
474 hw->phy.ops.release_phy(hw);
475
476out:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700477 return ret_val;
478}
479
480/**
481 * e1000e_write_phy_reg_igp - Write igp PHY register
482 * @hw: pointer to the HW structure
483 * @offset: register offset to write to
484 * @data: data to write at register offset
485 *
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000486 * Acquires semaphore then writes the data to PHY register
Auke Kokbc7f75f2007-09-17 12:30:59 -0700487 * at the offset. Release any acquired semaphores before exiting.
488 **/
489s32 e1000e_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data)
490{
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000491 return __e1000e_write_phy_reg_igp(hw, offset, data, false);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700492}
493
494/**
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000495 * e1000e_write_phy_reg_igp_locked - Write igp PHY register
496 * @hw: pointer to the HW structure
497 * @offset: register offset to write to
498 * @data: data to write at register offset
499 *
500 * Writes the data to PHY register at the offset.
501 * Assumes semaphore already acquired.
502 **/
503s32 e1000e_write_phy_reg_igp_locked(struct e1000_hw *hw, u32 offset, u16 data)
504{
505 return __e1000e_write_phy_reg_igp(hw, offset, data, true);
506}
507
508/**
509 * __e1000_read_kmrn_reg - Read kumeran register
Auke Kokbc7f75f2007-09-17 12:30:59 -0700510 * @hw: pointer to the HW structure
511 * @offset: register offset to be read
512 * @data: pointer to the read data
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000513 * @locked: semaphore has already been acquired or not
Auke Kokbc7f75f2007-09-17 12:30:59 -0700514 *
515 * Acquires semaphore, if necessary. Then reads the PHY register at offset
516 * using the kumeran interface. The information retrieved is stored in data.
517 * Release any acquired semaphores before exiting.
518 **/
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000519static s32 __e1000_read_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 *data,
520 bool locked)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700521{
522 u32 kmrnctrlsta;
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000523 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700524
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000525 if (!locked) {
526 if (!(hw->phy.ops.acquire_phy))
527 goto out;
528
529 ret_val = hw->phy.ops.acquire_phy(hw);
530 if (ret_val)
531 goto out;
532 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700533
534 kmrnctrlsta = ((offset << E1000_KMRNCTRLSTA_OFFSET_SHIFT) &
535 E1000_KMRNCTRLSTA_OFFSET) | E1000_KMRNCTRLSTA_REN;
536 ew32(KMRNCTRLSTA, kmrnctrlsta);
537
538 udelay(2);
539
540 kmrnctrlsta = er32(KMRNCTRLSTA);
541 *data = (u16)kmrnctrlsta;
542
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000543 if (!locked)
544 hw->phy.ops.release_phy(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700545
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000546out:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700547 return ret_val;
548}
549
550/**
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000551 * e1000e_read_kmrn_reg - Read kumeran register
552 * @hw: pointer to the HW structure
553 * @offset: register offset to be read
554 * @data: pointer to the read data
555 *
556 * Acquires semaphore then reads the PHY register at offset using the
557 * kumeran interface. The information retrieved is stored in data.
558 * Release the acquired semaphore before exiting.
559 **/
560s32 e1000e_read_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 *data)
561{
562 return __e1000_read_kmrn_reg(hw, offset, data, false);
563}
564
565/**
566 * e1000_read_kmrn_reg_locked - Read kumeran register
567 * @hw: pointer to the HW structure
568 * @offset: register offset to be read
569 * @data: pointer to the read data
570 *
571 * Reads the PHY register at offset using the kumeran interface. The
572 * information retrieved is stored in data.
573 * Assumes semaphore already acquired.
574 **/
575s32 e1000_read_kmrn_reg_locked(struct e1000_hw *hw, u32 offset, u16 *data)
576{
577 return __e1000_read_kmrn_reg(hw, offset, data, true);
578}
579
580/**
581 * __e1000_write_kmrn_reg - Write kumeran register
Auke Kokbc7f75f2007-09-17 12:30:59 -0700582 * @hw: pointer to the HW structure
583 * @offset: register offset to write to
584 * @data: data to write at register offset
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000585 * @locked: semaphore has already been acquired or not
Auke Kokbc7f75f2007-09-17 12:30:59 -0700586 *
587 * Acquires semaphore, if necessary. Then write the data to PHY register
588 * at the offset using the kumeran interface. Release any acquired semaphores
589 * before exiting.
590 **/
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000591static s32 __e1000_write_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 data,
592 bool locked)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700593{
594 u32 kmrnctrlsta;
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000595 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700596
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000597 if (!locked) {
598 if (!(hw->phy.ops.acquire_phy))
599 goto out;
600
601 ret_val = hw->phy.ops.acquire_phy(hw);
602 if (ret_val)
603 goto out;
604 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700605
606 kmrnctrlsta = ((offset << E1000_KMRNCTRLSTA_OFFSET_SHIFT) &
607 E1000_KMRNCTRLSTA_OFFSET) | data;
608 ew32(KMRNCTRLSTA, kmrnctrlsta);
609
610 udelay(2);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700611
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000612 if (!locked)
613 hw->phy.ops.release_phy(hw);
614
615out:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700616 return ret_val;
617}
618
619/**
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000620 * e1000e_write_kmrn_reg - Write kumeran register
621 * @hw: pointer to the HW structure
622 * @offset: register offset to write to
623 * @data: data to write at register offset
624 *
625 * Acquires semaphore then writes the data to the PHY register at the offset
626 * using the kumeran interface. Release the acquired semaphore before exiting.
627 **/
628s32 e1000e_write_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 data)
629{
630 return __e1000_write_kmrn_reg(hw, offset, data, false);
631}
632
633/**
634 * e1000_write_kmrn_reg_locked - Write kumeran register
635 * @hw: pointer to the HW structure
636 * @offset: register offset to write to
637 * @data: data to write at register offset
638 *
639 * Write the data to PHY register at the offset using the kumeran interface.
640 * Assumes semaphore already acquired.
641 **/
642s32 e1000_write_kmrn_reg_locked(struct e1000_hw *hw, u32 offset, u16 data)
643{
644 return __e1000_write_kmrn_reg(hw, offset, data, true);
645}
646
647/**
Bruce Allana4f58f52009-06-02 11:29:18 +0000648 * e1000_copper_link_setup_82577 - Setup 82577 PHY for copper link
649 * @hw: pointer to the HW structure
650 *
651 * Sets up Carrier-sense on Transmit and downshift values.
652 **/
653s32 e1000_copper_link_setup_82577(struct e1000_hw *hw)
654{
655 struct e1000_phy_info *phy = &hw->phy;
656 s32 ret_val;
657 u16 phy_data;
658
659 /* Enable CRS on TX. This must be set for half-duplex operation. */
660 ret_val = phy->ops.read_phy_reg(hw, I82577_CFG_REG, &phy_data);
661 if (ret_val)
662 goto out;
663
664 phy_data |= I82577_CFG_ASSERT_CRS_ON_TX;
665
666 /* Enable downshift */
667 phy_data |= I82577_CFG_ENABLE_DOWNSHIFT;
668
669 ret_val = phy->ops.write_phy_reg(hw, I82577_CFG_REG, phy_data);
670 if (ret_val)
671 goto out;
672
673 /* Set number of link attempts before downshift */
674 ret_val = phy->ops.read_phy_reg(hw, I82577_CTRL_REG, &phy_data);
675 if (ret_val)
676 goto out;
677 phy_data &= ~I82577_CTRL_DOWNSHIFT_MASK;
678 ret_val = phy->ops.write_phy_reg(hw, I82577_CTRL_REG, phy_data);
679
680out:
681 return ret_val;
682}
683
684/**
Auke Kokbc7f75f2007-09-17 12:30:59 -0700685 * e1000e_copper_link_setup_m88 - Setup m88 PHY's for copper link
686 * @hw: pointer to the HW structure
687 *
688 * Sets up MDI/MDI-X and polarity for m88 PHY's. If necessary, transmit clock
689 * and downshift values are set also.
690 **/
691s32 e1000e_copper_link_setup_m88(struct e1000_hw *hw)
692{
693 struct e1000_phy_info *phy = &hw->phy;
694 s32 ret_val;
695 u16 phy_data;
696
Bruce Allanad680762008-03-28 09:15:03 -0700697 /* Enable CRS on Tx. This must be set for half-duplex operation. */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700698 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
699 if (ret_val)
700 return ret_val;
701
Bruce Allana4f58f52009-06-02 11:29:18 +0000702 /* For BM PHY this bit is downshift enable */
703 if (phy->type != e1000_phy_bm)
David Graham2d9498f2008-04-23 11:09:14 -0700704 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700705
Bruce Allanad680762008-03-28 09:15:03 -0700706 /*
707 * Options:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700708 * MDI/MDI-X = 0 (default)
709 * 0 - Auto for all speeds
710 * 1 - MDI mode
711 * 2 - MDI-X mode
712 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
713 */
714 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
715
716 switch (phy->mdix) {
717 case 1:
718 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
719 break;
720 case 2:
721 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
722 break;
723 case 3:
724 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
725 break;
726 case 0:
727 default:
728 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
729 break;
730 }
731
Bruce Allanad680762008-03-28 09:15:03 -0700732 /*
733 * Options:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700734 * disable_polarity_correction = 0 (default)
735 * Automatic Correction for Reversed Cable Polarity
736 * 0 - Disabled
737 * 1 - Enabled
738 */
739 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
740 if (phy->disable_polarity_correction == 1)
741 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
742
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700743 /* Enable downshift on BM (disabled by default) */
744 if (phy->type == e1000_phy_bm)
745 phy_data |= BME1000_PSCR_ENABLE_DOWNSHIFT;
746
Auke Kokbc7f75f2007-09-17 12:30:59 -0700747 ret_val = e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
748 if (ret_val)
749 return ret_val;
750
Bruce Allan4662e822008-08-26 18:37:06 -0700751 if ((phy->type == e1000_phy_m88) &&
752 (phy->revision < E1000_REVISION_4) &&
753 (phy->id != BME1000_E_PHY_ID_R2)) {
Bruce Allanad680762008-03-28 09:15:03 -0700754 /*
755 * Force TX_CLK in the Extended PHY Specific Control Register
Auke Kokbc7f75f2007-09-17 12:30:59 -0700756 * to 25MHz clock.
757 */
758 ret_val = e1e_rphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
759 if (ret_val)
760 return ret_val;
761
762 phy_data |= M88E1000_EPSCR_TX_CLK_25;
763
764 if ((phy->revision == 2) &&
765 (phy->id == M88E1111_I_PHY_ID)) {
766 /* 82573L PHY - set the downshift counter to 5x. */
767 phy_data &= ~M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK;
768 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
769 } else {
770 /* Configure Master and Slave downshift values */
771 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
772 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
773 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
774 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
775 }
776 ret_val = e1e_wphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
777 if (ret_val)
778 return ret_val;
779 }
780
Bruce Allan4662e822008-08-26 18:37:06 -0700781 if ((phy->type == e1000_phy_bm) && (phy->id == BME1000_E_PHY_ID_R2)) {
782 /* Set PHY page 0, register 29 to 0x0003 */
783 ret_val = e1e_wphy(hw, 29, 0x0003);
784 if (ret_val)
785 return ret_val;
786
787 /* Set PHY page 0, register 30 to 0x0000 */
788 ret_val = e1e_wphy(hw, 30, 0x0000);
789 if (ret_val)
790 return ret_val;
791 }
792
Auke Kokbc7f75f2007-09-17 12:30:59 -0700793 /* Commit the changes. */
794 ret_val = e1000e_commit_phy(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +0000795 if (ret_val) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700796 hw_dbg(hw, "Error committing the PHY changes\n");
Bruce Allana4f58f52009-06-02 11:29:18 +0000797 return ret_val;
798 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700799
Bruce Allana4f58f52009-06-02 11:29:18 +0000800 if (phy->type == e1000_phy_82578) {
801 ret_val = phy->ops.read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
802 &phy_data);
803 if (ret_val)
804 return ret_val;
805
806 /* 82578 PHY - set the downshift count to 1x. */
807 phy_data |= I82578_EPSCR_DOWNSHIFT_ENABLE;
808 phy_data &= ~I82578_EPSCR_DOWNSHIFT_COUNTER_MASK;
809 ret_val = phy->ops.write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
810 phy_data);
811 if (ret_val)
812 return ret_val;
813 }
814
815 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700816}
817
818/**
819 * e1000e_copper_link_setup_igp - Setup igp PHY's for copper link
820 * @hw: pointer to the HW structure
821 *
822 * Sets up LPLU, MDI/MDI-X, polarity, Smartspeed and Master/Slave config for
823 * igp PHY's.
824 **/
825s32 e1000e_copper_link_setup_igp(struct e1000_hw *hw)
826{
827 struct e1000_phy_info *phy = &hw->phy;
828 s32 ret_val;
829 u16 data;
830
831 ret_val = e1000_phy_hw_reset(hw);
832 if (ret_val) {
833 hw_dbg(hw, "Error resetting the PHY.\n");
834 return ret_val;
835 }
836
David Graham2d9498f2008-04-23 11:09:14 -0700837 /*
838 * Wait 100ms for MAC to configure PHY from NVM settings, to avoid
839 * timeout issues when LFS is enabled.
840 */
841 msleep(100);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700842
843 /* disable lplu d0 during driver init */
844 ret_val = e1000_set_d0_lplu_state(hw, 0);
845 if (ret_val) {
846 hw_dbg(hw, "Error Disabling LPLU D0\n");
847 return ret_val;
848 }
849 /* Configure mdi-mdix settings */
850 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CTRL, &data);
851 if (ret_val)
852 return ret_val;
853
854 data &= ~IGP01E1000_PSCR_AUTO_MDIX;
855
856 switch (phy->mdix) {
857 case 1:
858 data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
859 break;
860 case 2:
861 data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
862 break;
863 case 0:
864 default:
865 data |= IGP01E1000_PSCR_AUTO_MDIX;
866 break;
867 }
868 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CTRL, data);
869 if (ret_val)
870 return ret_val;
871
872 /* set auto-master slave resolution settings */
873 if (hw->mac.autoneg) {
Bruce Allanad680762008-03-28 09:15:03 -0700874 /*
875 * when autonegotiation advertisement is only 1000Mbps then we
Auke Kokbc7f75f2007-09-17 12:30:59 -0700876 * should disable SmartSpeed and enable Auto MasterSlave
Bruce Allanad680762008-03-28 09:15:03 -0700877 * resolution as hardware default.
878 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700879 if (phy->autoneg_advertised == ADVERTISE_1000_FULL) {
880 /* Disable SmartSpeed */
881 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -0700882 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700883 if (ret_val)
884 return ret_val;
885
886 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
887 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -0700888 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700889 if (ret_val)
890 return ret_val;
891
892 /* Set auto Master/Slave resolution process */
893 ret_val = e1e_rphy(hw, PHY_1000T_CTRL, &data);
894 if (ret_val)
895 return ret_val;
896
897 data &= ~CR_1000T_MS_ENABLE;
898 ret_val = e1e_wphy(hw, PHY_1000T_CTRL, data);
899 if (ret_val)
900 return ret_val;
901 }
902
903 ret_val = e1e_rphy(hw, PHY_1000T_CTRL, &data);
904 if (ret_val)
905 return ret_val;
906
907 /* load defaults for future use */
908 phy->original_ms_type = (data & CR_1000T_MS_ENABLE) ?
909 ((data & CR_1000T_MS_VALUE) ?
910 e1000_ms_force_master :
911 e1000_ms_force_slave) :
912 e1000_ms_auto;
913
914 switch (phy->ms_type) {
915 case e1000_ms_force_master:
916 data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
917 break;
918 case e1000_ms_force_slave:
919 data |= CR_1000T_MS_ENABLE;
920 data &= ~(CR_1000T_MS_VALUE);
921 break;
922 case e1000_ms_auto:
923 data &= ~CR_1000T_MS_ENABLE;
924 default:
925 break;
926 }
927 ret_val = e1e_wphy(hw, PHY_1000T_CTRL, data);
928 }
929
930 return ret_val;
931}
932
933/**
934 * e1000_phy_setup_autoneg - Configure PHY for auto-negotiation
935 * @hw: pointer to the HW structure
936 *
937 * Reads the MII auto-neg advertisement register and/or the 1000T control
938 * register and if the PHY is already setup for auto-negotiation, then
939 * return successful. Otherwise, setup advertisement and flow control to
940 * the appropriate values for the wanted auto-negotiation.
941 **/
942static s32 e1000_phy_setup_autoneg(struct e1000_hw *hw)
943{
944 struct e1000_phy_info *phy = &hw->phy;
945 s32 ret_val;
946 u16 mii_autoneg_adv_reg;
947 u16 mii_1000t_ctrl_reg = 0;
948
949 phy->autoneg_advertised &= phy->autoneg_mask;
950
951 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
952 ret_val = e1e_rphy(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
953 if (ret_val)
954 return ret_val;
955
956 if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
957 /* Read the MII 1000Base-T Control Register (Address 9). */
958 ret_val = e1e_rphy(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
959 if (ret_val)
960 return ret_val;
961 }
962
Bruce Allanad680762008-03-28 09:15:03 -0700963 /*
964 * Need to parse both autoneg_advertised and fc and set up
Auke Kokbc7f75f2007-09-17 12:30:59 -0700965 * the appropriate PHY registers. First we will parse for
966 * autoneg_advertised software override. Since we can advertise
967 * a plethora of combinations, we need to check each bit
968 * individually.
969 */
970
Bruce Allanad680762008-03-28 09:15:03 -0700971 /*
972 * First we clear all the 10/100 mb speed bits in the Auto-Neg
Auke Kokbc7f75f2007-09-17 12:30:59 -0700973 * Advertisement Register (Address 4) and the 1000 mb speed bits in
974 * the 1000Base-T Control Register (Address 9).
975 */
976 mii_autoneg_adv_reg &= ~(NWAY_AR_100TX_FD_CAPS |
977 NWAY_AR_100TX_HD_CAPS |
978 NWAY_AR_10T_FD_CAPS |
979 NWAY_AR_10T_HD_CAPS);
980 mii_1000t_ctrl_reg &= ~(CR_1000T_HD_CAPS | CR_1000T_FD_CAPS);
981
982 hw_dbg(hw, "autoneg_advertised %x\n", phy->autoneg_advertised);
983
984 /* Do we want to advertise 10 Mb Half Duplex? */
985 if (phy->autoneg_advertised & ADVERTISE_10_HALF) {
986 hw_dbg(hw, "Advertise 10mb Half duplex\n");
987 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
988 }
989
990 /* Do we want to advertise 10 Mb Full Duplex? */
991 if (phy->autoneg_advertised & ADVERTISE_10_FULL) {
992 hw_dbg(hw, "Advertise 10mb Full duplex\n");
993 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
994 }
995
996 /* Do we want to advertise 100 Mb Half Duplex? */
997 if (phy->autoneg_advertised & ADVERTISE_100_HALF) {
998 hw_dbg(hw, "Advertise 100mb Half duplex\n");
999 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
1000 }
1001
1002 /* Do we want to advertise 100 Mb Full Duplex? */
1003 if (phy->autoneg_advertised & ADVERTISE_100_FULL) {
1004 hw_dbg(hw, "Advertise 100mb Full duplex\n");
1005 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
1006 }
1007
1008 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
1009 if (phy->autoneg_advertised & ADVERTISE_1000_HALF)
1010 hw_dbg(hw, "Advertise 1000mb Half duplex request denied!\n");
1011
1012 /* Do we want to advertise 1000 Mb Full Duplex? */
1013 if (phy->autoneg_advertised & ADVERTISE_1000_FULL) {
1014 hw_dbg(hw, "Advertise 1000mb Full duplex\n");
1015 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
1016 }
1017
Bruce Allanad680762008-03-28 09:15:03 -07001018 /*
1019 * Check for a software override of the flow control settings, and
Auke Kokbc7f75f2007-09-17 12:30:59 -07001020 * setup the PHY advertisement registers accordingly. If
1021 * auto-negotiation is enabled, then software will have to set the
1022 * "PAUSE" bits to the correct value in the Auto-Negotiation
1023 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-
1024 * negotiation.
1025 *
1026 * The possible values of the "fc" parameter are:
1027 * 0: Flow control is completely disabled
1028 * 1: Rx flow control is enabled (we can receive pause frames
1029 * but not send pause frames).
1030 * 2: Tx flow control is enabled (we can send pause frames
1031 * but we do not support receiving pause frames).
Bruce Allanad680762008-03-28 09:15:03 -07001032 * 3: Both Rx and Tx flow control (symmetric) are enabled.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001033 * other: No software override. The flow control configuration
1034 * in the EEPROM is used.
1035 */
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08001036 switch (hw->fc.current_mode) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001037 case e1000_fc_none:
Bruce Allanad680762008-03-28 09:15:03 -07001038 /*
1039 * Flow control (Rx & Tx) is completely disabled by a
Auke Kokbc7f75f2007-09-17 12:30:59 -07001040 * software over-ride.
1041 */
1042 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1043 break;
1044 case e1000_fc_rx_pause:
Bruce Allanad680762008-03-28 09:15:03 -07001045 /*
1046 * Rx Flow control is enabled, and Tx Flow control is
Auke Kokbc7f75f2007-09-17 12:30:59 -07001047 * disabled, by a software over-ride.
Bruce Allanad680762008-03-28 09:15:03 -07001048 *
1049 * Since there really isn't a way to advertise that we are
1050 * capable of Rx Pause ONLY, we will advertise that we
1051 * support both symmetric and asymmetric Rx PAUSE. Later
Auke Kokbc7f75f2007-09-17 12:30:59 -07001052 * (in e1000e_config_fc_after_link_up) we will disable the
1053 * hw's ability to send PAUSE frames.
1054 */
1055 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1056 break;
1057 case e1000_fc_tx_pause:
Bruce Allanad680762008-03-28 09:15:03 -07001058 /*
1059 * Tx Flow control is enabled, and Rx Flow control is
Auke Kokbc7f75f2007-09-17 12:30:59 -07001060 * disabled, by a software over-ride.
1061 */
1062 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
1063 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
1064 break;
1065 case e1000_fc_full:
Bruce Allanad680762008-03-28 09:15:03 -07001066 /*
1067 * Flow control (both Rx and Tx) is enabled by a software
Auke Kokbc7f75f2007-09-17 12:30:59 -07001068 * over-ride.
1069 */
1070 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1071 break;
1072 default:
1073 hw_dbg(hw, "Flow control param set incorrectly\n");
1074 ret_val = -E1000_ERR_CONFIG;
1075 return ret_val;
1076 }
1077
1078 ret_val = e1e_wphy(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
1079 if (ret_val)
1080 return ret_val;
1081
1082 hw_dbg(hw, "Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
1083
1084 if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
1085 ret_val = e1e_wphy(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg);
1086 }
1087
1088 return ret_val;
1089}
1090
1091/**
1092 * e1000_copper_link_autoneg - Setup/Enable autoneg for copper link
1093 * @hw: pointer to the HW structure
1094 *
1095 * Performs initial bounds checking on autoneg advertisement parameter, then
1096 * configure to advertise the full capability. Setup the PHY to autoneg
1097 * and restart the negotiation process between the link partner. If
Bruce Allanad680762008-03-28 09:15:03 -07001098 * autoneg_wait_to_complete, then wait for autoneg to complete before exiting.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001099 **/
1100static s32 e1000_copper_link_autoneg(struct e1000_hw *hw)
1101{
1102 struct e1000_phy_info *phy = &hw->phy;
1103 s32 ret_val;
1104 u16 phy_ctrl;
1105
Bruce Allanad680762008-03-28 09:15:03 -07001106 /*
1107 * Perform some bounds checking on the autoneg advertisement
Auke Kokbc7f75f2007-09-17 12:30:59 -07001108 * parameter.
1109 */
1110 phy->autoneg_advertised &= phy->autoneg_mask;
1111
Bruce Allanad680762008-03-28 09:15:03 -07001112 /*
1113 * If autoneg_advertised is zero, we assume it was not defaulted
Auke Kokbc7f75f2007-09-17 12:30:59 -07001114 * by the calling code so we set to advertise full capability.
1115 */
1116 if (phy->autoneg_advertised == 0)
1117 phy->autoneg_advertised = phy->autoneg_mask;
1118
1119 hw_dbg(hw, "Reconfiguring auto-neg advertisement params\n");
1120 ret_val = e1000_phy_setup_autoneg(hw);
1121 if (ret_val) {
1122 hw_dbg(hw, "Error Setting up Auto-Negotiation\n");
1123 return ret_val;
1124 }
1125 hw_dbg(hw, "Restarting Auto-Neg\n");
1126
Bruce Allanad680762008-03-28 09:15:03 -07001127 /*
1128 * Restart auto-negotiation by setting the Auto Neg Enable bit and
Auke Kokbc7f75f2007-09-17 12:30:59 -07001129 * the Auto Neg Restart bit in the PHY control register.
1130 */
1131 ret_val = e1e_rphy(hw, PHY_CONTROL, &phy_ctrl);
1132 if (ret_val)
1133 return ret_val;
1134
1135 phy_ctrl |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
1136 ret_val = e1e_wphy(hw, PHY_CONTROL, phy_ctrl);
1137 if (ret_val)
1138 return ret_val;
1139
Bruce Allanad680762008-03-28 09:15:03 -07001140 /*
1141 * Does the user want to wait for Auto-Neg to complete here, or
Auke Kokbc7f75f2007-09-17 12:30:59 -07001142 * check at a later time (for example, callback routine).
1143 */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001144 if (phy->autoneg_wait_to_complete) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001145 ret_val = e1000_wait_autoneg(hw);
1146 if (ret_val) {
1147 hw_dbg(hw, "Error while waiting for "
1148 "autoneg to complete\n");
1149 return ret_val;
1150 }
1151 }
1152
1153 hw->mac.get_link_status = 1;
1154
1155 return ret_val;
1156}
1157
1158/**
1159 * e1000e_setup_copper_link - Configure copper link settings
1160 * @hw: pointer to the HW structure
1161 *
1162 * Calls the appropriate function to configure the link for auto-neg or forced
1163 * speed and duplex. Then we check for link, once link is established calls
1164 * to configure collision distance and flow control are called. If link is
1165 * not established, we return -E1000_ERR_PHY (-2).
1166 **/
1167s32 e1000e_setup_copper_link(struct e1000_hw *hw)
1168{
1169 s32 ret_val;
1170 bool link;
1171
1172 if (hw->mac.autoneg) {
Bruce Allanad680762008-03-28 09:15:03 -07001173 /*
1174 * Setup autoneg and flow control advertisement and perform
1175 * autonegotiation.
1176 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001177 ret_val = e1000_copper_link_autoneg(hw);
1178 if (ret_val)
1179 return ret_val;
1180 } else {
Bruce Allanad680762008-03-28 09:15:03 -07001181 /*
1182 * PHY will be set to 10H, 10F, 100H or 100F
1183 * depending on user settings.
1184 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001185 hw_dbg(hw, "Forcing Speed and Duplex\n");
1186 ret_val = e1000_phy_force_speed_duplex(hw);
1187 if (ret_val) {
1188 hw_dbg(hw, "Error Forcing Speed and Duplex\n");
1189 return ret_val;
1190 }
1191 }
1192
Bruce Allanad680762008-03-28 09:15:03 -07001193 /*
1194 * Check link status. Wait up to 100 microseconds for link to become
Auke Kokbc7f75f2007-09-17 12:30:59 -07001195 * valid.
1196 */
1197 ret_val = e1000e_phy_has_link_generic(hw,
1198 COPPER_LINK_UP_LIMIT,
1199 10,
1200 &link);
1201 if (ret_val)
1202 return ret_val;
1203
1204 if (link) {
1205 hw_dbg(hw, "Valid link established!!!\n");
1206 e1000e_config_collision_dist(hw);
1207 ret_val = e1000e_config_fc_after_link_up(hw);
1208 } else {
1209 hw_dbg(hw, "Unable to establish link!!!\n");
1210 }
1211
1212 return ret_val;
1213}
1214
1215/**
1216 * e1000e_phy_force_speed_duplex_igp - Force speed/duplex for igp PHY
1217 * @hw: pointer to the HW structure
1218 *
1219 * Calls the PHY setup function to force speed and duplex. Clears the
1220 * auto-crossover to force MDI manually. Waits for link and returns
1221 * successful if link up is successful, else -E1000_ERR_PHY (-2).
1222 **/
1223s32 e1000e_phy_force_speed_duplex_igp(struct e1000_hw *hw)
1224{
1225 struct e1000_phy_info *phy = &hw->phy;
1226 s32 ret_val;
1227 u16 phy_data;
1228 bool link;
1229
1230 ret_val = e1e_rphy(hw, PHY_CONTROL, &phy_data);
1231 if (ret_val)
1232 return ret_val;
1233
1234 e1000e_phy_force_speed_duplex_setup(hw, &phy_data);
1235
1236 ret_val = e1e_wphy(hw, PHY_CONTROL, phy_data);
1237 if (ret_val)
1238 return ret_val;
1239
Bruce Allanad680762008-03-28 09:15:03 -07001240 /*
1241 * Clear Auto-Crossover to force MDI manually. IGP requires MDI
Auke Kokbc7f75f2007-09-17 12:30:59 -07001242 * forced whenever speed and duplex are forced.
1243 */
1244 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1245 if (ret_val)
1246 return ret_val;
1247
1248 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1249 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1250
1251 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1252 if (ret_val)
1253 return ret_val;
1254
1255 hw_dbg(hw, "IGP PSCR: %X\n", phy_data);
1256
1257 udelay(1);
1258
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001259 if (phy->autoneg_wait_to_complete) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001260 hw_dbg(hw, "Waiting for forced speed/duplex link on IGP phy.\n");
1261
1262 ret_val = e1000e_phy_has_link_generic(hw,
1263 PHY_FORCE_LIMIT,
1264 100000,
1265 &link);
1266 if (ret_val)
1267 return ret_val;
1268
1269 if (!link)
1270 hw_dbg(hw, "Link taking longer than expected.\n");
1271
1272 /* Try once more */
1273 ret_val = e1000e_phy_has_link_generic(hw,
1274 PHY_FORCE_LIMIT,
1275 100000,
1276 &link);
1277 if (ret_val)
1278 return ret_val;
1279 }
1280
1281 return ret_val;
1282}
1283
1284/**
1285 * e1000e_phy_force_speed_duplex_m88 - Force speed/duplex for m88 PHY
1286 * @hw: pointer to the HW structure
1287 *
1288 * Calls the PHY setup function to force speed and duplex. Clears the
1289 * auto-crossover to force MDI manually. Resets the PHY to commit the
1290 * changes. If time expires while waiting for link up, we reset the DSP.
Bruce Allanad680762008-03-28 09:15:03 -07001291 * After reset, TX_CLK and CRS on Tx must be set. Return successful upon
Auke Kokbc7f75f2007-09-17 12:30:59 -07001292 * successful completion, else return corresponding error code.
1293 **/
1294s32 e1000e_phy_force_speed_duplex_m88(struct e1000_hw *hw)
1295{
1296 struct e1000_phy_info *phy = &hw->phy;
1297 s32 ret_val;
1298 u16 phy_data;
1299 bool link;
1300
Bruce Allanad680762008-03-28 09:15:03 -07001301 /*
1302 * Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
Auke Kokbc7f75f2007-09-17 12:30:59 -07001303 * forced whenever speed and duplex are forced.
1304 */
1305 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1306 if (ret_val)
1307 return ret_val;
1308
1309 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1310 ret_val = e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1311 if (ret_val)
1312 return ret_val;
1313
1314 hw_dbg(hw, "M88E1000 PSCR: %X\n", phy_data);
1315
1316 ret_val = e1e_rphy(hw, PHY_CONTROL, &phy_data);
1317 if (ret_val)
1318 return ret_val;
1319
1320 e1000e_phy_force_speed_duplex_setup(hw, &phy_data);
1321
Auke Kokbc7f75f2007-09-17 12:30:59 -07001322 ret_val = e1e_wphy(hw, PHY_CONTROL, phy_data);
1323 if (ret_val)
1324 return ret_val;
1325
Bruce Allan5aa49c82008-11-21 16:49:53 -08001326 /* Reset the phy to commit changes. */
1327 ret_val = e1000e_commit_phy(hw);
1328 if (ret_val)
1329 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001330
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001331 if (phy->autoneg_wait_to_complete) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001332 hw_dbg(hw, "Waiting for forced speed/duplex link on M88 phy.\n");
1333
1334 ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
1335 100000, &link);
1336 if (ret_val)
1337 return ret_val;
1338
1339 if (!link) {
Bruce Allanad680762008-03-28 09:15:03 -07001340 /*
1341 * We didn't get link.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001342 * Reset the DSP and cross our fingers.
1343 */
Bruce Allanad680762008-03-28 09:15:03 -07001344 ret_val = e1e_wphy(hw, M88E1000_PHY_PAGE_SELECT,
1345 0x001d);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001346 if (ret_val)
1347 return ret_val;
1348 ret_val = e1000e_phy_reset_dsp(hw);
1349 if (ret_val)
1350 return ret_val;
1351 }
1352
1353 /* Try once more */
1354 ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
1355 100000, &link);
1356 if (ret_val)
1357 return ret_val;
1358 }
1359
1360 ret_val = e1e_rphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1361 if (ret_val)
1362 return ret_val;
1363
Bruce Allanad680762008-03-28 09:15:03 -07001364 /*
1365 * Resetting the phy means we need to re-force TX_CLK in the
Auke Kokbc7f75f2007-09-17 12:30:59 -07001366 * Extended PHY Specific Control Register to 25MHz clock from
1367 * the reset value of 2.5MHz.
1368 */
1369 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1370 ret_val = e1e_wphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1371 if (ret_val)
1372 return ret_val;
1373
Bruce Allanad680762008-03-28 09:15:03 -07001374 /*
1375 * In addition, we must re-enable CRS on Tx for both half and full
Auke Kokbc7f75f2007-09-17 12:30:59 -07001376 * duplex.
1377 */
1378 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1379 if (ret_val)
1380 return ret_val;
1381
1382 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1383 ret_val = e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1384
1385 return ret_val;
1386}
1387
1388/**
1389 * e1000e_phy_force_speed_duplex_setup - Configure forced PHY speed/duplex
1390 * @hw: pointer to the HW structure
1391 * @phy_ctrl: pointer to current value of PHY_CONTROL
1392 *
1393 * Forces speed and duplex on the PHY by doing the following: disable flow
1394 * control, force speed/duplex on the MAC, disable auto speed detection,
1395 * disable auto-negotiation, configure duplex, configure speed, configure
1396 * the collision distance, write configuration to CTRL register. The
1397 * caller must write to the PHY_CONTROL register for these settings to
1398 * take affect.
1399 **/
1400void e1000e_phy_force_speed_duplex_setup(struct e1000_hw *hw, u16 *phy_ctrl)
1401{
1402 struct e1000_mac_info *mac = &hw->mac;
1403 u32 ctrl;
1404
1405 /* Turn off flow control when forcing speed/duplex */
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08001406 hw->fc.current_mode = e1000_fc_none;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001407
1408 /* Force speed/duplex on the mac */
1409 ctrl = er32(CTRL);
1410 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1411 ctrl &= ~E1000_CTRL_SPD_SEL;
1412
1413 /* Disable Auto Speed Detection */
1414 ctrl &= ~E1000_CTRL_ASDE;
1415
1416 /* Disable autoneg on the phy */
1417 *phy_ctrl &= ~MII_CR_AUTO_NEG_EN;
1418
1419 /* Forcing Full or Half Duplex? */
1420 if (mac->forced_speed_duplex & E1000_ALL_HALF_DUPLEX) {
1421 ctrl &= ~E1000_CTRL_FD;
1422 *phy_ctrl &= ~MII_CR_FULL_DUPLEX;
1423 hw_dbg(hw, "Half Duplex\n");
1424 } else {
1425 ctrl |= E1000_CTRL_FD;
1426 *phy_ctrl |= MII_CR_FULL_DUPLEX;
1427 hw_dbg(hw, "Full Duplex\n");
1428 }
1429
1430 /* Forcing 10mb or 100mb? */
1431 if (mac->forced_speed_duplex & E1000_ALL_100_SPEED) {
1432 ctrl |= E1000_CTRL_SPD_100;
1433 *phy_ctrl |= MII_CR_SPEED_100;
1434 *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
1435 hw_dbg(hw, "Forcing 100mb\n");
1436 } else {
1437 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1438 *phy_ctrl |= MII_CR_SPEED_10;
1439 *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
1440 hw_dbg(hw, "Forcing 10mb\n");
1441 }
1442
1443 e1000e_config_collision_dist(hw);
1444
1445 ew32(CTRL, ctrl);
1446}
1447
1448/**
1449 * e1000e_set_d3_lplu_state - Sets low power link up state for D3
1450 * @hw: pointer to the HW structure
1451 * @active: boolean used to enable/disable lplu
1452 *
1453 * Success returns 0, Failure returns 1
1454 *
1455 * The low power link up (lplu) state is set to the power management level D3
1456 * and SmartSpeed is disabled when active is true, else clear lplu for D3
1457 * and enable Smartspeed. LPLU and Smartspeed are mutually exclusive. LPLU
1458 * is used during Dx states where the power conservation is most important.
1459 * During driver activity, SmartSpeed should be enabled so performance is
1460 * maintained.
1461 **/
1462s32 e1000e_set_d3_lplu_state(struct e1000_hw *hw, bool active)
1463{
1464 struct e1000_phy_info *phy = &hw->phy;
1465 s32 ret_val;
1466 u16 data;
1467
1468 ret_val = e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &data);
1469 if (ret_val)
1470 return ret_val;
1471
1472 if (!active) {
1473 data &= ~IGP02E1000_PM_D3_LPLU;
David Graham2d9498f2008-04-23 11:09:14 -07001474 ret_val = e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001475 if (ret_val)
1476 return ret_val;
Bruce Allanad680762008-03-28 09:15:03 -07001477 /*
1478 * LPLU and SmartSpeed are mutually exclusive. LPLU is used
Auke Kokbc7f75f2007-09-17 12:30:59 -07001479 * during Dx states where the power conservation is most
1480 * important. During driver activity we should enable
Bruce Allanad680762008-03-28 09:15:03 -07001481 * SmartSpeed, so performance is maintained.
1482 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001483 if (phy->smart_speed == e1000_smart_speed_on) {
1484 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07001485 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001486 if (ret_val)
1487 return ret_val;
1488
1489 data |= IGP01E1000_PSCFR_SMART_SPEED;
1490 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07001491 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001492 if (ret_val)
1493 return ret_val;
1494 } else if (phy->smart_speed == e1000_smart_speed_off) {
1495 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07001496 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001497 if (ret_val)
1498 return ret_val;
1499
1500 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1501 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07001502 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001503 if (ret_val)
1504 return ret_val;
1505 }
1506 } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
1507 (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
1508 (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
1509 data |= IGP02E1000_PM_D3_LPLU;
1510 ret_val = e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, data);
1511 if (ret_val)
1512 return ret_val;
1513
1514 /* When LPLU is enabled, we should disable SmartSpeed */
1515 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
1516 if (ret_val)
1517 return ret_val;
1518
1519 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1520 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
1521 }
1522
1523 return ret_val;
1524}
1525
1526/**
Auke Kok489815c2008-02-21 15:11:07 -08001527 * e1000e_check_downshift - Checks whether a downshift in speed occurred
Auke Kokbc7f75f2007-09-17 12:30:59 -07001528 * @hw: pointer to the HW structure
1529 *
1530 * Success returns 0, Failure returns 1
1531 *
1532 * A downshift is detected by querying the PHY link health.
1533 **/
1534s32 e1000e_check_downshift(struct e1000_hw *hw)
1535{
1536 struct e1000_phy_info *phy = &hw->phy;
1537 s32 ret_val;
1538 u16 phy_data, offset, mask;
1539
1540 switch (phy->type) {
1541 case e1000_phy_m88:
1542 case e1000_phy_gg82563:
Bruce Allana4f58f52009-06-02 11:29:18 +00001543 case e1000_phy_82578:
1544 case e1000_phy_82577:
Auke Kokbc7f75f2007-09-17 12:30:59 -07001545 offset = M88E1000_PHY_SPEC_STATUS;
1546 mask = M88E1000_PSSR_DOWNSHIFT;
1547 break;
1548 case e1000_phy_igp_2:
1549 case e1000_phy_igp_3:
1550 offset = IGP01E1000_PHY_LINK_HEALTH;
1551 mask = IGP01E1000_PLHR_SS_DOWNGRADE;
1552 break;
1553 default:
1554 /* speed downshift not supported */
1555 phy->speed_downgraded = 0;
1556 return 0;
1557 }
1558
1559 ret_val = e1e_rphy(hw, offset, &phy_data);
1560
1561 if (!ret_val)
1562 phy->speed_downgraded = (phy_data & mask);
1563
1564 return ret_val;
1565}
1566
1567/**
1568 * e1000_check_polarity_m88 - Checks the polarity.
1569 * @hw: pointer to the HW structure
1570 *
1571 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1572 *
1573 * Polarity is determined based on the PHY specific status register.
1574 **/
1575static s32 e1000_check_polarity_m88(struct e1000_hw *hw)
1576{
1577 struct e1000_phy_info *phy = &hw->phy;
1578 s32 ret_val;
1579 u16 data;
1580
1581 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &data);
1582
1583 if (!ret_val)
1584 phy->cable_polarity = (data & M88E1000_PSSR_REV_POLARITY)
1585 ? e1000_rev_polarity_reversed
1586 : e1000_rev_polarity_normal;
1587
1588 return ret_val;
1589}
1590
1591/**
1592 * e1000_check_polarity_igp - Checks the polarity.
1593 * @hw: pointer to the HW structure
1594 *
1595 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1596 *
1597 * Polarity is determined based on the PHY port status register, and the
1598 * current speed (since there is no polarity at 100Mbps).
1599 **/
1600static s32 e1000_check_polarity_igp(struct e1000_hw *hw)
1601{
1602 struct e1000_phy_info *phy = &hw->phy;
1603 s32 ret_val;
1604 u16 data, offset, mask;
1605
Bruce Allanad680762008-03-28 09:15:03 -07001606 /*
1607 * Polarity is determined based on the speed of
1608 * our connection.
1609 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001610 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_STATUS, &data);
1611 if (ret_val)
1612 return ret_val;
1613
1614 if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
1615 IGP01E1000_PSSR_SPEED_1000MBPS) {
1616 offset = IGP01E1000_PHY_PCS_INIT_REG;
1617 mask = IGP01E1000_PHY_POLARITY_MASK;
1618 } else {
Bruce Allanad680762008-03-28 09:15:03 -07001619 /*
1620 * This really only applies to 10Mbps since
Auke Kokbc7f75f2007-09-17 12:30:59 -07001621 * there is no polarity for 100Mbps (always 0).
1622 */
1623 offset = IGP01E1000_PHY_PORT_STATUS;
1624 mask = IGP01E1000_PSSR_POLARITY_REVERSED;
1625 }
1626
1627 ret_val = e1e_rphy(hw, offset, &data);
1628
1629 if (!ret_val)
1630 phy->cable_polarity = (data & mask)
1631 ? e1000_rev_polarity_reversed
1632 : e1000_rev_polarity_normal;
1633
1634 return ret_val;
1635}
1636
1637/**
Bruce Allanad680762008-03-28 09:15:03 -07001638 * e1000_wait_autoneg - Wait for auto-neg completion
Auke Kokbc7f75f2007-09-17 12:30:59 -07001639 * @hw: pointer to the HW structure
1640 *
1641 * Waits for auto-negotiation to complete or for the auto-negotiation time
1642 * limit to expire, which ever happens first.
1643 **/
1644static s32 e1000_wait_autoneg(struct e1000_hw *hw)
1645{
1646 s32 ret_val = 0;
1647 u16 i, phy_status;
1648
1649 /* Break after autoneg completes or PHY_AUTO_NEG_LIMIT expires. */
1650 for (i = PHY_AUTO_NEG_LIMIT; i > 0; i--) {
1651 ret_val = e1e_rphy(hw, PHY_STATUS, &phy_status);
1652 if (ret_val)
1653 break;
1654 ret_val = e1e_rphy(hw, PHY_STATUS, &phy_status);
1655 if (ret_val)
1656 break;
1657 if (phy_status & MII_SR_AUTONEG_COMPLETE)
1658 break;
1659 msleep(100);
1660 }
1661
Bruce Allanad680762008-03-28 09:15:03 -07001662 /*
1663 * PHY_AUTO_NEG_TIME expiration doesn't guarantee auto-negotiation
Auke Kokbc7f75f2007-09-17 12:30:59 -07001664 * has completed.
1665 */
1666 return ret_val;
1667}
1668
1669/**
1670 * e1000e_phy_has_link_generic - Polls PHY for link
1671 * @hw: pointer to the HW structure
1672 * @iterations: number of times to poll for link
1673 * @usec_interval: delay between polling attempts
1674 * @success: pointer to whether polling was successful or not
1675 *
1676 * Polls the PHY status register for link, 'iterations' number of times.
1677 **/
1678s32 e1000e_phy_has_link_generic(struct e1000_hw *hw, u32 iterations,
1679 u32 usec_interval, bool *success)
1680{
1681 s32 ret_val = 0;
1682 u16 i, phy_status;
1683
1684 for (i = 0; i < iterations; i++) {
Bruce Allanad680762008-03-28 09:15:03 -07001685 /*
1686 * Some PHYs require the PHY_STATUS register to be read
Auke Kokbc7f75f2007-09-17 12:30:59 -07001687 * twice due to the link bit being sticky. No harm doing
1688 * it across the board.
1689 */
1690 ret_val = e1e_rphy(hw, PHY_STATUS, &phy_status);
1691 if (ret_val)
Bruce Allan906e8d92009-07-01 13:28:50 +00001692 /*
1693 * If the first read fails, another entity may have
1694 * ownership of the resources, wait and try again to
1695 * see if they have relinquished the resources yet.
1696 */
1697 udelay(usec_interval);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001698 ret_val = e1e_rphy(hw, PHY_STATUS, &phy_status);
1699 if (ret_val)
1700 break;
1701 if (phy_status & MII_SR_LINK_STATUS)
1702 break;
1703 if (usec_interval >= 1000)
1704 mdelay(usec_interval/1000);
1705 else
1706 udelay(usec_interval);
1707 }
1708
1709 *success = (i < iterations);
1710
1711 return ret_val;
1712}
1713
1714/**
1715 * e1000e_get_cable_length_m88 - Determine cable length for m88 PHY
1716 * @hw: pointer to the HW structure
1717 *
1718 * Reads the PHY specific status register to retrieve the cable length
1719 * information. The cable length is determined by averaging the minimum and
1720 * maximum values to get the "average" cable length. The m88 PHY has four
1721 * possible cable length values, which are:
1722 * Register Value Cable Length
1723 * 0 < 50 meters
1724 * 1 50 - 80 meters
1725 * 2 80 - 110 meters
1726 * 3 110 - 140 meters
1727 * 4 > 140 meters
1728 **/
1729s32 e1000e_get_cable_length_m88(struct e1000_hw *hw)
1730{
1731 struct e1000_phy_info *phy = &hw->phy;
1732 s32 ret_val;
1733 u16 phy_data, index;
1734
1735 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
1736 if (ret_val)
1737 return ret_val;
1738
1739 index = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
1740 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
1741 phy->min_cable_length = e1000_m88_cable_length_table[index];
1742 phy->max_cable_length = e1000_m88_cable_length_table[index+1];
1743
1744 phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
1745
1746 return ret_val;
1747}
1748
1749/**
1750 * e1000e_get_cable_length_igp_2 - Determine cable length for igp2 PHY
1751 * @hw: pointer to the HW structure
1752 *
1753 * The automatic gain control (agc) normalizes the amplitude of the
1754 * received signal, adjusting for the attenuation produced by the
Auke Kok489815c2008-02-21 15:11:07 -08001755 * cable. By reading the AGC registers, which represent the
1756 * combination of course and fine gain value, the value can be put
Auke Kokbc7f75f2007-09-17 12:30:59 -07001757 * into a lookup table to obtain the approximate cable length
1758 * for each channel.
1759 **/
1760s32 e1000e_get_cable_length_igp_2(struct e1000_hw *hw)
1761{
1762 struct e1000_phy_info *phy = &hw->phy;
1763 s32 ret_val;
1764 u16 phy_data, i, agc_value = 0;
1765 u16 cur_agc_index, max_agc_index = 0;
1766 u16 min_agc_index = IGP02E1000_CABLE_LENGTH_TABLE_SIZE - 1;
1767 u16 agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] =
1768 {IGP02E1000_PHY_AGC_A,
1769 IGP02E1000_PHY_AGC_B,
1770 IGP02E1000_PHY_AGC_C,
1771 IGP02E1000_PHY_AGC_D};
1772
1773 /* Read the AGC registers for all channels */
1774 for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
1775 ret_val = e1e_rphy(hw, agc_reg_array[i], &phy_data);
1776 if (ret_val)
1777 return ret_val;
1778
Bruce Allanad680762008-03-28 09:15:03 -07001779 /*
1780 * Getting bits 15:9, which represent the combination of
Auke Kokbc7f75f2007-09-17 12:30:59 -07001781 * course and fine gain values. The result is a number
1782 * that can be put into the lookup table to obtain the
Bruce Allanad680762008-03-28 09:15:03 -07001783 * approximate cable length.
1784 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001785 cur_agc_index = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
1786 IGP02E1000_AGC_LENGTH_MASK;
1787
1788 /* Array index bound check. */
1789 if ((cur_agc_index >= IGP02E1000_CABLE_LENGTH_TABLE_SIZE) ||
1790 (cur_agc_index == 0))
1791 return -E1000_ERR_PHY;
1792
1793 /* Remove min & max AGC values from calculation. */
1794 if (e1000_igp_2_cable_length_table[min_agc_index] >
1795 e1000_igp_2_cable_length_table[cur_agc_index])
1796 min_agc_index = cur_agc_index;
1797 if (e1000_igp_2_cable_length_table[max_agc_index] <
1798 e1000_igp_2_cable_length_table[cur_agc_index])
1799 max_agc_index = cur_agc_index;
1800
1801 agc_value += e1000_igp_2_cable_length_table[cur_agc_index];
1802 }
1803
1804 agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] +
1805 e1000_igp_2_cable_length_table[max_agc_index]);
1806 agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
1807
1808 /* Calculate cable length with the error range of +/- 10 meters. */
1809 phy->min_cable_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
1810 (agc_value - IGP02E1000_AGC_RANGE) : 0;
1811 phy->max_cable_length = agc_value + IGP02E1000_AGC_RANGE;
1812
1813 phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
1814
1815 return ret_val;
1816}
1817
1818/**
1819 * e1000e_get_phy_info_m88 - Retrieve PHY information
1820 * @hw: pointer to the HW structure
1821 *
1822 * Valid for only copper links. Read the PHY status register (sticky read)
1823 * to verify that link is up. Read the PHY special control register to
1824 * determine the polarity and 10base-T extended distance. Read the PHY
1825 * special status register to determine MDI/MDIx and current speed. If
1826 * speed is 1000, then determine cable length, local and remote receiver.
1827 **/
1828s32 e1000e_get_phy_info_m88(struct e1000_hw *hw)
1829{
1830 struct e1000_phy_info *phy = &hw->phy;
1831 s32 ret_val;
1832 u16 phy_data;
1833 bool link;
1834
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001835 if (hw->phy.media_type != e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001836 hw_dbg(hw, "Phy info is only valid for copper media\n");
1837 return -E1000_ERR_CONFIG;
1838 }
1839
1840 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
1841 if (ret_val)
1842 return ret_val;
1843
1844 if (!link) {
1845 hw_dbg(hw, "Phy info is only valid if link is up\n");
1846 return -E1000_ERR_CONFIG;
1847 }
1848
1849 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1850 if (ret_val)
1851 return ret_val;
1852
1853 phy->polarity_correction = (phy_data &
1854 M88E1000_PSCR_POLARITY_REVERSAL);
1855
1856 ret_val = e1000_check_polarity_m88(hw);
1857 if (ret_val)
1858 return ret_val;
1859
1860 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
1861 if (ret_val)
1862 return ret_val;
1863
1864 phy->is_mdix = (phy_data & M88E1000_PSSR_MDIX);
1865
1866 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
1867 ret_val = e1000_get_cable_length(hw);
1868 if (ret_val)
1869 return ret_val;
1870
1871 ret_val = e1e_rphy(hw, PHY_1000T_STATUS, &phy_data);
1872 if (ret_val)
1873 return ret_val;
1874
1875 phy->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS)
1876 ? e1000_1000t_rx_status_ok
1877 : e1000_1000t_rx_status_not_ok;
1878
1879 phy->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS)
1880 ? e1000_1000t_rx_status_ok
1881 : e1000_1000t_rx_status_not_ok;
1882 } else {
1883 /* Set values to "undefined" */
1884 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
1885 phy->local_rx = e1000_1000t_rx_status_undefined;
1886 phy->remote_rx = e1000_1000t_rx_status_undefined;
1887 }
1888
1889 return ret_val;
1890}
1891
1892/**
1893 * e1000e_get_phy_info_igp - Retrieve igp PHY information
1894 * @hw: pointer to the HW structure
1895 *
1896 * Read PHY status to determine if link is up. If link is up, then
1897 * set/determine 10base-T extended distance and polarity correction. Read
1898 * PHY port status to determine MDI/MDIx and speed. Based on the speed,
1899 * determine on the cable length, local and remote receiver.
1900 **/
1901s32 e1000e_get_phy_info_igp(struct e1000_hw *hw)
1902{
1903 struct e1000_phy_info *phy = &hw->phy;
1904 s32 ret_val;
1905 u16 data;
1906 bool link;
1907
1908 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
1909 if (ret_val)
1910 return ret_val;
1911
1912 if (!link) {
1913 hw_dbg(hw, "Phy info is only valid if link is up\n");
1914 return -E1000_ERR_CONFIG;
1915 }
1916
1917 phy->polarity_correction = 1;
1918
1919 ret_val = e1000_check_polarity_igp(hw);
1920 if (ret_val)
1921 return ret_val;
1922
1923 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_STATUS, &data);
1924 if (ret_val)
1925 return ret_val;
1926
1927 phy->is_mdix = (data & IGP01E1000_PSSR_MDIX);
1928
1929 if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
1930 IGP01E1000_PSSR_SPEED_1000MBPS) {
1931 ret_val = e1000_get_cable_length(hw);
1932 if (ret_val)
1933 return ret_val;
1934
1935 ret_val = e1e_rphy(hw, PHY_1000T_STATUS, &data);
1936 if (ret_val)
1937 return ret_val;
1938
1939 phy->local_rx = (data & SR_1000T_LOCAL_RX_STATUS)
1940 ? e1000_1000t_rx_status_ok
1941 : e1000_1000t_rx_status_not_ok;
1942
1943 phy->remote_rx = (data & SR_1000T_REMOTE_RX_STATUS)
1944 ? e1000_1000t_rx_status_ok
1945 : e1000_1000t_rx_status_not_ok;
1946 } else {
1947 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
1948 phy->local_rx = e1000_1000t_rx_status_undefined;
1949 phy->remote_rx = e1000_1000t_rx_status_undefined;
1950 }
1951
1952 return ret_val;
1953}
1954
1955/**
1956 * e1000e_phy_sw_reset - PHY software reset
1957 * @hw: pointer to the HW structure
1958 *
1959 * Does a software reset of the PHY by reading the PHY control register and
1960 * setting/write the control register reset bit to the PHY.
1961 **/
1962s32 e1000e_phy_sw_reset(struct e1000_hw *hw)
1963{
1964 s32 ret_val;
1965 u16 phy_ctrl;
1966
1967 ret_val = e1e_rphy(hw, PHY_CONTROL, &phy_ctrl);
1968 if (ret_val)
1969 return ret_val;
1970
1971 phy_ctrl |= MII_CR_RESET;
1972 ret_val = e1e_wphy(hw, PHY_CONTROL, phy_ctrl);
1973 if (ret_val)
1974 return ret_val;
1975
1976 udelay(1);
1977
1978 return ret_val;
1979}
1980
1981/**
1982 * e1000e_phy_hw_reset_generic - PHY hardware reset
1983 * @hw: pointer to the HW structure
1984 *
1985 * Verify the reset block is not blocking us from resetting. Acquire
1986 * semaphore (if necessary) and read/set/write the device control reset
1987 * bit in the PHY. Wait the appropriate delay time for the device to
Auke Kok489815c2008-02-21 15:11:07 -08001988 * reset and release the semaphore (if necessary).
Auke Kokbc7f75f2007-09-17 12:30:59 -07001989 **/
1990s32 e1000e_phy_hw_reset_generic(struct e1000_hw *hw)
1991{
1992 struct e1000_phy_info *phy = &hw->phy;
1993 s32 ret_val;
1994 u32 ctrl;
1995
1996 ret_val = e1000_check_reset_block(hw);
1997 if (ret_val)
1998 return 0;
1999
2000 ret_val = phy->ops.acquire_phy(hw);
2001 if (ret_val)
2002 return ret_val;
2003
2004 ctrl = er32(CTRL);
2005 ew32(CTRL, ctrl | E1000_CTRL_PHY_RST);
2006 e1e_flush();
2007
2008 udelay(phy->reset_delay_us);
2009
2010 ew32(CTRL, ctrl);
2011 e1e_flush();
2012
2013 udelay(150);
2014
2015 phy->ops.release_phy(hw);
2016
2017 return e1000_get_phy_cfg_done(hw);
2018}
2019
2020/**
2021 * e1000e_get_cfg_done - Generic configuration done
2022 * @hw: pointer to the HW structure
2023 *
2024 * Generic function to wait 10 milli-seconds for configuration to complete
2025 * and return success.
2026 **/
2027s32 e1000e_get_cfg_done(struct e1000_hw *hw)
2028{
2029 mdelay(10);
2030 return 0;
2031}
2032
Bruce Allanf4187b52008-08-26 18:36:50 -07002033/**
2034 * e1000e_phy_init_script_igp3 - Inits the IGP3 PHY
2035 * @hw: pointer to the HW structure
2036 *
2037 * Initializes a Intel Gigabit PHY3 when an EEPROM is not present.
2038 **/
2039s32 e1000e_phy_init_script_igp3(struct e1000_hw *hw)
2040{
2041 hw_dbg(hw, "Running IGP 3 PHY init script\n");
2042
2043 /* PHY init IGP 3 */
2044 /* Enable rise/fall, 10-mode work in class-A */
2045 e1e_wphy(hw, 0x2F5B, 0x9018);
2046 /* Remove all caps from Replica path filter */
2047 e1e_wphy(hw, 0x2F52, 0x0000);
2048 /* Bias trimming for ADC, AFE and Driver (Default) */
2049 e1e_wphy(hw, 0x2FB1, 0x8B24);
2050 /* Increase Hybrid poly bias */
2051 e1e_wphy(hw, 0x2FB2, 0xF8F0);
2052 /* Add 4% to Tx amplitude in Gig mode */
2053 e1e_wphy(hw, 0x2010, 0x10B0);
2054 /* Disable trimming (TTT) */
2055 e1e_wphy(hw, 0x2011, 0x0000);
2056 /* Poly DC correction to 94.6% + 2% for all channels */
2057 e1e_wphy(hw, 0x20DD, 0x249A);
2058 /* ABS DC correction to 95.9% */
2059 e1e_wphy(hw, 0x20DE, 0x00D3);
2060 /* BG temp curve trim */
2061 e1e_wphy(hw, 0x28B4, 0x04CE);
2062 /* Increasing ADC OPAMP stage 1 currents to max */
2063 e1e_wphy(hw, 0x2F70, 0x29E4);
2064 /* Force 1000 ( required for enabling PHY regs configuration) */
2065 e1e_wphy(hw, 0x0000, 0x0140);
2066 /* Set upd_freq to 6 */
2067 e1e_wphy(hw, 0x1F30, 0x1606);
2068 /* Disable NPDFE */
2069 e1e_wphy(hw, 0x1F31, 0xB814);
2070 /* Disable adaptive fixed FFE (Default) */
2071 e1e_wphy(hw, 0x1F35, 0x002A);
2072 /* Enable FFE hysteresis */
2073 e1e_wphy(hw, 0x1F3E, 0x0067);
2074 /* Fixed FFE for short cable lengths */
2075 e1e_wphy(hw, 0x1F54, 0x0065);
2076 /* Fixed FFE for medium cable lengths */
2077 e1e_wphy(hw, 0x1F55, 0x002A);
2078 /* Fixed FFE for long cable lengths */
2079 e1e_wphy(hw, 0x1F56, 0x002A);
2080 /* Enable Adaptive Clip Threshold */
2081 e1e_wphy(hw, 0x1F72, 0x3FB0);
2082 /* AHT reset limit to 1 */
2083 e1e_wphy(hw, 0x1F76, 0xC0FF);
2084 /* Set AHT master delay to 127 msec */
2085 e1e_wphy(hw, 0x1F77, 0x1DEC);
2086 /* Set scan bits for AHT */
2087 e1e_wphy(hw, 0x1F78, 0xF9EF);
2088 /* Set AHT Preset bits */
2089 e1e_wphy(hw, 0x1F79, 0x0210);
2090 /* Change integ_factor of channel A to 3 */
2091 e1e_wphy(hw, 0x1895, 0x0003);
2092 /* Change prop_factor of channels BCD to 8 */
2093 e1e_wphy(hw, 0x1796, 0x0008);
2094 /* Change cg_icount + enable integbp for channels BCD */
2095 e1e_wphy(hw, 0x1798, 0xD008);
2096 /*
2097 * Change cg_icount + enable integbp + change prop_factor_master
2098 * to 8 for channel A
2099 */
2100 e1e_wphy(hw, 0x1898, 0xD918);
2101 /* Disable AHT in Slave mode on channel A */
2102 e1e_wphy(hw, 0x187A, 0x0800);
2103 /*
2104 * Enable LPLU and disable AN to 1000 in non-D0a states,
2105 * Enable SPD+B2B
2106 */
2107 e1e_wphy(hw, 0x0019, 0x008D);
2108 /* Enable restart AN on an1000_dis change */
2109 e1e_wphy(hw, 0x001B, 0x2080);
2110 /* Enable wh_fifo read clock in 10/100 modes */
2111 e1e_wphy(hw, 0x0014, 0x0045);
2112 /* Restart AN, Speed selection is 1000 */
2113 e1e_wphy(hw, 0x0000, 0x1340);
2114
2115 return 0;
2116}
2117
Auke Kokbc7f75f2007-09-17 12:30:59 -07002118/* Internal function pointers */
2119
2120/**
2121 * e1000_get_phy_cfg_done - Generic PHY configuration done
2122 * @hw: pointer to the HW structure
2123 *
2124 * Return success if silicon family did not implement a family specific
2125 * get_cfg_done function.
2126 **/
2127static s32 e1000_get_phy_cfg_done(struct e1000_hw *hw)
2128{
2129 if (hw->phy.ops.get_cfg_done)
2130 return hw->phy.ops.get_cfg_done(hw);
2131
2132 return 0;
2133}
2134
2135/**
2136 * e1000_phy_force_speed_duplex - Generic force PHY speed/duplex
2137 * @hw: pointer to the HW structure
2138 *
2139 * When the silicon family has not implemented a forced speed/duplex
2140 * function for the PHY, simply return 0.
2141 **/
2142static s32 e1000_phy_force_speed_duplex(struct e1000_hw *hw)
2143{
2144 if (hw->phy.ops.force_speed_duplex)
2145 return hw->phy.ops.force_speed_duplex(hw);
2146
2147 return 0;
2148}
2149
2150/**
2151 * e1000e_get_phy_type_from_id - Get PHY type from id
2152 * @phy_id: phy_id read from the phy
2153 *
2154 * Returns the phy type from the id.
2155 **/
2156enum e1000_phy_type e1000e_get_phy_type_from_id(u32 phy_id)
2157{
2158 enum e1000_phy_type phy_type = e1000_phy_unknown;
2159
2160 switch (phy_id) {
2161 case M88E1000_I_PHY_ID:
2162 case M88E1000_E_PHY_ID:
2163 case M88E1111_I_PHY_ID:
2164 case M88E1011_I_PHY_ID:
2165 phy_type = e1000_phy_m88;
2166 break;
2167 case IGP01E1000_I_PHY_ID: /* IGP 1 & 2 share this */
2168 phy_type = e1000_phy_igp_2;
2169 break;
2170 case GG82563_E_PHY_ID:
2171 phy_type = e1000_phy_gg82563;
2172 break;
2173 case IGP03E1000_E_PHY_ID:
2174 phy_type = e1000_phy_igp_3;
2175 break;
2176 case IFE_E_PHY_ID:
2177 case IFE_PLUS_E_PHY_ID:
2178 case IFE_C_E_PHY_ID:
2179 phy_type = e1000_phy_ife;
2180 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002181 case BME1000_E_PHY_ID:
2182 case BME1000_E_PHY_ID_R2:
2183 phy_type = e1000_phy_bm;
2184 break;
Bruce Allana4f58f52009-06-02 11:29:18 +00002185 case I82578_E_PHY_ID:
2186 phy_type = e1000_phy_82578;
2187 break;
2188 case I82577_E_PHY_ID:
2189 phy_type = e1000_phy_82577;
2190 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002191 default:
2192 phy_type = e1000_phy_unknown;
2193 break;
2194 }
2195 return phy_type;
2196}
2197
2198/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002199 * e1000e_determine_phy_address - Determines PHY address.
2200 * @hw: pointer to the HW structure
2201 *
2202 * This uses a trial and error method to loop through possible PHY
2203 * addresses. It tests each by reading the PHY ID registers and
2204 * checking for a match.
2205 **/
2206s32 e1000e_determine_phy_address(struct e1000_hw *hw)
2207{
2208 s32 ret_val = -E1000_ERR_PHY_TYPE;
2209 u32 phy_addr= 0;
2210 u32 i = 0;
2211 enum e1000_phy_type phy_type = e1000_phy_unknown;
2212
2213 do {
2214 for (phy_addr = 0; phy_addr < 4; phy_addr++) {
2215 hw->phy.addr = phy_addr;
2216 e1000e_get_phy_id(hw);
2217 phy_type = e1000e_get_phy_type_from_id(hw->phy.id);
2218
2219 /*
2220 * If phy_type is valid, break - we found our
2221 * PHY address
2222 */
2223 if (phy_type != e1000_phy_unknown) {
2224 ret_val = 0;
2225 break;
2226 }
2227 }
2228 i++;
2229 } while ((ret_val != 0) && (i < 100));
2230
2231 return ret_val;
2232}
2233
2234/**
2235 * e1000_get_phy_addr_for_bm_page - Retrieve PHY page address
2236 * @page: page to access
2237 *
2238 * Returns the phy address for the page requested.
2239 **/
2240static u32 e1000_get_phy_addr_for_bm_page(u32 page, u32 reg)
2241{
2242 u32 phy_addr = 2;
2243
2244 if ((page >= 768) || (page == 0 && reg == 25) || (reg == 31))
2245 phy_addr = 1;
2246
2247 return phy_addr;
2248}
2249
2250/**
2251 * e1000e_write_phy_reg_bm - Write BM PHY register
2252 * @hw: pointer to the HW structure
2253 * @offset: register offset to write to
2254 * @data: data to write at register offset
2255 *
2256 * Acquires semaphore, if necessary, then writes the data to PHY register
2257 * at the offset. Release any acquired semaphores before exiting.
2258 **/
2259s32 e1000e_write_phy_reg_bm(struct e1000_hw *hw, u32 offset, u16 data)
2260{
2261 s32 ret_val;
2262 u32 page_select = 0;
2263 u32 page = offset >> IGP_PAGE_SHIFT;
2264 u32 page_shift = 0;
2265
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002266 ret_val = hw->phy.ops.acquire_phy(hw);
2267 if (ret_val)
2268 return ret_val;
2269
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002270 /* Page 800 works differently than the rest so it has its own func */
2271 if (page == BM_WUC_PAGE) {
2272 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, &data,
2273 false);
2274 goto out;
2275 }
2276
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002277 hw->phy.addr = e1000_get_phy_addr_for_bm_page(page, offset);
2278
2279 if (offset > MAX_PHY_MULTI_PAGE_REG) {
2280 /*
2281 * Page select is register 31 for phy address 1 and 22 for
2282 * phy address 2 and 3. Page select is shifted only for
2283 * phy address 1.
2284 */
2285 if (hw->phy.addr == 1) {
2286 page_shift = IGP_PAGE_SHIFT;
2287 page_select = IGP01E1000_PHY_PAGE_SELECT;
2288 } else {
2289 page_shift = 0;
2290 page_select = BM_PHY_PAGE_SELECT;
2291 }
2292
2293 /* Page is shifted left, PHY expects (page x 32) */
2294 ret_val = e1000e_write_phy_reg_mdic(hw, page_select,
2295 (page << page_shift));
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002296 if (ret_val)
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002297 goto out;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002298 }
2299
2300 ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
2301 data);
2302
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002303out:
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002304 hw->phy.ops.release_phy(hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002305 return ret_val;
2306}
2307
2308/**
2309 * e1000e_read_phy_reg_bm - Read BM PHY register
2310 * @hw: pointer to the HW structure
2311 * @offset: register offset to be read
2312 * @data: pointer to the read data
2313 *
2314 * Acquires semaphore, if necessary, then reads the PHY register at offset
2315 * and storing the retrieved information in data. Release any acquired
2316 * semaphores before exiting.
2317 **/
2318s32 e1000e_read_phy_reg_bm(struct e1000_hw *hw, u32 offset, u16 *data)
2319{
2320 s32 ret_val;
2321 u32 page_select = 0;
2322 u32 page = offset >> IGP_PAGE_SHIFT;
2323 u32 page_shift = 0;
2324
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002325 ret_val = hw->phy.ops.acquire_phy(hw);
2326 if (ret_val)
2327 return ret_val;
2328
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002329 /* Page 800 works differently than the rest so it has its own func */
2330 if (page == BM_WUC_PAGE) {
2331 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, data,
2332 true);
2333 goto out;
2334 }
2335
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002336 hw->phy.addr = e1000_get_phy_addr_for_bm_page(page, offset);
2337
2338 if (offset > MAX_PHY_MULTI_PAGE_REG) {
2339 /*
2340 * Page select is register 31 for phy address 1 and 22 for
2341 * phy address 2 and 3. Page select is shifted only for
2342 * phy address 1.
2343 */
2344 if (hw->phy.addr == 1) {
2345 page_shift = IGP_PAGE_SHIFT;
2346 page_select = IGP01E1000_PHY_PAGE_SELECT;
2347 } else {
2348 page_shift = 0;
2349 page_select = BM_PHY_PAGE_SELECT;
2350 }
2351
2352 /* Page is shifted left, PHY expects (page x 32) */
2353 ret_val = e1000e_write_phy_reg_mdic(hw, page_select,
2354 (page << page_shift));
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002355 if (ret_val)
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002356 goto out;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002357 }
2358
2359 ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
2360 data);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002361out:
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002362 hw->phy.ops.release_phy(hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002363 return ret_val;
2364}
2365
2366/**
Bruce Allan4662e822008-08-26 18:37:06 -07002367 * e1000e_read_phy_reg_bm2 - Read BM PHY register
2368 * @hw: pointer to the HW structure
2369 * @offset: register offset to be read
2370 * @data: pointer to the read data
2371 *
2372 * Acquires semaphore, if necessary, then reads the PHY register at offset
2373 * and storing the retrieved information in data. Release any acquired
2374 * semaphores before exiting.
2375 **/
2376s32 e1000e_read_phy_reg_bm2(struct e1000_hw *hw, u32 offset, u16 *data)
2377{
2378 s32 ret_val;
2379 u16 page = (u16)(offset >> IGP_PAGE_SHIFT);
2380
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002381 ret_val = hw->phy.ops.acquire_phy(hw);
2382 if (ret_val)
2383 return ret_val;
2384
Bruce Allan4662e822008-08-26 18:37:06 -07002385 /* Page 800 works differently than the rest so it has its own func */
2386 if (page == BM_WUC_PAGE) {
2387 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, data,
2388 true);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002389 goto out;
Bruce Allan4662e822008-08-26 18:37:06 -07002390 }
2391
Bruce Allan4662e822008-08-26 18:37:06 -07002392 hw->phy.addr = 1;
2393
2394 if (offset > MAX_PHY_MULTI_PAGE_REG) {
2395
2396 /* Page is shifted left, PHY expects (page x 32) */
2397 ret_val = e1000e_write_phy_reg_mdic(hw, BM_PHY_PAGE_SELECT,
2398 page);
2399
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002400 if (ret_val)
2401 goto out;
Bruce Allan4662e822008-08-26 18:37:06 -07002402 }
2403
2404 ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
2405 data);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002406out:
Bruce Allan4662e822008-08-26 18:37:06 -07002407 hw->phy.ops.release_phy(hw);
Bruce Allan4662e822008-08-26 18:37:06 -07002408 return ret_val;
2409}
2410
2411/**
2412 * e1000e_write_phy_reg_bm2 - Write BM PHY register
2413 * @hw: pointer to the HW structure
2414 * @offset: register offset to write to
2415 * @data: data to write at register offset
2416 *
2417 * Acquires semaphore, if necessary, then writes the data to PHY register
2418 * at the offset. Release any acquired semaphores before exiting.
2419 **/
2420s32 e1000e_write_phy_reg_bm2(struct e1000_hw *hw, u32 offset, u16 data)
2421{
2422 s32 ret_val;
2423 u16 page = (u16)(offset >> IGP_PAGE_SHIFT);
2424
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002425 ret_val = hw->phy.ops.acquire_phy(hw);
2426 if (ret_val)
2427 return ret_val;
2428
Bruce Allan4662e822008-08-26 18:37:06 -07002429 /* Page 800 works differently than the rest so it has its own func */
2430 if (page == BM_WUC_PAGE) {
2431 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, &data,
2432 false);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002433 goto out;
Bruce Allan4662e822008-08-26 18:37:06 -07002434 }
2435
Bruce Allan4662e822008-08-26 18:37:06 -07002436 hw->phy.addr = 1;
2437
2438 if (offset > MAX_PHY_MULTI_PAGE_REG) {
2439 /* Page is shifted left, PHY expects (page x 32) */
2440 ret_val = e1000e_write_phy_reg_mdic(hw, BM_PHY_PAGE_SELECT,
2441 page);
2442
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002443 if (ret_val)
2444 goto out;
Bruce Allan4662e822008-08-26 18:37:06 -07002445 }
2446
2447 ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
2448 data);
2449
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002450out:
Bruce Allan4662e822008-08-26 18:37:06 -07002451 hw->phy.ops.release_phy(hw);
Bruce Allan4662e822008-08-26 18:37:06 -07002452 return ret_val;
2453}
2454
2455/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002456 * e1000_access_phy_wakeup_reg_bm - Read BM PHY wakeup register
2457 * @hw: pointer to the HW structure
2458 * @offset: register offset to be read or written
2459 * @data: pointer to the data to read or write
2460 * @read: determines if operation is read or write
2461 *
2462 * Acquires semaphore, if necessary, then reads the PHY register at offset
2463 * and storing the retrieved information in data. Release any acquired
2464 * semaphores before exiting. Note that procedure to read the wakeup
2465 * registers are different. It works as such:
2466 * 1) Set page 769, register 17, bit 2 = 1
2467 * 2) Set page to 800 for host (801 if we were manageability)
2468 * 3) Write the address using the address opcode (0x11)
2469 * 4) Read or write the data using the data opcode (0x12)
2470 * 5) Restore 769_17.2 to its original value
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002471 *
2472 * Assumes semaphore already acquired.
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002473 **/
2474static s32 e1000_access_phy_wakeup_reg_bm(struct e1000_hw *hw, u32 offset,
2475 u16 *data, bool read)
2476{
2477 s32 ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00002478 u16 reg = BM_PHY_REG_NUM(offset);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002479 u16 phy_reg = 0;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002480
Bruce Allana4f58f52009-06-02 11:29:18 +00002481 /* Gig must be disabled for MDIO accesses to page 800 */
2482 if ((hw->mac.type == e1000_pchlan) &&
2483 (!(er32(PHY_CTRL) & E1000_PHY_CTRL_GBE_DISABLE)))
2484 hw_dbg(hw, "Attempting to access page 800 while gig enabled\n");
2485
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002486 /* All operations in this function are phy address 1 */
2487 hw->phy.addr = 1;
2488
2489 /* Set page 769 */
2490 e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
2491 (BM_WUC_ENABLE_PAGE << IGP_PAGE_SHIFT));
2492
2493 ret_val = e1000e_read_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, &phy_reg);
2494 if (ret_val)
2495 goto out;
2496
2497 /* First clear bit 4 to avoid a power state change */
2498 phy_reg &= ~(BM_WUC_HOST_WU_BIT);
2499 ret_val = e1000e_write_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, phy_reg);
2500 if (ret_val)
2501 goto out;
2502
2503 /* Write bit 2 = 1, and clear bit 4 to 769_17 */
2504 ret_val = e1000e_write_phy_reg_mdic(hw, BM_WUC_ENABLE_REG,
2505 phy_reg | BM_WUC_ENABLE_BIT);
2506 if (ret_val)
2507 goto out;
2508
2509 /* Select page 800 */
2510 ret_val = e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
2511 (BM_WUC_PAGE << IGP_PAGE_SHIFT));
2512
2513 /* Write the page 800 offset value using opcode 0x11 */
2514 ret_val = e1000e_write_phy_reg_mdic(hw, BM_WUC_ADDRESS_OPCODE, reg);
2515 if (ret_val)
2516 goto out;
2517
2518 if (read) {
2519 /* Read the page 800 value using opcode 0x12 */
2520 ret_val = e1000e_read_phy_reg_mdic(hw, BM_WUC_DATA_OPCODE,
2521 data);
2522 } else {
2523 /* Read the page 800 value using opcode 0x12 */
2524 ret_val = e1000e_write_phy_reg_mdic(hw, BM_WUC_DATA_OPCODE,
2525 *data);
2526 }
2527
2528 if (ret_val)
2529 goto out;
2530
2531 /*
2532 * Restore 769_17.2 to its original value
2533 * Set page 769
2534 */
2535 e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
2536 (BM_WUC_ENABLE_PAGE << IGP_PAGE_SHIFT));
2537
2538 /* Clear 769_17.2 */
2539 ret_val = e1000e_write_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, phy_reg);
2540
2541out:
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002542 return ret_val;
2543}
2544
2545/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002546 * e1000e_commit_phy - Soft PHY reset
2547 * @hw: pointer to the HW structure
2548 *
2549 * Performs a soft PHY reset on those that apply. This is a function pointer
2550 * entry point called by drivers.
2551 **/
2552s32 e1000e_commit_phy(struct e1000_hw *hw)
2553{
2554 if (hw->phy.ops.commit_phy)
2555 return hw->phy.ops.commit_phy(hw);
2556
2557 return 0;
2558}
2559
2560/**
2561 * e1000_set_d0_lplu_state - Sets low power link up state for D0
2562 * @hw: pointer to the HW structure
2563 * @active: boolean used to enable/disable lplu
2564 *
2565 * Success returns 0, Failure returns 1
2566 *
2567 * The low power link up (lplu) state is set to the power management level D0
2568 * and SmartSpeed is disabled when active is true, else clear lplu for D0
2569 * and enable Smartspeed. LPLU and Smartspeed are mutually exclusive. LPLU
2570 * is used during Dx states where the power conservation is most important.
2571 * During driver activity, SmartSpeed should be enabled so performance is
2572 * maintained. This is a function pointer entry point called by drivers.
2573 **/
2574static s32 e1000_set_d0_lplu_state(struct e1000_hw *hw, bool active)
2575{
2576 if (hw->phy.ops.set_d0_lplu_state)
2577 return hw->phy.ops.set_d0_lplu_state(hw, active);
2578
2579 return 0;
2580}
Bruce Allana4f58f52009-06-02 11:29:18 +00002581
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002582/**
2583 * e1000_set_mdio_slow_mode_hv - Set slow MDIO access mode
2584 * @hw: pointer to the HW structure
2585 * @slow: true for slow mode, false for normal mode
2586 *
2587 * Assumes semaphore already acquired.
2588 **/
Bruce Allana4f58f52009-06-02 11:29:18 +00002589s32 e1000_set_mdio_slow_mode_hv(struct e1000_hw *hw, bool slow)
2590{
2591 s32 ret_val = 0;
2592 u16 data = 0;
2593
Bruce Allana4f58f52009-06-02 11:29:18 +00002594 /* Set MDIO mode - page 769, register 16: 0x2580==slow, 0x2180==fast */
2595 hw->phy.addr = 1;
2596 ret_val = e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
2597 (BM_PORT_CTRL_PAGE << IGP_PAGE_SHIFT));
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002598 if (ret_val)
2599 goto out;
2600
Bruce Allana4f58f52009-06-02 11:29:18 +00002601 ret_val = e1000e_write_phy_reg_mdic(hw, BM_CS_CTRL1,
2602 (0x2180 | (slow << 10)));
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002603 if (ret_val)
2604 goto out;
Bruce Allana4f58f52009-06-02 11:29:18 +00002605
2606 /* dummy read when reverting to fast mode - throw away result */
2607 if (!slow)
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002608 ret_val = e1000e_read_phy_reg_mdic(hw, BM_CS_CTRL1, &data);
Bruce Allana4f58f52009-06-02 11:29:18 +00002609
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002610out:
Bruce Allana4f58f52009-06-02 11:29:18 +00002611 return ret_val;
2612}
2613
2614/**
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002615 * __e1000_read_phy_reg_hv - Read HV PHY register
Bruce Allana4f58f52009-06-02 11:29:18 +00002616 * @hw: pointer to the HW structure
2617 * @offset: register offset to be read
2618 * @data: pointer to the read data
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002619 * @locked: semaphore has already been acquired or not
Bruce Allana4f58f52009-06-02 11:29:18 +00002620 *
2621 * Acquires semaphore, if necessary, then reads the PHY register at offset
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002622 * and stores the retrieved information in data. Release any acquired
Bruce Allana4f58f52009-06-02 11:29:18 +00002623 * semaphore before exiting.
2624 **/
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002625static s32 __e1000_read_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 *data,
2626 bool locked)
Bruce Allana4f58f52009-06-02 11:29:18 +00002627{
2628 s32 ret_val;
2629 u16 page = BM_PHY_REG_PAGE(offset);
2630 u16 reg = BM_PHY_REG_NUM(offset);
2631 bool in_slow_mode = false;
2632
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002633 if (!locked) {
2634 ret_val = hw->phy.ops.acquire_phy(hw);
2635 if (ret_val)
2636 return ret_val;
2637 }
2638
Bruce Allana4f58f52009-06-02 11:29:18 +00002639 /* Workaround failure in MDIO access while cable is disconnected */
2640 if ((hw->phy.type == e1000_phy_82577) &&
2641 !(er32(STATUS) & E1000_STATUS_LU)) {
2642 ret_val = e1000_set_mdio_slow_mode_hv(hw, true);
2643 if (ret_val)
2644 goto out;
2645
2646 in_slow_mode = true;
2647 }
2648
2649 /* Page 800 works differently than the rest so it has its own func */
2650 if (page == BM_WUC_PAGE) {
2651 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset,
2652 data, true);
2653 goto out;
2654 }
2655
2656 if (page > 0 && page < HV_INTC_FC_PAGE_START) {
2657 ret_val = e1000_access_phy_debug_regs_hv(hw, offset,
2658 data, true);
2659 goto out;
2660 }
2661
Bruce Allana4f58f52009-06-02 11:29:18 +00002662 hw->phy.addr = e1000_get_phy_addr_for_hv_page(page);
2663
2664 if (page == HV_INTC_FC_PAGE_START)
2665 page = 0;
2666
2667 if (reg > MAX_PHY_MULTI_PAGE_REG) {
2668 if ((hw->phy.type != e1000_phy_82578) ||
2669 ((reg != I82578_ADDR_REG) &&
2670 (reg != I82578_ADDR_REG + 1))) {
2671 u32 phy_addr = hw->phy.addr;
2672
2673 hw->phy.addr = 1;
2674
2675 /* Page is shifted left, PHY expects (page x 32) */
2676 ret_val = e1000e_write_phy_reg_mdic(hw,
2677 IGP01E1000_PHY_PAGE_SELECT,
2678 (page << IGP_PAGE_SHIFT));
Bruce Allana4f58f52009-06-02 11:29:18 +00002679 hw->phy.addr = phy_addr;
2680 }
2681 }
2682
2683 ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & reg,
2684 data);
Bruce Allana4f58f52009-06-02 11:29:18 +00002685out:
2686 /* Revert to MDIO fast mode, if applicable */
2687 if ((hw->phy.type == e1000_phy_82577) && in_slow_mode)
2688 ret_val = e1000_set_mdio_slow_mode_hv(hw, false);
2689
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002690 if (!locked)
2691 hw->phy.ops.release_phy(hw);
2692
Bruce Allana4f58f52009-06-02 11:29:18 +00002693 return ret_val;
2694}
2695
2696/**
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002697 * e1000_read_phy_reg_hv - Read HV PHY register
2698 * @hw: pointer to the HW structure
2699 * @offset: register offset to be read
2700 * @data: pointer to the read data
2701 *
2702 * Acquires semaphore then reads the PHY register at offset and stores
2703 * the retrieved information in data. Release the acquired semaphore
2704 * before exiting.
2705 **/
2706s32 e1000_read_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 *data)
2707{
2708 return __e1000_read_phy_reg_hv(hw, offset, data, false);
2709}
2710
2711/**
2712 * e1000_read_phy_reg_hv_locked - Read HV PHY register
2713 * @hw: pointer to the HW structure
2714 * @offset: register offset to be read
2715 * @data: pointer to the read data
2716 *
2717 * Reads the PHY register at offset and stores the retrieved information
2718 * in data. Assumes semaphore already acquired.
2719 **/
2720s32 e1000_read_phy_reg_hv_locked(struct e1000_hw *hw, u32 offset, u16 *data)
2721{
2722 return __e1000_read_phy_reg_hv(hw, offset, data, true);
2723}
2724
2725/**
2726 * __e1000_write_phy_reg_hv - Write HV PHY register
Bruce Allana4f58f52009-06-02 11:29:18 +00002727 * @hw: pointer to the HW structure
2728 * @offset: register offset to write to
2729 * @data: data to write at register offset
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002730 * @locked: semaphore has already been acquired or not
Bruce Allana4f58f52009-06-02 11:29:18 +00002731 *
2732 * Acquires semaphore, if necessary, then writes the data to PHY register
2733 * at the offset. Release any acquired semaphores before exiting.
2734 **/
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002735static s32 __e1000_write_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 data,
2736 bool locked)
Bruce Allana4f58f52009-06-02 11:29:18 +00002737{
2738 s32 ret_val;
2739 u16 page = BM_PHY_REG_PAGE(offset);
2740 u16 reg = BM_PHY_REG_NUM(offset);
2741 bool in_slow_mode = false;
2742
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002743 if (!locked) {
2744 ret_val = hw->phy.ops.acquire_phy(hw);
2745 if (ret_val)
2746 return ret_val;
2747 }
2748
Bruce Allana4f58f52009-06-02 11:29:18 +00002749 /* Workaround failure in MDIO access while cable is disconnected */
2750 if ((hw->phy.type == e1000_phy_82577) &&
2751 !(er32(STATUS) & E1000_STATUS_LU)) {
2752 ret_val = e1000_set_mdio_slow_mode_hv(hw, true);
2753 if (ret_val)
2754 goto out;
2755
2756 in_slow_mode = true;
2757 }
2758
2759 /* Page 800 works differently than the rest so it has its own func */
2760 if (page == BM_WUC_PAGE) {
2761 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset,
2762 &data, false);
2763 goto out;
2764 }
2765
2766 if (page > 0 && page < HV_INTC_FC_PAGE_START) {
2767 ret_val = e1000_access_phy_debug_regs_hv(hw, offset,
2768 &data, false);
2769 goto out;
2770 }
2771
Bruce Allana4f58f52009-06-02 11:29:18 +00002772 hw->phy.addr = e1000_get_phy_addr_for_hv_page(page);
2773
2774 if (page == HV_INTC_FC_PAGE_START)
2775 page = 0;
2776
2777 /*
2778 * Workaround MDIO accesses being disabled after entering IEEE Power
2779 * Down (whenever bit 11 of the PHY Control register is set)
2780 */
2781 if ((hw->phy.type == e1000_phy_82578) &&
2782 (hw->phy.revision >= 1) &&
2783 (hw->phy.addr == 2) &&
2784 ((MAX_PHY_REG_ADDRESS & reg) == 0) &&
2785 (data & (1 << 11))) {
2786 u16 data2 = 0x7EFF;
Bruce Allana4f58f52009-06-02 11:29:18 +00002787 ret_val = e1000_access_phy_debug_regs_hv(hw, (1 << 6) | 0x3,
2788 &data2, false);
2789 if (ret_val)
2790 goto out;
Bruce Allana4f58f52009-06-02 11:29:18 +00002791 }
2792
2793 if (reg > MAX_PHY_MULTI_PAGE_REG) {
2794 if ((hw->phy.type != e1000_phy_82578) ||
2795 ((reg != I82578_ADDR_REG) &&
2796 (reg != I82578_ADDR_REG + 1))) {
2797 u32 phy_addr = hw->phy.addr;
2798
2799 hw->phy.addr = 1;
2800
2801 /* Page is shifted left, PHY expects (page x 32) */
2802 ret_val = e1000e_write_phy_reg_mdic(hw,
2803 IGP01E1000_PHY_PAGE_SELECT,
2804 (page << IGP_PAGE_SHIFT));
Bruce Allana4f58f52009-06-02 11:29:18 +00002805 hw->phy.addr = phy_addr;
2806 }
2807 }
2808
2809 ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & reg,
2810 data);
Bruce Allana4f58f52009-06-02 11:29:18 +00002811
2812out:
2813 /* Revert to MDIO fast mode, if applicable */
2814 if ((hw->phy.type == e1000_phy_82577) && in_slow_mode)
2815 ret_val = e1000_set_mdio_slow_mode_hv(hw, false);
2816
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002817 if (!locked)
2818 hw->phy.ops.release_phy(hw);
2819
Bruce Allana4f58f52009-06-02 11:29:18 +00002820 return ret_val;
2821}
2822
2823/**
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002824 * e1000_write_phy_reg_hv - Write HV PHY register
2825 * @hw: pointer to the HW structure
2826 * @offset: register offset to write to
2827 * @data: data to write at register offset
2828 *
2829 * Acquires semaphore then writes the data to PHY register at the offset.
2830 * Release the acquired semaphores before exiting.
2831 **/
2832s32 e1000_write_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 data)
2833{
2834 return __e1000_write_phy_reg_hv(hw, offset, data, false);
2835}
2836
2837/**
2838 * e1000_write_phy_reg_hv_locked - Write HV PHY register
2839 * @hw: pointer to the HW structure
2840 * @offset: register offset to write to
2841 * @data: data to write at register offset
2842 *
2843 * Writes the data to PHY register at the offset. Assumes semaphore
2844 * already acquired.
2845 **/
2846s32 e1000_write_phy_reg_hv_locked(struct e1000_hw *hw, u32 offset, u16 data)
2847{
2848 return __e1000_write_phy_reg_hv(hw, offset, data, true);
2849}
2850
2851/**
Bruce Allana4f58f52009-06-02 11:29:18 +00002852 * e1000_get_phy_addr_for_hv_page - Get PHY adrress based on page
2853 * @page: page to be accessed
2854 **/
2855static u32 e1000_get_phy_addr_for_hv_page(u32 page)
2856{
2857 u32 phy_addr = 2;
2858
2859 if (page >= HV_INTC_FC_PAGE_START)
2860 phy_addr = 1;
2861
2862 return phy_addr;
2863}
2864
2865/**
2866 * e1000_access_phy_debug_regs_hv - Read HV PHY vendor specific high registers
2867 * @hw: pointer to the HW structure
2868 * @offset: register offset to be read or written
2869 * @data: pointer to the data to be read or written
2870 * @read: determines if operation is read or written
2871 *
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002872 * Reads the PHY register at offset and stores the retreived information
2873 * in data. Assumes semaphore already acquired. Note that the procedure
2874 * to read these regs uses the address port and data port to read/write.
Bruce Allana4f58f52009-06-02 11:29:18 +00002875 **/
2876static s32 e1000_access_phy_debug_regs_hv(struct e1000_hw *hw, u32 offset,
2877 u16 *data, bool read)
2878{
2879 s32 ret_val;
2880 u32 addr_reg = 0;
2881 u32 data_reg = 0;
Bruce Allana4f58f52009-06-02 11:29:18 +00002882
2883 /* This takes care of the difference with desktop vs mobile phy */
2884 addr_reg = (hw->phy.type == e1000_phy_82578) ?
2885 I82578_ADDR_REG : I82577_ADDR_REG;
2886 data_reg = addr_reg + 1;
2887
Bruce Allana4f58f52009-06-02 11:29:18 +00002888 /* All operations in this function are phy address 2 */
2889 hw->phy.addr = 2;
2890
2891 /* masking with 0x3F to remove the page from offset */
2892 ret_val = e1000e_write_phy_reg_mdic(hw, addr_reg, (u16)offset & 0x3F);
2893 if (ret_val) {
2894 hw_dbg(hw, "Could not write PHY the HV address register\n");
2895 goto out;
2896 }
2897
2898 /* Read or write the data value next */
2899 if (read)
2900 ret_val = e1000e_read_phy_reg_mdic(hw, data_reg, data);
2901 else
2902 ret_val = e1000e_write_phy_reg_mdic(hw, data_reg, *data);
2903
2904 if (ret_val) {
2905 hw_dbg(hw, "Could not read data value from HV data register\n");
2906 goto out;
2907 }
2908
2909out:
Bruce Allana4f58f52009-06-02 11:29:18 +00002910 return ret_val;
2911}
2912
2913/**
2914 * e1000_link_stall_workaround_hv - Si workaround
2915 * @hw: pointer to the HW structure
2916 *
2917 * This function works around a Si bug where the link partner can get
2918 * a link up indication before the PHY does. If small packets are sent
2919 * by the link partner they can be placed in the packet buffer without
2920 * being properly accounted for by the PHY and will stall preventing
2921 * further packets from being received. The workaround is to clear the
2922 * packet buffer after the PHY detects link up.
2923 **/
2924s32 e1000_link_stall_workaround_hv(struct e1000_hw *hw)
2925{
2926 s32 ret_val = 0;
2927 u16 data;
2928
2929 if (hw->phy.type != e1000_phy_82578)
2930 goto out;
2931
Bruce Allane65fa872009-07-01 13:27:31 +00002932 /* Do not apply workaround if in PHY loopback bit 14 set */
2933 hw->phy.ops.read_phy_reg(hw, PHY_CONTROL, &data);
2934 if (data & PHY_CONTROL_LB)
2935 goto out;
2936
Bruce Allana4f58f52009-06-02 11:29:18 +00002937 /* check if link is up and at 1Gbps */
2938 ret_val = hw->phy.ops.read_phy_reg(hw, BM_CS_STATUS, &data);
2939 if (ret_val)
2940 goto out;
2941
2942 data &= BM_CS_STATUS_LINK_UP |
2943 BM_CS_STATUS_RESOLVED |
2944 BM_CS_STATUS_SPEED_MASK;
2945
2946 if (data != (BM_CS_STATUS_LINK_UP |
2947 BM_CS_STATUS_RESOLVED |
2948 BM_CS_STATUS_SPEED_1000))
2949 goto out;
2950
2951 mdelay(200);
2952
2953 /* flush the packets in the fifo buffer */
2954 ret_val = hw->phy.ops.write_phy_reg(hw, HV_MUX_DATA_CTRL,
2955 HV_MUX_DATA_CTRL_GEN_TO_MAC |
2956 HV_MUX_DATA_CTRL_FORCE_SPEED);
2957 if (ret_val)
2958 goto out;
2959
2960 ret_val = hw->phy.ops.write_phy_reg(hw, HV_MUX_DATA_CTRL,
2961 HV_MUX_DATA_CTRL_GEN_TO_MAC);
2962
2963out:
2964 return ret_val;
2965}
2966
2967/**
2968 * e1000_check_polarity_82577 - Checks the polarity.
2969 * @hw: pointer to the HW structure
2970 *
2971 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
2972 *
2973 * Polarity is determined based on the PHY specific status register.
2974 **/
2975s32 e1000_check_polarity_82577(struct e1000_hw *hw)
2976{
2977 struct e1000_phy_info *phy = &hw->phy;
2978 s32 ret_val;
2979 u16 data;
2980
2981 ret_val = phy->ops.read_phy_reg(hw, I82577_PHY_STATUS_2, &data);
2982
2983 if (!ret_val)
2984 phy->cable_polarity = (data & I82577_PHY_STATUS2_REV_POLARITY)
2985 ? e1000_rev_polarity_reversed
2986 : e1000_rev_polarity_normal;
2987
2988 return ret_val;
2989}
2990
2991/**
2992 * e1000_phy_force_speed_duplex_82577 - Force speed/duplex for I82577 PHY
2993 * @hw: pointer to the HW structure
2994 *
2995 * Calls the PHY setup function to force speed and duplex. Clears the
2996 * auto-crossover to force MDI manually. Waits for link and returns
2997 * successful if link up is successful, else -E1000_ERR_PHY (-2).
2998 **/
2999s32 e1000_phy_force_speed_duplex_82577(struct e1000_hw *hw)
3000{
3001 struct e1000_phy_info *phy = &hw->phy;
3002 s32 ret_val;
3003 u16 phy_data;
3004 bool link;
3005
3006 ret_val = phy->ops.read_phy_reg(hw, PHY_CONTROL, &phy_data);
3007 if (ret_val)
3008 goto out;
3009
3010 e1000e_phy_force_speed_duplex_setup(hw, &phy_data);
3011
3012 ret_val = phy->ops.write_phy_reg(hw, PHY_CONTROL, phy_data);
3013 if (ret_val)
3014 goto out;
3015
3016 /*
3017 * Clear Auto-Crossover to force MDI manually. 82577 requires MDI
3018 * forced whenever speed and duplex are forced.
3019 */
3020 ret_val = phy->ops.read_phy_reg(hw, I82577_PHY_CTRL_2, &phy_data);
3021 if (ret_val)
3022 goto out;
3023
3024 phy_data &= ~I82577_PHY_CTRL2_AUTO_MDIX;
3025 phy_data &= ~I82577_PHY_CTRL2_FORCE_MDI_MDIX;
3026
3027 ret_val = phy->ops.write_phy_reg(hw, I82577_PHY_CTRL_2, phy_data);
3028 if (ret_val)
3029 goto out;
3030
3031 hw_dbg(hw, "I82577_PHY_CTRL_2: %X\n", phy_data);
3032
3033 udelay(1);
3034
3035 if (phy->autoneg_wait_to_complete) {
3036 hw_dbg(hw, "Waiting for forced speed/duplex link on 82577 phy\n");
3037
3038 ret_val = e1000e_phy_has_link_generic(hw,
3039 PHY_FORCE_LIMIT,
3040 100000,
3041 &link);
3042 if (ret_val)
3043 goto out;
3044
3045 if (!link)
3046 hw_dbg(hw, "Link taking longer than expected.\n");
3047
3048 /* Try once more */
3049 ret_val = e1000e_phy_has_link_generic(hw,
3050 PHY_FORCE_LIMIT,
3051 100000,
3052 &link);
3053 if (ret_val)
3054 goto out;
3055 }
3056
3057out:
3058 return ret_val;
3059}
3060
3061/**
3062 * e1000_get_phy_info_82577 - Retrieve I82577 PHY information
3063 * @hw: pointer to the HW structure
3064 *
3065 * Read PHY status to determine if link is up. If link is up, then
3066 * set/determine 10base-T extended distance and polarity correction. Read
3067 * PHY port status to determine MDI/MDIx and speed. Based on the speed,
3068 * determine on the cable length, local and remote receiver.
3069 **/
3070s32 e1000_get_phy_info_82577(struct e1000_hw *hw)
3071{
3072 struct e1000_phy_info *phy = &hw->phy;
3073 s32 ret_val;
3074 u16 data;
3075 bool link;
3076
3077 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
3078 if (ret_val)
3079 goto out;
3080
3081 if (!link) {
3082 hw_dbg(hw, "Phy info is only valid if link is up\n");
3083 ret_val = -E1000_ERR_CONFIG;
3084 goto out;
3085 }
3086
3087 phy->polarity_correction = true;
3088
3089 ret_val = e1000_check_polarity_82577(hw);
3090 if (ret_val)
3091 goto out;
3092
3093 ret_val = phy->ops.read_phy_reg(hw, I82577_PHY_STATUS_2, &data);
3094 if (ret_val)
3095 goto out;
3096
3097 phy->is_mdix = (data & I82577_PHY_STATUS2_MDIX) ? true : false;
3098
3099 if ((data & I82577_PHY_STATUS2_SPEED_MASK) ==
3100 I82577_PHY_STATUS2_SPEED_1000MBPS) {
3101 ret_val = hw->phy.ops.get_cable_length(hw);
3102 if (ret_val)
3103 goto out;
3104
3105 ret_val = phy->ops.read_phy_reg(hw, PHY_1000T_STATUS, &data);
3106 if (ret_val)
3107 goto out;
3108
3109 phy->local_rx = (data & SR_1000T_LOCAL_RX_STATUS)
3110 ? e1000_1000t_rx_status_ok
3111 : e1000_1000t_rx_status_not_ok;
3112
3113 phy->remote_rx = (data & SR_1000T_REMOTE_RX_STATUS)
3114 ? e1000_1000t_rx_status_ok
3115 : e1000_1000t_rx_status_not_ok;
3116 } else {
3117 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
3118 phy->local_rx = e1000_1000t_rx_status_undefined;
3119 phy->remote_rx = e1000_1000t_rx_status_undefined;
3120 }
3121
3122out:
3123 return ret_val;
3124}
3125
3126/**
3127 * e1000_get_cable_length_82577 - Determine cable length for 82577 PHY
3128 * @hw: pointer to the HW structure
3129 *
3130 * Reads the diagnostic status register and verifies result is valid before
3131 * placing it in the phy_cable_length field.
3132 **/
3133s32 e1000_get_cable_length_82577(struct e1000_hw *hw)
3134{
3135 struct e1000_phy_info *phy = &hw->phy;
3136 s32 ret_val;
3137 u16 phy_data, length;
3138
3139 ret_val = phy->ops.read_phy_reg(hw, I82577_PHY_DIAG_STATUS, &phy_data);
3140 if (ret_val)
3141 goto out;
3142
3143 length = (phy_data & I82577_DSTATUS_CABLE_LENGTH) >>
3144 I82577_DSTATUS_CABLE_LENGTH_SHIFT;
3145
3146 if (length == E1000_CABLE_LENGTH_UNDEFINED)
3147 ret_val = E1000_ERR_PHY;
3148
3149 phy->cable_length = length;
3150
3151out:
3152 return ret_val;
3153}