blob: 0a81d1437febd6edb22935f80dd71d26644802fc [file] [log] [blame]
Auke Kokbc7f75f2007-09-17 12:30:59 -07001/*******************************************************************************
2
3 Intel PRO/1000 Linux driver
Bruce Allanbf670442013-01-01 16:00:01 +00004 Copyright(c) 1999 - 2013 Intel Corporation.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
14
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Contact Information:
23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26
27*******************************************************************************/
28
Auke Kokbc7f75f2007-09-17 12:30:59 -070029#include "e1000.h"
30
Auke Kokbc7f75f2007-09-17 12:30:59 -070031static s32 e1000_wait_autoneg(struct e1000_hw *hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -070032static s32 e1000_access_phy_wakeup_reg_bm(struct e1000_hw *hw, u32 offset,
Bruce Allan2b6b1682011-05-13 07:20:09 +000033 u16 *data, bool read, bool page_set);
Bruce Allana4f58f52009-06-02 11:29:18 +000034static u32 e1000_get_phy_addr_for_hv_page(u32 page);
35static s32 e1000_access_phy_debug_regs_hv(struct e1000_hw *hw, u32 offset,
Bruce Allan1f96012d2013-01-05 03:06:54 +000036 u16 *data, bool read);
Auke Kokbc7f75f2007-09-17 12:30:59 -070037
38/* Cable length tables */
Bruce Allan64806412010-12-11 05:53:42 +000039static const u16 e1000_m88_cable_length_table[] = {
40 0, 50, 80, 110, 140, 140, E1000_CABLE_LENGTH_UNDEFINED };
Bruce Allanfc830b72013-02-20 04:06:11 +000041
Bruce Allaneb656d42009-12-01 15:47:02 +000042#define M88E1000_CABLE_LENGTH_TABLE_SIZE \
43 ARRAY_SIZE(e1000_m88_cable_length_table)
Auke Kokbc7f75f2007-09-17 12:30:59 -070044
Bruce Allan64806412010-12-11 05:53:42 +000045static const u16 e1000_igp_2_cable_length_table[] = {
46 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21, 0, 0, 0, 3,
47 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41, 6, 10, 14, 18, 22,
48 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61, 21, 26, 31, 35, 40,
49 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82, 40, 45, 51, 56, 61,
50 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104, 60, 66, 72, 77, 82,
51 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121, 83, 89, 95,
52 100, 105, 109, 113, 116, 119, 122, 124, 104, 109, 114, 118, 121,
53 124};
Bruce Allanfc830b72013-02-20 04:06:11 +000054
Auke Kokbc7f75f2007-09-17 12:30:59 -070055#define IGP02E1000_CABLE_LENGTH_TABLE_SIZE \
Alejandro Martinez Ruizc00acf42007-10-18 10:16:33 +020056 ARRAY_SIZE(e1000_igp_2_cable_length_table)
Auke Kokbc7f75f2007-09-17 12:30:59 -070057
58/**
59 * e1000e_check_reset_block_generic - Check if PHY reset is blocked
60 * @hw: pointer to the HW structure
61 *
62 * Read the PHY management control register and check whether a PHY reset
63 * is blocked. If a reset is not blocked return 0, otherwise
64 * return E1000_BLK_PHY_RESET (12).
65 **/
66s32 e1000e_check_reset_block_generic(struct e1000_hw *hw)
67{
68 u32 manc;
69
70 manc = er32(MANC);
71
72 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
73 E1000_BLK_PHY_RESET : 0;
74}
75
76/**
77 * e1000e_get_phy_id - Retrieve the PHY ID and revision
78 * @hw: pointer to the HW structure
79 *
80 * Reads the PHY registers and stores the PHY ID and possibly the PHY
81 * revision in the hardware structure.
82 **/
83s32 e1000e_get_phy_id(struct e1000_hw *hw)
84{
85 struct e1000_phy_info *phy = &hw->phy;
Bruce Allana4f58f52009-06-02 11:29:18 +000086 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -070087 u16 phy_id;
Bruce Allana4f58f52009-06-02 11:29:18 +000088 u16 retry_count = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -070089
Bruce Allan668018d2012-01-31 07:02:56 +000090 if (!phy->ops.read_reg)
Bruce Allan5015e532012-02-08 02:55:56 +000091 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -070092
Bruce Allana4f58f52009-06-02 11:29:18 +000093 while (retry_count < 2) {
Bruce Allanc2ade1a2013-01-16 08:54:35 +000094 ret_val = e1e_rphy(hw, MII_PHYSID1, &phy_id);
Bruce Allana4f58f52009-06-02 11:29:18 +000095 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +000096 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -070097
Bruce Allana4f58f52009-06-02 11:29:18 +000098 phy->id = (u32)(phy_id << 16);
99 udelay(20);
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000100 ret_val = e1e_rphy(hw, MII_PHYSID2, &phy_id);
Bruce Allana4f58f52009-06-02 11:29:18 +0000101 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000102 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700103
Bruce Allana4f58f52009-06-02 11:29:18 +0000104 phy->id |= (u32)(phy_id & PHY_REVISION_MASK);
105 phy->revision = (u32)(phy_id & ~PHY_REVISION_MASK);
106
107 if (phy->id != 0 && phy->id != PHY_REVISION_MASK)
Bruce Allan5015e532012-02-08 02:55:56 +0000108 return 0;
Bruce Allana4f58f52009-06-02 11:29:18 +0000109
Bruce Allana4f58f52009-06-02 11:29:18 +0000110 retry_count++;
111 }
Bruce Allan5015e532012-02-08 02:55:56 +0000112
113 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700114}
115
116/**
117 * e1000e_phy_reset_dsp - Reset PHY DSP
118 * @hw: pointer to the HW structure
119 *
120 * Reset the digital signal processor.
121 **/
122s32 e1000e_phy_reset_dsp(struct e1000_hw *hw)
123{
124 s32 ret_val;
125
126 ret_val = e1e_wphy(hw, M88E1000_PHY_GEN_CONTROL, 0xC1);
127 if (ret_val)
128 return ret_val;
129
130 return e1e_wphy(hw, M88E1000_PHY_GEN_CONTROL, 0);
131}
132
133/**
David Graham2d9498f2008-04-23 11:09:14 -0700134 * e1000e_read_phy_reg_mdic - Read MDI control register
Auke Kokbc7f75f2007-09-17 12:30:59 -0700135 * @hw: pointer to the HW structure
136 * @offset: register offset to be read
137 * @data: pointer to the read data
138 *
Auke Kok489815c2008-02-21 15:11:07 -0800139 * Reads the MDI control register in the PHY at offset and stores the
Auke Kokbc7f75f2007-09-17 12:30:59 -0700140 * information read to data.
141 **/
David Graham2d9498f2008-04-23 11:09:14 -0700142s32 e1000e_read_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 *data)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700143{
144 struct e1000_phy_info *phy = &hw->phy;
145 u32 i, mdic = 0;
146
147 if (offset > MAX_PHY_REG_ADDRESS) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000148 e_dbg("PHY Address %d is out of range\n", offset);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700149 return -E1000_ERR_PARAM;
150 }
151
Bruce Allane921eb12012-11-28 09:28:37 +0000152 /* Set up Op-code, Phy Address, and register offset in the MDI
Auke Kokbc7f75f2007-09-17 12:30:59 -0700153 * Control register. The MAC will take care of interfacing with the
154 * PHY to retrieve the desired data.
155 */
156 mdic = ((offset << E1000_MDIC_REG_SHIFT) |
157 (phy->addr << E1000_MDIC_PHY_SHIFT) |
158 (E1000_MDIC_OP_READ));
159
160 ew32(MDIC, mdic);
161
Bruce Allane921eb12012-11-28 09:28:37 +0000162 /* Poll the ready bit to see if the MDI read completed
Bruce Allanad680762008-03-28 09:15:03 -0700163 * Increasing the time out as testing showed failures with
164 * the lower time out
165 */
David Graham2d9498f2008-04-23 11:09:14 -0700166 for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700167 udelay(50);
168 mdic = er32(MDIC);
169 if (mdic & E1000_MDIC_READY)
170 break;
171 }
172 if (!(mdic & E1000_MDIC_READY)) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000173 e_dbg("MDI Read did not complete\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700174 return -E1000_ERR_PHY;
175 }
176 if (mdic & E1000_MDIC_ERROR) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000177 e_dbg("MDI Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700178 return -E1000_ERR_PHY;
179 }
Bruce Allan53aa82d2013-02-20 04:06:06 +0000180 *data = (u16)mdic;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700181
Bruce Allane921eb12012-11-28 09:28:37 +0000182 /* Allow some time after each MDIC transaction to avoid
Bruce Allan664dc872010-11-24 06:01:46 +0000183 * reading duplicate data in the next MDIC transaction.
184 */
185 if (hw->mac.type == e1000_pch2lan)
186 udelay(100);
187
Auke Kokbc7f75f2007-09-17 12:30:59 -0700188 return 0;
189}
190
191/**
David Graham2d9498f2008-04-23 11:09:14 -0700192 * e1000e_write_phy_reg_mdic - Write MDI control register
Auke Kokbc7f75f2007-09-17 12:30:59 -0700193 * @hw: pointer to the HW structure
194 * @offset: register offset to write to
195 * @data: data to write to register at offset
196 *
197 * Writes data to MDI control register in the PHY at offset.
198 **/
David Graham2d9498f2008-04-23 11:09:14 -0700199s32 e1000e_write_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 data)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700200{
201 struct e1000_phy_info *phy = &hw->phy;
202 u32 i, mdic = 0;
203
204 if (offset > MAX_PHY_REG_ADDRESS) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000205 e_dbg("PHY Address %d is out of range\n", offset);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700206 return -E1000_ERR_PARAM;
207 }
208
Bruce Allane921eb12012-11-28 09:28:37 +0000209 /* Set up Op-code, Phy Address, and register offset in the MDI
Auke Kokbc7f75f2007-09-17 12:30:59 -0700210 * Control register. The MAC will take care of interfacing with the
211 * PHY to retrieve the desired data.
212 */
213 mdic = (((u32)data) |
214 (offset << E1000_MDIC_REG_SHIFT) |
215 (phy->addr << E1000_MDIC_PHY_SHIFT) |
216 (E1000_MDIC_OP_WRITE));
217
218 ew32(MDIC, mdic);
219
Bruce Allane921eb12012-11-28 09:28:37 +0000220 /* Poll the ready bit to see if the MDI read completed
David Graham2d9498f2008-04-23 11:09:14 -0700221 * Increasing the time out as testing showed failures with
222 * the lower time out
223 */
224 for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
225 udelay(50);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700226 mdic = er32(MDIC);
227 if (mdic & E1000_MDIC_READY)
228 break;
229 }
230 if (!(mdic & E1000_MDIC_READY)) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000231 e_dbg("MDI Write did not complete\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700232 return -E1000_ERR_PHY;
233 }
David Graham2d9498f2008-04-23 11:09:14 -0700234 if (mdic & E1000_MDIC_ERROR) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000235 e_dbg("MDI Error\n");
David Graham2d9498f2008-04-23 11:09:14 -0700236 return -E1000_ERR_PHY;
237 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700238
Bruce Allane921eb12012-11-28 09:28:37 +0000239 /* Allow some time after each MDIC transaction to avoid
Bruce Allan664dc872010-11-24 06:01:46 +0000240 * reading duplicate data in the next MDIC transaction.
241 */
242 if (hw->mac.type == e1000_pch2lan)
243 udelay(100);
244
Auke Kokbc7f75f2007-09-17 12:30:59 -0700245 return 0;
246}
247
248/**
249 * e1000e_read_phy_reg_m88 - Read m88 PHY register
250 * @hw: pointer to the HW structure
251 * @offset: register offset to be read
252 * @data: pointer to the read data
253 *
254 * Acquires semaphore, if necessary, then reads the PHY register at offset
255 * and storing the retrieved information in data. Release any acquired
256 * semaphores before exiting.
257 **/
258s32 e1000e_read_phy_reg_m88(struct e1000_hw *hw, u32 offset, u16 *data)
259{
260 s32 ret_val;
261
Bruce Allan94d81862009-11-20 23:25:26 +0000262 ret_val = hw->phy.ops.acquire(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700263 if (ret_val)
264 return ret_val;
265
David Graham2d9498f2008-04-23 11:09:14 -0700266 ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
267 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700268
Bruce Allan94d81862009-11-20 23:25:26 +0000269 hw->phy.ops.release(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700270
271 return ret_val;
272}
273
274/**
275 * e1000e_write_phy_reg_m88 - Write m88 PHY register
276 * @hw: pointer to the HW structure
277 * @offset: register offset to write to
278 * @data: data to write at register offset
279 *
280 * Acquires semaphore, if necessary, then writes the data to PHY register
281 * at the offset. Release any acquired semaphores before exiting.
282 **/
283s32 e1000e_write_phy_reg_m88(struct e1000_hw *hw, u32 offset, u16 data)
284{
285 s32 ret_val;
286
Bruce Allan94d81862009-11-20 23:25:26 +0000287 ret_val = hw->phy.ops.acquire(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700288 if (ret_val)
289 return ret_val;
290
David Graham2d9498f2008-04-23 11:09:14 -0700291 ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
292 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700293
Bruce Allan94d81862009-11-20 23:25:26 +0000294 hw->phy.ops.release(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700295
296 return ret_val;
297}
298
299/**
Bruce Allan2b6b1682011-05-13 07:20:09 +0000300 * e1000_set_page_igp - Set page as on IGP-like PHY(s)
301 * @hw: pointer to the HW structure
302 * @page: page to set (shifted left when necessary)
303 *
304 * Sets PHY page required for PHY register access. Assumes semaphore is
305 * already acquired. Note, this function sets phy.addr to 1 so the caller
306 * must set it appropriately (if necessary) after this function returns.
307 **/
308s32 e1000_set_page_igp(struct e1000_hw *hw, u16 page)
309{
310 e_dbg("Setting page 0x%x\n", page);
311
312 hw->phy.addr = 1;
313
314 return e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT, page);
315}
316
317/**
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000318 * __e1000e_read_phy_reg_igp - Read igp PHY register
Auke Kokbc7f75f2007-09-17 12:30:59 -0700319 * @hw: pointer to the HW structure
320 * @offset: register offset to be read
321 * @data: pointer to the read data
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000322 * @locked: semaphore has already been acquired or not
Auke Kokbc7f75f2007-09-17 12:30:59 -0700323 *
324 * Acquires semaphore, if necessary, then reads the PHY register at offset
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000325 * and stores the retrieved information in data. Release any acquired
Auke Kokbc7f75f2007-09-17 12:30:59 -0700326 * semaphores before exiting.
327 **/
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000328static s32 __e1000e_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data,
Bruce Allan66501f52013-02-20 04:05:55 +0000329 bool locked)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700330{
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000331 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700332
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000333 if (!locked) {
Bruce Allan668018d2012-01-31 07:02:56 +0000334 if (!hw->phy.ops.acquire)
Bruce Allan5015e532012-02-08 02:55:56 +0000335 return 0;
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000336
Bruce Allan94d81862009-11-20 23:25:26 +0000337 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000338 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000339 return ret_val;
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000340 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700341
Bruce Allan5015e532012-02-08 02:55:56 +0000342 if (offset > MAX_PHY_MULTI_PAGE_REG)
David Graham2d9498f2008-04-23 11:09:14 -0700343 ret_val = e1000e_write_phy_reg_mdic(hw,
344 IGP01E1000_PHY_PAGE_SELECT,
345 (u16)offset);
Bruce Allan5015e532012-02-08 02:55:56 +0000346 if (!ret_val)
347 ret_val = e1000e_read_phy_reg_mdic(hw,
348 MAX_PHY_REG_ADDRESS & offset,
349 data);
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000350 if (!locked)
Bruce Allan94d81862009-11-20 23:25:26 +0000351 hw->phy.ops.release(hw);
Bruce Allan5015e532012-02-08 02:55:56 +0000352
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000353 return ret_val;
354}
Auke Kokbc7f75f2007-09-17 12:30:59 -0700355
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000356/**
357 * e1000e_read_phy_reg_igp - Read igp PHY register
358 * @hw: pointer to the HW structure
359 * @offset: register offset to be read
360 * @data: pointer to the read data
361 *
362 * Acquires semaphore then reads the PHY register at offset and stores the
363 * retrieved information in data.
364 * Release the acquired semaphore before exiting.
365 **/
366s32 e1000e_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data)
367{
368 return __e1000e_read_phy_reg_igp(hw, offset, data, false);
369}
370
371/**
372 * e1000e_read_phy_reg_igp_locked - Read igp PHY register
373 * @hw: pointer to the HW structure
374 * @offset: register offset to be read
375 * @data: pointer to the read data
376 *
377 * Reads the PHY register at offset and stores the retrieved information
378 * in data. Assumes semaphore already acquired.
379 **/
380s32 e1000e_read_phy_reg_igp_locked(struct e1000_hw *hw, u32 offset, u16 *data)
381{
382 return __e1000e_read_phy_reg_igp(hw, offset, data, true);
383}
384
385/**
386 * e1000e_write_phy_reg_igp - Write igp PHY register
387 * @hw: pointer to the HW structure
388 * @offset: register offset to write to
389 * @data: data to write at register offset
390 * @locked: semaphore has already been acquired or not
391 *
392 * Acquires semaphore, if necessary, then writes the data to PHY register
393 * at the offset. Release any acquired semaphores before exiting.
394 **/
395static s32 __e1000e_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data,
Bruce Allan66501f52013-02-20 04:05:55 +0000396 bool locked)
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000397{
398 s32 ret_val = 0;
399
400 if (!locked) {
Bruce Allan668018d2012-01-31 07:02:56 +0000401 if (!hw->phy.ops.acquire)
Bruce Allan5015e532012-02-08 02:55:56 +0000402 return 0;
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000403
Bruce Allan94d81862009-11-20 23:25:26 +0000404 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000405 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000406 return ret_val;
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000407 }
408
Bruce Allan5015e532012-02-08 02:55:56 +0000409 if (offset > MAX_PHY_MULTI_PAGE_REG)
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000410 ret_val = e1000e_write_phy_reg_mdic(hw,
411 IGP01E1000_PHY_PAGE_SELECT,
412 (u16)offset);
Bruce Allan5015e532012-02-08 02:55:56 +0000413 if (!ret_val)
414 ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS &
Bruce Allan17e813e2013-02-20 04:06:01 +0000415 offset, data);
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000416 if (!locked)
Bruce Allan94d81862009-11-20 23:25:26 +0000417 hw->phy.ops.release(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000418
Auke Kokbc7f75f2007-09-17 12:30:59 -0700419 return ret_val;
420}
421
422/**
423 * e1000e_write_phy_reg_igp - Write igp PHY register
424 * @hw: pointer to the HW structure
425 * @offset: register offset to write to
426 * @data: data to write at register offset
427 *
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000428 * Acquires semaphore then writes the data to PHY register
Auke Kokbc7f75f2007-09-17 12:30:59 -0700429 * at the offset. Release any acquired semaphores before exiting.
430 **/
431s32 e1000e_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data)
432{
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000433 return __e1000e_write_phy_reg_igp(hw, offset, data, false);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700434}
435
436/**
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000437 * e1000e_write_phy_reg_igp_locked - Write igp PHY register
438 * @hw: pointer to the HW structure
439 * @offset: register offset to write to
440 * @data: data to write at register offset
441 *
442 * Writes the data to PHY register at the offset.
443 * Assumes semaphore already acquired.
444 **/
445s32 e1000e_write_phy_reg_igp_locked(struct e1000_hw *hw, u32 offset, u16 data)
446{
447 return __e1000e_write_phy_reg_igp(hw, offset, data, true);
448}
449
450/**
451 * __e1000_read_kmrn_reg - Read kumeran register
Auke Kokbc7f75f2007-09-17 12:30:59 -0700452 * @hw: pointer to the HW structure
453 * @offset: register offset to be read
454 * @data: pointer to the read data
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000455 * @locked: semaphore has already been acquired or not
Auke Kokbc7f75f2007-09-17 12:30:59 -0700456 *
457 * Acquires semaphore, if necessary. Then reads the PHY register at offset
458 * using the kumeran interface. The information retrieved is stored in data.
459 * Release any acquired semaphores before exiting.
460 **/
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000461static s32 __e1000_read_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 *data,
Bruce Allan66501f52013-02-20 04:05:55 +0000462 bool locked)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700463{
464 u32 kmrnctrlsta;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700465
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000466 if (!locked) {
Bruce Allan5015e532012-02-08 02:55:56 +0000467 s32 ret_val = 0;
468
Bruce Allan668018d2012-01-31 07:02:56 +0000469 if (!hw->phy.ops.acquire)
Bruce Allan5015e532012-02-08 02:55:56 +0000470 return 0;
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000471
Bruce Allan94d81862009-11-20 23:25:26 +0000472 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000473 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000474 return ret_val;
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000475 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700476
477 kmrnctrlsta = ((offset << E1000_KMRNCTRLSTA_OFFSET_SHIFT) &
478 E1000_KMRNCTRLSTA_OFFSET) | E1000_KMRNCTRLSTA_REN;
479 ew32(KMRNCTRLSTA, kmrnctrlsta);
Jesse Brandeburg945a5152011-07-20 00:56:21 +0000480 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -0700481
482 udelay(2);
483
484 kmrnctrlsta = er32(KMRNCTRLSTA);
485 *data = (u16)kmrnctrlsta;
486
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000487 if (!locked)
Bruce Allan94d81862009-11-20 23:25:26 +0000488 hw->phy.ops.release(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700489
Bruce Allan5015e532012-02-08 02:55:56 +0000490 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700491}
492
493/**
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000494 * e1000e_read_kmrn_reg - Read kumeran register
495 * @hw: pointer to the HW structure
496 * @offset: register offset to be read
497 * @data: pointer to the read data
498 *
499 * Acquires semaphore then reads the PHY register at offset using the
500 * kumeran interface. The information retrieved is stored in data.
501 * Release the acquired semaphore before exiting.
502 **/
503s32 e1000e_read_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 *data)
504{
505 return __e1000_read_kmrn_reg(hw, offset, data, false);
506}
507
508/**
Bruce Allan1d5846b2009-10-29 13:46:05 +0000509 * e1000e_read_kmrn_reg_locked - Read kumeran register
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000510 * @hw: pointer to the HW structure
511 * @offset: register offset to be read
512 * @data: pointer to the read data
513 *
514 * Reads the PHY register at offset using the kumeran interface. The
515 * information retrieved is stored in data.
516 * Assumes semaphore already acquired.
517 **/
Bruce Allan1d5846b2009-10-29 13:46:05 +0000518s32 e1000e_read_kmrn_reg_locked(struct e1000_hw *hw, u32 offset, u16 *data)
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000519{
520 return __e1000_read_kmrn_reg(hw, offset, data, true);
521}
522
523/**
524 * __e1000_write_kmrn_reg - Write kumeran register
Auke Kokbc7f75f2007-09-17 12:30:59 -0700525 * @hw: pointer to the HW structure
526 * @offset: register offset to write to
527 * @data: data to write at register offset
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000528 * @locked: semaphore has already been acquired or not
Auke Kokbc7f75f2007-09-17 12:30:59 -0700529 *
530 * Acquires semaphore, if necessary. Then write the data to PHY register
531 * at the offset using the kumeran interface. Release any acquired semaphores
532 * before exiting.
533 **/
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000534static s32 __e1000_write_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 data,
Bruce Allan66501f52013-02-20 04:05:55 +0000535 bool locked)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700536{
537 u32 kmrnctrlsta;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700538
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000539 if (!locked) {
Bruce Allan5015e532012-02-08 02:55:56 +0000540 s32 ret_val = 0;
541
Bruce Allan668018d2012-01-31 07:02:56 +0000542 if (!hw->phy.ops.acquire)
Bruce Allan5015e532012-02-08 02:55:56 +0000543 return 0;
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000544
Bruce Allan94d81862009-11-20 23:25:26 +0000545 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000546 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000547 return ret_val;
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000548 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700549
550 kmrnctrlsta = ((offset << E1000_KMRNCTRLSTA_OFFSET_SHIFT) &
551 E1000_KMRNCTRLSTA_OFFSET) | data;
552 ew32(KMRNCTRLSTA, kmrnctrlsta);
Jesse Brandeburg945a5152011-07-20 00:56:21 +0000553 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -0700554
555 udelay(2);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700556
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000557 if (!locked)
Bruce Allan94d81862009-11-20 23:25:26 +0000558 hw->phy.ops.release(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000559
Bruce Allan5015e532012-02-08 02:55:56 +0000560 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700561}
562
563/**
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000564 * e1000e_write_kmrn_reg - Write kumeran register
565 * @hw: pointer to the HW structure
566 * @offset: register offset to write to
567 * @data: data to write at register offset
568 *
569 * Acquires semaphore then writes the data to the PHY register at the offset
570 * using the kumeran interface. Release the acquired semaphore before exiting.
571 **/
572s32 e1000e_write_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 data)
573{
574 return __e1000_write_kmrn_reg(hw, offset, data, false);
575}
576
577/**
Bruce Allan1d5846b2009-10-29 13:46:05 +0000578 * e1000e_write_kmrn_reg_locked - Write kumeran register
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000579 * @hw: pointer to the HW structure
580 * @offset: register offset to write to
581 * @data: data to write at register offset
582 *
583 * Write the data to PHY register at the offset using the kumeran interface.
584 * Assumes semaphore already acquired.
585 **/
Bruce Allan1d5846b2009-10-29 13:46:05 +0000586s32 e1000e_write_kmrn_reg_locked(struct e1000_hw *hw, u32 offset, u16 data)
Bruce Allan5ccdcec2009-10-26 11:24:02 +0000587{
588 return __e1000_write_kmrn_reg(hw, offset, data, true);
589}
590
591/**
Bruce Allan7b9f7e32012-03-20 03:47:41 +0000592 * e1000_set_master_slave_mode - Setup PHY for Master/slave mode
593 * @hw: pointer to the HW structure
594 *
595 * Sets up Master/slave mode
596 **/
597static s32 e1000_set_master_slave_mode(struct e1000_hw *hw)
598{
599 s32 ret_val;
600 u16 phy_data;
601
602 /* Resolve Master/Slave mode */
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000603 ret_val = e1e_rphy(hw, MII_CTRL1000, &phy_data);
Bruce Allan7b9f7e32012-03-20 03:47:41 +0000604 if (ret_val)
605 return ret_val;
606
607 /* load defaults for future use */
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000608 hw->phy.original_ms_type = (phy_data & CTL1000_ENABLE_MASTER) ?
609 ((phy_data & CTL1000_AS_MASTER) ?
Bruce Allan7b9f7e32012-03-20 03:47:41 +0000610 e1000_ms_force_master : e1000_ms_force_slave) : e1000_ms_auto;
611
612 switch (hw->phy.ms_type) {
613 case e1000_ms_force_master:
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000614 phy_data |= (CTL1000_ENABLE_MASTER | CTL1000_AS_MASTER);
Bruce Allan7b9f7e32012-03-20 03:47:41 +0000615 break;
616 case e1000_ms_force_slave:
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000617 phy_data |= CTL1000_ENABLE_MASTER;
618 phy_data &= ~(CTL1000_AS_MASTER);
Bruce Allan7b9f7e32012-03-20 03:47:41 +0000619 break;
620 case e1000_ms_auto:
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000621 phy_data &= ~CTL1000_ENABLE_MASTER;
Bruce Allan7b9f7e32012-03-20 03:47:41 +0000622 /* fall-through */
623 default:
624 break;
625 }
626
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000627 return e1e_wphy(hw, MII_CTRL1000, phy_data);
Bruce Allan7b9f7e32012-03-20 03:47:41 +0000628}
629
630/**
Bruce Allana4f58f52009-06-02 11:29:18 +0000631 * e1000_copper_link_setup_82577 - Setup 82577 PHY for copper link
632 * @hw: pointer to the HW structure
633 *
634 * Sets up Carrier-sense on Transmit and downshift values.
635 **/
636s32 e1000_copper_link_setup_82577(struct e1000_hw *hw)
637{
Bruce Allana4f58f52009-06-02 11:29:18 +0000638 s32 ret_val;
639 u16 phy_data;
640
Bruce Allanaf667a22010-12-31 06:10:01 +0000641 /* Enable CRS on Tx. This must be set for half-duplex operation. */
Bruce Allan482fed82011-01-06 14:29:49 +0000642 ret_val = e1e_rphy(hw, I82577_CFG_REG, &phy_data);
Bruce Allana4f58f52009-06-02 11:29:18 +0000643 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000644 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +0000645
646 phy_data |= I82577_CFG_ASSERT_CRS_ON_TX;
647
648 /* Enable downshift */
649 phy_data |= I82577_CFG_ENABLE_DOWNSHIFT;
650
Bruce Allan7b9f7e32012-03-20 03:47:41 +0000651 ret_val = e1e_wphy(hw, I82577_CFG_REG, phy_data);
652 if (ret_val)
653 return ret_val;
654
Bruce W Allane86fd892012-07-26 02:30:59 +0000655 /* Set MDI/MDIX mode */
656 ret_val = e1e_rphy(hw, I82577_PHY_CTRL_2, &phy_data);
657 if (ret_val)
658 return ret_val;
659 phy_data &= ~I82577_PHY_CTRL2_MDIX_CFG_MASK;
Bruce Allane921eb12012-11-28 09:28:37 +0000660 /* Options:
Bruce W Allane86fd892012-07-26 02:30:59 +0000661 * 0 - Auto (default)
662 * 1 - MDI mode
663 * 2 - MDI-X mode
664 */
665 switch (hw->phy.mdix) {
666 case 1:
667 break;
668 case 2:
669 phy_data |= I82577_PHY_CTRL2_MANUAL_MDIX;
670 break;
671 case 0:
672 default:
673 phy_data |= I82577_PHY_CTRL2_AUTO_MDI_MDIX;
674 break;
675 }
676 ret_val = e1e_wphy(hw, I82577_PHY_CTRL_2, phy_data);
677 if (ret_val)
678 return ret_val;
679
Bruce Allan7b9f7e32012-03-20 03:47:41 +0000680 return e1000_set_master_slave_mode(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +0000681}
682
683/**
Auke Kokbc7f75f2007-09-17 12:30:59 -0700684 * e1000e_copper_link_setup_m88 - Setup m88 PHY's for copper link
685 * @hw: pointer to the HW structure
686 *
687 * Sets up MDI/MDI-X and polarity for m88 PHY's. If necessary, transmit clock
688 * and downshift values are set also.
689 **/
690s32 e1000e_copper_link_setup_m88(struct e1000_hw *hw)
691{
692 struct e1000_phy_info *phy = &hw->phy;
693 s32 ret_val;
694 u16 phy_data;
695
Bruce Allanad680762008-03-28 09:15:03 -0700696 /* Enable CRS on Tx. This must be set for half-duplex operation. */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700697 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
698 if (ret_val)
699 return ret_val;
700
Bruce Allana4f58f52009-06-02 11:29:18 +0000701 /* For BM PHY this bit is downshift enable */
702 if (phy->type != e1000_phy_bm)
David Graham2d9498f2008-04-23 11:09:14 -0700703 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700704
Bruce Allane921eb12012-11-28 09:28:37 +0000705 /* Options:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700706 * MDI/MDI-X = 0 (default)
707 * 0 - Auto for all speeds
708 * 1 - MDI mode
709 * 2 - MDI-X mode
710 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
711 */
712 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
713
714 switch (phy->mdix) {
715 case 1:
716 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
717 break;
718 case 2:
719 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
720 break;
721 case 3:
722 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
723 break;
724 case 0:
725 default:
726 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
727 break;
728 }
729
Bruce Allane921eb12012-11-28 09:28:37 +0000730 /* Options:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700731 * disable_polarity_correction = 0 (default)
732 * Automatic Correction for Reversed Cable Polarity
733 * 0 - Disabled
734 * 1 - Enabled
735 */
736 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
Bruce Allan04499ec2012-04-13 00:08:31 +0000737 if (phy->disable_polarity_correction)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700738 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
739
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700740 /* Enable downshift on BM (disabled by default) */
Matthew Vick885fe7b2012-04-25 07:25:18 +0000741 if (phy->type == e1000_phy_bm) {
742 /* For 82574/82583, first disable then enable downshift */
743 if (phy->id == BME1000_E_PHY_ID_R2) {
744 phy_data &= ~BME1000_PSCR_ENABLE_DOWNSHIFT;
745 ret_val = e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL,
746 phy_data);
747 if (ret_val)
748 return ret_val;
749 /* Commit the changes. */
Bruce Allan6b598e12013-01-23 06:50:05 +0000750 ret_val = phy->ops.commit(hw);
Matthew Vick885fe7b2012-04-25 07:25:18 +0000751 if (ret_val) {
752 e_dbg("Error committing the PHY changes\n");
753 return ret_val;
754 }
755 }
756
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700757 phy_data |= BME1000_PSCR_ENABLE_DOWNSHIFT;
Matthew Vick885fe7b2012-04-25 07:25:18 +0000758 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700759
Auke Kokbc7f75f2007-09-17 12:30:59 -0700760 ret_val = e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
761 if (ret_val)
762 return ret_val;
763
Bruce Allan4662e822008-08-26 18:37:06 -0700764 if ((phy->type == e1000_phy_m88) &&
765 (phy->revision < E1000_REVISION_4) &&
766 (phy->id != BME1000_E_PHY_ID_R2)) {
Bruce Allane921eb12012-11-28 09:28:37 +0000767 /* Force TX_CLK in the Extended PHY Specific Control Register
Auke Kokbc7f75f2007-09-17 12:30:59 -0700768 * to 25MHz clock.
769 */
770 ret_val = e1e_rphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
771 if (ret_val)
772 return ret_val;
773
774 phy_data |= M88E1000_EPSCR_TX_CLK_25;
775
776 if ((phy->revision == 2) &&
777 (phy->id == M88E1111_I_PHY_ID)) {
778 /* 82573L PHY - set the downshift counter to 5x. */
779 phy_data &= ~M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK;
780 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
781 } else {
782 /* Configure Master and Slave downshift values */
783 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
784 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
785 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
786 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
787 }
788 ret_val = e1e_wphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
789 if (ret_val)
790 return ret_val;
791 }
792
Bruce Allan4662e822008-08-26 18:37:06 -0700793 if ((phy->type == e1000_phy_bm) && (phy->id == BME1000_E_PHY_ID_R2)) {
794 /* Set PHY page 0, register 29 to 0x0003 */
795 ret_val = e1e_wphy(hw, 29, 0x0003);
796 if (ret_val)
797 return ret_val;
798
799 /* Set PHY page 0, register 30 to 0x0000 */
800 ret_val = e1e_wphy(hw, 30, 0x0000);
801 if (ret_val)
802 return ret_val;
803 }
804
Auke Kokbc7f75f2007-09-17 12:30:59 -0700805 /* Commit the changes. */
Bruce Allan6b598e12013-01-23 06:50:05 +0000806 if (phy->ops.commit) {
807 ret_val = phy->ops.commit(hw);
808 if (ret_val) {
809 e_dbg("Error committing the PHY changes\n");
810 return ret_val;
811 }
Bruce Allana4f58f52009-06-02 11:29:18 +0000812 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700813
Bruce Allana4f58f52009-06-02 11:29:18 +0000814 if (phy->type == e1000_phy_82578) {
Bruce Allan482fed82011-01-06 14:29:49 +0000815 ret_val = e1e_rphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
Bruce Allana4f58f52009-06-02 11:29:18 +0000816 if (ret_val)
817 return ret_val;
818
819 /* 82578 PHY - set the downshift count to 1x. */
820 phy_data |= I82578_EPSCR_DOWNSHIFT_ENABLE;
821 phy_data &= ~I82578_EPSCR_DOWNSHIFT_COUNTER_MASK;
Bruce Allan482fed82011-01-06 14:29:49 +0000822 ret_val = e1e_wphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
Bruce Allana4f58f52009-06-02 11:29:18 +0000823 if (ret_val)
824 return ret_val;
825 }
826
827 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700828}
829
830/**
831 * e1000e_copper_link_setup_igp - Setup igp PHY's for copper link
832 * @hw: pointer to the HW structure
833 *
834 * Sets up LPLU, MDI/MDI-X, polarity, Smartspeed and Master/Slave config for
835 * igp PHY's.
836 **/
837s32 e1000e_copper_link_setup_igp(struct e1000_hw *hw)
838{
839 struct e1000_phy_info *phy = &hw->phy;
840 s32 ret_val;
841 u16 data;
842
843 ret_val = e1000_phy_hw_reset(hw);
844 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000845 e_dbg("Error resetting the PHY.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700846 return ret_val;
847 }
848
Bruce Allane921eb12012-11-28 09:28:37 +0000849 /* Wait 100ms for MAC to configure PHY from NVM settings, to avoid
David Graham2d9498f2008-04-23 11:09:14 -0700850 * timeout issues when LFS is enabled.
851 */
852 msleep(100);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700853
854 /* disable lplu d0 during driver init */
Bruce Allan7de89f02013-01-05 08:06:03 +0000855 if (hw->phy.ops.set_d0_lplu_state) {
856 ret_val = hw->phy.ops.set_d0_lplu_state(hw, false);
857 if (ret_val) {
858 e_dbg("Error Disabling LPLU D0\n");
859 return ret_val;
860 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700861 }
862 /* Configure mdi-mdix settings */
863 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CTRL, &data);
864 if (ret_val)
865 return ret_val;
866
867 data &= ~IGP01E1000_PSCR_AUTO_MDIX;
868
869 switch (phy->mdix) {
870 case 1:
871 data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
872 break;
873 case 2:
874 data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
875 break;
876 case 0:
877 default:
878 data |= IGP01E1000_PSCR_AUTO_MDIX;
879 break;
880 }
881 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CTRL, data);
882 if (ret_val)
883 return ret_val;
884
885 /* set auto-master slave resolution settings */
886 if (hw->mac.autoneg) {
Bruce Allane921eb12012-11-28 09:28:37 +0000887 /* when autonegotiation advertisement is only 1000Mbps then we
Auke Kokbc7f75f2007-09-17 12:30:59 -0700888 * should disable SmartSpeed and enable Auto MasterSlave
Bruce Allanad680762008-03-28 09:15:03 -0700889 * resolution as hardware default.
890 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700891 if (phy->autoneg_advertised == ADVERTISE_1000_FULL) {
892 /* Disable SmartSpeed */
893 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -0700894 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700895 if (ret_val)
896 return ret_val;
897
898 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
899 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -0700900 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700901 if (ret_val)
902 return ret_val;
903
904 /* Set auto Master/Slave resolution process */
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000905 ret_val = e1e_rphy(hw, MII_CTRL1000, &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700906 if (ret_val)
907 return ret_val;
908
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000909 data &= ~CTL1000_ENABLE_MASTER;
910 ret_val = e1e_wphy(hw, MII_CTRL1000, data);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700911 if (ret_val)
912 return ret_val;
913 }
914
Bruce Allan7b9f7e32012-03-20 03:47:41 +0000915 ret_val = e1000_set_master_slave_mode(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700916 }
917
918 return ret_val;
919}
920
921/**
922 * e1000_phy_setup_autoneg - Configure PHY for auto-negotiation
923 * @hw: pointer to the HW structure
924 *
925 * Reads the MII auto-neg advertisement register and/or the 1000T control
926 * register and if the PHY is already setup for auto-negotiation, then
927 * return successful. Otherwise, setup advertisement and flow control to
928 * the appropriate values for the wanted auto-negotiation.
929 **/
930static s32 e1000_phy_setup_autoneg(struct e1000_hw *hw)
931{
932 struct e1000_phy_info *phy = &hw->phy;
933 s32 ret_val;
934 u16 mii_autoneg_adv_reg;
935 u16 mii_1000t_ctrl_reg = 0;
936
937 phy->autoneg_advertised &= phy->autoneg_mask;
938
939 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000940 ret_val = e1e_rphy(hw, MII_ADVERTISE, &mii_autoneg_adv_reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700941 if (ret_val)
942 return ret_val;
943
944 if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
945 /* Read the MII 1000Base-T Control Register (Address 9). */
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000946 ret_val = e1e_rphy(hw, MII_CTRL1000, &mii_1000t_ctrl_reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700947 if (ret_val)
948 return ret_val;
949 }
950
Bruce Allane921eb12012-11-28 09:28:37 +0000951 /* Need to parse both autoneg_advertised and fc and set up
Auke Kokbc7f75f2007-09-17 12:30:59 -0700952 * the appropriate PHY registers. First we will parse for
953 * autoneg_advertised software override. Since we can advertise
954 * a plethora of combinations, we need to check each bit
955 * individually.
956 */
957
Bruce Allane921eb12012-11-28 09:28:37 +0000958 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
Auke Kokbc7f75f2007-09-17 12:30:59 -0700959 * Advertisement Register (Address 4) and the 1000 mb speed bits in
960 * the 1000Base-T Control Register (Address 9).
961 */
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000962 mii_autoneg_adv_reg &= ~(ADVERTISE_100FULL |
963 ADVERTISE_100HALF |
964 ADVERTISE_10FULL | ADVERTISE_10HALF);
965 mii_1000t_ctrl_reg &= ~(ADVERTISE_1000HALF | ADVERTISE_1000FULL);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700966
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000967 e_dbg("autoneg_advertised %x\n", phy->autoneg_advertised);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700968
969 /* Do we want to advertise 10 Mb Half Duplex? */
970 if (phy->autoneg_advertised & ADVERTISE_10_HALF) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000971 e_dbg("Advertise 10mb Half duplex\n");
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000972 mii_autoneg_adv_reg |= ADVERTISE_10HALF;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700973 }
974
975 /* Do we want to advertise 10 Mb Full Duplex? */
976 if (phy->autoneg_advertised & ADVERTISE_10_FULL) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000977 e_dbg("Advertise 10mb Full duplex\n");
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000978 mii_autoneg_adv_reg |= ADVERTISE_10FULL;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700979 }
980
981 /* Do we want to advertise 100 Mb Half Duplex? */
982 if (phy->autoneg_advertised & ADVERTISE_100_HALF) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000983 e_dbg("Advertise 100mb Half duplex\n");
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000984 mii_autoneg_adv_reg |= ADVERTISE_100HALF;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700985 }
986
987 /* Do we want to advertise 100 Mb Full Duplex? */
988 if (phy->autoneg_advertised & ADVERTISE_100_FULL) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000989 e_dbg("Advertise 100mb Full duplex\n");
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000990 mii_autoneg_adv_reg |= ADVERTISE_100FULL;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700991 }
992
993 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
994 if (phy->autoneg_advertised & ADVERTISE_1000_HALF)
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000995 e_dbg("Advertise 1000mb Half duplex request denied!\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700996
997 /* Do we want to advertise 1000 Mb Full Duplex? */
998 if (phy->autoneg_advertised & ADVERTISE_1000_FULL) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000999 e_dbg("Advertise 1000mb Full duplex\n");
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001000 mii_1000t_ctrl_reg |= ADVERTISE_1000FULL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001001 }
1002
Bruce Allane921eb12012-11-28 09:28:37 +00001003 /* Check for a software override of the flow control settings, and
Auke Kokbc7f75f2007-09-17 12:30:59 -07001004 * setup the PHY advertisement registers accordingly. If
1005 * auto-negotiation is enabled, then software will have to set the
1006 * "PAUSE" bits to the correct value in the Auto-Negotiation
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001007 * Advertisement Register (MII_ADVERTISE) and re-start auto-
Auke Kokbc7f75f2007-09-17 12:30:59 -07001008 * negotiation.
1009 *
1010 * The possible values of the "fc" parameter are:
1011 * 0: Flow control is completely disabled
1012 * 1: Rx flow control is enabled (we can receive pause frames
Bruce Allan3d3a1672012-02-23 03:13:18 +00001013 * but not send pause frames).
Auke Kokbc7f75f2007-09-17 12:30:59 -07001014 * 2: Tx flow control is enabled (we can send pause frames
Bruce Allan3d3a1672012-02-23 03:13:18 +00001015 * but we do not support receiving pause frames).
Bruce Allanad680762008-03-28 09:15:03 -07001016 * 3: Both Rx and Tx flow control (symmetric) are enabled.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001017 * other: No software override. The flow control configuration
Bruce Allan3d3a1672012-02-23 03:13:18 +00001018 * in the EEPROM is used.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001019 */
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08001020 switch (hw->fc.current_mode) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001021 case e1000_fc_none:
Bruce Allane921eb12012-11-28 09:28:37 +00001022 /* Flow control (Rx & Tx) is completely disabled by a
Auke Kokbc7f75f2007-09-17 12:30:59 -07001023 * software over-ride.
1024 */
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001025 mii_autoneg_adv_reg &=
1026 ~(ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001027 break;
1028 case e1000_fc_rx_pause:
Bruce Allane921eb12012-11-28 09:28:37 +00001029 /* Rx Flow control is enabled, and Tx Flow control is
Auke Kokbc7f75f2007-09-17 12:30:59 -07001030 * disabled, by a software over-ride.
Bruce Allanad680762008-03-28 09:15:03 -07001031 *
1032 * Since there really isn't a way to advertise that we are
1033 * capable of Rx Pause ONLY, we will advertise that we
1034 * support both symmetric and asymmetric Rx PAUSE. Later
Auke Kokbc7f75f2007-09-17 12:30:59 -07001035 * (in e1000e_config_fc_after_link_up) we will disable the
1036 * hw's ability to send PAUSE frames.
1037 */
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001038 mii_autoneg_adv_reg |=
1039 (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001040 break;
1041 case e1000_fc_tx_pause:
Bruce Allane921eb12012-11-28 09:28:37 +00001042 /* Tx Flow control is enabled, and Rx Flow control is
Auke Kokbc7f75f2007-09-17 12:30:59 -07001043 * disabled, by a software over-ride.
1044 */
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001045 mii_autoneg_adv_reg |= ADVERTISE_PAUSE_ASYM;
1046 mii_autoneg_adv_reg &= ~ADVERTISE_PAUSE_CAP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001047 break;
1048 case e1000_fc_full:
Bruce Allane921eb12012-11-28 09:28:37 +00001049 /* Flow control (both Rx and Tx) is enabled by a software
Auke Kokbc7f75f2007-09-17 12:30:59 -07001050 * over-ride.
1051 */
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001052 mii_autoneg_adv_reg |=
1053 (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001054 break;
1055 default:
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001056 e_dbg("Flow control param set incorrectly\n");
Bruce Allan7eb61d82012-02-08 02:55:03 +00001057 return -E1000_ERR_CONFIG;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001058 }
1059
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001060 ret_val = e1e_wphy(hw, MII_ADVERTISE, mii_autoneg_adv_reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001061 if (ret_val)
1062 return ret_val;
1063
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001064 e_dbg("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001065
Bruce Allanb1cdfea2010-12-11 05:53:47 +00001066 if (phy->autoneg_mask & ADVERTISE_1000_FULL)
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001067 ret_val = e1e_wphy(hw, MII_CTRL1000, mii_1000t_ctrl_reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001068
1069 return ret_val;
1070}
1071
1072/**
1073 * e1000_copper_link_autoneg - Setup/Enable autoneg for copper link
1074 * @hw: pointer to the HW structure
1075 *
1076 * Performs initial bounds checking on autoneg advertisement parameter, then
1077 * configure to advertise the full capability. Setup the PHY to autoneg
1078 * and restart the negotiation process between the link partner. If
Bruce Allanad680762008-03-28 09:15:03 -07001079 * autoneg_wait_to_complete, then wait for autoneg to complete before exiting.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001080 **/
1081static s32 e1000_copper_link_autoneg(struct e1000_hw *hw)
1082{
1083 struct e1000_phy_info *phy = &hw->phy;
1084 s32 ret_val;
1085 u16 phy_ctrl;
1086
Bruce Allane921eb12012-11-28 09:28:37 +00001087 /* Perform some bounds checking on the autoneg advertisement
Auke Kokbc7f75f2007-09-17 12:30:59 -07001088 * parameter.
1089 */
1090 phy->autoneg_advertised &= phy->autoneg_mask;
1091
Bruce Allane921eb12012-11-28 09:28:37 +00001092 /* If autoneg_advertised is zero, we assume it was not defaulted
Auke Kokbc7f75f2007-09-17 12:30:59 -07001093 * by the calling code so we set to advertise full capability.
1094 */
Bruce Allan04499ec2012-04-13 00:08:31 +00001095 if (!phy->autoneg_advertised)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001096 phy->autoneg_advertised = phy->autoneg_mask;
1097
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001098 e_dbg("Reconfiguring auto-neg advertisement params\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001099 ret_val = e1000_phy_setup_autoneg(hw);
1100 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001101 e_dbg("Error Setting up Auto-Negotiation\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001102 return ret_val;
1103 }
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001104 e_dbg("Restarting Auto-Neg\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001105
Bruce Allane921eb12012-11-28 09:28:37 +00001106 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
Auke Kokbc7f75f2007-09-17 12:30:59 -07001107 * the Auto Neg Restart bit in the PHY control register.
1108 */
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001109 ret_val = e1e_rphy(hw, MII_BMCR, &phy_ctrl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001110 if (ret_val)
1111 return ret_val;
1112
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001113 phy_ctrl |= (BMCR_ANENABLE | BMCR_ANRESTART);
1114 ret_val = e1e_wphy(hw, MII_BMCR, phy_ctrl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001115 if (ret_val)
1116 return ret_val;
1117
Bruce Allane921eb12012-11-28 09:28:37 +00001118 /* Does the user want to wait for Auto-Neg to complete here, or
Auke Kokbc7f75f2007-09-17 12:30:59 -07001119 * check at a later time (for example, callback routine).
1120 */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001121 if (phy->autoneg_wait_to_complete) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001122 ret_val = e1000_wait_autoneg(hw);
1123 if (ret_val) {
Bruce Allan434f1392011-12-16 00:46:54 +00001124 e_dbg("Error while waiting for autoneg to complete\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001125 return ret_val;
1126 }
1127 }
1128
Bruce Allanf92518d2012-02-01 11:16:42 +00001129 hw->mac.get_link_status = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001130
1131 return ret_val;
1132}
1133
1134/**
1135 * e1000e_setup_copper_link - Configure copper link settings
1136 * @hw: pointer to the HW structure
1137 *
1138 * Calls the appropriate function to configure the link for auto-neg or forced
1139 * speed and duplex. Then we check for link, once link is established calls
1140 * to configure collision distance and flow control are called. If link is
1141 * not established, we return -E1000_ERR_PHY (-2).
1142 **/
1143s32 e1000e_setup_copper_link(struct e1000_hw *hw)
1144{
1145 s32 ret_val;
1146 bool link;
1147
1148 if (hw->mac.autoneg) {
Bruce Allane921eb12012-11-28 09:28:37 +00001149 /* Setup autoneg and flow control advertisement and perform
Bruce Allanad680762008-03-28 09:15:03 -07001150 * autonegotiation.
1151 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001152 ret_val = e1000_copper_link_autoneg(hw);
1153 if (ret_val)
1154 return ret_val;
1155 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00001156 /* PHY will be set to 10H, 10F, 100H or 100F
Bruce Allanad680762008-03-28 09:15:03 -07001157 * depending on user settings.
1158 */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001159 e_dbg("Forcing Speed and Duplex\n");
Bruce Allanc2c66292013-01-05 08:06:08 +00001160 ret_val = hw->phy.ops.force_speed_duplex(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001161 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001162 e_dbg("Error Forcing Speed and Duplex\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001163 return ret_val;
1164 }
1165 }
1166
Bruce Allane921eb12012-11-28 09:28:37 +00001167 /* Check link status. Wait up to 100 microseconds for link to become
Auke Kokbc7f75f2007-09-17 12:30:59 -07001168 * valid.
1169 */
Bruce Allan3d3a1672012-02-23 03:13:18 +00001170 ret_val = e1000e_phy_has_link_generic(hw, COPPER_LINK_UP_LIMIT, 10,
1171 &link);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001172 if (ret_val)
1173 return ret_val;
1174
1175 if (link) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001176 e_dbg("Valid link established!!!\n");
Bruce Allan57cde762012-02-22 09:02:58 +00001177 hw->mac.ops.config_collision_dist(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001178 ret_val = e1000e_config_fc_after_link_up(hw);
1179 } else {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001180 e_dbg("Unable to establish link!!!\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001181 }
1182
1183 return ret_val;
1184}
1185
1186/**
1187 * e1000e_phy_force_speed_duplex_igp - Force speed/duplex for igp PHY
1188 * @hw: pointer to the HW structure
1189 *
1190 * Calls the PHY setup function to force speed and duplex. Clears the
1191 * auto-crossover to force MDI manually. Waits for link and returns
1192 * successful if link up is successful, else -E1000_ERR_PHY (-2).
1193 **/
1194s32 e1000e_phy_force_speed_duplex_igp(struct e1000_hw *hw)
1195{
1196 struct e1000_phy_info *phy = &hw->phy;
1197 s32 ret_val;
1198 u16 phy_data;
1199 bool link;
1200
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001201 ret_val = e1e_rphy(hw, MII_BMCR, &phy_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001202 if (ret_val)
1203 return ret_val;
1204
1205 e1000e_phy_force_speed_duplex_setup(hw, &phy_data);
1206
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001207 ret_val = e1e_wphy(hw, MII_BMCR, phy_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001208 if (ret_val)
1209 return ret_val;
1210
Bruce Allane921eb12012-11-28 09:28:37 +00001211 /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
Auke Kokbc7f75f2007-09-17 12:30:59 -07001212 * forced whenever speed and duplex are forced.
1213 */
1214 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1215 if (ret_val)
1216 return ret_val;
1217
1218 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1219 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1220
1221 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1222 if (ret_val)
1223 return ret_val;
1224
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001225 e_dbg("IGP PSCR: %X\n", phy_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001226
1227 udelay(1);
1228
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001229 if (phy->autoneg_wait_to_complete) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001230 e_dbg("Waiting for forced speed/duplex link on IGP phy.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001231
Bruce Allan3d3a1672012-02-23 03:13:18 +00001232 ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
1233 100000, &link);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001234 if (ret_val)
1235 return ret_val;
1236
1237 if (!link)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001238 e_dbg("Link taking longer than expected.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001239
1240 /* Try once more */
Bruce Allan3d3a1672012-02-23 03:13:18 +00001241 ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
1242 100000, &link);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001243 }
1244
1245 return ret_val;
1246}
1247
1248/**
1249 * e1000e_phy_force_speed_duplex_m88 - Force speed/duplex for m88 PHY
1250 * @hw: pointer to the HW structure
1251 *
1252 * Calls the PHY setup function to force speed and duplex. Clears the
1253 * auto-crossover to force MDI manually. Resets the PHY to commit the
1254 * changes. If time expires while waiting for link up, we reset the DSP.
Bruce Allanad680762008-03-28 09:15:03 -07001255 * After reset, TX_CLK and CRS on Tx must be set. Return successful upon
Auke Kokbc7f75f2007-09-17 12:30:59 -07001256 * successful completion, else return corresponding error code.
1257 **/
1258s32 e1000e_phy_force_speed_duplex_m88(struct e1000_hw *hw)
1259{
1260 struct e1000_phy_info *phy = &hw->phy;
1261 s32 ret_val;
1262 u16 phy_data;
1263 bool link;
1264
Bruce Allane921eb12012-11-28 09:28:37 +00001265 /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
Auke Kokbc7f75f2007-09-17 12:30:59 -07001266 * forced whenever speed and duplex are forced.
1267 */
1268 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1269 if (ret_val)
1270 return ret_val;
1271
1272 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1273 ret_val = e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1274 if (ret_val)
1275 return ret_val;
1276
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001277 e_dbg("M88E1000 PSCR: %X\n", phy_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001278
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001279 ret_val = e1e_rphy(hw, MII_BMCR, &phy_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001280 if (ret_val)
1281 return ret_val;
1282
1283 e1000e_phy_force_speed_duplex_setup(hw, &phy_data);
1284
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001285 ret_val = e1e_wphy(hw, MII_BMCR, phy_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001286 if (ret_val)
1287 return ret_val;
1288
Bruce Allan5aa49c82008-11-21 16:49:53 -08001289 /* Reset the phy to commit changes. */
Bruce Allan6b598e12013-01-23 06:50:05 +00001290 if (hw->phy.ops.commit) {
1291 ret_val = hw->phy.ops.commit(hw);
1292 if (ret_val)
1293 return ret_val;
1294 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001295
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001296 if (phy->autoneg_wait_to_complete) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001297 e_dbg("Waiting for forced speed/duplex link on M88 phy.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001298
1299 ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
Bruce Allan17e813e2013-02-20 04:06:01 +00001300 100000, &link);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001301 if (ret_val)
1302 return ret_val;
1303
1304 if (!link) {
Bruce Allan0be84012009-12-02 17:03:18 +00001305 if (hw->phy.type != e1000_phy_m88) {
1306 e_dbg("Link taking longer than expected.\n");
1307 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00001308 /* We didn't get link.
Bruce Allan0be84012009-12-02 17:03:18 +00001309 * Reset the DSP and cross our fingers.
1310 */
Bruce Allan482fed82011-01-06 14:29:49 +00001311 ret_val = e1e_wphy(hw, M88E1000_PHY_PAGE_SELECT,
1312 0x001d);
Bruce Allan0be84012009-12-02 17:03:18 +00001313 if (ret_val)
1314 return ret_val;
1315 ret_val = e1000e_phy_reset_dsp(hw);
1316 if (ret_val)
1317 return ret_val;
1318 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001319 }
1320
1321 /* Try once more */
1322 ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
Bruce Allan17e813e2013-02-20 04:06:01 +00001323 100000, &link);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001324 if (ret_val)
1325 return ret_val;
1326 }
1327
Bruce Allan0be84012009-12-02 17:03:18 +00001328 if (hw->phy.type != e1000_phy_m88)
1329 return 0;
1330
Auke Kokbc7f75f2007-09-17 12:30:59 -07001331 ret_val = e1e_rphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1332 if (ret_val)
1333 return ret_val;
1334
Bruce Allane921eb12012-11-28 09:28:37 +00001335 /* Resetting the phy means we need to re-force TX_CLK in the
Auke Kokbc7f75f2007-09-17 12:30:59 -07001336 * Extended PHY Specific Control Register to 25MHz clock from
1337 * the reset value of 2.5MHz.
1338 */
1339 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1340 ret_val = e1e_wphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1341 if (ret_val)
1342 return ret_val;
1343
Bruce Allane921eb12012-11-28 09:28:37 +00001344 /* In addition, we must re-enable CRS on Tx for both half and full
Auke Kokbc7f75f2007-09-17 12:30:59 -07001345 * duplex.
1346 */
1347 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1348 if (ret_val)
1349 return ret_val;
1350
1351 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1352 ret_val = e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1353
1354 return ret_val;
1355}
1356
1357/**
Bruce Allan0be84012009-12-02 17:03:18 +00001358 * e1000_phy_force_speed_duplex_ife - Force PHY speed & duplex
1359 * @hw: pointer to the HW structure
1360 *
1361 * Forces the speed and duplex settings of the PHY.
1362 * This is a function pointer entry point only called by
1363 * PHY setup routines.
1364 **/
1365s32 e1000_phy_force_speed_duplex_ife(struct e1000_hw *hw)
1366{
1367 struct e1000_phy_info *phy = &hw->phy;
1368 s32 ret_val;
1369 u16 data;
1370 bool link;
1371
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001372 ret_val = e1e_rphy(hw, MII_BMCR, &data);
Bruce Allan0be84012009-12-02 17:03:18 +00001373 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001374 return ret_val;
Bruce Allan0be84012009-12-02 17:03:18 +00001375
1376 e1000e_phy_force_speed_duplex_setup(hw, &data);
1377
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001378 ret_val = e1e_wphy(hw, MII_BMCR, data);
Bruce Allan0be84012009-12-02 17:03:18 +00001379 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001380 return ret_val;
Bruce Allan0be84012009-12-02 17:03:18 +00001381
1382 /* Disable MDI-X support for 10/100 */
1383 ret_val = e1e_rphy(hw, IFE_PHY_MDIX_CONTROL, &data);
1384 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001385 return ret_val;
Bruce Allan0be84012009-12-02 17:03:18 +00001386
1387 data &= ~IFE_PMC_AUTO_MDIX;
1388 data &= ~IFE_PMC_FORCE_MDIX;
1389
1390 ret_val = e1e_wphy(hw, IFE_PHY_MDIX_CONTROL, data);
1391 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001392 return ret_val;
Bruce Allan0be84012009-12-02 17:03:18 +00001393
1394 e_dbg("IFE PMC: %X\n", data);
1395
1396 udelay(1);
1397
1398 if (phy->autoneg_wait_to_complete) {
1399 e_dbg("Waiting for forced speed/duplex link on IFE phy.\n");
1400
Bruce Allan3d3a1672012-02-23 03:13:18 +00001401 ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
1402 100000, &link);
Bruce Allan0be84012009-12-02 17:03:18 +00001403 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001404 return ret_val;
Bruce Allan0be84012009-12-02 17:03:18 +00001405
1406 if (!link)
1407 e_dbg("Link taking longer than expected.\n");
1408
1409 /* Try once more */
Bruce Allan3d3a1672012-02-23 03:13:18 +00001410 ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
1411 100000, &link);
Bruce Allan0be84012009-12-02 17:03:18 +00001412 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001413 return ret_val;
Bruce Allan0be84012009-12-02 17:03:18 +00001414 }
1415
Bruce Allan5015e532012-02-08 02:55:56 +00001416 return 0;
Bruce Allan0be84012009-12-02 17:03:18 +00001417}
1418
1419/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001420 * e1000e_phy_force_speed_duplex_setup - Configure forced PHY speed/duplex
1421 * @hw: pointer to the HW structure
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001422 * @phy_ctrl: pointer to current value of MII_BMCR
Auke Kokbc7f75f2007-09-17 12:30:59 -07001423 *
1424 * Forces speed and duplex on the PHY by doing the following: disable flow
1425 * control, force speed/duplex on the MAC, disable auto speed detection,
1426 * disable auto-negotiation, configure duplex, configure speed, configure
1427 * the collision distance, write configuration to CTRL register. The
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001428 * caller must write to the MII_BMCR register for these settings to
Auke Kokbc7f75f2007-09-17 12:30:59 -07001429 * take affect.
1430 **/
1431void e1000e_phy_force_speed_duplex_setup(struct e1000_hw *hw, u16 *phy_ctrl)
1432{
1433 struct e1000_mac_info *mac = &hw->mac;
1434 u32 ctrl;
1435
1436 /* Turn off flow control when forcing speed/duplex */
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08001437 hw->fc.current_mode = e1000_fc_none;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001438
1439 /* Force speed/duplex on the mac */
1440 ctrl = er32(CTRL);
1441 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1442 ctrl &= ~E1000_CTRL_SPD_SEL;
1443
1444 /* Disable Auto Speed Detection */
1445 ctrl &= ~E1000_CTRL_ASDE;
1446
1447 /* Disable autoneg on the phy */
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001448 *phy_ctrl &= ~BMCR_ANENABLE;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001449
1450 /* Forcing Full or Half Duplex? */
1451 if (mac->forced_speed_duplex & E1000_ALL_HALF_DUPLEX) {
1452 ctrl &= ~E1000_CTRL_FD;
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001453 *phy_ctrl &= ~BMCR_FULLDPLX;
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001454 e_dbg("Half Duplex\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001455 } else {
1456 ctrl |= E1000_CTRL_FD;
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001457 *phy_ctrl |= BMCR_FULLDPLX;
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001458 e_dbg("Full Duplex\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001459 }
1460
1461 /* Forcing 10mb or 100mb? */
1462 if (mac->forced_speed_duplex & E1000_ALL_100_SPEED) {
1463 ctrl |= E1000_CTRL_SPD_100;
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001464 *phy_ctrl |= BMCR_SPEED100;
1465 *phy_ctrl &= ~BMCR_SPEED1000;
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001466 e_dbg("Forcing 100mb\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001467 } else {
1468 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001469 *phy_ctrl &= ~(BMCR_SPEED1000 | BMCR_SPEED100);
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001470 e_dbg("Forcing 10mb\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001471 }
1472
Bruce Allan57cde762012-02-22 09:02:58 +00001473 hw->mac.ops.config_collision_dist(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001474
1475 ew32(CTRL, ctrl);
1476}
1477
1478/**
1479 * e1000e_set_d3_lplu_state - Sets low power link up state for D3
1480 * @hw: pointer to the HW structure
1481 * @active: boolean used to enable/disable lplu
1482 *
1483 * Success returns 0, Failure returns 1
1484 *
1485 * The low power link up (lplu) state is set to the power management level D3
1486 * and SmartSpeed is disabled when active is true, else clear lplu for D3
1487 * and enable Smartspeed. LPLU and Smartspeed are mutually exclusive. LPLU
1488 * is used during Dx states where the power conservation is most important.
1489 * During driver activity, SmartSpeed should be enabled so performance is
1490 * maintained.
1491 **/
1492s32 e1000e_set_d3_lplu_state(struct e1000_hw *hw, bool active)
1493{
1494 struct e1000_phy_info *phy = &hw->phy;
1495 s32 ret_val;
1496 u16 data;
1497
1498 ret_val = e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &data);
1499 if (ret_val)
1500 return ret_val;
1501
1502 if (!active) {
1503 data &= ~IGP02E1000_PM_D3_LPLU;
David Graham2d9498f2008-04-23 11:09:14 -07001504 ret_val = e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001505 if (ret_val)
1506 return ret_val;
Bruce Allane921eb12012-11-28 09:28:37 +00001507 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
Auke Kokbc7f75f2007-09-17 12:30:59 -07001508 * during Dx states where the power conservation is most
1509 * important. During driver activity we should enable
Bruce Allanad680762008-03-28 09:15:03 -07001510 * SmartSpeed, so performance is maintained.
1511 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001512 if (phy->smart_speed == e1000_smart_speed_on) {
1513 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07001514 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001515 if (ret_val)
1516 return ret_val;
1517
1518 data |= IGP01E1000_PSCFR_SMART_SPEED;
1519 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07001520 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001521 if (ret_val)
1522 return ret_val;
1523 } else if (phy->smart_speed == e1000_smart_speed_off) {
1524 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07001525 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001526 if (ret_val)
1527 return ret_val;
1528
1529 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1530 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07001531 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001532 if (ret_val)
1533 return ret_val;
1534 }
1535 } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
1536 (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
1537 (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
1538 data |= IGP02E1000_PM_D3_LPLU;
1539 ret_val = e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, data);
1540 if (ret_val)
1541 return ret_val;
1542
1543 /* When LPLU is enabled, we should disable SmartSpeed */
1544 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
1545 if (ret_val)
1546 return ret_val;
1547
1548 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1549 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
1550 }
1551
1552 return ret_val;
1553}
1554
1555/**
Auke Kok489815c2008-02-21 15:11:07 -08001556 * e1000e_check_downshift - Checks whether a downshift in speed occurred
Auke Kokbc7f75f2007-09-17 12:30:59 -07001557 * @hw: pointer to the HW structure
1558 *
1559 * Success returns 0, Failure returns 1
1560 *
1561 * A downshift is detected by querying the PHY link health.
1562 **/
1563s32 e1000e_check_downshift(struct e1000_hw *hw)
1564{
1565 struct e1000_phy_info *phy = &hw->phy;
1566 s32 ret_val;
1567 u16 phy_data, offset, mask;
1568
1569 switch (phy->type) {
1570 case e1000_phy_m88:
1571 case e1000_phy_gg82563:
Bruce Allan07f025e2009-12-01 15:53:48 +00001572 case e1000_phy_bm:
Bruce Allana4f58f52009-06-02 11:29:18 +00001573 case e1000_phy_82578:
Auke Kokbc7f75f2007-09-17 12:30:59 -07001574 offset = M88E1000_PHY_SPEC_STATUS;
1575 mask = M88E1000_PSSR_DOWNSHIFT;
1576 break;
1577 case e1000_phy_igp_2:
1578 case e1000_phy_igp_3:
1579 offset = IGP01E1000_PHY_LINK_HEALTH;
1580 mask = IGP01E1000_PLHR_SS_DOWNGRADE;
1581 break;
1582 default:
1583 /* speed downshift not supported */
Bruce Allan564ea9b2009-11-20 23:26:44 +00001584 phy->speed_downgraded = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001585 return 0;
1586 }
1587
1588 ret_val = e1e_rphy(hw, offset, &phy_data);
1589
1590 if (!ret_val)
Bruce Allan04499ec2012-04-13 00:08:31 +00001591 phy->speed_downgraded = !!(phy_data & mask);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001592
1593 return ret_val;
1594}
1595
1596/**
1597 * e1000_check_polarity_m88 - Checks the polarity.
1598 * @hw: pointer to the HW structure
1599 *
1600 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1601 *
1602 * Polarity is determined based on the PHY specific status register.
1603 **/
Bruce Allan0be84012009-12-02 17:03:18 +00001604s32 e1000_check_polarity_m88(struct e1000_hw *hw)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001605{
1606 struct e1000_phy_info *phy = &hw->phy;
1607 s32 ret_val;
1608 u16 data;
1609
1610 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &data);
1611
1612 if (!ret_val)
Bruce Allanf0ff4392013-02-20 04:05:39 +00001613 phy->cable_polarity = ((data & M88E1000_PSSR_REV_POLARITY)
1614 ? e1000_rev_polarity_reversed
1615 : e1000_rev_polarity_normal);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001616
1617 return ret_val;
1618}
1619
1620/**
1621 * e1000_check_polarity_igp - Checks the polarity.
1622 * @hw: pointer to the HW structure
1623 *
1624 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1625 *
1626 * Polarity is determined based on the PHY port status register, and the
1627 * current speed (since there is no polarity at 100Mbps).
1628 **/
Bruce Allan0be84012009-12-02 17:03:18 +00001629s32 e1000_check_polarity_igp(struct e1000_hw *hw)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001630{
1631 struct e1000_phy_info *phy = &hw->phy;
1632 s32 ret_val;
1633 u16 data, offset, mask;
1634
Bruce Allane921eb12012-11-28 09:28:37 +00001635 /* Polarity is determined based on the speed of
Bruce Allanad680762008-03-28 09:15:03 -07001636 * our connection.
1637 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001638 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_STATUS, &data);
1639 if (ret_val)
1640 return ret_val;
1641
1642 if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
1643 IGP01E1000_PSSR_SPEED_1000MBPS) {
1644 offset = IGP01E1000_PHY_PCS_INIT_REG;
1645 mask = IGP01E1000_PHY_POLARITY_MASK;
1646 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00001647 /* This really only applies to 10Mbps since
Auke Kokbc7f75f2007-09-17 12:30:59 -07001648 * there is no polarity for 100Mbps (always 0).
1649 */
1650 offset = IGP01E1000_PHY_PORT_STATUS;
1651 mask = IGP01E1000_PSSR_POLARITY_REVERSED;
1652 }
1653
1654 ret_val = e1e_rphy(hw, offset, &data);
1655
1656 if (!ret_val)
Bruce Allanf0ff4392013-02-20 04:05:39 +00001657 phy->cable_polarity = ((data & mask)
1658 ? e1000_rev_polarity_reversed
1659 : e1000_rev_polarity_normal);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001660
1661 return ret_val;
1662}
1663
1664/**
Bruce Allan0be84012009-12-02 17:03:18 +00001665 * e1000_check_polarity_ife - Check cable polarity for IFE PHY
1666 * @hw: pointer to the HW structure
1667 *
1668 * Polarity is determined on the polarity reversal feature being enabled.
1669 **/
1670s32 e1000_check_polarity_ife(struct e1000_hw *hw)
1671{
1672 struct e1000_phy_info *phy = &hw->phy;
1673 s32 ret_val;
1674 u16 phy_data, offset, mask;
1675
Bruce Allane921eb12012-11-28 09:28:37 +00001676 /* Polarity is determined based on the reversal feature being enabled.
Bruce Allan0be84012009-12-02 17:03:18 +00001677 */
1678 if (phy->polarity_correction) {
1679 offset = IFE_PHY_EXTENDED_STATUS_CONTROL;
1680 mask = IFE_PESC_POLARITY_REVERSED;
1681 } else {
1682 offset = IFE_PHY_SPECIAL_CONTROL;
1683 mask = IFE_PSC_FORCE_POLARITY;
1684 }
1685
1686 ret_val = e1e_rphy(hw, offset, &phy_data);
1687
1688 if (!ret_val)
Bruce Allanf0ff4392013-02-20 04:05:39 +00001689 phy->cable_polarity = ((phy_data & mask)
1690 ? e1000_rev_polarity_reversed
1691 : e1000_rev_polarity_normal);
Bruce Allan0be84012009-12-02 17:03:18 +00001692
1693 return ret_val;
1694}
1695
1696/**
Bruce Allanad680762008-03-28 09:15:03 -07001697 * e1000_wait_autoneg - Wait for auto-neg completion
Auke Kokbc7f75f2007-09-17 12:30:59 -07001698 * @hw: pointer to the HW structure
1699 *
1700 * Waits for auto-negotiation to complete or for the auto-negotiation time
1701 * limit to expire, which ever happens first.
1702 **/
1703static s32 e1000_wait_autoneg(struct e1000_hw *hw)
1704{
1705 s32 ret_val = 0;
1706 u16 i, phy_status;
1707
1708 /* Break after autoneg completes or PHY_AUTO_NEG_LIMIT expires. */
1709 for (i = PHY_AUTO_NEG_LIMIT; i > 0; i--) {
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001710 ret_val = e1e_rphy(hw, MII_BMSR, &phy_status);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001711 if (ret_val)
1712 break;
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001713 ret_val = e1e_rphy(hw, MII_BMSR, &phy_status);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001714 if (ret_val)
1715 break;
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001716 if (phy_status & BMSR_ANEGCOMPLETE)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001717 break;
1718 msleep(100);
1719 }
1720
Bruce Allane921eb12012-11-28 09:28:37 +00001721 /* PHY_AUTO_NEG_TIME expiration doesn't guarantee auto-negotiation
Auke Kokbc7f75f2007-09-17 12:30:59 -07001722 * has completed.
1723 */
1724 return ret_val;
1725}
1726
1727/**
1728 * e1000e_phy_has_link_generic - Polls PHY for link
1729 * @hw: pointer to the HW structure
1730 * @iterations: number of times to poll for link
1731 * @usec_interval: delay between polling attempts
1732 * @success: pointer to whether polling was successful or not
1733 *
1734 * Polls the PHY status register for link, 'iterations' number of times.
1735 **/
1736s32 e1000e_phy_has_link_generic(struct e1000_hw *hw, u32 iterations,
Bruce Allan17e813e2013-02-20 04:06:01 +00001737 u32 usec_interval, bool *success)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001738{
1739 s32 ret_val = 0;
1740 u16 i, phy_status;
1741
1742 for (i = 0; i < iterations; i++) {
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001743 /* Some PHYs require the MII_BMSR register to be read
Auke Kokbc7f75f2007-09-17 12:30:59 -07001744 * twice due to the link bit being sticky. No harm doing
1745 * it across the board.
1746 */
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001747 ret_val = e1e_rphy(hw, MII_BMSR, &phy_status);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001748 if (ret_val)
Bruce Allane921eb12012-11-28 09:28:37 +00001749 /* If the first read fails, another entity may have
Bruce Allan906e8d92009-07-01 13:28:50 +00001750 * ownership of the resources, wait and try again to
1751 * see if they have relinquished the resources yet.
1752 */
1753 udelay(usec_interval);
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001754 ret_val = e1e_rphy(hw, MII_BMSR, &phy_status);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001755 if (ret_val)
1756 break;
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001757 if (phy_status & BMSR_LSTATUS)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001758 break;
1759 if (usec_interval >= 1000)
Bruce Allan362e20c2013-02-20 04:05:45 +00001760 mdelay(usec_interval / 1000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001761 else
1762 udelay(usec_interval);
1763 }
1764
1765 *success = (i < iterations);
1766
1767 return ret_val;
1768}
1769
1770/**
1771 * e1000e_get_cable_length_m88 - Determine cable length for m88 PHY
1772 * @hw: pointer to the HW structure
1773 *
1774 * Reads the PHY specific status register to retrieve the cable length
1775 * information. The cable length is determined by averaging the minimum and
1776 * maximum values to get the "average" cable length. The m88 PHY has four
1777 * possible cable length values, which are:
1778 * Register Value Cable Length
1779 * 0 < 50 meters
1780 * 1 50 - 80 meters
1781 * 2 80 - 110 meters
1782 * 3 110 - 140 meters
1783 * 4 > 140 meters
1784 **/
1785s32 e1000e_get_cable_length_m88(struct e1000_hw *hw)
1786{
1787 struct e1000_phy_info *phy = &hw->phy;
1788 s32 ret_val;
1789 u16 phy_data, index;
1790
1791 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
1792 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001793 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001794
Bruce Allanf0ff4392013-02-20 04:05:39 +00001795 index = ((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
1796 M88E1000_PSSR_CABLE_LENGTH_SHIFT);
Bruce Allan5015e532012-02-08 02:55:56 +00001797
1798 if (index >= M88E1000_CABLE_LENGTH_TABLE_SIZE - 1)
1799 return -E1000_ERR_PHY;
Bruce Allaneb656d42009-12-01 15:47:02 +00001800
Auke Kokbc7f75f2007-09-17 12:30:59 -07001801 phy->min_cable_length = e1000_m88_cable_length_table[index];
Bruce Allaneb656d42009-12-01 15:47:02 +00001802 phy->max_cable_length = e1000_m88_cable_length_table[index + 1];
Auke Kokbc7f75f2007-09-17 12:30:59 -07001803
1804 phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
1805
Bruce Allan5015e532012-02-08 02:55:56 +00001806 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001807}
1808
1809/**
1810 * e1000e_get_cable_length_igp_2 - Determine cable length for igp2 PHY
1811 * @hw: pointer to the HW structure
1812 *
1813 * The automatic gain control (agc) normalizes the amplitude of the
1814 * received signal, adjusting for the attenuation produced by the
Auke Kok489815c2008-02-21 15:11:07 -08001815 * cable. By reading the AGC registers, which represent the
Bruce Allan5ff5b662009-12-01 15:51:11 +00001816 * combination of coarse and fine gain value, the value can be put
Auke Kokbc7f75f2007-09-17 12:30:59 -07001817 * into a lookup table to obtain the approximate cable length
1818 * for each channel.
1819 **/
1820s32 e1000e_get_cable_length_igp_2(struct e1000_hw *hw)
1821{
1822 struct e1000_phy_info *phy = &hw->phy;
1823 s32 ret_val;
1824 u16 phy_data, i, agc_value = 0;
1825 u16 cur_agc_index, max_agc_index = 0;
1826 u16 min_agc_index = IGP02E1000_CABLE_LENGTH_TABLE_SIZE - 1;
Jeff Kirsher66744502010-12-01 19:59:50 +00001827 static const u16 agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] = {
Bruce Allanf0ff4392013-02-20 04:05:39 +00001828 IGP02E1000_PHY_AGC_A,
1829 IGP02E1000_PHY_AGC_B,
1830 IGP02E1000_PHY_AGC_C,
1831 IGP02E1000_PHY_AGC_D
Jeff Kirsher66744502010-12-01 19:59:50 +00001832 };
Auke Kokbc7f75f2007-09-17 12:30:59 -07001833
1834 /* Read the AGC registers for all channels */
1835 for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
1836 ret_val = e1e_rphy(hw, agc_reg_array[i], &phy_data);
1837 if (ret_val)
1838 return ret_val;
1839
Bruce Allane921eb12012-11-28 09:28:37 +00001840 /* Getting bits 15:9, which represent the combination of
Bruce Allan5ff5b662009-12-01 15:51:11 +00001841 * coarse and fine gain values. The result is a number
Auke Kokbc7f75f2007-09-17 12:30:59 -07001842 * that can be put into the lookup table to obtain the
Bruce Allanad680762008-03-28 09:15:03 -07001843 * approximate cable length.
1844 */
Bruce Allanf0ff4392013-02-20 04:05:39 +00001845 cur_agc_index = ((phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
1846 IGP02E1000_AGC_LENGTH_MASK);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001847
1848 /* Array index bound check. */
1849 if ((cur_agc_index >= IGP02E1000_CABLE_LENGTH_TABLE_SIZE) ||
1850 (cur_agc_index == 0))
1851 return -E1000_ERR_PHY;
1852
1853 /* Remove min & max AGC values from calculation. */
1854 if (e1000_igp_2_cable_length_table[min_agc_index] >
1855 e1000_igp_2_cable_length_table[cur_agc_index])
1856 min_agc_index = cur_agc_index;
1857 if (e1000_igp_2_cable_length_table[max_agc_index] <
1858 e1000_igp_2_cable_length_table[cur_agc_index])
1859 max_agc_index = cur_agc_index;
1860
1861 agc_value += e1000_igp_2_cable_length_table[cur_agc_index];
1862 }
1863
1864 agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] +
1865 e1000_igp_2_cable_length_table[max_agc_index]);
1866 agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
1867
1868 /* Calculate cable length with the error range of +/- 10 meters. */
Bruce Allanf0ff4392013-02-20 04:05:39 +00001869 phy->min_cable_length = (((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
1870 (agc_value - IGP02E1000_AGC_RANGE) : 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001871 phy->max_cable_length = agc_value + IGP02E1000_AGC_RANGE;
1872
1873 phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
1874
Bruce Allan82607252012-02-08 02:55:09 +00001875 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001876}
1877
1878/**
1879 * e1000e_get_phy_info_m88 - Retrieve PHY information
1880 * @hw: pointer to the HW structure
1881 *
1882 * Valid for only copper links. Read the PHY status register (sticky read)
1883 * to verify that link is up. Read the PHY special control register to
1884 * determine the polarity and 10base-T extended distance. Read the PHY
1885 * special status register to determine MDI/MDIx and current speed. If
1886 * speed is 1000, then determine cable length, local and remote receiver.
1887 **/
1888s32 e1000e_get_phy_info_m88(struct e1000_hw *hw)
1889{
1890 struct e1000_phy_info *phy = &hw->phy;
1891 s32 ret_val;
1892 u16 phy_data;
1893 bool link;
1894
Bruce Allan0be84012009-12-02 17:03:18 +00001895 if (phy->media_type != e1000_media_type_copper) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001896 e_dbg("Phy info is only valid for copper media\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001897 return -E1000_ERR_CONFIG;
1898 }
1899
1900 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
1901 if (ret_val)
1902 return ret_val;
1903
1904 if (!link) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001905 e_dbg("Phy info is only valid if link is up\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001906 return -E1000_ERR_CONFIG;
1907 }
1908
1909 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1910 if (ret_val)
1911 return ret_val;
1912
Bruce Allan04499ec2012-04-13 00:08:31 +00001913 phy->polarity_correction = !!(phy_data &
1914 M88E1000_PSCR_POLARITY_REVERSAL);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001915
1916 ret_val = e1000_check_polarity_m88(hw);
1917 if (ret_val)
1918 return ret_val;
1919
1920 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
1921 if (ret_val)
1922 return ret_val;
1923
Bruce Allan04499ec2012-04-13 00:08:31 +00001924 phy->is_mdix = !!(phy_data & M88E1000_PSSR_MDIX);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001925
1926 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
Bruce Allandde3a572013-01-05 08:06:24 +00001927 ret_val = hw->phy.ops.get_cable_length(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001928 if (ret_val)
1929 return ret_val;
1930
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001931 ret_val = e1e_rphy(hw, MII_STAT1000, &phy_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001932 if (ret_val)
1933 return ret_val;
1934
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001935 phy->local_rx = (phy_data & LPA_1000LOCALRXOK)
1936 ? e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001937
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001938 phy->remote_rx = (phy_data & LPA_1000REMRXOK)
1939 ? e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001940 } else {
1941 /* Set values to "undefined" */
1942 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
1943 phy->local_rx = e1000_1000t_rx_status_undefined;
1944 phy->remote_rx = e1000_1000t_rx_status_undefined;
1945 }
1946
1947 return ret_val;
1948}
1949
1950/**
1951 * e1000e_get_phy_info_igp - Retrieve igp PHY information
1952 * @hw: pointer to the HW structure
1953 *
1954 * Read PHY status to determine if link is up. If link is up, then
1955 * set/determine 10base-T extended distance and polarity correction. Read
1956 * PHY port status to determine MDI/MDIx and speed. Based on the speed,
1957 * determine on the cable length, local and remote receiver.
1958 **/
1959s32 e1000e_get_phy_info_igp(struct e1000_hw *hw)
1960{
1961 struct e1000_phy_info *phy = &hw->phy;
1962 s32 ret_val;
1963 u16 data;
1964 bool link;
1965
1966 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
1967 if (ret_val)
1968 return ret_val;
1969
1970 if (!link) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001971 e_dbg("Phy info is only valid if link is up\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001972 return -E1000_ERR_CONFIG;
1973 }
1974
Bruce Allan564ea9b2009-11-20 23:26:44 +00001975 phy->polarity_correction = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001976
1977 ret_val = e1000_check_polarity_igp(hw);
1978 if (ret_val)
1979 return ret_val;
1980
1981 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_STATUS, &data);
1982 if (ret_val)
1983 return ret_val;
1984
Bruce Allan04499ec2012-04-13 00:08:31 +00001985 phy->is_mdix = !!(data & IGP01E1000_PSSR_MDIX);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001986
1987 if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
1988 IGP01E1000_PSSR_SPEED_1000MBPS) {
Bruce Allandde3a572013-01-05 08:06:24 +00001989 ret_val = phy->ops.get_cable_length(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001990 if (ret_val)
1991 return ret_val;
1992
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001993 ret_val = e1e_rphy(hw, MII_STAT1000, &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001994 if (ret_val)
1995 return ret_val;
1996
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001997 phy->local_rx = (data & LPA_1000LOCALRXOK)
1998 ? e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001999
Bruce Allanc2ade1a2013-01-16 08:54:35 +00002000 phy->remote_rx = (data & LPA_1000REMRXOK)
2001 ? e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002002 } else {
2003 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
2004 phy->local_rx = e1000_1000t_rx_status_undefined;
2005 phy->remote_rx = e1000_1000t_rx_status_undefined;
2006 }
2007
2008 return ret_val;
2009}
2010
2011/**
Bruce Allan0be84012009-12-02 17:03:18 +00002012 * e1000_get_phy_info_ife - Retrieves various IFE PHY states
2013 * @hw: pointer to the HW structure
2014 *
2015 * Populates "phy" structure with various feature states.
2016 **/
2017s32 e1000_get_phy_info_ife(struct e1000_hw *hw)
2018{
2019 struct e1000_phy_info *phy = &hw->phy;
2020 s32 ret_val;
2021 u16 data;
2022 bool link;
2023
2024 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
2025 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002026 return ret_val;
Bruce Allan0be84012009-12-02 17:03:18 +00002027
2028 if (!link) {
2029 e_dbg("Phy info is only valid if link is up\n");
Bruce Allan5015e532012-02-08 02:55:56 +00002030 return -E1000_ERR_CONFIG;
Bruce Allan0be84012009-12-02 17:03:18 +00002031 }
2032
2033 ret_val = e1e_rphy(hw, IFE_PHY_SPECIAL_CONTROL, &data);
2034 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002035 return ret_val;
Bruce Allan04499ec2012-04-13 00:08:31 +00002036 phy->polarity_correction = !(data & IFE_PSC_AUTO_POLARITY_DISABLE);
Bruce Allan0be84012009-12-02 17:03:18 +00002037
2038 if (phy->polarity_correction) {
2039 ret_val = e1000_check_polarity_ife(hw);
2040 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002041 return ret_val;
Bruce Allan0be84012009-12-02 17:03:18 +00002042 } else {
2043 /* Polarity is forced */
Bruce Allanf0ff4392013-02-20 04:05:39 +00002044 phy->cable_polarity = ((data & IFE_PSC_FORCE_POLARITY)
2045 ? e1000_rev_polarity_reversed
2046 : e1000_rev_polarity_normal);
Bruce Allan0be84012009-12-02 17:03:18 +00002047 }
2048
2049 ret_val = e1e_rphy(hw, IFE_PHY_MDIX_CONTROL, &data);
2050 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002051 return ret_val;
Bruce Allan0be84012009-12-02 17:03:18 +00002052
Bruce Allan04499ec2012-04-13 00:08:31 +00002053 phy->is_mdix = !!(data & IFE_PMC_MDIX_STATUS);
Bruce Allan0be84012009-12-02 17:03:18 +00002054
2055 /* The following parameters are undefined for 10/100 operation. */
2056 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
2057 phy->local_rx = e1000_1000t_rx_status_undefined;
2058 phy->remote_rx = e1000_1000t_rx_status_undefined;
2059
Bruce Allan5015e532012-02-08 02:55:56 +00002060 return 0;
Bruce Allan0be84012009-12-02 17:03:18 +00002061}
2062
2063/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002064 * e1000e_phy_sw_reset - PHY software reset
2065 * @hw: pointer to the HW structure
2066 *
2067 * Does a software reset of the PHY by reading the PHY control register and
2068 * setting/write the control register reset bit to the PHY.
2069 **/
2070s32 e1000e_phy_sw_reset(struct e1000_hw *hw)
2071{
2072 s32 ret_val;
2073 u16 phy_ctrl;
2074
Bruce Allanc2ade1a2013-01-16 08:54:35 +00002075 ret_val = e1e_rphy(hw, MII_BMCR, &phy_ctrl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002076 if (ret_val)
2077 return ret_val;
2078
Bruce Allanc2ade1a2013-01-16 08:54:35 +00002079 phy_ctrl |= BMCR_RESET;
2080 ret_val = e1e_wphy(hw, MII_BMCR, phy_ctrl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002081 if (ret_val)
2082 return ret_val;
2083
2084 udelay(1);
2085
2086 return ret_val;
2087}
2088
2089/**
2090 * e1000e_phy_hw_reset_generic - PHY hardware reset
2091 * @hw: pointer to the HW structure
2092 *
2093 * Verify the reset block is not blocking us from resetting. Acquire
2094 * semaphore (if necessary) and read/set/write the device control reset
2095 * bit in the PHY. Wait the appropriate delay time for the device to
Auke Kok489815c2008-02-21 15:11:07 -08002096 * reset and release the semaphore (if necessary).
Auke Kokbc7f75f2007-09-17 12:30:59 -07002097 **/
2098s32 e1000e_phy_hw_reset_generic(struct e1000_hw *hw)
2099{
2100 struct e1000_phy_info *phy = &hw->phy;
2101 s32 ret_val;
2102 u32 ctrl;
2103
Bruce Allan470a5422012-05-26 06:08:48 +00002104 if (phy->ops.check_reset_block) {
2105 ret_val = phy->ops.check_reset_block(hw);
2106 if (ret_val)
2107 return 0;
2108 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002109
Bruce Allan94d81862009-11-20 23:25:26 +00002110 ret_val = phy->ops.acquire(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002111 if (ret_val)
2112 return ret_val;
2113
2114 ctrl = er32(CTRL);
2115 ew32(CTRL, ctrl | E1000_CTRL_PHY_RST);
2116 e1e_flush();
2117
2118 udelay(phy->reset_delay_us);
2119
2120 ew32(CTRL, ctrl);
2121 e1e_flush();
2122
2123 udelay(150);
2124
Bruce Allan94d81862009-11-20 23:25:26 +00002125 phy->ops.release(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002126
Bruce Allan84c1bef2013-01-05 08:06:19 +00002127 return phy->ops.get_cfg_done(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002128}
2129
2130/**
Bruce Allanfe908492013-01-05 08:06:14 +00002131 * e1000e_get_cfg_done_generic - Generic configuration done
Auke Kokbc7f75f2007-09-17 12:30:59 -07002132 * @hw: pointer to the HW structure
2133 *
2134 * Generic function to wait 10 milli-seconds for configuration to complete
2135 * and return success.
2136 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00002137s32 e1000e_get_cfg_done_generic(struct e1000_hw __always_unused *hw)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002138{
2139 mdelay(10);
Bruce Allan3d3a1672012-02-23 03:13:18 +00002140
Auke Kokbc7f75f2007-09-17 12:30:59 -07002141 return 0;
2142}
2143
Bruce Allanf4187b52008-08-26 18:36:50 -07002144/**
2145 * e1000e_phy_init_script_igp3 - Inits the IGP3 PHY
2146 * @hw: pointer to the HW structure
2147 *
2148 * Initializes a Intel Gigabit PHY3 when an EEPROM is not present.
2149 **/
2150s32 e1000e_phy_init_script_igp3(struct e1000_hw *hw)
2151{
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002152 e_dbg("Running IGP 3 PHY init script\n");
Bruce Allanf4187b52008-08-26 18:36:50 -07002153
2154 /* PHY init IGP 3 */
2155 /* Enable rise/fall, 10-mode work in class-A */
2156 e1e_wphy(hw, 0x2F5B, 0x9018);
2157 /* Remove all caps from Replica path filter */
2158 e1e_wphy(hw, 0x2F52, 0x0000);
2159 /* Bias trimming for ADC, AFE and Driver (Default) */
2160 e1e_wphy(hw, 0x2FB1, 0x8B24);
2161 /* Increase Hybrid poly bias */
2162 e1e_wphy(hw, 0x2FB2, 0xF8F0);
2163 /* Add 4% to Tx amplitude in Gig mode */
2164 e1e_wphy(hw, 0x2010, 0x10B0);
2165 /* Disable trimming (TTT) */
2166 e1e_wphy(hw, 0x2011, 0x0000);
2167 /* Poly DC correction to 94.6% + 2% for all channels */
2168 e1e_wphy(hw, 0x20DD, 0x249A);
2169 /* ABS DC correction to 95.9% */
2170 e1e_wphy(hw, 0x20DE, 0x00D3);
2171 /* BG temp curve trim */
2172 e1e_wphy(hw, 0x28B4, 0x04CE);
2173 /* Increasing ADC OPAMP stage 1 currents to max */
2174 e1e_wphy(hw, 0x2F70, 0x29E4);
2175 /* Force 1000 ( required for enabling PHY regs configuration) */
2176 e1e_wphy(hw, 0x0000, 0x0140);
2177 /* Set upd_freq to 6 */
2178 e1e_wphy(hw, 0x1F30, 0x1606);
2179 /* Disable NPDFE */
2180 e1e_wphy(hw, 0x1F31, 0xB814);
2181 /* Disable adaptive fixed FFE (Default) */
2182 e1e_wphy(hw, 0x1F35, 0x002A);
2183 /* Enable FFE hysteresis */
2184 e1e_wphy(hw, 0x1F3E, 0x0067);
2185 /* Fixed FFE for short cable lengths */
2186 e1e_wphy(hw, 0x1F54, 0x0065);
2187 /* Fixed FFE for medium cable lengths */
2188 e1e_wphy(hw, 0x1F55, 0x002A);
2189 /* Fixed FFE for long cable lengths */
2190 e1e_wphy(hw, 0x1F56, 0x002A);
2191 /* Enable Adaptive Clip Threshold */
2192 e1e_wphy(hw, 0x1F72, 0x3FB0);
2193 /* AHT reset limit to 1 */
2194 e1e_wphy(hw, 0x1F76, 0xC0FF);
2195 /* Set AHT master delay to 127 msec */
2196 e1e_wphy(hw, 0x1F77, 0x1DEC);
2197 /* Set scan bits for AHT */
2198 e1e_wphy(hw, 0x1F78, 0xF9EF);
2199 /* Set AHT Preset bits */
2200 e1e_wphy(hw, 0x1F79, 0x0210);
2201 /* Change integ_factor of channel A to 3 */
2202 e1e_wphy(hw, 0x1895, 0x0003);
2203 /* Change prop_factor of channels BCD to 8 */
2204 e1e_wphy(hw, 0x1796, 0x0008);
2205 /* Change cg_icount + enable integbp for channels BCD */
2206 e1e_wphy(hw, 0x1798, 0xD008);
Bruce Allane921eb12012-11-28 09:28:37 +00002207 /* Change cg_icount + enable integbp + change prop_factor_master
Bruce Allanf4187b52008-08-26 18:36:50 -07002208 * to 8 for channel A
2209 */
2210 e1e_wphy(hw, 0x1898, 0xD918);
2211 /* Disable AHT in Slave mode on channel A */
2212 e1e_wphy(hw, 0x187A, 0x0800);
Bruce Allane921eb12012-11-28 09:28:37 +00002213 /* Enable LPLU and disable AN to 1000 in non-D0a states,
Bruce Allanf4187b52008-08-26 18:36:50 -07002214 * Enable SPD+B2B
2215 */
2216 e1e_wphy(hw, 0x0019, 0x008D);
2217 /* Enable restart AN on an1000_dis change */
2218 e1e_wphy(hw, 0x001B, 0x2080);
2219 /* Enable wh_fifo read clock in 10/100 modes */
2220 e1e_wphy(hw, 0x0014, 0x0045);
2221 /* Restart AN, Speed selection is 1000 */
2222 e1e_wphy(hw, 0x0000, 0x1340);
2223
2224 return 0;
2225}
2226
Auke Kokbc7f75f2007-09-17 12:30:59 -07002227/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002228 * e1000e_get_phy_type_from_id - Get PHY type from id
2229 * @phy_id: phy_id read from the phy
2230 *
2231 * Returns the phy type from the id.
2232 **/
2233enum e1000_phy_type e1000e_get_phy_type_from_id(u32 phy_id)
2234{
2235 enum e1000_phy_type phy_type = e1000_phy_unknown;
2236
2237 switch (phy_id) {
2238 case M88E1000_I_PHY_ID:
2239 case M88E1000_E_PHY_ID:
2240 case M88E1111_I_PHY_ID:
2241 case M88E1011_I_PHY_ID:
2242 phy_type = e1000_phy_m88;
2243 break;
2244 case IGP01E1000_I_PHY_ID: /* IGP 1 & 2 share this */
2245 phy_type = e1000_phy_igp_2;
2246 break;
2247 case GG82563_E_PHY_ID:
2248 phy_type = e1000_phy_gg82563;
2249 break;
2250 case IGP03E1000_E_PHY_ID:
2251 phy_type = e1000_phy_igp_3;
2252 break;
2253 case IFE_E_PHY_ID:
2254 case IFE_PLUS_E_PHY_ID:
2255 case IFE_C_E_PHY_ID:
2256 phy_type = e1000_phy_ife;
2257 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002258 case BME1000_E_PHY_ID:
2259 case BME1000_E_PHY_ID_R2:
2260 phy_type = e1000_phy_bm;
2261 break;
Bruce Allana4f58f52009-06-02 11:29:18 +00002262 case I82578_E_PHY_ID:
2263 phy_type = e1000_phy_82578;
2264 break;
2265 case I82577_E_PHY_ID:
2266 phy_type = e1000_phy_82577;
2267 break;
Bruce Alland3738bb2010-06-16 13:27:28 +00002268 case I82579_E_PHY_ID:
2269 phy_type = e1000_phy_82579;
2270 break;
Bruce Allan2fbe4522012-04-19 03:21:47 +00002271 case I217_E_PHY_ID:
2272 phy_type = e1000_phy_i217;
2273 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002274 default:
2275 phy_type = e1000_phy_unknown;
2276 break;
2277 }
2278 return phy_type;
2279}
2280
2281/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002282 * e1000e_determine_phy_address - Determines PHY address.
2283 * @hw: pointer to the HW structure
2284 *
2285 * This uses a trial and error method to loop through possible PHY
2286 * addresses. It tests each by reading the PHY ID registers and
2287 * checking for a match.
2288 **/
2289s32 e1000e_determine_phy_address(struct e1000_hw *hw)
2290{
Bruce Allan5eb6f3c2009-12-02 17:02:43 +00002291 u32 phy_addr = 0;
2292 u32 i;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002293 enum e1000_phy_type phy_type = e1000_phy_unknown;
2294
Bruce Allan5eb6f3c2009-12-02 17:02:43 +00002295 hw->phy.id = phy_type;
2296
2297 for (phy_addr = 0; phy_addr < E1000_MAX_PHY_ADDR; phy_addr++) {
2298 hw->phy.addr = phy_addr;
2299 i = 0;
2300
2301 do {
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002302 e1000e_get_phy_id(hw);
2303 phy_type = e1000e_get_phy_type_from_id(hw->phy.id);
2304
Bruce Allane921eb12012-11-28 09:28:37 +00002305 /* If phy_type is valid, break - we found our
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002306 * PHY address
2307 */
Bruce Allan5015e532012-02-08 02:55:56 +00002308 if (phy_type != e1000_phy_unknown)
2309 return 0;
2310
Bruce Allan1bba4382011-03-19 00:27:20 +00002311 usleep_range(1000, 2000);
Bruce Allan5eb6f3c2009-12-02 17:02:43 +00002312 i++;
2313 } while (i < 10);
2314 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002315
Bruce Allan5015e532012-02-08 02:55:56 +00002316 return -E1000_ERR_PHY_TYPE;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002317}
2318
2319/**
2320 * e1000_get_phy_addr_for_bm_page - Retrieve PHY page address
2321 * @page: page to access
2322 *
2323 * Returns the phy address for the page requested.
2324 **/
2325static u32 e1000_get_phy_addr_for_bm_page(u32 page, u32 reg)
2326{
2327 u32 phy_addr = 2;
2328
2329 if ((page >= 768) || (page == 0 && reg == 25) || (reg == 31))
2330 phy_addr = 1;
2331
2332 return phy_addr;
2333}
2334
2335/**
2336 * e1000e_write_phy_reg_bm - Write BM PHY register
2337 * @hw: pointer to the HW structure
2338 * @offset: register offset to write to
2339 * @data: data to write at register offset
2340 *
2341 * Acquires semaphore, if necessary, then writes the data to PHY register
2342 * at the offset. Release any acquired semaphores before exiting.
2343 **/
2344s32 e1000e_write_phy_reg_bm(struct e1000_hw *hw, u32 offset, u16 data)
2345{
2346 s32 ret_val;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002347 u32 page = offset >> IGP_PAGE_SHIFT;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002348
Bruce Allan94d81862009-11-20 23:25:26 +00002349 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002350 if (ret_val)
2351 return ret_val;
2352
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002353 /* Page 800 works differently than the rest so it has its own func */
2354 if (page == BM_WUC_PAGE) {
2355 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, &data,
Bruce Allan2b6b1682011-05-13 07:20:09 +00002356 false, false);
Bruce Allan75ce1532012-02-08 02:54:48 +00002357 goto release;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002358 }
2359
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002360 hw->phy.addr = e1000_get_phy_addr_for_bm_page(page, offset);
2361
2362 if (offset > MAX_PHY_MULTI_PAGE_REG) {
Bruce Allan90da0662011-01-06 07:02:53 +00002363 u32 page_shift, page_select;
2364
Bruce Allane921eb12012-11-28 09:28:37 +00002365 /* Page select is register 31 for phy address 1 and 22 for
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002366 * phy address 2 and 3. Page select is shifted only for
2367 * phy address 1.
2368 */
2369 if (hw->phy.addr == 1) {
2370 page_shift = IGP_PAGE_SHIFT;
2371 page_select = IGP01E1000_PHY_PAGE_SELECT;
2372 } else {
2373 page_shift = 0;
2374 page_select = BM_PHY_PAGE_SELECT;
2375 }
2376
2377 /* Page is shifted left, PHY expects (page x 32) */
2378 ret_val = e1000e_write_phy_reg_mdic(hw, page_select,
Bruce Allanf0ff4392013-02-20 04:05:39 +00002379 (page << page_shift));
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002380 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00002381 goto release;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002382 }
2383
2384 ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
Bruce Allanf0ff4392013-02-20 04:05:39 +00002385 data);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002386
Bruce Allan75ce1532012-02-08 02:54:48 +00002387release:
Bruce Allan94d81862009-11-20 23:25:26 +00002388 hw->phy.ops.release(hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002389 return ret_val;
2390}
2391
2392/**
2393 * e1000e_read_phy_reg_bm - Read BM PHY register
2394 * @hw: pointer to the HW structure
2395 * @offset: register offset to be read
2396 * @data: pointer to the read data
2397 *
2398 * Acquires semaphore, if necessary, then reads the PHY register at offset
2399 * and storing the retrieved information in data. Release any acquired
2400 * semaphores before exiting.
2401 **/
2402s32 e1000e_read_phy_reg_bm(struct e1000_hw *hw, u32 offset, u16 *data)
2403{
2404 s32 ret_val;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002405 u32 page = offset >> IGP_PAGE_SHIFT;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002406
Bruce Allan94d81862009-11-20 23:25:26 +00002407 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002408 if (ret_val)
2409 return ret_val;
2410
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002411 /* Page 800 works differently than the rest so it has its own func */
2412 if (page == BM_WUC_PAGE) {
2413 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, data,
Bruce Allan2b6b1682011-05-13 07:20:09 +00002414 true, false);
Bruce Allan75ce1532012-02-08 02:54:48 +00002415 goto release;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002416 }
2417
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002418 hw->phy.addr = e1000_get_phy_addr_for_bm_page(page, offset);
2419
2420 if (offset > MAX_PHY_MULTI_PAGE_REG) {
Bruce Allan90da0662011-01-06 07:02:53 +00002421 u32 page_shift, page_select;
2422
Bruce Allane921eb12012-11-28 09:28:37 +00002423 /* Page select is register 31 for phy address 1 and 22 for
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002424 * phy address 2 and 3. Page select is shifted only for
2425 * phy address 1.
2426 */
2427 if (hw->phy.addr == 1) {
2428 page_shift = IGP_PAGE_SHIFT;
2429 page_select = IGP01E1000_PHY_PAGE_SELECT;
2430 } else {
2431 page_shift = 0;
2432 page_select = BM_PHY_PAGE_SELECT;
2433 }
2434
2435 /* Page is shifted left, PHY expects (page x 32) */
2436 ret_val = e1000e_write_phy_reg_mdic(hw, page_select,
Bruce Allanf0ff4392013-02-20 04:05:39 +00002437 (page << page_shift));
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002438 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00002439 goto release;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002440 }
2441
2442 ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
Bruce Allanf0ff4392013-02-20 04:05:39 +00002443 data);
Bruce Allan75ce1532012-02-08 02:54:48 +00002444release:
Bruce Allan94d81862009-11-20 23:25:26 +00002445 hw->phy.ops.release(hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002446 return ret_val;
2447}
2448
2449/**
Bruce Allan4662e822008-08-26 18:37:06 -07002450 * e1000e_read_phy_reg_bm2 - Read BM PHY register
2451 * @hw: pointer to the HW structure
2452 * @offset: register offset to be read
2453 * @data: pointer to the read data
2454 *
2455 * Acquires semaphore, if necessary, then reads the PHY register at offset
2456 * and storing the retrieved information in data. Release any acquired
2457 * semaphores before exiting.
2458 **/
2459s32 e1000e_read_phy_reg_bm2(struct e1000_hw *hw, u32 offset, u16 *data)
2460{
2461 s32 ret_val;
2462 u16 page = (u16)(offset >> IGP_PAGE_SHIFT);
2463
Bruce Allan94d81862009-11-20 23:25:26 +00002464 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002465 if (ret_val)
2466 return ret_val;
2467
Bruce Allan4662e822008-08-26 18:37:06 -07002468 /* Page 800 works differently than the rest so it has its own func */
2469 if (page == BM_WUC_PAGE) {
2470 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, data,
Bruce Allan2b6b1682011-05-13 07:20:09 +00002471 true, false);
Bruce Allan75ce1532012-02-08 02:54:48 +00002472 goto release;
Bruce Allan4662e822008-08-26 18:37:06 -07002473 }
2474
Bruce Allan4662e822008-08-26 18:37:06 -07002475 hw->phy.addr = 1;
2476
2477 if (offset > MAX_PHY_MULTI_PAGE_REG) {
Bruce Allan4662e822008-08-26 18:37:06 -07002478 /* Page is shifted left, PHY expects (page x 32) */
2479 ret_val = e1000e_write_phy_reg_mdic(hw, BM_PHY_PAGE_SELECT,
2480 page);
2481
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002482 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00002483 goto release;
Bruce Allan4662e822008-08-26 18:37:06 -07002484 }
2485
2486 ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
2487 data);
Bruce Allan75ce1532012-02-08 02:54:48 +00002488release:
Bruce Allan94d81862009-11-20 23:25:26 +00002489 hw->phy.ops.release(hw);
Bruce Allan4662e822008-08-26 18:37:06 -07002490 return ret_val;
2491}
2492
2493/**
2494 * e1000e_write_phy_reg_bm2 - Write BM PHY register
2495 * @hw: pointer to the HW structure
2496 * @offset: register offset to write to
2497 * @data: data to write at register offset
2498 *
2499 * Acquires semaphore, if necessary, then writes the data to PHY register
2500 * at the offset. Release any acquired semaphores before exiting.
2501 **/
2502s32 e1000e_write_phy_reg_bm2(struct e1000_hw *hw, u32 offset, u16 data)
2503{
2504 s32 ret_val;
2505 u16 page = (u16)(offset >> IGP_PAGE_SHIFT);
2506
Bruce Allan94d81862009-11-20 23:25:26 +00002507 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002508 if (ret_val)
2509 return ret_val;
2510
Bruce Allan4662e822008-08-26 18:37:06 -07002511 /* Page 800 works differently than the rest so it has its own func */
2512 if (page == BM_WUC_PAGE) {
2513 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, &data,
Bruce Allan2b6b1682011-05-13 07:20:09 +00002514 false, false);
Bruce Allan75ce1532012-02-08 02:54:48 +00002515 goto release;
Bruce Allan4662e822008-08-26 18:37:06 -07002516 }
2517
Bruce Allan4662e822008-08-26 18:37:06 -07002518 hw->phy.addr = 1;
2519
2520 if (offset > MAX_PHY_MULTI_PAGE_REG) {
2521 /* Page is shifted left, PHY expects (page x 32) */
2522 ret_val = e1000e_write_phy_reg_mdic(hw, BM_PHY_PAGE_SELECT,
2523 page);
2524
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002525 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00002526 goto release;
Bruce Allan4662e822008-08-26 18:37:06 -07002527 }
2528
2529 ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
2530 data);
2531
Bruce Allan75ce1532012-02-08 02:54:48 +00002532release:
Bruce Allan94d81862009-11-20 23:25:26 +00002533 hw->phy.ops.release(hw);
Bruce Allan4662e822008-08-26 18:37:06 -07002534 return ret_val;
2535}
2536
2537/**
Bruce Allan2b6b1682011-05-13 07:20:09 +00002538 * e1000_enable_phy_wakeup_reg_access_bm - enable access to BM wakeup registers
2539 * @hw: pointer to the HW structure
2540 * @phy_reg: pointer to store original contents of BM_WUC_ENABLE_REG
2541 *
2542 * Assumes semaphore already acquired and phy_reg points to a valid memory
2543 * address to store contents of the BM_WUC_ENABLE_REG register.
2544 **/
2545s32 e1000_enable_phy_wakeup_reg_access_bm(struct e1000_hw *hw, u16 *phy_reg)
2546{
2547 s32 ret_val;
2548 u16 temp;
2549
2550 /* All page select, port ctrl and wakeup registers use phy address 1 */
2551 hw->phy.addr = 1;
2552
2553 /* Select Port Control Registers page */
2554 ret_val = e1000_set_page_igp(hw, (BM_PORT_CTRL_PAGE << IGP_PAGE_SHIFT));
2555 if (ret_val) {
2556 e_dbg("Could not set Port Control page\n");
Bruce Allan5015e532012-02-08 02:55:56 +00002557 return ret_val;
Bruce Allan2b6b1682011-05-13 07:20:09 +00002558 }
2559
2560 ret_val = e1000e_read_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, phy_reg);
2561 if (ret_val) {
2562 e_dbg("Could not read PHY register %d.%d\n",
2563 BM_PORT_CTRL_PAGE, BM_WUC_ENABLE_REG);
Bruce Allan5015e532012-02-08 02:55:56 +00002564 return ret_val;
Bruce Allan2b6b1682011-05-13 07:20:09 +00002565 }
2566
Bruce Allane921eb12012-11-28 09:28:37 +00002567 /* Enable both PHY wakeup mode and Wakeup register page writes.
Bruce Allan2b6b1682011-05-13 07:20:09 +00002568 * Prevent a power state change by disabling ME and Host PHY wakeup.
2569 */
2570 temp = *phy_reg;
2571 temp |= BM_WUC_ENABLE_BIT;
2572 temp &= ~(BM_WUC_ME_WU_BIT | BM_WUC_HOST_WU_BIT);
2573
2574 ret_val = e1000e_write_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, temp);
2575 if (ret_val) {
2576 e_dbg("Could not write PHY register %d.%d\n",
2577 BM_PORT_CTRL_PAGE, BM_WUC_ENABLE_REG);
Bruce Allan5015e532012-02-08 02:55:56 +00002578 return ret_val;
Bruce Allan2b6b1682011-05-13 07:20:09 +00002579 }
2580
Bruce Allane921eb12012-11-28 09:28:37 +00002581 /* Select Host Wakeup Registers page - caller now able to write
Bruce Allan5015e532012-02-08 02:55:56 +00002582 * registers on the Wakeup registers page
2583 */
2584 return e1000_set_page_igp(hw, (BM_WUC_PAGE << IGP_PAGE_SHIFT));
Bruce Allan2b6b1682011-05-13 07:20:09 +00002585}
2586
2587/**
2588 * e1000_disable_phy_wakeup_reg_access_bm - disable access to BM wakeup regs
2589 * @hw: pointer to the HW structure
2590 * @phy_reg: pointer to original contents of BM_WUC_ENABLE_REG
2591 *
2592 * Restore BM_WUC_ENABLE_REG to its original value.
2593 *
2594 * Assumes semaphore already acquired and *phy_reg is the contents of the
2595 * BM_WUC_ENABLE_REG before register(s) on BM_WUC_PAGE were accessed by
2596 * caller.
2597 **/
2598s32 e1000_disable_phy_wakeup_reg_access_bm(struct e1000_hw *hw, u16 *phy_reg)
2599{
Bruce Allan70806a72013-01-05 05:08:37 +00002600 s32 ret_val;
Bruce Allan2b6b1682011-05-13 07:20:09 +00002601
2602 /* Select Port Control Registers page */
2603 ret_val = e1000_set_page_igp(hw, (BM_PORT_CTRL_PAGE << IGP_PAGE_SHIFT));
2604 if (ret_val) {
2605 e_dbg("Could not set Port Control page\n");
Bruce Allan5015e532012-02-08 02:55:56 +00002606 return ret_val;
Bruce Allan2b6b1682011-05-13 07:20:09 +00002607 }
2608
2609 /* Restore 769.17 to its original value */
2610 ret_val = e1000e_write_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, *phy_reg);
2611 if (ret_val)
2612 e_dbg("Could not restore PHY register %d.%d\n",
2613 BM_PORT_CTRL_PAGE, BM_WUC_ENABLE_REG);
Bruce Allan5015e532012-02-08 02:55:56 +00002614
Bruce Allan2b6b1682011-05-13 07:20:09 +00002615 return ret_val;
2616}
2617
2618/**
2619 * e1000_access_phy_wakeup_reg_bm - Read/write BM PHY wakeup register
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002620 * @hw: pointer to the HW structure
2621 * @offset: register offset to be read or written
2622 * @data: pointer to the data to read or write
2623 * @read: determines if operation is read or write
Bruce Allan2b6b1682011-05-13 07:20:09 +00002624 * @page_set: BM_WUC_PAGE already set and access enabled
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002625 *
Bruce Allan2b6b1682011-05-13 07:20:09 +00002626 * Read the PHY register at offset and store the retrieved information in
2627 * data, or write data to PHY register at offset. Note the procedure to
2628 * access the PHY wakeup registers is different than reading the other PHY
2629 * registers. It works as such:
2630 * 1) Set 769.17.2 (page 769, register 17, bit 2) = 1
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002631 * 2) Set page to 800 for host (801 if we were manageability)
2632 * 3) Write the address using the address opcode (0x11)
2633 * 4) Read or write the data using the data opcode (0x12)
Bruce Allan2b6b1682011-05-13 07:20:09 +00002634 * 5) Restore 769.17.2 to its original value
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002635 *
Bruce Allan2b6b1682011-05-13 07:20:09 +00002636 * Steps 1 and 2 are done by e1000_enable_phy_wakeup_reg_access_bm() and
2637 * step 5 is done by e1000_disable_phy_wakeup_reg_access_bm().
2638 *
2639 * Assumes semaphore is already acquired. When page_set==true, assumes
2640 * the PHY page is set to BM_WUC_PAGE (i.e. a function in the call stack
2641 * is responsible for calls to e1000_[enable|disable]_phy_wakeup_reg_bm()).
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002642 **/
2643static s32 e1000_access_phy_wakeup_reg_bm(struct e1000_hw *hw, u32 offset,
Bruce Allan2b6b1682011-05-13 07:20:09 +00002644 u16 *data, bool read, bool page_set)
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002645{
2646 s32 ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00002647 u16 reg = BM_PHY_REG_NUM(offset);
Bruce Allan2b6b1682011-05-13 07:20:09 +00002648 u16 page = BM_PHY_REG_PAGE(offset);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002649 u16 phy_reg = 0;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002650
Bruce Allan2b6b1682011-05-13 07:20:09 +00002651 /* Gig must be disabled for MDIO accesses to Host Wakeup reg page */
Bruce Allana4f58f52009-06-02 11:29:18 +00002652 if ((hw->mac.type == e1000_pchlan) &&
Bruce Allan2b6b1682011-05-13 07:20:09 +00002653 (!(er32(PHY_CTRL) & E1000_PHY_CTRL_GBE_DISABLE)))
2654 e_dbg("Attempting to access page %d while gig enabled.\n",
2655 page);
Bruce Allana4f58f52009-06-02 11:29:18 +00002656
Bruce Allan2b6b1682011-05-13 07:20:09 +00002657 if (!page_set) {
2658 /* Enable access to PHY wakeup registers */
2659 ret_val = e1000_enable_phy_wakeup_reg_access_bm(hw, &phy_reg);
2660 if (ret_val) {
2661 e_dbg("Could not enable PHY wakeup reg access\n");
Bruce Allan5015e532012-02-08 02:55:56 +00002662 return ret_val;
Bruce Allan2b6b1682011-05-13 07:20:09 +00002663 }
Bruce Allan9b71b412009-12-01 15:53:07 +00002664 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002665
Bruce Allan2b6b1682011-05-13 07:20:09 +00002666 e_dbg("Accessing PHY page %d reg 0x%x\n", page, reg);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002667
Bruce Allan2b6b1682011-05-13 07:20:09 +00002668 /* Write the Wakeup register page offset value using opcode 0x11 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002669 ret_val = e1000e_write_phy_reg_mdic(hw, BM_WUC_ADDRESS_OPCODE, reg);
Bruce Allan9b71b412009-12-01 15:53:07 +00002670 if (ret_val) {
Bruce Allan2b6b1682011-05-13 07:20:09 +00002671 e_dbg("Could not write address opcode to page %d\n", page);
Bruce Allan5015e532012-02-08 02:55:56 +00002672 return ret_val;
Bruce Allan9b71b412009-12-01 15:53:07 +00002673 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002674
2675 if (read) {
Bruce Allan2b6b1682011-05-13 07:20:09 +00002676 /* Read the Wakeup register page value using opcode 0x12 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002677 ret_val = e1000e_read_phy_reg_mdic(hw, BM_WUC_DATA_OPCODE,
Bruce Allanf0ff4392013-02-20 04:05:39 +00002678 data);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002679 } else {
Bruce Allan2b6b1682011-05-13 07:20:09 +00002680 /* Write the Wakeup register page value using opcode 0x12 */
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002681 ret_val = e1000e_write_phy_reg_mdic(hw, BM_WUC_DATA_OPCODE,
2682 *data);
2683 }
2684
Bruce Allan9b71b412009-12-01 15:53:07 +00002685 if (ret_val) {
Bruce Allan2b6b1682011-05-13 07:20:09 +00002686 e_dbg("Could not access PHY reg %d.%d\n", page, reg);
Bruce Allan5015e532012-02-08 02:55:56 +00002687 return ret_val;
Bruce Allan9b71b412009-12-01 15:53:07 +00002688 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002689
Bruce Allan2b6b1682011-05-13 07:20:09 +00002690 if (!page_set)
2691 ret_val = e1000_disable_phy_wakeup_reg_access_bm(hw, &phy_reg);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002692
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002693 return ret_val;
2694}
2695
2696/**
Bruce Allan17f208d2009-12-01 15:47:22 +00002697 * e1000_power_up_phy_copper - Restore copper link in case of PHY power down
2698 * @hw: pointer to the HW structure
2699 *
2700 * In the case of a PHY power down to save power, or to turn off link during a
2701 * driver unload, or wake on lan is not enabled, restore the link to previous
2702 * settings.
2703 **/
2704void e1000_power_up_phy_copper(struct e1000_hw *hw)
2705{
2706 u16 mii_reg = 0;
2707
2708 /* The PHY will retain its settings across a power down/up cycle */
Bruce Allanc2ade1a2013-01-16 08:54:35 +00002709 e1e_rphy(hw, MII_BMCR, &mii_reg);
2710 mii_reg &= ~BMCR_PDOWN;
2711 e1e_wphy(hw, MII_BMCR, mii_reg);
Bruce Allan17f208d2009-12-01 15:47:22 +00002712}
2713
2714/**
2715 * e1000_power_down_phy_copper - Restore copper link in case of PHY power down
2716 * @hw: pointer to the HW structure
2717 *
2718 * In the case of a PHY power down to save power, or to turn off link during a
2719 * driver unload, or wake on lan is not enabled, restore the link to previous
2720 * settings.
2721 **/
2722void e1000_power_down_phy_copper(struct e1000_hw *hw)
2723{
2724 u16 mii_reg = 0;
2725
2726 /* The PHY will retain its settings across a power down/up cycle */
Bruce Allanc2ade1a2013-01-16 08:54:35 +00002727 e1e_rphy(hw, MII_BMCR, &mii_reg);
2728 mii_reg |= BMCR_PDOWN;
2729 e1e_wphy(hw, MII_BMCR, mii_reg);
Bruce Allan1bba4382011-03-19 00:27:20 +00002730 usleep_range(1000, 2000);
Bruce Allan17f208d2009-12-01 15:47:22 +00002731}
2732
2733/**
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002734 * __e1000_read_phy_reg_hv - Read HV PHY register
Bruce Allana4f58f52009-06-02 11:29:18 +00002735 * @hw: pointer to the HW structure
2736 * @offset: register offset to be read
2737 * @data: pointer to the read data
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002738 * @locked: semaphore has already been acquired or not
Bruce Allana4f58f52009-06-02 11:29:18 +00002739 *
2740 * Acquires semaphore, if necessary, then reads the PHY register at offset
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002741 * and stores the retrieved information in data. Release any acquired
Bruce Allana4f58f52009-06-02 11:29:18 +00002742 * semaphore before exiting.
2743 **/
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002744static s32 __e1000_read_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 *data,
Bruce Allan2b6b1682011-05-13 07:20:09 +00002745 bool locked, bool page_set)
Bruce Allana4f58f52009-06-02 11:29:18 +00002746{
2747 s32 ret_val;
2748 u16 page = BM_PHY_REG_PAGE(offset);
2749 u16 reg = BM_PHY_REG_NUM(offset);
Bruce Allan2b6b1682011-05-13 07:20:09 +00002750 u32 phy_addr = hw->phy.addr = e1000_get_phy_addr_for_hv_page(page);
Bruce Allana4f58f52009-06-02 11:29:18 +00002751
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002752 if (!locked) {
Bruce Allan94d81862009-11-20 23:25:26 +00002753 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002754 if (ret_val)
2755 return ret_val;
2756 }
2757
Bruce Allana4f58f52009-06-02 11:29:18 +00002758 /* Page 800 works differently than the rest so it has its own func */
2759 if (page == BM_WUC_PAGE) {
Bruce Allan2b6b1682011-05-13 07:20:09 +00002760 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, data,
2761 true, page_set);
Bruce Allana4f58f52009-06-02 11:29:18 +00002762 goto out;
2763 }
2764
2765 if (page > 0 && page < HV_INTC_FC_PAGE_START) {
2766 ret_val = e1000_access_phy_debug_regs_hv(hw, offset,
Bruce Allanf0ff4392013-02-20 04:05:39 +00002767 data, true);
Bruce Allana4f58f52009-06-02 11:29:18 +00002768 goto out;
2769 }
2770
Bruce Allan2b6b1682011-05-13 07:20:09 +00002771 if (!page_set) {
2772 if (page == HV_INTC_FC_PAGE_START)
2773 page = 0;
Bruce Allana4f58f52009-06-02 11:29:18 +00002774
Bruce Allan2b6b1682011-05-13 07:20:09 +00002775 if (reg > MAX_PHY_MULTI_PAGE_REG) {
2776 /* Page is shifted left, PHY expects (page x 32) */
2777 ret_val = e1000_set_page_igp(hw,
2778 (page << IGP_PAGE_SHIFT));
Bruce Allana4f58f52009-06-02 11:29:18 +00002779
Bruce Allan2b6b1682011-05-13 07:20:09 +00002780 hw->phy.addr = phy_addr;
Bruce Allana4f58f52009-06-02 11:29:18 +00002781
Bruce Allan2b6b1682011-05-13 07:20:09 +00002782 if (ret_val)
2783 goto out;
2784 }
Bruce Allana4f58f52009-06-02 11:29:18 +00002785 }
2786
Bruce Allan2b6b1682011-05-13 07:20:09 +00002787 e_dbg("reading PHY page %d (or 0x%x shifted) reg 0x%x\n", page,
2788 page << IGP_PAGE_SHIFT, reg);
2789
Bruce Allanf0ff4392013-02-20 04:05:39 +00002790 ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & reg, data);
Bruce Allana4f58f52009-06-02 11:29:18 +00002791out:
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002792 if (!locked)
Bruce Allan94d81862009-11-20 23:25:26 +00002793 hw->phy.ops.release(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002794
Bruce Allana4f58f52009-06-02 11:29:18 +00002795 return ret_val;
2796}
2797
2798/**
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002799 * e1000_read_phy_reg_hv - Read HV PHY register
2800 * @hw: pointer to the HW structure
2801 * @offset: register offset to be read
2802 * @data: pointer to the read data
2803 *
2804 * Acquires semaphore then reads the PHY register at offset and stores
2805 * the retrieved information in data. Release the acquired semaphore
2806 * before exiting.
2807 **/
2808s32 e1000_read_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 *data)
2809{
Bruce Allan2b6b1682011-05-13 07:20:09 +00002810 return __e1000_read_phy_reg_hv(hw, offset, data, false, false);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002811}
2812
2813/**
2814 * e1000_read_phy_reg_hv_locked - Read HV PHY register
2815 * @hw: pointer to the HW structure
2816 * @offset: register offset to be read
2817 * @data: pointer to the read data
2818 *
2819 * Reads the PHY register at offset and stores the retrieved information
2820 * in data. Assumes semaphore already acquired.
2821 **/
2822s32 e1000_read_phy_reg_hv_locked(struct e1000_hw *hw, u32 offset, u16 *data)
2823{
Bruce Allan2b6b1682011-05-13 07:20:09 +00002824 return __e1000_read_phy_reg_hv(hw, offset, data, true, false);
2825}
2826
2827/**
2828 * e1000_read_phy_reg_page_hv - Read HV PHY register
2829 * @hw: pointer to the HW structure
2830 * @offset: register offset to write to
2831 * @data: data to write at register offset
2832 *
2833 * Reads the PHY register at offset and stores the retrieved information
2834 * in data. Assumes semaphore already acquired and page already set.
2835 **/
2836s32 e1000_read_phy_reg_page_hv(struct e1000_hw *hw, u32 offset, u16 *data)
2837{
2838 return __e1000_read_phy_reg_hv(hw, offset, data, true, true);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002839}
2840
2841/**
2842 * __e1000_write_phy_reg_hv - Write HV PHY register
Bruce Allana4f58f52009-06-02 11:29:18 +00002843 * @hw: pointer to the HW structure
2844 * @offset: register offset to write to
2845 * @data: data to write at register offset
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002846 * @locked: semaphore has already been acquired or not
Bruce Allana4f58f52009-06-02 11:29:18 +00002847 *
2848 * Acquires semaphore, if necessary, then writes the data to PHY register
2849 * at the offset. Release any acquired semaphores before exiting.
2850 **/
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002851static s32 __e1000_write_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 data,
Bruce Allan2b6b1682011-05-13 07:20:09 +00002852 bool locked, bool page_set)
Bruce Allana4f58f52009-06-02 11:29:18 +00002853{
2854 s32 ret_val;
2855 u16 page = BM_PHY_REG_PAGE(offset);
2856 u16 reg = BM_PHY_REG_NUM(offset);
Bruce Allan2b6b1682011-05-13 07:20:09 +00002857 u32 phy_addr = hw->phy.addr = e1000_get_phy_addr_for_hv_page(page);
Bruce Allana4f58f52009-06-02 11:29:18 +00002858
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002859 if (!locked) {
Bruce Allan94d81862009-11-20 23:25:26 +00002860 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002861 if (ret_val)
2862 return ret_val;
2863 }
2864
Bruce Allana4f58f52009-06-02 11:29:18 +00002865 /* Page 800 works differently than the rest so it has its own func */
2866 if (page == BM_WUC_PAGE) {
Bruce Allan2b6b1682011-05-13 07:20:09 +00002867 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, &data,
2868 false, page_set);
Bruce Allana4f58f52009-06-02 11:29:18 +00002869 goto out;
2870 }
2871
2872 if (page > 0 && page < HV_INTC_FC_PAGE_START) {
2873 ret_val = e1000_access_phy_debug_regs_hv(hw, offset,
Bruce Allanf0ff4392013-02-20 04:05:39 +00002874 &data, false);
Bruce Allana4f58f52009-06-02 11:29:18 +00002875 goto out;
2876 }
2877
Bruce Allan2b6b1682011-05-13 07:20:09 +00002878 if (!page_set) {
2879 if (page == HV_INTC_FC_PAGE_START)
2880 page = 0;
Bruce Allana4f58f52009-06-02 11:29:18 +00002881
Bruce Allane921eb12012-11-28 09:28:37 +00002882 /* Workaround MDIO accesses being disabled after entering IEEE
Bruce Allan2b6b1682011-05-13 07:20:09 +00002883 * Power Down (when bit 11 of the PHY Control register is set)
2884 */
2885 if ((hw->phy.type == e1000_phy_82578) &&
2886 (hw->phy.revision >= 1) &&
2887 (hw->phy.addr == 2) &&
Bruce Allan04499ec2012-04-13 00:08:31 +00002888 !(MAX_PHY_REG_ADDRESS & reg) && (data & (1 << 11))) {
Bruce Allan2b6b1682011-05-13 07:20:09 +00002889 u16 data2 = 0x7EFF;
2890 ret_val = e1000_access_phy_debug_regs_hv(hw,
2891 (1 << 6) | 0x3,
2892 &data2, false);
2893 if (ret_val)
2894 goto out;
2895 }
Bruce Allana4f58f52009-06-02 11:29:18 +00002896
Bruce Allan2b6b1682011-05-13 07:20:09 +00002897 if (reg > MAX_PHY_MULTI_PAGE_REG) {
2898 /* Page is shifted left, PHY expects (page x 32) */
2899 ret_val = e1000_set_page_igp(hw,
2900 (page << IGP_PAGE_SHIFT));
2901
2902 hw->phy.addr = phy_addr;
2903
2904 if (ret_val)
2905 goto out;
2906 }
Bruce Allana4f58f52009-06-02 11:29:18 +00002907 }
2908
Bruce Allan2b6b1682011-05-13 07:20:09 +00002909 e_dbg("writing PHY page %d (or 0x%x shifted) reg 0x%x\n", page,
2910 page << IGP_PAGE_SHIFT, reg);
Bruce Allana4f58f52009-06-02 11:29:18 +00002911
2912 ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & reg,
Bruce Allanf0ff4392013-02-20 04:05:39 +00002913 data);
Bruce Allana4f58f52009-06-02 11:29:18 +00002914
2915out:
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002916 if (!locked)
Bruce Allan94d81862009-11-20 23:25:26 +00002917 hw->phy.ops.release(hw);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002918
Bruce Allana4f58f52009-06-02 11:29:18 +00002919 return ret_val;
2920}
2921
2922/**
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002923 * e1000_write_phy_reg_hv - Write HV PHY register
2924 * @hw: pointer to the HW structure
2925 * @offset: register offset to write to
2926 * @data: data to write at register offset
2927 *
2928 * Acquires semaphore then writes the data to PHY register at the offset.
2929 * Release the acquired semaphores before exiting.
2930 **/
2931s32 e1000_write_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 data)
2932{
Bruce Allan2b6b1682011-05-13 07:20:09 +00002933 return __e1000_write_phy_reg_hv(hw, offset, data, false, false);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002934}
2935
2936/**
2937 * e1000_write_phy_reg_hv_locked - Write HV PHY register
2938 * @hw: pointer to the HW structure
2939 * @offset: register offset to write to
2940 * @data: data to write at register offset
2941 *
2942 * Writes the data to PHY register at the offset. Assumes semaphore
2943 * already acquired.
2944 **/
2945s32 e1000_write_phy_reg_hv_locked(struct e1000_hw *hw, u32 offset, u16 data)
2946{
Bruce Allan2b6b1682011-05-13 07:20:09 +00002947 return __e1000_write_phy_reg_hv(hw, offset, data, true, false);
2948}
2949
2950/**
2951 * e1000_write_phy_reg_page_hv - Write HV PHY register
2952 * @hw: pointer to the HW structure
2953 * @offset: register offset to write to
2954 * @data: data to write at register offset
2955 *
2956 * Writes the data to PHY register at the offset. Assumes semaphore
2957 * already acquired and page already set.
2958 **/
2959s32 e1000_write_phy_reg_page_hv(struct e1000_hw *hw, u32 offset, u16 data)
2960{
2961 return __e1000_write_phy_reg_hv(hw, offset, data, true, true);
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002962}
2963
2964/**
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04002965 * e1000_get_phy_addr_for_hv_page - Get PHY address based on page
Bruce Allana4f58f52009-06-02 11:29:18 +00002966 * @page: page to be accessed
2967 **/
2968static u32 e1000_get_phy_addr_for_hv_page(u32 page)
2969{
2970 u32 phy_addr = 2;
2971
2972 if (page >= HV_INTC_FC_PAGE_START)
2973 phy_addr = 1;
2974
2975 return phy_addr;
2976}
2977
2978/**
2979 * e1000_access_phy_debug_regs_hv - Read HV PHY vendor specific high registers
2980 * @hw: pointer to the HW structure
2981 * @offset: register offset to be read or written
2982 * @data: pointer to the data to be read or written
Bruce Allan2b6b1682011-05-13 07:20:09 +00002983 * @read: determines if operation is read or write
Bruce Allana4f58f52009-06-02 11:29:18 +00002984 *
Bruce Allan5ccdcec2009-10-26 11:24:02 +00002985 * Reads the PHY register at offset and stores the retreived information
2986 * in data. Assumes semaphore already acquired. Note that the procedure
Bruce Allan2b6b1682011-05-13 07:20:09 +00002987 * to access these regs uses the address port and data port to read/write.
2988 * These accesses done with PHY address 2 and without using pages.
Bruce Allana4f58f52009-06-02 11:29:18 +00002989 **/
2990static s32 e1000_access_phy_debug_regs_hv(struct e1000_hw *hw, u32 offset,
Bruce Allan66501f52013-02-20 04:05:55 +00002991 u16 *data, bool read)
Bruce Allana4f58f52009-06-02 11:29:18 +00002992{
2993 s32 ret_val;
Bruce Allan70806a72013-01-05 05:08:37 +00002994 u32 addr_reg;
2995 u32 data_reg;
Bruce Allana4f58f52009-06-02 11:29:18 +00002996
2997 /* This takes care of the difference with desktop vs mobile phy */
Bruce Allanf0ff4392013-02-20 04:05:39 +00002998 addr_reg = ((hw->phy.type == e1000_phy_82578) ?
2999 I82578_ADDR_REG : I82577_ADDR_REG);
Bruce Allana4f58f52009-06-02 11:29:18 +00003000 data_reg = addr_reg + 1;
3001
Bruce Allana4f58f52009-06-02 11:29:18 +00003002 /* All operations in this function are phy address 2 */
3003 hw->phy.addr = 2;
3004
3005 /* masking with 0x3F to remove the page from offset */
3006 ret_val = e1000e_write_phy_reg_mdic(hw, addr_reg, (u16)offset & 0x3F);
3007 if (ret_val) {
Bruce Allan2b6b1682011-05-13 07:20:09 +00003008 e_dbg("Could not write the Address Offset port register\n");
Bruce Allan5015e532012-02-08 02:55:56 +00003009 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003010 }
3011
3012 /* Read or write the data value next */
3013 if (read)
3014 ret_val = e1000e_read_phy_reg_mdic(hw, data_reg, data);
3015 else
3016 ret_val = e1000e_write_phy_reg_mdic(hw, data_reg, *data);
3017
Bruce Allan5015e532012-02-08 02:55:56 +00003018 if (ret_val)
Bruce Allan2b6b1682011-05-13 07:20:09 +00003019 e_dbg("Could not access the Data port register\n");
Bruce Allana4f58f52009-06-02 11:29:18 +00003020
Bruce Allana4f58f52009-06-02 11:29:18 +00003021 return ret_val;
3022}
3023
3024/**
3025 * e1000_link_stall_workaround_hv - Si workaround
3026 * @hw: pointer to the HW structure
3027 *
3028 * This function works around a Si bug where the link partner can get
3029 * a link up indication before the PHY does. If small packets are sent
3030 * by the link partner they can be placed in the packet buffer without
3031 * being properly accounted for by the PHY and will stall preventing
3032 * further packets from being received. The workaround is to clear the
3033 * packet buffer after the PHY detects link up.
3034 **/
3035s32 e1000_link_stall_workaround_hv(struct e1000_hw *hw)
3036{
3037 s32 ret_val = 0;
3038 u16 data;
3039
3040 if (hw->phy.type != e1000_phy_82578)
Bruce Allan5015e532012-02-08 02:55:56 +00003041 return 0;
Bruce Allana4f58f52009-06-02 11:29:18 +00003042
Bruce Allane65fa872009-07-01 13:27:31 +00003043 /* Do not apply workaround if in PHY loopback bit 14 set */
Bruce Allanc2ade1a2013-01-16 08:54:35 +00003044 e1e_rphy(hw, MII_BMCR, &data);
3045 if (data & BMCR_LOOPBACK)
Bruce Allan5015e532012-02-08 02:55:56 +00003046 return 0;
Bruce Allane65fa872009-07-01 13:27:31 +00003047
Bruce Allana4f58f52009-06-02 11:29:18 +00003048 /* check if link is up and at 1Gbps */
Bruce Allan482fed82011-01-06 14:29:49 +00003049 ret_val = e1e_rphy(hw, BM_CS_STATUS, &data);
Bruce Allana4f58f52009-06-02 11:29:18 +00003050 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003051 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003052
Bruce Allanf0ff4392013-02-20 04:05:39 +00003053 data &= (BM_CS_STATUS_LINK_UP | BM_CS_STATUS_RESOLVED |
3054 BM_CS_STATUS_SPEED_MASK);
Bruce Allana4f58f52009-06-02 11:29:18 +00003055
Bruce Allan3d3a1672012-02-23 03:13:18 +00003056 if (data != (BM_CS_STATUS_LINK_UP | BM_CS_STATUS_RESOLVED |
3057 BM_CS_STATUS_SPEED_1000))
Bruce Allan5015e532012-02-08 02:55:56 +00003058 return 0;
Bruce Allana4f58f52009-06-02 11:29:18 +00003059
Bruce Allanbb9c5ee2012-02-23 03:31:29 +00003060 msleep(200);
Bruce Allana4f58f52009-06-02 11:29:18 +00003061
3062 /* flush the packets in the fifo buffer */
Bruce Allanc063f602013-01-12 07:27:53 +00003063 ret_val = e1e_wphy(hw, HV_MUX_DATA_CTRL,
3064 (HV_MUX_DATA_CTRL_GEN_TO_MAC |
3065 HV_MUX_DATA_CTRL_FORCE_SPEED));
Bruce Allana4f58f52009-06-02 11:29:18 +00003066 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003067 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003068
Bruce Allan5015e532012-02-08 02:55:56 +00003069 return e1e_wphy(hw, HV_MUX_DATA_CTRL, HV_MUX_DATA_CTRL_GEN_TO_MAC);
Bruce Allana4f58f52009-06-02 11:29:18 +00003070}
3071
3072/**
3073 * e1000_check_polarity_82577 - Checks the polarity.
3074 * @hw: pointer to the HW structure
3075 *
3076 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
3077 *
3078 * Polarity is determined based on the PHY specific status register.
3079 **/
3080s32 e1000_check_polarity_82577(struct e1000_hw *hw)
3081{
3082 struct e1000_phy_info *phy = &hw->phy;
3083 s32 ret_val;
3084 u16 data;
3085
Bruce Allan482fed82011-01-06 14:29:49 +00003086 ret_val = e1e_rphy(hw, I82577_PHY_STATUS_2, &data);
Bruce Allana4f58f52009-06-02 11:29:18 +00003087
3088 if (!ret_val)
Bruce Allanf0ff4392013-02-20 04:05:39 +00003089 phy->cable_polarity = ((data & I82577_PHY_STATUS2_REV_POLARITY)
3090 ? e1000_rev_polarity_reversed
3091 : e1000_rev_polarity_normal);
Bruce Allana4f58f52009-06-02 11:29:18 +00003092
3093 return ret_val;
3094}
3095
3096/**
3097 * e1000_phy_force_speed_duplex_82577 - Force speed/duplex for I82577 PHY
3098 * @hw: pointer to the HW structure
3099 *
Bruce Allaneab50ff2010-05-10 15:01:30 +00003100 * Calls the PHY setup function to force speed and duplex.
Bruce Allana4f58f52009-06-02 11:29:18 +00003101 **/
3102s32 e1000_phy_force_speed_duplex_82577(struct e1000_hw *hw)
3103{
3104 struct e1000_phy_info *phy = &hw->phy;
3105 s32 ret_val;
3106 u16 phy_data;
3107 bool link;
3108
Bruce Allanc2ade1a2013-01-16 08:54:35 +00003109 ret_val = e1e_rphy(hw, MII_BMCR, &phy_data);
Bruce Allana4f58f52009-06-02 11:29:18 +00003110 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003111 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003112
3113 e1000e_phy_force_speed_duplex_setup(hw, &phy_data);
3114
Bruce Allanc2ade1a2013-01-16 08:54:35 +00003115 ret_val = e1e_wphy(hw, MII_BMCR, phy_data);
Bruce Allana4f58f52009-06-02 11:29:18 +00003116 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003117 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003118
Bruce Allana4f58f52009-06-02 11:29:18 +00003119 udelay(1);
3120
3121 if (phy->autoneg_wait_to_complete) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003122 e_dbg("Waiting for forced speed/duplex link on 82577 phy\n");
Bruce Allana4f58f52009-06-02 11:29:18 +00003123
Bruce Allan3d3a1672012-02-23 03:13:18 +00003124 ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
3125 100000, &link);
Bruce Allana4f58f52009-06-02 11:29:18 +00003126 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003127 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003128
3129 if (!link)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003130 e_dbg("Link taking longer than expected.\n");
Bruce Allana4f58f52009-06-02 11:29:18 +00003131
3132 /* Try once more */
Bruce Allan3d3a1672012-02-23 03:13:18 +00003133 ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
3134 100000, &link);
Bruce Allana4f58f52009-06-02 11:29:18 +00003135 }
3136
Bruce Allana4f58f52009-06-02 11:29:18 +00003137 return ret_val;
3138}
3139
3140/**
3141 * e1000_get_phy_info_82577 - Retrieve I82577 PHY information
3142 * @hw: pointer to the HW structure
3143 *
3144 * Read PHY status to determine if link is up. If link is up, then
3145 * set/determine 10base-T extended distance and polarity correction. Read
3146 * PHY port status to determine MDI/MDIx and speed. Based on the speed,
3147 * determine on the cable length, local and remote receiver.
3148 **/
3149s32 e1000_get_phy_info_82577(struct e1000_hw *hw)
3150{
3151 struct e1000_phy_info *phy = &hw->phy;
3152 s32 ret_val;
3153 u16 data;
3154 bool link;
3155
3156 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
3157 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003158 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003159
3160 if (!link) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003161 e_dbg("Phy info is only valid if link is up\n");
Bruce Allan5015e532012-02-08 02:55:56 +00003162 return -E1000_ERR_CONFIG;
Bruce Allana4f58f52009-06-02 11:29:18 +00003163 }
3164
3165 phy->polarity_correction = true;
3166
3167 ret_val = e1000_check_polarity_82577(hw);
3168 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003169 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003170
Bruce Allan482fed82011-01-06 14:29:49 +00003171 ret_val = e1e_rphy(hw, I82577_PHY_STATUS_2, &data);
Bruce Allana4f58f52009-06-02 11:29:18 +00003172 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003173 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003174
Bruce Allan04499ec2012-04-13 00:08:31 +00003175 phy->is_mdix = !!(data & I82577_PHY_STATUS2_MDIX);
Bruce Allana4f58f52009-06-02 11:29:18 +00003176
3177 if ((data & I82577_PHY_STATUS2_SPEED_MASK) ==
3178 I82577_PHY_STATUS2_SPEED_1000MBPS) {
3179 ret_val = hw->phy.ops.get_cable_length(hw);
3180 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003181 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003182
Bruce Allanc2ade1a2013-01-16 08:54:35 +00003183 ret_val = e1e_rphy(hw, MII_STAT1000, &data);
Bruce Allana4f58f52009-06-02 11:29:18 +00003184 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003185 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003186
Bruce Allanc2ade1a2013-01-16 08:54:35 +00003187 phy->local_rx = (data & LPA_1000LOCALRXOK)
3188 ? e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
Bruce Allana4f58f52009-06-02 11:29:18 +00003189
Bruce Allanc2ade1a2013-01-16 08:54:35 +00003190 phy->remote_rx = (data & LPA_1000REMRXOK)
3191 ? e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
Bruce Allana4f58f52009-06-02 11:29:18 +00003192 } else {
3193 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
3194 phy->local_rx = e1000_1000t_rx_status_undefined;
3195 phy->remote_rx = e1000_1000t_rx_status_undefined;
3196 }
3197
Bruce Allan5015e532012-02-08 02:55:56 +00003198 return 0;
Bruce Allana4f58f52009-06-02 11:29:18 +00003199}
3200
3201/**
3202 * e1000_get_cable_length_82577 - Determine cable length for 82577 PHY
3203 * @hw: pointer to the HW structure
3204 *
3205 * Reads the diagnostic status register and verifies result is valid before
3206 * placing it in the phy_cable_length field.
3207 **/
3208s32 e1000_get_cable_length_82577(struct e1000_hw *hw)
3209{
3210 struct e1000_phy_info *phy = &hw->phy;
3211 s32 ret_val;
3212 u16 phy_data, length;
3213
Bruce Allan482fed82011-01-06 14:29:49 +00003214 ret_val = e1e_rphy(hw, I82577_PHY_DIAG_STATUS, &phy_data);
Bruce Allana4f58f52009-06-02 11:29:18 +00003215 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003216 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003217
Bruce Allanf0ff4392013-02-20 04:05:39 +00003218 length = ((phy_data & I82577_DSTATUS_CABLE_LENGTH) >>
3219 I82577_DSTATUS_CABLE_LENGTH_SHIFT);
Bruce Allana4f58f52009-06-02 11:29:18 +00003220
3221 if (length == E1000_CABLE_LENGTH_UNDEFINED)
Bruce Allan7dbbe5d2013-01-05 05:08:31 +00003222 return -E1000_ERR_PHY;
Bruce Allana4f58f52009-06-02 11:29:18 +00003223
3224 phy->cable_length = length;
3225
Bruce Allan5015e532012-02-08 02:55:56 +00003226 return 0;
Bruce Allana4f58f52009-06-02 11:29:18 +00003227}