blob: e071ef77238081988429f1eab13a2cfcdea31ca6 [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[] = {
Bruce Allan04e115c2013-02-20 04:06:22 +000040 0, 50, 80, 110, 140, 140, E1000_CABLE_LENGTH_UNDEFINED
41};
Bruce Allanfc830b72013-02-20 04:06:11 +000042
Bruce Allaneb656d42009-12-01 15:47:02 +000043#define M88E1000_CABLE_LENGTH_TABLE_SIZE \
44 ARRAY_SIZE(e1000_m88_cable_length_table)
Auke Kokbc7f75f2007-09-17 12:30:59 -070045
Bruce Allan64806412010-12-11 05:53:42 +000046static const u16 e1000_igp_2_cable_length_table[] = {
47 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21, 0, 0, 0, 3,
48 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41, 6, 10, 14, 18, 22,
49 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61, 21, 26, 31, 35, 40,
50 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82, 40, 45, 51, 56, 61,
51 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104, 60, 66, 72, 77, 82,
52 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121, 83, 89, 95,
53 100, 105, 109, 113, 116, 119, 122, 124, 104, 109, 114, 118, 121,
Bruce Allan04e115c2013-02-20 04:06:22 +000054 124
55};
Bruce Allanfc830b72013-02-20 04:06:11 +000056
Auke Kokbc7f75f2007-09-17 12:30:59 -070057#define IGP02E1000_CABLE_LENGTH_TABLE_SIZE \
Alejandro Martinez Ruizc00acf42007-10-18 10:16:33 +020058 ARRAY_SIZE(e1000_igp_2_cable_length_table)
Auke Kokbc7f75f2007-09-17 12:30:59 -070059
60/**
61 * e1000e_check_reset_block_generic - Check if PHY reset is blocked
62 * @hw: pointer to the HW structure
63 *
64 * Read the PHY management control register and check whether a PHY reset
65 * is blocked. If a reset is not blocked return 0, otherwise
66 * return E1000_BLK_PHY_RESET (12).
67 **/
68s32 e1000e_check_reset_block_generic(struct e1000_hw *hw)
69{
70 u32 manc;
71
72 manc = er32(MANC);
73
74 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
75 E1000_BLK_PHY_RESET : 0;
76}
77
78/**
79 * e1000e_get_phy_id - Retrieve the PHY ID and revision
80 * @hw: pointer to the HW structure
81 *
82 * Reads the PHY registers and stores the PHY ID and possibly the PHY
83 * revision in the hardware structure.
84 **/
85s32 e1000e_get_phy_id(struct e1000_hw *hw)
86{
87 struct e1000_phy_info *phy = &hw->phy;
Bruce Allana4f58f52009-06-02 11:29:18 +000088 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -070089 u16 phy_id;
Bruce Allana4f58f52009-06-02 11:29:18 +000090 u16 retry_count = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -070091
Bruce Allan668018d2012-01-31 07:02:56 +000092 if (!phy->ops.read_reg)
Bruce Allan5015e532012-02-08 02:55:56 +000093 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -070094
Bruce Allana4f58f52009-06-02 11:29:18 +000095 while (retry_count < 2) {
Bruce Allanc2ade1a2013-01-16 08:54:35 +000096 ret_val = e1e_rphy(hw, MII_PHYSID1, &phy_id);
Bruce Allana4f58f52009-06-02 11:29:18 +000097 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +000098 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -070099
Bruce Allana4f58f52009-06-02 11:29:18 +0000100 phy->id = (u32)(phy_id << 16);
101 udelay(20);
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000102 ret_val = e1e_rphy(hw, MII_PHYSID2, &phy_id);
Bruce Allana4f58f52009-06-02 11:29:18 +0000103 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000104 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700105
Bruce Allana4f58f52009-06-02 11:29:18 +0000106 phy->id |= (u32)(phy_id & PHY_REVISION_MASK);
107 phy->revision = (u32)(phy_id & ~PHY_REVISION_MASK);
108
109 if (phy->id != 0 && phy->id != PHY_REVISION_MASK)
Bruce Allan5015e532012-02-08 02:55:56 +0000110 return 0;
Bruce Allana4f58f52009-06-02 11:29:18 +0000111
Bruce Allana4f58f52009-06-02 11:29:18 +0000112 retry_count++;
113 }
Bruce Allan5015e532012-02-08 02:55:56 +0000114
115 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700116}
117
118/**
119 * e1000e_phy_reset_dsp - Reset PHY DSP
120 * @hw: pointer to the HW structure
121 *
122 * Reset the digital signal processor.
123 **/
124s32 e1000e_phy_reset_dsp(struct e1000_hw *hw)
125{
126 s32 ret_val;
127
128 ret_val = e1e_wphy(hw, M88E1000_PHY_GEN_CONTROL, 0xC1);
129 if (ret_val)
130 return ret_val;
131
132 return e1e_wphy(hw, M88E1000_PHY_GEN_CONTROL, 0);
133}
134
135/**
David Graham2d9498f2008-04-23 11:09:14 -0700136 * e1000e_read_phy_reg_mdic - Read MDI control register
Auke Kokbc7f75f2007-09-17 12:30:59 -0700137 * @hw: pointer to the HW structure
138 * @offset: register offset to be read
139 * @data: pointer to the read data
140 *
Auke Kok489815c2008-02-21 15:11:07 -0800141 * Reads the MDI control register in the PHY at offset and stores the
Auke Kokbc7f75f2007-09-17 12:30:59 -0700142 * information read to data.
143 **/
David Graham2d9498f2008-04-23 11:09:14 -0700144s32 e1000e_read_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 *data)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700145{
146 struct e1000_phy_info *phy = &hw->phy;
147 u32 i, mdic = 0;
148
149 if (offset > MAX_PHY_REG_ADDRESS) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000150 e_dbg("PHY Address %d is out of range\n", offset);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700151 return -E1000_ERR_PARAM;
152 }
153
Bruce Allane921eb12012-11-28 09:28:37 +0000154 /* Set up Op-code, Phy Address, and register offset in the MDI
Auke Kokbc7f75f2007-09-17 12:30:59 -0700155 * Control register. The MAC will take care of interfacing with the
156 * PHY to retrieve the desired data.
157 */
158 mdic = ((offset << E1000_MDIC_REG_SHIFT) |
159 (phy->addr << E1000_MDIC_PHY_SHIFT) |
160 (E1000_MDIC_OP_READ));
161
162 ew32(MDIC, mdic);
163
Bruce Allane921eb12012-11-28 09:28:37 +0000164 /* Poll the ready bit to see if the MDI read completed
Bruce Allanad680762008-03-28 09:15:03 -0700165 * Increasing the time out as testing showed failures with
166 * the lower time out
167 */
David Graham2d9498f2008-04-23 11:09:14 -0700168 for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700169 udelay(50);
170 mdic = er32(MDIC);
171 if (mdic & E1000_MDIC_READY)
172 break;
173 }
174 if (!(mdic & E1000_MDIC_READY)) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000175 e_dbg("MDI Read did not complete\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700176 return -E1000_ERR_PHY;
177 }
178 if (mdic & E1000_MDIC_ERROR) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000179 e_dbg("MDI Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700180 return -E1000_ERR_PHY;
181 }
Bruce Allan53aa82d2013-02-20 04:06:06 +0000182 *data = (u16)mdic;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700183
Bruce Allane921eb12012-11-28 09:28:37 +0000184 /* Allow some time after each MDIC transaction to avoid
Bruce Allan664dc872010-11-24 06:01:46 +0000185 * reading duplicate data in the next MDIC transaction.
186 */
187 if (hw->mac.type == e1000_pch2lan)
188 udelay(100);
189
Auke Kokbc7f75f2007-09-17 12:30:59 -0700190 return 0;
191}
192
193/**
David Graham2d9498f2008-04-23 11:09:14 -0700194 * e1000e_write_phy_reg_mdic - Write MDI control register
Auke Kokbc7f75f2007-09-17 12:30:59 -0700195 * @hw: pointer to the HW structure
196 * @offset: register offset to write to
197 * @data: data to write to register at offset
198 *
199 * Writes data to MDI control register in the PHY at offset.
200 **/
David Graham2d9498f2008-04-23 11:09:14 -0700201s32 e1000e_write_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 data)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700202{
203 struct e1000_phy_info *phy = &hw->phy;
204 u32 i, mdic = 0;
205
206 if (offset > MAX_PHY_REG_ADDRESS) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000207 e_dbg("PHY Address %d is out of range\n", offset);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700208 return -E1000_ERR_PARAM;
209 }
210
Bruce Allane921eb12012-11-28 09:28:37 +0000211 /* Set up Op-code, Phy Address, and register offset in the MDI
Auke Kokbc7f75f2007-09-17 12:30:59 -0700212 * Control register. The MAC will take care of interfacing with the
213 * PHY to retrieve the desired data.
214 */
215 mdic = (((u32)data) |
216 (offset << E1000_MDIC_REG_SHIFT) |
217 (phy->addr << E1000_MDIC_PHY_SHIFT) |
218 (E1000_MDIC_OP_WRITE));
219
220 ew32(MDIC, mdic);
221
Bruce Allane921eb12012-11-28 09:28:37 +0000222 /* Poll the ready bit to see if the MDI read completed
David Graham2d9498f2008-04-23 11:09:14 -0700223 * Increasing the time out as testing showed failures with
224 * the lower time out
225 */
226 for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
227 udelay(50);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700228 mdic = er32(MDIC);
229 if (mdic & E1000_MDIC_READY)
230 break;
231 }
232 if (!(mdic & E1000_MDIC_READY)) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000233 e_dbg("MDI Write did not complete\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700234 return -E1000_ERR_PHY;
235 }
David Graham2d9498f2008-04-23 11:09:14 -0700236 if (mdic & E1000_MDIC_ERROR) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000237 e_dbg("MDI Error\n");
David Graham2d9498f2008-04-23 11:09:14 -0700238 return -E1000_ERR_PHY;
239 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700240
Bruce Allane921eb12012-11-28 09:28:37 +0000241 /* Allow some time after each MDIC transaction to avoid
Bruce Allan664dc872010-11-24 06:01:46 +0000242 * reading duplicate data in the next MDIC transaction.
243 */
244 if (hw->mac.type == e1000_pch2lan)
245 udelay(100);
246
Auke Kokbc7f75f2007-09-17 12:30:59 -0700247 return 0;
248}
249
250/**
251 * e1000e_read_phy_reg_m88 - Read m88 PHY register
252 * @hw: pointer to the HW structure
253 * @offset: register offset to be read
254 * @data: pointer to the read data
255 *
256 * Acquires semaphore, if necessary, then reads the PHY register at offset
257 * and storing the retrieved information in data. Release any acquired
258 * semaphores before exiting.
259 **/
260s32 e1000e_read_phy_reg_m88(struct e1000_hw *hw, u32 offset, u16 *data)
261{
262 s32 ret_val;
263
Bruce Allan94d81862009-11-20 23:25:26 +0000264 ret_val = hw->phy.ops.acquire(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700265 if (ret_val)
266 return ret_val;
267
David Graham2d9498f2008-04-23 11:09:14 -0700268 ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
269 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700270
Bruce Allan94d81862009-11-20 23:25:26 +0000271 hw->phy.ops.release(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700272
273 return ret_val;
274}
275
276/**
277 * e1000e_write_phy_reg_m88 - Write m88 PHY register
278 * @hw: pointer to the HW structure
279 * @offset: register offset to write to
280 * @data: data to write at register offset
281 *
282 * Acquires semaphore, if necessary, then writes the data to PHY register
283 * at the offset. Release any acquired semaphores before exiting.
284 **/
285s32 e1000e_write_phy_reg_m88(struct e1000_hw *hw, u32 offset, u16 data)
286{
287 s32 ret_val;
288
Bruce Allan94d81862009-11-20 23:25:26 +0000289 ret_val = hw->phy.ops.acquire(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700290 if (ret_val)
291 return ret_val;
292
David Graham2d9498f2008-04-23 11:09:14 -0700293 ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
294 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700295
Bruce Allan94d81862009-11-20 23:25:26 +0000296 hw->phy.ops.release(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700297
298 return ret_val;
299}
300
301/**
Bruce Allan2b6b1682011-05-13 07:20:09 +0000302 * e1000_set_page_igp - Set page as on IGP-like PHY(s)
303 * @hw: pointer to the HW structure
304 * @page: page to set (shifted left when necessary)
305 *
306 * Sets PHY page required for PHY register access. Assumes semaphore is
307 * already acquired. Note, this function sets phy.addr to 1 so the caller
308 * must set it appropriately (if necessary) after this function returns.
309 **/
310s32 e1000_set_page_igp(struct e1000_hw *hw, u16 page)
311{
312 e_dbg("Setting page 0x%x\n", page);
313
314 hw->phy.addr = 1;
315
316 return e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT, page);
317}
318
319/**
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000320 * __e1000e_read_phy_reg_igp - Read igp PHY register
Auke Kokbc7f75f2007-09-17 12:30:59 -0700321 * @hw: pointer to the HW structure
322 * @offset: register offset to be read
323 * @data: pointer to the read data
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000324 * @locked: semaphore has already been acquired or not
Auke Kokbc7f75f2007-09-17 12:30:59 -0700325 *
326 * Acquires semaphore, if necessary, then reads the PHY register at offset
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000327 * and stores the retrieved information in data. Release any acquired
Auke Kokbc7f75f2007-09-17 12:30:59 -0700328 * semaphores before exiting.
329 **/
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000330static s32 __e1000e_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data,
Bruce Allan66501f52013-02-20 04:05:55 +0000331 bool locked)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700332{
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000333 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700334
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000335 if (!locked) {
Bruce Allan668018d2012-01-31 07:02:56 +0000336 if (!hw->phy.ops.acquire)
Bruce Allan5015e532012-02-08 02:55:56 +0000337 return 0;
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000338
Bruce Allan94d81862009-11-20 23:25:26 +0000339 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000340 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000341 return ret_val;
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000342 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700343
Bruce Allan5015e532012-02-08 02:55:56 +0000344 if (offset > MAX_PHY_MULTI_PAGE_REG)
David Graham2d9498f2008-04-23 11:09:14 -0700345 ret_val = e1000e_write_phy_reg_mdic(hw,
346 IGP01E1000_PHY_PAGE_SELECT,
347 (u16)offset);
Bruce Allan5015e532012-02-08 02:55:56 +0000348 if (!ret_val)
349 ret_val = e1000e_read_phy_reg_mdic(hw,
350 MAX_PHY_REG_ADDRESS & offset,
351 data);
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000352 if (!locked)
Bruce Allan94d81862009-11-20 23:25:26 +0000353 hw->phy.ops.release(hw);
Bruce Allan5015e532012-02-08 02:55:56 +0000354
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000355 return ret_val;
356}
Auke Kokbc7f75f2007-09-17 12:30:59 -0700357
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000358/**
359 * e1000e_read_phy_reg_igp - Read igp PHY register
360 * @hw: pointer to the HW structure
361 * @offset: register offset to be read
362 * @data: pointer to the read data
363 *
364 * Acquires semaphore then reads the PHY register at offset and stores the
365 * retrieved information in data.
366 * Release the acquired semaphore before exiting.
367 **/
368s32 e1000e_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data)
369{
370 return __e1000e_read_phy_reg_igp(hw, offset, data, false);
371}
372
373/**
374 * e1000e_read_phy_reg_igp_locked - Read igp PHY register
375 * @hw: pointer to the HW structure
376 * @offset: register offset to be read
377 * @data: pointer to the read data
378 *
379 * Reads the PHY register at offset and stores the retrieved information
380 * in data. Assumes semaphore already acquired.
381 **/
382s32 e1000e_read_phy_reg_igp_locked(struct e1000_hw *hw, u32 offset, u16 *data)
383{
384 return __e1000e_read_phy_reg_igp(hw, offset, data, true);
385}
386
387/**
388 * e1000e_write_phy_reg_igp - Write igp PHY register
389 * @hw: pointer to the HW structure
390 * @offset: register offset to write to
391 * @data: data to write at register offset
392 * @locked: semaphore has already been acquired or not
393 *
394 * Acquires semaphore, if necessary, then writes the data to PHY register
395 * at the offset. Release any acquired semaphores before exiting.
396 **/
397static s32 __e1000e_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data,
Bruce Allan66501f52013-02-20 04:05:55 +0000398 bool locked)
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000399{
400 s32 ret_val = 0;
401
402 if (!locked) {
Bruce Allan668018d2012-01-31 07:02:56 +0000403 if (!hw->phy.ops.acquire)
Bruce Allan5015e532012-02-08 02:55:56 +0000404 return 0;
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000405
Bruce Allan94d81862009-11-20 23:25:26 +0000406 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000407 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000408 return ret_val;
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000409 }
410
Bruce Allan5015e532012-02-08 02:55:56 +0000411 if (offset > MAX_PHY_MULTI_PAGE_REG)
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000412 ret_val = e1000e_write_phy_reg_mdic(hw,
413 IGP01E1000_PHY_PAGE_SELECT,
414 (u16)offset);
Bruce Allan5015e532012-02-08 02:55:56 +0000415 if (!ret_val)
416 ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS &
Bruce Allan17e813e2013-02-20 04:06:01 +0000417 offset, data);
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000418 if (!locked)
Bruce Allan94d81862009-11-20 23:25:26 +0000419 hw->phy.ops.release(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000420
Auke Kokbc7f75f2007-09-17 12:30:59 -0700421 return ret_val;
422}
423
424/**
425 * e1000e_write_phy_reg_igp - Write igp PHY register
426 * @hw: pointer to the HW structure
427 * @offset: register offset to write to
428 * @data: data to write at register offset
429 *
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000430 * Acquires semaphore then writes the data to PHY register
Auke Kokbc7f75f2007-09-17 12:30:59 -0700431 * at the offset. Release any acquired semaphores before exiting.
432 **/
433s32 e1000e_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data)
434{
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000435 return __e1000e_write_phy_reg_igp(hw, offset, data, false);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700436}
437
438/**
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000439 * e1000e_write_phy_reg_igp_locked - Write igp PHY register
440 * @hw: pointer to the HW structure
441 * @offset: register offset to write to
442 * @data: data to write at register offset
443 *
444 * Writes the data to PHY register at the offset.
445 * Assumes semaphore already acquired.
446 **/
447s32 e1000e_write_phy_reg_igp_locked(struct e1000_hw *hw, u32 offset, u16 data)
448{
449 return __e1000e_write_phy_reg_igp(hw, offset, data, true);
450}
451
452/**
453 * __e1000_read_kmrn_reg - Read kumeran register
Auke Kokbc7f75f2007-09-17 12:30:59 -0700454 * @hw: pointer to the HW structure
455 * @offset: register offset to be read
456 * @data: pointer to the read data
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000457 * @locked: semaphore has already been acquired or not
Auke Kokbc7f75f2007-09-17 12:30:59 -0700458 *
459 * Acquires semaphore, if necessary. Then reads the PHY register at offset
460 * using the kumeran interface. The information retrieved is stored in data.
461 * Release any acquired semaphores before exiting.
462 **/
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000463static s32 __e1000_read_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 *data,
Bruce Allan66501f52013-02-20 04:05:55 +0000464 bool locked)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700465{
466 u32 kmrnctrlsta;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700467
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000468 if (!locked) {
Bruce Allan5015e532012-02-08 02:55:56 +0000469 s32 ret_val = 0;
470
Bruce Allan668018d2012-01-31 07:02:56 +0000471 if (!hw->phy.ops.acquire)
Bruce Allan5015e532012-02-08 02:55:56 +0000472 return 0;
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000473
Bruce Allan94d81862009-11-20 23:25:26 +0000474 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000475 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000476 return ret_val;
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000477 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700478
479 kmrnctrlsta = ((offset << E1000_KMRNCTRLSTA_OFFSET_SHIFT) &
480 E1000_KMRNCTRLSTA_OFFSET) | E1000_KMRNCTRLSTA_REN;
481 ew32(KMRNCTRLSTA, kmrnctrlsta);
Jesse Brandeburg945a5152011-07-20 00:56:21 +0000482 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -0700483
484 udelay(2);
485
486 kmrnctrlsta = er32(KMRNCTRLSTA);
487 *data = (u16)kmrnctrlsta;
488
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000489 if (!locked)
Bruce Allan94d81862009-11-20 23:25:26 +0000490 hw->phy.ops.release(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700491
Bruce Allan5015e532012-02-08 02:55:56 +0000492 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700493}
494
495/**
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000496 * e1000e_read_kmrn_reg - Read kumeran register
497 * @hw: pointer to the HW structure
498 * @offset: register offset to be read
499 * @data: pointer to the read data
500 *
501 * Acquires semaphore then reads the PHY register at offset using the
502 * kumeran interface. The information retrieved is stored in data.
503 * Release the acquired semaphore before exiting.
504 **/
505s32 e1000e_read_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 *data)
506{
507 return __e1000_read_kmrn_reg(hw, offset, data, false);
508}
509
510/**
Bruce Allan1d5846b2009-10-29 13:46:05 +0000511 * e1000e_read_kmrn_reg_locked - Read kumeran register
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000512 * @hw: pointer to the HW structure
513 * @offset: register offset to be read
514 * @data: pointer to the read data
515 *
516 * Reads the PHY register at offset using the kumeran interface. The
517 * information retrieved is stored in data.
518 * Assumes semaphore already acquired.
519 **/
Bruce Allan1d5846b2009-10-29 13:46:05 +0000520s32 e1000e_read_kmrn_reg_locked(struct e1000_hw *hw, u32 offset, u16 *data)
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000521{
522 return __e1000_read_kmrn_reg(hw, offset, data, true);
523}
524
525/**
526 * __e1000_write_kmrn_reg - Write kumeran register
Auke Kokbc7f75f2007-09-17 12:30:59 -0700527 * @hw: pointer to the HW structure
528 * @offset: register offset to write to
529 * @data: data to write at register offset
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000530 * @locked: semaphore has already been acquired or not
Auke Kokbc7f75f2007-09-17 12:30:59 -0700531 *
532 * Acquires semaphore, if necessary. Then write the data to PHY register
533 * at the offset using the kumeran interface. Release any acquired semaphores
534 * before exiting.
535 **/
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000536static s32 __e1000_write_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 data,
Bruce Allan66501f52013-02-20 04:05:55 +0000537 bool locked)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700538{
539 u32 kmrnctrlsta;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700540
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000541 if (!locked) {
Bruce Allan5015e532012-02-08 02:55:56 +0000542 s32 ret_val = 0;
543
Bruce Allan668018d2012-01-31 07:02:56 +0000544 if (!hw->phy.ops.acquire)
Bruce Allan5015e532012-02-08 02:55:56 +0000545 return 0;
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000546
Bruce Allan94d81862009-11-20 23:25:26 +0000547 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000548 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000549 return ret_val;
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000550 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700551
552 kmrnctrlsta = ((offset << E1000_KMRNCTRLSTA_OFFSET_SHIFT) &
553 E1000_KMRNCTRLSTA_OFFSET) | data;
554 ew32(KMRNCTRLSTA, kmrnctrlsta);
Jesse Brandeburg945a5152011-07-20 00:56:21 +0000555 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -0700556
557 udelay(2);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700558
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000559 if (!locked)
Bruce Allan94d81862009-11-20 23:25:26 +0000560 hw->phy.ops.release(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000561
Bruce Allan5015e532012-02-08 02:55:56 +0000562 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700563}
564
565/**
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000566 * e1000e_write_kmrn_reg - Write kumeran register
567 * @hw: pointer to the HW structure
568 * @offset: register offset to write to
569 * @data: data to write at register offset
570 *
571 * Acquires semaphore then writes the data to the PHY register at the offset
572 * using the kumeran interface. Release the acquired semaphore before exiting.
573 **/
574s32 e1000e_write_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 data)
575{
576 return __e1000_write_kmrn_reg(hw, offset, data, false);
577}
578
579/**
Bruce Allan1d5846b2009-10-29 13:46:05 +0000580 * e1000e_write_kmrn_reg_locked - Write kumeran register
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000581 * @hw: pointer to the HW structure
582 * @offset: register offset to write to
583 * @data: data to write at register offset
584 *
585 * Write the data to PHY register at the offset using the kumeran interface.
586 * Assumes semaphore already acquired.
587 **/
Bruce Allan1d5846b2009-10-29 13:46:05 +0000588s32 e1000e_write_kmrn_reg_locked(struct e1000_hw *hw, u32 offset, u16 data)
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000589{
590 return __e1000_write_kmrn_reg(hw, offset, data, true);
591}
592
593/**
Bruce Allan7b9f7e32012-03-20 03:47:41 +0000594 * e1000_set_master_slave_mode - Setup PHY for Master/slave mode
595 * @hw: pointer to the HW structure
596 *
597 * Sets up Master/slave mode
598 **/
599static s32 e1000_set_master_slave_mode(struct e1000_hw *hw)
600{
601 s32 ret_val;
602 u16 phy_data;
603
604 /* Resolve Master/Slave mode */
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000605 ret_val = e1e_rphy(hw, MII_CTRL1000, &phy_data);
Bruce Allan7b9f7e32012-03-20 03:47:41 +0000606 if (ret_val)
607 return ret_val;
608
609 /* load defaults for future use */
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000610 hw->phy.original_ms_type = (phy_data & CTL1000_ENABLE_MASTER) ?
611 ((phy_data & CTL1000_AS_MASTER) ?
Bruce Allan7b9f7e32012-03-20 03:47:41 +0000612 e1000_ms_force_master : e1000_ms_force_slave) : e1000_ms_auto;
613
614 switch (hw->phy.ms_type) {
615 case e1000_ms_force_master:
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000616 phy_data |= (CTL1000_ENABLE_MASTER | CTL1000_AS_MASTER);
Bruce Allan7b9f7e32012-03-20 03:47:41 +0000617 break;
618 case e1000_ms_force_slave:
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000619 phy_data |= CTL1000_ENABLE_MASTER;
620 phy_data &= ~(CTL1000_AS_MASTER);
Bruce Allan7b9f7e32012-03-20 03:47:41 +0000621 break;
622 case e1000_ms_auto:
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000623 phy_data &= ~CTL1000_ENABLE_MASTER;
Bruce Allan7b9f7e32012-03-20 03:47:41 +0000624 /* fall-through */
625 default:
626 break;
627 }
628
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000629 return e1e_wphy(hw, MII_CTRL1000, phy_data);
Bruce Allan7b9f7e32012-03-20 03:47:41 +0000630}
631
632/**
Bruce Allana4f58f52009-06-02 11:29:18 +0000633 * e1000_copper_link_setup_82577 - Setup 82577 PHY for copper link
634 * @hw: pointer to the HW structure
635 *
636 * Sets up Carrier-sense on Transmit and downshift values.
637 **/
638s32 e1000_copper_link_setup_82577(struct e1000_hw *hw)
639{
Bruce Allana4f58f52009-06-02 11:29:18 +0000640 s32 ret_val;
641 u16 phy_data;
642
Bruce Allanaf667a22010-12-31 06:10:01 +0000643 /* Enable CRS on Tx. This must be set for half-duplex operation. */
Bruce Allan482fed82011-01-06 14:29:49 +0000644 ret_val = e1e_rphy(hw, I82577_CFG_REG, &phy_data);
Bruce Allana4f58f52009-06-02 11:29:18 +0000645 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000646 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +0000647
648 phy_data |= I82577_CFG_ASSERT_CRS_ON_TX;
649
650 /* Enable downshift */
651 phy_data |= I82577_CFG_ENABLE_DOWNSHIFT;
652
Bruce Allan7b9f7e32012-03-20 03:47:41 +0000653 ret_val = e1e_wphy(hw, I82577_CFG_REG, phy_data);
654 if (ret_val)
655 return ret_val;
656
Bruce W Allane86fd892012-07-26 02:30:59 +0000657 /* Set MDI/MDIX mode */
658 ret_val = e1e_rphy(hw, I82577_PHY_CTRL_2, &phy_data);
659 if (ret_val)
660 return ret_val;
661 phy_data &= ~I82577_PHY_CTRL2_MDIX_CFG_MASK;
Bruce Allane921eb12012-11-28 09:28:37 +0000662 /* Options:
Bruce W Allane86fd892012-07-26 02:30:59 +0000663 * 0 - Auto (default)
664 * 1 - MDI mode
665 * 2 - MDI-X mode
666 */
667 switch (hw->phy.mdix) {
668 case 1:
669 break;
670 case 2:
671 phy_data |= I82577_PHY_CTRL2_MANUAL_MDIX;
672 break;
673 case 0:
674 default:
675 phy_data |= I82577_PHY_CTRL2_AUTO_MDI_MDIX;
676 break;
677 }
678 ret_val = e1e_wphy(hw, I82577_PHY_CTRL_2, phy_data);
679 if (ret_val)
680 return ret_val;
681
Bruce Allan7b9f7e32012-03-20 03:47:41 +0000682 return e1000_set_master_slave_mode(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +0000683}
684
685/**
Auke Kokbc7f75f2007-09-17 12:30:59 -0700686 * e1000e_copper_link_setup_m88 - Setup m88 PHY's for copper link
687 * @hw: pointer to the HW structure
688 *
689 * Sets up MDI/MDI-X and polarity for m88 PHY's. If necessary, transmit clock
690 * and downshift values are set also.
691 **/
692s32 e1000e_copper_link_setup_m88(struct e1000_hw *hw)
693{
694 struct e1000_phy_info *phy = &hw->phy;
695 s32 ret_val;
696 u16 phy_data;
697
Bruce Allanad680762008-03-28 09:15:03 -0700698 /* Enable CRS on Tx. This must be set for half-duplex operation. */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700699 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
700 if (ret_val)
701 return ret_val;
702
Bruce Allana4f58f52009-06-02 11:29:18 +0000703 /* For BM PHY this bit is downshift enable */
704 if (phy->type != e1000_phy_bm)
David Graham2d9498f2008-04-23 11:09:14 -0700705 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700706
Bruce Allane921eb12012-11-28 09:28:37 +0000707 /* Options:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700708 * MDI/MDI-X = 0 (default)
709 * 0 - Auto for all speeds
710 * 1 - MDI mode
711 * 2 - MDI-X mode
712 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
713 */
714 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
715
716 switch (phy->mdix) {
717 case 1:
718 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
719 break;
720 case 2:
721 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
722 break;
723 case 3:
724 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
725 break;
726 case 0:
727 default:
728 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
729 break;
730 }
731
Bruce Allane921eb12012-11-28 09:28:37 +0000732 /* Options:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700733 * disable_polarity_correction = 0 (default)
734 * Automatic Correction for Reversed Cable Polarity
735 * 0 - Disabled
736 * 1 - Enabled
737 */
738 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
Bruce Allan04499ec2012-04-13 00:08:31 +0000739 if (phy->disable_polarity_correction)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700740 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
741
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700742 /* Enable downshift on BM (disabled by default) */
Matthew Vick885fe7b2012-04-25 07:25:18 +0000743 if (phy->type == e1000_phy_bm) {
744 /* For 82574/82583, first disable then enable downshift */
745 if (phy->id == BME1000_E_PHY_ID_R2) {
746 phy_data &= ~BME1000_PSCR_ENABLE_DOWNSHIFT;
747 ret_val = e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL,
748 phy_data);
749 if (ret_val)
750 return ret_val;
751 /* Commit the changes. */
Bruce Allan6b598e12013-01-23 06:50:05 +0000752 ret_val = phy->ops.commit(hw);
Matthew Vick885fe7b2012-04-25 07:25:18 +0000753 if (ret_val) {
754 e_dbg("Error committing the PHY changes\n");
755 return ret_val;
756 }
757 }
758
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700759 phy_data |= BME1000_PSCR_ENABLE_DOWNSHIFT;
Matthew Vick885fe7b2012-04-25 07:25:18 +0000760 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700761
Auke Kokbc7f75f2007-09-17 12:30:59 -0700762 ret_val = e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
763 if (ret_val)
764 return ret_val;
765
Bruce Allan4662e822008-08-26 18:37:06 -0700766 if ((phy->type == e1000_phy_m88) &&
767 (phy->revision < E1000_REVISION_4) &&
768 (phy->id != BME1000_E_PHY_ID_R2)) {
Bruce Allane921eb12012-11-28 09:28:37 +0000769 /* Force TX_CLK in the Extended PHY Specific Control Register
Auke Kokbc7f75f2007-09-17 12:30:59 -0700770 * to 25MHz clock.
771 */
772 ret_val = e1e_rphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
773 if (ret_val)
774 return ret_val;
775
776 phy_data |= M88E1000_EPSCR_TX_CLK_25;
777
778 if ((phy->revision == 2) &&
779 (phy->id == M88E1111_I_PHY_ID)) {
780 /* 82573L PHY - set the downshift counter to 5x. */
781 phy_data &= ~M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK;
782 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
783 } else {
784 /* Configure Master and Slave downshift values */
785 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
786 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
787 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
788 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
789 }
790 ret_val = e1e_wphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
791 if (ret_val)
792 return ret_val;
793 }
794
Bruce Allan4662e822008-08-26 18:37:06 -0700795 if ((phy->type == e1000_phy_bm) && (phy->id == BME1000_E_PHY_ID_R2)) {
796 /* Set PHY page 0, register 29 to 0x0003 */
797 ret_val = e1e_wphy(hw, 29, 0x0003);
798 if (ret_val)
799 return ret_val;
800
801 /* Set PHY page 0, register 30 to 0x0000 */
802 ret_val = e1e_wphy(hw, 30, 0x0000);
803 if (ret_val)
804 return ret_val;
805 }
806
Auke Kokbc7f75f2007-09-17 12:30:59 -0700807 /* Commit the changes. */
Bruce Allan6b598e12013-01-23 06:50:05 +0000808 if (phy->ops.commit) {
809 ret_val = phy->ops.commit(hw);
810 if (ret_val) {
811 e_dbg("Error committing the PHY changes\n");
812 return ret_val;
813 }
Bruce Allana4f58f52009-06-02 11:29:18 +0000814 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700815
Bruce Allana4f58f52009-06-02 11:29:18 +0000816 if (phy->type == e1000_phy_82578) {
Bruce Allan482fed82011-01-06 14:29:49 +0000817 ret_val = e1e_rphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
Bruce Allana4f58f52009-06-02 11:29:18 +0000818 if (ret_val)
819 return ret_val;
820
821 /* 82578 PHY - set the downshift count to 1x. */
822 phy_data |= I82578_EPSCR_DOWNSHIFT_ENABLE;
823 phy_data &= ~I82578_EPSCR_DOWNSHIFT_COUNTER_MASK;
Bruce Allan482fed82011-01-06 14:29:49 +0000824 ret_val = e1e_wphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
Bruce Allana4f58f52009-06-02 11:29:18 +0000825 if (ret_val)
826 return ret_val;
827 }
828
829 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700830}
831
832/**
833 * e1000e_copper_link_setup_igp - Setup igp PHY's for copper link
834 * @hw: pointer to the HW structure
835 *
836 * Sets up LPLU, MDI/MDI-X, polarity, Smartspeed and Master/Slave config for
837 * igp PHY's.
838 **/
839s32 e1000e_copper_link_setup_igp(struct e1000_hw *hw)
840{
841 struct e1000_phy_info *phy = &hw->phy;
842 s32 ret_val;
843 u16 data;
844
845 ret_val = e1000_phy_hw_reset(hw);
846 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000847 e_dbg("Error resetting the PHY.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700848 return ret_val;
849 }
850
Bruce Allane921eb12012-11-28 09:28:37 +0000851 /* Wait 100ms for MAC to configure PHY from NVM settings, to avoid
David Graham2d9498f2008-04-23 11:09:14 -0700852 * timeout issues when LFS is enabled.
853 */
854 msleep(100);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700855
856 /* disable lplu d0 during driver init */
Bruce Allan7de89f02013-01-05 08:06:03 +0000857 if (hw->phy.ops.set_d0_lplu_state) {
858 ret_val = hw->phy.ops.set_d0_lplu_state(hw, false);
859 if (ret_val) {
860 e_dbg("Error Disabling LPLU D0\n");
861 return ret_val;
862 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700863 }
864 /* Configure mdi-mdix settings */
865 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CTRL, &data);
866 if (ret_val)
867 return ret_val;
868
869 data &= ~IGP01E1000_PSCR_AUTO_MDIX;
870
871 switch (phy->mdix) {
872 case 1:
873 data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
874 break;
875 case 2:
876 data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
877 break;
878 case 0:
879 default:
880 data |= IGP01E1000_PSCR_AUTO_MDIX;
881 break;
882 }
883 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CTRL, data);
884 if (ret_val)
885 return ret_val;
886
887 /* set auto-master slave resolution settings */
888 if (hw->mac.autoneg) {
Bruce Allane921eb12012-11-28 09:28:37 +0000889 /* when autonegotiation advertisement is only 1000Mbps then we
Auke Kokbc7f75f2007-09-17 12:30:59 -0700890 * should disable SmartSpeed and enable Auto MasterSlave
Bruce Allanad680762008-03-28 09:15:03 -0700891 * resolution as hardware default.
892 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700893 if (phy->autoneg_advertised == ADVERTISE_1000_FULL) {
894 /* Disable SmartSpeed */
895 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -0700896 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700897 if (ret_val)
898 return ret_val;
899
900 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
901 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -0700902 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700903 if (ret_val)
904 return ret_val;
905
906 /* Set auto Master/Slave resolution process */
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000907 ret_val = e1e_rphy(hw, MII_CTRL1000, &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700908 if (ret_val)
909 return ret_val;
910
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000911 data &= ~CTL1000_ENABLE_MASTER;
912 ret_val = e1e_wphy(hw, MII_CTRL1000, data);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700913 if (ret_val)
914 return ret_val;
915 }
916
Bruce Allan7b9f7e32012-03-20 03:47:41 +0000917 ret_val = e1000_set_master_slave_mode(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700918 }
919
920 return ret_val;
921}
922
923/**
924 * e1000_phy_setup_autoneg - Configure PHY for auto-negotiation
925 * @hw: pointer to the HW structure
926 *
927 * Reads the MII auto-neg advertisement register and/or the 1000T control
928 * register and if the PHY is already setup for auto-negotiation, then
929 * return successful. Otherwise, setup advertisement and flow control to
930 * the appropriate values for the wanted auto-negotiation.
931 **/
932static s32 e1000_phy_setup_autoneg(struct e1000_hw *hw)
933{
934 struct e1000_phy_info *phy = &hw->phy;
935 s32 ret_val;
936 u16 mii_autoneg_adv_reg;
937 u16 mii_1000t_ctrl_reg = 0;
938
939 phy->autoneg_advertised &= phy->autoneg_mask;
940
941 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000942 ret_val = e1e_rphy(hw, MII_ADVERTISE, &mii_autoneg_adv_reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700943 if (ret_val)
944 return ret_val;
945
946 if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
947 /* Read the MII 1000Base-T Control Register (Address 9). */
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000948 ret_val = e1e_rphy(hw, MII_CTRL1000, &mii_1000t_ctrl_reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700949 if (ret_val)
950 return ret_val;
951 }
952
Bruce Allane921eb12012-11-28 09:28:37 +0000953 /* Need to parse both autoneg_advertised and fc and set up
Auke Kokbc7f75f2007-09-17 12:30:59 -0700954 * the appropriate PHY registers. First we will parse for
955 * autoneg_advertised software override. Since we can advertise
956 * a plethora of combinations, we need to check each bit
957 * individually.
958 */
959
Bruce Allane921eb12012-11-28 09:28:37 +0000960 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
Auke Kokbc7f75f2007-09-17 12:30:59 -0700961 * Advertisement Register (Address 4) and the 1000 mb speed bits in
962 * the 1000Base-T Control Register (Address 9).
963 */
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000964 mii_autoneg_adv_reg &= ~(ADVERTISE_100FULL |
965 ADVERTISE_100HALF |
966 ADVERTISE_10FULL | ADVERTISE_10HALF);
967 mii_1000t_ctrl_reg &= ~(ADVERTISE_1000HALF | ADVERTISE_1000FULL);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700968
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000969 e_dbg("autoneg_advertised %x\n", phy->autoneg_advertised);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700970
971 /* Do we want to advertise 10 Mb Half Duplex? */
972 if (phy->autoneg_advertised & ADVERTISE_10_HALF) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000973 e_dbg("Advertise 10mb Half duplex\n");
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000974 mii_autoneg_adv_reg |= ADVERTISE_10HALF;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700975 }
976
977 /* Do we want to advertise 10 Mb Full Duplex? */
978 if (phy->autoneg_advertised & ADVERTISE_10_FULL) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000979 e_dbg("Advertise 10mb Full duplex\n");
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000980 mii_autoneg_adv_reg |= ADVERTISE_10FULL;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700981 }
982
983 /* Do we want to advertise 100 Mb Half Duplex? */
984 if (phy->autoneg_advertised & ADVERTISE_100_HALF) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000985 e_dbg("Advertise 100mb Half duplex\n");
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000986 mii_autoneg_adv_reg |= ADVERTISE_100HALF;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700987 }
988
989 /* Do we want to advertise 100 Mb Full Duplex? */
990 if (phy->autoneg_advertised & ADVERTISE_100_FULL) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000991 e_dbg("Advertise 100mb Full duplex\n");
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000992 mii_autoneg_adv_reg |= ADVERTISE_100FULL;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700993 }
994
995 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
996 if (phy->autoneg_advertised & ADVERTISE_1000_HALF)
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000997 e_dbg("Advertise 1000mb Half duplex request denied!\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700998
999 /* Do we want to advertise 1000 Mb Full Duplex? */
1000 if (phy->autoneg_advertised & ADVERTISE_1000_FULL) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001001 e_dbg("Advertise 1000mb Full duplex\n");
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001002 mii_1000t_ctrl_reg |= ADVERTISE_1000FULL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001003 }
1004
Bruce Allane921eb12012-11-28 09:28:37 +00001005 /* Check for a software override of the flow control settings, and
Auke Kokbc7f75f2007-09-17 12:30:59 -07001006 * setup the PHY advertisement registers accordingly. If
1007 * auto-negotiation is enabled, then software will have to set the
1008 * "PAUSE" bits to the correct value in the Auto-Negotiation
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001009 * Advertisement Register (MII_ADVERTISE) and re-start auto-
Auke Kokbc7f75f2007-09-17 12:30:59 -07001010 * negotiation.
1011 *
1012 * The possible values of the "fc" parameter are:
1013 * 0: Flow control is completely disabled
1014 * 1: Rx flow control is enabled (we can receive pause frames
Bruce Allan3d3a1672012-02-23 03:13:18 +00001015 * but not send pause frames).
Auke Kokbc7f75f2007-09-17 12:30:59 -07001016 * 2: Tx flow control is enabled (we can send pause frames
Bruce Allan3d3a1672012-02-23 03:13:18 +00001017 * but we do not support receiving pause frames).
Bruce Allanad680762008-03-28 09:15:03 -07001018 * 3: Both Rx and Tx flow control (symmetric) are enabled.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001019 * other: No software override. The flow control configuration
Bruce Allan3d3a1672012-02-23 03:13:18 +00001020 * in the EEPROM is used.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001021 */
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08001022 switch (hw->fc.current_mode) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001023 case e1000_fc_none:
Bruce Allane921eb12012-11-28 09:28:37 +00001024 /* Flow control (Rx & Tx) is completely disabled by a
Auke Kokbc7f75f2007-09-17 12:30:59 -07001025 * software over-ride.
1026 */
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001027 mii_autoneg_adv_reg &=
1028 ~(ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001029 break;
1030 case e1000_fc_rx_pause:
Bruce Allane921eb12012-11-28 09:28:37 +00001031 /* Rx Flow control is enabled, and Tx Flow control is
Auke Kokbc7f75f2007-09-17 12:30:59 -07001032 * disabled, by a software over-ride.
Bruce Allanad680762008-03-28 09:15:03 -07001033 *
1034 * Since there really isn't a way to advertise that we are
1035 * capable of Rx Pause ONLY, we will advertise that we
1036 * support both symmetric and asymmetric Rx PAUSE. Later
Auke Kokbc7f75f2007-09-17 12:30:59 -07001037 * (in e1000e_config_fc_after_link_up) we will disable the
1038 * hw's ability to send PAUSE frames.
1039 */
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001040 mii_autoneg_adv_reg |=
1041 (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001042 break;
1043 case e1000_fc_tx_pause:
Bruce Allane921eb12012-11-28 09:28:37 +00001044 /* Tx Flow control is enabled, and Rx Flow control is
Auke Kokbc7f75f2007-09-17 12:30:59 -07001045 * disabled, by a software over-ride.
1046 */
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001047 mii_autoneg_adv_reg |= ADVERTISE_PAUSE_ASYM;
1048 mii_autoneg_adv_reg &= ~ADVERTISE_PAUSE_CAP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001049 break;
1050 case e1000_fc_full:
Bruce Allane921eb12012-11-28 09:28:37 +00001051 /* Flow control (both Rx and Tx) is enabled by a software
Auke Kokbc7f75f2007-09-17 12:30:59 -07001052 * over-ride.
1053 */
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001054 mii_autoneg_adv_reg |=
1055 (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001056 break;
1057 default:
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001058 e_dbg("Flow control param set incorrectly\n");
Bruce Allan7eb61d82012-02-08 02:55:03 +00001059 return -E1000_ERR_CONFIG;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001060 }
1061
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001062 ret_val = e1e_wphy(hw, MII_ADVERTISE, mii_autoneg_adv_reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001063 if (ret_val)
1064 return ret_val;
1065
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001066 e_dbg("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001067
Bruce Allanb1cdfea2010-12-11 05:53:47 +00001068 if (phy->autoneg_mask & ADVERTISE_1000_FULL)
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001069 ret_val = e1e_wphy(hw, MII_CTRL1000, mii_1000t_ctrl_reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001070
1071 return ret_val;
1072}
1073
1074/**
1075 * e1000_copper_link_autoneg - Setup/Enable autoneg for copper link
1076 * @hw: pointer to the HW structure
1077 *
1078 * Performs initial bounds checking on autoneg advertisement parameter, then
1079 * configure to advertise the full capability. Setup the PHY to autoneg
1080 * and restart the negotiation process between the link partner. If
Bruce Allanad680762008-03-28 09:15:03 -07001081 * autoneg_wait_to_complete, then wait for autoneg to complete before exiting.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001082 **/
1083static s32 e1000_copper_link_autoneg(struct e1000_hw *hw)
1084{
1085 struct e1000_phy_info *phy = &hw->phy;
1086 s32 ret_val;
1087 u16 phy_ctrl;
1088
Bruce Allane921eb12012-11-28 09:28:37 +00001089 /* Perform some bounds checking on the autoneg advertisement
Auke Kokbc7f75f2007-09-17 12:30:59 -07001090 * parameter.
1091 */
1092 phy->autoneg_advertised &= phy->autoneg_mask;
1093
Bruce Allane921eb12012-11-28 09:28:37 +00001094 /* If autoneg_advertised is zero, we assume it was not defaulted
Auke Kokbc7f75f2007-09-17 12:30:59 -07001095 * by the calling code so we set to advertise full capability.
1096 */
Bruce Allan04499ec2012-04-13 00:08:31 +00001097 if (!phy->autoneg_advertised)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001098 phy->autoneg_advertised = phy->autoneg_mask;
1099
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001100 e_dbg("Reconfiguring auto-neg advertisement params\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001101 ret_val = e1000_phy_setup_autoneg(hw);
1102 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001103 e_dbg("Error Setting up Auto-Negotiation\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001104 return ret_val;
1105 }
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001106 e_dbg("Restarting Auto-Neg\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001107
Bruce Allane921eb12012-11-28 09:28:37 +00001108 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
Auke Kokbc7f75f2007-09-17 12:30:59 -07001109 * the Auto Neg Restart bit in the PHY control register.
1110 */
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001111 ret_val = e1e_rphy(hw, MII_BMCR, &phy_ctrl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001112 if (ret_val)
1113 return ret_val;
1114
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001115 phy_ctrl |= (BMCR_ANENABLE | BMCR_ANRESTART);
1116 ret_val = e1e_wphy(hw, MII_BMCR, phy_ctrl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001117 if (ret_val)
1118 return ret_val;
1119
Bruce Allane921eb12012-11-28 09:28:37 +00001120 /* Does the user want to wait for Auto-Neg to complete here, or
Auke Kokbc7f75f2007-09-17 12:30:59 -07001121 * check at a later time (for example, callback routine).
1122 */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001123 if (phy->autoneg_wait_to_complete) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001124 ret_val = e1000_wait_autoneg(hw);
1125 if (ret_val) {
Bruce Allan434f1392011-12-16 00:46:54 +00001126 e_dbg("Error while waiting for autoneg to complete\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001127 return ret_val;
1128 }
1129 }
1130
Bruce Allanf92518d2012-02-01 11:16:42 +00001131 hw->mac.get_link_status = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001132
1133 return ret_val;
1134}
1135
1136/**
1137 * e1000e_setup_copper_link - Configure copper link settings
1138 * @hw: pointer to the HW structure
1139 *
1140 * Calls the appropriate function to configure the link for auto-neg or forced
1141 * speed and duplex. Then we check for link, once link is established calls
1142 * to configure collision distance and flow control are called. If link is
1143 * not established, we return -E1000_ERR_PHY (-2).
1144 **/
1145s32 e1000e_setup_copper_link(struct e1000_hw *hw)
1146{
1147 s32 ret_val;
1148 bool link;
1149
1150 if (hw->mac.autoneg) {
Bruce Allane921eb12012-11-28 09:28:37 +00001151 /* Setup autoneg and flow control advertisement and perform
Bruce Allanad680762008-03-28 09:15:03 -07001152 * autonegotiation.
1153 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001154 ret_val = e1000_copper_link_autoneg(hw);
1155 if (ret_val)
1156 return ret_val;
1157 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00001158 /* PHY will be set to 10H, 10F, 100H or 100F
Bruce Allanad680762008-03-28 09:15:03 -07001159 * depending on user settings.
1160 */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001161 e_dbg("Forcing Speed and Duplex\n");
Bruce Allanc2c66292013-01-05 08:06:08 +00001162 ret_val = hw->phy.ops.force_speed_duplex(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001163 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001164 e_dbg("Error Forcing Speed and Duplex\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001165 return ret_val;
1166 }
1167 }
1168
Bruce Allane921eb12012-11-28 09:28:37 +00001169 /* Check link status. Wait up to 100 microseconds for link to become
Auke Kokbc7f75f2007-09-17 12:30:59 -07001170 * valid.
1171 */
Bruce Allan3d3a1672012-02-23 03:13:18 +00001172 ret_val = e1000e_phy_has_link_generic(hw, COPPER_LINK_UP_LIMIT, 10,
1173 &link);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001174 if (ret_val)
1175 return ret_val;
1176
1177 if (link) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001178 e_dbg("Valid link established!!!\n");
Bruce Allan57cde762012-02-22 09:02:58 +00001179 hw->mac.ops.config_collision_dist(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001180 ret_val = e1000e_config_fc_after_link_up(hw);
1181 } else {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001182 e_dbg("Unable to establish link!!!\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001183 }
1184
1185 return ret_val;
1186}
1187
1188/**
1189 * e1000e_phy_force_speed_duplex_igp - Force speed/duplex for igp PHY
1190 * @hw: pointer to the HW structure
1191 *
1192 * Calls the PHY setup function to force speed and duplex. Clears the
1193 * auto-crossover to force MDI manually. Waits for link and returns
1194 * successful if link up is successful, else -E1000_ERR_PHY (-2).
1195 **/
1196s32 e1000e_phy_force_speed_duplex_igp(struct e1000_hw *hw)
1197{
1198 struct e1000_phy_info *phy = &hw->phy;
1199 s32 ret_val;
1200 u16 phy_data;
1201 bool link;
1202
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001203 ret_val = e1e_rphy(hw, MII_BMCR, &phy_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001204 if (ret_val)
1205 return ret_val;
1206
1207 e1000e_phy_force_speed_duplex_setup(hw, &phy_data);
1208
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001209 ret_val = e1e_wphy(hw, MII_BMCR, phy_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001210 if (ret_val)
1211 return ret_val;
1212
Bruce Allane921eb12012-11-28 09:28:37 +00001213 /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
Auke Kokbc7f75f2007-09-17 12:30:59 -07001214 * forced whenever speed and duplex are forced.
1215 */
1216 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1217 if (ret_val)
1218 return ret_val;
1219
1220 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1221 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1222
1223 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1224 if (ret_val)
1225 return ret_val;
1226
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001227 e_dbg("IGP PSCR: %X\n", phy_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001228
1229 udelay(1);
1230
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001231 if (phy->autoneg_wait_to_complete) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001232 e_dbg("Waiting for forced speed/duplex link on IGP phy.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001233
Bruce Allan3d3a1672012-02-23 03:13:18 +00001234 ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
1235 100000, &link);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001236 if (ret_val)
1237 return ret_val;
1238
1239 if (!link)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001240 e_dbg("Link taking longer than expected.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001241
1242 /* Try once more */
Bruce Allan3d3a1672012-02-23 03:13:18 +00001243 ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
1244 100000, &link);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001245 }
1246
1247 return ret_val;
1248}
1249
1250/**
1251 * e1000e_phy_force_speed_duplex_m88 - Force speed/duplex for m88 PHY
1252 * @hw: pointer to the HW structure
1253 *
1254 * Calls the PHY setup function to force speed and duplex. Clears the
1255 * auto-crossover to force MDI manually. Resets the PHY to commit the
1256 * changes. If time expires while waiting for link up, we reset the DSP.
Bruce Allanad680762008-03-28 09:15:03 -07001257 * After reset, TX_CLK and CRS on Tx must be set. Return successful upon
Auke Kokbc7f75f2007-09-17 12:30:59 -07001258 * successful completion, else return corresponding error code.
1259 **/
1260s32 e1000e_phy_force_speed_duplex_m88(struct e1000_hw *hw)
1261{
1262 struct e1000_phy_info *phy = &hw->phy;
1263 s32 ret_val;
1264 u16 phy_data;
1265 bool link;
1266
Bruce Allane921eb12012-11-28 09:28:37 +00001267 /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
Auke Kokbc7f75f2007-09-17 12:30:59 -07001268 * forced whenever speed and duplex are forced.
1269 */
1270 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1271 if (ret_val)
1272 return ret_val;
1273
1274 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1275 ret_val = e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1276 if (ret_val)
1277 return ret_val;
1278
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001279 e_dbg("M88E1000 PSCR: %X\n", phy_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001280
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001281 ret_val = e1e_rphy(hw, MII_BMCR, &phy_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001282 if (ret_val)
1283 return ret_val;
1284
1285 e1000e_phy_force_speed_duplex_setup(hw, &phy_data);
1286
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001287 ret_val = e1e_wphy(hw, MII_BMCR, phy_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001288 if (ret_val)
1289 return ret_val;
1290
Bruce Allan5aa49c82008-11-21 16:49:53 -08001291 /* Reset the phy to commit changes. */
Bruce Allan6b598e12013-01-23 06:50:05 +00001292 if (hw->phy.ops.commit) {
1293 ret_val = hw->phy.ops.commit(hw);
1294 if (ret_val)
1295 return ret_val;
1296 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001297
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001298 if (phy->autoneg_wait_to_complete) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001299 e_dbg("Waiting for forced speed/duplex link on M88 phy.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001300
1301 ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
Bruce Allan17e813e2013-02-20 04:06:01 +00001302 100000, &link);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001303 if (ret_val)
1304 return ret_val;
1305
1306 if (!link) {
Bruce Allan0be84012009-12-02 17:03:18 +00001307 if (hw->phy.type != e1000_phy_m88) {
1308 e_dbg("Link taking longer than expected.\n");
1309 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00001310 /* We didn't get link.
Bruce Allan0be84012009-12-02 17:03:18 +00001311 * Reset the DSP and cross our fingers.
1312 */
Bruce Allan482fed82011-01-06 14:29:49 +00001313 ret_val = e1e_wphy(hw, M88E1000_PHY_PAGE_SELECT,
1314 0x001d);
Bruce Allan0be84012009-12-02 17:03:18 +00001315 if (ret_val)
1316 return ret_val;
1317 ret_val = e1000e_phy_reset_dsp(hw);
1318 if (ret_val)
1319 return ret_val;
1320 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001321 }
1322
1323 /* Try once more */
1324 ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
Bruce Allan17e813e2013-02-20 04:06:01 +00001325 100000, &link);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001326 if (ret_val)
1327 return ret_val;
1328 }
1329
Bruce Allan0be84012009-12-02 17:03:18 +00001330 if (hw->phy.type != e1000_phy_m88)
1331 return 0;
1332
Auke Kokbc7f75f2007-09-17 12:30:59 -07001333 ret_val = e1e_rphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1334 if (ret_val)
1335 return ret_val;
1336
Bruce Allane921eb12012-11-28 09:28:37 +00001337 /* Resetting the phy means we need to re-force TX_CLK in the
Auke Kokbc7f75f2007-09-17 12:30:59 -07001338 * Extended PHY Specific Control Register to 25MHz clock from
1339 * the reset value of 2.5MHz.
1340 */
1341 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1342 ret_val = e1e_wphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1343 if (ret_val)
1344 return ret_val;
1345
Bruce Allane921eb12012-11-28 09:28:37 +00001346 /* In addition, we must re-enable CRS on Tx for both half and full
Auke Kokbc7f75f2007-09-17 12:30:59 -07001347 * duplex.
1348 */
1349 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1350 if (ret_val)
1351 return ret_val;
1352
1353 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1354 ret_val = e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1355
1356 return ret_val;
1357}
1358
1359/**
Bruce Allan0be84012009-12-02 17:03:18 +00001360 * e1000_phy_force_speed_duplex_ife - Force PHY speed & duplex
1361 * @hw: pointer to the HW structure
1362 *
1363 * Forces the speed and duplex settings of the PHY.
1364 * This is a function pointer entry point only called by
1365 * PHY setup routines.
1366 **/
1367s32 e1000_phy_force_speed_duplex_ife(struct e1000_hw *hw)
1368{
1369 struct e1000_phy_info *phy = &hw->phy;
1370 s32 ret_val;
1371 u16 data;
1372 bool link;
1373
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001374 ret_val = e1e_rphy(hw, MII_BMCR, &data);
Bruce Allan0be84012009-12-02 17:03:18 +00001375 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001376 return ret_val;
Bruce Allan0be84012009-12-02 17:03:18 +00001377
1378 e1000e_phy_force_speed_duplex_setup(hw, &data);
1379
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001380 ret_val = e1e_wphy(hw, MII_BMCR, data);
Bruce Allan0be84012009-12-02 17:03:18 +00001381 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001382 return ret_val;
Bruce Allan0be84012009-12-02 17:03:18 +00001383
1384 /* Disable MDI-X support for 10/100 */
1385 ret_val = e1e_rphy(hw, IFE_PHY_MDIX_CONTROL, &data);
1386 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001387 return ret_val;
Bruce Allan0be84012009-12-02 17:03:18 +00001388
1389 data &= ~IFE_PMC_AUTO_MDIX;
1390 data &= ~IFE_PMC_FORCE_MDIX;
1391
1392 ret_val = e1e_wphy(hw, IFE_PHY_MDIX_CONTROL, data);
1393 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001394 return ret_val;
Bruce Allan0be84012009-12-02 17:03:18 +00001395
1396 e_dbg("IFE PMC: %X\n", data);
1397
1398 udelay(1);
1399
1400 if (phy->autoneg_wait_to_complete) {
1401 e_dbg("Waiting for forced speed/duplex link on IFE phy.\n");
1402
Bruce Allan3d3a1672012-02-23 03:13:18 +00001403 ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
1404 100000, &link);
Bruce Allan0be84012009-12-02 17:03:18 +00001405 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001406 return ret_val;
Bruce Allan0be84012009-12-02 17:03:18 +00001407
1408 if (!link)
1409 e_dbg("Link taking longer than expected.\n");
1410
1411 /* Try once more */
Bruce Allan3d3a1672012-02-23 03:13:18 +00001412 ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
1413 100000, &link);
Bruce Allan0be84012009-12-02 17:03:18 +00001414 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001415 return ret_val;
Bruce Allan0be84012009-12-02 17:03:18 +00001416 }
1417
Bruce Allan5015e532012-02-08 02:55:56 +00001418 return 0;
Bruce Allan0be84012009-12-02 17:03:18 +00001419}
1420
1421/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001422 * e1000e_phy_force_speed_duplex_setup - Configure forced PHY speed/duplex
1423 * @hw: pointer to the HW structure
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001424 * @phy_ctrl: pointer to current value of MII_BMCR
Auke Kokbc7f75f2007-09-17 12:30:59 -07001425 *
1426 * Forces speed and duplex on the PHY by doing the following: disable flow
1427 * control, force speed/duplex on the MAC, disable auto speed detection,
1428 * disable auto-negotiation, configure duplex, configure speed, configure
1429 * the collision distance, write configuration to CTRL register. The
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001430 * caller must write to the MII_BMCR register for these settings to
Auke Kokbc7f75f2007-09-17 12:30:59 -07001431 * take affect.
1432 **/
1433void e1000e_phy_force_speed_duplex_setup(struct e1000_hw *hw, u16 *phy_ctrl)
1434{
1435 struct e1000_mac_info *mac = &hw->mac;
1436 u32 ctrl;
1437
1438 /* Turn off flow control when forcing speed/duplex */
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08001439 hw->fc.current_mode = e1000_fc_none;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001440
1441 /* Force speed/duplex on the mac */
1442 ctrl = er32(CTRL);
1443 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1444 ctrl &= ~E1000_CTRL_SPD_SEL;
1445
1446 /* Disable Auto Speed Detection */
1447 ctrl &= ~E1000_CTRL_ASDE;
1448
1449 /* Disable autoneg on the phy */
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001450 *phy_ctrl &= ~BMCR_ANENABLE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001451
1452 /* Forcing Full or Half Duplex? */
1453 if (mac->forced_speed_duplex & E1000_ALL_HALF_DUPLEX) {
1454 ctrl &= ~E1000_CTRL_FD;
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001455 *phy_ctrl &= ~BMCR_FULLDPLX;
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001456 e_dbg("Half Duplex\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001457 } else {
1458 ctrl |= E1000_CTRL_FD;
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001459 *phy_ctrl |= BMCR_FULLDPLX;
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001460 e_dbg("Full Duplex\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001461 }
1462
1463 /* Forcing 10mb or 100mb? */
1464 if (mac->forced_speed_duplex & E1000_ALL_100_SPEED) {
1465 ctrl |= E1000_CTRL_SPD_100;
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001466 *phy_ctrl |= BMCR_SPEED100;
1467 *phy_ctrl &= ~BMCR_SPEED1000;
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001468 e_dbg("Forcing 100mb\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001469 } else {
1470 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001471 *phy_ctrl &= ~(BMCR_SPEED1000 | BMCR_SPEED100);
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001472 e_dbg("Forcing 10mb\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001473 }
1474
Bruce Allan57cde762012-02-22 09:02:58 +00001475 hw->mac.ops.config_collision_dist(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001476
1477 ew32(CTRL, ctrl);
1478}
1479
1480/**
1481 * e1000e_set_d3_lplu_state - Sets low power link up state for D3
1482 * @hw: pointer to the HW structure
1483 * @active: boolean used to enable/disable lplu
1484 *
1485 * Success returns 0, Failure returns 1
1486 *
1487 * The low power link up (lplu) state is set to the power management level D3
1488 * and SmartSpeed is disabled when active is true, else clear lplu for D3
1489 * and enable Smartspeed. LPLU and Smartspeed are mutually exclusive. LPLU
1490 * is used during Dx states where the power conservation is most important.
1491 * During driver activity, SmartSpeed should be enabled so performance is
1492 * maintained.
1493 **/
1494s32 e1000e_set_d3_lplu_state(struct e1000_hw *hw, bool active)
1495{
1496 struct e1000_phy_info *phy = &hw->phy;
1497 s32 ret_val;
1498 u16 data;
1499
1500 ret_val = e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &data);
1501 if (ret_val)
1502 return ret_val;
1503
1504 if (!active) {
1505 data &= ~IGP02E1000_PM_D3_LPLU;
David Graham2d9498f2008-04-23 11:09:14 -07001506 ret_val = e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001507 if (ret_val)
1508 return ret_val;
Bruce Allane921eb12012-11-28 09:28:37 +00001509 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
Auke Kokbc7f75f2007-09-17 12:30:59 -07001510 * during Dx states where the power conservation is most
1511 * important. During driver activity we should enable
Bruce Allanad680762008-03-28 09:15:03 -07001512 * SmartSpeed, so performance is maintained.
1513 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001514 if (phy->smart_speed == e1000_smart_speed_on) {
1515 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07001516 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001517 if (ret_val)
1518 return ret_val;
1519
1520 data |= IGP01E1000_PSCFR_SMART_SPEED;
1521 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07001522 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001523 if (ret_val)
1524 return ret_val;
1525 } else if (phy->smart_speed == e1000_smart_speed_off) {
1526 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07001527 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001528 if (ret_val)
1529 return ret_val;
1530
1531 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1532 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07001533 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001534 if (ret_val)
1535 return ret_val;
1536 }
1537 } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
1538 (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
1539 (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
1540 data |= IGP02E1000_PM_D3_LPLU;
1541 ret_val = e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, data);
1542 if (ret_val)
1543 return ret_val;
1544
1545 /* When LPLU is enabled, we should disable SmartSpeed */
1546 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
1547 if (ret_val)
1548 return ret_val;
1549
1550 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1551 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
1552 }
1553
1554 return ret_val;
1555}
1556
1557/**
Auke Kok489815c2008-02-21 15:11:07 -08001558 * e1000e_check_downshift - Checks whether a downshift in speed occurred
Auke Kokbc7f75f2007-09-17 12:30:59 -07001559 * @hw: pointer to the HW structure
1560 *
1561 * Success returns 0, Failure returns 1
1562 *
1563 * A downshift is detected by querying the PHY link health.
1564 **/
1565s32 e1000e_check_downshift(struct e1000_hw *hw)
1566{
1567 struct e1000_phy_info *phy = &hw->phy;
1568 s32 ret_val;
1569 u16 phy_data, offset, mask;
1570
1571 switch (phy->type) {
1572 case e1000_phy_m88:
1573 case e1000_phy_gg82563:
Bruce Allan07f025e2009-12-01 15:53:48 +00001574 case e1000_phy_bm:
Bruce Allana4f58f52009-06-02 11:29:18 +00001575 case e1000_phy_82578:
Auke Kokbc7f75f2007-09-17 12:30:59 -07001576 offset = M88E1000_PHY_SPEC_STATUS;
1577 mask = M88E1000_PSSR_DOWNSHIFT;
1578 break;
1579 case e1000_phy_igp_2:
1580 case e1000_phy_igp_3:
1581 offset = IGP01E1000_PHY_LINK_HEALTH;
1582 mask = IGP01E1000_PLHR_SS_DOWNGRADE;
1583 break;
1584 default:
1585 /* speed downshift not supported */
Bruce Allan564ea9b2009-11-20 23:26:44 +00001586 phy->speed_downgraded = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001587 return 0;
1588 }
1589
1590 ret_val = e1e_rphy(hw, offset, &phy_data);
1591
1592 if (!ret_val)
Bruce Allan04499ec2012-04-13 00:08:31 +00001593 phy->speed_downgraded = !!(phy_data & mask);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001594
1595 return ret_val;
1596}
1597
1598/**
1599 * e1000_check_polarity_m88 - Checks the polarity.
1600 * @hw: pointer to the HW structure
1601 *
1602 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1603 *
1604 * Polarity is determined based on the PHY specific status register.
1605 **/
Bruce Allan0be84012009-12-02 17:03:18 +00001606s32 e1000_check_polarity_m88(struct e1000_hw *hw)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001607{
1608 struct e1000_phy_info *phy = &hw->phy;
1609 s32 ret_val;
1610 u16 data;
1611
1612 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &data);
1613
1614 if (!ret_val)
Bruce Allanf0ff4392013-02-20 04:05:39 +00001615 phy->cable_polarity = ((data & M88E1000_PSSR_REV_POLARITY)
1616 ? e1000_rev_polarity_reversed
1617 : e1000_rev_polarity_normal);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001618
1619 return ret_val;
1620}
1621
1622/**
1623 * e1000_check_polarity_igp - Checks the polarity.
1624 * @hw: pointer to the HW structure
1625 *
1626 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1627 *
1628 * Polarity is determined based on the PHY port status register, and the
1629 * current speed (since there is no polarity at 100Mbps).
1630 **/
Bruce Allan0be84012009-12-02 17:03:18 +00001631s32 e1000_check_polarity_igp(struct e1000_hw *hw)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001632{
1633 struct e1000_phy_info *phy = &hw->phy;
1634 s32 ret_val;
1635 u16 data, offset, mask;
1636
Bruce Allane921eb12012-11-28 09:28:37 +00001637 /* Polarity is determined based on the speed of
Bruce Allanad680762008-03-28 09:15:03 -07001638 * our connection.
1639 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001640 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_STATUS, &data);
1641 if (ret_val)
1642 return ret_val;
1643
1644 if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
1645 IGP01E1000_PSSR_SPEED_1000MBPS) {
1646 offset = IGP01E1000_PHY_PCS_INIT_REG;
1647 mask = IGP01E1000_PHY_POLARITY_MASK;
1648 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00001649 /* This really only applies to 10Mbps since
Auke Kokbc7f75f2007-09-17 12:30:59 -07001650 * there is no polarity for 100Mbps (always 0).
1651 */
1652 offset = IGP01E1000_PHY_PORT_STATUS;
1653 mask = IGP01E1000_PSSR_POLARITY_REVERSED;
1654 }
1655
1656 ret_val = e1e_rphy(hw, offset, &data);
1657
1658 if (!ret_val)
Bruce Allanf0ff4392013-02-20 04:05:39 +00001659 phy->cable_polarity = ((data & mask)
1660 ? e1000_rev_polarity_reversed
1661 : e1000_rev_polarity_normal);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001662
1663 return ret_val;
1664}
1665
1666/**
Bruce Allan0be84012009-12-02 17:03:18 +00001667 * e1000_check_polarity_ife - Check cable polarity for IFE PHY
1668 * @hw: pointer to the HW structure
1669 *
1670 * Polarity is determined on the polarity reversal feature being enabled.
1671 **/
1672s32 e1000_check_polarity_ife(struct e1000_hw *hw)
1673{
1674 struct e1000_phy_info *phy = &hw->phy;
1675 s32 ret_val;
1676 u16 phy_data, offset, mask;
1677
Bruce Allane921eb12012-11-28 09:28:37 +00001678 /* Polarity is determined based on the reversal feature being enabled.
Bruce Allan0be84012009-12-02 17:03:18 +00001679 */
1680 if (phy->polarity_correction) {
1681 offset = IFE_PHY_EXTENDED_STATUS_CONTROL;
1682 mask = IFE_PESC_POLARITY_REVERSED;
1683 } else {
1684 offset = IFE_PHY_SPECIAL_CONTROL;
1685 mask = IFE_PSC_FORCE_POLARITY;
1686 }
1687
1688 ret_val = e1e_rphy(hw, offset, &phy_data);
1689
1690 if (!ret_val)
Bruce Allanf0ff4392013-02-20 04:05:39 +00001691 phy->cable_polarity = ((phy_data & mask)
1692 ? e1000_rev_polarity_reversed
1693 : e1000_rev_polarity_normal);
Bruce Allan0be84012009-12-02 17:03:18 +00001694
1695 return ret_val;
1696}
1697
1698/**
Bruce Allanad680762008-03-28 09:15:03 -07001699 * e1000_wait_autoneg - Wait for auto-neg completion
Auke Kokbc7f75f2007-09-17 12:30:59 -07001700 * @hw: pointer to the HW structure
1701 *
1702 * Waits for auto-negotiation to complete or for the auto-negotiation time
1703 * limit to expire, which ever happens first.
1704 **/
1705static s32 e1000_wait_autoneg(struct e1000_hw *hw)
1706{
1707 s32 ret_val = 0;
1708 u16 i, phy_status;
1709
1710 /* Break after autoneg completes or PHY_AUTO_NEG_LIMIT expires. */
1711 for (i = PHY_AUTO_NEG_LIMIT; i > 0; i--) {
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001712 ret_val = e1e_rphy(hw, MII_BMSR, &phy_status);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001713 if (ret_val)
1714 break;
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001715 ret_val = e1e_rphy(hw, MII_BMSR, &phy_status);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001716 if (ret_val)
1717 break;
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001718 if (phy_status & BMSR_ANEGCOMPLETE)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001719 break;
1720 msleep(100);
1721 }
1722
Bruce Allane921eb12012-11-28 09:28:37 +00001723 /* PHY_AUTO_NEG_TIME expiration doesn't guarantee auto-negotiation
Auke Kokbc7f75f2007-09-17 12:30:59 -07001724 * has completed.
1725 */
1726 return ret_val;
1727}
1728
1729/**
1730 * e1000e_phy_has_link_generic - Polls PHY for link
1731 * @hw: pointer to the HW structure
1732 * @iterations: number of times to poll for link
1733 * @usec_interval: delay between polling attempts
1734 * @success: pointer to whether polling was successful or not
1735 *
1736 * Polls the PHY status register for link, 'iterations' number of times.
1737 **/
1738s32 e1000e_phy_has_link_generic(struct e1000_hw *hw, u32 iterations,
Bruce Allan17e813e2013-02-20 04:06:01 +00001739 u32 usec_interval, bool *success)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001740{
1741 s32 ret_val = 0;
1742 u16 i, phy_status;
1743
1744 for (i = 0; i < iterations; i++) {
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001745 /* Some PHYs require the MII_BMSR register to be read
Auke Kokbc7f75f2007-09-17 12:30:59 -07001746 * twice due to the link bit being sticky. No harm doing
1747 * it across the board.
1748 */
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001749 ret_val = e1e_rphy(hw, MII_BMSR, &phy_status);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001750 if (ret_val)
Bruce Allane921eb12012-11-28 09:28:37 +00001751 /* If the first read fails, another entity may have
Bruce Allan906e8d92009-07-01 13:28:50 +00001752 * ownership of the resources, wait and try again to
1753 * see if they have relinquished the resources yet.
1754 */
1755 udelay(usec_interval);
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001756 ret_val = e1e_rphy(hw, MII_BMSR, &phy_status);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001757 if (ret_val)
1758 break;
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001759 if (phy_status & BMSR_LSTATUS)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001760 break;
1761 if (usec_interval >= 1000)
Bruce Allan362e20c2013-02-20 04:05:45 +00001762 mdelay(usec_interval / 1000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001763 else
1764 udelay(usec_interval);
1765 }
1766
1767 *success = (i < iterations);
1768
1769 return ret_val;
1770}
1771
1772/**
1773 * e1000e_get_cable_length_m88 - Determine cable length for m88 PHY
1774 * @hw: pointer to the HW structure
1775 *
1776 * Reads the PHY specific status register to retrieve the cable length
1777 * information. The cable length is determined by averaging the minimum and
1778 * maximum values to get the "average" cable length. The m88 PHY has four
1779 * possible cable length values, which are:
1780 * Register Value Cable Length
1781 * 0 < 50 meters
1782 * 1 50 - 80 meters
1783 * 2 80 - 110 meters
1784 * 3 110 - 140 meters
1785 * 4 > 140 meters
1786 **/
1787s32 e1000e_get_cable_length_m88(struct e1000_hw *hw)
1788{
1789 struct e1000_phy_info *phy = &hw->phy;
1790 s32 ret_val;
1791 u16 phy_data, index;
1792
1793 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
1794 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001795 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001796
Bruce Allanf0ff4392013-02-20 04:05:39 +00001797 index = ((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
1798 M88E1000_PSSR_CABLE_LENGTH_SHIFT);
Bruce Allan5015e532012-02-08 02:55:56 +00001799
1800 if (index >= M88E1000_CABLE_LENGTH_TABLE_SIZE - 1)
1801 return -E1000_ERR_PHY;
Bruce Allaneb656d42009-12-01 15:47:02 +00001802
Auke Kokbc7f75f2007-09-17 12:30:59 -07001803 phy->min_cable_length = e1000_m88_cable_length_table[index];
Bruce Allaneb656d42009-12-01 15:47:02 +00001804 phy->max_cable_length = e1000_m88_cable_length_table[index + 1];
Auke Kokbc7f75f2007-09-17 12:30:59 -07001805
1806 phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
1807
Bruce Allan5015e532012-02-08 02:55:56 +00001808 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001809}
1810
1811/**
1812 * e1000e_get_cable_length_igp_2 - Determine cable length for igp2 PHY
1813 * @hw: pointer to the HW structure
1814 *
1815 * The automatic gain control (agc) normalizes the amplitude of the
1816 * received signal, adjusting for the attenuation produced by the
Auke Kok489815c2008-02-21 15:11:07 -08001817 * cable. By reading the AGC registers, which represent the
Bruce Allan5ff5b662009-12-01 15:51:11 +00001818 * combination of coarse and fine gain value, the value can be put
Auke Kokbc7f75f2007-09-17 12:30:59 -07001819 * into a lookup table to obtain the approximate cable length
1820 * for each channel.
1821 **/
1822s32 e1000e_get_cable_length_igp_2(struct e1000_hw *hw)
1823{
1824 struct e1000_phy_info *phy = &hw->phy;
1825 s32 ret_val;
1826 u16 phy_data, i, agc_value = 0;
1827 u16 cur_agc_index, max_agc_index = 0;
1828 u16 min_agc_index = IGP02E1000_CABLE_LENGTH_TABLE_SIZE - 1;
Jeff Kirsher66744502010-12-01 19:59:50 +00001829 static const u16 agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] = {
Bruce Allanf0ff4392013-02-20 04:05:39 +00001830 IGP02E1000_PHY_AGC_A,
1831 IGP02E1000_PHY_AGC_B,
1832 IGP02E1000_PHY_AGC_C,
1833 IGP02E1000_PHY_AGC_D
Jeff Kirsher66744502010-12-01 19:59:50 +00001834 };
Auke Kokbc7f75f2007-09-17 12:30:59 -07001835
1836 /* Read the AGC registers for all channels */
1837 for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
1838 ret_val = e1e_rphy(hw, agc_reg_array[i], &phy_data);
1839 if (ret_val)
1840 return ret_val;
1841
Bruce Allane921eb12012-11-28 09:28:37 +00001842 /* Getting bits 15:9, which represent the combination of
Bruce Allan5ff5b662009-12-01 15:51:11 +00001843 * coarse and fine gain values. The result is a number
Auke Kokbc7f75f2007-09-17 12:30:59 -07001844 * that can be put into the lookup table to obtain the
Bruce Allanad680762008-03-28 09:15:03 -07001845 * approximate cable length.
1846 */
Bruce Allanf0ff4392013-02-20 04:05:39 +00001847 cur_agc_index = ((phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
1848 IGP02E1000_AGC_LENGTH_MASK);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001849
1850 /* Array index bound check. */
1851 if ((cur_agc_index >= IGP02E1000_CABLE_LENGTH_TABLE_SIZE) ||
1852 (cur_agc_index == 0))
1853 return -E1000_ERR_PHY;
1854
1855 /* Remove min & max AGC values from calculation. */
1856 if (e1000_igp_2_cable_length_table[min_agc_index] >
1857 e1000_igp_2_cable_length_table[cur_agc_index])
1858 min_agc_index = cur_agc_index;
1859 if (e1000_igp_2_cable_length_table[max_agc_index] <
1860 e1000_igp_2_cable_length_table[cur_agc_index])
1861 max_agc_index = cur_agc_index;
1862
1863 agc_value += e1000_igp_2_cable_length_table[cur_agc_index];
1864 }
1865
1866 agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] +
1867 e1000_igp_2_cable_length_table[max_agc_index]);
1868 agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
1869
1870 /* Calculate cable length with the error range of +/- 10 meters. */
Bruce Allanf0ff4392013-02-20 04:05:39 +00001871 phy->min_cable_length = (((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
1872 (agc_value - IGP02E1000_AGC_RANGE) : 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001873 phy->max_cable_length = agc_value + IGP02E1000_AGC_RANGE;
1874
1875 phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
1876
Bruce Allan82607252012-02-08 02:55:09 +00001877 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001878}
1879
1880/**
1881 * e1000e_get_phy_info_m88 - Retrieve PHY information
1882 * @hw: pointer to the HW structure
1883 *
1884 * Valid for only copper links. Read the PHY status register (sticky read)
1885 * to verify that link is up. Read the PHY special control register to
1886 * determine the polarity and 10base-T extended distance. Read the PHY
1887 * special status register to determine MDI/MDIx and current speed. If
1888 * speed is 1000, then determine cable length, local and remote receiver.
1889 **/
1890s32 e1000e_get_phy_info_m88(struct e1000_hw *hw)
1891{
1892 struct e1000_phy_info *phy = &hw->phy;
1893 s32 ret_val;
1894 u16 phy_data;
1895 bool link;
1896
Bruce Allan0be84012009-12-02 17:03:18 +00001897 if (phy->media_type != e1000_media_type_copper) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001898 e_dbg("Phy info is only valid for copper media\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001899 return -E1000_ERR_CONFIG;
1900 }
1901
1902 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
1903 if (ret_val)
1904 return ret_val;
1905
1906 if (!link) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001907 e_dbg("Phy info is only valid if link is up\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001908 return -E1000_ERR_CONFIG;
1909 }
1910
1911 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1912 if (ret_val)
1913 return ret_val;
1914
Bruce Allan04499ec2012-04-13 00:08:31 +00001915 phy->polarity_correction = !!(phy_data &
1916 M88E1000_PSCR_POLARITY_REVERSAL);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001917
1918 ret_val = e1000_check_polarity_m88(hw);
1919 if (ret_val)
1920 return ret_val;
1921
1922 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
1923 if (ret_val)
1924 return ret_val;
1925
Bruce Allan04499ec2012-04-13 00:08:31 +00001926 phy->is_mdix = !!(phy_data & M88E1000_PSSR_MDIX);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001927
1928 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
Bruce Allandde3a572013-01-05 08:06:24 +00001929 ret_val = hw->phy.ops.get_cable_length(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001930 if (ret_val)
1931 return ret_val;
1932
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001933 ret_val = e1e_rphy(hw, MII_STAT1000, &phy_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001934 if (ret_val)
1935 return ret_val;
1936
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001937 phy->local_rx = (phy_data & LPA_1000LOCALRXOK)
1938 ? e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001939
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001940 phy->remote_rx = (phy_data & LPA_1000REMRXOK)
1941 ? e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001942 } else {
1943 /* Set values to "undefined" */
1944 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
1945 phy->local_rx = e1000_1000t_rx_status_undefined;
1946 phy->remote_rx = e1000_1000t_rx_status_undefined;
1947 }
1948
1949 return ret_val;
1950}
1951
1952/**
1953 * e1000e_get_phy_info_igp - Retrieve igp PHY information
1954 * @hw: pointer to the HW structure
1955 *
1956 * Read PHY status to determine if link is up. If link is up, then
1957 * set/determine 10base-T extended distance and polarity correction. Read
1958 * PHY port status to determine MDI/MDIx and speed. Based on the speed,
1959 * determine on the cable length, local and remote receiver.
1960 **/
1961s32 e1000e_get_phy_info_igp(struct e1000_hw *hw)
1962{
1963 struct e1000_phy_info *phy = &hw->phy;
1964 s32 ret_val;
1965 u16 data;
1966 bool link;
1967
1968 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
1969 if (ret_val)
1970 return ret_val;
1971
1972 if (!link) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001973 e_dbg("Phy info is only valid if link is up\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001974 return -E1000_ERR_CONFIG;
1975 }
1976
Bruce Allan564ea9b2009-11-20 23:26:44 +00001977 phy->polarity_correction = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001978
1979 ret_val = e1000_check_polarity_igp(hw);
1980 if (ret_val)
1981 return ret_val;
1982
1983 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_STATUS, &data);
1984 if (ret_val)
1985 return ret_val;
1986
Bruce Allan04499ec2012-04-13 00:08:31 +00001987 phy->is_mdix = !!(data & IGP01E1000_PSSR_MDIX);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001988
1989 if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
1990 IGP01E1000_PSSR_SPEED_1000MBPS) {
Bruce Allandde3a572013-01-05 08:06:24 +00001991 ret_val = phy->ops.get_cable_length(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001992 if (ret_val)
1993 return ret_val;
1994
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001995 ret_val = e1e_rphy(hw, MII_STAT1000, &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001996 if (ret_val)
1997 return ret_val;
1998
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001999 phy->local_rx = (data & LPA_1000LOCALRXOK)
2000 ? e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002001
Bruce Allanc2ade1a2013-01-16 08:54:35 +00002002 phy->remote_rx = (data & LPA_1000REMRXOK)
2003 ? e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002004 } else {
2005 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
2006 phy->local_rx = e1000_1000t_rx_status_undefined;
2007 phy->remote_rx = e1000_1000t_rx_status_undefined;
2008 }
2009
2010 return ret_val;
2011}
2012
2013/**
Bruce Allan0be84012009-12-02 17:03:18 +00002014 * e1000_get_phy_info_ife - Retrieves various IFE PHY states
2015 * @hw: pointer to the HW structure
2016 *
2017 * Populates "phy" structure with various feature states.
2018 **/
2019s32 e1000_get_phy_info_ife(struct e1000_hw *hw)
2020{
2021 struct e1000_phy_info *phy = &hw->phy;
2022 s32 ret_val;
2023 u16 data;
2024 bool link;
2025
2026 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
2027 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002028 return ret_val;
Bruce Allan0be84012009-12-02 17:03:18 +00002029
2030 if (!link) {
2031 e_dbg("Phy info is only valid if link is up\n");
Bruce Allan5015e532012-02-08 02:55:56 +00002032 return -E1000_ERR_CONFIG;
Bruce Allan0be84012009-12-02 17:03:18 +00002033 }
2034
2035 ret_val = e1e_rphy(hw, IFE_PHY_SPECIAL_CONTROL, &data);
2036 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002037 return ret_val;
Bruce Allan04499ec2012-04-13 00:08:31 +00002038 phy->polarity_correction = !(data & IFE_PSC_AUTO_POLARITY_DISABLE);
Bruce Allan0be84012009-12-02 17:03:18 +00002039
2040 if (phy->polarity_correction) {
2041 ret_val = e1000_check_polarity_ife(hw);
2042 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002043 return ret_val;
Bruce Allan0be84012009-12-02 17:03:18 +00002044 } else {
2045 /* Polarity is forced */
Bruce Allanf0ff4392013-02-20 04:05:39 +00002046 phy->cable_polarity = ((data & IFE_PSC_FORCE_POLARITY)
2047 ? e1000_rev_polarity_reversed
2048 : e1000_rev_polarity_normal);
Bruce Allan0be84012009-12-02 17:03:18 +00002049 }
2050
2051 ret_val = e1e_rphy(hw, IFE_PHY_MDIX_CONTROL, &data);
2052 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002053 return ret_val;
Bruce Allan0be84012009-12-02 17:03:18 +00002054
Bruce Allan04499ec2012-04-13 00:08:31 +00002055 phy->is_mdix = !!(data & IFE_PMC_MDIX_STATUS);
Bruce Allan0be84012009-12-02 17:03:18 +00002056
2057 /* The following parameters are undefined for 10/100 operation. */
2058 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
2059 phy->local_rx = e1000_1000t_rx_status_undefined;
2060 phy->remote_rx = e1000_1000t_rx_status_undefined;
2061
Bruce Allan5015e532012-02-08 02:55:56 +00002062 return 0;
Bruce Allan0be84012009-12-02 17:03:18 +00002063}
2064
2065/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002066 * e1000e_phy_sw_reset - PHY software reset
2067 * @hw: pointer to the HW structure
2068 *
2069 * Does a software reset of the PHY by reading the PHY control register and
2070 * setting/write the control register reset bit to the PHY.
2071 **/
2072s32 e1000e_phy_sw_reset(struct e1000_hw *hw)
2073{
2074 s32 ret_val;
2075 u16 phy_ctrl;
2076
Bruce Allanc2ade1a2013-01-16 08:54:35 +00002077 ret_val = e1e_rphy(hw, MII_BMCR, &phy_ctrl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002078 if (ret_val)
2079 return ret_val;
2080
Bruce Allanc2ade1a2013-01-16 08:54:35 +00002081 phy_ctrl |= BMCR_RESET;
2082 ret_val = e1e_wphy(hw, MII_BMCR, phy_ctrl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002083 if (ret_val)
2084 return ret_val;
2085
2086 udelay(1);
2087
2088 return ret_val;
2089}
2090
2091/**
2092 * e1000e_phy_hw_reset_generic - PHY hardware reset
2093 * @hw: pointer to the HW structure
2094 *
2095 * Verify the reset block is not blocking us from resetting. Acquire
2096 * semaphore (if necessary) and read/set/write the device control reset
2097 * bit in the PHY. Wait the appropriate delay time for the device to
Auke Kok489815c2008-02-21 15:11:07 -08002098 * reset and release the semaphore (if necessary).
Auke Kokbc7f75f2007-09-17 12:30:59 -07002099 **/
2100s32 e1000e_phy_hw_reset_generic(struct e1000_hw *hw)
2101{
2102 struct e1000_phy_info *phy = &hw->phy;
2103 s32 ret_val;
2104 u32 ctrl;
2105
Bruce Allan470a5422012-05-26 06:08:48 +00002106 if (phy->ops.check_reset_block) {
2107 ret_val = phy->ops.check_reset_block(hw);
2108 if (ret_val)
2109 return 0;
2110 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002111
Bruce Allan94d81862009-11-20 23:25:26 +00002112 ret_val = phy->ops.acquire(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002113 if (ret_val)
2114 return ret_val;
2115
2116 ctrl = er32(CTRL);
2117 ew32(CTRL, ctrl | E1000_CTRL_PHY_RST);
2118 e1e_flush();
2119
2120 udelay(phy->reset_delay_us);
2121
2122 ew32(CTRL, ctrl);
2123 e1e_flush();
2124
2125 udelay(150);
2126
Bruce Allan94d81862009-11-20 23:25:26 +00002127 phy->ops.release(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002128
Bruce Allan84c1bef2013-01-05 08:06:19 +00002129 return phy->ops.get_cfg_done(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002130}
2131
2132/**
Bruce Allanfe908492013-01-05 08:06:14 +00002133 * e1000e_get_cfg_done_generic - Generic configuration done
Auke Kokbc7f75f2007-09-17 12:30:59 -07002134 * @hw: pointer to the HW structure
2135 *
2136 * Generic function to wait 10 milli-seconds for configuration to complete
2137 * and return success.
2138 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00002139s32 e1000e_get_cfg_done_generic(struct e1000_hw __always_unused *hw)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002140{
2141 mdelay(10);
Bruce Allan3d3a1672012-02-23 03:13:18 +00002142
Auke Kokbc7f75f2007-09-17 12:30:59 -07002143 return 0;
2144}
2145
Bruce Allanf4187b52008-08-26 18:36:50 -07002146/**
2147 * e1000e_phy_init_script_igp3 - Inits the IGP3 PHY
2148 * @hw: pointer to the HW structure
2149 *
2150 * Initializes a Intel Gigabit PHY3 when an EEPROM is not present.
2151 **/
2152s32 e1000e_phy_init_script_igp3(struct e1000_hw *hw)
2153{
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002154 e_dbg("Running IGP 3 PHY init script\n");
Bruce Allanf4187b52008-08-26 18:36:50 -07002155
2156 /* PHY init IGP 3 */
2157 /* Enable rise/fall, 10-mode work in class-A */
2158 e1e_wphy(hw, 0x2F5B, 0x9018);
2159 /* Remove all caps from Replica path filter */
2160 e1e_wphy(hw, 0x2F52, 0x0000);
2161 /* Bias trimming for ADC, AFE and Driver (Default) */
2162 e1e_wphy(hw, 0x2FB1, 0x8B24);
2163 /* Increase Hybrid poly bias */
2164 e1e_wphy(hw, 0x2FB2, 0xF8F0);
2165 /* Add 4% to Tx amplitude in Gig mode */
2166 e1e_wphy(hw, 0x2010, 0x10B0);
2167 /* Disable trimming (TTT) */
2168 e1e_wphy(hw, 0x2011, 0x0000);
2169 /* Poly DC correction to 94.6% + 2% for all channels */
2170 e1e_wphy(hw, 0x20DD, 0x249A);
2171 /* ABS DC correction to 95.9% */
2172 e1e_wphy(hw, 0x20DE, 0x00D3);
2173 /* BG temp curve trim */
2174 e1e_wphy(hw, 0x28B4, 0x04CE);
2175 /* Increasing ADC OPAMP stage 1 currents to max */
2176 e1e_wphy(hw, 0x2F70, 0x29E4);
2177 /* Force 1000 ( required for enabling PHY regs configuration) */
2178 e1e_wphy(hw, 0x0000, 0x0140);
2179 /* Set upd_freq to 6 */
2180 e1e_wphy(hw, 0x1F30, 0x1606);
2181 /* Disable NPDFE */
2182 e1e_wphy(hw, 0x1F31, 0xB814);
2183 /* Disable adaptive fixed FFE (Default) */
2184 e1e_wphy(hw, 0x1F35, 0x002A);
2185 /* Enable FFE hysteresis */
2186 e1e_wphy(hw, 0x1F3E, 0x0067);
2187 /* Fixed FFE for short cable lengths */
2188 e1e_wphy(hw, 0x1F54, 0x0065);
2189 /* Fixed FFE for medium cable lengths */
2190 e1e_wphy(hw, 0x1F55, 0x002A);
2191 /* Fixed FFE for long cable lengths */
2192 e1e_wphy(hw, 0x1F56, 0x002A);
2193 /* Enable Adaptive Clip Threshold */
2194 e1e_wphy(hw, 0x1F72, 0x3FB0);
2195 /* AHT reset limit to 1 */
2196 e1e_wphy(hw, 0x1F76, 0xC0FF);
2197 /* Set AHT master delay to 127 msec */
2198 e1e_wphy(hw, 0x1F77, 0x1DEC);
2199 /* Set scan bits for AHT */
2200 e1e_wphy(hw, 0x1F78, 0xF9EF);
2201 /* Set AHT Preset bits */
2202 e1e_wphy(hw, 0x1F79, 0x0210);
2203 /* Change integ_factor of channel A to 3 */
2204 e1e_wphy(hw, 0x1895, 0x0003);
2205 /* Change prop_factor of channels BCD to 8 */
2206 e1e_wphy(hw, 0x1796, 0x0008);
2207 /* Change cg_icount + enable integbp for channels BCD */
2208 e1e_wphy(hw, 0x1798, 0xD008);
Bruce Allane921eb12012-11-28 09:28:37 +00002209 /* Change cg_icount + enable integbp + change prop_factor_master
Bruce Allanf4187b52008-08-26 18:36:50 -07002210 * to 8 for channel A
2211 */
2212 e1e_wphy(hw, 0x1898, 0xD918);
2213 /* Disable AHT in Slave mode on channel A */
2214 e1e_wphy(hw, 0x187A, 0x0800);
Bruce Allane921eb12012-11-28 09:28:37 +00002215 /* Enable LPLU and disable AN to 1000 in non-D0a states,
Bruce Allanf4187b52008-08-26 18:36:50 -07002216 * Enable SPD+B2B
2217 */
2218 e1e_wphy(hw, 0x0019, 0x008D);
2219 /* Enable restart AN on an1000_dis change */
2220 e1e_wphy(hw, 0x001B, 0x2080);
2221 /* Enable wh_fifo read clock in 10/100 modes */
2222 e1e_wphy(hw, 0x0014, 0x0045);
2223 /* Restart AN, Speed selection is 1000 */
2224 e1e_wphy(hw, 0x0000, 0x1340);
2225
2226 return 0;
2227}
2228
Auke Kokbc7f75f2007-09-17 12:30:59 -07002229/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002230 * e1000e_get_phy_type_from_id - Get PHY type from id
2231 * @phy_id: phy_id read from the phy
2232 *
2233 * Returns the phy type from the id.
2234 **/
2235enum e1000_phy_type e1000e_get_phy_type_from_id(u32 phy_id)
2236{
2237 enum e1000_phy_type phy_type = e1000_phy_unknown;
2238
2239 switch (phy_id) {
2240 case M88E1000_I_PHY_ID:
2241 case M88E1000_E_PHY_ID:
2242 case M88E1111_I_PHY_ID:
2243 case M88E1011_I_PHY_ID:
2244 phy_type = e1000_phy_m88;
2245 break;
2246 case IGP01E1000_I_PHY_ID: /* IGP 1 & 2 share this */
2247 phy_type = e1000_phy_igp_2;
2248 break;
2249 case GG82563_E_PHY_ID:
2250 phy_type = e1000_phy_gg82563;
2251 break;
2252 case IGP03E1000_E_PHY_ID:
2253 phy_type = e1000_phy_igp_3;
2254 break;
2255 case IFE_E_PHY_ID:
2256 case IFE_PLUS_E_PHY_ID:
2257 case IFE_C_E_PHY_ID:
2258 phy_type = e1000_phy_ife;
2259 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002260 case BME1000_E_PHY_ID:
2261 case BME1000_E_PHY_ID_R2:
2262 phy_type = e1000_phy_bm;
2263 break;
Bruce Allana4f58f52009-06-02 11:29:18 +00002264 case I82578_E_PHY_ID:
2265 phy_type = e1000_phy_82578;
2266 break;
2267 case I82577_E_PHY_ID:
2268 phy_type = e1000_phy_82577;
2269 break;
Bruce Alland3738bb2010-06-16 13:27:28 +00002270 case I82579_E_PHY_ID:
2271 phy_type = e1000_phy_82579;
2272 break;
Bruce Allan2fbe4522012-04-19 03:21:47 +00002273 case I217_E_PHY_ID:
2274 phy_type = e1000_phy_i217;
2275 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002276 default:
2277 phy_type = e1000_phy_unknown;
2278 break;
2279 }
2280 return phy_type;
2281}
2282
2283/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002284 * e1000e_determine_phy_address - Determines PHY address.
2285 * @hw: pointer to the HW structure
2286 *
2287 * This uses a trial and error method to loop through possible PHY
2288 * addresses. It tests each by reading the PHY ID registers and
2289 * checking for a match.
2290 **/
2291s32 e1000e_determine_phy_address(struct e1000_hw *hw)
2292{
Bruce Allan5eb6f3c2009-12-02 17:02:43 +00002293 u32 phy_addr = 0;
2294 u32 i;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002295 enum e1000_phy_type phy_type = e1000_phy_unknown;
2296
Bruce Allan5eb6f3c2009-12-02 17:02:43 +00002297 hw->phy.id = phy_type;
2298
2299 for (phy_addr = 0; phy_addr < E1000_MAX_PHY_ADDR; phy_addr++) {
2300 hw->phy.addr = phy_addr;
2301 i = 0;
2302
2303 do {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002304 e1000e_get_phy_id(hw);
2305 phy_type = e1000e_get_phy_type_from_id(hw->phy.id);
2306
Bruce Allane921eb12012-11-28 09:28:37 +00002307 /* If phy_type is valid, break - we found our
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002308 * PHY address
2309 */
Bruce Allan5015e532012-02-08 02:55:56 +00002310 if (phy_type != e1000_phy_unknown)
2311 return 0;
2312
Bruce Allan1bba4382011-03-19 00:27:20 +00002313 usleep_range(1000, 2000);
Bruce Allan5eb6f3c2009-12-02 17:02:43 +00002314 i++;
2315 } while (i < 10);
2316 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002317
Bruce Allan5015e532012-02-08 02:55:56 +00002318 return -E1000_ERR_PHY_TYPE;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002319}
2320
2321/**
2322 * e1000_get_phy_addr_for_bm_page - Retrieve PHY page address
2323 * @page: page to access
2324 *
2325 * Returns the phy address for the page requested.
2326 **/
2327static u32 e1000_get_phy_addr_for_bm_page(u32 page, u32 reg)
2328{
2329 u32 phy_addr = 2;
2330
2331 if ((page >= 768) || (page == 0 && reg == 25) || (reg == 31))
2332 phy_addr = 1;
2333
2334 return phy_addr;
2335}
2336
2337/**
2338 * e1000e_write_phy_reg_bm - Write BM PHY register
2339 * @hw: pointer to the HW structure
2340 * @offset: register offset to write to
2341 * @data: data to write at register offset
2342 *
2343 * Acquires semaphore, if necessary, then writes the data to PHY register
2344 * at the offset. Release any acquired semaphores before exiting.
2345 **/
2346s32 e1000e_write_phy_reg_bm(struct e1000_hw *hw, u32 offset, u16 data)
2347{
2348 s32 ret_val;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002349 u32 page = offset >> IGP_PAGE_SHIFT;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002350
Bruce Allan94d81862009-11-20 23:25:26 +00002351 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002352 if (ret_val)
2353 return ret_val;
2354
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002355 /* Page 800 works differently than the rest so it has its own func */
2356 if (page == BM_WUC_PAGE) {
2357 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, &data,
Bruce Allan2b6b1682011-05-13 07:20:09 +00002358 false, false);
Bruce Allan75ce1532012-02-08 02:54:48 +00002359 goto release;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002360 }
2361
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002362 hw->phy.addr = e1000_get_phy_addr_for_bm_page(page, offset);
2363
2364 if (offset > MAX_PHY_MULTI_PAGE_REG) {
Bruce Allan90da0662011-01-06 07:02:53 +00002365 u32 page_shift, page_select;
2366
Bruce Allane921eb12012-11-28 09:28:37 +00002367 /* Page select is register 31 for phy address 1 and 22 for
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002368 * phy address 2 and 3. Page select is shifted only for
2369 * phy address 1.
2370 */
2371 if (hw->phy.addr == 1) {
2372 page_shift = IGP_PAGE_SHIFT;
2373 page_select = IGP01E1000_PHY_PAGE_SELECT;
2374 } else {
2375 page_shift = 0;
2376 page_select = BM_PHY_PAGE_SELECT;
2377 }
2378
2379 /* Page is shifted left, PHY expects (page x 32) */
2380 ret_val = e1000e_write_phy_reg_mdic(hw, page_select,
Bruce Allanf0ff4392013-02-20 04:05:39 +00002381 (page << page_shift));
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002382 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00002383 goto release;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002384 }
2385
2386 ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
Bruce Allanf0ff4392013-02-20 04:05:39 +00002387 data);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002388
Bruce Allan75ce1532012-02-08 02:54:48 +00002389release:
Bruce Allan94d81862009-11-20 23:25:26 +00002390 hw->phy.ops.release(hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002391 return ret_val;
2392}
2393
2394/**
2395 * e1000e_read_phy_reg_bm - Read BM PHY register
2396 * @hw: pointer to the HW structure
2397 * @offset: register offset to be read
2398 * @data: pointer to the read data
2399 *
2400 * Acquires semaphore, if necessary, then reads the PHY register at offset
2401 * and storing the retrieved information in data. Release any acquired
2402 * semaphores before exiting.
2403 **/
2404s32 e1000e_read_phy_reg_bm(struct e1000_hw *hw, u32 offset, u16 *data)
2405{
2406 s32 ret_val;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002407 u32 page = offset >> IGP_PAGE_SHIFT;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002408
Bruce Allan94d81862009-11-20 23:25:26 +00002409 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002410 if (ret_val)
2411 return ret_val;
2412
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002413 /* Page 800 works differently than the rest so it has its own func */
2414 if (page == BM_WUC_PAGE) {
2415 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, data,
Bruce Allan2b6b1682011-05-13 07:20:09 +00002416 true, false);
Bruce Allan75ce1532012-02-08 02:54:48 +00002417 goto release;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002418 }
2419
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002420 hw->phy.addr = e1000_get_phy_addr_for_bm_page(page, offset);
2421
2422 if (offset > MAX_PHY_MULTI_PAGE_REG) {
Bruce Allan90da0662011-01-06 07:02:53 +00002423 u32 page_shift, page_select;
2424
Bruce Allane921eb12012-11-28 09:28:37 +00002425 /* Page select is register 31 for phy address 1 and 22 for
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002426 * phy address 2 and 3. Page select is shifted only for
2427 * phy address 1.
2428 */
2429 if (hw->phy.addr == 1) {
2430 page_shift = IGP_PAGE_SHIFT;
2431 page_select = IGP01E1000_PHY_PAGE_SELECT;
2432 } else {
2433 page_shift = 0;
2434 page_select = BM_PHY_PAGE_SELECT;
2435 }
2436
2437 /* Page is shifted left, PHY expects (page x 32) */
2438 ret_val = e1000e_write_phy_reg_mdic(hw, page_select,
Bruce Allanf0ff4392013-02-20 04:05:39 +00002439 (page << page_shift));
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002440 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00002441 goto release;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002442 }
2443
2444 ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
Bruce Allanf0ff4392013-02-20 04:05:39 +00002445 data);
Bruce Allan75ce1532012-02-08 02:54:48 +00002446release:
Bruce Allan94d81862009-11-20 23:25:26 +00002447 hw->phy.ops.release(hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002448 return ret_val;
2449}
2450
2451/**
Bruce Allan4662e822008-08-26 18:37:06 -07002452 * e1000e_read_phy_reg_bm2 - Read BM PHY register
2453 * @hw: pointer to the HW structure
2454 * @offset: register offset to be read
2455 * @data: pointer to the read data
2456 *
2457 * Acquires semaphore, if necessary, then reads the PHY register at offset
2458 * and storing the retrieved information in data. Release any acquired
2459 * semaphores before exiting.
2460 **/
2461s32 e1000e_read_phy_reg_bm2(struct e1000_hw *hw, u32 offset, u16 *data)
2462{
2463 s32 ret_val;
2464 u16 page = (u16)(offset >> IGP_PAGE_SHIFT);
2465
Bruce Allan94d81862009-11-20 23:25:26 +00002466 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002467 if (ret_val)
2468 return ret_val;
2469
Bruce Allan4662e822008-08-26 18:37:06 -07002470 /* Page 800 works differently than the rest so it has its own func */
2471 if (page == BM_WUC_PAGE) {
2472 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, data,
Bruce Allan2b6b1682011-05-13 07:20:09 +00002473 true, false);
Bruce Allan75ce1532012-02-08 02:54:48 +00002474 goto release;
Bruce Allan4662e822008-08-26 18:37:06 -07002475 }
2476
Bruce Allan4662e822008-08-26 18:37:06 -07002477 hw->phy.addr = 1;
2478
2479 if (offset > MAX_PHY_MULTI_PAGE_REG) {
Bruce Allan4662e822008-08-26 18:37:06 -07002480 /* Page is shifted left, PHY expects (page x 32) */
2481 ret_val = e1000e_write_phy_reg_mdic(hw, BM_PHY_PAGE_SELECT,
2482 page);
2483
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002484 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00002485 goto release;
Bruce Allan4662e822008-08-26 18:37:06 -07002486 }
2487
2488 ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
2489 data);
Bruce Allan75ce1532012-02-08 02:54:48 +00002490release:
Bruce Allan94d81862009-11-20 23:25:26 +00002491 hw->phy.ops.release(hw);
Bruce Allan4662e822008-08-26 18:37:06 -07002492 return ret_val;
2493}
2494
2495/**
2496 * e1000e_write_phy_reg_bm2 - Write BM PHY register
2497 * @hw: pointer to the HW structure
2498 * @offset: register offset to write to
2499 * @data: data to write at register offset
2500 *
2501 * Acquires semaphore, if necessary, then writes the data to PHY register
2502 * at the offset. Release any acquired semaphores before exiting.
2503 **/
2504s32 e1000e_write_phy_reg_bm2(struct e1000_hw *hw, u32 offset, u16 data)
2505{
2506 s32 ret_val;
2507 u16 page = (u16)(offset >> IGP_PAGE_SHIFT);
2508
Bruce Allan94d81862009-11-20 23:25:26 +00002509 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002510 if (ret_val)
2511 return ret_val;
2512
Bruce Allan4662e822008-08-26 18:37:06 -07002513 /* Page 800 works differently than the rest so it has its own func */
2514 if (page == BM_WUC_PAGE) {
2515 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, &data,
Bruce Allan2b6b1682011-05-13 07:20:09 +00002516 false, false);
Bruce Allan75ce1532012-02-08 02:54:48 +00002517 goto release;
Bruce Allan4662e822008-08-26 18:37:06 -07002518 }
2519
Bruce Allan4662e822008-08-26 18:37:06 -07002520 hw->phy.addr = 1;
2521
2522 if (offset > MAX_PHY_MULTI_PAGE_REG) {
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_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
2532 data);
2533
Bruce Allan75ce1532012-02-08 02:54:48 +00002534release:
Bruce Allan94d81862009-11-20 23:25:26 +00002535 hw->phy.ops.release(hw);
Bruce Allan4662e822008-08-26 18:37:06 -07002536 return ret_val;
2537}
2538
2539/**
Bruce Allan2b6b1682011-05-13 07:20:09 +00002540 * e1000_enable_phy_wakeup_reg_access_bm - enable access to BM wakeup registers
2541 * @hw: pointer to the HW structure
2542 * @phy_reg: pointer to store original contents of BM_WUC_ENABLE_REG
2543 *
2544 * Assumes semaphore already acquired and phy_reg points to a valid memory
2545 * address to store contents of the BM_WUC_ENABLE_REG register.
2546 **/
2547s32 e1000_enable_phy_wakeup_reg_access_bm(struct e1000_hw *hw, u16 *phy_reg)
2548{
2549 s32 ret_val;
2550 u16 temp;
2551
2552 /* All page select, port ctrl and wakeup registers use phy address 1 */
2553 hw->phy.addr = 1;
2554
2555 /* Select Port Control Registers page */
2556 ret_val = e1000_set_page_igp(hw, (BM_PORT_CTRL_PAGE << IGP_PAGE_SHIFT));
2557 if (ret_val) {
2558 e_dbg("Could not set Port Control page\n");
Bruce Allan5015e532012-02-08 02:55:56 +00002559 return ret_val;
Bruce Allan2b6b1682011-05-13 07:20:09 +00002560 }
2561
2562 ret_val = e1000e_read_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, phy_reg);
2563 if (ret_val) {
2564 e_dbg("Could not read PHY register %d.%d\n",
2565 BM_PORT_CTRL_PAGE, BM_WUC_ENABLE_REG);
Bruce Allan5015e532012-02-08 02:55:56 +00002566 return ret_val;
Bruce Allan2b6b1682011-05-13 07:20:09 +00002567 }
2568
Bruce Allane921eb12012-11-28 09:28:37 +00002569 /* Enable both PHY wakeup mode and Wakeup register page writes.
Bruce Allan2b6b1682011-05-13 07:20:09 +00002570 * Prevent a power state change by disabling ME and Host PHY wakeup.
2571 */
2572 temp = *phy_reg;
2573 temp |= BM_WUC_ENABLE_BIT;
2574 temp &= ~(BM_WUC_ME_WU_BIT | BM_WUC_HOST_WU_BIT);
2575
2576 ret_val = e1000e_write_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, temp);
2577 if (ret_val) {
2578 e_dbg("Could not write PHY register %d.%d\n",
2579 BM_PORT_CTRL_PAGE, BM_WUC_ENABLE_REG);
Bruce Allan5015e532012-02-08 02:55:56 +00002580 return ret_val;
Bruce Allan2b6b1682011-05-13 07:20:09 +00002581 }
2582
Bruce Allane921eb12012-11-28 09:28:37 +00002583 /* Select Host Wakeup Registers page - caller now able to write
Bruce Allan5015e532012-02-08 02:55:56 +00002584 * registers on the Wakeup registers page
2585 */
2586 return e1000_set_page_igp(hw, (BM_WUC_PAGE << IGP_PAGE_SHIFT));
Bruce Allan2b6b1682011-05-13 07:20:09 +00002587}
2588
2589/**
2590 * e1000_disable_phy_wakeup_reg_access_bm - disable access to BM wakeup regs
2591 * @hw: pointer to the HW structure
2592 * @phy_reg: pointer to original contents of BM_WUC_ENABLE_REG
2593 *
2594 * Restore BM_WUC_ENABLE_REG to its original value.
2595 *
2596 * Assumes semaphore already acquired and *phy_reg is the contents of the
2597 * BM_WUC_ENABLE_REG before register(s) on BM_WUC_PAGE were accessed by
2598 * caller.
2599 **/
2600s32 e1000_disable_phy_wakeup_reg_access_bm(struct e1000_hw *hw, u16 *phy_reg)
2601{
Bruce Allan70806a72013-01-05 05:08:37 +00002602 s32 ret_val;
Bruce Allan2b6b1682011-05-13 07:20:09 +00002603
2604 /* Select Port Control Registers page */
2605 ret_val = e1000_set_page_igp(hw, (BM_PORT_CTRL_PAGE << IGP_PAGE_SHIFT));
2606 if (ret_val) {
2607 e_dbg("Could not set Port Control page\n");
Bruce Allan5015e532012-02-08 02:55:56 +00002608 return ret_val;
Bruce Allan2b6b1682011-05-13 07:20:09 +00002609 }
2610
2611 /* Restore 769.17 to its original value */
2612 ret_val = e1000e_write_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, *phy_reg);
2613 if (ret_val)
2614 e_dbg("Could not restore PHY register %d.%d\n",
2615 BM_PORT_CTRL_PAGE, BM_WUC_ENABLE_REG);
Bruce Allan5015e532012-02-08 02:55:56 +00002616
Bruce Allan2b6b1682011-05-13 07:20:09 +00002617 return ret_val;
2618}
2619
2620/**
2621 * e1000_access_phy_wakeup_reg_bm - Read/write BM PHY wakeup register
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002622 * @hw: pointer to the HW structure
2623 * @offset: register offset to be read or written
2624 * @data: pointer to the data to read or write
2625 * @read: determines if operation is read or write
Bruce Allan2b6b1682011-05-13 07:20:09 +00002626 * @page_set: BM_WUC_PAGE already set and access enabled
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002627 *
Bruce Allan2b6b1682011-05-13 07:20:09 +00002628 * Read the PHY register at offset and store the retrieved information in
2629 * data, or write data to PHY register at offset. Note the procedure to
2630 * access the PHY wakeup registers is different than reading the other PHY
2631 * registers. It works as such:
2632 * 1) Set 769.17.2 (page 769, register 17, bit 2) = 1
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002633 * 2) Set page to 800 for host (801 if we were manageability)
2634 * 3) Write the address using the address opcode (0x11)
2635 * 4) Read or write the data using the data opcode (0x12)
Bruce Allan2b6b1682011-05-13 07:20:09 +00002636 * 5) Restore 769.17.2 to its original value
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002637 *
Bruce Allan2b6b1682011-05-13 07:20:09 +00002638 * Steps 1 and 2 are done by e1000_enable_phy_wakeup_reg_access_bm() and
2639 * step 5 is done by e1000_disable_phy_wakeup_reg_access_bm().
2640 *
2641 * Assumes semaphore is already acquired. When page_set==true, assumes
2642 * the PHY page is set to BM_WUC_PAGE (i.e. a function in the call stack
2643 * is responsible for calls to e1000_[enable|disable]_phy_wakeup_reg_bm()).
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002644 **/
2645static s32 e1000_access_phy_wakeup_reg_bm(struct e1000_hw *hw, u32 offset,
Bruce Allan2b6b1682011-05-13 07:20:09 +00002646 u16 *data, bool read, bool page_set)
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002647{
2648 s32 ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00002649 u16 reg = BM_PHY_REG_NUM(offset);
Bruce Allan2b6b1682011-05-13 07:20:09 +00002650 u16 page = BM_PHY_REG_PAGE(offset);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002651 u16 phy_reg = 0;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002652
Bruce Allan2b6b1682011-05-13 07:20:09 +00002653 /* Gig must be disabled for MDIO accesses to Host Wakeup reg page */
Bruce Allana4f58f52009-06-02 11:29:18 +00002654 if ((hw->mac.type == e1000_pchlan) &&
Bruce Allan2b6b1682011-05-13 07:20:09 +00002655 (!(er32(PHY_CTRL) & E1000_PHY_CTRL_GBE_DISABLE)))
2656 e_dbg("Attempting to access page %d while gig enabled.\n",
2657 page);
Bruce Allana4f58f52009-06-02 11:29:18 +00002658
Bruce Allan2b6b1682011-05-13 07:20:09 +00002659 if (!page_set) {
2660 /* Enable access to PHY wakeup registers */
2661 ret_val = e1000_enable_phy_wakeup_reg_access_bm(hw, &phy_reg);
2662 if (ret_val) {
2663 e_dbg("Could not enable PHY wakeup reg access\n");
Bruce Allan5015e532012-02-08 02:55:56 +00002664 return ret_val;
Bruce Allan2b6b1682011-05-13 07:20:09 +00002665 }
Bruce Allan9b71b412009-12-01 15:53:07 +00002666 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002667
Bruce Allan2b6b1682011-05-13 07:20:09 +00002668 e_dbg("Accessing PHY page %d reg 0x%x\n", page, reg);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002669
Bruce Allan2b6b1682011-05-13 07:20:09 +00002670 /* Write the Wakeup register page offset value using opcode 0x11 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002671 ret_val = e1000e_write_phy_reg_mdic(hw, BM_WUC_ADDRESS_OPCODE, reg);
Bruce Allan9b71b412009-12-01 15:53:07 +00002672 if (ret_val) {
Bruce Allan2b6b1682011-05-13 07:20:09 +00002673 e_dbg("Could not write address opcode to page %d\n", page);
Bruce Allan5015e532012-02-08 02:55:56 +00002674 return ret_val;
Bruce Allan9b71b412009-12-01 15:53:07 +00002675 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002676
2677 if (read) {
Bruce Allan2b6b1682011-05-13 07:20:09 +00002678 /* Read the Wakeup register page value using opcode 0x12 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002679 ret_val = e1000e_read_phy_reg_mdic(hw, BM_WUC_DATA_OPCODE,
Bruce Allanf0ff4392013-02-20 04:05:39 +00002680 data);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002681 } else {
Bruce Allan2b6b1682011-05-13 07:20:09 +00002682 /* Write the Wakeup register page value using opcode 0x12 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002683 ret_val = e1000e_write_phy_reg_mdic(hw, BM_WUC_DATA_OPCODE,
2684 *data);
2685 }
2686
Bruce Allan9b71b412009-12-01 15:53:07 +00002687 if (ret_val) {
Bruce Allan2b6b1682011-05-13 07:20:09 +00002688 e_dbg("Could not access PHY reg %d.%d\n", page, reg);
Bruce Allan5015e532012-02-08 02:55:56 +00002689 return ret_val;
Bruce Allan9b71b412009-12-01 15:53:07 +00002690 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002691
Bruce Allan2b6b1682011-05-13 07:20:09 +00002692 if (!page_set)
2693 ret_val = e1000_disable_phy_wakeup_reg_access_bm(hw, &phy_reg);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002694
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002695 return ret_val;
2696}
2697
2698/**
Bruce Allan17f208d2009-12-01 15:47:22 +00002699 * e1000_power_up_phy_copper - Restore copper link in case of PHY power down
2700 * @hw: pointer to the HW structure
2701 *
2702 * In the case of a PHY power down to save power, or to turn off link during a
2703 * driver unload, or wake on lan is not enabled, restore the link to previous
2704 * settings.
2705 **/
2706void e1000_power_up_phy_copper(struct e1000_hw *hw)
2707{
2708 u16 mii_reg = 0;
2709
2710 /* The PHY will retain its settings across a power down/up cycle */
Bruce Allanc2ade1a2013-01-16 08:54:35 +00002711 e1e_rphy(hw, MII_BMCR, &mii_reg);
2712 mii_reg &= ~BMCR_PDOWN;
2713 e1e_wphy(hw, MII_BMCR, mii_reg);
Bruce Allan17f208d2009-12-01 15:47:22 +00002714}
2715
2716/**
2717 * e1000_power_down_phy_copper - Restore copper link in case of PHY power down
2718 * @hw: pointer to the HW structure
2719 *
2720 * In the case of a PHY power down to save power, or to turn off link during a
2721 * driver unload, or wake on lan is not enabled, restore the link to previous
2722 * settings.
2723 **/
2724void e1000_power_down_phy_copper(struct e1000_hw *hw)
2725{
2726 u16 mii_reg = 0;
2727
2728 /* The PHY will retain its settings across a power down/up cycle */
Bruce Allanc2ade1a2013-01-16 08:54:35 +00002729 e1e_rphy(hw, MII_BMCR, &mii_reg);
2730 mii_reg |= BMCR_PDOWN;
2731 e1e_wphy(hw, MII_BMCR, mii_reg);
Bruce Allan1bba4382011-03-19 00:27:20 +00002732 usleep_range(1000, 2000);
Bruce Allan17f208d2009-12-01 15:47:22 +00002733}
2734
2735/**
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002736 * __e1000_read_phy_reg_hv - Read HV PHY register
Bruce Allana4f58f52009-06-02 11:29:18 +00002737 * @hw: pointer to the HW structure
2738 * @offset: register offset to be read
2739 * @data: pointer to the read data
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002740 * @locked: semaphore has already been acquired or not
Bruce Allana4f58f52009-06-02 11:29:18 +00002741 *
2742 * Acquires semaphore, if necessary, then reads the PHY register at offset
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002743 * and stores the retrieved information in data. Release any acquired
Bruce Allana4f58f52009-06-02 11:29:18 +00002744 * semaphore before exiting.
2745 **/
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002746static s32 __e1000_read_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 *data,
Bruce Allan2b6b1682011-05-13 07:20:09 +00002747 bool locked, bool page_set)
Bruce Allana4f58f52009-06-02 11:29:18 +00002748{
2749 s32 ret_val;
2750 u16 page = BM_PHY_REG_PAGE(offset);
2751 u16 reg = BM_PHY_REG_NUM(offset);
Bruce Allan2b6b1682011-05-13 07:20:09 +00002752 u32 phy_addr = hw->phy.addr = e1000_get_phy_addr_for_hv_page(page);
Bruce Allana4f58f52009-06-02 11:29:18 +00002753
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002754 if (!locked) {
Bruce Allan94d81862009-11-20 23:25:26 +00002755 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002756 if (ret_val)
2757 return ret_val;
2758 }
2759
Bruce Allana4f58f52009-06-02 11:29:18 +00002760 /* Page 800 works differently than the rest so it has its own func */
2761 if (page == BM_WUC_PAGE) {
Bruce Allan2b6b1682011-05-13 07:20:09 +00002762 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, data,
2763 true, page_set);
Bruce Allana4f58f52009-06-02 11:29:18 +00002764 goto out;
2765 }
2766
2767 if (page > 0 && page < HV_INTC_FC_PAGE_START) {
2768 ret_val = e1000_access_phy_debug_regs_hv(hw, offset,
Bruce Allanf0ff4392013-02-20 04:05:39 +00002769 data, true);
Bruce Allana4f58f52009-06-02 11:29:18 +00002770 goto out;
2771 }
2772
Bruce Allan2b6b1682011-05-13 07:20:09 +00002773 if (!page_set) {
2774 if (page == HV_INTC_FC_PAGE_START)
2775 page = 0;
Bruce Allana4f58f52009-06-02 11:29:18 +00002776
Bruce Allan2b6b1682011-05-13 07:20:09 +00002777 if (reg > MAX_PHY_MULTI_PAGE_REG) {
2778 /* Page is shifted left, PHY expects (page x 32) */
2779 ret_val = e1000_set_page_igp(hw,
2780 (page << IGP_PAGE_SHIFT));
Bruce Allana4f58f52009-06-02 11:29:18 +00002781
Bruce Allan2b6b1682011-05-13 07:20:09 +00002782 hw->phy.addr = phy_addr;
Bruce Allana4f58f52009-06-02 11:29:18 +00002783
Bruce Allan2b6b1682011-05-13 07:20:09 +00002784 if (ret_val)
2785 goto out;
2786 }
Bruce Allana4f58f52009-06-02 11:29:18 +00002787 }
2788
Bruce Allan2b6b1682011-05-13 07:20:09 +00002789 e_dbg("reading PHY page %d (or 0x%x shifted) reg 0x%x\n", page,
2790 page << IGP_PAGE_SHIFT, reg);
2791
Bruce Allanf0ff4392013-02-20 04:05:39 +00002792 ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & reg, data);
Bruce Allana4f58f52009-06-02 11:29:18 +00002793out:
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002794 if (!locked)
Bruce Allan94d81862009-11-20 23:25:26 +00002795 hw->phy.ops.release(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002796
Bruce Allana4f58f52009-06-02 11:29:18 +00002797 return ret_val;
2798}
2799
2800/**
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002801 * e1000_read_phy_reg_hv - Read HV PHY register
2802 * @hw: pointer to the HW structure
2803 * @offset: register offset to be read
2804 * @data: pointer to the read data
2805 *
2806 * Acquires semaphore then reads the PHY register at offset and stores
2807 * the retrieved information in data. Release the acquired semaphore
2808 * before exiting.
2809 **/
2810s32 e1000_read_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 *data)
2811{
Bruce Allan2b6b1682011-05-13 07:20:09 +00002812 return __e1000_read_phy_reg_hv(hw, offset, data, false, false);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002813}
2814
2815/**
2816 * e1000_read_phy_reg_hv_locked - Read HV PHY register
2817 * @hw: pointer to the HW structure
2818 * @offset: register offset to be read
2819 * @data: pointer to the read data
2820 *
2821 * Reads the PHY register at offset and stores the retrieved information
2822 * in data. Assumes semaphore already acquired.
2823 **/
2824s32 e1000_read_phy_reg_hv_locked(struct e1000_hw *hw, u32 offset, u16 *data)
2825{
Bruce Allan2b6b1682011-05-13 07:20:09 +00002826 return __e1000_read_phy_reg_hv(hw, offset, data, true, false);
2827}
2828
2829/**
2830 * e1000_read_phy_reg_page_hv - Read HV PHY register
2831 * @hw: pointer to the HW structure
2832 * @offset: register offset to write to
2833 * @data: data to write at register offset
2834 *
2835 * Reads the PHY register at offset and stores the retrieved information
2836 * in data. Assumes semaphore already acquired and page already set.
2837 **/
2838s32 e1000_read_phy_reg_page_hv(struct e1000_hw *hw, u32 offset, u16 *data)
2839{
2840 return __e1000_read_phy_reg_hv(hw, offset, data, true, true);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002841}
2842
2843/**
2844 * __e1000_write_phy_reg_hv - Write HV PHY register
Bruce Allana4f58f52009-06-02 11:29:18 +00002845 * @hw: pointer to the HW structure
2846 * @offset: register offset to write to
2847 * @data: data to write at register offset
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002848 * @locked: semaphore has already been acquired or not
Bruce Allana4f58f52009-06-02 11:29:18 +00002849 *
2850 * Acquires semaphore, if necessary, then writes the data to PHY register
2851 * at the offset. Release any acquired semaphores before exiting.
2852 **/
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002853static s32 __e1000_write_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 data,
Bruce Allan2b6b1682011-05-13 07:20:09 +00002854 bool locked, bool page_set)
Bruce Allana4f58f52009-06-02 11:29:18 +00002855{
2856 s32 ret_val;
2857 u16 page = BM_PHY_REG_PAGE(offset);
2858 u16 reg = BM_PHY_REG_NUM(offset);
Bruce Allan2b6b1682011-05-13 07:20:09 +00002859 u32 phy_addr = hw->phy.addr = e1000_get_phy_addr_for_hv_page(page);
Bruce Allana4f58f52009-06-02 11:29:18 +00002860
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002861 if (!locked) {
Bruce Allan94d81862009-11-20 23:25:26 +00002862 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002863 if (ret_val)
2864 return ret_val;
2865 }
2866
Bruce Allana4f58f52009-06-02 11:29:18 +00002867 /* Page 800 works differently than the rest so it has its own func */
2868 if (page == BM_WUC_PAGE) {
Bruce Allan2b6b1682011-05-13 07:20:09 +00002869 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, &data,
2870 false, page_set);
Bruce Allana4f58f52009-06-02 11:29:18 +00002871 goto out;
2872 }
2873
2874 if (page > 0 && page < HV_INTC_FC_PAGE_START) {
2875 ret_val = e1000_access_phy_debug_regs_hv(hw, offset,
Bruce Allanf0ff4392013-02-20 04:05:39 +00002876 &data, false);
Bruce Allana4f58f52009-06-02 11:29:18 +00002877 goto out;
2878 }
2879
Bruce Allan2b6b1682011-05-13 07:20:09 +00002880 if (!page_set) {
2881 if (page == HV_INTC_FC_PAGE_START)
2882 page = 0;
Bruce Allana4f58f52009-06-02 11:29:18 +00002883
Bruce Allane921eb12012-11-28 09:28:37 +00002884 /* Workaround MDIO accesses being disabled after entering IEEE
Bruce Allan2b6b1682011-05-13 07:20:09 +00002885 * Power Down (when bit 11 of the PHY Control register is set)
2886 */
2887 if ((hw->phy.type == e1000_phy_82578) &&
2888 (hw->phy.revision >= 1) &&
2889 (hw->phy.addr == 2) &&
Bruce Allan04499ec2012-04-13 00:08:31 +00002890 !(MAX_PHY_REG_ADDRESS & reg) && (data & (1 << 11))) {
Bruce Allan2b6b1682011-05-13 07:20:09 +00002891 u16 data2 = 0x7EFF;
2892 ret_val = e1000_access_phy_debug_regs_hv(hw,
2893 (1 << 6) | 0x3,
2894 &data2, false);
2895 if (ret_val)
2896 goto out;
2897 }
Bruce Allana4f58f52009-06-02 11:29:18 +00002898
Bruce Allan2b6b1682011-05-13 07:20:09 +00002899 if (reg > MAX_PHY_MULTI_PAGE_REG) {
2900 /* Page is shifted left, PHY expects (page x 32) */
2901 ret_val = e1000_set_page_igp(hw,
2902 (page << IGP_PAGE_SHIFT));
2903
2904 hw->phy.addr = phy_addr;
2905
2906 if (ret_val)
2907 goto out;
2908 }
Bruce Allana4f58f52009-06-02 11:29:18 +00002909 }
2910
Bruce Allan2b6b1682011-05-13 07:20:09 +00002911 e_dbg("writing PHY page %d (or 0x%x shifted) reg 0x%x\n", page,
2912 page << IGP_PAGE_SHIFT, reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00002913
2914 ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & reg,
Bruce Allanf0ff4392013-02-20 04:05:39 +00002915 data);
Bruce Allana4f58f52009-06-02 11:29:18 +00002916
2917out:
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002918 if (!locked)
Bruce Allan94d81862009-11-20 23:25:26 +00002919 hw->phy.ops.release(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002920
Bruce Allana4f58f52009-06-02 11:29:18 +00002921 return ret_val;
2922}
2923
2924/**
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002925 * e1000_write_phy_reg_hv - Write HV PHY register
2926 * @hw: pointer to the HW structure
2927 * @offset: register offset to write to
2928 * @data: data to write at register offset
2929 *
2930 * Acquires semaphore then writes the data to PHY register at the offset.
2931 * Release the acquired semaphores before exiting.
2932 **/
2933s32 e1000_write_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 data)
2934{
Bruce Allan2b6b1682011-05-13 07:20:09 +00002935 return __e1000_write_phy_reg_hv(hw, offset, data, false, false);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002936}
2937
2938/**
2939 * e1000_write_phy_reg_hv_locked - Write HV PHY register
2940 * @hw: pointer to the HW structure
2941 * @offset: register offset to write to
2942 * @data: data to write at register offset
2943 *
2944 * Writes the data to PHY register at the offset. Assumes semaphore
2945 * already acquired.
2946 **/
2947s32 e1000_write_phy_reg_hv_locked(struct e1000_hw *hw, u32 offset, u16 data)
2948{
Bruce Allan2b6b1682011-05-13 07:20:09 +00002949 return __e1000_write_phy_reg_hv(hw, offset, data, true, false);
2950}
2951
2952/**
2953 * e1000_write_phy_reg_page_hv - Write HV PHY register
2954 * @hw: pointer to the HW structure
2955 * @offset: register offset to write to
2956 * @data: data to write at register offset
2957 *
2958 * Writes the data to PHY register at the offset. Assumes semaphore
2959 * already acquired and page already set.
2960 **/
2961s32 e1000_write_phy_reg_page_hv(struct e1000_hw *hw, u32 offset, u16 data)
2962{
2963 return __e1000_write_phy_reg_hv(hw, offset, data, true, true);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002964}
2965
2966/**
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04002967 * e1000_get_phy_addr_for_hv_page - Get PHY address based on page
Bruce Allana4f58f52009-06-02 11:29:18 +00002968 * @page: page to be accessed
2969 **/
2970static u32 e1000_get_phy_addr_for_hv_page(u32 page)
2971{
2972 u32 phy_addr = 2;
2973
2974 if (page >= HV_INTC_FC_PAGE_START)
2975 phy_addr = 1;
2976
2977 return phy_addr;
2978}
2979
2980/**
2981 * e1000_access_phy_debug_regs_hv - Read HV PHY vendor specific high registers
2982 * @hw: pointer to the HW structure
2983 * @offset: register offset to be read or written
2984 * @data: pointer to the data to be read or written
Bruce Allan2b6b1682011-05-13 07:20:09 +00002985 * @read: determines if operation is read or write
Bruce Allana4f58f52009-06-02 11:29:18 +00002986 *
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002987 * Reads the PHY register at offset and stores the retreived information
2988 * in data. Assumes semaphore already acquired. Note that the procedure
Bruce Allan2b6b1682011-05-13 07:20:09 +00002989 * to access these regs uses the address port and data port to read/write.
2990 * These accesses done with PHY address 2 and without using pages.
Bruce Allana4f58f52009-06-02 11:29:18 +00002991 **/
2992static s32 e1000_access_phy_debug_regs_hv(struct e1000_hw *hw, u32 offset,
Bruce Allan66501f52013-02-20 04:05:55 +00002993 u16 *data, bool read)
Bruce Allana4f58f52009-06-02 11:29:18 +00002994{
2995 s32 ret_val;
Bruce Allan70806a72013-01-05 05:08:37 +00002996 u32 addr_reg;
2997 u32 data_reg;
Bruce Allana4f58f52009-06-02 11:29:18 +00002998
2999 /* This takes care of the difference with desktop vs mobile phy */
Bruce Allanf0ff4392013-02-20 04:05:39 +00003000 addr_reg = ((hw->phy.type == e1000_phy_82578) ?
3001 I82578_ADDR_REG : I82577_ADDR_REG);
Bruce Allana4f58f52009-06-02 11:29:18 +00003002 data_reg = addr_reg + 1;
3003
Bruce Allana4f58f52009-06-02 11:29:18 +00003004 /* All operations in this function are phy address 2 */
3005 hw->phy.addr = 2;
3006
3007 /* masking with 0x3F to remove the page from offset */
3008 ret_val = e1000e_write_phy_reg_mdic(hw, addr_reg, (u16)offset & 0x3F);
3009 if (ret_val) {
Bruce Allan2b6b1682011-05-13 07:20:09 +00003010 e_dbg("Could not write the Address Offset port register\n");
Bruce Allan5015e532012-02-08 02:55:56 +00003011 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003012 }
3013
3014 /* Read or write the data value next */
3015 if (read)
3016 ret_val = e1000e_read_phy_reg_mdic(hw, data_reg, data);
3017 else
3018 ret_val = e1000e_write_phy_reg_mdic(hw, data_reg, *data);
3019
Bruce Allan5015e532012-02-08 02:55:56 +00003020 if (ret_val)
Bruce Allan2b6b1682011-05-13 07:20:09 +00003021 e_dbg("Could not access the Data port register\n");
Bruce Allana4f58f52009-06-02 11:29:18 +00003022
Bruce Allana4f58f52009-06-02 11:29:18 +00003023 return ret_val;
3024}
3025
3026/**
3027 * e1000_link_stall_workaround_hv - Si workaround
3028 * @hw: pointer to the HW structure
3029 *
3030 * This function works around a Si bug where the link partner can get
3031 * a link up indication before the PHY does. If small packets are sent
3032 * by the link partner they can be placed in the packet buffer without
3033 * being properly accounted for by the PHY and will stall preventing
3034 * further packets from being received. The workaround is to clear the
3035 * packet buffer after the PHY detects link up.
3036 **/
3037s32 e1000_link_stall_workaround_hv(struct e1000_hw *hw)
3038{
3039 s32 ret_val = 0;
3040 u16 data;
3041
3042 if (hw->phy.type != e1000_phy_82578)
Bruce Allan5015e532012-02-08 02:55:56 +00003043 return 0;
Bruce Allana4f58f52009-06-02 11:29:18 +00003044
Bruce Allane65fa872009-07-01 13:27:31 +00003045 /* Do not apply workaround if in PHY loopback bit 14 set */
Bruce Allanc2ade1a2013-01-16 08:54:35 +00003046 e1e_rphy(hw, MII_BMCR, &data);
3047 if (data & BMCR_LOOPBACK)
Bruce Allan5015e532012-02-08 02:55:56 +00003048 return 0;
Bruce Allane65fa872009-07-01 13:27:31 +00003049
Bruce Allana4f58f52009-06-02 11:29:18 +00003050 /* check if link is up and at 1Gbps */
Bruce Allan482fed82011-01-06 14:29:49 +00003051 ret_val = e1e_rphy(hw, BM_CS_STATUS, &data);
Bruce Allana4f58f52009-06-02 11:29:18 +00003052 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003053 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003054
Bruce Allanf0ff4392013-02-20 04:05:39 +00003055 data &= (BM_CS_STATUS_LINK_UP | BM_CS_STATUS_RESOLVED |
3056 BM_CS_STATUS_SPEED_MASK);
Bruce Allana4f58f52009-06-02 11:29:18 +00003057
Bruce Allan3d3a1672012-02-23 03:13:18 +00003058 if (data != (BM_CS_STATUS_LINK_UP | BM_CS_STATUS_RESOLVED |
3059 BM_CS_STATUS_SPEED_1000))
Bruce Allan5015e532012-02-08 02:55:56 +00003060 return 0;
Bruce Allana4f58f52009-06-02 11:29:18 +00003061
Bruce Allanbb9c5ee2012-02-23 03:31:29 +00003062 msleep(200);
Bruce Allana4f58f52009-06-02 11:29:18 +00003063
3064 /* flush the packets in the fifo buffer */
Bruce Allanc063f602013-01-12 07:27:53 +00003065 ret_val = e1e_wphy(hw, HV_MUX_DATA_CTRL,
3066 (HV_MUX_DATA_CTRL_GEN_TO_MAC |
3067 HV_MUX_DATA_CTRL_FORCE_SPEED));
Bruce Allana4f58f52009-06-02 11:29:18 +00003068 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003069 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003070
Bruce Allan5015e532012-02-08 02:55:56 +00003071 return e1e_wphy(hw, HV_MUX_DATA_CTRL, HV_MUX_DATA_CTRL_GEN_TO_MAC);
Bruce Allana4f58f52009-06-02 11:29:18 +00003072}
3073
3074/**
3075 * e1000_check_polarity_82577 - Checks the polarity.
3076 * @hw: pointer to the HW structure
3077 *
3078 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
3079 *
3080 * Polarity is determined based on the PHY specific status register.
3081 **/
3082s32 e1000_check_polarity_82577(struct e1000_hw *hw)
3083{
3084 struct e1000_phy_info *phy = &hw->phy;
3085 s32 ret_val;
3086 u16 data;
3087
Bruce Allan482fed82011-01-06 14:29:49 +00003088 ret_val = e1e_rphy(hw, I82577_PHY_STATUS_2, &data);
Bruce Allana4f58f52009-06-02 11:29:18 +00003089
3090 if (!ret_val)
Bruce Allanf0ff4392013-02-20 04:05:39 +00003091 phy->cable_polarity = ((data & I82577_PHY_STATUS2_REV_POLARITY)
3092 ? e1000_rev_polarity_reversed
3093 : e1000_rev_polarity_normal);
Bruce Allana4f58f52009-06-02 11:29:18 +00003094
3095 return ret_val;
3096}
3097
3098/**
3099 * e1000_phy_force_speed_duplex_82577 - Force speed/duplex for I82577 PHY
3100 * @hw: pointer to the HW structure
3101 *
Bruce Allaneab50ff2010-05-10 15:01:30 +00003102 * Calls the PHY setup function to force speed and duplex.
Bruce Allana4f58f52009-06-02 11:29:18 +00003103 **/
3104s32 e1000_phy_force_speed_duplex_82577(struct e1000_hw *hw)
3105{
3106 struct e1000_phy_info *phy = &hw->phy;
3107 s32 ret_val;
3108 u16 phy_data;
3109 bool link;
3110
Bruce Allanc2ade1a2013-01-16 08:54:35 +00003111 ret_val = e1e_rphy(hw, MII_BMCR, &phy_data);
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
3115 e1000e_phy_force_speed_duplex_setup(hw, &phy_data);
3116
Bruce Allanc2ade1a2013-01-16 08:54:35 +00003117 ret_val = e1e_wphy(hw, MII_BMCR, phy_data);
Bruce Allana4f58f52009-06-02 11:29:18 +00003118 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003119 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003120
Bruce Allana4f58f52009-06-02 11:29:18 +00003121 udelay(1);
3122
3123 if (phy->autoneg_wait_to_complete) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003124 e_dbg("Waiting for forced speed/duplex link on 82577 phy\n");
Bruce Allana4f58f52009-06-02 11:29:18 +00003125
Bruce Allan3d3a1672012-02-23 03:13:18 +00003126 ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
3127 100000, &link);
Bruce Allana4f58f52009-06-02 11:29:18 +00003128 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003129 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003130
3131 if (!link)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003132 e_dbg("Link taking longer than expected.\n");
Bruce Allana4f58f52009-06-02 11:29:18 +00003133
3134 /* Try once more */
Bruce Allan3d3a1672012-02-23 03:13:18 +00003135 ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
3136 100000, &link);
Bruce Allana4f58f52009-06-02 11:29:18 +00003137 }
3138
Bruce Allana4f58f52009-06-02 11:29:18 +00003139 return ret_val;
3140}
3141
3142/**
3143 * e1000_get_phy_info_82577 - Retrieve I82577 PHY information
3144 * @hw: pointer to the HW structure
3145 *
3146 * Read PHY status to determine if link is up. If link is up, then
3147 * set/determine 10base-T extended distance and polarity correction. Read
3148 * PHY port status to determine MDI/MDIx and speed. Based on the speed,
3149 * determine on the cable length, local and remote receiver.
3150 **/
3151s32 e1000_get_phy_info_82577(struct e1000_hw *hw)
3152{
3153 struct e1000_phy_info *phy = &hw->phy;
3154 s32 ret_val;
3155 u16 data;
3156 bool link;
3157
3158 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
3159 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003160 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003161
3162 if (!link) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003163 e_dbg("Phy info is only valid if link is up\n");
Bruce Allan5015e532012-02-08 02:55:56 +00003164 return -E1000_ERR_CONFIG;
Bruce Allana4f58f52009-06-02 11:29:18 +00003165 }
3166
3167 phy->polarity_correction = true;
3168
3169 ret_val = e1000_check_polarity_82577(hw);
3170 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003171 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003172
Bruce Allan482fed82011-01-06 14:29:49 +00003173 ret_val = e1e_rphy(hw, I82577_PHY_STATUS_2, &data);
Bruce Allana4f58f52009-06-02 11:29:18 +00003174 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003175 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003176
Bruce Allan04499ec2012-04-13 00:08:31 +00003177 phy->is_mdix = !!(data & I82577_PHY_STATUS2_MDIX);
Bruce Allana4f58f52009-06-02 11:29:18 +00003178
3179 if ((data & I82577_PHY_STATUS2_SPEED_MASK) ==
3180 I82577_PHY_STATUS2_SPEED_1000MBPS) {
3181 ret_val = hw->phy.ops.get_cable_length(hw);
3182 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003183 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003184
Bruce Allanc2ade1a2013-01-16 08:54:35 +00003185 ret_val = e1e_rphy(hw, MII_STAT1000, &data);
Bruce Allana4f58f52009-06-02 11:29:18 +00003186 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003187 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003188
Bruce Allanc2ade1a2013-01-16 08:54:35 +00003189 phy->local_rx = (data & LPA_1000LOCALRXOK)
3190 ? e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
Bruce Allana4f58f52009-06-02 11:29:18 +00003191
Bruce Allanc2ade1a2013-01-16 08:54:35 +00003192 phy->remote_rx = (data & LPA_1000REMRXOK)
3193 ? e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
Bruce Allana4f58f52009-06-02 11:29:18 +00003194 } else {
3195 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
3196 phy->local_rx = e1000_1000t_rx_status_undefined;
3197 phy->remote_rx = e1000_1000t_rx_status_undefined;
3198 }
3199
Bruce Allan5015e532012-02-08 02:55:56 +00003200 return 0;
Bruce Allana4f58f52009-06-02 11:29:18 +00003201}
3202
3203/**
3204 * e1000_get_cable_length_82577 - Determine cable length for 82577 PHY
3205 * @hw: pointer to the HW structure
3206 *
3207 * Reads the diagnostic status register and verifies result is valid before
3208 * placing it in the phy_cable_length field.
3209 **/
3210s32 e1000_get_cable_length_82577(struct e1000_hw *hw)
3211{
3212 struct e1000_phy_info *phy = &hw->phy;
3213 s32 ret_val;
3214 u16 phy_data, length;
3215
Bruce Allan482fed82011-01-06 14:29:49 +00003216 ret_val = e1e_rphy(hw, I82577_PHY_DIAG_STATUS, &phy_data);
Bruce Allana4f58f52009-06-02 11:29:18 +00003217 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003218 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003219
Bruce Allanf0ff4392013-02-20 04:05:39 +00003220 length = ((phy_data & I82577_DSTATUS_CABLE_LENGTH) >>
3221 I82577_DSTATUS_CABLE_LENGTH_SHIFT);
Bruce Allana4f58f52009-06-02 11:29:18 +00003222
3223 if (length == E1000_CABLE_LENGTH_UNDEFINED)
Bruce Allan7dbbe5d2013-01-05 05:08:31 +00003224 return -E1000_ERR_PHY;
Bruce Allana4f58f52009-06-02 11:29:18 +00003225
3226 phy->cable_length = length;
3227
Bruce Allan5015e532012-02-08 02:55:56 +00003228 return 0;
Bruce Allana4f58f52009-06-02 11:29:18 +00003229}