blob: 6f32811dbcf0a1c2fd6adb76b111ea710a39a149 [file] [log] [blame]
Auke Kokbc7f75f2007-09-17 12:30:59 -07001/*******************************************************************************
2
3 Intel PRO/1000 Linux driver
Bruce Allanbf670442013-01-01 16:00:01 +00004 Copyright(c) 1999 - 2013 Intel Corporation.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
14
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Contact Information:
23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26
27*******************************************************************************/
28
Auke Kokbc7f75f2007-09-17 12:30:59 -070029#include "e1000.h"
30
Auke Kokbc7f75f2007-09-17 12:30:59 -070031static s32 e1000_wait_autoneg(struct e1000_hw *hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -070032static s32 e1000_access_phy_wakeup_reg_bm(struct e1000_hw *hw, u32 offset,
Bruce Allan2b6b1682011-05-13 07:20:09 +000033 u16 *data, bool read, bool page_set);
Bruce Allana4f58f52009-06-02 11:29:18 +000034static u32 e1000_get_phy_addr_for_hv_page(u32 page);
35static s32 e1000_access_phy_debug_regs_hv(struct e1000_hw *hw, u32 offset,
Bruce Allan1f96012d2013-01-05 03:06:54 +000036 u16 *data, bool read);
Auke Kokbc7f75f2007-09-17 12:30:59 -070037
38/* Cable length tables */
Bruce Allan64806412010-12-11 05:53:42 +000039static const u16 e1000_m88_cable_length_table[] = {
40 0, 50, 80, 110, 140, 140, E1000_CABLE_LENGTH_UNDEFINED };
Bruce Allaneb656d42009-12-01 15:47:02 +000041#define M88E1000_CABLE_LENGTH_TABLE_SIZE \
42 ARRAY_SIZE(e1000_m88_cable_length_table)
Auke Kokbc7f75f2007-09-17 12:30:59 -070043
Bruce Allan64806412010-12-11 05:53:42 +000044static const u16 e1000_igp_2_cable_length_table[] = {
45 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21, 0, 0, 0, 3,
46 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41, 6, 10, 14, 18, 22,
47 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61, 21, 26, 31, 35, 40,
48 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82, 40, 45, 51, 56, 61,
49 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104, 60, 66, 72, 77, 82,
50 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121, 83, 89, 95,
51 100, 105, 109, 113, 116, 119, 122, 124, 104, 109, 114, 118, 121,
52 124};
Auke Kokbc7f75f2007-09-17 12:30:59 -070053#define IGP02E1000_CABLE_LENGTH_TABLE_SIZE \
Alejandro Martinez Ruizc00acf42007-10-18 10:16:33 +020054 ARRAY_SIZE(e1000_igp_2_cable_length_table)
Auke Kokbc7f75f2007-09-17 12:30:59 -070055
Bruce Allana4f58f52009-06-02 11:29:18 +000056#define BM_PHY_REG_PAGE(offset) \
57 ((u16)(((offset) >> PHY_PAGE_SHIFT) & 0xFFFF))
58#define BM_PHY_REG_NUM(offset) \
59 ((u16)(((offset) & MAX_PHY_REG_ADDRESS) |\
60 (((offset) >> (PHY_UPPER_SHIFT - PHY_PAGE_SHIFT)) &\
61 ~MAX_PHY_REG_ADDRESS)))
62
63#define HV_INTC_FC_PAGE_START 768
64#define I82578_ADDR_REG 29
65#define I82577_ADDR_REG 16
66#define I82577_CFG_REG 22
67#define I82577_CFG_ASSERT_CRS_ON_TX (1 << 15)
68#define I82577_CFG_ENABLE_DOWNSHIFT (3 << 10) /* auto downshift 100/10 */
69#define I82577_CTRL_REG 23
Bruce Allana4f58f52009-06-02 11:29:18 +000070
71/* 82577 specific PHY registers */
72#define I82577_PHY_CTRL_2 18
73#define I82577_PHY_STATUS_2 26
74#define I82577_PHY_DIAG_STATUS 31
75
76/* I82577 PHY Status 2 */
77#define I82577_PHY_STATUS2_REV_POLARITY 0x0400
78#define I82577_PHY_STATUS2_MDIX 0x0800
79#define I82577_PHY_STATUS2_SPEED_MASK 0x0300
80#define I82577_PHY_STATUS2_SPEED_1000MBPS 0x0200
81
82/* I82577 PHY Control 2 */
Bruce W Allane86fd892012-07-26 02:30:59 +000083#define I82577_PHY_CTRL2_MANUAL_MDIX 0x0200
84#define I82577_PHY_CTRL2_AUTO_MDI_MDIX 0x0400
85#define I82577_PHY_CTRL2_MDIX_CFG_MASK 0x0600
Bruce Allana4f58f52009-06-02 11:29:18 +000086
87/* I82577 PHY Diagnostics Status */
88#define I82577_DSTATUS_CABLE_LENGTH 0x03FC
89#define I82577_DSTATUS_CABLE_LENGTH_SHIFT 2
90
91/* BM PHY Copper Specific Control 1 */
92#define BM_CS_CTRL1 16
93
Bruce Allana4f58f52009-06-02 11:29:18 +000094#define HV_MUX_DATA_CTRL PHY_REG(776, 16)
95#define HV_MUX_DATA_CTRL_GEN_TO_MAC 0x0400
96#define HV_MUX_DATA_CTRL_FORCE_SPEED 0x0004
97
Auke Kokbc7f75f2007-09-17 12:30:59 -070098/**
99 * e1000e_check_reset_block_generic - Check if PHY reset is blocked
100 * @hw: pointer to the HW structure
101 *
102 * Read the PHY management control register and check whether a PHY reset
103 * is blocked. If a reset is not blocked return 0, otherwise
104 * return E1000_BLK_PHY_RESET (12).
105 **/
106s32 e1000e_check_reset_block_generic(struct e1000_hw *hw)
107{
108 u32 manc;
109
110 manc = er32(MANC);
111
112 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
113 E1000_BLK_PHY_RESET : 0;
114}
115
116/**
117 * e1000e_get_phy_id - Retrieve the PHY ID and revision
118 * @hw: pointer to the HW structure
119 *
120 * Reads the PHY registers and stores the PHY ID and possibly the PHY
121 * revision in the hardware structure.
122 **/
123s32 e1000e_get_phy_id(struct e1000_hw *hw)
124{
125 struct e1000_phy_info *phy = &hw->phy;
Bruce Allana4f58f52009-06-02 11:29:18 +0000126 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700127 u16 phy_id;
Bruce Allana4f58f52009-06-02 11:29:18 +0000128 u16 retry_count = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700129
Bruce Allan668018d2012-01-31 07:02:56 +0000130 if (!phy->ops.read_reg)
Bruce Allan5015e532012-02-08 02:55:56 +0000131 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700132
Bruce Allana4f58f52009-06-02 11:29:18 +0000133 while (retry_count < 2) {
134 ret_val = e1e_rphy(hw, PHY_ID1, &phy_id);
135 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000136 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700137
Bruce Allana4f58f52009-06-02 11:29:18 +0000138 phy->id = (u32)(phy_id << 16);
139 udelay(20);
140 ret_val = e1e_rphy(hw, PHY_ID2, &phy_id);
141 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000142 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700143
Bruce Allana4f58f52009-06-02 11:29:18 +0000144 phy->id |= (u32)(phy_id & PHY_REVISION_MASK);
145 phy->revision = (u32)(phy_id & ~PHY_REVISION_MASK);
146
147 if (phy->id != 0 && phy->id != PHY_REVISION_MASK)
Bruce Allan5015e532012-02-08 02:55:56 +0000148 return 0;
Bruce Allana4f58f52009-06-02 11:29:18 +0000149
Bruce Allana4f58f52009-06-02 11:29:18 +0000150 retry_count++;
151 }
Bruce Allan5015e532012-02-08 02:55:56 +0000152
153 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700154}
155
156/**
157 * e1000e_phy_reset_dsp - Reset PHY DSP
158 * @hw: pointer to the HW structure
159 *
160 * Reset the digital signal processor.
161 **/
162s32 e1000e_phy_reset_dsp(struct e1000_hw *hw)
163{
164 s32 ret_val;
165
166 ret_val = e1e_wphy(hw, M88E1000_PHY_GEN_CONTROL, 0xC1);
167 if (ret_val)
168 return ret_val;
169
170 return e1e_wphy(hw, M88E1000_PHY_GEN_CONTROL, 0);
171}
172
173/**
David Graham2d9498f2008-04-23 11:09:14 -0700174 * e1000e_read_phy_reg_mdic - Read MDI control register
Auke Kokbc7f75f2007-09-17 12:30:59 -0700175 * @hw: pointer to the HW structure
176 * @offset: register offset to be read
177 * @data: pointer to the read data
178 *
Auke Kok489815c2008-02-21 15:11:07 -0800179 * Reads the MDI control register in the PHY at offset and stores the
Auke Kokbc7f75f2007-09-17 12:30:59 -0700180 * information read to data.
181 **/
David Graham2d9498f2008-04-23 11:09:14 -0700182s32 e1000e_read_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 *data)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700183{
184 struct e1000_phy_info *phy = &hw->phy;
185 u32 i, mdic = 0;
186
187 if (offset > MAX_PHY_REG_ADDRESS) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000188 e_dbg("PHY Address %d is out of range\n", offset);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700189 return -E1000_ERR_PARAM;
190 }
191
Bruce Allane921eb12012-11-28 09:28:37 +0000192 /* Set up Op-code, Phy Address, and register offset in the MDI
Auke Kokbc7f75f2007-09-17 12:30:59 -0700193 * Control register. The MAC will take care of interfacing with the
194 * PHY to retrieve the desired data.
195 */
196 mdic = ((offset << E1000_MDIC_REG_SHIFT) |
197 (phy->addr << E1000_MDIC_PHY_SHIFT) |
198 (E1000_MDIC_OP_READ));
199
200 ew32(MDIC, mdic);
201
Bruce Allane921eb12012-11-28 09:28:37 +0000202 /* Poll the ready bit to see if the MDI read completed
Bruce Allanad680762008-03-28 09:15:03 -0700203 * Increasing the time out as testing showed failures with
204 * the lower time out
205 */
David Graham2d9498f2008-04-23 11:09:14 -0700206 for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700207 udelay(50);
208 mdic = er32(MDIC);
209 if (mdic & E1000_MDIC_READY)
210 break;
211 }
212 if (!(mdic & E1000_MDIC_READY)) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000213 e_dbg("MDI Read did not complete\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700214 return -E1000_ERR_PHY;
215 }
216 if (mdic & E1000_MDIC_ERROR) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000217 e_dbg("MDI Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700218 return -E1000_ERR_PHY;
219 }
220 *data = (u16) mdic;
221
Bruce Allane921eb12012-11-28 09:28:37 +0000222 /* Allow some time after each MDIC transaction to avoid
Bruce Allan664dc872010-11-24 06:01:46 +0000223 * reading duplicate data in the next MDIC transaction.
224 */
225 if (hw->mac.type == e1000_pch2lan)
226 udelay(100);
227
Auke Kokbc7f75f2007-09-17 12:30:59 -0700228 return 0;
229}
230
231/**
David Graham2d9498f2008-04-23 11:09:14 -0700232 * e1000e_write_phy_reg_mdic - Write MDI control register
Auke Kokbc7f75f2007-09-17 12:30:59 -0700233 * @hw: pointer to the HW structure
234 * @offset: register offset to write to
235 * @data: data to write to register at offset
236 *
237 * Writes data to MDI control register in the PHY at offset.
238 **/
David Graham2d9498f2008-04-23 11:09:14 -0700239s32 e1000e_write_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 data)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700240{
241 struct e1000_phy_info *phy = &hw->phy;
242 u32 i, mdic = 0;
243
244 if (offset > MAX_PHY_REG_ADDRESS) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000245 e_dbg("PHY Address %d is out of range\n", offset);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700246 return -E1000_ERR_PARAM;
247 }
248
Bruce Allane921eb12012-11-28 09:28:37 +0000249 /* Set up Op-code, Phy Address, and register offset in the MDI
Auke Kokbc7f75f2007-09-17 12:30:59 -0700250 * Control register. The MAC will take care of interfacing with the
251 * PHY to retrieve the desired data.
252 */
253 mdic = (((u32)data) |
254 (offset << E1000_MDIC_REG_SHIFT) |
255 (phy->addr << E1000_MDIC_PHY_SHIFT) |
256 (E1000_MDIC_OP_WRITE));
257
258 ew32(MDIC, mdic);
259
Bruce Allane921eb12012-11-28 09:28:37 +0000260 /* Poll the ready bit to see if the MDI read completed
David Graham2d9498f2008-04-23 11:09:14 -0700261 * Increasing the time out as testing showed failures with
262 * the lower time out
263 */
264 for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
265 udelay(50);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700266 mdic = er32(MDIC);
267 if (mdic & E1000_MDIC_READY)
268 break;
269 }
270 if (!(mdic & E1000_MDIC_READY)) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000271 e_dbg("MDI Write did not complete\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700272 return -E1000_ERR_PHY;
273 }
David Graham2d9498f2008-04-23 11:09:14 -0700274 if (mdic & E1000_MDIC_ERROR) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000275 e_dbg("MDI Error\n");
David Graham2d9498f2008-04-23 11:09:14 -0700276 return -E1000_ERR_PHY;
277 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700278
Bruce Allane921eb12012-11-28 09:28:37 +0000279 /* Allow some time after each MDIC transaction to avoid
Bruce Allan664dc872010-11-24 06:01:46 +0000280 * reading duplicate data in the next MDIC transaction.
281 */
282 if (hw->mac.type == e1000_pch2lan)
283 udelay(100);
284
Auke Kokbc7f75f2007-09-17 12:30:59 -0700285 return 0;
286}
287
288/**
289 * e1000e_read_phy_reg_m88 - Read m88 PHY register
290 * @hw: pointer to the HW structure
291 * @offset: register offset to be read
292 * @data: pointer to the read data
293 *
294 * Acquires semaphore, if necessary, then reads the PHY register at offset
295 * and storing the retrieved information in data. Release any acquired
296 * semaphores before exiting.
297 **/
298s32 e1000e_read_phy_reg_m88(struct e1000_hw *hw, u32 offset, u16 *data)
299{
300 s32 ret_val;
301
Bruce Allan94d81862009-11-20 23:25:26 +0000302 ret_val = hw->phy.ops.acquire(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700303 if (ret_val)
304 return ret_val;
305
David Graham2d9498f2008-04-23 11:09:14 -0700306 ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
307 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700308
Bruce Allan94d81862009-11-20 23:25:26 +0000309 hw->phy.ops.release(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700310
311 return ret_val;
312}
313
314/**
315 * e1000e_write_phy_reg_m88 - Write m88 PHY register
316 * @hw: pointer to the HW structure
317 * @offset: register offset to write to
318 * @data: data to write at register offset
319 *
320 * Acquires semaphore, if necessary, then writes the data to PHY register
321 * at the offset. Release any acquired semaphores before exiting.
322 **/
323s32 e1000e_write_phy_reg_m88(struct e1000_hw *hw, u32 offset, u16 data)
324{
325 s32 ret_val;
326
Bruce Allan94d81862009-11-20 23:25:26 +0000327 ret_val = hw->phy.ops.acquire(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700328 if (ret_val)
329 return ret_val;
330
David Graham2d9498f2008-04-23 11:09:14 -0700331 ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
332 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700333
Bruce Allan94d81862009-11-20 23:25:26 +0000334 hw->phy.ops.release(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700335
336 return ret_val;
337}
338
339/**
Bruce Allan2b6b1682011-05-13 07:20:09 +0000340 * e1000_set_page_igp - Set page as on IGP-like PHY(s)
341 * @hw: pointer to the HW structure
342 * @page: page to set (shifted left when necessary)
343 *
344 * Sets PHY page required for PHY register access. Assumes semaphore is
345 * already acquired. Note, this function sets phy.addr to 1 so the caller
346 * must set it appropriately (if necessary) after this function returns.
347 **/
348s32 e1000_set_page_igp(struct e1000_hw *hw, u16 page)
349{
350 e_dbg("Setting page 0x%x\n", page);
351
352 hw->phy.addr = 1;
353
354 return e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT, page);
355}
356
357/**
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000358 * __e1000e_read_phy_reg_igp - Read igp PHY register
Auke Kokbc7f75f2007-09-17 12:30:59 -0700359 * @hw: pointer to the HW structure
360 * @offset: register offset to be read
361 * @data: pointer to the read data
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000362 * @locked: semaphore has already been acquired or not
Auke Kokbc7f75f2007-09-17 12:30:59 -0700363 *
364 * Acquires semaphore, if necessary, then reads the PHY register at offset
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000365 * and stores the retrieved information in data. Release any acquired
Auke Kokbc7f75f2007-09-17 12:30:59 -0700366 * semaphores before exiting.
367 **/
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000368static s32 __e1000e_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data,
369 bool locked)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700370{
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000371 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700372
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000373 if (!locked) {
Bruce Allan668018d2012-01-31 07:02:56 +0000374 if (!hw->phy.ops.acquire)
Bruce Allan5015e532012-02-08 02:55:56 +0000375 return 0;
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000376
Bruce Allan94d81862009-11-20 23:25:26 +0000377 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000378 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000379 return ret_val;
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000380 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700381
Bruce Allan5015e532012-02-08 02:55:56 +0000382 if (offset > MAX_PHY_MULTI_PAGE_REG)
David Graham2d9498f2008-04-23 11:09:14 -0700383 ret_val = e1000e_write_phy_reg_mdic(hw,
384 IGP01E1000_PHY_PAGE_SELECT,
385 (u16)offset);
Bruce Allan5015e532012-02-08 02:55:56 +0000386 if (!ret_val)
387 ret_val = e1000e_read_phy_reg_mdic(hw,
388 MAX_PHY_REG_ADDRESS & offset,
389 data);
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000390 if (!locked)
Bruce Allan94d81862009-11-20 23:25:26 +0000391 hw->phy.ops.release(hw);
Bruce Allan5015e532012-02-08 02:55:56 +0000392
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000393 return ret_val;
394}
Auke Kokbc7f75f2007-09-17 12:30:59 -0700395
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000396/**
397 * e1000e_read_phy_reg_igp - Read igp PHY register
398 * @hw: pointer to the HW structure
399 * @offset: register offset to be read
400 * @data: pointer to the read data
401 *
402 * Acquires semaphore then reads the PHY register at offset and stores the
403 * retrieved information in data.
404 * Release the acquired semaphore before exiting.
405 **/
406s32 e1000e_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data)
407{
408 return __e1000e_read_phy_reg_igp(hw, offset, data, false);
409}
410
411/**
412 * e1000e_read_phy_reg_igp_locked - Read igp PHY register
413 * @hw: pointer to the HW structure
414 * @offset: register offset to be read
415 * @data: pointer to the read data
416 *
417 * Reads the PHY register at offset and stores the retrieved information
418 * in data. Assumes semaphore already acquired.
419 **/
420s32 e1000e_read_phy_reg_igp_locked(struct e1000_hw *hw, u32 offset, u16 *data)
421{
422 return __e1000e_read_phy_reg_igp(hw, offset, data, true);
423}
424
425/**
426 * e1000e_write_phy_reg_igp - Write igp PHY register
427 * @hw: pointer to the HW structure
428 * @offset: register offset to write to
429 * @data: data to write at register offset
430 * @locked: semaphore has already been acquired or not
431 *
432 * Acquires semaphore, if necessary, then writes the data to PHY register
433 * at the offset. Release any acquired semaphores before exiting.
434 **/
435static s32 __e1000e_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data,
436 bool locked)
437{
438 s32 ret_val = 0;
439
440 if (!locked) {
Bruce Allan668018d2012-01-31 07:02:56 +0000441 if (!hw->phy.ops.acquire)
Bruce Allan5015e532012-02-08 02:55:56 +0000442 return 0;
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000443
Bruce Allan94d81862009-11-20 23:25:26 +0000444 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000445 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000446 return ret_val;
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000447 }
448
Bruce Allan5015e532012-02-08 02:55:56 +0000449 if (offset > MAX_PHY_MULTI_PAGE_REG)
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000450 ret_val = e1000e_write_phy_reg_mdic(hw,
451 IGP01E1000_PHY_PAGE_SELECT,
452 (u16)offset);
Bruce Allan5015e532012-02-08 02:55:56 +0000453 if (!ret_val)
454 ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS &
455 offset,
456 data);
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000457 if (!locked)
Bruce Allan94d81862009-11-20 23:25:26 +0000458 hw->phy.ops.release(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000459
Auke Kokbc7f75f2007-09-17 12:30:59 -0700460 return ret_val;
461}
462
463/**
464 * e1000e_write_phy_reg_igp - Write igp PHY register
465 * @hw: pointer to the HW structure
466 * @offset: register offset to write to
467 * @data: data to write at register offset
468 *
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000469 * Acquires semaphore then writes the data to PHY register
Auke Kokbc7f75f2007-09-17 12:30:59 -0700470 * at the offset. Release any acquired semaphores before exiting.
471 **/
472s32 e1000e_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data)
473{
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000474 return __e1000e_write_phy_reg_igp(hw, offset, data, false);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700475}
476
477/**
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000478 * e1000e_write_phy_reg_igp_locked - Write igp PHY register
479 * @hw: pointer to the HW structure
480 * @offset: register offset to write to
481 * @data: data to write at register offset
482 *
483 * Writes the data to PHY register at the offset.
484 * Assumes semaphore already acquired.
485 **/
486s32 e1000e_write_phy_reg_igp_locked(struct e1000_hw *hw, u32 offset, u16 data)
487{
488 return __e1000e_write_phy_reg_igp(hw, offset, data, true);
489}
490
491/**
492 * __e1000_read_kmrn_reg - Read kumeran register
Auke Kokbc7f75f2007-09-17 12:30:59 -0700493 * @hw: pointer to the HW structure
494 * @offset: register offset to be read
495 * @data: pointer to the read data
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000496 * @locked: semaphore has already been acquired or not
Auke Kokbc7f75f2007-09-17 12:30:59 -0700497 *
498 * Acquires semaphore, if necessary. Then reads the PHY register at offset
499 * using the kumeran interface. The information retrieved is stored in data.
500 * Release any acquired semaphores before exiting.
501 **/
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000502static s32 __e1000_read_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 *data,
503 bool locked)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700504{
505 u32 kmrnctrlsta;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700506
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000507 if (!locked) {
Bruce Allan5015e532012-02-08 02:55:56 +0000508 s32 ret_val = 0;
509
Bruce Allan668018d2012-01-31 07:02:56 +0000510 if (!hw->phy.ops.acquire)
Bruce Allan5015e532012-02-08 02:55:56 +0000511 return 0;
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000512
Bruce Allan94d81862009-11-20 23:25:26 +0000513 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000514 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000515 return ret_val;
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000516 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700517
518 kmrnctrlsta = ((offset << E1000_KMRNCTRLSTA_OFFSET_SHIFT) &
519 E1000_KMRNCTRLSTA_OFFSET) | E1000_KMRNCTRLSTA_REN;
520 ew32(KMRNCTRLSTA, kmrnctrlsta);
Jesse Brandeburg945a5152011-07-20 00:56:21 +0000521 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -0700522
523 udelay(2);
524
525 kmrnctrlsta = er32(KMRNCTRLSTA);
526 *data = (u16)kmrnctrlsta;
527
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000528 if (!locked)
Bruce Allan94d81862009-11-20 23:25:26 +0000529 hw->phy.ops.release(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700530
Bruce Allan5015e532012-02-08 02:55:56 +0000531 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700532}
533
534/**
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000535 * e1000e_read_kmrn_reg - Read kumeran register
536 * @hw: pointer to the HW structure
537 * @offset: register offset to be read
538 * @data: pointer to the read data
539 *
540 * Acquires semaphore then reads the PHY register at offset using the
541 * kumeran interface. The information retrieved is stored in data.
542 * Release the acquired semaphore before exiting.
543 **/
544s32 e1000e_read_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 *data)
545{
546 return __e1000_read_kmrn_reg(hw, offset, data, false);
547}
548
549/**
Bruce Allan1d5846b2009-10-29 13:46:05 +0000550 * e1000e_read_kmrn_reg_locked - Read kumeran register
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000551 * @hw: pointer to the HW structure
552 * @offset: register offset to be read
553 * @data: pointer to the read data
554 *
555 * Reads the PHY register at offset using the kumeran interface. The
556 * information retrieved is stored in data.
557 * Assumes semaphore already acquired.
558 **/
Bruce Allan1d5846b2009-10-29 13:46:05 +0000559s32 e1000e_read_kmrn_reg_locked(struct e1000_hw *hw, u32 offset, u16 *data)
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000560{
561 return __e1000_read_kmrn_reg(hw, offset, data, true);
562}
563
564/**
565 * __e1000_write_kmrn_reg - Write kumeran register
Auke Kokbc7f75f2007-09-17 12:30:59 -0700566 * @hw: pointer to the HW structure
567 * @offset: register offset to write to
568 * @data: data to write at register offset
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000569 * @locked: semaphore has already been acquired or not
Auke Kokbc7f75f2007-09-17 12:30:59 -0700570 *
571 * Acquires semaphore, if necessary. Then write the data to PHY register
572 * at the offset using the kumeran interface. Release any acquired semaphores
573 * before exiting.
574 **/
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000575static s32 __e1000_write_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 data,
576 bool locked)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700577{
578 u32 kmrnctrlsta;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700579
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000580 if (!locked) {
Bruce Allan5015e532012-02-08 02:55:56 +0000581 s32 ret_val = 0;
582
Bruce Allan668018d2012-01-31 07:02:56 +0000583 if (!hw->phy.ops.acquire)
Bruce Allan5015e532012-02-08 02:55:56 +0000584 return 0;
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000585
Bruce Allan94d81862009-11-20 23:25:26 +0000586 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000587 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000588 return ret_val;
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000589 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700590
591 kmrnctrlsta = ((offset << E1000_KMRNCTRLSTA_OFFSET_SHIFT) &
592 E1000_KMRNCTRLSTA_OFFSET) | data;
593 ew32(KMRNCTRLSTA, kmrnctrlsta);
Jesse Brandeburg945a5152011-07-20 00:56:21 +0000594 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -0700595
596 udelay(2);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700597
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000598 if (!locked)
Bruce Allan94d81862009-11-20 23:25:26 +0000599 hw->phy.ops.release(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000600
Bruce Allan5015e532012-02-08 02:55:56 +0000601 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700602}
603
604/**
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000605 * e1000e_write_kmrn_reg - Write kumeran register
606 * @hw: pointer to the HW structure
607 * @offset: register offset to write to
608 * @data: data to write at register offset
609 *
610 * Acquires semaphore then writes the data to the PHY register at the offset
611 * using the kumeran interface. Release the acquired semaphore before exiting.
612 **/
613s32 e1000e_write_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 data)
614{
615 return __e1000_write_kmrn_reg(hw, offset, data, false);
616}
617
618/**
Bruce Allan1d5846b2009-10-29 13:46:05 +0000619 * e1000e_write_kmrn_reg_locked - Write kumeran register
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000620 * @hw: pointer to the HW structure
621 * @offset: register offset to write to
622 * @data: data to write at register offset
623 *
624 * Write the data to PHY register at the offset using the kumeran interface.
625 * Assumes semaphore already acquired.
626 **/
Bruce Allan1d5846b2009-10-29 13:46:05 +0000627s32 e1000e_write_kmrn_reg_locked(struct e1000_hw *hw, u32 offset, u16 data)
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000628{
629 return __e1000_write_kmrn_reg(hw, offset, data, true);
630}
631
632/**
Bruce Allan7b9f7e32012-03-20 03:47:41 +0000633 * e1000_set_master_slave_mode - Setup PHY for Master/slave mode
634 * @hw: pointer to the HW structure
635 *
636 * Sets up Master/slave mode
637 **/
638static s32 e1000_set_master_slave_mode(struct e1000_hw *hw)
639{
640 s32 ret_val;
641 u16 phy_data;
642
643 /* Resolve Master/Slave mode */
644 ret_val = e1e_rphy(hw, PHY_1000T_CTRL, &phy_data);
645 if (ret_val)
646 return ret_val;
647
648 /* load defaults for future use */
649 hw->phy.original_ms_type = (phy_data & CR_1000T_MS_ENABLE) ?
650 ((phy_data & CR_1000T_MS_VALUE) ?
651 e1000_ms_force_master : e1000_ms_force_slave) : e1000_ms_auto;
652
653 switch (hw->phy.ms_type) {
654 case e1000_ms_force_master:
655 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
656 break;
657 case e1000_ms_force_slave:
658 phy_data |= CR_1000T_MS_ENABLE;
659 phy_data &= ~(CR_1000T_MS_VALUE);
660 break;
661 case e1000_ms_auto:
662 phy_data &= ~CR_1000T_MS_ENABLE;
663 /* fall-through */
664 default:
665 break;
666 }
667
668 return e1e_wphy(hw, PHY_1000T_CTRL, phy_data);
669}
670
671/**
Bruce Allana4f58f52009-06-02 11:29:18 +0000672 * e1000_copper_link_setup_82577 - Setup 82577 PHY for copper link
673 * @hw: pointer to the HW structure
674 *
675 * Sets up Carrier-sense on Transmit and downshift values.
676 **/
677s32 e1000_copper_link_setup_82577(struct e1000_hw *hw)
678{
Bruce Allana4f58f52009-06-02 11:29:18 +0000679 s32 ret_val;
680 u16 phy_data;
681
Bruce Allanaf667a22010-12-31 06:10:01 +0000682 /* Enable CRS on Tx. This must be set for half-duplex operation. */
Bruce Allan482fed82011-01-06 14:29:49 +0000683 ret_val = e1e_rphy(hw, I82577_CFG_REG, &phy_data);
Bruce Allana4f58f52009-06-02 11:29:18 +0000684 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000685 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +0000686
687 phy_data |= I82577_CFG_ASSERT_CRS_ON_TX;
688
689 /* Enable downshift */
690 phy_data |= I82577_CFG_ENABLE_DOWNSHIFT;
691
Bruce Allan7b9f7e32012-03-20 03:47:41 +0000692 ret_val = e1e_wphy(hw, I82577_CFG_REG, phy_data);
693 if (ret_val)
694 return ret_val;
695
Bruce W Allane86fd892012-07-26 02:30:59 +0000696 /* Set MDI/MDIX mode */
697 ret_val = e1e_rphy(hw, I82577_PHY_CTRL_2, &phy_data);
698 if (ret_val)
699 return ret_val;
700 phy_data &= ~I82577_PHY_CTRL2_MDIX_CFG_MASK;
Bruce Allane921eb12012-11-28 09:28:37 +0000701 /* Options:
Bruce W Allane86fd892012-07-26 02:30:59 +0000702 * 0 - Auto (default)
703 * 1 - MDI mode
704 * 2 - MDI-X mode
705 */
706 switch (hw->phy.mdix) {
707 case 1:
708 break;
709 case 2:
710 phy_data |= I82577_PHY_CTRL2_MANUAL_MDIX;
711 break;
712 case 0:
713 default:
714 phy_data |= I82577_PHY_CTRL2_AUTO_MDI_MDIX;
715 break;
716 }
717 ret_val = e1e_wphy(hw, I82577_PHY_CTRL_2, phy_data);
718 if (ret_val)
719 return ret_val;
720
Bruce Allan7b9f7e32012-03-20 03:47:41 +0000721 return e1000_set_master_slave_mode(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +0000722}
723
724/**
Auke Kokbc7f75f2007-09-17 12:30:59 -0700725 * e1000e_copper_link_setup_m88 - Setup m88 PHY's for copper link
726 * @hw: pointer to the HW structure
727 *
728 * Sets up MDI/MDI-X and polarity for m88 PHY's. If necessary, transmit clock
729 * and downshift values are set also.
730 **/
731s32 e1000e_copper_link_setup_m88(struct e1000_hw *hw)
732{
733 struct e1000_phy_info *phy = &hw->phy;
734 s32 ret_val;
735 u16 phy_data;
736
Bruce Allanad680762008-03-28 09:15:03 -0700737 /* Enable CRS on Tx. This must be set for half-duplex operation. */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700738 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
739 if (ret_val)
740 return ret_val;
741
Bruce Allana4f58f52009-06-02 11:29:18 +0000742 /* For BM PHY this bit is downshift enable */
743 if (phy->type != e1000_phy_bm)
David Graham2d9498f2008-04-23 11:09:14 -0700744 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700745
Bruce Allane921eb12012-11-28 09:28:37 +0000746 /* Options:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700747 * MDI/MDI-X = 0 (default)
748 * 0 - Auto for all speeds
749 * 1 - MDI mode
750 * 2 - MDI-X mode
751 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
752 */
753 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
754
755 switch (phy->mdix) {
756 case 1:
757 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
758 break;
759 case 2:
760 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
761 break;
762 case 3:
763 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
764 break;
765 case 0:
766 default:
767 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
768 break;
769 }
770
Bruce Allane921eb12012-11-28 09:28:37 +0000771 /* Options:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700772 * disable_polarity_correction = 0 (default)
773 * Automatic Correction for Reversed Cable Polarity
774 * 0 - Disabled
775 * 1 - Enabled
776 */
777 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
Bruce Allan04499ec2012-04-13 00:08:31 +0000778 if (phy->disable_polarity_correction)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700779 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
780
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700781 /* Enable downshift on BM (disabled by default) */
Matthew Vick885fe7b2012-04-25 07:25:18 +0000782 if (phy->type == e1000_phy_bm) {
783 /* For 82574/82583, first disable then enable downshift */
784 if (phy->id == BME1000_E_PHY_ID_R2) {
785 phy_data &= ~BME1000_PSCR_ENABLE_DOWNSHIFT;
786 ret_val = e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL,
787 phy_data);
788 if (ret_val)
789 return ret_val;
790 /* Commit the changes. */
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 */
946 ret_val = e1e_rphy(hw, PHY_1000T_CTRL, &data);
947 if (ret_val)
948 return ret_val;
949
950 data &= ~CR_1000T_MS_ENABLE;
951 ret_val = e1e_wphy(hw, PHY_1000T_CTRL, data);
952 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). */
981 ret_val = e1e_rphy(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
982 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). */
987 ret_val = e1e_rphy(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
988 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 */
1003 mii_autoneg_adv_reg &= ~(NWAY_AR_100TX_FD_CAPS |
1004 NWAY_AR_100TX_HD_CAPS |
1005 NWAY_AR_10T_FD_CAPS |
1006 NWAY_AR_10T_HD_CAPS);
1007 mii_1000t_ctrl_reg &= ~(CR_1000T_HD_CAPS | CR_1000T_FD_CAPS);
1008
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001009 e_dbg("autoneg_advertised %x\n", phy->autoneg_advertised);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001010
1011 /* Do we want to advertise 10 Mb Half Duplex? */
1012 if (phy->autoneg_advertised & ADVERTISE_10_HALF) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001013 e_dbg("Advertise 10mb Half duplex\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001014 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
1015 }
1016
1017 /* Do we want to advertise 10 Mb Full Duplex? */
1018 if (phy->autoneg_advertised & ADVERTISE_10_FULL) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001019 e_dbg("Advertise 10mb Full duplex\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001020 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
1021 }
1022
1023 /* Do we want to advertise 100 Mb Half Duplex? */
1024 if (phy->autoneg_advertised & ADVERTISE_100_HALF) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001025 e_dbg("Advertise 100mb Half duplex\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001026 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
1027 }
1028
1029 /* Do we want to advertise 100 Mb Full Duplex? */
1030 if (phy->autoneg_advertised & ADVERTISE_100_FULL) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001031 e_dbg("Advertise 100mb Full duplex\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001032 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
1033 }
1034
1035 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
1036 if (phy->autoneg_advertised & ADVERTISE_1000_HALF)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001037 e_dbg("Advertise 1000mb Half duplex request denied!\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001038
1039 /* Do we want to advertise 1000 Mb Full Duplex? */
1040 if (phy->autoneg_advertised & ADVERTISE_1000_FULL) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001041 e_dbg("Advertise 1000mb Full duplex\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001042 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
1043 }
1044
Bruce Allane921eb12012-11-28 09:28:37 +00001045 /* Check for a software override of the flow control settings, and
Auke Kokbc7f75f2007-09-17 12:30:59 -07001046 * setup the PHY advertisement registers accordingly. If
1047 * auto-negotiation is enabled, then software will have to set the
1048 * "PAUSE" bits to the correct value in the Auto-Negotiation
1049 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-
1050 * negotiation.
1051 *
1052 * The possible values of the "fc" parameter are:
1053 * 0: Flow control is completely disabled
1054 * 1: Rx flow control is enabled (we can receive pause frames
Bruce Allan3d3a1672012-02-23 03:13:18 +00001055 * but not send pause frames).
Auke Kokbc7f75f2007-09-17 12:30:59 -07001056 * 2: Tx flow control is enabled (we can send pause frames
Bruce Allan3d3a1672012-02-23 03:13:18 +00001057 * but we do not support receiving pause frames).
Bruce Allanad680762008-03-28 09:15:03 -07001058 * 3: Both Rx and Tx flow control (symmetric) are enabled.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001059 * other: No software override. The flow control configuration
Bruce Allan3d3a1672012-02-23 03:13:18 +00001060 * in the EEPROM is used.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001061 */
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08001062 switch (hw->fc.current_mode) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001063 case e1000_fc_none:
Bruce Allane921eb12012-11-28 09:28:37 +00001064 /* Flow control (Rx & Tx) is completely disabled by a
Auke Kokbc7f75f2007-09-17 12:30:59 -07001065 * software over-ride.
1066 */
1067 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1068 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 */
1079 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1080 break;
1081 case e1000_fc_tx_pause:
Bruce Allane921eb12012-11-28 09:28:37 +00001082 /* Tx Flow control is enabled, and Rx Flow control is
Auke Kokbc7f75f2007-09-17 12:30:59 -07001083 * disabled, by a software over-ride.
1084 */
1085 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
1086 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
1087 break;
1088 case e1000_fc_full:
Bruce Allane921eb12012-11-28 09:28:37 +00001089 /* Flow control (both Rx and Tx) is enabled by a software
Auke Kokbc7f75f2007-09-17 12:30:59 -07001090 * over-ride.
1091 */
1092 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1093 break;
1094 default:
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001095 e_dbg("Flow control param set incorrectly\n");
Bruce Allan7eb61d82012-02-08 02:55:03 +00001096 return -E1000_ERR_CONFIG;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001097 }
1098
1099 ret_val = e1e_wphy(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
1100 if (ret_val)
1101 return ret_val;
1102
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001103 e_dbg("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001104
Bruce Allanb1cdfea2010-12-11 05:53:47 +00001105 if (phy->autoneg_mask & ADVERTISE_1000_FULL)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001106 ret_val = e1e_wphy(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001107
1108 return ret_val;
1109}
1110
1111/**
1112 * e1000_copper_link_autoneg - Setup/Enable autoneg for copper link
1113 * @hw: pointer to the HW structure
1114 *
1115 * Performs initial bounds checking on autoneg advertisement parameter, then
1116 * configure to advertise the full capability. Setup the PHY to autoneg
1117 * and restart the negotiation process between the link partner. If
Bruce Allanad680762008-03-28 09:15:03 -07001118 * autoneg_wait_to_complete, then wait for autoneg to complete before exiting.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001119 **/
1120static s32 e1000_copper_link_autoneg(struct e1000_hw *hw)
1121{
1122 struct e1000_phy_info *phy = &hw->phy;
1123 s32 ret_val;
1124 u16 phy_ctrl;
1125
Bruce Allane921eb12012-11-28 09:28:37 +00001126 /* Perform some bounds checking on the autoneg advertisement
Auke Kokbc7f75f2007-09-17 12:30:59 -07001127 * parameter.
1128 */
1129 phy->autoneg_advertised &= phy->autoneg_mask;
1130
Bruce Allane921eb12012-11-28 09:28:37 +00001131 /* If autoneg_advertised is zero, we assume it was not defaulted
Auke Kokbc7f75f2007-09-17 12:30:59 -07001132 * by the calling code so we set to advertise full capability.
1133 */
Bruce Allan04499ec2012-04-13 00:08:31 +00001134 if (!phy->autoneg_advertised)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001135 phy->autoneg_advertised = phy->autoneg_mask;
1136
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001137 e_dbg("Reconfiguring auto-neg advertisement params\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001138 ret_val = e1000_phy_setup_autoneg(hw);
1139 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001140 e_dbg("Error Setting up Auto-Negotiation\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001141 return ret_val;
1142 }
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001143 e_dbg("Restarting Auto-Neg\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001144
Bruce Allane921eb12012-11-28 09:28:37 +00001145 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
Auke Kokbc7f75f2007-09-17 12:30:59 -07001146 * the Auto Neg Restart bit in the PHY control register.
1147 */
1148 ret_val = e1e_rphy(hw, PHY_CONTROL, &phy_ctrl);
1149 if (ret_val)
1150 return ret_val;
1151
1152 phy_ctrl |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
1153 ret_val = e1e_wphy(hw, PHY_CONTROL, phy_ctrl);
1154 if (ret_val)
1155 return ret_val;
1156
Bruce Allane921eb12012-11-28 09:28:37 +00001157 /* Does the user want to wait for Auto-Neg to complete here, or
Auke Kokbc7f75f2007-09-17 12:30:59 -07001158 * check at a later time (for example, callback routine).
1159 */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001160 if (phy->autoneg_wait_to_complete) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001161 ret_val = e1000_wait_autoneg(hw);
1162 if (ret_val) {
Bruce Allan434f1392011-12-16 00:46:54 +00001163 e_dbg("Error while waiting for autoneg to complete\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001164 return ret_val;
1165 }
1166 }
1167
Bruce Allanf92518d2012-02-01 11:16:42 +00001168 hw->mac.get_link_status = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001169
1170 return ret_val;
1171}
1172
1173/**
1174 * e1000e_setup_copper_link - Configure copper link settings
1175 * @hw: pointer to the HW structure
1176 *
1177 * Calls the appropriate function to configure the link for auto-neg or forced
1178 * speed and duplex. Then we check for link, once link is established calls
1179 * to configure collision distance and flow control are called. If link is
1180 * not established, we return -E1000_ERR_PHY (-2).
1181 **/
1182s32 e1000e_setup_copper_link(struct e1000_hw *hw)
1183{
1184 s32 ret_val;
1185 bool link;
1186
1187 if (hw->mac.autoneg) {
Bruce Allane921eb12012-11-28 09:28:37 +00001188 /* Setup autoneg and flow control advertisement and perform
Bruce Allanad680762008-03-28 09:15:03 -07001189 * autonegotiation.
1190 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001191 ret_val = e1000_copper_link_autoneg(hw);
1192 if (ret_val)
1193 return ret_val;
1194 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00001195 /* PHY will be set to 10H, 10F, 100H or 100F
Bruce Allanad680762008-03-28 09:15:03 -07001196 * depending on user settings.
1197 */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001198 e_dbg("Forcing Speed and Duplex\n");
Bruce Allanc2c66292013-01-05 08:06:08 +00001199 ret_val = hw->phy.ops.force_speed_duplex(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001200 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001201 e_dbg("Error Forcing Speed and Duplex\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001202 return ret_val;
1203 }
1204 }
1205
Bruce Allane921eb12012-11-28 09:28:37 +00001206 /* Check link status. Wait up to 100 microseconds for link to become
Auke Kokbc7f75f2007-09-17 12:30:59 -07001207 * valid.
1208 */
Bruce Allan3d3a1672012-02-23 03:13:18 +00001209 ret_val = e1000e_phy_has_link_generic(hw, COPPER_LINK_UP_LIMIT, 10,
1210 &link);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001211 if (ret_val)
1212 return ret_val;
1213
1214 if (link) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001215 e_dbg("Valid link established!!!\n");
Bruce Allan57cde762012-02-22 09:02:58 +00001216 hw->mac.ops.config_collision_dist(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001217 ret_val = e1000e_config_fc_after_link_up(hw);
1218 } else {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001219 e_dbg("Unable to establish link!!!\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001220 }
1221
1222 return ret_val;
1223}
1224
1225/**
1226 * e1000e_phy_force_speed_duplex_igp - Force speed/duplex for igp PHY
1227 * @hw: pointer to the HW structure
1228 *
1229 * Calls the PHY setup function to force speed and duplex. Clears the
1230 * auto-crossover to force MDI manually. Waits for link and returns
1231 * successful if link up is successful, else -E1000_ERR_PHY (-2).
1232 **/
1233s32 e1000e_phy_force_speed_duplex_igp(struct e1000_hw *hw)
1234{
1235 struct e1000_phy_info *phy = &hw->phy;
1236 s32 ret_val;
1237 u16 phy_data;
1238 bool link;
1239
1240 ret_val = e1e_rphy(hw, PHY_CONTROL, &phy_data);
1241 if (ret_val)
1242 return ret_val;
1243
1244 e1000e_phy_force_speed_duplex_setup(hw, &phy_data);
1245
1246 ret_val = e1e_wphy(hw, PHY_CONTROL, phy_data);
1247 if (ret_val)
1248 return ret_val;
1249
Bruce Allane921eb12012-11-28 09:28:37 +00001250 /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
Auke Kokbc7f75f2007-09-17 12:30:59 -07001251 * forced whenever speed and duplex are forced.
1252 */
1253 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1254 if (ret_val)
1255 return ret_val;
1256
1257 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1258 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1259
1260 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1261 if (ret_val)
1262 return ret_val;
1263
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001264 e_dbg("IGP PSCR: %X\n", phy_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001265
1266 udelay(1);
1267
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001268 if (phy->autoneg_wait_to_complete) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001269 e_dbg("Waiting for forced speed/duplex link on IGP phy.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001270
Bruce Allan3d3a1672012-02-23 03:13:18 +00001271 ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
1272 100000, &link);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001273 if (ret_val)
1274 return ret_val;
1275
1276 if (!link)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001277 e_dbg("Link taking longer than expected.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001278
1279 /* Try once more */
Bruce Allan3d3a1672012-02-23 03:13:18 +00001280 ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
1281 100000, &link);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001282 }
1283
1284 return ret_val;
1285}
1286
1287/**
1288 * e1000e_phy_force_speed_duplex_m88 - Force speed/duplex for m88 PHY
1289 * @hw: pointer to the HW structure
1290 *
1291 * Calls the PHY setup function to force speed and duplex. Clears the
1292 * auto-crossover to force MDI manually. Resets the PHY to commit the
1293 * changes. If time expires while waiting for link up, we reset the DSP.
Bruce Allanad680762008-03-28 09:15:03 -07001294 * After reset, TX_CLK and CRS on Tx must be set. Return successful upon
Auke Kokbc7f75f2007-09-17 12:30:59 -07001295 * successful completion, else return corresponding error code.
1296 **/
1297s32 e1000e_phy_force_speed_duplex_m88(struct e1000_hw *hw)
1298{
1299 struct e1000_phy_info *phy = &hw->phy;
1300 s32 ret_val;
1301 u16 phy_data;
1302 bool link;
1303
Bruce Allane921eb12012-11-28 09:28:37 +00001304 /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
Auke Kokbc7f75f2007-09-17 12:30:59 -07001305 * forced whenever speed and duplex are forced.
1306 */
1307 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1308 if (ret_val)
1309 return ret_val;
1310
1311 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1312 ret_val = e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1313 if (ret_val)
1314 return ret_val;
1315
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001316 e_dbg("M88E1000 PSCR: %X\n", phy_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001317
1318 ret_val = e1e_rphy(hw, PHY_CONTROL, &phy_data);
1319 if (ret_val)
1320 return ret_val;
1321
1322 e1000e_phy_force_speed_duplex_setup(hw, &phy_data);
1323
Auke Kokbc7f75f2007-09-17 12:30:59 -07001324 ret_val = e1e_wphy(hw, PHY_CONTROL, phy_data);
1325 if (ret_val)
1326 return ret_val;
1327
Bruce Allan5aa49c82008-11-21 16:49:53 -08001328 /* Reset the phy to commit changes. */
Bruce Allan6b598e12013-01-23 06:50:05 +00001329 if (hw->phy.ops.commit) {
1330 ret_val = hw->phy.ops.commit(hw);
1331 if (ret_val)
1332 return ret_val;
1333 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001334
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001335 if (phy->autoneg_wait_to_complete) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001336 e_dbg("Waiting for forced speed/duplex link on M88 phy.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001337
1338 ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
1339 100000, &link);
1340 if (ret_val)
1341 return ret_val;
1342
1343 if (!link) {
Bruce Allan0be84012009-12-02 17:03:18 +00001344 if (hw->phy.type != e1000_phy_m88) {
1345 e_dbg("Link taking longer than expected.\n");
1346 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00001347 /* We didn't get link.
Bruce Allan0be84012009-12-02 17:03:18 +00001348 * Reset the DSP and cross our fingers.
1349 */
Bruce Allan482fed82011-01-06 14:29:49 +00001350 ret_val = e1e_wphy(hw, M88E1000_PHY_PAGE_SELECT,
1351 0x001d);
Bruce Allan0be84012009-12-02 17:03:18 +00001352 if (ret_val)
1353 return ret_val;
1354 ret_val = e1000e_phy_reset_dsp(hw);
1355 if (ret_val)
1356 return ret_val;
1357 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001358 }
1359
1360 /* Try once more */
1361 ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
1362 100000, &link);
1363 if (ret_val)
1364 return ret_val;
1365 }
1366
Bruce Allan0be84012009-12-02 17:03:18 +00001367 if (hw->phy.type != e1000_phy_m88)
1368 return 0;
1369
Auke Kokbc7f75f2007-09-17 12:30:59 -07001370 ret_val = e1e_rphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1371 if (ret_val)
1372 return ret_val;
1373
Bruce Allane921eb12012-11-28 09:28:37 +00001374 /* Resetting the phy means we need to re-force TX_CLK in the
Auke Kokbc7f75f2007-09-17 12:30:59 -07001375 * Extended PHY Specific Control Register to 25MHz clock from
1376 * the reset value of 2.5MHz.
1377 */
1378 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1379 ret_val = e1e_wphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1380 if (ret_val)
1381 return ret_val;
1382
Bruce Allane921eb12012-11-28 09:28:37 +00001383 /* In addition, we must re-enable CRS on Tx for both half and full
Auke Kokbc7f75f2007-09-17 12:30:59 -07001384 * duplex.
1385 */
1386 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1387 if (ret_val)
1388 return ret_val;
1389
1390 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1391 ret_val = e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1392
1393 return ret_val;
1394}
1395
1396/**
Bruce Allan0be84012009-12-02 17:03:18 +00001397 * e1000_phy_force_speed_duplex_ife - Force PHY speed & duplex
1398 * @hw: pointer to the HW structure
1399 *
1400 * Forces the speed and duplex settings of the PHY.
1401 * This is a function pointer entry point only called by
1402 * PHY setup routines.
1403 **/
1404s32 e1000_phy_force_speed_duplex_ife(struct e1000_hw *hw)
1405{
1406 struct e1000_phy_info *phy = &hw->phy;
1407 s32 ret_val;
1408 u16 data;
1409 bool link;
1410
1411 ret_val = e1e_rphy(hw, PHY_CONTROL, &data);
1412 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001413 return ret_val;
Bruce Allan0be84012009-12-02 17:03:18 +00001414
1415 e1000e_phy_force_speed_duplex_setup(hw, &data);
1416
1417 ret_val = e1e_wphy(hw, PHY_CONTROL, data);
1418 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001419 return ret_val;
Bruce Allan0be84012009-12-02 17:03:18 +00001420
1421 /* Disable MDI-X support for 10/100 */
1422 ret_val = e1e_rphy(hw, IFE_PHY_MDIX_CONTROL, &data);
1423 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001424 return ret_val;
Bruce Allan0be84012009-12-02 17:03:18 +00001425
1426 data &= ~IFE_PMC_AUTO_MDIX;
1427 data &= ~IFE_PMC_FORCE_MDIX;
1428
1429 ret_val = e1e_wphy(hw, IFE_PHY_MDIX_CONTROL, data);
1430 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001431 return ret_val;
Bruce Allan0be84012009-12-02 17:03:18 +00001432
1433 e_dbg("IFE PMC: %X\n", data);
1434
1435 udelay(1);
1436
1437 if (phy->autoneg_wait_to_complete) {
1438 e_dbg("Waiting for forced speed/duplex link on IFE phy.\n");
1439
Bruce Allan3d3a1672012-02-23 03:13:18 +00001440 ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
1441 100000, &link);
Bruce Allan0be84012009-12-02 17:03:18 +00001442 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001443 return ret_val;
Bruce Allan0be84012009-12-02 17:03:18 +00001444
1445 if (!link)
1446 e_dbg("Link taking longer than expected.\n");
1447
1448 /* Try once more */
Bruce Allan3d3a1672012-02-23 03:13:18 +00001449 ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
1450 100000, &link);
Bruce Allan0be84012009-12-02 17:03:18 +00001451 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001452 return ret_val;
Bruce Allan0be84012009-12-02 17:03:18 +00001453 }
1454
Bruce Allan5015e532012-02-08 02:55:56 +00001455 return 0;
Bruce Allan0be84012009-12-02 17:03:18 +00001456}
1457
1458/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001459 * e1000e_phy_force_speed_duplex_setup - Configure forced PHY speed/duplex
1460 * @hw: pointer to the HW structure
1461 * @phy_ctrl: pointer to current value of PHY_CONTROL
1462 *
1463 * Forces speed and duplex on the PHY by doing the following: disable flow
1464 * control, force speed/duplex on the MAC, disable auto speed detection,
1465 * disable auto-negotiation, configure duplex, configure speed, configure
1466 * the collision distance, write configuration to CTRL register. The
1467 * caller must write to the PHY_CONTROL register for these settings to
1468 * take affect.
1469 **/
1470void e1000e_phy_force_speed_duplex_setup(struct e1000_hw *hw, u16 *phy_ctrl)
1471{
1472 struct e1000_mac_info *mac = &hw->mac;
1473 u32 ctrl;
1474
1475 /* Turn off flow control when forcing speed/duplex */
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08001476 hw->fc.current_mode = e1000_fc_none;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001477
1478 /* Force speed/duplex on the mac */
1479 ctrl = er32(CTRL);
1480 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1481 ctrl &= ~E1000_CTRL_SPD_SEL;
1482
1483 /* Disable Auto Speed Detection */
1484 ctrl &= ~E1000_CTRL_ASDE;
1485
1486 /* Disable autoneg on the phy */
1487 *phy_ctrl &= ~MII_CR_AUTO_NEG_EN;
1488
1489 /* Forcing Full or Half Duplex? */
1490 if (mac->forced_speed_duplex & E1000_ALL_HALF_DUPLEX) {
1491 ctrl &= ~E1000_CTRL_FD;
1492 *phy_ctrl &= ~MII_CR_FULL_DUPLEX;
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001493 e_dbg("Half Duplex\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001494 } else {
1495 ctrl |= E1000_CTRL_FD;
1496 *phy_ctrl |= MII_CR_FULL_DUPLEX;
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001497 e_dbg("Full Duplex\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001498 }
1499
1500 /* Forcing 10mb or 100mb? */
1501 if (mac->forced_speed_duplex & E1000_ALL_100_SPEED) {
1502 ctrl |= E1000_CTRL_SPD_100;
1503 *phy_ctrl |= MII_CR_SPEED_100;
1504 *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001505 e_dbg("Forcing 100mb\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001506 } else {
1507 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1508 *phy_ctrl |= MII_CR_SPEED_10;
1509 *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001510 e_dbg("Forcing 10mb\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001511 }
1512
Bruce Allan57cde762012-02-22 09:02:58 +00001513 hw->mac.ops.config_collision_dist(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001514
1515 ew32(CTRL, ctrl);
1516}
1517
1518/**
1519 * e1000e_set_d3_lplu_state - Sets low power link up state for D3
1520 * @hw: pointer to the HW structure
1521 * @active: boolean used to enable/disable lplu
1522 *
1523 * Success returns 0, Failure returns 1
1524 *
1525 * The low power link up (lplu) state is set to the power management level D3
1526 * and SmartSpeed is disabled when active is true, else clear lplu for D3
1527 * and enable Smartspeed. LPLU and Smartspeed are mutually exclusive. LPLU
1528 * is used during Dx states where the power conservation is most important.
1529 * During driver activity, SmartSpeed should be enabled so performance is
1530 * maintained.
1531 **/
1532s32 e1000e_set_d3_lplu_state(struct e1000_hw *hw, bool active)
1533{
1534 struct e1000_phy_info *phy = &hw->phy;
1535 s32 ret_val;
1536 u16 data;
1537
1538 ret_val = e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &data);
1539 if (ret_val)
1540 return ret_val;
1541
1542 if (!active) {
1543 data &= ~IGP02E1000_PM_D3_LPLU;
David Graham2d9498f2008-04-23 11:09:14 -07001544 ret_val = e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001545 if (ret_val)
1546 return ret_val;
Bruce Allane921eb12012-11-28 09:28:37 +00001547 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
Auke Kokbc7f75f2007-09-17 12:30:59 -07001548 * during Dx states where the power conservation is most
1549 * important. During driver activity we should enable
Bruce Allanad680762008-03-28 09:15:03 -07001550 * SmartSpeed, so performance is maintained.
1551 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001552 if (phy->smart_speed == e1000_smart_speed_on) {
1553 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07001554 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001555 if (ret_val)
1556 return ret_val;
1557
1558 data |= IGP01E1000_PSCFR_SMART_SPEED;
1559 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07001560 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001561 if (ret_val)
1562 return ret_val;
1563 } else if (phy->smart_speed == e1000_smart_speed_off) {
1564 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07001565 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001566 if (ret_val)
1567 return ret_val;
1568
1569 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1570 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07001571 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001572 if (ret_val)
1573 return ret_val;
1574 }
1575 } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
1576 (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
1577 (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
1578 data |= IGP02E1000_PM_D3_LPLU;
1579 ret_val = e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, data);
1580 if (ret_val)
1581 return ret_val;
1582
1583 /* When LPLU is enabled, we should disable SmartSpeed */
1584 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
1585 if (ret_val)
1586 return ret_val;
1587
1588 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1589 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
1590 }
1591
1592 return ret_val;
1593}
1594
1595/**
Auke Kok489815c2008-02-21 15:11:07 -08001596 * e1000e_check_downshift - Checks whether a downshift in speed occurred
Auke Kokbc7f75f2007-09-17 12:30:59 -07001597 * @hw: pointer to the HW structure
1598 *
1599 * Success returns 0, Failure returns 1
1600 *
1601 * A downshift is detected by querying the PHY link health.
1602 **/
1603s32 e1000e_check_downshift(struct e1000_hw *hw)
1604{
1605 struct e1000_phy_info *phy = &hw->phy;
1606 s32 ret_val;
1607 u16 phy_data, offset, mask;
1608
1609 switch (phy->type) {
1610 case e1000_phy_m88:
1611 case e1000_phy_gg82563:
Bruce Allan07f025e2009-12-01 15:53:48 +00001612 case e1000_phy_bm:
Bruce Allana4f58f52009-06-02 11:29:18 +00001613 case e1000_phy_82578:
Auke Kokbc7f75f2007-09-17 12:30:59 -07001614 offset = M88E1000_PHY_SPEC_STATUS;
1615 mask = M88E1000_PSSR_DOWNSHIFT;
1616 break;
1617 case e1000_phy_igp_2:
1618 case e1000_phy_igp_3:
1619 offset = IGP01E1000_PHY_LINK_HEALTH;
1620 mask = IGP01E1000_PLHR_SS_DOWNGRADE;
1621 break;
1622 default:
1623 /* speed downshift not supported */
Bruce Allan564ea9b2009-11-20 23:26:44 +00001624 phy->speed_downgraded = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001625 return 0;
1626 }
1627
1628 ret_val = e1e_rphy(hw, offset, &phy_data);
1629
1630 if (!ret_val)
Bruce Allan04499ec2012-04-13 00:08:31 +00001631 phy->speed_downgraded = !!(phy_data & mask);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001632
1633 return ret_val;
1634}
1635
1636/**
1637 * e1000_check_polarity_m88 - Checks the polarity.
1638 * @hw: pointer to the HW structure
1639 *
1640 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1641 *
1642 * Polarity is determined based on the PHY specific status register.
1643 **/
Bruce Allan0be84012009-12-02 17:03:18 +00001644s32 e1000_check_polarity_m88(struct e1000_hw *hw)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001645{
1646 struct e1000_phy_info *phy = &hw->phy;
1647 s32 ret_val;
1648 u16 data;
1649
1650 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &data);
1651
1652 if (!ret_val)
1653 phy->cable_polarity = (data & M88E1000_PSSR_REV_POLARITY)
1654 ? e1000_rev_polarity_reversed
1655 : e1000_rev_polarity_normal;
1656
1657 return ret_val;
1658}
1659
1660/**
1661 * e1000_check_polarity_igp - Checks the polarity.
1662 * @hw: pointer to the HW structure
1663 *
1664 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1665 *
1666 * Polarity is determined based on the PHY port status register, and the
1667 * current speed (since there is no polarity at 100Mbps).
1668 **/
Bruce Allan0be84012009-12-02 17:03:18 +00001669s32 e1000_check_polarity_igp(struct e1000_hw *hw)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001670{
1671 struct e1000_phy_info *phy = &hw->phy;
1672 s32 ret_val;
1673 u16 data, offset, mask;
1674
Bruce Allane921eb12012-11-28 09:28:37 +00001675 /* Polarity is determined based on the speed of
Bruce Allanad680762008-03-28 09:15:03 -07001676 * our connection.
1677 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001678 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_STATUS, &data);
1679 if (ret_val)
1680 return ret_val;
1681
1682 if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
1683 IGP01E1000_PSSR_SPEED_1000MBPS) {
1684 offset = IGP01E1000_PHY_PCS_INIT_REG;
1685 mask = IGP01E1000_PHY_POLARITY_MASK;
1686 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00001687 /* This really only applies to 10Mbps since
Auke Kokbc7f75f2007-09-17 12:30:59 -07001688 * there is no polarity for 100Mbps (always 0).
1689 */
1690 offset = IGP01E1000_PHY_PORT_STATUS;
1691 mask = IGP01E1000_PSSR_POLARITY_REVERSED;
1692 }
1693
1694 ret_val = e1e_rphy(hw, offset, &data);
1695
1696 if (!ret_val)
1697 phy->cable_polarity = (data & mask)
1698 ? e1000_rev_polarity_reversed
1699 : e1000_rev_polarity_normal;
1700
1701 return ret_val;
1702}
1703
1704/**
Bruce Allan0be84012009-12-02 17:03:18 +00001705 * e1000_check_polarity_ife - Check cable polarity for IFE PHY
1706 * @hw: pointer to the HW structure
1707 *
1708 * Polarity is determined on the polarity reversal feature being enabled.
1709 **/
1710s32 e1000_check_polarity_ife(struct e1000_hw *hw)
1711{
1712 struct e1000_phy_info *phy = &hw->phy;
1713 s32 ret_val;
1714 u16 phy_data, offset, mask;
1715
Bruce Allane921eb12012-11-28 09:28:37 +00001716 /* Polarity is determined based on the reversal feature being enabled.
Bruce Allan0be84012009-12-02 17:03:18 +00001717 */
1718 if (phy->polarity_correction) {
1719 offset = IFE_PHY_EXTENDED_STATUS_CONTROL;
1720 mask = IFE_PESC_POLARITY_REVERSED;
1721 } else {
1722 offset = IFE_PHY_SPECIAL_CONTROL;
1723 mask = IFE_PSC_FORCE_POLARITY;
1724 }
1725
1726 ret_val = e1e_rphy(hw, offset, &phy_data);
1727
1728 if (!ret_val)
1729 phy->cable_polarity = (phy_data & mask)
1730 ? e1000_rev_polarity_reversed
1731 : e1000_rev_polarity_normal;
1732
1733 return ret_val;
1734}
1735
1736/**
Bruce Allanad680762008-03-28 09:15:03 -07001737 * e1000_wait_autoneg - Wait for auto-neg completion
Auke Kokbc7f75f2007-09-17 12:30:59 -07001738 * @hw: pointer to the HW structure
1739 *
1740 * Waits for auto-negotiation to complete or for the auto-negotiation time
1741 * limit to expire, which ever happens first.
1742 **/
1743static s32 e1000_wait_autoneg(struct e1000_hw *hw)
1744{
1745 s32 ret_val = 0;
1746 u16 i, phy_status;
1747
1748 /* Break after autoneg completes or PHY_AUTO_NEG_LIMIT expires. */
1749 for (i = PHY_AUTO_NEG_LIMIT; i > 0; i--) {
1750 ret_val = e1e_rphy(hw, PHY_STATUS, &phy_status);
1751 if (ret_val)
1752 break;
1753 ret_val = e1e_rphy(hw, PHY_STATUS, &phy_status);
1754 if (ret_val)
1755 break;
1756 if (phy_status & MII_SR_AUTONEG_COMPLETE)
1757 break;
1758 msleep(100);
1759 }
1760
Bruce Allane921eb12012-11-28 09:28:37 +00001761 /* PHY_AUTO_NEG_TIME expiration doesn't guarantee auto-negotiation
Auke Kokbc7f75f2007-09-17 12:30:59 -07001762 * has completed.
1763 */
1764 return ret_val;
1765}
1766
1767/**
1768 * e1000e_phy_has_link_generic - Polls PHY for link
1769 * @hw: pointer to the HW structure
1770 * @iterations: number of times to poll for link
1771 * @usec_interval: delay between polling attempts
1772 * @success: pointer to whether polling was successful or not
1773 *
1774 * Polls the PHY status register for link, 'iterations' number of times.
1775 **/
1776s32 e1000e_phy_has_link_generic(struct e1000_hw *hw, u32 iterations,
1777 u32 usec_interval, bool *success)
1778{
1779 s32 ret_val = 0;
1780 u16 i, phy_status;
1781
1782 for (i = 0; i < iterations; i++) {
Bruce Allane921eb12012-11-28 09:28:37 +00001783 /* Some PHYs require the PHY_STATUS register to be read
Auke Kokbc7f75f2007-09-17 12:30:59 -07001784 * twice due to the link bit being sticky. No harm doing
1785 * it across the board.
1786 */
1787 ret_val = e1e_rphy(hw, PHY_STATUS, &phy_status);
1788 if (ret_val)
Bruce Allane921eb12012-11-28 09:28:37 +00001789 /* If the first read fails, another entity may have
Bruce Allan906e8d92009-07-01 13:28:50 +00001790 * ownership of the resources, wait and try again to
1791 * see if they have relinquished the resources yet.
1792 */
1793 udelay(usec_interval);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001794 ret_val = e1e_rphy(hw, PHY_STATUS, &phy_status);
1795 if (ret_val)
1796 break;
1797 if (phy_status & MII_SR_LINK_STATUS)
1798 break;
1799 if (usec_interval >= 1000)
1800 mdelay(usec_interval/1000);
1801 else
1802 udelay(usec_interval);
1803 }
1804
1805 *success = (i < iterations);
1806
1807 return ret_val;
1808}
1809
1810/**
1811 * e1000e_get_cable_length_m88 - Determine cable length for m88 PHY
1812 * @hw: pointer to the HW structure
1813 *
1814 * Reads the PHY specific status register to retrieve the cable length
1815 * information. The cable length is determined by averaging the minimum and
1816 * maximum values to get the "average" cable length. The m88 PHY has four
1817 * possible cable length values, which are:
1818 * Register Value Cable Length
1819 * 0 < 50 meters
1820 * 1 50 - 80 meters
1821 * 2 80 - 110 meters
1822 * 3 110 - 140 meters
1823 * 4 > 140 meters
1824 **/
1825s32 e1000e_get_cable_length_m88(struct e1000_hw *hw)
1826{
1827 struct e1000_phy_info *phy = &hw->phy;
1828 s32 ret_val;
1829 u16 phy_data, index;
1830
1831 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
1832 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001833 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001834
1835 index = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
Bruce Allaneb656d42009-12-01 15:47:02 +00001836 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
Bruce Allan5015e532012-02-08 02:55:56 +00001837
1838 if (index >= M88E1000_CABLE_LENGTH_TABLE_SIZE - 1)
1839 return -E1000_ERR_PHY;
Bruce Allaneb656d42009-12-01 15:47:02 +00001840
Auke Kokbc7f75f2007-09-17 12:30:59 -07001841 phy->min_cable_length = e1000_m88_cable_length_table[index];
Bruce Allaneb656d42009-12-01 15:47:02 +00001842 phy->max_cable_length = e1000_m88_cable_length_table[index + 1];
Auke Kokbc7f75f2007-09-17 12:30:59 -07001843
1844 phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
1845
Bruce Allan5015e532012-02-08 02:55:56 +00001846 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001847}
1848
1849/**
1850 * e1000e_get_cable_length_igp_2 - Determine cable length for igp2 PHY
1851 * @hw: pointer to the HW structure
1852 *
1853 * The automatic gain control (agc) normalizes the amplitude of the
1854 * received signal, adjusting for the attenuation produced by the
Auke Kok489815c2008-02-21 15:11:07 -08001855 * cable. By reading the AGC registers, which represent the
Bruce Allan5ff5b662009-12-01 15:51:11 +00001856 * combination of coarse and fine gain value, the value can be put
Auke Kokbc7f75f2007-09-17 12:30:59 -07001857 * into a lookup table to obtain the approximate cable length
1858 * for each channel.
1859 **/
1860s32 e1000e_get_cable_length_igp_2(struct e1000_hw *hw)
1861{
1862 struct e1000_phy_info *phy = &hw->phy;
1863 s32 ret_val;
1864 u16 phy_data, i, agc_value = 0;
1865 u16 cur_agc_index, max_agc_index = 0;
1866 u16 min_agc_index = IGP02E1000_CABLE_LENGTH_TABLE_SIZE - 1;
Jeff Kirsher66744502010-12-01 19:59:50 +00001867 static const u16 agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] = {
1868 IGP02E1000_PHY_AGC_A,
1869 IGP02E1000_PHY_AGC_B,
1870 IGP02E1000_PHY_AGC_C,
1871 IGP02E1000_PHY_AGC_D
1872 };
Auke Kokbc7f75f2007-09-17 12:30:59 -07001873
1874 /* Read the AGC registers for all channels */
1875 for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
1876 ret_val = e1e_rphy(hw, agc_reg_array[i], &phy_data);
1877 if (ret_val)
1878 return ret_val;
1879
Bruce Allane921eb12012-11-28 09:28:37 +00001880 /* Getting bits 15:9, which represent the combination of
Bruce Allan5ff5b662009-12-01 15:51:11 +00001881 * coarse and fine gain values. The result is a number
Auke Kokbc7f75f2007-09-17 12:30:59 -07001882 * that can be put into the lookup table to obtain the
Bruce Allanad680762008-03-28 09:15:03 -07001883 * approximate cable length.
1884 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001885 cur_agc_index = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
1886 IGP02E1000_AGC_LENGTH_MASK;
1887
1888 /* Array index bound check. */
1889 if ((cur_agc_index >= IGP02E1000_CABLE_LENGTH_TABLE_SIZE) ||
1890 (cur_agc_index == 0))
1891 return -E1000_ERR_PHY;
1892
1893 /* Remove min & max AGC values from calculation. */
1894 if (e1000_igp_2_cable_length_table[min_agc_index] >
1895 e1000_igp_2_cable_length_table[cur_agc_index])
1896 min_agc_index = cur_agc_index;
1897 if (e1000_igp_2_cable_length_table[max_agc_index] <
1898 e1000_igp_2_cable_length_table[cur_agc_index])
1899 max_agc_index = cur_agc_index;
1900
1901 agc_value += e1000_igp_2_cable_length_table[cur_agc_index];
1902 }
1903
1904 agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] +
1905 e1000_igp_2_cable_length_table[max_agc_index]);
1906 agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
1907
1908 /* Calculate cable length with the error range of +/- 10 meters. */
1909 phy->min_cable_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
1910 (agc_value - IGP02E1000_AGC_RANGE) : 0;
1911 phy->max_cable_length = agc_value + IGP02E1000_AGC_RANGE;
1912
1913 phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
1914
Bruce Allan82607252012-02-08 02:55:09 +00001915 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001916}
1917
1918/**
1919 * e1000e_get_phy_info_m88 - Retrieve PHY information
1920 * @hw: pointer to the HW structure
1921 *
1922 * Valid for only copper links. Read the PHY status register (sticky read)
1923 * to verify that link is up. Read the PHY special control register to
1924 * determine the polarity and 10base-T extended distance. Read the PHY
1925 * special status register to determine MDI/MDIx and current speed. If
1926 * speed is 1000, then determine cable length, local and remote receiver.
1927 **/
1928s32 e1000e_get_phy_info_m88(struct e1000_hw *hw)
1929{
1930 struct e1000_phy_info *phy = &hw->phy;
1931 s32 ret_val;
1932 u16 phy_data;
1933 bool link;
1934
Bruce Allan0be84012009-12-02 17:03:18 +00001935 if (phy->media_type != e1000_media_type_copper) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001936 e_dbg("Phy info is only valid for copper media\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001937 return -E1000_ERR_CONFIG;
1938 }
1939
1940 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
1941 if (ret_val)
1942 return ret_val;
1943
1944 if (!link) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001945 e_dbg("Phy info is only valid if link is up\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001946 return -E1000_ERR_CONFIG;
1947 }
1948
1949 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1950 if (ret_val)
1951 return ret_val;
1952
Bruce Allan04499ec2012-04-13 00:08:31 +00001953 phy->polarity_correction = !!(phy_data &
1954 M88E1000_PSCR_POLARITY_REVERSAL);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001955
1956 ret_val = e1000_check_polarity_m88(hw);
1957 if (ret_val)
1958 return ret_val;
1959
1960 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
1961 if (ret_val)
1962 return ret_val;
1963
Bruce Allan04499ec2012-04-13 00:08:31 +00001964 phy->is_mdix = !!(phy_data & M88E1000_PSSR_MDIX);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001965
1966 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
Bruce Allandde3a572013-01-05 08:06:24 +00001967 ret_val = hw->phy.ops.get_cable_length(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001968 if (ret_val)
1969 return ret_val;
1970
1971 ret_val = e1e_rphy(hw, PHY_1000T_STATUS, &phy_data);
1972 if (ret_val)
1973 return ret_val;
1974
1975 phy->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS)
1976 ? e1000_1000t_rx_status_ok
1977 : e1000_1000t_rx_status_not_ok;
1978
1979 phy->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS)
1980 ? e1000_1000t_rx_status_ok
1981 : e1000_1000t_rx_status_not_ok;
1982 } else {
1983 /* Set values to "undefined" */
1984 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
1985 phy->local_rx = e1000_1000t_rx_status_undefined;
1986 phy->remote_rx = e1000_1000t_rx_status_undefined;
1987 }
1988
1989 return ret_val;
1990}
1991
1992/**
1993 * e1000e_get_phy_info_igp - Retrieve igp PHY information
1994 * @hw: pointer to the HW structure
1995 *
1996 * Read PHY status to determine if link is up. If link is up, then
1997 * set/determine 10base-T extended distance and polarity correction. Read
1998 * PHY port status to determine MDI/MDIx and speed. Based on the speed,
1999 * determine on the cable length, local and remote receiver.
2000 **/
2001s32 e1000e_get_phy_info_igp(struct e1000_hw *hw)
2002{
2003 struct e1000_phy_info *phy = &hw->phy;
2004 s32 ret_val;
2005 u16 data;
2006 bool link;
2007
2008 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
2009 if (ret_val)
2010 return ret_val;
2011
2012 if (!link) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002013 e_dbg("Phy info is only valid if link is up\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002014 return -E1000_ERR_CONFIG;
2015 }
2016
Bruce Allan564ea9b2009-11-20 23:26:44 +00002017 phy->polarity_correction = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002018
2019 ret_val = e1000_check_polarity_igp(hw);
2020 if (ret_val)
2021 return ret_val;
2022
2023 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_STATUS, &data);
2024 if (ret_val)
2025 return ret_val;
2026
Bruce Allan04499ec2012-04-13 00:08:31 +00002027 phy->is_mdix = !!(data & IGP01E1000_PSSR_MDIX);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002028
2029 if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
2030 IGP01E1000_PSSR_SPEED_1000MBPS) {
Bruce Allandde3a572013-01-05 08:06:24 +00002031 ret_val = phy->ops.get_cable_length(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002032 if (ret_val)
2033 return ret_val;
2034
2035 ret_val = e1e_rphy(hw, PHY_1000T_STATUS, &data);
2036 if (ret_val)
2037 return ret_val;
2038
2039 phy->local_rx = (data & SR_1000T_LOCAL_RX_STATUS)
2040 ? e1000_1000t_rx_status_ok
2041 : e1000_1000t_rx_status_not_ok;
2042
2043 phy->remote_rx = (data & SR_1000T_REMOTE_RX_STATUS)
2044 ? e1000_1000t_rx_status_ok
2045 : e1000_1000t_rx_status_not_ok;
2046 } else {
2047 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
2048 phy->local_rx = e1000_1000t_rx_status_undefined;
2049 phy->remote_rx = e1000_1000t_rx_status_undefined;
2050 }
2051
2052 return ret_val;
2053}
2054
2055/**
Bruce Allan0be84012009-12-02 17:03:18 +00002056 * e1000_get_phy_info_ife - Retrieves various IFE PHY states
2057 * @hw: pointer to the HW structure
2058 *
2059 * Populates "phy" structure with various feature states.
2060 **/
2061s32 e1000_get_phy_info_ife(struct e1000_hw *hw)
2062{
2063 struct e1000_phy_info *phy = &hw->phy;
2064 s32 ret_val;
2065 u16 data;
2066 bool link;
2067
2068 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
2069 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002070 return ret_val;
Bruce Allan0be84012009-12-02 17:03:18 +00002071
2072 if (!link) {
2073 e_dbg("Phy info is only valid if link is up\n");
Bruce Allan5015e532012-02-08 02:55:56 +00002074 return -E1000_ERR_CONFIG;
Bruce Allan0be84012009-12-02 17:03:18 +00002075 }
2076
2077 ret_val = e1e_rphy(hw, IFE_PHY_SPECIAL_CONTROL, &data);
2078 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002079 return ret_val;
Bruce Allan04499ec2012-04-13 00:08:31 +00002080 phy->polarity_correction = !(data & IFE_PSC_AUTO_POLARITY_DISABLE);
Bruce Allan0be84012009-12-02 17:03:18 +00002081
2082 if (phy->polarity_correction) {
2083 ret_val = e1000_check_polarity_ife(hw);
2084 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002085 return ret_val;
Bruce Allan0be84012009-12-02 17:03:18 +00002086 } else {
2087 /* Polarity is forced */
2088 phy->cable_polarity = (data & IFE_PSC_FORCE_POLARITY)
2089 ? e1000_rev_polarity_reversed
2090 : e1000_rev_polarity_normal;
2091 }
2092
2093 ret_val = e1e_rphy(hw, IFE_PHY_MDIX_CONTROL, &data);
2094 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002095 return ret_val;
Bruce Allan0be84012009-12-02 17:03:18 +00002096
Bruce Allan04499ec2012-04-13 00:08:31 +00002097 phy->is_mdix = !!(data & IFE_PMC_MDIX_STATUS);
Bruce Allan0be84012009-12-02 17:03:18 +00002098
2099 /* The following parameters are undefined for 10/100 operation. */
2100 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
2101 phy->local_rx = e1000_1000t_rx_status_undefined;
2102 phy->remote_rx = e1000_1000t_rx_status_undefined;
2103
Bruce Allan5015e532012-02-08 02:55:56 +00002104 return 0;
Bruce Allan0be84012009-12-02 17:03:18 +00002105}
2106
2107/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002108 * e1000e_phy_sw_reset - PHY software reset
2109 * @hw: pointer to the HW structure
2110 *
2111 * Does a software reset of the PHY by reading the PHY control register and
2112 * setting/write the control register reset bit to the PHY.
2113 **/
2114s32 e1000e_phy_sw_reset(struct e1000_hw *hw)
2115{
2116 s32 ret_val;
2117 u16 phy_ctrl;
2118
2119 ret_val = e1e_rphy(hw, PHY_CONTROL, &phy_ctrl);
2120 if (ret_val)
2121 return ret_val;
2122
2123 phy_ctrl |= MII_CR_RESET;
2124 ret_val = e1e_wphy(hw, PHY_CONTROL, phy_ctrl);
2125 if (ret_val)
2126 return ret_val;
2127
2128 udelay(1);
2129
2130 return ret_val;
2131}
2132
2133/**
2134 * e1000e_phy_hw_reset_generic - PHY hardware reset
2135 * @hw: pointer to the HW structure
2136 *
2137 * Verify the reset block is not blocking us from resetting. Acquire
2138 * semaphore (if necessary) and read/set/write the device control reset
2139 * bit in the PHY. Wait the appropriate delay time for the device to
Auke Kok489815c2008-02-21 15:11:07 -08002140 * reset and release the semaphore (if necessary).
Auke Kokbc7f75f2007-09-17 12:30:59 -07002141 **/
2142s32 e1000e_phy_hw_reset_generic(struct e1000_hw *hw)
2143{
2144 struct e1000_phy_info *phy = &hw->phy;
2145 s32 ret_val;
2146 u32 ctrl;
2147
Bruce Allan470a5422012-05-26 06:08:48 +00002148 if (phy->ops.check_reset_block) {
2149 ret_val = phy->ops.check_reset_block(hw);
2150 if (ret_val)
2151 return 0;
2152 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002153
Bruce Allan94d81862009-11-20 23:25:26 +00002154 ret_val = phy->ops.acquire(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002155 if (ret_val)
2156 return ret_val;
2157
2158 ctrl = er32(CTRL);
2159 ew32(CTRL, ctrl | E1000_CTRL_PHY_RST);
2160 e1e_flush();
2161
2162 udelay(phy->reset_delay_us);
2163
2164 ew32(CTRL, ctrl);
2165 e1e_flush();
2166
2167 udelay(150);
2168
Bruce Allan94d81862009-11-20 23:25:26 +00002169 phy->ops.release(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002170
Bruce Allan84c1bef2013-01-05 08:06:19 +00002171 return phy->ops.get_cfg_done(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002172}
2173
2174/**
Bruce Allanfe908492013-01-05 08:06:14 +00002175 * e1000e_get_cfg_done_generic - Generic configuration done
Auke Kokbc7f75f2007-09-17 12:30:59 -07002176 * @hw: pointer to the HW structure
2177 *
2178 * Generic function to wait 10 milli-seconds for configuration to complete
2179 * and return success.
2180 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00002181s32 e1000e_get_cfg_done_generic(struct e1000_hw __always_unused *hw)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002182{
2183 mdelay(10);
Bruce Allan3d3a1672012-02-23 03:13:18 +00002184
Auke Kokbc7f75f2007-09-17 12:30:59 -07002185 return 0;
2186}
2187
Bruce Allanf4187b52008-08-26 18:36:50 -07002188/**
2189 * e1000e_phy_init_script_igp3 - Inits the IGP3 PHY
2190 * @hw: pointer to the HW structure
2191 *
2192 * Initializes a Intel Gigabit PHY3 when an EEPROM is not present.
2193 **/
2194s32 e1000e_phy_init_script_igp3(struct e1000_hw *hw)
2195{
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002196 e_dbg("Running IGP 3 PHY init script\n");
Bruce Allanf4187b52008-08-26 18:36:50 -07002197
2198 /* PHY init IGP 3 */
2199 /* Enable rise/fall, 10-mode work in class-A */
2200 e1e_wphy(hw, 0x2F5B, 0x9018);
2201 /* Remove all caps from Replica path filter */
2202 e1e_wphy(hw, 0x2F52, 0x0000);
2203 /* Bias trimming for ADC, AFE and Driver (Default) */
2204 e1e_wphy(hw, 0x2FB1, 0x8B24);
2205 /* Increase Hybrid poly bias */
2206 e1e_wphy(hw, 0x2FB2, 0xF8F0);
2207 /* Add 4% to Tx amplitude in Gig mode */
2208 e1e_wphy(hw, 0x2010, 0x10B0);
2209 /* Disable trimming (TTT) */
2210 e1e_wphy(hw, 0x2011, 0x0000);
2211 /* Poly DC correction to 94.6% + 2% for all channels */
2212 e1e_wphy(hw, 0x20DD, 0x249A);
2213 /* ABS DC correction to 95.9% */
2214 e1e_wphy(hw, 0x20DE, 0x00D3);
2215 /* BG temp curve trim */
2216 e1e_wphy(hw, 0x28B4, 0x04CE);
2217 /* Increasing ADC OPAMP stage 1 currents to max */
2218 e1e_wphy(hw, 0x2F70, 0x29E4);
2219 /* Force 1000 ( required for enabling PHY regs configuration) */
2220 e1e_wphy(hw, 0x0000, 0x0140);
2221 /* Set upd_freq to 6 */
2222 e1e_wphy(hw, 0x1F30, 0x1606);
2223 /* Disable NPDFE */
2224 e1e_wphy(hw, 0x1F31, 0xB814);
2225 /* Disable adaptive fixed FFE (Default) */
2226 e1e_wphy(hw, 0x1F35, 0x002A);
2227 /* Enable FFE hysteresis */
2228 e1e_wphy(hw, 0x1F3E, 0x0067);
2229 /* Fixed FFE for short cable lengths */
2230 e1e_wphy(hw, 0x1F54, 0x0065);
2231 /* Fixed FFE for medium cable lengths */
2232 e1e_wphy(hw, 0x1F55, 0x002A);
2233 /* Fixed FFE for long cable lengths */
2234 e1e_wphy(hw, 0x1F56, 0x002A);
2235 /* Enable Adaptive Clip Threshold */
2236 e1e_wphy(hw, 0x1F72, 0x3FB0);
2237 /* AHT reset limit to 1 */
2238 e1e_wphy(hw, 0x1F76, 0xC0FF);
2239 /* Set AHT master delay to 127 msec */
2240 e1e_wphy(hw, 0x1F77, 0x1DEC);
2241 /* Set scan bits for AHT */
2242 e1e_wphy(hw, 0x1F78, 0xF9EF);
2243 /* Set AHT Preset bits */
2244 e1e_wphy(hw, 0x1F79, 0x0210);
2245 /* Change integ_factor of channel A to 3 */
2246 e1e_wphy(hw, 0x1895, 0x0003);
2247 /* Change prop_factor of channels BCD to 8 */
2248 e1e_wphy(hw, 0x1796, 0x0008);
2249 /* Change cg_icount + enable integbp for channels BCD */
2250 e1e_wphy(hw, 0x1798, 0xD008);
Bruce Allane921eb12012-11-28 09:28:37 +00002251 /* Change cg_icount + enable integbp + change prop_factor_master
Bruce Allanf4187b52008-08-26 18:36:50 -07002252 * to 8 for channel A
2253 */
2254 e1e_wphy(hw, 0x1898, 0xD918);
2255 /* Disable AHT in Slave mode on channel A */
2256 e1e_wphy(hw, 0x187A, 0x0800);
Bruce Allane921eb12012-11-28 09:28:37 +00002257 /* Enable LPLU and disable AN to 1000 in non-D0a states,
Bruce Allanf4187b52008-08-26 18:36:50 -07002258 * Enable SPD+B2B
2259 */
2260 e1e_wphy(hw, 0x0019, 0x008D);
2261 /* Enable restart AN on an1000_dis change */
2262 e1e_wphy(hw, 0x001B, 0x2080);
2263 /* Enable wh_fifo read clock in 10/100 modes */
2264 e1e_wphy(hw, 0x0014, 0x0045);
2265 /* Restart AN, Speed selection is 1000 */
2266 e1e_wphy(hw, 0x0000, 0x1340);
2267
2268 return 0;
2269}
2270
Auke Kokbc7f75f2007-09-17 12:30:59 -07002271/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002272 * e1000e_get_phy_type_from_id - Get PHY type from id
2273 * @phy_id: phy_id read from the phy
2274 *
2275 * Returns the phy type from the id.
2276 **/
2277enum e1000_phy_type e1000e_get_phy_type_from_id(u32 phy_id)
2278{
2279 enum e1000_phy_type phy_type = e1000_phy_unknown;
2280
2281 switch (phy_id) {
2282 case M88E1000_I_PHY_ID:
2283 case M88E1000_E_PHY_ID:
2284 case M88E1111_I_PHY_ID:
2285 case M88E1011_I_PHY_ID:
2286 phy_type = e1000_phy_m88;
2287 break;
2288 case IGP01E1000_I_PHY_ID: /* IGP 1 & 2 share this */
2289 phy_type = e1000_phy_igp_2;
2290 break;
2291 case GG82563_E_PHY_ID:
2292 phy_type = e1000_phy_gg82563;
2293 break;
2294 case IGP03E1000_E_PHY_ID:
2295 phy_type = e1000_phy_igp_3;
2296 break;
2297 case IFE_E_PHY_ID:
2298 case IFE_PLUS_E_PHY_ID:
2299 case IFE_C_E_PHY_ID:
2300 phy_type = e1000_phy_ife;
2301 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002302 case BME1000_E_PHY_ID:
2303 case BME1000_E_PHY_ID_R2:
2304 phy_type = e1000_phy_bm;
2305 break;
Bruce Allana4f58f52009-06-02 11:29:18 +00002306 case I82578_E_PHY_ID:
2307 phy_type = e1000_phy_82578;
2308 break;
2309 case I82577_E_PHY_ID:
2310 phy_type = e1000_phy_82577;
2311 break;
Bruce Alland3738bb2010-06-16 13:27:28 +00002312 case I82579_E_PHY_ID:
2313 phy_type = e1000_phy_82579;
2314 break;
Bruce Allan2fbe4522012-04-19 03:21:47 +00002315 case I217_E_PHY_ID:
2316 phy_type = e1000_phy_i217;
2317 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002318 default:
2319 phy_type = e1000_phy_unknown;
2320 break;
2321 }
2322 return phy_type;
2323}
2324
2325/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002326 * e1000e_determine_phy_address - Determines PHY address.
2327 * @hw: pointer to the HW structure
2328 *
2329 * This uses a trial and error method to loop through possible PHY
2330 * addresses. It tests each by reading the PHY ID registers and
2331 * checking for a match.
2332 **/
2333s32 e1000e_determine_phy_address(struct e1000_hw *hw)
2334{
Bruce Allan5eb6f3c2009-12-02 17:02:43 +00002335 u32 phy_addr = 0;
2336 u32 i;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002337 enum e1000_phy_type phy_type = e1000_phy_unknown;
2338
Bruce Allan5eb6f3c2009-12-02 17:02:43 +00002339 hw->phy.id = phy_type;
2340
2341 for (phy_addr = 0; phy_addr < E1000_MAX_PHY_ADDR; phy_addr++) {
2342 hw->phy.addr = phy_addr;
2343 i = 0;
2344
2345 do {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002346 e1000e_get_phy_id(hw);
2347 phy_type = e1000e_get_phy_type_from_id(hw->phy.id);
2348
Bruce Allane921eb12012-11-28 09:28:37 +00002349 /* If phy_type is valid, break - we found our
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002350 * PHY address
2351 */
Bruce Allan5015e532012-02-08 02:55:56 +00002352 if (phy_type != e1000_phy_unknown)
2353 return 0;
2354
Bruce Allan1bba4382011-03-19 00:27:20 +00002355 usleep_range(1000, 2000);
Bruce Allan5eb6f3c2009-12-02 17:02:43 +00002356 i++;
2357 } while (i < 10);
2358 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002359
Bruce Allan5015e532012-02-08 02:55:56 +00002360 return -E1000_ERR_PHY_TYPE;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002361}
2362
2363/**
2364 * e1000_get_phy_addr_for_bm_page - Retrieve PHY page address
2365 * @page: page to access
2366 *
2367 * Returns the phy address for the page requested.
2368 **/
2369static u32 e1000_get_phy_addr_for_bm_page(u32 page, u32 reg)
2370{
2371 u32 phy_addr = 2;
2372
2373 if ((page >= 768) || (page == 0 && reg == 25) || (reg == 31))
2374 phy_addr = 1;
2375
2376 return phy_addr;
2377}
2378
2379/**
2380 * e1000e_write_phy_reg_bm - Write BM PHY register
2381 * @hw: pointer to the HW structure
2382 * @offset: register offset to write to
2383 * @data: data to write at register offset
2384 *
2385 * Acquires semaphore, if necessary, then writes the data to PHY register
2386 * at the offset. Release any acquired semaphores before exiting.
2387 **/
2388s32 e1000e_write_phy_reg_bm(struct e1000_hw *hw, u32 offset, u16 data)
2389{
2390 s32 ret_val;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002391 u32 page = offset >> IGP_PAGE_SHIFT;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002392
Bruce Allan94d81862009-11-20 23:25:26 +00002393 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002394 if (ret_val)
2395 return ret_val;
2396
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002397 /* Page 800 works differently than the rest so it has its own func */
2398 if (page == BM_WUC_PAGE) {
2399 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, &data,
Bruce Allan2b6b1682011-05-13 07:20:09 +00002400 false, false);
Bruce Allan75ce1532012-02-08 02:54:48 +00002401 goto release;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002402 }
2403
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002404 hw->phy.addr = e1000_get_phy_addr_for_bm_page(page, offset);
2405
2406 if (offset > MAX_PHY_MULTI_PAGE_REG) {
Bruce Allan90da0662011-01-06 07:02:53 +00002407 u32 page_shift, page_select;
2408
Bruce Allane921eb12012-11-28 09:28:37 +00002409 /* Page select is register 31 for phy address 1 and 22 for
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002410 * phy address 2 and 3. Page select is shifted only for
2411 * phy address 1.
2412 */
2413 if (hw->phy.addr == 1) {
2414 page_shift = IGP_PAGE_SHIFT;
2415 page_select = IGP01E1000_PHY_PAGE_SELECT;
2416 } else {
2417 page_shift = 0;
2418 page_select = BM_PHY_PAGE_SELECT;
2419 }
2420
2421 /* Page is shifted left, PHY expects (page x 32) */
2422 ret_val = e1000e_write_phy_reg_mdic(hw, page_select,
2423 (page << page_shift));
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002424 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00002425 goto release;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002426 }
2427
2428 ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
2429 data);
2430
Bruce Allan75ce1532012-02-08 02:54:48 +00002431release:
Bruce Allan94d81862009-11-20 23:25:26 +00002432 hw->phy.ops.release(hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002433 return ret_val;
2434}
2435
2436/**
2437 * e1000e_read_phy_reg_bm - Read BM PHY register
2438 * @hw: pointer to the HW structure
2439 * @offset: register offset to be read
2440 * @data: pointer to the read data
2441 *
2442 * Acquires semaphore, if necessary, then reads the PHY register at offset
2443 * and storing the retrieved information in data. Release any acquired
2444 * semaphores before exiting.
2445 **/
2446s32 e1000e_read_phy_reg_bm(struct e1000_hw *hw, u32 offset, u16 *data)
2447{
2448 s32 ret_val;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002449 u32 page = offset >> IGP_PAGE_SHIFT;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002450
Bruce Allan94d81862009-11-20 23:25:26 +00002451 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002452 if (ret_val)
2453 return ret_val;
2454
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002455 /* Page 800 works differently than the rest so it has its own func */
2456 if (page == BM_WUC_PAGE) {
2457 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, data,
Bruce Allan2b6b1682011-05-13 07:20:09 +00002458 true, false);
Bruce Allan75ce1532012-02-08 02:54:48 +00002459 goto release;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002460 }
2461
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002462 hw->phy.addr = e1000_get_phy_addr_for_bm_page(page, offset);
2463
2464 if (offset > MAX_PHY_MULTI_PAGE_REG) {
Bruce Allan90da0662011-01-06 07:02:53 +00002465 u32 page_shift, page_select;
2466
Bruce Allane921eb12012-11-28 09:28:37 +00002467 /* Page select is register 31 for phy address 1 and 22 for
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002468 * phy address 2 and 3. Page select is shifted only for
2469 * phy address 1.
2470 */
2471 if (hw->phy.addr == 1) {
2472 page_shift = IGP_PAGE_SHIFT;
2473 page_select = IGP01E1000_PHY_PAGE_SELECT;
2474 } else {
2475 page_shift = 0;
2476 page_select = BM_PHY_PAGE_SELECT;
2477 }
2478
2479 /* Page is shifted left, PHY expects (page x 32) */
2480 ret_val = e1000e_write_phy_reg_mdic(hw, page_select,
2481 (page << page_shift));
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002482 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00002483 goto release;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002484 }
2485
2486 ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
2487 data);
Bruce Allan75ce1532012-02-08 02:54:48 +00002488release:
Bruce Allan94d81862009-11-20 23:25:26 +00002489 hw->phy.ops.release(hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002490 return ret_val;
2491}
2492
2493/**
Bruce Allan4662e822008-08-26 18:37:06 -07002494 * e1000e_read_phy_reg_bm2 - Read BM PHY register
2495 * @hw: pointer to the HW structure
2496 * @offset: register offset to be read
2497 * @data: pointer to the read data
2498 *
2499 * Acquires semaphore, if necessary, then reads the PHY register at offset
2500 * and storing the retrieved information in data. Release any acquired
2501 * semaphores before exiting.
2502 **/
2503s32 e1000e_read_phy_reg_bm2(struct e1000_hw *hw, u32 offset, u16 *data)
2504{
2505 s32 ret_val;
2506 u16 page = (u16)(offset >> IGP_PAGE_SHIFT);
2507
Bruce Allan94d81862009-11-20 23:25:26 +00002508 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002509 if (ret_val)
2510 return ret_val;
2511
Bruce Allan4662e822008-08-26 18:37:06 -07002512 /* Page 800 works differently than the rest so it has its own func */
2513 if (page == BM_WUC_PAGE) {
2514 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, data,
Bruce Allan2b6b1682011-05-13 07:20:09 +00002515 true, false);
Bruce Allan75ce1532012-02-08 02:54:48 +00002516 goto release;
Bruce Allan4662e822008-08-26 18:37:06 -07002517 }
2518
Bruce Allan4662e822008-08-26 18:37:06 -07002519 hw->phy.addr = 1;
2520
2521 if (offset > MAX_PHY_MULTI_PAGE_REG) {
2522
2523 /* Page is shifted left, PHY expects (page x 32) */
2524 ret_val = e1000e_write_phy_reg_mdic(hw, BM_PHY_PAGE_SELECT,
2525 page);
2526
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002527 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00002528 goto release;
Bruce Allan4662e822008-08-26 18:37:06 -07002529 }
2530
2531 ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
2532 data);
Bruce Allan75ce1532012-02-08 02:54:48 +00002533release:
Bruce Allan94d81862009-11-20 23:25:26 +00002534 hw->phy.ops.release(hw);
Bruce Allan4662e822008-08-26 18:37:06 -07002535 return ret_val;
2536}
2537
2538/**
2539 * e1000e_write_phy_reg_bm2 - Write BM PHY register
2540 * @hw: pointer to the HW structure
2541 * @offset: register offset to write to
2542 * @data: data to write at register offset
2543 *
2544 * Acquires semaphore, if necessary, then writes the data to PHY register
2545 * at the offset. Release any acquired semaphores before exiting.
2546 **/
2547s32 e1000e_write_phy_reg_bm2(struct e1000_hw *hw, u32 offset, u16 data)
2548{
2549 s32 ret_val;
2550 u16 page = (u16)(offset >> IGP_PAGE_SHIFT);
2551
Bruce Allan94d81862009-11-20 23:25:26 +00002552 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002553 if (ret_val)
2554 return ret_val;
2555
Bruce Allan4662e822008-08-26 18:37:06 -07002556 /* Page 800 works differently than the rest so it has its own func */
2557 if (page == BM_WUC_PAGE) {
2558 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, &data,
Bruce Allan2b6b1682011-05-13 07:20:09 +00002559 false, false);
Bruce Allan75ce1532012-02-08 02:54:48 +00002560 goto release;
Bruce Allan4662e822008-08-26 18:37:06 -07002561 }
2562
Bruce Allan4662e822008-08-26 18:37:06 -07002563 hw->phy.addr = 1;
2564
2565 if (offset > MAX_PHY_MULTI_PAGE_REG) {
2566 /* Page is shifted left, PHY expects (page x 32) */
2567 ret_val = e1000e_write_phy_reg_mdic(hw, BM_PHY_PAGE_SELECT,
2568 page);
2569
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002570 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00002571 goto release;
Bruce Allan4662e822008-08-26 18:37:06 -07002572 }
2573
2574 ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
2575 data);
2576
Bruce Allan75ce1532012-02-08 02:54:48 +00002577release:
Bruce Allan94d81862009-11-20 23:25:26 +00002578 hw->phy.ops.release(hw);
Bruce Allan4662e822008-08-26 18:37:06 -07002579 return ret_val;
2580}
2581
2582/**
Bruce Allan2b6b1682011-05-13 07:20:09 +00002583 * e1000_enable_phy_wakeup_reg_access_bm - enable access to BM wakeup registers
2584 * @hw: pointer to the HW structure
2585 * @phy_reg: pointer to store original contents of BM_WUC_ENABLE_REG
2586 *
2587 * Assumes semaphore already acquired and phy_reg points to a valid memory
2588 * address to store contents of the BM_WUC_ENABLE_REG register.
2589 **/
2590s32 e1000_enable_phy_wakeup_reg_access_bm(struct e1000_hw *hw, u16 *phy_reg)
2591{
2592 s32 ret_val;
2593 u16 temp;
2594
2595 /* All page select, port ctrl and wakeup registers use phy address 1 */
2596 hw->phy.addr = 1;
2597
2598 /* Select Port Control Registers page */
2599 ret_val = e1000_set_page_igp(hw, (BM_PORT_CTRL_PAGE << IGP_PAGE_SHIFT));
2600 if (ret_val) {
2601 e_dbg("Could not set Port Control page\n");
Bruce Allan5015e532012-02-08 02:55:56 +00002602 return ret_val;
Bruce Allan2b6b1682011-05-13 07:20:09 +00002603 }
2604
2605 ret_val = e1000e_read_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, phy_reg);
2606 if (ret_val) {
2607 e_dbg("Could not read PHY register %d.%d\n",
2608 BM_PORT_CTRL_PAGE, BM_WUC_ENABLE_REG);
Bruce Allan5015e532012-02-08 02:55:56 +00002609 return ret_val;
Bruce Allan2b6b1682011-05-13 07:20:09 +00002610 }
2611
Bruce Allane921eb12012-11-28 09:28:37 +00002612 /* Enable both PHY wakeup mode and Wakeup register page writes.
Bruce Allan2b6b1682011-05-13 07:20:09 +00002613 * Prevent a power state change by disabling ME and Host PHY wakeup.
2614 */
2615 temp = *phy_reg;
2616 temp |= BM_WUC_ENABLE_BIT;
2617 temp &= ~(BM_WUC_ME_WU_BIT | BM_WUC_HOST_WU_BIT);
2618
2619 ret_val = e1000e_write_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, temp);
2620 if (ret_val) {
2621 e_dbg("Could not write PHY register %d.%d\n",
2622 BM_PORT_CTRL_PAGE, BM_WUC_ENABLE_REG);
Bruce Allan5015e532012-02-08 02:55:56 +00002623 return ret_val;
Bruce Allan2b6b1682011-05-13 07:20:09 +00002624 }
2625
Bruce Allane921eb12012-11-28 09:28:37 +00002626 /* Select Host Wakeup Registers page - caller now able to write
Bruce Allan5015e532012-02-08 02:55:56 +00002627 * registers on the Wakeup registers page
2628 */
2629 return e1000_set_page_igp(hw, (BM_WUC_PAGE << IGP_PAGE_SHIFT));
Bruce Allan2b6b1682011-05-13 07:20:09 +00002630}
2631
2632/**
2633 * e1000_disable_phy_wakeup_reg_access_bm - disable access to BM wakeup regs
2634 * @hw: pointer to the HW structure
2635 * @phy_reg: pointer to original contents of BM_WUC_ENABLE_REG
2636 *
2637 * Restore BM_WUC_ENABLE_REG to its original value.
2638 *
2639 * Assumes semaphore already acquired and *phy_reg is the contents of the
2640 * BM_WUC_ENABLE_REG before register(s) on BM_WUC_PAGE were accessed by
2641 * caller.
2642 **/
2643s32 e1000_disable_phy_wakeup_reg_access_bm(struct e1000_hw *hw, u16 *phy_reg)
2644{
Bruce Allan70806a72013-01-05 05:08:37 +00002645 s32 ret_val;
Bruce Allan2b6b1682011-05-13 07:20:09 +00002646
2647 /* Select Port Control Registers page */
2648 ret_val = e1000_set_page_igp(hw, (BM_PORT_CTRL_PAGE << IGP_PAGE_SHIFT));
2649 if (ret_val) {
2650 e_dbg("Could not set Port Control page\n");
Bruce Allan5015e532012-02-08 02:55:56 +00002651 return ret_val;
Bruce Allan2b6b1682011-05-13 07:20:09 +00002652 }
2653
2654 /* Restore 769.17 to its original value */
2655 ret_val = e1000e_write_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, *phy_reg);
2656 if (ret_val)
2657 e_dbg("Could not restore PHY register %d.%d\n",
2658 BM_PORT_CTRL_PAGE, BM_WUC_ENABLE_REG);
Bruce Allan5015e532012-02-08 02:55:56 +00002659
Bruce Allan2b6b1682011-05-13 07:20:09 +00002660 return ret_val;
2661}
2662
2663/**
2664 * e1000_access_phy_wakeup_reg_bm - Read/write BM PHY wakeup register
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002665 * @hw: pointer to the HW structure
2666 * @offset: register offset to be read or written
2667 * @data: pointer to the data to read or write
2668 * @read: determines if operation is read or write
Bruce Allan2b6b1682011-05-13 07:20:09 +00002669 * @page_set: BM_WUC_PAGE already set and access enabled
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002670 *
Bruce Allan2b6b1682011-05-13 07:20:09 +00002671 * Read the PHY register at offset and store the retrieved information in
2672 * data, or write data to PHY register at offset. Note the procedure to
2673 * access the PHY wakeup registers is different than reading the other PHY
2674 * registers. It works as such:
2675 * 1) Set 769.17.2 (page 769, register 17, bit 2) = 1
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002676 * 2) Set page to 800 for host (801 if we were manageability)
2677 * 3) Write the address using the address opcode (0x11)
2678 * 4) Read or write the data using the data opcode (0x12)
Bruce Allan2b6b1682011-05-13 07:20:09 +00002679 * 5) Restore 769.17.2 to its original value
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002680 *
Bruce Allan2b6b1682011-05-13 07:20:09 +00002681 * Steps 1 and 2 are done by e1000_enable_phy_wakeup_reg_access_bm() and
2682 * step 5 is done by e1000_disable_phy_wakeup_reg_access_bm().
2683 *
2684 * Assumes semaphore is already acquired. When page_set==true, assumes
2685 * the PHY page is set to BM_WUC_PAGE (i.e. a function in the call stack
2686 * is responsible for calls to e1000_[enable|disable]_phy_wakeup_reg_bm()).
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002687 **/
2688static s32 e1000_access_phy_wakeup_reg_bm(struct e1000_hw *hw, u32 offset,
Bruce Allan2b6b1682011-05-13 07:20:09 +00002689 u16 *data, bool read, bool page_set)
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002690{
2691 s32 ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00002692 u16 reg = BM_PHY_REG_NUM(offset);
Bruce Allan2b6b1682011-05-13 07:20:09 +00002693 u16 page = BM_PHY_REG_PAGE(offset);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002694 u16 phy_reg = 0;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002695
Bruce Allan2b6b1682011-05-13 07:20:09 +00002696 /* Gig must be disabled for MDIO accesses to Host Wakeup reg page */
Bruce Allana4f58f52009-06-02 11:29:18 +00002697 if ((hw->mac.type == e1000_pchlan) &&
Bruce Allan2b6b1682011-05-13 07:20:09 +00002698 (!(er32(PHY_CTRL) & E1000_PHY_CTRL_GBE_DISABLE)))
2699 e_dbg("Attempting to access page %d while gig enabled.\n",
2700 page);
Bruce Allana4f58f52009-06-02 11:29:18 +00002701
Bruce Allan2b6b1682011-05-13 07:20:09 +00002702 if (!page_set) {
2703 /* Enable access to PHY wakeup registers */
2704 ret_val = e1000_enable_phy_wakeup_reg_access_bm(hw, &phy_reg);
2705 if (ret_val) {
2706 e_dbg("Could not enable PHY wakeup reg access\n");
Bruce Allan5015e532012-02-08 02:55:56 +00002707 return ret_val;
Bruce Allan2b6b1682011-05-13 07:20:09 +00002708 }
Bruce Allan9b71b412009-12-01 15:53:07 +00002709 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002710
Bruce Allan2b6b1682011-05-13 07:20:09 +00002711 e_dbg("Accessing PHY page %d reg 0x%x\n", page, reg);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002712
Bruce Allan2b6b1682011-05-13 07:20:09 +00002713 /* Write the Wakeup register page offset value using opcode 0x11 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002714 ret_val = e1000e_write_phy_reg_mdic(hw, BM_WUC_ADDRESS_OPCODE, reg);
Bruce Allan9b71b412009-12-01 15:53:07 +00002715 if (ret_val) {
Bruce Allan2b6b1682011-05-13 07:20:09 +00002716 e_dbg("Could not write address opcode to page %d\n", page);
Bruce Allan5015e532012-02-08 02:55:56 +00002717 return ret_val;
Bruce Allan9b71b412009-12-01 15:53:07 +00002718 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002719
2720 if (read) {
Bruce Allan2b6b1682011-05-13 07:20:09 +00002721 /* Read the Wakeup register page value using opcode 0x12 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002722 ret_val = e1000e_read_phy_reg_mdic(hw, BM_WUC_DATA_OPCODE,
2723 data);
2724 } else {
Bruce Allan2b6b1682011-05-13 07:20:09 +00002725 /* Write the Wakeup register page value using opcode 0x12 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002726 ret_val = e1000e_write_phy_reg_mdic(hw, BM_WUC_DATA_OPCODE,
2727 *data);
2728 }
2729
Bruce Allan9b71b412009-12-01 15:53:07 +00002730 if (ret_val) {
Bruce Allan2b6b1682011-05-13 07:20:09 +00002731 e_dbg("Could not access PHY reg %d.%d\n", page, reg);
Bruce Allan5015e532012-02-08 02:55:56 +00002732 return ret_val;
Bruce Allan9b71b412009-12-01 15:53:07 +00002733 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002734
Bruce Allan2b6b1682011-05-13 07:20:09 +00002735 if (!page_set)
2736 ret_val = e1000_disable_phy_wakeup_reg_access_bm(hw, &phy_reg);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002737
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002738 return ret_val;
2739}
2740
2741/**
Bruce Allan17f208d2009-12-01 15:47:22 +00002742 * e1000_power_up_phy_copper - Restore copper link in case of PHY power down
2743 * @hw: pointer to the HW structure
2744 *
2745 * In the case of a PHY power down to save power, or to turn off link during a
2746 * driver unload, or wake on lan is not enabled, restore the link to previous
2747 * settings.
2748 **/
2749void e1000_power_up_phy_copper(struct e1000_hw *hw)
2750{
2751 u16 mii_reg = 0;
2752
2753 /* The PHY will retain its settings across a power down/up cycle */
2754 e1e_rphy(hw, PHY_CONTROL, &mii_reg);
2755 mii_reg &= ~MII_CR_POWER_DOWN;
2756 e1e_wphy(hw, PHY_CONTROL, mii_reg);
2757}
2758
2759/**
2760 * e1000_power_down_phy_copper - Restore copper link in case of PHY power down
2761 * @hw: pointer to the HW structure
2762 *
2763 * In the case of a PHY power down to save power, or to turn off link during a
2764 * driver unload, or wake on lan is not enabled, restore the link to previous
2765 * settings.
2766 **/
2767void e1000_power_down_phy_copper(struct e1000_hw *hw)
2768{
2769 u16 mii_reg = 0;
2770
2771 /* The PHY will retain its settings across a power down/up cycle */
2772 e1e_rphy(hw, PHY_CONTROL, &mii_reg);
2773 mii_reg |= MII_CR_POWER_DOWN;
2774 e1e_wphy(hw, PHY_CONTROL, mii_reg);
Bruce Allan1bba4382011-03-19 00:27:20 +00002775 usleep_range(1000, 2000);
Bruce Allan17f208d2009-12-01 15:47:22 +00002776}
2777
2778/**
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002779 * __e1000_read_phy_reg_hv - Read HV PHY register
Bruce Allana4f58f52009-06-02 11:29:18 +00002780 * @hw: pointer to the HW structure
2781 * @offset: register offset to be read
2782 * @data: pointer to the read data
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002783 * @locked: semaphore has already been acquired or not
Bruce Allana4f58f52009-06-02 11:29:18 +00002784 *
2785 * Acquires semaphore, if necessary, then reads the PHY register at offset
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002786 * and stores the retrieved information in data. Release any acquired
Bruce Allana4f58f52009-06-02 11:29:18 +00002787 * semaphore before exiting.
2788 **/
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002789static s32 __e1000_read_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 *data,
Bruce Allan2b6b1682011-05-13 07:20:09 +00002790 bool locked, bool page_set)
Bruce Allana4f58f52009-06-02 11:29:18 +00002791{
2792 s32 ret_val;
2793 u16 page = BM_PHY_REG_PAGE(offset);
2794 u16 reg = BM_PHY_REG_NUM(offset);
Bruce Allan2b6b1682011-05-13 07:20:09 +00002795 u32 phy_addr = hw->phy.addr = e1000_get_phy_addr_for_hv_page(page);
Bruce Allana4f58f52009-06-02 11:29:18 +00002796
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002797 if (!locked) {
Bruce Allan94d81862009-11-20 23:25:26 +00002798 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002799 if (ret_val)
2800 return ret_val;
2801 }
2802
Bruce Allana4f58f52009-06-02 11:29:18 +00002803 /* Page 800 works differently than the rest so it has its own func */
2804 if (page == BM_WUC_PAGE) {
Bruce Allan2b6b1682011-05-13 07:20:09 +00002805 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, data,
2806 true, page_set);
Bruce Allana4f58f52009-06-02 11:29:18 +00002807 goto out;
2808 }
2809
2810 if (page > 0 && page < HV_INTC_FC_PAGE_START) {
2811 ret_val = e1000_access_phy_debug_regs_hv(hw, offset,
2812 data, true);
2813 goto out;
2814 }
2815
Bruce Allan2b6b1682011-05-13 07:20:09 +00002816 if (!page_set) {
2817 if (page == HV_INTC_FC_PAGE_START)
2818 page = 0;
Bruce Allana4f58f52009-06-02 11:29:18 +00002819
Bruce Allan2b6b1682011-05-13 07:20:09 +00002820 if (reg > MAX_PHY_MULTI_PAGE_REG) {
2821 /* Page is shifted left, PHY expects (page x 32) */
2822 ret_val = e1000_set_page_igp(hw,
2823 (page << IGP_PAGE_SHIFT));
Bruce Allana4f58f52009-06-02 11:29:18 +00002824
Bruce Allan2b6b1682011-05-13 07:20:09 +00002825 hw->phy.addr = phy_addr;
Bruce Allana4f58f52009-06-02 11:29:18 +00002826
Bruce Allan2b6b1682011-05-13 07:20:09 +00002827 if (ret_val)
2828 goto out;
2829 }
Bruce Allana4f58f52009-06-02 11:29:18 +00002830 }
2831
Bruce Allan2b6b1682011-05-13 07:20:09 +00002832 e_dbg("reading PHY page %d (or 0x%x shifted) reg 0x%x\n", page,
2833 page << IGP_PAGE_SHIFT, reg);
2834
Bruce Allana4f58f52009-06-02 11:29:18 +00002835 ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & reg,
2836 data);
Bruce Allana4f58f52009-06-02 11:29:18 +00002837out:
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002838 if (!locked)
Bruce Allan94d81862009-11-20 23:25:26 +00002839 hw->phy.ops.release(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002840
Bruce Allana4f58f52009-06-02 11:29:18 +00002841 return ret_val;
2842}
2843
2844/**
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002845 * e1000_read_phy_reg_hv - Read HV PHY register
2846 * @hw: pointer to the HW structure
2847 * @offset: register offset to be read
2848 * @data: pointer to the read data
2849 *
2850 * Acquires semaphore then reads the PHY register at offset and stores
2851 * the retrieved information in data. Release the acquired semaphore
2852 * before exiting.
2853 **/
2854s32 e1000_read_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 *data)
2855{
Bruce Allan2b6b1682011-05-13 07:20:09 +00002856 return __e1000_read_phy_reg_hv(hw, offset, data, false, false);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002857}
2858
2859/**
2860 * e1000_read_phy_reg_hv_locked - Read HV PHY register
2861 * @hw: pointer to the HW structure
2862 * @offset: register offset to be read
2863 * @data: pointer to the read data
2864 *
2865 * Reads the PHY register at offset and stores the retrieved information
2866 * in data. Assumes semaphore already acquired.
2867 **/
2868s32 e1000_read_phy_reg_hv_locked(struct e1000_hw *hw, u32 offset, u16 *data)
2869{
Bruce Allan2b6b1682011-05-13 07:20:09 +00002870 return __e1000_read_phy_reg_hv(hw, offset, data, true, false);
2871}
2872
2873/**
2874 * e1000_read_phy_reg_page_hv - Read HV PHY register
2875 * @hw: pointer to the HW structure
2876 * @offset: register offset to write to
2877 * @data: data to write at register offset
2878 *
2879 * Reads the PHY register at offset and stores the retrieved information
2880 * in data. Assumes semaphore already acquired and page already set.
2881 **/
2882s32 e1000_read_phy_reg_page_hv(struct e1000_hw *hw, u32 offset, u16 *data)
2883{
2884 return __e1000_read_phy_reg_hv(hw, offset, data, true, true);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002885}
2886
2887/**
2888 * __e1000_write_phy_reg_hv - Write HV PHY register
Bruce Allana4f58f52009-06-02 11:29:18 +00002889 * @hw: pointer to the HW structure
2890 * @offset: register offset to write to
2891 * @data: data to write at register offset
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002892 * @locked: semaphore has already been acquired or not
Bruce Allana4f58f52009-06-02 11:29:18 +00002893 *
2894 * Acquires semaphore, if necessary, then writes the data to PHY register
2895 * at the offset. Release any acquired semaphores before exiting.
2896 **/
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002897static s32 __e1000_write_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 data,
Bruce Allan2b6b1682011-05-13 07:20:09 +00002898 bool locked, bool page_set)
Bruce Allana4f58f52009-06-02 11:29:18 +00002899{
2900 s32 ret_val;
2901 u16 page = BM_PHY_REG_PAGE(offset);
2902 u16 reg = BM_PHY_REG_NUM(offset);
Bruce Allan2b6b1682011-05-13 07:20:09 +00002903 u32 phy_addr = hw->phy.addr = e1000_get_phy_addr_for_hv_page(page);
Bruce Allana4f58f52009-06-02 11:29:18 +00002904
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002905 if (!locked) {
Bruce Allan94d81862009-11-20 23:25:26 +00002906 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002907 if (ret_val)
2908 return ret_val;
2909 }
2910
Bruce Allana4f58f52009-06-02 11:29:18 +00002911 /* Page 800 works differently than the rest so it has its own func */
2912 if (page == BM_WUC_PAGE) {
Bruce Allan2b6b1682011-05-13 07:20:09 +00002913 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, &data,
2914 false, page_set);
Bruce Allana4f58f52009-06-02 11:29:18 +00002915 goto out;
2916 }
2917
2918 if (page > 0 && page < HV_INTC_FC_PAGE_START) {
2919 ret_val = e1000_access_phy_debug_regs_hv(hw, offset,
2920 &data, false);
2921 goto out;
2922 }
2923
Bruce Allan2b6b1682011-05-13 07:20:09 +00002924 if (!page_set) {
2925 if (page == HV_INTC_FC_PAGE_START)
2926 page = 0;
Bruce Allana4f58f52009-06-02 11:29:18 +00002927
Bruce Allane921eb12012-11-28 09:28:37 +00002928 /* Workaround MDIO accesses being disabled after entering IEEE
Bruce Allan2b6b1682011-05-13 07:20:09 +00002929 * Power Down (when bit 11 of the PHY Control register is set)
2930 */
2931 if ((hw->phy.type == e1000_phy_82578) &&
2932 (hw->phy.revision >= 1) &&
2933 (hw->phy.addr == 2) &&
Bruce Allan04499ec2012-04-13 00:08:31 +00002934 !(MAX_PHY_REG_ADDRESS & reg) && (data & (1 << 11))) {
Bruce Allan2b6b1682011-05-13 07:20:09 +00002935 u16 data2 = 0x7EFF;
2936 ret_val = e1000_access_phy_debug_regs_hv(hw,
2937 (1 << 6) | 0x3,
2938 &data2, false);
2939 if (ret_val)
2940 goto out;
2941 }
Bruce Allana4f58f52009-06-02 11:29:18 +00002942
Bruce Allan2b6b1682011-05-13 07:20:09 +00002943 if (reg > MAX_PHY_MULTI_PAGE_REG) {
2944 /* Page is shifted left, PHY expects (page x 32) */
2945 ret_val = e1000_set_page_igp(hw,
2946 (page << IGP_PAGE_SHIFT));
2947
2948 hw->phy.addr = phy_addr;
2949
2950 if (ret_val)
2951 goto out;
2952 }
Bruce Allana4f58f52009-06-02 11:29:18 +00002953 }
2954
Bruce Allan2b6b1682011-05-13 07:20:09 +00002955 e_dbg("writing PHY page %d (or 0x%x shifted) reg 0x%x\n", page,
2956 page << IGP_PAGE_SHIFT, reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00002957
2958 ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & reg,
2959 data);
Bruce Allana4f58f52009-06-02 11:29:18 +00002960
2961out:
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002962 if (!locked)
Bruce Allan94d81862009-11-20 23:25:26 +00002963 hw->phy.ops.release(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002964
Bruce Allana4f58f52009-06-02 11:29:18 +00002965 return ret_val;
2966}
2967
2968/**
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002969 * e1000_write_phy_reg_hv - Write HV PHY register
2970 * @hw: pointer to the HW structure
2971 * @offset: register offset to write to
2972 * @data: data to write at register offset
2973 *
2974 * Acquires semaphore then writes the data to PHY register at the offset.
2975 * Release the acquired semaphores before exiting.
2976 **/
2977s32 e1000_write_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 data)
2978{
Bruce Allan2b6b1682011-05-13 07:20:09 +00002979 return __e1000_write_phy_reg_hv(hw, offset, data, false, false);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002980}
2981
2982/**
2983 * e1000_write_phy_reg_hv_locked - Write HV PHY register
2984 * @hw: pointer to the HW structure
2985 * @offset: register offset to write to
2986 * @data: data to write at register offset
2987 *
2988 * Writes the data to PHY register at the offset. Assumes semaphore
2989 * already acquired.
2990 **/
2991s32 e1000_write_phy_reg_hv_locked(struct e1000_hw *hw, u32 offset, u16 data)
2992{
Bruce Allan2b6b1682011-05-13 07:20:09 +00002993 return __e1000_write_phy_reg_hv(hw, offset, data, true, false);
2994}
2995
2996/**
2997 * e1000_write_phy_reg_page_hv - Write HV PHY register
2998 * @hw: pointer to the HW structure
2999 * @offset: register offset to write to
3000 * @data: data to write at register offset
3001 *
3002 * Writes the data to PHY register at the offset. Assumes semaphore
3003 * already acquired and page already set.
3004 **/
3005s32 e1000_write_phy_reg_page_hv(struct e1000_hw *hw, u32 offset, u16 data)
3006{
3007 return __e1000_write_phy_reg_hv(hw, offset, data, true, true);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00003008}
3009
3010/**
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04003011 * e1000_get_phy_addr_for_hv_page - Get PHY address based on page
Bruce Allana4f58f52009-06-02 11:29:18 +00003012 * @page: page to be accessed
3013 **/
3014static u32 e1000_get_phy_addr_for_hv_page(u32 page)
3015{
3016 u32 phy_addr = 2;
3017
3018 if (page >= HV_INTC_FC_PAGE_START)
3019 phy_addr = 1;
3020
3021 return phy_addr;
3022}
3023
3024/**
3025 * e1000_access_phy_debug_regs_hv - Read HV PHY vendor specific high registers
3026 * @hw: pointer to the HW structure
3027 * @offset: register offset to be read or written
3028 * @data: pointer to the data to be read or written
Bruce Allan2b6b1682011-05-13 07:20:09 +00003029 * @read: determines if operation is read or write
Bruce Allana4f58f52009-06-02 11:29:18 +00003030 *
Bruce Allan5ccdcec2009-10-26 11:24:02 +00003031 * Reads the PHY register at offset and stores the retreived information
3032 * in data. Assumes semaphore already acquired. Note that the procedure
Bruce Allan2b6b1682011-05-13 07:20:09 +00003033 * to access these regs uses the address port and data port to read/write.
3034 * These accesses done with PHY address 2 and without using pages.
Bruce Allana4f58f52009-06-02 11:29:18 +00003035 **/
3036static s32 e1000_access_phy_debug_regs_hv(struct e1000_hw *hw, u32 offset,
3037 u16 *data, bool read)
3038{
3039 s32 ret_val;
Bruce Allan70806a72013-01-05 05:08:37 +00003040 u32 addr_reg;
3041 u32 data_reg;
Bruce Allana4f58f52009-06-02 11:29:18 +00003042
3043 /* This takes care of the difference with desktop vs mobile phy */
3044 addr_reg = (hw->phy.type == e1000_phy_82578) ?
3045 I82578_ADDR_REG : I82577_ADDR_REG;
3046 data_reg = addr_reg + 1;
3047
Bruce Allana4f58f52009-06-02 11:29:18 +00003048 /* All operations in this function are phy address 2 */
3049 hw->phy.addr = 2;
3050
3051 /* masking with 0x3F to remove the page from offset */
3052 ret_val = e1000e_write_phy_reg_mdic(hw, addr_reg, (u16)offset & 0x3F);
3053 if (ret_val) {
Bruce Allan2b6b1682011-05-13 07:20:09 +00003054 e_dbg("Could not write the Address Offset port register\n");
Bruce Allan5015e532012-02-08 02:55:56 +00003055 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003056 }
3057
3058 /* Read or write the data value next */
3059 if (read)
3060 ret_val = e1000e_read_phy_reg_mdic(hw, data_reg, data);
3061 else
3062 ret_val = e1000e_write_phy_reg_mdic(hw, data_reg, *data);
3063
Bruce Allan5015e532012-02-08 02:55:56 +00003064 if (ret_val)
Bruce Allan2b6b1682011-05-13 07:20:09 +00003065 e_dbg("Could not access the Data port register\n");
Bruce Allana4f58f52009-06-02 11:29:18 +00003066
Bruce Allana4f58f52009-06-02 11:29:18 +00003067 return ret_val;
3068}
3069
3070/**
3071 * e1000_link_stall_workaround_hv - Si workaround
3072 * @hw: pointer to the HW structure
3073 *
3074 * This function works around a Si bug where the link partner can get
3075 * a link up indication before the PHY does. If small packets are sent
3076 * by the link partner they can be placed in the packet buffer without
3077 * being properly accounted for by the PHY and will stall preventing
3078 * further packets from being received. The workaround is to clear the
3079 * packet buffer after the PHY detects link up.
3080 **/
3081s32 e1000_link_stall_workaround_hv(struct e1000_hw *hw)
3082{
3083 s32 ret_val = 0;
3084 u16 data;
3085
3086 if (hw->phy.type != e1000_phy_82578)
Bruce Allan5015e532012-02-08 02:55:56 +00003087 return 0;
Bruce Allana4f58f52009-06-02 11:29:18 +00003088
Bruce Allane65fa872009-07-01 13:27:31 +00003089 /* Do not apply workaround if in PHY loopback bit 14 set */
Bruce Allan482fed82011-01-06 14:29:49 +00003090 e1e_rphy(hw, PHY_CONTROL, &data);
Bruce Allane65fa872009-07-01 13:27:31 +00003091 if (data & PHY_CONTROL_LB)
Bruce Allan5015e532012-02-08 02:55:56 +00003092 return 0;
Bruce Allane65fa872009-07-01 13:27:31 +00003093
Bruce Allana4f58f52009-06-02 11:29:18 +00003094 /* check if link is up and at 1Gbps */
Bruce Allan482fed82011-01-06 14:29:49 +00003095 ret_val = e1e_rphy(hw, BM_CS_STATUS, &data);
Bruce Allana4f58f52009-06-02 11:29:18 +00003096 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003097 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003098
Bruce Allan3d3a1672012-02-23 03:13:18 +00003099 data &= BM_CS_STATUS_LINK_UP | BM_CS_STATUS_RESOLVED |
3100 BM_CS_STATUS_SPEED_MASK;
Bruce Allana4f58f52009-06-02 11:29:18 +00003101
Bruce Allan3d3a1672012-02-23 03:13:18 +00003102 if (data != (BM_CS_STATUS_LINK_UP | BM_CS_STATUS_RESOLVED |
3103 BM_CS_STATUS_SPEED_1000))
Bruce Allan5015e532012-02-08 02:55:56 +00003104 return 0;
Bruce Allana4f58f52009-06-02 11:29:18 +00003105
Bruce Allanbb9c5ee2012-02-23 03:31:29 +00003106 msleep(200);
Bruce Allana4f58f52009-06-02 11:29:18 +00003107
3108 /* flush the packets in the fifo buffer */
Bruce Allanc063f602013-01-12 07:27:53 +00003109 ret_val = e1e_wphy(hw, HV_MUX_DATA_CTRL,
3110 (HV_MUX_DATA_CTRL_GEN_TO_MAC |
3111 HV_MUX_DATA_CTRL_FORCE_SPEED));
Bruce Allana4f58f52009-06-02 11:29:18 +00003112 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003113 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003114
Bruce Allan5015e532012-02-08 02:55:56 +00003115 return e1e_wphy(hw, HV_MUX_DATA_CTRL, HV_MUX_DATA_CTRL_GEN_TO_MAC);
Bruce Allana4f58f52009-06-02 11:29:18 +00003116}
3117
3118/**
3119 * e1000_check_polarity_82577 - Checks the polarity.
3120 * @hw: pointer to the HW structure
3121 *
3122 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
3123 *
3124 * Polarity is determined based on the PHY specific status register.
3125 **/
3126s32 e1000_check_polarity_82577(struct e1000_hw *hw)
3127{
3128 struct e1000_phy_info *phy = &hw->phy;
3129 s32 ret_val;
3130 u16 data;
3131
Bruce Allan482fed82011-01-06 14:29:49 +00003132 ret_val = e1e_rphy(hw, I82577_PHY_STATUS_2, &data);
Bruce Allana4f58f52009-06-02 11:29:18 +00003133
3134 if (!ret_val)
3135 phy->cable_polarity = (data & I82577_PHY_STATUS2_REV_POLARITY)
3136 ? e1000_rev_polarity_reversed
3137 : e1000_rev_polarity_normal;
3138
3139 return ret_val;
3140}
3141
3142/**
3143 * e1000_phy_force_speed_duplex_82577 - Force speed/duplex for I82577 PHY
3144 * @hw: pointer to the HW structure
3145 *
Bruce Allaneab50ff2010-05-10 15:01:30 +00003146 * Calls the PHY setup function to force speed and duplex.
Bruce Allana4f58f52009-06-02 11:29:18 +00003147 **/
3148s32 e1000_phy_force_speed_duplex_82577(struct e1000_hw *hw)
3149{
3150 struct e1000_phy_info *phy = &hw->phy;
3151 s32 ret_val;
3152 u16 phy_data;
3153 bool link;
3154
Bruce Allan482fed82011-01-06 14:29:49 +00003155 ret_val = e1e_rphy(hw, PHY_CONTROL, &phy_data);
Bruce Allana4f58f52009-06-02 11:29:18 +00003156 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003157 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003158
3159 e1000e_phy_force_speed_duplex_setup(hw, &phy_data);
3160
Bruce Allan482fed82011-01-06 14:29:49 +00003161 ret_val = e1e_wphy(hw, PHY_CONTROL, phy_data);
Bruce Allana4f58f52009-06-02 11:29:18 +00003162 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003163 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003164
Bruce Allana4f58f52009-06-02 11:29:18 +00003165 udelay(1);
3166
3167 if (phy->autoneg_wait_to_complete) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003168 e_dbg("Waiting for forced speed/duplex link on 82577 phy\n");
Bruce Allana4f58f52009-06-02 11:29:18 +00003169
Bruce Allan3d3a1672012-02-23 03:13:18 +00003170 ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
3171 100000, &link);
Bruce Allana4f58f52009-06-02 11:29:18 +00003172 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003173 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003174
3175 if (!link)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003176 e_dbg("Link taking longer than expected.\n");
Bruce Allana4f58f52009-06-02 11:29:18 +00003177
3178 /* Try once more */
Bruce Allan3d3a1672012-02-23 03:13:18 +00003179 ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
3180 100000, &link);
Bruce Allana4f58f52009-06-02 11:29:18 +00003181 }
3182
Bruce Allana4f58f52009-06-02 11:29:18 +00003183 return ret_val;
3184}
3185
3186/**
3187 * e1000_get_phy_info_82577 - Retrieve I82577 PHY information
3188 * @hw: pointer to the HW structure
3189 *
3190 * Read PHY status to determine if link is up. If link is up, then
3191 * set/determine 10base-T extended distance and polarity correction. Read
3192 * PHY port status to determine MDI/MDIx and speed. Based on the speed,
3193 * determine on the cable length, local and remote receiver.
3194 **/
3195s32 e1000_get_phy_info_82577(struct e1000_hw *hw)
3196{
3197 struct e1000_phy_info *phy = &hw->phy;
3198 s32 ret_val;
3199 u16 data;
3200 bool link;
3201
3202 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
3203 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003204 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003205
3206 if (!link) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003207 e_dbg("Phy info is only valid if link is up\n");
Bruce Allan5015e532012-02-08 02:55:56 +00003208 return -E1000_ERR_CONFIG;
Bruce Allana4f58f52009-06-02 11:29:18 +00003209 }
3210
3211 phy->polarity_correction = true;
3212
3213 ret_val = e1000_check_polarity_82577(hw);
3214 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003215 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003216
Bruce Allan482fed82011-01-06 14:29:49 +00003217 ret_val = e1e_rphy(hw, I82577_PHY_STATUS_2, &data);
Bruce Allana4f58f52009-06-02 11:29:18 +00003218 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003219 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003220
Bruce Allan04499ec2012-04-13 00:08:31 +00003221 phy->is_mdix = !!(data & I82577_PHY_STATUS2_MDIX);
Bruce Allana4f58f52009-06-02 11:29:18 +00003222
3223 if ((data & I82577_PHY_STATUS2_SPEED_MASK) ==
3224 I82577_PHY_STATUS2_SPEED_1000MBPS) {
3225 ret_val = hw->phy.ops.get_cable_length(hw);
3226 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003227 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003228
Bruce Allan482fed82011-01-06 14:29:49 +00003229 ret_val = e1e_rphy(hw, PHY_1000T_STATUS, &data);
Bruce Allana4f58f52009-06-02 11:29:18 +00003230 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003231 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003232
3233 phy->local_rx = (data & SR_1000T_LOCAL_RX_STATUS)
3234 ? e1000_1000t_rx_status_ok
3235 : e1000_1000t_rx_status_not_ok;
3236
3237 phy->remote_rx = (data & SR_1000T_REMOTE_RX_STATUS)
3238 ? e1000_1000t_rx_status_ok
3239 : e1000_1000t_rx_status_not_ok;
3240 } else {
3241 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
3242 phy->local_rx = e1000_1000t_rx_status_undefined;
3243 phy->remote_rx = e1000_1000t_rx_status_undefined;
3244 }
3245
Bruce Allan5015e532012-02-08 02:55:56 +00003246 return 0;
Bruce Allana4f58f52009-06-02 11:29:18 +00003247}
3248
3249/**
3250 * e1000_get_cable_length_82577 - Determine cable length for 82577 PHY
3251 * @hw: pointer to the HW structure
3252 *
3253 * Reads the diagnostic status register and verifies result is valid before
3254 * placing it in the phy_cable_length field.
3255 **/
3256s32 e1000_get_cable_length_82577(struct e1000_hw *hw)
3257{
3258 struct e1000_phy_info *phy = &hw->phy;
3259 s32 ret_val;
3260 u16 phy_data, length;
3261
Bruce Allan482fed82011-01-06 14:29:49 +00003262 ret_val = e1e_rphy(hw, I82577_PHY_DIAG_STATUS, &phy_data);
Bruce Allana4f58f52009-06-02 11:29:18 +00003263 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003264 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003265
3266 length = (phy_data & I82577_DSTATUS_CABLE_LENGTH) >>
3267 I82577_DSTATUS_CABLE_LENGTH_SHIFT;
3268
3269 if (length == E1000_CABLE_LENGTH_UNDEFINED)
Bruce Allan7dbbe5d2013-01-05 05:08:31 +00003270 return -E1000_ERR_PHY;
Bruce Allana4f58f52009-06-02 11:29:18 +00003271
3272 phy->cable_length = length;
3273
Bruce Allan5015e532012-02-08 02:55:56 +00003274 return 0;
Bruce Allana4f58f52009-06-02 11:29:18 +00003275}