1dee1ad47SJeff Kirsher /*******************************************************************************
2dee1ad47SJeff Kirsher 
3dee1ad47SJeff Kirsher   Intel PRO/1000 Linux driver
4f5e261e6SBruce Allan   Copyright(c) 1999 - 2012 Intel Corporation.
5dee1ad47SJeff Kirsher 
6dee1ad47SJeff Kirsher   This program is free software; you can redistribute it and/or modify it
7dee1ad47SJeff Kirsher   under the terms and conditions of the GNU General Public License,
8dee1ad47SJeff Kirsher   version 2, as published by the Free Software Foundation.
9dee1ad47SJeff Kirsher 
10dee1ad47SJeff Kirsher   This program is distributed in the hope it will be useful, but WITHOUT
11dee1ad47SJeff Kirsher   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12dee1ad47SJeff Kirsher   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13dee1ad47SJeff Kirsher   more details.
14dee1ad47SJeff Kirsher 
15dee1ad47SJeff Kirsher   You should have received a copy of the GNU General Public License along with
16dee1ad47SJeff Kirsher   this program; if not, write to the Free Software Foundation, Inc.,
17dee1ad47SJeff Kirsher   51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18dee1ad47SJeff Kirsher 
19dee1ad47SJeff Kirsher   The full GNU General Public License is included in this distribution in
20dee1ad47SJeff Kirsher   the file called "COPYING".
21dee1ad47SJeff Kirsher 
22dee1ad47SJeff Kirsher   Contact Information:
23dee1ad47SJeff Kirsher   Linux NICS <linux.nics@intel.com>
24dee1ad47SJeff Kirsher   e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25dee1ad47SJeff Kirsher   Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26dee1ad47SJeff Kirsher 
27dee1ad47SJeff Kirsher *******************************************************************************/
28dee1ad47SJeff Kirsher 
29dee1ad47SJeff Kirsher #include <linux/delay.h>
30dee1ad47SJeff Kirsher 
31dee1ad47SJeff Kirsher #include "e1000.h"
32dee1ad47SJeff Kirsher 
33dee1ad47SJeff Kirsher static s32 e1000_get_phy_cfg_done(struct e1000_hw *hw);
34dee1ad47SJeff Kirsher static s32 e1000_phy_force_speed_duplex(struct e1000_hw *hw);
35dee1ad47SJeff Kirsher static s32 e1000_set_d0_lplu_state(struct e1000_hw *hw, bool active);
36dee1ad47SJeff Kirsher static s32 e1000_wait_autoneg(struct e1000_hw *hw);
37dee1ad47SJeff Kirsher static u32 e1000_get_phy_addr_for_bm_page(u32 page, u32 reg);
38dee1ad47SJeff Kirsher static s32 e1000_access_phy_wakeup_reg_bm(struct e1000_hw *hw, u32 offset,
39dee1ad47SJeff Kirsher 					  u16 *data, bool read, bool page_set);
40dee1ad47SJeff Kirsher static u32 e1000_get_phy_addr_for_hv_page(u32 page);
41dee1ad47SJeff Kirsher static s32 e1000_access_phy_debug_regs_hv(struct e1000_hw *hw, u32 offset,
42dee1ad47SJeff Kirsher                                           u16 *data, bool read);
43dee1ad47SJeff Kirsher 
44dee1ad47SJeff Kirsher /* Cable length tables */
45dee1ad47SJeff Kirsher static const u16 e1000_m88_cable_length_table[] = {
46dee1ad47SJeff Kirsher 	0, 50, 80, 110, 140, 140, E1000_CABLE_LENGTH_UNDEFINED };
47dee1ad47SJeff Kirsher #define M88E1000_CABLE_LENGTH_TABLE_SIZE \
48dee1ad47SJeff Kirsher 		ARRAY_SIZE(e1000_m88_cable_length_table)
49dee1ad47SJeff Kirsher 
50dee1ad47SJeff Kirsher static const u16 e1000_igp_2_cable_length_table[] = {
51dee1ad47SJeff Kirsher 	0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21, 0, 0, 0, 3,
52dee1ad47SJeff Kirsher 	6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41, 6, 10, 14, 18, 22,
53dee1ad47SJeff Kirsher 	26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61, 21, 26, 31, 35, 40,
54dee1ad47SJeff Kirsher 	44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82, 40, 45, 51, 56, 61,
55dee1ad47SJeff Kirsher 	66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104, 60, 66, 72, 77, 82,
56dee1ad47SJeff Kirsher 	87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121, 83, 89, 95,
57dee1ad47SJeff Kirsher 	100, 105, 109, 113, 116, 119, 122, 124, 104, 109, 114, 118, 121,
58dee1ad47SJeff Kirsher 	124};
59dee1ad47SJeff Kirsher #define IGP02E1000_CABLE_LENGTH_TABLE_SIZE \
60dee1ad47SJeff Kirsher 		ARRAY_SIZE(e1000_igp_2_cable_length_table)
61dee1ad47SJeff Kirsher 
62dee1ad47SJeff Kirsher #define BM_PHY_REG_PAGE(offset) \
63dee1ad47SJeff Kirsher 	((u16)(((offset) >> PHY_PAGE_SHIFT) & 0xFFFF))
64dee1ad47SJeff Kirsher #define BM_PHY_REG_NUM(offset) \
65dee1ad47SJeff Kirsher 	((u16)(((offset) & MAX_PHY_REG_ADDRESS) |\
66dee1ad47SJeff Kirsher 	 (((offset) >> (PHY_UPPER_SHIFT - PHY_PAGE_SHIFT)) &\
67dee1ad47SJeff Kirsher 		~MAX_PHY_REG_ADDRESS)))
68dee1ad47SJeff Kirsher 
69dee1ad47SJeff Kirsher #define HV_INTC_FC_PAGE_START             768
70dee1ad47SJeff Kirsher #define I82578_ADDR_REG                   29
71dee1ad47SJeff Kirsher #define I82577_ADDR_REG                   16
72dee1ad47SJeff Kirsher #define I82577_CFG_REG                    22
73dee1ad47SJeff Kirsher #define I82577_CFG_ASSERT_CRS_ON_TX       (1 << 15)
74dee1ad47SJeff Kirsher #define I82577_CFG_ENABLE_DOWNSHIFT       (3 << 10) /* auto downshift 100/10 */
75dee1ad47SJeff Kirsher #define I82577_CTRL_REG                   23
76dee1ad47SJeff Kirsher 
77dee1ad47SJeff Kirsher /* 82577 specific PHY registers */
78dee1ad47SJeff Kirsher #define I82577_PHY_CTRL_2            18
79dee1ad47SJeff Kirsher #define I82577_PHY_STATUS_2          26
80dee1ad47SJeff Kirsher #define I82577_PHY_DIAG_STATUS       31
81dee1ad47SJeff Kirsher 
82dee1ad47SJeff Kirsher /* I82577 PHY Status 2 */
83dee1ad47SJeff Kirsher #define I82577_PHY_STATUS2_REV_POLARITY   0x0400
84dee1ad47SJeff Kirsher #define I82577_PHY_STATUS2_MDIX           0x0800
85dee1ad47SJeff Kirsher #define I82577_PHY_STATUS2_SPEED_MASK     0x0300
86dee1ad47SJeff Kirsher #define I82577_PHY_STATUS2_SPEED_1000MBPS 0x0200
87dee1ad47SJeff Kirsher 
88dee1ad47SJeff Kirsher /* I82577 PHY Control 2 */
89dee1ad47SJeff Kirsher #define I82577_PHY_CTRL2_AUTO_MDIX        0x0400
90dee1ad47SJeff Kirsher #define I82577_PHY_CTRL2_FORCE_MDI_MDIX   0x0200
91dee1ad47SJeff Kirsher 
92dee1ad47SJeff Kirsher /* I82577 PHY Diagnostics Status */
93dee1ad47SJeff Kirsher #define I82577_DSTATUS_CABLE_LENGTH       0x03FC
94dee1ad47SJeff Kirsher #define I82577_DSTATUS_CABLE_LENGTH_SHIFT 2
95dee1ad47SJeff Kirsher 
96dee1ad47SJeff Kirsher /* BM PHY Copper Specific Control 1 */
97dee1ad47SJeff Kirsher #define BM_CS_CTRL1                       16
98dee1ad47SJeff Kirsher 
99dee1ad47SJeff Kirsher #define HV_MUX_DATA_CTRL               PHY_REG(776, 16)
100dee1ad47SJeff Kirsher #define HV_MUX_DATA_CTRL_GEN_TO_MAC    0x0400
101dee1ad47SJeff Kirsher #define HV_MUX_DATA_CTRL_FORCE_SPEED   0x0004
102dee1ad47SJeff Kirsher 
103dee1ad47SJeff Kirsher /**
104dee1ad47SJeff Kirsher  *  e1000e_check_reset_block_generic - Check if PHY reset is blocked
105dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
106dee1ad47SJeff Kirsher  *
107dee1ad47SJeff Kirsher  *  Read the PHY management control register and check whether a PHY reset
108dee1ad47SJeff Kirsher  *  is blocked.  If a reset is not blocked return 0, otherwise
109dee1ad47SJeff Kirsher  *  return E1000_BLK_PHY_RESET (12).
110dee1ad47SJeff Kirsher  **/
111dee1ad47SJeff Kirsher s32 e1000e_check_reset_block_generic(struct e1000_hw *hw)
112dee1ad47SJeff Kirsher {
113dee1ad47SJeff Kirsher 	u32 manc;
114dee1ad47SJeff Kirsher 
115dee1ad47SJeff Kirsher 	manc = er32(MANC);
116dee1ad47SJeff Kirsher 
117dee1ad47SJeff Kirsher 	return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
118dee1ad47SJeff Kirsher 	       E1000_BLK_PHY_RESET : 0;
119dee1ad47SJeff Kirsher }
120dee1ad47SJeff Kirsher 
121dee1ad47SJeff Kirsher /**
122dee1ad47SJeff Kirsher  *  e1000e_get_phy_id - Retrieve the PHY ID and revision
123dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
124dee1ad47SJeff Kirsher  *
125dee1ad47SJeff Kirsher  *  Reads the PHY registers and stores the PHY ID and possibly the PHY
126dee1ad47SJeff Kirsher  *  revision in the hardware structure.
127dee1ad47SJeff Kirsher  **/
128dee1ad47SJeff Kirsher s32 e1000e_get_phy_id(struct e1000_hw *hw)
129dee1ad47SJeff Kirsher {
130dee1ad47SJeff Kirsher 	struct e1000_phy_info *phy = &hw->phy;
131dee1ad47SJeff Kirsher 	s32 ret_val = 0;
132dee1ad47SJeff Kirsher 	u16 phy_id;
133dee1ad47SJeff Kirsher 	u16 retry_count = 0;
134dee1ad47SJeff Kirsher 
135668018d7SBruce Allan 	if (!phy->ops.read_reg)
136dee1ad47SJeff Kirsher 		goto out;
137dee1ad47SJeff Kirsher 
138dee1ad47SJeff Kirsher 	while (retry_count < 2) {
139dee1ad47SJeff Kirsher 		ret_val = e1e_rphy(hw, PHY_ID1, &phy_id);
140dee1ad47SJeff Kirsher 		if (ret_val)
141dee1ad47SJeff Kirsher 			goto out;
142dee1ad47SJeff Kirsher 
143dee1ad47SJeff Kirsher 		phy->id = (u32)(phy_id << 16);
144dee1ad47SJeff Kirsher 		udelay(20);
145dee1ad47SJeff Kirsher 		ret_val = e1e_rphy(hw, PHY_ID2, &phy_id);
146dee1ad47SJeff Kirsher 		if (ret_val)
147dee1ad47SJeff Kirsher 			goto out;
148dee1ad47SJeff Kirsher 
149dee1ad47SJeff Kirsher 		phy->id |= (u32)(phy_id & PHY_REVISION_MASK);
150dee1ad47SJeff Kirsher 		phy->revision = (u32)(phy_id & ~PHY_REVISION_MASK);
151dee1ad47SJeff Kirsher 
152dee1ad47SJeff Kirsher 		if (phy->id != 0 && phy->id != PHY_REVISION_MASK)
153dee1ad47SJeff Kirsher 			goto out;
154dee1ad47SJeff Kirsher 
155dee1ad47SJeff Kirsher 		retry_count++;
156dee1ad47SJeff Kirsher 	}
157dee1ad47SJeff Kirsher out:
158dee1ad47SJeff Kirsher 	return ret_val;
159dee1ad47SJeff Kirsher }
160dee1ad47SJeff Kirsher 
161dee1ad47SJeff Kirsher /**
162dee1ad47SJeff Kirsher  *  e1000e_phy_reset_dsp - Reset PHY DSP
163dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
164dee1ad47SJeff Kirsher  *
165dee1ad47SJeff Kirsher  *  Reset the digital signal processor.
166dee1ad47SJeff Kirsher  **/
167dee1ad47SJeff Kirsher s32 e1000e_phy_reset_dsp(struct e1000_hw *hw)
168dee1ad47SJeff Kirsher {
169dee1ad47SJeff Kirsher 	s32 ret_val;
170dee1ad47SJeff Kirsher 
171dee1ad47SJeff Kirsher 	ret_val = e1e_wphy(hw, M88E1000_PHY_GEN_CONTROL, 0xC1);
172dee1ad47SJeff Kirsher 	if (ret_val)
173dee1ad47SJeff Kirsher 		return ret_val;
174dee1ad47SJeff Kirsher 
175dee1ad47SJeff Kirsher 	return e1e_wphy(hw, M88E1000_PHY_GEN_CONTROL, 0);
176dee1ad47SJeff Kirsher }
177dee1ad47SJeff Kirsher 
178dee1ad47SJeff Kirsher /**
179dee1ad47SJeff Kirsher  *  e1000e_read_phy_reg_mdic - Read MDI control register
180dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
181dee1ad47SJeff Kirsher  *  @offset: register offset to be read
182dee1ad47SJeff Kirsher  *  @data: pointer to the read data
183dee1ad47SJeff Kirsher  *
184dee1ad47SJeff Kirsher  *  Reads the MDI control register in the PHY at offset and stores the
185dee1ad47SJeff Kirsher  *  information read to data.
186dee1ad47SJeff Kirsher  **/
187dee1ad47SJeff Kirsher s32 e1000e_read_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 *data)
188dee1ad47SJeff Kirsher {
189dee1ad47SJeff Kirsher 	struct e1000_phy_info *phy = &hw->phy;
190dee1ad47SJeff Kirsher 	u32 i, mdic = 0;
191dee1ad47SJeff Kirsher 
192dee1ad47SJeff Kirsher 	if (offset > MAX_PHY_REG_ADDRESS) {
193dee1ad47SJeff Kirsher 		e_dbg("PHY Address %d is out of range\n", offset);
194dee1ad47SJeff Kirsher 		return -E1000_ERR_PARAM;
195dee1ad47SJeff Kirsher 	}
196dee1ad47SJeff Kirsher 
197dee1ad47SJeff Kirsher 	/*
198dee1ad47SJeff Kirsher 	 * Set up Op-code, Phy Address, and register offset in the MDI
199dee1ad47SJeff Kirsher 	 * Control register.  The MAC will take care of interfacing with the
200dee1ad47SJeff Kirsher 	 * PHY to retrieve the desired data.
201dee1ad47SJeff Kirsher 	 */
202dee1ad47SJeff Kirsher 	mdic = ((offset << E1000_MDIC_REG_SHIFT) |
203dee1ad47SJeff Kirsher 		(phy->addr << E1000_MDIC_PHY_SHIFT) |
204dee1ad47SJeff Kirsher 		(E1000_MDIC_OP_READ));
205dee1ad47SJeff Kirsher 
206dee1ad47SJeff Kirsher 	ew32(MDIC, mdic);
207dee1ad47SJeff Kirsher 
208dee1ad47SJeff Kirsher 	/*
209dee1ad47SJeff Kirsher 	 * Poll the ready bit to see if the MDI read completed
210dee1ad47SJeff Kirsher 	 * Increasing the time out as testing showed failures with
211dee1ad47SJeff Kirsher 	 * the lower time out
212dee1ad47SJeff Kirsher 	 */
213dee1ad47SJeff Kirsher 	for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
214dee1ad47SJeff Kirsher 		udelay(50);
215dee1ad47SJeff Kirsher 		mdic = er32(MDIC);
216dee1ad47SJeff Kirsher 		if (mdic & E1000_MDIC_READY)
217dee1ad47SJeff Kirsher 			break;
218dee1ad47SJeff Kirsher 	}
219dee1ad47SJeff Kirsher 	if (!(mdic & E1000_MDIC_READY)) {
220dee1ad47SJeff Kirsher 		e_dbg("MDI Read did not complete\n");
221dee1ad47SJeff Kirsher 		return -E1000_ERR_PHY;
222dee1ad47SJeff Kirsher 	}
223dee1ad47SJeff Kirsher 	if (mdic & E1000_MDIC_ERROR) {
224dee1ad47SJeff Kirsher 		e_dbg("MDI Error\n");
225dee1ad47SJeff Kirsher 		return -E1000_ERR_PHY;
226dee1ad47SJeff Kirsher 	}
227dee1ad47SJeff Kirsher 	*data = (u16) mdic;
228dee1ad47SJeff Kirsher 
229dee1ad47SJeff Kirsher 	/*
230dee1ad47SJeff Kirsher 	 * Allow some time after each MDIC transaction to avoid
231dee1ad47SJeff Kirsher 	 * reading duplicate data in the next MDIC transaction.
232dee1ad47SJeff Kirsher 	 */
233dee1ad47SJeff Kirsher 	if (hw->mac.type == e1000_pch2lan)
234dee1ad47SJeff Kirsher 		udelay(100);
235dee1ad47SJeff Kirsher 
236dee1ad47SJeff Kirsher 	return 0;
237dee1ad47SJeff Kirsher }
238dee1ad47SJeff Kirsher 
239dee1ad47SJeff Kirsher /**
240dee1ad47SJeff Kirsher  *  e1000e_write_phy_reg_mdic - Write MDI control register
241dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
242dee1ad47SJeff Kirsher  *  @offset: register offset to write to
243dee1ad47SJeff Kirsher  *  @data: data to write to register at offset
244dee1ad47SJeff Kirsher  *
245dee1ad47SJeff Kirsher  *  Writes data to MDI control register in the PHY at offset.
246dee1ad47SJeff Kirsher  **/
247dee1ad47SJeff Kirsher s32 e1000e_write_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 data)
248dee1ad47SJeff Kirsher {
249dee1ad47SJeff Kirsher 	struct e1000_phy_info *phy = &hw->phy;
250dee1ad47SJeff Kirsher 	u32 i, mdic = 0;
251dee1ad47SJeff Kirsher 
252dee1ad47SJeff Kirsher 	if (offset > MAX_PHY_REG_ADDRESS) {
253dee1ad47SJeff Kirsher 		e_dbg("PHY Address %d is out of range\n", offset);
254dee1ad47SJeff Kirsher 		return -E1000_ERR_PARAM;
255dee1ad47SJeff Kirsher 	}
256dee1ad47SJeff Kirsher 
257dee1ad47SJeff Kirsher 	/*
258dee1ad47SJeff Kirsher 	 * Set up Op-code, Phy Address, and register offset in the MDI
259dee1ad47SJeff Kirsher 	 * Control register.  The MAC will take care of interfacing with the
260dee1ad47SJeff Kirsher 	 * PHY to retrieve the desired data.
261dee1ad47SJeff Kirsher 	 */
262dee1ad47SJeff Kirsher 	mdic = (((u32)data) |
263dee1ad47SJeff Kirsher 		(offset << E1000_MDIC_REG_SHIFT) |
264dee1ad47SJeff Kirsher 		(phy->addr << E1000_MDIC_PHY_SHIFT) |
265dee1ad47SJeff Kirsher 		(E1000_MDIC_OP_WRITE));
266dee1ad47SJeff Kirsher 
267dee1ad47SJeff Kirsher 	ew32(MDIC, mdic);
268dee1ad47SJeff Kirsher 
269dee1ad47SJeff Kirsher 	/*
270dee1ad47SJeff Kirsher 	 * Poll the ready bit to see if the MDI read completed
271dee1ad47SJeff Kirsher 	 * Increasing the time out as testing showed failures with
272dee1ad47SJeff Kirsher 	 * the lower time out
273dee1ad47SJeff Kirsher 	 */
274dee1ad47SJeff Kirsher 	for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
275dee1ad47SJeff Kirsher 		udelay(50);
276dee1ad47SJeff Kirsher 		mdic = er32(MDIC);
277dee1ad47SJeff Kirsher 		if (mdic & E1000_MDIC_READY)
278dee1ad47SJeff Kirsher 			break;
279dee1ad47SJeff Kirsher 	}
280dee1ad47SJeff Kirsher 	if (!(mdic & E1000_MDIC_READY)) {
281dee1ad47SJeff Kirsher 		e_dbg("MDI Write did not complete\n");
282dee1ad47SJeff Kirsher 		return -E1000_ERR_PHY;
283dee1ad47SJeff Kirsher 	}
284dee1ad47SJeff Kirsher 	if (mdic & E1000_MDIC_ERROR) {
285dee1ad47SJeff Kirsher 		e_dbg("MDI Error\n");
286dee1ad47SJeff Kirsher 		return -E1000_ERR_PHY;
287dee1ad47SJeff Kirsher 	}
288dee1ad47SJeff Kirsher 
289dee1ad47SJeff Kirsher 	/*
290dee1ad47SJeff Kirsher 	 * Allow some time after each MDIC transaction to avoid
291dee1ad47SJeff Kirsher 	 * reading duplicate data in the next MDIC transaction.
292dee1ad47SJeff Kirsher 	 */
293dee1ad47SJeff Kirsher 	if (hw->mac.type == e1000_pch2lan)
294dee1ad47SJeff Kirsher 		udelay(100);
295dee1ad47SJeff Kirsher 
296dee1ad47SJeff Kirsher 	return 0;
297dee1ad47SJeff Kirsher }
298dee1ad47SJeff Kirsher 
299dee1ad47SJeff Kirsher /**
300dee1ad47SJeff Kirsher  *  e1000e_read_phy_reg_m88 - Read m88 PHY register
301dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
302dee1ad47SJeff Kirsher  *  @offset: register offset to be read
303dee1ad47SJeff Kirsher  *  @data: pointer to the read data
304dee1ad47SJeff Kirsher  *
305dee1ad47SJeff Kirsher  *  Acquires semaphore, if necessary, then reads the PHY register at offset
306dee1ad47SJeff Kirsher  *  and storing the retrieved information in data.  Release any acquired
307dee1ad47SJeff Kirsher  *  semaphores before exiting.
308dee1ad47SJeff Kirsher  **/
309dee1ad47SJeff Kirsher s32 e1000e_read_phy_reg_m88(struct e1000_hw *hw, u32 offset, u16 *data)
310dee1ad47SJeff Kirsher {
311dee1ad47SJeff Kirsher 	s32 ret_val;
312dee1ad47SJeff Kirsher 
313dee1ad47SJeff Kirsher 	ret_val = hw->phy.ops.acquire(hw);
314dee1ad47SJeff Kirsher 	if (ret_val)
315dee1ad47SJeff Kirsher 		return ret_val;
316dee1ad47SJeff Kirsher 
317dee1ad47SJeff Kirsher 	ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
318dee1ad47SJeff Kirsher 					   data);
319dee1ad47SJeff Kirsher 
320dee1ad47SJeff Kirsher 	hw->phy.ops.release(hw);
321dee1ad47SJeff Kirsher 
322dee1ad47SJeff Kirsher 	return ret_val;
323dee1ad47SJeff Kirsher }
324dee1ad47SJeff Kirsher 
325dee1ad47SJeff Kirsher /**
326dee1ad47SJeff Kirsher  *  e1000e_write_phy_reg_m88 - Write m88 PHY register
327dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
328dee1ad47SJeff Kirsher  *  @offset: register offset to write to
329dee1ad47SJeff Kirsher  *  @data: data to write at register offset
330dee1ad47SJeff Kirsher  *
331dee1ad47SJeff Kirsher  *  Acquires semaphore, if necessary, then writes the data to PHY register
332dee1ad47SJeff Kirsher  *  at the offset.  Release any acquired semaphores before exiting.
333dee1ad47SJeff Kirsher  **/
334dee1ad47SJeff Kirsher s32 e1000e_write_phy_reg_m88(struct e1000_hw *hw, u32 offset, u16 data)
335dee1ad47SJeff Kirsher {
336dee1ad47SJeff Kirsher 	s32 ret_val;
337dee1ad47SJeff Kirsher 
338dee1ad47SJeff Kirsher 	ret_val = hw->phy.ops.acquire(hw);
339dee1ad47SJeff Kirsher 	if (ret_val)
340dee1ad47SJeff Kirsher 		return ret_val;
341dee1ad47SJeff Kirsher 
342dee1ad47SJeff Kirsher 	ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
343dee1ad47SJeff Kirsher 					    data);
344dee1ad47SJeff Kirsher 
345dee1ad47SJeff Kirsher 	hw->phy.ops.release(hw);
346dee1ad47SJeff Kirsher 
347dee1ad47SJeff Kirsher 	return ret_val;
348dee1ad47SJeff Kirsher }
349dee1ad47SJeff Kirsher 
350dee1ad47SJeff Kirsher /**
351dee1ad47SJeff Kirsher  *  e1000_set_page_igp - Set page as on IGP-like PHY(s)
352dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
353dee1ad47SJeff Kirsher  *  @page: page to set (shifted left when necessary)
354dee1ad47SJeff Kirsher  *
355dee1ad47SJeff Kirsher  *  Sets PHY page required for PHY register access.  Assumes semaphore is
356dee1ad47SJeff Kirsher  *  already acquired.  Note, this function sets phy.addr to 1 so the caller
357dee1ad47SJeff Kirsher  *  must set it appropriately (if necessary) after this function returns.
358dee1ad47SJeff Kirsher  **/
359dee1ad47SJeff Kirsher s32 e1000_set_page_igp(struct e1000_hw *hw, u16 page)
360dee1ad47SJeff Kirsher {
361dee1ad47SJeff Kirsher 	e_dbg("Setting page 0x%x\n", page);
362dee1ad47SJeff Kirsher 
363dee1ad47SJeff Kirsher 	hw->phy.addr = 1;
364dee1ad47SJeff Kirsher 
365dee1ad47SJeff Kirsher 	return e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT, page);
366dee1ad47SJeff Kirsher }
367dee1ad47SJeff Kirsher 
368dee1ad47SJeff Kirsher /**
369dee1ad47SJeff Kirsher  *  __e1000e_read_phy_reg_igp - Read igp PHY register
370dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
371dee1ad47SJeff Kirsher  *  @offset: register offset to be read
372dee1ad47SJeff Kirsher  *  @data: pointer to the read data
373dee1ad47SJeff Kirsher  *  @locked: semaphore has already been acquired or not
374dee1ad47SJeff Kirsher  *
375dee1ad47SJeff Kirsher  *  Acquires semaphore, if necessary, then reads the PHY register at offset
376dee1ad47SJeff Kirsher  *  and stores the retrieved information in data.  Release any acquired
377dee1ad47SJeff Kirsher  *  semaphores before exiting.
378dee1ad47SJeff Kirsher  **/
379dee1ad47SJeff Kirsher static s32 __e1000e_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data,
380dee1ad47SJeff Kirsher                                     bool locked)
381dee1ad47SJeff Kirsher {
382dee1ad47SJeff Kirsher 	s32 ret_val = 0;
383dee1ad47SJeff Kirsher 
384dee1ad47SJeff Kirsher 	if (!locked) {
385668018d7SBruce Allan 		if (!hw->phy.ops.acquire)
386dee1ad47SJeff Kirsher 			goto out;
387dee1ad47SJeff Kirsher 
388dee1ad47SJeff Kirsher 		ret_val = hw->phy.ops.acquire(hw);
389dee1ad47SJeff Kirsher 		if (ret_val)
390dee1ad47SJeff Kirsher 			goto out;
391dee1ad47SJeff Kirsher 	}
392dee1ad47SJeff Kirsher 
393dee1ad47SJeff Kirsher 	if (offset > MAX_PHY_MULTI_PAGE_REG) {
394dee1ad47SJeff Kirsher 		ret_val = e1000e_write_phy_reg_mdic(hw,
395dee1ad47SJeff Kirsher 						    IGP01E1000_PHY_PAGE_SELECT,
396dee1ad47SJeff Kirsher 						    (u16)offset);
397dee1ad47SJeff Kirsher 		if (ret_val)
398dee1ad47SJeff Kirsher 			goto release;
399dee1ad47SJeff Kirsher 	}
400dee1ad47SJeff Kirsher 
401dee1ad47SJeff Kirsher 	ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
402dee1ad47SJeff Kirsher 	                                  data);
403dee1ad47SJeff Kirsher 
404dee1ad47SJeff Kirsher release:
405dee1ad47SJeff Kirsher 	if (!locked)
406dee1ad47SJeff Kirsher 		hw->phy.ops.release(hw);
407dee1ad47SJeff Kirsher out:
408dee1ad47SJeff Kirsher 	return ret_val;
409dee1ad47SJeff Kirsher }
410dee1ad47SJeff Kirsher 
411dee1ad47SJeff Kirsher /**
412dee1ad47SJeff Kirsher  *  e1000e_read_phy_reg_igp - Read igp PHY register
413dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
414dee1ad47SJeff Kirsher  *  @offset: register offset to be read
415dee1ad47SJeff Kirsher  *  @data: pointer to the read data
416dee1ad47SJeff Kirsher  *
417dee1ad47SJeff Kirsher  *  Acquires semaphore then reads the PHY register at offset and stores the
418dee1ad47SJeff Kirsher  *  retrieved information in data.
419dee1ad47SJeff Kirsher  *  Release the acquired semaphore before exiting.
420dee1ad47SJeff Kirsher  **/
421dee1ad47SJeff Kirsher s32 e1000e_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data)
422dee1ad47SJeff Kirsher {
423dee1ad47SJeff Kirsher 	return __e1000e_read_phy_reg_igp(hw, offset, data, false);
424dee1ad47SJeff Kirsher }
425dee1ad47SJeff Kirsher 
426dee1ad47SJeff Kirsher /**
427dee1ad47SJeff Kirsher  *  e1000e_read_phy_reg_igp_locked - Read igp PHY register
428dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
429dee1ad47SJeff Kirsher  *  @offset: register offset to be read
430dee1ad47SJeff Kirsher  *  @data: pointer to the read data
431dee1ad47SJeff Kirsher  *
432dee1ad47SJeff Kirsher  *  Reads the PHY register at offset and stores the retrieved information
433dee1ad47SJeff Kirsher  *  in data.  Assumes semaphore already acquired.
434dee1ad47SJeff Kirsher  **/
435dee1ad47SJeff Kirsher s32 e1000e_read_phy_reg_igp_locked(struct e1000_hw *hw, u32 offset, u16 *data)
436dee1ad47SJeff Kirsher {
437dee1ad47SJeff Kirsher 	return __e1000e_read_phy_reg_igp(hw, offset, data, true);
438dee1ad47SJeff Kirsher }
439dee1ad47SJeff Kirsher 
440dee1ad47SJeff Kirsher /**
441dee1ad47SJeff Kirsher  *  e1000e_write_phy_reg_igp - Write igp PHY register
442dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
443dee1ad47SJeff Kirsher  *  @offset: register offset to write to
444dee1ad47SJeff Kirsher  *  @data: data to write at register offset
445dee1ad47SJeff Kirsher  *  @locked: semaphore has already been acquired or not
446dee1ad47SJeff Kirsher  *
447dee1ad47SJeff Kirsher  *  Acquires semaphore, if necessary, then writes the data to PHY register
448dee1ad47SJeff Kirsher  *  at the offset.  Release any acquired semaphores before exiting.
449dee1ad47SJeff Kirsher  **/
450dee1ad47SJeff Kirsher static s32 __e1000e_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data,
451dee1ad47SJeff Kirsher                                      bool locked)
452dee1ad47SJeff Kirsher {
453dee1ad47SJeff Kirsher 	s32 ret_val = 0;
454dee1ad47SJeff Kirsher 
455dee1ad47SJeff Kirsher 	if (!locked) {
456668018d7SBruce Allan 		if (!hw->phy.ops.acquire)
457dee1ad47SJeff Kirsher 			goto out;
458dee1ad47SJeff Kirsher 
459dee1ad47SJeff Kirsher 		ret_val = hw->phy.ops.acquire(hw);
460dee1ad47SJeff Kirsher 		if (ret_val)
461dee1ad47SJeff Kirsher 			goto out;
462dee1ad47SJeff Kirsher 	}
463dee1ad47SJeff Kirsher 
464dee1ad47SJeff Kirsher 	if (offset > MAX_PHY_MULTI_PAGE_REG) {
465dee1ad47SJeff Kirsher 		ret_val = e1000e_write_phy_reg_mdic(hw,
466dee1ad47SJeff Kirsher 						    IGP01E1000_PHY_PAGE_SELECT,
467dee1ad47SJeff Kirsher 						    (u16)offset);
468dee1ad47SJeff Kirsher 		if (ret_val)
469dee1ad47SJeff Kirsher 			goto release;
470dee1ad47SJeff Kirsher 	}
471dee1ad47SJeff Kirsher 
472dee1ad47SJeff Kirsher 	ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
473dee1ad47SJeff Kirsher 					    data);
474dee1ad47SJeff Kirsher 
475dee1ad47SJeff Kirsher release:
476dee1ad47SJeff Kirsher 	if (!locked)
477dee1ad47SJeff Kirsher 		hw->phy.ops.release(hw);
478dee1ad47SJeff Kirsher 
479dee1ad47SJeff Kirsher out:
480dee1ad47SJeff Kirsher 	return ret_val;
481dee1ad47SJeff Kirsher }
482dee1ad47SJeff Kirsher 
483dee1ad47SJeff Kirsher /**
484dee1ad47SJeff Kirsher  *  e1000e_write_phy_reg_igp - Write igp PHY register
485dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
486dee1ad47SJeff Kirsher  *  @offset: register offset to write to
487dee1ad47SJeff Kirsher  *  @data: data to write at register offset
488dee1ad47SJeff Kirsher  *
489dee1ad47SJeff Kirsher  *  Acquires semaphore then writes the data to PHY register
490dee1ad47SJeff Kirsher  *  at the offset.  Release any acquired semaphores before exiting.
491dee1ad47SJeff Kirsher  **/
492dee1ad47SJeff Kirsher s32 e1000e_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data)
493dee1ad47SJeff Kirsher {
494dee1ad47SJeff Kirsher 	return __e1000e_write_phy_reg_igp(hw, offset, data, false);
495dee1ad47SJeff Kirsher }
496dee1ad47SJeff Kirsher 
497dee1ad47SJeff Kirsher /**
498dee1ad47SJeff Kirsher  *  e1000e_write_phy_reg_igp_locked - Write igp PHY register
499dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
500dee1ad47SJeff Kirsher  *  @offset: register offset to write to
501dee1ad47SJeff Kirsher  *  @data: data to write at register offset
502dee1ad47SJeff Kirsher  *
503dee1ad47SJeff Kirsher  *  Writes the data to PHY register at the offset.
504dee1ad47SJeff Kirsher  *  Assumes semaphore already acquired.
505dee1ad47SJeff Kirsher  **/
506dee1ad47SJeff Kirsher s32 e1000e_write_phy_reg_igp_locked(struct e1000_hw *hw, u32 offset, u16 data)
507dee1ad47SJeff Kirsher {
508dee1ad47SJeff Kirsher 	return __e1000e_write_phy_reg_igp(hw, offset, data, true);
509dee1ad47SJeff Kirsher }
510dee1ad47SJeff Kirsher 
511dee1ad47SJeff Kirsher /**
512dee1ad47SJeff Kirsher  *  __e1000_read_kmrn_reg - Read kumeran register
513dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
514dee1ad47SJeff Kirsher  *  @offset: register offset to be read
515dee1ad47SJeff Kirsher  *  @data: pointer to the read data
516dee1ad47SJeff Kirsher  *  @locked: semaphore has already been acquired or not
517dee1ad47SJeff Kirsher  *
518dee1ad47SJeff Kirsher  *  Acquires semaphore, if necessary.  Then reads the PHY register at offset
519dee1ad47SJeff Kirsher  *  using the kumeran interface.  The information retrieved is stored in data.
520dee1ad47SJeff Kirsher  *  Release any acquired semaphores before exiting.
521dee1ad47SJeff Kirsher  **/
522dee1ad47SJeff Kirsher static s32 __e1000_read_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 *data,
523dee1ad47SJeff Kirsher                                  bool locked)
524dee1ad47SJeff Kirsher {
525dee1ad47SJeff Kirsher 	u32 kmrnctrlsta;
526dee1ad47SJeff Kirsher 	s32 ret_val = 0;
527dee1ad47SJeff Kirsher 
528dee1ad47SJeff Kirsher 	if (!locked) {
529668018d7SBruce Allan 		if (!hw->phy.ops.acquire)
530dee1ad47SJeff Kirsher 			goto out;
531dee1ad47SJeff Kirsher 
532dee1ad47SJeff Kirsher 		ret_val = hw->phy.ops.acquire(hw);
533dee1ad47SJeff Kirsher 		if (ret_val)
534dee1ad47SJeff Kirsher 			goto out;
535dee1ad47SJeff Kirsher 	}
536dee1ad47SJeff Kirsher 
537dee1ad47SJeff Kirsher 	kmrnctrlsta = ((offset << E1000_KMRNCTRLSTA_OFFSET_SHIFT) &
538dee1ad47SJeff Kirsher 		       E1000_KMRNCTRLSTA_OFFSET) | E1000_KMRNCTRLSTA_REN;
539dee1ad47SJeff Kirsher 	ew32(KMRNCTRLSTA, kmrnctrlsta);
540dee1ad47SJeff Kirsher 	e1e_flush();
541dee1ad47SJeff Kirsher 
542dee1ad47SJeff Kirsher 	udelay(2);
543dee1ad47SJeff Kirsher 
544dee1ad47SJeff Kirsher 	kmrnctrlsta = er32(KMRNCTRLSTA);
545dee1ad47SJeff Kirsher 	*data = (u16)kmrnctrlsta;
546dee1ad47SJeff Kirsher 
547dee1ad47SJeff Kirsher 	if (!locked)
548dee1ad47SJeff Kirsher 		hw->phy.ops.release(hw);
549dee1ad47SJeff Kirsher 
550dee1ad47SJeff Kirsher out:
551dee1ad47SJeff Kirsher 	return ret_val;
552dee1ad47SJeff Kirsher }
553dee1ad47SJeff Kirsher 
554dee1ad47SJeff Kirsher /**
555dee1ad47SJeff Kirsher  *  e1000e_read_kmrn_reg -  Read kumeran register
556dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
557dee1ad47SJeff Kirsher  *  @offset: register offset to be read
558dee1ad47SJeff Kirsher  *  @data: pointer to the read data
559dee1ad47SJeff Kirsher  *
560dee1ad47SJeff Kirsher  *  Acquires semaphore then reads the PHY register at offset using the
561dee1ad47SJeff Kirsher  *  kumeran interface.  The information retrieved is stored in data.
562dee1ad47SJeff Kirsher  *  Release the acquired semaphore before exiting.
563dee1ad47SJeff Kirsher  **/
564dee1ad47SJeff Kirsher s32 e1000e_read_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 *data)
565dee1ad47SJeff Kirsher {
566dee1ad47SJeff Kirsher 	return __e1000_read_kmrn_reg(hw, offset, data, false);
567dee1ad47SJeff Kirsher }
568dee1ad47SJeff Kirsher 
569dee1ad47SJeff Kirsher /**
570dee1ad47SJeff Kirsher  *  e1000e_read_kmrn_reg_locked -  Read kumeran register
571dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
572dee1ad47SJeff Kirsher  *  @offset: register offset to be read
573dee1ad47SJeff Kirsher  *  @data: pointer to the read data
574dee1ad47SJeff Kirsher  *
575dee1ad47SJeff Kirsher  *  Reads the PHY register at offset using the kumeran interface.  The
576dee1ad47SJeff Kirsher  *  information retrieved is stored in data.
577dee1ad47SJeff Kirsher  *  Assumes semaphore already acquired.
578dee1ad47SJeff Kirsher  **/
579dee1ad47SJeff Kirsher s32 e1000e_read_kmrn_reg_locked(struct e1000_hw *hw, u32 offset, u16 *data)
580dee1ad47SJeff Kirsher {
581dee1ad47SJeff Kirsher 	return __e1000_read_kmrn_reg(hw, offset, data, true);
582dee1ad47SJeff Kirsher }
583dee1ad47SJeff Kirsher 
584dee1ad47SJeff Kirsher /**
585dee1ad47SJeff Kirsher  *  __e1000_write_kmrn_reg - Write kumeran register
586dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
587dee1ad47SJeff Kirsher  *  @offset: register offset to write to
588dee1ad47SJeff Kirsher  *  @data: data to write at register offset
589dee1ad47SJeff Kirsher  *  @locked: semaphore has already been acquired or not
590dee1ad47SJeff Kirsher  *
591dee1ad47SJeff Kirsher  *  Acquires semaphore, if necessary.  Then write the data to PHY register
592dee1ad47SJeff Kirsher  *  at the offset using the kumeran interface.  Release any acquired semaphores
593dee1ad47SJeff Kirsher  *  before exiting.
594dee1ad47SJeff Kirsher  **/
595dee1ad47SJeff Kirsher static s32 __e1000_write_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 data,
596dee1ad47SJeff Kirsher                                   bool locked)
597dee1ad47SJeff Kirsher {
598dee1ad47SJeff Kirsher 	u32 kmrnctrlsta;
599dee1ad47SJeff Kirsher 	s32 ret_val = 0;
600dee1ad47SJeff Kirsher 
601dee1ad47SJeff Kirsher 	if (!locked) {
602668018d7SBruce Allan 		if (!hw->phy.ops.acquire)
603dee1ad47SJeff Kirsher 			goto out;
604dee1ad47SJeff Kirsher 
605dee1ad47SJeff Kirsher 		ret_val = hw->phy.ops.acquire(hw);
606dee1ad47SJeff Kirsher 		if (ret_val)
607dee1ad47SJeff Kirsher 			goto out;
608dee1ad47SJeff Kirsher 	}
609dee1ad47SJeff Kirsher 
610dee1ad47SJeff Kirsher 	kmrnctrlsta = ((offset << E1000_KMRNCTRLSTA_OFFSET_SHIFT) &
611dee1ad47SJeff Kirsher 		       E1000_KMRNCTRLSTA_OFFSET) | data;
612dee1ad47SJeff Kirsher 	ew32(KMRNCTRLSTA, kmrnctrlsta);
613dee1ad47SJeff Kirsher 	e1e_flush();
614dee1ad47SJeff Kirsher 
615dee1ad47SJeff Kirsher 	udelay(2);
616dee1ad47SJeff Kirsher 
617dee1ad47SJeff Kirsher 	if (!locked)
618dee1ad47SJeff Kirsher 		hw->phy.ops.release(hw);
619dee1ad47SJeff Kirsher 
620dee1ad47SJeff Kirsher out:
621dee1ad47SJeff Kirsher 	return ret_val;
622dee1ad47SJeff Kirsher }
623dee1ad47SJeff Kirsher 
624dee1ad47SJeff Kirsher /**
625dee1ad47SJeff Kirsher  *  e1000e_write_kmrn_reg -  Write kumeran register
626dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
627dee1ad47SJeff Kirsher  *  @offset: register offset to write to
628dee1ad47SJeff Kirsher  *  @data: data to write at register offset
629dee1ad47SJeff Kirsher  *
630dee1ad47SJeff Kirsher  *  Acquires semaphore then writes the data to the PHY register at the offset
631dee1ad47SJeff Kirsher  *  using the kumeran interface.  Release the acquired semaphore before exiting.
632dee1ad47SJeff Kirsher  **/
633dee1ad47SJeff Kirsher s32 e1000e_write_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 data)
634dee1ad47SJeff Kirsher {
635dee1ad47SJeff Kirsher 	return __e1000_write_kmrn_reg(hw, offset, data, false);
636dee1ad47SJeff Kirsher }
637dee1ad47SJeff Kirsher 
638dee1ad47SJeff Kirsher /**
639dee1ad47SJeff Kirsher  *  e1000e_write_kmrn_reg_locked -  Write kumeran register
640dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
641dee1ad47SJeff Kirsher  *  @offset: register offset to write to
642dee1ad47SJeff Kirsher  *  @data: data to write at register offset
643dee1ad47SJeff Kirsher  *
644dee1ad47SJeff Kirsher  *  Write the data to PHY register at the offset using the kumeran interface.
645dee1ad47SJeff Kirsher  *  Assumes semaphore already acquired.
646dee1ad47SJeff Kirsher  **/
647dee1ad47SJeff Kirsher s32 e1000e_write_kmrn_reg_locked(struct e1000_hw *hw, u32 offset, u16 data)
648dee1ad47SJeff Kirsher {
649dee1ad47SJeff Kirsher 	return __e1000_write_kmrn_reg(hw, offset, data, true);
650dee1ad47SJeff Kirsher }
651dee1ad47SJeff Kirsher 
652dee1ad47SJeff Kirsher /**
653dee1ad47SJeff Kirsher  *  e1000_copper_link_setup_82577 - Setup 82577 PHY for copper link
654dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
655dee1ad47SJeff Kirsher  *
656dee1ad47SJeff Kirsher  *  Sets up Carrier-sense on Transmit and downshift values.
657dee1ad47SJeff Kirsher  **/
658dee1ad47SJeff Kirsher s32 e1000_copper_link_setup_82577(struct e1000_hw *hw)
659dee1ad47SJeff Kirsher {
660dee1ad47SJeff Kirsher 	s32 ret_val;
661dee1ad47SJeff Kirsher 	u16 phy_data;
662dee1ad47SJeff Kirsher 
663dee1ad47SJeff Kirsher 	/* Enable CRS on Tx. This must be set for half-duplex operation. */
664dee1ad47SJeff Kirsher 	ret_val = e1e_rphy(hw, I82577_CFG_REG, &phy_data);
665dee1ad47SJeff Kirsher 	if (ret_val)
666dee1ad47SJeff Kirsher 		goto out;
667dee1ad47SJeff Kirsher 
668dee1ad47SJeff Kirsher 	phy_data |= I82577_CFG_ASSERT_CRS_ON_TX;
669dee1ad47SJeff Kirsher 
670dee1ad47SJeff Kirsher 	/* Enable downshift */
671dee1ad47SJeff Kirsher 	phy_data |= I82577_CFG_ENABLE_DOWNSHIFT;
672dee1ad47SJeff Kirsher 
673dee1ad47SJeff Kirsher 	ret_val = e1e_wphy(hw, I82577_CFG_REG, phy_data);
674dee1ad47SJeff Kirsher 
675dee1ad47SJeff Kirsher out:
676dee1ad47SJeff Kirsher 	return ret_val;
677dee1ad47SJeff Kirsher }
678dee1ad47SJeff Kirsher 
679dee1ad47SJeff Kirsher /**
680dee1ad47SJeff Kirsher  *  e1000e_copper_link_setup_m88 - Setup m88 PHY's for copper link
681dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
682dee1ad47SJeff Kirsher  *
683dee1ad47SJeff Kirsher  *  Sets up MDI/MDI-X and polarity for m88 PHY's.  If necessary, transmit clock
684dee1ad47SJeff Kirsher  *  and downshift values are set also.
685dee1ad47SJeff Kirsher  **/
686dee1ad47SJeff Kirsher s32 e1000e_copper_link_setup_m88(struct e1000_hw *hw)
687dee1ad47SJeff Kirsher {
688dee1ad47SJeff Kirsher 	struct e1000_phy_info *phy = &hw->phy;
689dee1ad47SJeff Kirsher 	s32 ret_val;
690dee1ad47SJeff Kirsher 	u16 phy_data;
691dee1ad47SJeff Kirsher 
692dee1ad47SJeff Kirsher 	/* Enable CRS on Tx. This must be set for half-duplex operation. */
693dee1ad47SJeff Kirsher 	ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
694dee1ad47SJeff Kirsher 	if (ret_val)
695dee1ad47SJeff Kirsher 		return ret_val;
696dee1ad47SJeff Kirsher 
697dee1ad47SJeff Kirsher 	/* For BM PHY this bit is downshift enable */
698dee1ad47SJeff Kirsher 	if (phy->type != e1000_phy_bm)
699dee1ad47SJeff Kirsher 		phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
700dee1ad47SJeff Kirsher 
701dee1ad47SJeff Kirsher 	/*
702dee1ad47SJeff Kirsher 	 * Options:
703dee1ad47SJeff Kirsher 	 *   MDI/MDI-X = 0 (default)
704dee1ad47SJeff Kirsher 	 *   0 - Auto for all speeds
705dee1ad47SJeff Kirsher 	 *   1 - MDI mode
706dee1ad47SJeff Kirsher 	 *   2 - MDI-X mode
707dee1ad47SJeff Kirsher 	 *   3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
708dee1ad47SJeff Kirsher 	 */
709dee1ad47SJeff Kirsher 	phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
710dee1ad47SJeff Kirsher 
711dee1ad47SJeff Kirsher 	switch (phy->mdix) {
712dee1ad47SJeff Kirsher 	case 1:
713dee1ad47SJeff Kirsher 		phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
714dee1ad47SJeff Kirsher 		break;
715dee1ad47SJeff Kirsher 	case 2:
716dee1ad47SJeff Kirsher 		phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
717dee1ad47SJeff Kirsher 		break;
718dee1ad47SJeff Kirsher 	case 3:
719dee1ad47SJeff Kirsher 		phy_data |= M88E1000_PSCR_AUTO_X_1000T;
720dee1ad47SJeff Kirsher 		break;
721dee1ad47SJeff Kirsher 	case 0:
722dee1ad47SJeff Kirsher 	default:
723dee1ad47SJeff Kirsher 		phy_data |= M88E1000_PSCR_AUTO_X_MODE;
724dee1ad47SJeff Kirsher 		break;
725dee1ad47SJeff Kirsher 	}
726dee1ad47SJeff Kirsher 
727dee1ad47SJeff Kirsher 	/*
728dee1ad47SJeff Kirsher 	 * Options:
729dee1ad47SJeff Kirsher 	 *   disable_polarity_correction = 0 (default)
730dee1ad47SJeff Kirsher 	 *       Automatic Correction for Reversed Cable Polarity
731dee1ad47SJeff Kirsher 	 *   0 - Disabled
732dee1ad47SJeff Kirsher 	 *   1 - Enabled
733dee1ad47SJeff Kirsher 	 */
734dee1ad47SJeff Kirsher 	phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
735dee1ad47SJeff Kirsher 	if (phy->disable_polarity_correction == 1)
736dee1ad47SJeff Kirsher 		phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
737dee1ad47SJeff Kirsher 
738dee1ad47SJeff Kirsher 	/* Enable downshift on BM (disabled by default) */
739dee1ad47SJeff Kirsher 	if (phy->type == e1000_phy_bm)
740dee1ad47SJeff Kirsher 		phy_data |= BME1000_PSCR_ENABLE_DOWNSHIFT;
741dee1ad47SJeff Kirsher 
742dee1ad47SJeff Kirsher 	ret_val = e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
743dee1ad47SJeff Kirsher 	if (ret_val)
744dee1ad47SJeff Kirsher 		return ret_val;
745dee1ad47SJeff Kirsher 
746dee1ad47SJeff Kirsher 	if ((phy->type == e1000_phy_m88) &&
747dee1ad47SJeff Kirsher 	    (phy->revision < E1000_REVISION_4) &&
748dee1ad47SJeff Kirsher 	    (phy->id != BME1000_E_PHY_ID_R2)) {
749dee1ad47SJeff Kirsher 		/*
750dee1ad47SJeff Kirsher 		 * Force TX_CLK in the Extended PHY Specific Control Register
751dee1ad47SJeff Kirsher 		 * to 25MHz clock.
752dee1ad47SJeff Kirsher 		 */
753dee1ad47SJeff Kirsher 		ret_val = e1e_rphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
754dee1ad47SJeff Kirsher 		if (ret_val)
755dee1ad47SJeff Kirsher 			return ret_val;
756dee1ad47SJeff Kirsher 
757dee1ad47SJeff Kirsher 		phy_data |= M88E1000_EPSCR_TX_CLK_25;
758dee1ad47SJeff Kirsher 
759dee1ad47SJeff Kirsher 		if ((phy->revision == 2) &&
760dee1ad47SJeff Kirsher 		    (phy->id == M88E1111_I_PHY_ID)) {
761dee1ad47SJeff Kirsher 			/* 82573L PHY - set the downshift counter to 5x. */
762dee1ad47SJeff Kirsher 			phy_data &= ~M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK;
763dee1ad47SJeff Kirsher 			phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
764dee1ad47SJeff Kirsher 		} else {
765dee1ad47SJeff Kirsher 			/* Configure Master and Slave downshift values */
766dee1ad47SJeff Kirsher 			phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
767dee1ad47SJeff Kirsher 				      M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
768dee1ad47SJeff Kirsher 			phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
769dee1ad47SJeff Kirsher 				     M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
770dee1ad47SJeff Kirsher 		}
771dee1ad47SJeff Kirsher 		ret_val = e1e_wphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
772dee1ad47SJeff Kirsher 		if (ret_val)
773dee1ad47SJeff Kirsher 			return ret_val;
774dee1ad47SJeff Kirsher 	}
775dee1ad47SJeff Kirsher 
776dee1ad47SJeff Kirsher 	if ((phy->type == e1000_phy_bm) && (phy->id == BME1000_E_PHY_ID_R2)) {
777dee1ad47SJeff Kirsher 		/* Set PHY page 0, register 29 to 0x0003 */
778dee1ad47SJeff Kirsher 		ret_val = e1e_wphy(hw, 29, 0x0003);
779dee1ad47SJeff Kirsher 		if (ret_val)
780dee1ad47SJeff Kirsher 			return ret_val;
781dee1ad47SJeff Kirsher 
782dee1ad47SJeff Kirsher 		/* Set PHY page 0, register 30 to 0x0000 */
783dee1ad47SJeff Kirsher 		ret_val = e1e_wphy(hw, 30, 0x0000);
784dee1ad47SJeff Kirsher 		if (ret_val)
785dee1ad47SJeff Kirsher 			return ret_val;
786dee1ad47SJeff Kirsher 	}
787dee1ad47SJeff Kirsher 
788dee1ad47SJeff Kirsher 	/* Commit the changes. */
789dee1ad47SJeff Kirsher 	ret_val = e1000e_commit_phy(hw);
790dee1ad47SJeff Kirsher 	if (ret_val) {
791dee1ad47SJeff Kirsher 		e_dbg("Error committing the PHY changes\n");
792dee1ad47SJeff Kirsher 		return ret_val;
793dee1ad47SJeff Kirsher 	}
794dee1ad47SJeff Kirsher 
795dee1ad47SJeff Kirsher 	if (phy->type == e1000_phy_82578) {
796dee1ad47SJeff Kirsher 		ret_val = e1e_rphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
797dee1ad47SJeff Kirsher 		if (ret_val)
798dee1ad47SJeff Kirsher 			return ret_val;
799dee1ad47SJeff Kirsher 
800dee1ad47SJeff Kirsher 		/* 82578 PHY - set the downshift count to 1x. */
801dee1ad47SJeff Kirsher 		phy_data |= I82578_EPSCR_DOWNSHIFT_ENABLE;
802dee1ad47SJeff Kirsher 		phy_data &= ~I82578_EPSCR_DOWNSHIFT_COUNTER_MASK;
803dee1ad47SJeff Kirsher 		ret_val = e1e_wphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
804dee1ad47SJeff Kirsher 		if (ret_val)
805dee1ad47SJeff Kirsher 			return ret_val;
806dee1ad47SJeff Kirsher 	}
807dee1ad47SJeff Kirsher 
808dee1ad47SJeff Kirsher 	return 0;
809dee1ad47SJeff Kirsher }
810dee1ad47SJeff Kirsher 
811dee1ad47SJeff Kirsher /**
812dee1ad47SJeff Kirsher  *  e1000e_copper_link_setup_igp - Setup igp PHY's for copper link
813dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
814dee1ad47SJeff Kirsher  *
815dee1ad47SJeff Kirsher  *  Sets up LPLU, MDI/MDI-X, polarity, Smartspeed and Master/Slave config for
816dee1ad47SJeff Kirsher  *  igp PHY's.
817dee1ad47SJeff Kirsher  **/
818dee1ad47SJeff Kirsher s32 e1000e_copper_link_setup_igp(struct e1000_hw *hw)
819dee1ad47SJeff Kirsher {
820dee1ad47SJeff Kirsher 	struct e1000_phy_info *phy = &hw->phy;
821dee1ad47SJeff Kirsher 	s32 ret_val;
822dee1ad47SJeff Kirsher 	u16 data;
823dee1ad47SJeff Kirsher 
824dee1ad47SJeff Kirsher 	ret_val = e1000_phy_hw_reset(hw);
825dee1ad47SJeff Kirsher 	if (ret_val) {
826dee1ad47SJeff Kirsher 		e_dbg("Error resetting the PHY.\n");
827dee1ad47SJeff Kirsher 		return ret_val;
828dee1ad47SJeff Kirsher 	}
829dee1ad47SJeff Kirsher 
830dee1ad47SJeff Kirsher 	/*
831dee1ad47SJeff Kirsher 	 * Wait 100ms for MAC to configure PHY from NVM settings, to avoid
832dee1ad47SJeff Kirsher 	 * timeout issues when LFS is enabled.
833dee1ad47SJeff Kirsher 	 */
834dee1ad47SJeff Kirsher 	msleep(100);
835dee1ad47SJeff Kirsher 
836dee1ad47SJeff Kirsher 	/* disable lplu d0 during driver init */
837dee1ad47SJeff Kirsher 	ret_val = e1000_set_d0_lplu_state(hw, false);
838dee1ad47SJeff Kirsher 	if (ret_val) {
839dee1ad47SJeff Kirsher 		e_dbg("Error Disabling LPLU D0\n");
840dee1ad47SJeff Kirsher 		return ret_val;
841dee1ad47SJeff Kirsher 	}
842dee1ad47SJeff Kirsher 	/* Configure mdi-mdix settings */
843dee1ad47SJeff Kirsher 	ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CTRL, &data);
844dee1ad47SJeff Kirsher 	if (ret_val)
845dee1ad47SJeff Kirsher 		return ret_val;
846dee1ad47SJeff Kirsher 
847dee1ad47SJeff Kirsher 	data &= ~IGP01E1000_PSCR_AUTO_MDIX;
848dee1ad47SJeff Kirsher 
849dee1ad47SJeff Kirsher 	switch (phy->mdix) {
850dee1ad47SJeff Kirsher 	case 1:
851dee1ad47SJeff Kirsher 		data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
852dee1ad47SJeff Kirsher 		break;
853dee1ad47SJeff Kirsher 	case 2:
854dee1ad47SJeff Kirsher 		data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
855dee1ad47SJeff Kirsher 		break;
856dee1ad47SJeff Kirsher 	case 0:
857dee1ad47SJeff Kirsher 	default:
858dee1ad47SJeff Kirsher 		data |= IGP01E1000_PSCR_AUTO_MDIX;
859dee1ad47SJeff Kirsher 		break;
860dee1ad47SJeff Kirsher 	}
861dee1ad47SJeff Kirsher 	ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CTRL, data);
862dee1ad47SJeff Kirsher 	if (ret_val)
863dee1ad47SJeff Kirsher 		return ret_val;
864dee1ad47SJeff Kirsher 
865dee1ad47SJeff Kirsher 	/* set auto-master slave resolution settings */
866dee1ad47SJeff Kirsher 	if (hw->mac.autoneg) {
867dee1ad47SJeff Kirsher 		/*
868dee1ad47SJeff Kirsher 		 * when autonegotiation advertisement is only 1000Mbps then we
869dee1ad47SJeff Kirsher 		 * should disable SmartSpeed and enable Auto MasterSlave
870dee1ad47SJeff Kirsher 		 * resolution as hardware default.
871dee1ad47SJeff Kirsher 		 */
872dee1ad47SJeff Kirsher 		if (phy->autoneg_advertised == ADVERTISE_1000_FULL) {
873dee1ad47SJeff Kirsher 			/* Disable SmartSpeed */
874dee1ad47SJeff Kirsher 			ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
875dee1ad47SJeff Kirsher 					   &data);
876dee1ad47SJeff Kirsher 			if (ret_val)
877dee1ad47SJeff Kirsher 				return ret_val;
878dee1ad47SJeff Kirsher 
879dee1ad47SJeff Kirsher 			data &= ~IGP01E1000_PSCFR_SMART_SPEED;
880dee1ad47SJeff Kirsher 			ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
881dee1ad47SJeff Kirsher 					   data);
882dee1ad47SJeff Kirsher 			if (ret_val)
883dee1ad47SJeff Kirsher 				return ret_val;
884dee1ad47SJeff Kirsher 
885dee1ad47SJeff Kirsher 			/* Set auto Master/Slave resolution process */
886dee1ad47SJeff Kirsher 			ret_val = e1e_rphy(hw, PHY_1000T_CTRL, &data);
887dee1ad47SJeff Kirsher 			if (ret_val)
888dee1ad47SJeff Kirsher 				return ret_val;
889dee1ad47SJeff Kirsher 
890dee1ad47SJeff Kirsher 			data &= ~CR_1000T_MS_ENABLE;
891dee1ad47SJeff Kirsher 			ret_val = e1e_wphy(hw, PHY_1000T_CTRL, data);
892dee1ad47SJeff Kirsher 			if (ret_val)
893dee1ad47SJeff Kirsher 				return ret_val;
894dee1ad47SJeff Kirsher 		}
895dee1ad47SJeff Kirsher 
896dee1ad47SJeff Kirsher 		ret_val = e1e_rphy(hw, PHY_1000T_CTRL, &data);
897dee1ad47SJeff Kirsher 		if (ret_val)
898dee1ad47SJeff Kirsher 			return ret_val;
899dee1ad47SJeff Kirsher 
900dee1ad47SJeff Kirsher 		/* load defaults for future use */
901dee1ad47SJeff Kirsher 		phy->original_ms_type = (data & CR_1000T_MS_ENABLE) ?
902dee1ad47SJeff Kirsher 			((data & CR_1000T_MS_VALUE) ?
903dee1ad47SJeff Kirsher 			e1000_ms_force_master :
904dee1ad47SJeff Kirsher 			e1000_ms_force_slave) :
905dee1ad47SJeff Kirsher 			e1000_ms_auto;
906dee1ad47SJeff Kirsher 
907dee1ad47SJeff Kirsher 		switch (phy->ms_type) {
908dee1ad47SJeff Kirsher 		case e1000_ms_force_master:
909dee1ad47SJeff Kirsher 			data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
910dee1ad47SJeff Kirsher 			break;
911dee1ad47SJeff Kirsher 		case e1000_ms_force_slave:
912dee1ad47SJeff Kirsher 			data |= CR_1000T_MS_ENABLE;
913dee1ad47SJeff Kirsher 			data &= ~(CR_1000T_MS_VALUE);
914dee1ad47SJeff Kirsher 			break;
915dee1ad47SJeff Kirsher 		case e1000_ms_auto:
916dee1ad47SJeff Kirsher 			data &= ~CR_1000T_MS_ENABLE;
917dee1ad47SJeff Kirsher 		default:
918dee1ad47SJeff Kirsher 			break;
919dee1ad47SJeff Kirsher 		}
920dee1ad47SJeff Kirsher 		ret_val = e1e_wphy(hw, PHY_1000T_CTRL, data);
921dee1ad47SJeff Kirsher 	}
922dee1ad47SJeff Kirsher 
923dee1ad47SJeff Kirsher 	return ret_val;
924dee1ad47SJeff Kirsher }
925dee1ad47SJeff Kirsher 
926dee1ad47SJeff Kirsher /**
927dee1ad47SJeff Kirsher  *  e1000_phy_setup_autoneg - Configure PHY for auto-negotiation
928dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
929dee1ad47SJeff Kirsher  *
930dee1ad47SJeff Kirsher  *  Reads the MII auto-neg advertisement register and/or the 1000T control
931dee1ad47SJeff Kirsher  *  register and if the PHY is already setup for auto-negotiation, then
932dee1ad47SJeff Kirsher  *  return successful.  Otherwise, setup advertisement and flow control to
933dee1ad47SJeff Kirsher  *  the appropriate values for the wanted auto-negotiation.
934dee1ad47SJeff Kirsher  **/
935dee1ad47SJeff Kirsher static s32 e1000_phy_setup_autoneg(struct e1000_hw *hw)
936dee1ad47SJeff Kirsher {
937dee1ad47SJeff Kirsher 	struct e1000_phy_info *phy = &hw->phy;
938dee1ad47SJeff Kirsher 	s32 ret_val;
939dee1ad47SJeff Kirsher 	u16 mii_autoneg_adv_reg;
940dee1ad47SJeff Kirsher 	u16 mii_1000t_ctrl_reg = 0;
941dee1ad47SJeff Kirsher 
942dee1ad47SJeff Kirsher 	phy->autoneg_advertised &= phy->autoneg_mask;
943dee1ad47SJeff Kirsher 
944dee1ad47SJeff Kirsher 	/* Read the MII Auto-Neg Advertisement Register (Address 4). */
945dee1ad47SJeff Kirsher 	ret_val = e1e_rphy(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
946dee1ad47SJeff Kirsher 	if (ret_val)
947dee1ad47SJeff Kirsher 		return ret_val;
948dee1ad47SJeff Kirsher 
949dee1ad47SJeff Kirsher 	if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
950dee1ad47SJeff Kirsher 		/* Read the MII 1000Base-T Control Register (Address 9). */
951dee1ad47SJeff Kirsher 		ret_val = e1e_rphy(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
952dee1ad47SJeff Kirsher 		if (ret_val)
953dee1ad47SJeff Kirsher 			return ret_val;
954dee1ad47SJeff Kirsher 	}
955dee1ad47SJeff Kirsher 
956dee1ad47SJeff Kirsher 	/*
957dee1ad47SJeff Kirsher 	 * Need to parse both autoneg_advertised and fc and set up
958dee1ad47SJeff Kirsher 	 * the appropriate PHY registers.  First we will parse for
959dee1ad47SJeff Kirsher 	 * autoneg_advertised software override.  Since we can advertise
960dee1ad47SJeff Kirsher 	 * a plethora of combinations, we need to check each bit
961dee1ad47SJeff Kirsher 	 * individually.
962dee1ad47SJeff Kirsher 	 */
963dee1ad47SJeff Kirsher 
964dee1ad47SJeff Kirsher 	/*
965dee1ad47SJeff Kirsher 	 * First we clear all the 10/100 mb speed bits in the Auto-Neg
966dee1ad47SJeff Kirsher 	 * Advertisement Register (Address 4) and the 1000 mb speed bits in
967dee1ad47SJeff Kirsher 	 * the  1000Base-T Control Register (Address 9).
968dee1ad47SJeff Kirsher 	 */
969dee1ad47SJeff Kirsher 	mii_autoneg_adv_reg &= ~(NWAY_AR_100TX_FD_CAPS |
970dee1ad47SJeff Kirsher 				 NWAY_AR_100TX_HD_CAPS |
971dee1ad47SJeff Kirsher 				 NWAY_AR_10T_FD_CAPS   |
972dee1ad47SJeff Kirsher 				 NWAY_AR_10T_HD_CAPS);
973dee1ad47SJeff Kirsher 	mii_1000t_ctrl_reg &= ~(CR_1000T_HD_CAPS | CR_1000T_FD_CAPS);
974dee1ad47SJeff Kirsher 
975dee1ad47SJeff Kirsher 	e_dbg("autoneg_advertised %x\n", phy->autoneg_advertised);
976dee1ad47SJeff Kirsher 
977dee1ad47SJeff Kirsher 	/* Do we want to advertise 10 Mb Half Duplex? */
978dee1ad47SJeff Kirsher 	if (phy->autoneg_advertised & ADVERTISE_10_HALF) {
979dee1ad47SJeff Kirsher 		e_dbg("Advertise 10mb Half duplex\n");
980dee1ad47SJeff Kirsher 		mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
981dee1ad47SJeff Kirsher 	}
982dee1ad47SJeff Kirsher 
983dee1ad47SJeff Kirsher 	/* Do we want to advertise 10 Mb Full Duplex? */
984dee1ad47SJeff Kirsher 	if (phy->autoneg_advertised & ADVERTISE_10_FULL) {
985dee1ad47SJeff Kirsher 		e_dbg("Advertise 10mb Full duplex\n");
986dee1ad47SJeff Kirsher 		mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
987dee1ad47SJeff Kirsher 	}
988dee1ad47SJeff Kirsher 
989dee1ad47SJeff Kirsher 	/* Do we want to advertise 100 Mb Half Duplex? */
990dee1ad47SJeff Kirsher 	if (phy->autoneg_advertised & ADVERTISE_100_HALF) {
991dee1ad47SJeff Kirsher 		e_dbg("Advertise 100mb Half duplex\n");
992dee1ad47SJeff Kirsher 		mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
993dee1ad47SJeff Kirsher 	}
994dee1ad47SJeff Kirsher 
995dee1ad47SJeff Kirsher 	/* Do we want to advertise 100 Mb Full Duplex? */
996dee1ad47SJeff Kirsher 	if (phy->autoneg_advertised & ADVERTISE_100_FULL) {
997dee1ad47SJeff Kirsher 		e_dbg("Advertise 100mb Full duplex\n");
998dee1ad47SJeff Kirsher 		mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
999dee1ad47SJeff Kirsher 	}
1000dee1ad47SJeff Kirsher 
1001dee1ad47SJeff Kirsher 	/* We do not allow the Phy to advertise 1000 Mb Half Duplex */
1002dee1ad47SJeff Kirsher 	if (phy->autoneg_advertised & ADVERTISE_1000_HALF)
1003dee1ad47SJeff Kirsher 		e_dbg("Advertise 1000mb Half duplex request denied!\n");
1004dee1ad47SJeff Kirsher 
1005dee1ad47SJeff Kirsher 	/* Do we want to advertise 1000 Mb Full Duplex? */
1006dee1ad47SJeff Kirsher 	if (phy->autoneg_advertised & ADVERTISE_1000_FULL) {
1007dee1ad47SJeff Kirsher 		e_dbg("Advertise 1000mb Full duplex\n");
1008dee1ad47SJeff Kirsher 		mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
1009dee1ad47SJeff Kirsher 	}
1010dee1ad47SJeff Kirsher 
1011dee1ad47SJeff Kirsher 	/*
1012dee1ad47SJeff Kirsher 	 * Check for a software override of the flow control settings, and
1013dee1ad47SJeff Kirsher 	 * setup the PHY advertisement registers accordingly.  If
1014dee1ad47SJeff Kirsher 	 * auto-negotiation is enabled, then software will have to set the
1015dee1ad47SJeff Kirsher 	 * "PAUSE" bits to the correct value in the Auto-Negotiation
1016dee1ad47SJeff Kirsher 	 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-
1017dee1ad47SJeff Kirsher 	 * negotiation.
1018dee1ad47SJeff Kirsher 	 *
1019dee1ad47SJeff Kirsher 	 * The possible values of the "fc" parameter are:
1020dee1ad47SJeff Kirsher 	 *      0:  Flow control is completely disabled
1021dee1ad47SJeff Kirsher 	 *      1:  Rx flow control is enabled (we can receive pause frames
1022dee1ad47SJeff Kirsher 	 *	  but not send pause frames).
1023dee1ad47SJeff Kirsher 	 *      2:  Tx flow control is enabled (we can send pause frames
1024dee1ad47SJeff Kirsher 	 *	  but we do not support receiving pause frames).
1025dee1ad47SJeff Kirsher 	 *      3:  Both Rx and Tx flow control (symmetric) are enabled.
1026dee1ad47SJeff Kirsher 	 *  other:  No software override.  The flow control configuration
1027dee1ad47SJeff Kirsher 	 *	  in the EEPROM is used.
1028dee1ad47SJeff Kirsher 	 */
1029dee1ad47SJeff Kirsher 	switch (hw->fc.current_mode) {
1030dee1ad47SJeff Kirsher 	case e1000_fc_none:
1031dee1ad47SJeff Kirsher 		/*
1032dee1ad47SJeff Kirsher 		 * Flow control (Rx & Tx) is completely disabled by a
1033dee1ad47SJeff Kirsher 		 * software over-ride.
1034dee1ad47SJeff Kirsher 		 */
1035dee1ad47SJeff Kirsher 		mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1036dee1ad47SJeff Kirsher 		break;
1037dee1ad47SJeff Kirsher 	case e1000_fc_rx_pause:
1038dee1ad47SJeff Kirsher 		/*
1039dee1ad47SJeff Kirsher 		 * Rx Flow control is enabled, and Tx Flow control is
1040dee1ad47SJeff Kirsher 		 * disabled, by a software over-ride.
1041dee1ad47SJeff Kirsher 		 *
1042dee1ad47SJeff Kirsher 		 * Since there really isn't a way to advertise that we are
1043dee1ad47SJeff Kirsher 		 * capable of Rx Pause ONLY, we will advertise that we
1044dee1ad47SJeff Kirsher 		 * support both symmetric and asymmetric Rx PAUSE.  Later
1045dee1ad47SJeff Kirsher 		 * (in e1000e_config_fc_after_link_up) we will disable the
1046dee1ad47SJeff Kirsher 		 * hw's ability to send PAUSE frames.
1047dee1ad47SJeff Kirsher 		 */
1048dee1ad47SJeff Kirsher 		mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1049dee1ad47SJeff Kirsher 		break;
1050dee1ad47SJeff Kirsher 	case e1000_fc_tx_pause:
1051dee1ad47SJeff Kirsher 		/*
1052dee1ad47SJeff Kirsher 		 * Tx Flow control is enabled, and Rx Flow control is
1053dee1ad47SJeff Kirsher 		 * disabled, by a software over-ride.
1054dee1ad47SJeff Kirsher 		 */
1055dee1ad47SJeff Kirsher 		mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
1056dee1ad47SJeff Kirsher 		mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
1057dee1ad47SJeff Kirsher 		break;
1058dee1ad47SJeff Kirsher 	case e1000_fc_full:
1059dee1ad47SJeff Kirsher 		/*
1060dee1ad47SJeff Kirsher 		 * Flow control (both Rx and Tx) is enabled by a software
1061dee1ad47SJeff Kirsher 		 * over-ride.
1062dee1ad47SJeff Kirsher 		 */
1063dee1ad47SJeff Kirsher 		mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1064dee1ad47SJeff Kirsher 		break;
1065dee1ad47SJeff Kirsher 	default:
1066dee1ad47SJeff Kirsher 		e_dbg("Flow control param set incorrectly\n");
1067dee1ad47SJeff Kirsher 		ret_val = -E1000_ERR_CONFIG;
1068dee1ad47SJeff Kirsher 		return ret_val;
1069dee1ad47SJeff Kirsher 	}
1070dee1ad47SJeff Kirsher 
1071dee1ad47SJeff Kirsher 	ret_val = e1e_wphy(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
1072dee1ad47SJeff Kirsher 	if (ret_val)
1073dee1ad47SJeff Kirsher 		return ret_val;
1074dee1ad47SJeff Kirsher 
1075dee1ad47SJeff Kirsher 	e_dbg("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
1076dee1ad47SJeff Kirsher 
1077dee1ad47SJeff Kirsher 	if (phy->autoneg_mask & ADVERTISE_1000_FULL)
1078dee1ad47SJeff Kirsher 		ret_val = e1e_wphy(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg);
1079dee1ad47SJeff Kirsher 
1080dee1ad47SJeff Kirsher 	return ret_val;
1081dee1ad47SJeff Kirsher }
1082dee1ad47SJeff Kirsher 
1083dee1ad47SJeff Kirsher /**
1084dee1ad47SJeff Kirsher  *  e1000_copper_link_autoneg - Setup/Enable autoneg for copper link
1085dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
1086dee1ad47SJeff Kirsher  *
1087dee1ad47SJeff Kirsher  *  Performs initial bounds checking on autoneg advertisement parameter, then
1088dee1ad47SJeff Kirsher  *  configure to advertise the full capability.  Setup the PHY to autoneg
1089dee1ad47SJeff Kirsher  *  and restart the negotiation process between the link partner.  If
1090dee1ad47SJeff Kirsher  *  autoneg_wait_to_complete, then wait for autoneg to complete before exiting.
1091dee1ad47SJeff Kirsher  **/
1092dee1ad47SJeff Kirsher static s32 e1000_copper_link_autoneg(struct e1000_hw *hw)
1093dee1ad47SJeff Kirsher {
1094dee1ad47SJeff Kirsher 	struct e1000_phy_info *phy = &hw->phy;
1095dee1ad47SJeff Kirsher 	s32 ret_val;
1096dee1ad47SJeff Kirsher 	u16 phy_ctrl;
1097dee1ad47SJeff Kirsher 
1098dee1ad47SJeff Kirsher 	/*
1099dee1ad47SJeff Kirsher 	 * Perform some bounds checking on the autoneg advertisement
1100dee1ad47SJeff Kirsher 	 * parameter.
1101dee1ad47SJeff Kirsher 	 */
1102dee1ad47SJeff Kirsher 	phy->autoneg_advertised &= phy->autoneg_mask;
1103dee1ad47SJeff Kirsher 
1104dee1ad47SJeff Kirsher 	/*
1105dee1ad47SJeff Kirsher 	 * If autoneg_advertised is zero, we assume it was not defaulted
1106dee1ad47SJeff Kirsher 	 * by the calling code so we set to advertise full capability.
1107dee1ad47SJeff Kirsher 	 */
1108dee1ad47SJeff Kirsher 	if (phy->autoneg_advertised == 0)
1109dee1ad47SJeff Kirsher 		phy->autoneg_advertised = phy->autoneg_mask;
1110dee1ad47SJeff Kirsher 
1111dee1ad47SJeff Kirsher 	e_dbg("Reconfiguring auto-neg advertisement params\n");
1112dee1ad47SJeff Kirsher 	ret_val = e1000_phy_setup_autoneg(hw);
1113dee1ad47SJeff Kirsher 	if (ret_val) {
1114dee1ad47SJeff Kirsher 		e_dbg("Error Setting up Auto-Negotiation\n");
1115dee1ad47SJeff Kirsher 		return ret_val;
1116dee1ad47SJeff Kirsher 	}
1117dee1ad47SJeff Kirsher 	e_dbg("Restarting Auto-Neg\n");
1118dee1ad47SJeff Kirsher 
1119dee1ad47SJeff Kirsher 	/*
1120dee1ad47SJeff Kirsher 	 * Restart auto-negotiation by setting the Auto Neg Enable bit and
1121dee1ad47SJeff Kirsher 	 * the Auto Neg Restart bit in the PHY control register.
1122dee1ad47SJeff Kirsher 	 */
1123dee1ad47SJeff Kirsher 	ret_val = e1e_rphy(hw, PHY_CONTROL, &phy_ctrl);
1124dee1ad47SJeff Kirsher 	if (ret_val)
1125dee1ad47SJeff Kirsher 		return ret_val;
1126dee1ad47SJeff Kirsher 
1127dee1ad47SJeff Kirsher 	phy_ctrl |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
1128dee1ad47SJeff Kirsher 	ret_val = e1e_wphy(hw, PHY_CONTROL, phy_ctrl);
1129dee1ad47SJeff Kirsher 	if (ret_val)
1130dee1ad47SJeff Kirsher 		return ret_val;
1131dee1ad47SJeff Kirsher 
1132dee1ad47SJeff Kirsher 	/*
1133dee1ad47SJeff Kirsher 	 * Does the user want to wait for Auto-Neg to complete here, or
1134dee1ad47SJeff Kirsher 	 * check at a later time (for example, callback routine).
1135dee1ad47SJeff Kirsher 	 */
1136dee1ad47SJeff Kirsher 	if (phy->autoneg_wait_to_complete) {
1137dee1ad47SJeff Kirsher 		ret_val = e1000_wait_autoneg(hw);
1138dee1ad47SJeff Kirsher 		if (ret_val) {
1139434f1392SBruce Allan 			e_dbg("Error while waiting for autoneg to complete\n");
1140dee1ad47SJeff Kirsher 			return ret_val;
1141dee1ad47SJeff Kirsher 		}
1142dee1ad47SJeff Kirsher 	}
1143dee1ad47SJeff Kirsher 
1144dee1ad47SJeff Kirsher 	hw->mac.get_link_status = 1;
1145dee1ad47SJeff Kirsher 
1146dee1ad47SJeff Kirsher 	return ret_val;
1147dee1ad47SJeff Kirsher }
1148dee1ad47SJeff Kirsher 
1149dee1ad47SJeff Kirsher /**
1150dee1ad47SJeff Kirsher  *  e1000e_setup_copper_link - Configure copper link settings
1151dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
1152dee1ad47SJeff Kirsher  *
1153dee1ad47SJeff Kirsher  *  Calls the appropriate function to configure the link for auto-neg or forced
1154dee1ad47SJeff Kirsher  *  speed and duplex.  Then we check for link, once link is established calls
1155dee1ad47SJeff Kirsher  *  to configure collision distance and flow control are called.  If link is
1156dee1ad47SJeff Kirsher  *  not established, we return -E1000_ERR_PHY (-2).
1157dee1ad47SJeff Kirsher  **/
1158dee1ad47SJeff Kirsher s32 e1000e_setup_copper_link(struct e1000_hw *hw)
1159dee1ad47SJeff Kirsher {
1160dee1ad47SJeff Kirsher 	s32 ret_val;
1161dee1ad47SJeff Kirsher 	bool link;
1162dee1ad47SJeff Kirsher 
1163dee1ad47SJeff Kirsher 	if (hw->mac.autoneg) {
1164dee1ad47SJeff Kirsher 		/*
1165dee1ad47SJeff Kirsher 		 * Setup autoneg and flow control advertisement and perform
1166dee1ad47SJeff Kirsher 		 * autonegotiation.
1167dee1ad47SJeff Kirsher 		 */
1168dee1ad47SJeff Kirsher 		ret_val = e1000_copper_link_autoneg(hw);
1169dee1ad47SJeff Kirsher 		if (ret_val)
1170dee1ad47SJeff Kirsher 			return ret_val;
1171dee1ad47SJeff Kirsher 	} else {
1172dee1ad47SJeff Kirsher 		/*
1173dee1ad47SJeff Kirsher 		 * PHY will be set to 10H, 10F, 100H or 100F
1174dee1ad47SJeff Kirsher 		 * depending on user settings.
1175dee1ad47SJeff Kirsher 		 */
1176dee1ad47SJeff Kirsher 		e_dbg("Forcing Speed and Duplex\n");
1177dee1ad47SJeff Kirsher 		ret_val = e1000_phy_force_speed_duplex(hw);
1178dee1ad47SJeff Kirsher 		if (ret_val) {
1179dee1ad47SJeff Kirsher 			e_dbg("Error Forcing Speed and Duplex\n");
1180dee1ad47SJeff Kirsher 			return ret_val;
1181dee1ad47SJeff Kirsher 		}
1182dee1ad47SJeff Kirsher 	}
1183dee1ad47SJeff Kirsher 
1184dee1ad47SJeff Kirsher 	/*
1185dee1ad47SJeff Kirsher 	 * Check link status. Wait up to 100 microseconds for link to become
1186dee1ad47SJeff Kirsher 	 * valid.
1187dee1ad47SJeff Kirsher 	 */
1188dee1ad47SJeff Kirsher 	ret_val = e1000e_phy_has_link_generic(hw,
1189dee1ad47SJeff Kirsher 					     COPPER_LINK_UP_LIMIT,
1190dee1ad47SJeff Kirsher 					     10,
1191dee1ad47SJeff Kirsher 					     &link);
1192dee1ad47SJeff Kirsher 	if (ret_val)
1193dee1ad47SJeff Kirsher 		return ret_val;
1194dee1ad47SJeff Kirsher 
1195dee1ad47SJeff Kirsher 	if (link) {
1196dee1ad47SJeff Kirsher 		e_dbg("Valid link established!!!\n");
1197dee1ad47SJeff Kirsher 		e1000e_config_collision_dist(hw);
1198dee1ad47SJeff Kirsher 		ret_val = e1000e_config_fc_after_link_up(hw);
1199dee1ad47SJeff Kirsher 	} else {
1200dee1ad47SJeff Kirsher 		e_dbg("Unable to establish link!!!\n");
1201dee1ad47SJeff Kirsher 	}
1202dee1ad47SJeff Kirsher 
1203dee1ad47SJeff Kirsher 	return ret_val;
1204dee1ad47SJeff Kirsher }
1205dee1ad47SJeff Kirsher 
1206dee1ad47SJeff Kirsher /**
1207dee1ad47SJeff Kirsher  *  e1000e_phy_force_speed_duplex_igp - Force speed/duplex for igp PHY
1208dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
1209dee1ad47SJeff Kirsher  *
1210dee1ad47SJeff Kirsher  *  Calls the PHY setup function to force speed and duplex.  Clears the
1211dee1ad47SJeff Kirsher  *  auto-crossover to force MDI manually.  Waits for link and returns
1212dee1ad47SJeff Kirsher  *  successful if link up is successful, else -E1000_ERR_PHY (-2).
1213dee1ad47SJeff Kirsher  **/
1214dee1ad47SJeff Kirsher s32 e1000e_phy_force_speed_duplex_igp(struct e1000_hw *hw)
1215dee1ad47SJeff Kirsher {
1216dee1ad47SJeff Kirsher 	struct e1000_phy_info *phy = &hw->phy;
1217dee1ad47SJeff Kirsher 	s32 ret_val;
1218dee1ad47SJeff Kirsher 	u16 phy_data;
1219dee1ad47SJeff Kirsher 	bool link;
1220dee1ad47SJeff Kirsher 
1221dee1ad47SJeff Kirsher 	ret_val = e1e_rphy(hw, PHY_CONTROL, &phy_data);
1222dee1ad47SJeff Kirsher 	if (ret_val)
1223dee1ad47SJeff Kirsher 		return ret_val;
1224dee1ad47SJeff Kirsher 
1225dee1ad47SJeff Kirsher 	e1000e_phy_force_speed_duplex_setup(hw, &phy_data);
1226dee1ad47SJeff Kirsher 
1227dee1ad47SJeff Kirsher 	ret_val = e1e_wphy(hw, PHY_CONTROL, phy_data);
1228dee1ad47SJeff Kirsher 	if (ret_val)
1229dee1ad47SJeff Kirsher 		return ret_val;
1230dee1ad47SJeff Kirsher 
1231dee1ad47SJeff Kirsher 	/*
1232dee1ad47SJeff Kirsher 	 * Clear Auto-Crossover to force MDI manually.  IGP requires MDI
1233dee1ad47SJeff Kirsher 	 * forced whenever speed and duplex are forced.
1234dee1ad47SJeff Kirsher 	 */
1235dee1ad47SJeff Kirsher 	ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1236dee1ad47SJeff Kirsher 	if (ret_val)
1237dee1ad47SJeff Kirsher 		return ret_val;
1238dee1ad47SJeff Kirsher 
1239dee1ad47SJeff Kirsher 	phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1240dee1ad47SJeff Kirsher 	phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1241dee1ad47SJeff Kirsher 
1242dee1ad47SJeff Kirsher 	ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1243dee1ad47SJeff Kirsher 	if (ret_val)
1244dee1ad47SJeff Kirsher 		return ret_val;
1245dee1ad47SJeff Kirsher 
1246dee1ad47SJeff Kirsher 	e_dbg("IGP PSCR: %X\n", phy_data);
1247dee1ad47SJeff Kirsher 
1248dee1ad47SJeff Kirsher 	udelay(1);
1249dee1ad47SJeff Kirsher 
1250dee1ad47SJeff Kirsher 	if (phy->autoneg_wait_to_complete) {
1251dee1ad47SJeff Kirsher 		e_dbg("Waiting for forced speed/duplex link on IGP phy.\n");
1252dee1ad47SJeff Kirsher 
1253dee1ad47SJeff Kirsher 		ret_val = e1000e_phy_has_link_generic(hw,
1254dee1ad47SJeff Kirsher 						     PHY_FORCE_LIMIT,
1255dee1ad47SJeff Kirsher 						     100000,
1256dee1ad47SJeff Kirsher 						     &link);
1257dee1ad47SJeff Kirsher 		if (ret_val)
1258dee1ad47SJeff Kirsher 			return ret_val;
1259dee1ad47SJeff Kirsher 
1260dee1ad47SJeff Kirsher 		if (!link)
1261dee1ad47SJeff Kirsher 			e_dbg("Link taking longer than expected.\n");
1262dee1ad47SJeff Kirsher 
1263dee1ad47SJeff Kirsher 		/* Try once more */
1264dee1ad47SJeff Kirsher 		ret_val = e1000e_phy_has_link_generic(hw,
1265dee1ad47SJeff Kirsher 						     PHY_FORCE_LIMIT,
1266dee1ad47SJeff Kirsher 						     100000,
1267dee1ad47SJeff Kirsher 						     &link);
1268dee1ad47SJeff Kirsher 		if (ret_val)
1269dee1ad47SJeff Kirsher 			return ret_val;
1270dee1ad47SJeff Kirsher 	}
1271dee1ad47SJeff Kirsher 
1272dee1ad47SJeff Kirsher 	return ret_val;
1273dee1ad47SJeff Kirsher }
1274dee1ad47SJeff Kirsher 
1275dee1ad47SJeff Kirsher /**
1276dee1ad47SJeff Kirsher  *  e1000e_phy_force_speed_duplex_m88 - Force speed/duplex for m88 PHY
1277dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
1278dee1ad47SJeff Kirsher  *
1279dee1ad47SJeff Kirsher  *  Calls the PHY setup function to force speed and duplex.  Clears the
1280dee1ad47SJeff Kirsher  *  auto-crossover to force MDI manually.  Resets the PHY to commit the
1281dee1ad47SJeff Kirsher  *  changes.  If time expires while waiting for link up, we reset the DSP.
1282dee1ad47SJeff Kirsher  *  After reset, TX_CLK and CRS on Tx must be set.  Return successful upon
1283dee1ad47SJeff Kirsher  *  successful completion, else return corresponding error code.
1284dee1ad47SJeff Kirsher  **/
1285dee1ad47SJeff Kirsher s32 e1000e_phy_force_speed_duplex_m88(struct e1000_hw *hw)
1286dee1ad47SJeff Kirsher {
1287dee1ad47SJeff Kirsher 	struct e1000_phy_info *phy = &hw->phy;
1288dee1ad47SJeff Kirsher 	s32 ret_val;
1289dee1ad47SJeff Kirsher 	u16 phy_data;
1290dee1ad47SJeff Kirsher 	bool link;
1291dee1ad47SJeff Kirsher 
1292dee1ad47SJeff Kirsher 	/*
1293dee1ad47SJeff Kirsher 	 * Clear Auto-Crossover to force MDI manually.  M88E1000 requires MDI
1294dee1ad47SJeff Kirsher 	 * forced whenever speed and duplex are forced.
1295dee1ad47SJeff Kirsher 	 */
1296dee1ad47SJeff Kirsher 	ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1297dee1ad47SJeff Kirsher 	if (ret_val)
1298dee1ad47SJeff Kirsher 		return ret_val;
1299dee1ad47SJeff Kirsher 
1300dee1ad47SJeff Kirsher 	phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1301dee1ad47SJeff Kirsher 	ret_val = e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1302dee1ad47SJeff Kirsher 	if (ret_val)
1303dee1ad47SJeff Kirsher 		return ret_val;
1304dee1ad47SJeff Kirsher 
1305dee1ad47SJeff Kirsher 	e_dbg("M88E1000 PSCR: %X\n", phy_data);
1306dee1ad47SJeff Kirsher 
1307dee1ad47SJeff Kirsher 	ret_val = e1e_rphy(hw, PHY_CONTROL, &phy_data);
1308dee1ad47SJeff Kirsher 	if (ret_val)
1309dee1ad47SJeff Kirsher 		return ret_val;
1310dee1ad47SJeff Kirsher 
1311dee1ad47SJeff Kirsher 	e1000e_phy_force_speed_duplex_setup(hw, &phy_data);
1312dee1ad47SJeff Kirsher 
1313dee1ad47SJeff Kirsher 	ret_val = e1e_wphy(hw, PHY_CONTROL, phy_data);
1314dee1ad47SJeff Kirsher 	if (ret_val)
1315dee1ad47SJeff Kirsher 		return ret_val;
1316dee1ad47SJeff Kirsher 
1317dee1ad47SJeff Kirsher 	/* Reset the phy to commit changes. */
1318dee1ad47SJeff Kirsher 	ret_val = e1000e_commit_phy(hw);
1319dee1ad47SJeff Kirsher 	if (ret_val)
1320dee1ad47SJeff Kirsher 		return ret_val;
1321dee1ad47SJeff Kirsher 
1322dee1ad47SJeff Kirsher 	if (phy->autoneg_wait_to_complete) {
1323dee1ad47SJeff Kirsher 		e_dbg("Waiting for forced speed/duplex link on M88 phy.\n");
1324dee1ad47SJeff Kirsher 
1325dee1ad47SJeff Kirsher 		ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
1326dee1ad47SJeff Kirsher 						     100000, &link);
1327dee1ad47SJeff Kirsher 		if (ret_val)
1328dee1ad47SJeff Kirsher 			return ret_val;
1329dee1ad47SJeff Kirsher 
1330dee1ad47SJeff Kirsher 		if (!link) {
1331dee1ad47SJeff Kirsher 			if (hw->phy.type != e1000_phy_m88) {
1332dee1ad47SJeff Kirsher 				e_dbg("Link taking longer than expected.\n");
1333dee1ad47SJeff Kirsher 			} else {
1334dee1ad47SJeff Kirsher 				/*
1335dee1ad47SJeff Kirsher 				 * We didn't get link.
1336dee1ad47SJeff Kirsher 				 * Reset the DSP and cross our fingers.
1337dee1ad47SJeff Kirsher 				 */
1338dee1ad47SJeff Kirsher 				ret_val = e1e_wphy(hw, M88E1000_PHY_PAGE_SELECT,
1339dee1ad47SJeff Kirsher 						   0x001d);
1340dee1ad47SJeff Kirsher 				if (ret_val)
1341dee1ad47SJeff Kirsher 					return ret_val;
1342dee1ad47SJeff Kirsher 				ret_val = e1000e_phy_reset_dsp(hw);
1343dee1ad47SJeff Kirsher 				if (ret_val)
1344dee1ad47SJeff Kirsher 					return ret_val;
1345dee1ad47SJeff Kirsher 			}
1346dee1ad47SJeff Kirsher 		}
1347dee1ad47SJeff Kirsher 
1348dee1ad47SJeff Kirsher 		/* Try once more */
1349dee1ad47SJeff Kirsher 		ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
1350dee1ad47SJeff Kirsher 						     100000, &link);
1351dee1ad47SJeff Kirsher 		if (ret_val)
1352dee1ad47SJeff Kirsher 			return ret_val;
1353dee1ad47SJeff Kirsher 	}
1354dee1ad47SJeff Kirsher 
1355dee1ad47SJeff Kirsher 	if (hw->phy.type != e1000_phy_m88)
1356dee1ad47SJeff Kirsher 		return 0;
1357dee1ad47SJeff Kirsher 
1358dee1ad47SJeff Kirsher 	ret_val = e1e_rphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1359dee1ad47SJeff Kirsher 	if (ret_val)
1360dee1ad47SJeff Kirsher 		return ret_val;
1361dee1ad47SJeff Kirsher 
1362dee1ad47SJeff Kirsher 	/*
1363dee1ad47SJeff Kirsher 	 * Resetting the phy means we need to re-force TX_CLK in the
1364dee1ad47SJeff Kirsher 	 * Extended PHY Specific Control Register to 25MHz clock from
1365dee1ad47SJeff Kirsher 	 * the reset value of 2.5MHz.
1366dee1ad47SJeff Kirsher 	 */
1367dee1ad47SJeff Kirsher 	phy_data |= M88E1000_EPSCR_TX_CLK_25;
1368dee1ad47SJeff Kirsher 	ret_val = e1e_wphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1369dee1ad47SJeff Kirsher 	if (ret_val)
1370dee1ad47SJeff Kirsher 		return ret_val;
1371dee1ad47SJeff Kirsher 
1372dee1ad47SJeff Kirsher 	/*
1373dee1ad47SJeff Kirsher 	 * In addition, we must re-enable CRS on Tx for both half and full
1374dee1ad47SJeff Kirsher 	 * duplex.
1375dee1ad47SJeff Kirsher 	 */
1376dee1ad47SJeff Kirsher 	ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1377dee1ad47SJeff Kirsher 	if (ret_val)
1378dee1ad47SJeff Kirsher 		return ret_val;
1379dee1ad47SJeff Kirsher 
1380dee1ad47SJeff Kirsher 	phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1381dee1ad47SJeff Kirsher 	ret_val = e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1382dee1ad47SJeff Kirsher 
1383dee1ad47SJeff Kirsher 	return ret_val;
1384dee1ad47SJeff Kirsher }
1385dee1ad47SJeff Kirsher 
1386dee1ad47SJeff Kirsher /**
1387dee1ad47SJeff Kirsher  *  e1000_phy_force_speed_duplex_ife - Force PHY speed & duplex
1388dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
1389dee1ad47SJeff Kirsher  *
1390dee1ad47SJeff Kirsher  *  Forces the speed and duplex settings of the PHY.
1391dee1ad47SJeff Kirsher  *  This is a function pointer entry point only called by
1392dee1ad47SJeff Kirsher  *  PHY setup routines.
1393dee1ad47SJeff Kirsher  **/
1394dee1ad47SJeff Kirsher s32 e1000_phy_force_speed_duplex_ife(struct e1000_hw *hw)
1395dee1ad47SJeff Kirsher {
1396dee1ad47SJeff Kirsher 	struct e1000_phy_info *phy = &hw->phy;
1397dee1ad47SJeff Kirsher 	s32 ret_val;
1398dee1ad47SJeff Kirsher 	u16 data;
1399dee1ad47SJeff Kirsher 	bool link;
1400dee1ad47SJeff Kirsher 
1401dee1ad47SJeff Kirsher 	ret_val = e1e_rphy(hw, PHY_CONTROL, &data);
1402dee1ad47SJeff Kirsher 	if (ret_val)
1403dee1ad47SJeff Kirsher 		goto out;
1404dee1ad47SJeff Kirsher 
1405dee1ad47SJeff Kirsher 	e1000e_phy_force_speed_duplex_setup(hw, &data);
1406dee1ad47SJeff Kirsher 
1407dee1ad47SJeff Kirsher 	ret_val = e1e_wphy(hw, PHY_CONTROL, data);
1408dee1ad47SJeff Kirsher 	if (ret_val)
1409dee1ad47SJeff Kirsher 		goto out;
1410dee1ad47SJeff Kirsher 
1411dee1ad47SJeff Kirsher 	/* Disable MDI-X support for 10/100 */
1412dee1ad47SJeff Kirsher 	ret_val = e1e_rphy(hw, IFE_PHY_MDIX_CONTROL, &data);
1413dee1ad47SJeff Kirsher 	if (ret_val)
1414dee1ad47SJeff Kirsher 		goto out;
1415dee1ad47SJeff Kirsher 
1416dee1ad47SJeff Kirsher 	data &= ~IFE_PMC_AUTO_MDIX;
1417dee1ad47SJeff Kirsher 	data &= ~IFE_PMC_FORCE_MDIX;
1418dee1ad47SJeff Kirsher 
1419dee1ad47SJeff Kirsher 	ret_val = e1e_wphy(hw, IFE_PHY_MDIX_CONTROL, data);
1420dee1ad47SJeff Kirsher 	if (ret_val)
1421dee1ad47SJeff Kirsher 		goto out;
1422dee1ad47SJeff Kirsher 
1423dee1ad47SJeff Kirsher 	e_dbg("IFE PMC: %X\n", data);
1424dee1ad47SJeff Kirsher 
1425dee1ad47SJeff Kirsher 	udelay(1);
1426dee1ad47SJeff Kirsher 
1427dee1ad47SJeff Kirsher 	if (phy->autoneg_wait_to_complete) {
1428dee1ad47SJeff Kirsher 		e_dbg("Waiting for forced speed/duplex link on IFE phy.\n");
1429dee1ad47SJeff Kirsher 
1430dee1ad47SJeff Kirsher 		ret_val = e1000e_phy_has_link_generic(hw,
1431dee1ad47SJeff Kirsher 		                                     PHY_FORCE_LIMIT,
1432dee1ad47SJeff Kirsher 		                                     100000,
1433dee1ad47SJeff Kirsher 		                                     &link);
1434dee1ad47SJeff Kirsher 		if (ret_val)
1435dee1ad47SJeff Kirsher 			goto out;
1436dee1ad47SJeff Kirsher 
1437dee1ad47SJeff Kirsher 		if (!link)
1438dee1ad47SJeff Kirsher 			e_dbg("Link taking longer than expected.\n");
1439dee1ad47SJeff Kirsher 
1440dee1ad47SJeff Kirsher 		/* Try once more */
1441dee1ad47SJeff Kirsher 		ret_val = e1000e_phy_has_link_generic(hw,
1442dee1ad47SJeff Kirsher 		                                     PHY_FORCE_LIMIT,
1443dee1ad47SJeff Kirsher 		                                     100000,
1444dee1ad47SJeff Kirsher 		                                     &link);
1445dee1ad47SJeff Kirsher 		if (ret_val)
1446dee1ad47SJeff Kirsher 			goto out;
1447dee1ad47SJeff Kirsher 	}
1448dee1ad47SJeff Kirsher 
1449dee1ad47SJeff Kirsher out:
1450dee1ad47SJeff Kirsher 	return ret_val;
1451dee1ad47SJeff Kirsher }
1452dee1ad47SJeff Kirsher 
1453dee1ad47SJeff Kirsher /**
1454dee1ad47SJeff Kirsher  *  e1000e_phy_force_speed_duplex_setup - Configure forced PHY speed/duplex
1455dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
1456dee1ad47SJeff Kirsher  *  @phy_ctrl: pointer to current value of PHY_CONTROL
1457dee1ad47SJeff Kirsher  *
1458dee1ad47SJeff Kirsher  *  Forces speed and duplex on the PHY by doing the following: disable flow
1459dee1ad47SJeff Kirsher  *  control, force speed/duplex on the MAC, disable auto speed detection,
1460dee1ad47SJeff Kirsher  *  disable auto-negotiation, configure duplex, configure speed, configure
1461dee1ad47SJeff Kirsher  *  the collision distance, write configuration to CTRL register.  The
1462dee1ad47SJeff Kirsher  *  caller must write to the PHY_CONTROL register for these settings to
1463dee1ad47SJeff Kirsher  *  take affect.
1464dee1ad47SJeff Kirsher  **/
1465dee1ad47SJeff Kirsher void e1000e_phy_force_speed_duplex_setup(struct e1000_hw *hw, u16 *phy_ctrl)
1466dee1ad47SJeff Kirsher {
1467dee1ad47SJeff Kirsher 	struct e1000_mac_info *mac = &hw->mac;
1468dee1ad47SJeff Kirsher 	u32 ctrl;
1469dee1ad47SJeff Kirsher 
1470dee1ad47SJeff Kirsher 	/* Turn off flow control when forcing speed/duplex */
1471dee1ad47SJeff Kirsher 	hw->fc.current_mode = e1000_fc_none;
1472dee1ad47SJeff Kirsher 
1473dee1ad47SJeff Kirsher 	/* Force speed/duplex on the mac */
1474dee1ad47SJeff Kirsher 	ctrl = er32(CTRL);
1475dee1ad47SJeff Kirsher 	ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1476dee1ad47SJeff Kirsher 	ctrl &= ~E1000_CTRL_SPD_SEL;
1477dee1ad47SJeff Kirsher 
1478dee1ad47SJeff Kirsher 	/* Disable Auto Speed Detection */
1479dee1ad47SJeff Kirsher 	ctrl &= ~E1000_CTRL_ASDE;
1480dee1ad47SJeff Kirsher 
1481dee1ad47SJeff Kirsher 	/* Disable autoneg on the phy */
1482dee1ad47SJeff Kirsher 	*phy_ctrl &= ~MII_CR_AUTO_NEG_EN;
1483dee1ad47SJeff Kirsher 
1484dee1ad47SJeff Kirsher 	/* Forcing Full or Half Duplex? */
1485dee1ad47SJeff Kirsher 	if (mac->forced_speed_duplex & E1000_ALL_HALF_DUPLEX) {
1486dee1ad47SJeff Kirsher 		ctrl &= ~E1000_CTRL_FD;
1487dee1ad47SJeff Kirsher 		*phy_ctrl &= ~MII_CR_FULL_DUPLEX;
1488dee1ad47SJeff Kirsher 		e_dbg("Half Duplex\n");
1489dee1ad47SJeff Kirsher 	} else {
1490dee1ad47SJeff Kirsher 		ctrl |= E1000_CTRL_FD;
1491dee1ad47SJeff Kirsher 		*phy_ctrl |= MII_CR_FULL_DUPLEX;
1492dee1ad47SJeff Kirsher 		e_dbg("Full Duplex\n");
1493dee1ad47SJeff Kirsher 	}
1494dee1ad47SJeff Kirsher 
1495dee1ad47SJeff Kirsher 	/* Forcing 10mb or 100mb? */
1496dee1ad47SJeff Kirsher 	if (mac->forced_speed_duplex & E1000_ALL_100_SPEED) {
1497dee1ad47SJeff Kirsher 		ctrl |= E1000_CTRL_SPD_100;
1498dee1ad47SJeff Kirsher 		*phy_ctrl |= MII_CR_SPEED_100;
1499dee1ad47SJeff Kirsher 		*phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
1500dee1ad47SJeff Kirsher 		e_dbg("Forcing 100mb\n");
1501dee1ad47SJeff Kirsher 	} else {
1502dee1ad47SJeff Kirsher 		ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1503dee1ad47SJeff Kirsher 		*phy_ctrl |= MII_CR_SPEED_10;
1504dee1ad47SJeff Kirsher 		*phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
1505dee1ad47SJeff Kirsher 		e_dbg("Forcing 10mb\n");
1506dee1ad47SJeff Kirsher 	}
1507dee1ad47SJeff Kirsher 
1508dee1ad47SJeff Kirsher 	e1000e_config_collision_dist(hw);
1509dee1ad47SJeff Kirsher 
1510dee1ad47SJeff Kirsher 	ew32(CTRL, ctrl);
1511dee1ad47SJeff Kirsher }
1512dee1ad47SJeff Kirsher 
1513dee1ad47SJeff Kirsher /**
1514dee1ad47SJeff Kirsher  *  e1000e_set_d3_lplu_state - Sets low power link up state for D3
1515dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
1516dee1ad47SJeff Kirsher  *  @active: boolean used to enable/disable lplu
1517dee1ad47SJeff Kirsher  *
1518dee1ad47SJeff Kirsher  *  Success returns 0, Failure returns 1
1519dee1ad47SJeff Kirsher  *
1520dee1ad47SJeff Kirsher  *  The low power link up (lplu) state is set to the power management level D3
1521dee1ad47SJeff Kirsher  *  and SmartSpeed is disabled when active is true, else clear lplu for D3
1522dee1ad47SJeff Kirsher  *  and enable Smartspeed.  LPLU and Smartspeed are mutually exclusive.  LPLU
1523dee1ad47SJeff Kirsher  *  is used during Dx states where the power conservation is most important.
1524dee1ad47SJeff Kirsher  *  During driver activity, SmartSpeed should be enabled so performance is
1525dee1ad47SJeff Kirsher  *  maintained.
1526dee1ad47SJeff Kirsher  **/
1527dee1ad47SJeff Kirsher s32 e1000e_set_d3_lplu_state(struct e1000_hw *hw, bool active)
1528dee1ad47SJeff Kirsher {
1529dee1ad47SJeff Kirsher 	struct e1000_phy_info *phy = &hw->phy;
1530dee1ad47SJeff Kirsher 	s32 ret_val;
1531dee1ad47SJeff Kirsher 	u16 data;
1532dee1ad47SJeff Kirsher 
1533dee1ad47SJeff Kirsher 	ret_val = e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &data);
1534dee1ad47SJeff Kirsher 	if (ret_val)
1535dee1ad47SJeff Kirsher 		return ret_val;
1536dee1ad47SJeff Kirsher 
1537dee1ad47SJeff Kirsher 	if (!active) {
1538dee1ad47SJeff Kirsher 		data &= ~IGP02E1000_PM_D3_LPLU;
1539dee1ad47SJeff Kirsher 		ret_val = e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, data);
1540dee1ad47SJeff Kirsher 		if (ret_val)
1541dee1ad47SJeff Kirsher 			return ret_val;
1542dee1ad47SJeff Kirsher 		/*
1543dee1ad47SJeff Kirsher 		 * LPLU and SmartSpeed are mutually exclusive.  LPLU is used
1544dee1ad47SJeff Kirsher 		 * during Dx states where the power conservation is most
1545dee1ad47SJeff Kirsher 		 * important.  During driver activity we should enable
1546dee1ad47SJeff Kirsher 		 * SmartSpeed, so performance is maintained.
1547dee1ad47SJeff Kirsher 		 */
1548dee1ad47SJeff Kirsher 		if (phy->smart_speed == e1000_smart_speed_on) {
1549dee1ad47SJeff Kirsher 			ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
1550dee1ad47SJeff Kirsher 					   &data);
1551dee1ad47SJeff Kirsher 			if (ret_val)
1552dee1ad47SJeff Kirsher 				return ret_val;
1553dee1ad47SJeff Kirsher 
1554dee1ad47SJeff Kirsher 			data |= IGP01E1000_PSCFR_SMART_SPEED;
1555dee1ad47SJeff Kirsher 			ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
1556dee1ad47SJeff Kirsher 					   data);
1557dee1ad47SJeff Kirsher 			if (ret_val)
1558dee1ad47SJeff Kirsher 				return ret_val;
1559dee1ad47SJeff Kirsher 		} else if (phy->smart_speed == e1000_smart_speed_off) {
1560dee1ad47SJeff Kirsher 			ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
1561dee1ad47SJeff Kirsher 					   &data);
1562dee1ad47SJeff Kirsher 			if (ret_val)
1563dee1ad47SJeff Kirsher 				return ret_val;
1564dee1ad47SJeff Kirsher 
1565dee1ad47SJeff Kirsher 			data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1566dee1ad47SJeff Kirsher 			ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
1567dee1ad47SJeff Kirsher 					   data);
1568dee1ad47SJeff Kirsher 			if (ret_val)
1569dee1ad47SJeff Kirsher 				return ret_val;
1570dee1ad47SJeff Kirsher 		}
1571dee1ad47SJeff Kirsher 	} else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
1572dee1ad47SJeff Kirsher 		   (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
1573dee1ad47SJeff Kirsher 		   (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
1574dee1ad47SJeff Kirsher 		data |= IGP02E1000_PM_D3_LPLU;
1575dee1ad47SJeff Kirsher 		ret_val = e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, data);
1576dee1ad47SJeff Kirsher 		if (ret_val)
1577dee1ad47SJeff Kirsher 			return ret_val;
1578dee1ad47SJeff Kirsher 
1579dee1ad47SJeff Kirsher 		/* When LPLU is enabled, we should disable SmartSpeed */
1580dee1ad47SJeff Kirsher 		ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
1581dee1ad47SJeff Kirsher 		if (ret_val)
1582dee1ad47SJeff Kirsher 			return ret_val;
1583dee1ad47SJeff Kirsher 
1584dee1ad47SJeff Kirsher 		data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1585dee1ad47SJeff Kirsher 		ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
1586dee1ad47SJeff Kirsher 	}
1587dee1ad47SJeff Kirsher 
1588dee1ad47SJeff Kirsher 	return ret_val;
1589dee1ad47SJeff Kirsher }
1590dee1ad47SJeff Kirsher 
1591dee1ad47SJeff Kirsher /**
1592dee1ad47SJeff Kirsher  *  e1000e_check_downshift - Checks whether a downshift in speed occurred
1593dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
1594dee1ad47SJeff Kirsher  *
1595dee1ad47SJeff Kirsher  *  Success returns 0, Failure returns 1
1596dee1ad47SJeff Kirsher  *
1597dee1ad47SJeff Kirsher  *  A downshift is detected by querying the PHY link health.
1598dee1ad47SJeff Kirsher  **/
1599dee1ad47SJeff Kirsher s32 e1000e_check_downshift(struct e1000_hw *hw)
1600dee1ad47SJeff Kirsher {
1601dee1ad47SJeff Kirsher 	struct e1000_phy_info *phy = &hw->phy;
1602dee1ad47SJeff Kirsher 	s32 ret_val;
1603dee1ad47SJeff Kirsher 	u16 phy_data, offset, mask;
1604dee1ad47SJeff Kirsher 
1605dee1ad47SJeff Kirsher 	switch (phy->type) {
1606dee1ad47SJeff Kirsher 	case e1000_phy_m88:
1607dee1ad47SJeff Kirsher 	case e1000_phy_gg82563:
1608dee1ad47SJeff Kirsher 	case e1000_phy_bm:
1609dee1ad47SJeff Kirsher 	case e1000_phy_82578:
1610dee1ad47SJeff Kirsher 		offset	= M88E1000_PHY_SPEC_STATUS;
1611dee1ad47SJeff Kirsher 		mask	= M88E1000_PSSR_DOWNSHIFT;
1612dee1ad47SJeff Kirsher 		break;
1613dee1ad47SJeff Kirsher 	case e1000_phy_igp_2:
1614dee1ad47SJeff Kirsher 	case e1000_phy_igp_3:
1615dee1ad47SJeff Kirsher 		offset	= IGP01E1000_PHY_LINK_HEALTH;
1616dee1ad47SJeff Kirsher 		mask	= IGP01E1000_PLHR_SS_DOWNGRADE;
1617dee1ad47SJeff Kirsher 		break;
1618dee1ad47SJeff Kirsher 	default:
1619dee1ad47SJeff Kirsher 		/* speed downshift not supported */
1620dee1ad47SJeff Kirsher 		phy->speed_downgraded = false;
1621dee1ad47SJeff Kirsher 		return 0;
1622dee1ad47SJeff Kirsher 	}
1623dee1ad47SJeff Kirsher 
1624dee1ad47SJeff Kirsher 	ret_val = e1e_rphy(hw, offset, &phy_data);
1625dee1ad47SJeff Kirsher 
1626dee1ad47SJeff Kirsher 	if (!ret_val)
1627dee1ad47SJeff Kirsher 		phy->speed_downgraded = (phy_data & mask);
1628dee1ad47SJeff Kirsher 
1629dee1ad47SJeff Kirsher 	return ret_val;
1630dee1ad47SJeff Kirsher }
1631dee1ad47SJeff Kirsher 
1632dee1ad47SJeff Kirsher /**
1633dee1ad47SJeff Kirsher  *  e1000_check_polarity_m88 - Checks the polarity.
1634dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
1635dee1ad47SJeff Kirsher  *
1636dee1ad47SJeff Kirsher  *  Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1637dee1ad47SJeff Kirsher  *
1638dee1ad47SJeff Kirsher  *  Polarity is determined based on the PHY specific status register.
1639dee1ad47SJeff Kirsher  **/
1640dee1ad47SJeff Kirsher s32 e1000_check_polarity_m88(struct e1000_hw *hw)
1641dee1ad47SJeff Kirsher {
1642dee1ad47SJeff Kirsher 	struct e1000_phy_info *phy = &hw->phy;
1643dee1ad47SJeff Kirsher 	s32 ret_val;
1644dee1ad47SJeff Kirsher 	u16 data;
1645dee1ad47SJeff Kirsher 
1646dee1ad47SJeff Kirsher 	ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &data);
1647dee1ad47SJeff Kirsher 
1648dee1ad47SJeff Kirsher 	if (!ret_val)
1649dee1ad47SJeff Kirsher 		phy->cable_polarity = (data & M88E1000_PSSR_REV_POLARITY)
1650dee1ad47SJeff Kirsher 				      ? e1000_rev_polarity_reversed
1651dee1ad47SJeff Kirsher 				      : e1000_rev_polarity_normal;
1652dee1ad47SJeff Kirsher 
1653dee1ad47SJeff Kirsher 	return ret_val;
1654dee1ad47SJeff Kirsher }
1655dee1ad47SJeff Kirsher 
1656dee1ad47SJeff Kirsher /**
1657dee1ad47SJeff Kirsher  *  e1000_check_polarity_igp - Checks the polarity.
1658dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
1659dee1ad47SJeff Kirsher  *
1660dee1ad47SJeff Kirsher  *  Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1661dee1ad47SJeff Kirsher  *
1662dee1ad47SJeff Kirsher  *  Polarity is determined based on the PHY port status register, and the
1663dee1ad47SJeff Kirsher  *  current speed (since there is no polarity at 100Mbps).
1664dee1ad47SJeff Kirsher  **/
1665dee1ad47SJeff Kirsher s32 e1000_check_polarity_igp(struct e1000_hw *hw)
1666dee1ad47SJeff Kirsher {
1667dee1ad47SJeff Kirsher 	struct e1000_phy_info *phy = &hw->phy;
1668dee1ad47SJeff Kirsher 	s32 ret_val;
1669dee1ad47SJeff Kirsher 	u16 data, offset, mask;
1670dee1ad47SJeff Kirsher 
1671dee1ad47SJeff Kirsher 	/*
1672dee1ad47SJeff Kirsher 	 * Polarity is determined based on the speed of
1673dee1ad47SJeff Kirsher 	 * our connection.
1674dee1ad47SJeff Kirsher 	 */
1675dee1ad47SJeff Kirsher 	ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_STATUS, &data);
1676dee1ad47SJeff Kirsher 	if (ret_val)
1677dee1ad47SJeff Kirsher 		return ret_val;
1678dee1ad47SJeff Kirsher 
1679dee1ad47SJeff Kirsher 	if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
1680dee1ad47SJeff Kirsher 	    IGP01E1000_PSSR_SPEED_1000MBPS) {
1681dee1ad47SJeff Kirsher 		offset	= IGP01E1000_PHY_PCS_INIT_REG;
1682dee1ad47SJeff Kirsher 		mask	= IGP01E1000_PHY_POLARITY_MASK;
1683dee1ad47SJeff Kirsher 	} else {
1684dee1ad47SJeff Kirsher 		/*
1685dee1ad47SJeff Kirsher 		 * This really only applies to 10Mbps since
1686dee1ad47SJeff Kirsher 		 * there is no polarity for 100Mbps (always 0).
1687dee1ad47SJeff Kirsher 		 */
1688dee1ad47SJeff Kirsher 		offset	= IGP01E1000_PHY_PORT_STATUS;
1689dee1ad47SJeff Kirsher 		mask	= IGP01E1000_PSSR_POLARITY_REVERSED;
1690dee1ad47SJeff Kirsher 	}
1691dee1ad47SJeff Kirsher 
1692dee1ad47SJeff Kirsher 	ret_val = e1e_rphy(hw, offset, &data);
1693dee1ad47SJeff Kirsher 
1694dee1ad47SJeff Kirsher 	if (!ret_val)
1695dee1ad47SJeff Kirsher 		phy->cable_polarity = (data & mask)
1696dee1ad47SJeff Kirsher 				      ? e1000_rev_polarity_reversed
1697dee1ad47SJeff Kirsher 				      : e1000_rev_polarity_normal;
1698dee1ad47SJeff Kirsher 
1699dee1ad47SJeff Kirsher 	return ret_val;
1700dee1ad47SJeff Kirsher }
1701dee1ad47SJeff Kirsher 
1702dee1ad47SJeff Kirsher /**
1703dee1ad47SJeff Kirsher  *  e1000_check_polarity_ife - Check cable polarity for IFE PHY
1704dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
1705dee1ad47SJeff Kirsher  *
1706dee1ad47SJeff Kirsher  *  Polarity is determined on the polarity reversal feature being enabled.
1707dee1ad47SJeff Kirsher  **/
1708dee1ad47SJeff Kirsher s32 e1000_check_polarity_ife(struct e1000_hw *hw)
1709dee1ad47SJeff Kirsher {
1710dee1ad47SJeff Kirsher 	struct e1000_phy_info *phy = &hw->phy;
1711dee1ad47SJeff Kirsher 	s32 ret_val;
1712dee1ad47SJeff Kirsher 	u16 phy_data, offset, mask;
1713dee1ad47SJeff Kirsher 
1714dee1ad47SJeff Kirsher 	/*
1715dee1ad47SJeff Kirsher 	 * Polarity is determined based on the reversal feature being enabled.
1716dee1ad47SJeff Kirsher 	 */
1717dee1ad47SJeff Kirsher 	if (phy->polarity_correction) {
1718dee1ad47SJeff Kirsher 		offset = IFE_PHY_EXTENDED_STATUS_CONTROL;
1719dee1ad47SJeff Kirsher 		mask = IFE_PESC_POLARITY_REVERSED;
1720dee1ad47SJeff Kirsher 	} else {
1721dee1ad47SJeff Kirsher 		offset = IFE_PHY_SPECIAL_CONTROL;
1722dee1ad47SJeff Kirsher 		mask = IFE_PSC_FORCE_POLARITY;
1723dee1ad47SJeff Kirsher 	}
1724dee1ad47SJeff Kirsher 
1725dee1ad47SJeff Kirsher 	ret_val = e1e_rphy(hw, offset, &phy_data);
1726dee1ad47SJeff Kirsher 
1727dee1ad47SJeff Kirsher 	if (!ret_val)
1728dee1ad47SJeff Kirsher 		phy->cable_polarity = (phy_data & mask)
1729dee1ad47SJeff Kirsher 		                       ? e1000_rev_polarity_reversed
1730dee1ad47SJeff Kirsher 		                       : e1000_rev_polarity_normal;
1731dee1ad47SJeff Kirsher 
1732dee1ad47SJeff Kirsher 	return ret_val;
1733dee1ad47SJeff Kirsher }
1734dee1ad47SJeff Kirsher 
1735dee1ad47SJeff Kirsher /**
1736dee1ad47SJeff Kirsher  *  e1000_wait_autoneg - Wait for auto-neg completion
1737dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
1738dee1ad47SJeff Kirsher  *
1739dee1ad47SJeff Kirsher  *  Waits for auto-negotiation to complete or for the auto-negotiation time
1740dee1ad47SJeff Kirsher  *  limit to expire, which ever happens first.
1741dee1ad47SJeff Kirsher  **/
1742dee1ad47SJeff Kirsher static s32 e1000_wait_autoneg(struct e1000_hw *hw)
1743dee1ad47SJeff Kirsher {
1744dee1ad47SJeff Kirsher 	s32 ret_val = 0;
1745dee1ad47SJeff Kirsher 	u16 i, phy_status;
1746dee1ad47SJeff Kirsher 
1747dee1ad47SJeff Kirsher 	/* Break after autoneg completes or PHY_AUTO_NEG_LIMIT expires. */
1748dee1ad47SJeff Kirsher 	for (i = PHY_AUTO_NEG_LIMIT; i > 0; i--) {
1749dee1ad47SJeff Kirsher 		ret_val = e1e_rphy(hw, PHY_STATUS, &phy_status);
1750dee1ad47SJeff Kirsher 		if (ret_val)
1751dee1ad47SJeff Kirsher 			break;
1752dee1ad47SJeff Kirsher 		ret_val = e1e_rphy(hw, PHY_STATUS, &phy_status);
1753dee1ad47SJeff Kirsher 		if (ret_val)
1754dee1ad47SJeff Kirsher 			break;
1755dee1ad47SJeff Kirsher 		if (phy_status & MII_SR_AUTONEG_COMPLETE)
1756dee1ad47SJeff Kirsher 			break;
1757dee1ad47SJeff Kirsher 		msleep(100);
1758dee1ad47SJeff Kirsher 	}
1759dee1ad47SJeff Kirsher 
1760dee1ad47SJeff Kirsher 	/*
1761dee1ad47SJeff Kirsher 	 * PHY_AUTO_NEG_TIME expiration doesn't guarantee auto-negotiation
1762dee1ad47SJeff Kirsher 	 * has completed.
1763dee1ad47SJeff Kirsher 	 */
1764dee1ad47SJeff Kirsher 	return ret_val;
1765dee1ad47SJeff Kirsher }
1766dee1ad47SJeff Kirsher 
1767dee1ad47SJeff Kirsher /**
1768dee1ad47SJeff Kirsher  *  e1000e_phy_has_link_generic - Polls PHY for link
1769dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
1770dee1ad47SJeff Kirsher  *  @iterations: number of times to poll for link
1771dee1ad47SJeff Kirsher  *  @usec_interval: delay between polling attempts
1772dee1ad47SJeff Kirsher  *  @success: pointer to whether polling was successful or not
1773dee1ad47SJeff Kirsher  *
1774dee1ad47SJeff Kirsher  *  Polls the PHY status register for link, 'iterations' number of times.
1775dee1ad47SJeff Kirsher  **/
1776dee1ad47SJeff Kirsher s32 e1000e_phy_has_link_generic(struct e1000_hw *hw, u32 iterations,
1777dee1ad47SJeff Kirsher 			       u32 usec_interval, bool *success)
1778dee1ad47SJeff Kirsher {
1779dee1ad47SJeff Kirsher 	s32 ret_val = 0;
1780dee1ad47SJeff Kirsher 	u16 i, phy_status;
1781dee1ad47SJeff Kirsher 
1782dee1ad47SJeff Kirsher 	for (i = 0; i < iterations; i++) {
1783dee1ad47SJeff Kirsher 		/*
1784dee1ad47SJeff Kirsher 		 * Some PHYs require the PHY_STATUS register to be read
1785dee1ad47SJeff Kirsher 		 * twice due to the link bit being sticky.  No harm doing
1786dee1ad47SJeff Kirsher 		 * it across the board.
1787dee1ad47SJeff Kirsher 		 */
1788dee1ad47SJeff Kirsher 		ret_val = e1e_rphy(hw, PHY_STATUS, &phy_status);
1789dee1ad47SJeff Kirsher 		if (ret_val)
1790dee1ad47SJeff Kirsher 			/*
1791dee1ad47SJeff Kirsher 			 * If the first read fails, another entity may have
1792dee1ad47SJeff Kirsher 			 * ownership of the resources, wait and try again to
1793dee1ad47SJeff Kirsher 			 * see if they have relinquished the resources yet.
1794dee1ad47SJeff Kirsher 			 */
1795dee1ad47SJeff Kirsher 			udelay(usec_interval);
1796dee1ad47SJeff Kirsher 		ret_val = e1e_rphy(hw, PHY_STATUS, &phy_status);
1797dee1ad47SJeff Kirsher 		if (ret_val)
1798dee1ad47SJeff Kirsher 			break;
1799dee1ad47SJeff Kirsher 		if (phy_status & MII_SR_LINK_STATUS)
1800dee1ad47SJeff Kirsher 			break;
1801dee1ad47SJeff Kirsher 		if (usec_interval >= 1000)
1802dee1ad47SJeff Kirsher 			mdelay(usec_interval/1000);
1803dee1ad47SJeff Kirsher 		else
1804dee1ad47SJeff Kirsher 			udelay(usec_interval);
1805dee1ad47SJeff Kirsher 	}
1806dee1ad47SJeff Kirsher 
1807dee1ad47SJeff Kirsher 	*success = (i < iterations);
1808dee1ad47SJeff Kirsher 
1809dee1ad47SJeff Kirsher 	return ret_val;
1810dee1ad47SJeff Kirsher }
1811dee1ad47SJeff Kirsher 
1812dee1ad47SJeff Kirsher /**
1813dee1ad47SJeff Kirsher  *  e1000e_get_cable_length_m88 - Determine cable length for m88 PHY
1814dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
1815dee1ad47SJeff Kirsher  *
1816dee1ad47SJeff Kirsher  *  Reads the PHY specific status register to retrieve the cable length
1817dee1ad47SJeff Kirsher  *  information.  The cable length is determined by averaging the minimum and
1818dee1ad47SJeff Kirsher  *  maximum values to get the "average" cable length.  The m88 PHY has four
1819dee1ad47SJeff Kirsher  *  possible cable length values, which are:
1820dee1ad47SJeff Kirsher  *	Register Value		Cable Length
1821dee1ad47SJeff Kirsher  *	0			< 50 meters
1822dee1ad47SJeff Kirsher  *	1			50 - 80 meters
1823dee1ad47SJeff Kirsher  *	2			80 - 110 meters
1824dee1ad47SJeff Kirsher  *	3			110 - 140 meters
1825dee1ad47SJeff Kirsher  *	4			> 140 meters
1826dee1ad47SJeff Kirsher  **/
1827dee1ad47SJeff Kirsher s32 e1000e_get_cable_length_m88(struct e1000_hw *hw)
1828dee1ad47SJeff Kirsher {
1829dee1ad47SJeff Kirsher 	struct e1000_phy_info *phy = &hw->phy;
1830dee1ad47SJeff Kirsher 	s32 ret_val;
1831dee1ad47SJeff Kirsher 	u16 phy_data, index;
1832dee1ad47SJeff Kirsher 
1833dee1ad47SJeff Kirsher 	ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
1834dee1ad47SJeff Kirsher 	if (ret_val)
1835dee1ad47SJeff Kirsher 		goto out;
1836dee1ad47SJeff Kirsher 
1837dee1ad47SJeff Kirsher 	index = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
1838dee1ad47SJeff Kirsher 	        M88E1000_PSSR_CABLE_LENGTH_SHIFT;
1839dee1ad47SJeff Kirsher 	if (index >= M88E1000_CABLE_LENGTH_TABLE_SIZE - 1) {
1840dee1ad47SJeff Kirsher 		ret_val = -E1000_ERR_PHY;
1841dee1ad47SJeff Kirsher 		goto out;
1842dee1ad47SJeff Kirsher 	}
1843dee1ad47SJeff Kirsher 
1844dee1ad47SJeff Kirsher 	phy->min_cable_length = e1000_m88_cable_length_table[index];
1845dee1ad47SJeff Kirsher 	phy->max_cable_length = e1000_m88_cable_length_table[index + 1];
1846dee1ad47SJeff Kirsher 
1847dee1ad47SJeff Kirsher 	phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
1848dee1ad47SJeff Kirsher 
1849dee1ad47SJeff Kirsher out:
1850dee1ad47SJeff Kirsher 	return ret_val;
1851dee1ad47SJeff Kirsher }
1852dee1ad47SJeff Kirsher 
1853dee1ad47SJeff Kirsher /**
1854dee1ad47SJeff Kirsher  *  e1000e_get_cable_length_igp_2 - Determine cable length for igp2 PHY
1855dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
1856dee1ad47SJeff Kirsher  *
1857dee1ad47SJeff Kirsher  *  The automatic gain control (agc) normalizes the amplitude of the
1858dee1ad47SJeff Kirsher  *  received signal, adjusting for the attenuation produced by the
1859dee1ad47SJeff Kirsher  *  cable.  By reading the AGC registers, which represent the
1860dee1ad47SJeff Kirsher  *  combination of coarse and fine gain value, the value can be put
1861dee1ad47SJeff Kirsher  *  into a lookup table to obtain the approximate cable length
1862dee1ad47SJeff Kirsher  *  for each channel.
1863dee1ad47SJeff Kirsher  **/
1864dee1ad47SJeff Kirsher s32 e1000e_get_cable_length_igp_2(struct e1000_hw *hw)
1865dee1ad47SJeff Kirsher {
1866dee1ad47SJeff Kirsher 	struct e1000_phy_info *phy = &hw->phy;
1867dee1ad47SJeff Kirsher 	s32 ret_val;
1868dee1ad47SJeff Kirsher 	u16 phy_data, i, agc_value = 0;
1869dee1ad47SJeff Kirsher 	u16 cur_agc_index, max_agc_index = 0;
1870dee1ad47SJeff Kirsher 	u16 min_agc_index = IGP02E1000_CABLE_LENGTH_TABLE_SIZE - 1;
1871dee1ad47SJeff Kirsher 	static const u16 agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] = {
1872dee1ad47SJeff Kirsher 	       IGP02E1000_PHY_AGC_A,
1873dee1ad47SJeff Kirsher 	       IGP02E1000_PHY_AGC_B,
1874dee1ad47SJeff Kirsher 	       IGP02E1000_PHY_AGC_C,
1875dee1ad47SJeff Kirsher 	       IGP02E1000_PHY_AGC_D
1876dee1ad47SJeff Kirsher 	};
1877dee1ad47SJeff Kirsher 
1878dee1ad47SJeff Kirsher 	/* Read the AGC registers for all channels */
1879dee1ad47SJeff Kirsher 	for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
1880dee1ad47SJeff Kirsher 		ret_val = e1e_rphy(hw, agc_reg_array[i], &phy_data);
1881dee1ad47SJeff Kirsher 		if (ret_val)
1882dee1ad47SJeff Kirsher 			return ret_val;
1883dee1ad47SJeff Kirsher 
1884dee1ad47SJeff Kirsher 		/*
1885dee1ad47SJeff Kirsher 		 * Getting bits 15:9, which represent the combination of
1886dee1ad47SJeff Kirsher 		 * coarse and fine gain values.  The result is a number
1887dee1ad47SJeff Kirsher 		 * that can be put into the lookup table to obtain the
1888dee1ad47SJeff Kirsher 		 * approximate cable length.
1889dee1ad47SJeff Kirsher 		 */
1890dee1ad47SJeff Kirsher 		cur_agc_index = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
1891dee1ad47SJeff Kirsher 				IGP02E1000_AGC_LENGTH_MASK;
1892dee1ad47SJeff Kirsher 
1893dee1ad47SJeff Kirsher 		/* Array index bound check. */
1894dee1ad47SJeff Kirsher 		if ((cur_agc_index >= IGP02E1000_CABLE_LENGTH_TABLE_SIZE) ||
1895dee1ad47SJeff Kirsher 		    (cur_agc_index == 0))
1896dee1ad47SJeff Kirsher 			return -E1000_ERR_PHY;
1897dee1ad47SJeff Kirsher 
1898dee1ad47SJeff Kirsher 		/* Remove min & max AGC values from calculation. */
1899dee1ad47SJeff Kirsher 		if (e1000_igp_2_cable_length_table[min_agc_index] >
1900dee1ad47SJeff Kirsher 		    e1000_igp_2_cable_length_table[cur_agc_index])
1901dee1ad47SJeff Kirsher 			min_agc_index = cur_agc_index;
1902dee1ad47SJeff Kirsher 		if (e1000_igp_2_cable_length_table[max_agc_index] <
1903dee1ad47SJeff Kirsher 		    e1000_igp_2_cable_length_table[cur_agc_index])
1904dee1ad47SJeff Kirsher 			max_agc_index = cur_agc_index;
1905dee1ad47SJeff Kirsher 
1906dee1ad47SJeff Kirsher 		agc_value += e1000_igp_2_cable_length_table[cur_agc_index];
1907dee1ad47SJeff Kirsher 	}
1908dee1ad47SJeff Kirsher 
1909dee1ad47SJeff Kirsher 	agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] +
1910dee1ad47SJeff Kirsher 		      e1000_igp_2_cable_length_table[max_agc_index]);
1911dee1ad47SJeff Kirsher 	agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
1912dee1ad47SJeff Kirsher 
1913dee1ad47SJeff Kirsher 	/* Calculate cable length with the error range of +/- 10 meters. */
1914dee1ad47SJeff Kirsher 	phy->min_cable_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
1915dee1ad47SJeff Kirsher 				 (agc_value - IGP02E1000_AGC_RANGE) : 0;
1916dee1ad47SJeff Kirsher 	phy->max_cable_length = agc_value + IGP02E1000_AGC_RANGE;
1917dee1ad47SJeff Kirsher 
1918dee1ad47SJeff Kirsher 	phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
1919dee1ad47SJeff Kirsher 
1920dee1ad47SJeff Kirsher 	return ret_val;
1921dee1ad47SJeff Kirsher }
1922dee1ad47SJeff Kirsher 
1923dee1ad47SJeff Kirsher /**
1924dee1ad47SJeff Kirsher  *  e1000e_get_phy_info_m88 - Retrieve PHY information
1925dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
1926dee1ad47SJeff Kirsher  *
1927dee1ad47SJeff Kirsher  *  Valid for only copper links.  Read the PHY status register (sticky read)
1928dee1ad47SJeff Kirsher  *  to verify that link is up.  Read the PHY special control register to
1929dee1ad47SJeff Kirsher  *  determine the polarity and 10base-T extended distance.  Read the PHY
1930dee1ad47SJeff Kirsher  *  special status register to determine MDI/MDIx and current speed.  If
1931dee1ad47SJeff Kirsher  *  speed is 1000, then determine cable length, local and remote receiver.
1932dee1ad47SJeff Kirsher  **/
1933dee1ad47SJeff Kirsher s32 e1000e_get_phy_info_m88(struct e1000_hw *hw)
1934dee1ad47SJeff Kirsher {
1935dee1ad47SJeff Kirsher 	struct e1000_phy_info *phy = &hw->phy;
1936dee1ad47SJeff Kirsher 	s32  ret_val;
1937dee1ad47SJeff Kirsher 	u16 phy_data;
1938dee1ad47SJeff Kirsher 	bool link;
1939dee1ad47SJeff Kirsher 
1940dee1ad47SJeff Kirsher 	if (phy->media_type != e1000_media_type_copper) {
1941dee1ad47SJeff Kirsher 		e_dbg("Phy info is only valid for copper media\n");
1942dee1ad47SJeff Kirsher 		return -E1000_ERR_CONFIG;
1943dee1ad47SJeff Kirsher 	}
1944dee1ad47SJeff Kirsher 
1945dee1ad47SJeff Kirsher 	ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
1946dee1ad47SJeff Kirsher 	if (ret_val)
1947dee1ad47SJeff Kirsher 		return ret_val;
1948dee1ad47SJeff Kirsher 
1949dee1ad47SJeff Kirsher 	if (!link) {
1950dee1ad47SJeff Kirsher 		e_dbg("Phy info is only valid if link is up\n");
1951dee1ad47SJeff Kirsher 		return -E1000_ERR_CONFIG;
1952dee1ad47SJeff Kirsher 	}
1953dee1ad47SJeff Kirsher 
1954dee1ad47SJeff Kirsher 	ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1955dee1ad47SJeff Kirsher 	if (ret_val)
1956dee1ad47SJeff Kirsher 		return ret_val;
1957dee1ad47SJeff Kirsher 
1958dee1ad47SJeff Kirsher 	phy->polarity_correction = (phy_data &
1959dee1ad47SJeff Kirsher 				    M88E1000_PSCR_POLARITY_REVERSAL);
1960dee1ad47SJeff Kirsher 
1961dee1ad47SJeff Kirsher 	ret_val = e1000_check_polarity_m88(hw);
1962dee1ad47SJeff Kirsher 	if (ret_val)
1963dee1ad47SJeff Kirsher 		return ret_val;
1964dee1ad47SJeff Kirsher 
1965dee1ad47SJeff Kirsher 	ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
1966dee1ad47SJeff Kirsher 	if (ret_val)
1967dee1ad47SJeff Kirsher 		return ret_val;
1968dee1ad47SJeff Kirsher 
1969dee1ad47SJeff Kirsher 	phy->is_mdix = (phy_data & M88E1000_PSSR_MDIX);
1970dee1ad47SJeff Kirsher 
1971dee1ad47SJeff Kirsher 	if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
1972dee1ad47SJeff Kirsher 		ret_val = e1000_get_cable_length(hw);
1973dee1ad47SJeff Kirsher 		if (ret_val)
1974dee1ad47SJeff Kirsher 			return ret_val;
1975dee1ad47SJeff Kirsher 
1976dee1ad47SJeff Kirsher 		ret_val = e1e_rphy(hw, PHY_1000T_STATUS, &phy_data);
1977dee1ad47SJeff Kirsher 		if (ret_val)
1978dee1ad47SJeff Kirsher 			return ret_val;
1979dee1ad47SJeff Kirsher 
1980dee1ad47SJeff Kirsher 		phy->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS)
1981dee1ad47SJeff Kirsher 				? e1000_1000t_rx_status_ok
1982dee1ad47SJeff Kirsher 				: e1000_1000t_rx_status_not_ok;
1983dee1ad47SJeff Kirsher 
1984dee1ad47SJeff Kirsher 		phy->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS)
1985dee1ad47SJeff Kirsher 				 ? e1000_1000t_rx_status_ok
1986dee1ad47SJeff Kirsher 				 : e1000_1000t_rx_status_not_ok;
1987dee1ad47SJeff Kirsher 	} else {
1988dee1ad47SJeff Kirsher 		/* Set values to "undefined" */
1989dee1ad47SJeff Kirsher 		phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
1990dee1ad47SJeff Kirsher 		phy->local_rx = e1000_1000t_rx_status_undefined;
1991dee1ad47SJeff Kirsher 		phy->remote_rx = e1000_1000t_rx_status_undefined;
1992dee1ad47SJeff Kirsher 	}
1993dee1ad47SJeff Kirsher 
1994dee1ad47SJeff Kirsher 	return ret_val;
1995dee1ad47SJeff Kirsher }
1996dee1ad47SJeff Kirsher 
1997dee1ad47SJeff Kirsher /**
1998dee1ad47SJeff Kirsher  *  e1000e_get_phy_info_igp - Retrieve igp PHY information
1999dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
2000dee1ad47SJeff Kirsher  *
2001dee1ad47SJeff Kirsher  *  Read PHY status to determine if link is up.  If link is up, then
2002dee1ad47SJeff Kirsher  *  set/determine 10base-T extended distance and polarity correction.  Read
2003dee1ad47SJeff Kirsher  *  PHY port status to determine MDI/MDIx and speed.  Based on the speed,
2004dee1ad47SJeff Kirsher  *  determine on the cable length, local and remote receiver.
2005dee1ad47SJeff Kirsher  **/
2006dee1ad47SJeff Kirsher s32 e1000e_get_phy_info_igp(struct e1000_hw *hw)
2007dee1ad47SJeff Kirsher {
2008dee1ad47SJeff Kirsher 	struct e1000_phy_info *phy = &hw->phy;
2009dee1ad47SJeff Kirsher 	s32 ret_val;
2010dee1ad47SJeff Kirsher 	u16 data;
2011dee1ad47SJeff Kirsher 	bool link;
2012dee1ad47SJeff Kirsher 
2013dee1ad47SJeff Kirsher 	ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
2014dee1ad47SJeff Kirsher 	if (ret_val)
2015dee1ad47SJeff Kirsher 		return ret_val;
2016dee1ad47SJeff Kirsher 
2017dee1ad47SJeff Kirsher 	if (!link) {
2018dee1ad47SJeff Kirsher 		e_dbg("Phy info is only valid if link is up\n");
2019dee1ad47SJeff Kirsher 		return -E1000_ERR_CONFIG;
2020dee1ad47SJeff Kirsher 	}
2021dee1ad47SJeff Kirsher 
2022dee1ad47SJeff Kirsher 	phy->polarity_correction = true;
2023dee1ad47SJeff Kirsher 
2024dee1ad47SJeff Kirsher 	ret_val = e1000_check_polarity_igp(hw);
2025dee1ad47SJeff Kirsher 	if (ret_val)
2026dee1ad47SJeff Kirsher 		return ret_val;
2027dee1ad47SJeff Kirsher 
2028dee1ad47SJeff Kirsher 	ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_STATUS, &data);
2029dee1ad47SJeff Kirsher 	if (ret_val)
2030dee1ad47SJeff Kirsher 		return ret_val;
2031dee1ad47SJeff Kirsher 
2032dee1ad47SJeff Kirsher 	phy->is_mdix = (data & IGP01E1000_PSSR_MDIX);
2033dee1ad47SJeff Kirsher 
2034dee1ad47SJeff Kirsher 	if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
2035dee1ad47SJeff Kirsher 	    IGP01E1000_PSSR_SPEED_1000MBPS) {
2036dee1ad47SJeff Kirsher 		ret_val = e1000_get_cable_length(hw);
2037dee1ad47SJeff Kirsher 		if (ret_val)
2038dee1ad47SJeff Kirsher 			return ret_val;
2039dee1ad47SJeff Kirsher 
2040dee1ad47SJeff Kirsher 		ret_val = e1e_rphy(hw, PHY_1000T_STATUS, &data);
2041dee1ad47SJeff Kirsher 		if (ret_val)
2042dee1ad47SJeff Kirsher 			return ret_val;
2043dee1ad47SJeff Kirsher 
2044dee1ad47SJeff Kirsher 		phy->local_rx = (data & SR_1000T_LOCAL_RX_STATUS)
2045dee1ad47SJeff Kirsher 				? e1000_1000t_rx_status_ok
2046dee1ad47SJeff Kirsher 				: e1000_1000t_rx_status_not_ok;
2047dee1ad47SJeff Kirsher 
2048dee1ad47SJeff Kirsher 		phy->remote_rx = (data & SR_1000T_REMOTE_RX_STATUS)
2049dee1ad47SJeff Kirsher 				 ? e1000_1000t_rx_status_ok
2050dee1ad47SJeff Kirsher 				 : e1000_1000t_rx_status_not_ok;
2051dee1ad47SJeff Kirsher 	} else {
2052dee1ad47SJeff Kirsher 		phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
2053dee1ad47SJeff Kirsher 		phy->local_rx = e1000_1000t_rx_status_undefined;
2054dee1ad47SJeff Kirsher 		phy->remote_rx = e1000_1000t_rx_status_undefined;
2055dee1ad47SJeff Kirsher 	}
2056dee1ad47SJeff Kirsher 
2057dee1ad47SJeff Kirsher 	return ret_val;
2058dee1ad47SJeff Kirsher }
2059dee1ad47SJeff Kirsher 
2060dee1ad47SJeff Kirsher /**
2061dee1ad47SJeff Kirsher  *  e1000_get_phy_info_ife - Retrieves various IFE PHY states
2062dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
2063dee1ad47SJeff Kirsher  *
2064dee1ad47SJeff Kirsher  *  Populates "phy" structure with various feature states.
2065dee1ad47SJeff Kirsher  **/
2066dee1ad47SJeff Kirsher s32 e1000_get_phy_info_ife(struct e1000_hw *hw)
2067dee1ad47SJeff Kirsher {
2068dee1ad47SJeff Kirsher 	struct e1000_phy_info *phy = &hw->phy;
2069dee1ad47SJeff Kirsher 	s32 ret_val;
2070dee1ad47SJeff Kirsher 	u16 data;
2071dee1ad47SJeff Kirsher 	bool link;
2072dee1ad47SJeff Kirsher 
2073dee1ad47SJeff Kirsher 	ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
2074dee1ad47SJeff Kirsher 	if (ret_val)
2075dee1ad47SJeff Kirsher 		goto out;
2076dee1ad47SJeff Kirsher 
2077dee1ad47SJeff Kirsher 	if (!link) {
2078dee1ad47SJeff Kirsher 		e_dbg("Phy info is only valid if link is up\n");
2079dee1ad47SJeff Kirsher 		ret_val = -E1000_ERR_CONFIG;
2080dee1ad47SJeff Kirsher 		goto out;
2081dee1ad47SJeff Kirsher 	}
2082dee1ad47SJeff Kirsher 
2083dee1ad47SJeff Kirsher 	ret_val = e1e_rphy(hw, IFE_PHY_SPECIAL_CONTROL, &data);
2084dee1ad47SJeff Kirsher 	if (ret_val)
2085dee1ad47SJeff Kirsher 		goto out;
2086dee1ad47SJeff Kirsher 	phy->polarity_correction = (data & IFE_PSC_AUTO_POLARITY_DISABLE)
2087dee1ad47SJeff Kirsher 	                           ? false : true;
2088dee1ad47SJeff Kirsher 
2089dee1ad47SJeff Kirsher 	if (phy->polarity_correction) {
2090dee1ad47SJeff Kirsher 		ret_val = e1000_check_polarity_ife(hw);
2091dee1ad47SJeff Kirsher 		if (ret_val)
2092dee1ad47SJeff Kirsher 			goto out;
2093dee1ad47SJeff Kirsher 	} else {
2094dee1ad47SJeff Kirsher 		/* Polarity is forced */
2095dee1ad47SJeff Kirsher 		phy->cable_polarity = (data & IFE_PSC_FORCE_POLARITY)
2096dee1ad47SJeff Kirsher 		                      ? e1000_rev_polarity_reversed
2097dee1ad47SJeff Kirsher 		                      : e1000_rev_polarity_normal;
2098dee1ad47SJeff Kirsher 	}
2099dee1ad47SJeff Kirsher 
2100dee1ad47SJeff Kirsher 	ret_val = e1e_rphy(hw, IFE_PHY_MDIX_CONTROL, &data);
2101dee1ad47SJeff Kirsher 	if (ret_val)
2102dee1ad47SJeff Kirsher 		goto out;
2103dee1ad47SJeff Kirsher 
2104dee1ad47SJeff Kirsher 	phy->is_mdix = (data & IFE_PMC_MDIX_STATUS) ? true : false;
2105dee1ad47SJeff Kirsher 
2106dee1ad47SJeff Kirsher 	/* The following parameters are undefined for 10/100 operation. */
2107dee1ad47SJeff Kirsher 	phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
2108dee1ad47SJeff Kirsher 	phy->local_rx = e1000_1000t_rx_status_undefined;
2109dee1ad47SJeff Kirsher 	phy->remote_rx = e1000_1000t_rx_status_undefined;
2110dee1ad47SJeff Kirsher 
2111dee1ad47SJeff Kirsher out:
2112dee1ad47SJeff Kirsher 	return ret_val;
2113dee1ad47SJeff Kirsher }
2114dee1ad47SJeff Kirsher 
2115dee1ad47SJeff Kirsher /**
2116dee1ad47SJeff Kirsher  *  e1000e_phy_sw_reset - PHY software reset
2117dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
2118dee1ad47SJeff Kirsher  *
2119dee1ad47SJeff Kirsher  *  Does a software reset of the PHY by reading the PHY control register and
2120dee1ad47SJeff Kirsher  *  setting/write the control register reset bit to the PHY.
2121dee1ad47SJeff Kirsher  **/
2122dee1ad47SJeff Kirsher s32 e1000e_phy_sw_reset(struct e1000_hw *hw)
2123dee1ad47SJeff Kirsher {
2124dee1ad47SJeff Kirsher 	s32 ret_val;
2125dee1ad47SJeff Kirsher 	u16 phy_ctrl;
2126dee1ad47SJeff Kirsher 
2127dee1ad47SJeff Kirsher 	ret_val = e1e_rphy(hw, PHY_CONTROL, &phy_ctrl);
2128dee1ad47SJeff Kirsher 	if (ret_val)
2129dee1ad47SJeff Kirsher 		return ret_val;
2130dee1ad47SJeff Kirsher 
2131dee1ad47SJeff Kirsher 	phy_ctrl |= MII_CR_RESET;
2132dee1ad47SJeff Kirsher 	ret_val = e1e_wphy(hw, PHY_CONTROL, phy_ctrl);
2133dee1ad47SJeff Kirsher 	if (ret_val)
2134dee1ad47SJeff Kirsher 		return ret_val;
2135dee1ad47SJeff Kirsher 
2136dee1ad47SJeff Kirsher 	udelay(1);
2137dee1ad47SJeff Kirsher 
2138dee1ad47SJeff Kirsher 	return ret_val;
2139dee1ad47SJeff Kirsher }
2140dee1ad47SJeff Kirsher 
2141dee1ad47SJeff Kirsher /**
2142dee1ad47SJeff Kirsher  *  e1000e_phy_hw_reset_generic - PHY hardware reset
2143dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
2144dee1ad47SJeff Kirsher  *
2145dee1ad47SJeff Kirsher  *  Verify the reset block is not blocking us from resetting.  Acquire
2146dee1ad47SJeff Kirsher  *  semaphore (if necessary) and read/set/write the device control reset
2147dee1ad47SJeff Kirsher  *  bit in the PHY.  Wait the appropriate delay time for the device to
2148dee1ad47SJeff Kirsher  *  reset and release the semaphore (if necessary).
2149dee1ad47SJeff Kirsher  **/
2150dee1ad47SJeff Kirsher s32 e1000e_phy_hw_reset_generic(struct e1000_hw *hw)
2151dee1ad47SJeff Kirsher {
2152dee1ad47SJeff Kirsher 	struct e1000_phy_info *phy = &hw->phy;
2153dee1ad47SJeff Kirsher 	s32 ret_val;
2154dee1ad47SJeff Kirsher 	u32 ctrl;
2155dee1ad47SJeff Kirsher 
2156dee1ad47SJeff Kirsher 	ret_val = e1000_check_reset_block(hw);
2157dee1ad47SJeff Kirsher 	if (ret_val)
2158dee1ad47SJeff Kirsher 		return 0;
2159dee1ad47SJeff Kirsher 
2160dee1ad47SJeff Kirsher 	ret_val = phy->ops.acquire(hw);
2161dee1ad47SJeff Kirsher 	if (ret_val)
2162dee1ad47SJeff Kirsher 		return ret_val;
2163dee1ad47SJeff Kirsher 
2164dee1ad47SJeff Kirsher 	ctrl = er32(CTRL);
2165dee1ad47SJeff Kirsher 	ew32(CTRL, ctrl | E1000_CTRL_PHY_RST);
2166dee1ad47SJeff Kirsher 	e1e_flush();
2167dee1ad47SJeff Kirsher 
2168dee1ad47SJeff Kirsher 	udelay(phy->reset_delay_us);
2169dee1ad47SJeff Kirsher 
2170dee1ad47SJeff Kirsher 	ew32(CTRL, ctrl);
2171dee1ad47SJeff Kirsher 	e1e_flush();
2172dee1ad47SJeff Kirsher 
2173dee1ad47SJeff Kirsher 	udelay(150);
2174dee1ad47SJeff Kirsher 
2175dee1ad47SJeff Kirsher 	phy->ops.release(hw);
2176dee1ad47SJeff Kirsher 
2177dee1ad47SJeff Kirsher 	return e1000_get_phy_cfg_done(hw);
2178dee1ad47SJeff Kirsher }
2179dee1ad47SJeff Kirsher 
2180dee1ad47SJeff Kirsher /**
2181dee1ad47SJeff Kirsher  *  e1000e_get_cfg_done - Generic configuration done
2182dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
2183dee1ad47SJeff Kirsher  *
2184dee1ad47SJeff Kirsher  *  Generic function to wait 10 milli-seconds for configuration to complete
2185dee1ad47SJeff Kirsher  *  and return success.
2186dee1ad47SJeff Kirsher  **/
2187dee1ad47SJeff Kirsher s32 e1000e_get_cfg_done(struct e1000_hw *hw)
2188dee1ad47SJeff Kirsher {
2189dee1ad47SJeff Kirsher 	mdelay(10);
2190dee1ad47SJeff Kirsher 	return 0;
2191dee1ad47SJeff Kirsher }
2192dee1ad47SJeff Kirsher 
2193dee1ad47SJeff Kirsher /**
2194dee1ad47SJeff Kirsher  *  e1000e_phy_init_script_igp3 - Inits the IGP3 PHY
2195dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
2196dee1ad47SJeff Kirsher  *
2197dee1ad47SJeff Kirsher  *  Initializes a Intel Gigabit PHY3 when an EEPROM is not present.
2198dee1ad47SJeff Kirsher  **/
2199dee1ad47SJeff Kirsher s32 e1000e_phy_init_script_igp3(struct e1000_hw *hw)
2200dee1ad47SJeff Kirsher {
2201dee1ad47SJeff Kirsher 	e_dbg("Running IGP 3 PHY init script\n");
2202dee1ad47SJeff Kirsher 
2203dee1ad47SJeff Kirsher 	/* PHY init IGP 3 */
2204dee1ad47SJeff Kirsher 	/* Enable rise/fall, 10-mode work in class-A */
2205dee1ad47SJeff Kirsher 	e1e_wphy(hw, 0x2F5B, 0x9018);
2206dee1ad47SJeff Kirsher 	/* Remove all caps from Replica path filter */
2207dee1ad47SJeff Kirsher 	e1e_wphy(hw, 0x2F52, 0x0000);
2208dee1ad47SJeff Kirsher 	/* Bias trimming for ADC, AFE and Driver (Default) */
2209dee1ad47SJeff Kirsher 	e1e_wphy(hw, 0x2FB1, 0x8B24);
2210dee1ad47SJeff Kirsher 	/* Increase Hybrid poly bias */
2211dee1ad47SJeff Kirsher 	e1e_wphy(hw, 0x2FB2, 0xF8F0);
2212dee1ad47SJeff Kirsher 	/* Add 4% to Tx amplitude in Gig mode */
2213dee1ad47SJeff Kirsher 	e1e_wphy(hw, 0x2010, 0x10B0);
2214dee1ad47SJeff Kirsher 	/* Disable trimming (TTT) */
2215dee1ad47SJeff Kirsher 	e1e_wphy(hw, 0x2011, 0x0000);
2216dee1ad47SJeff Kirsher 	/* Poly DC correction to 94.6% + 2% for all channels */
2217dee1ad47SJeff Kirsher 	e1e_wphy(hw, 0x20DD, 0x249A);
2218dee1ad47SJeff Kirsher 	/* ABS DC correction to 95.9% */
2219dee1ad47SJeff Kirsher 	e1e_wphy(hw, 0x20DE, 0x00D3);
2220dee1ad47SJeff Kirsher 	/* BG temp curve trim */
2221dee1ad47SJeff Kirsher 	e1e_wphy(hw, 0x28B4, 0x04CE);
2222dee1ad47SJeff Kirsher 	/* Increasing ADC OPAMP stage 1 currents to max */
2223dee1ad47SJeff Kirsher 	e1e_wphy(hw, 0x2F70, 0x29E4);
2224dee1ad47SJeff Kirsher 	/* Force 1000 ( required for enabling PHY regs configuration) */
2225dee1ad47SJeff Kirsher 	e1e_wphy(hw, 0x0000, 0x0140);
2226dee1ad47SJeff Kirsher 	/* Set upd_freq to 6 */
2227dee1ad47SJeff Kirsher 	e1e_wphy(hw, 0x1F30, 0x1606);
2228dee1ad47SJeff Kirsher 	/* Disable NPDFE */
2229dee1ad47SJeff Kirsher 	e1e_wphy(hw, 0x1F31, 0xB814);
2230dee1ad47SJeff Kirsher 	/* Disable adaptive fixed FFE (Default) */
2231dee1ad47SJeff Kirsher 	e1e_wphy(hw, 0x1F35, 0x002A);
2232dee1ad47SJeff Kirsher 	/* Enable FFE hysteresis */
2233dee1ad47SJeff Kirsher 	e1e_wphy(hw, 0x1F3E, 0x0067);
2234dee1ad47SJeff Kirsher 	/* Fixed FFE for short cable lengths */
2235dee1ad47SJeff Kirsher 	e1e_wphy(hw, 0x1F54, 0x0065);
2236dee1ad47SJeff Kirsher 	/* Fixed FFE for medium cable lengths */
2237dee1ad47SJeff Kirsher 	e1e_wphy(hw, 0x1F55, 0x002A);
2238dee1ad47SJeff Kirsher 	/* Fixed FFE for long cable lengths */
2239dee1ad47SJeff Kirsher 	e1e_wphy(hw, 0x1F56, 0x002A);
2240dee1ad47SJeff Kirsher 	/* Enable Adaptive Clip Threshold */
2241dee1ad47SJeff Kirsher 	e1e_wphy(hw, 0x1F72, 0x3FB0);
2242dee1ad47SJeff Kirsher 	/* AHT reset limit to 1 */
2243dee1ad47SJeff Kirsher 	e1e_wphy(hw, 0x1F76, 0xC0FF);
2244dee1ad47SJeff Kirsher 	/* Set AHT master delay to 127 msec */
2245dee1ad47SJeff Kirsher 	e1e_wphy(hw, 0x1F77, 0x1DEC);
2246dee1ad47SJeff Kirsher 	/* Set scan bits for AHT */
2247dee1ad47SJeff Kirsher 	e1e_wphy(hw, 0x1F78, 0xF9EF);
2248dee1ad47SJeff Kirsher 	/* Set AHT Preset bits */
2249dee1ad47SJeff Kirsher 	e1e_wphy(hw, 0x1F79, 0x0210);
2250dee1ad47SJeff Kirsher 	/* Change integ_factor of channel A to 3 */
2251dee1ad47SJeff Kirsher 	e1e_wphy(hw, 0x1895, 0x0003);
2252dee1ad47SJeff Kirsher 	/* Change prop_factor of channels BCD to 8 */
2253dee1ad47SJeff Kirsher 	e1e_wphy(hw, 0x1796, 0x0008);
2254dee1ad47SJeff Kirsher 	/* Change cg_icount + enable integbp for channels BCD */
2255dee1ad47SJeff Kirsher 	e1e_wphy(hw, 0x1798, 0xD008);
2256dee1ad47SJeff Kirsher 	/*
2257dee1ad47SJeff Kirsher 	 * Change cg_icount + enable integbp + change prop_factor_master
2258dee1ad47SJeff Kirsher 	 * to 8 for channel A
2259dee1ad47SJeff Kirsher 	 */
2260dee1ad47SJeff Kirsher 	e1e_wphy(hw, 0x1898, 0xD918);
2261dee1ad47SJeff Kirsher 	/* Disable AHT in Slave mode on channel A */
2262dee1ad47SJeff Kirsher 	e1e_wphy(hw, 0x187A, 0x0800);
2263dee1ad47SJeff Kirsher 	/*
2264dee1ad47SJeff Kirsher 	 * Enable LPLU and disable AN to 1000 in non-D0a states,
2265dee1ad47SJeff Kirsher 	 * Enable SPD+B2B
2266dee1ad47SJeff Kirsher 	 */
2267dee1ad47SJeff Kirsher 	e1e_wphy(hw, 0x0019, 0x008D);
2268dee1ad47SJeff Kirsher 	/* Enable restart AN on an1000_dis change */
2269dee1ad47SJeff Kirsher 	e1e_wphy(hw, 0x001B, 0x2080);
2270dee1ad47SJeff Kirsher 	/* Enable wh_fifo read clock in 10/100 modes */
2271dee1ad47SJeff Kirsher 	e1e_wphy(hw, 0x0014, 0x0045);
2272dee1ad47SJeff Kirsher 	/* Restart AN, Speed selection is 1000 */
2273dee1ad47SJeff Kirsher 	e1e_wphy(hw, 0x0000, 0x1340);
2274dee1ad47SJeff Kirsher 
2275dee1ad47SJeff Kirsher 	return 0;
2276dee1ad47SJeff Kirsher }
2277dee1ad47SJeff Kirsher 
2278dee1ad47SJeff Kirsher /* Internal function pointers */
2279dee1ad47SJeff Kirsher 
2280dee1ad47SJeff Kirsher /**
2281dee1ad47SJeff Kirsher  *  e1000_get_phy_cfg_done - Generic PHY configuration done
2282dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
2283dee1ad47SJeff Kirsher  *
2284dee1ad47SJeff Kirsher  *  Return success if silicon family did not implement a family specific
2285dee1ad47SJeff Kirsher  *  get_cfg_done function.
2286dee1ad47SJeff Kirsher  **/
2287dee1ad47SJeff Kirsher static s32 e1000_get_phy_cfg_done(struct e1000_hw *hw)
2288dee1ad47SJeff Kirsher {
2289dee1ad47SJeff Kirsher 	if (hw->phy.ops.get_cfg_done)
2290dee1ad47SJeff Kirsher 		return hw->phy.ops.get_cfg_done(hw);
2291dee1ad47SJeff Kirsher 
2292dee1ad47SJeff Kirsher 	return 0;
2293dee1ad47SJeff Kirsher }
2294dee1ad47SJeff Kirsher 
2295dee1ad47SJeff Kirsher /**
2296dee1ad47SJeff Kirsher  *  e1000_phy_force_speed_duplex - Generic force PHY speed/duplex
2297dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
2298dee1ad47SJeff Kirsher  *
2299dee1ad47SJeff Kirsher  *  When the silicon family has not implemented a forced speed/duplex
2300dee1ad47SJeff Kirsher  *  function for the PHY, simply return 0.
2301dee1ad47SJeff Kirsher  **/
2302dee1ad47SJeff Kirsher static s32 e1000_phy_force_speed_duplex(struct e1000_hw *hw)
2303dee1ad47SJeff Kirsher {
2304dee1ad47SJeff Kirsher 	if (hw->phy.ops.force_speed_duplex)
2305dee1ad47SJeff Kirsher 		return hw->phy.ops.force_speed_duplex(hw);
2306dee1ad47SJeff Kirsher 
2307dee1ad47SJeff Kirsher 	return 0;
2308dee1ad47SJeff Kirsher }
2309dee1ad47SJeff Kirsher 
2310dee1ad47SJeff Kirsher /**
2311dee1ad47SJeff Kirsher  *  e1000e_get_phy_type_from_id - Get PHY type from id
2312dee1ad47SJeff Kirsher  *  @phy_id: phy_id read from the phy
2313dee1ad47SJeff Kirsher  *
2314dee1ad47SJeff Kirsher  *  Returns the phy type from the id.
2315dee1ad47SJeff Kirsher  **/
2316dee1ad47SJeff Kirsher enum e1000_phy_type e1000e_get_phy_type_from_id(u32 phy_id)
2317dee1ad47SJeff Kirsher {
2318dee1ad47SJeff Kirsher 	enum e1000_phy_type phy_type = e1000_phy_unknown;
2319dee1ad47SJeff Kirsher 
2320dee1ad47SJeff Kirsher 	switch (phy_id) {
2321dee1ad47SJeff Kirsher 	case M88E1000_I_PHY_ID:
2322dee1ad47SJeff Kirsher 	case M88E1000_E_PHY_ID:
2323dee1ad47SJeff Kirsher 	case M88E1111_I_PHY_ID:
2324dee1ad47SJeff Kirsher 	case M88E1011_I_PHY_ID:
2325dee1ad47SJeff Kirsher 		phy_type = e1000_phy_m88;
2326dee1ad47SJeff Kirsher 		break;
2327dee1ad47SJeff Kirsher 	case IGP01E1000_I_PHY_ID: /* IGP 1 & 2 share this */
2328dee1ad47SJeff Kirsher 		phy_type = e1000_phy_igp_2;
2329dee1ad47SJeff Kirsher 		break;
2330dee1ad47SJeff Kirsher 	case GG82563_E_PHY_ID:
2331dee1ad47SJeff Kirsher 		phy_type = e1000_phy_gg82563;
2332dee1ad47SJeff Kirsher 		break;
2333dee1ad47SJeff Kirsher 	case IGP03E1000_E_PHY_ID:
2334dee1ad47SJeff Kirsher 		phy_type = e1000_phy_igp_3;
2335dee1ad47SJeff Kirsher 		break;
2336dee1ad47SJeff Kirsher 	case IFE_E_PHY_ID:
2337dee1ad47SJeff Kirsher 	case IFE_PLUS_E_PHY_ID:
2338dee1ad47SJeff Kirsher 	case IFE_C_E_PHY_ID:
2339dee1ad47SJeff Kirsher 		phy_type = e1000_phy_ife;
2340dee1ad47SJeff Kirsher 		break;
2341dee1ad47SJeff Kirsher 	case BME1000_E_PHY_ID:
2342dee1ad47SJeff Kirsher 	case BME1000_E_PHY_ID_R2:
2343dee1ad47SJeff Kirsher 		phy_type = e1000_phy_bm;
2344dee1ad47SJeff Kirsher 		break;
2345dee1ad47SJeff Kirsher 	case I82578_E_PHY_ID:
2346dee1ad47SJeff Kirsher 		phy_type = e1000_phy_82578;
2347dee1ad47SJeff Kirsher 		break;
2348dee1ad47SJeff Kirsher 	case I82577_E_PHY_ID:
2349dee1ad47SJeff Kirsher 		phy_type = e1000_phy_82577;
2350dee1ad47SJeff Kirsher 		break;
2351dee1ad47SJeff Kirsher 	case I82579_E_PHY_ID:
2352dee1ad47SJeff Kirsher 		phy_type = e1000_phy_82579;
2353dee1ad47SJeff Kirsher 		break;
2354dee1ad47SJeff Kirsher 	default:
2355dee1ad47SJeff Kirsher 		phy_type = e1000_phy_unknown;
2356dee1ad47SJeff Kirsher 		break;
2357dee1ad47SJeff Kirsher 	}
2358dee1ad47SJeff Kirsher 	return phy_type;
2359dee1ad47SJeff Kirsher }
2360dee1ad47SJeff Kirsher 
2361dee1ad47SJeff Kirsher /**
2362dee1ad47SJeff Kirsher  *  e1000e_determine_phy_address - Determines PHY address.
2363dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
2364dee1ad47SJeff Kirsher  *
2365dee1ad47SJeff Kirsher  *  This uses a trial and error method to loop through possible PHY
2366dee1ad47SJeff Kirsher  *  addresses. It tests each by reading the PHY ID registers and
2367dee1ad47SJeff Kirsher  *  checking for a match.
2368dee1ad47SJeff Kirsher  **/
2369dee1ad47SJeff Kirsher s32 e1000e_determine_phy_address(struct e1000_hw *hw)
2370dee1ad47SJeff Kirsher {
2371dee1ad47SJeff Kirsher 	s32 ret_val = -E1000_ERR_PHY_TYPE;
2372dee1ad47SJeff Kirsher 	u32 phy_addr = 0;
2373dee1ad47SJeff Kirsher 	u32 i;
2374dee1ad47SJeff Kirsher 	enum e1000_phy_type phy_type = e1000_phy_unknown;
2375dee1ad47SJeff Kirsher 
2376dee1ad47SJeff Kirsher 	hw->phy.id = phy_type;
2377dee1ad47SJeff Kirsher 
2378dee1ad47SJeff Kirsher 	for (phy_addr = 0; phy_addr < E1000_MAX_PHY_ADDR; phy_addr++) {
2379dee1ad47SJeff Kirsher 		hw->phy.addr = phy_addr;
2380dee1ad47SJeff Kirsher 		i = 0;
2381dee1ad47SJeff Kirsher 
2382dee1ad47SJeff Kirsher 		do {
2383dee1ad47SJeff Kirsher 			e1000e_get_phy_id(hw);
2384dee1ad47SJeff Kirsher 			phy_type = e1000e_get_phy_type_from_id(hw->phy.id);
2385dee1ad47SJeff Kirsher 
2386dee1ad47SJeff Kirsher 			/*
2387dee1ad47SJeff Kirsher 			 * If phy_type is valid, break - we found our
2388dee1ad47SJeff Kirsher 			 * PHY address
2389dee1ad47SJeff Kirsher 			 */
2390dee1ad47SJeff Kirsher 			if (phy_type  != e1000_phy_unknown) {
2391dee1ad47SJeff Kirsher 				ret_val = 0;
2392dee1ad47SJeff Kirsher 				goto out;
2393dee1ad47SJeff Kirsher 			}
2394dee1ad47SJeff Kirsher 			usleep_range(1000, 2000);
2395dee1ad47SJeff Kirsher 			i++;
2396dee1ad47SJeff Kirsher 		} while (i < 10);
2397dee1ad47SJeff Kirsher 	}
2398dee1ad47SJeff Kirsher 
2399dee1ad47SJeff Kirsher out:
2400dee1ad47SJeff Kirsher 	return ret_val;
2401dee1ad47SJeff Kirsher }
2402dee1ad47SJeff Kirsher 
2403dee1ad47SJeff Kirsher /**
2404dee1ad47SJeff Kirsher  *  e1000_get_phy_addr_for_bm_page - Retrieve PHY page address
2405dee1ad47SJeff Kirsher  *  @page: page to access
2406dee1ad47SJeff Kirsher  *
2407dee1ad47SJeff Kirsher  *  Returns the phy address for the page requested.
2408dee1ad47SJeff Kirsher  **/
2409dee1ad47SJeff Kirsher static u32 e1000_get_phy_addr_for_bm_page(u32 page, u32 reg)
2410dee1ad47SJeff Kirsher {
2411dee1ad47SJeff Kirsher 	u32 phy_addr = 2;
2412dee1ad47SJeff Kirsher 
2413dee1ad47SJeff Kirsher 	if ((page >= 768) || (page == 0 && reg == 25) || (reg == 31))
2414dee1ad47SJeff Kirsher 		phy_addr = 1;
2415dee1ad47SJeff Kirsher 
2416dee1ad47SJeff Kirsher 	return phy_addr;
2417dee1ad47SJeff Kirsher }
2418dee1ad47SJeff Kirsher 
2419dee1ad47SJeff Kirsher /**
2420dee1ad47SJeff Kirsher  *  e1000e_write_phy_reg_bm - Write BM PHY register
2421dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
2422dee1ad47SJeff Kirsher  *  @offset: register offset to write to
2423dee1ad47SJeff Kirsher  *  @data: data to write at register offset
2424dee1ad47SJeff Kirsher  *
2425dee1ad47SJeff Kirsher  *  Acquires semaphore, if necessary, then writes the data to PHY register
2426dee1ad47SJeff Kirsher  *  at the offset.  Release any acquired semaphores before exiting.
2427dee1ad47SJeff Kirsher  **/
2428dee1ad47SJeff Kirsher s32 e1000e_write_phy_reg_bm(struct e1000_hw *hw, u32 offset, u16 data)
2429dee1ad47SJeff Kirsher {
2430dee1ad47SJeff Kirsher 	s32 ret_val;
2431dee1ad47SJeff Kirsher 	u32 page = offset >> IGP_PAGE_SHIFT;
2432dee1ad47SJeff Kirsher 
2433dee1ad47SJeff Kirsher 	ret_val = hw->phy.ops.acquire(hw);
2434dee1ad47SJeff Kirsher 	if (ret_val)
2435dee1ad47SJeff Kirsher 		return ret_val;
2436dee1ad47SJeff Kirsher 
2437dee1ad47SJeff Kirsher 	/* Page 800 works differently than the rest so it has its own func */
2438dee1ad47SJeff Kirsher 	if (page == BM_WUC_PAGE) {
2439dee1ad47SJeff Kirsher 		ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, &data,
2440dee1ad47SJeff Kirsher 							 false, false);
2441dee1ad47SJeff Kirsher 		goto out;
2442dee1ad47SJeff Kirsher 	}
2443dee1ad47SJeff Kirsher 
2444dee1ad47SJeff Kirsher 	hw->phy.addr = e1000_get_phy_addr_for_bm_page(page, offset);
2445dee1ad47SJeff Kirsher 
2446dee1ad47SJeff Kirsher 	if (offset > MAX_PHY_MULTI_PAGE_REG) {
2447dee1ad47SJeff Kirsher 		u32 page_shift, page_select;
2448dee1ad47SJeff Kirsher 
2449dee1ad47SJeff Kirsher 		/*
2450dee1ad47SJeff Kirsher 		 * Page select is register 31 for phy address 1 and 22 for
2451dee1ad47SJeff Kirsher 		 * phy address 2 and 3. Page select is shifted only for
2452dee1ad47SJeff Kirsher 		 * phy address 1.
2453dee1ad47SJeff Kirsher 		 */
2454dee1ad47SJeff Kirsher 		if (hw->phy.addr == 1) {
2455dee1ad47SJeff Kirsher 			page_shift = IGP_PAGE_SHIFT;
2456dee1ad47SJeff Kirsher 			page_select = IGP01E1000_PHY_PAGE_SELECT;
2457dee1ad47SJeff Kirsher 		} else {
2458dee1ad47SJeff Kirsher 			page_shift = 0;
2459dee1ad47SJeff Kirsher 			page_select = BM_PHY_PAGE_SELECT;
2460dee1ad47SJeff Kirsher 		}
2461dee1ad47SJeff Kirsher 
2462dee1ad47SJeff Kirsher 		/* Page is shifted left, PHY expects (page x 32) */
2463dee1ad47SJeff Kirsher 		ret_val = e1000e_write_phy_reg_mdic(hw, page_select,
2464dee1ad47SJeff Kirsher 		                                    (page << page_shift));
2465dee1ad47SJeff Kirsher 		if (ret_val)
2466dee1ad47SJeff Kirsher 			goto out;
2467dee1ad47SJeff Kirsher 	}
2468dee1ad47SJeff Kirsher 
2469dee1ad47SJeff Kirsher 	ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
2470dee1ad47SJeff Kirsher 	                                    data);
2471dee1ad47SJeff Kirsher 
2472dee1ad47SJeff Kirsher out:
2473dee1ad47SJeff Kirsher 	hw->phy.ops.release(hw);
2474dee1ad47SJeff Kirsher 	return ret_val;
2475dee1ad47SJeff Kirsher }
2476dee1ad47SJeff Kirsher 
2477dee1ad47SJeff Kirsher /**
2478dee1ad47SJeff Kirsher  *  e1000e_read_phy_reg_bm - Read BM PHY register
2479dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
2480dee1ad47SJeff Kirsher  *  @offset: register offset to be read
2481dee1ad47SJeff Kirsher  *  @data: pointer to the read data
2482dee1ad47SJeff Kirsher  *
2483dee1ad47SJeff Kirsher  *  Acquires semaphore, if necessary, then reads the PHY register at offset
2484dee1ad47SJeff Kirsher  *  and storing the retrieved information in data.  Release any acquired
2485dee1ad47SJeff Kirsher  *  semaphores before exiting.
2486dee1ad47SJeff Kirsher  **/
2487dee1ad47SJeff Kirsher s32 e1000e_read_phy_reg_bm(struct e1000_hw *hw, u32 offset, u16 *data)
2488dee1ad47SJeff Kirsher {
2489dee1ad47SJeff Kirsher 	s32 ret_val;
2490dee1ad47SJeff Kirsher 	u32 page = offset >> IGP_PAGE_SHIFT;
2491dee1ad47SJeff Kirsher 
2492dee1ad47SJeff Kirsher 	ret_val = hw->phy.ops.acquire(hw);
2493dee1ad47SJeff Kirsher 	if (ret_val)
2494dee1ad47SJeff Kirsher 		return ret_val;
2495dee1ad47SJeff Kirsher 
2496dee1ad47SJeff Kirsher 	/* Page 800 works differently than the rest so it has its own func */
2497dee1ad47SJeff Kirsher 	if (page == BM_WUC_PAGE) {
2498dee1ad47SJeff Kirsher 		ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, data,
2499dee1ad47SJeff Kirsher 							 true, false);
2500dee1ad47SJeff Kirsher 		goto out;
2501dee1ad47SJeff Kirsher 	}
2502dee1ad47SJeff Kirsher 
2503dee1ad47SJeff Kirsher 	hw->phy.addr = e1000_get_phy_addr_for_bm_page(page, offset);
2504dee1ad47SJeff Kirsher 
2505dee1ad47SJeff Kirsher 	if (offset > MAX_PHY_MULTI_PAGE_REG) {
2506dee1ad47SJeff Kirsher 		u32 page_shift, page_select;
2507dee1ad47SJeff Kirsher 
2508dee1ad47SJeff Kirsher 		/*
2509dee1ad47SJeff Kirsher 		 * Page select is register 31 for phy address 1 and 22 for
2510dee1ad47SJeff Kirsher 		 * phy address 2 and 3. Page select is shifted only for
2511dee1ad47SJeff Kirsher 		 * phy address 1.
2512dee1ad47SJeff Kirsher 		 */
2513dee1ad47SJeff Kirsher 		if (hw->phy.addr == 1) {
2514dee1ad47SJeff Kirsher 			page_shift = IGP_PAGE_SHIFT;
2515dee1ad47SJeff Kirsher 			page_select = IGP01E1000_PHY_PAGE_SELECT;
2516dee1ad47SJeff Kirsher 		} else {
2517dee1ad47SJeff Kirsher 			page_shift = 0;
2518dee1ad47SJeff Kirsher 			page_select = BM_PHY_PAGE_SELECT;
2519dee1ad47SJeff Kirsher 		}
2520dee1ad47SJeff Kirsher 
2521dee1ad47SJeff Kirsher 		/* Page is shifted left, PHY expects (page x 32) */
2522dee1ad47SJeff Kirsher 		ret_val = e1000e_write_phy_reg_mdic(hw, page_select,
2523dee1ad47SJeff Kirsher 		                                    (page << page_shift));
2524dee1ad47SJeff Kirsher 		if (ret_val)
2525dee1ad47SJeff Kirsher 			goto out;
2526dee1ad47SJeff Kirsher 	}
2527dee1ad47SJeff Kirsher 
2528dee1ad47SJeff Kirsher 	ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
2529dee1ad47SJeff Kirsher 	                                   data);
2530dee1ad47SJeff Kirsher out:
2531dee1ad47SJeff Kirsher 	hw->phy.ops.release(hw);
2532dee1ad47SJeff Kirsher 	return ret_val;
2533dee1ad47SJeff Kirsher }
2534dee1ad47SJeff Kirsher 
2535dee1ad47SJeff Kirsher /**
2536dee1ad47SJeff Kirsher  *  e1000e_read_phy_reg_bm2 - Read BM PHY register
2537dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
2538dee1ad47SJeff Kirsher  *  @offset: register offset to be read
2539dee1ad47SJeff Kirsher  *  @data: pointer to the read data
2540dee1ad47SJeff Kirsher  *
2541dee1ad47SJeff Kirsher  *  Acquires semaphore, if necessary, then reads the PHY register at offset
2542dee1ad47SJeff Kirsher  *  and storing the retrieved information in data.  Release any acquired
2543dee1ad47SJeff Kirsher  *  semaphores before exiting.
2544dee1ad47SJeff Kirsher  **/
2545dee1ad47SJeff Kirsher s32 e1000e_read_phy_reg_bm2(struct e1000_hw *hw, u32 offset, u16 *data)
2546dee1ad47SJeff Kirsher {
2547dee1ad47SJeff Kirsher 	s32 ret_val;
2548dee1ad47SJeff Kirsher 	u16 page = (u16)(offset >> IGP_PAGE_SHIFT);
2549dee1ad47SJeff Kirsher 
2550dee1ad47SJeff Kirsher 	ret_val = hw->phy.ops.acquire(hw);
2551dee1ad47SJeff Kirsher 	if (ret_val)
2552dee1ad47SJeff Kirsher 		return ret_val;
2553dee1ad47SJeff Kirsher 
2554dee1ad47SJeff Kirsher 	/* Page 800 works differently than the rest so it has its own func */
2555dee1ad47SJeff Kirsher 	if (page == BM_WUC_PAGE) {
2556dee1ad47SJeff Kirsher 		ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, data,
2557dee1ad47SJeff Kirsher 							 true, false);
2558dee1ad47SJeff Kirsher 		goto out;
2559dee1ad47SJeff Kirsher 	}
2560dee1ad47SJeff Kirsher 
2561dee1ad47SJeff Kirsher 	hw->phy.addr = 1;
2562dee1ad47SJeff Kirsher 
2563dee1ad47SJeff Kirsher 	if (offset > MAX_PHY_MULTI_PAGE_REG) {
2564dee1ad47SJeff Kirsher 
2565dee1ad47SJeff Kirsher 		/* Page is shifted left, PHY expects (page x 32) */
2566dee1ad47SJeff Kirsher 		ret_val = e1000e_write_phy_reg_mdic(hw, BM_PHY_PAGE_SELECT,
2567dee1ad47SJeff Kirsher 						    page);
2568dee1ad47SJeff Kirsher 
2569dee1ad47SJeff Kirsher 		if (ret_val)
2570dee1ad47SJeff Kirsher 			goto out;
2571dee1ad47SJeff Kirsher 	}
2572dee1ad47SJeff Kirsher 
2573dee1ad47SJeff Kirsher 	ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
2574dee1ad47SJeff Kirsher 					   data);
2575dee1ad47SJeff Kirsher out:
2576dee1ad47SJeff Kirsher 	hw->phy.ops.release(hw);
2577dee1ad47SJeff Kirsher 	return ret_val;
2578dee1ad47SJeff Kirsher }
2579dee1ad47SJeff Kirsher 
2580dee1ad47SJeff Kirsher /**
2581dee1ad47SJeff Kirsher  *  e1000e_write_phy_reg_bm2 - Write BM PHY register
2582dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
2583dee1ad47SJeff Kirsher  *  @offset: register offset to write to
2584dee1ad47SJeff Kirsher  *  @data: data to write at register offset
2585dee1ad47SJeff Kirsher  *
2586dee1ad47SJeff Kirsher  *  Acquires semaphore, if necessary, then writes the data to PHY register
2587dee1ad47SJeff Kirsher  *  at the offset.  Release any acquired semaphores before exiting.
2588dee1ad47SJeff Kirsher  **/
2589dee1ad47SJeff Kirsher s32 e1000e_write_phy_reg_bm2(struct e1000_hw *hw, u32 offset, u16 data)
2590dee1ad47SJeff Kirsher {
2591dee1ad47SJeff Kirsher 	s32 ret_val;
2592dee1ad47SJeff Kirsher 	u16 page = (u16)(offset >> IGP_PAGE_SHIFT);
2593dee1ad47SJeff Kirsher 
2594dee1ad47SJeff Kirsher 	ret_val = hw->phy.ops.acquire(hw);
2595dee1ad47SJeff Kirsher 	if (ret_val)
2596dee1ad47SJeff Kirsher 		return ret_val;
2597dee1ad47SJeff Kirsher 
2598dee1ad47SJeff Kirsher 	/* Page 800 works differently than the rest so it has its own func */
2599dee1ad47SJeff Kirsher 	if (page == BM_WUC_PAGE) {
2600dee1ad47SJeff Kirsher 		ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, &data,
2601dee1ad47SJeff Kirsher 							 false, false);
2602dee1ad47SJeff Kirsher 		goto out;
2603dee1ad47SJeff Kirsher 	}
2604dee1ad47SJeff Kirsher 
2605dee1ad47SJeff Kirsher 	hw->phy.addr = 1;
2606dee1ad47SJeff Kirsher 
2607dee1ad47SJeff Kirsher 	if (offset > MAX_PHY_MULTI_PAGE_REG) {
2608dee1ad47SJeff Kirsher 		/* Page is shifted left, PHY expects (page x 32) */
2609dee1ad47SJeff Kirsher 		ret_val = e1000e_write_phy_reg_mdic(hw, BM_PHY_PAGE_SELECT,
2610dee1ad47SJeff Kirsher 						    page);
2611dee1ad47SJeff Kirsher 
2612dee1ad47SJeff Kirsher 		if (ret_val)
2613dee1ad47SJeff Kirsher 			goto out;
2614dee1ad47SJeff Kirsher 	}
2615dee1ad47SJeff Kirsher 
2616dee1ad47SJeff Kirsher 	ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
2617dee1ad47SJeff Kirsher 					    data);
2618dee1ad47SJeff Kirsher 
2619dee1ad47SJeff Kirsher out:
2620dee1ad47SJeff Kirsher 	hw->phy.ops.release(hw);
2621dee1ad47SJeff Kirsher 	return ret_val;
2622dee1ad47SJeff Kirsher }
2623dee1ad47SJeff Kirsher 
2624dee1ad47SJeff Kirsher /**
2625dee1ad47SJeff Kirsher  *  e1000_enable_phy_wakeup_reg_access_bm - enable access to BM wakeup registers
2626dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
2627dee1ad47SJeff Kirsher  *  @phy_reg: pointer to store original contents of BM_WUC_ENABLE_REG
2628dee1ad47SJeff Kirsher  *
2629dee1ad47SJeff Kirsher  *  Assumes semaphore already acquired and phy_reg points to a valid memory
2630dee1ad47SJeff Kirsher  *  address to store contents of the BM_WUC_ENABLE_REG register.
2631dee1ad47SJeff Kirsher  **/
2632dee1ad47SJeff Kirsher s32 e1000_enable_phy_wakeup_reg_access_bm(struct e1000_hw *hw, u16 *phy_reg)
2633dee1ad47SJeff Kirsher {
2634dee1ad47SJeff Kirsher 	s32 ret_val;
2635dee1ad47SJeff Kirsher 	u16 temp;
2636dee1ad47SJeff Kirsher 
2637dee1ad47SJeff Kirsher 	/* All page select, port ctrl and wakeup registers use phy address 1 */
2638dee1ad47SJeff Kirsher 	hw->phy.addr = 1;
2639dee1ad47SJeff Kirsher 
2640dee1ad47SJeff Kirsher 	/* Select Port Control Registers page */
2641dee1ad47SJeff Kirsher 	ret_val = e1000_set_page_igp(hw, (BM_PORT_CTRL_PAGE << IGP_PAGE_SHIFT));
2642dee1ad47SJeff Kirsher 	if (ret_val) {
2643dee1ad47SJeff Kirsher 		e_dbg("Could not set Port Control page\n");
2644dee1ad47SJeff Kirsher 		goto out;
2645dee1ad47SJeff Kirsher 	}
2646dee1ad47SJeff Kirsher 
2647dee1ad47SJeff Kirsher 	ret_val = e1000e_read_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, phy_reg);
2648dee1ad47SJeff Kirsher 	if (ret_val) {
2649dee1ad47SJeff Kirsher 		e_dbg("Could not read PHY register %d.%d\n",
2650dee1ad47SJeff Kirsher 		      BM_PORT_CTRL_PAGE, BM_WUC_ENABLE_REG);
2651dee1ad47SJeff Kirsher 		goto out;
2652dee1ad47SJeff Kirsher 	}
2653dee1ad47SJeff Kirsher 
2654dee1ad47SJeff Kirsher 	/*
2655dee1ad47SJeff Kirsher 	 * Enable both PHY wakeup mode and Wakeup register page writes.
2656dee1ad47SJeff Kirsher 	 * Prevent a power state change by disabling ME and Host PHY wakeup.
2657dee1ad47SJeff Kirsher 	 */
2658dee1ad47SJeff Kirsher 	temp = *phy_reg;
2659dee1ad47SJeff Kirsher 	temp |= BM_WUC_ENABLE_BIT;
2660dee1ad47SJeff Kirsher 	temp &= ~(BM_WUC_ME_WU_BIT | BM_WUC_HOST_WU_BIT);
2661dee1ad47SJeff Kirsher 
2662dee1ad47SJeff Kirsher 	ret_val = e1000e_write_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, temp);
2663dee1ad47SJeff Kirsher 	if (ret_val) {
2664dee1ad47SJeff Kirsher 		e_dbg("Could not write PHY register %d.%d\n",
2665dee1ad47SJeff Kirsher 		      BM_PORT_CTRL_PAGE, BM_WUC_ENABLE_REG);
2666dee1ad47SJeff Kirsher 		goto out;
2667dee1ad47SJeff Kirsher 	}
2668dee1ad47SJeff Kirsher 
2669dee1ad47SJeff Kirsher 	/* Select Host Wakeup Registers page */
2670dee1ad47SJeff Kirsher 	ret_val = e1000_set_page_igp(hw, (BM_WUC_PAGE << IGP_PAGE_SHIFT));
2671dee1ad47SJeff Kirsher 
2672dee1ad47SJeff Kirsher 	/* caller now able to write registers on the Wakeup registers page */
2673dee1ad47SJeff Kirsher out:
2674dee1ad47SJeff Kirsher 	return ret_val;
2675dee1ad47SJeff Kirsher }
2676dee1ad47SJeff Kirsher 
2677dee1ad47SJeff Kirsher /**
2678dee1ad47SJeff Kirsher  *  e1000_disable_phy_wakeup_reg_access_bm - disable access to BM wakeup regs
2679dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
2680dee1ad47SJeff Kirsher  *  @phy_reg: pointer to original contents of BM_WUC_ENABLE_REG
2681dee1ad47SJeff Kirsher  *
2682dee1ad47SJeff Kirsher  *  Restore BM_WUC_ENABLE_REG to its original value.
2683dee1ad47SJeff Kirsher  *
2684dee1ad47SJeff Kirsher  *  Assumes semaphore already acquired and *phy_reg is the contents of the
2685dee1ad47SJeff Kirsher  *  BM_WUC_ENABLE_REG before register(s) on BM_WUC_PAGE were accessed by
2686dee1ad47SJeff Kirsher  *  caller.
2687dee1ad47SJeff Kirsher  **/
2688dee1ad47SJeff Kirsher s32 e1000_disable_phy_wakeup_reg_access_bm(struct e1000_hw *hw, u16 *phy_reg)
2689dee1ad47SJeff Kirsher {
2690dee1ad47SJeff Kirsher 	s32 ret_val = 0;
2691dee1ad47SJeff Kirsher 
2692dee1ad47SJeff Kirsher 	/* Select Port Control Registers page */
2693dee1ad47SJeff Kirsher 	ret_val = e1000_set_page_igp(hw, (BM_PORT_CTRL_PAGE << IGP_PAGE_SHIFT));
2694dee1ad47SJeff Kirsher 	if (ret_val) {
2695dee1ad47SJeff Kirsher 		e_dbg("Could not set Port Control page\n");
2696dee1ad47SJeff Kirsher 		goto out;
2697dee1ad47SJeff Kirsher 	}
2698dee1ad47SJeff Kirsher 
2699dee1ad47SJeff Kirsher 	/* Restore 769.17 to its original value */
2700dee1ad47SJeff Kirsher 	ret_val = e1000e_write_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, *phy_reg);
2701dee1ad47SJeff Kirsher 	if (ret_val)
2702dee1ad47SJeff Kirsher 		e_dbg("Could not restore PHY register %d.%d\n",
2703dee1ad47SJeff Kirsher 		      BM_PORT_CTRL_PAGE, BM_WUC_ENABLE_REG);
2704dee1ad47SJeff Kirsher out:
2705dee1ad47SJeff Kirsher 	return ret_val;
2706dee1ad47SJeff Kirsher }
2707dee1ad47SJeff Kirsher 
2708dee1ad47SJeff Kirsher /**
2709dee1ad47SJeff Kirsher  *  e1000_access_phy_wakeup_reg_bm - Read/write BM PHY wakeup register
2710dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
2711dee1ad47SJeff Kirsher  *  @offset: register offset to be read or written
2712dee1ad47SJeff Kirsher  *  @data: pointer to the data to read or write
2713dee1ad47SJeff Kirsher  *  @read: determines if operation is read or write
2714dee1ad47SJeff Kirsher  *  @page_set: BM_WUC_PAGE already set and access enabled
2715dee1ad47SJeff Kirsher  *
2716dee1ad47SJeff Kirsher  *  Read the PHY register at offset and store the retrieved information in
2717dee1ad47SJeff Kirsher  *  data, or write data to PHY register at offset.  Note the procedure to
2718dee1ad47SJeff Kirsher  *  access the PHY wakeup registers is different than reading the other PHY
2719dee1ad47SJeff Kirsher  *  registers. It works as such:
2720dee1ad47SJeff Kirsher  *  1) Set 769.17.2 (page 769, register 17, bit 2) = 1
2721dee1ad47SJeff Kirsher  *  2) Set page to 800 for host (801 if we were manageability)
2722dee1ad47SJeff Kirsher  *  3) Write the address using the address opcode (0x11)
2723dee1ad47SJeff Kirsher  *  4) Read or write the data using the data opcode (0x12)
2724dee1ad47SJeff Kirsher  *  5) Restore 769.17.2 to its original value
2725dee1ad47SJeff Kirsher  *
2726dee1ad47SJeff Kirsher  *  Steps 1 and 2 are done by e1000_enable_phy_wakeup_reg_access_bm() and
2727dee1ad47SJeff Kirsher  *  step 5 is done by e1000_disable_phy_wakeup_reg_access_bm().
2728dee1ad47SJeff Kirsher  *
2729dee1ad47SJeff Kirsher  *  Assumes semaphore is already acquired.  When page_set==true, assumes
2730dee1ad47SJeff Kirsher  *  the PHY page is set to BM_WUC_PAGE (i.e. a function in the call stack
2731dee1ad47SJeff Kirsher  *  is responsible for calls to e1000_[enable|disable]_phy_wakeup_reg_bm()).
2732dee1ad47SJeff Kirsher  **/
2733dee1ad47SJeff Kirsher static s32 e1000_access_phy_wakeup_reg_bm(struct e1000_hw *hw, u32 offset,
2734dee1ad47SJeff Kirsher 					  u16 *data, bool read, bool page_set)
2735dee1ad47SJeff Kirsher {
2736dee1ad47SJeff Kirsher 	s32 ret_val;
2737dee1ad47SJeff Kirsher 	u16 reg = BM_PHY_REG_NUM(offset);
2738dee1ad47SJeff Kirsher 	u16 page = BM_PHY_REG_PAGE(offset);
2739dee1ad47SJeff Kirsher 	u16 phy_reg = 0;
2740dee1ad47SJeff Kirsher 
2741dee1ad47SJeff Kirsher 	/* Gig must be disabled for MDIO accesses to Host Wakeup reg page */
2742dee1ad47SJeff Kirsher 	if ((hw->mac.type == e1000_pchlan) &&
2743dee1ad47SJeff Kirsher 	    (!(er32(PHY_CTRL) & E1000_PHY_CTRL_GBE_DISABLE)))
2744dee1ad47SJeff Kirsher 		e_dbg("Attempting to access page %d while gig enabled.\n",
2745dee1ad47SJeff Kirsher 		      page);
2746dee1ad47SJeff Kirsher 
2747dee1ad47SJeff Kirsher 	if (!page_set) {
2748dee1ad47SJeff Kirsher 		/* Enable access to PHY wakeup registers */
2749dee1ad47SJeff Kirsher 		ret_val = e1000_enable_phy_wakeup_reg_access_bm(hw, &phy_reg);
2750dee1ad47SJeff Kirsher 		if (ret_val) {
2751dee1ad47SJeff Kirsher 			e_dbg("Could not enable PHY wakeup reg access\n");
2752dee1ad47SJeff Kirsher 			goto out;
2753dee1ad47SJeff Kirsher 		}
2754dee1ad47SJeff Kirsher 	}
2755dee1ad47SJeff Kirsher 
2756dee1ad47SJeff Kirsher 	e_dbg("Accessing PHY page %d reg 0x%x\n", page, reg);
2757dee1ad47SJeff Kirsher 
2758dee1ad47SJeff Kirsher 	/* Write the Wakeup register page offset value using opcode 0x11 */
2759dee1ad47SJeff Kirsher 	ret_val = e1000e_write_phy_reg_mdic(hw, BM_WUC_ADDRESS_OPCODE, reg);
2760dee1ad47SJeff Kirsher 	if (ret_val) {
2761dee1ad47SJeff Kirsher 		e_dbg("Could not write address opcode to page %d\n", page);
2762dee1ad47SJeff Kirsher 		goto out;
2763dee1ad47SJeff Kirsher 	}
2764dee1ad47SJeff Kirsher 
2765dee1ad47SJeff Kirsher 	if (read) {
2766dee1ad47SJeff Kirsher 		/* Read the Wakeup register page value using opcode 0x12 */
2767dee1ad47SJeff Kirsher 		ret_val = e1000e_read_phy_reg_mdic(hw, BM_WUC_DATA_OPCODE,
2768dee1ad47SJeff Kirsher 		                                   data);
2769dee1ad47SJeff Kirsher 	} else {
2770dee1ad47SJeff Kirsher 		/* Write the Wakeup register page value using opcode 0x12 */
2771dee1ad47SJeff Kirsher 		ret_val = e1000e_write_phy_reg_mdic(hw, BM_WUC_DATA_OPCODE,
2772dee1ad47SJeff Kirsher 						    *data);
2773dee1ad47SJeff Kirsher 	}
2774dee1ad47SJeff Kirsher 
2775dee1ad47SJeff Kirsher 	if (ret_val) {
2776dee1ad47SJeff Kirsher 		e_dbg("Could not access PHY reg %d.%d\n", page, reg);
2777dee1ad47SJeff Kirsher 		goto out;
2778dee1ad47SJeff Kirsher 	}
2779dee1ad47SJeff Kirsher 
2780dee1ad47SJeff Kirsher 	if (!page_set)
2781dee1ad47SJeff Kirsher 		ret_val = e1000_disable_phy_wakeup_reg_access_bm(hw, &phy_reg);
2782dee1ad47SJeff Kirsher 
2783dee1ad47SJeff Kirsher out:
2784dee1ad47SJeff Kirsher 	return ret_val;
2785dee1ad47SJeff Kirsher }
2786dee1ad47SJeff Kirsher 
2787dee1ad47SJeff Kirsher /**
2788dee1ad47SJeff Kirsher  * e1000_power_up_phy_copper - Restore copper link in case of PHY power down
2789dee1ad47SJeff Kirsher  * @hw: pointer to the HW structure
2790dee1ad47SJeff Kirsher  *
2791dee1ad47SJeff Kirsher  * In the case of a PHY power down to save power, or to turn off link during a
2792dee1ad47SJeff Kirsher  * driver unload, or wake on lan is not enabled, restore the link to previous
2793dee1ad47SJeff Kirsher  * settings.
2794dee1ad47SJeff Kirsher  **/
2795dee1ad47SJeff Kirsher void e1000_power_up_phy_copper(struct e1000_hw *hw)
2796dee1ad47SJeff Kirsher {
2797dee1ad47SJeff Kirsher 	u16 mii_reg = 0;
2798dee1ad47SJeff Kirsher 
2799dee1ad47SJeff Kirsher 	/* The PHY will retain its settings across a power down/up cycle */
2800dee1ad47SJeff Kirsher 	e1e_rphy(hw, PHY_CONTROL, &mii_reg);
2801dee1ad47SJeff Kirsher 	mii_reg &= ~MII_CR_POWER_DOWN;
2802dee1ad47SJeff Kirsher 	e1e_wphy(hw, PHY_CONTROL, mii_reg);
2803dee1ad47SJeff Kirsher }
2804dee1ad47SJeff Kirsher 
2805dee1ad47SJeff Kirsher /**
2806dee1ad47SJeff Kirsher  * e1000_power_down_phy_copper - Restore copper link in case of PHY power down
2807dee1ad47SJeff Kirsher  * @hw: pointer to the HW structure
2808dee1ad47SJeff Kirsher  *
2809dee1ad47SJeff Kirsher  * In the case of a PHY power down to save power, or to turn off link during a
2810dee1ad47SJeff Kirsher  * driver unload, or wake on lan is not enabled, restore the link to previous
2811dee1ad47SJeff Kirsher  * settings.
2812dee1ad47SJeff Kirsher  **/
2813dee1ad47SJeff Kirsher void e1000_power_down_phy_copper(struct e1000_hw *hw)
2814dee1ad47SJeff Kirsher {
2815dee1ad47SJeff Kirsher 	u16 mii_reg = 0;
2816dee1ad47SJeff Kirsher 
2817dee1ad47SJeff Kirsher 	/* The PHY will retain its settings across a power down/up cycle */
2818dee1ad47SJeff Kirsher 	e1e_rphy(hw, PHY_CONTROL, &mii_reg);
2819dee1ad47SJeff Kirsher 	mii_reg |= MII_CR_POWER_DOWN;
2820dee1ad47SJeff Kirsher 	e1e_wphy(hw, PHY_CONTROL, mii_reg);
2821dee1ad47SJeff Kirsher 	usleep_range(1000, 2000);
2822dee1ad47SJeff Kirsher }
2823dee1ad47SJeff Kirsher 
2824dee1ad47SJeff Kirsher /**
2825dee1ad47SJeff Kirsher  *  e1000e_commit_phy - Soft PHY reset
2826dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
2827dee1ad47SJeff Kirsher  *
2828dee1ad47SJeff Kirsher  *  Performs a soft PHY reset on those that apply. This is a function pointer
2829dee1ad47SJeff Kirsher  *  entry point called by drivers.
2830dee1ad47SJeff Kirsher  **/
2831dee1ad47SJeff Kirsher s32 e1000e_commit_phy(struct e1000_hw *hw)
2832dee1ad47SJeff Kirsher {
2833dee1ad47SJeff Kirsher 	if (hw->phy.ops.commit)
2834dee1ad47SJeff Kirsher 		return hw->phy.ops.commit(hw);
2835dee1ad47SJeff Kirsher 
2836dee1ad47SJeff Kirsher 	return 0;
2837dee1ad47SJeff Kirsher }
2838dee1ad47SJeff Kirsher 
2839dee1ad47SJeff Kirsher /**
2840dee1ad47SJeff Kirsher  *  e1000_set_d0_lplu_state - Sets low power link up state for D0
2841dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
2842dee1ad47SJeff Kirsher  *  @active: boolean used to enable/disable lplu
2843dee1ad47SJeff Kirsher  *
2844dee1ad47SJeff Kirsher  *  Success returns 0, Failure returns 1
2845dee1ad47SJeff Kirsher  *
2846dee1ad47SJeff Kirsher  *  The low power link up (lplu) state is set to the power management level D0
2847dee1ad47SJeff Kirsher  *  and SmartSpeed is disabled when active is true, else clear lplu for D0
2848dee1ad47SJeff Kirsher  *  and enable Smartspeed.  LPLU and Smartspeed are mutually exclusive.  LPLU
2849dee1ad47SJeff Kirsher  *  is used during Dx states where the power conservation is most important.
2850dee1ad47SJeff Kirsher  *  During driver activity, SmartSpeed should be enabled so performance is
2851dee1ad47SJeff Kirsher  *  maintained.  This is a function pointer entry point called by drivers.
2852dee1ad47SJeff Kirsher  **/
2853dee1ad47SJeff Kirsher static s32 e1000_set_d0_lplu_state(struct e1000_hw *hw, bool active)
2854dee1ad47SJeff Kirsher {
2855dee1ad47SJeff Kirsher 	if (hw->phy.ops.set_d0_lplu_state)
2856dee1ad47SJeff Kirsher 		return hw->phy.ops.set_d0_lplu_state(hw, active);
2857dee1ad47SJeff Kirsher 
2858dee1ad47SJeff Kirsher 	return 0;
2859dee1ad47SJeff Kirsher }
2860dee1ad47SJeff Kirsher 
2861dee1ad47SJeff Kirsher /**
2862dee1ad47SJeff Kirsher  *  __e1000_read_phy_reg_hv -  Read HV PHY register
2863dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
2864dee1ad47SJeff Kirsher  *  @offset: register offset to be read
2865dee1ad47SJeff Kirsher  *  @data: pointer to the read data
2866dee1ad47SJeff Kirsher  *  @locked: semaphore has already been acquired or not
2867dee1ad47SJeff Kirsher  *
2868dee1ad47SJeff Kirsher  *  Acquires semaphore, if necessary, then reads the PHY register at offset
2869dee1ad47SJeff Kirsher  *  and stores the retrieved information in data.  Release any acquired
2870dee1ad47SJeff Kirsher  *  semaphore before exiting.
2871dee1ad47SJeff Kirsher  **/
2872dee1ad47SJeff Kirsher static s32 __e1000_read_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 *data,
2873dee1ad47SJeff Kirsher 				   bool locked, bool page_set)
2874dee1ad47SJeff Kirsher {
2875dee1ad47SJeff Kirsher 	s32 ret_val;
2876dee1ad47SJeff Kirsher 	u16 page = BM_PHY_REG_PAGE(offset);
2877dee1ad47SJeff Kirsher 	u16 reg = BM_PHY_REG_NUM(offset);
2878dee1ad47SJeff Kirsher 	u32 phy_addr = hw->phy.addr = e1000_get_phy_addr_for_hv_page(page);
2879dee1ad47SJeff Kirsher 
2880dee1ad47SJeff Kirsher 	if (!locked) {
2881dee1ad47SJeff Kirsher 		ret_val = hw->phy.ops.acquire(hw);
2882dee1ad47SJeff Kirsher 		if (ret_val)
2883dee1ad47SJeff Kirsher 			return ret_val;
2884dee1ad47SJeff Kirsher 	}
2885dee1ad47SJeff Kirsher 
2886dee1ad47SJeff Kirsher 	/* Page 800 works differently than the rest so it has its own func */
2887dee1ad47SJeff Kirsher 	if (page == BM_WUC_PAGE) {
2888dee1ad47SJeff Kirsher 		ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, data,
2889dee1ad47SJeff Kirsher 							 true, page_set);
2890dee1ad47SJeff Kirsher 		goto out;
2891dee1ad47SJeff Kirsher 	}
2892dee1ad47SJeff Kirsher 
2893dee1ad47SJeff Kirsher 	if (page > 0 && page < HV_INTC_FC_PAGE_START) {
2894dee1ad47SJeff Kirsher 		ret_val = e1000_access_phy_debug_regs_hv(hw, offset,
2895dee1ad47SJeff Kirsher 		                                         data, true);
2896dee1ad47SJeff Kirsher 		goto out;
2897dee1ad47SJeff Kirsher 	}
2898dee1ad47SJeff Kirsher 
2899dee1ad47SJeff Kirsher 	if (!page_set) {
2900dee1ad47SJeff Kirsher 		if (page == HV_INTC_FC_PAGE_START)
2901dee1ad47SJeff Kirsher 			page = 0;
2902dee1ad47SJeff Kirsher 
2903dee1ad47SJeff Kirsher 		if (reg > MAX_PHY_MULTI_PAGE_REG) {
2904dee1ad47SJeff Kirsher 			/* Page is shifted left, PHY expects (page x 32) */
2905dee1ad47SJeff Kirsher 			ret_val = e1000_set_page_igp(hw,
2906dee1ad47SJeff Kirsher 						     (page << IGP_PAGE_SHIFT));
2907dee1ad47SJeff Kirsher 
2908dee1ad47SJeff Kirsher 			hw->phy.addr = phy_addr;
2909dee1ad47SJeff Kirsher 
2910dee1ad47SJeff Kirsher 			if (ret_val)
2911dee1ad47SJeff Kirsher 				goto out;
2912dee1ad47SJeff Kirsher 		}
2913dee1ad47SJeff Kirsher 	}
2914dee1ad47SJeff Kirsher 
2915dee1ad47SJeff Kirsher 	e_dbg("reading PHY page %d (or 0x%x shifted) reg 0x%x\n", page,
2916dee1ad47SJeff Kirsher 	      page << IGP_PAGE_SHIFT, reg);
2917dee1ad47SJeff Kirsher 
2918dee1ad47SJeff Kirsher 	ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & reg,
2919dee1ad47SJeff Kirsher 	                                  data);
2920dee1ad47SJeff Kirsher out:
2921dee1ad47SJeff Kirsher 	if (!locked)
2922dee1ad47SJeff Kirsher 		hw->phy.ops.release(hw);
2923dee1ad47SJeff Kirsher 
2924dee1ad47SJeff Kirsher 	return ret_val;
2925dee1ad47SJeff Kirsher }
2926dee1ad47SJeff Kirsher 
2927dee1ad47SJeff Kirsher /**
2928dee1ad47SJeff Kirsher  *  e1000_read_phy_reg_hv -  Read HV PHY register
2929dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
2930dee1ad47SJeff Kirsher  *  @offset: register offset to be read
2931dee1ad47SJeff Kirsher  *  @data: pointer to the read data
2932dee1ad47SJeff Kirsher  *
2933dee1ad47SJeff Kirsher  *  Acquires semaphore then reads the PHY register at offset and stores
2934dee1ad47SJeff Kirsher  *  the retrieved information in data.  Release the acquired semaphore
2935dee1ad47SJeff Kirsher  *  before exiting.
2936dee1ad47SJeff Kirsher  **/
2937dee1ad47SJeff Kirsher s32 e1000_read_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 *data)
2938dee1ad47SJeff Kirsher {
2939dee1ad47SJeff Kirsher 	return __e1000_read_phy_reg_hv(hw, offset, data, false, false);
2940dee1ad47SJeff Kirsher }
2941dee1ad47SJeff Kirsher 
2942dee1ad47SJeff Kirsher /**
2943dee1ad47SJeff Kirsher  *  e1000_read_phy_reg_hv_locked -  Read HV PHY register
2944dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
2945dee1ad47SJeff Kirsher  *  @offset: register offset to be read
2946dee1ad47SJeff Kirsher  *  @data: pointer to the read data
2947dee1ad47SJeff Kirsher  *
2948dee1ad47SJeff Kirsher  *  Reads the PHY register at offset and stores the retrieved information
2949dee1ad47SJeff Kirsher  *  in data.  Assumes semaphore already acquired.
2950dee1ad47SJeff Kirsher  **/
2951dee1ad47SJeff Kirsher s32 e1000_read_phy_reg_hv_locked(struct e1000_hw *hw, u32 offset, u16 *data)
2952dee1ad47SJeff Kirsher {
2953dee1ad47SJeff Kirsher 	return __e1000_read_phy_reg_hv(hw, offset, data, true, false);
2954dee1ad47SJeff Kirsher }
2955dee1ad47SJeff Kirsher 
2956dee1ad47SJeff Kirsher /**
2957dee1ad47SJeff Kirsher  *  e1000_read_phy_reg_page_hv - Read HV PHY register
2958dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
2959dee1ad47SJeff Kirsher  *  @offset: register offset to write to
2960dee1ad47SJeff Kirsher  *  @data: data to write at register offset
2961dee1ad47SJeff Kirsher  *
2962dee1ad47SJeff Kirsher  *  Reads the PHY register at offset and stores the retrieved information
2963dee1ad47SJeff Kirsher  *  in data.  Assumes semaphore already acquired and page already set.
2964dee1ad47SJeff Kirsher  **/
2965dee1ad47SJeff Kirsher s32 e1000_read_phy_reg_page_hv(struct e1000_hw *hw, u32 offset, u16 *data)
2966dee1ad47SJeff Kirsher {
2967dee1ad47SJeff Kirsher 	return __e1000_read_phy_reg_hv(hw, offset, data, true, true);
2968dee1ad47SJeff Kirsher }
2969dee1ad47SJeff Kirsher 
2970dee1ad47SJeff Kirsher /**
2971dee1ad47SJeff Kirsher  *  __e1000_write_phy_reg_hv - Write HV PHY register
2972dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
2973dee1ad47SJeff Kirsher  *  @offset: register offset to write to
2974dee1ad47SJeff Kirsher  *  @data: data to write at register offset
2975dee1ad47SJeff Kirsher  *  @locked: semaphore has already been acquired or not
2976dee1ad47SJeff Kirsher  *
2977dee1ad47SJeff Kirsher  *  Acquires semaphore, if necessary, then writes the data to PHY register
2978dee1ad47SJeff Kirsher  *  at the offset.  Release any acquired semaphores before exiting.
2979dee1ad47SJeff Kirsher  **/
2980dee1ad47SJeff Kirsher static s32 __e1000_write_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 data,
2981dee1ad47SJeff Kirsher 				    bool locked, bool page_set)
2982dee1ad47SJeff Kirsher {
2983dee1ad47SJeff Kirsher 	s32 ret_val;
2984dee1ad47SJeff Kirsher 	u16 page = BM_PHY_REG_PAGE(offset);
2985dee1ad47SJeff Kirsher 	u16 reg = BM_PHY_REG_NUM(offset);
2986dee1ad47SJeff Kirsher 	u32 phy_addr = hw->phy.addr = e1000_get_phy_addr_for_hv_page(page);
2987dee1ad47SJeff Kirsher 
2988dee1ad47SJeff Kirsher 	if (!locked) {
2989dee1ad47SJeff Kirsher 		ret_val = hw->phy.ops.acquire(hw);
2990dee1ad47SJeff Kirsher 		if (ret_val)
2991dee1ad47SJeff Kirsher 			return ret_val;
2992dee1ad47SJeff Kirsher 	}
2993dee1ad47SJeff Kirsher 
2994dee1ad47SJeff Kirsher 	/* Page 800 works differently than the rest so it has its own func */
2995dee1ad47SJeff Kirsher 	if (page == BM_WUC_PAGE) {
2996dee1ad47SJeff Kirsher 		ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, &data,
2997dee1ad47SJeff Kirsher 							 false, page_set);
2998dee1ad47SJeff Kirsher 		goto out;
2999dee1ad47SJeff Kirsher 	}
3000dee1ad47SJeff Kirsher 
3001dee1ad47SJeff Kirsher 	if (page > 0 && page < HV_INTC_FC_PAGE_START) {
3002dee1ad47SJeff Kirsher 		ret_val = e1000_access_phy_debug_regs_hv(hw, offset,
3003dee1ad47SJeff Kirsher 		                                         &data, false);
3004dee1ad47SJeff Kirsher 		goto out;
3005dee1ad47SJeff Kirsher 	}
3006dee1ad47SJeff Kirsher 
3007dee1ad47SJeff Kirsher 	if (!page_set) {
3008dee1ad47SJeff Kirsher 		if (page == HV_INTC_FC_PAGE_START)
3009dee1ad47SJeff Kirsher 			page = 0;
3010dee1ad47SJeff Kirsher 
3011dee1ad47SJeff Kirsher 		/*
3012dee1ad47SJeff Kirsher 		 * Workaround MDIO accesses being disabled after entering IEEE
3013dee1ad47SJeff Kirsher 		 * Power Down (when bit 11 of the PHY Control register is set)
3014dee1ad47SJeff Kirsher 		 */
3015dee1ad47SJeff Kirsher 		if ((hw->phy.type == e1000_phy_82578) &&
3016dee1ad47SJeff Kirsher 		    (hw->phy.revision >= 1) &&
3017dee1ad47SJeff Kirsher 		    (hw->phy.addr == 2) &&
3018dee1ad47SJeff Kirsher 		    ((MAX_PHY_REG_ADDRESS & reg) == 0) && (data & (1 << 11))) {
3019dee1ad47SJeff Kirsher 			u16 data2 = 0x7EFF;
3020dee1ad47SJeff Kirsher 			ret_val = e1000_access_phy_debug_regs_hv(hw,
3021dee1ad47SJeff Kirsher 								 (1 << 6) | 0x3,
3022dee1ad47SJeff Kirsher 								 &data2, false);
3023dee1ad47SJeff Kirsher 			if (ret_val)
3024dee1ad47SJeff Kirsher 				goto out;
3025dee1ad47SJeff Kirsher 		}
3026dee1ad47SJeff Kirsher 
3027dee1ad47SJeff Kirsher 		if (reg > MAX_PHY_MULTI_PAGE_REG) {
3028dee1ad47SJeff Kirsher 			/* Page is shifted left, PHY expects (page x 32) */
3029dee1ad47SJeff Kirsher 			ret_val = e1000_set_page_igp(hw,
3030dee1ad47SJeff Kirsher 						     (page << IGP_PAGE_SHIFT));
3031dee1ad47SJeff Kirsher 
3032dee1ad47SJeff Kirsher 			hw->phy.addr = phy_addr;
3033dee1ad47SJeff Kirsher 
3034dee1ad47SJeff Kirsher 			if (ret_val)
3035dee1ad47SJeff Kirsher 				goto out;
3036dee1ad47SJeff Kirsher 		}
3037dee1ad47SJeff Kirsher 	}
3038dee1ad47SJeff Kirsher 
3039dee1ad47SJeff Kirsher 	e_dbg("writing PHY page %d (or 0x%x shifted) reg 0x%x\n", page,
3040dee1ad47SJeff Kirsher 	      page << IGP_PAGE_SHIFT, reg);
3041dee1ad47SJeff Kirsher 
3042dee1ad47SJeff Kirsher 	ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & reg,
3043dee1ad47SJeff Kirsher 	                                  data);
3044dee1ad47SJeff Kirsher 
3045dee1ad47SJeff Kirsher out:
3046dee1ad47SJeff Kirsher 	if (!locked)
3047dee1ad47SJeff Kirsher 		hw->phy.ops.release(hw);
3048dee1ad47SJeff Kirsher 
3049dee1ad47SJeff Kirsher 	return ret_val;
3050dee1ad47SJeff Kirsher }
3051dee1ad47SJeff Kirsher 
3052dee1ad47SJeff Kirsher /**
3053dee1ad47SJeff Kirsher  *  e1000_write_phy_reg_hv - Write HV PHY register
3054dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
3055dee1ad47SJeff Kirsher  *  @offset: register offset to write to
3056dee1ad47SJeff Kirsher  *  @data: data to write at register offset
3057dee1ad47SJeff Kirsher  *
3058dee1ad47SJeff Kirsher  *  Acquires semaphore then writes the data to PHY register at the offset.
3059dee1ad47SJeff Kirsher  *  Release the acquired semaphores before exiting.
3060dee1ad47SJeff Kirsher  **/
3061dee1ad47SJeff Kirsher s32 e1000_write_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 data)
3062dee1ad47SJeff Kirsher {
3063dee1ad47SJeff Kirsher 	return __e1000_write_phy_reg_hv(hw, offset, data, false, false);
3064dee1ad47SJeff Kirsher }
3065dee1ad47SJeff Kirsher 
3066dee1ad47SJeff Kirsher /**
3067dee1ad47SJeff Kirsher  *  e1000_write_phy_reg_hv_locked - Write HV PHY register
3068dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
3069dee1ad47SJeff Kirsher  *  @offset: register offset to write to
3070dee1ad47SJeff Kirsher  *  @data: data to write at register offset
3071dee1ad47SJeff Kirsher  *
3072dee1ad47SJeff Kirsher  *  Writes the data to PHY register at the offset.  Assumes semaphore
3073dee1ad47SJeff Kirsher  *  already acquired.
3074dee1ad47SJeff Kirsher  **/
3075dee1ad47SJeff Kirsher s32 e1000_write_phy_reg_hv_locked(struct e1000_hw *hw, u32 offset, u16 data)
3076dee1ad47SJeff Kirsher {
3077dee1ad47SJeff Kirsher 	return __e1000_write_phy_reg_hv(hw, offset, data, true, false);
3078dee1ad47SJeff Kirsher }
3079dee1ad47SJeff Kirsher 
3080dee1ad47SJeff Kirsher /**
3081dee1ad47SJeff Kirsher  *  e1000_write_phy_reg_page_hv - Write HV PHY register
3082dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
3083dee1ad47SJeff Kirsher  *  @offset: register offset to write to
3084dee1ad47SJeff Kirsher  *  @data: data to write at register offset
3085dee1ad47SJeff Kirsher  *
3086dee1ad47SJeff Kirsher  *  Writes the data to PHY register at the offset.  Assumes semaphore
3087dee1ad47SJeff Kirsher  *  already acquired and page already set.
3088dee1ad47SJeff Kirsher  **/
3089dee1ad47SJeff Kirsher s32 e1000_write_phy_reg_page_hv(struct e1000_hw *hw, u32 offset, u16 data)
3090dee1ad47SJeff Kirsher {
3091dee1ad47SJeff Kirsher 	return __e1000_write_phy_reg_hv(hw, offset, data, true, true);
3092dee1ad47SJeff Kirsher }
3093dee1ad47SJeff Kirsher 
3094dee1ad47SJeff Kirsher /**
3095dee1ad47SJeff Kirsher  *  e1000_get_phy_addr_for_hv_page - Get PHY address based on page
3096dee1ad47SJeff Kirsher  *  @page: page to be accessed
3097dee1ad47SJeff Kirsher  **/
3098dee1ad47SJeff Kirsher static u32 e1000_get_phy_addr_for_hv_page(u32 page)
3099dee1ad47SJeff Kirsher {
3100dee1ad47SJeff Kirsher 	u32 phy_addr = 2;
3101dee1ad47SJeff Kirsher 
3102dee1ad47SJeff Kirsher 	if (page >= HV_INTC_FC_PAGE_START)
3103dee1ad47SJeff Kirsher 		phy_addr = 1;
3104dee1ad47SJeff Kirsher 
3105dee1ad47SJeff Kirsher 	return phy_addr;
3106dee1ad47SJeff Kirsher }
3107dee1ad47SJeff Kirsher 
3108dee1ad47SJeff Kirsher /**
3109dee1ad47SJeff Kirsher  *  e1000_access_phy_debug_regs_hv - Read HV PHY vendor specific high registers
3110dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
3111dee1ad47SJeff Kirsher  *  @offset: register offset to be read or written
3112dee1ad47SJeff Kirsher  *  @data: pointer to the data to be read or written
3113dee1ad47SJeff Kirsher  *  @read: determines if operation is read or write
3114dee1ad47SJeff Kirsher  *
3115dee1ad47SJeff Kirsher  *  Reads the PHY register at offset and stores the retreived information
3116dee1ad47SJeff Kirsher  *  in data.  Assumes semaphore already acquired.  Note that the procedure
3117dee1ad47SJeff Kirsher  *  to access these regs uses the address port and data port to read/write.
3118dee1ad47SJeff Kirsher  *  These accesses done with PHY address 2 and without using pages.
3119dee1ad47SJeff Kirsher  **/
3120dee1ad47SJeff Kirsher static s32 e1000_access_phy_debug_regs_hv(struct e1000_hw *hw, u32 offset,
3121dee1ad47SJeff Kirsher                                           u16 *data, bool read)
3122dee1ad47SJeff Kirsher {
3123dee1ad47SJeff Kirsher 	s32 ret_val;
3124dee1ad47SJeff Kirsher 	u32 addr_reg = 0;
3125dee1ad47SJeff Kirsher 	u32 data_reg = 0;
3126dee1ad47SJeff Kirsher 
3127dee1ad47SJeff Kirsher 	/* This takes care of the difference with desktop vs mobile phy */
3128dee1ad47SJeff Kirsher 	addr_reg = (hw->phy.type == e1000_phy_82578) ?
3129dee1ad47SJeff Kirsher 	           I82578_ADDR_REG : I82577_ADDR_REG;
3130dee1ad47SJeff Kirsher 	data_reg = addr_reg + 1;
3131dee1ad47SJeff Kirsher 
3132dee1ad47SJeff Kirsher 	/* All operations in this function are phy address 2 */
3133dee1ad47SJeff Kirsher 	hw->phy.addr = 2;
3134dee1ad47SJeff Kirsher 
3135dee1ad47SJeff Kirsher 	/* masking with 0x3F to remove the page from offset */
3136dee1ad47SJeff Kirsher 	ret_val = e1000e_write_phy_reg_mdic(hw, addr_reg, (u16)offset & 0x3F);
3137dee1ad47SJeff Kirsher 	if (ret_val) {
3138dee1ad47SJeff Kirsher 		e_dbg("Could not write the Address Offset port register\n");
3139dee1ad47SJeff Kirsher 		goto out;
3140dee1ad47SJeff Kirsher 	}
3141dee1ad47SJeff Kirsher 
3142dee1ad47SJeff Kirsher 	/* Read or write the data value next */
3143dee1ad47SJeff Kirsher 	if (read)
3144dee1ad47SJeff Kirsher 		ret_val = e1000e_read_phy_reg_mdic(hw, data_reg, data);
3145dee1ad47SJeff Kirsher 	else
3146dee1ad47SJeff Kirsher 		ret_val = e1000e_write_phy_reg_mdic(hw, data_reg, *data);
3147dee1ad47SJeff Kirsher 
3148dee1ad47SJeff Kirsher 	if (ret_val) {
3149dee1ad47SJeff Kirsher 		e_dbg("Could not access the Data port register\n");
3150dee1ad47SJeff Kirsher 		goto out;
3151dee1ad47SJeff Kirsher 	}
3152dee1ad47SJeff Kirsher 
3153dee1ad47SJeff Kirsher out:
3154dee1ad47SJeff Kirsher 	return ret_val;
3155dee1ad47SJeff Kirsher }
3156dee1ad47SJeff Kirsher 
3157dee1ad47SJeff Kirsher /**
3158dee1ad47SJeff Kirsher  *  e1000_link_stall_workaround_hv - Si workaround
3159dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
3160dee1ad47SJeff Kirsher  *
3161dee1ad47SJeff Kirsher  *  This function works around a Si bug where the link partner can get
3162dee1ad47SJeff Kirsher  *  a link up indication before the PHY does.  If small packets are sent
3163dee1ad47SJeff Kirsher  *  by the link partner they can be placed in the packet buffer without
3164dee1ad47SJeff Kirsher  *  being properly accounted for by the PHY and will stall preventing
3165dee1ad47SJeff Kirsher  *  further packets from being received.  The workaround is to clear the
3166dee1ad47SJeff Kirsher  *  packet buffer after the PHY detects link up.
3167dee1ad47SJeff Kirsher  **/
3168dee1ad47SJeff Kirsher s32 e1000_link_stall_workaround_hv(struct e1000_hw *hw)
3169dee1ad47SJeff Kirsher {
3170dee1ad47SJeff Kirsher 	s32 ret_val = 0;
3171dee1ad47SJeff Kirsher 	u16 data;
3172dee1ad47SJeff Kirsher 
3173dee1ad47SJeff Kirsher 	if (hw->phy.type != e1000_phy_82578)
3174dee1ad47SJeff Kirsher 		goto out;
3175dee1ad47SJeff Kirsher 
3176dee1ad47SJeff Kirsher 	/* Do not apply workaround if in PHY loopback bit 14 set */
3177dee1ad47SJeff Kirsher 	e1e_rphy(hw, PHY_CONTROL, &data);
3178dee1ad47SJeff Kirsher 	if (data & PHY_CONTROL_LB)
3179dee1ad47SJeff Kirsher 		goto out;
3180dee1ad47SJeff Kirsher 
3181dee1ad47SJeff Kirsher 	/* check if link is up and at 1Gbps */
3182dee1ad47SJeff Kirsher 	ret_val = e1e_rphy(hw, BM_CS_STATUS, &data);
3183dee1ad47SJeff Kirsher 	if (ret_val)
3184dee1ad47SJeff Kirsher 		goto out;
3185dee1ad47SJeff Kirsher 
3186dee1ad47SJeff Kirsher 	data &= BM_CS_STATUS_LINK_UP |
3187dee1ad47SJeff Kirsher 	        BM_CS_STATUS_RESOLVED |
3188dee1ad47SJeff Kirsher 	        BM_CS_STATUS_SPEED_MASK;
3189dee1ad47SJeff Kirsher 
3190dee1ad47SJeff Kirsher 	if (data != (BM_CS_STATUS_LINK_UP |
3191dee1ad47SJeff Kirsher 	             BM_CS_STATUS_RESOLVED |
3192dee1ad47SJeff Kirsher 	             BM_CS_STATUS_SPEED_1000))
3193dee1ad47SJeff Kirsher 		goto out;
3194dee1ad47SJeff Kirsher 
3195dee1ad47SJeff Kirsher 	mdelay(200);
3196dee1ad47SJeff Kirsher 
3197dee1ad47SJeff Kirsher 	/* flush the packets in the fifo buffer */
3198dee1ad47SJeff Kirsher 	ret_val = e1e_wphy(hw, HV_MUX_DATA_CTRL, HV_MUX_DATA_CTRL_GEN_TO_MAC |
3199dee1ad47SJeff Kirsher 			   HV_MUX_DATA_CTRL_FORCE_SPEED);
3200dee1ad47SJeff Kirsher 	if (ret_val)
3201dee1ad47SJeff Kirsher 		goto out;
3202dee1ad47SJeff Kirsher 
3203dee1ad47SJeff Kirsher 	ret_val = e1e_wphy(hw, HV_MUX_DATA_CTRL, HV_MUX_DATA_CTRL_GEN_TO_MAC);
3204dee1ad47SJeff Kirsher 
3205dee1ad47SJeff Kirsher out:
3206dee1ad47SJeff Kirsher 	return ret_val;
3207dee1ad47SJeff Kirsher }
3208dee1ad47SJeff Kirsher 
3209dee1ad47SJeff Kirsher /**
3210dee1ad47SJeff Kirsher  *  e1000_check_polarity_82577 - Checks the polarity.
3211dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
3212dee1ad47SJeff Kirsher  *
3213dee1ad47SJeff Kirsher  *  Success returns 0, Failure returns -E1000_ERR_PHY (-2)
3214dee1ad47SJeff Kirsher  *
3215dee1ad47SJeff Kirsher  *  Polarity is determined based on the PHY specific status register.
3216dee1ad47SJeff Kirsher  **/
3217dee1ad47SJeff Kirsher s32 e1000_check_polarity_82577(struct e1000_hw *hw)
3218dee1ad47SJeff Kirsher {
3219dee1ad47SJeff Kirsher 	struct e1000_phy_info *phy = &hw->phy;
3220dee1ad47SJeff Kirsher 	s32 ret_val;
3221dee1ad47SJeff Kirsher 	u16 data;
3222dee1ad47SJeff Kirsher 
3223dee1ad47SJeff Kirsher 	ret_val = e1e_rphy(hw, I82577_PHY_STATUS_2, &data);
3224dee1ad47SJeff Kirsher 
3225dee1ad47SJeff Kirsher 	if (!ret_val)
3226dee1ad47SJeff Kirsher 		phy->cable_polarity = (data & I82577_PHY_STATUS2_REV_POLARITY)
3227dee1ad47SJeff Kirsher 		                      ? e1000_rev_polarity_reversed
3228dee1ad47SJeff Kirsher 		                      : e1000_rev_polarity_normal;
3229dee1ad47SJeff Kirsher 
3230dee1ad47SJeff Kirsher 	return ret_val;
3231dee1ad47SJeff Kirsher }
3232dee1ad47SJeff Kirsher 
3233dee1ad47SJeff Kirsher /**
3234dee1ad47SJeff Kirsher  *  e1000_phy_force_speed_duplex_82577 - Force speed/duplex for I82577 PHY
3235dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
3236dee1ad47SJeff Kirsher  *
3237dee1ad47SJeff Kirsher  *  Calls the PHY setup function to force speed and duplex.
3238dee1ad47SJeff Kirsher  **/
3239dee1ad47SJeff Kirsher s32 e1000_phy_force_speed_duplex_82577(struct e1000_hw *hw)
3240dee1ad47SJeff Kirsher {
3241dee1ad47SJeff Kirsher 	struct e1000_phy_info *phy = &hw->phy;
3242dee1ad47SJeff Kirsher 	s32 ret_val;
3243dee1ad47SJeff Kirsher 	u16 phy_data;
3244dee1ad47SJeff Kirsher 	bool link;
3245dee1ad47SJeff Kirsher 
3246dee1ad47SJeff Kirsher 	ret_val = e1e_rphy(hw, PHY_CONTROL, &phy_data);
3247dee1ad47SJeff Kirsher 	if (ret_val)
3248dee1ad47SJeff Kirsher 		goto out;
3249dee1ad47SJeff Kirsher 
3250dee1ad47SJeff Kirsher 	e1000e_phy_force_speed_duplex_setup(hw, &phy_data);
3251dee1ad47SJeff Kirsher 
3252dee1ad47SJeff Kirsher 	ret_val = e1e_wphy(hw, PHY_CONTROL, phy_data);
3253dee1ad47SJeff Kirsher 	if (ret_val)
3254dee1ad47SJeff Kirsher 		goto out;
3255dee1ad47SJeff Kirsher 
3256dee1ad47SJeff Kirsher 	udelay(1);
3257dee1ad47SJeff Kirsher 
3258dee1ad47SJeff Kirsher 	if (phy->autoneg_wait_to_complete) {
3259dee1ad47SJeff Kirsher 		e_dbg("Waiting for forced speed/duplex link on 82577 phy\n");
3260dee1ad47SJeff Kirsher 
3261dee1ad47SJeff Kirsher 		ret_val = e1000e_phy_has_link_generic(hw,
3262dee1ad47SJeff Kirsher 		                                     PHY_FORCE_LIMIT,
3263dee1ad47SJeff Kirsher 		                                     100000,
3264dee1ad47SJeff Kirsher 		                                     &link);
3265dee1ad47SJeff Kirsher 		if (ret_val)
3266dee1ad47SJeff Kirsher 			goto out;
3267dee1ad47SJeff Kirsher 
3268dee1ad47SJeff Kirsher 		if (!link)
3269dee1ad47SJeff Kirsher 			e_dbg("Link taking longer than expected.\n");
3270dee1ad47SJeff Kirsher 
3271dee1ad47SJeff Kirsher 		/* Try once more */
3272dee1ad47SJeff Kirsher 		ret_val = e1000e_phy_has_link_generic(hw,
3273dee1ad47SJeff Kirsher 		                                     PHY_FORCE_LIMIT,
3274dee1ad47SJeff Kirsher 		                                     100000,
3275dee1ad47SJeff Kirsher 		                                     &link);
3276dee1ad47SJeff Kirsher 		if (ret_val)
3277dee1ad47SJeff Kirsher 			goto out;
3278dee1ad47SJeff Kirsher 	}
3279dee1ad47SJeff Kirsher 
3280dee1ad47SJeff Kirsher out:
3281dee1ad47SJeff Kirsher 	return ret_val;
3282dee1ad47SJeff Kirsher }
3283dee1ad47SJeff Kirsher 
3284dee1ad47SJeff Kirsher /**
3285dee1ad47SJeff Kirsher  *  e1000_get_phy_info_82577 - Retrieve I82577 PHY information
3286dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
3287dee1ad47SJeff Kirsher  *
3288dee1ad47SJeff Kirsher  *  Read PHY status to determine if link is up.  If link is up, then
3289dee1ad47SJeff Kirsher  *  set/determine 10base-T extended distance and polarity correction.  Read
3290dee1ad47SJeff Kirsher  *  PHY port status to determine MDI/MDIx and speed.  Based on the speed,
3291dee1ad47SJeff Kirsher  *  determine on the cable length, local and remote receiver.
3292dee1ad47SJeff Kirsher  **/
3293dee1ad47SJeff Kirsher s32 e1000_get_phy_info_82577(struct e1000_hw *hw)
3294dee1ad47SJeff Kirsher {
3295dee1ad47SJeff Kirsher 	struct e1000_phy_info *phy = &hw->phy;
3296dee1ad47SJeff Kirsher 	s32 ret_val;
3297dee1ad47SJeff Kirsher 	u16 data;
3298dee1ad47SJeff Kirsher 	bool link;
3299dee1ad47SJeff Kirsher 
3300dee1ad47SJeff Kirsher 	ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
3301dee1ad47SJeff Kirsher 	if (ret_val)
3302dee1ad47SJeff Kirsher 		goto out;
3303dee1ad47SJeff Kirsher 
3304dee1ad47SJeff Kirsher 	if (!link) {
3305dee1ad47SJeff Kirsher 		e_dbg("Phy info is only valid if link is up\n");
3306dee1ad47SJeff Kirsher 		ret_val = -E1000_ERR_CONFIG;
3307dee1ad47SJeff Kirsher 		goto out;
3308dee1ad47SJeff Kirsher 	}
3309dee1ad47SJeff Kirsher 
3310dee1ad47SJeff Kirsher 	phy->polarity_correction = true;
3311dee1ad47SJeff Kirsher 
3312dee1ad47SJeff Kirsher 	ret_val = e1000_check_polarity_82577(hw);
3313dee1ad47SJeff Kirsher 	if (ret_val)
3314dee1ad47SJeff Kirsher 		goto out;
3315dee1ad47SJeff Kirsher 
3316dee1ad47SJeff Kirsher 	ret_val = e1e_rphy(hw, I82577_PHY_STATUS_2, &data);
3317dee1ad47SJeff Kirsher 	if (ret_val)
3318dee1ad47SJeff Kirsher 		goto out;
3319dee1ad47SJeff Kirsher 
3320dee1ad47SJeff Kirsher 	phy->is_mdix = (data & I82577_PHY_STATUS2_MDIX) ? true : false;
3321dee1ad47SJeff Kirsher 
3322dee1ad47SJeff Kirsher 	if ((data & I82577_PHY_STATUS2_SPEED_MASK) ==
3323dee1ad47SJeff Kirsher 	    I82577_PHY_STATUS2_SPEED_1000MBPS) {
3324dee1ad47SJeff Kirsher 		ret_val = hw->phy.ops.get_cable_length(hw);
3325dee1ad47SJeff Kirsher 		if (ret_val)
3326dee1ad47SJeff Kirsher 			goto out;
3327dee1ad47SJeff Kirsher 
3328dee1ad47SJeff Kirsher 		ret_val = e1e_rphy(hw, PHY_1000T_STATUS, &data);
3329dee1ad47SJeff Kirsher 		if (ret_val)
3330dee1ad47SJeff Kirsher 			goto out;
3331dee1ad47SJeff Kirsher 
3332dee1ad47SJeff Kirsher 		phy->local_rx = (data & SR_1000T_LOCAL_RX_STATUS)
3333dee1ad47SJeff Kirsher 		                ? e1000_1000t_rx_status_ok
3334dee1ad47SJeff Kirsher 		                : e1000_1000t_rx_status_not_ok;
3335dee1ad47SJeff Kirsher 
3336dee1ad47SJeff Kirsher 		phy->remote_rx = (data & SR_1000T_REMOTE_RX_STATUS)
3337dee1ad47SJeff Kirsher 		                 ? e1000_1000t_rx_status_ok
3338dee1ad47SJeff Kirsher 		                 : e1000_1000t_rx_status_not_ok;
3339dee1ad47SJeff Kirsher 	} else {
3340dee1ad47SJeff Kirsher 		phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
3341dee1ad47SJeff Kirsher 		phy->local_rx = e1000_1000t_rx_status_undefined;
3342dee1ad47SJeff Kirsher 		phy->remote_rx = e1000_1000t_rx_status_undefined;
3343dee1ad47SJeff Kirsher 	}
3344dee1ad47SJeff Kirsher 
3345dee1ad47SJeff Kirsher out:
3346dee1ad47SJeff Kirsher 	return ret_val;
3347dee1ad47SJeff Kirsher }
3348dee1ad47SJeff Kirsher 
3349dee1ad47SJeff Kirsher /**
3350dee1ad47SJeff Kirsher  *  e1000_get_cable_length_82577 - Determine cable length for 82577 PHY
3351dee1ad47SJeff Kirsher  *  @hw: pointer to the HW structure
3352dee1ad47SJeff Kirsher  *
3353dee1ad47SJeff Kirsher  * Reads the diagnostic status register and verifies result is valid before
3354dee1ad47SJeff Kirsher  * placing it in the phy_cable_length field.
3355dee1ad47SJeff Kirsher  **/
3356dee1ad47SJeff Kirsher s32 e1000_get_cable_length_82577(struct e1000_hw *hw)
3357dee1ad47SJeff Kirsher {
3358dee1ad47SJeff Kirsher 	struct e1000_phy_info *phy = &hw->phy;
3359dee1ad47SJeff Kirsher 	s32 ret_val;
3360dee1ad47SJeff Kirsher 	u16 phy_data, length;
3361dee1ad47SJeff Kirsher 
3362dee1ad47SJeff Kirsher 	ret_val = e1e_rphy(hw, I82577_PHY_DIAG_STATUS, &phy_data);
3363dee1ad47SJeff Kirsher 	if (ret_val)
3364dee1ad47SJeff Kirsher 		goto out;
3365dee1ad47SJeff Kirsher 
3366dee1ad47SJeff Kirsher 	length = (phy_data & I82577_DSTATUS_CABLE_LENGTH) >>
3367dee1ad47SJeff Kirsher 	         I82577_DSTATUS_CABLE_LENGTH_SHIFT;
3368dee1ad47SJeff Kirsher 
3369dee1ad47SJeff Kirsher 	if (length == E1000_CABLE_LENGTH_UNDEFINED)
3370dee1ad47SJeff Kirsher 		ret_val = -E1000_ERR_PHY;
3371dee1ad47SJeff Kirsher 
3372dee1ad47SJeff Kirsher 	phy->cable_length = length;
3373dee1ad47SJeff Kirsher 
3374dee1ad47SJeff Kirsher out:
3375dee1ad47SJeff Kirsher 	return ret_val;
3376dee1ad47SJeff Kirsher }
3377