xref: /freebsd/sys/dev/e1000/e1000_phy.c (revision 48600901a8493d8debeaa065844f250b52414e55)
18cfa0ad2SJack F Vogel /******************************************************************************
28cfa0ad2SJack F Vogel 
37c669ab6SSean Bruno   Copyright (c) 2001-2015, Intel Corporation
48cfa0ad2SJack F Vogel   All rights reserved.
58cfa0ad2SJack F Vogel 
68cfa0ad2SJack F Vogel   Redistribution and use in source and binary forms, with or without
78cfa0ad2SJack F Vogel   modification, are permitted provided that the following conditions are met:
88cfa0ad2SJack F Vogel 
98cfa0ad2SJack F Vogel    1. Redistributions of source code must retain the above copyright notice,
108cfa0ad2SJack F Vogel       this list of conditions and the following disclaimer.
118cfa0ad2SJack F Vogel 
128cfa0ad2SJack F Vogel    2. Redistributions in binary form must reproduce the above copyright
138cfa0ad2SJack F Vogel       notice, this list of conditions and the following disclaimer in the
148cfa0ad2SJack F Vogel       documentation and/or other materials provided with the distribution.
158cfa0ad2SJack F Vogel 
168cfa0ad2SJack F Vogel    3. Neither the name of the Intel Corporation nor the names of its
178cfa0ad2SJack F Vogel       contributors may be used to endorse or promote products derived from
188cfa0ad2SJack F Vogel       this software without specific prior written permission.
198cfa0ad2SJack F Vogel 
208cfa0ad2SJack F Vogel   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
218cfa0ad2SJack F Vogel   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
228cfa0ad2SJack F Vogel   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
238cfa0ad2SJack F Vogel   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
248cfa0ad2SJack F Vogel   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
258cfa0ad2SJack F Vogel   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
268cfa0ad2SJack F Vogel   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
278cfa0ad2SJack F Vogel   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
288cfa0ad2SJack F Vogel   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
298cfa0ad2SJack F Vogel   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
308cfa0ad2SJack F Vogel   POSSIBILITY OF SUCH DAMAGE.
318cfa0ad2SJack F Vogel 
328cfa0ad2SJack F Vogel ******************************************************************************/
338cfa0ad2SJack F Vogel /*$FreeBSD$*/
348cfa0ad2SJack F Vogel 
358cfa0ad2SJack F Vogel #include "e1000_api.h"
368cfa0ad2SJack F Vogel 
376ab6bfe3SJack F Vogel static s32 e1000_wait_autoneg(struct e1000_hw *hw);
38daf9197cSJack F Vogel static s32 e1000_access_phy_wakeup_reg_bm(struct e1000_hw *hw, u32 offset,
394dab5c37SJack F Vogel 					  u16 *data, bool read, bool page_set);
409d81738fSJack F Vogel static u32 e1000_get_phy_addr_for_hv_page(u32 page);
419d81738fSJack F Vogel static s32 e1000_access_phy_debug_regs_hv(struct e1000_hw *hw, u32 offset,
429d81738fSJack F Vogel 					  u16 *data, bool read);
439d81738fSJack F Vogel 
448cfa0ad2SJack F Vogel /* Cable length tables */
45f0ecc46dSJack F Vogel static const u16 e1000_m88_cable_length_table[] = {
46f0ecc46dSJack F Vogel 	0, 50, 80, 110, 140, 140, E1000_CABLE_LENGTH_UNDEFINED };
478cfa0ad2SJack F Vogel #define M88E1000_CABLE_LENGTH_TABLE_SIZE \
488cfa0ad2SJack F Vogel 		(sizeof(e1000_m88_cable_length_table) / \
498cfa0ad2SJack F Vogel 		 sizeof(e1000_m88_cable_length_table[0]))
508cfa0ad2SJack F Vogel 
51f0ecc46dSJack F Vogel static const u16 e1000_igp_2_cable_length_table[] = {
52f0ecc46dSJack F Vogel 	0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21, 0, 0, 0, 3,
53f0ecc46dSJack F Vogel 	6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41, 6, 10, 14, 18, 22,
54f0ecc46dSJack F Vogel 	26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61, 21, 26, 31, 35, 40,
55f0ecc46dSJack F Vogel 	44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82, 40, 45, 51, 56, 61,
56f0ecc46dSJack F Vogel 	66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104, 60, 66, 72, 77, 82,
57f0ecc46dSJack F Vogel 	87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121, 83, 89, 95,
58f0ecc46dSJack F Vogel 	100, 105, 109, 113, 116, 119, 122, 124, 104, 109, 114, 118, 121,
59f0ecc46dSJack F Vogel 	124};
608cfa0ad2SJack F Vogel #define IGP02E1000_CABLE_LENGTH_TABLE_SIZE \
618cfa0ad2SJack F Vogel 		(sizeof(e1000_igp_2_cable_length_table) / \
628cfa0ad2SJack F Vogel 		 sizeof(e1000_igp_2_cable_length_table[0]))
638cfa0ad2SJack F Vogel 
648cfa0ad2SJack F Vogel /**
658cfa0ad2SJack F Vogel  *  e1000_init_phy_ops_generic - Initialize PHY function pointers
668cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
678cfa0ad2SJack F Vogel  *
688cfa0ad2SJack F Vogel  *  Setups up the function pointers to no-op functions
698cfa0ad2SJack F Vogel  **/
708cfa0ad2SJack F Vogel void e1000_init_phy_ops_generic(struct e1000_hw *hw)
718cfa0ad2SJack F Vogel {
728cfa0ad2SJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
738cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_init_phy_ops_generic");
748cfa0ad2SJack F Vogel 
758cfa0ad2SJack F Vogel 	/* Initialize function pointers */
768cfa0ad2SJack F Vogel 	phy->ops.init_params = e1000_null_ops_generic;
778cfa0ad2SJack F Vogel 	phy->ops.acquire = e1000_null_ops_generic;
788cfa0ad2SJack F Vogel 	phy->ops.check_polarity = e1000_null_ops_generic;
798cfa0ad2SJack F Vogel 	phy->ops.check_reset_block = e1000_null_ops_generic;
808cfa0ad2SJack F Vogel 	phy->ops.commit = e1000_null_ops_generic;
818cfa0ad2SJack F Vogel 	phy->ops.force_speed_duplex = e1000_null_ops_generic;
828cfa0ad2SJack F Vogel 	phy->ops.get_cfg_done = e1000_null_ops_generic;
838cfa0ad2SJack F Vogel 	phy->ops.get_cable_length = e1000_null_ops_generic;
848cfa0ad2SJack F Vogel 	phy->ops.get_info = e1000_null_ops_generic;
854dab5c37SJack F Vogel 	phy->ops.set_page = e1000_null_set_page;
868cfa0ad2SJack F Vogel 	phy->ops.read_reg = e1000_null_read_reg;
874edd8523SJack F Vogel 	phy->ops.read_reg_locked = e1000_null_read_reg;
884dab5c37SJack F Vogel 	phy->ops.read_reg_page = e1000_null_read_reg;
898cfa0ad2SJack F Vogel 	phy->ops.release = e1000_null_phy_generic;
908cfa0ad2SJack F Vogel 	phy->ops.reset = e1000_null_ops_generic;
918cfa0ad2SJack F Vogel 	phy->ops.set_d0_lplu_state = e1000_null_lplu_state;
928cfa0ad2SJack F Vogel 	phy->ops.set_d3_lplu_state = e1000_null_lplu_state;
938cfa0ad2SJack F Vogel 	phy->ops.write_reg = e1000_null_write_reg;
944edd8523SJack F Vogel 	phy->ops.write_reg_locked = e1000_null_write_reg;
954dab5c37SJack F Vogel 	phy->ops.write_reg_page = e1000_null_write_reg;
968cfa0ad2SJack F Vogel 	phy->ops.power_up = e1000_null_phy_generic;
978cfa0ad2SJack F Vogel 	phy->ops.power_down = e1000_null_phy_generic;
98ab5d0362SJack F Vogel 	phy->ops.read_i2c_byte = e1000_read_i2c_byte_null;
99ab5d0362SJack F Vogel 	phy->ops.write_i2c_byte = e1000_write_i2c_byte_null;
100daf9197cSJack F Vogel 	phy->ops.cfg_on_link_up = e1000_null_ops_generic;
1018cfa0ad2SJack F Vogel }
1028cfa0ad2SJack F Vogel 
1038cfa0ad2SJack F Vogel /**
1044dab5c37SJack F Vogel  *  e1000_null_set_page - No-op function, return 0
1054dab5c37SJack F Vogel  *  @hw: pointer to the HW structure
1064dab5c37SJack F Vogel  **/
1077609433eSJack F Vogel s32 e1000_null_set_page(struct e1000_hw E1000_UNUSEDARG *hw,
1087609433eSJack F Vogel 			u16 E1000_UNUSEDARG data)
1094dab5c37SJack F Vogel {
1104dab5c37SJack F Vogel 	DEBUGFUNC("e1000_null_set_page");
1114dab5c37SJack F Vogel 	return E1000_SUCCESS;
1124dab5c37SJack F Vogel }
1134dab5c37SJack F Vogel 
1144dab5c37SJack F Vogel /**
1158cfa0ad2SJack F Vogel  *  e1000_null_read_reg - No-op function, return 0
1168cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
1178cfa0ad2SJack F Vogel  **/
1187609433eSJack F Vogel s32 e1000_null_read_reg(struct e1000_hw E1000_UNUSEDARG *hw,
1197609433eSJack F Vogel 			u32 E1000_UNUSEDARG offset, u16 E1000_UNUSEDARG *data)
1208cfa0ad2SJack F Vogel {
1218cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_null_read_reg");
1228cfa0ad2SJack F Vogel 	return E1000_SUCCESS;
1238cfa0ad2SJack F Vogel }
1248cfa0ad2SJack F Vogel 
1258cfa0ad2SJack F Vogel /**
1268cfa0ad2SJack F Vogel  *  e1000_null_phy_generic - No-op function, return void
1278cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
1288cfa0ad2SJack F Vogel  **/
1297609433eSJack F Vogel void e1000_null_phy_generic(struct e1000_hw E1000_UNUSEDARG *hw)
1308cfa0ad2SJack F Vogel {
1318cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_null_phy_generic");
1328cfa0ad2SJack F Vogel 	return;
1338cfa0ad2SJack F Vogel }
1348cfa0ad2SJack F Vogel 
1358cfa0ad2SJack F Vogel /**
1368cfa0ad2SJack F Vogel  *  e1000_null_lplu_state - No-op function, return 0
1378cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
1388cfa0ad2SJack F Vogel  **/
1397609433eSJack F Vogel s32 e1000_null_lplu_state(struct e1000_hw E1000_UNUSEDARG *hw,
1407609433eSJack F Vogel 			  bool E1000_UNUSEDARG active)
1418cfa0ad2SJack F Vogel {
1428cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_null_lplu_state");
1438cfa0ad2SJack F Vogel 	return E1000_SUCCESS;
1448cfa0ad2SJack F Vogel }
1458cfa0ad2SJack F Vogel 
1468cfa0ad2SJack F Vogel /**
1478cfa0ad2SJack F Vogel  *  e1000_null_write_reg - No-op function, return 0
1488cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
1498cfa0ad2SJack F Vogel  **/
1507609433eSJack F Vogel s32 e1000_null_write_reg(struct e1000_hw E1000_UNUSEDARG *hw,
1517609433eSJack F Vogel 			 u32 E1000_UNUSEDARG offset, u16 E1000_UNUSEDARG data)
1528cfa0ad2SJack F Vogel {
1538cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_null_write_reg");
1548cfa0ad2SJack F Vogel 	return E1000_SUCCESS;
1558cfa0ad2SJack F Vogel }
1568cfa0ad2SJack F Vogel 
1578cfa0ad2SJack F Vogel /**
158ab5d0362SJack F Vogel  *  e1000_read_i2c_byte_null - No-op function, return 0
159ab5d0362SJack F Vogel  *  @hw: pointer to hardware structure
160ab5d0362SJack F Vogel  *  @byte_offset: byte offset to write
161ab5d0362SJack F Vogel  *  @dev_addr: device address
162ab5d0362SJack F Vogel  *  @data: data value read
163ab5d0362SJack F Vogel  *
164ab5d0362SJack F Vogel  **/
1657609433eSJack F Vogel s32 e1000_read_i2c_byte_null(struct e1000_hw E1000_UNUSEDARG *hw,
1667609433eSJack F Vogel 			     u8 E1000_UNUSEDARG byte_offset,
1677609433eSJack F Vogel 			     u8 E1000_UNUSEDARG dev_addr,
1687609433eSJack F Vogel 			     u8 E1000_UNUSEDARG *data)
169ab5d0362SJack F Vogel {
170ab5d0362SJack F Vogel 	DEBUGFUNC("e1000_read_i2c_byte_null");
171ab5d0362SJack F Vogel 	return E1000_SUCCESS;
172ab5d0362SJack F Vogel }
173ab5d0362SJack F Vogel 
174ab5d0362SJack F Vogel /**
175ab5d0362SJack F Vogel  *  e1000_write_i2c_byte_null - No-op function, return 0
176ab5d0362SJack F Vogel  *  @hw: pointer to hardware structure
177ab5d0362SJack F Vogel  *  @byte_offset: byte offset to write
178ab5d0362SJack F Vogel  *  @dev_addr: device address
179ab5d0362SJack F Vogel  *  @data: data value to write
180ab5d0362SJack F Vogel  *
181ab5d0362SJack F Vogel  **/
1827609433eSJack F Vogel s32 e1000_write_i2c_byte_null(struct e1000_hw E1000_UNUSEDARG *hw,
1837609433eSJack F Vogel 			      u8 E1000_UNUSEDARG byte_offset,
1847609433eSJack F Vogel 			      u8 E1000_UNUSEDARG dev_addr,
1857609433eSJack F Vogel 			      u8 E1000_UNUSEDARG data)
186ab5d0362SJack F Vogel {
187ab5d0362SJack F Vogel 	DEBUGFUNC("e1000_write_i2c_byte_null");
188ab5d0362SJack F Vogel 	return E1000_SUCCESS;
189ab5d0362SJack F Vogel }
190ab5d0362SJack F Vogel 
191ab5d0362SJack F Vogel /**
1928cfa0ad2SJack F Vogel  *  e1000_check_reset_block_generic - Check if PHY reset is blocked
1938cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
1948cfa0ad2SJack F Vogel  *
1958cfa0ad2SJack F Vogel  *  Read the PHY management control register and check whether a PHY reset
1968cfa0ad2SJack F Vogel  *  is blocked.  If a reset is not blocked return E1000_SUCCESS, otherwise
1978cfa0ad2SJack F Vogel  *  return E1000_BLK_PHY_RESET (12).
1988cfa0ad2SJack F Vogel  **/
1998cfa0ad2SJack F Vogel s32 e1000_check_reset_block_generic(struct e1000_hw *hw)
2008cfa0ad2SJack F Vogel {
2018cfa0ad2SJack F Vogel 	u32 manc;
2028cfa0ad2SJack F Vogel 
2038cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_check_reset_block");
2048cfa0ad2SJack F Vogel 
2058cfa0ad2SJack F Vogel 	manc = E1000_READ_REG(hw, E1000_MANC);
2068cfa0ad2SJack F Vogel 
2078cfa0ad2SJack F Vogel 	return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
2088cfa0ad2SJack F Vogel 	       E1000_BLK_PHY_RESET : E1000_SUCCESS;
2098cfa0ad2SJack F Vogel }
2108cfa0ad2SJack F Vogel 
2118cfa0ad2SJack F Vogel /**
2128cfa0ad2SJack F Vogel  *  e1000_get_phy_id - Retrieve the PHY ID and revision
2138cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
2148cfa0ad2SJack F Vogel  *
2158cfa0ad2SJack F Vogel  *  Reads the PHY registers and stores the PHY ID and possibly the PHY
2168cfa0ad2SJack F Vogel  *  revision in the hardware structure.
2178cfa0ad2SJack F Vogel  **/
2188cfa0ad2SJack F Vogel s32 e1000_get_phy_id(struct e1000_hw *hw)
2198cfa0ad2SJack F Vogel {
2208cfa0ad2SJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
2218cfa0ad2SJack F Vogel 	s32 ret_val = E1000_SUCCESS;
2228cfa0ad2SJack F Vogel 	u16 phy_id;
2239d81738fSJack F Vogel 	u16 retry_count = 0;
2248cfa0ad2SJack F Vogel 
2258cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_get_phy_id");
2268cfa0ad2SJack F Vogel 
227ab5d0362SJack F Vogel 	if (!phy->ops.read_reg)
228ab5d0362SJack F Vogel 		return E1000_SUCCESS;
2298cfa0ad2SJack F Vogel 
2309d81738fSJack F Vogel 	while (retry_count < 2) {
2318cfa0ad2SJack F Vogel 		ret_val = phy->ops.read_reg(hw, PHY_ID1, &phy_id);
2328cfa0ad2SJack F Vogel 		if (ret_val)
233ab5d0362SJack F Vogel 			return ret_val;
2348cfa0ad2SJack F Vogel 
2358cfa0ad2SJack F Vogel 		phy->id = (u32)(phy_id << 16);
2368cfa0ad2SJack F Vogel 		usec_delay(20);
2378cfa0ad2SJack F Vogel 		ret_val = phy->ops.read_reg(hw, PHY_ID2, &phy_id);
2388cfa0ad2SJack F Vogel 		if (ret_val)
239ab5d0362SJack F Vogel 			return ret_val;
2408cfa0ad2SJack F Vogel 
2418cfa0ad2SJack F Vogel 		phy->id |= (u32)(phy_id & PHY_REVISION_MASK);
2428cfa0ad2SJack F Vogel 		phy->revision = (u32)(phy_id & ~PHY_REVISION_MASK);
2438cfa0ad2SJack F Vogel 
2449d81738fSJack F Vogel 		if (phy->id != 0 && phy->id != PHY_REVISION_MASK)
245ab5d0362SJack F Vogel 			return E1000_SUCCESS;
2469d81738fSJack F Vogel 
2479d81738fSJack F Vogel 		retry_count++;
2489d81738fSJack F Vogel 	}
249ab5d0362SJack F Vogel 
250ab5d0362SJack F Vogel 	return E1000_SUCCESS;
2518cfa0ad2SJack F Vogel }
2528cfa0ad2SJack F Vogel 
2538cfa0ad2SJack F Vogel /**
2548cfa0ad2SJack F Vogel  *  e1000_phy_reset_dsp_generic - Reset PHY DSP
2558cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
2568cfa0ad2SJack F Vogel  *
2578cfa0ad2SJack F Vogel  *  Reset the digital signal processor.
2588cfa0ad2SJack F Vogel  **/
2598cfa0ad2SJack F Vogel s32 e1000_phy_reset_dsp_generic(struct e1000_hw *hw)
2608cfa0ad2SJack F Vogel {
261ab5d0362SJack F Vogel 	s32 ret_val;
2628cfa0ad2SJack F Vogel 
2638cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_phy_reset_dsp_generic");
2648cfa0ad2SJack F Vogel 
265ab5d0362SJack F Vogel 	if (!hw->phy.ops.write_reg)
266ab5d0362SJack F Vogel 		return E1000_SUCCESS;
2678cfa0ad2SJack F Vogel 
2688cfa0ad2SJack F Vogel 	ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xC1);
2698cfa0ad2SJack F Vogel 	if (ret_val)
2708cfa0ad2SJack F Vogel 		return ret_val;
271ab5d0362SJack F Vogel 
272ab5d0362SJack F Vogel 	return hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0);
2738cfa0ad2SJack F Vogel }
2748cfa0ad2SJack F Vogel 
2758cfa0ad2SJack F Vogel /**
2768cfa0ad2SJack F Vogel  *  e1000_read_phy_reg_mdic - Read MDI control register
2778cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
2788cfa0ad2SJack F Vogel  *  @offset: register offset to be read
2798cfa0ad2SJack F Vogel  *  @data: pointer to the read data
2808cfa0ad2SJack F Vogel  *
2818cfa0ad2SJack F Vogel  *  Reads the MDI control register in the PHY at offset and stores the
2828cfa0ad2SJack F Vogel  *  information read to data.
2838cfa0ad2SJack F Vogel  **/
2848cfa0ad2SJack F Vogel s32 e1000_read_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 *data)
2858cfa0ad2SJack F Vogel {
2868cfa0ad2SJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
2878cfa0ad2SJack F Vogel 	u32 i, mdic = 0;
2888cfa0ad2SJack F Vogel 
2898cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_read_phy_reg_mdic");
2908cfa0ad2SJack F Vogel 
291a69ed8dfSJack F Vogel 	if (offset > MAX_PHY_REG_ADDRESS) {
292a69ed8dfSJack F Vogel 		DEBUGOUT1("PHY Address %d is out of range\n", offset);
293a69ed8dfSJack F Vogel 		return -E1000_ERR_PARAM;
294a69ed8dfSJack F Vogel 	}
295a69ed8dfSJack F Vogel 
2966ab6bfe3SJack F Vogel 	/* Set up Op-code, Phy Address, and register offset in the MDI
2978cfa0ad2SJack F Vogel 	 * Control register.  The MAC will take care of interfacing with the
2988cfa0ad2SJack F Vogel 	 * PHY to retrieve the desired data.
2998cfa0ad2SJack F Vogel 	 */
3008cfa0ad2SJack F Vogel 	mdic = ((offset << E1000_MDIC_REG_SHIFT) |
3018cfa0ad2SJack F Vogel 		(phy->addr << E1000_MDIC_PHY_SHIFT) |
3028cfa0ad2SJack F Vogel 		(E1000_MDIC_OP_READ));
3038cfa0ad2SJack F Vogel 
3048cfa0ad2SJack F Vogel 	E1000_WRITE_REG(hw, E1000_MDIC, mdic);
3058cfa0ad2SJack F Vogel 
3066ab6bfe3SJack F Vogel 	/* Poll the ready bit to see if the MDI read completed
3078cfa0ad2SJack F Vogel 	 * Increasing the time out as testing showed failures with
3088cfa0ad2SJack F Vogel 	 * the lower time out
3098cfa0ad2SJack F Vogel 	 */
3108cfa0ad2SJack F Vogel 	for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
3117609433eSJack F Vogel 		usec_delay_irq(50);
3128cfa0ad2SJack F Vogel 		mdic = E1000_READ_REG(hw, E1000_MDIC);
3138cfa0ad2SJack F Vogel 		if (mdic & E1000_MDIC_READY)
3148cfa0ad2SJack F Vogel 			break;
3158cfa0ad2SJack F Vogel 	}
3168cfa0ad2SJack F Vogel 	if (!(mdic & E1000_MDIC_READY)) {
3178cfa0ad2SJack F Vogel 		DEBUGOUT("MDI Read did not complete\n");
318ab5d0362SJack F Vogel 		return -E1000_ERR_PHY;
3198cfa0ad2SJack F Vogel 	}
3208cfa0ad2SJack F Vogel 	if (mdic & E1000_MDIC_ERROR) {
3218cfa0ad2SJack F Vogel 		DEBUGOUT("MDI Error\n");
322ab5d0362SJack F Vogel 		return -E1000_ERR_PHY;
3238cfa0ad2SJack F Vogel 	}
3246ab6bfe3SJack F Vogel 	if (((mdic & E1000_MDIC_REG_MASK) >> E1000_MDIC_REG_SHIFT) != offset) {
3256ab6bfe3SJack F Vogel 		DEBUGOUT2("MDI Read offset error - requested %d, returned %d\n",
3266ab6bfe3SJack F Vogel 			  offset,
3276ab6bfe3SJack F Vogel 			  (mdic & E1000_MDIC_REG_MASK) >> E1000_MDIC_REG_SHIFT);
3286ab6bfe3SJack F Vogel 		return -E1000_ERR_PHY;
3296ab6bfe3SJack F Vogel 	}
3308cfa0ad2SJack F Vogel 	*data = (u16) mdic;
3318cfa0ad2SJack F Vogel 
3326ab6bfe3SJack F Vogel 	/* Allow some time after each MDIC transaction to avoid
3337d9119bdSJack F Vogel 	 * reading duplicate data in the next MDIC transaction.
3347d9119bdSJack F Vogel 	 */
3357d9119bdSJack F Vogel 	if (hw->mac.type == e1000_pch2lan)
3367609433eSJack F Vogel 		usec_delay_irq(100);
3377d9119bdSJack F Vogel 
338ab5d0362SJack F Vogel 	return E1000_SUCCESS;
3398cfa0ad2SJack F Vogel }
3408cfa0ad2SJack F Vogel 
3418cfa0ad2SJack F Vogel /**
3428cfa0ad2SJack F Vogel  *  e1000_write_phy_reg_mdic - Write MDI control register
3438cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
3448cfa0ad2SJack F Vogel  *  @offset: register offset to write to
3458cfa0ad2SJack F Vogel  *  @data: data to write to register at offset
3468cfa0ad2SJack F Vogel  *
3478cfa0ad2SJack F Vogel  *  Writes data to MDI control register in the PHY at offset.
3488cfa0ad2SJack F Vogel  **/
3498cfa0ad2SJack F Vogel s32 e1000_write_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 data)
3508cfa0ad2SJack F Vogel {
3518cfa0ad2SJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
3528cfa0ad2SJack F Vogel 	u32 i, mdic = 0;
3538cfa0ad2SJack F Vogel 
3548cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_write_phy_reg_mdic");
3558cfa0ad2SJack F Vogel 
356a69ed8dfSJack F Vogel 	if (offset > MAX_PHY_REG_ADDRESS) {
357a69ed8dfSJack F Vogel 		DEBUGOUT1("PHY Address %d is out of range\n", offset);
358a69ed8dfSJack F Vogel 		return -E1000_ERR_PARAM;
359a69ed8dfSJack F Vogel 	}
360a69ed8dfSJack F Vogel 
3616ab6bfe3SJack F Vogel 	/* Set up Op-code, Phy Address, and register offset in the MDI
3628cfa0ad2SJack F Vogel 	 * Control register.  The MAC will take care of interfacing with the
3638cfa0ad2SJack F Vogel 	 * PHY to retrieve the desired data.
3648cfa0ad2SJack F Vogel 	 */
3658cfa0ad2SJack F Vogel 	mdic = (((u32)data) |
3668cfa0ad2SJack F Vogel 		(offset << E1000_MDIC_REG_SHIFT) |
3678cfa0ad2SJack F Vogel 		(phy->addr << E1000_MDIC_PHY_SHIFT) |
3688cfa0ad2SJack F Vogel 		(E1000_MDIC_OP_WRITE));
3698cfa0ad2SJack F Vogel 
3708cfa0ad2SJack F Vogel 	E1000_WRITE_REG(hw, E1000_MDIC, mdic);
3718cfa0ad2SJack F Vogel 
3726ab6bfe3SJack F Vogel 	/* Poll the ready bit to see if the MDI read completed
3738cfa0ad2SJack F Vogel 	 * Increasing the time out as testing showed failures with
3748cfa0ad2SJack F Vogel 	 * the lower time out
3758cfa0ad2SJack F Vogel 	 */
3768cfa0ad2SJack F Vogel 	for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
3777609433eSJack F Vogel 		usec_delay_irq(50);
3788cfa0ad2SJack F Vogel 		mdic = E1000_READ_REG(hw, E1000_MDIC);
3798cfa0ad2SJack F Vogel 		if (mdic & E1000_MDIC_READY)
3808cfa0ad2SJack F Vogel 			break;
3818cfa0ad2SJack F Vogel 	}
3828cfa0ad2SJack F Vogel 	if (!(mdic & E1000_MDIC_READY)) {
3838cfa0ad2SJack F Vogel 		DEBUGOUT("MDI Write did not complete\n");
384ab5d0362SJack F Vogel 		return -E1000_ERR_PHY;
3858cfa0ad2SJack F Vogel 	}
3868cfa0ad2SJack F Vogel 	if (mdic & E1000_MDIC_ERROR) {
3878cfa0ad2SJack F Vogel 		DEBUGOUT("MDI Error\n");
388ab5d0362SJack F Vogel 		return -E1000_ERR_PHY;
3898cfa0ad2SJack F Vogel 	}
3906ab6bfe3SJack F Vogel 	if (((mdic & E1000_MDIC_REG_MASK) >> E1000_MDIC_REG_SHIFT) != offset) {
3916ab6bfe3SJack F Vogel 		DEBUGOUT2("MDI Write offset error - requested %d, returned %d\n",
3926ab6bfe3SJack F Vogel 			  offset,
3936ab6bfe3SJack F Vogel 			  (mdic & E1000_MDIC_REG_MASK) >> E1000_MDIC_REG_SHIFT);
3946ab6bfe3SJack F Vogel 		return -E1000_ERR_PHY;
3956ab6bfe3SJack F Vogel 	}
3968cfa0ad2SJack F Vogel 
3976ab6bfe3SJack F Vogel 	/* Allow some time after each MDIC transaction to avoid
3987d9119bdSJack F Vogel 	 * reading duplicate data in the next MDIC transaction.
3997d9119bdSJack F Vogel 	 */
4007d9119bdSJack F Vogel 	if (hw->mac.type == e1000_pch2lan)
4017609433eSJack F Vogel 		usec_delay_irq(100);
4027d9119bdSJack F Vogel 
403ab5d0362SJack F Vogel 	return E1000_SUCCESS;
4048cfa0ad2SJack F Vogel }
4058cfa0ad2SJack F Vogel 
4068cfa0ad2SJack F Vogel /**
4074edd8523SJack F Vogel  *  e1000_read_phy_reg_i2c - Read PHY register using i2c
4084edd8523SJack F Vogel  *  @hw: pointer to the HW structure
4094edd8523SJack F Vogel  *  @offset: register offset to be read
4104edd8523SJack F Vogel  *  @data: pointer to the read data
4114edd8523SJack F Vogel  *
4124edd8523SJack F Vogel  *  Reads the PHY register at offset using the i2c interface and stores the
4134edd8523SJack F Vogel  *  retrieved information in data.
4144edd8523SJack F Vogel  **/
4154edd8523SJack F Vogel s32 e1000_read_phy_reg_i2c(struct e1000_hw *hw, u32 offset, u16 *data)
4164edd8523SJack F Vogel {
4174edd8523SJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
4184edd8523SJack F Vogel 	u32 i, i2ccmd = 0;
4194edd8523SJack F Vogel 
4204edd8523SJack F Vogel 	DEBUGFUNC("e1000_read_phy_reg_i2c");
4214edd8523SJack F Vogel 
4226ab6bfe3SJack F Vogel 	/* Set up Op-code, Phy Address, and register address in the I2CCMD
4234edd8523SJack F Vogel 	 * register.  The MAC will take care of interfacing with the
4244edd8523SJack F Vogel 	 * PHY to retrieve the desired data.
4254edd8523SJack F Vogel 	 */
4264edd8523SJack F Vogel 	i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) |
4274edd8523SJack F Vogel 		  (phy->addr << E1000_I2CCMD_PHY_ADDR_SHIFT) |
4284edd8523SJack F Vogel 		  (E1000_I2CCMD_OPCODE_READ));
4294edd8523SJack F Vogel 
4304edd8523SJack F Vogel 	E1000_WRITE_REG(hw, E1000_I2CCMD, i2ccmd);
4314edd8523SJack F Vogel 
4324edd8523SJack F Vogel 	/* Poll the ready bit to see if the I2C read completed */
4334edd8523SJack F Vogel 	for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) {
4344edd8523SJack F Vogel 		usec_delay(50);
4354edd8523SJack F Vogel 		i2ccmd = E1000_READ_REG(hw, E1000_I2CCMD);
4364edd8523SJack F Vogel 		if (i2ccmd & E1000_I2CCMD_READY)
4374edd8523SJack F Vogel 			break;
4384edd8523SJack F Vogel 	}
4394edd8523SJack F Vogel 	if (!(i2ccmd & E1000_I2CCMD_READY)) {
4404edd8523SJack F Vogel 		DEBUGOUT("I2CCMD Read did not complete\n");
4414edd8523SJack F Vogel 		return -E1000_ERR_PHY;
4424edd8523SJack F Vogel 	}
4434edd8523SJack F Vogel 	if (i2ccmd & E1000_I2CCMD_ERROR) {
4444edd8523SJack F Vogel 		DEBUGOUT("I2CCMD Error bit set\n");
4454edd8523SJack F Vogel 		return -E1000_ERR_PHY;
4464edd8523SJack F Vogel 	}
4474edd8523SJack F Vogel 
4484edd8523SJack F Vogel 	/* Need to byte-swap the 16-bit value. */
4494edd8523SJack F Vogel 	*data = ((i2ccmd >> 8) & 0x00FF) | ((i2ccmd << 8) & 0xFF00);
4504edd8523SJack F Vogel 
4514edd8523SJack F Vogel 	return E1000_SUCCESS;
4524edd8523SJack F Vogel }
4534edd8523SJack F Vogel 
4544edd8523SJack F Vogel /**
4554edd8523SJack F Vogel  *  e1000_write_phy_reg_i2c - Write PHY register using i2c
4564edd8523SJack F Vogel  *  @hw: pointer to the HW structure
4574edd8523SJack F Vogel  *  @offset: register offset to write to
4584edd8523SJack F Vogel  *  @data: data to write at register offset
4594edd8523SJack F Vogel  *
4604edd8523SJack F Vogel  *  Writes the data to PHY register at the offset using the i2c interface.
4614edd8523SJack F Vogel  **/
4624edd8523SJack F Vogel s32 e1000_write_phy_reg_i2c(struct e1000_hw *hw, u32 offset, u16 data)
4634edd8523SJack F Vogel {
4644edd8523SJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
4654edd8523SJack F Vogel 	u32 i, i2ccmd = 0;
4664edd8523SJack F Vogel 	u16 phy_data_swapped;
4674edd8523SJack F Vogel 
4684edd8523SJack F Vogel 	DEBUGFUNC("e1000_write_phy_reg_i2c");
4694edd8523SJack F Vogel 
4704dab5c37SJack F Vogel 	/* Prevent overwritting SFP I2C EEPROM which is at A0 address.*/
4714dab5c37SJack F Vogel 	if ((hw->phy.addr == 0) || (hw->phy.addr > 7)) {
4724dab5c37SJack F Vogel 		DEBUGOUT1("PHY I2C Address %d is out of range.\n",
4734dab5c37SJack F Vogel 			  hw->phy.addr);
4744dab5c37SJack F Vogel 		return -E1000_ERR_CONFIG;
4754dab5c37SJack F Vogel 	}
4764dab5c37SJack F Vogel 
4774edd8523SJack F Vogel 	/* Swap the data bytes for the I2C interface */
4784edd8523SJack F Vogel 	phy_data_swapped = ((data >> 8) & 0x00FF) | ((data << 8) & 0xFF00);
4794edd8523SJack F Vogel 
4806ab6bfe3SJack F Vogel 	/* Set up Op-code, Phy Address, and register address in the I2CCMD
4814edd8523SJack F Vogel 	 * register.  The MAC will take care of interfacing with the
4824edd8523SJack F Vogel 	 * PHY to retrieve the desired data.
4834edd8523SJack F Vogel 	 */
4844edd8523SJack F Vogel 	i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) |
4854edd8523SJack F Vogel 		  (phy->addr << E1000_I2CCMD_PHY_ADDR_SHIFT) |
4864edd8523SJack F Vogel 		  E1000_I2CCMD_OPCODE_WRITE |
4874edd8523SJack F Vogel 		  phy_data_swapped);
4884edd8523SJack F Vogel 
4894edd8523SJack F Vogel 	E1000_WRITE_REG(hw, E1000_I2CCMD, i2ccmd);
4904edd8523SJack F Vogel 
4914edd8523SJack F Vogel 	/* Poll the ready bit to see if the I2C read completed */
4924edd8523SJack F Vogel 	for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) {
4934edd8523SJack F Vogel 		usec_delay(50);
4944edd8523SJack F Vogel 		i2ccmd = E1000_READ_REG(hw, E1000_I2CCMD);
4954edd8523SJack F Vogel 		if (i2ccmd & E1000_I2CCMD_READY)
4964edd8523SJack F Vogel 			break;
4974edd8523SJack F Vogel 	}
4984edd8523SJack F Vogel 	if (!(i2ccmd & E1000_I2CCMD_READY)) {
4994edd8523SJack F Vogel 		DEBUGOUT("I2CCMD Write did not complete\n");
5004edd8523SJack F Vogel 		return -E1000_ERR_PHY;
5014edd8523SJack F Vogel 	}
5024edd8523SJack F Vogel 	if (i2ccmd & E1000_I2CCMD_ERROR) {
5034edd8523SJack F Vogel 		DEBUGOUT("I2CCMD Error bit set\n");
5044edd8523SJack F Vogel 		return -E1000_ERR_PHY;
5054edd8523SJack F Vogel 	}
5064edd8523SJack F Vogel 
5074edd8523SJack F Vogel 	return E1000_SUCCESS;
5084edd8523SJack F Vogel }
5094edd8523SJack F Vogel 
5104edd8523SJack F Vogel /**
5114dab5c37SJack F Vogel  *  e1000_read_sfp_data_byte - Reads SFP module data.
5124dab5c37SJack F Vogel  *  @hw: pointer to the HW structure
5134dab5c37SJack F Vogel  *  @offset: byte location offset to be read
5144dab5c37SJack F Vogel  *  @data: read data buffer pointer
5154dab5c37SJack F Vogel  *
5164dab5c37SJack F Vogel  *  Reads one byte from SFP module data stored
5174dab5c37SJack F Vogel  *  in SFP resided EEPROM memory or SFP diagnostic area.
5184dab5c37SJack F Vogel  *  Function should be called with
5194dab5c37SJack F Vogel  *  E1000_I2CCMD_SFP_DATA_ADDR(<byte offset>) for SFP module database access
5204dab5c37SJack F Vogel  *  E1000_I2CCMD_SFP_DIAG_ADDR(<byte offset>) for SFP diagnostics parameters
5214dab5c37SJack F Vogel  *  access
5224dab5c37SJack F Vogel  **/
5234dab5c37SJack F Vogel s32 e1000_read_sfp_data_byte(struct e1000_hw *hw, u16 offset, u8 *data)
5244dab5c37SJack F Vogel {
5254dab5c37SJack F Vogel 	u32 i = 0;
5264dab5c37SJack F Vogel 	u32 i2ccmd = 0;
5274dab5c37SJack F Vogel 	u32 data_local = 0;
5284dab5c37SJack F Vogel 
5294dab5c37SJack F Vogel 	DEBUGFUNC("e1000_read_sfp_data_byte");
5304dab5c37SJack F Vogel 
5314dab5c37SJack F Vogel 	if (offset > E1000_I2CCMD_SFP_DIAG_ADDR(255)) {
5324dab5c37SJack F Vogel 		DEBUGOUT("I2CCMD command address exceeds upper limit\n");
5334dab5c37SJack F Vogel 		return -E1000_ERR_PHY;
5344dab5c37SJack F Vogel 	}
5354dab5c37SJack F Vogel 
5366ab6bfe3SJack F Vogel 	/* Set up Op-code, EEPROM Address,in the I2CCMD
5374dab5c37SJack F Vogel 	 * register. The MAC will take care of interfacing with the
5384dab5c37SJack F Vogel 	 * EEPROM to retrieve the desired data.
5394dab5c37SJack F Vogel 	 */
5404dab5c37SJack F Vogel 	i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) |
5414dab5c37SJack F Vogel 		  E1000_I2CCMD_OPCODE_READ);
5424dab5c37SJack F Vogel 
5434dab5c37SJack F Vogel 	E1000_WRITE_REG(hw, E1000_I2CCMD, i2ccmd);
5444dab5c37SJack F Vogel 
5454dab5c37SJack F Vogel 	/* Poll the ready bit to see if the I2C read completed */
5464dab5c37SJack F Vogel 	for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) {
5474dab5c37SJack F Vogel 		usec_delay(50);
5484dab5c37SJack F Vogel 		data_local = E1000_READ_REG(hw, E1000_I2CCMD);
5494dab5c37SJack F Vogel 		if (data_local & E1000_I2CCMD_READY)
5504dab5c37SJack F Vogel 			break;
5514dab5c37SJack F Vogel 	}
5524dab5c37SJack F Vogel 	if (!(data_local & E1000_I2CCMD_READY)) {
5534dab5c37SJack F Vogel 		DEBUGOUT("I2CCMD Read did not complete\n");
5544dab5c37SJack F Vogel 		return -E1000_ERR_PHY;
5554dab5c37SJack F Vogel 	}
5564dab5c37SJack F Vogel 	if (data_local & E1000_I2CCMD_ERROR) {
5574dab5c37SJack F Vogel 		DEBUGOUT("I2CCMD Error bit set\n");
5584dab5c37SJack F Vogel 		return -E1000_ERR_PHY;
5594dab5c37SJack F Vogel 	}
5604dab5c37SJack F Vogel 	*data = (u8) data_local & 0xFF;
5614dab5c37SJack F Vogel 
5624dab5c37SJack F Vogel 	return E1000_SUCCESS;
5634dab5c37SJack F Vogel }
5644dab5c37SJack F Vogel 
5654dab5c37SJack F Vogel /**
5664dab5c37SJack F Vogel  *  e1000_write_sfp_data_byte - Writes SFP module data.
5674dab5c37SJack F Vogel  *  @hw: pointer to the HW structure
5684dab5c37SJack F Vogel  *  @offset: byte location offset to write to
5694dab5c37SJack F Vogel  *  @data: data to write
5704dab5c37SJack F Vogel  *
5714dab5c37SJack F Vogel  *  Writes one byte to SFP module data stored
5724dab5c37SJack F Vogel  *  in SFP resided EEPROM memory or SFP diagnostic area.
5734dab5c37SJack F Vogel  *  Function should be called with
5744dab5c37SJack F Vogel  *  E1000_I2CCMD_SFP_DATA_ADDR(<byte offset>) for SFP module database access
5754dab5c37SJack F Vogel  *  E1000_I2CCMD_SFP_DIAG_ADDR(<byte offset>) for SFP diagnostics parameters
5764dab5c37SJack F Vogel  *  access
5774dab5c37SJack F Vogel  **/
5784dab5c37SJack F Vogel s32 e1000_write_sfp_data_byte(struct e1000_hw *hw, u16 offset, u8 data)
5794dab5c37SJack F Vogel {
5804dab5c37SJack F Vogel 	u32 i = 0;
5814dab5c37SJack F Vogel 	u32 i2ccmd = 0;
5824dab5c37SJack F Vogel 	u32 data_local = 0;
5834dab5c37SJack F Vogel 
5844dab5c37SJack F Vogel 	DEBUGFUNC("e1000_write_sfp_data_byte");
5854dab5c37SJack F Vogel 
5864dab5c37SJack F Vogel 	if (offset > E1000_I2CCMD_SFP_DIAG_ADDR(255)) {
5874dab5c37SJack F Vogel 		DEBUGOUT("I2CCMD command address exceeds upper limit\n");
5884dab5c37SJack F Vogel 		return -E1000_ERR_PHY;
5894dab5c37SJack F Vogel 	}
5906ab6bfe3SJack F Vogel 	/* The programming interface is 16 bits wide
5914dab5c37SJack F Vogel 	 * so we need to read the whole word first
5924dab5c37SJack F Vogel 	 * then update appropriate byte lane and write
5934dab5c37SJack F Vogel 	 * the updated word back.
5944dab5c37SJack F Vogel 	 */
5956ab6bfe3SJack F Vogel 	/* Set up Op-code, EEPROM Address,in the I2CCMD
5964dab5c37SJack F Vogel 	 * register. The MAC will take care of interfacing
5974dab5c37SJack F Vogel 	 * with an EEPROM to write the data given.
5984dab5c37SJack F Vogel 	 */
5994dab5c37SJack F Vogel 	i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) |
6004dab5c37SJack F Vogel 		  E1000_I2CCMD_OPCODE_READ);
6014dab5c37SJack F Vogel 	/* Set a command to read single word */
6024dab5c37SJack F Vogel 	E1000_WRITE_REG(hw, E1000_I2CCMD, i2ccmd);
6034dab5c37SJack F Vogel 	for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) {
6044dab5c37SJack F Vogel 		usec_delay(50);
6056ab6bfe3SJack F Vogel 		/* Poll the ready bit to see if lastly
6064dab5c37SJack F Vogel 		 * launched I2C operation completed
6074dab5c37SJack F Vogel 		 */
6084dab5c37SJack F Vogel 		i2ccmd = E1000_READ_REG(hw, E1000_I2CCMD);
6094dab5c37SJack F Vogel 		if (i2ccmd & E1000_I2CCMD_READY) {
6104dab5c37SJack F Vogel 			/* Check if this is READ or WRITE phase */
6114dab5c37SJack F Vogel 			if ((i2ccmd & E1000_I2CCMD_OPCODE_READ) ==
6124dab5c37SJack F Vogel 			    E1000_I2CCMD_OPCODE_READ) {
6136ab6bfe3SJack F Vogel 				/* Write the selected byte
6144dab5c37SJack F Vogel 				 * lane and update whole word
6154dab5c37SJack F Vogel 				 */
6164dab5c37SJack F Vogel 				data_local = i2ccmd & 0xFF00;
6174dab5c37SJack F Vogel 				data_local |= data;
6184dab5c37SJack F Vogel 				i2ccmd = ((offset <<
6194dab5c37SJack F Vogel 					E1000_I2CCMD_REG_ADDR_SHIFT) |
6204dab5c37SJack F Vogel 					E1000_I2CCMD_OPCODE_WRITE | data_local);
6214dab5c37SJack F Vogel 				E1000_WRITE_REG(hw, E1000_I2CCMD, i2ccmd);
6224dab5c37SJack F Vogel 			} else {
6234dab5c37SJack F Vogel 				break;
6244dab5c37SJack F Vogel 			}
6254dab5c37SJack F Vogel 		}
6264dab5c37SJack F Vogel 	}
6274dab5c37SJack F Vogel 	if (!(i2ccmd & E1000_I2CCMD_READY)) {
6284dab5c37SJack F Vogel 		DEBUGOUT("I2CCMD Write did not complete\n");
6294dab5c37SJack F Vogel 		return -E1000_ERR_PHY;
6304dab5c37SJack F Vogel 	}
6314dab5c37SJack F Vogel 	if (i2ccmd & E1000_I2CCMD_ERROR) {
6324dab5c37SJack F Vogel 		DEBUGOUT("I2CCMD Error bit set\n");
6334dab5c37SJack F Vogel 		return -E1000_ERR_PHY;
6344dab5c37SJack F Vogel 	}
6354dab5c37SJack F Vogel 	return E1000_SUCCESS;
6364dab5c37SJack F Vogel }
6374dab5c37SJack F Vogel 
6384dab5c37SJack F Vogel /**
6398cfa0ad2SJack F Vogel  *  e1000_read_phy_reg_m88 - Read m88 PHY register
6408cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
6418cfa0ad2SJack F Vogel  *  @offset: register offset to be read
6428cfa0ad2SJack F Vogel  *  @data: pointer to the read data
6438cfa0ad2SJack F Vogel  *
6448cfa0ad2SJack F Vogel  *  Acquires semaphore, if necessary, then reads the PHY register at offset
6458cfa0ad2SJack F Vogel  *  and storing the retrieved information in data.  Release any acquired
6468cfa0ad2SJack F Vogel  *  semaphores before exiting.
6478cfa0ad2SJack F Vogel  **/
6488cfa0ad2SJack F Vogel s32 e1000_read_phy_reg_m88(struct e1000_hw *hw, u32 offset, u16 *data)
6498cfa0ad2SJack F Vogel {
650ab5d0362SJack F Vogel 	s32 ret_val;
6518cfa0ad2SJack F Vogel 
6528cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_read_phy_reg_m88");
6538cfa0ad2SJack F Vogel 
654ab5d0362SJack F Vogel 	if (!hw->phy.ops.acquire)
655ab5d0362SJack F Vogel 		return E1000_SUCCESS;
6568cfa0ad2SJack F Vogel 
6578cfa0ad2SJack F Vogel 	ret_val = hw->phy.ops.acquire(hw);
6588cfa0ad2SJack F Vogel 	if (ret_val)
659ab5d0362SJack F Vogel 		return ret_val;
6608cfa0ad2SJack F Vogel 
661daf9197cSJack F Vogel 	ret_val = e1000_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
6628cfa0ad2SJack F Vogel 					  data);
6638cfa0ad2SJack F Vogel 
6648cfa0ad2SJack F Vogel 	hw->phy.ops.release(hw);
6658cfa0ad2SJack F Vogel 
6668cfa0ad2SJack F Vogel 	return ret_val;
6678cfa0ad2SJack F Vogel }
6688cfa0ad2SJack F Vogel 
6698cfa0ad2SJack F Vogel /**
6708cfa0ad2SJack F Vogel  *  e1000_write_phy_reg_m88 - Write m88 PHY register
6718cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
6728cfa0ad2SJack F Vogel  *  @offset: register offset to write to
6738cfa0ad2SJack F Vogel  *  @data: data to write at register offset
6748cfa0ad2SJack F Vogel  *
6758cfa0ad2SJack F Vogel  *  Acquires semaphore, if necessary, then writes the data to PHY register
6768cfa0ad2SJack F Vogel  *  at the offset.  Release any acquired semaphores before exiting.
6778cfa0ad2SJack F Vogel  **/
6788cfa0ad2SJack F Vogel s32 e1000_write_phy_reg_m88(struct e1000_hw *hw, u32 offset, u16 data)
6798cfa0ad2SJack F Vogel {
680ab5d0362SJack F Vogel 	s32 ret_val;
6818cfa0ad2SJack F Vogel 
6828cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_write_phy_reg_m88");
6838cfa0ad2SJack F Vogel 
684ab5d0362SJack F Vogel 	if (!hw->phy.ops.acquire)
685ab5d0362SJack F Vogel 		return E1000_SUCCESS;
6868cfa0ad2SJack F Vogel 
6878cfa0ad2SJack F Vogel 	ret_val = hw->phy.ops.acquire(hw);
6888cfa0ad2SJack F Vogel 	if (ret_val)
689ab5d0362SJack F Vogel 		return ret_val;
6908cfa0ad2SJack F Vogel 
691daf9197cSJack F Vogel 	ret_val = e1000_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
6928cfa0ad2SJack F Vogel 					   data);
6938cfa0ad2SJack F Vogel 
6948cfa0ad2SJack F Vogel 	hw->phy.ops.release(hw);
6958cfa0ad2SJack F Vogel 
6968cfa0ad2SJack F Vogel 	return ret_val;
6978cfa0ad2SJack F Vogel }
6988cfa0ad2SJack F Vogel 
6998cfa0ad2SJack F Vogel /**
7004dab5c37SJack F Vogel  *  e1000_set_page_igp - Set page as on IGP-like PHY(s)
7014dab5c37SJack F Vogel  *  @hw: pointer to the HW structure
7024dab5c37SJack F Vogel  *  @page: page to set (shifted left when necessary)
7034dab5c37SJack F Vogel  *
7044dab5c37SJack F Vogel  *  Sets PHY page required for PHY register access.  Assumes semaphore is
7054dab5c37SJack F Vogel  *  already acquired.  Note, this function sets phy.addr to 1 so the caller
7064dab5c37SJack F Vogel  *  must set it appropriately (if necessary) after this function returns.
7074dab5c37SJack F Vogel  **/
7084dab5c37SJack F Vogel s32 e1000_set_page_igp(struct e1000_hw *hw, u16 page)
7094dab5c37SJack F Vogel {
7104dab5c37SJack F Vogel 	DEBUGFUNC("e1000_set_page_igp");
7114dab5c37SJack F Vogel 
7124dab5c37SJack F Vogel 	DEBUGOUT1("Setting page 0x%x\n", page);
7134dab5c37SJack F Vogel 
7144dab5c37SJack F Vogel 	hw->phy.addr = 1;
7154dab5c37SJack F Vogel 
7164dab5c37SJack F Vogel 	return e1000_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT, page);
7174dab5c37SJack F Vogel }
7184dab5c37SJack F Vogel 
7194dab5c37SJack F Vogel /**
7204edd8523SJack F Vogel  *  __e1000_read_phy_reg_igp - Read igp PHY register
7218cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
7228cfa0ad2SJack F Vogel  *  @offset: register offset to be read
7238cfa0ad2SJack F Vogel  *  @data: pointer to the read data
7244edd8523SJack F Vogel  *  @locked: semaphore has already been acquired or not
7258cfa0ad2SJack F Vogel  *
7268cfa0ad2SJack F Vogel  *  Acquires semaphore, if necessary, then reads the PHY register at offset
7274edd8523SJack F Vogel  *  and stores the retrieved information in data.  Release any acquired
7288cfa0ad2SJack F Vogel  *  semaphores before exiting.
7298cfa0ad2SJack F Vogel  **/
7304edd8523SJack F Vogel static s32 __e1000_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data,
7314edd8523SJack F Vogel 				    bool locked)
7328cfa0ad2SJack F Vogel {
7338cfa0ad2SJack F Vogel 	s32 ret_val = E1000_SUCCESS;
7348cfa0ad2SJack F Vogel 
7354edd8523SJack F Vogel 	DEBUGFUNC("__e1000_read_phy_reg_igp");
7368cfa0ad2SJack F Vogel 
7374edd8523SJack F Vogel 	if (!locked) {
738ab5d0362SJack F Vogel 		if (!hw->phy.ops.acquire)
739ab5d0362SJack F Vogel 			return E1000_SUCCESS;
7408cfa0ad2SJack F Vogel 
7418cfa0ad2SJack F Vogel 		ret_val = hw->phy.ops.acquire(hw);
7428cfa0ad2SJack F Vogel 		if (ret_val)
743ab5d0362SJack F Vogel 			return ret_val;
7444edd8523SJack F Vogel 	}
7458cfa0ad2SJack F Vogel 
746ab5d0362SJack F Vogel 	if (offset > MAX_PHY_MULTI_PAGE_REG)
7478cfa0ad2SJack F Vogel 		ret_val = e1000_write_phy_reg_mdic(hw,
7488cfa0ad2SJack F Vogel 						   IGP01E1000_PHY_PAGE_SELECT,
7498cfa0ad2SJack F Vogel 						   (u16)offset);
750ab5d0362SJack F Vogel 	if (!ret_val)
751ab5d0362SJack F Vogel 		ret_val = e1000_read_phy_reg_mdic(hw,
752ab5d0362SJack F Vogel 						  MAX_PHY_REG_ADDRESS & offset,
7538cfa0ad2SJack F Vogel 						  data);
7544edd8523SJack F Vogel 	if (!locked)
7554edd8523SJack F Vogel 		hw->phy.ops.release(hw);
756ab5d0362SJack F Vogel 
7574edd8523SJack F Vogel 	return ret_val;
7584edd8523SJack F Vogel }
7594edd8523SJack F Vogel 
7604edd8523SJack F Vogel /**
7614edd8523SJack F Vogel  *  e1000_read_phy_reg_igp - Read igp PHY register
7624edd8523SJack F Vogel  *  @hw: pointer to the HW structure
7634edd8523SJack F Vogel  *  @offset: register offset to be read
7644edd8523SJack F Vogel  *  @data: pointer to the read data
7654edd8523SJack F Vogel  *
7664edd8523SJack F Vogel  *  Acquires semaphore then reads the PHY register at offset and stores the
7674edd8523SJack F Vogel  *  retrieved information in data.
7684edd8523SJack F Vogel  *  Release the acquired semaphore before exiting.
7694edd8523SJack F Vogel  **/
7704edd8523SJack F Vogel s32 e1000_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data)
7714edd8523SJack F Vogel {
7724edd8523SJack F Vogel 	return __e1000_read_phy_reg_igp(hw, offset, data, FALSE);
7734edd8523SJack F Vogel }
7744edd8523SJack F Vogel 
7754edd8523SJack F Vogel /**
7764edd8523SJack F Vogel  *  e1000_read_phy_reg_igp_locked - Read igp PHY register
7774edd8523SJack F Vogel  *  @hw: pointer to the HW structure
7784edd8523SJack F Vogel  *  @offset: register offset to be read
7794edd8523SJack F Vogel  *  @data: pointer to the read data
7804edd8523SJack F Vogel  *
7814edd8523SJack F Vogel  *  Reads the PHY register at offset and stores the retrieved information
7824edd8523SJack F Vogel  *  in data.  Assumes semaphore already acquired.
7834edd8523SJack F Vogel  **/
7844edd8523SJack F Vogel s32 e1000_read_phy_reg_igp_locked(struct e1000_hw *hw, u32 offset, u16 *data)
7854edd8523SJack F Vogel {
7864edd8523SJack F Vogel 	return __e1000_read_phy_reg_igp(hw, offset, data, TRUE);
7874edd8523SJack F Vogel }
7884edd8523SJack F Vogel 
7894edd8523SJack F Vogel /**
7904edd8523SJack F Vogel  *  e1000_write_phy_reg_igp - Write igp PHY register
7914edd8523SJack F Vogel  *  @hw: pointer to the HW structure
7924edd8523SJack F Vogel  *  @offset: register offset to write to
7934edd8523SJack F Vogel  *  @data: data to write at register offset
7944edd8523SJack F Vogel  *  @locked: semaphore has already been acquired or not
7954edd8523SJack F Vogel  *
7964edd8523SJack F Vogel  *  Acquires semaphore, if necessary, then writes the data to PHY register
7974edd8523SJack F Vogel  *  at the offset.  Release any acquired semaphores before exiting.
7984edd8523SJack F Vogel  **/
7994edd8523SJack F Vogel static s32 __e1000_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data,
8004edd8523SJack F Vogel 				     bool locked)
8014edd8523SJack F Vogel {
8024edd8523SJack F Vogel 	s32 ret_val = E1000_SUCCESS;
8034edd8523SJack F Vogel 
8044edd8523SJack F Vogel 	DEBUGFUNC("e1000_write_phy_reg_igp");
8054edd8523SJack F Vogel 
8064edd8523SJack F Vogel 	if (!locked) {
807ab5d0362SJack F Vogel 		if (!hw->phy.ops.acquire)
808ab5d0362SJack F Vogel 			return E1000_SUCCESS;
8094edd8523SJack F Vogel 
8104edd8523SJack F Vogel 		ret_val = hw->phy.ops.acquire(hw);
8114edd8523SJack F Vogel 		if (ret_val)
812ab5d0362SJack F Vogel 			return ret_val;
8134edd8523SJack F Vogel 	}
8144edd8523SJack F Vogel 
815ab5d0362SJack F Vogel 	if (offset > MAX_PHY_MULTI_PAGE_REG)
8164edd8523SJack F Vogel 		ret_val = e1000_write_phy_reg_mdic(hw,
8174edd8523SJack F Vogel 						   IGP01E1000_PHY_PAGE_SELECT,
8184edd8523SJack F Vogel 						   (u16)offset);
819ab5d0362SJack F Vogel 	if (!ret_val)
820ab5d0362SJack F Vogel 		ret_val = e1000_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS &
821ab5d0362SJack F Vogel 						       offset,
8224edd8523SJack F Vogel 						   data);
8234edd8523SJack F Vogel 	if (!locked)
8248cfa0ad2SJack F Vogel 		hw->phy.ops.release(hw);
8258cfa0ad2SJack F Vogel 
8268cfa0ad2SJack F Vogel 	return ret_val;
8278cfa0ad2SJack F Vogel }
8288cfa0ad2SJack F Vogel 
8298cfa0ad2SJack F Vogel /**
8308cfa0ad2SJack F Vogel  *  e1000_write_phy_reg_igp - Write igp PHY register
8318cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
8328cfa0ad2SJack F Vogel  *  @offset: register offset to write to
8338cfa0ad2SJack F Vogel  *  @data: data to write at register offset
8348cfa0ad2SJack F Vogel  *
8354edd8523SJack F Vogel  *  Acquires semaphore then writes the data to PHY register
8368cfa0ad2SJack F Vogel  *  at the offset.  Release any acquired semaphores before exiting.
8378cfa0ad2SJack F Vogel  **/
8388cfa0ad2SJack F Vogel s32 e1000_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data)
8398cfa0ad2SJack F Vogel {
8404edd8523SJack F Vogel 	return __e1000_write_phy_reg_igp(hw, offset, data, FALSE);
8414edd8523SJack F Vogel }
8424edd8523SJack F Vogel 
8434edd8523SJack F Vogel /**
8444edd8523SJack F Vogel  *  e1000_write_phy_reg_igp_locked - Write igp PHY register
8454edd8523SJack F Vogel  *  @hw: pointer to the HW structure
8464edd8523SJack F Vogel  *  @offset: register offset to write to
8474edd8523SJack F Vogel  *  @data: data to write at register offset
8484edd8523SJack F Vogel  *
8494edd8523SJack F Vogel  *  Writes the data to PHY register at the offset.
8504edd8523SJack F Vogel  *  Assumes semaphore already acquired.
8514edd8523SJack F Vogel  **/
8524edd8523SJack F Vogel s32 e1000_write_phy_reg_igp_locked(struct e1000_hw *hw, u32 offset, u16 data)
8534edd8523SJack F Vogel {
8544edd8523SJack F Vogel 	return __e1000_write_phy_reg_igp(hw, offset, data, TRUE);
8554edd8523SJack F Vogel }
8564edd8523SJack F Vogel 
8574edd8523SJack F Vogel /**
8584edd8523SJack F Vogel  *  __e1000_read_kmrn_reg - Read kumeran register
8594edd8523SJack F Vogel  *  @hw: pointer to the HW structure
8604edd8523SJack F Vogel  *  @offset: register offset to be read
8614edd8523SJack F Vogel  *  @data: pointer to the read data
8624edd8523SJack F Vogel  *  @locked: semaphore has already been acquired or not
8634edd8523SJack F Vogel  *
8644edd8523SJack F Vogel  *  Acquires semaphore, if necessary.  Then reads the PHY register at offset
8654edd8523SJack F Vogel  *  using the kumeran interface.  The information retrieved is stored in data.
8664edd8523SJack F Vogel  *  Release any acquired semaphores before exiting.
8674edd8523SJack F Vogel  **/
8684edd8523SJack F Vogel static s32 __e1000_read_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 *data,
8694edd8523SJack F Vogel 				 bool locked)
8704edd8523SJack F Vogel {
8714edd8523SJack F Vogel 	u32 kmrnctrlsta;
8728cfa0ad2SJack F Vogel 
8734edd8523SJack F Vogel 	DEBUGFUNC("__e1000_read_kmrn_reg");
8748cfa0ad2SJack F Vogel 
8754edd8523SJack F Vogel 	if (!locked) {
876ab5d0362SJack F Vogel 		s32 ret_val = E1000_SUCCESS;
877ab5d0362SJack F Vogel 
878ab5d0362SJack F Vogel 		if (!hw->phy.ops.acquire)
879ab5d0362SJack F Vogel 			return E1000_SUCCESS;
8808cfa0ad2SJack F Vogel 
8818cfa0ad2SJack F Vogel 		ret_val = hw->phy.ops.acquire(hw);
8828cfa0ad2SJack F Vogel 		if (ret_val)
883ab5d0362SJack F Vogel 			return ret_val;
8848cfa0ad2SJack F Vogel 	}
8858cfa0ad2SJack F Vogel 
8864edd8523SJack F Vogel 	kmrnctrlsta = ((offset << E1000_KMRNCTRLSTA_OFFSET_SHIFT) &
8874edd8523SJack F Vogel 		       E1000_KMRNCTRLSTA_OFFSET) | E1000_KMRNCTRLSTA_REN;
8884edd8523SJack F Vogel 	E1000_WRITE_REG(hw, E1000_KMRNCTRLSTA, kmrnctrlsta);
8894dab5c37SJack F Vogel 	E1000_WRITE_FLUSH(hw);
8908cfa0ad2SJack F Vogel 
8914edd8523SJack F Vogel 	usec_delay(2);
8924edd8523SJack F Vogel 
8934edd8523SJack F Vogel 	kmrnctrlsta = E1000_READ_REG(hw, E1000_KMRNCTRLSTA);
8944edd8523SJack F Vogel 	*data = (u16)kmrnctrlsta;
8954edd8523SJack F Vogel 
8964edd8523SJack F Vogel 	if (!locked)
8978cfa0ad2SJack F Vogel 		hw->phy.ops.release(hw);
8988cfa0ad2SJack F Vogel 
899ab5d0362SJack F Vogel 	return E1000_SUCCESS;
9008cfa0ad2SJack F Vogel }
9018cfa0ad2SJack F Vogel 
9028cfa0ad2SJack F Vogel /**
9038cfa0ad2SJack F Vogel  *  e1000_read_kmrn_reg_generic -  Read kumeran register
9048cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
9058cfa0ad2SJack F Vogel  *  @offset: register offset to be read
9068cfa0ad2SJack F Vogel  *  @data: pointer to the read data
9078cfa0ad2SJack F Vogel  *
9084edd8523SJack F Vogel  *  Acquires semaphore then reads the PHY register at offset using the
9094edd8523SJack F Vogel  *  kumeran interface.  The information retrieved is stored in data.
9104edd8523SJack F Vogel  *  Release the acquired semaphore before exiting.
9118cfa0ad2SJack F Vogel  **/
9128cfa0ad2SJack F Vogel s32 e1000_read_kmrn_reg_generic(struct e1000_hw *hw, u32 offset, u16 *data)
9138cfa0ad2SJack F Vogel {
9144edd8523SJack F Vogel 	return __e1000_read_kmrn_reg(hw, offset, data, FALSE);
9154edd8523SJack F Vogel }
9164edd8523SJack F Vogel 
9174edd8523SJack F Vogel /**
9184edd8523SJack F Vogel  *  e1000_read_kmrn_reg_locked -  Read kumeran register
9194edd8523SJack F Vogel  *  @hw: pointer to the HW structure
9204edd8523SJack F Vogel  *  @offset: register offset to be read
9214edd8523SJack F Vogel  *  @data: pointer to the read data
9224edd8523SJack F Vogel  *
9234edd8523SJack F Vogel  *  Reads the PHY register at offset using the kumeran interface.  The
9244edd8523SJack F Vogel  *  information retrieved is stored in data.
9254edd8523SJack F Vogel  *  Assumes semaphore already acquired.
9264edd8523SJack F Vogel  **/
9274edd8523SJack F Vogel s32 e1000_read_kmrn_reg_locked(struct e1000_hw *hw, u32 offset, u16 *data)
9284edd8523SJack F Vogel {
9294edd8523SJack F Vogel 	return __e1000_read_kmrn_reg(hw, offset, data, TRUE);
9304edd8523SJack F Vogel }
9314edd8523SJack F Vogel 
9324edd8523SJack F Vogel /**
9334edd8523SJack F Vogel  *  __e1000_write_kmrn_reg - Write kumeran register
9344edd8523SJack F Vogel  *  @hw: pointer to the HW structure
9354edd8523SJack F Vogel  *  @offset: register offset to write to
9364edd8523SJack F Vogel  *  @data: data to write at register offset
9374edd8523SJack F Vogel  *  @locked: semaphore has already been acquired or not
9384edd8523SJack F Vogel  *
9394edd8523SJack F Vogel  *  Acquires semaphore, if necessary.  Then write the data to PHY register
9404edd8523SJack F Vogel  *  at the offset using the kumeran interface.  Release any acquired semaphores
9414edd8523SJack F Vogel  *  before exiting.
9424edd8523SJack F Vogel  **/
9434edd8523SJack F Vogel static s32 __e1000_write_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 data,
9444edd8523SJack F Vogel 				  bool locked)
9454edd8523SJack F Vogel {
9468cfa0ad2SJack F Vogel 	u32 kmrnctrlsta;
9478cfa0ad2SJack F Vogel 
9484edd8523SJack F Vogel 	DEBUGFUNC("e1000_write_kmrn_reg_generic");
9498cfa0ad2SJack F Vogel 
9504edd8523SJack F Vogel 	if (!locked) {
951ab5d0362SJack F Vogel 		s32 ret_val = E1000_SUCCESS;
952ab5d0362SJack F Vogel 
953ab5d0362SJack F Vogel 		if (!hw->phy.ops.acquire)
954ab5d0362SJack F Vogel 			return E1000_SUCCESS;
9558cfa0ad2SJack F Vogel 
9568cfa0ad2SJack F Vogel 		ret_val = hw->phy.ops.acquire(hw);
9578cfa0ad2SJack F Vogel 		if (ret_val)
958ab5d0362SJack F Vogel 			return ret_val;
9594edd8523SJack F Vogel 	}
9608cfa0ad2SJack F Vogel 
9618cfa0ad2SJack F Vogel 	kmrnctrlsta = ((offset << E1000_KMRNCTRLSTA_OFFSET_SHIFT) &
9624edd8523SJack F Vogel 		       E1000_KMRNCTRLSTA_OFFSET) | data;
9638cfa0ad2SJack F Vogel 	E1000_WRITE_REG(hw, E1000_KMRNCTRLSTA, kmrnctrlsta);
9644dab5c37SJack F Vogel 	E1000_WRITE_FLUSH(hw);
9658cfa0ad2SJack F Vogel 
9668cfa0ad2SJack F Vogel 	usec_delay(2);
9678cfa0ad2SJack F Vogel 
9684edd8523SJack F Vogel 	if (!locked)
9698cfa0ad2SJack F Vogel 		hw->phy.ops.release(hw);
9708cfa0ad2SJack F Vogel 
971ab5d0362SJack F Vogel 	return E1000_SUCCESS;
9728cfa0ad2SJack F Vogel }
9738cfa0ad2SJack F Vogel 
9748cfa0ad2SJack F Vogel /**
9758cfa0ad2SJack F Vogel  *  e1000_write_kmrn_reg_generic -  Write kumeran register
9768cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
9778cfa0ad2SJack F Vogel  *  @offset: register offset to write to
9788cfa0ad2SJack F Vogel  *  @data: data to write at register offset
9798cfa0ad2SJack F Vogel  *
9804edd8523SJack F Vogel  *  Acquires semaphore then writes the data to the PHY register at the offset
9814edd8523SJack F Vogel  *  using the kumeran interface.  Release the acquired semaphore before exiting.
9828cfa0ad2SJack F Vogel  **/
9838cfa0ad2SJack F Vogel s32 e1000_write_kmrn_reg_generic(struct e1000_hw *hw, u32 offset, u16 data)
9848cfa0ad2SJack F Vogel {
9854edd8523SJack F Vogel 	return __e1000_write_kmrn_reg(hw, offset, data, FALSE);
9864edd8523SJack F Vogel }
9878cfa0ad2SJack F Vogel 
9884edd8523SJack F Vogel /**
9894edd8523SJack F Vogel  *  e1000_write_kmrn_reg_locked -  Write kumeran register
9904edd8523SJack F Vogel  *  @hw: pointer to the HW structure
9914edd8523SJack F Vogel  *  @offset: register offset to write to
9924edd8523SJack F Vogel  *  @data: data to write at register offset
9934edd8523SJack F Vogel  *
9944edd8523SJack F Vogel  *  Write the data to PHY register at the offset using the kumeran interface.
9954edd8523SJack F Vogel  *  Assumes semaphore already acquired.
9964edd8523SJack F Vogel  **/
9974edd8523SJack F Vogel s32 e1000_write_kmrn_reg_locked(struct e1000_hw *hw, u32 offset, u16 data)
9984edd8523SJack F Vogel {
9994edd8523SJack F Vogel 	return __e1000_write_kmrn_reg(hw, offset, data, TRUE);
10008cfa0ad2SJack F Vogel }
10018cfa0ad2SJack F Vogel 
10028cfa0ad2SJack F Vogel /**
1003ab5d0362SJack F Vogel  *  e1000_set_master_slave_mode - Setup PHY for Master/slave mode
10049d81738fSJack F Vogel  *  @hw: pointer to the HW structure
10059d81738fSJack F Vogel  *
1006ab5d0362SJack F Vogel  *  Sets up Master/slave mode
10079d81738fSJack F Vogel  **/
1008ab5d0362SJack F Vogel static s32 e1000_set_master_slave_mode(struct e1000_hw *hw)
10099d81738fSJack F Vogel {
10109d81738fSJack F Vogel 	s32 ret_val;
10119d81738fSJack F Vogel 	u16 phy_data;
10129d81738fSJack F Vogel 
10134dab5c37SJack F Vogel 	/* Resolve Master/Slave mode */
10144dab5c37SJack F Vogel 	ret_val = hw->phy.ops.read_reg(hw, PHY_1000T_CTRL, &phy_data);
10154dab5c37SJack F Vogel 	if (ret_val)
1016ab5d0362SJack F Vogel 		return ret_val;
10174dab5c37SJack F Vogel 
10184dab5c37SJack F Vogel 	/* load defaults for future use */
10194dab5c37SJack F Vogel 	hw->phy.original_ms_type = (phy_data & CR_1000T_MS_ENABLE) ?
10204dab5c37SJack F Vogel 				   ((phy_data & CR_1000T_MS_VALUE) ?
10214dab5c37SJack F Vogel 				    e1000_ms_force_master :
10224dab5c37SJack F Vogel 				    e1000_ms_force_slave) : e1000_ms_auto;
10234dab5c37SJack F Vogel 
10244dab5c37SJack F Vogel 	switch (hw->phy.ms_type) {
10254dab5c37SJack F Vogel 	case e1000_ms_force_master:
10264dab5c37SJack F Vogel 		phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
10274dab5c37SJack F Vogel 		break;
10284dab5c37SJack F Vogel 	case e1000_ms_force_slave:
10294dab5c37SJack F Vogel 		phy_data |= CR_1000T_MS_ENABLE;
10304dab5c37SJack F Vogel 		phy_data &= ~(CR_1000T_MS_VALUE);
10314dab5c37SJack F Vogel 		break;
10324dab5c37SJack F Vogel 	case e1000_ms_auto:
10334dab5c37SJack F Vogel 		phy_data &= ~CR_1000T_MS_ENABLE;
1034ab5d0362SJack F Vogel 		/* fall-through */
10354dab5c37SJack F Vogel 	default:
10364dab5c37SJack F Vogel 		break;
10374dab5c37SJack F Vogel 	}
10384dab5c37SJack F Vogel 
1039ab5d0362SJack F Vogel 	return hw->phy.ops.write_reg(hw, PHY_1000T_CTRL, phy_data);
1040ab5d0362SJack F Vogel }
10419d81738fSJack F Vogel 
1042ab5d0362SJack F Vogel /**
1043ab5d0362SJack F Vogel  *  e1000_copper_link_setup_82577 - Setup 82577 PHY for copper link
1044ab5d0362SJack F Vogel  *  @hw: pointer to the HW structure
1045ab5d0362SJack F Vogel  *
1046ab5d0362SJack F Vogel  *  Sets up Carrier-sense on Transmit and downshift values.
1047ab5d0362SJack F Vogel  **/
1048ab5d0362SJack F Vogel s32 e1000_copper_link_setup_82577(struct e1000_hw *hw)
1049ab5d0362SJack F Vogel {
1050ab5d0362SJack F Vogel 	s32 ret_val;
1051ab5d0362SJack F Vogel 	u16 phy_data;
1052ab5d0362SJack F Vogel 
1053ab5d0362SJack F Vogel 	DEBUGFUNC("e1000_copper_link_setup_82577");
1054ab5d0362SJack F Vogel 
1055ab5d0362SJack F Vogel 	if (hw->phy.type == e1000_phy_82580) {
1056ab5d0362SJack F Vogel 		ret_val = hw->phy.ops.reset(hw);
1057ab5d0362SJack F Vogel 		if (ret_val) {
1058ab5d0362SJack F Vogel 			DEBUGOUT("Error resetting the PHY.\n");
10599d81738fSJack F Vogel 			return ret_val;
10609d81738fSJack F Vogel 		}
1061ab5d0362SJack F Vogel 	}
1062ab5d0362SJack F Vogel 
10637609433eSJack F Vogel 	/* Enable CRS on Tx. This must be set for half-duplex operation. */
1064ab5d0362SJack F Vogel 	ret_val = hw->phy.ops.read_reg(hw, I82577_CFG_REG, &phy_data);
1065ab5d0362SJack F Vogel 	if (ret_val)
1066ab5d0362SJack F Vogel 		return ret_val;
1067ab5d0362SJack F Vogel 
1068ab5d0362SJack F Vogel 	phy_data |= I82577_CFG_ASSERT_CRS_ON_TX;
1069ab5d0362SJack F Vogel 
1070ab5d0362SJack F Vogel 	/* Enable downshift */
1071ab5d0362SJack F Vogel 	phy_data |= I82577_CFG_ENABLE_DOWNSHIFT;
1072ab5d0362SJack F Vogel 
1073ab5d0362SJack F Vogel 	ret_val = hw->phy.ops.write_reg(hw, I82577_CFG_REG, phy_data);
1074ab5d0362SJack F Vogel 	if (ret_val)
1075ab5d0362SJack F Vogel 		return ret_val;
1076ab5d0362SJack F Vogel 
1077ab5d0362SJack F Vogel 	/* Set MDI/MDIX mode */
1078ab5d0362SJack F Vogel 	ret_val = hw->phy.ops.read_reg(hw, I82577_PHY_CTRL_2, &phy_data);
1079ab5d0362SJack F Vogel 	if (ret_val)
1080ab5d0362SJack F Vogel 		return ret_val;
1081ab5d0362SJack F Vogel 	phy_data &= ~I82577_PHY_CTRL2_MDIX_CFG_MASK;
10826ab6bfe3SJack F Vogel 	/* Options:
1083ab5d0362SJack F Vogel 	 *   0 - Auto (default)
1084ab5d0362SJack F Vogel 	 *   1 - MDI mode
1085ab5d0362SJack F Vogel 	 *   2 - MDI-X mode
1086ab5d0362SJack F Vogel 	 */
1087ab5d0362SJack F Vogel 	switch (hw->phy.mdix) {
1088ab5d0362SJack F Vogel 	case 1:
1089ab5d0362SJack F Vogel 		break;
1090ab5d0362SJack F Vogel 	case 2:
1091ab5d0362SJack F Vogel 		phy_data |= I82577_PHY_CTRL2_MANUAL_MDIX;
1092ab5d0362SJack F Vogel 		break;
1093ab5d0362SJack F Vogel 	case 0:
1094ab5d0362SJack F Vogel 	default:
1095ab5d0362SJack F Vogel 		phy_data |= I82577_PHY_CTRL2_AUTO_MDI_MDIX;
1096ab5d0362SJack F Vogel 		break;
1097ab5d0362SJack F Vogel 	}
1098ab5d0362SJack F Vogel 	ret_val = hw->phy.ops.write_reg(hw, I82577_PHY_CTRL_2, phy_data);
1099ab5d0362SJack F Vogel 	if (ret_val)
1100ab5d0362SJack F Vogel 		return ret_val;
1101ab5d0362SJack F Vogel 
1102ab5d0362SJack F Vogel 	return e1000_set_master_slave_mode(hw);
1103ab5d0362SJack F Vogel }
11049d81738fSJack F Vogel 
11059d81738fSJack F Vogel /**
11068cfa0ad2SJack F Vogel  *  e1000_copper_link_setup_m88 - Setup m88 PHY's for copper link
11078cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
11088cfa0ad2SJack F Vogel  *
11098cfa0ad2SJack F Vogel  *  Sets up MDI/MDI-X and polarity for m88 PHY's.  If necessary, transmit clock
11108cfa0ad2SJack F Vogel  *  and downshift values are set also.
11118cfa0ad2SJack F Vogel  **/
11128cfa0ad2SJack F Vogel s32 e1000_copper_link_setup_m88(struct e1000_hw *hw)
11138cfa0ad2SJack F Vogel {
11148cfa0ad2SJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
11158cfa0ad2SJack F Vogel 	s32 ret_val;
11168cfa0ad2SJack F Vogel 	u16 phy_data;
11178cfa0ad2SJack F Vogel 
11188cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_copper_link_setup_m88");
11198cfa0ad2SJack F Vogel 
11208cfa0ad2SJack F Vogel 
1121a69ed8dfSJack F Vogel 	/* Enable CRS on Tx. This must be set for half-duplex operation. */
11228cfa0ad2SJack F Vogel 	ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
11238cfa0ad2SJack F Vogel 	if (ret_val)
1124ab5d0362SJack F Vogel 		return ret_val;
11258cfa0ad2SJack F Vogel 
11267d9119bdSJack F Vogel 	/* For BM PHY this bit is downshift enable */
1127f0ecc46dSJack F Vogel 	if (phy->type != e1000_phy_bm)
1128f0ecc46dSJack F Vogel 		phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
11298cfa0ad2SJack F Vogel 
11306ab6bfe3SJack F Vogel 	/* Options:
11318cfa0ad2SJack F Vogel 	 *   MDI/MDI-X = 0 (default)
11328cfa0ad2SJack F Vogel 	 *   0 - Auto for all speeds
11338cfa0ad2SJack F Vogel 	 *   1 - MDI mode
11348cfa0ad2SJack F Vogel 	 *   2 - MDI-X mode
11358cfa0ad2SJack F Vogel 	 *   3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
11368cfa0ad2SJack F Vogel 	 */
11378cfa0ad2SJack F Vogel 	phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
11388cfa0ad2SJack F Vogel 
11398cfa0ad2SJack F Vogel 	switch (phy->mdix) {
11408cfa0ad2SJack F Vogel 	case 1:
11418cfa0ad2SJack F Vogel 		phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
11428cfa0ad2SJack F Vogel 		break;
11438cfa0ad2SJack F Vogel 	case 2:
11448cfa0ad2SJack F Vogel 		phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
11458cfa0ad2SJack F Vogel 		break;
11468cfa0ad2SJack F Vogel 	case 3:
11478cfa0ad2SJack F Vogel 		phy_data |= M88E1000_PSCR_AUTO_X_1000T;
11488cfa0ad2SJack F Vogel 		break;
11498cfa0ad2SJack F Vogel 	case 0:
11508cfa0ad2SJack F Vogel 	default:
11518cfa0ad2SJack F Vogel 		phy_data |= M88E1000_PSCR_AUTO_X_MODE;
11528cfa0ad2SJack F Vogel 		break;
11538cfa0ad2SJack F Vogel 	}
11548cfa0ad2SJack F Vogel 
11556ab6bfe3SJack F Vogel 	/* Options:
11568cfa0ad2SJack F Vogel 	 *   disable_polarity_correction = 0 (default)
11578cfa0ad2SJack F Vogel 	 *       Automatic Correction for Reversed Cable Polarity
11588cfa0ad2SJack F Vogel 	 *   0 - Disabled
11598cfa0ad2SJack F Vogel 	 *   1 - Enabled
11608cfa0ad2SJack F Vogel 	 */
11618cfa0ad2SJack F Vogel 	phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
1162ab5d0362SJack F Vogel 	if (phy->disable_polarity_correction)
11638cfa0ad2SJack F Vogel 		phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
11648cfa0ad2SJack F Vogel 
11658cfa0ad2SJack F Vogel 	/* Enable downshift on BM (disabled by default) */
1166ab5d0362SJack F Vogel 	if (phy->type == e1000_phy_bm) {
1167ab5d0362SJack F Vogel 		/* For 82574/82583, first disable then enable downshift */
1168ab5d0362SJack F Vogel 		if (phy->id == BME1000_E_PHY_ID_R2) {
1169ab5d0362SJack F Vogel 			phy_data &= ~BME1000_PSCR_ENABLE_DOWNSHIFT;
1170ab5d0362SJack F Vogel 			ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL,
1171ab5d0362SJack F Vogel 						     phy_data);
1172ab5d0362SJack F Vogel 			if (ret_val)
1173ab5d0362SJack F Vogel 				return ret_val;
1174ab5d0362SJack F Vogel 			/* Commit the changes. */
1175ab5d0362SJack F Vogel 			ret_val = phy->ops.commit(hw);
1176ab5d0362SJack F Vogel 			if (ret_val) {
1177ab5d0362SJack F Vogel 				DEBUGOUT("Error committing the PHY changes\n");
1178ab5d0362SJack F Vogel 				return ret_val;
1179ab5d0362SJack F Vogel 			}
1180ab5d0362SJack F Vogel 		}
1181ab5d0362SJack F Vogel 
11828cfa0ad2SJack F Vogel 		phy_data |= BME1000_PSCR_ENABLE_DOWNSHIFT;
1183ab5d0362SJack F Vogel 	}
11848cfa0ad2SJack F Vogel 
11858cfa0ad2SJack F Vogel 	ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
11868cfa0ad2SJack F Vogel 	if (ret_val)
1187ab5d0362SJack F Vogel 		return ret_val;
11888cfa0ad2SJack F Vogel 
11898cfa0ad2SJack F Vogel 	if ((phy->type == e1000_phy_m88) &&
11908cfa0ad2SJack F Vogel 	    (phy->revision < E1000_REVISION_4) &&
11918cfa0ad2SJack F Vogel 	    (phy->id != BME1000_E_PHY_ID_R2)) {
11926ab6bfe3SJack F Vogel 		/* Force TX_CLK in the Extended PHY Specific Control Register
11938cfa0ad2SJack F Vogel 		 * to 25MHz clock.
11948cfa0ad2SJack F Vogel 		 */
1195daf9197cSJack F Vogel 		ret_val = phy->ops.read_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
11968cfa0ad2SJack F Vogel 					    &phy_data);
11978cfa0ad2SJack F Vogel 		if (ret_val)
1198ab5d0362SJack F Vogel 			return ret_val;
11998cfa0ad2SJack F Vogel 
12008cfa0ad2SJack F Vogel 		phy_data |= M88E1000_EPSCR_TX_CLK_25;
12018cfa0ad2SJack F Vogel 
12028cfa0ad2SJack F Vogel 		if ((phy->revision == E1000_REVISION_2) &&
12038cfa0ad2SJack F Vogel 		    (phy->id == M88E1111_I_PHY_ID)) {
12048cfa0ad2SJack F Vogel 			/* 82573L PHY - set the downshift counter to 5x. */
12058cfa0ad2SJack F Vogel 			phy_data &= ~M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK;
12068cfa0ad2SJack F Vogel 			phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
12078cfa0ad2SJack F Vogel 		} else {
12088cfa0ad2SJack F Vogel 			/* Configure Master and Slave downshift values */
12098cfa0ad2SJack F Vogel 			phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
12108cfa0ad2SJack F Vogel 				     M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
12118cfa0ad2SJack F Vogel 			phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
12128cfa0ad2SJack F Vogel 				     M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
12138cfa0ad2SJack F Vogel 		}
1214daf9197cSJack F Vogel 		ret_val = phy->ops.write_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
12158cfa0ad2SJack F Vogel 					     phy_data);
12168cfa0ad2SJack F Vogel 		if (ret_val)
1217ab5d0362SJack F Vogel 			return ret_val;
12188cfa0ad2SJack F Vogel 	}
12198cfa0ad2SJack F Vogel 
12208cfa0ad2SJack F Vogel 	if ((phy->type == e1000_phy_bm) && (phy->id == BME1000_E_PHY_ID_R2)) {
12218cfa0ad2SJack F Vogel 		/* Set PHY page 0, register 29 to 0x0003 */
12228cfa0ad2SJack F Vogel 		ret_val = phy->ops.write_reg(hw, 29, 0x0003);
12238cfa0ad2SJack F Vogel 		if (ret_val)
1224ab5d0362SJack F Vogel 			return ret_val;
12258cfa0ad2SJack F Vogel 
12268cfa0ad2SJack F Vogel 		/* Set PHY page 0, register 30 to 0x0000 */
12278cfa0ad2SJack F Vogel 		ret_val = phy->ops.write_reg(hw, 30, 0x0000);
12288cfa0ad2SJack F Vogel 		if (ret_val)
1229ab5d0362SJack F Vogel 			return ret_val;
12308cfa0ad2SJack F Vogel 	}
12318cfa0ad2SJack F Vogel 
12328cfa0ad2SJack F Vogel 	/* Commit the changes. */
12338cfa0ad2SJack F Vogel 	ret_val = phy->ops.commit(hw);
12348cfa0ad2SJack F Vogel 	if (ret_val) {
12358cfa0ad2SJack F Vogel 		DEBUGOUT("Error committing the PHY changes\n");
1236ab5d0362SJack F Vogel 		return ret_val;
12378cfa0ad2SJack F Vogel 	}
12388cfa0ad2SJack F Vogel 
12399d81738fSJack F Vogel 	if (phy->type == e1000_phy_82578) {
12409d81738fSJack F Vogel 		ret_val = phy->ops.read_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
12419d81738fSJack F Vogel 					    &phy_data);
12429d81738fSJack F Vogel 		if (ret_val)
1243ab5d0362SJack F Vogel 			return ret_val;
12449d81738fSJack F Vogel 
12459d81738fSJack F Vogel 		/* 82578 PHY - set the downshift count to 1x. */
12469d81738fSJack F Vogel 		phy_data |= I82578_EPSCR_DOWNSHIFT_ENABLE;
12479d81738fSJack F Vogel 		phy_data &= ~I82578_EPSCR_DOWNSHIFT_COUNTER_MASK;
12489d81738fSJack F Vogel 		ret_val = phy->ops.write_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
12499d81738fSJack F Vogel 					     phy_data);
12509d81738fSJack F Vogel 		if (ret_val)
1251ab5d0362SJack F Vogel 			return ret_val;
12529d81738fSJack F Vogel 	}
12539d81738fSJack F Vogel 
1254ab5d0362SJack F Vogel 	return E1000_SUCCESS;
1255ab5d0362SJack F Vogel }
1256ab5d0362SJack F Vogel 
12578cfa0ad2SJack F Vogel /**
1258f0ecc46dSJack F Vogel  *  e1000_copper_link_setup_m88_gen2 - Setup m88 PHY's for copper link
1259f0ecc46dSJack F Vogel  *  @hw: pointer to the HW structure
1260f0ecc46dSJack F Vogel  *
1261f0ecc46dSJack F Vogel  *  Sets up MDI/MDI-X and polarity for i347-AT4, m88e1322 and m88e1112 PHY's.
1262f0ecc46dSJack F Vogel  *  Also enables and sets the downshift parameters.
1263f0ecc46dSJack F Vogel  **/
1264f0ecc46dSJack F Vogel s32 e1000_copper_link_setup_m88_gen2(struct e1000_hw *hw)
1265f0ecc46dSJack F Vogel {
1266f0ecc46dSJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
1267f0ecc46dSJack F Vogel 	s32 ret_val;
1268f0ecc46dSJack F Vogel 	u16 phy_data;
1269f0ecc46dSJack F Vogel 
1270f0ecc46dSJack F Vogel 	DEBUGFUNC("e1000_copper_link_setup_m88_gen2");
1271f0ecc46dSJack F Vogel 
1272f0ecc46dSJack F Vogel 
1273f0ecc46dSJack F Vogel 	/* Enable CRS on Tx. This must be set for half-duplex operation. */
1274f0ecc46dSJack F Vogel 	ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1275f0ecc46dSJack F Vogel 	if (ret_val)
1276ab5d0362SJack F Vogel 		return ret_val;
1277f0ecc46dSJack F Vogel 
12786ab6bfe3SJack F Vogel 	/* Options:
1279f0ecc46dSJack F Vogel 	 *   MDI/MDI-X = 0 (default)
1280f0ecc46dSJack F Vogel 	 *   0 - Auto for all speeds
1281f0ecc46dSJack F Vogel 	 *   1 - MDI mode
1282f0ecc46dSJack F Vogel 	 *   2 - MDI-X mode
1283f0ecc46dSJack F Vogel 	 *   3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1284f0ecc46dSJack F Vogel 	 */
1285f0ecc46dSJack F Vogel 	phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1286f0ecc46dSJack F Vogel 
1287f0ecc46dSJack F Vogel 	switch (phy->mdix) {
1288f0ecc46dSJack F Vogel 	case 1:
1289f0ecc46dSJack F Vogel 		phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
1290f0ecc46dSJack F Vogel 		break;
1291f0ecc46dSJack F Vogel 	case 2:
1292f0ecc46dSJack F Vogel 		phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
1293f0ecc46dSJack F Vogel 		break;
1294f0ecc46dSJack F Vogel 	case 3:
1295f0ecc46dSJack F Vogel 		/* M88E1112 does not support this mode) */
1296f0ecc46dSJack F Vogel 		if (phy->id != M88E1112_E_PHY_ID) {
1297f0ecc46dSJack F Vogel 			phy_data |= M88E1000_PSCR_AUTO_X_1000T;
1298f0ecc46dSJack F Vogel 			break;
1299f0ecc46dSJack F Vogel 		}
1300f0ecc46dSJack F Vogel 	case 0:
1301f0ecc46dSJack F Vogel 	default:
1302f0ecc46dSJack F Vogel 		phy_data |= M88E1000_PSCR_AUTO_X_MODE;
1303f0ecc46dSJack F Vogel 		break;
1304f0ecc46dSJack F Vogel 	}
1305f0ecc46dSJack F Vogel 
13066ab6bfe3SJack F Vogel 	/* Options:
1307f0ecc46dSJack F Vogel 	 *   disable_polarity_correction = 0 (default)
1308f0ecc46dSJack F Vogel 	 *       Automatic Correction for Reversed Cable Polarity
1309f0ecc46dSJack F Vogel 	 *   0 - Disabled
1310f0ecc46dSJack F Vogel 	 *   1 - Enabled
1311f0ecc46dSJack F Vogel 	 */
1312f0ecc46dSJack F Vogel 	phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
1313ab5d0362SJack F Vogel 	if (phy->disable_polarity_correction)
1314f0ecc46dSJack F Vogel 		phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
1315f0ecc46dSJack F Vogel 
1316f0ecc46dSJack F Vogel 	/* Enable downshift and setting it to X6 */
13177609433eSJack F Vogel 	if (phy->id == M88E1543_E_PHY_ID) {
13187609433eSJack F Vogel 		phy_data &= ~I347AT4_PSCR_DOWNSHIFT_ENABLE;
13197609433eSJack F Vogel 		ret_val =
13207609433eSJack F Vogel 		    phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
13217609433eSJack F Vogel 		if (ret_val)
13227609433eSJack F Vogel 			return ret_val;
13237609433eSJack F Vogel 
13247609433eSJack F Vogel 		ret_val = phy->ops.commit(hw);
13257609433eSJack F Vogel 		if (ret_val) {
13267609433eSJack F Vogel 			DEBUGOUT("Error committing the PHY changes\n");
13277609433eSJack F Vogel 			return ret_val;
13287609433eSJack F Vogel 		}
13297609433eSJack F Vogel 	}
13307609433eSJack F Vogel 
1331f0ecc46dSJack F Vogel 	phy_data &= ~I347AT4_PSCR_DOWNSHIFT_MASK;
1332f0ecc46dSJack F Vogel 	phy_data |= I347AT4_PSCR_DOWNSHIFT_6X;
1333f0ecc46dSJack F Vogel 	phy_data |= I347AT4_PSCR_DOWNSHIFT_ENABLE;
1334f0ecc46dSJack F Vogel 
1335f0ecc46dSJack F Vogel 	ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1336f0ecc46dSJack F Vogel 	if (ret_val)
1337ab5d0362SJack F Vogel 		return ret_val;
1338f0ecc46dSJack F Vogel 
1339f0ecc46dSJack F Vogel 	/* Commit the changes. */
1340f0ecc46dSJack F Vogel 	ret_val = phy->ops.commit(hw);
1341f0ecc46dSJack F Vogel 	if (ret_val) {
1342f0ecc46dSJack F Vogel 		DEBUGOUT("Error committing the PHY changes\n");
1343ab5d0362SJack F Vogel 		return ret_val;
1344f0ecc46dSJack F Vogel 	}
1345f0ecc46dSJack F Vogel 
13467609433eSJack F Vogel 	ret_val = e1000_set_master_slave_mode(hw);
13477609433eSJack F Vogel 	if (ret_val)
13487609433eSJack F Vogel 		return ret_val;
13497609433eSJack F Vogel 
1350ab5d0362SJack F Vogel 	return E1000_SUCCESS;
1351f0ecc46dSJack F Vogel }
1352f0ecc46dSJack F Vogel 
1353f0ecc46dSJack F Vogel /**
13548cfa0ad2SJack F Vogel  *  e1000_copper_link_setup_igp - Setup igp PHY's for copper link
13558cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
13568cfa0ad2SJack F Vogel  *
13578cfa0ad2SJack F Vogel  *  Sets up LPLU, MDI/MDI-X, polarity, Smartspeed and Master/Slave config for
13588cfa0ad2SJack F Vogel  *  igp PHY's.
13598cfa0ad2SJack F Vogel  **/
13608cfa0ad2SJack F Vogel s32 e1000_copper_link_setup_igp(struct e1000_hw *hw)
13618cfa0ad2SJack F Vogel {
13628cfa0ad2SJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
13638cfa0ad2SJack F Vogel 	s32 ret_val;
13648cfa0ad2SJack F Vogel 	u16 data;
13658cfa0ad2SJack F Vogel 
13668cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_copper_link_setup_igp");
13678cfa0ad2SJack F Vogel 
13688cfa0ad2SJack F Vogel 
13698cfa0ad2SJack F Vogel 	ret_val = hw->phy.ops.reset(hw);
13708cfa0ad2SJack F Vogel 	if (ret_val) {
13718cfa0ad2SJack F Vogel 		DEBUGOUT("Error resetting the PHY.\n");
1372ab5d0362SJack F Vogel 		return ret_val;
13738cfa0ad2SJack F Vogel 	}
13748cfa0ad2SJack F Vogel 
13756ab6bfe3SJack F Vogel 	/* Wait 100ms for MAC to configure PHY from NVM settings, to avoid
13768cfa0ad2SJack F Vogel 	 * timeout issues when LFS is enabled.
13778cfa0ad2SJack F Vogel 	 */
13788cfa0ad2SJack F Vogel 	msec_delay(100);
13798cfa0ad2SJack F Vogel 
13806ab6bfe3SJack F Vogel 	/* The NVM settings will configure LPLU in D3 for
13818cfa0ad2SJack F Vogel 	 * non-IGP1 PHYs.
13828cfa0ad2SJack F Vogel 	 */
13838cfa0ad2SJack F Vogel 	if (phy->type == e1000_phy_igp) {
13848cfa0ad2SJack F Vogel 		/* disable lplu d3 during driver init */
13858cfa0ad2SJack F Vogel 		ret_val = hw->phy.ops.set_d3_lplu_state(hw, FALSE);
13868cfa0ad2SJack F Vogel 		if (ret_val) {
13878cfa0ad2SJack F Vogel 			DEBUGOUT("Error Disabling LPLU D3\n");
1388ab5d0362SJack F Vogel 			return ret_val;
13898cfa0ad2SJack F Vogel 		}
13908cfa0ad2SJack F Vogel 	}
13918cfa0ad2SJack F Vogel 
13928cfa0ad2SJack F Vogel 	/* disable lplu d0 during driver init */
13938cfa0ad2SJack F Vogel 	if (hw->phy.ops.set_d0_lplu_state) {
13948cfa0ad2SJack F Vogel 		ret_val = hw->phy.ops.set_d0_lplu_state(hw, FALSE);
13958cfa0ad2SJack F Vogel 		if (ret_val) {
13968cfa0ad2SJack F Vogel 			DEBUGOUT("Error Disabling LPLU D0\n");
1397ab5d0362SJack F Vogel 			return ret_val;
13988cfa0ad2SJack F Vogel 		}
13998cfa0ad2SJack F Vogel 	}
14008cfa0ad2SJack F Vogel 	/* Configure mdi-mdix settings */
14018cfa0ad2SJack F Vogel 	ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CTRL, &data);
14028cfa0ad2SJack F Vogel 	if (ret_val)
1403ab5d0362SJack F Vogel 		return ret_val;
14048cfa0ad2SJack F Vogel 
14058cfa0ad2SJack F Vogel 	data &= ~IGP01E1000_PSCR_AUTO_MDIX;
14068cfa0ad2SJack F Vogel 
14078cfa0ad2SJack F Vogel 	switch (phy->mdix) {
14088cfa0ad2SJack F Vogel 	case 1:
14098cfa0ad2SJack F Vogel 		data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
14108cfa0ad2SJack F Vogel 		break;
14118cfa0ad2SJack F Vogel 	case 2:
14128cfa0ad2SJack F Vogel 		data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
14138cfa0ad2SJack F Vogel 		break;
14148cfa0ad2SJack F Vogel 	case 0:
14158cfa0ad2SJack F Vogel 	default:
14168cfa0ad2SJack F Vogel 		data |= IGP01E1000_PSCR_AUTO_MDIX;
14178cfa0ad2SJack F Vogel 		break;
14188cfa0ad2SJack F Vogel 	}
14198cfa0ad2SJack F Vogel 	ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CTRL, data);
14208cfa0ad2SJack F Vogel 	if (ret_val)
1421ab5d0362SJack F Vogel 		return ret_val;
14228cfa0ad2SJack F Vogel 
14238cfa0ad2SJack F Vogel 	/* set auto-master slave resolution settings */
14248cfa0ad2SJack F Vogel 	if (hw->mac.autoneg) {
14256ab6bfe3SJack F Vogel 		/* when autonegotiation advertisement is only 1000Mbps then we
14268cfa0ad2SJack F Vogel 		 * should disable SmartSpeed and enable Auto MasterSlave
14278cfa0ad2SJack F Vogel 		 * resolution as hardware default.
14288cfa0ad2SJack F Vogel 		 */
14298cfa0ad2SJack F Vogel 		if (phy->autoneg_advertised == ADVERTISE_1000_FULL) {
14308cfa0ad2SJack F Vogel 			/* Disable SmartSpeed */
14318cfa0ad2SJack F Vogel 			ret_val = phy->ops.read_reg(hw,
14328cfa0ad2SJack F Vogel 						    IGP01E1000_PHY_PORT_CONFIG,
14338cfa0ad2SJack F Vogel 						    &data);
14348cfa0ad2SJack F Vogel 			if (ret_val)
1435ab5d0362SJack F Vogel 				return ret_val;
14368cfa0ad2SJack F Vogel 
14378cfa0ad2SJack F Vogel 			data &= ~IGP01E1000_PSCFR_SMART_SPEED;
14388cfa0ad2SJack F Vogel 			ret_val = phy->ops.write_reg(hw,
14398cfa0ad2SJack F Vogel 						     IGP01E1000_PHY_PORT_CONFIG,
14408cfa0ad2SJack F Vogel 						     data);
14418cfa0ad2SJack F Vogel 			if (ret_val)
1442ab5d0362SJack F Vogel 				return ret_val;
14438cfa0ad2SJack F Vogel 
14448cfa0ad2SJack F Vogel 			/* Set auto Master/Slave resolution process */
14458cfa0ad2SJack F Vogel 			ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL, &data);
14468cfa0ad2SJack F Vogel 			if (ret_val)
1447ab5d0362SJack F Vogel 				return ret_val;
14488cfa0ad2SJack F Vogel 
14498cfa0ad2SJack F Vogel 			data &= ~CR_1000T_MS_ENABLE;
14508cfa0ad2SJack F Vogel 			ret_val = phy->ops.write_reg(hw, PHY_1000T_CTRL, data);
14518cfa0ad2SJack F Vogel 			if (ret_val)
14528cfa0ad2SJack F Vogel 				return ret_val;
14538cfa0ad2SJack F Vogel 		}
14548cfa0ad2SJack F Vogel 
1455ab5d0362SJack F Vogel 		ret_val = e1000_set_master_slave_mode(hw);
14568cfa0ad2SJack F Vogel 	}
14578cfa0ad2SJack F Vogel 
14588cfa0ad2SJack F Vogel 	return ret_val;
14598cfa0ad2SJack F Vogel }
14608cfa0ad2SJack F Vogel 
14618cfa0ad2SJack F Vogel /**
14628cfa0ad2SJack F Vogel  *  e1000_phy_setup_autoneg - Configure PHY for auto-negotiation
14638cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
14648cfa0ad2SJack F Vogel  *
14658cfa0ad2SJack F Vogel  *  Reads the MII auto-neg advertisement register and/or the 1000T control
14668cfa0ad2SJack F Vogel  *  register and if the PHY is already setup for auto-negotiation, then
14678cfa0ad2SJack F Vogel  *  return successful.  Otherwise, setup advertisement and flow control to
14688cfa0ad2SJack F Vogel  *  the appropriate values for the wanted auto-negotiation.
14698cfa0ad2SJack F Vogel  **/
14708cfa0ad2SJack F Vogel s32 e1000_phy_setup_autoneg(struct e1000_hw *hw)
14718cfa0ad2SJack F Vogel {
14728cfa0ad2SJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
14738cfa0ad2SJack F Vogel 	s32 ret_val;
14748cfa0ad2SJack F Vogel 	u16 mii_autoneg_adv_reg;
14758cfa0ad2SJack F Vogel 	u16 mii_1000t_ctrl_reg = 0;
14768cfa0ad2SJack F Vogel 
14778cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_phy_setup_autoneg");
14788cfa0ad2SJack F Vogel 
14798cfa0ad2SJack F Vogel 	phy->autoneg_advertised &= phy->autoneg_mask;
14808cfa0ad2SJack F Vogel 
14818cfa0ad2SJack F Vogel 	/* Read the MII Auto-Neg Advertisement Register (Address 4). */
14828cfa0ad2SJack F Vogel 	ret_val = phy->ops.read_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
14838cfa0ad2SJack F Vogel 	if (ret_val)
1484ab5d0362SJack F Vogel 		return ret_val;
14858cfa0ad2SJack F Vogel 
14868cfa0ad2SJack F Vogel 	if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
14878cfa0ad2SJack F Vogel 		/* Read the MII 1000Base-T Control Register (Address 9). */
1488daf9197cSJack F Vogel 		ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL,
14898cfa0ad2SJack F Vogel 					    &mii_1000t_ctrl_reg);
14908cfa0ad2SJack F Vogel 		if (ret_val)
1491ab5d0362SJack F Vogel 			return ret_val;
14928cfa0ad2SJack F Vogel 	}
14938cfa0ad2SJack F Vogel 
14946ab6bfe3SJack F Vogel 	/* Need to parse both autoneg_advertised and fc and set up
14958cfa0ad2SJack F Vogel 	 * the appropriate PHY registers.  First we will parse for
14968cfa0ad2SJack F Vogel 	 * autoneg_advertised software override.  Since we can advertise
14978cfa0ad2SJack F Vogel 	 * a plethora of combinations, we need to check each bit
14988cfa0ad2SJack F Vogel 	 * individually.
14998cfa0ad2SJack F Vogel 	 */
15008cfa0ad2SJack F Vogel 
15016ab6bfe3SJack F Vogel 	/* First we clear all the 10/100 mb speed bits in the Auto-Neg
15028cfa0ad2SJack F Vogel 	 * Advertisement Register (Address 4) and the 1000 mb speed bits in
15038cfa0ad2SJack F Vogel 	 * the  1000Base-T Control Register (Address 9).
15048cfa0ad2SJack F Vogel 	 */
15058cfa0ad2SJack F Vogel 	mii_autoneg_adv_reg &= ~(NWAY_AR_100TX_FD_CAPS |
15068cfa0ad2SJack F Vogel 				 NWAY_AR_100TX_HD_CAPS |
15078cfa0ad2SJack F Vogel 				 NWAY_AR_10T_FD_CAPS   |
15088cfa0ad2SJack F Vogel 				 NWAY_AR_10T_HD_CAPS);
15098cfa0ad2SJack F Vogel 	mii_1000t_ctrl_reg &= ~(CR_1000T_HD_CAPS | CR_1000T_FD_CAPS);
15108cfa0ad2SJack F Vogel 
15118cfa0ad2SJack F Vogel 	DEBUGOUT1("autoneg_advertised %x\n", phy->autoneg_advertised);
15128cfa0ad2SJack F Vogel 
15138cfa0ad2SJack F Vogel 	/* Do we want to advertise 10 Mb Half Duplex? */
15148cfa0ad2SJack F Vogel 	if (phy->autoneg_advertised & ADVERTISE_10_HALF) {
15158cfa0ad2SJack F Vogel 		DEBUGOUT("Advertise 10mb Half duplex\n");
15168cfa0ad2SJack F Vogel 		mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
15178cfa0ad2SJack F Vogel 	}
15188cfa0ad2SJack F Vogel 
15198cfa0ad2SJack F Vogel 	/* Do we want to advertise 10 Mb Full Duplex? */
15208cfa0ad2SJack F Vogel 	if (phy->autoneg_advertised & ADVERTISE_10_FULL) {
15218cfa0ad2SJack F Vogel 		DEBUGOUT("Advertise 10mb Full duplex\n");
15228cfa0ad2SJack F Vogel 		mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
15238cfa0ad2SJack F Vogel 	}
15248cfa0ad2SJack F Vogel 
15258cfa0ad2SJack F Vogel 	/* Do we want to advertise 100 Mb Half Duplex? */
15268cfa0ad2SJack F Vogel 	if (phy->autoneg_advertised & ADVERTISE_100_HALF) {
15278cfa0ad2SJack F Vogel 		DEBUGOUT("Advertise 100mb Half duplex\n");
15288cfa0ad2SJack F Vogel 		mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
15298cfa0ad2SJack F Vogel 	}
15308cfa0ad2SJack F Vogel 
15318cfa0ad2SJack F Vogel 	/* Do we want to advertise 100 Mb Full Duplex? */
15328cfa0ad2SJack F Vogel 	if (phy->autoneg_advertised & ADVERTISE_100_FULL) {
15338cfa0ad2SJack F Vogel 		DEBUGOUT("Advertise 100mb Full duplex\n");
15348cfa0ad2SJack F Vogel 		mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
15358cfa0ad2SJack F Vogel 	}
15368cfa0ad2SJack F Vogel 
15378cfa0ad2SJack F Vogel 	/* We do not allow the Phy to advertise 1000 Mb Half Duplex */
1538daf9197cSJack F Vogel 	if (phy->autoneg_advertised & ADVERTISE_1000_HALF)
15398cfa0ad2SJack F Vogel 		DEBUGOUT("Advertise 1000mb Half duplex request denied!\n");
15408cfa0ad2SJack F Vogel 
15418cfa0ad2SJack F Vogel 	/* Do we want to advertise 1000 Mb Full Duplex? */
15428cfa0ad2SJack F Vogel 	if (phy->autoneg_advertised & ADVERTISE_1000_FULL) {
15438cfa0ad2SJack F Vogel 		DEBUGOUT("Advertise 1000mb Full duplex\n");
15448cfa0ad2SJack F Vogel 		mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
15458cfa0ad2SJack F Vogel 	}
15468cfa0ad2SJack F Vogel 
15476ab6bfe3SJack F Vogel 	/* Check for a software override of the flow control settings, and
15488cfa0ad2SJack F Vogel 	 * setup the PHY advertisement registers accordingly.  If
15498cfa0ad2SJack F Vogel 	 * auto-negotiation is enabled, then software will have to set the
15508cfa0ad2SJack F Vogel 	 * "PAUSE" bits to the correct value in the Auto-Negotiation
15518cfa0ad2SJack F Vogel 	 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-
15528cfa0ad2SJack F Vogel 	 * negotiation.
15538cfa0ad2SJack F Vogel 	 *
15548cfa0ad2SJack F Vogel 	 * The possible values of the "fc" parameter are:
15558cfa0ad2SJack F Vogel 	 *      0:  Flow control is completely disabled
15568cfa0ad2SJack F Vogel 	 *      1:  Rx flow control is enabled (we can receive pause frames
15578cfa0ad2SJack F Vogel 	 *          but not send pause frames).
15588cfa0ad2SJack F Vogel 	 *      2:  Tx flow control is enabled (we can send pause frames
15598cfa0ad2SJack F Vogel 	 *          but we do not support receiving pause frames).
15608cfa0ad2SJack F Vogel 	 *      3:  Both Rx and Tx flow control (symmetric) are enabled.
15618cfa0ad2SJack F Vogel 	 *  other:  No software override.  The flow control configuration
15628cfa0ad2SJack F Vogel 	 *          in the EEPROM is used.
15638cfa0ad2SJack F Vogel 	 */
1564daf9197cSJack F Vogel 	switch (hw->fc.current_mode) {
15658cfa0ad2SJack F Vogel 	case e1000_fc_none:
15666ab6bfe3SJack F Vogel 		/* Flow control (Rx & Tx) is completely disabled by a
15678cfa0ad2SJack F Vogel 		 * software over-ride.
15688cfa0ad2SJack F Vogel 		 */
15698cfa0ad2SJack F Vogel 		mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
15708cfa0ad2SJack F Vogel 		break;
15718cfa0ad2SJack F Vogel 	case e1000_fc_rx_pause:
15726ab6bfe3SJack F Vogel 		/* Rx Flow control is enabled, and Tx Flow control is
15738cfa0ad2SJack F Vogel 		 * disabled, by a software over-ride.
15748cfa0ad2SJack F Vogel 		 *
15758cfa0ad2SJack F Vogel 		 * Since there really isn't a way to advertise that we are
15768cfa0ad2SJack F Vogel 		 * capable of Rx Pause ONLY, we will advertise that we
15778cfa0ad2SJack F Vogel 		 * support both symmetric and asymmetric Rx PAUSE.  Later
15788cfa0ad2SJack F Vogel 		 * (in e1000_config_fc_after_link_up) we will disable the
15798cfa0ad2SJack F Vogel 		 * hw's ability to send PAUSE frames.
15808cfa0ad2SJack F Vogel 		 */
15818cfa0ad2SJack F Vogel 		mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
15828cfa0ad2SJack F Vogel 		break;
15838cfa0ad2SJack F Vogel 	case e1000_fc_tx_pause:
15846ab6bfe3SJack F Vogel 		/* Tx Flow control is enabled, and Rx Flow control is
15858cfa0ad2SJack F Vogel 		 * disabled, by a software over-ride.
15868cfa0ad2SJack F Vogel 		 */
15878cfa0ad2SJack F Vogel 		mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
15888cfa0ad2SJack F Vogel 		mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
15898cfa0ad2SJack F Vogel 		break;
15908cfa0ad2SJack F Vogel 	case e1000_fc_full:
15916ab6bfe3SJack F Vogel 		/* Flow control (both Rx and Tx) is enabled by a software
15928cfa0ad2SJack F Vogel 		 * over-ride.
15938cfa0ad2SJack F Vogel 		 */
15948cfa0ad2SJack F Vogel 		mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
15958cfa0ad2SJack F Vogel 		break;
15968cfa0ad2SJack F Vogel 	default:
15978cfa0ad2SJack F Vogel 		DEBUGOUT("Flow control param set incorrectly\n");
1598ab5d0362SJack F Vogel 		return -E1000_ERR_CONFIG;
15998cfa0ad2SJack F Vogel 	}
16008cfa0ad2SJack F Vogel 
16018cfa0ad2SJack F Vogel 	ret_val = phy->ops.write_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
16028cfa0ad2SJack F Vogel 	if (ret_val)
1603ab5d0362SJack F Vogel 		return ret_val;
16048cfa0ad2SJack F Vogel 
16058cfa0ad2SJack F Vogel 	DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
16068cfa0ad2SJack F Vogel 
1607ab5d0362SJack F Vogel 	if (phy->autoneg_mask & ADVERTISE_1000_FULL)
16084dab5c37SJack F Vogel 		ret_val = phy->ops.write_reg(hw, PHY_1000T_CTRL,
16098cfa0ad2SJack F Vogel 					     mii_1000t_ctrl_reg);
1610ab5d0362SJack F Vogel 
1611ab5d0362SJack F Vogel 	return ret_val;
16128cfa0ad2SJack F Vogel }
16138cfa0ad2SJack F Vogel 
1614ab5d0362SJack F Vogel /**
1615ab5d0362SJack F Vogel  *  e1000_copper_link_autoneg - Setup/Enable autoneg for copper link
1616ab5d0362SJack F Vogel  *  @hw: pointer to the HW structure
1617ab5d0362SJack F Vogel  *
1618ab5d0362SJack F Vogel  *  Performs initial bounds checking on autoneg advertisement parameter, then
1619ab5d0362SJack F Vogel  *  configure to advertise the full capability.  Setup the PHY to autoneg
1620ab5d0362SJack F Vogel  *  and restart the negotiation process between the link partner.  If
1621ab5d0362SJack F Vogel  *  autoneg_wait_to_complete, then wait for autoneg to complete before exiting.
1622ab5d0362SJack F Vogel  **/
1623ab5d0362SJack F Vogel s32 e1000_copper_link_autoneg(struct e1000_hw *hw)
1624ab5d0362SJack F Vogel {
1625ab5d0362SJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
1626ab5d0362SJack F Vogel 	s32 ret_val;
1627ab5d0362SJack F Vogel 	u16 phy_ctrl;
1628ab5d0362SJack F Vogel 
1629ab5d0362SJack F Vogel 	DEBUGFUNC("e1000_copper_link_autoneg");
1630ab5d0362SJack F Vogel 
16316ab6bfe3SJack F Vogel 	/* Perform some bounds checking on the autoneg advertisement
1632ab5d0362SJack F Vogel 	 * parameter.
1633ab5d0362SJack F Vogel 	 */
1634ab5d0362SJack F Vogel 	phy->autoneg_advertised &= phy->autoneg_mask;
1635ab5d0362SJack F Vogel 
16366ab6bfe3SJack F Vogel 	/* If autoneg_advertised is zero, we assume it was not defaulted
1637ab5d0362SJack F Vogel 	 * by the calling code so we set to advertise full capability.
1638ab5d0362SJack F Vogel 	 */
1639ab5d0362SJack F Vogel 	if (!phy->autoneg_advertised)
1640ab5d0362SJack F Vogel 		phy->autoneg_advertised = phy->autoneg_mask;
1641ab5d0362SJack F Vogel 
1642ab5d0362SJack F Vogel 	DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
1643ab5d0362SJack F Vogel 	ret_val = e1000_phy_setup_autoneg(hw);
1644ab5d0362SJack F Vogel 	if (ret_val) {
1645ab5d0362SJack F Vogel 		DEBUGOUT("Error Setting up Auto-Negotiation\n");
1646ab5d0362SJack F Vogel 		return ret_val;
1647ab5d0362SJack F Vogel 	}
1648ab5d0362SJack F Vogel 	DEBUGOUT("Restarting Auto-Neg\n");
1649ab5d0362SJack F Vogel 
16506ab6bfe3SJack F Vogel 	/* Restart auto-negotiation by setting the Auto Neg Enable bit and
1651ab5d0362SJack F Vogel 	 * the Auto Neg Restart bit in the PHY control register.
1652ab5d0362SJack F Vogel 	 */
1653ab5d0362SJack F Vogel 	ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_ctrl);
1654ab5d0362SJack F Vogel 	if (ret_val)
1655ab5d0362SJack F Vogel 		return ret_val;
1656ab5d0362SJack F Vogel 
1657ab5d0362SJack F Vogel 	phy_ctrl |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
1658ab5d0362SJack F Vogel 	ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_ctrl);
1659ab5d0362SJack F Vogel 	if (ret_val)
1660ab5d0362SJack F Vogel 		return ret_val;
1661ab5d0362SJack F Vogel 
16626ab6bfe3SJack F Vogel 	/* Does the user want to wait for Auto-Neg to complete here, or
1663ab5d0362SJack F Vogel 	 * check at a later time (for example, callback routine).
1664ab5d0362SJack F Vogel 	 */
1665ab5d0362SJack F Vogel 	if (phy->autoneg_wait_to_complete) {
16666ab6bfe3SJack F Vogel 		ret_val = e1000_wait_autoneg(hw);
1667ab5d0362SJack F Vogel 		if (ret_val) {
1668ab5d0362SJack F Vogel 			DEBUGOUT("Error while waiting for autoneg to complete\n");
1669ab5d0362SJack F Vogel 			return ret_val;
1670ab5d0362SJack F Vogel 		}
1671ab5d0362SJack F Vogel 	}
1672ab5d0362SJack F Vogel 
1673ab5d0362SJack F Vogel 	hw->mac.get_link_status = TRUE;
1674ab5d0362SJack F Vogel 
16758cfa0ad2SJack F Vogel 	return ret_val;
16768cfa0ad2SJack F Vogel }
16778cfa0ad2SJack F Vogel 
16788cfa0ad2SJack F Vogel /**
16798cfa0ad2SJack F Vogel  *  e1000_setup_copper_link_generic - Configure copper link settings
16808cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
16818cfa0ad2SJack F Vogel  *
16828cfa0ad2SJack F Vogel  *  Calls the appropriate function to configure the link for auto-neg or forced
16838cfa0ad2SJack F Vogel  *  speed and duplex.  Then we check for link, once link is established calls
16848cfa0ad2SJack F Vogel  *  to configure collision distance and flow control are called.  If link is
16858cfa0ad2SJack F Vogel  *  not established, we return -E1000_ERR_PHY (-2).
16868cfa0ad2SJack F Vogel  **/
16878cfa0ad2SJack F Vogel s32 e1000_setup_copper_link_generic(struct e1000_hw *hw)
16888cfa0ad2SJack F Vogel {
16898cfa0ad2SJack F Vogel 	s32 ret_val;
16908cfa0ad2SJack F Vogel 	bool link;
16918cfa0ad2SJack F Vogel 
16928cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_setup_copper_link_generic");
16938cfa0ad2SJack F Vogel 
16948cfa0ad2SJack F Vogel 	if (hw->mac.autoneg) {
16956ab6bfe3SJack F Vogel 		/* Setup autoneg and flow control advertisement and perform
16968cfa0ad2SJack F Vogel 		 * autonegotiation.
16978cfa0ad2SJack F Vogel 		 */
16988cfa0ad2SJack F Vogel 		ret_val = e1000_copper_link_autoneg(hw);
16998cfa0ad2SJack F Vogel 		if (ret_val)
1700ab5d0362SJack F Vogel 			return ret_val;
17018cfa0ad2SJack F Vogel 	} else {
17026ab6bfe3SJack F Vogel 		/* PHY will be set to 10H, 10F, 100H or 100F
17038cfa0ad2SJack F Vogel 		 * depending on user settings.
17048cfa0ad2SJack F Vogel 		 */
17058cfa0ad2SJack F Vogel 		DEBUGOUT("Forcing Speed and Duplex\n");
17068cfa0ad2SJack F Vogel 		ret_val = hw->phy.ops.force_speed_duplex(hw);
17078cfa0ad2SJack F Vogel 		if (ret_val) {
17088cfa0ad2SJack F Vogel 			DEBUGOUT("Error Forcing Speed and Duplex\n");
1709ab5d0362SJack F Vogel 			return ret_val;
17108cfa0ad2SJack F Vogel 		}
17118cfa0ad2SJack F Vogel 	}
17128cfa0ad2SJack F Vogel 
17136ab6bfe3SJack F Vogel 	/* Check link status. Wait up to 100 microseconds for link to become
17148cfa0ad2SJack F Vogel 	 * valid.
17158cfa0ad2SJack F Vogel 	 */
17164dab5c37SJack F Vogel 	ret_val = e1000_phy_has_link_generic(hw, COPPER_LINK_UP_LIMIT, 10,
17178cfa0ad2SJack F Vogel 					     &link);
17188cfa0ad2SJack F Vogel 	if (ret_val)
1719ab5d0362SJack F Vogel 		return ret_val;
17208cfa0ad2SJack F Vogel 
17218cfa0ad2SJack F Vogel 	if (link) {
17228cfa0ad2SJack F Vogel 		DEBUGOUT("Valid link established!!!\n");
1723ab5d0362SJack F Vogel 		hw->mac.ops.config_collision_dist(hw);
17248cfa0ad2SJack F Vogel 		ret_val = e1000_config_fc_after_link_up_generic(hw);
17258cfa0ad2SJack F Vogel 	} else {
17268cfa0ad2SJack F Vogel 		DEBUGOUT("Unable to establish link!!!\n");
17278cfa0ad2SJack F Vogel 	}
17288cfa0ad2SJack F Vogel 
17298cfa0ad2SJack F Vogel 	return ret_val;
17308cfa0ad2SJack F Vogel }
17318cfa0ad2SJack F Vogel 
17328cfa0ad2SJack F Vogel /**
17338cfa0ad2SJack F Vogel  *  e1000_phy_force_speed_duplex_igp - Force speed/duplex for igp PHY
17348cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
17358cfa0ad2SJack F Vogel  *
17368cfa0ad2SJack F Vogel  *  Calls the PHY setup function to force speed and duplex.  Clears the
17378cfa0ad2SJack F Vogel  *  auto-crossover to force MDI manually.  Waits for link and returns
17388cfa0ad2SJack F Vogel  *  successful if link up is successful, else -E1000_ERR_PHY (-2).
17398cfa0ad2SJack F Vogel  **/
17408cfa0ad2SJack F Vogel s32 e1000_phy_force_speed_duplex_igp(struct e1000_hw *hw)
17418cfa0ad2SJack F Vogel {
17428cfa0ad2SJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
17438cfa0ad2SJack F Vogel 	s32 ret_val;
17448cfa0ad2SJack F Vogel 	u16 phy_data;
17458cfa0ad2SJack F Vogel 	bool link;
17468cfa0ad2SJack F Vogel 
17478cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_phy_force_speed_duplex_igp");
17488cfa0ad2SJack F Vogel 
17498cfa0ad2SJack F Vogel 	ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data);
17508cfa0ad2SJack F Vogel 	if (ret_val)
1751ab5d0362SJack F Vogel 		return ret_val;
17528cfa0ad2SJack F Vogel 
17538cfa0ad2SJack F Vogel 	e1000_phy_force_speed_duplex_setup(hw, &phy_data);
17548cfa0ad2SJack F Vogel 
17558cfa0ad2SJack F Vogel 	ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data);
17568cfa0ad2SJack F Vogel 	if (ret_val)
1757ab5d0362SJack F Vogel 		return ret_val;
17588cfa0ad2SJack F Vogel 
17596ab6bfe3SJack F Vogel 	/* Clear Auto-Crossover to force MDI manually.  IGP requires MDI
17608cfa0ad2SJack F Vogel 	 * forced whenever speed and duplex are forced.
17618cfa0ad2SJack F Vogel 	 */
17628cfa0ad2SJack F Vogel 	ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
17638cfa0ad2SJack F Vogel 	if (ret_val)
1764ab5d0362SJack F Vogel 		return ret_val;
17658cfa0ad2SJack F Vogel 
17668cfa0ad2SJack F Vogel 	phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
17678cfa0ad2SJack F Vogel 	phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
17688cfa0ad2SJack F Vogel 
17698cfa0ad2SJack F Vogel 	ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
17708cfa0ad2SJack F Vogel 	if (ret_val)
1771ab5d0362SJack F Vogel 		return ret_val;
17728cfa0ad2SJack F Vogel 
17738cfa0ad2SJack F Vogel 	DEBUGOUT1("IGP PSCR: %X\n", phy_data);
17748cfa0ad2SJack F Vogel 
17758cfa0ad2SJack F Vogel 	usec_delay(1);
17768cfa0ad2SJack F Vogel 
17778cfa0ad2SJack F Vogel 	if (phy->autoneg_wait_to_complete) {
17788cfa0ad2SJack F Vogel 		DEBUGOUT("Waiting for forced speed/duplex link on IGP phy.\n");
17798cfa0ad2SJack F Vogel 
17804dab5c37SJack F Vogel 		ret_val = e1000_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
17814dab5c37SJack F Vogel 						     100000, &link);
17828cfa0ad2SJack F Vogel 		if (ret_val)
1783ab5d0362SJack F Vogel 			return ret_val;
17848cfa0ad2SJack F Vogel 
1785daf9197cSJack F Vogel 		if (!link)
17868cfa0ad2SJack F Vogel 			DEBUGOUT("Link taking longer than expected.\n");
17878cfa0ad2SJack F Vogel 
17888cfa0ad2SJack F Vogel 		/* Try once more */
17894dab5c37SJack F Vogel 		ret_val = e1000_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
17904dab5c37SJack F Vogel 						     100000, &link);
17918cfa0ad2SJack F Vogel 	}
17928cfa0ad2SJack F Vogel 
17938cfa0ad2SJack F Vogel 	return ret_val;
17948cfa0ad2SJack F Vogel }
17958cfa0ad2SJack F Vogel 
17968cfa0ad2SJack F Vogel /**
17978cfa0ad2SJack F Vogel  *  e1000_phy_force_speed_duplex_m88 - Force speed/duplex for m88 PHY
17988cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
17998cfa0ad2SJack F Vogel  *
18008cfa0ad2SJack F Vogel  *  Calls the PHY setup function to force speed and duplex.  Clears the
18018cfa0ad2SJack F Vogel  *  auto-crossover to force MDI manually.  Resets the PHY to commit the
18028cfa0ad2SJack F Vogel  *  changes.  If time expires while waiting for link up, we reset the DSP.
18038cfa0ad2SJack F Vogel  *  After reset, TX_CLK and CRS on Tx must be set.  Return successful upon
18048cfa0ad2SJack F Vogel  *  successful completion, else return corresponding error code.
18058cfa0ad2SJack F Vogel  **/
18068cfa0ad2SJack F Vogel s32 e1000_phy_force_speed_duplex_m88(struct e1000_hw *hw)
18078cfa0ad2SJack F Vogel {
18088cfa0ad2SJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
18098cfa0ad2SJack F Vogel 	s32 ret_val;
18108cfa0ad2SJack F Vogel 	u16 phy_data;
18118cfa0ad2SJack F Vogel 	bool link;
18128cfa0ad2SJack F Vogel 
18138cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_phy_force_speed_duplex_m88");
18148cfa0ad2SJack F Vogel 
18156ab6bfe3SJack F Vogel 	/* I210 and I211 devices support Auto-Crossover in forced operation. */
18166ab6bfe3SJack F Vogel 	if (phy->type != e1000_phy_i210) {
18176ab6bfe3SJack F Vogel 		/* Clear Auto-Crossover to force MDI manually.  M88E1000
18186ab6bfe3SJack F Vogel 		 * requires MDI forced whenever speed and duplex are forced.
18198cfa0ad2SJack F Vogel 		 */
18206ab6bfe3SJack F Vogel 		ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL,
18216ab6bfe3SJack F Vogel 					    &phy_data);
18228cfa0ad2SJack F Vogel 		if (ret_val)
1823ab5d0362SJack F Vogel 			return ret_val;
18248cfa0ad2SJack F Vogel 
18258cfa0ad2SJack F Vogel 		phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
18266ab6bfe3SJack F Vogel 		ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL,
18276ab6bfe3SJack F Vogel 					     phy_data);
18288cfa0ad2SJack F Vogel 		if (ret_val)
1829ab5d0362SJack F Vogel 			return ret_val;
18306ab6bfe3SJack F Vogel 	}
18318cfa0ad2SJack F Vogel 
18328cfa0ad2SJack F Vogel 	DEBUGOUT1("M88E1000 PSCR: %X\n", phy_data);
18338cfa0ad2SJack F Vogel 
18348cfa0ad2SJack F Vogel 	ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data);
18358cfa0ad2SJack F Vogel 	if (ret_val)
1836ab5d0362SJack F Vogel 		return ret_val;
18378cfa0ad2SJack F Vogel 
18388cfa0ad2SJack F Vogel 	e1000_phy_force_speed_duplex_setup(hw, &phy_data);
18398cfa0ad2SJack F Vogel 
18408cfa0ad2SJack F Vogel 	ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data);
18418cfa0ad2SJack F Vogel 	if (ret_val)
1842ab5d0362SJack F Vogel 		return ret_val;
18438cfa0ad2SJack F Vogel 
18448cfa0ad2SJack F Vogel 	/* Reset the phy to commit changes. */
18458cfa0ad2SJack F Vogel 	ret_val = hw->phy.ops.commit(hw);
18468cfa0ad2SJack F Vogel 	if (ret_val)
1847ab5d0362SJack F Vogel 		return ret_val;
18488cfa0ad2SJack F Vogel 
18498cfa0ad2SJack F Vogel 	if (phy->autoneg_wait_to_complete) {
18508cfa0ad2SJack F Vogel 		DEBUGOUT("Waiting for forced speed/duplex link on M88 phy.\n");
18518cfa0ad2SJack F Vogel 
1852daf9197cSJack F Vogel 		ret_val = e1000_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
1853daf9197cSJack F Vogel 						     100000, &link);
18548cfa0ad2SJack F Vogel 		if (ret_val)
1855ab5d0362SJack F Vogel 			return ret_val;
18568cfa0ad2SJack F Vogel 
18578cfa0ad2SJack F Vogel 		if (!link) {
1858ab5d0362SJack F Vogel 			bool reset_dsp = TRUE;
1859ab5d0362SJack F Vogel 
1860ab5d0362SJack F Vogel 			switch (hw->phy.id) {
1861ab5d0362SJack F Vogel 			case I347AT4_E_PHY_ID:
1862ab5d0362SJack F Vogel 			case M88E1340M_E_PHY_ID:
1863ab5d0362SJack F Vogel 			case M88E1112_E_PHY_ID:
18647609433eSJack F Vogel 			case M88E1543_E_PHY_ID:
18657609433eSJack F Vogel 			case M88E1512_E_PHY_ID:
1866ab5d0362SJack F Vogel 			case I210_I_PHY_ID:
1867ab5d0362SJack F Vogel 				reset_dsp = FALSE;
1868ab5d0362SJack F Vogel 				break;
1869ab5d0362SJack F Vogel 			default:
1870ab5d0362SJack F Vogel 				if (hw->phy.type != e1000_phy_m88)
1871ab5d0362SJack F Vogel 					reset_dsp = FALSE;
1872ab5d0362SJack F Vogel 				break;
1873ab5d0362SJack F Vogel 			}
1874ab5d0362SJack F Vogel 
1875ab5d0362SJack F Vogel 			if (!reset_dsp) {
18764edd8523SJack F Vogel 				DEBUGOUT("Link taking longer than expected.\n");
18774edd8523SJack F Vogel 			} else {
18786ab6bfe3SJack F Vogel 				/* We didn't get link.
18798cfa0ad2SJack F Vogel 				 * Reset the DSP and cross our fingers.
18808cfa0ad2SJack F Vogel 				 */
18818cfa0ad2SJack F Vogel 				ret_val = phy->ops.write_reg(hw,
18828cfa0ad2SJack F Vogel 						M88E1000_PHY_PAGE_SELECT,
18838cfa0ad2SJack F Vogel 						0x001d);
18848cfa0ad2SJack F Vogel 				if (ret_val)
1885ab5d0362SJack F Vogel 					return ret_val;
18868cfa0ad2SJack F Vogel 				ret_val = e1000_phy_reset_dsp_generic(hw);
18878cfa0ad2SJack F Vogel 				if (ret_val)
1888ab5d0362SJack F Vogel 					return ret_val;
18898cfa0ad2SJack F Vogel 			}
18904edd8523SJack F Vogel 		}
18918cfa0ad2SJack F Vogel 
18928cfa0ad2SJack F Vogel 		/* Try once more */
1893daf9197cSJack F Vogel 		ret_val = e1000_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
1894daf9197cSJack F Vogel 						     100000, &link);
18958cfa0ad2SJack F Vogel 		if (ret_val)
1896ab5d0362SJack F Vogel 			return ret_val;
18978cfa0ad2SJack F Vogel 	}
18988cfa0ad2SJack F Vogel 
1899ab5d0362SJack F Vogel 	if (hw->phy.type != e1000_phy_m88)
1900ab5d0362SJack F Vogel 		return E1000_SUCCESS;
1901ab5d0362SJack F Vogel 
1902ab5d0362SJack F Vogel 	if (hw->phy.id == I347AT4_E_PHY_ID ||
19031fd3c44fSJack F Vogel 		hw->phy.id == M88E1340M_E_PHY_ID ||
1904f0ecc46dSJack F Vogel 		hw->phy.id == M88E1112_E_PHY_ID)
1905ab5d0362SJack F Vogel 		return E1000_SUCCESS;
1906ab5d0362SJack F Vogel 	if (hw->phy.id == I210_I_PHY_ID)
1907ab5d0362SJack F Vogel 		return E1000_SUCCESS;
19087609433eSJack F Vogel 	if ((hw->phy.id == M88E1543_E_PHY_ID) ||
19097609433eSJack F Vogel 	    (hw->phy.id == M88E1512_E_PHY_ID))
19107609433eSJack F Vogel 		return E1000_SUCCESS;
19118cfa0ad2SJack F Vogel 	ret_val = phy->ops.read_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
19128cfa0ad2SJack F Vogel 	if (ret_val)
1913ab5d0362SJack F Vogel 		return ret_val;
19148cfa0ad2SJack F Vogel 
19156ab6bfe3SJack F Vogel 	/* Resetting the phy means we need to re-force TX_CLK in the
19168cfa0ad2SJack F Vogel 	 * Extended PHY Specific Control Register to 25MHz clock from
19178cfa0ad2SJack F Vogel 	 * the reset value of 2.5MHz.
19188cfa0ad2SJack F Vogel 	 */
19198cfa0ad2SJack F Vogel 	phy_data |= M88E1000_EPSCR_TX_CLK_25;
19208cfa0ad2SJack F Vogel 	ret_val = phy->ops.write_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
19218cfa0ad2SJack F Vogel 	if (ret_val)
1922ab5d0362SJack F Vogel 		return ret_val;
19238cfa0ad2SJack F Vogel 
19246ab6bfe3SJack F Vogel 	/* In addition, we must re-enable CRS on Tx for both half and full
19258cfa0ad2SJack F Vogel 	 * duplex.
19268cfa0ad2SJack F Vogel 	 */
19278cfa0ad2SJack F Vogel 	ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
19288cfa0ad2SJack F Vogel 	if (ret_val)
1929ab5d0362SJack F Vogel 		return ret_val;
19308cfa0ad2SJack F Vogel 
19318cfa0ad2SJack F Vogel 	phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
19328cfa0ad2SJack F Vogel 	ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
19338cfa0ad2SJack F Vogel 
19348cfa0ad2SJack F Vogel 	return ret_val;
19358cfa0ad2SJack F Vogel }
19368cfa0ad2SJack F Vogel 
19378cfa0ad2SJack F Vogel /**
19389d81738fSJack F Vogel  *  e1000_phy_force_speed_duplex_ife - Force PHY speed & duplex
19399d81738fSJack F Vogel  *  @hw: pointer to the HW structure
19409d81738fSJack F Vogel  *
19419d81738fSJack F Vogel  *  Forces the speed and duplex settings of the PHY.
19429d81738fSJack F Vogel  *  This is a function pointer entry point only called by
19439d81738fSJack F Vogel  *  PHY setup routines.
19449d81738fSJack F Vogel  **/
19459d81738fSJack F Vogel s32 e1000_phy_force_speed_duplex_ife(struct e1000_hw *hw)
19469d81738fSJack F Vogel {
19479d81738fSJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
19489d81738fSJack F Vogel 	s32 ret_val;
19499d81738fSJack F Vogel 	u16 data;
19509d81738fSJack F Vogel 	bool link;
19519d81738fSJack F Vogel 
19529d81738fSJack F Vogel 	DEBUGFUNC("e1000_phy_force_speed_duplex_ife");
19539d81738fSJack F Vogel 
19549d81738fSJack F Vogel 	ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &data);
19559d81738fSJack F Vogel 	if (ret_val)
1956ab5d0362SJack F Vogel 		return ret_val;
19579d81738fSJack F Vogel 
19589d81738fSJack F Vogel 	e1000_phy_force_speed_duplex_setup(hw, &data);
19599d81738fSJack F Vogel 
19609d81738fSJack F Vogel 	ret_val = phy->ops.write_reg(hw, PHY_CONTROL, data);
19619d81738fSJack F Vogel 	if (ret_val)
1962ab5d0362SJack F Vogel 		return ret_val;
19639d81738fSJack F Vogel 
19649d81738fSJack F Vogel 	/* Disable MDI-X support for 10/100 */
19659d81738fSJack F Vogel 	ret_val = phy->ops.read_reg(hw, IFE_PHY_MDIX_CONTROL, &data);
19669d81738fSJack F Vogel 	if (ret_val)
1967ab5d0362SJack F Vogel 		return ret_val;
19689d81738fSJack F Vogel 
19699d81738fSJack F Vogel 	data &= ~IFE_PMC_AUTO_MDIX;
19709d81738fSJack F Vogel 	data &= ~IFE_PMC_FORCE_MDIX;
19719d81738fSJack F Vogel 
19729d81738fSJack F Vogel 	ret_val = phy->ops.write_reg(hw, IFE_PHY_MDIX_CONTROL, data);
19739d81738fSJack F Vogel 	if (ret_val)
1974ab5d0362SJack F Vogel 		return ret_val;
19759d81738fSJack F Vogel 
19769d81738fSJack F Vogel 	DEBUGOUT1("IFE PMC: %X\n", data);
19779d81738fSJack F Vogel 
19789d81738fSJack F Vogel 	usec_delay(1);
19799d81738fSJack F Vogel 
19809d81738fSJack F Vogel 	if (phy->autoneg_wait_to_complete) {
19819d81738fSJack F Vogel 		DEBUGOUT("Waiting for forced speed/duplex link on IFE phy.\n");
19829d81738fSJack F Vogel 
19834dab5c37SJack F Vogel 		ret_val = e1000_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
19844dab5c37SJack F Vogel 						     100000, &link);
19859d81738fSJack F Vogel 		if (ret_val)
1986ab5d0362SJack F Vogel 			return ret_val;
19879d81738fSJack F Vogel 
19889d81738fSJack F Vogel 		if (!link)
19899d81738fSJack F Vogel 			DEBUGOUT("Link taking longer than expected.\n");
19909d81738fSJack F Vogel 
19919d81738fSJack F Vogel 		/* Try once more */
19924dab5c37SJack F Vogel 		ret_val = e1000_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
19934dab5c37SJack F Vogel 						     100000, &link);
19949d81738fSJack F Vogel 		if (ret_val)
1995ab5d0362SJack F Vogel 			return ret_val;
19969d81738fSJack F Vogel 	}
19979d81738fSJack F Vogel 
1998ab5d0362SJack F Vogel 	return E1000_SUCCESS;
19999d81738fSJack F Vogel }
20009d81738fSJack F Vogel 
20019d81738fSJack F Vogel /**
20028cfa0ad2SJack F Vogel  *  e1000_phy_force_speed_duplex_setup - Configure forced PHY speed/duplex
20038cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
20048cfa0ad2SJack F Vogel  *  @phy_ctrl: pointer to current value of PHY_CONTROL
20058cfa0ad2SJack F Vogel  *
20068cfa0ad2SJack F Vogel  *  Forces speed and duplex on the PHY by doing the following: disable flow
20078cfa0ad2SJack F Vogel  *  control, force speed/duplex on the MAC, disable auto speed detection,
20088cfa0ad2SJack F Vogel  *  disable auto-negotiation, configure duplex, configure speed, configure
20098cfa0ad2SJack F Vogel  *  the collision distance, write configuration to CTRL register.  The
20108cfa0ad2SJack F Vogel  *  caller must write to the PHY_CONTROL register for these settings to
20118cfa0ad2SJack F Vogel  *  take affect.
20128cfa0ad2SJack F Vogel  **/
20138cfa0ad2SJack F Vogel void e1000_phy_force_speed_duplex_setup(struct e1000_hw *hw, u16 *phy_ctrl)
20148cfa0ad2SJack F Vogel {
20158cfa0ad2SJack F Vogel 	struct e1000_mac_info *mac = &hw->mac;
20168cfa0ad2SJack F Vogel 	u32 ctrl;
20178cfa0ad2SJack F Vogel 
20188cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_phy_force_speed_duplex_setup");
20198cfa0ad2SJack F Vogel 
20208cfa0ad2SJack F Vogel 	/* Turn off flow control when forcing speed/duplex */
2021daf9197cSJack F Vogel 	hw->fc.current_mode = e1000_fc_none;
20228cfa0ad2SJack F Vogel 
20238cfa0ad2SJack F Vogel 	/* Force speed/duplex on the mac */
20248cfa0ad2SJack F Vogel 	ctrl = E1000_READ_REG(hw, E1000_CTRL);
20258cfa0ad2SJack F Vogel 	ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
20268cfa0ad2SJack F Vogel 	ctrl &= ~E1000_CTRL_SPD_SEL;
20278cfa0ad2SJack F Vogel 
20288cfa0ad2SJack F Vogel 	/* Disable Auto Speed Detection */
20298cfa0ad2SJack F Vogel 	ctrl &= ~E1000_CTRL_ASDE;
20308cfa0ad2SJack F Vogel 
20318cfa0ad2SJack F Vogel 	/* Disable autoneg on the phy */
20328cfa0ad2SJack F Vogel 	*phy_ctrl &= ~MII_CR_AUTO_NEG_EN;
20338cfa0ad2SJack F Vogel 
20348cfa0ad2SJack F Vogel 	/* Forcing Full or Half Duplex? */
20358cfa0ad2SJack F Vogel 	if (mac->forced_speed_duplex & E1000_ALL_HALF_DUPLEX) {
20368cfa0ad2SJack F Vogel 		ctrl &= ~E1000_CTRL_FD;
20378cfa0ad2SJack F Vogel 		*phy_ctrl &= ~MII_CR_FULL_DUPLEX;
20388cfa0ad2SJack F Vogel 		DEBUGOUT("Half Duplex\n");
20398cfa0ad2SJack F Vogel 	} else {
20408cfa0ad2SJack F Vogel 		ctrl |= E1000_CTRL_FD;
20418cfa0ad2SJack F Vogel 		*phy_ctrl |= MII_CR_FULL_DUPLEX;
20428cfa0ad2SJack F Vogel 		DEBUGOUT("Full Duplex\n");
20438cfa0ad2SJack F Vogel 	}
20448cfa0ad2SJack F Vogel 
20458cfa0ad2SJack F Vogel 	/* Forcing 10mb or 100mb? */
20468cfa0ad2SJack F Vogel 	if (mac->forced_speed_duplex & E1000_ALL_100_SPEED) {
20478cfa0ad2SJack F Vogel 		ctrl |= E1000_CTRL_SPD_100;
20488cfa0ad2SJack F Vogel 		*phy_ctrl |= MII_CR_SPEED_100;
20496ab6bfe3SJack F Vogel 		*phy_ctrl &= ~MII_CR_SPEED_1000;
20508cfa0ad2SJack F Vogel 		DEBUGOUT("Forcing 100mb\n");
20518cfa0ad2SJack F Vogel 	} else {
20528cfa0ad2SJack F Vogel 		ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
20538cfa0ad2SJack F Vogel 		*phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
20548cfa0ad2SJack F Vogel 		DEBUGOUT("Forcing 10mb\n");
20558cfa0ad2SJack F Vogel 	}
20568cfa0ad2SJack F Vogel 
2057ab5d0362SJack F Vogel 	hw->mac.ops.config_collision_dist(hw);
20588cfa0ad2SJack F Vogel 
20598cfa0ad2SJack F Vogel 	E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
20608cfa0ad2SJack F Vogel }
20618cfa0ad2SJack F Vogel 
20628cfa0ad2SJack F Vogel /**
20638cfa0ad2SJack F Vogel  *  e1000_set_d3_lplu_state_generic - Sets low power link up state for D3
20648cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
20658cfa0ad2SJack F Vogel  *  @active: boolean used to enable/disable lplu
20668cfa0ad2SJack F Vogel  *
20678cfa0ad2SJack F Vogel  *  Success returns 0, Failure returns 1
20688cfa0ad2SJack F Vogel  *
20698cfa0ad2SJack F Vogel  *  The low power link up (lplu) state is set to the power management level D3
20708cfa0ad2SJack F Vogel  *  and SmartSpeed is disabled when active is TRUE, else clear lplu for D3
20718cfa0ad2SJack F Vogel  *  and enable Smartspeed.  LPLU and Smartspeed are mutually exclusive.  LPLU
20728cfa0ad2SJack F Vogel  *  is used during Dx states where the power conservation is most important.
20738cfa0ad2SJack F Vogel  *  During driver activity, SmartSpeed should be enabled so performance is
20748cfa0ad2SJack F Vogel  *  maintained.
20758cfa0ad2SJack F Vogel  **/
20768cfa0ad2SJack F Vogel s32 e1000_set_d3_lplu_state_generic(struct e1000_hw *hw, bool active)
20778cfa0ad2SJack F Vogel {
20788cfa0ad2SJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
2079ab5d0362SJack F Vogel 	s32 ret_val;
20808cfa0ad2SJack F Vogel 	u16 data;
20818cfa0ad2SJack F Vogel 
20828cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_set_d3_lplu_state_generic");
20838cfa0ad2SJack F Vogel 
2084ab5d0362SJack F Vogel 	if (!hw->phy.ops.read_reg)
2085ab5d0362SJack F Vogel 		return E1000_SUCCESS;
20868cfa0ad2SJack F Vogel 
20878cfa0ad2SJack F Vogel 	ret_val = phy->ops.read_reg(hw, IGP02E1000_PHY_POWER_MGMT, &data);
20888cfa0ad2SJack F Vogel 	if (ret_val)
2089ab5d0362SJack F Vogel 		return ret_val;
20908cfa0ad2SJack F Vogel 
20918cfa0ad2SJack F Vogel 	if (!active) {
20928cfa0ad2SJack F Vogel 		data &= ~IGP02E1000_PM_D3_LPLU;
2093daf9197cSJack F Vogel 		ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
20948cfa0ad2SJack F Vogel 					     data);
20958cfa0ad2SJack F Vogel 		if (ret_val)
2096ab5d0362SJack F Vogel 			return ret_val;
20976ab6bfe3SJack F Vogel 		/* LPLU and SmartSpeed are mutually exclusive.  LPLU is used
20988cfa0ad2SJack F Vogel 		 * during Dx states where the power conservation is most
20998cfa0ad2SJack F Vogel 		 * important.  During driver activity we should enable
21008cfa0ad2SJack F Vogel 		 * SmartSpeed, so performance is maintained.
21018cfa0ad2SJack F Vogel 		 */
21028cfa0ad2SJack F Vogel 		if (phy->smart_speed == e1000_smart_speed_on) {
21038cfa0ad2SJack F Vogel 			ret_val = phy->ops.read_reg(hw,
21048cfa0ad2SJack F Vogel 						    IGP01E1000_PHY_PORT_CONFIG,
21058cfa0ad2SJack F Vogel 						    &data);
21068cfa0ad2SJack F Vogel 			if (ret_val)
2107ab5d0362SJack F Vogel 				return ret_val;
21088cfa0ad2SJack F Vogel 
21098cfa0ad2SJack F Vogel 			data |= IGP01E1000_PSCFR_SMART_SPEED;
21108cfa0ad2SJack F Vogel 			ret_val = phy->ops.write_reg(hw,
21118cfa0ad2SJack F Vogel 						     IGP01E1000_PHY_PORT_CONFIG,
21128cfa0ad2SJack F Vogel 						     data);
21138cfa0ad2SJack F Vogel 			if (ret_val)
2114ab5d0362SJack F Vogel 				return ret_val;
21158cfa0ad2SJack F Vogel 		} else if (phy->smart_speed == e1000_smart_speed_off) {
21168cfa0ad2SJack F Vogel 			ret_val = phy->ops.read_reg(hw,
21178cfa0ad2SJack F Vogel 						    IGP01E1000_PHY_PORT_CONFIG,
21188cfa0ad2SJack F Vogel 						    &data);
21198cfa0ad2SJack F Vogel 			if (ret_val)
2120ab5d0362SJack F Vogel 				return ret_val;
21218cfa0ad2SJack F Vogel 
21228cfa0ad2SJack F Vogel 			data &= ~IGP01E1000_PSCFR_SMART_SPEED;
21238cfa0ad2SJack F Vogel 			ret_val = phy->ops.write_reg(hw,
21248cfa0ad2SJack F Vogel 						     IGP01E1000_PHY_PORT_CONFIG,
21258cfa0ad2SJack F Vogel 						     data);
21268cfa0ad2SJack F Vogel 			if (ret_val)
2127ab5d0362SJack F Vogel 				return ret_val;
21288cfa0ad2SJack F Vogel 		}
21298cfa0ad2SJack F Vogel 	} else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
21308cfa0ad2SJack F Vogel 		   (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
21318cfa0ad2SJack F Vogel 		   (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
21328cfa0ad2SJack F Vogel 		data |= IGP02E1000_PM_D3_LPLU;
2133daf9197cSJack F Vogel 		ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
21348cfa0ad2SJack F Vogel 					     data);
21358cfa0ad2SJack F Vogel 		if (ret_val)
2136ab5d0362SJack F Vogel 			return ret_val;
21378cfa0ad2SJack F Vogel 
21388cfa0ad2SJack F Vogel 		/* When LPLU is enabled, we should disable SmartSpeed */
2139daf9197cSJack F Vogel 		ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
21408cfa0ad2SJack F Vogel 					    &data);
21418cfa0ad2SJack F Vogel 		if (ret_val)
2142ab5d0362SJack F Vogel 			return ret_val;
21438cfa0ad2SJack F Vogel 
21448cfa0ad2SJack F Vogel 		data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2145daf9197cSJack F Vogel 		ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
21468cfa0ad2SJack F Vogel 					     data);
21478cfa0ad2SJack F Vogel 	}
21488cfa0ad2SJack F Vogel 
21498cfa0ad2SJack F Vogel 	return ret_val;
21508cfa0ad2SJack F Vogel }
21518cfa0ad2SJack F Vogel 
21528cfa0ad2SJack F Vogel /**
21538cfa0ad2SJack F Vogel  *  e1000_check_downshift_generic - Checks whether a downshift in speed occurred
21548cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
21558cfa0ad2SJack F Vogel  *
21568cfa0ad2SJack F Vogel  *  Success returns 0, Failure returns 1
21578cfa0ad2SJack F Vogel  *
21588cfa0ad2SJack F Vogel  *  A downshift is detected by querying the PHY link health.
21598cfa0ad2SJack F Vogel  **/
21608cfa0ad2SJack F Vogel s32 e1000_check_downshift_generic(struct e1000_hw *hw)
21618cfa0ad2SJack F Vogel {
21628cfa0ad2SJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
21638cfa0ad2SJack F Vogel 	s32 ret_val;
21648cfa0ad2SJack F Vogel 	u16 phy_data, offset, mask;
21658cfa0ad2SJack F Vogel 
21668cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_check_downshift_generic");
21678cfa0ad2SJack F Vogel 
21688cfa0ad2SJack F Vogel 	switch (phy->type) {
2169ab5d0362SJack F Vogel 	case e1000_phy_i210:
21708cfa0ad2SJack F Vogel 	case e1000_phy_m88:
21718cfa0ad2SJack F Vogel 	case e1000_phy_gg82563:
21728cfa0ad2SJack F Vogel 	case e1000_phy_bm:
21739d81738fSJack F Vogel 	case e1000_phy_82578:
21748cfa0ad2SJack F Vogel 		offset = M88E1000_PHY_SPEC_STATUS;
21758cfa0ad2SJack F Vogel 		mask = M88E1000_PSSR_DOWNSHIFT;
21768cfa0ad2SJack F Vogel 		break;
21778cfa0ad2SJack F Vogel 	case e1000_phy_igp:
21784edd8523SJack F Vogel 	case e1000_phy_igp_2:
21798cfa0ad2SJack F Vogel 	case e1000_phy_igp_3:
21808cfa0ad2SJack F Vogel 		offset = IGP01E1000_PHY_LINK_HEALTH;
21818cfa0ad2SJack F Vogel 		mask = IGP01E1000_PLHR_SS_DOWNGRADE;
21828cfa0ad2SJack F Vogel 		break;
21838cfa0ad2SJack F Vogel 	default:
21848cfa0ad2SJack F Vogel 		/* speed downshift not supported */
21858cfa0ad2SJack F Vogel 		phy->speed_downgraded = FALSE;
2186ab5d0362SJack F Vogel 		return E1000_SUCCESS;
21878cfa0ad2SJack F Vogel 	}
21888cfa0ad2SJack F Vogel 
21898cfa0ad2SJack F Vogel 	ret_val = phy->ops.read_reg(hw, offset, &phy_data);
21908cfa0ad2SJack F Vogel 
21918cfa0ad2SJack F Vogel 	if (!ret_val)
2192ab5d0362SJack F Vogel 		phy->speed_downgraded = !!(phy_data & mask);
21938cfa0ad2SJack F Vogel 
21948cfa0ad2SJack F Vogel 	return ret_val;
21958cfa0ad2SJack F Vogel }
21968cfa0ad2SJack F Vogel 
21978cfa0ad2SJack F Vogel /**
21988cfa0ad2SJack F Vogel  *  e1000_check_polarity_m88 - Checks the polarity.
21998cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
22008cfa0ad2SJack F Vogel  *
22018cfa0ad2SJack F Vogel  *  Success returns 0, Failure returns -E1000_ERR_PHY (-2)
22028cfa0ad2SJack F Vogel  *
22038cfa0ad2SJack F Vogel  *  Polarity is determined based on the PHY specific status register.
22048cfa0ad2SJack F Vogel  **/
22058cfa0ad2SJack F Vogel s32 e1000_check_polarity_m88(struct e1000_hw *hw)
22068cfa0ad2SJack F Vogel {
22078cfa0ad2SJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
22088cfa0ad2SJack F Vogel 	s32 ret_val;
22098cfa0ad2SJack F Vogel 	u16 data;
22108cfa0ad2SJack F Vogel 
22118cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_check_polarity_m88");
22128cfa0ad2SJack F Vogel 
22138cfa0ad2SJack F Vogel 	ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &data);
22148cfa0ad2SJack F Vogel 
22158cfa0ad2SJack F Vogel 	if (!ret_val)
22167609433eSJack F Vogel 		phy->cable_polarity = ((data & M88E1000_PSSR_REV_POLARITY)
22178cfa0ad2SJack F Vogel 				       ? e1000_rev_polarity_reversed
22187609433eSJack F Vogel 				       : e1000_rev_polarity_normal);
22198cfa0ad2SJack F Vogel 
22208cfa0ad2SJack F Vogel 	return ret_val;
22218cfa0ad2SJack F Vogel }
22228cfa0ad2SJack F Vogel 
22238cfa0ad2SJack F Vogel /**
22248cfa0ad2SJack F Vogel  *  e1000_check_polarity_igp - Checks the polarity.
22258cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
22268cfa0ad2SJack F Vogel  *
22278cfa0ad2SJack F Vogel  *  Success returns 0, Failure returns -E1000_ERR_PHY (-2)
22288cfa0ad2SJack F Vogel  *
22298cfa0ad2SJack F Vogel  *  Polarity is determined based on the PHY port status register, and the
22308cfa0ad2SJack F Vogel  *  current speed (since there is no polarity at 100Mbps).
22318cfa0ad2SJack F Vogel  **/
22328cfa0ad2SJack F Vogel s32 e1000_check_polarity_igp(struct e1000_hw *hw)
22338cfa0ad2SJack F Vogel {
22348cfa0ad2SJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
22358cfa0ad2SJack F Vogel 	s32 ret_val;
22368cfa0ad2SJack F Vogel 	u16 data, offset, mask;
22378cfa0ad2SJack F Vogel 
22388cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_check_polarity_igp");
22398cfa0ad2SJack F Vogel 
22406ab6bfe3SJack F Vogel 	/* Polarity is determined based on the speed of
22418cfa0ad2SJack F Vogel 	 * our connection.
22428cfa0ad2SJack F Vogel 	 */
22438cfa0ad2SJack F Vogel 	ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_STATUS, &data);
22448cfa0ad2SJack F Vogel 	if (ret_val)
2245ab5d0362SJack F Vogel 		return ret_val;
22468cfa0ad2SJack F Vogel 
22478cfa0ad2SJack F Vogel 	if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
22488cfa0ad2SJack F Vogel 	    IGP01E1000_PSSR_SPEED_1000MBPS) {
22498cfa0ad2SJack F Vogel 		offset = IGP01E1000_PHY_PCS_INIT_REG;
22508cfa0ad2SJack F Vogel 		mask = IGP01E1000_PHY_POLARITY_MASK;
22518cfa0ad2SJack F Vogel 	} else {
22526ab6bfe3SJack F Vogel 		/* This really only applies to 10Mbps since
22538cfa0ad2SJack F Vogel 		 * there is no polarity for 100Mbps (always 0).
22548cfa0ad2SJack F Vogel 		 */
22558cfa0ad2SJack F Vogel 		offset = IGP01E1000_PHY_PORT_STATUS;
22568cfa0ad2SJack F Vogel 		mask = IGP01E1000_PSSR_POLARITY_REVERSED;
22578cfa0ad2SJack F Vogel 	}
22588cfa0ad2SJack F Vogel 
22598cfa0ad2SJack F Vogel 	ret_val = phy->ops.read_reg(hw, offset, &data);
22608cfa0ad2SJack F Vogel 
22618cfa0ad2SJack F Vogel 	if (!ret_val)
22627609433eSJack F Vogel 		phy->cable_polarity = ((data & mask)
22638cfa0ad2SJack F Vogel 				       ? e1000_rev_polarity_reversed
22647609433eSJack F Vogel 				       : e1000_rev_polarity_normal);
22658cfa0ad2SJack F Vogel 
22668cfa0ad2SJack F Vogel 	return ret_val;
22678cfa0ad2SJack F Vogel }
22688cfa0ad2SJack F Vogel 
22698cfa0ad2SJack F Vogel /**
22709d81738fSJack F Vogel  *  e1000_check_polarity_ife - Check cable polarity for IFE PHY
22719d81738fSJack F Vogel  *  @hw: pointer to the HW structure
22729d81738fSJack F Vogel  *
22739d81738fSJack F Vogel  *  Polarity is determined on the polarity reversal feature being enabled.
22749d81738fSJack F Vogel  **/
22759d81738fSJack F Vogel s32 e1000_check_polarity_ife(struct e1000_hw *hw)
22769d81738fSJack F Vogel {
22779d81738fSJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
22789d81738fSJack F Vogel 	s32 ret_val;
22799d81738fSJack F Vogel 	u16 phy_data, offset, mask;
22809d81738fSJack F Vogel 
22819d81738fSJack F Vogel 	DEBUGFUNC("e1000_check_polarity_ife");
22829d81738fSJack F Vogel 
22836ab6bfe3SJack F Vogel 	/* Polarity is determined based on the reversal feature being enabled.
22849d81738fSJack F Vogel 	 */
22859d81738fSJack F Vogel 	if (phy->polarity_correction) {
22869d81738fSJack F Vogel 		offset = IFE_PHY_EXTENDED_STATUS_CONTROL;
22879d81738fSJack F Vogel 		mask = IFE_PESC_POLARITY_REVERSED;
22889d81738fSJack F Vogel 	} else {
22899d81738fSJack F Vogel 		offset = IFE_PHY_SPECIAL_CONTROL;
22909d81738fSJack F Vogel 		mask = IFE_PSC_FORCE_POLARITY;
22919d81738fSJack F Vogel 	}
22929d81738fSJack F Vogel 
22939d81738fSJack F Vogel 	ret_val = phy->ops.read_reg(hw, offset, &phy_data);
22949d81738fSJack F Vogel 
22959d81738fSJack F Vogel 	if (!ret_val)
22967609433eSJack F Vogel 		phy->cable_polarity = ((phy_data & mask)
22979d81738fSJack F Vogel 				       ? e1000_rev_polarity_reversed
22987609433eSJack F Vogel 				       : e1000_rev_polarity_normal);
22999d81738fSJack F Vogel 
23009d81738fSJack F Vogel 	return ret_val;
23019d81738fSJack F Vogel }
23029d81738fSJack F Vogel 
23039d81738fSJack F Vogel /**
23046ab6bfe3SJack F Vogel  *  e1000_wait_autoneg - Wait for auto-neg completion
23058cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
23068cfa0ad2SJack F Vogel  *
23078cfa0ad2SJack F Vogel  *  Waits for auto-negotiation to complete or for the auto-negotiation time
23088cfa0ad2SJack F Vogel  *  limit to expire, which ever happens first.
23098cfa0ad2SJack F Vogel  **/
23106ab6bfe3SJack F Vogel static s32 e1000_wait_autoneg(struct e1000_hw *hw)
23118cfa0ad2SJack F Vogel {
23128cfa0ad2SJack F Vogel 	s32 ret_val = E1000_SUCCESS;
23138cfa0ad2SJack F Vogel 	u16 i, phy_status;
23148cfa0ad2SJack F Vogel 
23156ab6bfe3SJack F Vogel 	DEBUGFUNC("e1000_wait_autoneg");
23168cfa0ad2SJack F Vogel 
2317ab5d0362SJack F Vogel 	if (!hw->phy.ops.read_reg)
23188cfa0ad2SJack F Vogel 		return E1000_SUCCESS;
23198cfa0ad2SJack F Vogel 
23208cfa0ad2SJack F Vogel 	/* Break after autoneg completes or PHY_AUTO_NEG_LIMIT expires. */
23218cfa0ad2SJack F Vogel 	for (i = PHY_AUTO_NEG_LIMIT; i > 0; i--) {
23228cfa0ad2SJack F Vogel 		ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
23238cfa0ad2SJack F Vogel 		if (ret_val)
23248cfa0ad2SJack F Vogel 			break;
23258cfa0ad2SJack F Vogel 		ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
23268cfa0ad2SJack F Vogel 		if (ret_val)
23278cfa0ad2SJack F Vogel 			break;
23288cfa0ad2SJack F Vogel 		if (phy_status & MII_SR_AUTONEG_COMPLETE)
23298cfa0ad2SJack F Vogel 			break;
23308cfa0ad2SJack F Vogel 		msec_delay(100);
23318cfa0ad2SJack F Vogel 	}
23328cfa0ad2SJack F Vogel 
23336ab6bfe3SJack F Vogel 	/* PHY_AUTO_NEG_TIME expiration doesn't guarantee auto-negotiation
23348cfa0ad2SJack F Vogel 	 * has completed.
23358cfa0ad2SJack F Vogel 	 */
23368cfa0ad2SJack F Vogel 	return ret_val;
23378cfa0ad2SJack F Vogel }
23388cfa0ad2SJack F Vogel 
23398cfa0ad2SJack F Vogel /**
23408cfa0ad2SJack F Vogel  *  e1000_phy_has_link_generic - Polls PHY for link
23418cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
23428cfa0ad2SJack F Vogel  *  @iterations: number of times to poll for link
23438cfa0ad2SJack F Vogel  *  @usec_interval: delay between polling attempts
23448cfa0ad2SJack F Vogel  *  @success: pointer to whether polling was successful or not
23458cfa0ad2SJack F Vogel  *
23468cfa0ad2SJack F Vogel  *  Polls the PHY status register for link, 'iterations' number of times.
23478cfa0ad2SJack F Vogel  **/
23488cfa0ad2SJack F Vogel s32 e1000_phy_has_link_generic(struct e1000_hw *hw, u32 iterations,
23498cfa0ad2SJack F Vogel 			       u32 usec_interval, bool *success)
23508cfa0ad2SJack F Vogel {
23518cfa0ad2SJack F Vogel 	s32 ret_val = E1000_SUCCESS;
23528cfa0ad2SJack F Vogel 	u16 i, phy_status;
23538cfa0ad2SJack F Vogel 
23548cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_phy_has_link_generic");
23558cfa0ad2SJack F Vogel 
2356ab5d0362SJack F Vogel 	if (!hw->phy.ops.read_reg)
23578cfa0ad2SJack F Vogel 		return E1000_SUCCESS;
23588cfa0ad2SJack F Vogel 
23598cfa0ad2SJack F Vogel 	for (i = 0; i < iterations; i++) {
23606ab6bfe3SJack F Vogel 		/* Some PHYs require the PHY_STATUS register to be read
23618cfa0ad2SJack F Vogel 		 * twice due to the link bit being sticky.  No harm doing
23628cfa0ad2SJack F Vogel 		 * it across the board.
23638cfa0ad2SJack F Vogel 		 */
23648cfa0ad2SJack F Vogel 		ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
23658cc64f1eSJack F Vogel 		if (ret_val) {
23666ab6bfe3SJack F Vogel 			/* If the first read fails, another entity may have
23679d81738fSJack F Vogel 			 * ownership of the resources, wait and try again to
23689d81738fSJack F Vogel 			 * see if they have relinquished the resources yet.
23699d81738fSJack F Vogel 			 */
23708cc64f1eSJack F Vogel 			if (usec_interval >= 1000)
23718cc64f1eSJack F Vogel 				msec_delay(usec_interval/1000);
23728cc64f1eSJack F Vogel 			else
23739d81738fSJack F Vogel 				usec_delay(usec_interval);
23748cc64f1eSJack F Vogel 		}
23754edd8523SJack F Vogel 		ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
23768cfa0ad2SJack F Vogel 		if (ret_val)
23778cfa0ad2SJack F Vogel 			break;
23788cfa0ad2SJack F Vogel 		if (phy_status & MII_SR_LINK_STATUS)
23798cfa0ad2SJack F Vogel 			break;
23808cfa0ad2SJack F Vogel 		if (usec_interval >= 1000)
23818cc64f1eSJack F Vogel 			msec_delay(usec_interval/1000);
23828cfa0ad2SJack F Vogel 		else
23838cfa0ad2SJack F Vogel 			usec_delay(usec_interval);
23848cfa0ad2SJack F Vogel 	}
23858cfa0ad2SJack F Vogel 
2386ab5d0362SJack F Vogel 	*success = (i < iterations);
23878cfa0ad2SJack F Vogel 
23888cfa0ad2SJack F Vogel 	return ret_val;
23898cfa0ad2SJack F Vogel }
23908cfa0ad2SJack F Vogel 
23918cfa0ad2SJack F Vogel /**
23928cfa0ad2SJack F Vogel  *  e1000_get_cable_length_m88 - Determine cable length for m88 PHY
23938cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
23948cfa0ad2SJack F Vogel  *
23958cfa0ad2SJack F Vogel  *  Reads the PHY specific status register to retrieve the cable length
23968cfa0ad2SJack F Vogel  *  information.  The cable length is determined by averaging the minimum and
23978cfa0ad2SJack F Vogel  *  maximum values to get the "average" cable length.  The m88 PHY has four
23988cfa0ad2SJack F Vogel  *  possible cable length values, which are:
23998cfa0ad2SJack F Vogel  *	Register Value		Cable Length
24008cfa0ad2SJack F Vogel  *	0			< 50 meters
24018cfa0ad2SJack F Vogel  *	1			50 - 80 meters
24028cfa0ad2SJack F Vogel  *	2			80 - 110 meters
24038cfa0ad2SJack F Vogel  *	3			110 - 140 meters
24048cfa0ad2SJack F Vogel  *	4			> 140 meters
24058cfa0ad2SJack F Vogel  **/
24068cfa0ad2SJack F Vogel s32 e1000_get_cable_length_m88(struct e1000_hw *hw)
24078cfa0ad2SJack F Vogel {
24088cfa0ad2SJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
24098cfa0ad2SJack F Vogel 	s32 ret_val;
24108cfa0ad2SJack F Vogel 	u16 phy_data, index;
24118cfa0ad2SJack F Vogel 
24128cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_get_cable_length_m88");
24138cfa0ad2SJack F Vogel 
24148cfa0ad2SJack F Vogel 	ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
24158cfa0ad2SJack F Vogel 	if (ret_val)
2416ab5d0362SJack F Vogel 		return ret_val;
24178cfa0ad2SJack F Vogel 
24187609433eSJack F Vogel 	index = ((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
24197609433eSJack F Vogel 		 M88E1000_PSSR_CABLE_LENGTH_SHIFT);
2420ab5d0362SJack F Vogel 
2421ab5d0362SJack F Vogel 	if (index >= M88E1000_CABLE_LENGTH_TABLE_SIZE - 1)
2422ab5d0362SJack F Vogel 		return -E1000_ERR_PHY;
2423d035aa2dSJack F Vogel 
24248cfa0ad2SJack F Vogel 	phy->min_cable_length = e1000_m88_cable_length_table[index];
24258cfa0ad2SJack F Vogel 	phy->max_cable_length = e1000_m88_cable_length_table[index + 1];
24268cfa0ad2SJack F Vogel 
2427d035aa2dSJack F Vogel 	phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
24288cfa0ad2SJack F Vogel 
2429ab5d0362SJack F Vogel 	return E1000_SUCCESS;
24308cfa0ad2SJack F Vogel }
24318cfa0ad2SJack F Vogel 
2432f0ecc46dSJack F Vogel s32 e1000_get_cable_length_m88_gen2(struct e1000_hw *hw)
2433f0ecc46dSJack F Vogel {
2434f0ecc46dSJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
2435f0ecc46dSJack F Vogel 	s32 ret_val;
24366ab6bfe3SJack F Vogel 	u16 phy_data, phy_data2, is_cm;
24376ab6bfe3SJack F Vogel 	u16 index, default_page;
2438f0ecc46dSJack F Vogel 
2439f0ecc46dSJack F Vogel 	DEBUGFUNC("e1000_get_cable_length_m88_gen2");
2440f0ecc46dSJack F Vogel 
2441f0ecc46dSJack F Vogel 	switch (hw->phy.id) {
2442ab5d0362SJack F Vogel 	case I210_I_PHY_ID:
2443ab5d0362SJack F Vogel 		/* Get cable length from PHY Cable Diagnostics Control Reg */
2444ab5d0362SJack F Vogel 		ret_val = phy->ops.read_reg(hw, (0x7 << GS40G_PAGE_SHIFT) +
2445ab5d0362SJack F Vogel 					    (I347AT4_PCDL + phy->addr),
2446ab5d0362SJack F Vogel 					    &phy_data);
2447ab5d0362SJack F Vogel 		if (ret_val)
2448ab5d0362SJack F Vogel 			return ret_val;
2449ab5d0362SJack F Vogel 
2450ab5d0362SJack F Vogel 		/* Check if the unit of cable length is meters or cm */
2451ab5d0362SJack F Vogel 		ret_val = phy->ops.read_reg(hw, (0x7 << GS40G_PAGE_SHIFT) +
2452ab5d0362SJack F Vogel 					    I347AT4_PCDC, &phy_data2);
2453ab5d0362SJack F Vogel 		if (ret_val)
2454ab5d0362SJack F Vogel 			return ret_val;
2455ab5d0362SJack F Vogel 
2456ab5d0362SJack F Vogel 		is_cm = !(phy_data2 & I347AT4_PCDC_CABLE_LENGTH_UNIT);
2457ab5d0362SJack F Vogel 
2458ab5d0362SJack F Vogel 		/* Populate the phy structure with cable length in meters */
2459ab5d0362SJack F Vogel 		phy->min_cable_length = phy_data / (is_cm ? 100 : 1);
2460ab5d0362SJack F Vogel 		phy->max_cable_length = phy_data / (is_cm ? 100 : 1);
2461ab5d0362SJack F Vogel 		phy->cable_length = phy_data / (is_cm ? 100 : 1);
2462ab5d0362SJack F Vogel 		break;
24637609433eSJack F Vogel 	case M88E1543_E_PHY_ID:
24647609433eSJack F Vogel 	case M88E1512_E_PHY_ID:
24651fd3c44fSJack F Vogel 	case M88E1340M_E_PHY_ID:
2466f0ecc46dSJack F Vogel 	case I347AT4_E_PHY_ID:
2467f0ecc46dSJack F Vogel 		/* Remember the original page select and set it to 7 */
2468f0ecc46dSJack F Vogel 		ret_val = phy->ops.read_reg(hw, I347AT4_PAGE_SELECT,
2469f0ecc46dSJack F Vogel 					    &default_page);
2470f0ecc46dSJack F Vogel 		if (ret_val)
2471ab5d0362SJack F Vogel 			return ret_val;
2472f0ecc46dSJack F Vogel 
2473f0ecc46dSJack F Vogel 		ret_val = phy->ops.write_reg(hw, I347AT4_PAGE_SELECT, 0x07);
2474f0ecc46dSJack F Vogel 		if (ret_val)
2475ab5d0362SJack F Vogel 			return ret_val;
2476f0ecc46dSJack F Vogel 
2477f0ecc46dSJack F Vogel 		/* Get cable length from PHY Cable Diagnostics Control Reg */
2478f0ecc46dSJack F Vogel 		ret_val = phy->ops.read_reg(hw, (I347AT4_PCDL + phy->addr),
2479f0ecc46dSJack F Vogel 					    &phy_data);
2480f0ecc46dSJack F Vogel 		if (ret_val)
2481ab5d0362SJack F Vogel 			return ret_val;
2482f0ecc46dSJack F Vogel 
2483f0ecc46dSJack F Vogel 		/* Check if the unit of cable length is meters or cm */
2484f0ecc46dSJack F Vogel 		ret_val = phy->ops.read_reg(hw, I347AT4_PCDC, &phy_data2);
2485f0ecc46dSJack F Vogel 		if (ret_val)
2486ab5d0362SJack F Vogel 			return ret_val;
2487f0ecc46dSJack F Vogel 
24884dab5c37SJack F Vogel 		is_cm = !(phy_data2 & I347AT4_PCDC_CABLE_LENGTH_UNIT);
2489f0ecc46dSJack F Vogel 
2490f0ecc46dSJack F Vogel 		/* Populate the phy structure with cable length in meters */
2491f0ecc46dSJack F Vogel 		phy->min_cable_length = phy_data / (is_cm ? 100 : 1);
2492f0ecc46dSJack F Vogel 		phy->max_cable_length = phy_data / (is_cm ? 100 : 1);
2493f0ecc46dSJack F Vogel 		phy->cable_length = phy_data / (is_cm ? 100 : 1);
2494f0ecc46dSJack F Vogel 
24954dab5c37SJack F Vogel 		/* Reset the page select to its original value */
2496f0ecc46dSJack F Vogel 		ret_val = phy->ops.write_reg(hw, I347AT4_PAGE_SELECT,
2497f0ecc46dSJack F Vogel 					     default_page);
2498f0ecc46dSJack F Vogel 		if (ret_val)
2499ab5d0362SJack F Vogel 			return ret_val;
2500f0ecc46dSJack F Vogel 		break;
2501ab5d0362SJack F Vogel 
2502f0ecc46dSJack F Vogel 	case M88E1112_E_PHY_ID:
2503f0ecc46dSJack F Vogel 		/* Remember the original page select and set it to 5 */
2504f0ecc46dSJack F Vogel 		ret_val = phy->ops.read_reg(hw, I347AT4_PAGE_SELECT,
2505f0ecc46dSJack F Vogel 					    &default_page);
2506f0ecc46dSJack F Vogel 		if (ret_val)
2507ab5d0362SJack F Vogel 			return ret_val;
2508f0ecc46dSJack F Vogel 
2509f0ecc46dSJack F Vogel 		ret_val = phy->ops.write_reg(hw, I347AT4_PAGE_SELECT, 0x05);
2510f0ecc46dSJack F Vogel 		if (ret_val)
2511ab5d0362SJack F Vogel 			return ret_val;
2512f0ecc46dSJack F Vogel 
2513f0ecc46dSJack F Vogel 		ret_val = phy->ops.read_reg(hw, M88E1112_VCT_DSP_DISTANCE,
2514f0ecc46dSJack F Vogel 					    &phy_data);
2515f0ecc46dSJack F Vogel 		if (ret_val)
2516ab5d0362SJack F Vogel 			return ret_val;
2517f0ecc46dSJack F Vogel 
2518f0ecc46dSJack F Vogel 		index = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
2519f0ecc46dSJack F Vogel 			M88E1000_PSSR_CABLE_LENGTH_SHIFT;
2520ab5d0362SJack F Vogel 
2521ab5d0362SJack F Vogel 		if (index >= M88E1000_CABLE_LENGTH_TABLE_SIZE - 1)
2522ab5d0362SJack F Vogel 			return -E1000_ERR_PHY;
2523f0ecc46dSJack F Vogel 
2524f0ecc46dSJack F Vogel 		phy->min_cable_length = e1000_m88_cable_length_table[index];
2525f0ecc46dSJack F Vogel 		phy->max_cable_length = e1000_m88_cable_length_table[index + 1];
2526f0ecc46dSJack F Vogel 
2527f0ecc46dSJack F Vogel 		phy->cable_length = (phy->min_cable_length +
2528f0ecc46dSJack F Vogel 				     phy->max_cable_length) / 2;
2529f0ecc46dSJack F Vogel 
2530f0ecc46dSJack F Vogel 		/* Reset the page select to its original value */
2531f0ecc46dSJack F Vogel 		ret_val = phy->ops.write_reg(hw, I347AT4_PAGE_SELECT,
2532f0ecc46dSJack F Vogel 					     default_page);
2533f0ecc46dSJack F Vogel 		if (ret_val)
2534ab5d0362SJack F Vogel 			return ret_val;
2535f0ecc46dSJack F Vogel 
2536f0ecc46dSJack F Vogel 		break;
2537f0ecc46dSJack F Vogel 	default:
2538ab5d0362SJack F Vogel 		return -E1000_ERR_PHY;
2539f0ecc46dSJack F Vogel 	}
2540f0ecc46dSJack F Vogel 
2541f0ecc46dSJack F Vogel 	return ret_val;
2542f0ecc46dSJack F Vogel }
2543f0ecc46dSJack F Vogel 
25448cfa0ad2SJack F Vogel /**
25458cfa0ad2SJack F Vogel  *  e1000_get_cable_length_igp_2 - Determine cable length for igp2 PHY
25468cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
25478cfa0ad2SJack F Vogel  *
25488cfa0ad2SJack F Vogel  *  The automatic gain control (agc) normalizes the amplitude of the
25498cfa0ad2SJack F Vogel  *  received signal, adjusting for the attenuation produced by the
25508cfa0ad2SJack F Vogel  *  cable.  By reading the AGC registers, which represent the
25518cfa0ad2SJack F Vogel  *  combination of coarse and fine gain value, the value can be put
25528cfa0ad2SJack F Vogel  *  into a lookup table to obtain the approximate cable length
25538cfa0ad2SJack F Vogel  *  for each channel.
25548cfa0ad2SJack F Vogel  **/
25558cfa0ad2SJack F Vogel s32 e1000_get_cable_length_igp_2(struct e1000_hw *hw)
25568cfa0ad2SJack F Vogel {
25578cfa0ad2SJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
2558ab5d0362SJack F Vogel 	s32 ret_val;
25598cfa0ad2SJack F Vogel 	u16 phy_data, i, agc_value = 0;
25608cfa0ad2SJack F Vogel 	u16 cur_agc_index, max_agc_index = 0;
25618cfa0ad2SJack F Vogel 	u16 min_agc_index = IGP02E1000_CABLE_LENGTH_TABLE_SIZE - 1;
2562f0ecc46dSJack F Vogel 	static const u16 agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] = {
2563f0ecc46dSJack F Vogel 		IGP02E1000_PHY_AGC_A,
25648cfa0ad2SJack F Vogel 		IGP02E1000_PHY_AGC_B,
25658cfa0ad2SJack F Vogel 		IGP02E1000_PHY_AGC_C,
2566f0ecc46dSJack F Vogel 		IGP02E1000_PHY_AGC_D
2567f0ecc46dSJack F Vogel 	};
25688cfa0ad2SJack F Vogel 
25698cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_get_cable_length_igp_2");
25708cfa0ad2SJack F Vogel 
25718cfa0ad2SJack F Vogel 	/* Read the AGC registers for all channels */
25728cfa0ad2SJack F Vogel 	for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
25738cfa0ad2SJack F Vogel 		ret_val = phy->ops.read_reg(hw, agc_reg_array[i], &phy_data);
25748cfa0ad2SJack F Vogel 		if (ret_val)
2575ab5d0362SJack F Vogel 			return ret_val;
25768cfa0ad2SJack F Vogel 
25776ab6bfe3SJack F Vogel 		/* Getting bits 15:9, which represent the combination of
25788cfa0ad2SJack F Vogel 		 * coarse and fine gain values.  The result is a number
25798cfa0ad2SJack F Vogel 		 * that can be put into the lookup table to obtain the
25808cfa0ad2SJack F Vogel 		 * approximate cable length.
25818cfa0ad2SJack F Vogel 		 */
25827609433eSJack F Vogel 		cur_agc_index = ((phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
25837609433eSJack F Vogel 				 IGP02E1000_AGC_LENGTH_MASK);
25848cfa0ad2SJack F Vogel 
25858cfa0ad2SJack F Vogel 		/* Array index bound check. */
25868cfa0ad2SJack F Vogel 		if ((cur_agc_index >= IGP02E1000_CABLE_LENGTH_TABLE_SIZE) ||
2587ab5d0362SJack F Vogel 		    (cur_agc_index == 0))
2588ab5d0362SJack F Vogel 			return -E1000_ERR_PHY;
25898cfa0ad2SJack F Vogel 
25908cfa0ad2SJack F Vogel 		/* Remove min & max AGC values from calculation. */
25918cfa0ad2SJack F Vogel 		if (e1000_igp_2_cable_length_table[min_agc_index] >
25928cfa0ad2SJack F Vogel 		    e1000_igp_2_cable_length_table[cur_agc_index])
25938cfa0ad2SJack F Vogel 			min_agc_index = cur_agc_index;
25948cfa0ad2SJack F Vogel 		if (e1000_igp_2_cable_length_table[max_agc_index] <
25958cfa0ad2SJack F Vogel 		    e1000_igp_2_cable_length_table[cur_agc_index])
25968cfa0ad2SJack F Vogel 			max_agc_index = cur_agc_index;
25978cfa0ad2SJack F Vogel 
25988cfa0ad2SJack F Vogel 		agc_value += e1000_igp_2_cable_length_table[cur_agc_index];
25998cfa0ad2SJack F Vogel 	}
26008cfa0ad2SJack F Vogel 
26018cfa0ad2SJack F Vogel 	agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] +
26028cfa0ad2SJack F Vogel 		      e1000_igp_2_cable_length_table[max_agc_index]);
26038cfa0ad2SJack F Vogel 	agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
26048cfa0ad2SJack F Vogel 
26058cfa0ad2SJack F Vogel 	/* Calculate cable length with the error range of +/- 10 meters. */
26067609433eSJack F Vogel 	phy->min_cable_length = (((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
26077609433eSJack F Vogel 				 (agc_value - IGP02E1000_AGC_RANGE) : 0);
26088cfa0ad2SJack F Vogel 	phy->max_cable_length = agc_value + IGP02E1000_AGC_RANGE;
26098cfa0ad2SJack F Vogel 
26108cfa0ad2SJack F Vogel 	phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
26118cfa0ad2SJack F Vogel 
2612ab5d0362SJack F Vogel 	return E1000_SUCCESS;
26138cfa0ad2SJack F Vogel }
26148cfa0ad2SJack F Vogel 
26158cfa0ad2SJack F Vogel /**
26168cfa0ad2SJack F Vogel  *  e1000_get_phy_info_m88 - Retrieve PHY information
26178cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
26188cfa0ad2SJack F Vogel  *
26198cfa0ad2SJack F Vogel  *  Valid for only copper links.  Read the PHY status register (sticky read)
26208cfa0ad2SJack F Vogel  *  to verify that link is up.  Read the PHY special control register to
26218cfa0ad2SJack F Vogel  *  determine the polarity and 10base-T extended distance.  Read the PHY
26228cfa0ad2SJack F Vogel  *  special status register to determine MDI/MDIx and current speed.  If
26238cfa0ad2SJack F Vogel  *  speed is 1000, then determine cable length, local and remote receiver.
26248cfa0ad2SJack F Vogel  **/
26258cfa0ad2SJack F Vogel s32 e1000_get_phy_info_m88(struct e1000_hw *hw)
26268cfa0ad2SJack F Vogel {
26278cfa0ad2SJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
26288cfa0ad2SJack F Vogel 	s32  ret_val;
26298cfa0ad2SJack F Vogel 	u16 phy_data;
26308cfa0ad2SJack F Vogel 	bool link;
26318cfa0ad2SJack F Vogel 
26328cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_get_phy_info_m88");
26338cfa0ad2SJack F Vogel 
26344edd8523SJack F Vogel 	if (phy->media_type != e1000_media_type_copper) {
26358cfa0ad2SJack F Vogel 		DEBUGOUT("Phy info is only valid for copper media\n");
2636ab5d0362SJack F Vogel 		return -E1000_ERR_CONFIG;
26378cfa0ad2SJack F Vogel 	}
26388cfa0ad2SJack F Vogel 
26398cfa0ad2SJack F Vogel 	ret_val = e1000_phy_has_link_generic(hw, 1, 0, &link);
26408cfa0ad2SJack F Vogel 	if (ret_val)
2641ab5d0362SJack F Vogel 		return ret_val;
26428cfa0ad2SJack F Vogel 
26438cfa0ad2SJack F Vogel 	if (!link) {
26448cfa0ad2SJack F Vogel 		DEBUGOUT("Phy info is only valid if link is up\n");
2645ab5d0362SJack F Vogel 		return -E1000_ERR_CONFIG;
26468cfa0ad2SJack F Vogel 	}
26478cfa0ad2SJack F Vogel 
26488cfa0ad2SJack F Vogel 	ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
26498cfa0ad2SJack F Vogel 	if (ret_val)
2650ab5d0362SJack F Vogel 		return ret_val;
26518cfa0ad2SJack F Vogel 
2652ab5d0362SJack F Vogel 	phy->polarity_correction = !!(phy_data &
2653ab5d0362SJack F Vogel 				      M88E1000_PSCR_POLARITY_REVERSAL);
26548cfa0ad2SJack F Vogel 
26558cfa0ad2SJack F Vogel 	ret_val = e1000_check_polarity_m88(hw);
26568cfa0ad2SJack F Vogel 	if (ret_val)
2657ab5d0362SJack F Vogel 		return ret_val;
26588cfa0ad2SJack F Vogel 
26598cfa0ad2SJack F Vogel 	ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
26608cfa0ad2SJack F Vogel 	if (ret_val)
2661ab5d0362SJack F Vogel 		return ret_val;
26628cfa0ad2SJack F Vogel 
2663ab5d0362SJack F Vogel 	phy->is_mdix = !!(phy_data & M88E1000_PSSR_MDIX);
26648cfa0ad2SJack F Vogel 
26658cfa0ad2SJack F Vogel 	if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
26668cfa0ad2SJack F Vogel 		ret_val = hw->phy.ops.get_cable_length(hw);
26678cfa0ad2SJack F Vogel 		if (ret_val)
2668ab5d0362SJack F Vogel 			return ret_val;
26698cfa0ad2SJack F Vogel 
26708cfa0ad2SJack F Vogel 		ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &phy_data);
26718cfa0ad2SJack F Vogel 		if (ret_val)
2672ab5d0362SJack F Vogel 			return ret_val;
26738cfa0ad2SJack F Vogel 
26748cfa0ad2SJack F Vogel 		phy->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS)
26758cfa0ad2SJack F Vogel 				? e1000_1000t_rx_status_ok
26768cfa0ad2SJack F Vogel 				: e1000_1000t_rx_status_not_ok;
26778cfa0ad2SJack F Vogel 
26788cfa0ad2SJack F Vogel 		phy->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS)
26798cfa0ad2SJack F Vogel 				 ? e1000_1000t_rx_status_ok
26808cfa0ad2SJack F Vogel 				 : e1000_1000t_rx_status_not_ok;
26818cfa0ad2SJack F Vogel 	} else {
26828cfa0ad2SJack F Vogel 		/* Set values to "undefined" */
26838cfa0ad2SJack F Vogel 		phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
26848cfa0ad2SJack F Vogel 		phy->local_rx = e1000_1000t_rx_status_undefined;
26858cfa0ad2SJack F Vogel 		phy->remote_rx = e1000_1000t_rx_status_undefined;
26868cfa0ad2SJack F Vogel 	}
26878cfa0ad2SJack F Vogel 
26888cfa0ad2SJack F Vogel 	return ret_val;
26898cfa0ad2SJack F Vogel }
26908cfa0ad2SJack F Vogel 
26918cfa0ad2SJack F Vogel /**
26928cfa0ad2SJack F Vogel  *  e1000_get_phy_info_igp - Retrieve igp PHY information
26938cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
26948cfa0ad2SJack F Vogel  *
26958cfa0ad2SJack F Vogel  *  Read PHY status to determine if link is up.  If link is up, then
26968cfa0ad2SJack F Vogel  *  set/determine 10base-T extended distance and polarity correction.  Read
26978cfa0ad2SJack F Vogel  *  PHY port status to determine MDI/MDIx and speed.  Based on the speed,
26988cfa0ad2SJack F Vogel  *  determine on the cable length, local and remote receiver.
26998cfa0ad2SJack F Vogel  **/
27008cfa0ad2SJack F Vogel s32 e1000_get_phy_info_igp(struct e1000_hw *hw)
27018cfa0ad2SJack F Vogel {
27028cfa0ad2SJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
27038cfa0ad2SJack F Vogel 	s32 ret_val;
27048cfa0ad2SJack F Vogel 	u16 data;
27058cfa0ad2SJack F Vogel 	bool link;
27068cfa0ad2SJack F Vogel 
27078cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_get_phy_info_igp");
27088cfa0ad2SJack F Vogel 
27098cfa0ad2SJack F Vogel 	ret_val = e1000_phy_has_link_generic(hw, 1, 0, &link);
27108cfa0ad2SJack F Vogel 	if (ret_val)
2711ab5d0362SJack F Vogel 		return ret_val;
27128cfa0ad2SJack F Vogel 
27138cfa0ad2SJack F Vogel 	if (!link) {
27148cfa0ad2SJack F Vogel 		DEBUGOUT("Phy info is only valid if link is up\n");
2715ab5d0362SJack F Vogel 		return -E1000_ERR_CONFIG;
27168cfa0ad2SJack F Vogel 	}
27178cfa0ad2SJack F Vogel 
27188cfa0ad2SJack F Vogel 	phy->polarity_correction = TRUE;
27198cfa0ad2SJack F Vogel 
27208cfa0ad2SJack F Vogel 	ret_val = e1000_check_polarity_igp(hw);
27218cfa0ad2SJack F Vogel 	if (ret_val)
2722ab5d0362SJack F Vogel 		return ret_val;
27238cfa0ad2SJack F Vogel 
27248cfa0ad2SJack F Vogel 	ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_STATUS, &data);
27258cfa0ad2SJack F Vogel 	if (ret_val)
2726ab5d0362SJack F Vogel 		return ret_val;
27278cfa0ad2SJack F Vogel 
2728ab5d0362SJack F Vogel 	phy->is_mdix = !!(data & IGP01E1000_PSSR_MDIX);
27298cfa0ad2SJack F Vogel 
27308cfa0ad2SJack F Vogel 	if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
27318cfa0ad2SJack F Vogel 	    IGP01E1000_PSSR_SPEED_1000MBPS) {
27324edd8523SJack F Vogel 		ret_val = phy->ops.get_cable_length(hw);
27338cfa0ad2SJack F Vogel 		if (ret_val)
2734ab5d0362SJack F Vogel 			return ret_val;
27358cfa0ad2SJack F Vogel 
27368cfa0ad2SJack F Vogel 		ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &data);
27378cfa0ad2SJack F Vogel 		if (ret_val)
2738ab5d0362SJack F Vogel 			return ret_val;
27398cfa0ad2SJack F Vogel 
27408cfa0ad2SJack F Vogel 		phy->local_rx = (data & SR_1000T_LOCAL_RX_STATUS)
27418cfa0ad2SJack F Vogel 				? e1000_1000t_rx_status_ok
27428cfa0ad2SJack F Vogel 				: e1000_1000t_rx_status_not_ok;
27438cfa0ad2SJack F Vogel 
27448cfa0ad2SJack F Vogel 		phy->remote_rx = (data & SR_1000T_REMOTE_RX_STATUS)
27458cfa0ad2SJack F Vogel 				 ? e1000_1000t_rx_status_ok
27468cfa0ad2SJack F Vogel 				 : e1000_1000t_rx_status_not_ok;
27478cfa0ad2SJack F Vogel 	} else {
27488cfa0ad2SJack F Vogel 		phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
27498cfa0ad2SJack F Vogel 		phy->local_rx = e1000_1000t_rx_status_undefined;
27508cfa0ad2SJack F Vogel 		phy->remote_rx = e1000_1000t_rx_status_undefined;
27518cfa0ad2SJack F Vogel 	}
27528cfa0ad2SJack F Vogel 
27538cfa0ad2SJack F Vogel 	return ret_val;
27548cfa0ad2SJack F Vogel }
27558cfa0ad2SJack F Vogel 
27568cfa0ad2SJack F Vogel /**
27574edd8523SJack F Vogel  *  e1000_get_phy_info_ife - Retrieves various IFE PHY states
27584edd8523SJack F Vogel  *  @hw: pointer to the HW structure
27594edd8523SJack F Vogel  *
27604edd8523SJack F Vogel  *  Populates "phy" structure with various feature states.
27614edd8523SJack F Vogel  **/
27624edd8523SJack F Vogel s32 e1000_get_phy_info_ife(struct e1000_hw *hw)
27634edd8523SJack F Vogel {
27644edd8523SJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
27654edd8523SJack F Vogel 	s32 ret_val;
27664edd8523SJack F Vogel 	u16 data;
27674edd8523SJack F Vogel 	bool link;
27684edd8523SJack F Vogel 
27694edd8523SJack F Vogel 	DEBUGFUNC("e1000_get_phy_info_ife");
27704edd8523SJack F Vogel 
27714edd8523SJack F Vogel 	ret_val = e1000_phy_has_link_generic(hw, 1, 0, &link);
27724edd8523SJack F Vogel 	if (ret_val)
2773ab5d0362SJack F Vogel 		return ret_val;
27744edd8523SJack F Vogel 
27754edd8523SJack F Vogel 	if (!link) {
27764edd8523SJack F Vogel 		DEBUGOUT("Phy info is only valid if link is up\n");
2777ab5d0362SJack F Vogel 		return -E1000_ERR_CONFIG;
27784edd8523SJack F Vogel 	}
27794edd8523SJack F Vogel 
27804edd8523SJack F Vogel 	ret_val = phy->ops.read_reg(hw, IFE_PHY_SPECIAL_CONTROL, &data);
27814edd8523SJack F Vogel 	if (ret_val)
2782ab5d0362SJack F Vogel 		return ret_val;
2783ab5d0362SJack F Vogel 	phy->polarity_correction = !(data & IFE_PSC_AUTO_POLARITY_DISABLE);
27844edd8523SJack F Vogel 
27854edd8523SJack F Vogel 	if (phy->polarity_correction) {
27864edd8523SJack F Vogel 		ret_val = e1000_check_polarity_ife(hw);
27874edd8523SJack F Vogel 		if (ret_val)
2788ab5d0362SJack F Vogel 			return ret_val;
27894edd8523SJack F Vogel 	} else {
27904edd8523SJack F Vogel 		/* Polarity is forced */
27917609433eSJack F Vogel 		phy->cable_polarity = ((data & IFE_PSC_FORCE_POLARITY)
27924edd8523SJack F Vogel 				       ? e1000_rev_polarity_reversed
27937609433eSJack F Vogel 				       : e1000_rev_polarity_normal);
27944edd8523SJack F Vogel 	}
27954edd8523SJack F Vogel 
27964edd8523SJack F Vogel 	ret_val = phy->ops.read_reg(hw, IFE_PHY_MDIX_CONTROL, &data);
27974edd8523SJack F Vogel 	if (ret_val)
2798ab5d0362SJack F Vogel 		return ret_val;
27994edd8523SJack F Vogel 
2800ab5d0362SJack F Vogel 	phy->is_mdix = !!(data & IFE_PMC_MDIX_STATUS);
28014edd8523SJack F Vogel 
28024edd8523SJack F Vogel 	/* The following parameters are undefined for 10/100 operation. */
28034edd8523SJack F Vogel 	phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
28044edd8523SJack F Vogel 	phy->local_rx = e1000_1000t_rx_status_undefined;
28054edd8523SJack F Vogel 	phy->remote_rx = e1000_1000t_rx_status_undefined;
28064edd8523SJack F Vogel 
2807ab5d0362SJack F Vogel 	return E1000_SUCCESS;
28084edd8523SJack F Vogel }
28094edd8523SJack F Vogel 
28104edd8523SJack F Vogel /**
28118cfa0ad2SJack F Vogel  *  e1000_phy_sw_reset_generic - PHY software reset
28128cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
28138cfa0ad2SJack F Vogel  *
28148cfa0ad2SJack F Vogel  *  Does a software reset of the PHY by reading the PHY control register and
28158cfa0ad2SJack F Vogel  *  setting/write the control register reset bit to the PHY.
28168cfa0ad2SJack F Vogel  **/
28178cfa0ad2SJack F Vogel s32 e1000_phy_sw_reset_generic(struct e1000_hw *hw)
28188cfa0ad2SJack F Vogel {
2819ab5d0362SJack F Vogel 	s32 ret_val;
28208cfa0ad2SJack F Vogel 	u16 phy_ctrl;
28218cfa0ad2SJack F Vogel 
28228cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_phy_sw_reset_generic");
28238cfa0ad2SJack F Vogel 
2824ab5d0362SJack F Vogel 	if (!hw->phy.ops.read_reg)
2825ab5d0362SJack F Vogel 		return E1000_SUCCESS;
28268cfa0ad2SJack F Vogel 
28278cfa0ad2SJack F Vogel 	ret_val = hw->phy.ops.read_reg(hw, PHY_CONTROL, &phy_ctrl);
28288cfa0ad2SJack F Vogel 	if (ret_val)
2829ab5d0362SJack F Vogel 		return ret_val;
28308cfa0ad2SJack F Vogel 
28318cfa0ad2SJack F Vogel 	phy_ctrl |= MII_CR_RESET;
28328cfa0ad2SJack F Vogel 	ret_val = hw->phy.ops.write_reg(hw, PHY_CONTROL, phy_ctrl);
28338cfa0ad2SJack F Vogel 	if (ret_val)
2834ab5d0362SJack F Vogel 		return ret_val;
28358cfa0ad2SJack F Vogel 
28368cfa0ad2SJack F Vogel 	usec_delay(1);
28378cfa0ad2SJack F Vogel 
28388cfa0ad2SJack F Vogel 	return ret_val;
28398cfa0ad2SJack F Vogel }
28408cfa0ad2SJack F Vogel 
28418cfa0ad2SJack F Vogel /**
28428cfa0ad2SJack F Vogel  *  e1000_phy_hw_reset_generic - PHY hardware reset
28438cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
28448cfa0ad2SJack F Vogel  *
28458cfa0ad2SJack F Vogel  *  Verify the reset block is not blocking us from resetting.  Acquire
28468cfa0ad2SJack F Vogel  *  semaphore (if necessary) and read/set/write the device control reset
28478cfa0ad2SJack F Vogel  *  bit in the PHY.  Wait the appropriate delay time for the device to
28488cfa0ad2SJack F Vogel  *  reset and release the semaphore (if necessary).
28498cfa0ad2SJack F Vogel  **/
28508cfa0ad2SJack F Vogel s32 e1000_phy_hw_reset_generic(struct e1000_hw *hw)
28518cfa0ad2SJack F Vogel {
28528cfa0ad2SJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
2853ab5d0362SJack F Vogel 	s32 ret_val;
28548cfa0ad2SJack F Vogel 	u32 ctrl;
28558cfa0ad2SJack F Vogel 
28568cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_phy_hw_reset_generic");
28578cfa0ad2SJack F Vogel 
2858ab5d0362SJack F Vogel 	if (phy->ops.check_reset_block) {
28598cfa0ad2SJack F Vogel 		ret_val = phy->ops.check_reset_block(hw);
2860ab5d0362SJack F Vogel 		if (ret_val)
2861ab5d0362SJack F Vogel 			return E1000_SUCCESS;
28628cfa0ad2SJack F Vogel 	}
28638cfa0ad2SJack F Vogel 
28648cfa0ad2SJack F Vogel 	ret_val = phy->ops.acquire(hw);
28658cfa0ad2SJack F Vogel 	if (ret_val)
2866ab5d0362SJack F Vogel 		return ret_val;
28678cfa0ad2SJack F Vogel 
28688cfa0ad2SJack F Vogel 	ctrl = E1000_READ_REG(hw, E1000_CTRL);
28698cfa0ad2SJack F Vogel 	E1000_WRITE_REG(hw, E1000_CTRL, ctrl | E1000_CTRL_PHY_RST);
28708cfa0ad2SJack F Vogel 	E1000_WRITE_FLUSH(hw);
28718cfa0ad2SJack F Vogel 
28728cfa0ad2SJack F Vogel 	usec_delay(phy->reset_delay_us);
28738cfa0ad2SJack F Vogel 
28748cfa0ad2SJack F Vogel 	E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
28758cfa0ad2SJack F Vogel 	E1000_WRITE_FLUSH(hw);
28768cfa0ad2SJack F Vogel 
28778cfa0ad2SJack F Vogel 	usec_delay(150);
28788cfa0ad2SJack F Vogel 
28798cfa0ad2SJack F Vogel 	phy->ops.release(hw);
28808cfa0ad2SJack F Vogel 
2881ab5d0362SJack F Vogel 	return phy->ops.get_cfg_done(hw);
28828cfa0ad2SJack F Vogel }
28838cfa0ad2SJack F Vogel 
28848cfa0ad2SJack F Vogel /**
28858cfa0ad2SJack F Vogel  *  e1000_get_cfg_done_generic - Generic configuration done
28868cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
28878cfa0ad2SJack F Vogel  *
28888cfa0ad2SJack F Vogel  *  Generic function to wait 10 milli-seconds for configuration to complete
28898cfa0ad2SJack F Vogel  *  and return success.
28908cfa0ad2SJack F Vogel  **/
28917609433eSJack F Vogel s32 e1000_get_cfg_done_generic(struct e1000_hw E1000_UNUSEDARG *hw)
28928cfa0ad2SJack F Vogel {
28938cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_get_cfg_done_generic");
28948cfa0ad2SJack F Vogel 
28958cfa0ad2SJack F Vogel 	msec_delay_irq(10);
28968cfa0ad2SJack F Vogel 
28978cfa0ad2SJack F Vogel 	return E1000_SUCCESS;
28988cfa0ad2SJack F Vogel }
28998cfa0ad2SJack F Vogel 
29008cfa0ad2SJack F Vogel /**
29018cfa0ad2SJack F Vogel  *  e1000_phy_init_script_igp3 - Inits the IGP3 PHY
29028cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
29038cfa0ad2SJack F Vogel  *
29048cfa0ad2SJack F Vogel  *  Initializes a Intel Gigabit PHY3 when an EEPROM is not present.
29058cfa0ad2SJack F Vogel  **/
29068cfa0ad2SJack F Vogel s32 e1000_phy_init_script_igp3(struct e1000_hw *hw)
29078cfa0ad2SJack F Vogel {
29088cfa0ad2SJack F Vogel 	DEBUGOUT("Running IGP 3 PHY init script\n");
29098cfa0ad2SJack F Vogel 
29108cfa0ad2SJack F Vogel 	/* PHY init IGP 3 */
29118cfa0ad2SJack F Vogel 	/* Enable rise/fall, 10-mode work in class-A */
29128cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x2F5B, 0x9018);
29138cfa0ad2SJack F Vogel 	/* Remove all caps from Replica path filter */
29148cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x2F52, 0x0000);
29158cfa0ad2SJack F Vogel 	/* Bias trimming for ADC, AFE and Driver (Default) */
29168cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x2FB1, 0x8B24);
29178cfa0ad2SJack F Vogel 	/* Increase Hybrid poly bias */
29188cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x2FB2, 0xF8F0);
29198cfa0ad2SJack F Vogel 	/* Add 4% to Tx amplitude in Gig mode */
29208cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x2010, 0x10B0);
29218cfa0ad2SJack F Vogel 	/* Disable trimming (TTT) */
29228cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x2011, 0x0000);
29238cfa0ad2SJack F Vogel 	/* Poly DC correction to 94.6% + 2% for all channels */
29248cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x20DD, 0x249A);
29258cfa0ad2SJack F Vogel 	/* ABS DC correction to 95.9% */
29268cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x20DE, 0x00D3);
29278cfa0ad2SJack F Vogel 	/* BG temp curve trim */
29288cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x28B4, 0x04CE);
29298cfa0ad2SJack F Vogel 	/* Increasing ADC OPAMP stage 1 currents to max */
29308cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x2F70, 0x29E4);
29318cfa0ad2SJack F Vogel 	/* Force 1000 ( required for enabling PHY regs configuration) */
29328cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x0000, 0x0140);
29338cfa0ad2SJack F Vogel 	/* Set upd_freq to 6 */
29348cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x1F30, 0x1606);
29358cfa0ad2SJack F Vogel 	/* Disable NPDFE */
29368cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x1F31, 0xB814);
29378cfa0ad2SJack F Vogel 	/* Disable adaptive fixed FFE (Default) */
29388cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x1F35, 0x002A);
29398cfa0ad2SJack F Vogel 	/* Enable FFE hysteresis */
29408cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x1F3E, 0x0067);
29418cfa0ad2SJack F Vogel 	/* Fixed FFE for short cable lengths */
29428cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x1F54, 0x0065);
29438cfa0ad2SJack F Vogel 	/* Fixed FFE for medium cable lengths */
29448cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x1F55, 0x002A);
29458cfa0ad2SJack F Vogel 	/* Fixed FFE for long cable lengths */
29468cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x1F56, 0x002A);
29478cfa0ad2SJack F Vogel 	/* Enable Adaptive Clip Threshold */
29488cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x1F72, 0x3FB0);
29498cfa0ad2SJack F Vogel 	/* AHT reset limit to 1 */
29508cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x1F76, 0xC0FF);
29518cfa0ad2SJack F Vogel 	/* Set AHT master delay to 127 msec */
29528cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x1F77, 0x1DEC);
29538cfa0ad2SJack F Vogel 	/* Set scan bits for AHT */
29548cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x1F78, 0xF9EF);
29558cfa0ad2SJack F Vogel 	/* Set AHT Preset bits */
29568cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x1F79, 0x0210);
29578cfa0ad2SJack F Vogel 	/* Change integ_factor of channel A to 3 */
29588cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x1895, 0x0003);
29598cfa0ad2SJack F Vogel 	/* Change prop_factor of channels BCD to 8 */
29608cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x1796, 0x0008);
29618cfa0ad2SJack F Vogel 	/* Change cg_icount + enable integbp for channels BCD */
29628cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x1798, 0xD008);
29636ab6bfe3SJack F Vogel 	/* Change cg_icount + enable integbp + change prop_factor_master
29648cfa0ad2SJack F Vogel 	 * to 8 for channel A
29658cfa0ad2SJack F Vogel 	 */
29668cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x1898, 0xD918);
29678cfa0ad2SJack F Vogel 	/* Disable AHT in Slave mode on channel A */
29688cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x187A, 0x0800);
29696ab6bfe3SJack F Vogel 	/* Enable LPLU and disable AN to 1000 in non-D0a states,
29708cfa0ad2SJack F Vogel 	 * Enable SPD+B2B
29718cfa0ad2SJack F Vogel 	 */
29728cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x0019, 0x008D);
29738cfa0ad2SJack F Vogel 	/* Enable restart AN on an1000_dis change */
29748cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x001B, 0x2080);
29758cfa0ad2SJack F Vogel 	/* Enable wh_fifo read clock in 10/100 modes */
29768cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x0014, 0x0045);
29778cfa0ad2SJack F Vogel 	/* Restart AN, Speed selection is 1000 */
29788cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x0000, 0x1340);
29798cfa0ad2SJack F Vogel 
29808cfa0ad2SJack F Vogel 	return E1000_SUCCESS;
29818cfa0ad2SJack F Vogel }
29828cfa0ad2SJack F Vogel 
29838cfa0ad2SJack F Vogel /**
29848cfa0ad2SJack F Vogel  *  e1000_get_phy_type_from_id - Get PHY type from id
29858cfa0ad2SJack F Vogel  *  @phy_id: phy_id read from the phy
29868cfa0ad2SJack F Vogel  *
29878cfa0ad2SJack F Vogel  *  Returns the phy type from the id.
29888cfa0ad2SJack F Vogel  **/
29898cfa0ad2SJack F Vogel enum e1000_phy_type e1000_get_phy_type_from_id(u32 phy_id)
29908cfa0ad2SJack F Vogel {
29918cfa0ad2SJack F Vogel 	enum e1000_phy_type phy_type = e1000_phy_unknown;
29928cfa0ad2SJack F Vogel 
29938cfa0ad2SJack F Vogel 	switch (phy_id) {
29948cfa0ad2SJack F Vogel 	case M88E1000_I_PHY_ID:
29958cfa0ad2SJack F Vogel 	case M88E1000_E_PHY_ID:
29968cfa0ad2SJack F Vogel 	case M88E1111_I_PHY_ID:
29978cfa0ad2SJack F Vogel 	case M88E1011_I_PHY_ID:
29987609433eSJack F Vogel 	case M88E1543_E_PHY_ID:
29997609433eSJack F Vogel 	case M88E1512_E_PHY_ID:
3000f0ecc46dSJack F Vogel 	case I347AT4_E_PHY_ID:
3001f0ecc46dSJack F Vogel 	case M88E1112_E_PHY_ID:
30021fd3c44fSJack F Vogel 	case M88E1340M_E_PHY_ID:
30038cfa0ad2SJack F Vogel 		phy_type = e1000_phy_m88;
30048cfa0ad2SJack F Vogel 		break;
30058cfa0ad2SJack F Vogel 	case IGP01E1000_I_PHY_ID: /* IGP 1 & 2 share this */
30068cfa0ad2SJack F Vogel 		phy_type = e1000_phy_igp_2;
30078cfa0ad2SJack F Vogel 		break;
30088cfa0ad2SJack F Vogel 	case GG82563_E_PHY_ID:
30098cfa0ad2SJack F Vogel 		phy_type = e1000_phy_gg82563;
30108cfa0ad2SJack F Vogel 		break;
30118cfa0ad2SJack F Vogel 	case IGP03E1000_E_PHY_ID:
30128cfa0ad2SJack F Vogel 		phy_type = e1000_phy_igp_3;
30138cfa0ad2SJack F Vogel 		break;
30148cfa0ad2SJack F Vogel 	case IFE_E_PHY_ID:
30158cfa0ad2SJack F Vogel 	case IFE_PLUS_E_PHY_ID:
30168cfa0ad2SJack F Vogel 	case IFE_C_E_PHY_ID:
30178cfa0ad2SJack F Vogel 		phy_type = e1000_phy_ife;
30188cfa0ad2SJack F Vogel 		break;
30198cfa0ad2SJack F Vogel 	case BME1000_E_PHY_ID:
30208cfa0ad2SJack F Vogel 	case BME1000_E_PHY_ID_R2:
30218cfa0ad2SJack F Vogel 		phy_type = e1000_phy_bm;
30228cfa0ad2SJack F Vogel 		break;
30239d81738fSJack F Vogel 	case I82578_E_PHY_ID:
30249d81738fSJack F Vogel 		phy_type = e1000_phy_82578;
30259d81738fSJack F Vogel 		break;
30269d81738fSJack F Vogel 	case I82577_E_PHY_ID:
30279d81738fSJack F Vogel 		phy_type = e1000_phy_82577;
30289d81738fSJack F Vogel 		break;
30297d9119bdSJack F Vogel 	case I82579_E_PHY_ID:
30307d9119bdSJack F Vogel 		phy_type = e1000_phy_82579;
30317d9119bdSJack F Vogel 		break;
30326ab6bfe3SJack F Vogel 	case I217_E_PHY_ID:
30336ab6bfe3SJack F Vogel 		phy_type = e1000_phy_i217;
30346ab6bfe3SJack F Vogel 		break;
30354edd8523SJack F Vogel 	case I82580_I_PHY_ID:
30364edd8523SJack F Vogel 		phy_type = e1000_phy_82580;
30374edd8523SJack F Vogel 		break;
3038ab5d0362SJack F Vogel 	case I210_I_PHY_ID:
3039ab5d0362SJack F Vogel 		phy_type = e1000_phy_i210;
3040ab5d0362SJack F Vogel 		break;
30418cfa0ad2SJack F Vogel 	default:
30428cfa0ad2SJack F Vogel 		phy_type = e1000_phy_unknown;
30438cfa0ad2SJack F Vogel 		break;
30448cfa0ad2SJack F Vogel 	}
30458cfa0ad2SJack F Vogel 	return phy_type;
30468cfa0ad2SJack F Vogel }
30478cfa0ad2SJack F Vogel 
30488cfa0ad2SJack F Vogel /**
30498cfa0ad2SJack F Vogel  *  e1000_determine_phy_address - Determines PHY address.
30508cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
30518cfa0ad2SJack F Vogel  *
30528cfa0ad2SJack F Vogel  *  This uses a trial and error method to loop through possible PHY
30538cfa0ad2SJack F Vogel  *  addresses. It tests each by reading the PHY ID registers and
30548cfa0ad2SJack F Vogel  *  checking for a match.
30558cfa0ad2SJack F Vogel  **/
30568cfa0ad2SJack F Vogel s32 e1000_determine_phy_address(struct e1000_hw *hw)
30578cfa0ad2SJack F Vogel {
30588cfa0ad2SJack F Vogel 	u32 phy_addr = 0;
30598cfa0ad2SJack F Vogel 	u32 i;
30608cfa0ad2SJack F Vogel 	enum e1000_phy_type phy_type = e1000_phy_unknown;
30618cfa0ad2SJack F Vogel 
3062d035aa2dSJack F Vogel 	hw->phy.id = phy_type;
3063d035aa2dSJack F Vogel 
30648cfa0ad2SJack F Vogel 	for (phy_addr = 0; phy_addr < E1000_MAX_PHY_ADDR; phy_addr++) {
30658cfa0ad2SJack F Vogel 		hw->phy.addr = phy_addr;
30668cfa0ad2SJack F Vogel 		i = 0;
30678cfa0ad2SJack F Vogel 
30688cfa0ad2SJack F Vogel 		do {
30698cfa0ad2SJack F Vogel 			e1000_get_phy_id(hw);
30708cfa0ad2SJack F Vogel 			phy_type = e1000_get_phy_type_from_id(hw->phy.id);
30718cfa0ad2SJack F Vogel 
30726ab6bfe3SJack F Vogel 			/* If phy_type is valid, break - we found our
30738cfa0ad2SJack F Vogel 			 * PHY address
30748cfa0ad2SJack F Vogel 			 */
3075ab5d0362SJack F Vogel 			if (phy_type != e1000_phy_unknown)
3076ab5d0362SJack F Vogel 				return E1000_SUCCESS;
3077ab5d0362SJack F Vogel 
30788cfa0ad2SJack F Vogel 			msec_delay(1);
30798cfa0ad2SJack F Vogel 			i++;
30808cfa0ad2SJack F Vogel 		} while (i < 10);
30818cfa0ad2SJack F Vogel 	}
30828cfa0ad2SJack F Vogel 
3083ab5d0362SJack F Vogel 	return -E1000_ERR_PHY_TYPE;
30848cfa0ad2SJack F Vogel }
30858cfa0ad2SJack F Vogel 
30868cfa0ad2SJack F Vogel /**
30878cfa0ad2SJack F Vogel  *  e1000_get_phy_addr_for_bm_page - Retrieve PHY page address
30888cfa0ad2SJack F Vogel  *  @page: page to access
30898cfa0ad2SJack F Vogel  *
30908cfa0ad2SJack F Vogel  *  Returns the phy address for the page requested.
30918cfa0ad2SJack F Vogel  **/
30928cfa0ad2SJack F Vogel static u32 e1000_get_phy_addr_for_bm_page(u32 page, u32 reg)
30938cfa0ad2SJack F Vogel {
30948cfa0ad2SJack F Vogel 	u32 phy_addr = 2;
30958cfa0ad2SJack F Vogel 
30968cfa0ad2SJack F Vogel 	if ((page >= 768) || (page == 0 && reg == 25) || (reg == 31))
30978cfa0ad2SJack F Vogel 		phy_addr = 1;
30988cfa0ad2SJack F Vogel 
30998cfa0ad2SJack F Vogel 	return phy_addr;
31008cfa0ad2SJack F Vogel }
31018cfa0ad2SJack F Vogel 
31028cfa0ad2SJack F Vogel /**
31038cfa0ad2SJack F Vogel  *  e1000_write_phy_reg_bm - Write BM PHY register
31048cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
31058cfa0ad2SJack F Vogel  *  @offset: register offset to write to
31068cfa0ad2SJack F Vogel  *  @data: data to write at register offset
31078cfa0ad2SJack F Vogel  *
31088cfa0ad2SJack F Vogel  *  Acquires semaphore, if necessary, then writes the data to PHY register
31098cfa0ad2SJack F Vogel  *  at the offset.  Release any acquired semaphores before exiting.
31108cfa0ad2SJack F Vogel  **/
31118cfa0ad2SJack F Vogel s32 e1000_write_phy_reg_bm(struct e1000_hw *hw, u32 offset, u16 data)
31128cfa0ad2SJack F Vogel {
31138cfa0ad2SJack F Vogel 	s32 ret_val;
31148cfa0ad2SJack F Vogel 	u32 page = offset >> IGP_PAGE_SHIFT;
31158cfa0ad2SJack F Vogel 
31168cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_write_phy_reg_bm");
31178cfa0ad2SJack F Vogel 
31184edd8523SJack F Vogel 	ret_val = hw->phy.ops.acquire(hw);
31194edd8523SJack F Vogel 	if (ret_val)
31204edd8523SJack F Vogel 		return ret_val;
31214edd8523SJack F Vogel 
31228cfa0ad2SJack F Vogel 	/* Page 800 works differently than the rest so it has its own func */
31238cfa0ad2SJack F Vogel 	if (page == BM_WUC_PAGE) {
3124daf9197cSJack F Vogel 		ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, &data,
3125*48600901SSean Bruno 							 FALSE, false);
3126ab5d0362SJack F Vogel 		goto release;
31278cfa0ad2SJack F Vogel 	}
31288cfa0ad2SJack F Vogel 
31298cfa0ad2SJack F Vogel 	hw->phy.addr = e1000_get_phy_addr_for_bm_page(page, offset);
31308cfa0ad2SJack F Vogel 
31318cfa0ad2SJack F Vogel 	if (offset > MAX_PHY_MULTI_PAGE_REG) {
3132f0ecc46dSJack F Vogel 		u32 page_shift, page_select;
3133f0ecc46dSJack F Vogel 
31346ab6bfe3SJack F Vogel 		/* Page select is register 31 for phy address 1 and 22 for
31358cfa0ad2SJack F Vogel 		 * phy address 2 and 3. Page select is shifted only for
31368cfa0ad2SJack F Vogel 		 * phy address 1.
31378cfa0ad2SJack F Vogel 		 */
31388cfa0ad2SJack F Vogel 		if (hw->phy.addr == 1) {
31398cfa0ad2SJack F Vogel 			page_shift = IGP_PAGE_SHIFT;
31408cfa0ad2SJack F Vogel 			page_select = IGP01E1000_PHY_PAGE_SELECT;
31418cfa0ad2SJack F Vogel 		} else {
31428cfa0ad2SJack F Vogel 			page_shift = 0;
31438cfa0ad2SJack F Vogel 			page_select = BM_PHY_PAGE_SELECT;
31448cfa0ad2SJack F Vogel 		}
31458cfa0ad2SJack F Vogel 
31468cfa0ad2SJack F Vogel 		/* Page is shifted left, PHY expects (page x 32) */
31478cfa0ad2SJack F Vogel 		ret_val = e1000_write_phy_reg_mdic(hw, page_select,
31488cfa0ad2SJack F Vogel 						   (page << page_shift));
31494edd8523SJack F Vogel 		if (ret_val)
3150ab5d0362SJack F Vogel 			goto release;
31518cfa0ad2SJack F Vogel 	}
31528cfa0ad2SJack F Vogel 
3153daf9197cSJack F Vogel 	ret_val = e1000_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
31548cfa0ad2SJack F Vogel 					   data);
31558cfa0ad2SJack F Vogel 
3156ab5d0362SJack F Vogel release:
31574edd8523SJack F Vogel 	hw->phy.ops.release(hw);
31588cfa0ad2SJack F Vogel 	return ret_val;
31598cfa0ad2SJack F Vogel }
31608cfa0ad2SJack F Vogel 
31618cfa0ad2SJack F Vogel /**
31628cfa0ad2SJack F Vogel  *  e1000_read_phy_reg_bm - Read BM PHY register
31638cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
31648cfa0ad2SJack F Vogel  *  @offset: register offset to be read
31658cfa0ad2SJack F Vogel  *  @data: pointer to the read data
31668cfa0ad2SJack F Vogel  *
31678cfa0ad2SJack F Vogel  *  Acquires semaphore, if necessary, then reads the PHY register at offset
31688cfa0ad2SJack F Vogel  *  and storing the retrieved information in data.  Release any acquired
31698cfa0ad2SJack F Vogel  *  semaphores before exiting.
31708cfa0ad2SJack F Vogel  **/
31718cfa0ad2SJack F Vogel s32 e1000_read_phy_reg_bm(struct e1000_hw *hw, u32 offset, u16 *data)
31728cfa0ad2SJack F Vogel {
31738cfa0ad2SJack F Vogel 	s32 ret_val;
31748cfa0ad2SJack F Vogel 	u32 page = offset >> IGP_PAGE_SHIFT;
31758cfa0ad2SJack F Vogel 
31768cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_read_phy_reg_bm");
31778cfa0ad2SJack F Vogel 
31784edd8523SJack F Vogel 	ret_val = hw->phy.ops.acquire(hw);
31794edd8523SJack F Vogel 	if (ret_val)
31804edd8523SJack F Vogel 		return ret_val;
31814edd8523SJack F Vogel 
31828cfa0ad2SJack F Vogel 	/* Page 800 works differently than the rest so it has its own func */
31838cfa0ad2SJack F Vogel 	if (page == BM_WUC_PAGE) {
3184daf9197cSJack F Vogel 		ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, data,
31854dab5c37SJack F Vogel 							 TRUE, FALSE);
3186ab5d0362SJack F Vogel 		goto release;
31878cfa0ad2SJack F Vogel 	}
31888cfa0ad2SJack F Vogel 
31898cfa0ad2SJack F Vogel 	hw->phy.addr = e1000_get_phy_addr_for_bm_page(page, offset);
31908cfa0ad2SJack F Vogel 
31918cfa0ad2SJack F Vogel 	if (offset > MAX_PHY_MULTI_PAGE_REG) {
3192f0ecc46dSJack F Vogel 		u32 page_shift, page_select;
3193f0ecc46dSJack F Vogel 
31946ab6bfe3SJack F Vogel 		/* Page select is register 31 for phy address 1 and 22 for
31958cfa0ad2SJack F Vogel 		 * phy address 2 and 3. Page select is shifted only for
31968cfa0ad2SJack F Vogel 		 * phy address 1.
31978cfa0ad2SJack F Vogel 		 */
31988cfa0ad2SJack F Vogel 		if (hw->phy.addr == 1) {
31998cfa0ad2SJack F Vogel 			page_shift = IGP_PAGE_SHIFT;
32008cfa0ad2SJack F Vogel 			page_select = IGP01E1000_PHY_PAGE_SELECT;
32018cfa0ad2SJack F Vogel 		} else {
32028cfa0ad2SJack F Vogel 			page_shift = 0;
32038cfa0ad2SJack F Vogel 			page_select = BM_PHY_PAGE_SELECT;
32048cfa0ad2SJack F Vogel 		}
32058cfa0ad2SJack F Vogel 
32068cfa0ad2SJack F Vogel 		/* Page is shifted left, PHY expects (page x 32) */
32078cfa0ad2SJack F Vogel 		ret_val = e1000_write_phy_reg_mdic(hw, page_select,
32088cfa0ad2SJack F Vogel 						   (page << page_shift));
32094edd8523SJack F Vogel 		if (ret_val)
3210ab5d0362SJack F Vogel 			goto release;
32118cfa0ad2SJack F Vogel 	}
32128cfa0ad2SJack F Vogel 
3213daf9197cSJack F Vogel 	ret_val = e1000_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
32148cfa0ad2SJack F Vogel 					  data);
3215ab5d0362SJack F Vogel release:
32164edd8523SJack F Vogel 	hw->phy.ops.release(hw);
32178cfa0ad2SJack F Vogel 	return ret_val;
32188cfa0ad2SJack F Vogel }
32198cfa0ad2SJack F Vogel 
32208cfa0ad2SJack F Vogel /**
32218cfa0ad2SJack F Vogel  *  e1000_read_phy_reg_bm2 - Read BM PHY register
32228cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
32238cfa0ad2SJack F Vogel  *  @offset: register offset to be read
32248cfa0ad2SJack F Vogel  *  @data: pointer to the read data
32258cfa0ad2SJack F Vogel  *
32268cfa0ad2SJack F Vogel  *  Acquires semaphore, if necessary, then reads the PHY register at offset
32278cfa0ad2SJack F Vogel  *  and storing the retrieved information in data.  Release any acquired
32288cfa0ad2SJack F Vogel  *  semaphores before exiting.
32298cfa0ad2SJack F Vogel  **/
32308cfa0ad2SJack F Vogel s32 e1000_read_phy_reg_bm2(struct e1000_hw *hw, u32 offset, u16 *data)
32318cfa0ad2SJack F Vogel {
32328cfa0ad2SJack F Vogel 	s32 ret_val;
32338cfa0ad2SJack F Vogel 	u16 page = (u16)(offset >> IGP_PAGE_SHIFT);
32348cfa0ad2SJack F Vogel 
32354dab5c37SJack F Vogel 	DEBUGFUNC("e1000_read_phy_reg_bm2");
32368cfa0ad2SJack F Vogel 
32374edd8523SJack F Vogel 	ret_val = hw->phy.ops.acquire(hw);
32384edd8523SJack F Vogel 	if (ret_val)
32394edd8523SJack F Vogel 		return ret_val;
32404edd8523SJack F Vogel 
32418cfa0ad2SJack F Vogel 	/* Page 800 works differently than the rest so it has its own func */
32428cfa0ad2SJack F Vogel 	if (page == BM_WUC_PAGE) {
32438cfa0ad2SJack F Vogel 		ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, data,
32444dab5c37SJack F Vogel 							 TRUE, FALSE);
3245ab5d0362SJack F Vogel 		goto release;
32468cfa0ad2SJack F Vogel 	}
32478cfa0ad2SJack F Vogel 
32488cfa0ad2SJack F Vogel 	hw->phy.addr = 1;
32498cfa0ad2SJack F Vogel 
32508cfa0ad2SJack F Vogel 	if (offset > MAX_PHY_MULTI_PAGE_REG) {
32518cfa0ad2SJack F Vogel 		/* Page is shifted left, PHY expects (page x 32) */
32528cfa0ad2SJack F Vogel 		ret_val = e1000_write_phy_reg_mdic(hw, BM_PHY_PAGE_SELECT,
32538cfa0ad2SJack F Vogel 						   page);
32548cfa0ad2SJack F Vogel 
32554edd8523SJack F Vogel 		if (ret_val)
3256ab5d0362SJack F Vogel 			goto release;
32578cfa0ad2SJack F Vogel 	}
32588cfa0ad2SJack F Vogel 
32598cfa0ad2SJack F Vogel 	ret_val = e1000_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
32608cfa0ad2SJack F Vogel 					  data);
3261ab5d0362SJack F Vogel release:
32624edd8523SJack F Vogel 	hw->phy.ops.release(hw);
32638cfa0ad2SJack F Vogel 	return ret_val;
32648cfa0ad2SJack F Vogel }
32658cfa0ad2SJack F Vogel 
32668cfa0ad2SJack F Vogel /**
32678cfa0ad2SJack F Vogel  *  e1000_write_phy_reg_bm2 - Write BM PHY register
32688cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
32698cfa0ad2SJack F Vogel  *  @offset: register offset to write to
32708cfa0ad2SJack F Vogel  *  @data: data to write at register offset
32718cfa0ad2SJack F Vogel  *
32728cfa0ad2SJack F Vogel  *  Acquires semaphore, if necessary, then writes the data to PHY register
32738cfa0ad2SJack F Vogel  *  at the offset.  Release any acquired semaphores before exiting.
32748cfa0ad2SJack F Vogel  **/
32758cfa0ad2SJack F Vogel s32 e1000_write_phy_reg_bm2(struct e1000_hw *hw, u32 offset, u16 data)
32768cfa0ad2SJack F Vogel {
32778cfa0ad2SJack F Vogel 	s32 ret_val;
32788cfa0ad2SJack F Vogel 	u16 page = (u16)(offset >> IGP_PAGE_SHIFT);
32798cfa0ad2SJack F Vogel 
32808cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_write_phy_reg_bm2");
32818cfa0ad2SJack F Vogel 
32824edd8523SJack F Vogel 	ret_val = hw->phy.ops.acquire(hw);
32834edd8523SJack F Vogel 	if (ret_val)
32844edd8523SJack F Vogel 		return ret_val;
32854edd8523SJack F Vogel 
32868cfa0ad2SJack F Vogel 	/* Page 800 works differently than the rest so it has its own func */
32878cfa0ad2SJack F Vogel 	if (page == BM_WUC_PAGE) {
32888cfa0ad2SJack F Vogel 		ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, &data,
3289*48600901SSean Bruno 							 FALSE, false);
3290ab5d0362SJack F Vogel 		goto release;
32918cfa0ad2SJack F Vogel 	}
32928cfa0ad2SJack F Vogel 
32938cfa0ad2SJack F Vogel 	hw->phy.addr = 1;
32948cfa0ad2SJack F Vogel 
32958cfa0ad2SJack F Vogel 	if (offset > MAX_PHY_MULTI_PAGE_REG) {
32968cfa0ad2SJack F Vogel 		/* Page is shifted left, PHY expects (page x 32) */
32978cfa0ad2SJack F Vogel 		ret_val = e1000_write_phy_reg_mdic(hw, BM_PHY_PAGE_SELECT,
32988cfa0ad2SJack F Vogel 						   page);
32998cfa0ad2SJack F Vogel 
33004edd8523SJack F Vogel 		if (ret_val)
3301ab5d0362SJack F Vogel 			goto release;
33028cfa0ad2SJack F Vogel 	}
33038cfa0ad2SJack F Vogel 
33048cfa0ad2SJack F Vogel 	ret_val = e1000_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
33058cfa0ad2SJack F Vogel 					   data);
33068cfa0ad2SJack F Vogel 
3307ab5d0362SJack F Vogel release:
33084edd8523SJack F Vogel 	hw->phy.ops.release(hw);
33098cfa0ad2SJack F Vogel 	return ret_val;
33108cfa0ad2SJack F Vogel }
33118cfa0ad2SJack F Vogel 
33128cfa0ad2SJack F Vogel /**
33134dab5c37SJack F Vogel  *  e1000_enable_phy_wakeup_reg_access_bm - enable access to BM wakeup registers
33144dab5c37SJack F Vogel  *  @hw: pointer to the HW structure
33154dab5c37SJack F Vogel  *  @phy_reg: pointer to store original contents of BM_WUC_ENABLE_REG
33164dab5c37SJack F Vogel  *
33174dab5c37SJack F Vogel  *  Assumes semaphore already acquired and phy_reg points to a valid memory
33184dab5c37SJack F Vogel  *  address to store contents of the BM_WUC_ENABLE_REG register.
33194dab5c37SJack F Vogel  **/
33204dab5c37SJack F Vogel s32 e1000_enable_phy_wakeup_reg_access_bm(struct e1000_hw *hw, u16 *phy_reg)
33214dab5c37SJack F Vogel {
33224dab5c37SJack F Vogel 	s32 ret_val;
33234dab5c37SJack F Vogel 	u16 temp;
33244dab5c37SJack F Vogel 
33254dab5c37SJack F Vogel 	DEBUGFUNC("e1000_enable_phy_wakeup_reg_access_bm");
33264dab5c37SJack F Vogel 
3327ab5d0362SJack F Vogel 	if (!phy_reg)
3328ab5d0362SJack F Vogel 		return -E1000_ERR_PARAM;
33294dab5c37SJack F Vogel 
33304dab5c37SJack F Vogel 	/* All page select, port ctrl and wakeup registers use phy address 1 */
33314dab5c37SJack F Vogel 	hw->phy.addr = 1;
33324dab5c37SJack F Vogel 
33334dab5c37SJack F Vogel 	/* Select Port Control Registers page */
33344dab5c37SJack F Vogel 	ret_val = e1000_set_page_igp(hw, (BM_PORT_CTRL_PAGE << IGP_PAGE_SHIFT));
33354dab5c37SJack F Vogel 	if (ret_val) {
33364dab5c37SJack F Vogel 		DEBUGOUT("Could not set Port Control page\n");
3337ab5d0362SJack F Vogel 		return ret_val;
33384dab5c37SJack F Vogel 	}
33394dab5c37SJack F Vogel 
33404dab5c37SJack F Vogel 	ret_val = e1000_read_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, phy_reg);
33414dab5c37SJack F Vogel 	if (ret_val) {
33424dab5c37SJack F Vogel 		DEBUGOUT2("Could not read PHY register %d.%d\n",
33434dab5c37SJack F Vogel 			  BM_PORT_CTRL_PAGE, BM_WUC_ENABLE_REG);
3344ab5d0362SJack F Vogel 		return ret_val;
33454dab5c37SJack F Vogel 	}
33464dab5c37SJack F Vogel 
33476ab6bfe3SJack F Vogel 	/* Enable both PHY wakeup mode and Wakeup register page writes.
33484dab5c37SJack F Vogel 	 * Prevent a power state change by disabling ME and Host PHY wakeup.
33494dab5c37SJack F Vogel 	 */
33504dab5c37SJack F Vogel 	temp = *phy_reg;
33514dab5c37SJack F Vogel 	temp |= BM_WUC_ENABLE_BIT;
33524dab5c37SJack F Vogel 	temp &= ~(BM_WUC_ME_WU_BIT | BM_WUC_HOST_WU_BIT);
33534dab5c37SJack F Vogel 
33544dab5c37SJack F Vogel 	ret_val = e1000_write_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, temp);
33554dab5c37SJack F Vogel 	if (ret_val) {
33564dab5c37SJack F Vogel 		DEBUGOUT2("Could not write PHY register %d.%d\n",
33574dab5c37SJack F Vogel 			  BM_PORT_CTRL_PAGE, BM_WUC_ENABLE_REG);
3358ab5d0362SJack F Vogel 		return ret_val;
33594dab5c37SJack F Vogel 	}
33604dab5c37SJack F Vogel 
33616ab6bfe3SJack F Vogel 	/* Select Host Wakeup Registers page - caller now able to write
3362ab5d0362SJack F Vogel 	 * registers on the Wakeup registers page
3363ab5d0362SJack F Vogel 	 */
3364ab5d0362SJack F Vogel 	return e1000_set_page_igp(hw, (BM_WUC_PAGE << IGP_PAGE_SHIFT));
33654dab5c37SJack F Vogel }
33664dab5c37SJack F Vogel 
33674dab5c37SJack F Vogel /**
33684dab5c37SJack F Vogel  *  e1000_disable_phy_wakeup_reg_access_bm - disable access to BM wakeup regs
33694dab5c37SJack F Vogel  *  @hw: pointer to the HW structure
33704dab5c37SJack F Vogel  *  @phy_reg: pointer to original contents of BM_WUC_ENABLE_REG
33714dab5c37SJack F Vogel  *
33724dab5c37SJack F Vogel  *  Restore BM_WUC_ENABLE_REG to its original value.
33734dab5c37SJack F Vogel  *
33744dab5c37SJack F Vogel  *  Assumes semaphore already acquired and *phy_reg is the contents of the
33754dab5c37SJack F Vogel  *  BM_WUC_ENABLE_REG before register(s) on BM_WUC_PAGE were accessed by
33764dab5c37SJack F Vogel  *  caller.
33774dab5c37SJack F Vogel  **/
33784dab5c37SJack F Vogel s32 e1000_disable_phy_wakeup_reg_access_bm(struct e1000_hw *hw, u16 *phy_reg)
33794dab5c37SJack F Vogel {
33806ab6bfe3SJack F Vogel 	s32 ret_val;
33814dab5c37SJack F Vogel 
33824dab5c37SJack F Vogel 	DEBUGFUNC("e1000_disable_phy_wakeup_reg_access_bm");
33834dab5c37SJack F Vogel 
33844dab5c37SJack F Vogel 	if (!phy_reg)
33854dab5c37SJack F Vogel 		return -E1000_ERR_PARAM;
33864dab5c37SJack F Vogel 
33874dab5c37SJack F Vogel 	/* Select Port Control Registers page */
33884dab5c37SJack F Vogel 	ret_val = e1000_set_page_igp(hw, (BM_PORT_CTRL_PAGE << IGP_PAGE_SHIFT));
33894dab5c37SJack F Vogel 	if (ret_val) {
33904dab5c37SJack F Vogel 		DEBUGOUT("Could not set Port Control page\n");
3391ab5d0362SJack F Vogel 		return ret_val;
33924dab5c37SJack F Vogel 	}
33934dab5c37SJack F Vogel 
33944dab5c37SJack F Vogel 	/* Restore 769.17 to its original value */
33954dab5c37SJack F Vogel 	ret_val = e1000_write_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, *phy_reg);
33964dab5c37SJack F Vogel 	if (ret_val)
33974dab5c37SJack F Vogel 		DEBUGOUT2("Could not restore PHY register %d.%d\n",
33984dab5c37SJack F Vogel 			  BM_PORT_CTRL_PAGE, BM_WUC_ENABLE_REG);
3399ab5d0362SJack F Vogel 
34004dab5c37SJack F Vogel 	return ret_val;
34014dab5c37SJack F Vogel }
34024dab5c37SJack F Vogel 
34034dab5c37SJack F Vogel /**
34044dab5c37SJack F Vogel  *  e1000_access_phy_wakeup_reg_bm - Read/write BM PHY wakeup register
34058cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
34068cfa0ad2SJack F Vogel  *  @offset: register offset to be read or written
34078cfa0ad2SJack F Vogel  *  @data: pointer to the data to read or write
34088cfa0ad2SJack F Vogel  *  @read: determines if operation is read or write
34094dab5c37SJack F Vogel  *  @page_set: BM_WUC_PAGE already set and access enabled
34108cfa0ad2SJack F Vogel  *
34114dab5c37SJack F Vogel  *  Read the PHY register at offset and store the retrieved information in
34124dab5c37SJack F Vogel  *  data, or write data to PHY register at offset.  Note the procedure to
34134dab5c37SJack F Vogel  *  access the PHY wakeup registers is different than reading the other PHY
34144dab5c37SJack F Vogel  *  registers. It works as such:
34154dab5c37SJack F Vogel  *  1) Set 769.17.2 (page 769, register 17, bit 2) = 1
34168cfa0ad2SJack F Vogel  *  2) Set page to 800 for host (801 if we were manageability)
34178cfa0ad2SJack F Vogel  *  3) Write the address using the address opcode (0x11)
34188cfa0ad2SJack F Vogel  *  4) Read or write the data using the data opcode (0x12)
34194dab5c37SJack F Vogel  *  5) Restore 769.17.2 to its original value
34204edd8523SJack F Vogel  *
34214dab5c37SJack F Vogel  *  Steps 1 and 2 are done by e1000_enable_phy_wakeup_reg_access_bm() and
34224dab5c37SJack F Vogel  *  step 5 is done by e1000_disable_phy_wakeup_reg_access_bm().
34234dab5c37SJack F Vogel  *
34244dab5c37SJack F Vogel  *  Assumes semaphore is already acquired.  When page_set==TRUE, assumes
34254dab5c37SJack F Vogel  *  the PHY page is set to BM_WUC_PAGE (i.e. a function in the call stack
34264dab5c37SJack F Vogel  *  is responsible for calls to e1000_[enable|disable]_phy_wakeup_reg_bm()).
34278cfa0ad2SJack F Vogel  **/
3428daf9197cSJack F Vogel static s32 e1000_access_phy_wakeup_reg_bm(struct e1000_hw *hw, u32 offset,
34294dab5c37SJack F Vogel 					  u16 *data, bool read, bool page_set)
34308cfa0ad2SJack F Vogel {
34318cfa0ad2SJack F Vogel 	s32 ret_val;
34328cc64f1eSJack F Vogel 	u16 reg, page;
34338cfa0ad2SJack F Vogel 	u16 phy_reg = 0;
34348cfa0ad2SJack F Vogel 
3435d035aa2dSJack F Vogel 	DEBUGFUNC("e1000_access_phy_wakeup_reg_bm");
3436*48600901SSean Bruno 
34378cc64f1eSJack F Vogel 	reg = BM_PHY_REG_NUM(offset);
34388cc64f1eSJack F Vogel 	page = BM_PHY_REG_PAGE(offset);
34398cfa0ad2SJack F Vogel 
34404dab5c37SJack F Vogel 	/* Gig must be disabled for MDIO accesses to Host Wakeup reg page */
34419d81738fSJack F Vogel 	if ((hw->mac.type == e1000_pchlan) &&
34429d81738fSJack F Vogel 	   (!(E1000_READ_REG(hw, E1000_PHY_CTRL) & E1000_PHY_CTRL_GBE_DISABLE)))
34434dab5c37SJack F Vogel 		DEBUGOUT1("Attempting to access page %d while gig enabled.\n",
34444dab5c37SJack F Vogel 			  page);
34459d81738fSJack F Vogel 
34464dab5c37SJack F Vogel 	if (!page_set) {
34474dab5c37SJack F Vogel 		/* Enable access to PHY wakeup registers */
34484dab5c37SJack F Vogel 		ret_val = e1000_enable_phy_wakeup_reg_access_bm(hw, &phy_reg);
34498cfa0ad2SJack F Vogel 		if (ret_val) {
34504dab5c37SJack F Vogel 			DEBUGOUT("Could not enable PHY wakeup reg access\n");
3451ab5d0362SJack F Vogel 			return ret_val;
34528cfa0ad2SJack F Vogel 		}
34538cfa0ad2SJack F Vogel 	}
34548cfa0ad2SJack F Vogel 
34554dab5c37SJack F Vogel 	DEBUGOUT2("Accessing PHY page %d reg 0x%x\n", page, reg);
34568cfa0ad2SJack F Vogel 
34574dab5c37SJack F Vogel 	/* Write the Wakeup register page offset value using opcode 0x11 */
34588cfa0ad2SJack F Vogel 	ret_val = e1000_write_phy_reg_mdic(hw, BM_WUC_ADDRESS_OPCODE, reg);
34598cfa0ad2SJack F Vogel 	if (ret_val) {
34604dab5c37SJack F Vogel 		DEBUGOUT1("Could not write address opcode to page %d\n", page);
3461ab5d0362SJack F Vogel 		return ret_val;
34628cfa0ad2SJack F Vogel 	}
34638cfa0ad2SJack F Vogel 
34648cfa0ad2SJack F Vogel 	if (read) {
34654dab5c37SJack F Vogel 		/* Read the Wakeup register page value using opcode 0x12 */
34668cfa0ad2SJack F Vogel 		ret_val = e1000_read_phy_reg_mdic(hw, BM_WUC_DATA_OPCODE,
34678cfa0ad2SJack F Vogel 						  data);
34688cfa0ad2SJack F Vogel 	} else {
34694dab5c37SJack F Vogel 		/* Write the Wakeup register page value using opcode 0x12 */
34708cfa0ad2SJack F Vogel 		ret_val = e1000_write_phy_reg_mdic(hw, BM_WUC_DATA_OPCODE,
34718cfa0ad2SJack F Vogel 						   *data);
34728cfa0ad2SJack F Vogel 	}
34738cfa0ad2SJack F Vogel 
34748cfa0ad2SJack F Vogel 	if (ret_val) {
34754dab5c37SJack F Vogel 		DEBUGOUT2("Could not access PHY reg %d.%d\n", page, reg);
3476ab5d0362SJack F Vogel 		return ret_val;
34778cfa0ad2SJack F Vogel 	}
34788cfa0ad2SJack F Vogel 
34794dab5c37SJack F Vogel 	if (!page_set)
34804dab5c37SJack F Vogel 		ret_val = e1000_disable_phy_wakeup_reg_access_bm(hw, &phy_reg);
34818cfa0ad2SJack F Vogel 
34828cfa0ad2SJack F Vogel 	return ret_val;
34838cfa0ad2SJack F Vogel }
34848cfa0ad2SJack F Vogel 
34858cfa0ad2SJack F Vogel /**
34868cfa0ad2SJack F Vogel  * e1000_power_up_phy_copper - Restore copper link in case of PHY power down
34878cfa0ad2SJack F Vogel  * @hw: pointer to the HW structure
34888cfa0ad2SJack F Vogel  *
34898cfa0ad2SJack F Vogel  * In the case of a PHY power down to save power, or to turn off link during a
34908cfa0ad2SJack F Vogel  * driver unload, or wake on lan is not enabled, restore the link to previous
34918cfa0ad2SJack F Vogel  * settings.
34928cfa0ad2SJack F Vogel  **/
34938cfa0ad2SJack F Vogel void e1000_power_up_phy_copper(struct e1000_hw *hw)
34948cfa0ad2SJack F Vogel {
34958cfa0ad2SJack F Vogel 	u16 mii_reg = 0;
34968cfa0ad2SJack F Vogel 
34978cfa0ad2SJack F Vogel 	/* The PHY will retain its settings across a power down/up cycle */
34988cfa0ad2SJack F Vogel 	hw->phy.ops.read_reg(hw, PHY_CONTROL, &mii_reg);
34998cfa0ad2SJack F Vogel 	mii_reg &= ~MII_CR_POWER_DOWN;
35008cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, PHY_CONTROL, mii_reg);
35018cfa0ad2SJack F Vogel }
35028cfa0ad2SJack F Vogel 
35038cfa0ad2SJack F Vogel /**
35048cfa0ad2SJack F Vogel  * e1000_power_down_phy_copper - Restore copper link in case of PHY power down
35058cfa0ad2SJack F Vogel  * @hw: pointer to the HW structure
35068cfa0ad2SJack F Vogel  *
35078cfa0ad2SJack F Vogel  * In the case of a PHY power down to save power, or to turn off link during a
35088cfa0ad2SJack F Vogel  * driver unload, or wake on lan is not enabled, restore the link to previous
35098cfa0ad2SJack F Vogel  * settings.
35108cfa0ad2SJack F Vogel  **/
35118cfa0ad2SJack F Vogel void e1000_power_down_phy_copper(struct e1000_hw *hw)
35128cfa0ad2SJack F Vogel {
35138cfa0ad2SJack F Vogel 	u16 mii_reg = 0;
35148cfa0ad2SJack F Vogel 
35158cfa0ad2SJack F Vogel 	/* The PHY will retain its settings across a power down/up cycle */
35168cfa0ad2SJack F Vogel 	hw->phy.ops.read_reg(hw, PHY_CONTROL, &mii_reg);
35178cfa0ad2SJack F Vogel 	mii_reg |= MII_CR_POWER_DOWN;
35188cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, PHY_CONTROL, mii_reg);
35198cfa0ad2SJack F Vogel 	msec_delay(1);
35208cfa0ad2SJack F Vogel }
35219d81738fSJack F Vogel 
35224edd8523SJack F Vogel /**
35234edd8523SJack F Vogel  *  __e1000_read_phy_reg_hv -  Read HV PHY register
35244edd8523SJack F Vogel  *  @hw: pointer to the HW structure
35254edd8523SJack F Vogel  *  @offset: register offset to be read
35264edd8523SJack F Vogel  *  @data: pointer to the read data
35274edd8523SJack F Vogel  *  @locked: semaphore has already been acquired or not
35284edd8523SJack F Vogel  *
35294edd8523SJack F Vogel  *  Acquires semaphore, if necessary, then reads the PHY register at offset
35304edd8523SJack F Vogel  *  and stores the retrieved information in data.  Release any acquired
35314edd8523SJack F Vogel  *  semaphore before exiting.
35324edd8523SJack F Vogel  **/
35334edd8523SJack F Vogel static s32 __e1000_read_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 *data,
35344dab5c37SJack F Vogel 				   bool locked, bool page_set)
35354edd8523SJack F Vogel {
35364edd8523SJack F Vogel 	s32 ret_val;
35374edd8523SJack F Vogel 	u16 page = BM_PHY_REG_PAGE(offset);
35384edd8523SJack F Vogel 	u16 reg = BM_PHY_REG_NUM(offset);
35394dab5c37SJack F Vogel 	u32 phy_addr = hw->phy.addr = e1000_get_phy_addr_for_hv_page(page);
35404edd8523SJack F Vogel 
3541a69ed8dfSJack F Vogel 	DEBUGFUNC("__e1000_read_phy_reg_hv");
35424edd8523SJack F Vogel 
35434edd8523SJack F Vogel 	if (!locked) {
35444edd8523SJack F Vogel 		ret_val = hw->phy.ops.acquire(hw);
35454edd8523SJack F Vogel 		if (ret_val)
35464edd8523SJack F Vogel 			return ret_val;
35474edd8523SJack F Vogel 	}
35484edd8523SJack F Vogel 	/* Page 800 works differently than the rest so it has its own func */
35494edd8523SJack F Vogel 	if (page == BM_WUC_PAGE) {
35504dab5c37SJack F Vogel 		ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, data,
35514dab5c37SJack F Vogel 							 TRUE, page_set);
35524edd8523SJack F Vogel 		goto out;
35534edd8523SJack F Vogel 	}
35544edd8523SJack F Vogel 
35554edd8523SJack F Vogel 	if (page > 0 && page < HV_INTC_FC_PAGE_START) {
35564edd8523SJack F Vogel 		ret_val = e1000_access_phy_debug_regs_hv(hw, offset,
35574edd8523SJack F Vogel 							 data, TRUE);
35584edd8523SJack F Vogel 		goto out;
35594edd8523SJack F Vogel 	}
35604edd8523SJack F Vogel 
35614dab5c37SJack F Vogel 	if (!page_set) {
35624edd8523SJack F Vogel 		if (page == HV_INTC_FC_PAGE_START)
35634edd8523SJack F Vogel 			page = 0;
35644edd8523SJack F Vogel 
35654edd8523SJack F Vogel 		if (reg > MAX_PHY_MULTI_PAGE_REG) {
35664edd8523SJack F Vogel 			/* Page is shifted left, PHY expects (page x 32) */
35674dab5c37SJack F Vogel 			ret_val = e1000_set_page_igp(hw,
35684edd8523SJack F Vogel 						     (page << IGP_PAGE_SHIFT));
35694dab5c37SJack F Vogel 
35704edd8523SJack F Vogel 			hw->phy.addr = phy_addr;
35714edd8523SJack F Vogel 
35724edd8523SJack F Vogel 			if (ret_val)
35734edd8523SJack F Vogel 				goto out;
35744edd8523SJack F Vogel 		}
35754dab5c37SJack F Vogel 	}
35764dab5c37SJack F Vogel 
35774dab5c37SJack F Vogel 	DEBUGOUT3("reading PHY page %d (or 0x%x shifted) reg 0x%x\n", page,
35784dab5c37SJack F Vogel 		  page << IGP_PAGE_SHIFT, reg);
35794edd8523SJack F Vogel 
35804edd8523SJack F Vogel 	ret_val = e1000_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & reg,
35814edd8523SJack F Vogel 					  data);
35824edd8523SJack F Vogel out:
35834edd8523SJack F Vogel 	if (!locked)
35849d81738fSJack F Vogel 		hw->phy.ops.release(hw);
35859d81738fSJack F Vogel 
35869d81738fSJack F Vogel 	return ret_val;
35879d81738fSJack F Vogel }
35889d81738fSJack F Vogel 
35899d81738fSJack F Vogel /**
35909d81738fSJack F Vogel  *  e1000_read_phy_reg_hv -  Read HV PHY register
35919d81738fSJack F Vogel  *  @hw: pointer to the HW structure
35929d81738fSJack F Vogel  *  @offset: register offset to be read
35939d81738fSJack F Vogel  *  @data: pointer to the read data
35949d81738fSJack F Vogel  *
35954edd8523SJack F Vogel  *  Acquires semaphore then reads the PHY register at offset and stores
35964edd8523SJack F Vogel  *  the retrieved information in data.  Release the acquired semaphore
35974edd8523SJack F Vogel  *  before exiting.
35989d81738fSJack F Vogel  **/
35999d81738fSJack F Vogel s32 e1000_read_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 *data)
36009d81738fSJack F Vogel {
3601*48600901SSean Bruno 	return __e1000_read_phy_reg_hv(hw, offset, data, FALSE, false);
36029d81738fSJack F Vogel }
36039d81738fSJack F Vogel 
36049d81738fSJack F Vogel /**
36054edd8523SJack F Vogel  *  e1000_read_phy_reg_hv_locked -  Read HV PHY register
36064edd8523SJack F Vogel  *  @hw: pointer to the HW structure
36074edd8523SJack F Vogel  *  @offset: register offset to be read
36084edd8523SJack F Vogel  *  @data: pointer to the read data
36094edd8523SJack F Vogel  *
36104edd8523SJack F Vogel  *  Reads the PHY register at offset and stores the retrieved information
36114edd8523SJack F Vogel  *  in data.  Assumes semaphore already acquired.
36124edd8523SJack F Vogel  **/
36134edd8523SJack F Vogel s32 e1000_read_phy_reg_hv_locked(struct e1000_hw *hw, u32 offset, u16 *data)
36144edd8523SJack F Vogel {
36154dab5c37SJack F Vogel 	return __e1000_read_phy_reg_hv(hw, offset, data, TRUE, FALSE);
36164dab5c37SJack F Vogel }
36174dab5c37SJack F Vogel 
36184dab5c37SJack F Vogel /**
36194dab5c37SJack F Vogel  *  e1000_read_phy_reg_page_hv - Read HV PHY register
36204dab5c37SJack F Vogel  *  @hw: pointer to the HW structure
36214dab5c37SJack F Vogel  *  @offset: register offset to write to
36224dab5c37SJack F Vogel  *  @data: data to write at register offset
36234dab5c37SJack F Vogel  *
36244dab5c37SJack F Vogel  *  Reads the PHY register at offset and stores the retrieved information
36254dab5c37SJack F Vogel  *  in data.  Assumes semaphore already acquired and page already set.
36264dab5c37SJack F Vogel  **/
36274dab5c37SJack F Vogel s32 e1000_read_phy_reg_page_hv(struct e1000_hw *hw, u32 offset, u16 *data)
36284dab5c37SJack F Vogel {
36294dab5c37SJack F Vogel 	return __e1000_read_phy_reg_hv(hw, offset, data, TRUE, true);
36304edd8523SJack F Vogel }
36314edd8523SJack F Vogel 
36324edd8523SJack F Vogel /**
36334edd8523SJack F Vogel  *  __e1000_write_phy_reg_hv - Write HV PHY register
36349d81738fSJack F Vogel  *  @hw: pointer to the HW structure
36359d81738fSJack F Vogel  *  @offset: register offset to write to
36369d81738fSJack F Vogel  *  @data: data to write at register offset
36374edd8523SJack F Vogel  *  @locked: semaphore has already been acquired or not
36389d81738fSJack F Vogel  *
36399d81738fSJack F Vogel  *  Acquires semaphore, if necessary, then writes the data to PHY register
36409d81738fSJack F Vogel  *  at the offset.  Release any acquired semaphores before exiting.
36419d81738fSJack F Vogel  **/
36424edd8523SJack F Vogel static s32 __e1000_write_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 data,
36434dab5c37SJack F Vogel 				    bool locked, bool page_set)
36449d81738fSJack F Vogel {
36459d81738fSJack F Vogel 	s32 ret_val;
36469d81738fSJack F Vogel 	u16 page = BM_PHY_REG_PAGE(offset);
36479d81738fSJack F Vogel 	u16 reg = BM_PHY_REG_NUM(offset);
36484dab5c37SJack F Vogel 	u32 phy_addr = hw->phy.addr = e1000_get_phy_addr_for_hv_page(page);
36499d81738fSJack F Vogel 
3650a69ed8dfSJack F Vogel 	DEBUGFUNC("__e1000_write_phy_reg_hv");
36519d81738fSJack F Vogel 
36524edd8523SJack F Vogel 	if (!locked) {
36534edd8523SJack F Vogel 		ret_val = hw->phy.ops.acquire(hw);
36544edd8523SJack F Vogel 		if (ret_val)
36554edd8523SJack F Vogel 			return ret_val;
36564edd8523SJack F Vogel 	}
36579d81738fSJack F Vogel 	/* Page 800 works differently than the rest so it has its own func */
36589d81738fSJack F Vogel 	if (page == BM_WUC_PAGE) {
36594dab5c37SJack F Vogel 		ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, &data,
36604dab5c37SJack F Vogel 							 FALSE, page_set);
36619d81738fSJack F Vogel 		goto out;
36629d81738fSJack F Vogel 	}
36639d81738fSJack F Vogel 
36649d81738fSJack F Vogel 	if (page > 0 && page < HV_INTC_FC_PAGE_START) {
36659d81738fSJack F Vogel 		ret_val = e1000_access_phy_debug_regs_hv(hw, offset,
36669d81738fSJack F Vogel 							 &data, FALSE);
36679d81738fSJack F Vogel 		goto out;
36689d81738fSJack F Vogel 	}
36699d81738fSJack F Vogel 
36704dab5c37SJack F Vogel 	if (!page_set) {
36719d81738fSJack F Vogel 		if (page == HV_INTC_FC_PAGE_START)
36729d81738fSJack F Vogel 			page = 0;
36739d81738fSJack F Vogel 
36746ab6bfe3SJack F Vogel 		/* Workaround MDIO accesses being disabled after entering IEEE
36754dab5c37SJack F Vogel 		 * Power Down (when bit 11 of the PHY Control register is set)
36769d81738fSJack F Vogel 		 */
36779d81738fSJack F Vogel 		if ((hw->phy.type == e1000_phy_82578) &&
36789d81738fSJack F Vogel 		    (hw->phy.revision >= 1) &&
36799d81738fSJack F Vogel 		    (hw->phy.addr == 2) &&
3680ab5d0362SJack F Vogel 		    !(MAX_PHY_REG_ADDRESS & reg) &&
36819d81738fSJack F Vogel 		    (data & (1 << 11))) {
36829d81738fSJack F Vogel 			u16 data2 = 0x7EFF;
36834dab5c37SJack F Vogel 			ret_val = e1000_access_phy_debug_regs_hv(hw,
36844dab5c37SJack F Vogel 								 (1 << 6) | 0x3,
36859d81738fSJack F Vogel 								 &data2, FALSE);
36869d81738fSJack F Vogel 			if (ret_val)
36879d81738fSJack F Vogel 				goto out;
36889d81738fSJack F Vogel 		}
36899d81738fSJack F Vogel 
36909d81738fSJack F Vogel 		if (reg > MAX_PHY_MULTI_PAGE_REG) {
36919d81738fSJack F Vogel 			/* Page is shifted left, PHY expects (page x 32) */
36924dab5c37SJack F Vogel 			ret_val = e1000_set_page_igp(hw,
36939d81738fSJack F Vogel 						     (page << IGP_PAGE_SHIFT));
36944dab5c37SJack F Vogel 
36959d81738fSJack F Vogel 			hw->phy.addr = phy_addr;
36964edd8523SJack F Vogel 
36974edd8523SJack F Vogel 			if (ret_val)
36984edd8523SJack F Vogel 				goto out;
36999d81738fSJack F Vogel 		}
37004dab5c37SJack F Vogel 	}
37014dab5c37SJack F Vogel 
37024dab5c37SJack F Vogel 	DEBUGOUT3("writing PHY page %d (or 0x%x shifted) reg 0x%x\n", page,
37034dab5c37SJack F Vogel 		  page << IGP_PAGE_SHIFT, reg);
37049d81738fSJack F Vogel 
37059d81738fSJack F Vogel 	ret_val = e1000_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & reg,
37069d81738fSJack F Vogel 					   data);
37079d81738fSJack F Vogel 
37089d81738fSJack F Vogel out:
37094edd8523SJack F Vogel 	if (!locked)
37104edd8523SJack F Vogel 		hw->phy.ops.release(hw);
37119d81738fSJack F Vogel 
37129d81738fSJack F Vogel 	return ret_val;
37139d81738fSJack F Vogel }
37149d81738fSJack F Vogel 
37159d81738fSJack F Vogel /**
37164edd8523SJack F Vogel  *  e1000_write_phy_reg_hv - Write HV PHY register
37174edd8523SJack F Vogel  *  @hw: pointer to the HW structure
37184edd8523SJack F Vogel  *  @offset: register offset to write to
37194edd8523SJack F Vogel  *  @data: data to write at register offset
37204edd8523SJack F Vogel  *
37214edd8523SJack F Vogel  *  Acquires semaphore then writes the data to PHY register at the offset.
37224edd8523SJack F Vogel  *  Release the acquired semaphores before exiting.
37234edd8523SJack F Vogel  **/
37244edd8523SJack F Vogel s32 e1000_write_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 data)
37254edd8523SJack F Vogel {
3726*48600901SSean Bruno 	return __e1000_write_phy_reg_hv(hw, offset, data, FALSE, false);
37274edd8523SJack F Vogel }
37284edd8523SJack F Vogel 
37294edd8523SJack F Vogel /**
37304edd8523SJack F Vogel  *  e1000_write_phy_reg_hv_locked - Write HV PHY register
37314edd8523SJack F Vogel  *  @hw: pointer to the HW structure
37324edd8523SJack F Vogel  *  @offset: register offset to write to
37334edd8523SJack F Vogel  *  @data: data to write at register offset
37344edd8523SJack F Vogel  *
37354edd8523SJack F Vogel  *  Writes the data to PHY register at the offset.  Assumes semaphore
37364edd8523SJack F Vogel  *  already acquired.
37374edd8523SJack F Vogel  **/
37384edd8523SJack F Vogel s32 e1000_write_phy_reg_hv_locked(struct e1000_hw *hw, u32 offset, u16 data)
37394edd8523SJack F Vogel {
37404dab5c37SJack F Vogel 	return __e1000_write_phy_reg_hv(hw, offset, data, TRUE, FALSE);
37414dab5c37SJack F Vogel }
37424dab5c37SJack F Vogel 
37434dab5c37SJack F Vogel /**
37444dab5c37SJack F Vogel  *  e1000_write_phy_reg_page_hv - Write HV PHY register
37454dab5c37SJack F Vogel  *  @hw: pointer to the HW structure
37464dab5c37SJack F Vogel  *  @offset: register offset to write to
37474dab5c37SJack F Vogel  *  @data: data to write at register offset
37484dab5c37SJack F Vogel  *
37494dab5c37SJack F Vogel  *  Writes the data to PHY register at the offset.  Assumes semaphore
37504dab5c37SJack F Vogel  *  already acquired and page already set.
37514dab5c37SJack F Vogel  **/
37524dab5c37SJack F Vogel s32 e1000_write_phy_reg_page_hv(struct e1000_hw *hw, u32 offset, u16 data)
37534dab5c37SJack F Vogel {
37544dab5c37SJack F Vogel 	return __e1000_write_phy_reg_hv(hw, offset, data, TRUE, true);
37554edd8523SJack F Vogel }
37564edd8523SJack F Vogel 
37574edd8523SJack F Vogel /**
37589d81738fSJack F Vogel  *  e1000_get_phy_addr_for_hv_page - Get PHY adrress based on page
37599d81738fSJack F Vogel  *  @page: page to be accessed
37609d81738fSJack F Vogel  **/
37619d81738fSJack F Vogel static u32 e1000_get_phy_addr_for_hv_page(u32 page)
37629d81738fSJack F Vogel {
37639d81738fSJack F Vogel 	u32 phy_addr = 2;
37649d81738fSJack F Vogel 
37659d81738fSJack F Vogel 	if (page >= HV_INTC_FC_PAGE_START)
37669d81738fSJack F Vogel 		phy_addr = 1;
37679d81738fSJack F Vogel 
37689d81738fSJack F Vogel 	return phy_addr;
37699d81738fSJack F Vogel }
37709d81738fSJack F Vogel 
37719d81738fSJack F Vogel /**
37729d81738fSJack F Vogel  *  e1000_access_phy_debug_regs_hv - Read HV PHY vendor specific high registers
37739d81738fSJack F Vogel  *  @hw: pointer to the HW structure
37749d81738fSJack F Vogel  *  @offset: register offset to be read or written
37759d81738fSJack F Vogel  *  @data: pointer to the data to be read or written
37764dab5c37SJack F Vogel  *  @read: determines if operation is read or write
37779d81738fSJack F Vogel  *
37784edd8523SJack F Vogel  *  Reads the PHY register at offset and stores the retreived information
37794edd8523SJack F Vogel  *  in data.  Assumes semaphore already acquired.  Note that the procedure
37804dab5c37SJack F Vogel  *  to access these regs uses the address port and data port to read/write.
37814dab5c37SJack F Vogel  *  These accesses done with PHY address 2 and without using pages.
37829d81738fSJack F Vogel  **/
37839d81738fSJack F Vogel static s32 e1000_access_phy_debug_regs_hv(struct e1000_hw *hw, u32 offset,
37849d81738fSJack F Vogel 					  u16 *data, bool read)
37859d81738fSJack F Vogel {
37869d81738fSJack F Vogel 	s32 ret_val;
37876ab6bfe3SJack F Vogel 	u32 addr_reg;
37886ab6bfe3SJack F Vogel 	u32 data_reg;
37899d81738fSJack F Vogel 
37909d81738fSJack F Vogel 	DEBUGFUNC("e1000_access_phy_debug_regs_hv");
37919d81738fSJack F Vogel 
37929d81738fSJack F Vogel 	/* This takes care of the difference with desktop vs mobile phy */
37937609433eSJack F Vogel 	addr_reg = ((hw->phy.type == e1000_phy_82578) ?
37947609433eSJack F Vogel 		    I82578_ADDR_REG : I82577_ADDR_REG);
37959d81738fSJack F Vogel 	data_reg = addr_reg + 1;
37969d81738fSJack F Vogel 
37979d81738fSJack F Vogel 	/* All operations in this function are phy address 2 */
37989d81738fSJack F Vogel 	hw->phy.addr = 2;
37999d81738fSJack F Vogel 
38009d81738fSJack F Vogel 	/* masking with 0x3F to remove the page from offset */
38019d81738fSJack F Vogel 	ret_val = e1000_write_phy_reg_mdic(hw, addr_reg, (u16)offset & 0x3F);
38029d81738fSJack F Vogel 	if (ret_val) {
38034dab5c37SJack F Vogel 		DEBUGOUT("Could not write the Address Offset port register\n");
3804ab5d0362SJack F Vogel 		return ret_val;
38059d81738fSJack F Vogel 	}
38069d81738fSJack F Vogel 
38079d81738fSJack F Vogel 	/* Read or write the data value next */
38089d81738fSJack F Vogel 	if (read)
38099d81738fSJack F Vogel 		ret_val = e1000_read_phy_reg_mdic(hw, data_reg, data);
38109d81738fSJack F Vogel 	else
38119d81738fSJack F Vogel 		ret_val = e1000_write_phy_reg_mdic(hw, data_reg, *data);
38129d81738fSJack F Vogel 
3813ab5d0362SJack F Vogel 	if (ret_val)
38144dab5c37SJack F Vogel 		DEBUGOUT("Could not access the Data port register\n");
38159d81738fSJack F Vogel 
38169d81738fSJack F Vogel 	return ret_val;
38179d81738fSJack F Vogel }
38189d81738fSJack F Vogel 
38199d81738fSJack F Vogel /**
38209d81738fSJack F Vogel  *  e1000_link_stall_workaround_hv - Si workaround
38219d81738fSJack F Vogel  *  @hw: pointer to the HW structure
38229d81738fSJack F Vogel  *
38239d81738fSJack F Vogel  *  This function works around a Si bug where the link partner can get
38249d81738fSJack F Vogel  *  a link up indication before the PHY does.  If small packets are sent
38259d81738fSJack F Vogel  *  by the link partner they can be placed in the packet buffer without
38269d81738fSJack F Vogel  *  being properly accounted for by the PHY and will stall preventing
38279d81738fSJack F Vogel  *  further packets from being received.  The workaround is to clear the
38289d81738fSJack F Vogel  *  packet buffer after the PHY detects link up.
38299d81738fSJack F Vogel  **/
38309d81738fSJack F Vogel s32 e1000_link_stall_workaround_hv(struct e1000_hw *hw)
38319d81738fSJack F Vogel {
38329d81738fSJack F Vogel 	s32 ret_val = E1000_SUCCESS;
38339d81738fSJack F Vogel 	u16 data;
38349d81738fSJack F Vogel 
38359d81738fSJack F Vogel 	DEBUGFUNC("e1000_link_stall_workaround_hv");
38369d81738fSJack F Vogel 
38379d81738fSJack F Vogel 	if (hw->phy.type != e1000_phy_82578)
3838ab5d0362SJack F Vogel 		return E1000_SUCCESS;
38399d81738fSJack F Vogel 
38409d81738fSJack F Vogel 	/* Do not apply workaround if in PHY loopback bit 14 set */
38419d81738fSJack F Vogel 	hw->phy.ops.read_reg(hw, PHY_CONTROL, &data);
38429d81738fSJack F Vogel 	if (data & PHY_CONTROL_LB)
3843ab5d0362SJack F Vogel 		return E1000_SUCCESS;
38449d81738fSJack F Vogel 
38459d81738fSJack F Vogel 	/* check if link is up and at 1Gbps */
38469d81738fSJack F Vogel 	ret_val = hw->phy.ops.read_reg(hw, BM_CS_STATUS, &data);
38479d81738fSJack F Vogel 	if (ret_val)
3848ab5d0362SJack F Vogel 		return ret_val;
38499d81738fSJack F Vogel 
38507609433eSJack F Vogel 	data &= (BM_CS_STATUS_LINK_UP | BM_CS_STATUS_RESOLVED |
38517609433eSJack F Vogel 		 BM_CS_STATUS_SPEED_MASK);
38529d81738fSJack F Vogel 
38534dab5c37SJack F Vogel 	if (data != (BM_CS_STATUS_LINK_UP | BM_CS_STATUS_RESOLVED |
38549d81738fSJack F Vogel 		     BM_CS_STATUS_SPEED_1000))
3855ab5d0362SJack F Vogel 		return E1000_SUCCESS;
38569d81738fSJack F Vogel 
38579d81738fSJack F Vogel 	msec_delay(200);
38589d81738fSJack F Vogel 
38599d81738fSJack F Vogel 	/* flush the packets in the fifo buffer */
38609d81738fSJack F Vogel 	ret_val = hw->phy.ops.write_reg(hw, HV_MUX_DATA_CTRL,
38616ab6bfe3SJack F Vogel 					(HV_MUX_DATA_CTRL_GEN_TO_MAC |
38626ab6bfe3SJack F Vogel 					 HV_MUX_DATA_CTRL_FORCE_SPEED));
38639d81738fSJack F Vogel 	if (ret_val)
38649d81738fSJack F Vogel 		return ret_val;
3865ab5d0362SJack F Vogel 
3866ab5d0362SJack F Vogel 	return hw->phy.ops.write_reg(hw, HV_MUX_DATA_CTRL,
3867ab5d0362SJack F Vogel 				     HV_MUX_DATA_CTRL_GEN_TO_MAC);
38689d81738fSJack F Vogel }
38699d81738fSJack F Vogel 
38709d81738fSJack F Vogel /**
38719d81738fSJack F Vogel  *  e1000_check_polarity_82577 - Checks the polarity.
38729d81738fSJack F Vogel  *  @hw: pointer to the HW structure
38739d81738fSJack F Vogel  *
38749d81738fSJack F Vogel  *  Success returns 0, Failure returns -E1000_ERR_PHY (-2)
38759d81738fSJack F Vogel  *
38769d81738fSJack F Vogel  *  Polarity is determined based on the PHY specific status register.
38779d81738fSJack F Vogel  **/
38789d81738fSJack F Vogel s32 e1000_check_polarity_82577(struct e1000_hw *hw)
38799d81738fSJack F Vogel {
38809d81738fSJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
38819d81738fSJack F Vogel 	s32 ret_val;
38829d81738fSJack F Vogel 	u16 data;
38839d81738fSJack F Vogel 
38849d81738fSJack F Vogel 	DEBUGFUNC("e1000_check_polarity_82577");
38859d81738fSJack F Vogel 
38869d81738fSJack F Vogel 	ret_val = phy->ops.read_reg(hw, I82577_PHY_STATUS_2, &data);
38879d81738fSJack F Vogel 
38889d81738fSJack F Vogel 	if (!ret_val)
38897609433eSJack F Vogel 		phy->cable_polarity = ((data & I82577_PHY_STATUS2_REV_POLARITY)
38909d81738fSJack F Vogel 				       ? e1000_rev_polarity_reversed
38917609433eSJack F Vogel 				       : e1000_rev_polarity_normal);
38929d81738fSJack F Vogel 
38939d81738fSJack F Vogel 	return ret_val;
38949d81738fSJack F Vogel }
38959d81738fSJack F Vogel 
38969d81738fSJack F Vogel /**
38979d81738fSJack F Vogel  *  e1000_phy_force_speed_duplex_82577 - Force speed/duplex for I82577 PHY
38989d81738fSJack F Vogel  *  @hw: pointer to the HW structure
38999d81738fSJack F Vogel  *
39008ec87fc5SJack F Vogel  *  Calls the PHY setup function to force speed and duplex.
39019d81738fSJack F Vogel  **/
39029d81738fSJack F Vogel s32 e1000_phy_force_speed_duplex_82577(struct e1000_hw *hw)
39039d81738fSJack F Vogel {
39049d81738fSJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
39059d81738fSJack F Vogel 	s32 ret_val;
39069d81738fSJack F Vogel 	u16 phy_data;
39079d81738fSJack F Vogel 	bool link;
39089d81738fSJack F Vogel 
39099d81738fSJack F Vogel 	DEBUGFUNC("e1000_phy_force_speed_duplex_82577");
39109d81738fSJack F Vogel 
39119d81738fSJack F Vogel 	ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data);
39129d81738fSJack F Vogel 	if (ret_val)
3913ab5d0362SJack F Vogel 		return ret_val;
39149d81738fSJack F Vogel 
39159d81738fSJack F Vogel 	e1000_phy_force_speed_duplex_setup(hw, &phy_data);
39169d81738fSJack F Vogel 
39179d81738fSJack F Vogel 	ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data);
39189d81738fSJack F Vogel 	if (ret_val)
3919ab5d0362SJack F Vogel 		return ret_val;
39209d81738fSJack F Vogel 
39219d81738fSJack F Vogel 	usec_delay(1);
39229d81738fSJack F Vogel 
39239d81738fSJack F Vogel 	if (phy->autoneg_wait_to_complete) {
39249d81738fSJack F Vogel 		DEBUGOUT("Waiting for forced speed/duplex link on 82577 phy\n");
39259d81738fSJack F Vogel 
39264dab5c37SJack F Vogel 		ret_val = e1000_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
39274dab5c37SJack F Vogel 						     100000, &link);
39289d81738fSJack F Vogel 		if (ret_val)
3929ab5d0362SJack F Vogel 			return ret_val;
39309d81738fSJack F Vogel 
39319d81738fSJack F Vogel 		if (!link)
39329d81738fSJack F Vogel 			DEBUGOUT("Link taking longer than expected.\n");
39339d81738fSJack F Vogel 
39349d81738fSJack F Vogel 		/* Try once more */
39354dab5c37SJack F Vogel 		ret_val = e1000_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
39364dab5c37SJack F Vogel 						     100000, &link);
39379d81738fSJack F Vogel 	}
39389d81738fSJack F Vogel 
39399d81738fSJack F Vogel 	return ret_val;
39409d81738fSJack F Vogel }
39419d81738fSJack F Vogel 
39429d81738fSJack F Vogel /**
39439d81738fSJack F Vogel  *  e1000_get_phy_info_82577 - Retrieve I82577 PHY information
39449d81738fSJack F Vogel  *  @hw: pointer to the HW structure
39459d81738fSJack F Vogel  *
39469d81738fSJack F Vogel  *  Read PHY status to determine if link is up.  If link is up, then
39479d81738fSJack F Vogel  *  set/determine 10base-T extended distance and polarity correction.  Read
39489d81738fSJack F Vogel  *  PHY port status to determine MDI/MDIx and speed.  Based on the speed,
39499d81738fSJack F Vogel  *  determine on the cable length, local and remote receiver.
39509d81738fSJack F Vogel  **/
39519d81738fSJack F Vogel s32 e1000_get_phy_info_82577(struct e1000_hw *hw)
39529d81738fSJack F Vogel {
39539d81738fSJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
39549d81738fSJack F Vogel 	s32 ret_val;
39559d81738fSJack F Vogel 	u16 data;
39569d81738fSJack F Vogel 	bool link;
39579d81738fSJack F Vogel 
39589d81738fSJack F Vogel 	DEBUGFUNC("e1000_get_phy_info_82577");
39599d81738fSJack F Vogel 
39609d81738fSJack F Vogel 	ret_val = e1000_phy_has_link_generic(hw, 1, 0, &link);
39619d81738fSJack F Vogel 	if (ret_val)
3962ab5d0362SJack F Vogel 		return ret_val;
39639d81738fSJack F Vogel 
39649d81738fSJack F Vogel 	if (!link) {
39659d81738fSJack F Vogel 		DEBUGOUT("Phy info is only valid if link is up\n");
3966ab5d0362SJack F Vogel 		return -E1000_ERR_CONFIG;
39679d81738fSJack F Vogel 	}
39689d81738fSJack F Vogel 
39699d81738fSJack F Vogel 	phy->polarity_correction = TRUE;
39709d81738fSJack F Vogel 
39719d81738fSJack F Vogel 	ret_val = e1000_check_polarity_82577(hw);
39729d81738fSJack F Vogel 	if (ret_val)
3973ab5d0362SJack F Vogel 		return ret_val;
39749d81738fSJack F Vogel 
39759d81738fSJack F Vogel 	ret_val = phy->ops.read_reg(hw, I82577_PHY_STATUS_2, &data);
39769d81738fSJack F Vogel 	if (ret_val)
3977ab5d0362SJack F Vogel 		return ret_val;
39789d81738fSJack F Vogel 
3979ab5d0362SJack F Vogel 	phy->is_mdix = !!(data & I82577_PHY_STATUS2_MDIX);
39809d81738fSJack F Vogel 
39819d81738fSJack F Vogel 	if ((data & I82577_PHY_STATUS2_SPEED_MASK) ==
39829d81738fSJack F Vogel 	    I82577_PHY_STATUS2_SPEED_1000MBPS) {
39839d81738fSJack F Vogel 		ret_val = hw->phy.ops.get_cable_length(hw);
39849d81738fSJack F Vogel 		if (ret_val)
3985ab5d0362SJack F Vogel 			return ret_val;
39869d81738fSJack F Vogel 
39879d81738fSJack F Vogel 		ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &data);
39889d81738fSJack F Vogel 		if (ret_val)
3989ab5d0362SJack F Vogel 			return ret_val;
39909d81738fSJack F Vogel 
39919d81738fSJack F Vogel 		phy->local_rx = (data & SR_1000T_LOCAL_RX_STATUS)
39929d81738fSJack F Vogel 				? e1000_1000t_rx_status_ok
39939d81738fSJack F Vogel 				: e1000_1000t_rx_status_not_ok;
39949d81738fSJack F Vogel 
39959d81738fSJack F Vogel 		phy->remote_rx = (data & SR_1000T_REMOTE_RX_STATUS)
39969d81738fSJack F Vogel 				 ? e1000_1000t_rx_status_ok
39979d81738fSJack F Vogel 				 : e1000_1000t_rx_status_not_ok;
39989d81738fSJack F Vogel 	} else {
39999d81738fSJack F Vogel 		phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
40009d81738fSJack F Vogel 		phy->local_rx = e1000_1000t_rx_status_undefined;
40019d81738fSJack F Vogel 		phy->remote_rx = e1000_1000t_rx_status_undefined;
40029d81738fSJack F Vogel 	}
40039d81738fSJack F Vogel 
4004ab5d0362SJack F Vogel 	return E1000_SUCCESS;
40059d81738fSJack F Vogel }
40069d81738fSJack F Vogel 
40079d81738fSJack F Vogel /**
40089d81738fSJack F Vogel  *  e1000_get_cable_length_82577 - Determine cable length for 82577 PHY
40099d81738fSJack F Vogel  *  @hw: pointer to the HW structure
40109d81738fSJack F Vogel  *
40119d81738fSJack F Vogel  * Reads the diagnostic status register and verifies result is valid before
40129d81738fSJack F Vogel  * placing it in the phy_cable_length field.
40139d81738fSJack F Vogel  **/
40149d81738fSJack F Vogel s32 e1000_get_cable_length_82577(struct e1000_hw *hw)
40159d81738fSJack F Vogel {
40169d81738fSJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
40179d81738fSJack F Vogel 	s32 ret_val;
40189d81738fSJack F Vogel 	u16 phy_data, length;
40199d81738fSJack F Vogel 
40209d81738fSJack F Vogel 	DEBUGFUNC("e1000_get_cable_length_82577");
40219d81738fSJack F Vogel 
40229d81738fSJack F Vogel 	ret_val = phy->ops.read_reg(hw, I82577_PHY_DIAG_STATUS, &phy_data);
40239d81738fSJack F Vogel 	if (ret_val)
4024ab5d0362SJack F Vogel 		return ret_val;
40259d81738fSJack F Vogel 
40267609433eSJack F Vogel 	length = ((phy_data & I82577_DSTATUS_CABLE_LENGTH) >>
40277609433eSJack F Vogel 		  I82577_DSTATUS_CABLE_LENGTH_SHIFT);
40289d81738fSJack F Vogel 
40299d81738fSJack F Vogel 	if (length == E1000_CABLE_LENGTH_UNDEFINED)
40306ab6bfe3SJack F Vogel 		return -E1000_ERR_PHY;
40319d81738fSJack F Vogel 
40329d81738fSJack F Vogel 	phy->cable_length = length;
40339d81738fSJack F Vogel 
4034ab5d0362SJack F Vogel 	return E1000_SUCCESS;
4035ab5d0362SJack F Vogel }
4036ab5d0362SJack F Vogel 
4037ab5d0362SJack F Vogel /**
4038ab5d0362SJack F Vogel  *  e1000_write_phy_reg_gs40g - Write GS40G  PHY register
4039ab5d0362SJack F Vogel  *  @hw: pointer to the HW structure
4040ab5d0362SJack F Vogel  *  @offset: register offset to write to
4041ab5d0362SJack F Vogel  *  @data: data to write at register offset
4042ab5d0362SJack F Vogel  *
4043ab5d0362SJack F Vogel  *  Acquires semaphore, if necessary, then writes the data to PHY register
4044ab5d0362SJack F Vogel  *  at the offset.  Release any acquired semaphores before exiting.
4045ab5d0362SJack F Vogel  **/
4046ab5d0362SJack F Vogel s32 e1000_write_phy_reg_gs40g(struct e1000_hw *hw, u32 offset, u16 data)
4047ab5d0362SJack F Vogel {
4048ab5d0362SJack F Vogel 	s32 ret_val;
4049ab5d0362SJack F Vogel 	u16 page = offset >> GS40G_PAGE_SHIFT;
4050ab5d0362SJack F Vogel 
4051ab5d0362SJack F Vogel 	DEBUGFUNC("e1000_write_phy_reg_gs40g");
4052ab5d0362SJack F Vogel 
4053ab5d0362SJack F Vogel 	offset = offset & GS40G_OFFSET_MASK;
4054ab5d0362SJack F Vogel 	ret_val = hw->phy.ops.acquire(hw);
4055ab5d0362SJack F Vogel 	if (ret_val)
4056ab5d0362SJack F Vogel 		return ret_val;
4057ab5d0362SJack F Vogel 
4058ab5d0362SJack F Vogel 	ret_val = e1000_write_phy_reg_mdic(hw, GS40G_PAGE_SELECT, page);
4059ab5d0362SJack F Vogel 	if (ret_val)
4060ab5d0362SJack F Vogel 		goto release;
4061ab5d0362SJack F Vogel 	ret_val = e1000_write_phy_reg_mdic(hw, offset, data);
4062ab5d0362SJack F Vogel 
4063ab5d0362SJack F Vogel release:
4064ab5d0362SJack F Vogel 	hw->phy.ops.release(hw);
4065ab5d0362SJack F Vogel 	return ret_val;
4066ab5d0362SJack F Vogel }
4067ab5d0362SJack F Vogel 
4068ab5d0362SJack F Vogel /**
4069ab5d0362SJack F Vogel  *  e1000_read_phy_reg_gs40g - Read GS40G  PHY register
4070ab5d0362SJack F Vogel  *  @hw: pointer to the HW structure
4071ab5d0362SJack F Vogel  *  @offset: lower half is register offset to read to
4072ab5d0362SJack F Vogel  *     upper half is page to use.
4073ab5d0362SJack F Vogel  *  @data: data to read at register offset
4074ab5d0362SJack F Vogel  *
4075ab5d0362SJack F Vogel  *  Acquires semaphore, if necessary, then reads the data in the PHY register
4076ab5d0362SJack F Vogel  *  at the offset.  Release any acquired semaphores before exiting.
4077ab5d0362SJack F Vogel  **/
4078ab5d0362SJack F Vogel s32 e1000_read_phy_reg_gs40g(struct e1000_hw *hw, u32 offset, u16 *data)
4079ab5d0362SJack F Vogel {
4080ab5d0362SJack F Vogel 	s32 ret_val;
4081ab5d0362SJack F Vogel 	u16 page = offset >> GS40G_PAGE_SHIFT;
4082ab5d0362SJack F Vogel 
4083ab5d0362SJack F Vogel 	DEBUGFUNC("e1000_read_phy_reg_gs40g");
4084ab5d0362SJack F Vogel 
4085ab5d0362SJack F Vogel 	offset = offset & GS40G_OFFSET_MASK;
4086ab5d0362SJack F Vogel 	ret_val = hw->phy.ops.acquire(hw);
4087ab5d0362SJack F Vogel 	if (ret_val)
4088ab5d0362SJack F Vogel 		return ret_val;
4089ab5d0362SJack F Vogel 
4090ab5d0362SJack F Vogel 	ret_val = e1000_write_phy_reg_mdic(hw, GS40G_PAGE_SELECT, page);
4091ab5d0362SJack F Vogel 	if (ret_val)
4092ab5d0362SJack F Vogel 		goto release;
4093ab5d0362SJack F Vogel 	ret_val = e1000_read_phy_reg_mdic(hw, offset, data);
4094ab5d0362SJack F Vogel 
4095ab5d0362SJack F Vogel release:
4096ab5d0362SJack F Vogel 	hw->phy.ops.release(hw);
40979d81738fSJack F Vogel 	return ret_val;
40989d81738fSJack F Vogel }
40996ab6bfe3SJack F Vogel 
41007609433eSJack F Vogel /**
41017609433eSJack F Vogel  *  e1000_read_phy_reg_mphy - Read mPHY control register
41027609433eSJack F Vogel  *  @hw: pointer to the HW structure
41037609433eSJack F Vogel  *  @address: address to be read
41047609433eSJack F Vogel  *  @data: pointer to the read data
41057609433eSJack F Vogel  *
41067609433eSJack F Vogel  *  Reads the mPHY control register in the PHY at offset and stores the
41077609433eSJack F Vogel  *  information read to data.
41087609433eSJack F Vogel  **/
41097609433eSJack F Vogel s32 e1000_read_phy_reg_mphy(struct e1000_hw *hw, u32 address, u32 *data)
41107609433eSJack F Vogel {
41117609433eSJack F Vogel 	u32 mphy_ctrl = 0;
41127609433eSJack F Vogel 	bool locked = FALSE;
41138cc64f1eSJack F Vogel 	bool ready;
41147609433eSJack F Vogel 
41157609433eSJack F Vogel 	DEBUGFUNC("e1000_read_phy_reg_mphy");
41167609433eSJack F Vogel 
41177609433eSJack F Vogel 	/* Check if mPHY is ready to read/write operations */
41187609433eSJack F Vogel 	ready = e1000_is_mphy_ready(hw);
41197609433eSJack F Vogel 	if (!ready)
41207609433eSJack F Vogel 		return -E1000_ERR_PHY;
41217609433eSJack F Vogel 
41227609433eSJack F Vogel 	/* Check if mPHY access is disabled and enable it if so */
41237609433eSJack F Vogel 	mphy_ctrl = E1000_READ_REG(hw, E1000_MPHY_ADDR_CTRL);
41247609433eSJack F Vogel 	if (mphy_ctrl & E1000_MPHY_DIS_ACCESS) {
41257609433eSJack F Vogel 		locked = TRUE;
41267609433eSJack F Vogel 		ready = e1000_is_mphy_ready(hw);
41277609433eSJack F Vogel 		if (!ready)
41287609433eSJack F Vogel 			return -E1000_ERR_PHY;
41297609433eSJack F Vogel 		mphy_ctrl |= E1000_MPHY_ENA_ACCESS;
41307609433eSJack F Vogel 		E1000_WRITE_REG(hw, E1000_MPHY_ADDR_CTRL, mphy_ctrl);
41317609433eSJack F Vogel 	}
41327609433eSJack F Vogel 
41337609433eSJack F Vogel 	/* Set the address that we want to read */
41347609433eSJack F Vogel 	ready = e1000_is_mphy_ready(hw);
41357609433eSJack F Vogel 	if (!ready)
41367609433eSJack F Vogel 		return -E1000_ERR_PHY;
41377609433eSJack F Vogel 
41387609433eSJack F Vogel 	/* We mask address, because we want to use only current lane */
41397609433eSJack F Vogel 	mphy_ctrl = (mphy_ctrl & ~E1000_MPHY_ADDRESS_MASK &
41407609433eSJack F Vogel 		~E1000_MPHY_ADDRESS_FNC_OVERRIDE) |
41417609433eSJack F Vogel 		(address & E1000_MPHY_ADDRESS_MASK);
41427609433eSJack F Vogel 	E1000_WRITE_REG(hw, E1000_MPHY_ADDR_CTRL, mphy_ctrl);
41437609433eSJack F Vogel 
41447609433eSJack F Vogel 	/* Read data from the address */
41457609433eSJack F Vogel 	ready = e1000_is_mphy_ready(hw);
41467609433eSJack F Vogel 	if (!ready)
41477609433eSJack F Vogel 		return -E1000_ERR_PHY;
41487609433eSJack F Vogel 	*data = E1000_READ_REG(hw, E1000_MPHY_DATA);
41497609433eSJack F Vogel 
41507609433eSJack F Vogel 	/* Disable access to mPHY if it was originally disabled */
41518cc64f1eSJack F Vogel 	if (locked)
41527609433eSJack F Vogel 		ready = e1000_is_mphy_ready(hw);
41537609433eSJack F Vogel 		if (!ready)
41547609433eSJack F Vogel 			return -E1000_ERR_PHY;
41557609433eSJack F Vogel 		E1000_WRITE_REG(hw, E1000_MPHY_ADDR_CTRL,
41567609433eSJack F Vogel 				E1000_MPHY_DIS_ACCESS);
41577609433eSJack F Vogel 
41587609433eSJack F Vogel 	return E1000_SUCCESS;
41597609433eSJack F Vogel }
41607609433eSJack F Vogel 
41617609433eSJack F Vogel /**
41627609433eSJack F Vogel  *  e1000_write_phy_reg_mphy - Write mPHY control register
41637609433eSJack F Vogel  *  @hw: pointer to the HW structure
41647609433eSJack F Vogel  *  @address: address to write to
41657609433eSJack F Vogel  *  @data: data to write to register at offset
41667609433eSJack F Vogel  *  @line_override: used when we want to use different line than default one
41677609433eSJack F Vogel  *
41687609433eSJack F Vogel  *  Writes data to mPHY control register.
41697609433eSJack F Vogel  **/
41707609433eSJack F Vogel s32 e1000_write_phy_reg_mphy(struct e1000_hw *hw, u32 address, u32 data,
41717609433eSJack F Vogel 			     bool line_override)
41727609433eSJack F Vogel {
41737609433eSJack F Vogel 	u32 mphy_ctrl = 0;
41747609433eSJack F Vogel 	bool locked = FALSE;
41758cc64f1eSJack F Vogel 	bool ready;
41767609433eSJack F Vogel 
41777609433eSJack F Vogel 	DEBUGFUNC("e1000_write_phy_reg_mphy");
41787609433eSJack F Vogel 
41797609433eSJack F Vogel 	/* Check if mPHY is ready to read/write operations */
41807609433eSJack F Vogel 	ready = e1000_is_mphy_ready(hw);
41817609433eSJack F Vogel 	if (!ready)
41827609433eSJack F Vogel 		return -E1000_ERR_PHY;
41837609433eSJack F Vogel 
41847609433eSJack F Vogel 	/* Check if mPHY access is disabled and enable it if so */
41857609433eSJack F Vogel 	mphy_ctrl = E1000_READ_REG(hw, E1000_MPHY_ADDR_CTRL);
41867609433eSJack F Vogel 	if (mphy_ctrl & E1000_MPHY_DIS_ACCESS) {
41877609433eSJack F Vogel 		locked = TRUE;
41887609433eSJack F Vogel 		ready = e1000_is_mphy_ready(hw);
41897609433eSJack F Vogel 		if (!ready)
41907609433eSJack F Vogel 			return -E1000_ERR_PHY;
41917609433eSJack F Vogel 		mphy_ctrl |= E1000_MPHY_ENA_ACCESS;
41927609433eSJack F Vogel 		E1000_WRITE_REG(hw, E1000_MPHY_ADDR_CTRL, mphy_ctrl);
41937609433eSJack F Vogel 	}
41947609433eSJack F Vogel 
41957609433eSJack F Vogel 	/* Set the address that we want to read */
41967609433eSJack F Vogel 	ready = e1000_is_mphy_ready(hw);
41977609433eSJack F Vogel 	if (!ready)
41987609433eSJack F Vogel 		return -E1000_ERR_PHY;
41997609433eSJack F Vogel 
42007609433eSJack F Vogel 	/* We mask address, because we want to use only current lane */
42017609433eSJack F Vogel 	if (line_override)
42027609433eSJack F Vogel 		mphy_ctrl |= E1000_MPHY_ADDRESS_FNC_OVERRIDE;
42037609433eSJack F Vogel 	else
42047609433eSJack F Vogel 		mphy_ctrl &= ~E1000_MPHY_ADDRESS_FNC_OVERRIDE;
42057609433eSJack F Vogel 	mphy_ctrl = (mphy_ctrl & ~E1000_MPHY_ADDRESS_MASK) |
42067609433eSJack F Vogel 		(address & E1000_MPHY_ADDRESS_MASK);
42077609433eSJack F Vogel 	E1000_WRITE_REG(hw, E1000_MPHY_ADDR_CTRL, mphy_ctrl);
42087609433eSJack F Vogel 
42097609433eSJack F Vogel 	/* Read data from the address */
42107609433eSJack F Vogel 	ready = e1000_is_mphy_ready(hw);
42117609433eSJack F Vogel 	if (!ready)
42127609433eSJack F Vogel 		return -E1000_ERR_PHY;
42137609433eSJack F Vogel 	E1000_WRITE_REG(hw, E1000_MPHY_DATA, data);
42147609433eSJack F Vogel 
42157609433eSJack F Vogel 	/* Disable access to mPHY if it was originally disabled */
42168cc64f1eSJack F Vogel 	if (locked)
42177609433eSJack F Vogel 		ready = e1000_is_mphy_ready(hw);
42187609433eSJack F Vogel 		if (!ready)
42197609433eSJack F Vogel 			return -E1000_ERR_PHY;
42207609433eSJack F Vogel 		E1000_WRITE_REG(hw, E1000_MPHY_ADDR_CTRL,
42217609433eSJack F Vogel 				E1000_MPHY_DIS_ACCESS);
42227609433eSJack F Vogel 
42237609433eSJack F Vogel 	return E1000_SUCCESS;
42247609433eSJack F Vogel }
42257609433eSJack F Vogel 
42267609433eSJack F Vogel /**
42277609433eSJack F Vogel  *  e1000_is_mphy_ready - Check if mPHY control register is not busy
42287609433eSJack F Vogel  *  @hw: pointer to the HW structure
42297609433eSJack F Vogel  *
42307609433eSJack F Vogel  *  Returns mPHY control register status.
42317609433eSJack F Vogel  **/
42327609433eSJack F Vogel bool e1000_is_mphy_ready(struct e1000_hw *hw)
42337609433eSJack F Vogel {
42347609433eSJack F Vogel 	u16 retry_count = 0;
42357609433eSJack F Vogel 	u32 mphy_ctrl = 0;
42367609433eSJack F Vogel 	bool ready = FALSE;
42377609433eSJack F Vogel 
42387609433eSJack F Vogel 	while (retry_count < 2) {
42397609433eSJack F Vogel 		mphy_ctrl = E1000_READ_REG(hw, E1000_MPHY_ADDR_CTRL);
42407609433eSJack F Vogel 		if (mphy_ctrl & E1000_MPHY_BUSY) {
42417609433eSJack F Vogel 			usec_delay(20);
42427609433eSJack F Vogel 			retry_count++;
42437609433eSJack F Vogel 			continue;
42447609433eSJack F Vogel 		}
42457609433eSJack F Vogel 		ready = TRUE;
42467609433eSJack F Vogel 		break;
42477609433eSJack F Vogel 	}
42487609433eSJack F Vogel 
42497609433eSJack F Vogel 	if (!ready)
42507609433eSJack F Vogel 		DEBUGOUT("ERROR READING mPHY control register, phy is busy.\n");
42517609433eSJack F Vogel 
42527609433eSJack F Vogel 	return ready;
42537609433eSJack F Vogel }
4254