blob: 3cf627be97769cae68d0d30af50bb910d6983569 [file] [log] [blame]
Auke Kokbc7f75f2007-09-17 12:30:59 -07001/*******************************************************************************
2
3 Intel PRO/1000 Linux driver
Bruce Allanbf670442013-01-01 16:00:01 +00004 Copyright(c) 1999 - 2013 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
Auke Kokbc7f75f2007-09-17 12:30:59 -070029#include "e1000.h"
30
Auke Kokbc7f75f2007-09-17 12:30:59 -070031static s32 e1000_wait_autoneg(struct e1000_hw *hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -070032static s32 e1000_access_phy_wakeup_reg_bm(struct e1000_hw *hw, u32 offset,
Bruce Allan2b6b1682011-05-13 07:20:09 +000033 u16 *data, bool read, bool page_set);
Bruce Allana4f58f52009-06-02 11:29:18 +000034static u32 e1000_get_phy_addr_for_hv_page(u32 page);
35static s32 e1000_access_phy_debug_regs_hv(struct e1000_hw *hw, u32 offset,
Bruce Allan1f96012d2013-01-05 03:06:54 +000036 u16 *data, bool read);
Auke Kokbc7f75f2007-09-17 12:30:59 -070037
38/* Cable length tables */
Bruce Allan64806412010-12-11 05:53:42 +000039static const u16 e1000_m88_cable_length_table[] = {
40 0, 50, 80, 110, 140, 140, E1000_CABLE_LENGTH_UNDEFINED };
Bruce Allaneb656d42009-12-01 15:47:02 +000041#define M88E1000_CABLE_LENGTH_TABLE_SIZE \
42 ARRAY_SIZE(e1000_m88_cable_length_table)
Auke Kokbc7f75f2007-09-17 12:30:59 -070043
Bruce Allan64806412010-12-11 05:53:42 +000044static const u16 e1000_igp_2_cable_length_table[] = {
45 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21, 0, 0, 0, 3,
46 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41, 6, 10, 14, 18, 22,
47 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61, 21, 26, 31, 35, 40,
48 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82, 40, 45, 51, 56, 61,
49 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104, 60, 66, 72, 77, 82,
50 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121, 83, 89, 95,
51 100, 105, 109, 113, 116, 119, 122, 124, 104, 109, 114, 118, 121,
52 124};
Auke Kokbc7f75f2007-09-17 12:30:59 -070053#define IGP02E1000_CABLE_LENGTH_TABLE_SIZE \
Alejandro Martinez Ruizc00acf42007-10-18 10:16:33 +020054 ARRAY_SIZE(e1000_igp_2_cable_length_table)
Auke Kokbc7f75f2007-09-17 12:30:59 -070055
Bruce Allana4f58f52009-06-02 11:29:18 +000056#define BM_PHY_REG_PAGE(offset) \
57 ((u16)(((offset) >> PHY_PAGE_SHIFT) & 0xFFFF))
58#define BM_PHY_REG_NUM(offset) \
59 ((u16)(((offset) & MAX_PHY_REG_ADDRESS) |\
60 (((offset) >> (PHY_UPPER_SHIFT - PHY_PAGE_SHIFT)) &\
61 ~MAX_PHY_REG_ADDRESS)))
62
63#define HV_INTC_FC_PAGE_START 768
64#define I82578_ADDR_REG 29
65#define I82577_ADDR_REG 16
66#define I82577_CFG_REG 22
67#define I82577_CFG_ASSERT_CRS_ON_TX (1 << 15)
68#define I82577_CFG_ENABLE_DOWNSHIFT (3 << 10) /* auto downshift 100/10 */
69#define I82577_CTRL_REG 23
Bruce Allana4f58f52009-06-02 11:29:18 +000070
71/* 82577 specific PHY registers */
72#define I82577_PHY_CTRL_2 18
73#define I82577_PHY_STATUS_2 26
74#define I82577_PHY_DIAG_STATUS 31
75
76/* I82577 PHY Status 2 */
77#define I82577_PHY_STATUS2_REV_POLARITY 0x0400
78#define I82577_PHY_STATUS2_MDIX 0x0800
79#define I82577_PHY_STATUS2_SPEED_MASK 0x0300
80#define I82577_PHY_STATUS2_SPEED_1000MBPS 0x0200
81
82/* I82577 PHY Control 2 */
Bruce W Allane86fd892012-07-26 02:30:59 +000083#define I82577_PHY_CTRL2_MANUAL_MDIX 0x0200
84#define I82577_PHY_CTRL2_AUTO_MDI_MDIX 0x0400
85#define I82577_PHY_CTRL2_MDIX_CFG_MASK 0x0600
Bruce Allana4f58f52009-06-02 11:29:18 +000086
87/* I82577 PHY Diagnostics Status */
88#define I82577_DSTATUS_CABLE_LENGTH 0x03FC
89#define I82577_DSTATUS_CABLE_LENGTH_SHIFT 2
90
91/* BM PHY Copper Specific Control 1 */
92#define BM_CS_CTRL1 16
93
Bruce Allana4f58f52009-06-02 11:29:18 +000094#define HV_MUX_DATA_CTRL PHY_REG(776, 16)
95#define HV_MUX_DATA_CTRL_GEN_TO_MAC 0x0400
96#define HV_MUX_DATA_CTRL_FORCE_SPEED 0x0004
97
Auke Kokbc7f75f2007-09-17 12:30:59 -070098/**
99 * e1000e_check_reset_block_generic - Check if PHY reset is blocked
100 * @hw: pointer to the HW structure
101 *
102 * Read the PHY management control register and check whether a PHY reset
103 * is blocked. If a reset is not blocked return 0, otherwise
104 * return E1000_BLK_PHY_RESET (12).
105 **/
106s32 e1000e_check_reset_block_generic(struct e1000_hw *hw)
107{
108 u32 manc;
109
110 manc = er32(MANC);
111
112 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
113 E1000_BLK_PHY_RESET : 0;
114}
115
116/**
117 * e1000e_get_phy_id - Retrieve the PHY ID and revision
118 * @hw: pointer to the HW structure
119 *
120 * Reads the PHY registers and stores the PHY ID and possibly the PHY
121 * revision in the hardware structure.
122 **/
123s32 e1000e_get_phy_id(struct e1000_hw *hw)
124{
125 struct e1000_phy_info *phy = &hw->phy;
Bruce Allana4f58f52009-06-02 11:29:18 +0000126 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700127 u16 phy_id;
Bruce Allana4f58f52009-06-02 11:29:18 +0000128 u16 retry_count = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700129
Bruce Allan668018d2012-01-31 07:02:56 +0000130 if (!phy->ops.read_reg)
Bruce Allan5015e532012-02-08 02:55:56 +0000131 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700132
Bruce Allana4f58f52009-06-02 11:29:18 +0000133 while (retry_count < 2) {
134 ret_val = e1e_rphy(hw, PHY_ID1, &phy_id);
135 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000136 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700137
Bruce Allana4f58f52009-06-02 11:29:18 +0000138 phy->id = (u32)(phy_id << 16);
139 udelay(20);
140 ret_val = e1e_rphy(hw, PHY_ID2, &phy_id);
141 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000142 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700143
Bruce Allana4f58f52009-06-02 11:29:18 +0000144 phy->id |= (u32)(phy_id & PHY_REVISION_MASK);
145 phy->revision = (u32)(phy_id & ~PHY_REVISION_MASK);
146
147 if (phy->id != 0 && phy->id != PHY_REVISION_MASK)
Bruce Allan5015e532012-02-08 02:55:56 +0000148 return 0;
Bruce Allana4f58f52009-06-02 11:29:18 +0000149
Bruce Allana4f58f52009-06-02 11:29:18 +0000150 retry_count++;
151 }
Bruce Allan5015e532012-02-08 02:55:56 +0000152
153 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700154}
155
156/**
157 * e1000e_phy_reset_dsp - Reset PHY DSP
158 * @hw: pointer to the HW structure
159 *
160 * Reset the digital signal processor.
161 **/
162s32 e1000e_phy_reset_dsp(struct e1000_hw *hw)
163{
164 s32 ret_val;
165
166 ret_val = e1e_wphy(hw, M88E1000_PHY_GEN_CONTROL, 0xC1);
167 if (ret_val)
168 return ret_val;
169
170 return e1e_wphy(hw, M88E1000_PHY_GEN_CONTROL, 0);
171}
172
173/**
David Graham2d9498f2008-04-23 11:09:14 -0700174 * e1000e_read_phy_reg_mdic - Read MDI control register
Auke Kokbc7f75f2007-09-17 12:30:59 -0700175 * @hw: pointer to the HW structure
176 * @offset: register offset to be read
177 * @data: pointer to the read data
178 *
Auke Kok489815c2008-02-21 15:11:07 -0800179 * Reads the MDI control register in the PHY at offset and stores the
Auke Kokbc7f75f2007-09-17 12:30:59 -0700180 * information read to data.
181 **/
David Graham2d9498f2008-04-23 11:09:14 -0700182s32 e1000e_read_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 *data)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700183{
184 struct e1000_phy_info *phy = &hw->phy;
185 u32 i, mdic = 0;
186
187 if (offset > MAX_PHY_REG_ADDRESS) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000188 e_dbg("PHY Address %d is out of range\n", offset);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700189 return -E1000_ERR_PARAM;
190 }
191
Bruce Allane921eb12012-11-28 09:28:37 +0000192 /* Set up Op-code, Phy Address, and register offset in the MDI
Auke Kokbc7f75f2007-09-17 12:30:59 -0700193 * Control register. The MAC will take care of interfacing with the
194 * PHY to retrieve the desired data.
195 */
196 mdic = ((offset << E1000_MDIC_REG_SHIFT) |
197 (phy->addr << E1000_MDIC_PHY_SHIFT) |
198 (E1000_MDIC_OP_READ));
199
200 ew32(MDIC, mdic);
201
Bruce Allane921eb12012-11-28 09:28:37 +0000202 /* Poll the ready bit to see if the MDI read completed
Bruce Allanad680762008-03-28 09:15:03 -0700203 * Increasing the time out as testing showed failures with
204 * the lower time out
205 */
David Graham2d9498f2008-04-23 11:09:14 -0700206 for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700207 udelay(50);
208 mdic = er32(MDIC);
209 if (mdic & E1000_MDIC_READY)
210 break;
211 }
212 if (!(mdic & E1000_MDIC_READY)) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000213 e_dbg("MDI Read did not complete\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700214 return -E1000_ERR_PHY;
215 }
216 if (mdic & E1000_MDIC_ERROR) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000217 e_dbg("MDI Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700218 return -E1000_ERR_PHY;
219 }
220 *data = (u16) mdic;
221
Bruce Allane921eb12012-11-28 09:28:37 +0000222 /* Allow some time after each MDIC transaction to avoid
Bruce Allan664dc872010-11-24 06:01:46 +0000223 * reading duplicate data in the next MDIC transaction.
224 */
225 if (hw->mac.type == e1000_pch2lan)
226 udelay(100);
227
Auke Kokbc7f75f2007-09-17 12:30:59 -0700228 return 0;
229}
230
231/**
David Graham2d9498f2008-04-23 11:09:14 -0700232 * e1000e_write_phy_reg_mdic - Write MDI control register
Auke Kokbc7f75f2007-09-17 12:30:59 -0700233 * @hw: pointer to the HW structure
234 * @offset: register offset to write to
235 * @data: data to write to register at offset
236 *
237 * Writes data to MDI control register in the PHY at offset.
238 **/
David Graham2d9498f2008-04-23 11:09:14 -0700239s32 e1000e_write_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 data)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700240{
241 struct e1000_phy_info *phy = &hw->phy;
242 u32 i, mdic = 0;
243
244 if (offset > MAX_PHY_REG_ADDRESS) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000245 e_dbg("PHY Address %d is out of range\n", offset);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700246 return -E1000_ERR_PARAM;
247 }
248
Bruce Allane921eb12012-11-28 09:28:37 +0000249 /* Set up Op-code, Phy Address, and register offset in the MDI
Auke Kokbc7f75f2007-09-17 12:30:59 -0700250 * Control register. The MAC will take care of interfacing with the
251 * PHY to retrieve the desired data.
252 */
253 mdic = (((u32)data) |
254 (offset << E1000_MDIC_REG_SHIFT) |
255 (phy->addr << E1000_MDIC_PHY_SHIFT) |
256 (E1000_MDIC_OP_WRITE));
257
258 ew32(MDIC, mdic);
259
Bruce Allane921eb12012-11-28 09:28:37 +0000260 /* Poll the ready bit to see if the MDI read completed
David Graham2d9498f2008-04-23 11:09:14 -0700261 * Increasing the time out as testing showed failures with
262 * the lower time out
263 */
264 for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
265 udelay(50);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700266 mdic = er32(MDIC);
267 if (mdic & E1000_MDIC_READY)
268 break;
269 }
270 if (!(mdic & E1000_MDIC_READY)) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000271 e_dbg("MDI Write did not complete\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700272 return -E1000_ERR_PHY;
273 }
David Graham2d9498f2008-04-23 11:09:14 -0700274 if (mdic & E1000_MDIC_ERROR) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000275 e_dbg("MDI Error\n");
David Graham2d9498f2008-04-23 11:09:14 -0700276 return -E1000_ERR_PHY;
277 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700278
Bruce Allane921eb12012-11-28 09:28:37 +0000279 /* Allow some time after each MDIC transaction to avoid
Bruce Allan664dc872010-11-24 06:01:46 +0000280 * reading duplicate data in the next MDIC transaction.
281 */
282 if (hw->mac.type == e1000_pch2lan)
283 udelay(100);
284
Auke Kokbc7f75f2007-09-17 12:30:59 -0700285 return 0;
286}
287
288/**
289 * e1000e_read_phy_reg_m88 - Read m88 PHY register
290 * @hw: pointer to the HW structure
291 * @offset: register offset to be read
292 * @data: pointer to the read data
293 *
294 * Acquires semaphore, if necessary, then reads the PHY register at offset
295 * and storing the retrieved information in data. Release any acquired
296 * semaphores before exiting.
297 **/
298s32 e1000e_read_phy_reg_m88(struct e1000_hw *hw, u32 offset, u16 *data)
299{
300 s32 ret_val;
301
Bruce Allan94d81862009-11-20 23:25:26 +0000302 ret_val = hw->phy.ops.acquire(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700303 if (ret_val)
304 return ret_val;
305
David Graham2d9498f2008-04-23 11:09:14 -0700306 ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
307 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700308
Bruce Allan94d81862009-11-20 23:25:26 +0000309 hw->phy.ops.release(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700310
311 return ret_val;
312}
313
314/**
315 * e1000e_write_phy_reg_m88 - Write m88 PHY register
316 * @hw: pointer to the HW structure
317 * @offset: register offset to write to
318 * @data: data to write at register offset
319 *
320 * Acquires semaphore, if necessary, then writes the data to PHY register
321 * at the offset. Release any acquired semaphores before exiting.
322 **/
323s32 e1000e_write_phy_reg_m88(struct e1000_hw *hw, u32 offset, u16 data)
324{
325 s32 ret_val;
326
Bruce Allan94d81862009-11-20 23:25:26 +0000327 ret_val = hw->phy.ops.acquire(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700328 if (ret_val)
329 return ret_val;
330
David Graham2d9498f2008-04-23 11:09:14 -0700331 ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
332 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700333
Bruce Allan94d81862009-11-20 23:25:26 +0000334 hw->phy.ops.release(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700335
336 return ret_val;
337}
338
339/**
Bruce Allan2b6b1682011-05-13 07:20:09 +0000340 * e1000_set_page_igp - Set page as on IGP-like PHY(s)
341 * @hw: pointer to the HW structure
342 * @page: page to set (shifted left when necessary)
343 *
344 * Sets PHY page required for PHY register access. Assumes semaphore is
345 * already acquired. Note, this function sets phy.addr to 1 so the caller
346 * must set it appropriately (if necessary) after this function returns.
347 **/
348s32 e1000_set_page_igp(struct e1000_hw *hw, u16 page)
349{
350 e_dbg("Setting page 0x%x\n", page);
351
352 hw->phy.addr = 1;
353
354 return e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT, page);
355}
356
357/**
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000358 * __e1000e_read_phy_reg_igp - Read igp PHY register
Auke Kokbc7f75f2007-09-17 12:30:59 -0700359 * @hw: pointer to the HW structure
360 * @offset: register offset to be read
361 * @data: pointer to the read data
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000362 * @locked: semaphore has already been acquired or not
Auke Kokbc7f75f2007-09-17 12:30:59 -0700363 *
364 * Acquires semaphore, if necessary, then reads the PHY register at offset
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000365 * and stores the retrieved information in data. Release any acquired
Auke Kokbc7f75f2007-09-17 12:30:59 -0700366 * semaphores before exiting.
367 **/
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000368static s32 __e1000e_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data,
369 bool locked)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700370{
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000371 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700372
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000373 if (!locked) {
Bruce Allan668018d2012-01-31 07:02:56 +0000374 if (!hw->phy.ops.acquire)
Bruce Allan5015e532012-02-08 02:55:56 +0000375 return 0;
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000376
Bruce Allan94d81862009-11-20 23:25:26 +0000377 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000378 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000379 return ret_val;
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000380 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700381
Bruce Allan5015e532012-02-08 02:55:56 +0000382 if (offset > MAX_PHY_MULTI_PAGE_REG)
David Graham2d9498f2008-04-23 11:09:14 -0700383 ret_val = e1000e_write_phy_reg_mdic(hw,
384 IGP01E1000_PHY_PAGE_SELECT,
385 (u16)offset);
Bruce Allan5015e532012-02-08 02:55:56 +0000386 if (!ret_val)
387 ret_val = e1000e_read_phy_reg_mdic(hw,
388 MAX_PHY_REG_ADDRESS & offset,
389 data);
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000390 if (!locked)
Bruce Allan94d81862009-11-20 23:25:26 +0000391 hw->phy.ops.release(hw);
Bruce Allan5015e532012-02-08 02:55:56 +0000392
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000393 return ret_val;
394}
Auke Kokbc7f75f2007-09-17 12:30:59 -0700395
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000396/**
397 * e1000e_read_phy_reg_igp - Read igp PHY register
398 * @hw: pointer to the HW structure
399 * @offset: register offset to be read
400 * @data: pointer to the read data
401 *
402 * Acquires semaphore then reads the PHY register at offset and stores the
403 * retrieved information in data.
404 * Release the acquired semaphore before exiting.
405 **/
406s32 e1000e_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data)
407{
408 return __e1000e_read_phy_reg_igp(hw, offset, data, false);
409}
410
411/**
412 * e1000e_read_phy_reg_igp_locked - Read igp PHY register
413 * @hw: pointer to the HW structure
414 * @offset: register offset to be read
415 * @data: pointer to the read data
416 *
417 * Reads the PHY register at offset and stores the retrieved information
418 * in data. Assumes semaphore already acquired.
419 **/
420s32 e1000e_read_phy_reg_igp_locked(struct e1000_hw *hw, u32 offset, u16 *data)
421{
422 return __e1000e_read_phy_reg_igp(hw, offset, data, true);
423}
424
425/**
426 * e1000e_write_phy_reg_igp - Write igp PHY register
427 * @hw: pointer to the HW structure
428 * @offset: register offset to write to
429 * @data: data to write at register offset
430 * @locked: semaphore has already been acquired or not
431 *
432 * Acquires semaphore, if necessary, then writes the data to PHY register
433 * at the offset. Release any acquired semaphores before exiting.
434 **/
435static s32 __e1000e_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data,
436 bool locked)
437{
438 s32 ret_val = 0;
439
440 if (!locked) {
Bruce Allan668018d2012-01-31 07:02:56 +0000441 if (!hw->phy.ops.acquire)
Bruce Allan5015e532012-02-08 02:55:56 +0000442 return 0;
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000443
Bruce Allan94d81862009-11-20 23:25:26 +0000444 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000445 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000446 return ret_val;
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000447 }
448
Bruce Allan5015e532012-02-08 02:55:56 +0000449 if (offset > MAX_PHY_MULTI_PAGE_REG)
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000450 ret_val = e1000e_write_phy_reg_mdic(hw,
451 IGP01E1000_PHY_PAGE_SELECT,
452 (u16)offset);
Bruce Allan5015e532012-02-08 02:55:56 +0000453 if (!ret_val)
454 ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS &
455 offset,
456 data);
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000457 if (!locked)
Bruce Allan94d81862009-11-20 23:25:26 +0000458 hw->phy.ops.release(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000459
Auke Kokbc7f75f2007-09-17 12:30:59 -0700460 return ret_val;
461}
462
463/**
464 * e1000e_write_phy_reg_igp - Write igp PHY register
465 * @hw: pointer to the HW structure
466 * @offset: register offset to write to
467 * @data: data to write at register offset
468 *
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000469 * Acquires semaphore then writes the data to PHY register
Auke Kokbc7f75f2007-09-17 12:30:59 -0700470 * at the offset. Release any acquired semaphores before exiting.
471 **/
472s32 e1000e_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data)
473{
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000474 return __e1000e_write_phy_reg_igp(hw, offset, data, false);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700475}
476
477/**
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000478 * e1000e_write_phy_reg_igp_locked - Write igp PHY register
479 * @hw: pointer to the HW structure
480 * @offset: register offset to write to
481 * @data: data to write at register offset
482 *
483 * Writes the data to PHY register at the offset.
484 * Assumes semaphore already acquired.
485 **/
486s32 e1000e_write_phy_reg_igp_locked(struct e1000_hw *hw, u32 offset, u16 data)
487{
488 return __e1000e_write_phy_reg_igp(hw, offset, data, true);
489}
490
491/**
492 * __e1000_read_kmrn_reg - Read kumeran register
Auke Kokbc7f75f2007-09-17 12:30:59 -0700493 * @hw: pointer to the HW structure
494 * @offset: register offset to be read
495 * @data: pointer to the read data
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000496 * @locked: semaphore has already been acquired or not
Auke Kokbc7f75f2007-09-17 12:30:59 -0700497 *
498 * Acquires semaphore, if necessary. Then reads the PHY register at offset
499 * using the kumeran interface. The information retrieved is stored in data.
500 * Release any acquired semaphores before exiting.
501 **/
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000502static s32 __e1000_read_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 *data,
503 bool locked)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700504{
505 u32 kmrnctrlsta;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700506
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000507 if (!locked) {
Bruce Allan5015e532012-02-08 02:55:56 +0000508 s32 ret_val = 0;
509
Bruce Allan668018d2012-01-31 07:02:56 +0000510 if (!hw->phy.ops.acquire)
Bruce Allan5015e532012-02-08 02:55:56 +0000511 return 0;
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000512
Bruce Allan94d81862009-11-20 23:25:26 +0000513 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000514 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000515 return ret_val;
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000516 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700517
518 kmrnctrlsta = ((offset << E1000_KMRNCTRLSTA_OFFSET_SHIFT) &
519 E1000_KMRNCTRLSTA_OFFSET) | E1000_KMRNCTRLSTA_REN;
520 ew32(KMRNCTRLSTA, kmrnctrlsta);
Jesse Brandeburg945a5152011-07-20 00:56:21 +0000521 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -0700522
523 udelay(2);
524
525 kmrnctrlsta = er32(KMRNCTRLSTA);
526 *data = (u16)kmrnctrlsta;
527
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000528 if (!locked)
Bruce Allan94d81862009-11-20 23:25:26 +0000529 hw->phy.ops.release(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700530
Bruce Allan5015e532012-02-08 02:55:56 +0000531 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700532}
533
534/**
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000535 * e1000e_read_kmrn_reg - Read kumeran register
536 * @hw: pointer to the HW structure
537 * @offset: register offset to be read
538 * @data: pointer to the read data
539 *
540 * Acquires semaphore then reads the PHY register at offset using the
541 * kumeran interface. The information retrieved is stored in data.
542 * Release the acquired semaphore before exiting.
543 **/
544s32 e1000e_read_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 *data)
545{
546 return __e1000_read_kmrn_reg(hw, offset, data, false);
547}
548
549/**
Bruce Allan1d5846b2009-10-29 13:46:05 +0000550 * e1000e_read_kmrn_reg_locked - Read kumeran register
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000551 * @hw: pointer to the HW structure
552 * @offset: register offset to be read
553 * @data: pointer to the read data
554 *
555 * Reads the PHY register at offset using the kumeran interface. The
556 * information retrieved is stored in data.
557 * Assumes semaphore already acquired.
558 **/
Bruce Allan1d5846b2009-10-29 13:46:05 +0000559s32 e1000e_read_kmrn_reg_locked(struct e1000_hw *hw, u32 offset, u16 *data)
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000560{
561 return __e1000_read_kmrn_reg(hw, offset, data, true);
562}
563
564/**
565 * __e1000_write_kmrn_reg - Write kumeran register
Auke Kokbc7f75f2007-09-17 12:30:59 -0700566 * @hw: pointer to the HW structure
567 * @offset: register offset to write to
568 * @data: data to write at register offset
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000569 * @locked: semaphore has already been acquired or not
Auke Kokbc7f75f2007-09-17 12:30:59 -0700570 *
571 * Acquires semaphore, if necessary. Then write the data to PHY register
572 * at the offset using the kumeran interface. Release any acquired semaphores
573 * before exiting.
574 **/
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000575static s32 __e1000_write_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 data,
576 bool locked)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700577{
578 u32 kmrnctrlsta;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700579
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000580 if (!locked) {
Bruce Allan5015e532012-02-08 02:55:56 +0000581 s32 ret_val = 0;
582
Bruce Allan668018d2012-01-31 07:02:56 +0000583 if (!hw->phy.ops.acquire)
Bruce Allan5015e532012-02-08 02:55:56 +0000584 return 0;
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000585
Bruce Allan94d81862009-11-20 23:25:26 +0000586 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000587 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000588 return ret_val;
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000589 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700590
591 kmrnctrlsta = ((offset << E1000_KMRNCTRLSTA_OFFSET_SHIFT) &
592 E1000_KMRNCTRLSTA_OFFSET) | data;
593 ew32(KMRNCTRLSTA, kmrnctrlsta);
Jesse Brandeburg945a5152011-07-20 00:56:21 +0000594 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -0700595
596 udelay(2);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700597
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000598 if (!locked)
Bruce Allan94d81862009-11-20 23:25:26 +0000599 hw->phy.ops.release(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000600
Bruce Allan5015e532012-02-08 02:55:56 +0000601 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700602}
603
604/**
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000605 * e1000e_write_kmrn_reg - Write kumeran register
606 * @hw: pointer to the HW structure
607 * @offset: register offset to write to
608 * @data: data to write at register offset
609 *
610 * Acquires semaphore then writes the data to the PHY register at the offset
611 * using the kumeran interface. Release the acquired semaphore before exiting.
612 **/
613s32 e1000e_write_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 data)
614{
615 return __e1000_write_kmrn_reg(hw, offset, data, false);
616}
617
618/**
Bruce Allan1d5846b2009-10-29 13:46:05 +0000619 * e1000e_write_kmrn_reg_locked - Write kumeran register
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000620 * @hw: pointer to the HW structure
621 * @offset: register offset to write to
622 * @data: data to write at register offset
623 *
624 * Write the data to PHY register at the offset using the kumeran interface.
625 * Assumes semaphore already acquired.
626 **/
Bruce Allan1d5846b2009-10-29 13:46:05 +0000627s32 e1000e_write_kmrn_reg_locked(struct e1000_hw *hw, u32 offset, u16 data)
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000628{
629 return __e1000_write_kmrn_reg(hw, offset, data, true);
630}
631
632/**
Bruce Allan7b9f7e32012-03-20 03:47:41 +0000633 * e1000_set_master_slave_mode - Setup PHY for Master/slave mode
634 * @hw: pointer to the HW structure
635 *
636 * Sets up Master/slave mode
637 **/
638static s32 e1000_set_master_slave_mode(struct e1000_hw *hw)
639{
640 s32 ret_val;
641 u16 phy_data;
642
643 /* Resolve Master/Slave mode */
644 ret_val = e1e_rphy(hw, PHY_1000T_CTRL, &phy_data);
645 if (ret_val)
646 return ret_val;
647
648 /* load defaults for future use */
649 hw->phy.original_ms_type = (phy_data & CR_1000T_MS_ENABLE) ?
650 ((phy_data & CR_1000T_MS_VALUE) ?
651 e1000_ms_force_master : e1000_ms_force_slave) : e1000_ms_auto;
652
653 switch (hw->phy.ms_type) {
654 case e1000_ms_force_master:
655 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
656 break;
657 case e1000_ms_force_slave:
658 phy_data |= CR_1000T_MS_ENABLE;
659 phy_data &= ~(CR_1000T_MS_VALUE);
660 break;
661 case e1000_ms_auto:
662 phy_data &= ~CR_1000T_MS_ENABLE;
663 /* fall-through */
664 default:
665 break;
666 }
667
668 return e1e_wphy(hw, PHY_1000T_CTRL, phy_data);
669}
670
671/**
Bruce Allana4f58f52009-06-02 11:29:18 +0000672 * e1000_copper_link_setup_82577 - Setup 82577 PHY for copper link
673 * @hw: pointer to the HW structure
674 *
675 * Sets up Carrier-sense on Transmit and downshift values.
676 **/
677s32 e1000_copper_link_setup_82577(struct e1000_hw *hw)
678{
Bruce Allana4f58f52009-06-02 11:29:18 +0000679 s32 ret_val;
680 u16 phy_data;
681
Bruce Allanaf667a22010-12-31 06:10:01 +0000682 /* Enable CRS on Tx. This must be set for half-duplex operation. */
Bruce Allan482fed82011-01-06 14:29:49 +0000683 ret_val = e1e_rphy(hw, I82577_CFG_REG, &phy_data);
Bruce Allana4f58f52009-06-02 11:29:18 +0000684 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000685 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +0000686
687 phy_data |= I82577_CFG_ASSERT_CRS_ON_TX;
688
689 /* Enable downshift */
690 phy_data |= I82577_CFG_ENABLE_DOWNSHIFT;
691
Bruce Allan7b9f7e32012-03-20 03:47:41 +0000692 ret_val = e1e_wphy(hw, I82577_CFG_REG, phy_data);
693 if (ret_val)
694 return ret_val;
695
Bruce W Allane86fd892012-07-26 02:30:59 +0000696 /* Set MDI/MDIX mode */
697 ret_val = e1e_rphy(hw, I82577_PHY_CTRL_2, &phy_data);
698 if (ret_val)
699 return ret_val;
700 phy_data &= ~I82577_PHY_CTRL2_MDIX_CFG_MASK;
Bruce Allane921eb12012-11-28 09:28:37 +0000701 /* Options:
Bruce W Allane86fd892012-07-26 02:30:59 +0000702 * 0 - Auto (default)
703 * 1 - MDI mode
704 * 2 - MDI-X mode
705 */
706 switch (hw->phy.mdix) {
707 case 1:
708 break;
709 case 2:
710 phy_data |= I82577_PHY_CTRL2_MANUAL_MDIX;
711 break;
712 case 0:
713 default:
714 phy_data |= I82577_PHY_CTRL2_AUTO_MDI_MDIX;
715 break;
716 }
717 ret_val = e1e_wphy(hw, I82577_PHY_CTRL_2, phy_data);
718 if (ret_val)
719 return ret_val;
720
Bruce Allan7b9f7e32012-03-20 03:47:41 +0000721 return e1000_set_master_slave_mode(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +0000722}
723
724/**
Auke Kokbc7f75f2007-09-17 12:30:59 -0700725 * e1000e_copper_link_setup_m88 - Setup m88 PHY's for copper link
726 * @hw: pointer to the HW structure
727 *
728 * Sets up MDI/MDI-X and polarity for m88 PHY's. If necessary, transmit clock
729 * and downshift values are set also.
730 **/
731s32 e1000e_copper_link_setup_m88(struct e1000_hw *hw)
732{
733 struct e1000_phy_info *phy = &hw->phy;
734 s32 ret_val;
735 u16 phy_data;
736
Bruce Allanad680762008-03-28 09:15:03 -0700737 /* Enable CRS on Tx. This must be set for half-duplex operation. */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700738 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
739 if (ret_val)
740 return ret_val;
741
Bruce Allana4f58f52009-06-02 11:29:18 +0000742 /* For BM PHY this bit is downshift enable */
743 if (phy->type != e1000_phy_bm)
David Graham2d9498f2008-04-23 11:09:14 -0700744 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700745
Bruce Allane921eb12012-11-28 09:28:37 +0000746 /* Options:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700747 * MDI/MDI-X = 0 (default)
748 * 0 - Auto for all speeds
749 * 1 - MDI mode
750 * 2 - MDI-X mode
751 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
752 */
753 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
754
755 switch (phy->mdix) {
756 case 1:
757 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
758 break;
759 case 2:
760 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
761 break;
762 case 3:
763 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
764 break;
765 case 0:
766 default:
767 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
768 break;
769 }
770
Bruce Allane921eb12012-11-28 09:28:37 +0000771 /* Options:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700772 * disable_polarity_correction = 0 (default)
773 * Automatic Correction for Reversed Cable Polarity
774 * 0 - Disabled
775 * 1 - Enabled
776 */
777 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
Bruce Allan04499ec2012-04-13 00:08:31 +0000778 if (phy->disable_polarity_correction)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700779 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
780
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700781 /* Enable downshift on BM (disabled by default) */
Matthew Vick885fe7b2012-04-25 07:25:18 +0000782 if (phy->type == e1000_phy_bm) {
783 /* For 82574/82583, first disable then enable downshift */
784 if (phy->id == BME1000_E_PHY_ID_R2) {
785 phy_data &= ~BME1000_PSCR_ENABLE_DOWNSHIFT;
786 ret_val = e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL,
787 phy_data);
788 if (ret_val)
789 return ret_val;
790 /* Commit the changes. */
791 ret_val = e1000e_commit_phy(hw);
792 if (ret_val) {
793 e_dbg("Error committing the PHY changes\n");
794 return ret_val;
795 }
796 }
797
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700798 phy_data |= BME1000_PSCR_ENABLE_DOWNSHIFT;
Matthew Vick885fe7b2012-04-25 07:25:18 +0000799 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700800
Auke Kokbc7f75f2007-09-17 12:30:59 -0700801 ret_val = e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
802 if (ret_val)
803 return ret_val;
804
Bruce Allan4662e822008-08-26 18:37:06 -0700805 if ((phy->type == e1000_phy_m88) &&
806 (phy->revision < E1000_REVISION_4) &&
807 (phy->id != BME1000_E_PHY_ID_R2)) {
Bruce Allane921eb12012-11-28 09:28:37 +0000808 /* Force TX_CLK in the Extended PHY Specific Control Register
Auke Kokbc7f75f2007-09-17 12:30:59 -0700809 * to 25MHz clock.
810 */
811 ret_val = e1e_rphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
812 if (ret_val)
813 return ret_val;
814
815 phy_data |= M88E1000_EPSCR_TX_CLK_25;
816
817 if ((phy->revision == 2) &&
818 (phy->id == M88E1111_I_PHY_ID)) {
819 /* 82573L PHY - set the downshift counter to 5x. */
820 phy_data &= ~M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK;
821 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
822 } else {
823 /* Configure Master and Slave downshift values */
824 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
825 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
826 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
827 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
828 }
829 ret_val = e1e_wphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
830 if (ret_val)
831 return ret_val;
832 }
833
Bruce Allan4662e822008-08-26 18:37:06 -0700834 if ((phy->type == e1000_phy_bm) && (phy->id == BME1000_E_PHY_ID_R2)) {
835 /* Set PHY page 0, register 29 to 0x0003 */
836 ret_val = e1e_wphy(hw, 29, 0x0003);
837 if (ret_val)
838 return ret_val;
839
840 /* Set PHY page 0, register 30 to 0x0000 */
841 ret_val = e1e_wphy(hw, 30, 0x0000);
842 if (ret_val)
843 return ret_val;
844 }
845
Auke Kokbc7f75f2007-09-17 12:30:59 -0700846 /* Commit the changes. */
847 ret_val = e1000e_commit_phy(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +0000848 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000849 e_dbg("Error committing the PHY changes\n");
Bruce Allana4f58f52009-06-02 11:29:18 +0000850 return ret_val;
851 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700852
Bruce Allana4f58f52009-06-02 11:29:18 +0000853 if (phy->type == e1000_phy_82578) {
Bruce Allan482fed82011-01-06 14:29:49 +0000854 ret_val = e1e_rphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
Bruce Allana4f58f52009-06-02 11:29:18 +0000855 if (ret_val)
856 return ret_val;
857
858 /* 82578 PHY - set the downshift count to 1x. */
859 phy_data |= I82578_EPSCR_DOWNSHIFT_ENABLE;
860 phy_data &= ~I82578_EPSCR_DOWNSHIFT_COUNTER_MASK;
Bruce Allan482fed82011-01-06 14:29:49 +0000861 ret_val = e1e_wphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
Bruce Allana4f58f52009-06-02 11:29:18 +0000862 if (ret_val)
863 return ret_val;
864 }
865
866 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700867}
868
869/**
870 * e1000e_copper_link_setup_igp - Setup igp PHY's for copper link
871 * @hw: pointer to the HW structure
872 *
873 * Sets up LPLU, MDI/MDI-X, polarity, Smartspeed and Master/Slave config for
874 * igp PHY's.
875 **/
876s32 e1000e_copper_link_setup_igp(struct e1000_hw *hw)
877{
878 struct e1000_phy_info *phy = &hw->phy;
879 s32 ret_val;
880 u16 data;
881
882 ret_val = e1000_phy_hw_reset(hw);
883 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000884 e_dbg("Error resetting the PHY.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700885 return ret_val;
886 }
887
Bruce Allane921eb12012-11-28 09:28:37 +0000888 /* Wait 100ms for MAC to configure PHY from NVM settings, to avoid
David Graham2d9498f2008-04-23 11:09:14 -0700889 * timeout issues when LFS is enabled.
890 */
891 msleep(100);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700892
893 /* disable lplu d0 during driver init */
Bruce Allan7de89f02013-01-05 08:06:03 +0000894 if (hw->phy.ops.set_d0_lplu_state) {
895 ret_val = hw->phy.ops.set_d0_lplu_state(hw, false);
896 if (ret_val) {
897 e_dbg("Error Disabling LPLU D0\n");
898 return ret_val;
899 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700900 }
901 /* Configure mdi-mdix settings */
902 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CTRL, &data);
903 if (ret_val)
904 return ret_val;
905
906 data &= ~IGP01E1000_PSCR_AUTO_MDIX;
907
908 switch (phy->mdix) {
909 case 1:
910 data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
911 break;
912 case 2:
913 data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
914 break;
915 case 0:
916 default:
917 data |= IGP01E1000_PSCR_AUTO_MDIX;
918 break;
919 }
920 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CTRL, data);
921 if (ret_val)
922 return ret_val;
923
924 /* set auto-master slave resolution settings */
925 if (hw->mac.autoneg) {
Bruce Allane921eb12012-11-28 09:28:37 +0000926 /* when autonegotiation advertisement is only 1000Mbps then we
Auke Kokbc7f75f2007-09-17 12:30:59 -0700927 * should disable SmartSpeed and enable Auto MasterSlave
Bruce Allanad680762008-03-28 09:15:03 -0700928 * resolution as hardware default.
929 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700930 if (phy->autoneg_advertised == ADVERTISE_1000_FULL) {
931 /* Disable SmartSpeed */
932 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -0700933 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700934 if (ret_val)
935 return ret_val;
936
937 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
938 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -0700939 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700940 if (ret_val)
941 return ret_val;
942
943 /* Set auto Master/Slave resolution process */
944 ret_val = e1e_rphy(hw, PHY_1000T_CTRL, &data);
945 if (ret_val)
946 return ret_val;
947
948 data &= ~CR_1000T_MS_ENABLE;
949 ret_val = e1e_wphy(hw, PHY_1000T_CTRL, data);
950 if (ret_val)
951 return ret_val;
952 }
953
Bruce Allan7b9f7e32012-03-20 03:47:41 +0000954 ret_val = e1000_set_master_slave_mode(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700955 }
956
957 return ret_val;
958}
959
960/**
961 * e1000_phy_setup_autoneg - Configure PHY for auto-negotiation
962 * @hw: pointer to the HW structure
963 *
964 * Reads the MII auto-neg advertisement register and/or the 1000T control
965 * register and if the PHY is already setup for auto-negotiation, then
966 * return successful. Otherwise, setup advertisement and flow control to
967 * the appropriate values for the wanted auto-negotiation.
968 **/
969static s32 e1000_phy_setup_autoneg(struct e1000_hw *hw)
970{
971 struct e1000_phy_info *phy = &hw->phy;
972 s32 ret_val;
973 u16 mii_autoneg_adv_reg;
974 u16 mii_1000t_ctrl_reg = 0;
975
976 phy->autoneg_advertised &= phy->autoneg_mask;
977
978 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
979 ret_val = e1e_rphy(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
980 if (ret_val)
981 return ret_val;
982
983 if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
984 /* Read the MII 1000Base-T Control Register (Address 9). */
985 ret_val = e1e_rphy(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
986 if (ret_val)
987 return ret_val;
988 }
989
Bruce Allane921eb12012-11-28 09:28:37 +0000990 /* Need to parse both autoneg_advertised and fc and set up
Auke Kokbc7f75f2007-09-17 12:30:59 -0700991 * the appropriate PHY registers. First we will parse for
992 * autoneg_advertised software override. Since we can advertise
993 * a plethora of combinations, we need to check each bit
994 * individually.
995 */
996
Bruce Allane921eb12012-11-28 09:28:37 +0000997 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
Auke Kokbc7f75f2007-09-17 12:30:59 -0700998 * Advertisement Register (Address 4) and the 1000 mb speed bits in
999 * the 1000Base-T Control Register (Address 9).
1000 */
1001 mii_autoneg_adv_reg &= ~(NWAY_AR_100TX_FD_CAPS |
1002 NWAY_AR_100TX_HD_CAPS |
1003 NWAY_AR_10T_FD_CAPS |
1004 NWAY_AR_10T_HD_CAPS);
1005 mii_1000t_ctrl_reg &= ~(CR_1000T_HD_CAPS | CR_1000T_FD_CAPS);
1006
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001007 e_dbg("autoneg_advertised %x\n", phy->autoneg_advertised);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001008
1009 /* Do we want to advertise 10 Mb Half Duplex? */
1010 if (phy->autoneg_advertised & ADVERTISE_10_HALF) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001011 e_dbg("Advertise 10mb Half duplex\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001012 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
1013 }
1014
1015 /* Do we want to advertise 10 Mb Full Duplex? */
1016 if (phy->autoneg_advertised & ADVERTISE_10_FULL) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001017 e_dbg("Advertise 10mb Full duplex\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001018 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
1019 }
1020
1021 /* Do we want to advertise 100 Mb Half Duplex? */
1022 if (phy->autoneg_advertised & ADVERTISE_100_HALF) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001023 e_dbg("Advertise 100mb Half duplex\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001024 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
1025 }
1026
1027 /* Do we want to advertise 100 Mb Full Duplex? */
1028 if (phy->autoneg_advertised & ADVERTISE_100_FULL) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001029 e_dbg("Advertise 100mb Full duplex\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001030 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
1031 }
1032
1033 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
1034 if (phy->autoneg_advertised & ADVERTISE_1000_HALF)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001035 e_dbg("Advertise 1000mb Half duplex request denied!\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001036
1037 /* Do we want to advertise 1000 Mb Full Duplex? */
1038 if (phy->autoneg_advertised & ADVERTISE_1000_FULL) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001039 e_dbg("Advertise 1000mb Full duplex\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001040 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
1041 }
1042
Bruce Allane921eb12012-11-28 09:28:37 +00001043 /* Check for a software override of the flow control settings, and
Auke Kokbc7f75f2007-09-17 12:30:59 -07001044 * setup the PHY advertisement registers accordingly. If
1045 * auto-negotiation is enabled, then software will have to set the
1046 * "PAUSE" bits to the correct value in the Auto-Negotiation
1047 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-
1048 * negotiation.
1049 *
1050 * The possible values of the "fc" parameter are:
1051 * 0: Flow control is completely disabled
1052 * 1: Rx flow control is enabled (we can receive pause frames
Bruce Allan3d3a1672012-02-23 03:13:18 +00001053 * but not send pause frames).
Auke Kokbc7f75f2007-09-17 12:30:59 -07001054 * 2: Tx flow control is enabled (we can send pause frames
Bruce Allan3d3a1672012-02-23 03:13:18 +00001055 * but we do not support receiving pause frames).
Bruce Allanad680762008-03-28 09:15:03 -07001056 * 3: Both Rx and Tx flow control (symmetric) are enabled.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001057 * other: No software override. The flow control configuration
Bruce Allan3d3a1672012-02-23 03:13:18 +00001058 * in the EEPROM is used.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001059 */
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08001060 switch (hw->fc.current_mode) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001061 case e1000_fc_none:
Bruce Allane921eb12012-11-28 09:28:37 +00001062 /* Flow control (Rx & Tx) is completely disabled by a
Auke Kokbc7f75f2007-09-17 12:30:59 -07001063 * software over-ride.
1064 */
1065 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1066 break;
1067 case e1000_fc_rx_pause:
Bruce Allane921eb12012-11-28 09:28:37 +00001068 /* Rx Flow control is enabled, and Tx Flow control is
Auke Kokbc7f75f2007-09-17 12:30:59 -07001069 * disabled, by a software over-ride.
Bruce Allanad680762008-03-28 09:15:03 -07001070 *
1071 * Since there really isn't a way to advertise that we are
1072 * capable of Rx Pause ONLY, we will advertise that we
1073 * support both symmetric and asymmetric Rx PAUSE. Later
Auke Kokbc7f75f2007-09-17 12:30:59 -07001074 * (in e1000e_config_fc_after_link_up) we will disable the
1075 * hw's ability to send PAUSE frames.
1076 */
1077 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1078 break;
1079 case e1000_fc_tx_pause:
Bruce Allane921eb12012-11-28 09:28:37 +00001080 /* Tx Flow control is enabled, and Rx Flow control is
Auke Kokbc7f75f2007-09-17 12:30:59 -07001081 * disabled, by a software over-ride.
1082 */
1083 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
1084 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
1085 break;
1086 case e1000_fc_full:
Bruce Allane921eb12012-11-28 09:28:37 +00001087 /* Flow control (both Rx and Tx) is enabled by a software
Auke Kokbc7f75f2007-09-17 12:30:59 -07001088 * over-ride.
1089 */
1090 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1091 break;
1092 default:
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001093 e_dbg("Flow control param set incorrectly\n");
Bruce Allan7eb61d82012-02-08 02:55:03 +00001094 return -E1000_ERR_CONFIG;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001095 }
1096
1097 ret_val = e1e_wphy(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
1098 if (ret_val)
1099 return ret_val;
1100
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001101 e_dbg("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001102
Bruce Allanb1cdfea2010-12-11 05:53:47 +00001103 if (phy->autoneg_mask & ADVERTISE_1000_FULL)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001104 ret_val = e1e_wphy(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001105
1106 return ret_val;
1107}
1108
1109/**
1110 * e1000_copper_link_autoneg - Setup/Enable autoneg for copper link
1111 * @hw: pointer to the HW structure
1112 *
1113 * Performs initial bounds checking on autoneg advertisement parameter, then
1114 * configure to advertise the full capability. Setup the PHY to autoneg
1115 * and restart the negotiation process between the link partner. If
Bruce Allanad680762008-03-28 09:15:03 -07001116 * autoneg_wait_to_complete, then wait for autoneg to complete before exiting.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001117 **/
1118static s32 e1000_copper_link_autoneg(struct e1000_hw *hw)
1119{
1120 struct e1000_phy_info *phy = &hw->phy;
1121 s32 ret_val;
1122 u16 phy_ctrl;
1123
Bruce Allane921eb12012-11-28 09:28:37 +00001124 /* Perform some bounds checking on the autoneg advertisement
Auke Kokbc7f75f2007-09-17 12:30:59 -07001125 * parameter.
1126 */
1127 phy->autoneg_advertised &= phy->autoneg_mask;
1128
Bruce Allane921eb12012-11-28 09:28:37 +00001129 /* If autoneg_advertised is zero, we assume it was not defaulted
Auke Kokbc7f75f2007-09-17 12:30:59 -07001130 * by the calling code so we set to advertise full capability.
1131 */
Bruce Allan04499ec2012-04-13 00:08:31 +00001132 if (!phy->autoneg_advertised)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001133 phy->autoneg_advertised = phy->autoneg_mask;
1134
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001135 e_dbg("Reconfiguring auto-neg advertisement params\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001136 ret_val = e1000_phy_setup_autoneg(hw);
1137 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001138 e_dbg("Error Setting up Auto-Negotiation\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001139 return ret_val;
1140 }
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001141 e_dbg("Restarting Auto-Neg\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001142
Bruce Allane921eb12012-11-28 09:28:37 +00001143 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
Auke Kokbc7f75f2007-09-17 12:30:59 -07001144 * the Auto Neg Restart bit in the PHY control register.
1145 */
1146 ret_val = e1e_rphy(hw, PHY_CONTROL, &phy_ctrl);
1147 if (ret_val)
1148 return ret_val;
1149
1150 phy_ctrl |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
1151 ret_val = e1e_wphy(hw, PHY_CONTROL, phy_ctrl);
1152 if (ret_val)
1153 return ret_val;
1154
Bruce Allane921eb12012-11-28 09:28:37 +00001155 /* Does the user want to wait for Auto-Neg to complete here, or
Auke Kokbc7f75f2007-09-17 12:30:59 -07001156 * check at a later time (for example, callback routine).
1157 */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001158 if (phy->autoneg_wait_to_complete) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001159 ret_val = e1000_wait_autoneg(hw);
1160 if (ret_val) {
Bruce Allan434f1392011-12-16 00:46:54 +00001161 e_dbg("Error while waiting for autoneg to complete\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001162 return ret_val;
1163 }
1164 }
1165
Bruce Allanf92518d2012-02-01 11:16:42 +00001166 hw->mac.get_link_status = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001167
1168 return ret_val;
1169}
1170
1171/**
1172 * e1000e_setup_copper_link - Configure copper link settings
1173 * @hw: pointer to the HW structure
1174 *
1175 * Calls the appropriate function to configure the link for auto-neg or forced
1176 * speed and duplex. Then we check for link, once link is established calls
1177 * to configure collision distance and flow control are called. If link is
1178 * not established, we return -E1000_ERR_PHY (-2).
1179 **/
1180s32 e1000e_setup_copper_link(struct e1000_hw *hw)
1181{
1182 s32 ret_val;
1183 bool link;
1184
1185 if (hw->mac.autoneg) {
Bruce Allane921eb12012-11-28 09:28:37 +00001186 /* Setup autoneg and flow control advertisement and perform
Bruce Allanad680762008-03-28 09:15:03 -07001187 * autonegotiation.
1188 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001189 ret_val = e1000_copper_link_autoneg(hw);
1190 if (ret_val)
1191 return ret_val;
1192 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00001193 /* PHY will be set to 10H, 10F, 100H or 100F
Bruce Allanad680762008-03-28 09:15:03 -07001194 * depending on user settings.
1195 */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001196 e_dbg("Forcing Speed and Duplex\n");
Bruce Allanc2c66292013-01-05 08:06:08 +00001197 ret_val = hw->phy.ops.force_speed_duplex(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001198 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001199 e_dbg("Error Forcing Speed and Duplex\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001200 return ret_val;
1201 }
1202 }
1203
Bruce Allane921eb12012-11-28 09:28:37 +00001204 /* Check link status. Wait up to 100 microseconds for link to become
Auke Kokbc7f75f2007-09-17 12:30:59 -07001205 * valid.
1206 */
Bruce Allan3d3a1672012-02-23 03:13:18 +00001207 ret_val = e1000e_phy_has_link_generic(hw, COPPER_LINK_UP_LIMIT, 10,
1208 &link);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001209 if (ret_val)
1210 return ret_val;
1211
1212 if (link) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001213 e_dbg("Valid link established!!!\n");
Bruce Allan57cde762012-02-22 09:02:58 +00001214 hw->mac.ops.config_collision_dist(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001215 ret_val = e1000e_config_fc_after_link_up(hw);
1216 } else {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001217 e_dbg("Unable to establish link!!!\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001218 }
1219
1220 return ret_val;
1221}
1222
1223/**
1224 * e1000e_phy_force_speed_duplex_igp - Force speed/duplex for igp PHY
1225 * @hw: pointer to the HW structure
1226 *
1227 * Calls the PHY setup function to force speed and duplex. Clears the
1228 * auto-crossover to force MDI manually. Waits for link and returns
1229 * successful if link up is successful, else -E1000_ERR_PHY (-2).
1230 **/
1231s32 e1000e_phy_force_speed_duplex_igp(struct e1000_hw *hw)
1232{
1233 struct e1000_phy_info *phy = &hw->phy;
1234 s32 ret_val;
1235 u16 phy_data;
1236 bool link;
1237
1238 ret_val = e1e_rphy(hw, PHY_CONTROL, &phy_data);
1239 if (ret_val)
1240 return ret_val;
1241
1242 e1000e_phy_force_speed_duplex_setup(hw, &phy_data);
1243
1244 ret_val = e1e_wphy(hw, PHY_CONTROL, phy_data);
1245 if (ret_val)
1246 return ret_val;
1247
Bruce Allane921eb12012-11-28 09:28:37 +00001248 /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
Auke Kokbc7f75f2007-09-17 12:30:59 -07001249 * forced whenever speed and duplex are forced.
1250 */
1251 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1252 if (ret_val)
1253 return ret_val;
1254
1255 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1256 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1257
1258 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1259 if (ret_val)
1260 return ret_val;
1261
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001262 e_dbg("IGP PSCR: %X\n", phy_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001263
1264 udelay(1);
1265
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001266 if (phy->autoneg_wait_to_complete) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001267 e_dbg("Waiting for forced speed/duplex link on IGP phy.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001268
Bruce Allan3d3a1672012-02-23 03:13:18 +00001269 ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
1270 100000, &link);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001271 if (ret_val)
1272 return ret_val;
1273
1274 if (!link)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001275 e_dbg("Link taking longer than expected.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001276
1277 /* Try once more */
Bruce Allan3d3a1672012-02-23 03:13:18 +00001278 ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
1279 100000, &link);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001280 }
1281
1282 return ret_val;
1283}
1284
1285/**
1286 * e1000e_phy_force_speed_duplex_m88 - Force speed/duplex for m88 PHY
1287 * @hw: pointer to the HW structure
1288 *
1289 * Calls the PHY setup function to force speed and duplex. Clears the
1290 * auto-crossover to force MDI manually. Resets the PHY to commit the
1291 * changes. If time expires while waiting for link up, we reset the DSP.
Bruce Allanad680762008-03-28 09:15:03 -07001292 * After reset, TX_CLK and CRS on Tx must be set. Return successful upon
Auke Kokbc7f75f2007-09-17 12:30:59 -07001293 * successful completion, else return corresponding error code.
1294 **/
1295s32 e1000e_phy_force_speed_duplex_m88(struct e1000_hw *hw)
1296{
1297 struct e1000_phy_info *phy = &hw->phy;
1298 s32 ret_val;
1299 u16 phy_data;
1300 bool link;
1301
Bruce Allane921eb12012-11-28 09:28:37 +00001302 /* 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
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001314 e_dbg("M88E1000 PSCR: %X\n", phy_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001315
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) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001332 e_dbg("Waiting for forced speed/duplex link on M88 phy.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001333
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 Allan0be84012009-12-02 17:03:18 +00001340 if (hw->phy.type != e1000_phy_m88) {
1341 e_dbg("Link taking longer than expected.\n");
1342 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00001343 /* We didn't get link.
Bruce Allan0be84012009-12-02 17:03:18 +00001344 * Reset the DSP and cross our fingers.
1345 */
Bruce Allan482fed82011-01-06 14:29:49 +00001346 ret_val = e1e_wphy(hw, M88E1000_PHY_PAGE_SELECT,
1347 0x001d);
Bruce Allan0be84012009-12-02 17:03:18 +00001348 if (ret_val)
1349 return ret_val;
1350 ret_val = e1000e_phy_reset_dsp(hw);
1351 if (ret_val)
1352 return ret_val;
1353 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001354 }
1355
1356 /* Try once more */
1357 ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
1358 100000, &link);
1359 if (ret_val)
1360 return ret_val;
1361 }
1362
Bruce Allan0be84012009-12-02 17:03:18 +00001363 if (hw->phy.type != e1000_phy_m88)
1364 return 0;
1365
Auke Kokbc7f75f2007-09-17 12:30:59 -07001366 ret_val = e1e_rphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1367 if (ret_val)
1368 return ret_val;
1369
Bruce Allane921eb12012-11-28 09:28:37 +00001370 /* Resetting the phy means we need to re-force TX_CLK in the
Auke Kokbc7f75f2007-09-17 12:30:59 -07001371 * Extended PHY Specific Control Register to 25MHz clock from
1372 * the reset value of 2.5MHz.
1373 */
1374 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1375 ret_val = e1e_wphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1376 if (ret_val)
1377 return ret_val;
1378
Bruce Allane921eb12012-11-28 09:28:37 +00001379 /* In addition, we must re-enable CRS on Tx for both half and full
Auke Kokbc7f75f2007-09-17 12:30:59 -07001380 * duplex.
1381 */
1382 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1383 if (ret_val)
1384 return ret_val;
1385
1386 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1387 ret_val = e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1388
1389 return ret_val;
1390}
1391
1392/**
Bruce Allan0be84012009-12-02 17:03:18 +00001393 * e1000_phy_force_speed_duplex_ife - Force PHY speed & duplex
1394 * @hw: pointer to the HW structure
1395 *
1396 * Forces the speed and duplex settings of the PHY.
1397 * This is a function pointer entry point only called by
1398 * PHY setup routines.
1399 **/
1400s32 e1000_phy_force_speed_duplex_ife(struct e1000_hw *hw)
1401{
1402 struct e1000_phy_info *phy = &hw->phy;
1403 s32 ret_val;
1404 u16 data;
1405 bool link;
1406
1407 ret_val = e1e_rphy(hw, PHY_CONTROL, &data);
1408 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001409 return ret_val;
Bruce Allan0be84012009-12-02 17:03:18 +00001410
1411 e1000e_phy_force_speed_duplex_setup(hw, &data);
1412
1413 ret_val = e1e_wphy(hw, PHY_CONTROL, data);
1414 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001415 return ret_val;
Bruce Allan0be84012009-12-02 17:03:18 +00001416
1417 /* Disable MDI-X support for 10/100 */
1418 ret_val = e1e_rphy(hw, IFE_PHY_MDIX_CONTROL, &data);
1419 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001420 return ret_val;
Bruce Allan0be84012009-12-02 17:03:18 +00001421
1422 data &= ~IFE_PMC_AUTO_MDIX;
1423 data &= ~IFE_PMC_FORCE_MDIX;
1424
1425 ret_val = e1e_wphy(hw, IFE_PHY_MDIX_CONTROL, data);
1426 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001427 return ret_val;
Bruce Allan0be84012009-12-02 17:03:18 +00001428
1429 e_dbg("IFE PMC: %X\n", data);
1430
1431 udelay(1);
1432
1433 if (phy->autoneg_wait_to_complete) {
1434 e_dbg("Waiting for forced speed/duplex link on IFE phy.\n");
1435
Bruce Allan3d3a1672012-02-23 03:13:18 +00001436 ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
1437 100000, &link);
Bruce Allan0be84012009-12-02 17:03:18 +00001438 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001439 return ret_val;
Bruce Allan0be84012009-12-02 17:03:18 +00001440
1441 if (!link)
1442 e_dbg("Link taking longer than expected.\n");
1443
1444 /* Try once more */
Bruce Allan3d3a1672012-02-23 03:13:18 +00001445 ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
1446 100000, &link);
Bruce Allan0be84012009-12-02 17:03:18 +00001447 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001448 return ret_val;
Bruce Allan0be84012009-12-02 17:03:18 +00001449 }
1450
Bruce Allan5015e532012-02-08 02:55:56 +00001451 return 0;
Bruce Allan0be84012009-12-02 17:03:18 +00001452}
1453
1454/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001455 * e1000e_phy_force_speed_duplex_setup - Configure forced PHY speed/duplex
1456 * @hw: pointer to the HW structure
1457 * @phy_ctrl: pointer to current value of PHY_CONTROL
1458 *
1459 * Forces speed and duplex on the PHY by doing the following: disable flow
1460 * control, force speed/duplex on the MAC, disable auto speed detection,
1461 * disable auto-negotiation, configure duplex, configure speed, configure
1462 * the collision distance, write configuration to CTRL register. The
1463 * caller must write to the PHY_CONTROL register for these settings to
1464 * take affect.
1465 **/
1466void e1000e_phy_force_speed_duplex_setup(struct e1000_hw *hw, u16 *phy_ctrl)
1467{
1468 struct e1000_mac_info *mac = &hw->mac;
1469 u32 ctrl;
1470
1471 /* Turn off flow control when forcing speed/duplex */
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08001472 hw->fc.current_mode = e1000_fc_none;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001473
1474 /* Force speed/duplex on the mac */
1475 ctrl = er32(CTRL);
1476 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1477 ctrl &= ~E1000_CTRL_SPD_SEL;
1478
1479 /* Disable Auto Speed Detection */
1480 ctrl &= ~E1000_CTRL_ASDE;
1481
1482 /* Disable autoneg on the phy */
1483 *phy_ctrl &= ~MII_CR_AUTO_NEG_EN;
1484
1485 /* Forcing Full or Half Duplex? */
1486 if (mac->forced_speed_duplex & E1000_ALL_HALF_DUPLEX) {
1487 ctrl &= ~E1000_CTRL_FD;
1488 *phy_ctrl &= ~MII_CR_FULL_DUPLEX;
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001489 e_dbg("Half Duplex\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001490 } else {
1491 ctrl |= E1000_CTRL_FD;
1492 *phy_ctrl |= MII_CR_FULL_DUPLEX;
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001493 e_dbg("Full Duplex\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001494 }
1495
1496 /* Forcing 10mb or 100mb? */
1497 if (mac->forced_speed_duplex & E1000_ALL_100_SPEED) {
1498 ctrl |= E1000_CTRL_SPD_100;
1499 *phy_ctrl |= MII_CR_SPEED_100;
1500 *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001501 e_dbg("Forcing 100mb\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001502 } else {
1503 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1504 *phy_ctrl |= MII_CR_SPEED_10;
1505 *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001506 e_dbg("Forcing 10mb\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001507 }
1508
Bruce Allan57cde762012-02-22 09:02:58 +00001509 hw->mac.ops.config_collision_dist(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001510
1511 ew32(CTRL, ctrl);
1512}
1513
1514/**
1515 * e1000e_set_d3_lplu_state - Sets low power link up state for D3
1516 * @hw: pointer to the HW structure
1517 * @active: boolean used to enable/disable lplu
1518 *
1519 * Success returns 0, Failure returns 1
1520 *
1521 * The low power link up (lplu) state is set to the power management level D3
1522 * and SmartSpeed is disabled when active is true, else clear lplu for D3
1523 * and enable Smartspeed. LPLU and Smartspeed are mutually exclusive. LPLU
1524 * is used during Dx states where the power conservation is most important.
1525 * During driver activity, SmartSpeed should be enabled so performance is
1526 * maintained.
1527 **/
1528s32 e1000e_set_d3_lplu_state(struct e1000_hw *hw, bool active)
1529{
1530 struct e1000_phy_info *phy = &hw->phy;
1531 s32 ret_val;
1532 u16 data;
1533
1534 ret_val = e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &data);
1535 if (ret_val)
1536 return ret_val;
1537
1538 if (!active) {
1539 data &= ~IGP02E1000_PM_D3_LPLU;
David Graham2d9498f2008-04-23 11:09:14 -07001540 ret_val = e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001541 if (ret_val)
1542 return ret_val;
Bruce Allane921eb12012-11-28 09:28:37 +00001543 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
Auke Kokbc7f75f2007-09-17 12:30:59 -07001544 * during Dx states where the power conservation is most
1545 * important. During driver activity we should enable
Bruce Allanad680762008-03-28 09:15:03 -07001546 * SmartSpeed, so performance is maintained.
1547 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001548 if (phy->smart_speed == e1000_smart_speed_on) {
1549 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07001550 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001551 if (ret_val)
1552 return ret_val;
1553
1554 data |= IGP01E1000_PSCFR_SMART_SPEED;
1555 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07001556 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001557 if (ret_val)
1558 return ret_val;
1559 } else if (phy->smart_speed == e1000_smart_speed_off) {
1560 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07001561 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001562 if (ret_val)
1563 return ret_val;
1564
1565 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1566 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07001567 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001568 if (ret_val)
1569 return ret_val;
1570 }
1571 } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
1572 (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
1573 (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
1574 data |= IGP02E1000_PM_D3_LPLU;
1575 ret_val = e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, data);
1576 if (ret_val)
1577 return ret_val;
1578
1579 /* When LPLU is enabled, we should disable SmartSpeed */
1580 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
1581 if (ret_val)
1582 return ret_val;
1583
1584 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1585 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
1586 }
1587
1588 return ret_val;
1589}
1590
1591/**
Auke Kok489815c2008-02-21 15:11:07 -08001592 * e1000e_check_downshift - Checks whether a downshift in speed occurred
Auke Kokbc7f75f2007-09-17 12:30:59 -07001593 * @hw: pointer to the HW structure
1594 *
1595 * Success returns 0, Failure returns 1
1596 *
1597 * A downshift is detected by querying the PHY link health.
1598 **/
1599s32 e1000e_check_downshift(struct e1000_hw *hw)
1600{
1601 struct e1000_phy_info *phy = &hw->phy;
1602 s32 ret_val;
1603 u16 phy_data, offset, mask;
1604
1605 switch (phy->type) {
1606 case e1000_phy_m88:
1607 case e1000_phy_gg82563:
Bruce Allan07f025e2009-12-01 15:53:48 +00001608 case e1000_phy_bm:
Bruce Allana4f58f52009-06-02 11:29:18 +00001609 case e1000_phy_82578:
Auke Kokbc7f75f2007-09-17 12:30:59 -07001610 offset = M88E1000_PHY_SPEC_STATUS;
1611 mask = M88E1000_PSSR_DOWNSHIFT;
1612 break;
1613 case e1000_phy_igp_2:
1614 case e1000_phy_igp_3:
1615 offset = IGP01E1000_PHY_LINK_HEALTH;
1616 mask = IGP01E1000_PLHR_SS_DOWNGRADE;
1617 break;
1618 default:
1619 /* speed downshift not supported */
Bruce Allan564ea9b2009-11-20 23:26:44 +00001620 phy->speed_downgraded = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001621 return 0;
1622 }
1623
1624 ret_val = e1e_rphy(hw, offset, &phy_data);
1625
1626 if (!ret_val)
Bruce Allan04499ec2012-04-13 00:08:31 +00001627 phy->speed_downgraded = !!(phy_data & mask);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001628
1629 return ret_val;
1630}
1631
1632/**
1633 * e1000_check_polarity_m88 - Checks the polarity.
1634 * @hw: pointer to the HW structure
1635 *
1636 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1637 *
1638 * Polarity is determined based on the PHY specific status register.
1639 **/
Bruce Allan0be84012009-12-02 17:03:18 +00001640s32 e1000_check_polarity_m88(struct e1000_hw *hw)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001641{
1642 struct e1000_phy_info *phy = &hw->phy;
1643 s32 ret_val;
1644 u16 data;
1645
1646 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &data);
1647
1648 if (!ret_val)
1649 phy->cable_polarity = (data & M88E1000_PSSR_REV_POLARITY)
1650 ? e1000_rev_polarity_reversed
1651 : e1000_rev_polarity_normal;
1652
1653 return ret_val;
1654}
1655
1656/**
1657 * e1000_check_polarity_igp - Checks the polarity.
1658 * @hw: pointer to the HW structure
1659 *
1660 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1661 *
1662 * Polarity is determined based on the PHY port status register, and the
1663 * current speed (since there is no polarity at 100Mbps).
1664 **/
Bruce Allan0be84012009-12-02 17:03:18 +00001665s32 e1000_check_polarity_igp(struct e1000_hw *hw)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001666{
1667 struct e1000_phy_info *phy = &hw->phy;
1668 s32 ret_val;
1669 u16 data, offset, mask;
1670
Bruce Allane921eb12012-11-28 09:28:37 +00001671 /* Polarity is determined based on the speed of
Bruce Allanad680762008-03-28 09:15:03 -07001672 * our connection.
1673 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001674 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_STATUS, &data);
1675 if (ret_val)
1676 return ret_val;
1677
1678 if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
1679 IGP01E1000_PSSR_SPEED_1000MBPS) {
1680 offset = IGP01E1000_PHY_PCS_INIT_REG;
1681 mask = IGP01E1000_PHY_POLARITY_MASK;
1682 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00001683 /* This really only applies to 10Mbps since
Auke Kokbc7f75f2007-09-17 12:30:59 -07001684 * there is no polarity for 100Mbps (always 0).
1685 */
1686 offset = IGP01E1000_PHY_PORT_STATUS;
1687 mask = IGP01E1000_PSSR_POLARITY_REVERSED;
1688 }
1689
1690 ret_val = e1e_rphy(hw, offset, &data);
1691
1692 if (!ret_val)
1693 phy->cable_polarity = (data & mask)
1694 ? e1000_rev_polarity_reversed
1695 : e1000_rev_polarity_normal;
1696
1697 return ret_val;
1698}
1699
1700/**
Bruce Allan0be84012009-12-02 17:03:18 +00001701 * e1000_check_polarity_ife - Check cable polarity for IFE PHY
1702 * @hw: pointer to the HW structure
1703 *
1704 * Polarity is determined on the polarity reversal feature being enabled.
1705 **/
1706s32 e1000_check_polarity_ife(struct e1000_hw *hw)
1707{
1708 struct e1000_phy_info *phy = &hw->phy;
1709 s32 ret_val;
1710 u16 phy_data, offset, mask;
1711
Bruce Allane921eb12012-11-28 09:28:37 +00001712 /* Polarity is determined based on the reversal feature being enabled.
Bruce Allan0be84012009-12-02 17:03:18 +00001713 */
1714 if (phy->polarity_correction) {
1715 offset = IFE_PHY_EXTENDED_STATUS_CONTROL;
1716 mask = IFE_PESC_POLARITY_REVERSED;
1717 } else {
1718 offset = IFE_PHY_SPECIAL_CONTROL;
1719 mask = IFE_PSC_FORCE_POLARITY;
1720 }
1721
1722 ret_val = e1e_rphy(hw, offset, &phy_data);
1723
1724 if (!ret_val)
1725 phy->cable_polarity = (phy_data & mask)
1726 ? e1000_rev_polarity_reversed
1727 : e1000_rev_polarity_normal;
1728
1729 return ret_val;
1730}
1731
1732/**
Bruce Allanad680762008-03-28 09:15:03 -07001733 * e1000_wait_autoneg - Wait for auto-neg completion
Auke Kokbc7f75f2007-09-17 12:30:59 -07001734 * @hw: pointer to the HW structure
1735 *
1736 * Waits for auto-negotiation to complete or for the auto-negotiation time
1737 * limit to expire, which ever happens first.
1738 **/
1739static s32 e1000_wait_autoneg(struct e1000_hw *hw)
1740{
1741 s32 ret_val = 0;
1742 u16 i, phy_status;
1743
1744 /* Break after autoneg completes or PHY_AUTO_NEG_LIMIT expires. */
1745 for (i = PHY_AUTO_NEG_LIMIT; i > 0; i--) {
1746 ret_val = e1e_rphy(hw, PHY_STATUS, &phy_status);
1747 if (ret_val)
1748 break;
1749 ret_val = e1e_rphy(hw, PHY_STATUS, &phy_status);
1750 if (ret_val)
1751 break;
1752 if (phy_status & MII_SR_AUTONEG_COMPLETE)
1753 break;
1754 msleep(100);
1755 }
1756
Bruce Allane921eb12012-11-28 09:28:37 +00001757 /* PHY_AUTO_NEG_TIME expiration doesn't guarantee auto-negotiation
Auke Kokbc7f75f2007-09-17 12:30:59 -07001758 * has completed.
1759 */
1760 return ret_val;
1761}
1762
1763/**
1764 * e1000e_phy_has_link_generic - Polls PHY for link
1765 * @hw: pointer to the HW structure
1766 * @iterations: number of times to poll for link
1767 * @usec_interval: delay between polling attempts
1768 * @success: pointer to whether polling was successful or not
1769 *
1770 * Polls the PHY status register for link, 'iterations' number of times.
1771 **/
1772s32 e1000e_phy_has_link_generic(struct e1000_hw *hw, u32 iterations,
1773 u32 usec_interval, bool *success)
1774{
1775 s32 ret_val = 0;
1776 u16 i, phy_status;
1777
1778 for (i = 0; i < iterations; i++) {
Bruce Allane921eb12012-11-28 09:28:37 +00001779 /* Some PHYs require the PHY_STATUS register to be read
Auke Kokbc7f75f2007-09-17 12:30:59 -07001780 * twice due to the link bit being sticky. No harm doing
1781 * it across the board.
1782 */
1783 ret_val = e1e_rphy(hw, PHY_STATUS, &phy_status);
1784 if (ret_val)
Bruce Allane921eb12012-11-28 09:28:37 +00001785 /* If the first read fails, another entity may have
Bruce Allan906e8d92009-07-01 13:28:50 +00001786 * ownership of the resources, wait and try again to
1787 * see if they have relinquished the resources yet.
1788 */
1789 udelay(usec_interval);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001790 ret_val = e1e_rphy(hw, PHY_STATUS, &phy_status);
1791 if (ret_val)
1792 break;
1793 if (phy_status & MII_SR_LINK_STATUS)
1794 break;
1795 if (usec_interval >= 1000)
1796 mdelay(usec_interval/1000);
1797 else
1798 udelay(usec_interval);
1799 }
1800
1801 *success = (i < iterations);
1802
1803 return ret_val;
1804}
1805
1806/**
1807 * e1000e_get_cable_length_m88 - Determine cable length for m88 PHY
1808 * @hw: pointer to the HW structure
1809 *
1810 * Reads the PHY specific status register to retrieve the cable length
1811 * information. The cable length is determined by averaging the minimum and
1812 * maximum values to get the "average" cable length. The m88 PHY has four
1813 * possible cable length values, which are:
1814 * Register Value Cable Length
1815 * 0 < 50 meters
1816 * 1 50 - 80 meters
1817 * 2 80 - 110 meters
1818 * 3 110 - 140 meters
1819 * 4 > 140 meters
1820 **/
1821s32 e1000e_get_cable_length_m88(struct e1000_hw *hw)
1822{
1823 struct e1000_phy_info *phy = &hw->phy;
1824 s32 ret_val;
1825 u16 phy_data, index;
1826
1827 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
1828 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001829 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001830
1831 index = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
Bruce Allaneb656d42009-12-01 15:47:02 +00001832 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
Bruce Allan5015e532012-02-08 02:55:56 +00001833
1834 if (index >= M88E1000_CABLE_LENGTH_TABLE_SIZE - 1)
1835 return -E1000_ERR_PHY;
Bruce Allaneb656d42009-12-01 15:47:02 +00001836
Auke Kokbc7f75f2007-09-17 12:30:59 -07001837 phy->min_cable_length = e1000_m88_cable_length_table[index];
Bruce Allaneb656d42009-12-01 15:47:02 +00001838 phy->max_cable_length = e1000_m88_cable_length_table[index + 1];
Auke Kokbc7f75f2007-09-17 12:30:59 -07001839
1840 phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
1841
Bruce Allan5015e532012-02-08 02:55:56 +00001842 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001843}
1844
1845/**
1846 * e1000e_get_cable_length_igp_2 - Determine cable length for igp2 PHY
1847 * @hw: pointer to the HW structure
1848 *
1849 * The automatic gain control (agc) normalizes the amplitude of the
1850 * received signal, adjusting for the attenuation produced by the
Auke Kok489815c2008-02-21 15:11:07 -08001851 * cable. By reading the AGC registers, which represent the
Bruce Allan5ff5b662009-12-01 15:51:11 +00001852 * combination of coarse and fine gain value, the value can be put
Auke Kokbc7f75f2007-09-17 12:30:59 -07001853 * into a lookup table to obtain the approximate cable length
1854 * for each channel.
1855 **/
1856s32 e1000e_get_cable_length_igp_2(struct e1000_hw *hw)
1857{
1858 struct e1000_phy_info *phy = &hw->phy;
1859 s32 ret_val;
1860 u16 phy_data, i, agc_value = 0;
1861 u16 cur_agc_index, max_agc_index = 0;
1862 u16 min_agc_index = IGP02E1000_CABLE_LENGTH_TABLE_SIZE - 1;
Jeff Kirsher66744502010-12-01 19:59:50 +00001863 static const u16 agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] = {
1864 IGP02E1000_PHY_AGC_A,
1865 IGP02E1000_PHY_AGC_B,
1866 IGP02E1000_PHY_AGC_C,
1867 IGP02E1000_PHY_AGC_D
1868 };
Auke Kokbc7f75f2007-09-17 12:30:59 -07001869
1870 /* Read the AGC registers for all channels */
1871 for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
1872 ret_val = e1e_rphy(hw, agc_reg_array[i], &phy_data);
1873 if (ret_val)
1874 return ret_val;
1875
Bruce Allane921eb12012-11-28 09:28:37 +00001876 /* Getting bits 15:9, which represent the combination of
Bruce Allan5ff5b662009-12-01 15:51:11 +00001877 * coarse and fine gain values. The result is a number
Auke Kokbc7f75f2007-09-17 12:30:59 -07001878 * that can be put into the lookup table to obtain the
Bruce Allanad680762008-03-28 09:15:03 -07001879 * approximate cable length.
1880 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001881 cur_agc_index = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
1882 IGP02E1000_AGC_LENGTH_MASK;
1883
1884 /* Array index bound check. */
1885 if ((cur_agc_index >= IGP02E1000_CABLE_LENGTH_TABLE_SIZE) ||
1886 (cur_agc_index == 0))
1887 return -E1000_ERR_PHY;
1888
1889 /* Remove min & max AGC values from calculation. */
1890 if (e1000_igp_2_cable_length_table[min_agc_index] >
1891 e1000_igp_2_cable_length_table[cur_agc_index])
1892 min_agc_index = cur_agc_index;
1893 if (e1000_igp_2_cable_length_table[max_agc_index] <
1894 e1000_igp_2_cable_length_table[cur_agc_index])
1895 max_agc_index = cur_agc_index;
1896
1897 agc_value += e1000_igp_2_cable_length_table[cur_agc_index];
1898 }
1899
1900 agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] +
1901 e1000_igp_2_cable_length_table[max_agc_index]);
1902 agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
1903
1904 /* Calculate cable length with the error range of +/- 10 meters. */
1905 phy->min_cable_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
1906 (agc_value - IGP02E1000_AGC_RANGE) : 0;
1907 phy->max_cable_length = agc_value + IGP02E1000_AGC_RANGE;
1908
1909 phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
1910
Bruce Allan82607252012-02-08 02:55:09 +00001911 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001912}
1913
1914/**
1915 * e1000e_get_phy_info_m88 - Retrieve PHY information
1916 * @hw: pointer to the HW structure
1917 *
1918 * Valid for only copper links. Read the PHY status register (sticky read)
1919 * to verify that link is up. Read the PHY special control register to
1920 * determine the polarity and 10base-T extended distance. Read the PHY
1921 * special status register to determine MDI/MDIx and current speed. If
1922 * speed is 1000, then determine cable length, local and remote receiver.
1923 **/
1924s32 e1000e_get_phy_info_m88(struct e1000_hw *hw)
1925{
1926 struct e1000_phy_info *phy = &hw->phy;
1927 s32 ret_val;
1928 u16 phy_data;
1929 bool link;
1930
Bruce Allan0be84012009-12-02 17:03:18 +00001931 if (phy->media_type != e1000_media_type_copper) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001932 e_dbg("Phy info is only valid for copper media\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001933 return -E1000_ERR_CONFIG;
1934 }
1935
1936 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
1937 if (ret_val)
1938 return ret_val;
1939
1940 if (!link) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001941 e_dbg("Phy info is only valid if link is up\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001942 return -E1000_ERR_CONFIG;
1943 }
1944
1945 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1946 if (ret_val)
1947 return ret_val;
1948
Bruce Allan04499ec2012-04-13 00:08:31 +00001949 phy->polarity_correction = !!(phy_data &
1950 M88E1000_PSCR_POLARITY_REVERSAL);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001951
1952 ret_val = e1000_check_polarity_m88(hw);
1953 if (ret_val)
1954 return ret_val;
1955
1956 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
1957 if (ret_val)
1958 return ret_val;
1959
Bruce Allan04499ec2012-04-13 00:08:31 +00001960 phy->is_mdix = !!(phy_data & M88E1000_PSSR_MDIX);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001961
1962 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
1963 ret_val = e1000_get_cable_length(hw);
1964 if (ret_val)
1965 return ret_val;
1966
1967 ret_val = e1e_rphy(hw, PHY_1000T_STATUS, &phy_data);
1968 if (ret_val)
1969 return ret_val;
1970
1971 phy->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS)
1972 ? e1000_1000t_rx_status_ok
1973 : e1000_1000t_rx_status_not_ok;
1974
1975 phy->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS)
1976 ? e1000_1000t_rx_status_ok
1977 : e1000_1000t_rx_status_not_ok;
1978 } else {
1979 /* Set values to "undefined" */
1980 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
1981 phy->local_rx = e1000_1000t_rx_status_undefined;
1982 phy->remote_rx = e1000_1000t_rx_status_undefined;
1983 }
1984
1985 return ret_val;
1986}
1987
1988/**
1989 * e1000e_get_phy_info_igp - Retrieve igp PHY information
1990 * @hw: pointer to the HW structure
1991 *
1992 * Read PHY status to determine if link is up. If link is up, then
1993 * set/determine 10base-T extended distance and polarity correction. Read
1994 * PHY port status to determine MDI/MDIx and speed. Based on the speed,
1995 * determine on the cable length, local and remote receiver.
1996 **/
1997s32 e1000e_get_phy_info_igp(struct e1000_hw *hw)
1998{
1999 struct e1000_phy_info *phy = &hw->phy;
2000 s32 ret_val;
2001 u16 data;
2002 bool link;
2003
2004 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
2005 if (ret_val)
2006 return ret_val;
2007
2008 if (!link) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002009 e_dbg("Phy info is only valid if link is up\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002010 return -E1000_ERR_CONFIG;
2011 }
2012
Bruce Allan564ea9b2009-11-20 23:26:44 +00002013 phy->polarity_correction = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002014
2015 ret_val = e1000_check_polarity_igp(hw);
2016 if (ret_val)
2017 return ret_val;
2018
2019 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_STATUS, &data);
2020 if (ret_val)
2021 return ret_val;
2022
Bruce Allan04499ec2012-04-13 00:08:31 +00002023 phy->is_mdix = !!(data & IGP01E1000_PSSR_MDIX);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002024
2025 if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
2026 IGP01E1000_PSSR_SPEED_1000MBPS) {
2027 ret_val = e1000_get_cable_length(hw);
2028 if (ret_val)
2029 return ret_val;
2030
2031 ret_val = e1e_rphy(hw, PHY_1000T_STATUS, &data);
2032 if (ret_val)
2033 return ret_val;
2034
2035 phy->local_rx = (data & SR_1000T_LOCAL_RX_STATUS)
2036 ? e1000_1000t_rx_status_ok
2037 : e1000_1000t_rx_status_not_ok;
2038
2039 phy->remote_rx = (data & SR_1000T_REMOTE_RX_STATUS)
2040 ? e1000_1000t_rx_status_ok
2041 : e1000_1000t_rx_status_not_ok;
2042 } else {
2043 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
2044 phy->local_rx = e1000_1000t_rx_status_undefined;
2045 phy->remote_rx = e1000_1000t_rx_status_undefined;
2046 }
2047
2048 return ret_val;
2049}
2050
2051/**
Bruce Allan0be84012009-12-02 17:03:18 +00002052 * e1000_get_phy_info_ife - Retrieves various IFE PHY states
2053 * @hw: pointer to the HW structure
2054 *
2055 * Populates "phy" structure with various feature states.
2056 **/
2057s32 e1000_get_phy_info_ife(struct e1000_hw *hw)
2058{
2059 struct e1000_phy_info *phy = &hw->phy;
2060 s32 ret_val;
2061 u16 data;
2062 bool link;
2063
2064 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
2065 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002066 return ret_val;
Bruce Allan0be84012009-12-02 17:03:18 +00002067
2068 if (!link) {
2069 e_dbg("Phy info is only valid if link is up\n");
Bruce Allan5015e532012-02-08 02:55:56 +00002070 return -E1000_ERR_CONFIG;
Bruce Allan0be84012009-12-02 17:03:18 +00002071 }
2072
2073 ret_val = e1e_rphy(hw, IFE_PHY_SPECIAL_CONTROL, &data);
2074 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002075 return ret_val;
Bruce Allan04499ec2012-04-13 00:08:31 +00002076 phy->polarity_correction = !(data & IFE_PSC_AUTO_POLARITY_DISABLE);
Bruce Allan0be84012009-12-02 17:03:18 +00002077
2078 if (phy->polarity_correction) {
2079 ret_val = e1000_check_polarity_ife(hw);
2080 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002081 return ret_val;
Bruce Allan0be84012009-12-02 17:03:18 +00002082 } else {
2083 /* Polarity is forced */
2084 phy->cable_polarity = (data & IFE_PSC_FORCE_POLARITY)
2085 ? e1000_rev_polarity_reversed
2086 : e1000_rev_polarity_normal;
2087 }
2088
2089 ret_val = e1e_rphy(hw, IFE_PHY_MDIX_CONTROL, &data);
2090 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002091 return ret_val;
Bruce Allan0be84012009-12-02 17:03:18 +00002092
Bruce Allan04499ec2012-04-13 00:08:31 +00002093 phy->is_mdix = !!(data & IFE_PMC_MDIX_STATUS);
Bruce Allan0be84012009-12-02 17:03:18 +00002094
2095 /* The following parameters are undefined for 10/100 operation. */
2096 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
2097 phy->local_rx = e1000_1000t_rx_status_undefined;
2098 phy->remote_rx = e1000_1000t_rx_status_undefined;
2099
Bruce Allan5015e532012-02-08 02:55:56 +00002100 return 0;
Bruce Allan0be84012009-12-02 17:03:18 +00002101}
2102
2103/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002104 * e1000e_phy_sw_reset - PHY software reset
2105 * @hw: pointer to the HW structure
2106 *
2107 * Does a software reset of the PHY by reading the PHY control register and
2108 * setting/write the control register reset bit to the PHY.
2109 **/
2110s32 e1000e_phy_sw_reset(struct e1000_hw *hw)
2111{
2112 s32 ret_val;
2113 u16 phy_ctrl;
2114
2115 ret_val = e1e_rphy(hw, PHY_CONTROL, &phy_ctrl);
2116 if (ret_val)
2117 return ret_val;
2118
2119 phy_ctrl |= MII_CR_RESET;
2120 ret_val = e1e_wphy(hw, PHY_CONTROL, phy_ctrl);
2121 if (ret_val)
2122 return ret_val;
2123
2124 udelay(1);
2125
2126 return ret_val;
2127}
2128
2129/**
2130 * e1000e_phy_hw_reset_generic - PHY hardware reset
2131 * @hw: pointer to the HW structure
2132 *
2133 * Verify the reset block is not blocking us from resetting. Acquire
2134 * semaphore (if necessary) and read/set/write the device control reset
2135 * bit in the PHY. Wait the appropriate delay time for the device to
Auke Kok489815c2008-02-21 15:11:07 -08002136 * reset and release the semaphore (if necessary).
Auke Kokbc7f75f2007-09-17 12:30:59 -07002137 **/
2138s32 e1000e_phy_hw_reset_generic(struct e1000_hw *hw)
2139{
2140 struct e1000_phy_info *phy = &hw->phy;
2141 s32 ret_val;
2142 u32 ctrl;
2143
Bruce Allan470a5422012-05-26 06:08:48 +00002144 if (phy->ops.check_reset_block) {
2145 ret_val = phy->ops.check_reset_block(hw);
2146 if (ret_val)
2147 return 0;
2148 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002149
Bruce Allan94d81862009-11-20 23:25:26 +00002150 ret_val = phy->ops.acquire(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002151 if (ret_val)
2152 return ret_val;
2153
2154 ctrl = er32(CTRL);
2155 ew32(CTRL, ctrl | E1000_CTRL_PHY_RST);
2156 e1e_flush();
2157
2158 udelay(phy->reset_delay_us);
2159
2160 ew32(CTRL, ctrl);
2161 e1e_flush();
2162
2163 udelay(150);
2164
Bruce Allan94d81862009-11-20 23:25:26 +00002165 phy->ops.release(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002166
Bruce Allan84c1bef2013-01-05 08:06:19 +00002167 return phy->ops.get_cfg_done(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002168}
2169
2170/**
Bruce Allanfe908492013-01-05 08:06:14 +00002171 * e1000e_get_cfg_done_generic - Generic configuration done
Auke Kokbc7f75f2007-09-17 12:30:59 -07002172 * @hw: pointer to the HW structure
2173 *
2174 * Generic function to wait 10 milli-seconds for configuration to complete
2175 * and return success.
2176 **/
Bruce Allanfe908492013-01-05 08:06:14 +00002177s32 e1000e_get_cfg_done_generic(struct e1000_hw *hw)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002178{
2179 mdelay(10);
Bruce Allan3d3a1672012-02-23 03:13:18 +00002180
Auke Kokbc7f75f2007-09-17 12:30:59 -07002181 return 0;
2182}
2183
Bruce Allanf4187b52008-08-26 18:36:50 -07002184/**
2185 * e1000e_phy_init_script_igp3 - Inits the IGP3 PHY
2186 * @hw: pointer to the HW structure
2187 *
2188 * Initializes a Intel Gigabit PHY3 when an EEPROM is not present.
2189 **/
2190s32 e1000e_phy_init_script_igp3(struct e1000_hw *hw)
2191{
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002192 e_dbg("Running IGP 3 PHY init script\n");
Bruce Allanf4187b52008-08-26 18:36:50 -07002193
2194 /* PHY init IGP 3 */
2195 /* Enable rise/fall, 10-mode work in class-A */
2196 e1e_wphy(hw, 0x2F5B, 0x9018);
2197 /* Remove all caps from Replica path filter */
2198 e1e_wphy(hw, 0x2F52, 0x0000);
2199 /* Bias trimming for ADC, AFE and Driver (Default) */
2200 e1e_wphy(hw, 0x2FB1, 0x8B24);
2201 /* Increase Hybrid poly bias */
2202 e1e_wphy(hw, 0x2FB2, 0xF8F0);
2203 /* Add 4% to Tx amplitude in Gig mode */
2204 e1e_wphy(hw, 0x2010, 0x10B0);
2205 /* Disable trimming (TTT) */
2206 e1e_wphy(hw, 0x2011, 0x0000);
2207 /* Poly DC correction to 94.6% + 2% for all channels */
2208 e1e_wphy(hw, 0x20DD, 0x249A);
2209 /* ABS DC correction to 95.9% */
2210 e1e_wphy(hw, 0x20DE, 0x00D3);
2211 /* BG temp curve trim */
2212 e1e_wphy(hw, 0x28B4, 0x04CE);
2213 /* Increasing ADC OPAMP stage 1 currents to max */
2214 e1e_wphy(hw, 0x2F70, 0x29E4);
2215 /* Force 1000 ( required for enabling PHY regs configuration) */
2216 e1e_wphy(hw, 0x0000, 0x0140);
2217 /* Set upd_freq to 6 */
2218 e1e_wphy(hw, 0x1F30, 0x1606);
2219 /* Disable NPDFE */
2220 e1e_wphy(hw, 0x1F31, 0xB814);
2221 /* Disable adaptive fixed FFE (Default) */
2222 e1e_wphy(hw, 0x1F35, 0x002A);
2223 /* Enable FFE hysteresis */
2224 e1e_wphy(hw, 0x1F3E, 0x0067);
2225 /* Fixed FFE for short cable lengths */
2226 e1e_wphy(hw, 0x1F54, 0x0065);
2227 /* Fixed FFE for medium cable lengths */
2228 e1e_wphy(hw, 0x1F55, 0x002A);
2229 /* Fixed FFE for long cable lengths */
2230 e1e_wphy(hw, 0x1F56, 0x002A);
2231 /* Enable Adaptive Clip Threshold */
2232 e1e_wphy(hw, 0x1F72, 0x3FB0);
2233 /* AHT reset limit to 1 */
2234 e1e_wphy(hw, 0x1F76, 0xC0FF);
2235 /* Set AHT master delay to 127 msec */
2236 e1e_wphy(hw, 0x1F77, 0x1DEC);
2237 /* Set scan bits for AHT */
2238 e1e_wphy(hw, 0x1F78, 0xF9EF);
2239 /* Set AHT Preset bits */
2240 e1e_wphy(hw, 0x1F79, 0x0210);
2241 /* Change integ_factor of channel A to 3 */
2242 e1e_wphy(hw, 0x1895, 0x0003);
2243 /* Change prop_factor of channels BCD to 8 */
2244 e1e_wphy(hw, 0x1796, 0x0008);
2245 /* Change cg_icount + enable integbp for channels BCD */
2246 e1e_wphy(hw, 0x1798, 0xD008);
Bruce Allane921eb12012-11-28 09:28:37 +00002247 /* Change cg_icount + enable integbp + change prop_factor_master
Bruce Allanf4187b52008-08-26 18:36:50 -07002248 * to 8 for channel A
2249 */
2250 e1e_wphy(hw, 0x1898, 0xD918);
2251 /* Disable AHT in Slave mode on channel A */
2252 e1e_wphy(hw, 0x187A, 0x0800);
Bruce Allane921eb12012-11-28 09:28:37 +00002253 /* Enable LPLU and disable AN to 1000 in non-D0a states,
Bruce Allanf4187b52008-08-26 18:36:50 -07002254 * Enable SPD+B2B
2255 */
2256 e1e_wphy(hw, 0x0019, 0x008D);
2257 /* Enable restart AN on an1000_dis change */
2258 e1e_wphy(hw, 0x001B, 0x2080);
2259 /* Enable wh_fifo read clock in 10/100 modes */
2260 e1e_wphy(hw, 0x0014, 0x0045);
2261 /* Restart AN, Speed selection is 1000 */
2262 e1e_wphy(hw, 0x0000, 0x1340);
2263
2264 return 0;
2265}
2266
Auke Kokbc7f75f2007-09-17 12:30:59 -07002267/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002268 * e1000e_get_phy_type_from_id - Get PHY type from id
2269 * @phy_id: phy_id read from the phy
2270 *
2271 * Returns the phy type from the id.
2272 **/
2273enum e1000_phy_type e1000e_get_phy_type_from_id(u32 phy_id)
2274{
2275 enum e1000_phy_type phy_type = e1000_phy_unknown;
2276
2277 switch (phy_id) {
2278 case M88E1000_I_PHY_ID:
2279 case M88E1000_E_PHY_ID:
2280 case M88E1111_I_PHY_ID:
2281 case M88E1011_I_PHY_ID:
2282 phy_type = e1000_phy_m88;
2283 break;
2284 case IGP01E1000_I_PHY_ID: /* IGP 1 & 2 share this */
2285 phy_type = e1000_phy_igp_2;
2286 break;
2287 case GG82563_E_PHY_ID:
2288 phy_type = e1000_phy_gg82563;
2289 break;
2290 case IGP03E1000_E_PHY_ID:
2291 phy_type = e1000_phy_igp_3;
2292 break;
2293 case IFE_E_PHY_ID:
2294 case IFE_PLUS_E_PHY_ID:
2295 case IFE_C_E_PHY_ID:
2296 phy_type = e1000_phy_ife;
2297 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002298 case BME1000_E_PHY_ID:
2299 case BME1000_E_PHY_ID_R2:
2300 phy_type = e1000_phy_bm;
2301 break;
Bruce Allana4f58f52009-06-02 11:29:18 +00002302 case I82578_E_PHY_ID:
2303 phy_type = e1000_phy_82578;
2304 break;
2305 case I82577_E_PHY_ID:
2306 phy_type = e1000_phy_82577;
2307 break;
Bruce Alland3738bb2010-06-16 13:27:28 +00002308 case I82579_E_PHY_ID:
2309 phy_type = e1000_phy_82579;
2310 break;
Bruce Allan2fbe4522012-04-19 03:21:47 +00002311 case I217_E_PHY_ID:
2312 phy_type = e1000_phy_i217;
2313 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002314 default:
2315 phy_type = e1000_phy_unknown;
2316 break;
2317 }
2318 return phy_type;
2319}
2320
2321/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002322 * e1000e_determine_phy_address - Determines PHY address.
2323 * @hw: pointer to the HW structure
2324 *
2325 * This uses a trial and error method to loop through possible PHY
2326 * addresses. It tests each by reading the PHY ID registers and
2327 * checking for a match.
2328 **/
2329s32 e1000e_determine_phy_address(struct e1000_hw *hw)
2330{
Bruce Allan5eb6f3c2009-12-02 17:02:43 +00002331 u32 phy_addr = 0;
2332 u32 i;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002333 enum e1000_phy_type phy_type = e1000_phy_unknown;
2334
Bruce Allan5eb6f3c2009-12-02 17:02:43 +00002335 hw->phy.id = phy_type;
2336
2337 for (phy_addr = 0; phy_addr < E1000_MAX_PHY_ADDR; phy_addr++) {
2338 hw->phy.addr = phy_addr;
2339 i = 0;
2340
2341 do {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002342 e1000e_get_phy_id(hw);
2343 phy_type = e1000e_get_phy_type_from_id(hw->phy.id);
2344
Bruce Allane921eb12012-11-28 09:28:37 +00002345 /* If phy_type is valid, break - we found our
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002346 * PHY address
2347 */
Bruce Allan5015e532012-02-08 02:55:56 +00002348 if (phy_type != e1000_phy_unknown)
2349 return 0;
2350
Bruce Allan1bba4382011-03-19 00:27:20 +00002351 usleep_range(1000, 2000);
Bruce Allan5eb6f3c2009-12-02 17:02:43 +00002352 i++;
2353 } while (i < 10);
2354 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002355
Bruce Allan5015e532012-02-08 02:55:56 +00002356 return -E1000_ERR_PHY_TYPE;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002357}
2358
2359/**
2360 * e1000_get_phy_addr_for_bm_page - Retrieve PHY page address
2361 * @page: page to access
2362 *
2363 * Returns the phy address for the page requested.
2364 **/
2365static u32 e1000_get_phy_addr_for_bm_page(u32 page, u32 reg)
2366{
2367 u32 phy_addr = 2;
2368
2369 if ((page >= 768) || (page == 0 && reg == 25) || (reg == 31))
2370 phy_addr = 1;
2371
2372 return phy_addr;
2373}
2374
2375/**
2376 * e1000e_write_phy_reg_bm - Write BM PHY register
2377 * @hw: pointer to the HW structure
2378 * @offset: register offset to write to
2379 * @data: data to write at register offset
2380 *
2381 * Acquires semaphore, if necessary, then writes the data to PHY register
2382 * at the offset. Release any acquired semaphores before exiting.
2383 **/
2384s32 e1000e_write_phy_reg_bm(struct e1000_hw *hw, u32 offset, u16 data)
2385{
2386 s32 ret_val;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002387 u32 page = offset >> IGP_PAGE_SHIFT;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002388
Bruce Allan94d81862009-11-20 23:25:26 +00002389 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002390 if (ret_val)
2391 return ret_val;
2392
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002393 /* Page 800 works differently than the rest so it has its own func */
2394 if (page == BM_WUC_PAGE) {
2395 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, &data,
Bruce Allan2b6b1682011-05-13 07:20:09 +00002396 false, false);
Bruce Allan75ce1532012-02-08 02:54:48 +00002397 goto release;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002398 }
2399
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002400 hw->phy.addr = e1000_get_phy_addr_for_bm_page(page, offset);
2401
2402 if (offset > MAX_PHY_MULTI_PAGE_REG) {
Bruce Allan90da0662011-01-06 07:02:53 +00002403 u32 page_shift, page_select;
2404
Bruce Allane921eb12012-11-28 09:28:37 +00002405 /* Page select is register 31 for phy address 1 and 22 for
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002406 * phy address 2 and 3. Page select is shifted only for
2407 * phy address 1.
2408 */
2409 if (hw->phy.addr == 1) {
2410 page_shift = IGP_PAGE_SHIFT;
2411 page_select = IGP01E1000_PHY_PAGE_SELECT;
2412 } else {
2413 page_shift = 0;
2414 page_select = BM_PHY_PAGE_SELECT;
2415 }
2416
2417 /* Page is shifted left, PHY expects (page x 32) */
2418 ret_val = e1000e_write_phy_reg_mdic(hw, page_select,
2419 (page << page_shift));
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002420 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00002421 goto release;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002422 }
2423
2424 ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
2425 data);
2426
Bruce Allan75ce1532012-02-08 02:54:48 +00002427release:
Bruce Allan94d81862009-11-20 23:25:26 +00002428 hw->phy.ops.release(hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002429 return ret_val;
2430}
2431
2432/**
2433 * e1000e_read_phy_reg_bm - Read BM PHY register
2434 * @hw: pointer to the HW structure
2435 * @offset: register offset to be read
2436 * @data: pointer to the read data
2437 *
2438 * Acquires semaphore, if necessary, then reads the PHY register at offset
2439 * and storing the retrieved information in data. Release any acquired
2440 * semaphores before exiting.
2441 **/
2442s32 e1000e_read_phy_reg_bm(struct e1000_hw *hw, u32 offset, u16 *data)
2443{
2444 s32 ret_val;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002445 u32 page = offset >> IGP_PAGE_SHIFT;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002446
Bruce Allan94d81862009-11-20 23:25:26 +00002447 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002448 if (ret_val)
2449 return ret_val;
2450
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002451 /* Page 800 works differently than the rest so it has its own func */
2452 if (page == BM_WUC_PAGE) {
2453 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, data,
Bruce Allan2b6b1682011-05-13 07:20:09 +00002454 true, false);
Bruce Allan75ce1532012-02-08 02:54:48 +00002455 goto release;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002456 }
2457
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002458 hw->phy.addr = e1000_get_phy_addr_for_bm_page(page, offset);
2459
2460 if (offset > MAX_PHY_MULTI_PAGE_REG) {
Bruce Allan90da0662011-01-06 07:02:53 +00002461 u32 page_shift, page_select;
2462
Bruce Allane921eb12012-11-28 09:28:37 +00002463 /* Page select is register 31 for phy address 1 and 22 for
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002464 * phy address 2 and 3. Page select is shifted only for
2465 * phy address 1.
2466 */
2467 if (hw->phy.addr == 1) {
2468 page_shift = IGP_PAGE_SHIFT;
2469 page_select = IGP01E1000_PHY_PAGE_SELECT;
2470 } else {
2471 page_shift = 0;
2472 page_select = BM_PHY_PAGE_SELECT;
2473 }
2474
2475 /* Page is shifted left, PHY expects (page x 32) */
2476 ret_val = e1000e_write_phy_reg_mdic(hw, page_select,
2477 (page << page_shift));
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002478 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00002479 goto release;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002480 }
2481
2482 ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
2483 data);
Bruce Allan75ce1532012-02-08 02:54:48 +00002484release:
Bruce Allan94d81862009-11-20 23:25:26 +00002485 hw->phy.ops.release(hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002486 return ret_val;
2487}
2488
2489/**
Bruce Allan4662e822008-08-26 18:37:06 -07002490 * e1000e_read_phy_reg_bm2 - Read BM PHY register
2491 * @hw: pointer to the HW structure
2492 * @offset: register offset to be read
2493 * @data: pointer to the read data
2494 *
2495 * Acquires semaphore, if necessary, then reads the PHY register at offset
2496 * and storing the retrieved information in data. Release any acquired
2497 * semaphores before exiting.
2498 **/
2499s32 e1000e_read_phy_reg_bm2(struct e1000_hw *hw, u32 offset, u16 *data)
2500{
2501 s32 ret_val;
2502 u16 page = (u16)(offset >> IGP_PAGE_SHIFT);
2503
Bruce Allan94d81862009-11-20 23:25:26 +00002504 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002505 if (ret_val)
2506 return ret_val;
2507
Bruce Allan4662e822008-08-26 18:37:06 -07002508 /* Page 800 works differently than the rest so it has its own func */
2509 if (page == BM_WUC_PAGE) {
2510 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, data,
Bruce Allan2b6b1682011-05-13 07:20:09 +00002511 true, false);
Bruce Allan75ce1532012-02-08 02:54:48 +00002512 goto release;
Bruce Allan4662e822008-08-26 18:37:06 -07002513 }
2514
Bruce Allan4662e822008-08-26 18:37:06 -07002515 hw->phy.addr = 1;
2516
2517 if (offset > MAX_PHY_MULTI_PAGE_REG) {
2518
2519 /* Page is shifted left, PHY expects (page x 32) */
2520 ret_val = e1000e_write_phy_reg_mdic(hw, BM_PHY_PAGE_SELECT,
2521 page);
2522
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002523 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00002524 goto release;
Bruce Allan4662e822008-08-26 18:37:06 -07002525 }
2526
2527 ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
2528 data);
Bruce Allan75ce1532012-02-08 02:54:48 +00002529release:
Bruce Allan94d81862009-11-20 23:25:26 +00002530 hw->phy.ops.release(hw);
Bruce Allan4662e822008-08-26 18:37:06 -07002531 return ret_val;
2532}
2533
2534/**
2535 * e1000e_write_phy_reg_bm2 - Write BM PHY register
2536 * @hw: pointer to the HW structure
2537 * @offset: register offset to write to
2538 * @data: data to write at register offset
2539 *
2540 * Acquires semaphore, if necessary, then writes the data to PHY register
2541 * at the offset. Release any acquired semaphores before exiting.
2542 **/
2543s32 e1000e_write_phy_reg_bm2(struct e1000_hw *hw, u32 offset, u16 data)
2544{
2545 s32 ret_val;
2546 u16 page = (u16)(offset >> IGP_PAGE_SHIFT);
2547
Bruce Allan94d81862009-11-20 23:25:26 +00002548 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002549 if (ret_val)
2550 return ret_val;
2551
Bruce Allan4662e822008-08-26 18:37:06 -07002552 /* Page 800 works differently than the rest so it has its own func */
2553 if (page == BM_WUC_PAGE) {
2554 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, &data,
Bruce Allan2b6b1682011-05-13 07:20:09 +00002555 false, false);
Bruce Allan75ce1532012-02-08 02:54:48 +00002556 goto release;
Bruce Allan4662e822008-08-26 18:37:06 -07002557 }
2558
Bruce Allan4662e822008-08-26 18:37:06 -07002559 hw->phy.addr = 1;
2560
2561 if (offset > MAX_PHY_MULTI_PAGE_REG) {
2562 /* Page is shifted left, PHY expects (page x 32) */
2563 ret_val = e1000e_write_phy_reg_mdic(hw, BM_PHY_PAGE_SELECT,
2564 page);
2565
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002566 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00002567 goto release;
Bruce Allan4662e822008-08-26 18:37:06 -07002568 }
2569
2570 ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
2571 data);
2572
Bruce Allan75ce1532012-02-08 02:54:48 +00002573release:
Bruce Allan94d81862009-11-20 23:25:26 +00002574 hw->phy.ops.release(hw);
Bruce Allan4662e822008-08-26 18:37:06 -07002575 return ret_val;
2576}
2577
2578/**
Bruce Allan2b6b1682011-05-13 07:20:09 +00002579 * e1000_enable_phy_wakeup_reg_access_bm - enable access to BM wakeup registers
2580 * @hw: pointer to the HW structure
2581 * @phy_reg: pointer to store original contents of BM_WUC_ENABLE_REG
2582 *
2583 * Assumes semaphore already acquired and phy_reg points to a valid memory
2584 * address to store contents of the BM_WUC_ENABLE_REG register.
2585 **/
2586s32 e1000_enable_phy_wakeup_reg_access_bm(struct e1000_hw *hw, u16 *phy_reg)
2587{
2588 s32 ret_val;
2589 u16 temp;
2590
2591 /* All page select, port ctrl and wakeup registers use phy address 1 */
2592 hw->phy.addr = 1;
2593
2594 /* Select Port Control Registers page */
2595 ret_val = e1000_set_page_igp(hw, (BM_PORT_CTRL_PAGE << IGP_PAGE_SHIFT));
2596 if (ret_val) {
2597 e_dbg("Could not set Port Control page\n");
Bruce Allan5015e532012-02-08 02:55:56 +00002598 return ret_val;
Bruce Allan2b6b1682011-05-13 07:20:09 +00002599 }
2600
2601 ret_val = e1000e_read_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, phy_reg);
2602 if (ret_val) {
2603 e_dbg("Could not read PHY register %d.%d\n",
2604 BM_PORT_CTRL_PAGE, BM_WUC_ENABLE_REG);
Bruce Allan5015e532012-02-08 02:55:56 +00002605 return ret_val;
Bruce Allan2b6b1682011-05-13 07:20:09 +00002606 }
2607
Bruce Allane921eb12012-11-28 09:28:37 +00002608 /* Enable both PHY wakeup mode and Wakeup register page writes.
Bruce Allan2b6b1682011-05-13 07:20:09 +00002609 * Prevent a power state change by disabling ME and Host PHY wakeup.
2610 */
2611 temp = *phy_reg;
2612 temp |= BM_WUC_ENABLE_BIT;
2613 temp &= ~(BM_WUC_ME_WU_BIT | BM_WUC_HOST_WU_BIT);
2614
2615 ret_val = e1000e_write_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, temp);
2616 if (ret_val) {
2617 e_dbg("Could not write PHY register %d.%d\n",
2618 BM_PORT_CTRL_PAGE, BM_WUC_ENABLE_REG);
Bruce Allan5015e532012-02-08 02:55:56 +00002619 return ret_val;
Bruce Allan2b6b1682011-05-13 07:20:09 +00002620 }
2621
Bruce Allane921eb12012-11-28 09:28:37 +00002622 /* Select Host Wakeup Registers page - caller now able to write
Bruce Allan5015e532012-02-08 02:55:56 +00002623 * registers on the Wakeup registers page
2624 */
2625 return e1000_set_page_igp(hw, (BM_WUC_PAGE << IGP_PAGE_SHIFT));
Bruce Allan2b6b1682011-05-13 07:20:09 +00002626}
2627
2628/**
2629 * e1000_disable_phy_wakeup_reg_access_bm - disable access to BM wakeup regs
2630 * @hw: pointer to the HW structure
2631 * @phy_reg: pointer to original contents of BM_WUC_ENABLE_REG
2632 *
2633 * Restore BM_WUC_ENABLE_REG to its original value.
2634 *
2635 * Assumes semaphore already acquired and *phy_reg is the contents of the
2636 * BM_WUC_ENABLE_REG before register(s) on BM_WUC_PAGE were accessed by
2637 * caller.
2638 **/
2639s32 e1000_disable_phy_wakeup_reg_access_bm(struct e1000_hw *hw, u16 *phy_reg)
2640{
Bruce Allan70806a72013-01-05 05:08:37 +00002641 s32 ret_val;
Bruce Allan2b6b1682011-05-13 07:20:09 +00002642
2643 /* Select Port Control Registers page */
2644 ret_val = e1000_set_page_igp(hw, (BM_PORT_CTRL_PAGE << IGP_PAGE_SHIFT));
2645 if (ret_val) {
2646 e_dbg("Could not set Port Control page\n");
Bruce Allan5015e532012-02-08 02:55:56 +00002647 return ret_val;
Bruce Allan2b6b1682011-05-13 07:20:09 +00002648 }
2649
2650 /* Restore 769.17 to its original value */
2651 ret_val = e1000e_write_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, *phy_reg);
2652 if (ret_val)
2653 e_dbg("Could not restore PHY register %d.%d\n",
2654 BM_PORT_CTRL_PAGE, BM_WUC_ENABLE_REG);
Bruce Allan5015e532012-02-08 02:55:56 +00002655
Bruce Allan2b6b1682011-05-13 07:20:09 +00002656 return ret_val;
2657}
2658
2659/**
2660 * e1000_access_phy_wakeup_reg_bm - Read/write BM PHY wakeup register
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002661 * @hw: pointer to the HW structure
2662 * @offset: register offset to be read or written
2663 * @data: pointer to the data to read or write
2664 * @read: determines if operation is read or write
Bruce Allan2b6b1682011-05-13 07:20:09 +00002665 * @page_set: BM_WUC_PAGE already set and access enabled
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002666 *
Bruce Allan2b6b1682011-05-13 07:20:09 +00002667 * Read the PHY register at offset and store the retrieved information in
2668 * data, or write data to PHY register at offset. Note the procedure to
2669 * access the PHY wakeup registers is different than reading the other PHY
2670 * registers. It works as such:
2671 * 1) Set 769.17.2 (page 769, register 17, bit 2) = 1
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002672 * 2) Set page to 800 for host (801 if we were manageability)
2673 * 3) Write the address using the address opcode (0x11)
2674 * 4) Read or write the data using the data opcode (0x12)
Bruce Allan2b6b1682011-05-13 07:20:09 +00002675 * 5) Restore 769.17.2 to its original value
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002676 *
Bruce Allan2b6b1682011-05-13 07:20:09 +00002677 * Steps 1 and 2 are done by e1000_enable_phy_wakeup_reg_access_bm() and
2678 * step 5 is done by e1000_disable_phy_wakeup_reg_access_bm().
2679 *
2680 * Assumes semaphore is already acquired. When page_set==true, assumes
2681 * the PHY page is set to BM_WUC_PAGE (i.e. a function in the call stack
2682 * is responsible for calls to e1000_[enable|disable]_phy_wakeup_reg_bm()).
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002683 **/
2684static s32 e1000_access_phy_wakeup_reg_bm(struct e1000_hw *hw, u32 offset,
Bruce Allan2b6b1682011-05-13 07:20:09 +00002685 u16 *data, bool read, bool page_set)
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002686{
2687 s32 ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00002688 u16 reg = BM_PHY_REG_NUM(offset);
Bruce Allan2b6b1682011-05-13 07:20:09 +00002689 u16 page = BM_PHY_REG_PAGE(offset);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002690 u16 phy_reg = 0;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002691
Bruce Allan2b6b1682011-05-13 07:20:09 +00002692 /* Gig must be disabled for MDIO accesses to Host Wakeup reg page */
Bruce Allana4f58f52009-06-02 11:29:18 +00002693 if ((hw->mac.type == e1000_pchlan) &&
Bruce Allan2b6b1682011-05-13 07:20:09 +00002694 (!(er32(PHY_CTRL) & E1000_PHY_CTRL_GBE_DISABLE)))
2695 e_dbg("Attempting to access page %d while gig enabled.\n",
2696 page);
Bruce Allana4f58f52009-06-02 11:29:18 +00002697
Bruce Allan2b6b1682011-05-13 07:20:09 +00002698 if (!page_set) {
2699 /* Enable access to PHY wakeup registers */
2700 ret_val = e1000_enable_phy_wakeup_reg_access_bm(hw, &phy_reg);
2701 if (ret_val) {
2702 e_dbg("Could not enable PHY wakeup reg access\n");
Bruce Allan5015e532012-02-08 02:55:56 +00002703 return ret_val;
Bruce Allan2b6b1682011-05-13 07:20:09 +00002704 }
Bruce Allan9b71b412009-12-01 15:53:07 +00002705 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002706
Bruce Allan2b6b1682011-05-13 07:20:09 +00002707 e_dbg("Accessing PHY page %d reg 0x%x\n", page, reg);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002708
Bruce Allan2b6b1682011-05-13 07:20:09 +00002709 /* Write the Wakeup register page offset value using opcode 0x11 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002710 ret_val = e1000e_write_phy_reg_mdic(hw, BM_WUC_ADDRESS_OPCODE, reg);
Bruce Allan9b71b412009-12-01 15:53:07 +00002711 if (ret_val) {
Bruce Allan2b6b1682011-05-13 07:20:09 +00002712 e_dbg("Could not write address opcode to page %d\n", page);
Bruce Allan5015e532012-02-08 02:55:56 +00002713 return ret_val;
Bruce Allan9b71b412009-12-01 15:53:07 +00002714 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002715
2716 if (read) {
Bruce Allan2b6b1682011-05-13 07:20:09 +00002717 /* Read the Wakeup register page value using opcode 0x12 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002718 ret_val = e1000e_read_phy_reg_mdic(hw, BM_WUC_DATA_OPCODE,
2719 data);
2720 } else {
Bruce Allan2b6b1682011-05-13 07:20:09 +00002721 /* Write the Wakeup register page value using opcode 0x12 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002722 ret_val = e1000e_write_phy_reg_mdic(hw, BM_WUC_DATA_OPCODE,
2723 *data);
2724 }
2725
Bruce Allan9b71b412009-12-01 15:53:07 +00002726 if (ret_val) {
Bruce Allan2b6b1682011-05-13 07:20:09 +00002727 e_dbg("Could not access PHY reg %d.%d\n", page, reg);
Bruce Allan5015e532012-02-08 02:55:56 +00002728 return ret_val;
Bruce Allan9b71b412009-12-01 15:53:07 +00002729 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002730
Bruce Allan2b6b1682011-05-13 07:20:09 +00002731 if (!page_set)
2732 ret_val = e1000_disable_phy_wakeup_reg_access_bm(hw, &phy_reg);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002733
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002734 return ret_val;
2735}
2736
2737/**
Bruce Allan17f208d2009-12-01 15:47:22 +00002738 * e1000_power_up_phy_copper - Restore copper link in case of PHY power down
2739 * @hw: pointer to the HW structure
2740 *
2741 * In the case of a PHY power down to save power, or to turn off link during a
2742 * driver unload, or wake on lan is not enabled, restore the link to previous
2743 * settings.
2744 **/
2745void e1000_power_up_phy_copper(struct e1000_hw *hw)
2746{
2747 u16 mii_reg = 0;
2748
2749 /* The PHY will retain its settings across a power down/up cycle */
2750 e1e_rphy(hw, PHY_CONTROL, &mii_reg);
2751 mii_reg &= ~MII_CR_POWER_DOWN;
2752 e1e_wphy(hw, PHY_CONTROL, mii_reg);
2753}
2754
2755/**
2756 * e1000_power_down_phy_copper - Restore copper link in case of PHY power down
2757 * @hw: pointer to the HW structure
2758 *
2759 * In the case of a PHY power down to save power, or to turn off link during a
2760 * driver unload, or wake on lan is not enabled, restore the link to previous
2761 * settings.
2762 **/
2763void e1000_power_down_phy_copper(struct e1000_hw *hw)
2764{
2765 u16 mii_reg = 0;
2766
2767 /* The PHY will retain its settings across a power down/up cycle */
2768 e1e_rphy(hw, PHY_CONTROL, &mii_reg);
2769 mii_reg |= MII_CR_POWER_DOWN;
2770 e1e_wphy(hw, PHY_CONTROL, mii_reg);
Bruce Allan1bba4382011-03-19 00:27:20 +00002771 usleep_range(1000, 2000);
Bruce Allan17f208d2009-12-01 15:47:22 +00002772}
2773
2774/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002775 * e1000e_commit_phy - Soft PHY reset
2776 * @hw: pointer to the HW structure
2777 *
2778 * Performs a soft PHY reset on those that apply. This is a function pointer
2779 * entry point called by drivers.
2780 **/
2781s32 e1000e_commit_phy(struct e1000_hw *hw)
2782{
Bruce Allan94d81862009-11-20 23:25:26 +00002783 if (hw->phy.ops.commit)
2784 return hw->phy.ops.commit(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002785
2786 return 0;
2787}
2788
2789/**
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002790 * __e1000_read_phy_reg_hv - Read HV PHY register
Bruce Allana4f58f52009-06-02 11:29:18 +00002791 * @hw: pointer to the HW structure
2792 * @offset: register offset to be read
2793 * @data: pointer to the read data
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002794 * @locked: semaphore has already been acquired or not
Bruce Allana4f58f52009-06-02 11:29:18 +00002795 *
2796 * Acquires semaphore, if necessary, then reads the PHY register at offset
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002797 * and stores the retrieved information in data. Release any acquired
Bruce Allana4f58f52009-06-02 11:29:18 +00002798 * semaphore before exiting.
2799 **/
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002800static s32 __e1000_read_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 *data,
Bruce Allan2b6b1682011-05-13 07:20:09 +00002801 bool locked, bool page_set)
Bruce Allana4f58f52009-06-02 11:29:18 +00002802{
2803 s32 ret_val;
2804 u16 page = BM_PHY_REG_PAGE(offset);
2805 u16 reg = BM_PHY_REG_NUM(offset);
Bruce Allan2b6b1682011-05-13 07:20:09 +00002806 u32 phy_addr = hw->phy.addr = e1000_get_phy_addr_for_hv_page(page);
Bruce Allana4f58f52009-06-02 11:29:18 +00002807
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002808 if (!locked) {
Bruce Allan94d81862009-11-20 23:25:26 +00002809 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002810 if (ret_val)
2811 return ret_val;
2812 }
2813
Bruce Allana4f58f52009-06-02 11:29:18 +00002814 /* Page 800 works differently than the rest so it has its own func */
2815 if (page == BM_WUC_PAGE) {
Bruce Allan2b6b1682011-05-13 07:20:09 +00002816 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, data,
2817 true, page_set);
Bruce Allana4f58f52009-06-02 11:29:18 +00002818 goto out;
2819 }
2820
2821 if (page > 0 && page < HV_INTC_FC_PAGE_START) {
2822 ret_val = e1000_access_phy_debug_regs_hv(hw, offset,
2823 data, true);
2824 goto out;
2825 }
2826
Bruce Allan2b6b1682011-05-13 07:20:09 +00002827 if (!page_set) {
2828 if (page == HV_INTC_FC_PAGE_START)
2829 page = 0;
Bruce Allana4f58f52009-06-02 11:29:18 +00002830
Bruce Allan2b6b1682011-05-13 07:20:09 +00002831 if (reg > MAX_PHY_MULTI_PAGE_REG) {
2832 /* Page is shifted left, PHY expects (page x 32) */
2833 ret_val = e1000_set_page_igp(hw,
2834 (page << IGP_PAGE_SHIFT));
Bruce Allana4f58f52009-06-02 11:29:18 +00002835
Bruce Allan2b6b1682011-05-13 07:20:09 +00002836 hw->phy.addr = phy_addr;
Bruce Allana4f58f52009-06-02 11:29:18 +00002837
Bruce Allan2b6b1682011-05-13 07:20:09 +00002838 if (ret_val)
2839 goto out;
2840 }
Bruce Allana4f58f52009-06-02 11:29:18 +00002841 }
2842
Bruce Allan2b6b1682011-05-13 07:20:09 +00002843 e_dbg("reading PHY page %d (or 0x%x shifted) reg 0x%x\n", page,
2844 page << IGP_PAGE_SHIFT, reg);
2845
Bruce Allana4f58f52009-06-02 11:29:18 +00002846 ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & reg,
2847 data);
Bruce Allana4f58f52009-06-02 11:29:18 +00002848out:
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002849 if (!locked)
Bruce Allan94d81862009-11-20 23:25:26 +00002850 hw->phy.ops.release(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002851
Bruce Allana4f58f52009-06-02 11:29:18 +00002852 return ret_val;
2853}
2854
2855/**
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002856 * e1000_read_phy_reg_hv - Read HV PHY register
2857 * @hw: pointer to the HW structure
2858 * @offset: register offset to be read
2859 * @data: pointer to the read data
2860 *
2861 * Acquires semaphore then reads the PHY register at offset and stores
2862 * the retrieved information in data. Release the acquired semaphore
2863 * before exiting.
2864 **/
2865s32 e1000_read_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 *data)
2866{
Bruce Allan2b6b1682011-05-13 07:20:09 +00002867 return __e1000_read_phy_reg_hv(hw, offset, data, false, false);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002868}
2869
2870/**
2871 * e1000_read_phy_reg_hv_locked - Read HV PHY register
2872 * @hw: pointer to the HW structure
2873 * @offset: register offset to be read
2874 * @data: pointer to the read data
2875 *
2876 * Reads the PHY register at offset and stores the retrieved information
2877 * in data. Assumes semaphore already acquired.
2878 **/
2879s32 e1000_read_phy_reg_hv_locked(struct e1000_hw *hw, u32 offset, u16 *data)
2880{
Bruce Allan2b6b1682011-05-13 07:20:09 +00002881 return __e1000_read_phy_reg_hv(hw, offset, data, true, false);
2882}
2883
2884/**
2885 * e1000_read_phy_reg_page_hv - Read HV PHY register
2886 * @hw: pointer to the HW structure
2887 * @offset: register offset to write to
2888 * @data: data to write at register offset
2889 *
2890 * Reads the PHY register at offset and stores the retrieved information
2891 * in data. Assumes semaphore already acquired and page already set.
2892 **/
2893s32 e1000_read_phy_reg_page_hv(struct e1000_hw *hw, u32 offset, u16 *data)
2894{
2895 return __e1000_read_phy_reg_hv(hw, offset, data, true, true);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002896}
2897
2898/**
2899 * __e1000_write_phy_reg_hv - Write HV PHY register
Bruce Allana4f58f52009-06-02 11:29:18 +00002900 * @hw: pointer to the HW structure
2901 * @offset: register offset to write to
2902 * @data: data to write at register offset
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002903 * @locked: semaphore has already been acquired or not
Bruce Allana4f58f52009-06-02 11:29:18 +00002904 *
2905 * Acquires semaphore, if necessary, then writes the data to PHY register
2906 * at the offset. Release any acquired semaphores before exiting.
2907 **/
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002908static s32 __e1000_write_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 data,
Bruce Allan2b6b1682011-05-13 07:20:09 +00002909 bool locked, bool page_set)
Bruce Allana4f58f52009-06-02 11:29:18 +00002910{
2911 s32 ret_val;
2912 u16 page = BM_PHY_REG_PAGE(offset);
2913 u16 reg = BM_PHY_REG_NUM(offset);
Bruce Allan2b6b1682011-05-13 07:20:09 +00002914 u32 phy_addr = hw->phy.addr = e1000_get_phy_addr_for_hv_page(page);
Bruce Allana4f58f52009-06-02 11:29:18 +00002915
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002916 if (!locked) {
Bruce Allan94d81862009-11-20 23:25:26 +00002917 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002918 if (ret_val)
2919 return ret_val;
2920 }
2921
Bruce Allana4f58f52009-06-02 11:29:18 +00002922 /* Page 800 works differently than the rest so it has its own func */
2923 if (page == BM_WUC_PAGE) {
Bruce Allan2b6b1682011-05-13 07:20:09 +00002924 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, &data,
2925 false, page_set);
Bruce Allana4f58f52009-06-02 11:29:18 +00002926 goto out;
2927 }
2928
2929 if (page > 0 && page < HV_INTC_FC_PAGE_START) {
2930 ret_val = e1000_access_phy_debug_regs_hv(hw, offset,
2931 &data, false);
2932 goto out;
2933 }
2934
Bruce Allan2b6b1682011-05-13 07:20:09 +00002935 if (!page_set) {
2936 if (page == HV_INTC_FC_PAGE_START)
2937 page = 0;
Bruce Allana4f58f52009-06-02 11:29:18 +00002938
Bruce Allane921eb12012-11-28 09:28:37 +00002939 /* Workaround MDIO accesses being disabled after entering IEEE
Bruce Allan2b6b1682011-05-13 07:20:09 +00002940 * Power Down (when bit 11 of the PHY Control register is set)
2941 */
2942 if ((hw->phy.type == e1000_phy_82578) &&
2943 (hw->phy.revision >= 1) &&
2944 (hw->phy.addr == 2) &&
Bruce Allan04499ec2012-04-13 00:08:31 +00002945 !(MAX_PHY_REG_ADDRESS & reg) && (data & (1 << 11))) {
Bruce Allan2b6b1682011-05-13 07:20:09 +00002946 u16 data2 = 0x7EFF;
2947 ret_val = e1000_access_phy_debug_regs_hv(hw,
2948 (1 << 6) | 0x3,
2949 &data2, false);
2950 if (ret_val)
2951 goto out;
2952 }
Bruce Allana4f58f52009-06-02 11:29:18 +00002953
Bruce Allan2b6b1682011-05-13 07:20:09 +00002954 if (reg > MAX_PHY_MULTI_PAGE_REG) {
2955 /* Page is shifted left, PHY expects (page x 32) */
2956 ret_val = e1000_set_page_igp(hw,
2957 (page << IGP_PAGE_SHIFT));
2958
2959 hw->phy.addr = phy_addr;
2960
2961 if (ret_val)
2962 goto out;
2963 }
Bruce Allana4f58f52009-06-02 11:29:18 +00002964 }
2965
Bruce Allan2b6b1682011-05-13 07:20:09 +00002966 e_dbg("writing PHY page %d (or 0x%x shifted) reg 0x%x\n", page,
2967 page << IGP_PAGE_SHIFT, reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00002968
2969 ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & reg,
2970 data);
Bruce Allana4f58f52009-06-02 11:29:18 +00002971
2972out:
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002973 if (!locked)
Bruce Allan94d81862009-11-20 23:25:26 +00002974 hw->phy.ops.release(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002975
Bruce Allana4f58f52009-06-02 11:29:18 +00002976 return ret_val;
2977}
2978
2979/**
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002980 * e1000_write_phy_reg_hv - Write HV PHY register
2981 * @hw: pointer to the HW structure
2982 * @offset: register offset to write to
2983 * @data: data to write at register offset
2984 *
2985 * Acquires semaphore then writes the data to PHY register at the offset.
2986 * Release the acquired semaphores before exiting.
2987 **/
2988s32 e1000_write_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 data)
2989{
Bruce Allan2b6b1682011-05-13 07:20:09 +00002990 return __e1000_write_phy_reg_hv(hw, offset, data, false, false);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002991}
2992
2993/**
2994 * e1000_write_phy_reg_hv_locked - Write HV PHY register
2995 * @hw: pointer to the HW structure
2996 * @offset: register offset to write to
2997 * @data: data to write at register offset
2998 *
2999 * Writes the data to PHY register at the offset. Assumes semaphore
3000 * already acquired.
3001 **/
3002s32 e1000_write_phy_reg_hv_locked(struct e1000_hw *hw, u32 offset, u16 data)
3003{
Bruce Allan2b6b1682011-05-13 07:20:09 +00003004 return __e1000_write_phy_reg_hv(hw, offset, data, true, false);
3005}
3006
3007/**
3008 * e1000_write_phy_reg_page_hv - Write HV PHY register
3009 * @hw: pointer to the HW structure
3010 * @offset: register offset to write to
3011 * @data: data to write at register offset
3012 *
3013 * Writes the data to PHY register at the offset. Assumes semaphore
3014 * already acquired and page already set.
3015 **/
3016s32 e1000_write_phy_reg_page_hv(struct e1000_hw *hw, u32 offset, u16 data)
3017{
3018 return __e1000_write_phy_reg_hv(hw, offset, data, true, true);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00003019}
3020
3021/**
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04003022 * e1000_get_phy_addr_for_hv_page - Get PHY address based on page
Bruce Allana4f58f52009-06-02 11:29:18 +00003023 * @page: page to be accessed
3024 **/
3025static u32 e1000_get_phy_addr_for_hv_page(u32 page)
3026{
3027 u32 phy_addr = 2;
3028
3029 if (page >= HV_INTC_FC_PAGE_START)
3030 phy_addr = 1;
3031
3032 return phy_addr;
3033}
3034
3035/**
3036 * e1000_access_phy_debug_regs_hv - Read HV PHY vendor specific high registers
3037 * @hw: pointer to the HW structure
3038 * @offset: register offset to be read or written
3039 * @data: pointer to the data to be read or written
Bruce Allan2b6b1682011-05-13 07:20:09 +00003040 * @read: determines if operation is read or write
Bruce Allana4f58f52009-06-02 11:29:18 +00003041 *
Bruce Allan5ccdcec2009-10-26 11:24:02 +00003042 * Reads the PHY register at offset and stores the retreived information
3043 * in data. Assumes semaphore already acquired. Note that the procedure
Bruce Allan2b6b1682011-05-13 07:20:09 +00003044 * to access these regs uses the address port and data port to read/write.
3045 * These accesses done with PHY address 2 and without using pages.
Bruce Allana4f58f52009-06-02 11:29:18 +00003046 **/
3047static s32 e1000_access_phy_debug_regs_hv(struct e1000_hw *hw, u32 offset,
3048 u16 *data, bool read)
3049{
3050 s32 ret_val;
Bruce Allan70806a72013-01-05 05:08:37 +00003051 u32 addr_reg;
3052 u32 data_reg;
Bruce Allana4f58f52009-06-02 11:29:18 +00003053
3054 /* This takes care of the difference with desktop vs mobile phy */
3055 addr_reg = (hw->phy.type == e1000_phy_82578) ?
3056 I82578_ADDR_REG : I82577_ADDR_REG;
3057 data_reg = addr_reg + 1;
3058
Bruce Allana4f58f52009-06-02 11:29:18 +00003059 /* All operations in this function are phy address 2 */
3060 hw->phy.addr = 2;
3061
3062 /* masking with 0x3F to remove the page from offset */
3063 ret_val = e1000e_write_phy_reg_mdic(hw, addr_reg, (u16)offset & 0x3F);
3064 if (ret_val) {
Bruce Allan2b6b1682011-05-13 07:20:09 +00003065 e_dbg("Could not write the Address Offset port register\n");
Bruce Allan5015e532012-02-08 02:55:56 +00003066 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003067 }
3068
3069 /* Read or write the data value next */
3070 if (read)
3071 ret_val = e1000e_read_phy_reg_mdic(hw, data_reg, data);
3072 else
3073 ret_val = e1000e_write_phy_reg_mdic(hw, data_reg, *data);
3074
Bruce Allan5015e532012-02-08 02:55:56 +00003075 if (ret_val)
Bruce Allan2b6b1682011-05-13 07:20:09 +00003076 e_dbg("Could not access the Data port register\n");
Bruce Allana4f58f52009-06-02 11:29:18 +00003077
Bruce Allana4f58f52009-06-02 11:29:18 +00003078 return ret_val;
3079}
3080
3081/**
3082 * e1000_link_stall_workaround_hv - Si workaround
3083 * @hw: pointer to the HW structure
3084 *
3085 * This function works around a Si bug where the link partner can get
3086 * a link up indication before the PHY does. If small packets are sent
3087 * by the link partner they can be placed in the packet buffer without
3088 * being properly accounted for by the PHY and will stall preventing
3089 * further packets from being received. The workaround is to clear the
3090 * packet buffer after the PHY detects link up.
3091 **/
3092s32 e1000_link_stall_workaround_hv(struct e1000_hw *hw)
3093{
3094 s32 ret_val = 0;
3095 u16 data;
3096
3097 if (hw->phy.type != e1000_phy_82578)
Bruce Allan5015e532012-02-08 02:55:56 +00003098 return 0;
Bruce Allana4f58f52009-06-02 11:29:18 +00003099
Bruce Allane65fa872009-07-01 13:27:31 +00003100 /* Do not apply workaround if in PHY loopback bit 14 set */
Bruce Allan482fed82011-01-06 14:29:49 +00003101 e1e_rphy(hw, PHY_CONTROL, &data);
Bruce Allane65fa872009-07-01 13:27:31 +00003102 if (data & PHY_CONTROL_LB)
Bruce Allan5015e532012-02-08 02:55:56 +00003103 return 0;
Bruce Allane65fa872009-07-01 13:27:31 +00003104
Bruce Allana4f58f52009-06-02 11:29:18 +00003105 /* check if link is up and at 1Gbps */
Bruce Allan482fed82011-01-06 14:29:49 +00003106 ret_val = e1e_rphy(hw, BM_CS_STATUS, &data);
Bruce Allana4f58f52009-06-02 11:29:18 +00003107 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003108 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003109
Bruce Allan3d3a1672012-02-23 03:13:18 +00003110 data &= BM_CS_STATUS_LINK_UP | BM_CS_STATUS_RESOLVED |
3111 BM_CS_STATUS_SPEED_MASK;
Bruce Allana4f58f52009-06-02 11:29:18 +00003112
Bruce Allan3d3a1672012-02-23 03:13:18 +00003113 if (data != (BM_CS_STATUS_LINK_UP | BM_CS_STATUS_RESOLVED |
3114 BM_CS_STATUS_SPEED_1000))
Bruce Allan5015e532012-02-08 02:55:56 +00003115 return 0;
Bruce Allana4f58f52009-06-02 11:29:18 +00003116
Bruce Allanbb9c5ee2012-02-23 03:31:29 +00003117 msleep(200);
Bruce Allana4f58f52009-06-02 11:29:18 +00003118
3119 /* flush the packets in the fifo buffer */
Bruce Allan482fed82011-01-06 14:29:49 +00003120 ret_val = e1e_wphy(hw, HV_MUX_DATA_CTRL, HV_MUX_DATA_CTRL_GEN_TO_MAC |
3121 HV_MUX_DATA_CTRL_FORCE_SPEED);
Bruce Allana4f58f52009-06-02 11:29:18 +00003122 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003123 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003124
Bruce Allan5015e532012-02-08 02:55:56 +00003125 return e1e_wphy(hw, HV_MUX_DATA_CTRL, HV_MUX_DATA_CTRL_GEN_TO_MAC);
Bruce Allana4f58f52009-06-02 11:29:18 +00003126}
3127
3128/**
3129 * e1000_check_polarity_82577 - Checks the polarity.
3130 * @hw: pointer to the HW structure
3131 *
3132 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
3133 *
3134 * Polarity is determined based on the PHY specific status register.
3135 **/
3136s32 e1000_check_polarity_82577(struct e1000_hw *hw)
3137{
3138 struct e1000_phy_info *phy = &hw->phy;
3139 s32 ret_val;
3140 u16 data;
3141
Bruce Allan482fed82011-01-06 14:29:49 +00003142 ret_val = e1e_rphy(hw, I82577_PHY_STATUS_2, &data);
Bruce Allana4f58f52009-06-02 11:29:18 +00003143
3144 if (!ret_val)
3145 phy->cable_polarity = (data & I82577_PHY_STATUS2_REV_POLARITY)
3146 ? e1000_rev_polarity_reversed
3147 : e1000_rev_polarity_normal;
3148
3149 return ret_val;
3150}
3151
3152/**
3153 * e1000_phy_force_speed_duplex_82577 - Force speed/duplex for I82577 PHY
3154 * @hw: pointer to the HW structure
3155 *
Bruce Allaneab50ff2010-05-10 15:01:30 +00003156 * Calls the PHY setup function to force speed and duplex.
Bruce Allana4f58f52009-06-02 11:29:18 +00003157 **/
3158s32 e1000_phy_force_speed_duplex_82577(struct e1000_hw *hw)
3159{
3160 struct e1000_phy_info *phy = &hw->phy;
3161 s32 ret_val;
3162 u16 phy_data;
3163 bool link;
3164
Bruce Allan482fed82011-01-06 14:29:49 +00003165 ret_val = e1e_rphy(hw, PHY_CONTROL, &phy_data);
Bruce Allana4f58f52009-06-02 11:29:18 +00003166 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003167 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003168
3169 e1000e_phy_force_speed_duplex_setup(hw, &phy_data);
3170
Bruce Allan482fed82011-01-06 14:29:49 +00003171 ret_val = e1e_wphy(hw, PHY_CONTROL, phy_data);
Bruce Allana4f58f52009-06-02 11:29:18 +00003172 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003173 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003174
Bruce Allana4f58f52009-06-02 11:29:18 +00003175 udelay(1);
3176
3177 if (phy->autoneg_wait_to_complete) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003178 e_dbg("Waiting for forced speed/duplex link on 82577 phy\n");
Bruce Allana4f58f52009-06-02 11:29:18 +00003179
Bruce Allan3d3a1672012-02-23 03:13:18 +00003180 ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
3181 100000, &link);
Bruce Allana4f58f52009-06-02 11:29:18 +00003182 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003183 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003184
3185 if (!link)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003186 e_dbg("Link taking longer than expected.\n");
Bruce Allana4f58f52009-06-02 11:29:18 +00003187
3188 /* Try once more */
Bruce Allan3d3a1672012-02-23 03:13:18 +00003189 ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
3190 100000, &link);
Bruce Allana4f58f52009-06-02 11:29:18 +00003191 }
3192
Bruce Allana4f58f52009-06-02 11:29:18 +00003193 return ret_val;
3194}
3195
3196/**
3197 * e1000_get_phy_info_82577 - Retrieve I82577 PHY information
3198 * @hw: pointer to the HW structure
3199 *
3200 * Read PHY status to determine if link is up. If link is up, then
3201 * set/determine 10base-T extended distance and polarity correction. Read
3202 * PHY port status to determine MDI/MDIx and speed. Based on the speed,
3203 * determine on the cable length, local and remote receiver.
3204 **/
3205s32 e1000_get_phy_info_82577(struct e1000_hw *hw)
3206{
3207 struct e1000_phy_info *phy = &hw->phy;
3208 s32 ret_val;
3209 u16 data;
3210 bool link;
3211
3212 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
3213 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003214 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003215
3216 if (!link) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003217 e_dbg("Phy info is only valid if link is up\n");
Bruce Allan5015e532012-02-08 02:55:56 +00003218 return -E1000_ERR_CONFIG;
Bruce Allana4f58f52009-06-02 11:29:18 +00003219 }
3220
3221 phy->polarity_correction = true;
3222
3223 ret_val = e1000_check_polarity_82577(hw);
3224 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003225 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003226
Bruce Allan482fed82011-01-06 14:29:49 +00003227 ret_val = e1e_rphy(hw, I82577_PHY_STATUS_2, &data);
Bruce Allana4f58f52009-06-02 11:29:18 +00003228 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003229 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003230
Bruce Allan04499ec2012-04-13 00:08:31 +00003231 phy->is_mdix = !!(data & I82577_PHY_STATUS2_MDIX);
Bruce Allana4f58f52009-06-02 11:29:18 +00003232
3233 if ((data & I82577_PHY_STATUS2_SPEED_MASK) ==
3234 I82577_PHY_STATUS2_SPEED_1000MBPS) {
3235 ret_val = hw->phy.ops.get_cable_length(hw);
3236 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003237 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003238
Bruce Allan482fed82011-01-06 14:29:49 +00003239 ret_val = e1e_rphy(hw, PHY_1000T_STATUS, &data);
Bruce Allana4f58f52009-06-02 11:29:18 +00003240 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003241 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003242
3243 phy->local_rx = (data & SR_1000T_LOCAL_RX_STATUS)
3244 ? e1000_1000t_rx_status_ok
3245 : e1000_1000t_rx_status_not_ok;
3246
3247 phy->remote_rx = (data & SR_1000T_REMOTE_RX_STATUS)
3248 ? e1000_1000t_rx_status_ok
3249 : e1000_1000t_rx_status_not_ok;
3250 } else {
3251 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
3252 phy->local_rx = e1000_1000t_rx_status_undefined;
3253 phy->remote_rx = e1000_1000t_rx_status_undefined;
3254 }
3255
Bruce Allan5015e532012-02-08 02:55:56 +00003256 return 0;
Bruce Allana4f58f52009-06-02 11:29:18 +00003257}
3258
3259/**
3260 * e1000_get_cable_length_82577 - Determine cable length for 82577 PHY
3261 * @hw: pointer to the HW structure
3262 *
3263 * Reads the diagnostic status register and verifies result is valid before
3264 * placing it in the phy_cable_length field.
3265 **/
3266s32 e1000_get_cable_length_82577(struct e1000_hw *hw)
3267{
3268 struct e1000_phy_info *phy = &hw->phy;
3269 s32 ret_val;
3270 u16 phy_data, length;
3271
Bruce Allan482fed82011-01-06 14:29:49 +00003272 ret_val = e1e_rphy(hw, I82577_PHY_DIAG_STATUS, &phy_data);
Bruce Allana4f58f52009-06-02 11:29:18 +00003273 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003274 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003275
3276 length = (phy_data & I82577_DSTATUS_CABLE_LENGTH) >>
3277 I82577_DSTATUS_CABLE_LENGTH_SHIFT;
3278
3279 if (length == E1000_CABLE_LENGTH_UNDEFINED)
Bruce Allan7dbbe5d2013-01-05 05:08:31 +00003280 return -E1000_ERR_PHY;
Bruce Allana4f58f52009-06-02 11:29:18 +00003281
3282 phy->cable_length = length;
3283
Bruce Allan5015e532012-02-08 02:55:56 +00003284 return 0;
Bruce Allana4f58f52009-06-02 11:29:18 +00003285}