blob: ae656f16c9fd461517415650c336405cd1879907 [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) {
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000134 ret_val = e1e_rphy(hw, MII_PHYSID1, &phy_id);
Bruce Allana4f58f52009-06-02 11:29:18 +0000135 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);
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000140 ret_val = e1e_rphy(hw, MII_PHYSID2, &phy_id);
Bruce Allana4f58f52009-06-02 11:29:18 +0000141 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 */
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000644 ret_val = e1e_rphy(hw, MII_CTRL1000, &phy_data);
Bruce Allan7b9f7e32012-03-20 03:47:41 +0000645 if (ret_val)
646 return ret_val;
647
648 /* load defaults for future use */
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000649 hw->phy.original_ms_type = (phy_data & CTL1000_ENABLE_MASTER) ?
650 ((phy_data & CTL1000_AS_MASTER) ?
Bruce Allan7b9f7e32012-03-20 03:47:41 +0000651 e1000_ms_force_master : e1000_ms_force_slave) : e1000_ms_auto;
652
653 switch (hw->phy.ms_type) {
654 case e1000_ms_force_master:
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000655 phy_data |= (CTL1000_ENABLE_MASTER | CTL1000_AS_MASTER);
Bruce Allan7b9f7e32012-03-20 03:47:41 +0000656 break;
657 case e1000_ms_force_slave:
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000658 phy_data |= CTL1000_ENABLE_MASTER;
659 phy_data &= ~(CTL1000_AS_MASTER);
Bruce Allan7b9f7e32012-03-20 03:47:41 +0000660 break;
661 case e1000_ms_auto:
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000662 phy_data &= ~CTL1000_ENABLE_MASTER;
Bruce Allan7b9f7e32012-03-20 03:47:41 +0000663 /* fall-through */
664 default:
665 break;
666 }
667
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000668 return e1e_wphy(hw, MII_CTRL1000, phy_data);
Bruce Allan7b9f7e32012-03-20 03:47:41 +0000669}
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. */
Bruce Allan6b598e12013-01-23 06:50:05 +0000791 ret_val = phy->ops.commit(hw);
Matthew Vick885fe7b2012-04-25 07:25:18 +0000792 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. */
Bruce Allan6b598e12013-01-23 06:50:05 +0000847 if (phy->ops.commit) {
848 ret_val = phy->ops.commit(hw);
849 if (ret_val) {
850 e_dbg("Error committing the PHY changes\n");
851 return ret_val;
852 }
Bruce Allana4f58f52009-06-02 11:29:18 +0000853 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700854
Bruce Allana4f58f52009-06-02 11:29:18 +0000855 if (phy->type == e1000_phy_82578) {
Bruce Allan482fed82011-01-06 14:29:49 +0000856 ret_val = e1e_rphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
Bruce Allana4f58f52009-06-02 11:29:18 +0000857 if (ret_val)
858 return ret_val;
859
860 /* 82578 PHY - set the downshift count to 1x. */
861 phy_data |= I82578_EPSCR_DOWNSHIFT_ENABLE;
862 phy_data &= ~I82578_EPSCR_DOWNSHIFT_COUNTER_MASK;
Bruce Allan482fed82011-01-06 14:29:49 +0000863 ret_val = e1e_wphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
Bruce Allana4f58f52009-06-02 11:29:18 +0000864 if (ret_val)
865 return ret_val;
866 }
867
868 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700869}
870
871/**
872 * e1000e_copper_link_setup_igp - Setup igp PHY's for copper link
873 * @hw: pointer to the HW structure
874 *
875 * Sets up LPLU, MDI/MDI-X, polarity, Smartspeed and Master/Slave config for
876 * igp PHY's.
877 **/
878s32 e1000e_copper_link_setup_igp(struct e1000_hw *hw)
879{
880 struct e1000_phy_info *phy = &hw->phy;
881 s32 ret_val;
882 u16 data;
883
884 ret_val = e1000_phy_hw_reset(hw);
885 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000886 e_dbg("Error resetting the PHY.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700887 return ret_val;
888 }
889
Bruce Allane921eb12012-11-28 09:28:37 +0000890 /* Wait 100ms for MAC to configure PHY from NVM settings, to avoid
David Graham2d9498f2008-04-23 11:09:14 -0700891 * timeout issues when LFS is enabled.
892 */
893 msleep(100);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700894
895 /* disable lplu d0 during driver init */
Bruce Allan7de89f02013-01-05 08:06:03 +0000896 if (hw->phy.ops.set_d0_lplu_state) {
897 ret_val = hw->phy.ops.set_d0_lplu_state(hw, false);
898 if (ret_val) {
899 e_dbg("Error Disabling LPLU D0\n");
900 return ret_val;
901 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700902 }
903 /* Configure mdi-mdix settings */
904 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CTRL, &data);
905 if (ret_val)
906 return ret_val;
907
908 data &= ~IGP01E1000_PSCR_AUTO_MDIX;
909
910 switch (phy->mdix) {
911 case 1:
912 data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
913 break;
914 case 2:
915 data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
916 break;
917 case 0:
918 default:
919 data |= IGP01E1000_PSCR_AUTO_MDIX;
920 break;
921 }
922 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CTRL, data);
923 if (ret_val)
924 return ret_val;
925
926 /* set auto-master slave resolution settings */
927 if (hw->mac.autoneg) {
Bruce Allane921eb12012-11-28 09:28:37 +0000928 /* when autonegotiation advertisement is only 1000Mbps then we
Auke Kokbc7f75f2007-09-17 12:30:59 -0700929 * should disable SmartSpeed and enable Auto MasterSlave
Bruce Allanad680762008-03-28 09:15:03 -0700930 * resolution as hardware default.
931 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700932 if (phy->autoneg_advertised == ADVERTISE_1000_FULL) {
933 /* Disable SmartSpeed */
934 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -0700935 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700936 if (ret_val)
937 return ret_val;
938
939 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
940 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -0700941 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700942 if (ret_val)
943 return ret_val;
944
945 /* Set auto Master/Slave resolution process */
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000946 ret_val = e1e_rphy(hw, MII_CTRL1000, &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700947 if (ret_val)
948 return ret_val;
949
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000950 data &= ~CTL1000_ENABLE_MASTER;
951 ret_val = e1e_wphy(hw, MII_CTRL1000, data);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700952 if (ret_val)
953 return ret_val;
954 }
955
Bruce Allan7b9f7e32012-03-20 03:47:41 +0000956 ret_val = e1000_set_master_slave_mode(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700957 }
958
959 return ret_val;
960}
961
962/**
963 * e1000_phy_setup_autoneg - Configure PHY for auto-negotiation
964 * @hw: pointer to the HW structure
965 *
966 * Reads the MII auto-neg advertisement register and/or the 1000T control
967 * register and if the PHY is already setup for auto-negotiation, then
968 * return successful. Otherwise, setup advertisement and flow control to
969 * the appropriate values for the wanted auto-negotiation.
970 **/
971static s32 e1000_phy_setup_autoneg(struct e1000_hw *hw)
972{
973 struct e1000_phy_info *phy = &hw->phy;
974 s32 ret_val;
975 u16 mii_autoneg_adv_reg;
976 u16 mii_1000t_ctrl_reg = 0;
977
978 phy->autoneg_advertised &= phy->autoneg_mask;
979
980 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000981 ret_val = e1e_rphy(hw, MII_ADVERTISE, &mii_autoneg_adv_reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700982 if (ret_val)
983 return ret_val;
984
985 if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
986 /* Read the MII 1000Base-T Control Register (Address 9). */
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000987 ret_val = e1e_rphy(hw, MII_CTRL1000, &mii_1000t_ctrl_reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700988 if (ret_val)
989 return ret_val;
990 }
991
Bruce Allane921eb12012-11-28 09:28:37 +0000992 /* Need to parse both autoneg_advertised and fc and set up
Auke Kokbc7f75f2007-09-17 12:30:59 -0700993 * the appropriate PHY registers. First we will parse for
994 * autoneg_advertised software override. Since we can advertise
995 * a plethora of combinations, we need to check each bit
996 * individually.
997 */
998
Bruce Allane921eb12012-11-28 09:28:37 +0000999 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
Auke Kokbc7f75f2007-09-17 12:30:59 -07001000 * Advertisement Register (Address 4) and the 1000 mb speed bits in
1001 * the 1000Base-T Control Register (Address 9).
1002 */
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001003 mii_autoneg_adv_reg &= ~(ADVERTISE_100FULL |
1004 ADVERTISE_100HALF |
1005 ADVERTISE_10FULL | ADVERTISE_10HALF);
1006 mii_1000t_ctrl_reg &= ~(ADVERTISE_1000HALF | ADVERTISE_1000FULL);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001007
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001008 e_dbg("autoneg_advertised %x\n", phy->autoneg_advertised);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001009
1010 /* Do we want to advertise 10 Mb Half Duplex? */
1011 if (phy->autoneg_advertised & ADVERTISE_10_HALF) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001012 e_dbg("Advertise 10mb Half duplex\n");
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001013 mii_autoneg_adv_reg |= ADVERTISE_10HALF;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001014 }
1015
1016 /* Do we want to advertise 10 Mb Full Duplex? */
1017 if (phy->autoneg_advertised & ADVERTISE_10_FULL) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001018 e_dbg("Advertise 10mb Full duplex\n");
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001019 mii_autoneg_adv_reg |= ADVERTISE_10FULL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001020 }
1021
1022 /* Do we want to advertise 100 Mb Half Duplex? */
1023 if (phy->autoneg_advertised & ADVERTISE_100_HALF) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001024 e_dbg("Advertise 100mb Half duplex\n");
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001025 mii_autoneg_adv_reg |= ADVERTISE_100HALF;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001026 }
1027
1028 /* Do we want to advertise 100 Mb Full Duplex? */
1029 if (phy->autoneg_advertised & ADVERTISE_100_FULL) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001030 e_dbg("Advertise 100mb Full duplex\n");
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001031 mii_autoneg_adv_reg |= ADVERTISE_100FULL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001032 }
1033
1034 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
1035 if (phy->autoneg_advertised & ADVERTISE_1000_HALF)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001036 e_dbg("Advertise 1000mb Half duplex request denied!\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001037
1038 /* Do we want to advertise 1000 Mb Full Duplex? */
1039 if (phy->autoneg_advertised & ADVERTISE_1000_FULL) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001040 e_dbg("Advertise 1000mb Full duplex\n");
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001041 mii_1000t_ctrl_reg |= ADVERTISE_1000FULL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001042 }
1043
Bruce Allane921eb12012-11-28 09:28:37 +00001044 /* Check for a software override of the flow control settings, and
Auke Kokbc7f75f2007-09-17 12:30:59 -07001045 * setup the PHY advertisement registers accordingly. If
1046 * auto-negotiation is enabled, then software will have to set the
1047 * "PAUSE" bits to the correct value in the Auto-Negotiation
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001048 * Advertisement Register (MII_ADVERTISE) and re-start auto-
Auke Kokbc7f75f2007-09-17 12:30:59 -07001049 * negotiation.
1050 *
1051 * The possible values of the "fc" parameter are:
1052 * 0: Flow control is completely disabled
1053 * 1: Rx flow control is enabled (we can receive pause frames
Bruce Allan3d3a1672012-02-23 03:13:18 +00001054 * but not send pause frames).
Auke Kokbc7f75f2007-09-17 12:30:59 -07001055 * 2: Tx flow control is enabled (we can send pause frames
Bruce Allan3d3a1672012-02-23 03:13:18 +00001056 * but we do not support receiving pause frames).
Bruce Allanad680762008-03-28 09:15:03 -07001057 * 3: Both Rx and Tx flow control (symmetric) are enabled.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001058 * other: No software override. The flow control configuration
Bruce Allan3d3a1672012-02-23 03:13:18 +00001059 * in the EEPROM is used.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001060 */
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08001061 switch (hw->fc.current_mode) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001062 case e1000_fc_none:
Bruce Allane921eb12012-11-28 09:28:37 +00001063 /* Flow control (Rx & Tx) is completely disabled by a
Auke Kokbc7f75f2007-09-17 12:30:59 -07001064 * software over-ride.
1065 */
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001066 mii_autoneg_adv_reg &=
1067 ~(ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001068 break;
1069 case e1000_fc_rx_pause:
Bruce Allane921eb12012-11-28 09:28:37 +00001070 /* Rx Flow control is enabled, and Tx Flow control is
Auke Kokbc7f75f2007-09-17 12:30:59 -07001071 * disabled, by a software over-ride.
Bruce Allanad680762008-03-28 09:15:03 -07001072 *
1073 * Since there really isn't a way to advertise that we are
1074 * capable of Rx Pause ONLY, we will advertise that we
1075 * support both symmetric and asymmetric Rx PAUSE. Later
Auke Kokbc7f75f2007-09-17 12:30:59 -07001076 * (in e1000e_config_fc_after_link_up) we will disable the
1077 * hw's ability to send PAUSE frames.
1078 */
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001079 mii_autoneg_adv_reg |=
1080 (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001081 break;
1082 case e1000_fc_tx_pause:
Bruce Allane921eb12012-11-28 09:28:37 +00001083 /* Tx Flow control is enabled, and Rx Flow control is
Auke Kokbc7f75f2007-09-17 12:30:59 -07001084 * disabled, by a software over-ride.
1085 */
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001086 mii_autoneg_adv_reg |= ADVERTISE_PAUSE_ASYM;
1087 mii_autoneg_adv_reg &= ~ADVERTISE_PAUSE_CAP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001088 break;
1089 case e1000_fc_full:
Bruce Allane921eb12012-11-28 09:28:37 +00001090 /* Flow control (both Rx and Tx) is enabled by a software
Auke Kokbc7f75f2007-09-17 12:30:59 -07001091 * over-ride.
1092 */
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001093 mii_autoneg_adv_reg |=
1094 (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001095 break;
1096 default:
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001097 e_dbg("Flow control param set incorrectly\n");
Bruce Allan7eb61d82012-02-08 02:55:03 +00001098 return -E1000_ERR_CONFIG;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001099 }
1100
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001101 ret_val = e1e_wphy(hw, MII_ADVERTISE, mii_autoneg_adv_reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001102 if (ret_val)
1103 return ret_val;
1104
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001105 e_dbg("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001106
Bruce Allanb1cdfea2010-12-11 05:53:47 +00001107 if (phy->autoneg_mask & ADVERTISE_1000_FULL)
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001108 ret_val = e1e_wphy(hw, MII_CTRL1000, mii_1000t_ctrl_reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001109
1110 return ret_val;
1111}
1112
1113/**
1114 * e1000_copper_link_autoneg - Setup/Enable autoneg for copper link
1115 * @hw: pointer to the HW structure
1116 *
1117 * Performs initial bounds checking on autoneg advertisement parameter, then
1118 * configure to advertise the full capability. Setup the PHY to autoneg
1119 * and restart the negotiation process between the link partner. If
Bruce Allanad680762008-03-28 09:15:03 -07001120 * autoneg_wait_to_complete, then wait for autoneg to complete before exiting.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001121 **/
1122static s32 e1000_copper_link_autoneg(struct e1000_hw *hw)
1123{
1124 struct e1000_phy_info *phy = &hw->phy;
1125 s32 ret_val;
1126 u16 phy_ctrl;
1127
Bruce Allane921eb12012-11-28 09:28:37 +00001128 /* Perform some bounds checking on the autoneg advertisement
Auke Kokbc7f75f2007-09-17 12:30:59 -07001129 * parameter.
1130 */
1131 phy->autoneg_advertised &= phy->autoneg_mask;
1132
Bruce Allane921eb12012-11-28 09:28:37 +00001133 /* If autoneg_advertised is zero, we assume it was not defaulted
Auke Kokbc7f75f2007-09-17 12:30:59 -07001134 * by the calling code so we set to advertise full capability.
1135 */
Bruce Allan04499ec2012-04-13 00:08:31 +00001136 if (!phy->autoneg_advertised)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001137 phy->autoneg_advertised = phy->autoneg_mask;
1138
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001139 e_dbg("Reconfiguring auto-neg advertisement params\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001140 ret_val = e1000_phy_setup_autoneg(hw);
1141 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001142 e_dbg("Error Setting up Auto-Negotiation\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001143 return ret_val;
1144 }
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001145 e_dbg("Restarting Auto-Neg\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001146
Bruce Allane921eb12012-11-28 09:28:37 +00001147 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
Auke Kokbc7f75f2007-09-17 12:30:59 -07001148 * the Auto Neg Restart bit in the PHY control register.
1149 */
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001150 ret_val = e1e_rphy(hw, MII_BMCR, &phy_ctrl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001151 if (ret_val)
1152 return ret_val;
1153
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001154 phy_ctrl |= (BMCR_ANENABLE | BMCR_ANRESTART);
1155 ret_val = e1e_wphy(hw, MII_BMCR, phy_ctrl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001156 if (ret_val)
1157 return ret_val;
1158
Bruce Allane921eb12012-11-28 09:28:37 +00001159 /* Does the user want to wait for Auto-Neg to complete here, or
Auke Kokbc7f75f2007-09-17 12:30:59 -07001160 * check at a later time (for example, callback routine).
1161 */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001162 if (phy->autoneg_wait_to_complete) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001163 ret_val = e1000_wait_autoneg(hw);
1164 if (ret_val) {
Bruce Allan434f1392011-12-16 00:46:54 +00001165 e_dbg("Error while waiting for autoneg to complete\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001166 return ret_val;
1167 }
1168 }
1169
Bruce Allanf92518d2012-02-01 11:16:42 +00001170 hw->mac.get_link_status = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001171
1172 return ret_val;
1173}
1174
1175/**
1176 * e1000e_setup_copper_link - Configure copper link settings
1177 * @hw: pointer to the HW structure
1178 *
1179 * Calls the appropriate function to configure the link for auto-neg or forced
1180 * speed and duplex. Then we check for link, once link is established calls
1181 * to configure collision distance and flow control are called. If link is
1182 * not established, we return -E1000_ERR_PHY (-2).
1183 **/
1184s32 e1000e_setup_copper_link(struct e1000_hw *hw)
1185{
1186 s32 ret_val;
1187 bool link;
1188
1189 if (hw->mac.autoneg) {
Bruce Allane921eb12012-11-28 09:28:37 +00001190 /* Setup autoneg and flow control advertisement and perform
Bruce Allanad680762008-03-28 09:15:03 -07001191 * autonegotiation.
1192 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001193 ret_val = e1000_copper_link_autoneg(hw);
1194 if (ret_val)
1195 return ret_val;
1196 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00001197 /* PHY will be set to 10H, 10F, 100H or 100F
Bruce Allanad680762008-03-28 09:15:03 -07001198 * depending on user settings.
1199 */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001200 e_dbg("Forcing Speed and Duplex\n");
Bruce Allanc2c66292013-01-05 08:06:08 +00001201 ret_val = hw->phy.ops.force_speed_duplex(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001202 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001203 e_dbg("Error Forcing Speed and Duplex\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001204 return ret_val;
1205 }
1206 }
1207
Bruce Allane921eb12012-11-28 09:28:37 +00001208 /* Check link status. Wait up to 100 microseconds for link to become
Auke Kokbc7f75f2007-09-17 12:30:59 -07001209 * valid.
1210 */
Bruce Allan3d3a1672012-02-23 03:13:18 +00001211 ret_val = e1000e_phy_has_link_generic(hw, COPPER_LINK_UP_LIMIT, 10,
1212 &link);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001213 if (ret_val)
1214 return ret_val;
1215
1216 if (link) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001217 e_dbg("Valid link established!!!\n");
Bruce Allan57cde762012-02-22 09:02:58 +00001218 hw->mac.ops.config_collision_dist(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001219 ret_val = e1000e_config_fc_after_link_up(hw);
1220 } else {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001221 e_dbg("Unable to establish link!!!\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001222 }
1223
1224 return ret_val;
1225}
1226
1227/**
1228 * e1000e_phy_force_speed_duplex_igp - Force speed/duplex for igp PHY
1229 * @hw: pointer to the HW structure
1230 *
1231 * Calls the PHY setup function to force speed and duplex. Clears the
1232 * auto-crossover to force MDI manually. Waits for link and returns
1233 * successful if link up is successful, else -E1000_ERR_PHY (-2).
1234 **/
1235s32 e1000e_phy_force_speed_duplex_igp(struct e1000_hw *hw)
1236{
1237 struct e1000_phy_info *phy = &hw->phy;
1238 s32 ret_val;
1239 u16 phy_data;
1240 bool link;
1241
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001242 ret_val = e1e_rphy(hw, MII_BMCR, &phy_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001243 if (ret_val)
1244 return ret_val;
1245
1246 e1000e_phy_force_speed_duplex_setup(hw, &phy_data);
1247
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001248 ret_val = e1e_wphy(hw, MII_BMCR, phy_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001249 if (ret_val)
1250 return ret_val;
1251
Bruce Allane921eb12012-11-28 09:28:37 +00001252 /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
Auke Kokbc7f75f2007-09-17 12:30:59 -07001253 * forced whenever speed and duplex are forced.
1254 */
1255 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1256 if (ret_val)
1257 return ret_val;
1258
1259 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1260 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1261
1262 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1263 if (ret_val)
1264 return ret_val;
1265
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001266 e_dbg("IGP PSCR: %X\n", phy_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001267
1268 udelay(1);
1269
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001270 if (phy->autoneg_wait_to_complete) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001271 e_dbg("Waiting for forced speed/duplex link on IGP phy.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001272
Bruce Allan3d3a1672012-02-23 03:13:18 +00001273 ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
1274 100000, &link);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001275 if (ret_val)
1276 return ret_val;
1277
1278 if (!link)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001279 e_dbg("Link taking longer than expected.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001280
1281 /* Try once more */
Bruce Allan3d3a1672012-02-23 03:13:18 +00001282 ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
1283 100000, &link);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001284 }
1285
1286 return ret_val;
1287}
1288
1289/**
1290 * e1000e_phy_force_speed_duplex_m88 - Force speed/duplex for m88 PHY
1291 * @hw: pointer to the HW structure
1292 *
1293 * Calls the PHY setup function to force speed and duplex. Clears the
1294 * auto-crossover to force MDI manually. Resets the PHY to commit the
1295 * changes. If time expires while waiting for link up, we reset the DSP.
Bruce Allanad680762008-03-28 09:15:03 -07001296 * After reset, TX_CLK and CRS on Tx must be set. Return successful upon
Auke Kokbc7f75f2007-09-17 12:30:59 -07001297 * successful completion, else return corresponding error code.
1298 **/
1299s32 e1000e_phy_force_speed_duplex_m88(struct e1000_hw *hw)
1300{
1301 struct e1000_phy_info *phy = &hw->phy;
1302 s32 ret_val;
1303 u16 phy_data;
1304 bool link;
1305
Bruce Allane921eb12012-11-28 09:28:37 +00001306 /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
Auke Kokbc7f75f2007-09-17 12:30:59 -07001307 * forced whenever speed and duplex are forced.
1308 */
1309 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1310 if (ret_val)
1311 return ret_val;
1312
1313 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1314 ret_val = e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1315 if (ret_val)
1316 return ret_val;
1317
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001318 e_dbg("M88E1000 PSCR: %X\n", phy_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001319
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001320 ret_val = e1e_rphy(hw, MII_BMCR, &phy_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001321 if (ret_val)
1322 return ret_val;
1323
1324 e1000e_phy_force_speed_duplex_setup(hw, &phy_data);
1325
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001326 ret_val = e1e_wphy(hw, MII_BMCR, phy_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001327 if (ret_val)
1328 return ret_val;
1329
Bruce Allan5aa49c82008-11-21 16:49:53 -08001330 /* Reset the phy to commit changes. */
Bruce Allan6b598e12013-01-23 06:50:05 +00001331 if (hw->phy.ops.commit) {
1332 ret_val = hw->phy.ops.commit(hw);
1333 if (ret_val)
1334 return ret_val;
1335 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001336
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001337 if (phy->autoneg_wait_to_complete) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001338 e_dbg("Waiting for forced speed/duplex link on M88 phy.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001339
1340 ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
1341 100000, &link);
1342 if (ret_val)
1343 return ret_val;
1344
1345 if (!link) {
Bruce Allan0be84012009-12-02 17:03:18 +00001346 if (hw->phy.type != e1000_phy_m88) {
1347 e_dbg("Link taking longer than expected.\n");
1348 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00001349 /* We didn't get link.
Bruce Allan0be84012009-12-02 17:03:18 +00001350 * Reset the DSP and cross our fingers.
1351 */
Bruce Allan482fed82011-01-06 14:29:49 +00001352 ret_val = e1e_wphy(hw, M88E1000_PHY_PAGE_SELECT,
1353 0x001d);
Bruce Allan0be84012009-12-02 17:03:18 +00001354 if (ret_val)
1355 return ret_val;
1356 ret_val = e1000e_phy_reset_dsp(hw);
1357 if (ret_val)
1358 return ret_val;
1359 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001360 }
1361
1362 /* Try once more */
1363 ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
1364 100000, &link);
1365 if (ret_val)
1366 return ret_val;
1367 }
1368
Bruce Allan0be84012009-12-02 17:03:18 +00001369 if (hw->phy.type != e1000_phy_m88)
1370 return 0;
1371
Auke Kokbc7f75f2007-09-17 12:30:59 -07001372 ret_val = e1e_rphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1373 if (ret_val)
1374 return ret_val;
1375
Bruce Allane921eb12012-11-28 09:28:37 +00001376 /* Resetting the phy means we need to re-force TX_CLK in the
Auke Kokbc7f75f2007-09-17 12:30:59 -07001377 * Extended PHY Specific Control Register to 25MHz clock from
1378 * the reset value of 2.5MHz.
1379 */
1380 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1381 ret_val = e1e_wphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1382 if (ret_val)
1383 return ret_val;
1384
Bruce Allane921eb12012-11-28 09:28:37 +00001385 /* In addition, we must re-enable CRS on Tx for both half and full
Auke Kokbc7f75f2007-09-17 12:30:59 -07001386 * duplex.
1387 */
1388 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1389 if (ret_val)
1390 return ret_val;
1391
1392 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1393 ret_val = e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1394
1395 return ret_val;
1396}
1397
1398/**
Bruce Allan0be84012009-12-02 17:03:18 +00001399 * e1000_phy_force_speed_duplex_ife - Force PHY speed & duplex
1400 * @hw: pointer to the HW structure
1401 *
1402 * Forces the speed and duplex settings of the PHY.
1403 * This is a function pointer entry point only called by
1404 * PHY setup routines.
1405 **/
1406s32 e1000_phy_force_speed_duplex_ife(struct e1000_hw *hw)
1407{
1408 struct e1000_phy_info *phy = &hw->phy;
1409 s32 ret_val;
1410 u16 data;
1411 bool link;
1412
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001413 ret_val = e1e_rphy(hw, MII_BMCR, &data);
Bruce Allan0be84012009-12-02 17:03:18 +00001414 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001415 return ret_val;
Bruce Allan0be84012009-12-02 17:03:18 +00001416
1417 e1000e_phy_force_speed_duplex_setup(hw, &data);
1418
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001419 ret_val = e1e_wphy(hw, MII_BMCR, data);
Bruce Allan0be84012009-12-02 17:03:18 +00001420 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001421 return ret_val;
Bruce Allan0be84012009-12-02 17:03:18 +00001422
1423 /* Disable MDI-X support for 10/100 */
1424 ret_val = e1e_rphy(hw, IFE_PHY_MDIX_CONTROL, &data);
1425 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001426 return ret_val;
Bruce Allan0be84012009-12-02 17:03:18 +00001427
1428 data &= ~IFE_PMC_AUTO_MDIX;
1429 data &= ~IFE_PMC_FORCE_MDIX;
1430
1431 ret_val = e1e_wphy(hw, IFE_PHY_MDIX_CONTROL, data);
1432 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001433 return ret_val;
Bruce Allan0be84012009-12-02 17:03:18 +00001434
1435 e_dbg("IFE PMC: %X\n", data);
1436
1437 udelay(1);
1438
1439 if (phy->autoneg_wait_to_complete) {
1440 e_dbg("Waiting for forced speed/duplex link on IFE phy.\n");
1441
Bruce Allan3d3a1672012-02-23 03:13:18 +00001442 ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
1443 100000, &link);
Bruce Allan0be84012009-12-02 17:03:18 +00001444 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001445 return ret_val;
Bruce Allan0be84012009-12-02 17:03:18 +00001446
1447 if (!link)
1448 e_dbg("Link taking longer than expected.\n");
1449
1450 /* Try once more */
Bruce Allan3d3a1672012-02-23 03:13:18 +00001451 ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
1452 100000, &link);
Bruce Allan0be84012009-12-02 17:03:18 +00001453 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001454 return ret_val;
Bruce Allan0be84012009-12-02 17:03:18 +00001455 }
1456
Bruce Allan5015e532012-02-08 02:55:56 +00001457 return 0;
Bruce Allan0be84012009-12-02 17:03:18 +00001458}
1459
1460/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001461 * e1000e_phy_force_speed_duplex_setup - Configure forced PHY speed/duplex
1462 * @hw: pointer to the HW structure
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001463 * @phy_ctrl: pointer to current value of MII_BMCR
Auke Kokbc7f75f2007-09-17 12:30:59 -07001464 *
1465 * Forces speed and duplex on the PHY by doing the following: disable flow
1466 * control, force speed/duplex on the MAC, disable auto speed detection,
1467 * disable auto-negotiation, configure duplex, configure speed, configure
1468 * the collision distance, write configuration to CTRL register. The
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001469 * caller must write to the MII_BMCR register for these settings to
Auke Kokbc7f75f2007-09-17 12:30:59 -07001470 * take affect.
1471 **/
1472void e1000e_phy_force_speed_duplex_setup(struct e1000_hw *hw, u16 *phy_ctrl)
1473{
1474 struct e1000_mac_info *mac = &hw->mac;
1475 u32 ctrl;
1476
1477 /* Turn off flow control when forcing speed/duplex */
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08001478 hw->fc.current_mode = e1000_fc_none;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001479
1480 /* Force speed/duplex on the mac */
1481 ctrl = er32(CTRL);
1482 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1483 ctrl &= ~E1000_CTRL_SPD_SEL;
1484
1485 /* Disable Auto Speed Detection */
1486 ctrl &= ~E1000_CTRL_ASDE;
1487
1488 /* Disable autoneg on the phy */
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001489 *phy_ctrl &= ~BMCR_ANENABLE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001490
1491 /* Forcing Full or Half Duplex? */
1492 if (mac->forced_speed_duplex & E1000_ALL_HALF_DUPLEX) {
1493 ctrl &= ~E1000_CTRL_FD;
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001494 *phy_ctrl &= ~BMCR_FULLDPLX;
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001495 e_dbg("Half Duplex\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001496 } else {
1497 ctrl |= E1000_CTRL_FD;
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001498 *phy_ctrl |= BMCR_FULLDPLX;
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001499 e_dbg("Full Duplex\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001500 }
1501
1502 /* Forcing 10mb or 100mb? */
1503 if (mac->forced_speed_duplex & E1000_ALL_100_SPEED) {
1504 ctrl |= E1000_CTRL_SPD_100;
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001505 *phy_ctrl |= BMCR_SPEED100;
1506 *phy_ctrl &= ~BMCR_SPEED1000;
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001507 e_dbg("Forcing 100mb\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001508 } else {
1509 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001510 *phy_ctrl &= ~(BMCR_SPEED1000 | BMCR_SPEED100);
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001511 e_dbg("Forcing 10mb\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001512 }
1513
Bruce Allan57cde762012-02-22 09:02:58 +00001514 hw->mac.ops.config_collision_dist(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001515
1516 ew32(CTRL, ctrl);
1517}
1518
1519/**
1520 * e1000e_set_d3_lplu_state - Sets low power link up state for D3
1521 * @hw: pointer to the HW structure
1522 * @active: boolean used to enable/disable lplu
1523 *
1524 * Success returns 0, Failure returns 1
1525 *
1526 * The low power link up (lplu) state is set to the power management level D3
1527 * and SmartSpeed is disabled when active is true, else clear lplu for D3
1528 * and enable Smartspeed. LPLU and Smartspeed are mutually exclusive. LPLU
1529 * is used during Dx states where the power conservation is most important.
1530 * During driver activity, SmartSpeed should be enabled so performance is
1531 * maintained.
1532 **/
1533s32 e1000e_set_d3_lplu_state(struct e1000_hw *hw, bool active)
1534{
1535 struct e1000_phy_info *phy = &hw->phy;
1536 s32 ret_val;
1537 u16 data;
1538
1539 ret_val = e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &data);
1540 if (ret_val)
1541 return ret_val;
1542
1543 if (!active) {
1544 data &= ~IGP02E1000_PM_D3_LPLU;
David Graham2d9498f2008-04-23 11:09:14 -07001545 ret_val = e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001546 if (ret_val)
1547 return ret_val;
Bruce Allane921eb12012-11-28 09:28:37 +00001548 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
Auke Kokbc7f75f2007-09-17 12:30:59 -07001549 * during Dx states where the power conservation is most
1550 * important. During driver activity we should enable
Bruce Allanad680762008-03-28 09:15:03 -07001551 * SmartSpeed, so performance is maintained.
1552 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001553 if (phy->smart_speed == e1000_smart_speed_on) {
1554 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07001555 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001556 if (ret_val)
1557 return ret_val;
1558
1559 data |= IGP01E1000_PSCFR_SMART_SPEED;
1560 ret_val = e1e_wphy(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 } else if (phy->smart_speed == e1000_smart_speed_off) {
1565 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07001566 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001567 if (ret_val)
1568 return ret_val;
1569
1570 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1571 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07001572 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001573 if (ret_val)
1574 return ret_val;
1575 }
1576 } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
1577 (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
1578 (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
1579 data |= IGP02E1000_PM_D3_LPLU;
1580 ret_val = e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, data);
1581 if (ret_val)
1582 return ret_val;
1583
1584 /* When LPLU is enabled, we should disable SmartSpeed */
1585 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
1586 if (ret_val)
1587 return ret_val;
1588
1589 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1590 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
1591 }
1592
1593 return ret_val;
1594}
1595
1596/**
Auke Kok489815c2008-02-21 15:11:07 -08001597 * e1000e_check_downshift - Checks whether a downshift in speed occurred
Auke Kokbc7f75f2007-09-17 12:30:59 -07001598 * @hw: pointer to the HW structure
1599 *
1600 * Success returns 0, Failure returns 1
1601 *
1602 * A downshift is detected by querying the PHY link health.
1603 **/
1604s32 e1000e_check_downshift(struct e1000_hw *hw)
1605{
1606 struct e1000_phy_info *phy = &hw->phy;
1607 s32 ret_val;
1608 u16 phy_data, offset, mask;
1609
1610 switch (phy->type) {
1611 case e1000_phy_m88:
1612 case e1000_phy_gg82563:
Bruce Allan07f025e2009-12-01 15:53:48 +00001613 case e1000_phy_bm:
Bruce Allana4f58f52009-06-02 11:29:18 +00001614 case e1000_phy_82578:
Auke Kokbc7f75f2007-09-17 12:30:59 -07001615 offset = M88E1000_PHY_SPEC_STATUS;
1616 mask = M88E1000_PSSR_DOWNSHIFT;
1617 break;
1618 case e1000_phy_igp_2:
1619 case e1000_phy_igp_3:
1620 offset = IGP01E1000_PHY_LINK_HEALTH;
1621 mask = IGP01E1000_PLHR_SS_DOWNGRADE;
1622 break;
1623 default:
1624 /* speed downshift not supported */
Bruce Allan564ea9b2009-11-20 23:26:44 +00001625 phy->speed_downgraded = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001626 return 0;
1627 }
1628
1629 ret_val = e1e_rphy(hw, offset, &phy_data);
1630
1631 if (!ret_val)
Bruce Allan04499ec2012-04-13 00:08:31 +00001632 phy->speed_downgraded = !!(phy_data & mask);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001633
1634 return ret_val;
1635}
1636
1637/**
1638 * e1000_check_polarity_m88 - Checks the polarity.
1639 * @hw: pointer to the HW structure
1640 *
1641 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1642 *
1643 * Polarity is determined based on the PHY specific status register.
1644 **/
Bruce Allan0be84012009-12-02 17:03:18 +00001645s32 e1000_check_polarity_m88(struct e1000_hw *hw)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001646{
1647 struct e1000_phy_info *phy = &hw->phy;
1648 s32 ret_val;
1649 u16 data;
1650
1651 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &data);
1652
1653 if (!ret_val)
1654 phy->cable_polarity = (data & M88E1000_PSSR_REV_POLARITY)
1655 ? e1000_rev_polarity_reversed
1656 : e1000_rev_polarity_normal;
1657
1658 return ret_val;
1659}
1660
1661/**
1662 * e1000_check_polarity_igp - Checks the polarity.
1663 * @hw: pointer to the HW structure
1664 *
1665 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1666 *
1667 * Polarity is determined based on the PHY port status register, and the
1668 * current speed (since there is no polarity at 100Mbps).
1669 **/
Bruce Allan0be84012009-12-02 17:03:18 +00001670s32 e1000_check_polarity_igp(struct e1000_hw *hw)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001671{
1672 struct e1000_phy_info *phy = &hw->phy;
1673 s32 ret_val;
1674 u16 data, offset, mask;
1675
Bruce Allane921eb12012-11-28 09:28:37 +00001676 /* Polarity is determined based on the speed of
Bruce Allanad680762008-03-28 09:15:03 -07001677 * our connection.
1678 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001679 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_STATUS, &data);
1680 if (ret_val)
1681 return ret_val;
1682
1683 if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
1684 IGP01E1000_PSSR_SPEED_1000MBPS) {
1685 offset = IGP01E1000_PHY_PCS_INIT_REG;
1686 mask = IGP01E1000_PHY_POLARITY_MASK;
1687 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00001688 /* This really only applies to 10Mbps since
Auke Kokbc7f75f2007-09-17 12:30:59 -07001689 * there is no polarity for 100Mbps (always 0).
1690 */
1691 offset = IGP01E1000_PHY_PORT_STATUS;
1692 mask = IGP01E1000_PSSR_POLARITY_REVERSED;
1693 }
1694
1695 ret_val = e1e_rphy(hw, offset, &data);
1696
1697 if (!ret_val)
1698 phy->cable_polarity = (data & mask)
1699 ? e1000_rev_polarity_reversed
1700 : e1000_rev_polarity_normal;
1701
1702 return ret_val;
1703}
1704
1705/**
Bruce Allan0be84012009-12-02 17:03:18 +00001706 * e1000_check_polarity_ife - Check cable polarity for IFE PHY
1707 * @hw: pointer to the HW structure
1708 *
1709 * Polarity is determined on the polarity reversal feature being enabled.
1710 **/
1711s32 e1000_check_polarity_ife(struct e1000_hw *hw)
1712{
1713 struct e1000_phy_info *phy = &hw->phy;
1714 s32 ret_val;
1715 u16 phy_data, offset, mask;
1716
Bruce Allane921eb12012-11-28 09:28:37 +00001717 /* Polarity is determined based on the reversal feature being enabled.
Bruce Allan0be84012009-12-02 17:03:18 +00001718 */
1719 if (phy->polarity_correction) {
1720 offset = IFE_PHY_EXTENDED_STATUS_CONTROL;
1721 mask = IFE_PESC_POLARITY_REVERSED;
1722 } else {
1723 offset = IFE_PHY_SPECIAL_CONTROL;
1724 mask = IFE_PSC_FORCE_POLARITY;
1725 }
1726
1727 ret_val = e1e_rphy(hw, offset, &phy_data);
1728
1729 if (!ret_val)
1730 phy->cable_polarity = (phy_data & mask)
1731 ? e1000_rev_polarity_reversed
1732 : e1000_rev_polarity_normal;
1733
1734 return ret_val;
1735}
1736
1737/**
Bruce Allanad680762008-03-28 09:15:03 -07001738 * e1000_wait_autoneg - Wait for auto-neg completion
Auke Kokbc7f75f2007-09-17 12:30:59 -07001739 * @hw: pointer to the HW structure
1740 *
1741 * Waits for auto-negotiation to complete or for the auto-negotiation time
1742 * limit to expire, which ever happens first.
1743 **/
1744static s32 e1000_wait_autoneg(struct e1000_hw *hw)
1745{
1746 s32 ret_val = 0;
1747 u16 i, phy_status;
1748
1749 /* Break after autoneg completes or PHY_AUTO_NEG_LIMIT expires. */
1750 for (i = PHY_AUTO_NEG_LIMIT; i > 0; i--) {
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001751 ret_val = e1e_rphy(hw, MII_BMSR, &phy_status);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001752 if (ret_val)
1753 break;
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001754 ret_val = e1e_rphy(hw, MII_BMSR, &phy_status);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001755 if (ret_val)
1756 break;
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001757 if (phy_status & BMSR_ANEGCOMPLETE)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001758 break;
1759 msleep(100);
1760 }
1761
Bruce Allane921eb12012-11-28 09:28:37 +00001762 /* PHY_AUTO_NEG_TIME expiration doesn't guarantee auto-negotiation
Auke Kokbc7f75f2007-09-17 12:30:59 -07001763 * has completed.
1764 */
1765 return ret_val;
1766}
1767
1768/**
1769 * e1000e_phy_has_link_generic - Polls PHY for link
1770 * @hw: pointer to the HW structure
1771 * @iterations: number of times to poll for link
1772 * @usec_interval: delay between polling attempts
1773 * @success: pointer to whether polling was successful or not
1774 *
1775 * Polls the PHY status register for link, 'iterations' number of times.
1776 **/
1777s32 e1000e_phy_has_link_generic(struct e1000_hw *hw, u32 iterations,
1778 u32 usec_interval, bool *success)
1779{
1780 s32 ret_val = 0;
1781 u16 i, phy_status;
1782
1783 for (i = 0; i < iterations; i++) {
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001784 /* Some PHYs require the MII_BMSR register to be read
Auke Kokbc7f75f2007-09-17 12:30:59 -07001785 * twice due to the link bit being sticky. No harm doing
1786 * it across the board.
1787 */
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001788 ret_val = e1e_rphy(hw, MII_BMSR, &phy_status);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001789 if (ret_val)
Bruce Allane921eb12012-11-28 09:28:37 +00001790 /* If the first read fails, another entity may have
Bruce Allan906e8d92009-07-01 13:28:50 +00001791 * ownership of the resources, wait and try again to
1792 * see if they have relinquished the resources yet.
1793 */
1794 udelay(usec_interval);
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001795 ret_val = e1e_rphy(hw, MII_BMSR, &phy_status);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001796 if (ret_val)
1797 break;
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001798 if (phy_status & BMSR_LSTATUS)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001799 break;
1800 if (usec_interval >= 1000)
1801 mdelay(usec_interval/1000);
1802 else
1803 udelay(usec_interval);
1804 }
1805
1806 *success = (i < iterations);
1807
1808 return ret_val;
1809}
1810
1811/**
1812 * e1000e_get_cable_length_m88 - Determine cable length for m88 PHY
1813 * @hw: pointer to the HW structure
1814 *
1815 * Reads the PHY specific status register to retrieve the cable length
1816 * information. The cable length is determined by averaging the minimum and
1817 * maximum values to get the "average" cable length. The m88 PHY has four
1818 * possible cable length values, which are:
1819 * Register Value Cable Length
1820 * 0 < 50 meters
1821 * 1 50 - 80 meters
1822 * 2 80 - 110 meters
1823 * 3 110 - 140 meters
1824 * 4 > 140 meters
1825 **/
1826s32 e1000e_get_cable_length_m88(struct e1000_hw *hw)
1827{
1828 struct e1000_phy_info *phy = &hw->phy;
1829 s32 ret_val;
1830 u16 phy_data, index;
1831
1832 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
1833 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001834 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001835
1836 index = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
Bruce Allaneb656d42009-12-01 15:47:02 +00001837 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
Bruce Allan5015e532012-02-08 02:55:56 +00001838
1839 if (index >= M88E1000_CABLE_LENGTH_TABLE_SIZE - 1)
1840 return -E1000_ERR_PHY;
Bruce Allaneb656d42009-12-01 15:47:02 +00001841
Auke Kokbc7f75f2007-09-17 12:30:59 -07001842 phy->min_cable_length = e1000_m88_cable_length_table[index];
Bruce Allaneb656d42009-12-01 15:47:02 +00001843 phy->max_cable_length = e1000_m88_cable_length_table[index + 1];
Auke Kokbc7f75f2007-09-17 12:30:59 -07001844
1845 phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
1846
Bruce Allan5015e532012-02-08 02:55:56 +00001847 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001848}
1849
1850/**
1851 * e1000e_get_cable_length_igp_2 - Determine cable length for igp2 PHY
1852 * @hw: pointer to the HW structure
1853 *
1854 * The automatic gain control (agc) normalizes the amplitude of the
1855 * received signal, adjusting for the attenuation produced by the
Auke Kok489815c2008-02-21 15:11:07 -08001856 * cable. By reading the AGC registers, which represent the
Bruce Allan5ff5b662009-12-01 15:51:11 +00001857 * combination of coarse and fine gain value, the value can be put
Auke Kokbc7f75f2007-09-17 12:30:59 -07001858 * into a lookup table to obtain the approximate cable length
1859 * for each channel.
1860 **/
1861s32 e1000e_get_cable_length_igp_2(struct e1000_hw *hw)
1862{
1863 struct e1000_phy_info *phy = &hw->phy;
1864 s32 ret_val;
1865 u16 phy_data, i, agc_value = 0;
1866 u16 cur_agc_index, max_agc_index = 0;
1867 u16 min_agc_index = IGP02E1000_CABLE_LENGTH_TABLE_SIZE - 1;
Jeff Kirsher66744502010-12-01 19:59:50 +00001868 static const u16 agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] = {
1869 IGP02E1000_PHY_AGC_A,
1870 IGP02E1000_PHY_AGC_B,
1871 IGP02E1000_PHY_AGC_C,
1872 IGP02E1000_PHY_AGC_D
1873 };
Auke Kokbc7f75f2007-09-17 12:30:59 -07001874
1875 /* Read the AGC registers for all channels */
1876 for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
1877 ret_val = e1e_rphy(hw, agc_reg_array[i], &phy_data);
1878 if (ret_val)
1879 return ret_val;
1880
Bruce Allane921eb12012-11-28 09:28:37 +00001881 /* Getting bits 15:9, which represent the combination of
Bruce Allan5ff5b662009-12-01 15:51:11 +00001882 * coarse and fine gain values. The result is a number
Auke Kokbc7f75f2007-09-17 12:30:59 -07001883 * that can be put into the lookup table to obtain the
Bruce Allanad680762008-03-28 09:15:03 -07001884 * approximate cable length.
1885 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001886 cur_agc_index = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
1887 IGP02E1000_AGC_LENGTH_MASK;
1888
1889 /* Array index bound check. */
1890 if ((cur_agc_index >= IGP02E1000_CABLE_LENGTH_TABLE_SIZE) ||
1891 (cur_agc_index == 0))
1892 return -E1000_ERR_PHY;
1893
1894 /* Remove min & max AGC values from calculation. */
1895 if (e1000_igp_2_cable_length_table[min_agc_index] >
1896 e1000_igp_2_cable_length_table[cur_agc_index])
1897 min_agc_index = cur_agc_index;
1898 if (e1000_igp_2_cable_length_table[max_agc_index] <
1899 e1000_igp_2_cable_length_table[cur_agc_index])
1900 max_agc_index = cur_agc_index;
1901
1902 agc_value += e1000_igp_2_cable_length_table[cur_agc_index];
1903 }
1904
1905 agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] +
1906 e1000_igp_2_cable_length_table[max_agc_index]);
1907 agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
1908
1909 /* Calculate cable length with the error range of +/- 10 meters. */
1910 phy->min_cable_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
1911 (agc_value - IGP02E1000_AGC_RANGE) : 0;
1912 phy->max_cable_length = agc_value + IGP02E1000_AGC_RANGE;
1913
1914 phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
1915
Bruce Allan82607252012-02-08 02:55:09 +00001916 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001917}
1918
1919/**
1920 * e1000e_get_phy_info_m88 - Retrieve PHY information
1921 * @hw: pointer to the HW structure
1922 *
1923 * Valid for only copper links. Read the PHY status register (sticky read)
1924 * to verify that link is up. Read the PHY special control register to
1925 * determine the polarity and 10base-T extended distance. Read the PHY
1926 * special status register to determine MDI/MDIx and current speed. If
1927 * speed is 1000, then determine cable length, local and remote receiver.
1928 **/
1929s32 e1000e_get_phy_info_m88(struct e1000_hw *hw)
1930{
1931 struct e1000_phy_info *phy = &hw->phy;
1932 s32 ret_val;
1933 u16 phy_data;
1934 bool link;
1935
Bruce Allan0be84012009-12-02 17:03:18 +00001936 if (phy->media_type != e1000_media_type_copper) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001937 e_dbg("Phy info is only valid for copper media\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001938 return -E1000_ERR_CONFIG;
1939 }
1940
1941 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
1942 if (ret_val)
1943 return ret_val;
1944
1945 if (!link) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001946 e_dbg("Phy info is only valid if link is up\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001947 return -E1000_ERR_CONFIG;
1948 }
1949
1950 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1951 if (ret_val)
1952 return ret_val;
1953
Bruce Allan04499ec2012-04-13 00:08:31 +00001954 phy->polarity_correction = !!(phy_data &
1955 M88E1000_PSCR_POLARITY_REVERSAL);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001956
1957 ret_val = e1000_check_polarity_m88(hw);
1958 if (ret_val)
1959 return ret_val;
1960
1961 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
1962 if (ret_val)
1963 return ret_val;
1964
Bruce Allan04499ec2012-04-13 00:08:31 +00001965 phy->is_mdix = !!(phy_data & M88E1000_PSSR_MDIX);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001966
1967 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
Bruce Allandde3a572013-01-05 08:06:24 +00001968 ret_val = hw->phy.ops.get_cable_length(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001969 if (ret_val)
1970 return ret_val;
1971
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001972 ret_val = e1e_rphy(hw, MII_STAT1000, &phy_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001973 if (ret_val)
1974 return ret_val;
1975
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001976 phy->local_rx = (phy_data & LPA_1000LOCALRXOK)
1977 ? e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001978
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001979 phy->remote_rx = (phy_data & LPA_1000REMRXOK)
1980 ? e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001981 } else {
1982 /* Set values to "undefined" */
1983 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
1984 phy->local_rx = e1000_1000t_rx_status_undefined;
1985 phy->remote_rx = e1000_1000t_rx_status_undefined;
1986 }
1987
1988 return ret_val;
1989}
1990
1991/**
1992 * e1000e_get_phy_info_igp - Retrieve igp PHY information
1993 * @hw: pointer to the HW structure
1994 *
1995 * Read PHY status to determine if link is up. If link is up, then
1996 * set/determine 10base-T extended distance and polarity correction. Read
1997 * PHY port status to determine MDI/MDIx and speed. Based on the speed,
1998 * determine on the cable length, local and remote receiver.
1999 **/
2000s32 e1000e_get_phy_info_igp(struct e1000_hw *hw)
2001{
2002 struct e1000_phy_info *phy = &hw->phy;
2003 s32 ret_val;
2004 u16 data;
2005 bool link;
2006
2007 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
2008 if (ret_val)
2009 return ret_val;
2010
2011 if (!link) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002012 e_dbg("Phy info is only valid if link is up\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002013 return -E1000_ERR_CONFIG;
2014 }
2015
Bruce Allan564ea9b2009-11-20 23:26:44 +00002016 phy->polarity_correction = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002017
2018 ret_val = e1000_check_polarity_igp(hw);
2019 if (ret_val)
2020 return ret_val;
2021
2022 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_STATUS, &data);
2023 if (ret_val)
2024 return ret_val;
2025
Bruce Allan04499ec2012-04-13 00:08:31 +00002026 phy->is_mdix = !!(data & IGP01E1000_PSSR_MDIX);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002027
2028 if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
2029 IGP01E1000_PSSR_SPEED_1000MBPS) {
Bruce Allandde3a572013-01-05 08:06:24 +00002030 ret_val = phy->ops.get_cable_length(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002031 if (ret_val)
2032 return ret_val;
2033
Bruce Allanc2ade1a2013-01-16 08:54:35 +00002034 ret_val = e1e_rphy(hw, MII_STAT1000, &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002035 if (ret_val)
2036 return ret_val;
2037
Bruce Allanc2ade1a2013-01-16 08:54:35 +00002038 phy->local_rx = (data & LPA_1000LOCALRXOK)
2039 ? e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002040
Bruce Allanc2ade1a2013-01-16 08:54:35 +00002041 phy->remote_rx = (data & LPA_1000REMRXOK)
2042 ? e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002043 } else {
2044 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
2045 phy->local_rx = e1000_1000t_rx_status_undefined;
2046 phy->remote_rx = e1000_1000t_rx_status_undefined;
2047 }
2048
2049 return ret_val;
2050}
2051
2052/**
Bruce Allan0be84012009-12-02 17:03:18 +00002053 * e1000_get_phy_info_ife - Retrieves various IFE PHY states
2054 * @hw: pointer to the HW structure
2055 *
2056 * Populates "phy" structure with various feature states.
2057 **/
2058s32 e1000_get_phy_info_ife(struct e1000_hw *hw)
2059{
2060 struct e1000_phy_info *phy = &hw->phy;
2061 s32 ret_val;
2062 u16 data;
2063 bool link;
2064
2065 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
2066 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002067 return ret_val;
Bruce Allan0be84012009-12-02 17:03:18 +00002068
2069 if (!link) {
2070 e_dbg("Phy info is only valid if link is up\n");
Bruce Allan5015e532012-02-08 02:55:56 +00002071 return -E1000_ERR_CONFIG;
Bruce Allan0be84012009-12-02 17:03:18 +00002072 }
2073
2074 ret_val = e1e_rphy(hw, IFE_PHY_SPECIAL_CONTROL, &data);
2075 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002076 return ret_val;
Bruce Allan04499ec2012-04-13 00:08:31 +00002077 phy->polarity_correction = !(data & IFE_PSC_AUTO_POLARITY_DISABLE);
Bruce Allan0be84012009-12-02 17:03:18 +00002078
2079 if (phy->polarity_correction) {
2080 ret_val = e1000_check_polarity_ife(hw);
2081 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002082 return ret_val;
Bruce Allan0be84012009-12-02 17:03:18 +00002083 } else {
2084 /* Polarity is forced */
2085 phy->cable_polarity = (data & IFE_PSC_FORCE_POLARITY)
2086 ? e1000_rev_polarity_reversed
2087 : e1000_rev_polarity_normal;
2088 }
2089
2090 ret_val = e1e_rphy(hw, IFE_PHY_MDIX_CONTROL, &data);
2091 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002092 return ret_val;
Bruce Allan0be84012009-12-02 17:03:18 +00002093
Bruce Allan04499ec2012-04-13 00:08:31 +00002094 phy->is_mdix = !!(data & IFE_PMC_MDIX_STATUS);
Bruce Allan0be84012009-12-02 17:03:18 +00002095
2096 /* The following parameters are undefined for 10/100 operation. */
2097 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
2098 phy->local_rx = e1000_1000t_rx_status_undefined;
2099 phy->remote_rx = e1000_1000t_rx_status_undefined;
2100
Bruce Allan5015e532012-02-08 02:55:56 +00002101 return 0;
Bruce Allan0be84012009-12-02 17:03:18 +00002102}
2103
2104/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002105 * e1000e_phy_sw_reset - PHY software reset
2106 * @hw: pointer to the HW structure
2107 *
2108 * Does a software reset of the PHY by reading the PHY control register and
2109 * setting/write the control register reset bit to the PHY.
2110 **/
2111s32 e1000e_phy_sw_reset(struct e1000_hw *hw)
2112{
2113 s32 ret_val;
2114 u16 phy_ctrl;
2115
Bruce Allanc2ade1a2013-01-16 08:54:35 +00002116 ret_val = e1e_rphy(hw, MII_BMCR, &phy_ctrl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002117 if (ret_val)
2118 return ret_val;
2119
Bruce Allanc2ade1a2013-01-16 08:54:35 +00002120 phy_ctrl |= BMCR_RESET;
2121 ret_val = e1e_wphy(hw, MII_BMCR, phy_ctrl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002122 if (ret_val)
2123 return ret_val;
2124
2125 udelay(1);
2126
2127 return ret_val;
2128}
2129
2130/**
2131 * e1000e_phy_hw_reset_generic - PHY hardware reset
2132 * @hw: pointer to the HW structure
2133 *
2134 * Verify the reset block is not blocking us from resetting. Acquire
2135 * semaphore (if necessary) and read/set/write the device control reset
2136 * bit in the PHY. Wait the appropriate delay time for the device to
Auke Kok489815c2008-02-21 15:11:07 -08002137 * reset and release the semaphore (if necessary).
Auke Kokbc7f75f2007-09-17 12:30:59 -07002138 **/
2139s32 e1000e_phy_hw_reset_generic(struct e1000_hw *hw)
2140{
2141 struct e1000_phy_info *phy = &hw->phy;
2142 s32 ret_val;
2143 u32 ctrl;
2144
Bruce Allan470a5422012-05-26 06:08:48 +00002145 if (phy->ops.check_reset_block) {
2146 ret_val = phy->ops.check_reset_block(hw);
2147 if (ret_val)
2148 return 0;
2149 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002150
Bruce Allan94d81862009-11-20 23:25:26 +00002151 ret_val = phy->ops.acquire(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002152 if (ret_val)
2153 return ret_val;
2154
2155 ctrl = er32(CTRL);
2156 ew32(CTRL, ctrl | E1000_CTRL_PHY_RST);
2157 e1e_flush();
2158
2159 udelay(phy->reset_delay_us);
2160
2161 ew32(CTRL, ctrl);
2162 e1e_flush();
2163
2164 udelay(150);
2165
Bruce Allan94d81862009-11-20 23:25:26 +00002166 phy->ops.release(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002167
Bruce Allan84c1bef2013-01-05 08:06:19 +00002168 return phy->ops.get_cfg_done(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002169}
2170
2171/**
Bruce Allanfe908492013-01-05 08:06:14 +00002172 * e1000e_get_cfg_done_generic - Generic configuration done
Auke Kokbc7f75f2007-09-17 12:30:59 -07002173 * @hw: pointer to the HW structure
2174 *
2175 * Generic function to wait 10 milli-seconds for configuration to complete
2176 * and return success.
2177 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00002178s32 e1000e_get_cfg_done_generic(struct e1000_hw __always_unused *hw)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002179{
2180 mdelay(10);
Bruce Allan3d3a1672012-02-23 03:13:18 +00002181
Auke Kokbc7f75f2007-09-17 12:30:59 -07002182 return 0;
2183}
2184
Bruce Allanf4187b52008-08-26 18:36:50 -07002185/**
2186 * e1000e_phy_init_script_igp3 - Inits the IGP3 PHY
2187 * @hw: pointer to the HW structure
2188 *
2189 * Initializes a Intel Gigabit PHY3 when an EEPROM is not present.
2190 **/
2191s32 e1000e_phy_init_script_igp3(struct e1000_hw *hw)
2192{
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002193 e_dbg("Running IGP 3 PHY init script\n");
Bruce Allanf4187b52008-08-26 18:36:50 -07002194
2195 /* PHY init IGP 3 */
2196 /* Enable rise/fall, 10-mode work in class-A */
2197 e1e_wphy(hw, 0x2F5B, 0x9018);
2198 /* Remove all caps from Replica path filter */
2199 e1e_wphy(hw, 0x2F52, 0x0000);
2200 /* Bias trimming for ADC, AFE and Driver (Default) */
2201 e1e_wphy(hw, 0x2FB1, 0x8B24);
2202 /* Increase Hybrid poly bias */
2203 e1e_wphy(hw, 0x2FB2, 0xF8F0);
2204 /* Add 4% to Tx amplitude in Gig mode */
2205 e1e_wphy(hw, 0x2010, 0x10B0);
2206 /* Disable trimming (TTT) */
2207 e1e_wphy(hw, 0x2011, 0x0000);
2208 /* Poly DC correction to 94.6% + 2% for all channels */
2209 e1e_wphy(hw, 0x20DD, 0x249A);
2210 /* ABS DC correction to 95.9% */
2211 e1e_wphy(hw, 0x20DE, 0x00D3);
2212 /* BG temp curve trim */
2213 e1e_wphy(hw, 0x28B4, 0x04CE);
2214 /* Increasing ADC OPAMP stage 1 currents to max */
2215 e1e_wphy(hw, 0x2F70, 0x29E4);
2216 /* Force 1000 ( required for enabling PHY regs configuration) */
2217 e1e_wphy(hw, 0x0000, 0x0140);
2218 /* Set upd_freq to 6 */
2219 e1e_wphy(hw, 0x1F30, 0x1606);
2220 /* Disable NPDFE */
2221 e1e_wphy(hw, 0x1F31, 0xB814);
2222 /* Disable adaptive fixed FFE (Default) */
2223 e1e_wphy(hw, 0x1F35, 0x002A);
2224 /* Enable FFE hysteresis */
2225 e1e_wphy(hw, 0x1F3E, 0x0067);
2226 /* Fixed FFE for short cable lengths */
2227 e1e_wphy(hw, 0x1F54, 0x0065);
2228 /* Fixed FFE for medium cable lengths */
2229 e1e_wphy(hw, 0x1F55, 0x002A);
2230 /* Fixed FFE for long cable lengths */
2231 e1e_wphy(hw, 0x1F56, 0x002A);
2232 /* Enable Adaptive Clip Threshold */
2233 e1e_wphy(hw, 0x1F72, 0x3FB0);
2234 /* AHT reset limit to 1 */
2235 e1e_wphy(hw, 0x1F76, 0xC0FF);
2236 /* Set AHT master delay to 127 msec */
2237 e1e_wphy(hw, 0x1F77, 0x1DEC);
2238 /* Set scan bits for AHT */
2239 e1e_wphy(hw, 0x1F78, 0xF9EF);
2240 /* Set AHT Preset bits */
2241 e1e_wphy(hw, 0x1F79, 0x0210);
2242 /* Change integ_factor of channel A to 3 */
2243 e1e_wphy(hw, 0x1895, 0x0003);
2244 /* Change prop_factor of channels BCD to 8 */
2245 e1e_wphy(hw, 0x1796, 0x0008);
2246 /* Change cg_icount + enable integbp for channels BCD */
2247 e1e_wphy(hw, 0x1798, 0xD008);
Bruce Allane921eb12012-11-28 09:28:37 +00002248 /* Change cg_icount + enable integbp + change prop_factor_master
Bruce Allanf4187b52008-08-26 18:36:50 -07002249 * to 8 for channel A
2250 */
2251 e1e_wphy(hw, 0x1898, 0xD918);
2252 /* Disable AHT in Slave mode on channel A */
2253 e1e_wphy(hw, 0x187A, 0x0800);
Bruce Allane921eb12012-11-28 09:28:37 +00002254 /* Enable LPLU and disable AN to 1000 in non-D0a states,
Bruce Allanf4187b52008-08-26 18:36:50 -07002255 * Enable SPD+B2B
2256 */
2257 e1e_wphy(hw, 0x0019, 0x008D);
2258 /* Enable restart AN on an1000_dis change */
2259 e1e_wphy(hw, 0x001B, 0x2080);
2260 /* Enable wh_fifo read clock in 10/100 modes */
2261 e1e_wphy(hw, 0x0014, 0x0045);
2262 /* Restart AN, Speed selection is 1000 */
2263 e1e_wphy(hw, 0x0000, 0x1340);
2264
2265 return 0;
2266}
2267
Auke Kokbc7f75f2007-09-17 12:30:59 -07002268/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002269 * e1000e_get_phy_type_from_id - Get PHY type from id
2270 * @phy_id: phy_id read from the phy
2271 *
2272 * Returns the phy type from the id.
2273 **/
2274enum e1000_phy_type e1000e_get_phy_type_from_id(u32 phy_id)
2275{
2276 enum e1000_phy_type phy_type = e1000_phy_unknown;
2277
2278 switch (phy_id) {
2279 case M88E1000_I_PHY_ID:
2280 case M88E1000_E_PHY_ID:
2281 case M88E1111_I_PHY_ID:
2282 case M88E1011_I_PHY_ID:
2283 phy_type = e1000_phy_m88;
2284 break;
2285 case IGP01E1000_I_PHY_ID: /* IGP 1 & 2 share this */
2286 phy_type = e1000_phy_igp_2;
2287 break;
2288 case GG82563_E_PHY_ID:
2289 phy_type = e1000_phy_gg82563;
2290 break;
2291 case IGP03E1000_E_PHY_ID:
2292 phy_type = e1000_phy_igp_3;
2293 break;
2294 case IFE_E_PHY_ID:
2295 case IFE_PLUS_E_PHY_ID:
2296 case IFE_C_E_PHY_ID:
2297 phy_type = e1000_phy_ife;
2298 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002299 case BME1000_E_PHY_ID:
2300 case BME1000_E_PHY_ID_R2:
2301 phy_type = e1000_phy_bm;
2302 break;
Bruce Allana4f58f52009-06-02 11:29:18 +00002303 case I82578_E_PHY_ID:
2304 phy_type = e1000_phy_82578;
2305 break;
2306 case I82577_E_PHY_ID:
2307 phy_type = e1000_phy_82577;
2308 break;
Bruce Alland3738bb2010-06-16 13:27:28 +00002309 case I82579_E_PHY_ID:
2310 phy_type = e1000_phy_82579;
2311 break;
Bruce Allan2fbe4522012-04-19 03:21:47 +00002312 case I217_E_PHY_ID:
2313 phy_type = e1000_phy_i217;
2314 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002315 default:
2316 phy_type = e1000_phy_unknown;
2317 break;
2318 }
2319 return phy_type;
2320}
2321
2322/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002323 * e1000e_determine_phy_address - Determines PHY address.
2324 * @hw: pointer to the HW structure
2325 *
2326 * This uses a trial and error method to loop through possible PHY
2327 * addresses. It tests each by reading the PHY ID registers and
2328 * checking for a match.
2329 **/
2330s32 e1000e_determine_phy_address(struct e1000_hw *hw)
2331{
Bruce Allan5eb6f3c2009-12-02 17:02:43 +00002332 u32 phy_addr = 0;
2333 u32 i;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002334 enum e1000_phy_type phy_type = e1000_phy_unknown;
2335
Bruce Allan5eb6f3c2009-12-02 17:02:43 +00002336 hw->phy.id = phy_type;
2337
2338 for (phy_addr = 0; phy_addr < E1000_MAX_PHY_ADDR; phy_addr++) {
2339 hw->phy.addr = phy_addr;
2340 i = 0;
2341
2342 do {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002343 e1000e_get_phy_id(hw);
2344 phy_type = e1000e_get_phy_type_from_id(hw->phy.id);
2345
Bruce Allane921eb12012-11-28 09:28:37 +00002346 /* If phy_type is valid, break - we found our
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002347 * PHY address
2348 */
Bruce Allan5015e532012-02-08 02:55:56 +00002349 if (phy_type != e1000_phy_unknown)
2350 return 0;
2351
Bruce Allan1bba4382011-03-19 00:27:20 +00002352 usleep_range(1000, 2000);
Bruce Allan5eb6f3c2009-12-02 17:02:43 +00002353 i++;
2354 } while (i < 10);
2355 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002356
Bruce Allan5015e532012-02-08 02:55:56 +00002357 return -E1000_ERR_PHY_TYPE;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002358}
2359
2360/**
2361 * e1000_get_phy_addr_for_bm_page - Retrieve PHY page address
2362 * @page: page to access
2363 *
2364 * Returns the phy address for the page requested.
2365 **/
2366static u32 e1000_get_phy_addr_for_bm_page(u32 page, u32 reg)
2367{
2368 u32 phy_addr = 2;
2369
2370 if ((page >= 768) || (page == 0 && reg == 25) || (reg == 31))
2371 phy_addr = 1;
2372
2373 return phy_addr;
2374}
2375
2376/**
2377 * e1000e_write_phy_reg_bm - Write BM PHY register
2378 * @hw: pointer to the HW structure
2379 * @offset: register offset to write to
2380 * @data: data to write at register offset
2381 *
2382 * Acquires semaphore, if necessary, then writes the data to PHY register
2383 * at the offset. Release any acquired semaphores before exiting.
2384 **/
2385s32 e1000e_write_phy_reg_bm(struct e1000_hw *hw, u32 offset, u16 data)
2386{
2387 s32 ret_val;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002388 u32 page = offset >> IGP_PAGE_SHIFT;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002389
Bruce Allan94d81862009-11-20 23:25:26 +00002390 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002391 if (ret_val)
2392 return ret_val;
2393
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002394 /* Page 800 works differently than the rest so it has its own func */
2395 if (page == BM_WUC_PAGE) {
2396 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, &data,
Bruce Allan2b6b1682011-05-13 07:20:09 +00002397 false, false);
Bruce Allan75ce1532012-02-08 02:54:48 +00002398 goto release;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002399 }
2400
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002401 hw->phy.addr = e1000_get_phy_addr_for_bm_page(page, offset);
2402
2403 if (offset > MAX_PHY_MULTI_PAGE_REG) {
Bruce Allan90da0662011-01-06 07:02:53 +00002404 u32 page_shift, page_select;
2405
Bruce Allane921eb12012-11-28 09:28:37 +00002406 /* Page select is register 31 for phy address 1 and 22 for
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002407 * phy address 2 and 3. Page select is shifted only for
2408 * phy address 1.
2409 */
2410 if (hw->phy.addr == 1) {
2411 page_shift = IGP_PAGE_SHIFT;
2412 page_select = IGP01E1000_PHY_PAGE_SELECT;
2413 } else {
2414 page_shift = 0;
2415 page_select = BM_PHY_PAGE_SELECT;
2416 }
2417
2418 /* Page is shifted left, PHY expects (page x 32) */
2419 ret_val = e1000e_write_phy_reg_mdic(hw, page_select,
2420 (page << page_shift));
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002421 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00002422 goto release;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002423 }
2424
2425 ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
2426 data);
2427
Bruce Allan75ce1532012-02-08 02:54:48 +00002428release:
Bruce Allan94d81862009-11-20 23:25:26 +00002429 hw->phy.ops.release(hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002430 return ret_val;
2431}
2432
2433/**
2434 * e1000e_read_phy_reg_bm - Read BM PHY register
2435 * @hw: pointer to the HW structure
2436 * @offset: register offset to be read
2437 * @data: pointer to the read data
2438 *
2439 * Acquires semaphore, if necessary, then reads the PHY register at offset
2440 * and storing the retrieved information in data. Release any acquired
2441 * semaphores before exiting.
2442 **/
2443s32 e1000e_read_phy_reg_bm(struct e1000_hw *hw, u32 offset, u16 *data)
2444{
2445 s32 ret_val;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002446 u32 page = offset >> IGP_PAGE_SHIFT;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002447
Bruce Allan94d81862009-11-20 23:25:26 +00002448 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002449 if (ret_val)
2450 return ret_val;
2451
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002452 /* Page 800 works differently than the rest so it has its own func */
2453 if (page == BM_WUC_PAGE) {
2454 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, data,
Bruce Allan2b6b1682011-05-13 07:20:09 +00002455 true, false);
Bruce Allan75ce1532012-02-08 02:54:48 +00002456 goto release;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002457 }
2458
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002459 hw->phy.addr = e1000_get_phy_addr_for_bm_page(page, offset);
2460
2461 if (offset > MAX_PHY_MULTI_PAGE_REG) {
Bruce Allan90da0662011-01-06 07:02:53 +00002462 u32 page_shift, page_select;
2463
Bruce Allane921eb12012-11-28 09:28:37 +00002464 /* Page select is register 31 for phy address 1 and 22 for
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002465 * phy address 2 and 3. Page select is shifted only for
2466 * phy address 1.
2467 */
2468 if (hw->phy.addr == 1) {
2469 page_shift = IGP_PAGE_SHIFT;
2470 page_select = IGP01E1000_PHY_PAGE_SELECT;
2471 } else {
2472 page_shift = 0;
2473 page_select = BM_PHY_PAGE_SELECT;
2474 }
2475
2476 /* Page is shifted left, PHY expects (page x 32) */
2477 ret_val = e1000e_write_phy_reg_mdic(hw, page_select,
2478 (page << page_shift));
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002479 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00002480 goto release;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002481 }
2482
2483 ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
2484 data);
Bruce Allan75ce1532012-02-08 02:54:48 +00002485release:
Bruce Allan94d81862009-11-20 23:25:26 +00002486 hw->phy.ops.release(hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002487 return ret_val;
2488}
2489
2490/**
Bruce Allan4662e822008-08-26 18:37:06 -07002491 * e1000e_read_phy_reg_bm2 - Read BM PHY register
2492 * @hw: pointer to the HW structure
2493 * @offset: register offset to be read
2494 * @data: pointer to the read data
2495 *
2496 * Acquires semaphore, if necessary, then reads the PHY register at offset
2497 * and storing the retrieved information in data. Release any acquired
2498 * semaphores before exiting.
2499 **/
2500s32 e1000e_read_phy_reg_bm2(struct e1000_hw *hw, u32 offset, u16 *data)
2501{
2502 s32 ret_val;
2503 u16 page = (u16)(offset >> IGP_PAGE_SHIFT);
2504
Bruce Allan94d81862009-11-20 23:25:26 +00002505 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002506 if (ret_val)
2507 return ret_val;
2508
Bruce Allan4662e822008-08-26 18:37:06 -07002509 /* Page 800 works differently than the rest so it has its own func */
2510 if (page == BM_WUC_PAGE) {
2511 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, data,
Bruce Allan2b6b1682011-05-13 07:20:09 +00002512 true, false);
Bruce Allan75ce1532012-02-08 02:54:48 +00002513 goto release;
Bruce Allan4662e822008-08-26 18:37:06 -07002514 }
2515
Bruce Allan4662e822008-08-26 18:37:06 -07002516 hw->phy.addr = 1;
2517
2518 if (offset > MAX_PHY_MULTI_PAGE_REG) {
2519
2520 /* Page is shifted left, PHY expects (page x 32) */
2521 ret_val = e1000e_write_phy_reg_mdic(hw, BM_PHY_PAGE_SELECT,
2522 page);
2523
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002524 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00002525 goto release;
Bruce Allan4662e822008-08-26 18:37:06 -07002526 }
2527
2528 ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
2529 data);
Bruce Allan75ce1532012-02-08 02:54:48 +00002530release:
Bruce Allan94d81862009-11-20 23:25:26 +00002531 hw->phy.ops.release(hw);
Bruce Allan4662e822008-08-26 18:37:06 -07002532 return ret_val;
2533}
2534
2535/**
2536 * e1000e_write_phy_reg_bm2 - Write BM PHY register
2537 * @hw: pointer to the HW structure
2538 * @offset: register offset to write to
2539 * @data: data to write at register offset
2540 *
2541 * Acquires semaphore, if necessary, then writes the data to PHY register
2542 * at the offset. Release any acquired semaphores before exiting.
2543 **/
2544s32 e1000e_write_phy_reg_bm2(struct e1000_hw *hw, u32 offset, u16 data)
2545{
2546 s32 ret_val;
2547 u16 page = (u16)(offset >> IGP_PAGE_SHIFT);
2548
Bruce Allan94d81862009-11-20 23:25:26 +00002549 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002550 if (ret_val)
2551 return ret_val;
2552
Bruce Allan4662e822008-08-26 18:37:06 -07002553 /* Page 800 works differently than the rest so it has its own func */
2554 if (page == BM_WUC_PAGE) {
2555 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, &data,
Bruce Allan2b6b1682011-05-13 07:20:09 +00002556 false, false);
Bruce Allan75ce1532012-02-08 02:54:48 +00002557 goto release;
Bruce Allan4662e822008-08-26 18:37:06 -07002558 }
2559
Bruce Allan4662e822008-08-26 18:37:06 -07002560 hw->phy.addr = 1;
2561
2562 if (offset > MAX_PHY_MULTI_PAGE_REG) {
2563 /* Page is shifted left, PHY expects (page x 32) */
2564 ret_val = e1000e_write_phy_reg_mdic(hw, BM_PHY_PAGE_SELECT,
2565 page);
2566
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002567 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00002568 goto release;
Bruce Allan4662e822008-08-26 18:37:06 -07002569 }
2570
2571 ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
2572 data);
2573
Bruce Allan75ce1532012-02-08 02:54:48 +00002574release:
Bruce Allan94d81862009-11-20 23:25:26 +00002575 hw->phy.ops.release(hw);
Bruce Allan4662e822008-08-26 18:37:06 -07002576 return ret_val;
2577}
2578
2579/**
Bruce Allan2b6b1682011-05-13 07:20:09 +00002580 * e1000_enable_phy_wakeup_reg_access_bm - enable access to BM wakeup registers
2581 * @hw: pointer to the HW structure
2582 * @phy_reg: pointer to store original contents of BM_WUC_ENABLE_REG
2583 *
2584 * Assumes semaphore already acquired and phy_reg points to a valid memory
2585 * address to store contents of the BM_WUC_ENABLE_REG register.
2586 **/
2587s32 e1000_enable_phy_wakeup_reg_access_bm(struct e1000_hw *hw, u16 *phy_reg)
2588{
2589 s32 ret_val;
2590 u16 temp;
2591
2592 /* All page select, port ctrl and wakeup registers use phy address 1 */
2593 hw->phy.addr = 1;
2594
2595 /* Select Port Control Registers page */
2596 ret_val = e1000_set_page_igp(hw, (BM_PORT_CTRL_PAGE << IGP_PAGE_SHIFT));
2597 if (ret_val) {
2598 e_dbg("Could not set Port Control page\n");
Bruce Allan5015e532012-02-08 02:55:56 +00002599 return ret_val;
Bruce Allan2b6b1682011-05-13 07:20:09 +00002600 }
2601
2602 ret_val = e1000e_read_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, phy_reg);
2603 if (ret_val) {
2604 e_dbg("Could not read PHY register %d.%d\n",
2605 BM_PORT_CTRL_PAGE, BM_WUC_ENABLE_REG);
Bruce Allan5015e532012-02-08 02:55:56 +00002606 return ret_val;
Bruce Allan2b6b1682011-05-13 07:20:09 +00002607 }
2608
Bruce Allane921eb12012-11-28 09:28:37 +00002609 /* Enable both PHY wakeup mode and Wakeup register page writes.
Bruce Allan2b6b1682011-05-13 07:20:09 +00002610 * Prevent a power state change by disabling ME and Host PHY wakeup.
2611 */
2612 temp = *phy_reg;
2613 temp |= BM_WUC_ENABLE_BIT;
2614 temp &= ~(BM_WUC_ME_WU_BIT | BM_WUC_HOST_WU_BIT);
2615
2616 ret_val = e1000e_write_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, temp);
2617 if (ret_val) {
2618 e_dbg("Could not write PHY register %d.%d\n",
2619 BM_PORT_CTRL_PAGE, BM_WUC_ENABLE_REG);
Bruce Allan5015e532012-02-08 02:55:56 +00002620 return ret_val;
Bruce Allan2b6b1682011-05-13 07:20:09 +00002621 }
2622
Bruce Allane921eb12012-11-28 09:28:37 +00002623 /* Select Host Wakeup Registers page - caller now able to write
Bruce Allan5015e532012-02-08 02:55:56 +00002624 * registers on the Wakeup registers page
2625 */
2626 return e1000_set_page_igp(hw, (BM_WUC_PAGE << IGP_PAGE_SHIFT));
Bruce Allan2b6b1682011-05-13 07:20:09 +00002627}
2628
2629/**
2630 * e1000_disable_phy_wakeup_reg_access_bm - disable access to BM wakeup regs
2631 * @hw: pointer to the HW structure
2632 * @phy_reg: pointer to original contents of BM_WUC_ENABLE_REG
2633 *
2634 * Restore BM_WUC_ENABLE_REG to its original value.
2635 *
2636 * Assumes semaphore already acquired and *phy_reg is the contents of the
2637 * BM_WUC_ENABLE_REG before register(s) on BM_WUC_PAGE were accessed by
2638 * caller.
2639 **/
2640s32 e1000_disable_phy_wakeup_reg_access_bm(struct e1000_hw *hw, u16 *phy_reg)
2641{
Bruce Allan70806a72013-01-05 05:08:37 +00002642 s32 ret_val;
Bruce Allan2b6b1682011-05-13 07:20:09 +00002643
2644 /* Select Port Control Registers page */
2645 ret_val = e1000_set_page_igp(hw, (BM_PORT_CTRL_PAGE << IGP_PAGE_SHIFT));
2646 if (ret_val) {
2647 e_dbg("Could not set Port Control page\n");
Bruce Allan5015e532012-02-08 02:55:56 +00002648 return ret_val;
Bruce Allan2b6b1682011-05-13 07:20:09 +00002649 }
2650
2651 /* Restore 769.17 to its original value */
2652 ret_val = e1000e_write_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, *phy_reg);
2653 if (ret_val)
2654 e_dbg("Could not restore PHY register %d.%d\n",
2655 BM_PORT_CTRL_PAGE, BM_WUC_ENABLE_REG);
Bruce Allan5015e532012-02-08 02:55:56 +00002656
Bruce Allan2b6b1682011-05-13 07:20:09 +00002657 return ret_val;
2658}
2659
2660/**
2661 * e1000_access_phy_wakeup_reg_bm - Read/write BM PHY wakeup register
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002662 * @hw: pointer to the HW structure
2663 * @offset: register offset to be read or written
2664 * @data: pointer to the data to read or write
2665 * @read: determines if operation is read or write
Bruce Allan2b6b1682011-05-13 07:20:09 +00002666 * @page_set: BM_WUC_PAGE already set and access enabled
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002667 *
Bruce Allan2b6b1682011-05-13 07:20:09 +00002668 * Read the PHY register at offset and store the retrieved information in
2669 * data, or write data to PHY register at offset. Note the procedure to
2670 * access the PHY wakeup registers is different than reading the other PHY
2671 * registers. It works as such:
2672 * 1) Set 769.17.2 (page 769, register 17, bit 2) = 1
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002673 * 2) Set page to 800 for host (801 if we were manageability)
2674 * 3) Write the address using the address opcode (0x11)
2675 * 4) Read or write the data using the data opcode (0x12)
Bruce Allan2b6b1682011-05-13 07:20:09 +00002676 * 5) Restore 769.17.2 to its original value
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002677 *
Bruce Allan2b6b1682011-05-13 07:20:09 +00002678 * Steps 1 and 2 are done by e1000_enable_phy_wakeup_reg_access_bm() and
2679 * step 5 is done by e1000_disable_phy_wakeup_reg_access_bm().
2680 *
2681 * Assumes semaphore is already acquired. When page_set==true, assumes
2682 * the PHY page is set to BM_WUC_PAGE (i.e. a function in the call stack
2683 * is responsible for calls to e1000_[enable|disable]_phy_wakeup_reg_bm()).
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002684 **/
2685static s32 e1000_access_phy_wakeup_reg_bm(struct e1000_hw *hw, u32 offset,
Bruce Allan2b6b1682011-05-13 07:20:09 +00002686 u16 *data, bool read, bool page_set)
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002687{
2688 s32 ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00002689 u16 reg = BM_PHY_REG_NUM(offset);
Bruce Allan2b6b1682011-05-13 07:20:09 +00002690 u16 page = BM_PHY_REG_PAGE(offset);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002691 u16 phy_reg = 0;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002692
Bruce Allan2b6b1682011-05-13 07:20:09 +00002693 /* Gig must be disabled for MDIO accesses to Host Wakeup reg page */
Bruce Allana4f58f52009-06-02 11:29:18 +00002694 if ((hw->mac.type == e1000_pchlan) &&
Bruce Allan2b6b1682011-05-13 07:20:09 +00002695 (!(er32(PHY_CTRL) & E1000_PHY_CTRL_GBE_DISABLE)))
2696 e_dbg("Attempting to access page %d while gig enabled.\n",
2697 page);
Bruce Allana4f58f52009-06-02 11:29:18 +00002698
Bruce Allan2b6b1682011-05-13 07:20:09 +00002699 if (!page_set) {
2700 /* Enable access to PHY wakeup registers */
2701 ret_val = e1000_enable_phy_wakeup_reg_access_bm(hw, &phy_reg);
2702 if (ret_val) {
2703 e_dbg("Could not enable PHY wakeup reg access\n");
Bruce Allan5015e532012-02-08 02:55:56 +00002704 return ret_val;
Bruce Allan2b6b1682011-05-13 07:20:09 +00002705 }
Bruce Allan9b71b412009-12-01 15:53:07 +00002706 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002707
Bruce Allan2b6b1682011-05-13 07:20:09 +00002708 e_dbg("Accessing PHY page %d reg 0x%x\n", page, reg);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002709
Bruce Allan2b6b1682011-05-13 07:20:09 +00002710 /* Write the Wakeup register page offset value using opcode 0x11 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002711 ret_val = e1000e_write_phy_reg_mdic(hw, BM_WUC_ADDRESS_OPCODE, reg);
Bruce Allan9b71b412009-12-01 15:53:07 +00002712 if (ret_val) {
Bruce Allan2b6b1682011-05-13 07:20:09 +00002713 e_dbg("Could not write address opcode to page %d\n", page);
Bruce Allan5015e532012-02-08 02:55:56 +00002714 return ret_val;
Bruce Allan9b71b412009-12-01 15:53:07 +00002715 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002716
2717 if (read) {
Bruce Allan2b6b1682011-05-13 07:20:09 +00002718 /* Read the Wakeup register page value using opcode 0x12 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002719 ret_val = e1000e_read_phy_reg_mdic(hw, BM_WUC_DATA_OPCODE,
2720 data);
2721 } else {
Bruce Allan2b6b1682011-05-13 07:20:09 +00002722 /* Write the Wakeup register page value using opcode 0x12 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002723 ret_val = e1000e_write_phy_reg_mdic(hw, BM_WUC_DATA_OPCODE,
2724 *data);
2725 }
2726
Bruce Allan9b71b412009-12-01 15:53:07 +00002727 if (ret_val) {
Bruce Allan2b6b1682011-05-13 07:20:09 +00002728 e_dbg("Could not access PHY reg %d.%d\n", page, reg);
Bruce Allan5015e532012-02-08 02:55:56 +00002729 return ret_val;
Bruce Allan9b71b412009-12-01 15:53:07 +00002730 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002731
Bruce Allan2b6b1682011-05-13 07:20:09 +00002732 if (!page_set)
2733 ret_val = e1000_disable_phy_wakeup_reg_access_bm(hw, &phy_reg);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002734
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002735 return ret_val;
2736}
2737
2738/**
Bruce Allan17f208d2009-12-01 15:47:22 +00002739 * e1000_power_up_phy_copper - Restore copper link in case of PHY power down
2740 * @hw: pointer to the HW structure
2741 *
2742 * In the case of a PHY power down to save power, or to turn off link during a
2743 * driver unload, or wake on lan is not enabled, restore the link to previous
2744 * settings.
2745 **/
2746void e1000_power_up_phy_copper(struct e1000_hw *hw)
2747{
2748 u16 mii_reg = 0;
2749
2750 /* The PHY will retain its settings across a power down/up cycle */
Bruce Allanc2ade1a2013-01-16 08:54:35 +00002751 e1e_rphy(hw, MII_BMCR, &mii_reg);
2752 mii_reg &= ~BMCR_PDOWN;
2753 e1e_wphy(hw, MII_BMCR, mii_reg);
Bruce Allan17f208d2009-12-01 15:47:22 +00002754}
2755
2756/**
2757 * e1000_power_down_phy_copper - Restore copper link in case of PHY power down
2758 * @hw: pointer to the HW structure
2759 *
2760 * In the case of a PHY power down to save power, or to turn off link during a
2761 * driver unload, or wake on lan is not enabled, restore the link to previous
2762 * settings.
2763 **/
2764void e1000_power_down_phy_copper(struct e1000_hw *hw)
2765{
2766 u16 mii_reg = 0;
2767
2768 /* The PHY will retain its settings across a power down/up cycle */
Bruce Allanc2ade1a2013-01-16 08:54:35 +00002769 e1e_rphy(hw, MII_BMCR, &mii_reg);
2770 mii_reg |= BMCR_PDOWN;
2771 e1e_wphy(hw, MII_BMCR, mii_reg);
Bruce Allan1bba4382011-03-19 00:27:20 +00002772 usleep_range(1000, 2000);
Bruce Allan17f208d2009-12-01 15:47:22 +00002773}
2774
2775/**
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002776 * __e1000_read_phy_reg_hv - Read HV PHY register
Bruce Allana4f58f52009-06-02 11:29:18 +00002777 * @hw: pointer to the HW structure
2778 * @offset: register offset to be read
2779 * @data: pointer to the read data
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002780 * @locked: semaphore has already been acquired or not
Bruce Allana4f58f52009-06-02 11:29:18 +00002781 *
2782 * Acquires semaphore, if necessary, then reads the PHY register at offset
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002783 * and stores the retrieved information in data. Release any acquired
Bruce Allana4f58f52009-06-02 11:29:18 +00002784 * semaphore before exiting.
2785 **/
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002786static s32 __e1000_read_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 *data,
Bruce Allan2b6b1682011-05-13 07:20:09 +00002787 bool locked, bool page_set)
Bruce Allana4f58f52009-06-02 11:29:18 +00002788{
2789 s32 ret_val;
2790 u16 page = BM_PHY_REG_PAGE(offset);
2791 u16 reg = BM_PHY_REG_NUM(offset);
Bruce Allan2b6b1682011-05-13 07:20:09 +00002792 u32 phy_addr = hw->phy.addr = e1000_get_phy_addr_for_hv_page(page);
Bruce Allana4f58f52009-06-02 11:29:18 +00002793
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002794 if (!locked) {
Bruce Allan94d81862009-11-20 23:25:26 +00002795 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002796 if (ret_val)
2797 return ret_val;
2798 }
2799
Bruce Allana4f58f52009-06-02 11:29:18 +00002800 /* Page 800 works differently than the rest so it has its own func */
2801 if (page == BM_WUC_PAGE) {
Bruce Allan2b6b1682011-05-13 07:20:09 +00002802 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, data,
2803 true, page_set);
Bruce Allana4f58f52009-06-02 11:29:18 +00002804 goto out;
2805 }
2806
2807 if (page > 0 && page < HV_INTC_FC_PAGE_START) {
2808 ret_val = e1000_access_phy_debug_regs_hv(hw, offset,
2809 data, true);
2810 goto out;
2811 }
2812
Bruce Allan2b6b1682011-05-13 07:20:09 +00002813 if (!page_set) {
2814 if (page == HV_INTC_FC_PAGE_START)
2815 page = 0;
Bruce Allana4f58f52009-06-02 11:29:18 +00002816
Bruce Allan2b6b1682011-05-13 07:20:09 +00002817 if (reg > MAX_PHY_MULTI_PAGE_REG) {
2818 /* Page is shifted left, PHY expects (page x 32) */
2819 ret_val = e1000_set_page_igp(hw,
2820 (page << IGP_PAGE_SHIFT));
Bruce Allana4f58f52009-06-02 11:29:18 +00002821
Bruce Allan2b6b1682011-05-13 07:20:09 +00002822 hw->phy.addr = phy_addr;
Bruce Allana4f58f52009-06-02 11:29:18 +00002823
Bruce Allan2b6b1682011-05-13 07:20:09 +00002824 if (ret_val)
2825 goto out;
2826 }
Bruce Allana4f58f52009-06-02 11:29:18 +00002827 }
2828
Bruce Allan2b6b1682011-05-13 07:20:09 +00002829 e_dbg("reading PHY page %d (or 0x%x shifted) reg 0x%x\n", page,
2830 page << IGP_PAGE_SHIFT, reg);
2831
Bruce Allana4f58f52009-06-02 11:29:18 +00002832 ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & reg,
2833 data);
Bruce Allana4f58f52009-06-02 11:29:18 +00002834out:
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002835 if (!locked)
Bruce Allan94d81862009-11-20 23:25:26 +00002836 hw->phy.ops.release(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002837
Bruce Allana4f58f52009-06-02 11:29:18 +00002838 return ret_val;
2839}
2840
2841/**
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002842 * e1000_read_phy_reg_hv - Read HV PHY register
2843 * @hw: pointer to the HW structure
2844 * @offset: register offset to be read
2845 * @data: pointer to the read data
2846 *
2847 * Acquires semaphore then reads the PHY register at offset and stores
2848 * the retrieved information in data. Release the acquired semaphore
2849 * before exiting.
2850 **/
2851s32 e1000_read_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 *data)
2852{
Bruce Allan2b6b1682011-05-13 07:20:09 +00002853 return __e1000_read_phy_reg_hv(hw, offset, data, false, false);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002854}
2855
2856/**
2857 * e1000_read_phy_reg_hv_locked - Read HV PHY register
2858 * @hw: pointer to the HW structure
2859 * @offset: register offset to be read
2860 * @data: pointer to the read data
2861 *
2862 * Reads the PHY register at offset and stores the retrieved information
2863 * in data. Assumes semaphore already acquired.
2864 **/
2865s32 e1000_read_phy_reg_hv_locked(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, true, false);
2868}
2869
2870/**
2871 * e1000_read_phy_reg_page_hv - Read HV PHY register
2872 * @hw: pointer to the HW structure
2873 * @offset: register offset to write to
2874 * @data: data to write at register offset
2875 *
2876 * Reads the PHY register at offset and stores the retrieved information
2877 * in data. Assumes semaphore already acquired and page already set.
2878 **/
2879s32 e1000_read_phy_reg_page_hv(struct e1000_hw *hw, u32 offset, u16 *data)
2880{
2881 return __e1000_read_phy_reg_hv(hw, offset, data, true, true);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002882}
2883
2884/**
2885 * __e1000_write_phy_reg_hv - Write HV PHY register
Bruce Allana4f58f52009-06-02 11:29:18 +00002886 * @hw: pointer to the HW structure
2887 * @offset: register offset to write to
2888 * @data: data to write at register offset
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002889 * @locked: semaphore has already been acquired or not
Bruce Allana4f58f52009-06-02 11:29:18 +00002890 *
2891 * Acquires semaphore, if necessary, then writes the data to PHY register
2892 * at the offset. Release any acquired semaphores before exiting.
2893 **/
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002894static s32 __e1000_write_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 data,
Bruce Allan2b6b1682011-05-13 07:20:09 +00002895 bool locked, bool page_set)
Bruce Allana4f58f52009-06-02 11:29:18 +00002896{
2897 s32 ret_val;
2898 u16 page = BM_PHY_REG_PAGE(offset);
2899 u16 reg = BM_PHY_REG_NUM(offset);
Bruce Allan2b6b1682011-05-13 07:20:09 +00002900 u32 phy_addr = hw->phy.addr = e1000_get_phy_addr_for_hv_page(page);
Bruce Allana4f58f52009-06-02 11:29:18 +00002901
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002902 if (!locked) {
Bruce Allan94d81862009-11-20 23:25:26 +00002903 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002904 if (ret_val)
2905 return ret_val;
2906 }
2907
Bruce Allana4f58f52009-06-02 11:29:18 +00002908 /* Page 800 works differently than the rest so it has its own func */
2909 if (page == BM_WUC_PAGE) {
Bruce Allan2b6b1682011-05-13 07:20:09 +00002910 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, &data,
2911 false, page_set);
Bruce Allana4f58f52009-06-02 11:29:18 +00002912 goto out;
2913 }
2914
2915 if (page > 0 && page < HV_INTC_FC_PAGE_START) {
2916 ret_val = e1000_access_phy_debug_regs_hv(hw, offset,
2917 &data, false);
2918 goto out;
2919 }
2920
Bruce Allan2b6b1682011-05-13 07:20:09 +00002921 if (!page_set) {
2922 if (page == HV_INTC_FC_PAGE_START)
2923 page = 0;
Bruce Allana4f58f52009-06-02 11:29:18 +00002924
Bruce Allane921eb12012-11-28 09:28:37 +00002925 /* Workaround MDIO accesses being disabled after entering IEEE
Bruce Allan2b6b1682011-05-13 07:20:09 +00002926 * Power Down (when bit 11 of the PHY Control register is set)
2927 */
2928 if ((hw->phy.type == e1000_phy_82578) &&
2929 (hw->phy.revision >= 1) &&
2930 (hw->phy.addr == 2) &&
Bruce Allan04499ec2012-04-13 00:08:31 +00002931 !(MAX_PHY_REG_ADDRESS & reg) && (data & (1 << 11))) {
Bruce Allan2b6b1682011-05-13 07:20:09 +00002932 u16 data2 = 0x7EFF;
2933 ret_val = e1000_access_phy_debug_regs_hv(hw,
2934 (1 << 6) | 0x3,
2935 &data2, false);
2936 if (ret_val)
2937 goto out;
2938 }
Bruce Allana4f58f52009-06-02 11:29:18 +00002939
Bruce Allan2b6b1682011-05-13 07:20:09 +00002940 if (reg > MAX_PHY_MULTI_PAGE_REG) {
2941 /* Page is shifted left, PHY expects (page x 32) */
2942 ret_val = e1000_set_page_igp(hw,
2943 (page << IGP_PAGE_SHIFT));
2944
2945 hw->phy.addr = phy_addr;
2946
2947 if (ret_val)
2948 goto out;
2949 }
Bruce Allana4f58f52009-06-02 11:29:18 +00002950 }
2951
Bruce Allan2b6b1682011-05-13 07:20:09 +00002952 e_dbg("writing PHY page %d (or 0x%x shifted) reg 0x%x\n", page,
2953 page << IGP_PAGE_SHIFT, reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00002954
2955 ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & reg,
2956 data);
Bruce Allana4f58f52009-06-02 11:29:18 +00002957
2958out:
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002959 if (!locked)
Bruce Allan94d81862009-11-20 23:25:26 +00002960 hw->phy.ops.release(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002961
Bruce Allana4f58f52009-06-02 11:29:18 +00002962 return ret_val;
2963}
2964
2965/**
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002966 * e1000_write_phy_reg_hv - Write HV PHY register
2967 * @hw: pointer to the HW structure
2968 * @offset: register offset to write to
2969 * @data: data to write at register offset
2970 *
2971 * Acquires semaphore then writes the data to PHY register at the offset.
2972 * Release the acquired semaphores before exiting.
2973 **/
2974s32 e1000_write_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 data)
2975{
Bruce Allan2b6b1682011-05-13 07:20:09 +00002976 return __e1000_write_phy_reg_hv(hw, offset, data, false, false);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002977}
2978
2979/**
2980 * e1000_write_phy_reg_hv_locked - 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 * Writes the data to PHY register at the offset. Assumes semaphore
2986 * already acquired.
2987 **/
2988s32 e1000_write_phy_reg_hv_locked(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, true, false);
2991}
2992
2993/**
2994 * e1000_write_phy_reg_page_hv - 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 and page already set.
3001 **/
3002s32 e1000_write_phy_reg_page_hv(struct e1000_hw *hw, u32 offset, u16 data)
3003{
3004 return __e1000_write_phy_reg_hv(hw, offset, data, true, true);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00003005}
3006
3007/**
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04003008 * e1000_get_phy_addr_for_hv_page - Get PHY address based on page
Bruce Allana4f58f52009-06-02 11:29:18 +00003009 * @page: page to be accessed
3010 **/
3011static u32 e1000_get_phy_addr_for_hv_page(u32 page)
3012{
3013 u32 phy_addr = 2;
3014
3015 if (page >= HV_INTC_FC_PAGE_START)
3016 phy_addr = 1;
3017
3018 return phy_addr;
3019}
3020
3021/**
3022 * e1000_access_phy_debug_regs_hv - Read HV PHY vendor specific high registers
3023 * @hw: pointer to the HW structure
3024 * @offset: register offset to be read or written
3025 * @data: pointer to the data to be read or written
Bruce Allan2b6b1682011-05-13 07:20:09 +00003026 * @read: determines if operation is read or write
Bruce Allana4f58f52009-06-02 11:29:18 +00003027 *
Bruce Allan5ccdcec2009-10-26 11:24:02 +00003028 * Reads the PHY register at offset and stores the retreived information
3029 * in data. Assumes semaphore already acquired. Note that the procedure
Bruce Allan2b6b1682011-05-13 07:20:09 +00003030 * to access these regs uses the address port and data port to read/write.
3031 * These accesses done with PHY address 2 and without using pages.
Bruce Allana4f58f52009-06-02 11:29:18 +00003032 **/
3033static s32 e1000_access_phy_debug_regs_hv(struct e1000_hw *hw, u32 offset,
3034 u16 *data, bool read)
3035{
3036 s32 ret_val;
Bruce Allan70806a72013-01-05 05:08:37 +00003037 u32 addr_reg;
3038 u32 data_reg;
Bruce Allana4f58f52009-06-02 11:29:18 +00003039
3040 /* This takes care of the difference with desktop vs mobile phy */
3041 addr_reg = (hw->phy.type == e1000_phy_82578) ?
3042 I82578_ADDR_REG : I82577_ADDR_REG;
3043 data_reg = addr_reg + 1;
3044
Bruce Allana4f58f52009-06-02 11:29:18 +00003045 /* All operations in this function are phy address 2 */
3046 hw->phy.addr = 2;
3047
3048 /* masking with 0x3F to remove the page from offset */
3049 ret_val = e1000e_write_phy_reg_mdic(hw, addr_reg, (u16)offset & 0x3F);
3050 if (ret_val) {
Bruce Allan2b6b1682011-05-13 07:20:09 +00003051 e_dbg("Could not write the Address Offset port register\n");
Bruce Allan5015e532012-02-08 02:55:56 +00003052 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003053 }
3054
3055 /* Read or write the data value next */
3056 if (read)
3057 ret_val = e1000e_read_phy_reg_mdic(hw, data_reg, data);
3058 else
3059 ret_val = e1000e_write_phy_reg_mdic(hw, data_reg, *data);
3060
Bruce Allan5015e532012-02-08 02:55:56 +00003061 if (ret_val)
Bruce Allan2b6b1682011-05-13 07:20:09 +00003062 e_dbg("Could not access the Data port register\n");
Bruce Allana4f58f52009-06-02 11:29:18 +00003063
Bruce Allana4f58f52009-06-02 11:29:18 +00003064 return ret_val;
3065}
3066
3067/**
3068 * e1000_link_stall_workaround_hv - Si workaround
3069 * @hw: pointer to the HW structure
3070 *
3071 * This function works around a Si bug where the link partner can get
3072 * a link up indication before the PHY does. If small packets are sent
3073 * by the link partner they can be placed in the packet buffer without
3074 * being properly accounted for by the PHY and will stall preventing
3075 * further packets from being received. The workaround is to clear the
3076 * packet buffer after the PHY detects link up.
3077 **/
3078s32 e1000_link_stall_workaround_hv(struct e1000_hw *hw)
3079{
3080 s32 ret_val = 0;
3081 u16 data;
3082
3083 if (hw->phy.type != e1000_phy_82578)
Bruce Allan5015e532012-02-08 02:55:56 +00003084 return 0;
Bruce Allana4f58f52009-06-02 11:29:18 +00003085
Bruce Allane65fa872009-07-01 13:27:31 +00003086 /* Do not apply workaround if in PHY loopback bit 14 set */
Bruce Allanc2ade1a2013-01-16 08:54:35 +00003087 e1e_rphy(hw, MII_BMCR, &data);
3088 if (data & BMCR_LOOPBACK)
Bruce Allan5015e532012-02-08 02:55:56 +00003089 return 0;
Bruce Allane65fa872009-07-01 13:27:31 +00003090
Bruce Allana4f58f52009-06-02 11:29:18 +00003091 /* check if link is up and at 1Gbps */
Bruce Allan482fed82011-01-06 14:29:49 +00003092 ret_val = e1e_rphy(hw, BM_CS_STATUS, &data);
Bruce Allana4f58f52009-06-02 11:29:18 +00003093 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003094 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003095
Bruce Allan3d3a1672012-02-23 03:13:18 +00003096 data &= BM_CS_STATUS_LINK_UP | BM_CS_STATUS_RESOLVED |
3097 BM_CS_STATUS_SPEED_MASK;
Bruce Allana4f58f52009-06-02 11:29:18 +00003098
Bruce Allan3d3a1672012-02-23 03:13:18 +00003099 if (data != (BM_CS_STATUS_LINK_UP | BM_CS_STATUS_RESOLVED |
3100 BM_CS_STATUS_SPEED_1000))
Bruce Allan5015e532012-02-08 02:55:56 +00003101 return 0;
Bruce Allana4f58f52009-06-02 11:29:18 +00003102
Bruce Allanbb9c5ee2012-02-23 03:31:29 +00003103 msleep(200);
Bruce Allana4f58f52009-06-02 11:29:18 +00003104
3105 /* flush the packets in the fifo buffer */
Bruce Allanc063f602013-01-12 07:27:53 +00003106 ret_val = e1e_wphy(hw, HV_MUX_DATA_CTRL,
3107 (HV_MUX_DATA_CTRL_GEN_TO_MAC |
3108 HV_MUX_DATA_CTRL_FORCE_SPEED));
Bruce Allana4f58f52009-06-02 11:29:18 +00003109 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003110 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003111
Bruce Allan5015e532012-02-08 02:55:56 +00003112 return e1e_wphy(hw, HV_MUX_DATA_CTRL, HV_MUX_DATA_CTRL_GEN_TO_MAC);
Bruce Allana4f58f52009-06-02 11:29:18 +00003113}
3114
3115/**
3116 * e1000_check_polarity_82577 - Checks the polarity.
3117 * @hw: pointer to the HW structure
3118 *
3119 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
3120 *
3121 * Polarity is determined based on the PHY specific status register.
3122 **/
3123s32 e1000_check_polarity_82577(struct e1000_hw *hw)
3124{
3125 struct e1000_phy_info *phy = &hw->phy;
3126 s32 ret_val;
3127 u16 data;
3128
Bruce Allan482fed82011-01-06 14:29:49 +00003129 ret_val = e1e_rphy(hw, I82577_PHY_STATUS_2, &data);
Bruce Allana4f58f52009-06-02 11:29:18 +00003130
3131 if (!ret_val)
3132 phy->cable_polarity = (data & I82577_PHY_STATUS2_REV_POLARITY)
3133 ? e1000_rev_polarity_reversed
3134 : e1000_rev_polarity_normal;
3135
3136 return ret_val;
3137}
3138
3139/**
3140 * e1000_phy_force_speed_duplex_82577 - Force speed/duplex for I82577 PHY
3141 * @hw: pointer to the HW structure
3142 *
Bruce Allaneab50ff2010-05-10 15:01:30 +00003143 * Calls the PHY setup function to force speed and duplex.
Bruce Allana4f58f52009-06-02 11:29:18 +00003144 **/
3145s32 e1000_phy_force_speed_duplex_82577(struct e1000_hw *hw)
3146{
3147 struct e1000_phy_info *phy = &hw->phy;
3148 s32 ret_val;
3149 u16 phy_data;
3150 bool link;
3151
Bruce Allanc2ade1a2013-01-16 08:54:35 +00003152 ret_val = e1e_rphy(hw, MII_BMCR, &phy_data);
Bruce Allana4f58f52009-06-02 11:29:18 +00003153 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003154 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003155
3156 e1000e_phy_force_speed_duplex_setup(hw, &phy_data);
3157
Bruce Allanc2ade1a2013-01-16 08:54:35 +00003158 ret_val = e1e_wphy(hw, MII_BMCR, phy_data);
Bruce Allana4f58f52009-06-02 11:29:18 +00003159 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003160 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003161
Bruce Allana4f58f52009-06-02 11:29:18 +00003162 udelay(1);
3163
3164 if (phy->autoneg_wait_to_complete) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003165 e_dbg("Waiting for forced speed/duplex link on 82577 phy\n");
Bruce Allana4f58f52009-06-02 11:29:18 +00003166
Bruce Allan3d3a1672012-02-23 03:13:18 +00003167 ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
3168 100000, &link);
Bruce Allana4f58f52009-06-02 11:29:18 +00003169 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003170 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003171
3172 if (!link)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003173 e_dbg("Link taking longer than expected.\n");
Bruce Allana4f58f52009-06-02 11:29:18 +00003174
3175 /* Try once more */
Bruce Allan3d3a1672012-02-23 03:13:18 +00003176 ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
3177 100000, &link);
Bruce Allana4f58f52009-06-02 11:29:18 +00003178 }
3179
Bruce Allana4f58f52009-06-02 11:29:18 +00003180 return ret_val;
3181}
3182
3183/**
3184 * e1000_get_phy_info_82577 - Retrieve I82577 PHY information
3185 * @hw: pointer to the HW structure
3186 *
3187 * Read PHY status to determine if link is up. If link is up, then
3188 * set/determine 10base-T extended distance and polarity correction. Read
3189 * PHY port status to determine MDI/MDIx and speed. Based on the speed,
3190 * determine on the cable length, local and remote receiver.
3191 **/
3192s32 e1000_get_phy_info_82577(struct e1000_hw *hw)
3193{
3194 struct e1000_phy_info *phy = &hw->phy;
3195 s32 ret_val;
3196 u16 data;
3197 bool link;
3198
3199 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
3200 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003201 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003202
3203 if (!link) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003204 e_dbg("Phy info is only valid if link is up\n");
Bruce Allan5015e532012-02-08 02:55:56 +00003205 return -E1000_ERR_CONFIG;
Bruce Allana4f58f52009-06-02 11:29:18 +00003206 }
3207
3208 phy->polarity_correction = true;
3209
3210 ret_val = e1000_check_polarity_82577(hw);
3211 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003212 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003213
Bruce Allan482fed82011-01-06 14:29:49 +00003214 ret_val = e1e_rphy(hw, I82577_PHY_STATUS_2, &data);
Bruce Allana4f58f52009-06-02 11:29:18 +00003215 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003216 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003217
Bruce Allan04499ec2012-04-13 00:08:31 +00003218 phy->is_mdix = !!(data & I82577_PHY_STATUS2_MDIX);
Bruce Allana4f58f52009-06-02 11:29:18 +00003219
3220 if ((data & I82577_PHY_STATUS2_SPEED_MASK) ==
3221 I82577_PHY_STATUS2_SPEED_1000MBPS) {
3222 ret_val = hw->phy.ops.get_cable_length(hw);
3223 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003224 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003225
Bruce Allanc2ade1a2013-01-16 08:54:35 +00003226 ret_val = e1e_rphy(hw, MII_STAT1000, &data);
Bruce Allana4f58f52009-06-02 11:29:18 +00003227 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003228 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003229
Bruce Allanc2ade1a2013-01-16 08:54:35 +00003230 phy->local_rx = (data & LPA_1000LOCALRXOK)
3231 ? e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
Bruce Allana4f58f52009-06-02 11:29:18 +00003232
Bruce Allanc2ade1a2013-01-16 08:54:35 +00003233 phy->remote_rx = (data & LPA_1000REMRXOK)
3234 ? e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
Bruce Allana4f58f52009-06-02 11:29:18 +00003235 } else {
3236 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
3237 phy->local_rx = e1000_1000t_rx_status_undefined;
3238 phy->remote_rx = e1000_1000t_rx_status_undefined;
3239 }
3240
Bruce Allan5015e532012-02-08 02:55:56 +00003241 return 0;
Bruce Allana4f58f52009-06-02 11:29:18 +00003242}
3243
3244/**
3245 * e1000_get_cable_length_82577 - Determine cable length for 82577 PHY
3246 * @hw: pointer to the HW structure
3247 *
3248 * Reads the diagnostic status register and verifies result is valid before
3249 * placing it in the phy_cable_length field.
3250 **/
3251s32 e1000_get_cable_length_82577(struct e1000_hw *hw)
3252{
3253 struct e1000_phy_info *phy = &hw->phy;
3254 s32 ret_val;
3255 u16 phy_data, length;
3256
Bruce Allan482fed82011-01-06 14:29:49 +00003257 ret_val = e1e_rphy(hw, I82577_PHY_DIAG_STATUS, &phy_data);
Bruce Allana4f58f52009-06-02 11:29:18 +00003258 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003259 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003260
3261 length = (phy_data & I82577_DSTATUS_CABLE_LENGTH) >>
3262 I82577_DSTATUS_CABLE_LENGTH_SHIFT;
3263
3264 if (length == E1000_CABLE_LENGTH_UNDEFINED)
Bruce Allan7dbbe5d2013-01-05 05:08:31 +00003265 return -E1000_ERR_PHY;
Bruce Allana4f58f52009-06-02 11:29:18 +00003266
3267 phy->cable_length = length;
3268
Bruce Allan5015e532012-02-08 02:55:56 +00003269 return 0;
Bruce Allana4f58f52009-06-02 11:29:18 +00003270}